forked from jaildesigner-jailgames/jaildoctors_dilemma
afegit comptador de frames per segon
This commit is contained in:
@@ -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();
|
||||
@@ -105,7 +112,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
|
||||
// Establece el modo de video
|
||||
setVideoMode(options.video.mode);
|
||||
|
||||
|
||||
// Muestra la ventana
|
||||
show();
|
||||
resetShaders();
|
||||
@@ -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
|
||||
@@ -479,4 +490,21 @@ void Screen::createShadersTexture()
|
||||
std::cerr << "Error: shaders_texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user