Represents a difference between two SystemTimes, with moderate resolution. More...
#include <sifteo/time.h>
Public Member Functions | |
unsigned | frames (TimeDelta duration) const |
Return the number of frames, of a particular duration, that are represented by this time delta, rounding down. More... | |
bool | isNegative () const |
Is this time value negative? More... | |
bool | isPositive () const |
Is this time value positive? | |
int32_t | milliseconds () const |
Return the delta in milliseconds. | |
int64_t | nanoseconds () const |
Return the delta in nanoseconds. | |
operator double () const | |
Explicit converstion to double. | |
operator float () const | |
Explicit conversion to float. | |
unsigned | pullFrames (TimeDelta duration) |
Return a frame count, and subtract (pull) the time corresponding with those frames from this TimeDelta. More... | |
float | seconds () const |
Return the delta in seconds, as a floating point value. | |
TimeDelta (float sec) | |
Construct a new TimeDelta from a floating point time, in seconds. More... | |
Static Public Member Functions | |
static TimeDelta | fromMillisec (int32_t m) |
Construct a new TimeDelta from an integer time, in milliseconds. | |
static TimeDelta | hz (float h) |
Construct a TimeDelta representing the period which corresponds with a given frequency. More... | |
Represents a difference between two SystemTimes, with moderate resolution.
Deltas are internally stored as 32-bit millisecond counts, but they can be converted to many other units.
TimeDeltas can be directly compared to floating point values efficiently. In cases where the comparison is made against a constant, we can convert the entire operation to integer math at compile-time.
|
inline |
Construct a new TimeDelta from a floating point time, in seconds.
These constructors also provide an implicit conversion that makes tests like "delta < 1.5" work.
|
inline |
Return the number of frames, of a particular duration, that are represented by this time delta, rounding down.
This is integer division with truncation.
You can use this to implement animations which start at a particular reference point. At each frame, look at the current time, subtract the reference SystemTime to yield a TimeDelta, then use frames() to convert that value to an integer frame count.
|
inlinestatic |
|
inline |
Is this time value negative?
Time deltas are signed, but in many cases it makes sense to reject negative deltas. This predicate can be used quickly in ASSERTs.
|
inline |
Return a frame count, and subtract (pull) the time corresponding with those frames from this TimeDelta.
This leaves the remainder, i.e. the time since the beginning of the current frame, in this Time Delta.
This can be used as an alternative to frames() in cases where time is being accumulated frame-by-frame instead of being calculated based on a fixed reference point. This is also very handy for animating at a fixed rate or running a fixed timestep physics simulation, while saving the remainders for later.
Sifteo SDK v1.1.0 (see all versions)
Last updated Tue Dec 23 2014, by Doxygen