00001 00033 #ifndef LL_LLFRAMETIMER_H 00034 #define LL_LLFRAMETIMER_H 00035 00042 #include "lltimer.h" 00043 #include "timing.h" 00044 00045 class LLFrameTimer 00046 { 00047 public: 00048 LLFrameTimer() : mStartTime( sFrameTime ), mExpiry(0), mStarted(TRUE) {} 00049 00050 // Return the number of seconds since the start of this 00051 // application instance. 00052 static F64 getElapsedSeconds() 00053 { 00054 // Loses msec precision after ~4.5 hours... 00055 return sFrameTime; 00056 } 00057 00058 // Return a low precision usec since epoch 00059 static U64 getTotalTime() 00060 { 00061 return sTotalTime ? sTotalTime : totalTime(); 00062 } 00063 00064 // Return a low precision seconds since epoch 00065 static F64 getTotalSeconds() 00066 { 00067 return sTotalSeconds; 00068 } 00069 00070 // Call this method once per frame to update the current frame time. 00071 static void updateFrameTime(); 00072 00073 static S32 getFrameCount() { return sFrameCount; } 00074 00075 static F32 getFrameDeltaTimeF32(); 00076 00077 // MANIPULATORS 00078 void start(); 00079 void stop(); 00080 void reset(); 00081 void resetWithExpiry(F32 expiration); 00082 void pause(); 00083 void unpause(); 00084 void setTimerExpirySec(F32 expiration); 00085 void setExpiryAt(F64 seconds_since_epoch); 00086 BOOL checkExpirationAndReset(F32 expiration); 00087 F32 getElapsedTimeAndResetF32() { F32 t = F32(sFrameTime - mStartTime); reset(); return t; } 00088 00089 void setAge(const F64 age) { mStartTime = sFrameTime - age; } 00090 00091 // ACCESSORS 00092 BOOL hasExpired() const { return (sFrameTime >= mExpiry); } 00093 F32 getTimeToExpireF32() const { return (F32)(mExpiry - sFrameTime); } 00094 F32 getElapsedTimeF32() const { return mStarted ? (F32)(sFrameTime - mStartTime) : (F32)mStartTime; } 00095 BOOL getStarted() const { return mStarted; } 00096 00097 // return the seconds since epoch when this timer will expire. 00098 F64 expiresAt() const; 00099 00100 protected: 00101 // A single, high resolution timer that drives all LLFrameTimers 00102 // *NOTE: no longer used. 00103 //static LLTimer sInternalTimer; 00104 00105 // 00106 // Aplication constants 00107 // 00108 00109 // Start time of opp in usec since epoch 00110 static U64 sStartTotalTime; 00111 00112 // 00113 // Data updated per frame 00114 // 00115 00116 // Seconds since application start 00117 static F64 sFrameTime; 00118 00119 // Time that has elapsed since last call to updateFrameTime() 00120 static U64 sFrameDeltaTime; 00121 00122 // Total microseconds since epoch. 00123 static U64 sTotalTime; 00124 00125 // Seconds since epoch. 00126 static F64 sTotalSeconds; 00127 00128 // Total number of frames elapsed in application 00129 static S32 sFrameCount; 00130 00131 // 00132 // Member data 00133 // 00134 00135 // Number of seconds after application start when this timer was 00136 // started. Set equal to sFrameTime when reset. 00137 F64 mStartTime; 00138 00139 // Timer expires this many seconds after application start time. 00140 F64 mExpiry; 00141 00142 // Useful bit of state usually associated with timers, but does 00143 // not affect actual functionality 00144 BOOL mStarted; 00145 }; 00146 00147 #endif // LL_LLFRAMETIMER_H