v0.1.8
|
A timer to keep track of time, similar to a stop watch. More...
#include <Timer.hpp>
Public Member Functions | |
Timer () | |
Default constructor. | |
Timer & | operator= (const Timer &operand) |
Copies data from one timer into another. More... | |
void | Start () |
Starts the timer causing time to elapse. More... | |
void | Stop () |
Stops the timer, freezing it at the current time. More... | |
void | Reset () |
Resets the timer to zero without stopping or starting it. More... | |
void | SetElapsedSeconds (Float64 seconds) |
void | SetElapsedMilliseconds (Float64 milliseconds) |
Float64 | GetElapsedSeconds () const |
Get the elapsed time (in seconds) from when the timer was started. More... | |
Float64 | GetElapsedMilliseconds () const |
Get the elapsed time (in milliseconds) from when the timer was started. More... | |
Float64 | GetDeltaTime () |
A quick utility function for calculating delta time. More... | |
Static Public Member Functions | |
static void | Sleep (UInt32 milliseconds) |
Causes the current thread to idle for the given amount of time (in millseconds). More... | |
static Float64 | GetSeconds () |
Get a system time in seconds. More... | |
static Float64 | GetMilliseconds () |
Get a system time in milliseconds. More... | |
static UInt64 | GetRawTime () |
Gets a high precision timestamp. More... | |
A timer to keep track of time, similar to a stop watch.
CGUL::Float64 CGUL::Timer::GetDeltaTime | ( | ) |
A quick utility function for calculating delta time.
Determines time in between calls and returns a floating point (decimal) time in seconds. It is recommended that this method be used instead of Start, Stop, and Reset for delta time calculations because it is better optimized for that purpose and will yield more accurate results. Additionally, this method will reset the timer every time it is called so the GetElapsedSeconds and GetElapsedMilliseconds methods will not give accurate results.
CGUL::Float64 CGUL::Timer::GetElapsedMilliseconds | ( | ) | const |
Get the elapsed time (in milliseconds) from when the timer was started.
Represents the time currently recorded by this clock some time after a call to the Start method. If a clock has not been started this method will simply return zero.
CGUL::Float64 CGUL::Timer::GetElapsedSeconds | ( | ) | const |
Get the elapsed time (in seconds) from when the timer was started.
Same as GetElapsedMilliseconds method but in seconds.
|
static |
Get a system time in milliseconds.
Gets a time from the operating system in milliseconds. The time acquired is not guaranteed to represent any significance aside from being incremental from a previous GetMilliseconds or GetSeconds call. In other words, this time does not represent the current time of day, the time the operating system has been up, or any other such data. The only purpose of this method is to compare two time stamps to find a delta in time.
|
static |
Gets a high precision timestamp.
The value here is practically guaranteed to be different everytime it's called. The value is primarily useful for seeding random numbers.
|
static |
Get a system time in seconds.
Same as the GetMilliseconds method but in seconds.
CGUL::Timer & CGUL::Timer::operator= | ( | const Timer & | operand | ) |
Copies data from one timer into another.
Copies over whatever data is in the right-hand-side timer, including time and whether or not its running.
void CGUL::Timer::Reset | ( | ) |
Resets the timer to zero without stopping or starting it.
Acts just as the reset would on a stop watch. The current time is set to zero but the state of the clock is not changed. If the clock was running when this method was called then it will continue to run starting from zero. In order to both stop and reset the clock, the methods Stop and Reset must be called in that order. Calling the Start method after calling Reset will cause the clock to pick up the time where it left off.
void CGUL::Timer::SetElapsedMilliseconds | ( | Float64 | milliseconds | ) |
milliseconds | Number of milliseconds on the clock. |
void CGUL::Timer::SetElapsedSeconds | ( | Float64 | seconds | ) |
seconds | Number of seconds on the clock. |
|
static |
Causes the current thread to idle for the given amount of time (in millseconds).
A program that never sleeps can cause CPU thrashing so its a good idea to call sleep and let the CPU take care of other things for a short while. Sleeping will cause the currently active thread to halt for the given amount of time. As little as 1 millisecond is enough to take a huge load off of the CPU and its recommended that applications in a constant loop makes a call each tick to the Sleep method. It is not guaranteed (and in fact very unlikely) that this method will halt the program for exactly the amount of milliseconds specified.
milliseconds | The amount of time to sleep in milliseconds. |
void CGUL::Timer::Start | ( | ) |
void CGUL::Timer::Stop | ( | ) |
Stops the timer, freezing it at the current time.
Acts just as the stop would on a stop watch. The current time will be recorded and the clock will stop progressing forward. This method will not reset the clock to zero, for that the Reset method must be called separately. If the clock is already stopped then this method does nothing.