mirror of
https://gitlab.com/GaryOderNichts/re3-wiiu.git
synced 2024-11-25 18:46:52 +01:00
Refactor CTimer::Update
This commit is contained in:
parent
5c1af537af
commit
1f082a85cb
@ -83,14 +83,14 @@ void CTimer::Shutdown(void)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
#ifdef FIX_BUGS
|
||||
void CTimer::Update(void)
|
||||
{
|
||||
#ifdef FIX_BUGS
|
||||
static double frameTimeLogical = 0.0;
|
||||
static double frameTimeFraction = 0.0;
|
||||
static double frameTimeFractionScaled = 0.0;
|
||||
#endif
|
||||
double frameTime;
|
||||
double dblUpdInMs;
|
||||
|
||||
m_snPreviousTimeInMilliseconds = m_snTimeInMilliseconds;
|
||||
|
||||
@ -105,49 +105,100 @@ void CTimer::Update(void)
|
||||
_oldPerfCounter = pc;
|
||||
|
||||
// bugfix from VC
|
||||
#ifdef FIX_BUGS
|
||||
float updInCyclesScaled = GetIsPaused() ? updInCycles : updInCycles * ms_fTimeScale;
|
||||
#else
|
||||
float updInCyclesScaled = updInCycles * ms_fTimeScale;
|
||||
|
||||
frameTime = updInCyclesScaled / (double)_nCyclesPerMS;
|
||||
|
||||
dblUpdInMs = (double)updInCycles / (double)_nCyclesPerMS;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
RsTimerType timer = RsTimer();
|
||||
|
||||
RsTimerType updInMs = timer - oldPcTimer;
|
||||
|
||||
frameTime = (double)updInMs * ms_fTimeScale;
|
||||
|
||||
oldPcTimer = timer;
|
||||
|
||||
dblUpdInMs = (double)updInMs;
|
||||
}
|
||||
|
||||
// count frames as if we're running at 30 fps
|
||||
m_LogicalFramesPassed = 0;
|
||||
frameTimeLogical += dblUpdInMs;
|
||||
while(frameTimeLogical >= 1000.0 / 30.0) {
|
||||
frameTimeLogical -= 1000.0 / 30.0;
|
||||
m_LogicalFramesPassed++;
|
||||
}
|
||||
m_LogicalFrameCounter += m_LogicalFramesPassed;
|
||||
|
||||
frameTimeFraction += dblUpdInMs;
|
||||
frameTimeFractionScaled += frameTime;
|
||||
|
||||
m_snTimeInMillisecondsPauseMode += uint32(frameTimeFraction);
|
||||
|
||||
if ( GetIsPaused() )
|
||||
ms_fTimeStep = 0.0f;
|
||||
else
|
||||
{
|
||||
m_snTimeInMilliseconds += uint32(frameTimeFractionScaled);
|
||||
m_snTimeInMillisecondsNonClipped += uint32(frameTimeFractionScaled);
|
||||
ms_fTimeStep = frameTime / 1000.0f * 50.0f;
|
||||
}
|
||||
frameTimeFraction -= uint32(frameTimeFraction);
|
||||
frameTimeFractionScaled -= uint32(frameTimeFractionScaled);
|
||||
|
||||
if ( ms_fTimeStep < 0.01f && !GetIsPaused() )
|
||||
ms_fTimeStep = 0.01f;
|
||||
|
||||
ms_fTimeStepNonClipped = ms_fTimeStep;
|
||||
|
||||
if ( !CRecordDataForGame::IsPlayingBack() )
|
||||
{
|
||||
ms_fTimeStep = Min(3.0f, ms_fTimeStep);
|
||||
|
||||
if ( (m_snTimeInMilliseconds - m_snPreviousTimeInMilliseconds) > 60 )
|
||||
m_snTimeInMilliseconds = m_snPreviousTimeInMilliseconds + 60;
|
||||
}
|
||||
|
||||
if ( CRecordDataForChase::IsRecording() )
|
||||
{
|
||||
ms_fTimeStep = 1.0f;
|
||||
m_snTimeInMilliseconds = m_snPreviousTimeInMilliseconds + 16;
|
||||
}
|
||||
|
||||
m_FrameCounter++;
|
||||
}
|
||||
#else
|
||||
void CTimer::Update(void)
|
||||
{
|
||||
m_snPreviousTimeInMilliseconds = m_snTimeInMilliseconds;
|
||||
|
||||
#ifdef _WIN32
|
||||
if ( (double)_nCyclesPerMS != 0.0 )
|
||||
{
|
||||
LARGE_INTEGER pc;
|
||||
QueryPerformanceCounter(&pc);
|
||||
|
||||
int32 updInCycles = (pc.LowPart - _oldPerfCounter.LowPart); // & 0x7FFFFFFF; pointless
|
||||
|
||||
_oldPerfCounter = pc;
|
||||
|
||||
float updInCyclesScaled = updInCycles * ms_fTimeScale;
|
||||
|
||||
double frameTime = updInCyclesScaled / (double)_nCyclesPerMS;
|
||||
|
||||
#ifdef FIX_BUGS
|
||||
// count frames as if we're running at 30 fps
|
||||
m_LogicalFramesPassed = 0;
|
||||
frameTimeLogical += ((double)updInCycles / (double)_nCyclesPerMS);
|
||||
while (frameTimeLogical >= 1000.0 / 30.0) {
|
||||
frameTimeLogical -= 1000.0 / 30.0;
|
||||
m_LogicalFramesPassed++;
|
||||
}
|
||||
m_LogicalFrameCounter += m_LogicalFramesPassed;
|
||||
|
||||
frameTimeFraction += (double)updInCycles / (double)_nCyclesPerMS;
|
||||
frameTimeFractionScaled += frameTime;
|
||||
|
||||
m_snTimeInMillisecondsPauseMode += uint32(frameTimeFraction);
|
||||
#else
|
||||
m_snTimeInMillisecondsPauseMode = m_snTimeInMillisecondsPauseMode + frameTime;
|
||||
#endif
|
||||
|
||||
if ( GetIsPaused() )
|
||||
ms_fTimeStep = 0.0f;
|
||||
else
|
||||
{
|
||||
#ifdef FIX_BUGS
|
||||
m_snTimeInMilliseconds += uint32(frameTimeFractionScaled);
|
||||
m_snTimeInMillisecondsNonClipped += uint32(frameTimeFractionScaled);
|
||||
#else
|
||||
m_snTimeInMilliseconds = m_snTimeInMilliseconds + frameTime;
|
||||
m_snTimeInMillisecondsNonClipped = m_snTimeInMillisecondsNonClipped + frameTime;
|
||||
#endif
|
||||
ms_fTimeStep = frameTime / 1000.0f * 50.0f;
|
||||
}
|
||||
#ifdef FIX_BUGS
|
||||
frameTimeFraction -= uint32(frameTimeFraction);
|
||||
frameTimeFractionScaled -= uint32(frameTimeFractionScaled);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@ -160,41 +211,16 @@ void CTimer::Update(void)
|
||||
|
||||
oldPcTimer = timer;
|
||||
|
||||
#ifdef FIX_BUGS
|
||||
// count frames as if we're running at 30 fps
|
||||
m_LogicalFramesPassed = 0;
|
||||
frameTimeLogical += (double)updInMs;
|
||||
while(frameTimeLogical >= 1000.0 / 30.0) {
|
||||
frameTimeLogical -= 1000.0 / 30.0;
|
||||
m_LogicalFramesPassed++;
|
||||
}
|
||||
m_LogicalFrameCounter += m_LogicalFramesPassed;
|
||||
|
||||
frameTimeFraction += (double)updInMs;
|
||||
frameTimeFractionScaled += frameTime;
|
||||
|
||||
m_snTimeInMillisecondsPauseMode += uint32(frameTimeFraction);
|
||||
#else
|
||||
m_snTimeInMillisecondsPauseMode = m_snTimeInMillisecondsPauseMode + frameTime;
|
||||
#endif
|
||||
|
||||
if ( GetIsPaused() )
|
||||
ms_fTimeStep = 0.0f;
|
||||
else
|
||||
{
|
||||
#ifdef FIX_BUGS
|
||||
m_snTimeInMilliseconds += uint32(frameTimeFractionScaled);
|
||||
m_snTimeInMillisecondsNonClipped += uint32(frameTimeFractionScaled);
|
||||
#else
|
||||
m_snTimeInMilliseconds = m_snTimeInMilliseconds + frameTime;
|
||||
m_snTimeInMillisecondsNonClipped = m_snTimeInMillisecondsNonClipped + frameTime;
|
||||
#endif
|
||||
ms_fTimeStep = frameTime / 1000.0f * 50.0f;
|
||||
}
|
||||
#ifdef FIX_BUGS
|
||||
frameTimeFraction -= uint32(frameTimeFraction);
|
||||
frameTimeFractionScaled -= uint32(frameTimeFractionScaled);
|
||||
#endif
|
||||
}
|
||||
|
||||
if ( ms_fTimeStep < 0.01f && !GetIsPaused() )
|
||||
@ -218,6 +244,7 @@ void CTimer::Update(void)
|
||||
|
||||
m_FrameCounter++;
|
||||
}
|
||||
#endif
|
||||
|
||||
void CTimer::Suspend(void)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user