修改OpenGl渲染底层之前

This commit is contained in:
2025-10-20 20:50:12 +08:00
parent 1b011b9b68
commit 2b888aae5b
61 changed files with 1609 additions and 680 deletions

View File

@@ -3,6 +3,7 @@
#include "Asset/Asset_Script.h"
#include "Tool/Math.h"
#include "EngineFrame/Actor/Actor.h"
#include "EngineCore/Game.h"
Animation::Animation()
{
@@ -66,20 +67,20 @@ void Animation::Init(std::string AniPath)
// TODO 染色
// 判断是否有Als
if (Asset_Script::GetInstance().GetFileInfo(AniPath + ".als"))
{
AniScriptParser::AlsInfo Info = AssetManager::GetInstance().StructAlsInfo(AniPath + ".als");
if (Info.AniList.size() > 0)
{
std::string Dir = AniPath.substr(0, AniPath.find_last_of("/") + 1);
for (auto &Ani : Info.AniList)
{
RefPtr<Animation> AlsAniObj = new Animation(Dir + Ani.second.path);
AlsAniObj->SetRenderZOrder(Ani.second.layer[1]);
AddChild(AlsAniObj);
}
}
}
// if (Asset_Script::GetInstance().GetFileInfo(AniPath + ".als"))
// {
// AniScriptParser::AlsInfo Info = AssetManager::GetInstance().StructAlsInfo(AniPath + ".als");
// if (Info.AniList.size() > 0)
// {
// std::string Dir = AniPath.substr(0, AniPath.find_last_of("/") + 1);
// for (auto &Ani : Info.AniList)
// {
// RefPtr<Animation> AlsAniObj = new Animation(Dir + Ani.second.path);
// AlsAniObj->SetRenderZOrder(Ani.second.layer[1]);
// AddChild(AlsAniObj);
// }
// }
// }
FlushFrame(0);
}
@@ -134,7 +135,18 @@ void Animation::Render()
{
if (!Visible)
return;
Actor::Render();
// 是否裁切
if (CropFlag)
{
SDL_Renderer *renderer = Game::GetInstance().GetRenderer();
SDL_RenderSetClipRect(renderer, &CropRect);
Actor::Render();
SDL_RenderSetClipRect(renderer, NULL);
}
else
{
Actor::Render();
}
}
void Animation::OnAdded(BaseNode *node)
@@ -153,6 +165,7 @@ void Animation::SetVisible(bool visible)
if (visible)
{
CurrentFrame->CalcRenderInfoLogic();
CurrentFrame->CalcRenderInfo();
}
Actor::SetVisible(visible);
}
@@ -192,7 +205,6 @@ void Animation::FlushFrame(int Index)
if (FlagBuf.count("IMAGE_RATE"))
{
VecFPos Rate = std::get<VecFPos>(FlagBuf["IMAGE_RATE"]);
CurrentFrame->SetAnchor(VecFPos{0.5f, 0.5f});
CurrentFrame->SetScale(VecFPos{Rate.x, Rate.y});
}
// 线性减淡
@@ -233,7 +245,6 @@ void Animation::FlushFrame(int Index)
}
// Ani的大小同步为精灵帧对象的大小
SetSize(CurrentFrame->GetSize());
// 裁切 //TODO
}
void Animation::Reset()
@@ -317,3 +328,22 @@ void Animation::InterpolationLogic()
CurrentFrame->SetRotation(OldAngleData + (NewAngleData - OldAngleData) * InterRate);
}
}
void Animation::SetClipRect(SDL_Rect clipRect)
{
CropFlag = true;
CropRect = clipRect;
}
void Animation::UnsetClipRect()
{
CropFlag = false;
}
void Animation::SetShadow()
{
for (auto &Sp : SpriteArr)
{
Sp->SetShadow();
}
}