TurtleBrains  0.3.1
High quality, portable, C++ framework for rapid 2D game development.
tb_game_timer.h
1 
9 #ifndef _TurtleBrains_GameTimer_h_
10 #define _TurtleBrains_GameTimer_h_
11 
12 #include "../core/tb_types.h"
13 
14 namespace TurtleBrains
15 {
16  namespace Game
17  {
18 
25  class GameTimer
26  {
27  public:
32 
36  static GameTimer Zero(void);
37 
41  static GameTimer Infinity(void);
42 
46  GameTimer(void);
47 
53  GameTimer(const Milliseconds& valueMilliseconds);
54 
58  GameTimer(const GameTimer& other);
59 
63  ~GameTimer(void);
64 
68  GameTimer& operator=(const GameTimer& other);
69 
76  bool DecrementStep(void);
77 
90  bool IncrementStep(const GameTimer& maximumValue = Infinity());
91 
95  bool IsZero(void) const;
96 
101  const Milliseconds& GetElapsedTime(void) const;
102 
107  const Milliseconds& GetRemainingTime(void) const;
108 
118  float GetPercentageOf(const GameTimer& timeValue) const;
119 
125  static float ToSeconds(const Milliseconds& valueMilliseconds);
126 
133  static Milliseconds ToMilliseconds(const float& valueSeconds);
134 
141  static void SetMillisecondsPerStep(const Milliseconds& millisecondsPerStep);
142 
146  static Milliseconds GetMillisecondsPerStep(void);
147 
154  static float GetSecondsPerStep(void);
155 
156  TurtleBrains::Game::GameTimer operator+(const TurtleBrains::Game::GameTimer& right) const;
158  TurtleBrains::Game::GameTimer operator-(const TurtleBrains::Game::GameTimer& right) const;
160 
161  private:
162  Milliseconds mMillisecondTimer;
163  static Milliseconds sMillisecondsPerStep;
164  };
165 
166  inline bool operator==(const TurtleBrains::Game::GameTimer& left, const TurtleBrains::Game::GameTimer& right)
167  {
168  return (left.GetElapsedTime() == right.GetElapsedTime()) ? true : false;
169  }
170 
171  inline bool operator!=(const TurtleBrains::Game::GameTimer& left, const TurtleBrains::Game::GameTimer& right)
172  {
173  return (left.GetElapsedTime() != right.GetElapsedTime()) ? true : false;
174  }
175 
176  inline bool operator>=(const TurtleBrains::Game::GameTimer& left, const TurtleBrains::Game::GameTimer& right)
177  {
178  return (left.GetElapsedTime() >= right.GetElapsedTime()) ? true : false;
179  }
180 
181  inline bool operator<=(const TurtleBrains::Game::GameTimer& left, const TurtleBrains::Game::GameTimer& right)
182  {
183  return (left.GetElapsedTime() <= right.GetElapsedTime()) ? true : false;
184  }
185 
186  inline bool operator>(const TurtleBrains::Game::GameTimer& left, const TurtleBrains::Game::GameTimer& right)
187  {
188  return (left.GetElapsedTime() > right.GetElapsedTime()) ? true : false;
189  }
190 
191  inline bool operator<(const TurtleBrains::Game::GameTimer& left, const TurtleBrains::Game::GameTimer& right)
192  {
193  return (left.GetElapsedTime() < right.GetElapsedTime()) ? true : false;
194  }
195 
196  }; /* namespace Game */
197 }; /* namespace TurtleBrains */
198 
199 namespace tbGame = TurtleBrains::Game;
200 
201 #endif /* _TurtleBrains_GameTimer_h_ */
GameTimer & operator=(const GameTimer &other)
static GameTimer Zero(void)
static Milliseconds GetMillisecondsPerStep(void)
float GetPercentageOf(const GameTimer &timeValue) const
static float GetSecondsPerStep(void)
const Milliseconds & GetRemainingTime(void) const
static GameTimer Infinity(void)
static void SetMillisecondsPerStep(const Milliseconds &millisecondsPerStep)
bool IncrementStep(const GameTimer &maximumValue=Infinity())
Here is some information about the primary namespace.
Definition: tb_application_dialog.h:21
static float ToSeconds(const Milliseconds &valueMilliseconds)
static Milliseconds ToMilliseconds(const float &valueSeconds)
uint32_t uint32
Unsigned integer with a size of 32 bits. Supports values from 0 to 4294967295, (2^32 - 1)...
Definition: tb_types.h:28
const Milliseconds & GetElapsedTime(void) const
tbCore::uint32 Milliseconds
Definition: tb_game_timer.h:31
This is the heart of TurtleBrains for game developers to create GameScenes and Entities to interact w...
Definition: tb_game_timer.h:25