2018-09-04 19:25:54 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-09-06 05:14:00 +00:00
|
|
|
#include <ctime>
|
2018-09-04 19:25:54 +00:00
|
|
|
|
|
|
|
//A class to handle the FPS of the game
|
|
|
|
//Calculations are done per the number of frames specified
|
|
|
|
//Frames must be a value from 2 - 255
|
|
|
|
//Recommended numbers for frames is 2 (Instant), 5 (Slightly Smoothed), 60 (Smoothed)
|
|
|
|
//Max number for frames = 255
|
|
|
|
//Lower frames = jumpy, instant updates
|
|
|
|
//Higher frames = smoother, flowing updates
|
2018-09-07 03:22:40 +00:00
|
|
|
class FPS final
|
2018-09-04 19:25:54 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
FPS(unsigned short frames = 2);
|
|
|
|
~FPS();
|
|
|
|
|
|
|
|
//Returns the clock of the last mark() call
|
|
|
|
const clock_t& get_clock() const;
|
|
|
|
|
|
|
|
//Returns FPS (frames per second) of the game (based on the last marked frame)
|
|
|
|
//CLOCKS_PER_SECOND / (m_clock - m_prevClock)
|
|
|
|
float get_spf() const;
|
|
|
|
|
|
|
|
//Returns FPS (frames per second) of the game (based on the last marked frame)
|
|
|
|
//CLOCKS_PER_SECOND / (m_clock - m_prevClock)
|
|
|
|
float get_fps() const;
|
|
|
|
|
|
|
|
//Fills the clocks with the current clock() value (to prevent unreasonable clock counts at the first few frames)
|
|
|
|
void prepare();
|
|
|
|
|
|
|
|
//Marks the end of the frame (resets the clock)
|
|
|
|
//Should be called right before the update() and render() functions
|
|
|
|
//Also calculates the seconds per frame (able to be considered the dTime)
|
|
|
|
//(m_clock - m_prevClock) / CLOCKS_PER_SEC
|
|
|
|
float mark();
|
|
|
|
|
|
|
|
private:
|
|
|
|
//m_iter marks the place of the next mark
|
|
|
|
unsigned short m_iter;
|
|
|
|
unsigned short m_frames;
|
|
|
|
|
|
|
|
clock_t* m_clocks = nullptr;
|
|
|
|
};
|