"L. Spiro Engine"
|
00001 00020 #ifndef __LSSTD_TIME_H__ 00021 #define __LSSTD_TIME_H__ 00022 00023 #include "../LSSTDStandardLib.h" 00024 00025 #if defined( MACOS_X ) || defined( __APPLE__ ) 00026 // Macintosh. 00027 #include <mach/mach.h> 00028 #include <mach/mach_time.h> 00029 #define LSSTD_TIME_MAC 00030 00031 #endif // #if defined( MACOS_X ) || defined( __APPLE__ ) 00032 00033 namespace lsstd { 00034 00045 class CTime { 00046 public : 00047 // == Various constructors. 00048 LSE_CALL CTime(); 00049 00050 // == Functions. 00056 LSE_INLINE LSUINT64 LSE_CALL GetCurMicros() const; 00057 00063 LSE_INLINE LSUINT64 LSE_CALL GetCurVirtMicros() const; 00064 00070 LSE_INLINE LSUINT64 LSE_CALL GetCurMills() const; 00071 00077 LSE_INLINE LSUINT64 LSE_CALL GetCurVirtMills() const; 00078 00084 LSE_INLINE LSUINT32 LSE_CALL GetCurFrame() const; 00085 00091 LSE_INLINE LSUINT32 LSE_CALL GetCurVirtFrame() const; 00092 00098 LSE_INLINE LSUINT64 LSE_CALL GetMicrosSinceLastFrame() const; 00099 00105 LSE_INLINE LSUINT64 LSE_CALL GetVirtMicrosSinceLastFrame() const; 00106 00112 LSE_INLINE LSUINT64 LSE_CALL GetMillsSinceLastFrame() const; 00113 00119 LSE_INLINE LSUINT64 LSE_CALL GetVirtMillsSinceLastFrame() const; 00120 00126 LSE_INLINE LSFLOAT LSE_CALL GetSecondsSinceLastFrame() const; 00127 00133 LSE_INLINE LSFLOAT LSE_CALL GetVirtSecondsSinceLastFrame() const; 00134 00142 LSE_INLINE LSUINT64 LSE_CALL GetTicksSinceLastFrame() const; 00143 00150 LSE_INLINE LSUINT64 LSE_CALL GetCurTicks() const; 00151 00155 LSVOID LSE_CALL Reset(); 00156 00162 LSVOID LSE_CALL Update( LSBOOL _bUpdateVirtuals ); 00163 00170 LSVOID LSE_CALL UpdateBy( LSUINT64 _ui64Amnt, LSBOOL _bUpdateVirtuals ); 00171 00178 LSVOID LSE_CALL UpdateByConstantTime( LSUINT64 _ui64Amnt, LSBOOL _bUpdateVirtuals ); 00179 00192 LSUINT32 LSE_CALL GetConstantStepUpdateTimesFromTicks( LSUINT64 _ui64Ticks, LSUINT32 &_ui32UnitsToNextUpdate ); 00193 00200 LSUINT64 LSE_CALL MicrosToTicks( LSUINT64 _ui64Amnt ) const; 00201 00208 LSUINT64 LSE_CALL GetRealTime() const; 00209 00210 00211 protected : 00212 // == Members. 00216 LSUINT64 m_ui64Resolution; 00217 00221 LSUINT64 m_ui64CurTime; 00222 00226 LSUINT64 m_ui64LastTime; 00227 00231 LSUINT64 m_ui64CurVirtTime; 00232 LSUINT64 m_ui64LastVirtTime; 00233 00237 LSUINT64 m_ui64LastRealTime; 00238 00242 LSUINT64 m_ui64CurMicros; 00243 00247 LSUINT64 m_ui64LastMicros; 00248 00252 LSUINT64 m_ui64CurVirtMicros; 00253 00257 LSUINT64 m_ui64LastVirtMicros; 00258 00262 LSUINT32 m_ui32Frame; 00263 LSUINT32 m_ui32VirtFrame; 00264 00268 LSBOOL m_bHiRes; 00269 00270 #ifdef LSSTD_TIME_MAC 00271 mach_timebase_info_data_t m_mtidTimeData; 00272 #endif // #ifdef LSSTD_TIME_MAC 00273 }; 00274 00275 00276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00277 // DEFINITIONS 00278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00279 // == Functions. 00285 LSE_INLINE LSUINT64 LSE_CALL CTime::GetCurMicros() const { 00286 return m_ui64CurMicros; 00287 } 00288 00294 LSE_INLINE LSUINT64 LSE_CALL CTime::GetCurVirtMicros() const { 00295 return m_ui64CurVirtMicros; 00296 } 00297 00303 LSE_INLINE LSUINT64 LSE_CALL CTime::GetCurMills() const { 00304 return m_ui64CurMicros / 1000ULL; 00305 } 00306 00312 LSE_INLINE LSUINT64 LSE_CALL CTime::GetCurVirtMills() const { 00313 return m_ui64CurVirtMicros / 1000ULL; 00314 } 00315 00321 LSE_INLINE LSUINT32 LSE_CALL CTime::GetCurFrame() const { 00322 return m_ui32Frame; 00323 } 00324 00330 LSE_INLINE LSUINT32 LSE_CALL CTime::GetCurVirtFrame() const { 00331 return m_ui32VirtFrame; 00332 } 00333 00339 LSE_INLINE LSUINT64 LSE_CALL CTime::GetMicrosSinceLastFrame() const { 00340 return GetCurMicros() - m_ui64LastMicros; 00341 } 00342 00348 LSE_INLINE LSUINT64 LSE_CALL CTime::GetVirtMicrosSinceLastFrame() const { 00349 return GetCurVirtMicros() - m_ui64LastVirtMicros; 00350 } 00351 00357 LSE_INLINE LSUINT64 LSE_CALL CTime::GetMillsSinceLastFrame() const { 00358 return GetCurMills() - m_ui64LastMicros / 1000ULL; 00359 } 00360 00366 LSE_INLINE LSUINT64 LSE_CALL CTime::GetVirtMillsSinceLastFrame() const { 00367 return GetCurVirtMills() - m_ui64CurVirtMicros / 1000ULL; 00368 } 00369 00375 LSE_INLINE LSFLOAT LSE_CALL CTime::GetSecondsSinceLastFrame() const { 00376 return GetMicrosSinceLastFrame() * (1.0f / 1000000.0f); 00377 } 00378 00384 LSE_INLINE LSFLOAT LSE_CALL CTime::GetVirtSecondsSinceLastFrame() const { 00385 return GetVirtMicrosSinceLastFrame() * (1.0f / 1000000.0f); 00386 } 00387 00395 LSE_INLINE LSUINT64 LSE_CALL CTime::GetTicksSinceLastFrame() const { 00396 return m_ui64CurTime - m_ui64LastTime; 00397 } 00398 00405 LSE_INLINE LSUINT64 LSE_CALL CTime::GetCurTicks() const { 00406 return m_ui64CurTime; 00407 } 00408 00409 } // namespace lsstd 00410 00411 #endif // __LSSTD_TIME_H__