llframetimer.h

Go to the documentation of this file.
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         // Return seconds since the current frame started
00078         static F32  getCurrentFrameTime();
00079 
00080         // MANIPULATORS
00081         void start();
00082         void stop();
00083         void reset();
00084         void resetWithExpiry(F32 expiration);
00085         void pause();
00086         void unpause();
00087         void setTimerExpirySec(F32 expiration);
00088         void setExpiryAt(F64 seconds_since_epoch);
00089         BOOL checkExpirationAndReset(F32 expiration);
00090         F32 getElapsedTimeAndResetF32()                                 { F32 t = F32(sFrameTime - mStartTime); reset(); return t; }
00091 
00092         void setAge(const F64 age)                                              { mStartTime = sFrameTime - age; }
00093 
00094         // ACCESSORS
00095         BOOL hasExpired() const                                                 { return (sFrameTime >= mExpiry); }
00096         F32  getTimeToExpireF32() const                                 { return (F32)(mExpiry - sFrameTime); }
00097         F32  getElapsedTimeF32() const                                  { return mStarted ? (F32)(sFrameTime - mStartTime) : (F32)mStartTime; }
00098         BOOL getStarted() const                                                 { return mStarted; }
00099 
00100         // return the seconds since epoch when this timer will expire.
00101         F64 expiresAt() const;
00102 
00103 protected:      
00104         // A single, high resolution timer that drives all LLFrameTimers
00105         // *NOTE: no longer used.
00106         //static LLTimer sInternalTimer;                
00107 
00108         //
00109         // Aplication constants
00110         //
00111 
00112         // Start time of opp in usec since epoch
00113         static U64 sStartTotalTime;     
00114 
00115         // 
00116         // Data updated per frame
00117         //
00118 
00119         // Seconds since application start
00120         static F64 sFrameTime;
00121 
00122         // Time that has elapsed since last call to updateFrameTime()
00123         static U64 sFrameDeltaTime;
00124 
00125         // Total microseconds since epoch.
00126         static U64 sTotalTime;                  
00127 
00128         // Seconds since epoch.
00129         static F64 sTotalSeconds;
00130 
00131         // Total number of frames elapsed in application
00132         static S32 sFrameCount;
00133 
00134         //
00135         // Member data
00136         //
00137 
00138         // Number of seconds after application start when this timer was
00139         // started. Set equal to sFrameTime when reset.
00140         F64 mStartTime;
00141 
00142         // Timer expires this many seconds after application start time.
00143         F64 mExpiry;
00144 
00145         // Useful bit of state usually associated with timers, but does
00146         // not affect actual functionality
00147         BOOL mStarted;
00148 };
00149 
00150 // Glue code for Havok (or anything else that doesn't want the full .h files)
00151 extern F32  getCurrentFrameTime();
00152 
00153 #endif  // LL_LLFRAMETIMER_H

Generated on Fri May 16 08:32:03 2008 for SecondLife by  doxygen 1.5.5