refactor(#28): DebugOverlay rep Config::RenderingConfig per referència
Pas 2/N del hallazgo #28. DebugOverlay deixa d'incloure game/options.hpp i passa a rebre un const Config::RenderingConfig& en el seu constructor. El Director li passa Options::rendering (que ja és un alias d'engine_config.rendering). Eliminat: include "game/options.hpp" des de core/system/debug_overlay.cpp. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -5,28 +5,28 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "core/types.hpp"
|
#include "core/types.hpp"
|
||||||
#include "game/options.hpp"
|
|
||||||
|
|
||||||
namespace System {
|
namespace System {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
// Posición y tamaño del overlay en coordenadas lógicas (1280×720).
|
// Posición y tamaño del overlay en coordenadas lógicas (1280×720).
|
||||||
constexpr float OVERLAY_X = 12.0F;
|
constexpr float OVERLAY_X = 12.0F;
|
||||||
constexpr float OVERLAY_Y_FPS = 12.0F;
|
constexpr float OVERLAY_Y_FPS = 12.0F;
|
||||||
constexpr float OVERLAY_LINE_HEIGHT = 18.0F; // separación entre líneas (scale 0.4 → ~16 px alto)
|
constexpr float OVERLAY_LINE_HEIGHT = 18.0F; // separación entre líneas (scale 0.4 → ~16 px alto)
|
||||||
constexpr float OVERLAY_SCALE = 0.4F;
|
constexpr float OVERLAY_SCALE = 0.4F;
|
||||||
constexpr float OVERLAY_SPACING = 2.0F;
|
constexpr float OVERLAY_SPACING = 2.0F;
|
||||||
constexpr float OVERLAY_BRIGHTNESS = 1.0F;
|
constexpr float OVERLAY_BRIGHTNESS = 1.0F;
|
||||||
|
|
||||||
// Cadencia de actualización del valor de FPS mostrado.
|
// Cadencia de actualización del valor de FPS mostrado.
|
||||||
constexpr float FPS_UPDATE_INTERVAL = 0.5F;
|
constexpr float FPS_UPDATE_INTERVAL = 0.5F;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
DebugOverlay::DebugOverlay(Rendering::Renderer* renderer)
|
DebugOverlay::DebugOverlay(Rendering::Renderer* renderer,
|
||||||
: text_(renderer)
|
const Config::RenderingConfig& rendering_cfg)
|
||||||
{}
|
: text_(renderer),
|
||||||
|
rendering_cfg_(&rendering_cfg) {}
|
||||||
|
|
||||||
void DebugOverlay::update(float delta_time) {
|
void DebugOverlay::update(float delta_time) {
|
||||||
fps_accumulator_ += delta_time;
|
fps_accumulator_ += delta_time;
|
||||||
fps_frame_count_++;
|
fps_frame_count_++;
|
||||||
|
|
||||||
@@ -35,23 +35,26 @@ void DebugOverlay::update(float delta_time) {
|
|||||||
fps_frame_count_ = 0;
|
fps_frame_count_ = 0;
|
||||||
fps_accumulator_ = 0.0F;
|
fps_accumulator_ = 0.0F;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugOverlay::draw() const {
|
void DebugOverlay::draw() const {
|
||||||
if (!visible_) {
|
if (!visible_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string FPS_TEXT = "FPS: " + std::to_string(fps_display_);
|
const std::string FPS_TEXT = "FPS: " + std::to_string(fps_display_);
|
||||||
const std::string VSYNC_TEXT = std::string("VSYNC: ")
|
const std::string VSYNC_TEXT = std::string("VSYNC: ") + (rendering_cfg_->vsync == 1 ? "ON" : "OFF");
|
||||||
+ (Options::rendering.vsync == 1 ? "ON" : "OFF");
|
|
||||||
|
|
||||||
text_.render(FPS_TEXT,
|
text_.render(FPS_TEXT,
|
||||||
Vec2{.x = OVERLAY_X, .y = OVERLAY_Y_FPS},
|
Vec2{.x = OVERLAY_X, .y = OVERLAY_Y_FPS},
|
||||||
OVERLAY_SCALE, OVERLAY_SPACING, OVERLAY_BRIGHTNESS);
|
OVERLAY_SCALE,
|
||||||
|
OVERLAY_SPACING,
|
||||||
|
OVERLAY_BRIGHTNESS);
|
||||||
text_.render(VSYNC_TEXT,
|
text_.render(VSYNC_TEXT,
|
||||||
Vec2{.x = OVERLAY_X, .y = OVERLAY_Y_FPS + OVERLAY_LINE_HEIGHT},
|
Vec2{.x = OVERLAY_X, .y = OVERLAY_Y_FPS + OVERLAY_LINE_HEIGHT},
|
||||||
OVERLAY_SCALE, OVERLAY_SPACING, OVERLAY_BRIGHTNESS);
|
OVERLAY_SCALE,
|
||||||
}
|
OVERLAY_SPACING,
|
||||||
|
OVERLAY_BRIGHTNESS);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace System
|
} // namespace System
|
||||||
|
|||||||
@@ -7,14 +7,18 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "core/config/engine_config.hpp"
|
||||||
#include "core/graphics/vector_text.hpp"
|
#include "core/graphics/vector_text.hpp"
|
||||||
#include "core/rendering/render_context.hpp"
|
#include "core/rendering/render_context.hpp"
|
||||||
|
|
||||||
namespace System {
|
namespace System {
|
||||||
|
|
||||||
class DebugOverlay {
|
class DebugOverlay {
|
||||||
public:
|
public:
|
||||||
explicit DebugOverlay(Rendering::Renderer* renderer);
|
// El rendering_cfg ha de viure tant com l'overlay (el posseeix
|
||||||
|
// el Director, que sobreviu a tots els sistemes).
|
||||||
|
DebugOverlay(Rendering::Renderer* renderer,
|
||||||
|
const Config::RenderingConfig& rendering_cfg);
|
||||||
|
|
||||||
// Acumula FPS. Llamar una vez por frame con el delta del Director.
|
// Acumula FPS. Llamar una vez por frame con el delta del Director.
|
||||||
void update(float delta_time);
|
void update(float delta_time);
|
||||||
@@ -27,12 +31,13 @@ class DebugOverlay {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Graphics::VectorText text_;
|
Graphics::VectorText text_;
|
||||||
|
const Config::RenderingConfig* rendering_cfg_;
|
||||||
bool visible_{true};
|
bool visible_{true};
|
||||||
|
|
||||||
// FPS counter — se actualiza cada FPS_UPDATE_INTERVAL segundos.
|
// FPS counter — se actualiza cada FPS_UPDATE_INTERVAL segundos.
|
||||||
float fps_accumulator_{0.0F};
|
float fps_accumulator_{0.0F};
|
||||||
int fps_frame_count_{0};
|
int fps_frame_count_{0};
|
||||||
int fps_display_{0};
|
int fps_display_{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace System
|
} // namespace System
|
||||||
|
|||||||
@@ -258,7 +258,7 @@ auto Director::run() -> int {
|
|||||||
|
|
||||||
// Overlay de debug (FPS + VSync). Vive en el Director porque es global
|
// Overlay de debug (FPS + VSync). Vive en el Director porque es global
|
||||||
// a todas las escenas. Toggle con F11 (visible por defecto en _DEBUG).
|
// a todas las escenas. Toggle con F11 (visible por defecto en _DEBUG).
|
||||||
System::DebugOverlay debug_overlay(sdl.getRenderer());
|
System::DebugOverlay debug_overlay(sdl.getRenderer(), Options::rendering);
|
||||||
|
|
||||||
// Bucle principal: construir escena → frame loop → destruir → siguiente.
|
// Bucle principal: construir escena → frame loop → destruir → siguiente.
|
||||||
while (context.nextScene() != SceneType::EXIT) {
|
while (context.nextScene() != SceneType::EXIT) {
|
||||||
|
|||||||
Reference in New Issue
Block a user