Nymph Game Engine
Chaiscript based Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fps_counter.h
Go to the documentation of this file.
1 #ifndef FPS_COUNTER_H
2 #define FPS_COUNTER_H
3 #include <chrono>
4 #include "events/subject.h"
5 
6 //= SCRIPTABLE
7 //= SCRIPTABLE BASES Subject
8 
9 namespace Utility {
13  class FPSCounter : public Events::Subject {
14  private:
15  float max_fps;
16  float current_fps;
17  std::chrono::time_point<std::chrono::high_resolution_clock> last_time;
18  std::chrono::time_point<std::chrono::high_resolution_clock> current_time;
19  float delta;
20  float delta_accum;
21  unsigned int frame_count;
22  float fps_accum;
23  void sleepFor(const int milliseconds);
24 
25  public:
31  FPSCounter(const float max_fps = 0.0f);
35  virtual ~FPSCounter() = default;
36 
42  float assessCountAndGetDelta();
43 
44  //= BEGIN SCRIPTABLE
45 
51  float getMaxFPS() const noexcept;
57  float getCurrentFPS() const noexcept;
63  float getAverageFPS() const noexcept;
67  void resetAverageFPS() noexcept;
68  //= END SCRIPTABLE
69  };
70 }
71 
72 #endif
float getCurrentFPS() const noexcept
Gets the current fps.
Definition: fps_counter.cpp:21
FPSCounter(const float max_fps=0.0f)
FPSCounter cunstructer.
Definition: fps_counter.cpp:11
Class for fps counter.
Definition: fps_counter.h:13
void resetAverageFPS() noexcept
Resets FPS Average.
Definition: fps_counter.cpp:32
Class for a subject that an observer would observe for changes.
Definition: subject.h:13
float assessCountAndGetDelta()
Calculates frame delta from FPS counter.
Definition: fps_counter.cpp:42
virtual ~FPSCounter()=default
Destroys the object.
float getAverageFPS() const noexcept
Gets the average fps.
Definition: fps_counter.cpp:25
float getMaxFPS() const noexcept
Gets the maximum fps.
Definition: fps_counter.cpp:17