18 #ifndef ZENI_CHRONOMETER_HXX
19 #define ZENI_CHRONOMETER_HXX
31 : m_seconds_counted(0.0
f),
33 m_scaling_factor(typename
TIME::Second_Type(1))
35 get_chronometers().insert(
this);
40 get_chronometers().erase(
this);
41 get_paused().erase(
this);
46 : m_seconds_counted(rhs.m_seconds_counted),
47 m_start_time(rhs.m_start_time),
48 m_end_time(rhs.m_end_time),
49 m_running(rhs.m_running),
50 m_scaling_factor(rhs.m_scaling_factor)
52 get_chronometers().insert(
this);
54 if(g_are_paused && m_running)
55 get_paused().insert(
this);
61 if(m_running && !rhs.m_running)
62 get_paused().erase(
this);
63 else if(rhs.m_running && !m_running)
64 get_paused().insert(
this);
67 m_seconds_counted = rhs.m_seconds_counted;
68 m_start_time = rhs.m_start_time;
69 m_end_time = rhs.m_end_time;
70 m_running = rhs.m_running;
71 m_scaling_factor = rhs.m_scaling_factor;
84 get_paused().insert(
this);
89 m_start_time.update();
100 get_paused().erase(
this);
106 m_seconds_counted += m_end_time.get_seconds_since(m_start_time) * m_scaling_factor;
113 template <
class TIME>
115 return m_seconds_counted + (m_running ?
116 m_start_time.get_seconds_passed() * m_scaling_factor :
120 template <
class TIME>
123 m_start_time.update();
125 m_seconds_counted = time;
128 template <
class TIME>
130 m_start_time.update();
131 m_seconds_counted = 0.0f;
134 template <
class TIME>
136 return m_scaling_factor;
139 template <
class TIME>
143 m_seconds_counted += m_end_time.get_seconds_since(m_start_time) * m_scaling_factor;
144 m_start_time = m_end_time;
147 m_scaling_factor = scaling_factor;
150 template <
class TIME>
155 template <
class TIME>
157 std::set<Chronometer<TIME> *> &chronometers = get_chronometers();
158 std::set<Chronometer<TIME> *> &paused = get_paused();
161 it != chronometers.end();
164 if((*it)->is_running()) {
173 template <
class TIME>
175 g_are_paused =
false;
177 std::set<Chronometer<TIME> *> &paused = get_paused();
189 template <
class TIME>
191 static std::set<Chronometer<TIME> *> * chronometers =
new std::set<Chronometer<TIME> *>;
192 return *chronometers;
195 template <
class TIME>
196 std::set<Chronometer<TIME> *> & Chronometer<TIME>::get_paused() {
197 static std::set<Chronometer<TIME> *> * paused =
new std::set<Chronometer<TIME> *>;
201 template <
class TIME>
202 bool Chronometer<TIME>::g_are_paused =
false;
Chronometer & operator=(const Chronometer< TIME > &rhs)
void scale(const typename TIME::Second_Type &scaling_factor=typename TIME::Second_Type(1))
Scale the amount of time that passes by some amount.
void set(const typename TIME::Second_Type &time)
Set the number of seconds counted by the Chronometer.
const TIME::Second_Type & scaling_factor() const
Get the scaling factor.
static void pause_all()
Pause all Chronometer<TIME> objects.
const bool & is_running() const
Get whether the Chronometer is currently counting or stopped.
const TIME & stop()
Stop the Chronometer and get the current TIME.
A stoppable running timer.
static bool are_paused()
Check to see if all Chronometer<TIME> objects are paused.
void reset()
Reset the Chronometer. This does NOT stop the Chronometer.
TIME::Second_Type seconds() const
Get the number of seconds counted by the Chronometer.
const TIME & start()
Start the Chronometer and get the current TIME. This does NOT reset the Chronometer.
static void unpause_all()
Unpause all Chronometer<TIME> objects.