Cambiado de showFps a showInfo

This commit is contained in:
2024-09-09 22:51:26 +02:00
parent e1fb069010
commit 824bc08077
4 changed files with 45 additions and 33 deletions

View File

@@ -37,7 +37,7 @@ enum inputs_e
input_video_shaders,
input_reset,
input_mute,
input_showfps,
input_showinfo,
// Input obligatorio
input_null,

View File

@@ -39,14 +39,16 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input *
fpsCounter = 0;
fps = 0;
#ifdef DEBUG
showFps = true;
showInfo = true;
#else
showFps = false;
showInfo = false;
#endif
SDL_DisplayMode DM;
SDL_GetCurrentDisplayMode(0, &DM);
displayWidth = DM.w;
displayHeight = DM.h;
displayRefreshRate = DM.refresh_rate;
infoResolution = std::to_string(displayWidth) + " X " + std::to_string(displayHeight) + " AT " + std::to_string(displayRefreshRate) + " HZ";
// Crea los objetos
notify = new Notify(renderer, asset->get("notify.png"), asset->get("8bithud.png"), asset->get("8bithud.txt"), asset->get("notify.wav"), options);
@@ -93,23 +95,14 @@ void Screen::blit()
// Atenua la pantalla
doAttenuate();
// Pinta las notificaciones
notify->render();
// Actualiza el contador de FPS
fpsCounter++;
// Pinta en pantalla el contador de FPS
if (showFps)
{
// FPS
const std::string fpstext = std::to_string(fps) + " FPS";
dbg_print(0, 0, fpstext.c_str(), 255, 255, 255);
// Resolution
const std::string resolution = std::to_string(displayWidth) + " X " + std::to_string(displayHeight);
dbg_print(0, 8, resolution.c_str(), 255, 255, 255);
}
// Muestra información por pantalla
displayInfo();
// Muestra las notificaciones
notify->render();
#ifdef NO_SHADERS
// Vuelve a dejar el renderizador en modo normal
@@ -341,9 +334,9 @@ void Screen::checkInput()
}
#endif
if (input->checkInput(input_showfps, DO_NOT_ALLOW_REPEAT))
if (input->checkInput(input_showinfo, DO_NOT_ALLOW_REPEAT))
{
showFps = !showFps;
showInfo = !showInfo;
}
}
@@ -458,4 +451,18 @@ void Screen::updateFPS()
fps = fpsCounter;
fpsCounter = 0;
}
}
// Muestra información por pantalla
void Screen::displayInfo()
{
if (showInfo)
{
// FPS
const std::string fpstext = std::to_string(fps) + " FPS";
dbg_print(gameCanvasWidth - fpstext.length() * 8, 0, fpstext.c_str(), 255, 255, 0);
// Resolution
dbg_print(0, 0, infoResolution.c_str(), 255, 255, 0);
}
}

View File

@@ -27,19 +27,21 @@ private:
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
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
bool attenuateEffect; // Indica si la pantalla ha de estar atenuada
Uint32 fpsTicks; // Ticks para contar los frames por segundo
int fpsCounter; // Contador de frames por segundo
int fps; // Frames calculados en el último segundo
bool showFps; // Indica si ha de mostrar/ocultar la información de los frames por segundo en pantalla
int displayWidth; // Anchura de la pantalla
int displayHeight; // Altura de 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
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
bool attenuateEffect; // Indica si la pantalla ha de estar atenuada
Uint32 fpsTicks; // Ticks para contar los frames por segundo
int fpsCounter; // Contador de frames por segundo
int fps; // Frames calculados en el último segundo
bool showInfo; // Indica si ha de mostrar/ocultar la información de la pantalla
int displayWidth; // Anchura de la pantalla
int displayHeight; // Altura de la pantalla
int displayRefreshRate; // Frecuencia de refresco de la pantalla
std::string infoResolution; // Texto con la informacion de la pantalla
struct effect_t
{
@@ -74,6 +76,9 @@ private:
// Calcula los frames por segundo
void updateFPS();
// Muestra información por pantalla
void displayInfo();
public:
// Constructor
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input *input, options_t *options);

View File

@@ -135,7 +135,7 @@ void Director::initInput()
input->bindKey(input_window_fullscreen, SDL_SCANCODE_F3);
input->bindKey(input_video_shaders, SDL_SCANCODE_F4);
input->bindKey(input_mute, SDL_SCANCODE_F5);
input->bindKey(input_showfps, SDL_SCANCODE_F6);
input->bindKey(input_showinfo, SDL_SCANCODE_F6);
input->bindKey(input_reset, SDL_SCANCODE_F10);
const int numGamePads = input->getNumControllers();