Skip to content

Commit 61fccbc

Browse files
committed
Revert "Refactored frame rate limiter"
This reverts commit bc94009. This partially reverts 96549e8 as well. This is an investigatory fix for #763.
1 parent bff494d commit 61fccbc

File tree

6 files changed

+35
-82
lines changed

6 files changed

+35
-82
lines changed

Client/core/CCore.cpp

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,14 +1718,6 @@ void CCore::UpdateRecentlyPlayed()
17181718
CCore::GetSingleton().SaveConfig();
17191719
}
17201720

1721-
//
1722-
// Called just before GTA calculates frame time deltas
1723-
//
1724-
void CCore::OnGameTimerUpdate()
1725-
{
1726-
ApplyQueuedFrameRateLimit();
1727-
}
1728-
17291721
//
17301722
// Recalculate FPS limit to use
17311723
//
@@ -1801,47 +1793,34 @@ void CCore::ApplyFrameRateLimit(uint uiOverrideRate)
18011793

18021794
uint uiUseRate = uiOverrideRate != -1 ? uiOverrideRate : m_uiFrameRateLimit;
18031795

1804-
if (uiUseRate > 0)
1805-
{
1806-
// Apply previous frame rate if is hasn't been done yet
1807-
ApplyQueuedFrameRateLimit();
1796+
TIMING_GRAPH("Limiter");
1797+
1798+
if (uiUseRate < 1)
1799+
return DoReliablePulse();
1800+
1801+
if (m_DiagnosticDebug != EDiagnosticDebug::D3D_6732)
1802+
Sleep(1); // Make frame rate smoother maybe
18081803

1809-
// Limit is usually applied in OnGameTimerUpdate
1810-
m_uiQueuedFrameRate = uiUseRate;
1811-
m_bQueuedFrameRateValid = true;
1804+
// Calc required time in ms between frames
1805+
const double dTargetTimeToUse = 1000.0 / uiUseRate;
1806+
1807+
while(true)
1808+
{
1809+
// See if we need to wait
1810+
double dSpare = dTargetTimeToUse - m_FrameRateTimer.Get();
1811+
if (dSpare <= 0.0)
1812+
break;
1813+
if (dSpare >= 2.0)
1814+
Sleep(1);
18121815
}
1816+
m_FrameRateTimer.Reset();
18131817

18141818
DoReliablePulse();
18151819

18161820
TIMING_GRAPH("FrameEnd");
18171821
TIMING_GRAPH("");
18181822
}
18191823

1820-
//
1821-
// Frame rate limit (wait) is done here.
1822-
//
1823-
void CCore::ApplyQueuedFrameRateLimit()
1824-
{
1825-
if (m_bQueuedFrameRateValid)
1826-
{
1827-
m_bQueuedFrameRateValid = false;
1828-
// Calc required time in ms between frames
1829-
const double dTargetTimeToUse = 1000.0 / m_uiQueuedFrameRate;
1830-
1831-
while (true)
1832-
{
1833-
// See if we need to wait
1834-
double dSpare = dTargetTimeToUse - m_FrameRateTimer.Get();
1835-
if (dSpare <= 0.0)
1836-
break;
1837-
if (dSpare >= 2.0)
1838-
Sleep(1);
1839-
}
1840-
m_FrameRateTimer.Reset();
1841-
TIMING_GRAPH("Limiter");
1842-
}
1843-
}
1844-
18451824
//
18461825
// DoReliablePulse
18471826
//

Client/core/CCore.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
124124
void EnableChatInput(char* szCommand, DWORD dwColor);
125125
bool IsChatInputEnabled(void);
126126
bool ClearChat();
127-
void OnGameTimerUpdate(void);
128127

129128
// Screenshots
130129
void TakeScreenShot(void);
@@ -214,7 +213,6 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
214213
uint GetFrameRateLimit(void) { return m_uiFrameRateLimit; }
215214
void RecalculateFrameRateLimit(uint uiServerFrameRateLimit = -1, bool bLogToConsole = true);
216215
void ApplyFrameRateLimit(uint uiOverrideRate = -1);
217-
void ApplyQueuedFrameRateLimit(void);
218216
void EnsureFrameRateLimitApplied(void);
219217
void SetClientScriptFrameRateLimit(uint uiClientScriptFrameRateLimit);
220218
void DoReliablePulse(void);
@@ -351,8 +349,6 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
351349
uint m_uiClientScriptFrameRateLimit;
352350
uint m_uiFrameRateLimit;
353351
CElapsedTimeHD m_FrameRateTimer;
354-
uint m_uiQueuedFrameRate;
355-
bool m_bQueuedFrameRateValid;
356352
bool m_bWaitToSetNick;
357353
uint m_uiNewNickWaitFrames;
358354
EDiagnosticDebugType m_DiagnosticDebug;

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3909,14 +3909,19 @@ void CClientGame::PostWorldProcessHandler(void)
39093909
m_pManager->GetPointLightsManager()->DoPulse();
39103910
m_pManager->GetObjectManager()->DoPulse();
39113911

3912-
double dTimeSlice = m_TimeSliceTimer.Get();
3913-
m_TimeSliceTimer.Reset();
3914-
m_uiFrameCount++;
3912+
// Update frame time slice
3913+
uint uiCurrentTick = GetTickCount32();
3914+
if (m_uiLastFrameTick)
3915+
{
3916+
m_uiFrameTimeSlice = uiCurrentTick - m_uiLastFrameTick;
3917+
m_uiFrameCount++;
39153918

3916-
// Call onClientPreRender LUA event
3917-
CLuaArguments Arguments;
3918-
Arguments.PushNumber(dTimeSlice);
3919-
m_pRootEntity->CallEvent("onClientPreRender", Arguments, false);
3919+
// Call onClientPreRender LUA event
3920+
CLuaArguments Arguments;
3921+
Arguments.PushNumber(m_uiFrameTimeSlice);
3922+
m_pRootEntity->CallEvent("onClientPreRender", Arguments, false);
3923+
}
3924+
m_uiLastFrameTick = uiCurrentTick;
39203925
}
39213926

39223927
void CClientGame::IdleHandler(void)

Client/mods/deathmatch/logic/CClientGame.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ class CClientGame
238238
void DoPulses(void);
239239
void DoPulses2(bool bCalledFromIdle);
240240

241+
uint GetFrameTimeSlice(void) { return m_uiFrameTimeSlice; }
241242
uint GetFrameCount(void) { return m_uiFrameCount; }
242243

243244
void HandleException(CExceptionInformation* pExceptionInformation);
@@ -763,8 +764,9 @@ class CClientGame
763764
unsigned long m_ulBigPacketBytesReceivedBase;
764765
CTransferBox* m_pBigPacketTransferBox;
765766

766-
CElapsedTimeHD m_TimeSliceTimer;
767-
uint m_uiFrameCount;
767+
uint m_uiFrameTimeSlice; // how long it took (in ms) to process the current frame
768+
uint m_uiLastFrameTick; // time at which the previous frame was processed
769+
uint m_uiFrameCount; // Frame counter
768770

769771
long long m_llLastTransgressionTime;
770772
SString m_strLastDiagnosticStatus;

Client/multiplayer_sa/CMultiplayerSA_Rendering.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -339,33 +339,6 @@ void _declspec(naked) HOOK_WinLoop()
339339
}
340340
}
341341

342-
//////////////////////////////////////////////////////////////////////////////////////////
343-
//
344-
// CTimer::Update
345-
//
346-
// Just before GTA calculates frame time deltas
347-
//
348-
//////////////////////////////////////////////////////////////////////////////////////////
349-
#define HOOKPOS_CTimer_Update 0x561B10
350-
#define HOOKSIZE_CTimer_Update 6
351-
static const DWORD CONTINUE_CTimer_Update = 0x561B16;
352-
static void _declspec(naked) HOOK_CTimer_Update()
353-
{
354-
_asm
355-
{
356-
pushad
357-
}
358-
359-
g_pCore->OnGameTimerUpdate();
360-
361-
_asm
362-
{
363-
popad
364-
mov ecx,dword ptr ds:[0B7CB28h]
365-
jmp CONTINUE_CTimer_Update
366-
}
367-
}
368-
369342
//////////////////////////////////////////////////////////////////////////////////////////
370343
//
371344
// Photograph screen grab in windowed mode
@@ -651,7 +624,6 @@ void CMultiplayerSA::InitHooks_Rendering(void)
651624
EZHookInstall(Check_NoOfVisibleLods);
652625
EZHookInstall(Check_NoOfVisibleEntities);
653626
EZHookInstall(WinLoop);
654-
EZHookInstall(CTimer_Update);
655627
EZHookInstall(psGrabScreen);
656628
EZHookInstallChecked(CClouds_RenderSkyPolys);
657629
EZHookInstallChecked(RwCameraSetNearClipPlane);

Client/sdk/core/CCoreInterface.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ class CCoreInterface
172172
virtual void SetFakeLagCommandEnabled(bool bEnabled) = 0;
173173
virtual SString GetBlueCopyrightString(void) = 0;
174174
virtual bool ClearChat() = 0;
175-
virtual void OnGameTimerUpdate(void) = 0;
176175

177176
virtual bool IsHostSmotraServer() = 0;
178177
};

0 commit comments

Comments
 (0)