NRE_Clock.hpp
Go to the documentation of this file.
1 
10  #pragma once
11 
12  #include <iostream>
13  #include <thread>
14  #include <chrono>
15 
16  #include <Utility/String/NRE_String.hpp>
17 
22  namespace NRE {
27  namespace Time {
28 
30  typedef std::chrono::steady_clock Chrono;
32  typedef std::chrono::time_point<Chrono> TimePoint;
34  typedef std::chrono::duration<float, std::milli> TimeStep;
35 
40  class Clock {
41  private: //Fields
42  TimePoint now;
43  TimePoint before;
44  TimePoint frame;
45  TimeStep timestep;
46  int nbFrames;
47  bool show;
49  public: // Methods
50  //## Constructor ##//
54  Clock();
55 
56  //## Copy-Constructor ##//
61  Clock(Clock const& c) = default;
62 
63  //## Move-Constructor ##//
68  Clock(Clock && c) = default;
69 
70  //## Deconstructor ##//
74  ~Clock() = default;
75 
76  //## Getter ##//
80  TimeStep const& getTimestep() const;
84  float getDelta() const;
85 
86  //## Methods ##//
90  void update();
95  void updateAndSleep(TimeStep const& time);
100  void sleep(TimeStep const& time);
104  void showFPS();
108  void hideFPS();
109 
110  //## Assignment Operator ##//
116  Clock& operator =(Clock const& c) = default;
122  Clock& operator =(Clock && c) = default;
123 
124  //## Stream Operator ##//
129  Utility::String toString() const;
130 
131  private: // Methods
135  void updateNow();
139  void updateBefore();
143  void updateTimestep();
147  void updateFrame();
148 
149  public: // Static
150  static float TIMESTEP;
151  };
152 
159  std::ostream& operator <<(std::ostream& stream, Clock const& o);
160  }
161  }
162 
163  #include "NRE_Clock.tpp"
Time&#39;s API.
std::chrono::duration< float, std::milli > TimeStep
Definition: NRE_Clock.hpp:34
void updateAndSleep(TimeStep const &time)
TimeStep const & getTimestep() const
std::chrono::steady_clock Chrono
Definition: NRE_Clock.hpp:30
The NearlyRealEngine&#39;s global namespace.
~Clock()=default
void sleep(TimeStep const &time)
Manage timing and program pause.
Definition: NRE_Clock.hpp:40
static float TIMESTEP
Definition: NRE_Clock.hpp:150
Clock & operator=(Clock const &c)=default
Utility::String toString() const
Definition: NRE_Clock.cpp:31
float getDelta() const
std::chrono::time_point< Chrono > TimePoint
Definition: NRE_Clock.hpp:32