Refactor fase 1: Extraer InputHandler de Engine
Aplicación del Principio de Responsabilidad Única (SRP) - Fase 1/6
## Cambios realizados
### Nuevos archivos
- source/input/input_handler.h - Declaración clase InputHandler
- source/input/input_handler.cpp - Procesamiento eventos SDL (~180 líneas)
- REFACTOR_PLAN.md - Documento de seguimiento del refactor
### Modificaciones en Engine
- **engine.h**: Agregados 24 métodos públicos para InputHandler
- **engine.cpp**:
- Eliminado handleEvents() (420 líneas)
- Implementados métodos públicos wrapper (~180 líneas)
- Renombrados métodos internos con sufijo `Internal`:
* toggleShapeMode → toggleShapeModeInternal
* activateShape → activateShapeInternal
* switchTexture → switchTextureInternal
- Bucle run() simplificado (5 → 12 líneas)
### Actualización build
- CMakeLists.txt: Agregado source/input/*.cpp a archivos fuente
## Impacto
- **Líneas extraídas**: ~430 del switch gigante de handleEvents()
- **Compilación**: ✅ Exitosa sin errores
- **Funcionalidad**: ✅ 100% preservada
## Beneficios
- ✅ Engine desacoplado de eventos SDL
- ✅ InputHandler stateless (fácilmente testeable)
- ✅ Clara separación detección input vs ejecución lógica
- ✅ Preparado para testing unitario de inputs
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#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 "shapes/shape.h" // for Shape (interfaz polimórfica)
|
||||
#include "text/textrenderer.h" // for TextRenderer
|
||||
#include "theme_manager.h" // for ThemeManager
|
||||
@@ -28,12 +29,57 @@ enum class AppMode {
|
||||
|
||||
class Engine {
|
||||
public:
|
||||
// Interfaz pública
|
||||
// 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
|
||||
|
||||
// Recursos SDL
|
||||
SDL_Window* window_ = nullptr;
|
||||
SDL_Renderer* renderer_ = nullptr;
|
||||
@@ -140,23 +186,17 @@ class Engine {
|
||||
// Métodos principales del loop
|
||||
void calculateDeltaTime();
|
||||
void update();
|
||||
void handleEvents();
|
||||
void render();
|
||||
|
||||
// Métodos auxiliares
|
||||
// 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 pushBallsAwayFromGravity();
|
||||
void switchBallsGravity();
|
||||
void enableBallsGravityIfDisabled();
|
||||
void forceBallsGravityOn();
|
||||
void forceBallsGravityOff();
|
||||
void changeGravityDirection(GravityDirection direction);
|
||||
void toggleVSync();
|
||||
void toggleFullscreen();
|
||||
void toggleRealFullscreen();
|
||||
void toggleIntegerScaling();
|
||||
std::string gravityDirectionToString(GravityDirection direction) const;
|
||||
|
||||
// Sistema de gestión de estados (MANUAL/DEMO/DEMO_LITE/LOGO)
|
||||
@@ -168,16 +208,15 @@ class Engine {
|
||||
void randomizeOnDemoStart(bool is_lite);
|
||||
void toggleGravityOnOff();
|
||||
|
||||
// Sistema de Modo Logo (easter egg)
|
||||
void toggleLogoMode(); // Activar/desactivar modo logo manual (tecla K)
|
||||
// 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
|
||||
void switchTexture(bool show_notification = true); // Cambia a siguiente textura disponible
|
||||
void updateBallSizes(int old_size, int new_size); // Ajusta posiciones al cambiar tamaño
|
||||
// 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
|
||||
// Sistema de zoom dinámico - Métodos privados
|
||||
int calculateMaxWindowZoom() const;
|
||||
void setWindowZoom(int new_zoom);
|
||||
void zoomIn();
|
||||
@@ -187,10 +226,10 @@ 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
|
||||
void toggleShapeMode(bool force_gravity_on_exit = true); // Toggle PHYSICS ↔ última figura (tecla F)
|
||||
void activateShape(ShapeType type); // Activar figura específica (teclas Q/W/E/R/Y/U/I)
|
||||
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
|
||||
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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user