fix: la pantalla de carrega carregava mal a 60FPS. es saltava bolcs per pintar.

style: adjustat el timing de loading_screen
This commit is contained in:
2025-11-10 17:14:15 +01:00
parent 6ea0acd3f3
commit 1821b84e73
3 changed files with 66 additions and 38 deletions

View File

@@ -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<int>(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<float>(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<float>(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<int>(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<int>(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<float>((CURRENT_BLOCK * COLOR_BLOCK_SPACING) % 256);
load_rect_.y = static_cast<float>((CURRENT_BLOCK / COLOR_BLOCKS_PER_ROW) * COLOR_BLOCK_SPACING);
load_rect_.w = static_cast<float>(COLOR_BLOCK_WIDTH);
load_rect_.h = static_cast<float>(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<float>((block * COLOR_BLOCK_SPACING) % 256);
load_rect_.y = static_cast<float>((block / COLOR_BLOCKS_PER_ROW) * COLOR_BLOCK_SPACING);
load_rect_.w = static_cast<float>(COLOR_BLOCK_WIDTH);
load_rect_.h = static_cast<float>(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