修改渲染底层,新增场景摄像机逻辑,地图可行区域逻辑

This commit is contained in:
2025-10-08 23:58:15 +08:00
parent df2cacdb92
commit 1b011b9b68
23 changed files with 5350 additions and 40 deletions

View File

@@ -60,6 +60,7 @@ void Game::Init(std::function<void()> CallBack)
}
// 启用渲染器的混合功能(必须,否则纹理混合模式无效)
SDL_SetRenderDrawBlendMode(m_renderer, SDL_BLENDMODE_BLEND);
// SDL_RenderSetScale(m_renderer, 1.2, 1.2);
IMG_Init(IMG_INIT_PNG);
// 初始化SDL_mixer支持OGG格式

View File

@@ -77,7 +77,11 @@ private:
RefPtr<Scene> m_uiScene;
// 帧数
int m_fps = 10000;
#ifdef __SWITCH__
int m_fps = 60;
#else
int m_fps = 2000;
#endif
u32 m_frameTime;
float m_deltaTime;
// 新增:帧率统计变量

View File

@@ -4,16 +4,16 @@
Debug_Actor::Debug_Actor()
{
m_debugFont = TTF_OpenFont("Fonts/GasinamuNew.ttf", 16);
m_debugFont = TTF_OpenFont("Fonts/VonwaonBitmap-12px.ttf", 12);
if (m_debugFont == nullptr)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to load debug font: %s", TTF_GetError());
}
FPS_Text = new Text("Current FPS:", m_debugFont, SDL_Color{255, 255, 255, 255});
DT_Text = new Text("DeltaTime :", m_debugFont, SDL_Color{255, 255, 255, 255});
RC_Text = new Text("Render Calls:", m_debugFont, SDL_Color{255, 255, 255, 255});
FPS_Text = new Text("当 前 帧 数 :", m_debugFont, SDL_Color{255, 255, 255, 255});
DT_Text = new Text("帧 时 间 :", m_debugFont, SDL_Color{255, 255, 255, 255});
RC_Text = new Text("渲 染 调 用 次 数:", m_debugFont, SDL_Color{255, 255, 255, 255});
if (FPS_Text != nullptr)
{
SDL_Point Pos{26, 26};
@@ -50,11 +50,11 @@ void Debug_Actor::Update(float deltaTime)
if (FPS_Text != nullptr)
{
std::string fpsText = "Current FPS: " + std::to_string(FPS);
std::string fpsText = "当前帧数 : " + std::to_string(FPS);
FPS_Text->SetText(fpsText);
std::string dtText = "DeltaTime: " + std::to_string((int)(deltaTime * 1000));
std::string dtText = "帧时间 : " + std::to_string((int)(deltaTime * 1000));
DT_Text->SetText(dtText);
std::string rcText = "Render Calls: " + std::to_string(RenderCount);
std::string rcText = "渲染调用次数 : " + std::to_string(RenderCount);
RC_Text->SetText(rcText);
}
}

View File

@@ -92,6 +92,7 @@ int BaseNode::GetRenderZOrder()
void BaseNode::SetRenderZOrder(int zOrder)
{
m_RenderZOrder = zOrder;
Reorder();
}
void BaseNode::Reorder()

View File

@@ -118,7 +118,7 @@ public:
// 获取大小
VecSize GetSize();
// 设置是否显示
void SetVisible(bool visible);
virtual void SetVisible(bool visible);
// 获取是否显示
bool GetVisible();
};

View File

@@ -147,6 +147,16 @@ void Animation::Clear()
{
}
void Animation::SetVisible(bool visible)
{
// 设置启用的时候要更新一下当前帧的渲染信息 避免因为延迟造成的坐标闪烁
if (visible)
{
CurrentFrame->CalcRenderInfoLogic();
}
Actor::SetVisible(visible);
}
void Animation::FlushFrame(int Index)
{
// 关闭旧帧显示

View File

@@ -30,6 +30,7 @@ public:
void Render() override;
void OnAdded(BaseNode *node) override;
void Clear() override;
void SetVisible(bool visible) override;
public:
void FlushFrame(int Index);