diff --git a/stepmania/src/RageTimer.cpp b/stepmania/src/RageTimer.cpp index a4936640d8..0c3d014e1a 100644 --- a/stepmania/src/RageTimer.cpp +++ b/stepmania/src/RageTimer.cpp @@ -38,6 +38,23 @@ float RageTimer::GetDeltaTime() return diff; } +/* Get a timer representing half of the time ago as this one. This is + * useful for averaging time. For example, + * + * RageTimer tm; + * ... do stuff ... + * RageTimer AverageTime = tm.Half(); + * printf("Something happened between now and tm; the average time is %f.\n", tm.Ago()); + * tm.Touch(); + */ +RageTimer RageTimer::Half() const +{ + const RageTimer now; + const float ProbableDelay = -(now - *this) / 2; + return *this + ProbableDelay; +} + + RageTimer RageTimer::operator+(float tm) const { return Sum(*this, tm); diff --git a/stepmania/src/RageTimer.h b/stepmania/src/RageTimer.h index 83056ee670..3310708b05 100644 --- a/stepmania/src/RageTimer.h +++ b/stepmania/src/RageTimer.h @@ -42,6 +42,9 @@ public: /* deprecated: */ static float GetTimeSinceStart(); // seconds since the program was started + /* Get a timer representing half of the time ago as this one. */ + RageTimer Half() const; + /* Add (or subtract) a duration from a timestamp. The result is another timestamp. */ RageTimer operator+(float tm) const;