40 #ifndef _extendedtimer_cpp
41 #define _extendedtimer_cpp
43 #include "extendedtimer.h"
44 #include "eventmanager.h"
51 Type = Timer::Extended;
72 MEZZ_EXCEPTION(Exception::INVALID_STATE_EXCEPTION,
"Invalid Timer type acquisition");
76 void ExtendedTimer::Update(
const Whole MicroSecondsElapsed)
83 UpdateAsNormal(MicroSecondsElapsed);
85 case Timer::StopWatch:
87 UpdateAsStopWatch(MicroSecondsElapsed);
91 Callback->DoCallbackItems();
100 UpdateAsNormal(MicroSecondsElapsed);
104 Callback->DoCallbackItems();
115 void ExtendedTimer::UpdateAsNormal(
const Whole MicroSecondsElapsed)
117 CurrentTime.Microseconds+=(
Integer)MicroSecondsElapsed;
125 void ExtendedTimer::UpdateAsStopWatch(
const Whole MicroSecondsElapsed)
127 CurrentTime.Microseconds-=MicroSecondsElapsed;
128 if(CurrentTime.Microseconds < 0)
130 Whole GoesInto = CurrentTime.Microseconds * 0.001;
131 Whole Remainder = CurrentTime.Microseconds - GoesInto * 1000;
132 CurrentTime.Microseconds = Remainder;
133 CurrentTime.Milliseconds+=GoesInto;
135 if(CurrentTime.Milliseconds < 0)
137 Integer GoesInto = CurrentTime.Milliseconds * 0.001;
138 Integer Remainder = CurrentTime.Milliseconds - GoesInto * 1000;
139 CurrentTime.Milliseconds = Remainder;
140 CurrentTime.Seconds+=GoesInto;
142 if(CurrentTime.Seconds < 0)
144 Integer GoesInto = CurrentTime.Seconds / 60;
145 Integer Remainder = CurrentTime.Seconds - GoesInto * 60;
146 CurrentTime.Seconds = Remainder;
147 CurrentTime.Minutes+=GoesInto;
149 if(CurrentTime.Minutes < 0)
151 Integer GoesInto = CurrentTime.Minutes / 60;
152 Integer Remainder = CurrentTime.Minutes - GoesInto * 60;
153 CurrentTime.Minutes = Remainder;
154 CurrentTime.Hours+=GoesInto;
156 if(CurrentTime.Hours < 0)
158 Integer GoesInto = CurrentTime.Hours / 24;
159 Integer Remainder = CurrentTime.Hours - GoesInto * 24;
160 CurrentTime.Hours = Remainder;
161 CurrentTime.Days+=GoesInto;
167 if(GetStruct(Struct).Microseconds > 1000)
169 Integer GoesInto = GetStruct(Struct).Microseconds * 0.001;
170 Integer Remainder = GetStruct(Struct).Microseconds - GoesInto * 1000;
171 GetStruct(Struct).Microseconds = Remainder;
172 GetStruct(Struct).Milliseconds+=GoesInto;
174 }
else{
return false; }
179 if(GetStruct(Struct).Milliseconds > 1000)
181 Integer GoesInto = GetStruct(Struct).Milliseconds * 0.001;
182 Integer Remainder = GetStruct(Struct).Milliseconds - GoesInto * 1000;
183 GetStruct(Struct).Milliseconds = Remainder;
184 GetStruct(Struct).Seconds+=GoesInto;
186 }
else{
return false; }
191 if(GetStruct(Struct).Seconds > 60)
193 Integer GoesInto = GetStruct(Struct).Seconds / 60;
194 Integer Remainder = GetStruct(Struct).Seconds - GoesInto * 60;
195 GetStruct(Struct).Seconds = Remainder;
196 GetStruct(Struct).Minutes+=GoesInto;
198 }
else{
return false; }
203 if(GetStruct(Struct).Minutes > 60)
205 Integer GoesInto = GetStruct(Struct).Minutes / 60;
206 Integer Remainder = GetStruct(Struct).Minutes - GoesInto * 60;
207 GetStruct(Struct).Minutes = Remainder;
208 GetStruct(Struct).Hours+=GoesInto;
210 }
else{
return false; }
215 if(GetStruct(Struct).Hours > 24)
217 Integer GoesInto = GetStruct(Struct).Hours / 24;
218 Integer Remainder = GetStruct(Struct).Hours - GoesInto * 24;
219 GetStruct(Struct).Hours = Remainder;
220 GetStruct(Struct).Days+=GoesInto;
222 }
else{
return false; }
232 if(CheckMicroSeconds(Struct) || CheckMilliSeconds(Struct) || CheckSeconds(Struct)
233 || CheckMinutes(Struct) || CheckHours(Struct) || CheckDays(Struct))
236 }
else{
return false; }
241 return Timer::StopWatch == Style ? Current < Goal : Current >
Goal;
250 Boole ExtendedTimer::GoalReached()
252 if(CurrentTime.Days == GoalTime.Days)
254 if(CurrentTime.Hours == GoalTime.Hours)
256 if(CurrentTime.Minutes == GoalTime.Minutes)
258 if(CurrentTime.Seconds == GoalTime.Seconds)
260 if(CurrentTime.Milliseconds == GoalTime.Milliseconds)
262 if(CurrentTime.Microseconds == GoalTime.Microseconds)
266 else if (CompareCurrentAndGoal(CurrentTime.Microseconds,GoalTime.Microseconds))
267 {
return true; }
else{
return false; }
269 else if (CompareCurrentAndGoal(CurrentTime.Milliseconds,GoalTime.Milliseconds))
270 {
return true; }
else{
return false; }
272 else if (CompareCurrentAndGoal(CurrentTime.Seconds,GoalTime.Seconds))
273 {
return true; }
else{
return false; }
275 else if (CompareCurrentAndGoal(CurrentTime.Minutes,GoalTime.Minutes))
276 {
return true; }
else{
return false; }
278 else if (CompareCurrentAndGoal(CurrentTime.Hours,GoalTime.Hours))
279 {
return true; }
else{
return false; }
281 else if (CompareCurrentAndGoal(CurrentTime.Days,GoalTime.Days))
282 {
return true; }
else{
return false; }
287 CurrentTime.Milliseconds = InitialTime.Milliseconds;
288 CurrentTime.Seconds = InitialTime.Seconds;
289 CurrentTime.Minutes = InitialTime.Minutes;
290 CurrentTime.Hours = InitialTime.Hours;
291 CurrentTime.Days = InitialTime.Days;
296 ResetAtGoal = AutoReset;
302 GetStruct(Struct).Microseconds = MS;
309 GetStruct(Struct).Milliseconds = MS;
310 CheckMilliSeconds(Struct);
311 CheckSeconds(Struct);
312 CheckMinutes(Struct);
319 GetStruct(Struct).Seconds = Sec;
320 CheckSeconds(Struct);
321 CheckMinutes(Struct);
328 GetStruct(Struct).Minutes = Min;
329 CheckMinutes(Struct);
336 GetStruct(Struct).Hours = Hr;
343 GetStruct(Struct).Days = Day;
349 return GetStruct(Struct).Milliseconds;
354 return GetStruct(Struct).Seconds;
359 return GetStruct(Struct).Minutes;
364 return GetStruct(Struct).Hours;
369 return GetStruct(Struct).Days;
TimeStruct
The internal time struct to be used...
bool Boole
Generally acts a single bit, true or false.
virtual ExtendedTimer & SetSeconds(Integer Sec, const ExtendedTimer::TimeStruct Struct=ExtendedTimer::Current)
Sets the value for Seconds of the specified struct.
virtual ExtendedTimer & SetMinutes(Integer Min, const ExtendedTimer::TimeStruct Struct=ExtendedTimer::Current)
Sets the value for Minutes of the specified struct.
virtual Integer GetMinutes(const ExtendedTimer::TimeStruct Struct=ExtendedTimer::Current)
Gets the current internal Minute count.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
virtual ~ExtendedTimer()
Class destructor.
int Integer
A datatype used to represent any integer close to.
virtual Integer GetMilliseconds(const ExtendedTimer::TimeStruct Struct=ExtendedTimer::Current)
Gets the current internal Millisecond count.
virtual Integer GetHours(const ExtendedTimer::TimeStruct Struct=ExtendedTimer::Current)
Gets the current internal Hour count.
virtual ExtendedTimer & SetMicroseconds(Integer MS, const ExtendedTimer::TimeStruct Struct=ExtendedTimer::Current)
Sets the value for Microseconds of the specified struct.
An enhanced timer class that can store and track many units of time.
virtual ExtendedTimer & SetDays(Integer Day, const ExtendedTimer::TimeStruct Struct=ExtendedTimer::Current)
Sets the value for Days of the specified struct.
virtual ExtendedTimer & SetHours(Integer Hr, const ExtendedTimer::TimeStruct Struct=ExtendedTimer::Current)
Sets the value for Hours of the specified struct.
ExtendedTimer(const Timer::TimerStyle style)
Standard Constructor.
virtual ExtendedTimer & SetMilliseconds(Integer MS, const ExtendedTimer::TimeStruct Struct=ExtendedTimer::Current)
Sets the value for Milliseconds of the specified struct.
A container for the metrics of time relevant for the timer class.
virtual Integer GetDays(const ExtendedTimer::TimeStruct Struct=ExtendedTimer::Current)
Gets the current internal Day count.
A basic timer class to assist in timed operations.
void Stop()
Deactivates the Timer.
The bulk of the engine components go in this namspace.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
virtual Integer GetSeconds(const ExtendedTimer::TimeStruct Struct=ExtendedTimer::Current)
Gets the current internal Second count.
virtual void Reset()
Sets the current values to their initial values.
virtual ExtendedTimer & SetAutoReset(const Boole AutoReset)
Sets whether or not the Timer should reset if it reaches it's goal. Ex. If a stopwatch reaches 0...