Split stage rendering and debug overlay

This commit is contained in:
2026-06-09 00:39:15 +08:00
parent ce815ed58b
commit cc75b94c44
9 changed files with 199 additions and 47 deletions
+4 -36
View File
@@ -9,14 +9,6 @@
namespace ns_game {
namespace {
void drawRect(const frostbite2D::Rect& rect, const frostbite2D::Color& color) {
frostbite2D::Renderer::get().drawQuad(rect, color);
}
} // namespace
void WhiteboxScene::onEnter() {
frostbite2D::Scene::onEnter();
level_ = CreateWhiteboxLevel();
@@ -32,35 +24,11 @@ void WhiteboxScene::OnUpdate(float deltaTime) {
}
void WhiteboxScene::Render() {
drawWhitebox();
stageRenderer_.Render(level_, debugFlags_);
frostbite2D::Scene::Render();
}
void WhiteboxScene::drawWhitebox() const {
const float worldWidth = level_.collision.levelRight - level_.collision.levelLeft;
drawRect(frostbite2D::Rect(level_.collision.levelLeft, 0.0f, worldWidth,
config::kVirtualHeight),
frostbite2D::Color(0.10f, 0.12f, 0.14f, 1.0f));
for (float x = level_.collision.levelLeft; x <= level_.collision.levelRight;
x += 80.0f) {
drawRect(frostbite2D::Rect(x, 0.0f, 1.0f, config::kVirtualHeight),
frostbite2D::Color(0.20f, 0.22f, 0.25f, 1.0f));
}
for (float y = 0.0f; y <= config::kVirtualHeight; y += 80.0f) {
drawRect(frostbite2D::Rect(level_.collision.levelLeft, y, worldWidth, 1.0f),
frostbite2D::Color(0.20f, 0.22f, 0.25f, 1.0f));
}
for (const auto& prop : level_.props) {
drawRect(prop.bounds, prop.color);
}
for (const auto& platform : level_.collision.platforms) {
drawRect(platform, frostbite2D::Color(0.62f, 0.68f, 0.73f, 1.0f));
drawRect(frostbite2D::Rect(platform.left(), platform.top(), platform.width(), 4.0f),
frostbite2D::Color(0.91f, 0.95f, 0.98f, 1.0f));
}
const frostbite2D::Rect playerBounds =
player_ ? player_->GetWorldBounds() : frostbite2D::Rect::Zero();
debugOverlay_.Render(level_, debugFlags_, player_ ? &playerBounds : nullptr);
}
void WhiteboxScene::updateCamera() {
+6 -1
View File
@@ -1,7 +1,10 @@
#pragma once
#include "../actor/player_actor.h"
#include "../core/debug_flags.h"
#include "../data/level_definition.h"
#include "../debug/debug_overlay.h"
#include "../stage/stage_renderer.h"
#include <frostbite2D/scene/scene.h>
#include <frostbite2D/types/type_math.h>
@@ -15,10 +18,12 @@ public:
void Render() override;
private:
void drawWhitebox() const;
void updateCamera();
LevelDefinition level_;
DebugFlags debugFlags_;
StageRenderer stageRenderer_;
DebugOverlay debugOverlay_;
frostbite2D::Ptr<PlayerActor> player_;
};