Skip to content

Commit a9c3768

Browse files
authored
Merge branch 'master' into 230724_Add_getLoadedFiles
2 parents 04a49af + ad1da87 commit a9c3768

32 files changed

+439
-252
lines changed

Client/cefweb/CWebApp.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ CefRefPtr<CefResourceHandler> CWebApp::HandleError(const SString& strError, unsi
2121

2222
void CWebApp::OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line)
2323
{
24+
CWebCore* pWebCore = static_cast<CWebCore*>(g_pCore->GetWebCore());
25+
26+
if (!pWebCore->GetGPUEnabled())
27+
command_line->AppendSwitch("disable-gpu");
28+
29+
command_line->AppendSwitch("disable-gpu-compositing"); // always disable this, causes issues with official builds
30+
2431
// command_line->AppendSwitch("disable-d3d11");
2532
command_line->AppendSwitch("enable-begin-frame-scheduling");
2633

Client/cefweb/CWebCore.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ CWebCore::~CWebCore()
4949
delete m_pXmlConfig;
5050
}
5151

52-
bool CWebCore::Initialise()
52+
bool CWebCore::Initialise(bool gpuEnabled)
5353
{
5454
CefMainArgs mainArgs;
5555
void* sandboxInfo = nullptr;
56+
57+
m_bGPUEnabled = gpuEnabled;
58+
5659
CefRefPtr<CWebApp> app(new CWebApp);
5760

5861
#ifdef CEF_ENABLE_SANDBOX
@@ -869,3 +872,8 @@ void CWebCore::StaticFetchBlacklistFinished(const SHttpDownloadResult& result)
869872
OutputDebugLine("Updated browser blacklist!");
870873
#endif
871874
}
875+
876+
bool CWebCore::GetGPUEnabled() const noexcept
877+
{
878+
return m_bGPUEnabled;
879+
}

Client/cefweb/CWebCore.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class CWebCore : public CWebCoreInterface
5454
public:
5555
CWebCore();
5656
~CWebCore();
57-
bool Initialise() override;
57+
bool Initialise(bool gpuEnabled) override;
5858

5959
CWebViewInterface* CreateWebView(unsigned int uiWidth, unsigned int uiHeight, bool bIsLocal, CWebBrowserItem* pWebBrowserRenderItem, bool bTransparent);
6060
void DestroyWebView(CWebViewInterface* pWebViewInterface);
@@ -108,6 +108,8 @@ class CWebCore : public CWebCoreInterface
108108
static void StaticFetchWhitelistFinished(const SHttpDownloadResult& result);
109109
static void StaticFetchBlacklistFinished(const SHttpDownloadResult& result);
110110

111+
bool GetGPUEnabled() const noexcept;
112+
111113
private:
112114
typedef std::pair<bool, eWebFilterType> WebFilterPair;
113115

@@ -129,4 +131,7 @@ class CWebCore : public CWebCoreInterface
129131
CXMLFile* m_pXmlConfig;
130132
int m_iWhitelistRevision;
131133
int m_iBlacklistRevision;
134+
135+
// Shouldn't be changed after init
136+
bool m_bGPUEnabled;
132137
};

Client/core/CClientVariables.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ void CClientVariables::LoadDefaults()
358358
DEFAULT("discord_rpc_share_data", false); // Consistent Rich Presence data sharing
359359
DEFAULT("discord_rpc_share_data_firsttime", false); // Display the user data sharing consent dialog box - for the first time
360360
DEFAULT("_beta_qc_rightclick_command", _S("reconnect")); // Command to run when right clicking quick connect (beta - can be removed at any time)
361+
DEFAULT("browser_enable_gpu", true); // Enable GPU in CEF? (allows stuff like WebGL to function)
361362

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

Client/core/CCore.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1155,8 +1155,12 @@ CWebCoreInterface* CCore::GetWebCore()
11551155
{
11561156
if (m_pWebCore == nullptr)
11571157
{
1158+
bool gpuEnabled;
1159+
auto cvars = g_pCore->GetCVars();
1160+
cvars->Get("browser_enable_gpu", gpuEnabled);
1161+
11581162
m_pWebCore = CreateModule<CWebCoreInterface>(m_WebCoreModule, "CefWeb", "cefweb", "InitWebCoreInterface", this);
1159-
m_pWebCore->Initialise();
1163+
m_pWebCore->Initialise(gpuEnabled);
11601164
}
11611165
return m_pWebCore;
11621166
}

Client/core/CGUI.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,15 @@ CLocalGUI::~CLocalGUI()
5656

5757
void CLocalGUI::SetSkin(const char* szName)
5858
{
59+
CVector2D consolePos, consoleSize;
60+
5961
bool guiWasLoaded = m_pMainMenu != NULL;
6062
if (guiWasLoaded)
63+
{
64+
consolePos = m_pConsole->GetPosition();
65+
consoleSize = m_pConsole->GetSize();
6166
DestroyWindows();
67+
}
6268

6369
std::string error;
6470

@@ -93,7 +99,11 @@ void CLocalGUI::SetSkin(const char* szName)
9399
m_LastSettingsRevision = cvars->GetRevision();
94100

95101
if (guiWasLoaded)
102+
{
96103
CreateWindows(guiWasLoaded);
104+
m_pConsole->SetPosition(consolePos);
105+
m_pConsole->SetSize(consoleSize);
106+
}
97107

98108
if (CCore::GetSingleton().GetConsole() && !error.empty())
99109
CCore::GetSingleton().GetConsole()->Echo(error.c_str());
@@ -104,8 +114,8 @@ void CLocalGUI::ChangeLocale(const char* szName)
104114
bool guiWasLoaded = m_pMainMenu != NULL;
105115
assert(guiWasLoaded);
106116

107-
CVector2D vPos = m_pConsole->GetPosition();
108-
CVector2D vSize = m_pConsole->GetSize();
117+
CVector2D consolePos = m_pConsole->GetPosition();
118+
CVector2D consoleSize = m_pConsole->GetSize();
109119

110120
if (guiWasLoaded)
111121
DestroyWindows();
@@ -119,12 +129,8 @@ void CLocalGUI::ChangeLocale(const char* szName)
119129
if (guiWasLoaded)
120130
{
121131
CreateWindows(guiWasLoaded);
122-
123-
if (m_pConsole != nullptr)
124-
{
125-
m_pConsole->SetPosition(vPos);
126-
m_pConsole->SetSize(vSize);
127-
}
132+
m_pConsole->SetPosition(consolePos);
133+
m_pConsole->SetSize(consoleSize);
128134
}
129135
}
130136

Client/core/CNickGen.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
*****************************************************************************/
99

1010
#include "StdInc.h"
11-
#include "time.h"
11+
#include <random>
1212

1313
// These words are of a maximum length of 10 characters, capitalized, and stripped of whitespace
14-
const char* const CNickGen::m_szAdjectives[] = {
14+
const char* const szAdjectives[] = {
1515
"Aback", "Abaft", "Abandoned", "Abashed", "Aberrant", "Abhorrent", "Abiding", "Abject", "Ablaze", "Able", "Abnormal",
1616
"Aboard", "Aboriginal", "Abortive", "Abounding", "Abrasive", "Abrupt", "Absent", "Absorbed", "Absorbing", "Abstracted", "Absurd",
1717
"Abundant", "Abusive", "Acceptable", "Accessible", "Accidental", "Accurate", "Acid", "Acidic", "Acoustic", "Acrid", "Actually",
@@ -109,7 +109,7 @@ const char* const CNickGen::m_szAdjectives[] = {
109109
"Worried", "Worthless", "Wrathful", "Wretched", "Wrong", "Wry",
110110
};
111111

112-
const char* const CNickGen::m_szNouns[] = {
112+
const char* const szNouns[] = {
113113
"Aardvark", "Buffalo", "Alligator", "Ant", "Anteater", "Antelope", "Ape", "Armadillo", "Donkey", "Baboon", "Badger",
114114
"Barracuda", "Bat", "Bear", "Beaver", "Bee", "Bison", "Boar", "Bush", "Butterfly", "Camel", "Calf",
115115
"Cat", "Kitten", "Cattle", "Chamois", "Cheetah", "Chicken", "Chick", "Chimpanzee", "Infant", "Empress", "Troop",
@@ -196,10 +196,18 @@ const char* const CNickGen::m_szNouns[] = {
196196
"Vampire", "Parasite", "Tramp", "Bum", "Hobo", "Hitchhiker", "Deadbeat", "Acrobat",
197197
};
198198

199+
constexpr auto numAdjectives = std::size(szAdjectives);
200+
constexpr auto numNouns = std::size(szNouns);
201+
constexpr auto maxNum = 100;
202+
199203
SString CNickGen::GetRandomNickname()
200204
{
201-
srand((unsigned int)time(NULL));
202-
int iAdjective = rand() % NICKGEN_NUM_ADJECTIVES;
203-
int iNoun = rand() % NICKGEN_NUM_NOUNS;
204-
return SString("%s%s%i", m_szAdjectives[iAdjective], m_szNouns[iNoun], rand() % 100);
205+
std::random_device rd;
206+
std::mt19937 gen(rd());
207+
208+
std::uniform_int_distribution<int> adjectiveDist(0, numAdjectives - 1);
209+
std::uniform_int_distribution<int> nounDist(0, numNouns - 1);
210+
std::uniform_int_distribution<int> numDist(0, maxNum);
211+
212+
return SString("%s%s%i", szAdjectives[adjectiveDist(gen)], szNouns[nounDist(gen)], numDist(gen));
205213
}

Client/core/CNickGen.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@
99

1010
#pragma once
1111

12-
#define NICKGEN_NUM_ADJECTIVES 1048
13-
#define NICKGEN_NUM_NOUNS 934
14-
1512
class CNickGen
1613
{
1714
public:
18-
static const char* const m_szAdjectives[NICKGEN_NUM_ADJECTIVES];
19-
static const char* const m_szNouns[NICKGEN_NUM_NOUNS];
2015
static SString GetRandomNickname();
2116
};

Client/core/CSettings.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,10 @@ void CSettings::CreateGUI()
917917
m_pCheckBoxRemoteJavascript->GetPosition(vecTemp);
918918
m_pCheckBoxRemoteJavascript->AutoSize(NULL, 20.0f);
919919

920+
m_pCheckBoxBrowserGPUEnabled = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(m_pTabBrowser, _("Enable GPU rendering"), true));
921+
m_pCheckBoxBrowserGPUEnabled->SetPosition(CVector2D(vecTemp.fX + 300.0f, vecTemp.fY - 25.0f));
922+
m_pCheckBoxBrowserGPUEnabled->AutoSize(NULL, 20.0f);
923+
920924
m_pLabelBrowserCustomBlacklist = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(m_pTabBrowser, _("Custom blacklist")));
921925
m_pLabelBrowserCustomBlacklist->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 30.0f));
922926
m_pLabelBrowserCustomBlacklist->GetPosition(vecTemp);
@@ -3287,6 +3291,8 @@ void CSettings::LoadData()
32873291
m_pCheckBoxRemoteBrowser->SetSelected(bVar);
32883292
CVARS_GET("browser_remote_javascript", bVar);
32893293
m_pCheckBoxRemoteJavascript->SetSelected(bVar);
3294+
CVARS_GET("browser_enable_gpu", bVar);
3295+
m_pCheckBoxBrowserGPUEnabled->SetSelected(bVar);
32903296

32913297
ReloadBrowserLists();
32923298
}
@@ -3711,6 +3717,13 @@ void CSettings::SaveData()
37113717
bBrowserSettingChanged = true;
37123718
}
37133719

3720+
bool bBrowserGPUEnabled = false;
3721+
CVARS_GET("browser_enable_gpu", bBrowserGPUEnabled);
3722+
3723+
bool bBrowserGPUSetting = m_pCheckBoxBrowserGPUEnabled->GetSelected();
3724+
bool bBrowserGPUSettingChanged = (bBrowserGPUSetting != bBrowserGPUEnabled);
3725+
CVARS_SET("browser_enable_gpu", bBrowserGPUSetting);
3726+
37143727
// Ensure CVARS ranges ok
37153728
CClientVariables::GetSingleton().ValidateValues();
37163729

@@ -3720,7 +3733,7 @@ void CSettings::SaveData()
37203733
gameSettings->Save();
37213734

37223735
// Ask to restart?
3723-
if (bIsVideoModeChanged || bIsAntiAliasingChanged || bIsCustomizedSAFilesChanged || processsDPIAwareChanged)
3736+
if (bIsVideoModeChanged || bIsAntiAliasingChanged || bIsCustomizedSAFilesChanged || processsDPIAwareChanged || bBrowserGPUSettingChanged)
37243737
ShowRestartQuestion();
37253738
else if (CModManager::GetSingleton().IsLoaded() && bBrowserSettingChanged)
37263739
ShowDisconnectQuestion();

Client/core/CSettings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ class CSettings
338338
CGUIButton* m_pButtonBrowserWhitelistAdd;
339339
CGUIGridList* m_pGridBrowserWhitelist;
340340
CGUIButton* m_pButtonBrowserWhitelistRemove;
341+
CGUICheckBox* m_pCheckBoxBrowserGPUEnabled;
341342
bool m_bBrowserListsChanged;
342343
bool m_bBrowserListsLoadEnabled;
343344

0 commit comments

Comments
 (0)