Files
vibe4_shaders/source/engine.h
Sergio Valor 6a84234265 Implementar arquitectura multi-backend para vibe4_shaders
- Actualizar proyecto de vibe3_physics a vibe4_shaders
- Crear sistema modular de renderizado con RendererInterface
- Añadir WindowManager para gestión de ventana y backends
- Implementar backends: SDL (fallback), Vulkan, Metal
- Añadir soporte para efectos CRT en software
- Migrar sistema de renderizado a batch processing
- Actualizar README con nueva arquitectura

NOTA: Funcionalidad básica necesita restauración (texto y texturas)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-27 23:07:48 +02:00

124 lines
3.6 KiB
C++

#pragma once
#include <SDL3/SDL_events.h> // for SDL_Event
#include <SDL3/SDL_stdinc.h> // for Uint64
#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 "window_manager.h" // for WindowManager
#include "backends/renderer_interface.h" // for CRTParams, SpriteData
class Engine {
public:
// Interfaz pública
bool initialize();
void run();
void shutdown();
private:
// Sistema de renderizado
std::unique_ptr<vibe4::WindowManager> window_manager_;
void* texture_data_ = nullptr; // Datos de textura para sprites
// 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;
// Control de efectos CRT
vibe4::CRTParams crt_params_;
bool crt_effects_enabled_ = 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";
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;
// 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;
std::vector<Color> ball_colors;
};
// Temas de colores definidos
ThemeColors themes_[5];
// Batch rendering
std::vector<vibe4::SpriteData> sprite_batch_;
// 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 changeGravityDirection(GravityDirection direction);
void toggleVSync();
void toggleFullscreen();
void toggleRealFullscreen();
std::string gravityDirectionToString(GravityDirection direction) const;
void initializeThemes();
void checkAutoRestart();
void performRandomRestart();
// Sistema de zoom dinámico
void zoomIn();
void zoomOut();
// Control de efectos CRT
void toggleCRTEffects();
void adjustScanlineIntensity(float delta);
void adjustCurvature(float delta);
void adjustBloom(float delta);
// Rendering
void renderGradientBackground();
void addSpriteToBatch(float x, float y, float w, float h, int r, int g, int b);
void clearSpriteBatch();
void renderSpriteBatch();
// Control de backend
void switchRenderingBackend();
std::string getBackendInfo() const;
};