Refactor fase 2: Extraer SceneManager de Engine
Migra toda la lógica de gestión de bolas y física a SceneManager siguiendo el principio de Single Responsibility (SRP). ## Archivos Nuevos **source/scene/scene_manager.h:** - Declaración de clase SceneManager - Gestión de bolas (creación, destrucción, actualización) - Control de gravedad direccional y estado - Métodos de acceso: getBalls(), getBallsMutable(), getFirstBall() - Constructor: SceneManager(screen_width, screen_height) **source/scene/scene_manager.cpp:** - Implementación de lógica de escena (~200 líneas) - changeScenario(): Crea N bolas según escenario - pushBallsAwayFromGravity(): Impulso direccional - switchBallsGravity(), forceBallsGravityOn/Off() - changeGravityDirection(): Cambio de dirección física - updateBallTexture(): Actualiza textura y tamaño - updateScreenSize(): Ajusta resolución de pantalla - updateBallSizes(): Reescala pelotas desde centro ## Archivos Modificados **source/engine.h:** - Agregado: #include "scene/scene_manager.h" - Agregado: std::unique_ptr<SceneManager> scene_manager_ - Removido: std::vector<std::unique_ptr<Ball>> balls_ - Removido: GravityDirection current_gravity_ - Removido: int scenario_ - Removidos métodos privados: initBalls(), switchBallsGravity(), enableBallsGravityIfDisabled(), forceBallsGravityOn/Off(), changeGravityDirection(), updateBallSizes() **source/engine.cpp:** - initialize(): Crea scene_manager_ con resolución - update(): Delega a scene_manager_->update() - render(): Usa scene_manager_->getBalls() - changeScenario(): Delega a scene_manager_ - pushBallsAwayFromGravity(): Delega a scene_manager_ - handleGravityToggle(): Usa scene_manager_->switchBallsGravity() - handleGravityDirectionChange(): Delega dirección - switchTextureInternal(): Usa updateBallTexture() - toggleShapeModeInternal(): Usa getBallsMutable() - activateShapeInternal(): Usa forceBallsGravityOff() - updateShape(): Usa getBallsMutable() para asignar targets - Debug HUD: Usa getFirstBall() para info - toggleRealFullscreen(): Usa updateScreenSize() + changeScenario() - performDemoAction(): Delega gravedad y escenarios - randomizeOnDemoStart(): Delega changeScenario() - toggleGravityOnOff(): Usa forceBallsGravity*() - enterLogoMode(): Usa getBallCount() y changeScenario() - exitLogoMode(): Usa updateBallTexture() - Removidos ~150 líneas de implementación movidas a SceneManager **CMakeLists.txt:** - Agregado source/scene/*.cpp a file(GLOB SOURCE_FILES ...) ## Resultado - Engine.cpp reducido de 2341 → ~2150 líneas (-191 líneas) - SceneManager: 202 líneas de lógica de física/escena - Separación clara: Engine coordina, SceneManager ejecuta física - 100% funcional: Compila sin errores ni warnings - Preparado para Fase 3 (UIManager) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -11,13 +11,14 @@
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ball.h" // for Ball
|
||||
#include "defines.h" // for GravityDirection, ColorTheme, ShapeType
|
||||
#include "external/texture.h" // for Texture
|
||||
#include "defines.h" // for GravityDirection, ColorTheme, ShapeType
|
||||
#include "external/texture.h" // for Texture
|
||||
#include "input/input_handler.h" // for InputHandler
|
||||
#include "shapes/shape.h" // for Shape (interfaz polimórfica)
|
||||
#include "text/textrenderer.h" // for TextRenderer
|
||||
#include "theme_manager.h" // for ThemeManager
|
||||
#include "ui/notifier.h" // for Notifier
|
||||
#include "scene/scene_manager.h" // for SceneManager
|
||||
#include "shapes/shape.h" // for Shape (interfaz polimórfica)
|
||||
#include "text/textrenderer.h" // for TextRenderer
|
||||
#include "theme_manager.h" // for ThemeManager
|
||||
#include "ui/notifier.h" // for Notifier
|
||||
|
||||
// Modos de aplicación mutuamente excluyentes
|
||||
enum class AppMode {
|
||||
@@ -79,6 +80,7 @@ class Engine {
|
||||
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
|
||||
|
||||
// Recursos SDL
|
||||
SDL_Window* window_ = nullptr;
|
||||
@@ -90,9 +92,6 @@ class Engine {
|
||||
int current_ball_size_ = 10; // Tamaño actual de pelotas (dinámico, se actualiza desde texture)
|
||||
|
||||
// Estado del simulador
|
||||
std::vector<std::unique_ptr<Ball>> balls_;
|
||||
GravityDirection current_gravity_ = GravityDirection::DOWN;
|
||||
int scenario_ = 0;
|
||||
bool should_exit_ = false;
|
||||
|
||||
// Sistema de timing
|
||||
@@ -189,14 +188,8 @@ class Engine {
|
||||
void render();
|
||||
|
||||
// Métodos auxiliares privados (llamados por la interfaz pública)
|
||||
void initBalls(int value);
|
||||
void setText(); // DEPRECATED - usar showNotificationForAction() en su lugar
|
||||
void showNotificationForAction(const std::string& text); // Mostrar notificación solo en modo MANUAL
|
||||
void switchBallsGravity();
|
||||
void enableBallsGravityIfDisabled();
|
||||
void forceBallsGravityOn();
|
||||
void forceBallsGravityOff();
|
||||
void changeGravityDirection(GravityDirection direction);
|
||||
std::string gravityDirectionToString(GravityDirection direction) const;
|
||||
|
||||
// Sistema de gestión de estados (MANUAL/DEMO/DEMO_LITE/LOGO)
|
||||
@@ -214,7 +207,6 @@ class Engine {
|
||||
|
||||
// Sistema de cambio de sprites dinámico - Métodos privados
|
||||
void switchTextureInternal(bool show_notification); // Implementación interna del cambio de textura
|
||||
void updateBallSizes(int old_size, int new_size); // Ajusta posiciones al cambiar tamaño
|
||||
|
||||
// Sistema de zoom dinámico - Métodos privados
|
||||
int calculateMaxWindowZoom() const;
|
||||
|
||||
Reference in New Issue
Block a user