diff options
author | eray orçunus <erayorcunus@gmail.com> | 2020-05-11 04:55:57 +0200 |
---|---|---|
committer | eray orçunus <erayorcunus@gmail.com> | 2020-05-11 20:00:55 +0200 |
commit | 8a4fa58cd42b7cca4a86fe2d9913b839b554bf10 (patch) | |
tree | 294e44de2168e1b581ba847775d827924c07bf2e /src/core/Timer.cpp | |
parent | Merge pull request #509 from Fire-Head/master (diff) | |
download | re3-8a4fa58cd42b7cca4a86fe2d9913b839b554bf10.tar re3-8a4fa58cd42b7cca4a86fe2d9913b839b554bf10.tar.gz re3-8a4fa58cd42b7cca4a86fe2d9913b839b554bf10.tar.bz2 re3-8a4fa58cd42b7cca4a86fe2d9913b839b554bf10.tar.lz re3-8a4fa58cd42b7cca4a86fe2d9913b839b554bf10.tar.xz re3-8a4fa58cd42b7cca4a86fe2d9913b839b554bf10.tar.zst re3-8a4fa58cd42b7cca4a86fe2d9913b839b554bf10.zip |
Diffstat (limited to 'src/core/Timer.cpp')
-rw-r--r-- | src/core/Timer.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/core/Timer.cpp b/src/core/Timer.cpp index aca7c1dc..ed5580fd 100644 --- a/src/core/Timer.cpp +++ b/src/core/Timer.cpp @@ -1,5 +1,6 @@ #define WITHWINDOWS #include "common.h" +#include "crossplatform.h" #include "DMAudio.h" #include "Record.h" @@ -16,15 +17,19 @@ float CTimer::ms_fTimeStepNonClipped; bool CTimer::m_UserPause; bool CTimer::m_CodePause; -uint32 oldPcTimer; - -uint32 suspendPcTimer; - uint32 _nCyclesPerMS = 1; +#ifdef _WIN32 LARGE_INTEGER _oldPerfCounter; - LARGE_INTEGER perfSuspendCounter; +#define RsTimerType uint32 +#else +#define RsTimerType double +#endif + +RsTimerType oldPcTimer; + +RsTimerType suspendPcTimer; uint32 suspendDepth; @@ -45,6 +50,7 @@ void CTimer::Initialise(void) m_snPreviousTimeInMilliseconds = 0; m_snTimeInMilliseconds = 1; +#ifdef _WIN32 LARGE_INTEGER perfFreq; if ( QueryPerformanceFrequency(&perfFreq) ) { @@ -53,6 +59,7 @@ void CTimer::Initialise(void) QueryPerformanceCounter(&_oldPerfCounter); } else +#endif { OutputDebugString("Performance counter not available, using millesecond timer\n"); _nCyclesPerMS = 0; @@ -77,6 +84,7 @@ void CTimer::Update(void) { m_snPreviousTimeInMilliseconds = m_snTimeInMilliseconds; +#ifdef _WIN32 if ( (double)_nCyclesPerMS != 0.0 ) { LARGE_INTEGER pc; @@ -106,10 +114,11 @@ void CTimer::Update(void) } } else +#endif { - uint32 timer = RsTimer(); + RsTimerType timer = RsTimer(); - uint32 updInMs = timer - oldPcTimer; + RsTimerType updInMs = timer - oldPcTimer; // We need that real frame time to fix transparent menu bug. #ifndef FIX_BUGS @@ -158,9 +167,11 @@ void CTimer::Suspend(void) if ( ++suspendDepth > 1 ) return; +#ifdef _WIN32 if ( (double)_nCyclesPerMS != 0.0 ) QueryPerformanceCounter(&perfSuspendCounter); else +#endif suspendPcTimer = RsTimer(); } @@ -169,6 +180,7 @@ void CTimer::Resume(void) if ( --suspendDepth != 0 ) return; +#ifdef _WIN32 if ( (double)_nCyclesPerMS != 0.0 ) { LARGE_INTEGER pc; @@ -177,19 +189,23 @@ void CTimer::Resume(void) _oldPerfCounter.LowPart += pc.LowPart - perfSuspendCounter.LowPart; } else +#endif oldPcTimer += RsTimer() - suspendPcTimer; } uint32 CTimer::GetCyclesPerMillisecond(void) { +#ifdef _WIN32 if (_nCyclesPerMS != 0) return _nCyclesPerMS; else +#endif return 1; } uint32 CTimer::GetCurrentTimeInCycles(void) { +#ifdef _WIN32 if ( _nCyclesPerMS != 0 ) { LARGE_INTEGER pc; @@ -197,6 +213,7 @@ uint32 CTimer::GetCurrentTimeInCycles(void) return (pc.LowPart - _oldPerfCounter.LowPart); // & 0x7FFFFFFF; pointless } else +#endif return RsTimer() - oldPcTimer; } |