refactor(bloques2-5): auditoria de codi - limpieza i arquitectura
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>
This commit is contained in:
@@ -10,14 +10,13 @@
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "app_logo.hpp" // for AppLogo
|
||||
#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/shape.hpp" // for Shape (interfaz polimórfica)
|
||||
#include "shapes_mgr/shape_manager.hpp" // for ShapeManager
|
||||
#include "state/state_manager.hpp" // for StateManager
|
||||
#include "theme_manager.hpp" // for ThemeManager
|
||||
@@ -93,17 +92,11 @@ class Engine {
|
||||
void toggleDemoLiteMode();
|
||||
void toggleLogoMode();
|
||||
|
||||
// === Métodos públicos para StateManager (callbacks) ===
|
||||
// NOTA: StateManager coordina estados, Engine proporciona implementación
|
||||
// Estos callbacks permiten que StateManager ejecute acciones complejas que
|
||||
// requieren acceso a múltiples componentes (SceneManager, ThemeManager, ShapeManager, etc.)
|
||||
// Este enfoque es pragmático y mantiene la separación de responsabilidades limpia
|
||||
void performLogoAction(bool logo_waiting_for_flip);
|
||||
void executeDemoAction(bool is_lite);
|
||||
void executeRandomizeOnDemoStart(bool is_lite);
|
||||
void executeToggleGravityOnOff();
|
||||
void executeEnterLogoMode(size_t ball_count);
|
||||
void executeExitLogoMode();
|
||||
// === 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_; }
|
||||
@@ -119,6 +112,7 @@ class Engine {
|
||||
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) ===
|
||||
@@ -172,22 +166,13 @@ class Engine {
|
||||
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: Engine mantiene implementación de figuras usada por callbacks DEMO/LOGO
|
||||
// ShapeManager tiene implementación paralela para controles manuales del usuario
|
||||
// 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;
|
||||
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: Engine mantiene estado de implementación para callbacks performLogoAction()
|
||||
// StateManager coordina los triggers y timers, Engine ejecuta las acciones
|
||||
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)
|
||||
int max_auto_scenario_ = 5; // Índice máximo en modos auto (default conservador: 5000 bolas)
|
||||
// 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;
|
||||
@@ -195,30 +180,6 @@ class Engine {
|
||||
bool custom_auto_available_ = false;
|
||||
bool skip_benchmark_ = false;
|
||||
|
||||
// Sistema de convergencia para LOGO MODE (escala con resolución)
|
||||
// Usado por performLogoAction() para detectar cuando las bolas forman el 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)
|
||||
// Permite que LOGO espere a que ocurran rotaciones antes de cambiar estado
|
||||
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
|
||||
|
||||
// NOTA: logo_entered_manually_ fue eliminado de Engine (duplicado)
|
||||
// Ahora se obtiene de StateManager con state_manager_->getLogoEnteredManually()
|
||||
// Esto evita desincronización entre Engine y StateManager
|
||||
|
||||
// Estado previo antes de entrar a Logo Mode (para restaurar al salir)
|
||||
// Guardado por executeEnterLogoMode(), restaurado por executeExitLogoMode()
|
||||
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_;
|
||||
@@ -255,12 +216,9 @@ class Engine {
|
||||
// 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
|
||||
// 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()
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user