Timer Functions
Timers may become inaccurate at higher resolutions due to overhead. The code to actually control the timers is fairly accurate, however, the macro may not be able to process data fast enough to keep up with the timers. This should not be an issue unless you are going into nanosecond timers.
Note:
The MicroMacro library also provides "simple", automatic timers. These will save you some time and learning. It is highly recommended to use automatic timers instead. Automatic timer functions are provided in the Library.
Contents
newTimer
newTimer(name)
Creates a new timer with the given name.
Example
newTimer("my_timer");
removeTimer
removeTimer(name)
Removes a timer with the given name, freeing it's used resources.
Example
removeTimer("my_timer");
startTimer
startTimer(name, time)
Starts or restarts a timer with the given name, with a given time value in miliseconds (1/1000th of a second).
Example
startTimer( "my_timer", 1000 );
isTriggered
bool isTriggered(name)
Returns if a timer has been triggered or not. Returns true if it has, false otherwise.
Remember to (re)start timers after they have been triggered.
Example
if( isTriggered("my_timer") ) then
do_something();
startTimer("my_timer", 1000);
end
getTime
table getTime()
Returns a high-resolution timestamp of the current time on the user's computer. This should be used in combination with deltaTime().
Example:
local now = getTime();
getTimerFrequency
table getTimerFrequency()
Returns a 64-byte integer (represented as a table) detailing how many processor cycles occur in a second. This varies across processors, and is generally not of much use to the average user.
local freq = getTimerFrequency()
deltaTime
number deltaTime(T2, T1)
Returns a floating-point integer that gives a precise amount of time, in milliseconds, that have elapsed between two timestamps. T2 should represent a 'newer' time than T1, such that T2 - T1 would be a positive value.
Example:
local startTime = getTime();
yrest(1000);
local endTime = getTime();
printf("%d milliseconds have elapsed.", deltaTime(endTime, startTime));
-- The value displayed should be roughly 1,000.