Add scene debug layer toggles

This commit is contained in:
2026-06-09 15:25:56 +08:00
parent 0a59d20ffa
commit 3a19005bbf
7 changed files with 51 additions and 22 deletions
@@ -354,9 +354,9 @@ mindmap
下一步:
- `debug/debug_overlay.*` 已经提供碰撞玩家包围盒绘制。
- `F1` 切换 debug overlay。
- 绘制平台碰撞、battle zonecamera lock 和 spawn point。
- `debug/debug_overlay.*` 已经提供碰撞玩家包围盒、battle zone、camera lock 和 spawn point 绘制。
- `F1` 切换 debug overlay 总开关
- `F3-F6` 分别切换碰撞/网格、玩家框、battle zone/cameraspawn point。
- 绘制 hitbox / hurtbox。
- 输出当前场景、角色状态、FPS。
- 增加日志分级和异常状态重置入口。
+11 -1
View File
@@ -28,6 +28,7 @@
- `StageLayerSource` 已接入:`StageRect` 支持色块占位或 sprite 资源路径,资源不存在时回退色块。
- `StageAssetSlots` 已建立:`game/assets/stage/stage_01/` 已预留 background、tiles、props、effects、audio 目录和素材来源记录。
- `StageProps` 已统一:旧 `WhiteboxProp` 已移除,后景/前景 props 都走 `StageLayer`,其中 `props_front` 在角色之后绘制用于遮挡。
- `SceneDebug` 已扩展:`F1` 控制 debug 总开关,`F3-F6` 分别切换碰撞/网格、玩家框、battle zone/camera、spawn point。
## 2. 第一关场景目标
@@ -260,9 +261,18 @@ game/assets/stage/stage_01/
3. 已完成:`StageLayerSource` 扩展 `StageLayer`,让每个 rect 支持色块占位或 sprite 资源路径。
4. 已完成:`StageAssetSlots` 创建并记录 `stage_01` 资源槽位,不要求已有最终素材。
5. 已完成:`StageProps` 把 props 从旧 `WhiteboxProp` 迁移到统一 layer 数据,支持 back/front 两层。
6. `SceneDebug`补齐 F1 debug 总开关,并预留分项开关。
6. 已完成:`SceneDebug` 补齐 F1 debug 总开关,并预留/接入分项开关。
7. `SceneAcceptanceRun`PC 和 Switch 都构建通过,PC 能从起点移动到终点并看到相机推进。
### Debug 快捷键
- `F1`debug overlay 总开关。
- `F2`debug 清当前 battle zone,占位模拟清场解锁。
- `F3`:碰撞矩形和场景网格。
- `F4`:玩家包围盒。
- `F5`battle zone 触发框和 camera bounds。
- `F6`:敌人出生点。
### 素材落位标准
素材准备好后只做这些操作:
+3
View File
@@ -3,11 +3,14 @@
namespace ns_game {
struct DebugFlags {
bool enabled = true;
bool showStageGrid = true;
bool showCollision = true;
bool showActorBounds = true;
bool showBattleZones = true;
bool showSpawnPoints = true;
bool showHitboxes = false;
bool showEnemies = true;
};
} // namespace ns_game
+4
View File
@@ -69,6 +69,10 @@ void DebugOverlay::Render(const LevelDefinition& level, const DebugFlags& flags,
const frostbite2D::Rect* playerBounds,
const std::vector<BattleZoneDebugInfo>*
battleZoneDebug) const {
if (!flags.enabled) {
return;
}
if (flags.showCollision) {
drawCollision(level);
}
+28 -17
View File
@@ -34,14 +34,7 @@ void WhiteboxScene::Update(float deltaTime) {
bool WhiteboxScene::OnEvent(const frostbite2D::Event& event) {
if (event.getType() == frostbite2D::EventType::KeyDown) {
const auto& keyEvent = static_cast<const frostbite2D::KeyEvent&>(event);
if (!keyEvent.isRepeat() &&
keyEvent.getKeyCode() == frostbite2D::KeyCode::F1) {
toggleDebugOverlay();
return true;
}
if (!keyEvent.isRepeat() &&
keyEvent.getKeyCode() == frostbite2D::KeyCode::F2) {
clearActiveBattleZone();
if (!keyEvent.isRepeat() && handleDebugKey(keyEvent.getKeyCode())) {
return true;
}
}
@@ -103,16 +96,34 @@ void WhiteboxScene::configureCamera() {
}
}
bool WhiteboxScene::handleDebugKey(frostbite2D::KeyCode keyCode) {
switch (keyCode) {
case frostbite2D::KeyCode::F1:
toggleDebugOverlay();
return true;
case frostbite2D::KeyCode::F2:
clearActiveBattleZone();
return true;
case frostbite2D::KeyCode::F3:
debugFlags_.showCollision = !debugFlags_.showCollision;
debugFlags_.showStageGrid = debugFlags_.showCollision;
return true;
case frostbite2D::KeyCode::F4:
debugFlags_.showActorBounds = !debugFlags_.showActorBounds;
return true;
case frostbite2D::KeyCode::F5:
debugFlags_.showBattleZones = !debugFlags_.showBattleZones;
return true;
case frostbite2D::KeyCode::F6:
debugFlags_.showSpawnPoints = !debugFlags_.showSpawnPoints;
return true;
default:
return false;
}
}
void WhiteboxScene::toggleDebugOverlay() {
const bool enabled = !(debugFlags_.showStageGrid || debugFlags_.showCollision ||
debugFlags_.showActorBounds ||
debugFlags_.showBattleZones ||
debugFlags_.showSpawnPoints);
debugFlags_.showStageGrid = enabled;
debugFlags_.showCollision = enabled;
debugFlags_.showActorBounds = enabled;
debugFlags_.showBattleZones = enabled;
debugFlags_.showSpawnPoints = enabled;
debugFlags_.enabled = !debugFlags_.enabled;
}
void WhiteboxScene::beginCameraBoundsBlend(
+1
View File
@@ -30,6 +30,7 @@ private:
frostbite2D::Camera* activeCamera() const;
std::vector<BattleZoneDebugInfo> buildBattleZoneDebugInfo() const;
void configureCamera();
bool handleDebugKey(frostbite2D::KeyCode keyCode);
void toggleDebugOverlay();
void beginCameraBoundsBlend(const frostbite2D::Rect& targetBounds);
void clearActiveBattleZone();
+1 -1
View File
@@ -49,7 +49,7 @@ void StageRenderer::Render(const LevelDefinition& level,
}
drawLayer(level, layer);
}
if (debugFlags.showStageGrid) {
if (debugFlags.enabled && debugFlags.showStageGrid) {
drawGrid(level);
}
}