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