v1.1.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
Public Member Functions | Static Public Member Functions | List of all members
Sifteo::SystemTime Class Reference

Absolute time, measured by the system's monotonically increasing nanosecond timer. More...

#include <sifteo/time.h>

Public Member Functions

TimeDelta cycleDelta (TimeDelta period) const
 Measure the amount of time since the beginning of a repeating cycle with arbitrary phase and the specified period. More...
 
unsigned cycleFrame (TimeDelta period, unsigned frames) const
 Like cycleDelta(), but scales the result to the range [0, frames-1]. More...
 
float cyclePhase (TimeDelta period) const
 Like cycleDelta(), but scales the result to the range [0,1], where 0 and 1 represent the beginning and end of the current cycle.
 
bool inFuture () const
 Is this time in the future?
 
bool inPast () const
 Is this time in the past?
 
bool isValid () const
 Is this SystemTime valid? More...
 
TimeDelta operator- (SystemTime b) const
 Subtract two SystemTimes, and return a 32-bit TimeDelta, with millisecond resolution. More...
 
 SystemTime ()
 Creates an invalid SystemTime. More...
 
double uptime () const
 Return the SystemTime, in seconds since boot. Returns a double-precision floating point value.
 
uint64_t uptimeMS () const
 Return the SystemTime as a count of milliseconds since boot.
 
uint64_t uptimeNS () const
 Return the SystemTime as a count of nanoseconds since boot.
 
uint64_t uptimeUS () const
 Return the SystemTime as a count of microseconds since boot.
 

Static Public Member Functions

static SystemTime now ()
 Returns a new SystemTime representing the current system clock value.
 

Detailed Description

Absolute time, measured by the system's monotonically increasing nanosecond timer.

This clock is high resolution, guaranteed to never go backwards, and it will not roll over in any reasonable amount of time.

This clock will pause when the application is paused by the system, such as when the app falls outside of its registered Metadata::cubeRange() or when it is explicitly paused by the user.

SystemTimes are represented internally as a 64-bit count of nanoseconds since system boot. Applications should never rely on any particular absolute time having a particular meaning, and there isn't necessarily a reliable mapping from SystemTime to wall-clock time.

SystemTime objects can be compared against each other, and you can subtract two SystemTimes to yield a TimeDelta object, which can be converted to seconds, milliseconds, etc.

TimeDelta objects are 32-bit, with millisecond resolution. They are much more efficient to store and to perform arithmetic on than SystemTime.

Constructor & Destructor Documentation

Sifteo::SystemTime::SystemTime ( )
inline

Creates an invalid SystemTime.

Using it will result in an ASSERT failure, but this invalid value can be used as a sentinel. You can test for this value with isValid().

Member Function Documentation

TimeDelta Sifteo::SystemTime::cycleDelta ( TimeDelta  period) const
inline

Measure the amount of time since the beginning of a repeating cycle with arbitrary phase and the specified period.

This can be used, for example, to implement ambient animations which must repeat at a particular rate but which don't need any particular phase alignment with respect to the rest of the game.

unsigned Sifteo::SystemTime::cycleFrame ( TimeDelta  period,
unsigned  frames 
) const
inline

Like cycleDelta(), but scales the result to the range [0, frames-1].

This can be used directly to compute the frame in an animation that repeats with the specified period.

bool Sifteo::SystemTime::isValid ( ) const
inline

Is this SystemTime valid?

Returns true if it was returned by now(), false if it was an uninitialized value or a copy of an uninitialized value.

TimeDelta Sifteo::SystemTime::operator- ( SystemTime  b) const
inline

Subtract two SystemTimes, and return a 32-bit TimeDelta, with millisecond resolution.

TimeDeltas are truncated to the neares millisecond boundary. (Round toward zero)


The documentation for this class was generated from the following file: