28 # error This is a userspace-only header, not allowed by the current build.
31 #include <sifteo/macros.h>
32 #include <sifteo/abi.h>
68 TimeDelta(
double sec) : mMilli(sec * 1e3) {}
99 return mMilli * (int64_t)1000000;
106 return mMilli * 1e-3;
125 return mMilli / duration.mMilli;
143 unsigned f =
frames(duration);
145 mMilli -= duration.mMilli * f;
174 friend class SystemTime;
180 inline bool operator== (TimeDelta a, TimeDelta b) {
return a.milliseconds() == b.milliseconds(); }
181 inline bool operator!= (TimeDelta a, TimeDelta b) {
return a.milliseconds() != b.milliseconds(); }
182 inline bool operator< (TimeDelta a, TimeDelta b) {
return a.milliseconds() < b.milliseconds(); }
183 inline bool operator> (TimeDelta a, TimeDelta b) {
return a.milliseconds() > b.milliseconds(); }
184 inline bool operator<= (TimeDelta a, TimeDelta b) {
return a.milliseconds() <= b.milliseconds(); }
185 inline bool operator>= (TimeDelta a, TimeDelta b) {
return a.milliseconds() >= b.milliseconds(); }
187 inline bool operator== (TimeDelta a,
float b) {
return a.milliseconds() == TimeDelta(b).milliseconds(); }
188 inline bool operator!= (TimeDelta a,
float b) {
return a.milliseconds() != TimeDelta(b).milliseconds(); }
189 inline bool operator< (TimeDelta a,
float b) {
return a.milliseconds() < TimeDelta(b).milliseconds(); }
190 inline bool operator> (TimeDelta a,
float b) {
return a.milliseconds() > TimeDelta(b).milliseconds(); }
191 inline bool operator<= (TimeDelta a,
float b) {
return a.milliseconds() <= TimeDelta(b).milliseconds(); }
192 inline bool operator>= (TimeDelta a,
float b) {
return a.milliseconds() >= TimeDelta(b).milliseconds(); }
194 inline bool operator== (
float a, TimeDelta b) {
return TimeDelta(a).milliseconds() == b.milliseconds(); }
195 inline bool operator!= (
float a, TimeDelta b) {
return TimeDelta(a).milliseconds() != b.milliseconds(); }
196 inline bool operator< (
float a, TimeDelta b) {
return TimeDelta(a).milliseconds() < b.milliseconds(); }
197 inline bool operator> (
float a, TimeDelta b) {
return TimeDelta(a).milliseconds() > b.milliseconds(); }
198 inline bool operator<= (
float a, TimeDelta b) {
return TimeDelta(a).milliseconds() <= b.milliseconds(); }
199 inline bool operator>= (
float a, TimeDelta b) {
return TimeDelta(a).milliseconds() >= b.milliseconds(); }
201 inline bool operator== (TimeDelta a,
double b) {
return a.milliseconds() == TimeDelta(b).milliseconds(); }
202 inline bool operator!= (TimeDelta a,
double b) {
return a.milliseconds() != TimeDelta(b).milliseconds(); }
203 inline bool operator< (TimeDelta a,
double b) {
return a.milliseconds() < TimeDelta(b).milliseconds(); }
204 inline bool operator> (TimeDelta a,
double b) {
return a.milliseconds() > TimeDelta(b).milliseconds(); }
205 inline bool operator<= (TimeDelta a,
double b) {
return a.milliseconds() <= TimeDelta(b).milliseconds(); }
206 inline bool operator>= (TimeDelta a,
double b) {
return a.milliseconds() >= TimeDelta(b).milliseconds(); }
208 inline bool operator== (
double a, TimeDelta b) {
return TimeDelta(a).milliseconds() == b.milliseconds(); }
209 inline bool operator!= (
double a, TimeDelta b) {
return TimeDelta(a).milliseconds() != b.milliseconds(); }
210 inline bool operator< (
double a, TimeDelta b) {
return TimeDelta(a).milliseconds() < b.milliseconds(); }
211 inline bool operator> (
double a, TimeDelta b) {
return TimeDelta(a).milliseconds() > b.milliseconds(); }
212 inline bool operator<= (
double a, TimeDelta b) {
return TimeDelta(a).milliseconds() <= b.milliseconds(); }
213 inline bool operator>= (
double a, TimeDelta b) {
return TimeDelta(a).milliseconds() >= b.milliseconds(); }
215 inline TimeDelta operator+ (TimeDelta a, TimeDelta b) {
return TimeDelta::fromMillisec(a.milliseconds() + b.milliseconds()); }
216 inline TimeDelta operator- (TimeDelta a, TimeDelta b) {
return TimeDelta::fromMillisec(a.milliseconds() - b.milliseconds()); }
228 inline float operator+= (
float &a, TimeDelta b) {
return a += b.
seconds(); }
229 inline float operator-= (
float &a, TimeDelta b) {
return a -= b.seconds(); }
287 return mTicks >
now().mTicks;
294 return mTicks <
now().mTicks;
310 return mTicks / (uint64_t)1000;
318 return mTicks / (uint64_t)1000000;
327 return mTicks * 1e-9;
374 return TimeDelta((int32_t)(diff / 1000000));
378 SystemTime &operator-= (
const TimeDelta &rhs) { mTicks -= rhs.nanoseconds();
return *
this; }
388 inline bool operator== (SystemTime a, SystemTime b) {
return a.uptimeNS() == b.uptimeNS(); }
389 inline bool operator!= (SystemTime a, SystemTime b) {
return a.uptimeNS() != b.uptimeNS(); }
390 inline bool operator< (SystemTime a, SystemTime b) {
return a.uptimeNS() < b.uptimeNS(); }
391 inline bool operator> (SystemTime a, SystemTime b) {
return a.uptimeNS() > b.uptimeNS(); }
392 inline bool operator<= (SystemTime a, SystemTime b) {
return a.uptimeNS() <= b.uptimeNS(); }
393 inline bool operator>= (SystemTime a, SystemTime b) {
return a.uptimeNS() >= b.uptimeNS(); }
395 inline SystemTime operator+ (TimeDelta a, SystemTime b) {
return b + a; }
396 inline SystemTime operator- (TimeDelta a, SystemTime b) {
return b - a; }
414 TimeStep() : mPrevTime(), mDelta(0.0) {}
448 return mPrevTime - mDelta;
465 mDelta = now - mPrevTime;
497 TimeTicker() : mRemainder(0.0f), mPeriod(0.0) {}
504 void setRate(
float hz) {
SystemTime()
Creates an invalid SystemTime.
Definition: time.h:264
int32_t milliseconds() const
Return the delta in milliseconds.
Definition: time.h:91
SystemTime end() const
Retrieve the SystemTime at the end of the interval described by delta().
Definition: time.h:433
uint64_t uptimeUS() const
Return the SystemTime as a count of microseconds since boot.
Definition: time.h:308
SystemTime begin() const
Retrieve the SystemTime at the beginning of the interval described by delta().
Definition: time.h:445
Represents a difference between two SystemTimes, with moderate resolution.
Definition: time.h:58
bool inFuture() const
Is this time in the future?
Definition: time.h:286
static SystemTime now()
Returns a new SystemTime representing the current system clock value.
Definition: time.h:269
void next()
Advance to the next time interval.
Definition: time.h:457
#define ASSERT(_x)
Runtime debug assertion.
Definition: macros.h:205
TimeDelta cycleDelta(TimeDelta period) const
Measure the amount of time since the beginning of a repeating cycle with arbitrary phase and the spec...
Definition: time.h:339
TimeStep is a higher-level utility for keeping track of time the duration of game timesteps...
Definition: time.h:412
unsigned pullFrames(TimeDelta duration)
Return a frame count, and subtract (pull) the time corresponding with those frames from this TimeDelt...
Definition: time.h:142
bool inPast() const
Is this time in the past?
Definition: time.h:293
bool isNegative() const
Is this time value negative?
Definition: time.h:155
double uptime() const
Return the SystemTime, in seconds since boot. Returns a double-precision floating point value...
Definition: time.h:325
bool isValid() const
Is this SystemTime valid?
Definition: time.h:279
bool isPositive() const
Is this time value positive?
Definition: time.h:160
int64_t nanoseconds() const
Return the delta in nanoseconds.
Definition: time.h:98
TimeDelta delta() const
Retrieve the duration of the last time interval.
Definition: time.h:422
TimeDelta(float sec)
Construct a new TimeDelta from a floating point time, in seconds.
Definition: time.h:67
uint64_t uptimeMS() const
Return the SystemTime as a count of milliseconds since boot.
Definition: time.h:316
unsigned frames(TimeDelta duration) const
Return the number of frames, of a particular duration, that are represented by this time delta...
Definition: time.h:122
float seconds() const
Return the delta in seconds, as a floating point value.
Definition: time.h:105
TimeTicker is a utility for converting a stream of time deltas into a stream of discrete ticks...
Definition: time.h:495
static TimeDelta hz(float h)
Construct a TimeDelta representing the period which corresponds with a given frequency.
Definition: time.h:77
Absolute time, measured by the system's monotonically increasing nanosecond timer.
Definition: time.h:256
static TimeDelta fromMillisec(int32_t m)
Construct a new TimeDelta from an integer time, in milliseconds.
Definition: time.h:84
unsigned cycleFrame(TimeDelta period, unsigned frames) const
Like cycleDelta(), but scales the result to the range [0, frames-1].
Definition: time.h:360
TimeDelta operator-(SystemTime b) const
Subtract two SystemTimes, and return a 32-bit TimeDelta, with millisecond resolution.
Definition: time.h:372
uint64_t uptimeNS() const
Return the SystemTime as a count of nanoseconds since boot.
Definition: time.h:300
float cyclePhase(TimeDelta period) const
Like cycleDelta(), but scales the result to the range [0,1], where 0 and 1 represent the beginning an...
Definition: time.h:349