From 87370dd11d9289f4fbfa6aa65e023d64caf8df48 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 26 Oct 2025 23:07:08 +0100 Subject: [PATCH] migracio de Title a time based --- CMakeLists.txt | 3 + source/core/rendering/screen.hpp | 4 +- source/external/jail_audio.cpp | 2 +- source/game/entities/player.cpp | 34 ++++----- source/game/entities/player.hpp | 4 +- source/game/gameplay/room.cpp | 14 ++-- source/game/options.cpp | 2 +- source/game/scene_manager.hpp | 2 +- source/game/scenes/game.cpp | 21 +++--- source/game/scenes/game.hpp | 2 +- source/game/scenes/title.cpp | 122 +++++++++++++++++-------------- source/game/scenes/title.hpp | 74 +++++++++---------- 12 files changed, 150 insertions(+), 134 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e64f5b1..b123794 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,9 @@ project(jaildoctors_dilemma VERSION 1.00) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED True) +# Exportar comandos de compilación para herramientas de análisis +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + # Establece la política CMP0072 para indicar cómo se debe seleccionar la implementación de OpenGL. # En este caso, se elige la opción "GLVND", que utiliza bibliotecas modernas y modulares (libOpenGL, libGLX), # en lugar de la biblioteca OpenGL clásica (libGL). Esto mejora la compatibilidad con drivers recientes diff --git a/source/core/rendering/screen.hpp b/source/core/rendering/screen.hpp index c73f89d..f6ab848 100644 --- a/source/core/rendering/screen.hpp +++ b/source/core/rendering/screen.hpp @@ -86,8 +86,8 @@ class Screen { std::string fragment_shader_source_; // Almacena el fragment shader DisplayMonitor display_monitor_; // Informacion de la pantalla -#ifdef DEBUG - bool show_debug_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla +#ifdef _DEBUG + bool show_debug_info_ = true; // Indica si ha de mostrar/ocultar la información de la pantalla #else bool show_debug_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla #endif diff --git a/source/external/jail_audio.cpp b/source/external/jail_audio.cpp index e8c2c3d..72ea435 100644 --- a/source/external/jail_audio.cpp +++ b/source/external/jail_audio.cpp @@ -114,7 +114,7 @@ void JA_Update() void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channels) { - #ifdef DEBUG + #ifdef _DEBUG SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG); #endif diff --git a/source/game/entities/player.cpp b/source/game/entities/player.cpp index 7fb6a20..930901a 100644 --- a/source/game/entities/player.cpp +++ b/source/game/entities/player.cpp @@ -30,7 +30,7 @@ Player::Player(const PlayerData& player) under_feet_.resize(under_feet_.size() + 2, {0, 0}); feet_.resize(feet_.size() + 2, {0, 0}); -#ifdef DEBUG +#ifdef _DEBUG debug_rect_x_ = {0, 0, 0, 0}; debug_rect_y_ = {0, 0, 0, 0}; debug_color_ = static_cast(PaletteColor::GREEN); @@ -42,7 +42,7 @@ Player::Player(const PlayerData& player) void Player::render() { sprite_->render(1, color_); -#ifdef DEBUG +#ifdef _DEBUG renderDebugInfo(); #endif } @@ -221,7 +221,7 @@ void Player::move() { applyGravity(); // Aplica gravedad al jugador checkState(); // Comprueba el estado del jugador -#ifdef DEBUG +#ifdef _DEBUG debug_color_ = static_cast(PaletteColor::GREEN); #endif @@ -234,7 +234,7 @@ void Player::move() { proj.h = HEIGHT_; proj.w = static_cast(std::ceil(std::fabs(vx_))); // Para evitar que tenga un ancho de 0 pixels -#ifdef DEBUG +#ifdef _DEBUG debug_rect_x_ = proj; #endif @@ -274,7 +274,7 @@ void Player::move() { proj.h = HEIGHT_; proj.w = ceil(vx_); // Para evitar que tenga un ancho de 0 pixels -#ifdef DEBUG +#ifdef _DEBUG debug_rect_x_ = proj; #endif @@ -328,7 +328,7 @@ void Player::move() { proj.h = static_cast(std::ceil(std::fabs(vy_))); // Para evitar que tenga una altura de 0 pixels proj.w = WIDTH_; -#ifdef DEBUG +#ifdef _DEBUG debug_rect_y_ = proj; #endif @@ -355,7 +355,7 @@ void Player::move() { proj.h = ceil(vy_); // Para evitar que tenga una altura de 0 pixels proj.w = WIDTH_; -#ifdef DEBUG +#ifdef _DEBUG debug_rect_y_ = proj; #endif @@ -380,7 +380,7 @@ void Player::move() { // Calcula la nueva posición y_ = POINT - HEIGHT_; setState(PlayerState::STANDING); -#ifdef DEBUG +#ifdef _DEBUG debug_color_ = static_cast(PaletteColor::YELLOW); debug_point_ = {x_ + (WIDTH_ / 2), POINT}; #endif @@ -388,7 +388,7 @@ void Player::move() { // No está saltando y no hay colisón con una rampa // Calcula la nueva posición y_ += vy_; -#ifdef DEBUG +#ifdef _DEBUG debug_color_ = static_cast(PaletteColor::RED); #endif } @@ -403,7 +403,7 @@ void Player::move() { placeSprite(); // Coloca el sprite en la nueva posición collider_box_ = getRect(); // Actualiza el rectangulo de colisión -#ifdef DEBUG +#ifdef _DEBUG Debug::get()->add("RECT_X: " + std::to_string(debug_rect_x_.x) + "," + std::to_string(debug_rect_x_.y) + "," + std::to_string(debug_rect_x_.w) + "," + std::to_string(debug_rect_x_.h)); Debug::get()->add("RECT_Y: " + std::to_string(debug_rect_y_.x) + "," + std::to_string(debug_rect_y_.y) + "," + std::to_string(debug_rect_y_.w) + "," + std::to_string(debug_rect_y_.h)); #endif @@ -436,7 +436,7 @@ void Player::playJumpSound() { JA_PlaySound(jumping_sound_[jumping_counter_ / 4]); } -#ifdef DEBUG +#ifdef _DEBUG Debug::get()->add("JUMP: " + std::to_string(jumping_counter_ / 4)); #endif } @@ -447,7 +447,7 @@ void Player::playFallSound() { JA_PlaySound(falling_sound_[std::min((falling_counter_ / 4), (int)falling_sound_.size() - 1)]); } -#ifdef DEBUG +#ifdef _DEBUG Debug::get()->add("FALL: " + std::to_string(falling_counter_ / 4)); #endif } @@ -470,7 +470,7 @@ bool Player::isOnFloor() { on_slope_l = room_->checkLeftSlopes(&under_feet_[0]); on_slope_r = room_->checkRightSlopes(&under_feet_[1]); -#ifdef DEBUG +#ifdef _DEBUG if (on_floor) { Debug::get()->add("ON_FLOOR"); } @@ -498,7 +498,7 @@ bool Player::isOnAutoSurface() { on_auto_surface |= room_->checkAutoSurfaces(&f); } -#ifdef DEBUG +#ifdef _DEBUG if (on_auto_surface) { Debug::get()->add("ON_AUTO_SURFACE"); } @@ -522,7 +522,7 @@ bool Player::isOnDownSlope() { on_slope |= room_->checkLeftSlopes(&under_feet_[0]); on_slope |= room_->checkRightSlopes(&under_feet_[1]); -#ifdef DEBUG +#ifdef _DEBUG if (on_slope) { Debug::get()->add("ON_DOWN_SLOPE"); } @@ -627,7 +627,7 @@ void Player::initSprite(const std::string& surface_path, const std::string& anim sprite_->setCurrentAnimation("walk"); } -#ifdef DEBUG +#ifdef _DEBUG // Pinta la información de debug del jugador void Player::renderDebugInfo() { if (Debug::get()->getEnabled()) { @@ -653,4 +653,4 @@ void Player::renderDebugInfo() { surface->putPixel(debug_point_.x, debug_point_.y, rand() % 16); } } -#endif // DEBUG \ No newline at end of file +#endif // _DEBUG \ No newline at end of file diff --git a/source/game/entities/player.hpp b/source/game/entities/player.hpp index 690931b..f302e8f 100644 --- a/source/game/entities/player.hpp +++ b/source/game/entities/player.hpp @@ -98,7 +98,7 @@ class Player { int jumping_counter_ = 0; // Cuenta el tiempo de salto int falling_counter_ = 0; // Cuenta el tiempo de caida -#ifdef DEBUG +#ifdef _DEBUG SDL_FRect debug_rect_x_; // Rectangulo de desplazamiento para el modo debug SDL_FRect debug_rect_y_; // Rectangulo de desplazamiento para el modo debug Uint8 debug_color_; // Color del recuadro de debug del jugador @@ -165,7 +165,7 @@ class Player { // Inicializa el sprite del jugador void initSprite(const std::string& texture_path, const std::string& animations_path); -#ifdef DEBUG +#ifdef _DEBUG // Pinta la información de debug del jugador void renderDebugInfo(); #endif diff --git a/source/game/gameplay/room.cpp b/source/game/gameplay/room.cpp index 6c15758..8e05a86 100644 --- a/source/game/gameplay/room.cpp +++ b/source/game/gameplay/room.cpp @@ -378,7 +378,7 @@ void Room::fillMapTexture() { } } -#ifdef DEBUG +#ifdef _DEBUG if (Debug::get()->getEnabled()) { auto surface = Screen::get()->getRendererSurface(); @@ -432,7 +432,7 @@ void Room::fillMapTexture() { } } -#endif // DEBUG +#endif // _DEBUG Screen::get()->setRendererSurface(previuos_renderer); } @@ -443,7 +443,7 @@ void Room::renderMap() { map_surface_->render(nullptr, &dest); // Dibuja los tiles animados -#ifdef DEBUG +#ifdef _DEBUG if (!Debug::get()->getEnabled()) { renderAnimatedTiles(); } @@ -591,25 +591,25 @@ bool Room::itemCollision(SDL_FRect& rect) { int Room::getSlopeHeight(SDL_FPoint p, TileType slope) { // Calcula la base del tile int base = ((p.y / TILE_SIZE_) * TILE_SIZE_) + TILE_SIZE_; -#ifdef DEBUG +#ifdef _DEBUG Debug::get()->add("BASE = " + std::to_string(base)); #endif // Calcula cuanto se ha entrado en el tile horizontalmente const int pos = (static_cast(p.x) % TILE_SIZE_); // Esto da un valor entre 0 y 7 -#ifdef DEBUG +#ifdef _DEBUG Debug::get()->add("POS = " + std::to_string(pos)); #endif // Se resta a la base la cantidad de pixeles pos en funcion de la rampa if (slope == TileType::SLOPE_R) { base -= pos + 1; -#ifdef DEBUG +#ifdef _DEBUG Debug::get()->add("BASE_R = " + std::to_string(base)); #endif } else { base -= (TILE_SIZE_ - pos); -#ifdef DEBUG +#ifdef _DEBUG Debug::get()->add("BASE_L = " + std::to_string(base)); #endif } diff --git a/source/game/options.cpp b/source/game/options.cpp index 88a0da5..2d6bd20 100644 --- a/source/game/options.cpp +++ b/source/game/options.cpp @@ -20,7 +20,7 @@ bool setOptions(const std::string& var, const std::string& value); // Crea e inicializa las opciones del programa void init() { -#ifdef DEBUG +#ifdef _DEBUG console = true; #else console = false; diff --git a/source/game/scene_manager.hpp b/source/game/scene_manager.hpp index 6271c30..c82b56a 100644 --- a/source/game/scene_manager.hpp +++ b/source/game/scene_manager.hpp @@ -37,7 +37,7 @@ enum class Options { inline Scene current = Scene::LOGO; // Escena actual inline Options options = Options::LOGO_TO_LOADING_SCREEN; // Opciones de la escena actual #else -inline Scene current = Scene::LOADING_SCREEN; // Escena actual +inline Scene current = Scene::TITLE; // Escena actual inline Options options = Options::LOGO_TO_LOADING_SCREEN; // Opciones de la escena actual #endif diff --git a/source/game/scenes/game.cpp b/source/game/scenes/game.cpp index f5cff2f..2611b42 100644 --- a/source/game/scenes/game.cpp +++ b/source/game/scenes/game.cpp @@ -1,5 +1,3 @@ -#include "game/scene_manager.hpp" // Para SceneManager - #include "game/scenes/game.hpp" #include @@ -14,17 +12,18 @@ #include "core/resources/asset.hpp" // Para Asset #include "core/resources/resource.hpp" // Para ResourceRoom, Resource #include "core/system/debug.hpp" // Para Debug +#include "core/system/global_events.hpp" // Para check #include "external/jail_audio.h" // Para JA_PauseMusic, JA_GetMusicState, JA_P... #include "game/gameplay/cheevos.hpp" // Para Cheevos #include "game/gameplay/item_tracker.hpp" // Para ItemTracker -#include "game/options.hpp" // Para Options, options, Cheat, SectionState #include "game/gameplay/room.hpp" // Para Room, RoomData #include "game/gameplay/room_tracker.hpp" // Para RoomTracker #include "game/gameplay/scoreboard.hpp" // Para ScoreboardData, Scoreboard #include "game/gameplay/stats.hpp" // Para Stats +#include "game/options.hpp" // Para Options, options, Cheat, SectionState +#include "game/scene_manager.hpp" // Para SceneManager #include "game/ui/notifier.hpp" // Para Notifier, NotificationText, CHEEVO_NO... #include "utils/defines.hpp" // Para BLOCK, PLAY_AREA_HEIGHT, RoomBorder::BOTTOM -#include "core/system/global_events.hpp" // Para check #include "utils/utils.hpp" // Para PaletteColor, stringToColor // Constructor @@ -34,7 +33,7 @@ Game::Game(GameMode mode) room_tracker_(std::make_shared()), stats_(std::make_shared(Asset::get()->get("stats.csv"), Asset::get()->get("stats_buffer.csv"))), mode_(mode), -#ifdef DEBUG +#ifdef _DEBUG current_room_("03.room"), spawn_point_(PlayerSpawn(25 * BLOCK, 13 * BLOCK, 0, 0, 0, PlayerState::STANDING, SDL_FLIP_HORIZONTAL)) #else @@ -42,7 +41,7 @@ Game::Game(GameMode mode) spawn_point_(PlayerSpawn(25 * BLOCK, 13 * BLOCK, 0, 0, 0, PlayerState::STANDING, SDL_FLIP_HORIZONTAL)) #endif { -#ifdef DEBUG +#ifdef _DEBUG Debug::get()->setEnabled(false); #endif @@ -73,7 +72,7 @@ void Game::checkEvents() { SDL_Event event; while (SDL_PollEvent(&event)) { globalEvents::check(event); -#ifdef DEBUG +#ifdef _DEBUG checkDebugEvents(event); #endif } @@ -123,7 +122,7 @@ void Game::update() { // Comprueba el teclado checkInput(); -#ifdef DEBUG +#ifdef _DEBUG Debug::get()->clear(); #endif @@ -147,7 +146,7 @@ void Game::update() { Screen::get()->update(); -#ifdef DEBUG +#ifdef _DEBUG updateDebugInfo(); #endif } @@ -169,7 +168,7 @@ void Game::render() { scoreboard_->render(); renderBlackScreen(); -#ifdef DEBUG +#ifdef _DEBUG // Debug info renderDebugInfo(); #endif @@ -178,7 +177,7 @@ void Game::render() { Screen::get()->render(); } -#ifdef DEBUG +#ifdef _DEBUG // Pasa la información de debug void Game::updateDebugInfo() { Debug::get()->add("X = " + std::to_string(static_cast(player_->x_)) + ", Y = " + std::to_string(static_cast(player_->y_))); diff --git a/source/game/scenes/game.hpp b/source/game/scenes/game.hpp index 0f1d8ca..bff27db 100644 --- a/source/game/scenes/game.hpp +++ b/source/game/scenes/game.hpp @@ -74,7 +74,7 @@ class Game { // Comprueba los eventos de la cola void checkEvents(); -#ifdef DEBUG +#ifdef _DEBUG // Pone la información de debug en pantalla void updateDebugInfo(); diff --git a/source/game/scenes/title.cpp b/source/game/scenes/title.cpp index 5a76662..1354ec6 100644 --- a/source/game/scenes/title.cpp +++ b/source/game/scenes/title.cpp @@ -24,7 +24,11 @@ Title::Title() title_logo_sprite_(std::make_shared(title_logo_surface_, 29, 9, title_logo_surface_->getWidth(), title_logo_surface_->getHeight())), loading_screen_surface_(Resource::get()->getSurface("loading_screen_color.gif")), loading_screen_sprite_(std::make_shared(loading_screen_surface_, 0, 0, loading_screen_surface_->getWidth(), loading_screen_surface_->getHeight())), - bg_surface_(std::make_shared(Options::game.width, Options::game.height)) { + bg_surface_(std::make_shared(Options::game.width, Options::game.height)), + delta_timer_(std::make_unique()), + state_time_(0.0f), + fade_accumulator_(0.0f), + current_delta_(0.0f) { // Inicializa variables state_ = SceneManager::options == SceneManager::Options::TITLE_WITH_LOADING_SCREEN ? TitleState::SHOW_LOADING_SCREEN : TitleState::SHOW_MENU; SceneManager::current = SceneManager::Scene::TITLE; @@ -51,7 +55,7 @@ void Title::initMarquee() { for (int i = 0; i < (int)long_text_.length(); ++i) { TitleLetter l; l.letter = long_text_.substr(i, 1); - l.x = 256; + l.x = 256.0f; l.enabled = false; letters_.push_back(l); } @@ -89,18 +93,17 @@ void Title::checkEvents() { void Title::checkInput() { if (show_cheevos_) { if (Input::get()->checkInput(InputAction::DOWN, INPUT_ALLOW_REPEAT)) { - moveCheevosList(1); + moveCheevosList(1, current_delta_); } else if (Input::get()->checkInput(InputAction::UP, INPUT_ALLOW_REPEAT)) { - moveCheevosList(0); + moveCheevosList(0, current_delta_); } else if (Input::get()->checkInput(InputAction::ACCEPT, INPUT_DO_NOT_ALLOW_REPEAT)) { hideCheevosList(); - counter_ = 0; } } if (Input::get()->checkInput(InputAction::ACCEPT, INPUT_DO_NOT_ALLOW_REPEAT)) { if (state_ == TitleState::SHOW_LOADING_SCREEN) { - state_ = TitleState::FADE_LOADING_SCREEN; + transitionToState(TitleState::FADE_LOADING_SCREEN); } } @@ -108,25 +111,26 @@ void Title::checkInput() { } // Actualiza la marquesina -void Title::updateMarquee() { +void Title::updateMarquee(float delta_time) { const auto TEXT = Resource::get()->getText("gauntlet"); + const float displacement = MARQUEE_SPEED * delta_time; for (int i = 0; i < (int)letters_.size(); ++i) { if (letters_[i].enabled) { - letters_[i].x -= marquee_speed_; - if (letters_[i].x < -10) { + letters_[i].x -= displacement; + if (letters_[i].x < -10.0f) { letters_[i].enabled = false; } } else { - if (i > 0 && letters_[i - 1].x < 256 && letters_[i - 1].enabled) { + if (i > 0 && letters_[i - 1].x < 256.0f && letters_[i - 1].enabled) { letters_[i].enabled = true; - letters_[i].x = letters_[i - 1].x + TEXT->lenght(letters_[i - 1].letter) + 1; + letters_[i].x = letters_[i - 1].x + TEXT->lenght(letters_[i - 1].letter) + 1.0f; } } } // Comprueba si ha terminado la marquesina y la reinicia - if (letters_[letters_.size() - 1].x < -10) { + if (letters_[letters_.size() - 1].x < -10.0f) { // Inicializa la marquesina initMarquee(); } @@ -144,55 +148,63 @@ void Title::renderMarquee() { // Actualiza las variables void Title::update() { - // Comprueba que la diferencia de ticks sea mayor a la velocidad del juego - if (SDL_GetTicks() - ticks_ > GAME_SPEED) { - // Actualiza el contador de ticks - ticks_ = SDL_GetTicks(); + // Obtener delta time + current_delta_ = delta_timer_->tick(); - // Comprueba las entradas - checkInput(); + // Comprueba las entradas + checkInput(); - Screen::get()->update(); + // Actualiza la pantalla + Screen::get()->update(); - // Incrementa el contador - counter_++; + // Actualiza el estado actual + updateState(current_delta_); +} - switch (state_) { - case TitleState::SHOW_LOADING_SCREEN: - if (counter_ == 500) { - counter_ = 0; - state_ = TitleState::FADE_LOADING_SCREEN; +// Actualiza el estado actual +void Title::updateState(float delta_time) { + state_time_ += delta_time; + + switch (state_) { + case TitleState::SHOW_LOADING_SCREEN: + if (state_time_ >= SHOW_LOADING_DURATION) { + transitionToState(TitleState::FADE_LOADING_SCREEN); + } + break; + + case TitleState::FADE_LOADING_SCREEN: + fade_accumulator_ += delta_time; + if (fade_accumulator_ >= FADE_STEP_INTERVAL) { + fade_accumulator_ = 0.0f; + if (loading_screen_surface_->fadeSubPalette()) { + transitionToState(TitleState::SHOW_MENU); } - break; + } + break; - case TitleState::FADE_LOADING_SCREEN: - if (counter_ % 4 == 0) { - if (loading_screen_surface_->fadeSubPalette()) { - counter_ = 0; - state_ = TitleState::SHOW_MENU; - } - } - break; + case TitleState::SHOW_MENU: + // Actualiza la marquesina + updateMarquee(delta_time); - case TitleState::SHOW_MENU: - // Actualiza la marquesina - updateMarquee(); + // Si el tiempo alcanza el timeout, va a créditos + if (state_time_ >= AUTO_CREDITS_TIMEOUT && !show_cheevos_) { + SceneManager::current = SceneManager::Scene::CREDITS; + SceneManager::options = SceneManager::Options::NONE; + } + break; - // Si el contador alcanza cierto valor, termina la seccion - if (counter_ == 2200) { - if (!show_cheevos_) { - SceneManager::current = SceneManager::Scene::CREDITS; - SceneManager::options = SceneManager::Options::NONE; - } - } - break; - - default: - break; - } + default: + break; } } +// Transiciona a un nuevo estado +void Title::transitionToState(TitleState new_state) { + state_ = new_state; + state_time_ = 0.0f; + fade_accumulator_ = 0.0f; +} + // Dibuja en pantalla void Title::render() { // Prepara para empezar a dibujar en la textura de juego @@ -237,10 +249,14 @@ void Title::run() { } // Desplaza la lista de logros -void Title::moveCheevosList(int direction) { +void Title::moveCheevosList(int direction, float delta_time) { + // Calcula el desplazamiento basado en tiempo + const float displacement = CHEEVOS_SCROLL_SPEED * delta_time; + // Modifica la posición de la ventana de vista - constexpr int SPEED = 2; - cheevos_surface_view_.y = direction == 0 ? cheevos_surface_view_.y - SPEED : cheevos_surface_view_.y + SPEED; + cheevos_surface_view_.y = direction == 0 + ? cheevos_surface_view_.y - displacement + : cheevos_surface_view_.y + displacement; // Ajusta los limites const float BOTTOM = cheevos_surface_->getHeight() - cheevos_surface_view_.h; diff --git a/source/game/scenes/title.hpp b/source/game/scenes/title.hpp index 7a6f4de..f4f3eaa 100644 --- a/source/game/scenes/title.hpp +++ b/source/game/scenes/title.hpp @@ -2,17 +2,19 @@ #include -#include // Para shared_ptr -#include // Para string -#include // Para vector -class SurfaceSprite; // lines 9-9 -class Surface; // lines 10-10 +#include // Para shared_ptr +#include // Para string +#include // Para vector + +#include "utils/delta_timer.hpp" // Para DeltaTimer +class SurfaceSprite; // Forward declaration +class Surface; // Forward declaration class Title { private: struct TitleLetter { std::string letter; // Letra a escribir - int x; // Posición en el eje x + float x; // Posición en el eje x (float para precisión con delta time) bool enabled; // Solo se escriben y mueven si estan habilitadas }; @@ -22,6 +24,13 @@ class Title { SHOW_MENU }; + // --- Constantes de tiempo (en segundos) --- + static constexpr float SHOW_LOADING_DURATION = 5.0f; // Tiempo mostrando loading screen (antes 500 frames) + static constexpr float FADE_STEP_INTERVAL = 0.033f; // Intervalo entre pasos de fade (antes cada 4 frames) + static constexpr float AUTO_CREDITS_TIMEOUT = 22.0f; // Timeout para ir a créditos (antes 2200 frames) + static constexpr float MARQUEE_SPEED = 100.0f; // Velocidad de marquesina (pixels/segundo) + static constexpr float CHEEVOS_SCROLL_SPEED = 120.0f; // Velocidad de scroll de logros (pixels/segundo) + // Objetos y punteros std::shared_ptr title_logo_surface_; // Textura con los graficos std::shared_ptr title_logo_sprite_; // SSprite para manejar la surface @@ -31,39 +40,28 @@ class Title { std::shared_ptr cheevos_surface_; // Textura con la lista de logros std::shared_ptr cheevos_sprite_; // SSprite para manejar la surface con la lista de logros - // Variables - int counter_ = 0; // Contador - std::string long_text_; // Texto que aparece en la parte inferior del titulo - Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa - std::vector letters_; // Vector con las letras de la marquesina - int marquee_speed_ = 2; // Velocidad de desplazamiento de la marquesina - bool show_cheevos_ = false; // Indica si se muestra por pantalla el listado de logros - SDL_FRect cheevos_surface_view_; // Zona visible de la surface con el listado de logros - TitleState state_; // Estado en el que se encuentra el bucle principal + // --- Variables de estado --- + std::unique_ptr delta_timer_; // Timer para delta time + std::string long_text_; // Texto que aparece en la parte inferior del titulo + std::vector letters_; // Vector con las letras de la marquesina + bool show_cheevos_ = false; // Indica si se muestra por pantalla el listado de logros + SDL_FRect cheevos_surface_view_; // Zona visible de la surface con el listado de logros + TitleState state_; // Estado en el que se encuentra el bucle principal + float state_time_; // Tiempo acumulado en el estado actual + float fade_accumulator_; // Acumulador para controlar el fade por tiempo + float current_delta_; // Delta time del frame actual - // Actualiza las variables - void update(); - - // Dibuja en pantalla - void render(); - - // Comprueba el manejador de eventos - void checkEvents(); - - // Comprueba las entradas - void checkInput(); - - // Inicializa la marquesina - void initMarquee(); - - // Actualiza la marquesina - void updateMarquee(); - - // Dibuja la marquesina - void renderMarquee(); - - // Desplaza la lista de logros - void moveCheevosList(int direction); + // --- Funciones --- + void update(); // Actualiza las variables + void render(); // Dibuja en pantalla + void checkEvents(); // Comprueba el manejador de eventos + void checkInput(); // Comprueba las entradas + void updateState(float delta_time); // Actualiza el estado actual + void transitionToState(TitleState new_state); // Transiciona a un nuevo estado + void initMarquee(); // Inicializa la marquesina + void updateMarquee(float delta_time); // Actualiza la marquesina (time-based) + void renderMarquee(); // Dibuja la marquesina + void moveCheevosList(int direction, float delta_time); // Desplaza la lista de logros (time-based) // Rellena la surface de fondo con todos los gráficos void fillSurface();