afegit comptador de frames per segon
This commit is contained in:
@@ -244,6 +244,7 @@ void Director::initInput()
|
||||
Input::get()->bindKey(InputAction::NEXT_PALETTE, SDL_SCANCODE_F5);
|
||||
Input::get()->bindKey(InputAction::PREVIOUS_PALETTE, SDL_SCANCODE_F6);
|
||||
Input::get()->bindKey(InputAction::TOGGLE_INTEGER_SCALE, SDL_SCANCODE_F7);
|
||||
Input::get()->bindKey(InputAction::SHOW_DEBUG_INFO, SDL_SCANCODE_F12);
|
||||
Input::get()->bindKey(InputAction::TOGGLE_MUSIC, SDL_SCANCODE_M);
|
||||
Input::get()->bindKey(InputAction::TOGGLE_BORDER, SDL_SCANCODE_B);
|
||||
|
||||
|
||||
@@ -114,5 +114,10 @@ namespace globalInputs
|
||||
Screen::get()->setVideoMode(options.video.mode);
|
||||
Notifier::get()->show({"INTEGER SCALE " + std::string(options.video.integer_scale ? "ENABLED" : "DISABLED")}, NotificationText::CENTER);
|
||||
}
|
||||
|
||||
else if (Input::get()->checkInput(InputAction::SHOW_DEBUG_INFO, INPUT_DO_NOT_ALLOW_REPEAT))
|
||||
{
|
||||
Screen::get()->toggleDebugInfo();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,7 @@ enum class InputAction
|
||||
NEXT_PALETTE,
|
||||
PREVIOUS_PALETTE,
|
||||
TOGGLE_SHADERS,
|
||||
SHOW_DEBUG_INFO,
|
||||
|
||||
// Input obligatorio
|
||||
NONE,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <SDL2/SDL_events.h> // Para SDL_DISABLE, SDL_ENABLE
|
||||
#include <SDL2/SDL_mouse.h> // Para SDL_ShowCursor
|
||||
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORM...
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <ctype.h> // Para toupper
|
||||
#include <algorithm> // Para max, min, transform
|
||||
#include <fstream> // Para basic_ostream, operator<<, endl, basic_...
|
||||
@@ -16,6 +17,7 @@
|
||||
#include "options.h" // Para Options, options, OptionsVideo, Border
|
||||
#include "resource.h" // Para Resource
|
||||
#include "surface.h" // Para Surface, readPalFile
|
||||
#include "text.h" // Para Text
|
||||
|
||||
// [SINGLETON]
|
||||
Screen *Screen::screen_ = nullptr;
|
||||
@@ -44,6 +46,11 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
renderer_(renderer),
|
||||
palettes_(Asset::get()->getListByType(AssetType::PALETTE))
|
||||
{
|
||||
// Inicializa variables
|
||||
SDL_DisplayMode DM;
|
||||
SDL_GetCurrentDisplayMode(0, &DM);
|
||||
info_resolution_ = std::to_string(DM.w) + " X " + std::to_string(DM.h) + " AT " + std::to_string(DM.refresh_rate) + " HZ";
|
||||
|
||||
// Ajusta los tamaños
|
||||
adjustGameCanvasRect();
|
||||
adjustWindowSize();
|
||||
@@ -142,6 +149,8 @@ void Screen::start()
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
void Screen::render()
|
||||
{
|
||||
fps_.increment();
|
||||
|
||||
// Renderiza todos los overlays
|
||||
renderOverlays();
|
||||
|
||||
@@ -262,6 +271,7 @@ void Screen::toggleShaders()
|
||||
// Actualiza la lógica de la clase
|
||||
void Screen::update()
|
||||
{
|
||||
fps_.calculate(SDL_GetTicks());
|
||||
Notifier::get()->update();
|
||||
Mouse::updateCursorVisibility();
|
||||
}
|
||||
@@ -442,6 +452,7 @@ void Screen::textureToRenderer()
|
||||
void Screen::renderOverlays()
|
||||
{
|
||||
renderNotifications();
|
||||
renderInfo();
|
||||
}
|
||||
|
||||
// Localiza la paleta dentro del vector de paletas
|
||||
@@ -480,3 +491,20 @@ void Screen::createShadersTexture()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Muestra información por pantalla
|
||||
void Screen::renderInfo()
|
||||
{
|
||||
if (show_debug_info_ && Resource::get())
|
||||
{
|
||||
auto text = Resource::get()->getText("smb2");
|
||||
auto color = static_cast<Uint8>(PaletteColor::YELLOW);
|
||||
|
||||
// FPS
|
||||
const std::string FPS_TEXT = std::to_string(fps_.lastValue) + " FPS";
|
||||
text->writeColored(options.game.width - text->lenght(FPS_TEXT), 0, FPS_TEXT, color);
|
||||
|
||||
// Resolution
|
||||
text->writeColored(0, 0, info_resolution_, color);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,35 @@ enum class ScreenFilter : Uint32
|
||||
class Screen
|
||||
{
|
||||
private:
|
||||
// Estructuras
|
||||
struct FPS
|
||||
{
|
||||
Uint32 ticks; // Tiempo en milisegundos desde que se comenzó a contar.
|
||||
int frameCount; // Número acumulado de frames en el intervalo.
|
||||
int lastValue; // Número de frames calculado en el último segundo.
|
||||
|
||||
// Constructor para inicializar la estructura.
|
||||
FPS() : ticks(0), frameCount(0), lastValue(0) {}
|
||||
|
||||
// Incrementador que se llama en cada frame.
|
||||
void increment()
|
||||
{
|
||||
frameCount++;
|
||||
}
|
||||
|
||||
// Método para calcular y devolver el valor de FPS.
|
||||
int calculate(Uint32 currentTicks)
|
||||
{
|
||||
if (currentTicks - ticks >= 1000) // Si ha pasado un segundo o más.
|
||||
{
|
||||
lastValue = frameCount; // Actualizamos el valor del último FPS.
|
||||
frameCount = 0; // Reiniciamos el contador de frames.
|
||||
ticks = currentTicks; // Actualizamos el tiempo base.
|
||||
}
|
||||
return lastValue;
|
||||
}
|
||||
};
|
||||
|
||||
// Constantes
|
||||
static constexpr int WINDOWS_DECORATIONS_ = 35;
|
||||
|
||||
@@ -46,6 +75,14 @@ private:
|
||||
std::vector<std::string> palettes_; // Listado de los ficheros de paletta disponibles
|
||||
Uint8 current_palette_ = 0; // Indice para el vector de paletas
|
||||
bool notifications_enabled_ = false; // indica si se muestran las notificaciones
|
||||
FPS fps_; // Variable para gestionar los frames por segundo
|
||||
std::string info_resolution_; // Texto con la informacion de la pantalla
|
||||
|
||||
#ifdef DEBUG
|
||||
bool show_debug_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla
|
||||
#else
|
||||
bool show_debug_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla
|
||||
#endif
|
||||
|
||||
// Dibuja las notificaciones
|
||||
void renderNotifications();
|
||||
@@ -80,6 +117,9 @@ private:
|
||||
// Recrea la textura para los shaders
|
||||
void createShadersTexture();
|
||||
|
||||
// Muestra información por pantalla
|
||||
void renderInfo();
|
||||
|
||||
// Constructor
|
||||
Screen(SDL_Window *window, SDL_Renderer *renderer);
|
||||
|
||||
@@ -166,4 +206,7 @@ public:
|
||||
|
||||
// Establece la visibilidad de las notificaciones
|
||||
void setNotificationsEnabled(bool value) { notifications_enabled_ = value; }
|
||||
|
||||
// Activa / desactiva la información de debug
|
||||
void toggleDebugInfo() { show_debug_info_ = !show_debug_info_; }
|
||||
};
|
||||
Reference in New Issue
Block a user