diff --git a/source/core/rendering/screen.hpp b/source/core/rendering/screen.hpp index 9441697f..8f5c5d84 100644 --- a/source/core/rendering/screen.hpp +++ b/source/core/rendering/screen.hpp @@ -21,8 +21,50 @@ enum class ScreenFilter : Uint32 { }; class Screen { + public: + // [SINGLETON] Crearemos el objeto con esta función estática + static void init(); + + // [SINGLETON] Destruiremos el objeto con esta función estática + static void destroy(); + + // [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él + static auto get() -> Screen*; + + void clearRenderer(Color color = {0x00, 0x00, 0x00}); // Limpia el renderer + void clearSurface(Uint8 index); // Limpia la game_surface_ + void start(); // Prepara para empezar a dibujar en la textura de juego + void render(); // Vuelca el contenido del renderizador en pantalla + void update(float delta_time); // Actualiza la lógica de la clase + void setVideoMode(bool mode); // Establece el modo de video + void toggleVideoMode(); // Camibia entre pantalla completa y ventana + void toggleIntegerScale(); // Alterna entre activar y desactivar el escalado entero + void toggleVSync(); // Alterna entre activar y desactivar el V-Sync + auto decWindowZoom() -> bool; // Reduce el tamaño de la ventana + auto incWindowZoom() -> bool; // Aumenta el tamaño de la ventana + void setBorderColor(Uint8 color); // Cambia el color del borde + static void setBorderWidth(int width); // Establece el tamaño del borde + static void setBorderHeight(int height); // Establece el tamaño del borde + static void setBorderEnabled(bool value); // Establece si se ha de ver el borde en el modo ventana + void toggleBorder(); // Cambia entre borde visible y no visible + void toggleShaders(); // Cambia el estado de los shaders + void show(); // Muestra la ventana + void hide(); // Oculta la ventana + void setRendererSurface(const std::shared_ptr& surface = nullptr); // Establece el renderizador para las surfaces + void nextPalette(); // Cambia la paleta + void previousPalette(); // Cambia la paleta + void setPalete(); // Establece la paleta + void setNotificationsEnabled(bool value); // Establece la visibilidad de las notificaciones + void toggleDebugInfo(); // Activa o desactiva la información de debug + + // --- Getters --- + auto getRenderer() -> SDL_Renderer*; + auto getRendererSurface() -> std::shared_ptr; + auto getBorderSurface() -> std::shared_ptr; + [[nodiscard]] auto getText() const -> std::shared_ptr { return text_; } + private: - // Constantes + // --- Constantes --- static constexpr int WINDOWS_DECORATIONS = 35; // Decoraciones de la ventana struct DisplayMonitor { @@ -38,9 +80,7 @@ class Screen { int last_value{0}; // Número de frames calculado en el último segundo. // Constructor para inicializar la estructura. - FPS() - - = default; + FPS() = default; // Incrementador que se llama en cada frame. void increment() { @@ -62,7 +102,7 @@ class Screen { // [SINGLETON] Objeto privado static Screen* screen; - // Objetos y punteros + // --- Objetos y punteros --- SDL_Window* window_; // Ventana de la aplicación SDL_Renderer* renderer_; // El renderizador de la ventana SDL_Texture* game_texture_; // Textura donde se dibuja el juego @@ -73,7 +113,7 @@ class Screen { std::unique_ptr shader_backend_; // Backend de shaders (OpenGL/Metal/Vulkan) std::shared_ptr text_; // Objeto para escribir texto en pantalla de carga - // Variables + // --- Variables --- int window_width_; // Ancho de la pantalla o ventana int window_height_; // Alto de la pantalla o ventana SDL_FRect game_surface_dstrect_; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana @@ -92,130 +132,25 @@ class Screen { #else bool show_debug_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla #endif - - // Dibuja las notificaciones - void renderNotifications() const; - - // Calcula el tamaño de la ventana - void adjustWindowSize(); - - // Ajusta el tamaño lógico del renderizador - void adjustRenderLogicalSize(); - - // Extrae los nombres de las paletas - void processPaletteList(); - - // Copia la surface a la textura - void surfaceToTexture(); - - // Copia la textura al renderizador - void textureToRenderer(); - - // Renderiza todos los overlays - void renderOverlays(); - - // Localiza la paleta dentro del vector de paletas - auto findPalette(const std::string& name) -> size_t; - - void initShaders(); // Inicializa los shaders - void loadShaders(); // Carga el contenido del archivo GLSL - void renderInfo(); // Muestra información por pantalla - void getDisplayInfo(); // Obtiene información sobre la pantalla - auto initSDLVideo() -> bool; // Arranca SDL VIDEO y crea la ventana - void createText(); // Crea el objeto de texto + // --- Funciones --- + void renderNotifications() const; // Dibuja las notificaciones + void adjustWindowSize(); // Calcula el tamaño de la ventana + void adjustRenderLogicalSize(); // Ajusta el tamaño lógico del renderizador + void processPaletteList(); // Extrae los nombres de las paletas + void surfaceToTexture(); // Copia la surface a la textura + void textureToRenderer(); // Copia la textura al renderizador + void renderOverlays(); // Renderiza todos los overlays + auto findPalette(const std::string& name) -> size_t; // Localiza la paleta dentro del vector de paletas + void initShaders(); // Inicializa los shaders + void loadShaders(); // Carga el contenido del archivo GLSL + void renderInfo(); // Muestra información por pantalla + void getDisplayInfo(); // Obtiene información sobre la pantalla + auto initSDLVideo() -> bool; // Arranca SDL VIDEO y crea la ventana + void createText(); // Crea el objeto de texto // Constructor Screen(); // Destructor ~Screen(); - - public: - // [SINGLETON] Crearemos el objeto con esta función estática - static void init(); - - // [SINGLETON] Destruiremos el objeto con esta función estática - static void destroy(); - - // [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él - static auto get() -> Screen*; - - // Limpia el renderer - void clearRenderer(Color color = {0x00, 0x00, 0x00}); - - // Limpia la game_surface_ - void clearSurface(Uint8 index); - - // Prepara para empezar a dibujar en la textura de juego - void start(); - - // Vuelca el contenido del renderizador en pantalla - void render(); - - // Actualiza la lógica de la clase - void update(float delta_time); // Para escenas migradas (con delta_time) - - // Establece el modo de video - void setVideoMode(bool mode); - - // Camibia entre pantalla completa y ventana - void toggleVideoMode(); - - // Alterna entre activar y desactivar el escalado entero - void toggleIntegerScale(); - - // Alterna entre activar y desactivar el V-Sync - void toggleVSync(); - - // Reduce el tamaño de la ventana - auto decWindowZoom() -> bool; - - // Aumenta el tamaño de la ventana - auto incWindowZoom() -> bool; - - // Cambia el color del borde - void setBorderColor(Uint8 color); - - // Establece el tamaño del borde - static void setBorderWidth(int width); - - // Establece el tamaño del borde - static void setBorderHeight(int height); - - // Establece si se ha de ver el borde en el modo ventana - static void setBorderEnabled(bool value); - - // Cambia entre borde visible y no visible - void toggleBorder(); - - // Cambia el estado de los shaders - void toggleShaders(); - - // Muestra la ventana - void show(); - - // Oculta la ventana - void hide(); - - // Establece el renderizador para las surfaces - void setRendererSurface(const std::shared_ptr& surface = nullptr); - - // Cambia la paleta - void nextPalette(); - void previousPalette(); - - // Establece la paleta - void setPalete(); - - // Establece la visibilidad de las notificaciones - void setNotificationsEnabled(bool value); - - // Activa o desactiva la información de debug - void toggleDebugInfo(); - - // Getters - auto getRenderer() -> SDL_Renderer*; - auto getRendererSurface() -> std::shared_ptr; - auto getBorderSurface() -> std::shared_ptr; - [[nodiscard]] auto getText() const -> std::shared_ptr { return text_; } }; \ No newline at end of file diff --git a/source/game/entities/player.cpp b/source/game/entities/player.cpp index 0414db68..cd23f374 100644 --- a/source/game/entities/player.cpp +++ b/source/game/entities/player.cpp @@ -91,7 +91,7 @@ void Player::handleInput(float delta_time) { // Ya que se coloca el estado STANDING al cambiar de pantalla if (isOnFloor() || isOnAutoSurface()) { - setState(State::JUMPING); + transitionToState(State::JUMPING); vy_ = JUMP_VELOCITY; last_grounded_position_ = static_cast(y_); } @@ -136,7 +136,7 @@ void Player::handleState(float delta_time) { // Si no tiene suelo debajo y no está en rampa descendente -> FALLING if (!isOnFloor() && !isOnAutoSurface() && !isOnDownSlope()) { last_grounded_position_ = static_cast(y_); // Guarda Y actual al SALIR de STANDING - setState(State::FALLING); // setState() establece vx_=0, vy_=MAX_VY + transitionToState(State::FALLING); // setState() establece vx_=0, vy_=MAX_VY playFallSound(); } } else if (state_ == State::JUMPING) { @@ -149,12 +149,12 @@ void Player::switchBorders() { switch (border_) { case Room::Border::TOP: y_ = PLAY_AREA_BOTTOM - HEIGHT - TILE_SIZE; - setState(State::STANDING); + transitionToState(State::STANDING); break; case Room::Border::BOTTOM: y_ = PLAY_AREA_TOP; - setState(State::STANDING); + transitionToState(State::STANDING); break; case Room::Border::RIGHT: @@ -278,7 +278,7 @@ void Player::moveVerticalUp(float delta_time) { // Si hay colisión lo mueve hasta donde no colisiona // Regla: Si está JUMPING y tropieza contra el techo -> FALLING y_ = POS + 1; - setState(State::FALLING); + transitionToState(State::FALLING); } } @@ -305,7 +305,7 @@ void Player::moveVerticalDown(float delta_time) { is_alive_ = false; // Muere si cae más de 32 píxeles } - setState(State::STANDING); + transitionToState(State::STANDING); last_grounded_position_ = static_cast(y_); // Actualizar AL ENTRAR en STANDING // Deja de estar enganchado a la superficie automatica auto_movement_ = false; @@ -329,7 +329,7 @@ void Player::moveVerticalDown(float delta_time) { is_alive_ = false; // Muere si cae más de 32 píxeles } - setState(State::STANDING); + transitionToState(State::STANDING); last_grounded_position_ = static_cast(y_); // Actualizar AL ENTRAR en STANDING } else { // No está saltando y no hay colisón con una rampa @@ -358,7 +358,7 @@ void Player::move(float delta_time) { // Si ha salido del suelo, el jugador cae if (state_ == State::STANDING && !isOnFloor()) { - setState(State::FALLING); + transitionToState(State::FALLING); auto_movement_ = false; } @@ -392,7 +392,7 @@ void Player::handleJumpEnd() { // Si el jugador vuelve EXACTAMENTE a la altura inicial, debe CONTINUAR en JUMPING // Solo cuando la SUPERA (desciende más allá) cambia a FALLING if (state_ == State::JUMPING && vy_ > 0.0F && static_cast(y_) > last_grounded_position_) { - setState(State::FALLING); + transitionToState(State::FALLING); } } @@ -551,7 +551,7 @@ void Player::updateFeet() { } // Cambia el estado del jugador -void Player::setState(State value) { +void Player::transitionToState(State value) { previous_state_ = state_; state_ = value; diff --git a/source/game/entities/player.hpp b/source/game/entities/player.hpp index 4d529528..40695880 100644 --- a/source/game/entities/player.hpp +++ b/source/game/entities/player.hpp @@ -68,7 +68,7 @@ class Player { // --- Funciones --- void render(); // Pinta el enemigo en pantalla void update(float delta_time); // Actualiza las variables del objeto - [[nodiscard]] auto getOnBorder() const -> bool { return is_on_border_; } // Indica si el jugador esta en uno de los cuatro bordes de la pantalla + [[nodiscard]] auto isOnBorder() const -> bool { return is_on_border_; } // Indica si el jugador esta en uno de los cuatro bordes de la pantalla [[nodiscard]] auto getBorder() const -> Room::Border { return border_; } // Indica en cual de los cuatro bordes se encuentra void switchBorders(); // Cambia al jugador de un borde al opuesto. Util para el cambio de pantalla auto getRect() -> SDL_FRect { return {x_, y_, WIDTH, HEIGHT}; } // Obtiene el rectangulo que delimita al jugador @@ -137,8 +137,8 @@ class Player { void handleInput(float delta_time); // Comprueba las entradas y modifica variables // --- Funciones de gestión de estado --- - void handleState(float delta_time); // Comprueba el estado del jugador y actualiza variables - void setState(State value); // Cambia el estado del jugador + void handleState(float delta_time); // Comprueba el estado del jugador y actualiza variables + void transitionToState(State value); // Cambia el estado del jugador // --- Funciones de física --- void applyGravity(float delta_time); // Aplica gravedad al jugador diff --git a/source/game/scenes/game.cpp b/source/game/scenes/game.cpp index a36cec3b..37bacd66 100644 --- a/source/game/scenes/game.cpp +++ b/source/game/scenes/game.cpp @@ -307,7 +307,7 @@ auto Game::changeRoom(const std::string& room_path) -> bool { // Comprueba si el jugador esta en el borde de la pantalla void Game::checkPlayerIsOnBorder() { - if (player_->getOnBorder()) { + if (player_->isOnBorder()) { const std::string ROOM_NAME = room_->getRoom(player_->getBorder()); if (changeRoom(ROOM_NAME)) { player_->switchBorders(); diff --git a/source/game/scenes/logo.hpp b/source/game/scenes/logo.hpp index 3d65fc46..a92b0eb6 100644 --- a/source/game/scenes/logo.hpp +++ b/source/game/scenes/logo.hpp @@ -54,17 +54,17 @@ class Logo { float state_time_ = 0.0F; // Tiempo acumulado en el estado actual // --- Funciones --- - void update(); // Actualiza las variables - void render(); // Dibuja en pantalla - static void handleEvents(); // Comprueba el manejador de eventos - static void handleInput(); // Comprueba las entradas - void updateJAILGAMES(float delta_time); // Gestiona el logo de JAILGAME (time-based) - void updateTextureColors(); // Gestiona el color de las texturas - void updateState(float delta_time); // Actualiza el estado actual - void transitionToState(State new_state); // Transiciona a un nuevo estado - [[nodiscard]] auto getColorIndex(float progress) const -> int; // Calcula el índice de color según el progreso (0.0-1.0) + void update(); // Actualiza las variables + void render(); // Dibuja en pantalla + static void handleEvents(); // Comprueba el manejador de eventos + static void handleInput(); // Comprueba las entradas + void updateJAILGAMES(float delta_time); // Gestiona el logo de JAILGAME (time-based) + void updateTextureColors(); // Gestiona el color de las texturas + void updateState(float delta_time); // Actualiza el estado actual + void transitionToState(State new_state); // Transiciona a un nuevo estado + [[nodiscard]] auto getColorIndex(float progress) const -> int; // Calcula el índice de color según el progreso (0.0-1.0) [[nodiscard]] auto allJailgamesLinesInPosition() const -> bool; // Verifica si todas las líneas están en su posición destino - static void endSection(); // Termina la sección - void initColors(); // Inicializa el vector de colores - void initSprites(); // Crea los sprites de cada linea + static void endSection(); // Termina la sección + void initColors(); // Inicializa el vector de colores + void initSprites(); // Crea los sprites de cada linea }; \ No newline at end of file