- Agregar zoom dinámico de ventana con F1/F2 - F1: reducir zoom hasta 1x mínimo - F2: aumentar zoom hasta máximo basado en resolución - Centrado inteligente al cambiar zoom - Cálculo correcto de zoom máximo usando SDL_GetCurrentDisplayMode() - F3: toggle fullscreen entre ventana y pantalla completa - Mover temas de colores de F1-F4 a teclado numérico (KP_1-4) - Mejorar resolución base a 640x480 con zoom inicial 2x - Resolver paths absolutos para data/ball.png 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
119 lines
4.2 KiB
C++
119 lines
4.2 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
|
|
#include "ball.h" // for Ball
|
|
#include "external/texture.h" // for 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;
|
|
|
|
// 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;
|
|
|
|
// Sistema de temas
|
|
ColorTheme current_theme_ = ColorTheme::SUNSET;
|
|
|
|
// Estructura de tema de colores
|
|
struct ThemeColors {
|
|
float bg_top_r, bg_top_g, bg_top_b;
|
|
float bg_bottom_r, bg_bottom_g, bg_bottom_b;
|
|
int ball_colors[8][3];
|
|
};
|
|
|
|
// Temas de colores definidos
|
|
ThemeColors themes_[4] = {
|
|
// SUNSET: Naranjas, rojos, amarillos, rosas
|
|
{180.0f / 255.0f, 140.0f / 255.0f, 100.0f / 255.0f, // Fondo superior (naranja suave)
|
|
40.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, // Fondo inferior (púrpura oscuro)
|
|
{{255, 140, 0}, {255, 69, 0}, {255, 215, 0}, {255, 20, 147}, {255, 99, 71}, {255, 165, 0}, {255, 192, 203}, {220, 20, 60}}},
|
|
// OCEAN: Azules, turquesas, blancos
|
|
{100.0f / 255.0f, 150.0f / 255.0f, 200.0f / 255.0f, // Fondo superior (azul cielo)
|
|
20.0f / 255.0f, 40.0f / 255.0f, 80.0f / 255.0f, // Fondo inferior (azul marino)
|
|
{{0, 191, 255}, {0, 255, 255}, {32, 178, 170}, {176, 224, 230}, {70, 130, 180}, {0, 206, 209}, {240, 248, 255}, {64, 224, 208}}},
|
|
// NEON: Cian, magenta, verde lima, amarillo vibrante
|
|
{20.0f / 255.0f, 20.0f / 255.0f, 40.0f / 255.0f, // Fondo superior (negro azulado)
|
|
0.0f / 255.0f, 0.0f / 255.0f, 0.0f / 255.0f, // Fondo inferior (negro)
|
|
{{0, 255, 255}, {255, 0, 255}, {50, 205, 50}, {255, 255, 0}, {255, 20, 147}, {0, 255, 127}, {138, 43, 226}, {255, 69, 0}}},
|
|
// FOREST: Verdes, marrones, amarillos otoño
|
|
{144.0f / 255.0f, 238.0f / 255.0f, 144.0f / 255.0f, // Fondo superior (verde claro)
|
|
101.0f / 255.0f, 67.0f / 255.0f, 33.0f / 255.0f, // Fondo inferior (marrón tierra)
|
|
{{34, 139, 34}, {107, 142, 35}, {154, 205, 50}, {255, 215, 0}, {210, 180, 140}, {160, 82, 45}, {218, 165, 32}, {50, 205, 50}}}
|
|
};
|
|
|
|
// 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();
|
|
void toggleFullscreen();
|
|
std::string gravityDirectionToString(GravityDirection direction) const;
|
|
|
|
// 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);
|
|
}; |