Skip to content

Commit acbcc8e

Browse files
authored
Set main menu FPS limit to current display refresh rate (PR #4083)
1 parent 6bb19ac commit acbcc8e

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

Client/core/CCore.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ CCore::CCore()
156156
m_bGettingIdleCallsFromMultiplayer = false;
157157
m_bWindowsTimerEnabled = false;
158158
m_timeDiscordAppLastUpdate = 0;
159+
m_CurrentRefreshRate = 60;
159160

160161
// Create tray icon
161162
m_pTrayIcon = new CTrayIcon();
@@ -1835,6 +1836,9 @@ void CCore::RecalculateFrameRateLimit(uint uiServerFrameRateLimit, bool bLogToCo
18351836
if ((m_uiFrameRateLimit == 0 || uiClientScriptRate < m_uiFrameRateLimit) && uiClientScriptRate > 0)
18361837
m_uiFrameRateLimit = uiClientScriptRate;
18371838

1839+
if (!IsConnected())
1840+
m_uiFrameRateLimit = m_CurrentRefreshRate;
1841+
18381842
// Removes Limiter from Frame Graph if limit is zero and skips frame limit
18391843
if (m_uiFrameRateLimit == 0)
18401844
{
@@ -1861,6 +1865,12 @@ void CCore::SetClientScriptFrameRateLimit(uint uiClientScriptFrameRateLimit)
18611865
RecalculateFrameRateLimit(-1, false);
18621866
}
18631867

1868+
void CCore::SetCurrentRefreshRate(uint value)
1869+
{
1870+
m_CurrentRefreshRate = value;
1871+
RecalculateFrameRateLimit(-1, false);
1872+
}
1873+
18641874
//
18651875
// Make sure the frame rate limit has been applied since the last call
18661876
//
@@ -1921,7 +1931,7 @@ void CCore::ApplyQueuedFrameRateLimit()
19211931
double dSpare = dTargetTimeToUse - m_FrameRateTimer.Get();
19221932
if (dSpare <= 0.0)
19231933
break;
1924-
if (dSpare >= 2.0)
1934+
if (dSpare >= 10.0)
19251935
Sleep(1);
19261936
}
19271937
m_FrameRateTimer.Reset();

Client/core/CCore.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
223223
void ApplyQueuedFrameRateLimit();
224224
void EnsureFrameRateLimitApplied();
225225
void SetClientScriptFrameRateLimit(uint uiClientScriptFrameRateLimit);
226+
void SetCurrentRefreshRate(uint value);
226227
void DoReliablePulse();
227228

228229
bool IsTimingCheckpoints();
@@ -371,6 +372,7 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
371372
CElapsedTimeHD m_FrameRateTimer;
372373
uint m_uiQueuedFrameRate;
373374
bool m_bQueuedFrameRateValid;
375+
uint m_CurrentRefreshRate;
374376
bool m_requestNewNickname{false};
375377
EDiagnosticDebugType m_DiagnosticDebug;
376378

Client/core/CMainMenu.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,9 @@ void CMainMenu::SetIsIngame(bool bIsIngame)
778778
m_bIsIngame = bIsIngame;
779779
m_Settings.SetIsModLoaded(bIsIngame);
780780

781+
// Reset frame rate limit
782+
CCore::GetSingleton().RecalculateFrameRateLimit(-1, false);
783+
781784
m_ulMoveStartTick = GetTickCount32();
782785
if (bIsIngame)
783786
{

Client/core/CModManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void CModManager::DoPulsePostFrame()
9393
if (m_client != nullptr)
9494
CCore::GetSingleton().EnsureFrameRateLimitApplied(); // Catch missed frames
9595
else
96-
CCore::GetSingleton().ApplyFrameRateLimit(88); // Limit when not connected
96+
CCore::GetSingleton().ApplyFrameRateLimit(); // Limit when not connected
9797

9898
if (m_state == State::PendingStart)
9999
{

Client/core/DXHook/CProxyDirect3D9.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,13 @@ HRESULT HandleCreateDeviceResult(HRESULT hResult, IDirect3D9* pDirect3D, UINT Ad
833833
strMessage += SString("Direct3D CreateDevice error: %08x", hResult);
834834
BrowseToSolution("d3dcreatedevice-fail", EXIT_GAME_FIRST | ASK_GO_ONLINE, strMessage);
835835
}
836+
else
837+
{
838+
// Get current refresh rate
839+
D3DDISPLAYMODE DisplayMode;
840+
if (pDirect3D->GetAdapterDisplayMode(Adapter, &DisplayMode) == D3D_OK)
841+
CCore::GetSingleton().SetCurrentRefreshRate(DisplayMode.RefreshRate);
842+
}
836843

837844
return hResult;
838845
}

0 commit comments

Comments
 (0)