Bloque 2: eliminar codi mort comentat (shape_manager, engine)
Bloque 3: Engine shape methods com thin wrappers a ShapeManager;
eliminar estat duplicat de shapes en Engine
Bloque 4: encapsular getBallsMutable() amb helpers a SceneManager
(enableShapeAttractionAll, resetDepthScalesAll)
Bloque 5: StateManager Phase 9 - tota la logica DEMO/LOGO
implementada directament amb refs a SceneManager,
ThemeManager i ShapeManager; eliminar callbacks a Engine.
Acoplament Engine<->StateManager passa a unidireccional.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
225 lines
10 KiB
C++
225 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 "ui/app_logo.hpp" // for AppLogo
|
|
#include "ball.hpp" // for Ball
|
|
#include "boids_mgr/boid_manager.hpp" // for BoidManager
|
|
#include "defines.hpp" // for GravityDirection, ColorTheme, ShapeType
|
|
#include "external/texture.hpp" // for Texture
|
|
#include "input/input_handler.hpp" // for InputHandler
|
|
#include "scene/scene_manager.hpp" // for SceneManager
|
|
#include "shapes_mgr/shape_manager.hpp" // for ShapeManager
|
|
#include "state/state_manager.hpp" // for StateManager
|
|
#include "theme_manager.hpp" // for ThemeManager
|
|
#include "ui/ui_manager.hpp" // for UIManager
|
|
|
|
class Engine {
|
|
public:
|
|
// Interfaz pública principal
|
|
bool initialize(int width = 0, int height = 0, int zoom = 0, bool fullscreen = false, AppMode initial_mode = AppMode::SANDBOX);
|
|
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();
|
|
void toggleHelp();
|
|
|
|
// Figuras 3D
|
|
void toggleShapeMode();
|
|
void activateShape(ShapeType type, const char* notification_text);
|
|
void handleShapeScaleChange(bool increase);
|
|
void resetShapeScale();
|
|
void toggleDepthZoom();
|
|
|
|
// Boids (comportamiento de enjambre)
|
|
void toggleBoidsMode(bool force_gravity_on = true);
|
|
|
|
// 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();
|
|
|
|
// Modo kiosko
|
|
void setKioskMode(bool enabled) { kiosk_mode_ = enabled; }
|
|
bool isKioskMode() const { return kiosk_mode_; }
|
|
|
|
// Escenario custom (tecla 9, --custom-balls)
|
|
void setCustomScenario(int balls);
|
|
bool isCustomScenarioEnabled() const { return custom_scenario_enabled_; }
|
|
bool isCustomAutoAvailable() const { return custom_auto_available_; }
|
|
int getCustomScenarioBalls() const { return custom_scenario_balls_; }
|
|
|
|
// Control manual del benchmark (--skip-benchmark, --max-balls)
|
|
void setSkipBenchmark();
|
|
void setMaxBallsOverride(int n);
|
|
|
|
// Notificaciones (público para InputHandler)
|
|
void showNotificationForAction(const std::string& text);
|
|
|
|
// Modos de aplicación (DEMO/LOGO)
|
|
void toggleDemoMode();
|
|
void toggleDemoLiteMode();
|
|
void toggleLogoMode();
|
|
|
|
// === Métodos públicos para StateManager (automatización DEMO/LOGO sin notificación) ===
|
|
void enterShapeMode(ShapeType type); // Activar figura (sin notificación)
|
|
void exitShapeMode(bool force_gravity = true); // Volver a física (sin notificación)
|
|
void switchTextureSilent(); // Cambiar textura (sin notificación)
|
|
void setTextureByIndex(size_t index); // Restaurar textura específica
|
|
|
|
// === Getters públicos para UIManager (Debug HUD) ===
|
|
bool getVSyncEnabled() const { return vsync_enabled_; }
|
|
bool getFullscreenEnabled() const { return fullscreen_enabled_; }
|
|
bool getRealFullscreenEnabled() const { return real_fullscreen_enabled_; }
|
|
ScalingMode getCurrentScalingMode() const { return current_scaling_mode_; }
|
|
int getCurrentScreenWidth() const { return current_screen_width_; }
|
|
int getCurrentScreenHeight() const { return current_screen_height_; }
|
|
std::string getCurrentTextureName() const {
|
|
if (texture_names_.empty()) return "";
|
|
return texture_names_[current_texture_index_];
|
|
}
|
|
int getBaseScreenWidth() const { return base_screen_width_; }
|
|
int getBaseScreenHeight() const { return base_screen_height_; }
|
|
int getMaxAutoScenario() const { return max_auto_scenario_; }
|
|
size_t getCurrentTextureIndex() const { return current_texture_index_; }
|
|
|
|
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<BoidManager> boid_manager_; // Gestión de comportamiento boids
|
|
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)
|
|
std::unique_ptr<AppLogo> app_logo_; // Gestión de logo periódico en pantalla
|
|
|
|
// 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;
|
|
bool kiosk_mode_ = 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
|
|
|
|
// Modo de simulación actual (PHYSICS/SHAPE/BOIDS) — fuente de verdad para Engine
|
|
// El estado de figuras (active_shape_, scale, etc.) está en ShapeManager
|
|
SimulationMode current_mode_ = SimulationMode::PHYSICS;
|
|
|
|
// Sistema de Modo DEMO (auto-play) y LOGO
|
|
// Toda la lógica DEMO/LOGO y su estado vive en StateManager
|
|
int max_auto_scenario_ = 5; // Índice máximo en modos auto (resultado del benchmark)
|
|
|
|
// Escenario custom (--custom-balls)
|
|
int custom_scenario_balls_ = 0;
|
|
bool custom_scenario_enabled_ = false;
|
|
bool custom_auto_available_ = false;
|
|
bool skip_benchmark_ = false;
|
|
|
|
// Batch rendering
|
|
std::vector<SDL_Vertex> batch_vertices_;
|
|
std::vector<int> batch_indices_;
|
|
|
|
// Bucket sort per z-ordering (SHAPE mode)
|
|
static constexpr int DEPTH_SORT_BUCKETS = 256;
|
|
std::array<std::vector<size_t>, DEPTH_SORT_BUCKETS> depth_buckets_;
|
|
|
|
// 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();
|
|
|
|
// Benchmark de rendimiento (determina max_auto_scenario_ al inicio)
|
|
void runPerformanceBenchmark();
|
|
|
|
// Métodos auxiliares privados (llamados por la interfaz pública)
|
|
|
|
// 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 (thin wrappers a ShapeManager)
|
|
void toggleShapeModeInternal(bool force_gravity_on_exit = true); // Delega a ShapeManager + sincroniza current_mode_
|
|
void activateShapeInternal(ShapeType type); // Delega a ShapeManager + sets current_mode_ = SHAPE
|
|
void updateShape(); // Delega a ShapeManager::update()
|
|
void generateShape(); // Delega a ShapeManager::generateShape()
|
|
};
|