Refactorización inicial: Crear estructura de clase Engine
PROGRESO INTERMEDIO - Estructura base de Engine implementada: Nuevos archivos: - engine.h: Declaración completa de clase Engine con encapsulación - engine.cpp: Esqueleto de implementación con métodos stub - main_new.cpp: Nuevo main simplificado (15 líneas vs 580) Cambios en archivos existentes: - defines.h: Añadir enum ColorTheme (centralizar definiciones) - main.cpp: Eliminar enum ColorTheme duplicado Arquitectura Engine: - Encapsulación completa de variables globales (SDL, estado, timing, UI) - Métodos organizados por responsabilidad (public/private) - Eliminación de problemas de orden de declaración - Base sólida para futuras extensiones Estado: Compilación exitosa ✅ Pendiente: Migrar funcionalidad completa de métodos stub 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
82
source/engine.h
Normal file
82
source/engine.h
Normal file
@@ -0,0 +1,82 @@
|
||||
#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 "defines.h" // for GravityDirection, ColorTheme
|
||||
|
||||
class Ball;
|
||||
class Texture;
|
||||
|
||||
class Engine {
|
||||
public:
|
||||
// Interfaz pública
|
||||
bool initialize();
|
||||
void run();
|
||||
void shutdown();
|
||||
|
||||
private:
|
||||
// Recursos SDL
|
||||
SDL_Window* window_ = nullptr;
|
||||
SDL_Renderer* renderer_ = nullptr;
|
||||
std::shared_ptr<Texture> texture_ = nullptr;
|
||||
|
||||
// Estado del simulador
|
||||
std::vector<std::unique_ptr<Ball>> balls_;
|
||||
std::array<int, 8> test_ = {1, 10, 100, 500, 1000, 10000, 50000, 100000};
|
||||
GravityDirection current_gravity_ = GravityDirection::DOWN;
|
||||
int scenario_ = 0;
|
||||
bool should_exit_ = false;
|
||||
|
||||
// Sistema de timing
|
||||
Uint64 last_frame_time_ = 0;
|
||||
float delta_time_ = 0.0f;
|
||||
|
||||
// UI y debug
|
||||
bool show_debug_ = false;
|
||||
bool show_text_ = true;
|
||||
std::string text_;
|
||||
int text_pos_ = 0;
|
||||
Uint64 text_init_time_ = 0;
|
||||
|
||||
// FPS y V-Sync
|
||||
Uint64 fps_last_time_ = 0;
|
||||
int fps_frame_count_ = 0;
|
||||
int fps_current_ = 0;
|
||||
std::string fps_text_ = "FPS: 0";
|
||||
bool vsync_enabled_ = true;
|
||||
std::string vsync_text_ = "VSYNC ON";
|
||||
|
||||
// Sistema de temas
|
||||
ColorTheme current_theme_ = ColorTheme::SUNSET;
|
||||
|
||||
// Batch rendering
|
||||
std::vector<SDL_Vertex> batch_vertices_;
|
||||
std::vector<int> batch_indices_;
|
||||
|
||||
// Métodos principales del loop
|
||||
void calculateDeltaTime();
|
||||
void update();
|
||||
void handleEvents();
|
||||
void render();
|
||||
|
||||
// Métodos auxiliares
|
||||
void initBalls(int value);
|
||||
void setText();
|
||||
void pushUpBalls();
|
||||
void switchBallsGravity();
|
||||
void changeGravityDirection(GravityDirection direction);
|
||||
void toggleVSync();
|
||||
std::string gravityDirectionToString(GravityDirection direction) const;
|
||||
|
||||
// Rendering
|
||||
void renderGradientBackground();
|
||||
void addSpriteToBatch(float x, float y, float w, float h, int r, int g, int b);
|
||||
};
|
||||
Reference in New Issue
Block a user