fix: petada per tancar mal director (supose que introduit per Claude al pasar a sdl_callbacks)

eliminat codi mort d'screen
This commit is contained in:
2026-04-13 16:44:27 +02:00
parent 86323a0e56
commit 66c3e0089c
6 changed files with 35 additions and 182 deletions

View File

@@ -91,6 +91,14 @@ Director::Director(int argc, const char *argv[]) {
Director::~Director() { Director::~Director() {
saveConfigFile(); 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 asset;
delete input; delete input;
delete screen; delete screen;

View File

@@ -19,7 +19,11 @@ struct section_t;
constexpr const char *WINDOW_CAPTION = "© 2020 Coffee Crisis — JailDesigner"; constexpr const char *WINDOW_CAPTION = "© 2020 Coffee Crisis — JailDesigner";
// Secciones activas del Director // Secciones activas del Director
enum class ActiveSection { None, Logo, Intro, Title, Game }; enum class ActiveSection { None,
Logo,
Intro,
Title,
Game };
class Director { class Director {
private: private:

View File

@@ -23,9 +23,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
borderWidth = options->borderWidth * 2; borderWidth = options->borderWidth * 2;
borderHeight = options->borderHeight * 2; borderHeight = options->borderHeight * 2;
iniFade();
iniSpectrumFade();
// Define el color del borde para el modo de pantalla completa // Define el color del borde para el modo de pantalla completa
borderColor = {0x00, 0x00, 0x00}; borderColor = {0x00, 0x00, 0x00};
@@ -243,120 +240,6 @@ void Screen::switchBorder() {
setVideoMode(0); 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<std::string> 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 // 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) { void Screen::notify(const std::string &text, color_t textColor, color_t outlineColor, Uint32 durationMs) {
notificationMessage = text; notificationMessage = text;
@@ -377,7 +260,11 @@ void Screen::renderNotification() {
return; return;
} }
notificationText->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, notificationText->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE,
gameCanvasWidth / 2, notificationY, gameCanvasWidth / 2,
notificationMessage, 1, notificationY,
notificationTextColor, 1, notificationOutlineColor); notificationMessage,
1,
notificationTextColor,
1,
notificationOutlineColor);
} }

View File

@@ -3,7 +3,6 @@
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
#include <string> // for string #include <string> // for string
#include <vector> // for vector
#include "utils.h" // for color_t #include "utils.h" // for color_t
class Asset; class Asset;
@@ -43,33 +42,6 @@ class Screen {
// Dibuja la notificación activa (si la hay) sobre el gameCanvas // Dibuja la notificación activa (si la hay) sobre el gameCanvas
void renderNotification(); 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<color_t> 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: public:
// Constructor // Constructor
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options); 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 // Cambia entre borde visible y no visible
void switchBorder(); 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. // Muestra una notificación en la línea superior del canvas durante durationMs.
// Sobrescribe cualquier notificación activa (sin apilación). // Sobrescribe cualquier notificación activa (sin apilación).
void notify(const std::string &text, color_t textColor, color_t outlineColor, Uint32 durationMs); void notify(const std::string &text, color_t textColor, color_t outlineColor, Uint32 durationMs);