ENFOQUE PRAGMÁTICO: - ShapeManager creado e implementado completamente - Código DUPLICADO entre Engine y ShapeManager temporalmente - Engine mantiene implementación para DEMO/LOGO (hasta Fase 8) - Compilación exitosa, aplicación funcional ARCHIVOS CREADOS/MODIFICADOS: 1. shape_manager.h: - Interfaz completa de ShapeManager - Métodos públicos para control de figuras 3D - Referencias a Scene/UI/StateManager 2. shape_manager.cpp: - Implementación completa de todos los métodos - toggleShapeMode(), activateShape(), update(), generateShape() - Sistema de atracción física con spring forces - Cálculo de convergencia para LOGO MODE - Includes de todas las Shape classes 3. engine.h: - Variables de figuras 3D MANTENIDAS (duplicadas con ShapeManager) - Comentarios documentando duplicación temporal - TODO markers para Fase 8 4. engine.cpp: - Inicialización de ShapeManager con dependencias - Métodos de figuras restaurados (no eliminados) - Código DEMO/LOGO funciona con variables locales - Sistema de rendering usa current_mode_ local DUPLICACIÓN TEMPORAL DOCUMENTADA: ```cpp // Engine mantiene: - current_mode_, current_shape_type_, last_shape_type_ - active_shape_, shape_scale_factor_, depth_zoom_enabled_ - shape_convergence_ - toggleShapeModeInternal(), activateShapeInternal() - updateShape(), generateShape(), clampShapeScale() ``` JUSTIFICACIÓN: - Migrar ShapeManager sin migrar DEMO/LOGO causaba conflictos masivos - Enfoque incremental: Fase 7 (ShapeManager) → Fase 8 (DEMO/LOGO) - Permite compilación y testing entre fases - ShapeManager está listo para uso futuro en controles manuales RESULTADO: ✅ Compilación exitosa (1 warning menor) ✅ Aplicación funciona correctamente ✅ Todas las características operativas ✅ ShapeManager completamente implementado ✅ Listo para Fase 8 (migración DEMO/LOGO a StateManager) PRÓXIMOS PASOS (Fase 8): 1. Migrar lógica DEMO/LOGO de Engine a StateManager 2. Convertir métodos de Engine en wrappers a StateManager/ShapeManager 3. Eliminar código duplicado 4. Limpieza final 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
215 lines
10 KiB
C++
215 lines
10 KiB
C++
#pragma once
|
|
|
|
#include <SDL3/SDL_events.h> // for SDL_Event
|
|
#include <SDL3/SDL_render.h> // for SDL_Renderer
|
|
#include <SDL3/SDL_stdinc.h> // for Uint64
|
|
#include <SDL3/SDL_video.h> // for SDL_Window
|
|
|
|
#include <array> // for array
|
|
#include <memory> // for unique_ptr, shared_ptr
|
|
#include <string> // for string
|
|
#include <vector> // for vector
|
|
|
|
#include "ball.h" // for Ball
|
|
#include "defines.h" // for GravityDirection, ColorTheme, ShapeType
|
|
#include "external/texture.h" // for Texture
|
|
#include "input/input_handler.h" // for InputHandler
|
|
#include "scene/scene_manager.h" // for SceneManager
|
|
#include "shapes/shape.h" // for Shape (interfaz polimórfica)
|
|
#include "shapes_mgr/shape_manager.h" // for ShapeManager
|
|
#include "state/state_manager.h" // for StateManager
|
|
#include "theme_manager.h" // for ThemeManager
|
|
#include "ui/ui_manager.h" // for UIManager
|
|
|
|
class Engine {
|
|
public:
|
|
// Interfaz pública principal
|
|
bool initialize(int width = 0, int height = 0, int zoom = 0, bool fullscreen = false);
|
|
void run();
|
|
void shutdown();
|
|
|
|
// === Métodos públicos para InputHandler ===
|
|
|
|
// Gravedad y física
|
|
void pushBallsAwayFromGravity();
|
|
void handleGravityToggle();
|
|
void handleGravityDirectionChange(GravityDirection direction, const char* notification_text);
|
|
|
|
// Display y depuración
|
|
void toggleVSync();
|
|
void toggleDebug();
|
|
|
|
// Figuras 3D
|
|
void toggleShapeMode();
|
|
void activateShape(ShapeType type, const char* notification_text);
|
|
void handleShapeScaleChange(bool increase);
|
|
void resetShapeScale();
|
|
void toggleDepthZoom();
|
|
|
|
// Temas de colores
|
|
void cycleTheme(bool forward);
|
|
void switchThemeByNumpad(int numpad_key);
|
|
void toggleThemePage();
|
|
void pauseDynamicTheme();
|
|
|
|
// Sprites/Texturas
|
|
void switchTexture();
|
|
|
|
// Escenarios (número de pelotas)
|
|
void changeScenario(int scenario_id, const char* notification_text);
|
|
|
|
// Zoom y fullscreen
|
|
void handleZoomIn();
|
|
void handleZoomOut();
|
|
void toggleFullscreen();
|
|
void toggleRealFullscreen();
|
|
void toggleIntegerScaling();
|
|
|
|
// Modos de aplicación (DEMO/LOGO)
|
|
void toggleDemoMode();
|
|
void toggleDemoLiteMode();
|
|
void toggleLogoMode();
|
|
|
|
private:
|
|
// === Componentes del sistema (Composición) ===
|
|
std::unique_ptr<InputHandler> input_handler_; // Manejo de entradas SDL
|
|
std::unique_ptr<SceneManager> scene_manager_; // Gestión de bolas y física
|
|
std::unique_ptr<ShapeManager> shape_manager_; // Gestión de figuras 3D
|
|
std::unique_ptr<StateManager> state_manager_; // Gestión de estados (DEMO/LOGO)
|
|
std::unique_ptr<UIManager> ui_manager_; // Gestión de UI (HUD, FPS, notificaciones)
|
|
|
|
// Recursos SDL
|
|
SDL_Window* window_ = nullptr;
|
|
SDL_Renderer* renderer_ = nullptr;
|
|
std::shared_ptr<Texture> texture_ = nullptr; // Textura activa actual
|
|
std::vector<std::shared_ptr<Texture>> textures_; // Todas las texturas disponibles
|
|
std::vector<std::string> texture_names_; // Nombres de texturas (sin extensión)
|
|
size_t current_texture_index_ = 0; // Índice de textura activa
|
|
int current_ball_size_ = 10; // Tamaño actual de pelotas (dinámico, se actualiza desde texture)
|
|
|
|
// Estado del simulador
|
|
bool should_exit_ = false;
|
|
|
|
// Sistema de timing
|
|
Uint64 last_frame_time_ = 0;
|
|
float delta_time_ = 0.0f;
|
|
|
|
// Sistema de zoom dinámico
|
|
int current_window_zoom_ = DEFAULT_WINDOW_ZOOM;
|
|
|
|
// V-Sync
|
|
bool vsync_enabled_ = true;
|
|
bool fullscreen_enabled_ = false;
|
|
bool real_fullscreen_enabled_ = false;
|
|
ScalingMode current_scaling_mode_ = ScalingMode::INTEGER; // Modo de escalado actual (F5)
|
|
|
|
// Resolución base (configurada por CLI o default)
|
|
int base_screen_width_ = DEFAULT_SCREEN_WIDTH;
|
|
int base_screen_height_ = DEFAULT_SCREEN_HEIGHT;
|
|
|
|
// Resolución dinámica actual (cambia en fullscreen real)
|
|
int current_screen_width_ = DEFAULT_SCREEN_WIDTH;
|
|
int current_screen_height_ = DEFAULT_SCREEN_HEIGHT;
|
|
|
|
// Resolución física real de ventana/pantalla (para texto absoluto)
|
|
int physical_window_width_ = DEFAULT_SCREEN_WIDTH;
|
|
int physical_window_height_ = DEFAULT_SCREEN_HEIGHT;
|
|
|
|
// Sistema de temas (delegado a ThemeManager)
|
|
std::unique_ptr<ThemeManager> theme_manager_;
|
|
int theme_page_ = 0; // Página actual de temas (0 o 1) para acceso por Numpad
|
|
|
|
// Sistema de Figuras 3D (polimórfico)
|
|
// NOTA FASE 7: Variables DUPLICADAS temporalmente con ShapeManager
|
|
// ShapeManager es la fuente de verdad, Engine mantiene copias para DEMO/LOGO
|
|
// TODO FASE 8: Eliminar duplicación cuando migremos DEMO/LOGO a StateManager
|
|
SimulationMode current_mode_ = SimulationMode::PHYSICS;
|
|
ShapeType current_shape_type_ = ShapeType::SPHERE; // Tipo de figura actual
|
|
ShapeType last_shape_type_ = ShapeType::SPHERE; // Última figura para toggle F
|
|
std::unique_ptr<Shape> active_shape_; // Puntero polimórfico a figura activa
|
|
float shape_scale_factor_ = 1.0f; // Factor de escala manual (Numpad +/-)
|
|
bool depth_zoom_enabled_ = true; // Zoom por profundidad Z activado
|
|
|
|
// Sistema de Modo DEMO (auto-play) y LOGO
|
|
// NOTA: Estado parcialmente duplicado con StateManager por pragmatismo
|
|
// StateManager mantiene current_app_mode_ (fuente de verdad)
|
|
// Engine mantiene variables de implementación temporalmente
|
|
AppMode previous_app_mode_ = AppMode::SANDBOX; // Modo previo antes de entrar a LOGO (temporal)
|
|
float demo_timer_ = 0.0f; // Contador de tiempo para próxima acción
|
|
float demo_next_action_time_ = 0.0f; // Tiempo aleatorio hasta próxima acción (segundos)
|
|
|
|
// Sistema de convergencia para LOGO MODE (escala con resolución)
|
|
// NOTA FASE 7: shape_convergence_ duplicado con ShapeManager temporalmente
|
|
// TODO FASE 8: Eliminar cuando migremos DEMO/LOGO
|
|
float shape_convergence_ = 0.0f; // % de pelotas cerca del objetivo (0.0-1.0)
|
|
float logo_convergence_threshold_ = 0.90f; // Threshold aleatorio (75-100%)
|
|
float logo_min_time_ = 3.0f; // Tiempo mínimo escalado con resolución
|
|
float logo_max_time_ = 5.0f; // Tiempo máximo escalado (backup)
|
|
|
|
// Sistema de espera de flips en LOGO MODE (camino alternativo)
|
|
bool logo_waiting_for_flip_ = false; // true si eligió el camino "esperar flip"
|
|
int logo_target_flip_number_ = 0; // En qué flip actuar (1, 2 o 3)
|
|
float logo_target_flip_percentage_ = 0.0f; // % de flip a esperar (0.2-0.8)
|
|
int logo_current_flip_count_ = 0; // Flips observados hasta ahora
|
|
|
|
// Control de entrada manual vs automática a LOGO MODE
|
|
bool logo_entered_manually_ = false; // true si se activó con tecla K, false si automático desde DEMO
|
|
|
|
// Estado previo antes de entrar a Logo Mode (para restaurar al salir)
|
|
int logo_previous_theme_ = 0; // Índice de tema (0-9)
|
|
size_t logo_previous_texture_index_ = 0;
|
|
float logo_previous_shape_scale_ = 1.0f;
|
|
|
|
// Batch rendering
|
|
std::vector<SDL_Vertex> batch_vertices_;
|
|
std::vector<int> batch_indices_;
|
|
|
|
// Configuración del sistema de texto (constantes configurables)
|
|
static constexpr const char* TEXT_FONT_PATH = "data/fonts/determination.ttf";
|
|
static constexpr int TEXT_BASE_SIZE = 24; // Tamaño base para 240p
|
|
static constexpr bool TEXT_ANTIALIASING = true; // true = suavizado, false = píxeles nítidos
|
|
|
|
// Métodos principales del loop
|
|
void calculateDeltaTime();
|
|
void update();
|
|
void render();
|
|
|
|
// Métodos auxiliares privados (llamados por la interfaz pública)
|
|
void showNotificationForAction(const std::string& text); // Mostrar notificación solo en modo MANUAL
|
|
|
|
// Sistema de gestión de estados (MANUAL/DEMO/DEMO_LITE/LOGO)
|
|
void setState(AppMode new_mode); // Cambiar modo de aplicación (mutuamente excluyente)
|
|
|
|
// Sistema de Modo DEMO
|
|
void updateDemoMode();
|
|
void performDemoAction(bool is_lite);
|
|
void randomizeOnDemoStart(bool is_lite);
|
|
void toggleGravityOnOff();
|
|
|
|
// Sistema de Modo Logo (easter egg) - Métodos privados
|
|
void enterLogoMode(bool from_demo = false); // Entrar al modo logo (manual o automático)
|
|
void exitLogoMode(bool return_to_demo = false); // Salir del modo logo
|
|
|
|
// Sistema de cambio de sprites dinámico - Métodos privados
|
|
void switchTextureInternal(bool show_notification); // Implementación interna del cambio de textura
|
|
|
|
// Sistema de zoom dinámico - Métodos privados
|
|
int calculateMaxWindowZoom() const;
|
|
void setWindowZoom(int new_zoom);
|
|
void zoomIn();
|
|
void zoomOut();
|
|
void updatePhysicalWindowSize(); // Actualizar tamaño físico real de ventana
|
|
|
|
// Rendering
|
|
void addSpriteToBatch(float x, float y, float w, float h, int r, int g, int b, float scale = 1.0f);
|
|
|
|
// Sistema de Figuras 3D - Métodos privados
|
|
// NOTA FASE 7: Métodos DUPLICADOS con ShapeManager (Engine mantiene implementación para DEMO/LOGO)
|
|
// TODO FASE 8: Convertir en wrappers puros cuando migremos DEMO/LOGO
|
|
void toggleShapeModeInternal(bool force_gravity_on_exit = true); // Implementación interna del toggle
|
|
void activateShapeInternal(ShapeType type); // Implementación interna de activación
|
|
void updateShape(); // Actualizar figura activa
|
|
void generateShape(); // Generar puntos de figura activa
|
|
void clampShapeScale(); // Limitar escala para evitar clipping
|
|
};
|