llframetimer.cpp

Go to the documentation of this file.
00001 
00031 #include "linden_common.h"
00032 
00033 #include "u64.h"
00034 
00035 #include "llframetimer.h"
00036 
00037 // Static members
00038 //LLTimer       LLFrameTimer::sInternalTimer;
00039 U64 LLFrameTimer::sStartTotalTime = totalTime();
00040 F64 LLFrameTimer::sFrameTime = 0.0;
00041 U64 LLFrameTimer::sTotalTime = 0;
00042 F64 LLFrameTimer::sTotalSeconds = 0.0;
00043 S32 LLFrameTimer::sFrameCount = 0;
00044 U64 LLFrameTimer::sFrameDeltaTime = 0;
00045 const F64 USEC_PER_SECOND = 1000000.0;
00046 const F64 USEC_TO_SEC_F64 = 0.000001;
00047 
00048 // static
00049 void LLFrameTimer::updateFrameTime()
00050 {
00051         U64 total_time = totalTime();
00052         sFrameDeltaTime = total_time - sTotalTime;
00053         sTotalTime = total_time;
00054         sTotalSeconds = U64_to_F64(sTotalTime) * USEC_TO_SEC_F64;
00055         sFrameTime = U64_to_F64(sTotalTime - sStartTotalTime) * USEC_TO_SEC_F64;
00056         sFrameCount++;
00057 } 
00058 
00059 void LLFrameTimer::start()
00060 {
00061         reset();
00062         mStarted = TRUE;
00063 }
00064 
00065 void LLFrameTimer::stop()
00066 {
00067         mStarted = FALSE;
00068 }
00069 
00070 void LLFrameTimer::reset()
00071 {
00072         mStartTime = sFrameTime;
00073         mExpiry = sFrameTime;
00074 }
00075 
00076 void LLFrameTimer::resetWithExpiry(F32 expiration)
00077 {
00078         reset();
00079         setTimerExpirySec(expiration);
00080 }
00081 
00082 // Don't combine pause/unpause with start/stop
00083 // Useage:
00084 //  LLFrameTime foo; // starts automatically
00085 //  foo.unpause(); // noop but safe
00086 //  foo.pause(); // pauses timer
00087 //  foo.unpause() // unpauses
00088 //  F32 elapsed = foo.getElapsedTimeF32() // does not include time between pause() and unpause()
00089 //  Note: elapsed would also be valid with no unpause() call (= time run until pause() called)
00090 void LLFrameTimer::pause()
00091 {
00092         if (mStarted)
00093                 mStartTime = sFrameTime - mStartTime; // save dtime
00094         mStarted = FALSE;
00095 }
00096 
00097 void LLFrameTimer::unpause()
00098 {
00099         if (!mStarted)
00100                 mStartTime = sFrameTime - mStartTime; // restore dtime
00101         mStarted = TRUE;
00102 }
00103 
00104 void LLFrameTimer::setTimerExpirySec(F32 expiration)
00105 {
00106         mExpiry = expiration + mStartTime;
00107 }
00108 
00109 void LLFrameTimer::setExpiryAt(F64 seconds_since_epoch)
00110 {
00111         mStartTime = sFrameTime;
00112         mExpiry = seconds_since_epoch - (USEC_TO_SEC_F64 * sStartTotalTime);
00113 }
00114 
00115 F64 LLFrameTimer::expiresAt() const
00116 {
00117         F64 expires_at = U64_to_F64(sStartTotalTime) * USEC_TO_SEC_F64;
00118         expires_at += mExpiry;
00119         return expires_at;
00120 }
00121 
00122 BOOL LLFrameTimer::checkExpirationAndReset(F32 expiration)
00123 {
00124         //llinfos << "LLFrameTimer::checkExpirationAndReset()" << llendl;
00125         //llinfos << "  mStartTime:" << mStartTime << llendl;
00126         //llinfos << "  sFrameTime:" << sFrameTime << llendl;
00127         //llinfos << "  mExpiry:   " <<  mExpiry << llendl;
00128 
00129         if(hasExpired())
00130         {
00131                 reset();
00132                 setTimerExpirySec(expiration);
00133                 return TRUE;
00134         }
00135         return FALSE;
00136 }
00137 
00138 // static
00139 F32 LLFrameTimer::getFrameDeltaTimeF32()
00140 {
00141         return (F32)(U64_to_F64(sFrameDeltaTime) * USEC_TO_SEC_F64); 
00142 }

Generated on Thu Jul 1 06:08:39 2010 for Second Life Viewer by  doxygen 1.4.7