diff --git a/source/game/scene_manager.hpp b/source/game/scene_manager.hpp index 9ee627ac..ceabe82a 100644 --- a/source/game/scene_manager.hpp +++ b/source/game/scene_manager.hpp @@ -34,7 +34,7 @@ enum class Options { // --- Variables de estado globales --- #ifdef _DEBUG -inline Scene current = Scene::GAME; // Escena actual +inline Scene current = Scene::LOADING_SCREEN; // Escena actual inline Options options = Options::LOGO_TO_LOADING_SCREEN; // Opciones de la escena actual #else inline Scene current = Scene::LOGO; // Escena actual diff --git a/source/game/scenes/loading_screen.cpp b/source/game/scenes/loading_screen.cpp index 57409af0..64ad567f 100644 --- a/source/game/scenes/loading_screen.cpp +++ b/source/game/scenes/loading_screen.cpp @@ -106,11 +106,13 @@ void LoadingScreen::transitionToState(State new_state) { case State::LOADING_MONO: current_border_type_ = Border::YELLOW_AND_BLUE; Audio::get()->playMusic("loading_screen_data.ogg", 0); + last_mono_step_ = -1; // Resetear contador de pasos mono break; case State::LOADING_COLOR: current_border_type_ = Border::YELLOW_AND_BLUE; Audio::get()->playMusic("loading_screen_color.ogg", 0); + last_color_block_ = -1; // Resetear contador de bloques color break; case State::COMPLETE: @@ -184,34 +186,47 @@ void LoadingScreen::updateMonoLoad(float delta_time) { const int TOTAL_STEPS = MONO_TOTAL_LINES * MONO_STEPS_PER_LINE; // 192 * 5 = 960 const int CURRENT_STEP = static_cast(progress * TOTAL_STEPS); - // Calcular línea y sub-paso - const int CURRENT_LINE = CURRENT_STEP / MONO_STEPS_PER_LINE; // 0-191 - const int CURRENT_SUBSTEP = CURRENT_STEP % MONO_STEPS_PER_LINE; // 0-4 - // Verificar si ha completado todas las líneas - if (CURRENT_LINE >= MONO_TOTAL_LINES) { + if (CURRENT_STEP >= TOTAL_STEPS) { transitionToState(State::LOADING_COLOR); return; } - // Calcular rectángulo de clip (con floats para mayor precisión) + // Dibujar todos los pasos intermedios desde el último dibujado const float TEXTURE_WIDTH = mono_loading_screen_surface_->getWidth(); const float CLIP_WIDTH = TEXTURE_WIDTH / MONO_STEPS_PER_LINE; - const float CLIP_X = CURRENT_SUBSTEP * CLIP_WIDTH; - - load_rect_.x = CLIP_X; - load_rect_.y = static_cast(line_index_[CURRENT_LINE]); - load_rect_.w = CLIP_WIDTH; - load_rect_.h = 1.0F; - - // Configurar y dibujar sobre screen_surface_ - mono_loading_screen_sprite_->setClip(load_rect_); - mono_loading_screen_sprite_->setPosition(load_rect_); auto previous_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(screen_surface_); - mono_loading_screen_sprite_->render(); + + for (int step = last_mono_step_ + 1; step <= CURRENT_STEP; ++step) { + // Calcular línea y sub-paso para este paso + const int CURRENT_LINE = step / MONO_STEPS_PER_LINE; // 0-191 + const int CURRENT_SUBSTEP = step % MONO_STEPS_PER_LINE; // 0-4 + + // Saltar si excede el total de líneas + if (CURRENT_LINE >= MONO_TOTAL_LINES) { + break; + } + + // Calcular rectángulo de clip para este paso + const float CLIP_X = CURRENT_SUBSTEP * CLIP_WIDTH; + + load_rect_.x = CLIP_X; + load_rect_.y = static_cast(line_index_[CURRENT_LINE]); + load_rect_.w = CLIP_WIDTH; + load_rect_.h = 1.0F; + + // Configurar y dibujar sobre screen_surface_ + mono_loading_screen_sprite_->setClip(load_rect_); + mono_loading_screen_sprite_->setPosition(load_rect_); + mono_loading_screen_sprite_->render(); + } + Screen::get()->setRendererSurface(previous_renderer); + + // Actualizar el último paso dibujado + last_mono_step_ = CURRENT_STEP; } // Gestiona la carga en color @@ -220,12 +235,8 @@ void LoadingScreen::updateColorLoad(float delta_time) { float progress = state_time_ / LOADING_COLOR_DURATION; progress = std::min(progress, 1.0F); - // Calcular iteración actual (el código original incrementaba de 2 en 2) - const int TOTAL_ITERATIONS = COLOR_TOTAL_BLOCKS / 2; // 768 / 2 = 384 iteraciones - const int CURRENT_ITERATION = static_cast(progress * TOTAL_ITERATIONS); - - // Convertir a bloque (incrementa de 2 en 2, empezando en 0) - const int CURRENT_BLOCK = CURRENT_ITERATION * 2; + // Calcular bloque actual (0-767) - ahora pinta de 1 en 1 en lugar de 2 en 2 + const int CURRENT_BLOCK = static_cast(progress * COLOR_TOTAL_BLOCKS); // Verificar si ha completado todos los bloques if (CURRENT_BLOCK >= COLOR_TOTAL_BLOCKS) { @@ -233,20 +244,33 @@ void LoadingScreen::updateColorLoad(float delta_time) { return; } - // Calcular posición del bloque - load_rect_.x = static_cast((CURRENT_BLOCK * COLOR_BLOCK_SPACING) % 256); - load_rect_.y = static_cast((CURRENT_BLOCK / COLOR_BLOCKS_PER_ROW) * COLOR_BLOCK_SPACING); - load_rect_.w = static_cast(COLOR_BLOCK_WIDTH); - load_rect_.h = static_cast(COLOR_BLOCK_HEIGHT); - - // Configurar y dibujar sobre screen_surface_ - color_loading_screen_sprite_->setClip(load_rect_); - color_loading_screen_sprite_->setPosition(load_rect_); - + // Dibujar todos los bloques intermedios desde el último dibujado auto previous_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(screen_surface_); - color_loading_screen_sprite_->render(); + + // Iterar desde el último bloque + 1 hasta el bloque actual (de 1 en 1) + for (int block = last_color_block_ + 1; block <= CURRENT_BLOCK; ++block) { + // Saltar si excede el total de bloques + if (block >= COLOR_TOTAL_BLOCKS) { + break; + } + + // Calcular posición del bloque + load_rect_.x = static_cast((block * COLOR_BLOCK_SPACING) % 256); + load_rect_.y = static_cast((block / COLOR_BLOCKS_PER_ROW) * COLOR_BLOCK_SPACING); + load_rect_.w = static_cast(COLOR_BLOCK_WIDTH); + load_rect_.h = static_cast(COLOR_BLOCK_HEIGHT); + + // Configurar y dibujar sobre screen_surface_ + color_loading_screen_sprite_->setClip(load_rect_); + color_loading_screen_sprite_->setPosition(load_rect_); + color_loading_screen_sprite_->render(); + } + Screen::get()->setRendererSurface(previous_renderer); + + // Actualizar el último bloque dibujado + last_color_block_ = CURRENT_BLOCK; } // Dibuja el efecto de carga amarillo y azul en el borde diff --git a/source/game/scenes/loading_screen.hpp b/source/game/scenes/loading_screen.hpp index 600d5ad5..88a3e8a8 100644 --- a/source/game/scenes/loading_screen.hpp +++ b/source/game/scenes/loading_screen.hpp @@ -61,9 +61,9 @@ class LoadingScreen { // --- Constantes de tiempo (en segundos) --- static constexpr float SILENT1_DURATION = 2.0F; // Pausa inicial static constexpr float HEADER1_DURATION = 4.0F; // Cabecera - static constexpr float DATA1_DURATION = 0.2F; // Datos - static constexpr float SILENT2_DURATION = 2.0F; // Segunda pausa - static constexpr float HEADER2_DURATION = 3.0F; // Cabecera pantalla + static constexpr float DATA1_DURATION = 0.18F; // Datos + static constexpr float SILENT2_DURATION = 1.6F; // Segunda pausa + static constexpr float HEADER2_DURATION = 2.0F; // Cabecera pantalla static constexpr float LOADING_MONO_DURATION = 16.0F; // Duración total de la carga monocromática static constexpr float LOADING_COLOR_DURATION = 4.0F; // Duración total de la carga en color static constexpr float DATA2_DURATION = 5.0F; // Datos @@ -116,4 +116,8 @@ class LoadingScreen { SDL_FRect load_rect_{0.0F, 0.0F, 0.0F, 1.0F}; // Rectángulo para dibujar la pantalla de carga Carrier carrier_; // Estructura para los efectos de la carga de cabeceras Noise noise_; // Variaciones de ruido durante los silencios + + // Variables de seguimiento para evitar saltos de pasos/bloques + int last_mono_step_{-1}; // Último paso mono dibujado + int last_color_block_{-1}; // Último bloque color dibujado }; \ No newline at end of file