Debug overlay (FPS + VSync) toggleable con F11
Crea core/system/DebugOverlay como sistema global propiedad del Director
que muestra FPS y estado de VSync en la esquina superior izquierda usando
VectorText. Visible por defecto en builds debug, oculto en release; F11
alterna.
Cambios:
- Nuevo DebugOverlay con su propio contador de FPS interno (cadencia 0.5s).
El cálculo que vivía en SDLManager::updateFPS se mueve aquí.
- Director construye el overlay una vez y lo pasa a runFrameLoop. F11 se
intercepta directamente en el event loop del Director (no en
GlobalEvents para no acoplar la firma a la presencia del overlay).
- Limpieza de SDLManager: fuera updateFPS, updateColors (era no-op desde
Fase 8c), setWindowTitle (no se usaba) y los campos fps_*.
- Título de ventana estático estilo CCAE:
© 2026 Orni Attack — JailDesigner
Ya no se reescribe cada 0.5s con FPS y VSync; ese estado vive en el
overlay.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -21,8 +21,10 @@ namespace {
|
|||||||
auto initWindowAndGpu(SDL_Window** out_window,
|
auto initWindowAndGpu(SDL_Window** out_window,
|
||||||
Rendering::Renderer& gpu_renderer,
|
Rendering::Renderer& gpu_renderer,
|
||||||
int width, int height, bool fullscreen) -> bool {
|
int width, int height, bool fullscreen) -> bool {
|
||||||
// Construir título dinámico
|
// Título estático estilo CCAE. El FPS y el estado de VSync los muestra
|
||||||
const std::string TITLE = std::format("{} v{} ({})", Project::LONG_NAME, Project::VERSION, Project::COPYRIGHT);
|
// el DebugOverlay (toggle F11), no la barra de título.
|
||||||
|
const std::string TITLE = std::format("© 2026 {} — JailDesigner",
|
||||||
|
Project::LONG_NAME);
|
||||||
|
|
||||||
SDL_WindowFlags flags = SDL_WINDOW_RESIZABLE;
|
SDL_WindowFlags flags = SDL_WINDOW_RESIZABLE;
|
||||||
if (fullscreen) {
|
if (fullscreen) {
|
||||||
@@ -62,9 +64,6 @@ auto initWindowAndGpu(SDL_Window** out_window,
|
|||||||
|
|
||||||
SDLManager::SDLManager()
|
SDLManager::SDLManager()
|
||||||
: finestra_(nullptr),
|
: finestra_(nullptr),
|
||||||
fps_accumulator_(0.0F),
|
|
||||||
fps_frame_count_(0),
|
|
||||||
fps_display_(0),
|
|
||||||
current_width_(Defaults::Window::WIDTH),
|
current_width_(Defaults::Window::WIDTH),
|
||||||
current_height_(Defaults::Window::HEIGHT),
|
current_height_(Defaults::Window::HEIGHT),
|
||||||
is_fullscreen_(false),
|
is_fullscreen_(false),
|
||||||
@@ -95,9 +94,6 @@ SDLManager::SDLManager()
|
|||||||
|
|
||||||
SDLManager::SDLManager(int width, int height, bool fullscreen)
|
SDLManager::SDLManager(int width, int height, bool fullscreen)
|
||||||
: finestra_(nullptr),
|
: finestra_(nullptr),
|
||||||
fps_accumulator_(0.0F),
|
|
||||||
fps_frame_count_(0),
|
|
||||||
fps_display_(0),
|
|
||||||
current_width_(width),
|
current_width_(width),
|
||||||
current_height_(height),
|
current_height_(height),
|
||||||
is_fullscreen_(fullscreen),
|
is_fullscreen_(fullscreen),
|
||||||
@@ -334,47 +330,8 @@ void SDLManager::present() {
|
|||||||
gpu_renderer_.endFrame();
|
gpu_renderer_.endFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLManager::updateColors(float delta_time) {
|
|
||||||
// No-op desde la migración a postpro. La oscilación de brillo y el pulso
|
|
||||||
// de fondo los aplica shaders/postfx.frag.glsl directamente sobre wall-clock.
|
|
||||||
(void)delta_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDLManager::updateFPS(float delta_time) {
|
|
||||||
fps_accumulator_ += delta_time;
|
|
||||||
fps_frame_count_++;
|
|
||||||
|
|
||||||
if (fps_accumulator_ >= 0.5F) {
|
|
||||||
fps_display_ = static_cast<int>(fps_frame_count_ / fps_accumulator_);
|
|
||||||
fps_frame_count_ = 0;
|
|
||||||
fps_accumulator_ = 0.0F;
|
|
||||||
|
|
||||||
std::string vsync_state = (Options::rendering.vsync == 1) ? "ON" : "OFF";
|
|
||||||
std::string title = std::format("{} v{} ({}) - {} FPS - VSync: {}",
|
|
||||||
Project::LONG_NAME,
|
|
||||||
Project::VERSION,
|
|
||||||
Project::COPYRIGHT,
|
|
||||||
fps_display_,
|
|
||||||
vsync_state);
|
|
||||||
|
|
||||||
if (finestra_ != nullptr) {
|
|
||||||
SDL_SetWindowTitle(finestra_, title.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDLManager::setWindowTitle(const std::string& title) {
|
|
||||||
if (finestra_ != nullptr) {
|
|
||||||
SDL_SetWindowTitle(finestra_, title.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDLManager::toggleVSync() {
|
void SDLManager::toggleVSync() {
|
||||||
Options::rendering.vsync = (Options::rendering.vsync == 1) ? 0 : 1;
|
Options::rendering.vsync = (Options::rendering.vsync == 1) ? 0 : 1;
|
||||||
gpu_renderer_.setVSync(Options::rendering.vsync != 0);
|
gpu_renderer_.setVSync(Options::rendering.vsync != 0);
|
||||||
|
|
||||||
fps_accumulator_ = 0.0F;
|
|
||||||
fps_frame_count_ = 0;
|
|
||||||
|
|
||||||
Options::saveToFile();
|
Options::saveToFile();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "core/rendering/render_context.hpp"
|
#include "core/rendering/render_context.hpp"
|
||||||
|
|
||||||
@@ -36,21 +35,10 @@ class SDLManager {
|
|||||||
void clear(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0);
|
void clear(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0);
|
||||||
void present();
|
void present();
|
||||||
|
|
||||||
// No-op desde la migración a postpro (la oscilación de brillo la
|
|
||||||
// gestiona el shader, no la CPU). Se mantiene la firma para no tocar
|
|
||||||
// los escenarios que la siguen invocando.
|
|
||||||
void updateColors(float delta_time);
|
|
||||||
|
|
||||||
// [NUEVO] Actualitzar counter de FPS
|
|
||||||
void updateFPS(float delta_time);
|
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
auto getRenderer() -> Rendering::Renderer* { return &gpu_renderer_; }
|
auto getRenderer() -> Rendering::Renderer* { return &gpu_renderer_; }
|
||||||
[[nodiscard]] auto getScaleFactor() const -> float { return zoom_factor_; }
|
[[nodiscard]] auto getScaleFactor() const -> float { return zoom_factor_; }
|
||||||
|
|
||||||
// [NUEVO] Actualitzar título de la finestra
|
|
||||||
void setWindowTitle(const std::string& title);
|
|
||||||
|
|
||||||
// [NUEVO] Actualitzar context de renderizado (factor de scale global)
|
// [NUEVO] Actualitzar context de renderizado (factor de scale global)
|
||||||
void updateRenderingContext() const;
|
void updateRenderingContext() const;
|
||||||
|
|
||||||
@@ -58,11 +46,6 @@ class SDLManager {
|
|||||||
SDL_Window* finestra_;
|
SDL_Window* finestra_;
|
||||||
Rendering::Renderer gpu_renderer_; // GpuFrameRenderer (SDL3 GPU)
|
Rendering::Renderer gpu_renderer_; // GpuFrameRenderer (SDL3 GPU)
|
||||||
|
|
||||||
// [NUEVO] Variables FPS
|
|
||||||
float fps_accumulator_;
|
|
||||||
int fps_frame_count_;
|
|
||||||
int fps_display_;
|
|
||||||
|
|
||||||
// [NUEVO] Estat de la finestra
|
// [NUEVO] Estat de la finestra
|
||||||
int current_width_; // Mida física actual
|
int current_width_; // Mida física actual
|
||||||
int current_height_;
|
int current_height_;
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
// debug_overlay.cpp - Implementación del overlay de debug.
|
||||||
|
|
||||||
|
#include "core/system/debug_overlay.hpp"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "core/types.hpp"
|
||||||
|
#include "game/options.hpp"
|
||||||
|
|
||||||
|
namespace System {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
// Posición y tamaño del overlay en coordenadas lógicas (1280×720).
|
||||||
|
constexpr float OVERLAY_X = 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_SCALE = 0.4F;
|
||||||
|
constexpr float OVERLAY_SPACING = 2.0F;
|
||||||
|
constexpr float OVERLAY_BRIGHTNESS = 1.0F;
|
||||||
|
|
||||||
|
// Cadencia de actualización del valor de FPS mostrado.
|
||||||
|
constexpr float FPS_UPDATE_INTERVAL = 0.5F;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
DebugOverlay::DebugOverlay(Rendering::Renderer* renderer)
|
||||||
|
: text_(renderer),
|
||||||
|
#ifdef _DEBUG
|
||||||
|
visible_(true),
|
||||||
|
#else
|
||||||
|
visible_(false),
|
||||||
|
#endif
|
||||||
|
fps_accumulator_(0.0F),
|
||||||
|
fps_frame_count_(0),
|
||||||
|
fps_display_(0) {}
|
||||||
|
|
||||||
|
void DebugOverlay::update(float delta_time) {
|
||||||
|
fps_accumulator_ += delta_time;
|
||||||
|
fps_frame_count_++;
|
||||||
|
|
||||||
|
if (fps_accumulator_ >= FPS_UPDATE_INTERVAL) {
|
||||||
|
fps_display_ = static_cast<int>(fps_frame_count_ / fps_accumulator_);
|
||||||
|
fps_frame_count_ = 0;
|
||||||
|
fps_accumulator_ = 0.0F;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DebugOverlay::draw() const {
|
||||||
|
if (!visible_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string FPS_TEXT = "FPS: " + std::to_string(fps_display_);
|
||||||
|
const std::string VSYNC_TEXT = std::string("VSYNC: ")
|
||||||
|
+ (Options::rendering.vsync == 1 ? "ON" : "OFF");
|
||||||
|
|
||||||
|
text_.render(FPS_TEXT,
|
||||||
|
Vec2{.x = OVERLAY_X, .y = OVERLAY_Y_FPS},
|
||||||
|
OVERLAY_SCALE, OVERLAY_SPACING, OVERLAY_BRIGHTNESS);
|
||||||
|
text_.render(VSYNC_TEXT,
|
||||||
|
Vec2{.x = OVERLAY_X, .y = OVERLAY_Y_FPS + OVERLAY_LINE_HEIGHT},
|
||||||
|
OVERLAY_SCALE, OVERLAY_SPACING, OVERLAY_BRIGHTNESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace System
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
// debug_overlay.hpp - Overlay de debug (FPS + VSync) toggleable con F11
|
||||||
|
// © 2025 Orni Attack
|
||||||
|
//
|
||||||
|
// Sistema global propiedad del Director. Se actualiza y dibuja cada frame
|
||||||
|
// después de la escena (queda on top). En builds debug arranca visible,
|
||||||
|
// en release oculto. F11 alterna visibilidad.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "core/graphics/vector_text.hpp"
|
||||||
|
#include "core/rendering/render_context.hpp"
|
||||||
|
|
||||||
|
namespace System {
|
||||||
|
|
||||||
|
class DebugOverlay {
|
||||||
|
public:
|
||||||
|
explicit DebugOverlay(Rendering::Renderer* renderer);
|
||||||
|
|
||||||
|
// Acumula FPS. Llamar una vez por frame con el delta del Director.
|
||||||
|
void update(float delta_time);
|
||||||
|
|
||||||
|
// Pinta el overlay si está visible. Posición esquina sup-izq.
|
||||||
|
void draw() const;
|
||||||
|
|
||||||
|
void toggle() { visible_ = !visible_; }
|
||||||
|
[[nodiscard]] auto isVisible() const -> bool { return visible_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Graphics::VectorText text_;
|
||||||
|
bool visible_;
|
||||||
|
|
||||||
|
// FPS counter — se actualiza cada FPS_UPDATE_INTERVAL segundos.
|
||||||
|
float fps_accumulator_;
|
||||||
|
int fps_frame_count_;
|
||||||
|
int fps_display_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace System
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "debug_overlay.hpp"
|
||||||
#include "scene.hpp"
|
#include "scene.hpp"
|
||||||
#include "scene_context.hpp"
|
#include "scene_context.hpp"
|
||||||
#include "global_events.hpp"
|
#include "global_events.hpp"
|
||||||
@@ -255,6 +256,10 @@ auto Director::run() -> int {
|
|||||||
context.setNextScene(SceneType::LOGO);
|
context.setNextScene(SceneType::LOGO);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Overlay de debug (FPS + VSync). Vive en el Director porque es global
|
||||||
|
// a todas las escenas. Toggle con F11 (visible por defecto en _DEBUG).
|
||||||
|
System::DebugOverlay debug_overlay(sdl.getRenderer());
|
||||||
|
|
||||||
// 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) {
|
||||||
SceneManager::actual = context.nextScene();
|
SceneManager::actual = context.nextScene();
|
||||||
@@ -262,7 +267,7 @@ auto Director::run() -> int {
|
|||||||
if (!scene) {
|
if (!scene) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
runFrameLoop(*scene, sdl, context);
|
runFrameLoop(*scene, sdl, context, debug_overlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
SceneManager::actual = SceneType::EXIT;
|
SceneManager::actual = SceneType::EXIT;
|
||||||
@@ -284,7 +289,8 @@ auto Director::buildScene(SceneType type, SDLManager& sdl, SceneContext& context
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Director::runFrameLoop(Scene& scene, SDLManager& sdl, SceneContext& context) {
|
void Director::runFrameLoop(Scene& scene, SDLManager& sdl, SceneContext& context,
|
||||||
|
System::DebugOverlay& debug_overlay) {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
Uint64 last_time = SDL_GetTicks();
|
Uint64 last_time = SDL_GetTicks();
|
||||||
|
|
||||||
@@ -295,11 +301,11 @@ void Director::runFrameLoop(Scene& scene, SDLManager& sdl, SceneContext& context
|
|||||||
last_time = NOW;
|
last_time = NOW;
|
||||||
delta_time = std::min(delta_time, 0.05F);
|
delta_time = std::min(delta_time, 0.05F);
|
||||||
|
|
||||||
sdl.updateFPS(delta_time);
|
|
||||||
Mouse::updateCursorVisibility();
|
Mouse::updateCursorVisibility();
|
||||||
Input::get()->update();
|
Input::get()->update();
|
||||||
|
|
||||||
// Event loop: primero ventana, después globales, después escena.
|
// Event loop: primero ventana, después globales, después F11
|
||||||
|
// (toggle del overlay), después escena.
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
if (sdl.handleWindowEvent(event)) {
|
if (sdl.handleWindowEvent(event)) {
|
||||||
continue;
|
continue;
|
||||||
@@ -307,17 +313,22 @@ void Director::runFrameLoop(Scene& scene, SDLManager& sdl, SceneContext& context
|
|||||||
if (GlobalEvents::handle(event, sdl, context)) {
|
if (GlobalEvents::handle(event, sdl, context)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (event.type == SDL_EVENT_KEY_DOWN
|
||||||
|
&& event.key.scancode == SDL_SCANCODE_F11) {
|
||||||
|
debug_overlay.toggle();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
scene.handleEvent(event);
|
scene.handleEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
scene.update(delta_time);
|
scene.update(delta_time);
|
||||||
|
debug_overlay.update(delta_time);
|
||||||
Audio::update();
|
Audio::update();
|
||||||
sdl.updateColors(delta_time); // no-op desde Fase 8c (oscilación en shader)
|
|
||||||
|
|
||||||
sdl.clear(0, 0, 0);
|
sdl.clear(0, 0, 0);
|
||||||
sdl.updateRenderingContext();
|
sdl.updateRenderingContext();
|
||||||
scene.draw();
|
scene.draw();
|
||||||
// Hook futuro: overlays globales aquí (FPS+VSync, profilers...).
|
debug_overlay.draw(); // siempre on top de la escena
|
||||||
sdl.present();
|
sdl.present();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
class Scene;
|
class Scene;
|
||||||
class SDLManager;
|
class SDLManager;
|
||||||
|
namespace System { class DebugOverlay; }
|
||||||
|
|
||||||
class Director {
|
class Director {
|
||||||
public:
|
public:
|
||||||
@@ -33,6 +34,8 @@ class Director {
|
|||||||
|
|
||||||
// Ejecuta el bucle de frames de UNA escena hasta que scene.isFinished()
|
// Ejecuta el bucle de frames de UNA escena hasta que scene.isFinished()
|
||||||
// sea true. Maneja delta_time, eventos (globales + escena), update y draw.
|
// sea true. Maneja delta_time, eventos (globales + escena), update y draw.
|
||||||
|
// El debug_overlay es global a todas las escenas; el Director lo posee.
|
||||||
static void runFrameLoop(Scene& scene, SDLManager& sdl,
|
static void runFrameLoop(Scene& scene, SDLManager& sdl,
|
||||||
SceneManager::SceneContext& context);
|
SceneManager::SceneContext& context,
|
||||||
|
System::DebugOverlay& debug_overlay);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user