Sistema de múltiples texturas: - Carga ball.png (10x10) y ball_small.png (6x6) al inicio - Variable current_ball_size_ obtiene tamaño desde texture->getWidth() - Eliminar constante BALL_SIZE hardcoded Cambio de tamaño con ajuste de posiciones: - updateBallSizes() ajusta pos según gravedad y superficie - DOWN: mueve Y hacia abajo si crece - UP: mueve Y hacia arriba si crece - LEFT/RIGHT: mueve X correspondiente - Solo ajusta pelotas en superficie (isOnSurface()) Ball class actualizada: - Constructor recibe ball_size como parámetro - updateSize(new_size): actualiza hitbox y sprite - setTexture(texture): cambia textura del sprite - setPosition() usa setRotoBallScreenPosition() Sprite class: - Añadido setTexture() inline para hot-swap Tecla N: - Cicla entre texturas disponibles - Actualiza todas las pelotas sin reiniciar física - Texto informativo "SPRITE: NORMAL" / "SPRITE: SMALL" Fix bug initBalls(): - Ahora usa current_ball_size_ en constructor - Pelotas nuevas tienen tamaño correcto según textura activa 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
155 lines
6.0 KiB
C++
155 lines
6.0 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 "defines.h" // for GravityDirection, ColorTheme, ShapeType
|
|
#include "ball.h" // for Ball
|
|
#include "external/texture.h" // for Texture
|
|
#include "shapes/shape.h" // for Shape (interfaz polimórfica)
|
|
|
|
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; // Textura activa actual
|
|
std::vector<std::shared_ptr<Texture>> textures_; // Todas las texturas disponibles
|
|
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
|
|
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;
|
|
|
|
// Sistema de zoom dinámico
|
|
int current_window_zoom_ = WINDOW_ZOOM;
|
|
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";
|
|
bool fullscreen_enabled_ = false;
|
|
bool real_fullscreen_enabled_ = false;
|
|
|
|
// Auto-restart system
|
|
Uint64 all_balls_stopped_start_time_ = 0; // Momento cuando todas se pararon
|
|
bool all_balls_were_stopped_ = false; // Flag de estado anterior
|
|
static constexpr Uint64 AUTO_RESTART_DELAY = 5000; // 5 segundos en ms
|
|
|
|
// Resolución dinámica para modo real fullscreen
|
|
int current_screen_width_ = SCREEN_WIDTH;
|
|
int current_screen_height_ = SCREEN_HEIGHT;
|
|
|
|
// Sistema de temas
|
|
ColorTheme current_theme_ = ColorTheme::SUNSET;
|
|
ColorTheme target_theme_ = ColorTheme::SUNSET; // Tema destino para transición
|
|
bool transitioning_ = false; // ¿Estamos en transición?
|
|
float transition_progress_ = 0.0f; // Progreso de 0.0 a 1.0
|
|
float transition_duration_ = 0.5f; // Duración en segundos
|
|
|
|
// Estructura de tema de colores
|
|
struct ThemeColors {
|
|
const char* name_en; // Nombre en inglés (para debug)
|
|
const char* name_es; // Nombre en español (para display)
|
|
int text_color_r, text_color_g, text_color_b; // Color del texto del tema
|
|
float bg_top_r, bg_top_g, bg_top_b;
|
|
float bg_bottom_r, bg_bottom_g, bg_bottom_b;
|
|
std::vector<Color> ball_colors;
|
|
};
|
|
|
|
// Temas de colores definidos
|
|
ThemeColors themes_[6]; // 6 temas: SUNSET, OCEAN, NEON, FOREST, RGB, MONOCHROME
|
|
|
|
// Sistema de Figuras 3D (polimórfico)
|
|
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
|
|
|
|
// 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 pushBallsAwayFromGravity();
|
|
void switchBallsGravity();
|
|
void enableBallsGravityIfDisabled();
|
|
void forceBallsGravityOn();
|
|
void forceBallsGravityOff();
|
|
void changeGravityDirection(GravityDirection direction);
|
|
void toggleVSync();
|
|
void toggleFullscreen();
|
|
void toggleRealFullscreen();
|
|
std::string gravityDirectionToString(GravityDirection direction) const;
|
|
void initializeThemes();
|
|
void checkAutoRestart();
|
|
void performRandomRestart();
|
|
|
|
// Sistema de transiciones LERP
|
|
float lerp(float a, float b, float t) const { return a + (b - a) * t; }
|
|
Color getInterpolatedColor(size_t ball_index) const; // Obtener color interpolado durante transición
|
|
void startThemeTransition(ColorTheme new_theme);
|
|
|
|
// Sistema de cambio de sprites dinámico
|
|
void switchTexture(); // Cambia a siguiente textura disponible
|
|
void updateBallSizes(int old_size, int new_size); // Ajusta posiciones al cambiar tamaño
|
|
|
|
// Sistema de zoom dinámico
|
|
int calculateMaxWindowZoom() const;
|
|
void setWindowZoom(int new_zoom);
|
|
void zoomIn();
|
|
void zoomOut();
|
|
|
|
// Rendering
|
|
void renderGradientBackground();
|
|
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
|
|
};
|