add RageTimer::Half

This commit is contained in:
Glenn Maynard
2003-07-20 19:13:03 +00:00
parent b656bda455
commit e3274ec002
2 changed files with 20 additions and 0 deletions
+17
View File
@@ -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);
+3
View File
@@ -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;