Clock class
#include <Spore ModAPI/Spore/Clock.h>
A class used for measuring time.
It supports multiple precisions from the enum Clock::
In order to use a clock, first you have to start it with the Clock::
You can pause the clock using Clock::Start()
again to continue counting the accumulated time. If you want to clear the accumulated time and count from 0, use Clock::
Public types
- enum class Mode { Ticks = 0, ProcessorTimeStamp = 1, Nanoseconds = 2, Microseconds = 3, Milliseconds = 4, Seconds = 5, Minutes = 6 }
Constructors, destructors, conversion operators
-
Clock(Clock::
Mode mode = Clock:: Mode:: Ticks, bool start = false) - Creates a new clock object with the specified precision mode.
Public functions
-
auto SetMode(Clock::
Mode mode) -> void - Changes the precision mode.
- auto Start() -> void
- Starts the clock, if it's not already running.
- auto Pause() -> void
- Stops the clock, reseting the initial time to 0.
- auto Reset() -> void
- Stops the clock and clears all accumulated time.
- auto GetElapsed() const -> float
- Returns the elapsed time in the specified precision measure, conserving all decimals.
-
auto GetElapsedTicks() const -> LARGE_
INTEGER - Returns the elapsed time in ticks (regardles of the clock mode).
- auto GetElapsedTime() const -> int
- Returns the elapsed time in the specified precision measure, rounded to the closest integer.
- auto IsRunning() const -> bool
- Tells whether the clock is counting (
true
) or is paused (false
).
Protected variables
-
LARGE_
INTEGER mStartTime -
LARGE_
INTEGER mAccumulatedTime -
Clock::
Mode mMode - The mode (precision) with which the time is measured.
- float mMeasurePerTick
- Derived from mMode, how many units of measurement (seconds, nanoseconds, etc) are equal to 1 tick.
Enum documentation
enum class Clock:: Mode
Enumerators | |
---|---|
Ticks |
Uses QueryPerformanceCounter to measure time (in ticks). |
ProcessorTimeStamp |
Uses __rdtsc (Read Time Stamp Counter) to get the current time (in ticks?), instead of QueryPerformanceCounter. |
Nanoseconds |
Measures the time with nanosecond precision (1 second = 10e9 nanoseconds). Uses QueryPerformanceCounter to measure time. |
Microseconds |
Measures the time with microsecond precision (1 second = 10e6 microseconds). Uses QueryPerformanceCounter to measure time. |
Milliseconds |
Measures the time with milliseconds precision (1 second = 10e3 milliseconds). Uses QueryPerformanceCounter to measure time. |
Seconds |
Measures the time with seconds precision. Uses QueryPerformanceCounter to measure time. |
Minutes |
Measures the time with minute precision (60 seconds = 1 minute). Uses QueryPerformanceCounter to measure time. |
Function documentation
Clock:: Clock(Clock:: Mode mode = Clock:: Mode:: Ticks,
bool start = false)
Creates a new clock object with the specified precision mode.
Parameters | |
---|---|
mode | The precision with which the clock will measure time. |
start | [Optional] If true, the clock will start counting time. False by default. |
Optionally, you can make the clock start counting.
void Clock:: SetMode(Clock:: Mode mode)
Changes the precision mode.
Parameters | |
---|---|
mode | The precision with which the clock will measure time. |
void Clock:: Pause()
Stops the clock, reseting the initial time to 0.
After pausing, the clock can be started again using Clock::
float Clock:: GetElapsed() const
Returns the elapsed time in the specified precision measure, conserving all decimals.
Returns | The time passed since the clock was created/reset, in the assigned units. |
---|