YAPOG  0.0.1
Yet Another Pokemon Online Game
Timer.cpp
Go to the documentation of this file.
2 
3 namespace yap
4 {
6  : clock_ ()
7  , init_ ()
8  {
9  }
10 
11  Timer::Timer (const Time& init)
12  : clock_ ()
13  , init_ (init)
14  {
15  }
16 
17  void Timer::Reset ()
18  {
19  Reset (Time ());
20  }
21 
22  void Timer::Reset (const Time& init)
23  {
24  init_ = init;
25 
26  clock_.restart ();
27  }
28 
30  {
31  return Time (clock_.getElapsedTime ()) + init_;
32  }
33 
34  int Timer::DelayIsComplete (const Time& delay, bool reset)
35  {
36  float currentTime = GetCurrentTime ().GetValue ();
37 
38  int factor = static_cast<int> (
39  currentTime / delay.GetValue ());
40 
41  if (reset && factor > 0)
42  Reset (Time (currentTime - factor * delay.GetValue ()));
43 
44  return factor;
45  }
46 } // namespace yap