Skip to content

Commit feb981b

Browse files
authored
Merge branch 'master' into patch-6
2 parents e767df2 + 0556e1a commit feb981b

23 files changed

+462
-382
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/CCore.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,17 @@ void CCore::ApplyCoreInitSettings()
17951795

17961796
SetApplicationSettingInt("reset-settings-revision", 21486);
17971797
}
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);
17981809
}
17991810

18001811
//

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/game_sa/TaskJumpFallSA.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class CTaskSimpleClimbSA : public virtual CTaskSimpleSA, public virtual CTaskSim
5959
class CTaskSimpleJetPackSAInterface : public CTaskSimpleSAInterface
6060
{
6161
public:
62-
unsigned char m_bIsFinished;
62+
bool m_bIsFinished;
6363
unsigned char m_bAddedIdleAnim;
6464
unsigned char m_bAnimsReferenced;
6565
unsigned char m_bAttackButtonPressed;
@@ -100,4 +100,6 @@ class CTaskSimpleJetPackSA : public virtual CTaskSimpleSA, public virtual CTaskS
100100
public:
101101
CTaskSimpleJetPackSA(){};
102102
CTaskSimpleJetPackSA(const CVector* pVecTargetPos, float fCruiseHeight = 10.0f, int nHoverTime = 0);
103+
104+
bool IsFinished() const override { return static_cast<const CTaskSimpleJetPackSAInterface*>(GetInterface())->m_bIsFinished; }
103105
};

Client/mods/deathmatch/logic/CClientDisplay.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,14 @@
1010

1111
#include <StdInc.h>
1212

13-
CClientDisplay::CClientDisplay(CClientDisplayManager* pDisplayManager, unsigned long ulID)
13+
CClientDisplay::CClientDisplay(unsigned long ulID)
1414
{
15-
m_pDisplayManager = pDisplayManager;
1615
m_ulID = ulID;
17-
18-
m_ulExpirationTime = 0;
1916
m_bVisible = true;
2017
m_Color = SColorRGBA(255, 255, 255, 255);
21-
22-
m_pDisplayManager->AddToList(this);
23-
}
24-
25-
CClientDisplay::~CClientDisplay()
26-
{
27-
// Remove us from the manager
28-
m_pDisplayManager->RemoveFromList(this);
2918
}
3019

3120
void CClientDisplay::SetColorAlpha(unsigned char ucAlpha)
3221
{
3322
m_Color.A = ucAlpha;
34-
}
23+
}

Client/mods/deathmatch/logic/CClientDisplay.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,13 @@ enum eDisplayType
2222

2323
class CClientDisplay
2424
{
25-
friend class CClientDisplayManager;
26-
2725
public:
28-
CClientDisplay(class CClientDisplayManager* pDisplayManager, unsigned long ulID);
29-
virtual ~CClientDisplay();
26+
CClientDisplay(unsigned long ulID);
27+
virtual ~CClientDisplay() = default;
3028

31-
unsigned long GetID() { return m_ulID; }
29+
unsigned long GetID() const { return m_ulID; }
3230
virtual eDisplayType GetType() = 0;
3331

34-
unsigned long GetExpirationTime() { return m_ulExpirationTime; };
35-
void SetExpirationTime(unsigned long ulTime) { m_ulExpirationTime = ulTime; };
36-
unsigned long GetTimeTillExpiration() { return m_ulExpirationTime - CClientTime::GetTime(); };
37-
void SetTimeTillExpiration(unsigned long ulMs) { m_ulExpirationTime = CClientTime::GetTime() + ulMs; };
38-
3932
virtual const CVector& GetPosition() { return m_vecPosition; };
4033
virtual void SetPosition(const CVector& vecPosition) { m_vecPosition = vecPosition; };
4134

@@ -49,12 +42,7 @@ class CClientDisplay
4942
virtual void Render() = 0;
5043

5144
protected:
52-
bool IsExpired() { return (m_ulExpirationTime != 0 && (CClientTime::GetTime() > m_ulExpirationTime)); };
53-
54-
CClientDisplayManager* m_pDisplayManager;
55-
5645
unsigned long m_ulID;
57-
unsigned long m_ulExpirationTime;
5846
bool m_bVisible;
5947
CVector m_vecPosition;
6048
SColor m_Color;

Client/mods/deathmatch/logic/CClientDisplayManager.cpp

Lines changed: 30 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,21 @@
1212

1313
using std::list;
1414

15-
CClientDisplayManager::CClientDisplayManager()
16-
{
17-
// Init
18-
m_bCanRemoveFromList = true;
19-
}
20-
21-
CClientDisplayManager::~CClientDisplayManager()
22-
{
23-
RemoveAll();
24-
}
25-
26-
CClientDisplay* CClientDisplayManager::Get(unsigned long ulID)
15+
std::shared_ptr<CClientDisplay> CClientDisplayManager::Get(unsigned long ulID)
2716
{
2817
// Find the display with the given id
29-
list<CClientDisplay*>::const_iterator iter = m_List.begin();
30-
for (; iter != m_List.end(); iter++)
18+
auto iter = m_List.begin();
19+
20+
for (; iter != m_List.end(); iter++) // Iterate weak_ptr list
3121
{
32-
if ((*iter)->GetID() == ulID)
22+
if (const auto& display = (*iter).lock()) // Make sure the shared_ptr still exists
3323
{
34-
return *iter;
24+
if (display->GetID() == ulID)
25+
{
26+
return display;
27+
}
3528
}
29+
3630
}
3731

3832
return NULL;
@@ -49,57 +43,38 @@ void CClientDisplayManager::DrawText2D(const char* szCaption, const CVector& vec
4943
static_cast<int>(fResHeight), rgbaColor, szCaption, fScale, fScale, 0);
5044
}
5145

52-
void CClientDisplayManager::AddToList(CClientDisplay* pDisplay)
46+
void CClientDisplayManager::AddToList(const std::shared_ptr<CClientDisplay>& display)
5347
{
54-
m_List.push_back(pDisplay);
48+
m_List.push_back(display);
5549
}
5650

57-
void CClientDisplayManager::RemoveAll()
51+
void CClientDisplayManager::DoPulse()
5852
{
59-
// Delete all the items in the list
60-
m_bCanRemoveFromList = false;
61-
list<CClientDisplay*>::iterator iter = m_List.begin();
62-
for (; iter != m_List.end(); iter++)
63-
{
64-
delete *iter;
65-
}
53+
// Render all our displays
54+
auto iter = m_List.begin();
6655

67-
// Clear the list
68-
m_List.clear();
69-
m_bCanRemoveFromList = true;
70-
}
56+
// Clean up expired weak_ptr
57+
m_List.remove_if([](const std::weak_ptr<CClientDisplay>& wp) { return wp.expired(); });
7158

72-
void CClientDisplayManager::RemoveFromList(CClientDisplay* pDisplay)
73-
{
74-
if (m_bCanRemoveFromList)
59+
for (; iter != m_List.end(); iter++) // Iterate weak_ptr list
7560
{
76-
if (!m_List.empty())
61+
if (const auto& display = (*iter).lock()) // Make sure the shared_ptr still exists
7762
{
78-
m_List.remove(pDisplay);
63+
display->Render();
7964
}
8065
}
8166
}
8267

83-
void CClientDisplayManager::DoPulse()
68+
std::shared_ptr<CClientVectorGraphicDisplay> CClientDisplayManager::CreateVectorGraphicDisplay(CClientVectorGraphic* svg)
8469
{
85-
// Render all our displays
86-
m_bCanRemoveFromList = false;
87-
list<CClientDisplay*>::iterator iter = m_List.begin();
88-
while (iter != m_List.end())
89-
{
90-
CClientDisplay* pObject = *iter;
91-
if (pObject->IsExpired())
92-
{
93-
// Delete it and remove it from the list
94-
delete pObject;
95-
iter = m_List.erase(iter);
96-
}
97-
else
98-
{
99-
++iter;
100-
pObject->Render();
101-
}
102-
}
70+
auto display = std::make_shared<CClientVectorGraphicDisplay>(svg);
71+
AddToList(display);
72+
return display;
73+
}
10374

104-
m_bCanRemoveFromList = true;
75+
std::shared_ptr<CClientTextDisplay> CClientDisplayManager::CreateTextDisplay(int ID)
76+
{
77+
auto display = std::make_shared<CClientTextDisplay>(ID);
78+
AddToList(display);
79+
return display;
10580
}

0 commit comments

Comments
 (0)