afegit comptador de frames per segon
This commit is contained in:
@@ -15,6 +15,9 @@
|
|||||||
SDLManager::SDLManager()
|
SDLManager::SDLManager()
|
||||||
: finestra_(nullptr),
|
: finestra_(nullptr),
|
||||||
renderer_(nullptr),
|
renderer_(nullptr),
|
||||||
|
fps_accumulator_(0.0f),
|
||||||
|
fps_frame_count_(0),
|
||||||
|
fps_display_(0),
|
||||||
current_width_(Defaults::Window::WIDTH),
|
current_width_(Defaults::Window::WIDTH),
|
||||||
current_height_(Defaults::Window::HEIGHT),
|
current_height_(Defaults::Window::HEIGHT),
|
||||||
is_fullscreen_(false),
|
is_fullscreen_(false),
|
||||||
@@ -69,6 +72,9 @@ SDLManager::SDLManager()
|
|||||||
SDLManager::SDLManager(int width, int height, bool fullscreen)
|
SDLManager::SDLManager(int width, int height, bool fullscreen)
|
||||||
: finestra_(nullptr),
|
: finestra_(nullptr),
|
||||||
renderer_(nullptr),
|
renderer_(nullptr),
|
||||||
|
fps_accumulator_(0.0f),
|
||||||
|
fps_frame_count_(0),
|
||||||
|
fps_display_(0),
|
||||||
current_width_(width),
|
current_width_(width),
|
||||||
current_height_(height),
|
current_height_(height),
|
||||||
is_fullscreen_(fullscreen),
|
is_fullscreen_(fullscreen),
|
||||||
@@ -305,3 +311,35 @@ void SDLManager::updateColors(float delta_time) {
|
|||||||
// Actualitzar color global de línies
|
// Actualitzar color global de línies
|
||||||
Rendering::setLineColor(color_oscillator_.getCurrentLineColor());
|
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 <SDL3/SDL.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "core/rendering/color_oscillator.hpp"
|
#include "core/rendering/color_oscillator.hpp"
|
||||||
|
|
||||||
@@ -35,13 +36,24 @@ class SDLManager {
|
|||||||
// [NUEVO] Actualització de colors (oscil·lació)
|
// [NUEVO] Actualització de colors (oscil·lació)
|
||||||
void updateColors(float delta_time);
|
void updateColors(float delta_time);
|
||||||
|
|
||||||
|
// [NUEVO] Actualitzar comptador de FPS
|
||||||
|
void updateFPS(float delta_time);
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
SDL_Renderer* obte_renderer() { return renderer_; }
|
SDL_Renderer* obte_renderer() { return renderer_; }
|
||||||
|
|
||||||
|
// [NUEVO] Actualitzar títol de la finestra
|
||||||
|
void setWindowTitle(const std::string& title);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SDL_Window* finestra_;
|
SDL_Window* finestra_;
|
||||||
SDL_Renderer* renderer_;
|
SDL_Renderer* renderer_;
|
||||||
|
|
||||||
|
// [NUEVO] Variables FPS
|
||||||
|
float fps_accumulator_;
|
||||||
|
int fps_frame_count_;
|
||||||
|
int fps_display_;
|
||||||
|
|
||||||
// [NUEVO] Estat de la finestra
|
// [NUEVO] Estat de la finestra
|
||||||
int current_width_; // Mida física actual
|
int current_width_; // Mida física actual
|
||||||
int current_height_;
|
int current_height_;
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ void EscenaJoc::executar() {
|
|||||||
delta_time = 0.05f;
|
delta_time = 0.05f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actualitzar comptador de FPS
|
||||||
|
sdl_.updateFPS(delta_time);
|
||||||
|
|
||||||
// Processar events SDL
|
// Processar events SDL
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
// Manejo de finestra
|
// Manejo de finestra
|
||||||
|
|||||||
@@ -60,6 +60,9 @@ void EscenaLogo::executar() {
|
|||||||
delta_time = 0.05f;
|
delta_time = 0.05f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actualitzar comptador de FPS
|
||||||
|
sdl_.updateFPS(delta_time);
|
||||||
|
|
||||||
// Processar events SDL
|
// Processar events SDL
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
// Manejo de finestra
|
// Manejo de finestra
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class EscenaLogo {
|
|||||||
static constexpr float DURACIO_ZOOM = 4.0f; // Duració del zoom (segons)
|
static constexpr float DURACIO_ZOOM = 4.0f; // Duració del zoom (segons)
|
||||||
static constexpr float DURACIO_POST_ANIMATION = 3.0f; // Duració POST_ANIMATION (logo complet)
|
static constexpr float DURACIO_POST_ANIMATION = 3.0f; // Duració POST_ANIMATION (logo complet)
|
||||||
static constexpr float DURACIO_POST_EXPLOSION = 3.0f; // Duració POST_EXPLOSION (espera final)
|
static constexpr float DURACIO_POST_EXPLOSION = 3.0f; // Duració POST_EXPLOSION (espera final)
|
||||||
static constexpr float DELAY_ENTRE_EXPLOSIONS = 1.0f; // Temps entre explosions de lletres
|
static constexpr float DELAY_ENTRE_EXPLOSIONS = 0.15f; // Temps entre explosions de lletres
|
||||||
static constexpr float VELOCITAT_EXPLOSIO = 80.0f; // Velocitat base fragments (px/s)
|
static constexpr float VELOCITAT_EXPLOSIO = 80.0f; // Velocitat base fragments (px/s)
|
||||||
static constexpr float ESCALA_INICIAL = 0.1f; // Escala inicial (10%)
|
static constexpr float ESCALA_INICIAL = 0.1f; // Escala inicial (10%)
|
||||||
static constexpr float ESCALA_FINAL = 0.8f; // Escala final (80%)
|
static constexpr float ESCALA_FINAL = 0.8f; // Escala final (80%)
|
||||||
|
|||||||
Reference in New Issue
Block a user