Game Project
Loading...
Searching...
No Matches
FPSTracker.h
1#pragma once
2#include <SFML/System.hpp>
3#include <array>
4
8class FPSTracker
9{
10public:
11 FPSTracker();
12
17 void Update(const sf::Time& delta_time);
21 void UpdateStats(const sf::Time& delta_time);
22
27 const float& GetAverageFps() const { return current_average_fps_; }
32 const float& GetFrameTimeMs() const { return current_frame_time_ms_; }
37 const float& GetHighsFps() const { return current_highs_fps_; }
42 const float& GetLowsFps() const { return current_lows_fps_; }
43private:
44 static constexpr size_t FPS_HISTORY_SIZE_ = 64; // Must be a power of 2 for performance. Constexpr to make it a compile time constant, making it faster
45 float fps_history_[FPS_HISTORY_SIZE_];
46 float current_average_fps_ = 0.f;
47 float current_highs_fps_ = 0.f;
48 float current_lows_fps_ = 0.f;
49 float current_frame_time_ms_ = 0.f;
50
51 size_t current_index_ = 0; // Used for going through the FPS hisroty in a circular manner
52
57 std::array<float, FPS_HISTORY_SIZE_> GetSortedHistory();
58};
59
const float & GetFrameTimeMs() const
Returns the last calculated Frame Time in MS.
Definition FPSTracker.h:32
const float & GetLowsFps() const
Returns the last calculated Low FPS.
Definition FPSTracker.h:42
const float & GetHighsFps() const
Returns the last calculated High FPS.
Definition FPSTracker.h:37
const float & GetAverageFps() const
Returns the last calculated average FPS.
Definition FPSTracker.h:27
void Update(const sf::Time &delta_time)
Adds an extra sample to the FPS history.
Definition FPSTracker.cpp:14
void UpdateStats(const sf::Time &delta_time)
Updates the current stats: average, highs, lows.
Definition FPSTracker.cpp:31