Eliminada gran cantidad de código sobrante

This commit is contained in:
2024-05-31 17:27:46 +02:00
parent 514372c9f0
commit d13e4daf25
9 changed files with 122 additions and 614 deletions

View File

@@ -14,31 +14,23 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
// Crea los objetos
notify = new Notify(renderer, asset->get("notify.png"), asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav"), options);
gameCanvasWidth = options->gameWidth;
gameCanvasHeight = options->gameHeight;
borderWidth = options->borderWidth * 2;
borderHeight = options->borderHeight * 2;
gameCanvasWidth = options->video.gameWidth;
gameCanvasHeight = options->video.gameHeight;
borderWidth = options->video.borderWidth * 2;
borderHeight = options->video.borderHeight * 2;
notificationLogicalWidth = gameCanvasWidth;
notificationLogicalHeight = gameCanvasHeight;
iniFade();
iniSpectrumFade();
// Define el color del borde para el modo de pantalla completa
borderColor = {0x00, 0x00, 0x00};
// Crea la textura donde se dibujan los graficos del juego
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
if (gameCanvas == nullptr)
{
if (options->console)
{
std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
// Establece el modo de video
setVideoMode(options->videoMode);
setVideoMode(options->video.mode);
// Inicializa variables
notifyActive = false;
@@ -99,7 +91,7 @@ void Screen::setVideoMode(int videoMode)
// Esconde la ventana
//SDL_HideWindow(window);
if (options->borderEnabled)
if (options->video.borderEnabled)
{
windowWidth = gameCanvasWidth + borderWidth;
windowHeight = gameCanvasHeight + borderHeight;
@@ -114,7 +106,7 @@ void Screen::setVideoMode(int videoMode)
}
// Modifica el tamaño de la ventana
SDL_SetWindowSize(window, windowWidth * options->windowSize, windowHeight * options->windowSize);
SDL_SetWindowSize(window, windowWidth * options->video.windowSize, windowHeight * options->video.windowSize);
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
// Muestra la ventana
@@ -131,7 +123,7 @@ void Screen::setVideoMode(int videoMode)
SDL_GetWindowSize(window, &windowWidth, &windowHeight);
// Aplica el escalado al rectangulo donde se pinta la textura del juego
if (options->integerScale)
if (options->video.integerScale)
{
// Calcula el tamaño de la escala máxima
int scale = 0;
@@ -145,7 +137,7 @@ void Screen::setVideoMode(int videoMode)
dest.x = (windowWidth - dest.w) / 2;
dest.y = (windowHeight - dest.h) / 2;
}
else if (options->keepAspect)
else if (options->video.keepAspect)
{
float ratio = (float)gameCanvasWidth / (float)gameCanvasHeight;
if ((windowWidth - gameCanvasWidth) >= (windowHeight - gameCanvasHeight))
@@ -175,9 +167,9 @@ void Screen::setVideoMode(int videoMode)
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
// Actualiza las opciones
options->videoMode = videoMode;
options->screen.windowWidth = windowWidth;
options->screen.windowHeight = windowHeight;
options->video.mode = videoMode;
options->video.windowWidth = windowWidth;
options->video.windowHeight = windowHeight;
// Establece el tamaño de las notificaciones
setNotificationSize();
@@ -186,30 +178,30 @@ void Screen::setVideoMode(int videoMode)
// Camibia entre pantalla completa y ventana
void Screen::switchVideoMode()
{
options->videoMode = (options->videoMode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
setVideoMode(options->videoMode);
options->video.mode = (options->video.mode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
setVideoMode(options->video.mode);
}
// Cambia el tamaño de la ventana
void Screen::setWindowSize(int size)
{
options->windowSize = size;
options->video.windowSize = size;
setVideoMode(0);
}
// Reduce el tamaño de la ventana
void Screen::decWindowSize()
{
--options->windowSize;
options->windowSize = std::max(options->windowSize, 1);
--options->video.windowSize;
options->video.windowSize = std::max(options->video.windowSize, 1);
setVideoMode(0);
}
// Aumenta el tamaño de la ventana
void Screen::incWindowSize()
{
++options->windowSize;
options->windowSize = std::min(options->windowSize, 4);
++options->video.windowSize;
options->video.windowSize = std::min(options->video.windowSize, 4);
setVideoMode(0);
}
@@ -228,25 +220,25 @@ void Screen::setBlendMode(SDL_BlendMode blendMode)
// Establece el tamaño del borde
void Screen::setBorderWidth(int s)
{
options->borderWidth = s;
options->video.borderWidth = s;
}
// Establece el tamaño del borde
void Screen::setBorderHeight(int s)
{
options->borderHeight = s;
options->video.borderHeight = s;
}
// Establece si se ha de ver el borde en el modo ventana
void Screen::setBorderEnabled(bool value)
{
options->borderEnabled = value;
options->video.borderEnabled = value;
}
// Cambia entre borde visible y no visible
void Screen::switchBorder()
{
options->borderEnabled = !options->borderEnabled;
options->video.borderEnabled = !options->video.borderEnabled;
setVideoMode(0);
}
@@ -323,66 +315,16 @@ void Screen::renderFade()
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();
}
// Actualiza el notificador
@@ -414,9 +356,9 @@ void Screen::renderNotifications()
// Establece el tamaño de las notificaciones
void Screen::setNotificationSize()
{
if (options->videoMode == 0)
if (options->video.mode == 0)
{
if (options->windowSize == 3)
if (options->video.windowSize == 3)
{
notificationLogicalWidth = (windowWidth * 3) / 2;
notificationLogicalHeight = (windowHeight * 3) / 2;
@@ -428,7 +370,7 @@ void Screen::setNotificationSize()
}
}
if (options->videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
if (options->video.mode == SDL_WINDOW_FULLSCREEN_DESKTOP)
{
notificationLogicalWidth = windowWidth / 3;
notificationLogicalHeight = windowHeight / 3;