Skip to content

Commit 88e0484

Browse files
committed
Merge remote-tracking branch 'upstream/master' into feature/add-new-cj-clothes
2 parents 43b922c + 0556e1a commit 88e0484

File tree

88 files changed

+97462
-97006
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+97462
-97006
lines changed

Client/core/CClientVariables.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ void CClientVariables::LoadDefaults()
357357
DEFAULT("discord_rpc_share_data", false); // Consistent Rich Presence data sharing
358358
DEFAULT("discord_rpc_share_data_firsttime", false); // Display the user data sharing consent dialog box - for the first time
359359
DEFAULT("browser_enable_gpu", true); // Enable GPU in CEF? (allows stuff like WebGL to function)
360+
DEFAULT("process_cpu_affinity", false); // Set CPU 0 affinity to improve game performance and fix the known issue in single-threaded games
360361

361362
if (!Exists("locale"))
362363
{

Client/core/CConnectManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*****************************************************************************/
1111

1212
#include "StdInc.h"
13-
#include "net/packetenums.h"
13+
#include "net/Packets.h"
1414
using namespace std;
1515

1616
static CConnectManager* g_pConnectManager = NULL;

Client/core/CCore.cpp

Lines changed: 22 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();
@@ -1794,6 +1795,17 @@ void CCore::ApplyCoreInitSettings()
17941795

17951796
SetApplicationSettingInt("reset-settings-revision", 21486);
17961797
}
1798+
1799+
// Set process settings
1800+
HANDLE currProc = GetCurrentProcess();
1801+
1802+
// Process priority
1803+
int PriorityClassList[] = {NORMAL_PRIORITY_CLASS, ABOVE_NORMAL_PRIORITY_CLASS, HIGH_PRIORITY_CLASS};
1804+
SetPriorityClass(currProc, PriorityClassList[CVARS_GET_VALUE<int>("process_priority") % 3]);
1805+
1806+
// Process CPU affinity
1807+
if (CVARS_GET_VALUE<bool>("process_cpu_affinity"))
1808+
SetProcessAffinityMask(currProc, 1 << 0);
17971809
}
17981810

17991811
//
@@ -1835,6 +1847,9 @@ void CCore::RecalculateFrameRateLimit(uint uiServerFrameRateLimit, bool bLogToCo
18351847
if ((m_uiFrameRateLimit == 0 || uiClientScriptRate < m_uiFrameRateLimit) && uiClientScriptRate > 0)
18361848
m_uiFrameRateLimit = uiClientScriptRate;
18371849

1850+
if (!IsConnected())
1851+
m_uiFrameRateLimit = m_CurrentRefreshRate;
1852+
18381853
// Removes Limiter from Frame Graph if limit is zero and skips frame limit
18391854
if (m_uiFrameRateLimit == 0)
18401855
{
@@ -1861,6 +1876,12 @@ void CCore::SetClientScriptFrameRateLimit(uint uiClientScriptFrameRateLimit)
18611876
RecalculateFrameRateLimit(-1, false);
18621877
}
18631878

1879+
void CCore::SetCurrentRefreshRate(uint value)
1880+
{
1881+
m_CurrentRefreshRate = value;
1882+
RecalculateFrameRateLimit(-1, false);
1883+
}
1884+
18641885
//
18651886
// Make sure the frame rate limit has been applied since the last call
18661887
//
@@ -1921,7 +1942,7 @@ void CCore::ApplyQueuedFrameRateLimit()
19211942
double dSpare = dTargetTimeToUse - m_FrameRateTimer.Get();
19221943
if (dSpare <= 0.0)
19231944
break;
1924-
if (dSpare >= 2.0)
1945+
if (dSpare >= 10.0)
19251946
Sleep(1);
19261947
}
19271948
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: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
#define CORE_MTA_DISABLED_ALPHA 0.4f
4141
#define CORE_MTA_ENABLED_ALPHA 1.0f
4242

43-
#define CORE_MTA_ANIMATION_TIME 200
43+
#define CORE_MTA_ANIMATION_TIME_IN 200
44+
#define CORE_MTA_ANIMATION_TIME_OUT 100
4445
#define CORE_MTA_MOVE_ANIM_TIME 600
4546

4647
#define CORE_MTA_STATIC_BG "cgui\\images\\background.png"
@@ -517,11 +518,9 @@ void CMainMenu::Update()
517518

518519
if (m_pHoveredItem)
519520
{
520-
float fProgress = (m_pHoveredItem->image->GetAlpha() - CORE_MTA_NORMAL_ALPHA) / (CORE_MTA_HOVER_ALPHA - CORE_MTA_NORMAL_ALPHA);
521-
// Let's work out what the target progress should be by working out the time passed
522-
fProgress = ((float)ulTimePassed / CORE_MTA_ANIMATION_TIME) * (CORE_MTA_HOVER_ALPHA - CORE_MTA_NORMAL_ALPHA) + fProgress;
521+
float progress = m_pHoveredItem->animProgress + ((float)ulTimePassed / CORE_MTA_ANIMATION_TIME_IN);
523522
MapRemove(m_unhoveredItems, m_pHoveredItem);
524-
SetItemHoverProgress(m_pHoveredItem, fProgress, true);
523+
SetItemHoverProgress(m_pHoveredItem, progress, true);
525524
}
526525
}
527526
else if (m_pHoveredItem)
@@ -534,11 +533,10 @@ void CMainMenu::Update()
534533
std::set<sMenuItem*>::iterator it = m_unhoveredItems.begin();
535534
while (it != m_unhoveredItems.end())
536535
{
537-
float fProgress = ((*it)->image->GetAlpha() - CORE_MTA_NORMAL_ALPHA) / (CORE_MTA_HOVER_ALPHA - CORE_MTA_NORMAL_ALPHA);
538536
// Let's work out what the target progress should be by working out the time passed
539537
// Min of 0.5 progress fixes occasional graphical glitchekal
540-
fProgress = fProgress - std::min(0.5f, ((float)ulTimePassed / CORE_MTA_ANIMATION_TIME) * (CORE_MTA_HOVER_ALPHA - CORE_MTA_NORMAL_ALPHA));
541-
if (SetItemHoverProgress((*it), fProgress, false))
538+
float newProgress = (*it)->animProgress - std::min(0.5f, ((float)ulTimePassed / CORE_MTA_ANIMATION_TIME_OUT) * (CORE_MTA_HOVER_ALPHA - CORE_MTA_NORMAL_ALPHA));
539+
if (SetItemHoverProgress((*it), newProgress, false))
542540
{
543541
std::set<sMenuItem*>::iterator itToErase = it++;
544542
m_unhoveredItems.erase(itToErase);
@@ -778,6 +776,9 @@ void CMainMenu::SetIsIngame(bool bIsIngame)
778776
m_bIsIngame = bIsIngame;
779777
m_Settings.SetIsModLoaded(bIsIngame);
780778

779+
// Reset frame rate limit
780+
CCore::GetSingleton().RecalculateFrameRateLimit(-1, false);
781+
781782
m_ulMoveStartTick = GetTickCount32();
782783
if (bIsIngame)
783784
{
@@ -1098,8 +1099,10 @@ bool CMainMenu::SetItemHoverProgress(sMenuItem* pItem, float fProgress, bool bHo
10981099
{
10991100
fProgress = Clamp<float>(0, fProgress, 1);
11001101

1101-
// Use OutQuad equation for easing, or OutQuad for unhovering
1102-
fProgress = bHovering ? -fProgress * (fProgress - 2) : fProgress * fProgress;
1102+
pItem->animProgress = fProgress;
1103+
1104+
// Always use OutQuad for both hovering and unhovering, to avoid animation glitches.
1105+
fProgress = -fProgress * (fProgress - 2);
11031106

11041107
// Work out the target scale
11051108
float fTargetScale = (CORE_MTA_HOVER_SCALE - CORE_MTA_NORMAL_SCALE) * (fProgress) + CORE_MTA_NORMAL_SCALE;
@@ -1118,7 +1121,7 @@ bool CMainMenu::SetItemHoverProgress(sMenuItem* pItem, float fProgress, bool bHo
11181121
pItem->image->SetSize(CVector2D(iSizeX, iSizeY), false);
11191122

11201123
// Return whether the hovering has maxed out
1121-
return bHovering ? (fProgress == 1) : (fProgress == 0);
1124+
return bHovering ? (pItem->animProgress >= 1.0) : (pItem->animProgress <= 0.0f);
11221125
}
11231126

11241127
void CMainMenu::SetNewsHeadline(int iIndex, const SString& strHeadline, const SString& strDate, bool bIsNew)

Client/core/CMainMenu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct sMenuItem
3333
int nativeSizeX;
3434
int nativeSizeY;
3535
CGUIStaticImage* image;
36+
float animProgress{};
3637
};
3738

3839
class CMainMenu

Client/core/CModManager.cpp

Lines changed: 4 additions & 4 deletions
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
{
@@ -165,13 +165,13 @@ bool CModManager::TryStart()
165165
DWORD size = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, errorCode,
166166
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPSTR>(&buffer), 0, nullptr);
167167

168-
if (size > 0)
168+
if (buffer != nullptr && size > 0)
169169
{
170-
LocalFree(buffer);
171-
172170
std::string message{buffer, size};
173171
size_t length = message.find_last_not_of("\t\n\v\f\r ");
174172

173+
LocalFree(buffer);
174+
175175
if (length == std::string::npos)
176176
return false;
177177

Client/core/CSettings.cpp

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,12 @@ void CSettings::CreateGUI()
405405
m_pCheckBoxAllowDiscordRPC->GetPosition(vecTemp, false);
406406
m_pCheckBoxAllowDiscordRPC->AutoSize(NULL, 20.0f);
407407

408+
// Enable camera photos getting saved to documents folder
409+
m_pPhotoSavingCheckbox = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabMultiplayer, _("Save photos taken by camera weapon to GTA San Andreas User Files folder"), true));
410+
m_pPhotoSavingCheckbox->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 20.0f));
411+
m_pPhotoSavingCheckbox->GetPosition(vecTemp, false);
412+
m_pPhotoSavingCheckbox->AutoSize(NULL, 20.0f);
413+
408414
m_pCheckBoxCustomizedSAFiles = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabMultiplayer, _("Use customized GTA:SA files"), true));
409415
m_pCheckBoxCustomizedSAFiles->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 20.0f));
410416
m_pCheckBoxCustomizedSAFiles->GetPosition(vecTemp, false);
@@ -1201,10 +1207,10 @@ void CSettings::CreateGUI()
12011207
m_pCachePathValue->AutoSize();
12021208
vecTemp.fY += fLineHeight;
12031209

1204-
// Enable camera photos getting saved to documents folder
1205-
m_pPhotoSavingCheckbox = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabAdvanced, _("Save photos taken by camera weapon to GTA San Andreas User Files folder"), true));
1206-
m_pPhotoSavingCheckbox->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY));
1207-
m_pPhotoSavingCheckbox->AutoSize(NULL, 20.0f);
1210+
// Process affinity
1211+
m_pProcessAffinityCheckbox = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabAdvanced, _("Set CPU 0 affinity to improve game performance"), true));
1212+
m_pProcessAffinityCheckbox->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY));
1213+
m_pProcessAffinityCheckbox->AutoSize(nullptr, 20.0f);
12081214
vecTemp.fY += fLineHeight;
12091215

12101216
// Auto updater section label
@@ -1306,6 +1312,7 @@ void CSettings::CreateGUI()
13061312
m_pButtonBrowserWhitelistRemove->SetClickHandler(GUI_CALLBACK(&CSettings::OnBrowserWhitelistRemove, this));
13071313
m_pEditBrowserWhitelistAdd->SetActivateHandler(GUI_CALLBACK(&CSettings::OnBrowserWhitelistDomainAddFocused, this));
13081314
m_pEditBrowserWhitelistAdd->SetDeactivateHandler(GUI_CALLBACK(&CSettings::OnBrowserWhitelistDomainAddDefocused, this));
1315+
m_pProcessAffinityCheckbox->SetClickHandler(GUI_CALLBACK(&CSettings::OnAffinityClick, this));
13091316

13101317
// Set up the events for advanced description
13111318
m_pPriorityLabel->SetMouseEnterHandler(GUI_CALLBACK(&CSettings::OnShowAdvancedSettingDescription, this));
@@ -1374,6 +1381,9 @@ void CSettings::CreateGUI()
13741381
m_pUpdateAutoInstallCombo->SetMouseEnterHandler(GUI_CALLBACK(&CSettings::OnShowAdvancedSettingDescription, this));
13751382
m_pUpdateAutoInstallCombo->SetMouseLeaveHandler(GUI_CALLBACK(&CSettings::OnHideAdvancedSettingDescription, this));
13761383

1384+
m_pProcessAffinityCheckbox->SetMouseEnterHandler(GUI_CALLBACK(&CSettings::OnShowAdvancedSettingDescription, this));
1385+
m_pProcessAffinityCheckbox->SetMouseLeaveHandler(GUI_CALLBACK(&CSettings::OnHideAdvancedSettingDescription, this));
1386+
13771387
// Load Chat presets
13781388
LoadChatPresets();
13791389

@@ -3228,6 +3238,22 @@ void CSettings::LoadData()
32283238
CVARS_GET("photosaving", bVar);
32293239
m_pPhotoSavingCheckbox->SetSelected(bVar);
32303240

3241+
// Process CPU Affinity
3242+
CVARS_GET("process_cpu_affinity", bVar);
3243+
m_pProcessAffinityCheckbox->SetSelected(bVar);
3244+
3245+
DWORD_PTR affinityMask = 0;
3246+
if (bVar)
3247+
affinityMask = 1 << 0; // CPU 0 only
3248+
else
3249+
{
3250+
SYSTEM_INFO sysInfo;
3251+
GetSystemInfo(&sysInfo);
3252+
3253+
affinityMask = (1 << sysInfo.dwNumberOfProcessors) - 1; // All cores (default)
3254+
}
3255+
SetProcessAffinityMask(GetCurrentProcess(), affinityMask);
3256+
32313257
// Update build type
32323258
CVARS_GET("update_build_type", iVar);
32333259
if (iVar == 0 || iVar == 1)
@@ -3624,6 +3650,22 @@ void CSettings::SaveData()
36243650
CVARS_SET("photosaving", photoSaving);
36253651
CScreenShot::SetPhotoSavingInsideDocuments(photoSaving);
36263652

3653+
// Process CPU Affinity
3654+
bool cpuAffinity = m_pProcessAffinityCheckbox->GetSelected();
3655+
CVARS_SET("process_cpu_affinity", cpuAffinity);
3656+
3657+
DWORD_PTR affinityMask = 0;
3658+
if (cpuAffinity)
3659+
affinityMask = 1 << 0; // CPU 0 only
3660+
else
3661+
{
3662+
SYSTEM_INFO sysInfo;
3663+
GetSystemInfo(&sysInfo);
3664+
3665+
affinityMask = (1 << sysInfo.dwNumberOfProcessors) - 1; // All cores (default)
3666+
}
3667+
SetProcessAffinityMask(GetCurrentProcess(), affinityMask);
3668+
36273669
// Debug setting
36283670
if (CGUIListItem* pSelected = m_pDebugSettingCombo->GetSelectedItem())
36293671
{
@@ -4711,6 +4753,44 @@ static void DPIAwareQuestionCallBack(void* userdata, unsigned int uiButton)
47114753
}
47124754
}
47134755

4756+
static void CPUAffinityQuestionCallBack(void* userdata, unsigned int button)
4757+
{
4758+
CCore::GetSingleton().GetLocalGUI()->GetMainMenu()->GetQuestionWindow()->Reset();
4759+
4760+
if (button == 0)
4761+
{
4762+
auto const checkBox = reinterpret_cast<CGUICheckBox*>(userdata);
4763+
checkBox->SetSelected(false);
4764+
}
4765+
}
4766+
4767+
bool CSettings::OnAffinityClick(CGUIElement* pElement)
4768+
{
4769+
static bool shownWarning = false;
4770+
4771+
if (m_pProcessAffinityCheckbox->GetSelected() && !shownWarning)
4772+
{
4773+
shownWarning = true;
4774+
4775+
std::string message = std::string(
4776+
_("Enabling this setting may improve game performance, but on some processors, it may worsen it.\n"
4777+
"We have observed issues with AMD Ryzen processors featuring 3D V-Cache.\n"
4778+
"The exact list of affected processors is unknown.\n"
4779+
"\nAre you sure you want to enable this option?"));
4780+
4781+
CQuestionBox* pQuestionBox = CCore::GetSingleton().GetLocalGUI()->GetMainMenu()->GetQuestionWindow();
4782+
pQuestionBox->Reset();
4783+
pQuestionBox->SetTitle(_("EXPERIMENTAL FEATURE"));
4784+
pQuestionBox->SetMessage(message);
4785+
pQuestionBox->SetButton(0, _("No"));
4786+
pQuestionBox->SetButton(1, _("Yes"));
4787+
pQuestionBox->SetCallback(CPUAffinityQuestionCallBack, m_pProcessAffinityCheckbox);
4788+
pQuestionBox->Show();
4789+
}
4790+
4791+
return true;
4792+
}
4793+
47144794
bool CSettings::OnBrowserBlacklistAdd(CGUIElement* pElement)
47154795
{
47164796
SString strDomain = m_pEditBrowserBlacklistAdd->GetText();
@@ -4874,6 +4954,8 @@ bool CSettings::OnShowAdvancedSettingDescription(CGUIElement* pElement)
48744954
strText = std::string(_("16-bit color:")) + " " + std::string(_("Enable 16 bit color modes - Requires MTA restart"));
48754955
else if (pCheckBox && pCheckBox == m_pWin8MouseCheckBox)
48764956
strText = std::string(_("Mouse fix:")) + " " + std::string(_("Mouse movement fix - May need PC restart"));
4957+
else if (pCheckBox && pCheckBox == m_pProcessAffinityCheckbox)
4958+
strText = std::string(_("CPU affinity:")) + " " + std::string(_("Experimental feature - It may improve performance or worsen it."));
48774959

48784960
if (strText != "")
48794961
m_pAdvancedSettingDescriptionLabel->SetText(strText.c_str());

Client/core/CSettings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ class CSettings
216216
CGUICheckBox* m_pWin8ColorCheckBox;
217217
CGUICheckBox* m_pWin8MouseCheckBox;
218218
CGUICheckBox* m_pPhotoSavingCheckbox;
219+
CGUICheckBox* m_pProcessAffinityCheckbox;
219220
CGUILabel* m_pUpdateBuildTypeLabel;
220221
CGUIComboBox* m_pUpdateBuildTypeCombo;
221222
CGUILabel* m_pUpdateAutoInstallLabel;
@@ -406,6 +407,7 @@ class CSettings
406407
bool OnShowAdvancedSettingDescription(CGUIElement* pElement);
407408
bool OnHideAdvancedSettingDescription(CGUIElement* pElement);
408409
bool OnTabChanged(CGUIElement* pElement);
410+
bool OnAffinityClick(CGUIElement* pElement);
409411
void ReloadBrowserLists();
410412

411413
private:

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)