From 34fc2b6b06edf1a5bdbe7132e188a66b553b0613 Mon Sep 17 00:00:00 2001 From: Sergio Valor Martinez Date: Wed, 30 Nov 2022 10:10:10 +0100 Subject: [PATCH] Optimizada la intro --- source/intro.cpp | 116 ++++++++++------------------------------------- source/intro.h | 4 +- 2 files changed, 24 insertions(+), 96 deletions(-) diff --git a/source/intro.cpp b/source/intro.cpp index bb45c8a..ed99691 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -36,17 +36,8 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset * ticks = 0; ticksSpeed = 15; loadCounter = 0; - lineCounter = 0; loadingFirstPart = true; - loadRect = {0, 0, 50, 1}; - - // Ls lineas que tapan la primera textura - for (int i = 0; i < 192; ++i) - { - lines[i].x1 = 0; - lines[i].x2 = 257; - lines[i].y = i; - } + loadRect = {0, 0, 51, 1}; // Establece el orden de las lineas para imitar el direccionamiento de memoria del spectrum for (int i = 0; i < 192; ++i) @@ -152,40 +143,14 @@ void Intro::updateLoad() { // Primera parte de la carga, la parte en blanco ynegro if (loadingFirstPart) - /*{ - // Cada 5 pasos el loadCounter se incrementa en uno - const int numSteps = 5; - loadCounter = counter / numSteps; - - if (loadCounter < 192) - { - const int step = 256 / numSteps; - lines[lineIndex[loadCounter]].x1 = step * (counter % numSteps); - - // Elimina por completo la linea anterior - if (loadCounter > 0) - { - lines[lineIndex[loadCounter - 1]].x1 = 256; - } - } - - // Una vez actualizadas las 192 lineas, pasa a la segunda fase de la carga - else if (loadCounter == 192) - { - loadingFirstPart = false; - loadCounter = 0; - JA_PlayMusic(loadingSound3); - } - }*/ { // Cada 5 pasos el loadCounter se incrementa en uno const int numSteps = 5; + const int step = 51; loadCounter = counter / numSteps; if (loadCounter < 192) { - const int step = 256 / numSteps; - lines[lineIndex[loadCounter]].x1 = step * (counter % numSteps); loadRect.x = step * (counter % numSteps); loadRect.y = lineIndex[loadCounter]; sprite1->setSpriteClip(loadRect); @@ -196,6 +161,9 @@ void Intro::updateLoad() { loadingFirstPart = false; loadCounter = 0; + loadRect = {0, 0, 16, 8}; + sprite2->setRect(loadRect); + sprite2->setSpriteClip(loadRect); JA_PlayMusic(loadingSound3); } } @@ -203,60 +171,36 @@ void Intro::updateLoad() else { loadCounter += 2; - loadCounter = std::min(loadCounter, 768); + loadRect.x = (loadCounter * 8) % 256; + loadRect.y = (loadCounter / 32) * 8; + sprite2->setSpriteClip(loadRect); + sprite2->setRect(loadRect); + + // Comprueba si ha terminado la intro + if (loadCounter >= 768) + { + section.name = SECTION_PROG_TITLE; + section.subsection = 0; + JA_StopMusic(); + } } } // Gestiona el contador interno void Intro::updateCounter() { - if (preCounter >= 50) - { // Si el contador previo ha llegado a 50, empieza a contar el contador normal - if (counter == 0) - { - JA_PlayMusic(loadingSound2); - } - counter++; - } - else - { // Actualiza el precontador - preCounter++; + (preCounter >= 50) ? counter++ : preCounter++; + + if (counter == 1) + { + JA_PlayMusic(loadingSound2); } } // Dibuja la pantalla de carga void Intro::renderLoad() { - // Carga 1 - Blanco y negro - if (loadingFirstPart) - /*{ - // Dibuja la textura de pantalla de carga en blanco y negro en pantalla - sprite1->render(); - - // Dibuja las 192 lineas negras sobre la textura - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); - for (int i = 0; i < 192; ++i) - { - SDL_RenderDrawLine(renderer, lines[i].x1, lines[i].y, lines[i].x2, lines[i].y); - } - }*/ - { - sprite1->render(); - } - else - // Carga 2 - Color - { - sprite1->render(); - SDL_Rect rect = {0, 0, 8, 8}; - for (int i = 0; i < loadCounter; ++i) - { - rect.x = (i * 8) % 256; - rect.y = (i / 32) * 8; - sprite2->setRect(rect); - sprite2->setSpriteClip(rect); - sprite2->render(); - } - } + loadingFirstPart ? sprite1->render() : sprite2->render(); } // Actualiza las variables @@ -279,14 +223,6 @@ void Intro::update() // Actualiza las notificaciones screen->updateNotifier(); - - // Comprueba si ha terminado la intro - if (loadCounter >= 768) - { - section.name = SECTION_PROG_TITLE; - section.subsection = 0; - JA_StopMusic(); - } } } @@ -296,12 +232,6 @@ void Intro::render() // Prepara para empezar a dibujar en la textura de juego screen->start(); - // Limpia la pantalla - // screen->clean(); - - if (!loadingFirstPart) - screen->clean(); - // Dibuja la pantalla de carga renderLoad(); diff --git a/source/intro.h b/source/intro.h index 5c40bb8..691827e 100644 --- a/source/intro.h +++ b/source/intro.h @@ -38,14 +38,12 @@ private: Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa int loadCounter; // Contador para controlar las cargas - int lineCounter; // Contador para dibujar las lineas de carga bool loadingFirstPart; // Para saber en que parte de la carga se encuentra JA_Music loadingSound1; // Sonidos para imitar la carga tipo spectrum JA_Music loadingSound2; // Sonidos para imitar la carga tipo spectrum JA_Music loadingSound3; // Sonidos para imitar la carga tipo spectrum - h_line_t lines[192]; // Las 192 lineas que forman la pantalla de carga int lineIndex[192]; // El orden en el que se procesan las 192 lineas de la pantalla de carga - SDL_Rect loadRect; + SDL_Rect loadRect; // Rectangulo para dibujar la pantalla de carga // Actualiza las variables void update();