#pragma once #include //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 class FPS { 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; };