Mejoras de rendimiento y usabilidad del Help Overlay: 1. Anchura dinámica basada en contenido: - Ya no es siempre cuadrado (box_size_) - Calcula ancho real según texto más largo por columna - Mantiene mínimo del 90% dimensión menor como antes - Nueva función calculateTextDimensions() 2. Render-to-texture caching para optimización: - Renderiza overlay completo a textura una sola vez - Detecta cambios de color con umbral (threshold 5/255) - Soporta temas dinámicos con LERP sin rebuild constante - Regenera solo cuando colores cambian o ventana redimensiona 3. Impacto en performance: - Antes: 1200 FPS → 200 FPS con overlay activo - Después: 1200 FPS → 1000-1200 FPS (casi sin impacto) - Temas estáticos: 1 render total (~∞x más rápido) - Temas dinámicos: regenera cada ~20-30 frames (~25x más rápido) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
88 lines
2.5 KiB
C++
88 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
class ThemeManager;
|
|
class TextRenderer;
|
|
|
|
/**
|
|
* @class HelpOverlay
|
|
* @brief Overlay de ayuda con listado de controles de teclado
|
|
*
|
|
* Muestra un recuadro cuadrado centrado con todas las teclas y sus funciones.
|
|
* Usa los colores del tema actual (como las notificaciones).
|
|
* Toggle on/off con tecla H. La simulación continúa en el fondo.
|
|
*/
|
|
class HelpOverlay {
|
|
public:
|
|
HelpOverlay();
|
|
~HelpOverlay();
|
|
|
|
/**
|
|
* @brief Inicializa el overlay con renderer y theme manager
|
|
*/
|
|
void initialize(SDL_Renderer* renderer, ThemeManager* theme_mgr, int physical_width, int physical_height);
|
|
|
|
/**
|
|
* @brief Renderiza el overlay si está visible
|
|
*/
|
|
void render(SDL_Renderer* renderer);
|
|
|
|
/**
|
|
* @brief Actualiza dimensiones físicas de ventana (zoom, fullscreen, etc.)
|
|
*/
|
|
void updatePhysicalWindowSize(int physical_width, int physical_height);
|
|
|
|
/**
|
|
* @brief Toggle visibilidad del overlay
|
|
*/
|
|
void toggle() { visible_ = !visible_; }
|
|
|
|
/**
|
|
* @brief Consulta si el overlay está visible
|
|
*/
|
|
bool isVisible() const { return visible_; }
|
|
|
|
private:
|
|
SDL_Renderer* renderer_;
|
|
ThemeManager* theme_mgr_;
|
|
TextRenderer* text_renderer_; // Renderer de texto para la ayuda
|
|
int physical_width_;
|
|
int physical_height_;
|
|
bool visible_;
|
|
|
|
// Dimensiones calculadas del recuadro (anchura dinámica según texto, centrado)
|
|
int box_width_;
|
|
int box_height_;
|
|
int box_x_;
|
|
int box_y_;
|
|
|
|
// Sistema de caché para optimización de rendimiento
|
|
SDL_Texture* cached_texture_; // Textura cacheada del overlay completo
|
|
SDL_Color last_category_color_; // Último color de categorías renderizado
|
|
SDL_Color last_content_color_; // Último color de contenido renderizado
|
|
SDL_Color last_bg_color_; // Último color de fondo renderizado
|
|
bool texture_needs_rebuild_; // Flag para forzar regeneración de textura
|
|
|
|
// Calcular dimensiones del texto más largo
|
|
void calculateTextDimensions(int& max_width, int& total_height);
|
|
|
|
// Calcular dimensiones del recuadro según tamaño de ventana y texto
|
|
void calculateBoxDimensions();
|
|
|
|
// Regenerar textura cacheada del overlay
|
|
void rebuildCachedTexture();
|
|
|
|
// Estructura para par tecla-descripción
|
|
struct KeyBinding {
|
|
const char* key;
|
|
const char* description;
|
|
};
|
|
|
|
// Lista de todos los controles (se llena en constructor)
|
|
std::vector<KeyBinding> key_bindings_;
|
|
};
|