afegit comptador de frames per segon
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
SDLManager::SDLManager()
|
||||
: finestra_(nullptr),
|
||||
renderer_(nullptr),
|
||||
fps_accumulator_(0.0f),
|
||||
fps_frame_count_(0),
|
||||
fps_display_(0),
|
||||
current_width_(Defaults::Window::WIDTH),
|
||||
current_height_(Defaults::Window::HEIGHT),
|
||||
is_fullscreen_(false),
|
||||
@@ -69,6 +72,9 @@ SDLManager::SDLManager()
|
||||
SDLManager::SDLManager(int width, int height, bool fullscreen)
|
||||
: finestra_(nullptr),
|
||||
renderer_(nullptr),
|
||||
fps_accumulator_(0.0f),
|
||||
fps_frame_count_(0),
|
||||
fps_display_(0),
|
||||
current_width_(width),
|
||||
current_height_(height),
|
||||
is_fullscreen_(fullscreen),
|
||||
@@ -305,3 +311,35 @@ void SDLManager::updateColors(float delta_time) {
|
||||
// Actualitzar color global de línies
|
||||
Rendering::setLineColor(color_oscillator_.getCurrentLineColor());
|
||||
}
|
||||
|
||||
// [NUEVO] Actualitzar comptador de FPS
|
||||
void SDLManager::updateFPS(float delta_time) {
|
||||
// Acumular temps i frames
|
||||
fps_accumulator_ += delta_time;
|
||||
fps_frame_count_++;
|
||||
|
||||
// Actualitzar display cada 0.5 segons
|
||||
if (fps_accumulator_ >= 0.5f) {
|
||||
fps_display_ = static_cast<int>(fps_frame_count_ / fps_accumulator_);
|
||||
fps_frame_count_ = 0;
|
||||
fps_accumulator_ = 0.0f;
|
||||
|
||||
// Actualitzar títol de la finestra
|
||||
std::string title = std::format("{} v{} ({}) - {} FPS",
|
||||
Project::LONG_NAME,
|
||||
Project::VERSION,
|
||||
Project::COPYRIGHT,
|
||||
fps_display_);
|
||||
|
||||
if (finestra_) {
|
||||
SDL_SetWindowTitle(finestra_, title.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// [NUEVO] Actualitzar títol de la finestra
|
||||
void SDLManager::setWindowTitle(const std::string& title) {
|
||||
if (finestra_) {
|
||||
SDL_SetWindowTitle(finestra_, title.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "core/rendering/color_oscillator.hpp"
|
||||
|
||||
@@ -35,13 +36,24 @@ class SDLManager {
|
||||
// [NUEVO] Actualització de colors (oscil·lació)
|
||||
void updateColors(float delta_time);
|
||||
|
||||
// [NUEVO] Actualitzar comptador de FPS
|
||||
void updateFPS(float delta_time);
|
||||
|
||||
// Getters
|
||||
SDL_Renderer* obte_renderer() { return renderer_; }
|
||||
|
||||
// [NUEVO] Actualitzar títol de la finestra
|
||||
void setWindowTitle(const std::string& title);
|
||||
|
||||
private:
|
||||
SDL_Window* finestra_;
|
||||
SDL_Renderer* renderer_;
|
||||
|
||||
// [NUEVO] Variables FPS
|
||||
float fps_accumulator_;
|
||||
int fps_frame_count_;
|
||||
int fps_display_;
|
||||
|
||||
// [NUEVO] Estat de la finestra
|
||||
int current_width_; // Mida física actual
|
||||
int current_height_;
|
||||
|
||||
Reference in New Issue
Block a user