Optimizado el renderizado de notificaciones

This commit is contained in:
2022-11-18 19:26:31 +01:00
parent 74d5bbddaa
commit ea994bcc2f
6 changed files with 42 additions and 40 deletions

View File

@@ -141,3 +141,14 @@ void Notify::showText(std::string text)
// Añade la notificación a la lista // Añade la notificación a la lista
notifications.push_back(n); notifications.push_back(n);
} }
// Indica si hay notificaciones activas
bool Notify::active()
{
if ((int)notifications.size() > 0)
{
return true;
}
return false;
}

View File

@@ -73,6 +73,9 @@ public:
// Muestra una notificación de texto por pantalla; // Muestra una notificación de texto por pantalla;
void showText(std::string text); void showText(std::string text);
// Indica si hay notificaciones activas
bool active();
}; };
#endif #endif

View File

@@ -12,7 +12,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
this->asset = asset; this->asset = asset;
// Crea los objetos // Crea los objetos
//notify = new Notify(renderer, asset->get("smb2_big.png"), asset->get("smb2_big.txt"));
notify = new Notify(renderer, asset->get("smb2.png"), asset->get("smb2.txt")); notify = new Notify(renderer, asset->get("smb2.png"), asset->get("smb2.txt"));
gameCanvasWidth = gameInternalResX; gameCanvasWidth = gameInternalResX;
@@ -41,6 +40,9 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
anchor.top = 0; anchor.top = 0;
anchor.bottom = gameCanvasHeight; anchor.bottom = gameCanvasHeight;
anchor.middle = gameCanvasHeight / 2; anchor.middle = gameCanvasHeight / 2;
// Inicializa variables
notifyActive = false;
} }
// Destructor // Destructor
@@ -171,15 +173,7 @@ void Screen::setVideoMode(int fullScreenMode)
// Camibia entre pantalla completa y ventana // Camibia entre pantalla completa y ventana
void Screen::switchVideoMode() void Screen::switchVideoMode()
{ {
if (options->fullScreenMode == 0) options->fullScreenMode = (options->fullScreenMode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
{
options->fullScreenMode = SDL_WINDOW_FULLSCREEN_DESKTOP;
}
else
{
options->fullScreenMode = 0;
}
setVideoMode(options->fullScreenMode); setVideoMode(options->fullScreenMode);
} }
@@ -303,30 +297,12 @@ void Screen::iniSpectrumFade()
spectrumColor.clear(); spectrumColor.clear();
color_t c; // Inicializa el vector de colores
c = stringToColor("black"); const std::vector<std::string> vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"};
spectrumColor.push_back(c); for (auto v : vColors)
{
c = stringToColor("blue"); spectrumColor.push_back(stringToColor(p_zxspectrum, v));
spectrumColor.push_back(c); }
c = stringToColor("red");
spectrumColor.push_back(c);
c = stringToColor("magenta");
spectrumColor.push_back(c);
c = stringToColor("green");
spectrumColor.push_back(c);
c = stringToColor("cyan");
spectrumColor.push_back(c);
c = stringToColor("yellow");
spectrumColor.push_back(c);
c = stringToColor("bright_white");
spectrumColor.push_back(c);
} }
// Actualiza el spectrum fade // Actualiza el spectrum fade
@@ -378,6 +354,7 @@ void Screen::renderFX()
void Screen::updateNotifier() void Screen::updateNotifier()
{ {
notify->update(); notify->update();
notifyActive = notify->active();
} }
// Muestra una notificación de texto por pantalla; // Muestra una notificación de texto por pantalla;
@@ -389,6 +366,11 @@ void Screen::showText(std::string text)
// Dibuja las notificaciones // Dibuja las notificaciones
void Screen::renderNotifications() void Screen::renderNotifications()
{ {
if (!notifyActive)
{
return;
}
SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight); SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight);
notify->render(); notify->render();
SDL_RenderSetLogicalSize(renderer, gameCanvasWidth, gameCanvasHeight); SDL_RenderSetLogicalSize(renderer, gameCanvasWidth, gameCanvasHeight);

View File

@@ -41,6 +41,7 @@ private:
anchor_t anchor; // Variable con los anclajes de la pantalla anchor_t anchor; // Variable con los anclajes de la pantalla
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana 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 color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
bool notifyActive; // Indica si hay notificaciones activas
// EFECTOS // EFECTOS
bool fade; // Indica si esta activo el efecto de fade bool fade; // Indica si esta activo el efecto de fade

View File

@@ -380,11 +380,9 @@ bool checkCollision(SDL_Point &p, d_line_t &l)
} }
// Devuelve un color_t a partir de un string // Devuelve un color_t a partir de un string
color_t stringToColor(std::string str) color_t stringToColor(palette_e pal, std::string str)
{ {
const std::string palette = "spectrum"; if (pal == p_zxspectrum)
if (palette == "spectrum")
{ {
if (str == "black") if (str == "black")
{ {
@@ -467,7 +465,7 @@ color_t stringToColor(std::string str)
} }
} }
else else if (pal == p_zxarne)
{ // zxarne { // zxarne
if (str == "black") if (str == "black")
{ {

View File

@@ -57,6 +57,13 @@ struct color_t
Uint8 b; Uint8 b;
}; };
// Tipos de paleta
enum palette_e
{
p_zxspectrum,
p_zxarne
};
// Estructura para saber la seccion y subseccion del programa // Estructura para saber la seccion y subseccion del programa
struct section_t struct section_t
{ {
@@ -151,7 +158,7 @@ bool checkCollision(SDL_Point &p, d_line_t &l);
void normalizeLine(d_line_t &l); void normalizeLine(d_line_t &l);
// Devuelve un color_t a partir de un string // Devuelve un color_t a partir de un string
color_t stringToColor(std::string str); color_t stringToColor(palette_e pal, std::string str);
// Convierte una cadena en un valor booleano // Convierte una cadena en un valor booleano
bool stringToBool(std::string str); bool stringToBool(std::string str);