Refactorizar estilo del proyecto: .h → .hpp, #pragma once, includes desde raíz
Modernizar convenciones de código C++ aplicando las siguientes directivas:
## Cambios principales
**1. Renombrar headers (.h → .hpp)**
- 36 archivos renombrados a extensión .hpp (estándar C++)
- Mantenidos como .h: stb_image.h, stb_image_resize2.h (librerías C externas)
**2. Modernizar include guards (#ifndef → #pragma once)**
- resource_manager.hpp: #ifndef RESOURCE_MANAGER_H → #pragma once
- resource_pack.hpp: #ifndef RESOURCE_PACK_H → #pragma once
- spatial_grid.hpp: #ifndef SPATIAL_GRID_H → #pragma once
**3. Sistema de includes desde raíz del proyecto**
- CMakeLists.txt: añadido include_directories(${CMAKE_SOURCE_DIR}/source)
- Eliminadas rutas relativas (../) en todos los includes
- Includes ahora usan rutas absolutas desde source/
**Antes:**
```cpp
#include "../defines.h"
#include "../text/textrenderer.h"
```
**Ahora:**
```cpp
#include "defines.hpp"
#include "text/textrenderer.hpp"
```
## Archivos afectados
- 1 archivo CMakeLists.txt modificado
- 36 archivos renombrados (.h → .hpp)
- 32 archivos .cpp actualizados (includes)
- 36 archivos .hpp actualizados (includes + guards)
- 1 archivo tools/ actualizado
**Total: 70 archivos modificados**
## Verificación
✅ Proyecto compila sin errores
✅ Todas las rutas de includes correctas
✅ Include guards modernizados
✅ Librerías externas C mantienen extensión .h
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
113
source/theme_manager.hpp
Normal file
113
source/theme_manager.hpp
Normal file
@@ -0,0 +1,113 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory> // for unique_ptr
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ball.hpp" // for Ball class
|
||||
#include "defines.hpp" // for Color, ColorTheme
|
||||
#include "themes/theme.hpp" // for Theme interface
|
||||
#include "themes/theme_snapshot.hpp" // for ThemeSnapshot
|
||||
|
||||
/**
|
||||
* ThemeManager: Gestiona el sistema de temas visuales (unificado, estáticos y dinámicos)
|
||||
*
|
||||
* PHASE 2 - Sistema Unificado:
|
||||
* - Vector unificado de 15 temas (9 estáticos + 6 dinámicos)
|
||||
* - Índices 0-14 mapeados a ColorTheme enum (SUNSET=0, OCEAN=1, ..., VOLCANIC=14)
|
||||
* - API simplificada: switchToTheme(0-14) para cualquier tema
|
||||
* - Sin lógica dual (eliminados if(dynamic_theme_active_) scattered)
|
||||
*
|
||||
* PHASE 3 - LERP Universal:
|
||||
* - Transiciones suaves entre CUALQUIER par de temas (estático↔estático, estático↔dinámico, dinámico↔dinámico)
|
||||
* - Sistema de snapshots: Captura estado del tema origen antes de cambiar
|
||||
* - LERP durante transición: snapshot origen → tema destino
|
||||
* - Duración configurable (THEME_TRANSITION_DURATION = 0.5s por defecto)
|
||||
*
|
||||
* Responsabilidades:
|
||||
* - Mantener 15 temas polimórficos (StaticTheme / DynamicTheme)
|
||||
* - Actualizar animación de tema activo si es dinámico
|
||||
* - Gestionar transiciones LERP suaves entre temas
|
||||
* - Proporcionar colores interpolados para renderizado (con LERP si hay transición activa)
|
||||
*
|
||||
* Uso desde Engine:
|
||||
* - initialize() al inicio
|
||||
* - update(delta_time) cada frame (actualiza tema activo + transición LERP)
|
||||
* - switchToTheme(0-14) para cambiar tema con transición suave (Numpad/Shift+Numpad, Tecla B)
|
||||
* - getInterpolatedColor(index) en render loop (retorna color con LERP si transitioning)
|
||||
*/
|
||||
class ThemeManager {
|
||||
public:
|
||||
// Constructor/Destructor
|
||||
ThemeManager() = default;
|
||||
~ThemeManager() = default;
|
||||
|
||||
// Inicialización
|
||||
void initialize(); // Inicializa 15 temas unificados (9 estáticos + 6 dinámicos)
|
||||
|
||||
// Interfaz unificada (PHASE 2 + PHASE 3)
|
||||
void switchToTheme(int theme_index); // Cambia a tema 0-14 con transición LERP suave (PHASE 3)
|
||||
void update(float delta_time); // Actualiza transición LERP + tema activo si es dinámico
|
||||
void cycleTheme(); // Cicla al siguiente tema (0→1→...→14→0) - Tecla B
|
||||
void cyclePrevTheme(); // Cicla al tema anterior (14→...→1→0) - Shift+B
|
||||
void pauseDynamic(); // Toggle pausa de animación (Shift+D, solo dinámicos)
|
||||
|
||||
// Queries de colores (usado en rendering)
|
||||
Color getInterpolatedColor(size_t ball_index) const; // Obtiene color interpolado para pelota
|
||||
void getBackgroundColors(float& top_r, float& top_g, float& top_b,
|
||||
float& bottom_r, float& bottom_g, float& bottom_b) const; // Obtiene colores de fondo degradado
|
||||
|
||||
// Queries de estado (para debug display y lógica)
|
||||
int getCurrentThemeIndex() const { return current_theme_index_; }
|
||||
bool isCurrentThemeDynamic() const;
|
||||
bool isTransitioning() const { return transitioning_; } // ¿Hay transición LERP activa? (PHASE 3)
|
||||
|
||||
// Obtener información de tema actual para debug display
|
||||
const char* getCurrentThemeNameEN() const;
|
||||
const char* getCurrentThemeNameES() const;
|
||||
void getCurrentThemeTextColor(int& r, int& g, int& b) const;
|
||||
void getCurrentNotificationBackgroundColor(int& r, int& g, int& b) const;
|
||||
|
||||
// Obtener color inicial para nuevas pelotas (usado en initBalls)
|
||||
Color getInitialBallColor(int random_index) const;
|
||||
|
||||
private:
|
||||
// ========================================
|
||||
// DATOS UNIFICADOS (PHASE 2)
|
||||
// ========================================
|
||||
|
||||
// Vector unificado de 15 temas (índices 0-14)
|
||||
// 0-8: Estáticos (SUNSET, OCEAN, NEON, FOREST, RGB, MONOCHROME, LAVENDER, CRIMSON, EMERALD)
|
||||
// 9-14: Dinámicos (SUNRISE, OCEAN_WAVES, NEON_PULSE, FIRE, AURORA, VOLCANIC)
|
||||
std::vector<std::unique_ptr<Theme>> themes_;
|
||||
|
||||
// Índice de tema activo actual (0-14)
|
||||
int current_theme_index_ = 0; // Por defecto SUNSET
|
||||
|
||||
// ========================================
|
||||
// SISTEMA DE TRANSICIÓN LERP (PHASE 3)
|
||||
// ========================================
|
||||
|
||||
// Estado de transición
|
||||
bool transitioning_ = false; // ¿Hay transición LERP activa?
|
||||
float transition_progress_ = 0.0f; // Progreso 0.0-1.0 (0.0 = origen, 1.0 = destino)
|
||||
float transition_duration_ = THEME_TRANSITION_DURATION; // Duración en segundos (configurable en defines.h)
|
||||
|
||||
// Índices de temas involucrados en transición
|
||||
int source_theme_index_ = 0; // Tema origen (del que venimos)
|
||||
int target_theme_index_ = 0; // Tema destino (al que vamos)
|
||||
|
||||
// Snapshot del tema origen (capturado al iniciar transición)
|
||||
std::unique_ptr<ThemeSnapshot> source_snapshot_; // nullptr si no hay transición
|
||||
|
||||
// ========================================
|
||||
// MÉTODOS PRIVADOS
|
||||
// ========================================
|
||||
|
||||
// Inicialización
|
||||
void initializeStaticThemes(); // Crea 9 temas estáticos (índices 0-8)
|
||||
void initializeDynamicThemes(); // Crea 6 temas dinámicos (índices 9-14)
|
||||
|
||||
// Sistema de transición LERP (PHASE 3)
|
||||
std::unique_ptr<ThemeSnapshot> captureCurrentSnapshot() const; // Captura snapshot del tema actual
|
||||
float lerp(float a, float b, float t) const { return a + (b - a) * t; } // Interpolación lineal
|
||||
};
|
||||
Reference in New Issue
Block a user