diff --git a/source/director.cpp b/source/director.cpp index 1bf02cf..b622b65 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -1,9 +1,9 @@ #include "director.h" #include -#include // for errno, EEXIST, EACCES, ENAMETOO... -#include // for printf, perror -#include // for strcmp +#include // for errno, EEXIST, EACCES, ENAMETOO... +#include // for printf, perror +#include // for strcmp #ifndef __EMSCRIPTEN__ #include // for mkdir, stat, S_IRWXU #include // for getuid @@ -91,6 +91,14 @@ Director::Director(int argc, const char *argv[]) { Director::~Director() { saveConfigFile(); + // Libera las secciones primero: sus destructores tocan audio/render SDL + // (p.ej. Intro::~Intro llama a JA_DeleteMusic) y deben ejecutarse antes + // de SDL_Quit(). + logo.reset(); + intro.reset(); + title.reset(); + game.reset(); + delete asset; delete input; delete screen; diff --git a/source/director.h b/source/director.h index 8d6885f..31b5c15 100644 --- a/source/director.h +++ b/source/director.h @@ -19,7 +19,11 @@ struct section_t; constexpr const char *WINDOW_CAPTION = "© 2020 Coffee Crisis — JailDesigner"; // Secciones activas del Director -enum class ActiveSection { None, Logo, Intro, Title, Game }; +enum class ActiveSection { None, + Logo, + Intro, + Title, + Game }; class Director { private: diff --git a/source/mouse.cpp b/source/mouse.cpp index 133d9d8..85f6fdd 100644 --- a/source/mouse.cpp +++ b/source/mouse.cpp @@ -1,9 +1,9 @@ #include "mouse.hpp" namespace Mouse { - Uint32 cursorHideTime = 3000; // Tiempo en milisegundos para ocultar el cursor por inactividad - Uint32 lastMouseMoveTime = 0; // Última vez que el ratón se movió - bool cursorVisible = true; // Estado del cursor + Uint32 cursorHideTime = 3000; // Tiempo en milisegundos para ocultar el cursor por inactividad + Uint32 lastMouseMoveTime = 0; // Última vez que el ratón se movió + bool cursorVisible = true; // Estado del cursor void handleEvent(const SDL_Event &event, bool fullscreen) { if (event.type == SDL_EVENT_MOUSE_MOTION) { diff --git a/source/screen.cpp b/source/screen.cpp index 1e02a13..182accf 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -23,9 +23,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options borderWidth = options->borderWidth * 2; borderHeight = options->borderHeight * 2; - iniFade(); - iniSpectrumFade(); - // Define el color del borde para el modo de pantalla completa borderColor = {0x00, 0x00, 0x00}; @@ -243,120 +240,6 @@ void Screen::switchBorder() { setVideoMode(0); } -// Activa el fade -void Screen::setFade() { - fade = true; -} - -// Comprueba si ha terminado el fade -bool Screen::fadeEnded() { - if (fade || fadeCounter > 0) { - return false; - } - - return true; -} - -// Activa el spectrum fade -void Screen::setspectrumFade() { - spectrumFade = true; -} - -// Comprueba si ha terminado el spectrum fade -bool Screen::spectrumFadeEnded() { - if (spectrumFade || spectrumFadeCounter > 0) { - return false; - } - - return true; -} - -// Inicializa las variables para el fade -void Screen::iniFade() { - fade = false; - fadeCounter = 0; - fadeLenght = 200; -} - -// Actualiza el fade -void Screen::updateFade() { - if (!fade) { - return; - } - - fadeCounter++; - if (fadeCounter > fadeLenght) { - iniFade(); - } -} - -// Dibuja el fade -void Screen::renderFade() { - if (!fade) { - return; - } - - const SDL_FRect rect = {0, 0, (float)gameCanvasWidth, (float)gameCanvasHeight}; - color_t color = {0, 0, 0}; - const float step = (float)fadeCounter / (float)fadeLenght; - const int alpha = 0 + (255 - 0) * step; - SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, alpha); - SDL_RenderFillRect(renderer, &rect); -} - -// Inicializa las variables para el fade spectrum -void Screen::iniSpectrumFade() { - spectrumFade = false; - spectrumFadeCounter = 0; - spectrumFadeLenght = 50; - - spectrumColor.clear(); - - // Inicializa el vector de colores - const std::vector vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"}; - for (auto v : vColors) { - spectrumColor.push_back(stringToColor(options->palette, v)); - } -} - -// Actualiza el spectrum fade -void Screen::updateSpectrumFade() { - if (!spectrumFade) { - return; - } - - spectrumFadeCounter++; - if (spectrumFadeCounter > spectrumFadeLenght) { - iniSpectrumFade(); - SDL_SetTextureColorMod(gameCanvas, 255, 255, 255); - } -} - -// Dibuja el spectrum fade -void Screen::renderSpectrumFade() { - if (!spectrumFade) { - return; - } - - const float step = (float)spectrumFadeCounter / (float)spectrumFadeLenght; - const int max = spectrumColor.size() - 1; - const int index = max + (0 - max) * step; - const color_t c = spectrumColor[index]; - SDL_SetTextureColorMod(gameCanvas, c.r, c.g, c.b); -} - -// Actualiza los efectos -void Screen::updateFX() { - updateFade(); - updateSpectrumFade(); -} - -// Dibuja los efectos -void Screen::renderFX() { - renderFade(); - renderSpectrumFade(); -} - // Muestra una notificación en la línea superior durante durationMs void Screen::notify(const std::string &text, color_t textColor, color_t outlineColor, Uint32 durationMs) { notificationMessage = text; @@ -377,7 +260,11 @@ void Screen::renderNotification() { return; } notificationText->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, - gameCanvasWidth / 2, notificationY, - notificationMessage, 1, - notificationTextColor, 1, notificationOutlineColor); + gameCanvasWidth / 2, + notificationY, + notificationMessage, + 1, + notificationTextColor, + 1, + notificationOutlineColor); } \ No newline at end of file diff --git a/source/screen.h b/source/screen.h index 9a793bb..c667b6d 100644 --- a/source/screen.h +++ b/source/screen.h @@ -3,7 +3,6 @@ #include #include // for string -#include // for vector #include "utils.h" // for color_t class Asset; @@ -23,14 +22,14 @@ class Screen { options_t *options; // Variable con todas las opciones del programa // Variables - int windowWidth; // Ancho de la pantalla o ventana - int windowHeight; // Alto de la pantalla o ventana - int gameCanvasWidth; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego - int gameCanvasHeight; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego - int borderWidth; // Anchura del borde - int borderHeight; // Anltura del borde - SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana - color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla + int windowWidth; // Ancho de la pantalla o ventana + int windowHeight; // Alto de la pantalla o ventana + int gameCanvasWidth; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego + int gameCanvasHeight; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego + int borderWidth; // Anchura del borde + int borderHeight; // Anltura del borde + SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana + color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla // Notificaciones - una sola activa, sin apilación ni animaciones Text *notificationText; // Fuente 8bithud dedicada a las notificaciones @@ -43,33 +42,6 @@ class Screen { // Dibuja la notificación activa (si la hay) sobre el gameCanvas void renderNotification(); - // Variables - Efectos - bool fade; // Indica si esta activo el efecto de fade - int fadeCounter; // Temporizador para el efecto de fade - int fadeLenght; // Duración del fade - bool spectrumFade; // Indica si esta activo el efecto de fade spectrum - int spectrumFadeCounter; // Temporizador para el efecto de fade spectrum - int spectrumFadeLenght; // Duración del fade spectrum - std::vector spectrumColor; // Colores para el fade spectrum - - // Inicializa las variables para el fade - void iniFade(); - - // Actualiza el fade - void updateFade(); - - // Dibuja el fade - void renderFade(); - - // Inicializa las variables para el fade spectrum - void iniSpectrumFade(); - - // Actualiza el spectrum fade - void updateSpectrumFade(); - - // Dibuja el spectrum fade - void renderSpectrumFade(); - public: // Constructor Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options); @@ -117,24 +89,6 @@ class Screen { // Cambia entre borde visible y no visible void switchBorder(); - // Activa el fade - void setFade(); - - // Comprueba si ha terminado el fade - bool fadeEnded(); - - // Activa el spectrum fade - void setspectrumFade(); - - // Comprueba si ha terminado el spectrum fade - bool spectrumFadeEnded(); - - // Actualiza los efectos - void updateFX(); - - // Dibuja los efectos - void renderFX(); - // Muestra una notificación en la línea superior del canvas durante durationMs. // Sobrescribe cualquier notificación activa (sin apilación). void notify(const std::string &text, color_t textColor, color_t outlineColor, Uint32 durationMs); diff --git a/source/title.cpp b/source/title.cpp index 48973c5..39dee16 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -651,7 +651,7 @@ void Title::checkInput() { section->name = SECTION_PROG_QUIT; } else #endif - if (input->checkInput(input_window_fullscreen, REPEAT_FALSE)) { + if (input->checkInput(input_window_fullscreen, REPEAT_FALSE)) { screen->switchVideoMode(); }