Make singletons use static memory

Avoid heap memory allocation and a level of indirection. This allows the compiler to optimize the program even more. No logic has been changed in this patch.
This commit is contained in:
Kawe Mazidjatari 2024-01-21 21:29:23 +01:00
parent 4662995f2e
commit fcf3a09418
38 changed files with 172 additions and 167 deletions

View File

@ -88,7 +88,7 @@ MP_HostName_Changed_f
void MP_HostName_Changed_f(IConVar* pConVar, const char* pOldString, float flOldValue)
{
#ifndef DEDICATED
g_pBrowser->SetHostName(pylon_matchmaking_hostname->GetString());
g_Browser.SetHostName(pylon_matchmaking_hostname->GetString());
#endif // !DEDICATED
}
@ -100,7 +100,7 @@ ToggleConsole_f
*/
void ToggleConsole_f(const CCommand& args)
{
g_pConsole->m_bActivate ^= true;
g_Console.m_bActivate ^= true;
ResetInput(); // Disable input to game when console is drawn.
}
@ -111,7 +111,7 @@ ToggleBrowser_f
*/
void ToggleBrowser_f(const CCommand& args)
{
g_pBrowser->m_bActivate ^= true;
g_Browser.m_bActivate ^= true;
ResetInput(); // Disable input to game when browser is drawn.
}
#endif // !DEDICATED
@ -137,22 +137,22 @@ void _Author_Client_f(const CCommand& args, EKickType type)
{
case KICK_NAME:
{
g_pBanSystem->KickPlayerByName(args.Arg(1), szReason);
g_BanSystem.KickPlayerByName(args.Arg(1), szReason);
break;
}
case KICK_ID:
{
g_pBanSystem->KickPlayerById(args.Arg(1), szReason);
g_BanSystem.KickPlayerById(args.Arg(1), szReason);
break;
}
case BAN_NAME:
{
g_pBanSystem->BanPlayerByName(args.Arg(1), szReason);
g_BanSystem.BanPlayerByName(args.Arg(1), szReason);
break;
}
case BAN_ID:
{
g_pBanSystem->BanPlayerById(args.Arg(1), szReason);
g_BanSystem.BanPlayerById(args.Arg(1), szReason);
break;
}
default:
@ -216,7 +216,7 @@ void Host_Unban_f(const CCommand& args)
return;
}
g_pBanSystem->UnbanPlayer(args.Arg(1));
g_BanSystem.UnbanPlayer(args.Arg(1));
}
/*
@ -226,7 +226,7 @@ Host_ReloadBanList_f
*/
void Host_ReloadBanList_f(const CCommand& args)
{
g_pBanSystem->LoadList(); // Reload banned list.
g_BanSystem.LoadList(); // Reload banned list.
}
/*
@ -866,7 +866,7 @@ CON_LogHistory_f
*/
void CON_LogHistory_f(const CCommand& args)
{
const vector<string> vHistory = g_pConsole->GetHistory();
const vector<string> vHistory = g_Console.GetHistory();
for (size_t i = 0, nh = vHistory.size(); i < nh; i++)
{
Msg(eDLL_T::COMMON, "%3d: %s\n", i, vHistory[i].c_str());
@ -892,7 +892,7 @@ void CON_RemoveLine_f(const CCommand& args)
int start = atoi(args[1]);
int end = atoi(args[2]);
g_pConsole->RemoveLog(start, end);
g_Console.RemoveLog(start, end);
}
/*
@ -905,7 +905,7 @@ CON_ClearLines_f
*/
void CON_ClearLines_f(const CCommand& args)
{
g_pConsole->ClearLog();
g_Console.ClearLog();
}
/*
@ -918,7 +918,7 @@ CON_ClearHistory_f
*/
void CON_ClearHistory_f(const CCommand& args)
{
g_pConsole->ClearHistory();
g_Console.ClearHistory();
}
/*
@ -1059,7 +1059,7 @@ void LanguageChanged_f(IConVar* pConVar, const char* pOldString, float flOldValu
}
pConVarRef->SetValue(pNewString);
g_pMasterServer->SetLanguage(pNewString);
g_MasterServer.SetLanguage(pNewString);
}
}

View File

@ -290,14 +290,14 @@ void EngineLoggerSink(LogType_t logType, LogLevel_t logLevel, eDLL_T context,
g_ImGuiLogger->debug(message);
const string logStreamBuf = g_LogStream.str();
g_pConsole->AddLog(ConLog_t(logStreamBuf, overlayColor));
g_Console.AddLog(ConLog_t(logStreamBuf, overlayColor));
// We can only log to the in-game overlay console when the SDK has
// been fully initialized, due to the use of ConVar's.
if (g_bSdkInitialized && logLevel >= LogLevel_t::LEVEL_NOTIFY)
{
// Draw to mini console.
g_pOverlay->AddLog(overlayContext, logStreamBuf.c_str());
g_TextOverlay.AddLog(overlayContext, logStreamBuf.c_str());
}
#endif // !DEDICATED
}

View File

@ -150,7 +150,7 @@ bool CClient::Authenticate(const char* const playerName, char* const reasonBuf,
"%lld-%s-%s",
this->m_DataBlock.userData,
playerName,
g_pMasterServer->GetHostIP().c_str()
g_MasterServer.GetHostIP().c_str()
);
DevMsg(eDLL_T::SERVER, "%s: newId=%s\n", __FUNCTION__, newId.c_str());

View File

@ -219,7 +219,7 @@ bool CClientState::Authenticate(connectparams_t* connectParams, char* const reas
// verify that the client is not lying about their account identity
// code is immediately discarded upon verification
const bool ret = g_pMasterServer->AuthForConnection(*g_NucleusID, connectParams->netAdr, g_OriginAuthCode, msToken, message);
const bool ret = g_MasterServer.AuthForConnection(*g_NucleusID, connectParams->netAdr, g_OriginAuthCode, msToken, message);
if (!ret)
{
FORMAT_ERROR_REASON("%s", message.c_str());

View File

@ -72,7 +72,7 @@ void _Host_RunFrame(void* unused, float time)
}), g_FrameTasks.end());
#ifndef DEDICATED
g_pOverlay->ShouldDraw(time);
g_TextOverlay.ShouldDraw(time);
#endif // !DEDICATED
return v_Host_RunFrame(unused, time);

View File

@ -69,20 +69,20 @@ bool HostState_KeepAlive(const NetGameServer_t& netGameServer)
string hostToken;
string hostIp;
const bool result = g_pMasterServer->PostServerHost(errorMsg, hostToken, hostIp, netGameServer);
const bool result = g_MasterServer.PostServerHost(errorMsg, hostToken, hostIp, netGameServer);
if (!result)
{
if (!errorMsg.empty() && g_pMasterServer->GetCurrentError().compare(errorMsg) != NULL)
if (!errorMsg.empty() && g_MasterServer.GetCurrentError().compare(errorMsg) != NULL)
{
g_pMasterServer->SetCurrentError(errorMsg);
g_MasterServer.SetCurrentError(errorMsg);
Error(eDLL_T::SERVER, NO_ERROR, "%s\n", errorMsg.c_str());
}
}
else // Attempt to log the token, if there is one.
{
if (!hostToken.empty() && g_pMasterServer->GetCurrentToken().compare(hostToken) != NULL)
if (!hostToken.empty() && g_MasterServer.GetCurrentToken().compare(hostToken) != NULL)
{
g_pMasterServer->SetCurrentToken(hostToken);
g_MasterServer.SetCurrentToken(hostToken);
Msg(eDLL_T::SERVER, "Published server with token: %s'%s%s%s'\n",
g_svReset, g_svGreyB,
hostToken.c_str(), g_svReset);
@ -90,7 +90,7 @@ bool HostState_KeepAlive(const NetGameServer_t& netGameServer)
}
if (hostIp.length() != 0)
g_pMasterServer->SetHostIP(hostIp);
g_MasterServer.SetHostIP(hostIp);
return result;
}
@ -252,7 +252,7 @@ void CHostState::Setup(void)
{
g_pHostState->LoadConfig();
#ifndef CLIENT_DLL
g_pBanSystem->LoadList();
g_BanSystem.LoadList();
#endif // !CLIENT_DLL
ConVar_PurgeHostNames();

View File

@ -20,11 +20,11 @@ void CEngineSDK::FixedFrame()
for (;;)
{
#ifndef DEDICATED
g_pBrowser->Think();
g_pConsole->Think();
g_Browser.Think();
g_Console.Think();
#endif // !DEDICATED
std::this_thread::sleep_for(IntervalToDuration(sdk_fixedframe_tickinterval->GetFloat()));
}
}
CEngineSDK* g_EngineSDK = new CEngineSDK();
CEngineSDK g_EngineSDK;

View File

@ -7,6 +7,6 @@ public:
void FixedFrame();
};
extern CEngineSDK* g_EngineSDK;
extern CEngineSDK g_EngineSDK;
#endif // SDK_DLL_H

View File

@ -143,9 +143,9 @@ CClient* CServer::ConnectClient(CServer* pServer, user_creds_s* pChallenge)
return nullptr;
}
if (g_pBanSystem->IsBanListValid())
if (g_BanSystem.IsBanListValid())
{
if (g_pBanSystem->IsBanned(pszAddresBuffer, nNucleusID))
if (g_BanSystem.IsBanned(pszAddresBuffer, nNucleusID))
{
pServer->RejectConnection(pServer->m_Socket, &pChallenge->netAdr, "#Valve_Reject_Banned");
if (bEnableLogging)
@ -158,7 +158,7 @@ CClient* CServer::ConnectClient(CServer* pServer, user_creds_s* pChallenge)
CClient* pClient = CServer__ConnectClient(pServer, pChallenge);
for (auto& callback : !g_pPluginSystem->GetConnectClientCallbacks())
for (auto& callback : !g_PluginSystem.GetConnectClientCallbacks())
{
if (!callback(pServer, pClient, pChallenge))
{

View File

@ -24,7 +24,7 @@ void SV_IsClientBanned(CClient* pClient, const string& svIPAddr,
Assert(pClient != nullptr);
string svError;
bool bCompBanned = g_pMasterServer->CheckForBan(svIPAddr, nNucleusID, svPersonaName, svError);
bool bCompBanned = g_MasterServer.CheckForBan(svIPAddr, nNucleusID, svPersonaName, svError);
if (bCompBanned)
{
@ -56,7 +56,7 @@ void SV_IsClientBanned(CClient* pClient, const string& svIPAddr,
void SV_ProcessBulkCheck(const CBanSystem::BannedList_t* pBannedVec, const bool bDelete)
{
CBanSystem::BannedList_t* outBannedVec = new CBanSystem::BannedList_t();
g_pMasterServer->GetBannedList(*pBannedVec, *outBannedVec);
g_MasterServer.GetBannedList(*pBannedVec, *outBannedVec);
// Caller wants to destroy the vector.
if (bDelete)

View File

@ -66,7 +66,7 @@ bool CSourceAppSystemGroup::StaticCreate(CSourceAppSystemGroup* pSourceAppSystem
//-----------------------------------------------------------------------------
int CModAppSystemGroup::StaticMain(CModAppSystemGroup* pModAppSystemGroup)
{
std::thread fixed(&CEngineSDK::FixedFrame, g_EngineSDK);
std::thread fixed(&CEngineSDK::FixedFrame, &g_EngineSDK);
fixed.detach();
int nRunResult = RUN_OK;
@ -102,22 +102,22 @@ bool CModAppSystemGroup::StaticCreate(CModAppSystemGroup* pModAppSystemGroup)
EXPOSE_INTERFACE_FN((InstantiateInterfaceFn)KeyValuesSystem, CKeyValuesSystem, KEYVALUESSYSTEM_INTERFACE_VERSION);
InitPluginSystem(pModAppSystemGroup);
CALL_PLUGIN_CALLBACKS(g_pPluginSystem->GetCreateCallbacks(), pModAppSystemGroup);
CALL_PLUGIN_CALLBACKS(g_PluginSystem.GetCreateCallbacks(), pModAppSystemGroup);
g_pModSystem->Init();
ModSystem()->Init();
g_pDebugOverlay = (CIVDebugOverlay*)g_pFactorySystem->GetFactory(VDEBUG_OVERLAY_INTERFACE_VERSION);
g_pDebugOverlay = (CIVDebugOverlay*)g_FactorySystem.GetFactory(VDEBUG_OVERLAY_INTERFACE_VERSION);
#ifndef CLIENT_DLL
g_pServerGameDLL = (CServerGameDLL*)g_pFactorySystem->GetFactory(INTERFACEVERSION_SERVERGAMEDLL);
g_pServerGameClients = (CServerGameClients*)g_pFactorySystem->GetFactory(INTERFACEVERSION_SERVERGAMECLIENTS_NEW);
g_pServerGameDLL = (CServerGameDLL*)g_FactorySystem.GetFactory(INTERFACEVERSION_SERVERGAMEDLL);
g_pServerGameClients = (CServerGameClients*)g_FactorySystem.GetFactory(INTERFACEVERSION_SERVERGAMECLIENTS_NEW);
if (!g_pServerGameClients)
g_pServerGameClients = (CServerGameClients*)g_pFactorySystem->GetFactory(INTERFACEVERSION_SERVERGAMECLIENTS);
g_pServerGameEntities = (CServerGameEnts*)g_pFactorySystem->GetFactory(INTERFACEVERSION_SERVERGAMEENTS);
g_pServerGameClients = (CServerGameClients*)g_FactorySystem.GetFactory(INTERFACEVERSION_SERVERGAMECLIENTS);
g_pServerGameEntities = (CServerGameEnts*)g_FactorySystem.GetFactory(INTERFACEVERSION_SERVERGAMEENTS);
#endif // !CLIENT_DLL
#ifndef DEDICATED
g_pClientEntityList = (CClientEntityList*)g_pFactorySystem->GetFactory(VCLIENTENTITYLIST_INTERFACE_VERSION);
g_pEngineTraceClient = (CEngineTraceClient*)g_pFactorySystem->GetFactory(INTERFACEVERSION_ENGINETRACE_CLIENT);
g_pClientEntityList = (CClientEntityList*)g_FactorySystem.GetFactory(VCLIENTENTITYLIST_INTERFACE_VERSION);
g_pEngineTraceClient = (CEngineTraceClient*)g_FactorySystem.GetFactory(INTERFACEVERSION_ENGINETRACE_CLIENT);
g_pImGuiConfig->Load(); // Load ImGui configs.
DirectX_Init();
@ -139,11 +139,11 @@ bool CModAppSystemGroup::StaticCreate(CModAppSystemGroup* pModAppSystemGroup)
//-----------------------------------------------------------------------------
void CModAppSystemGroup::InitPluginSystem(CModAppSystemGroup* pModAppSystemGroup)
{
g_pPluginSystem->Init();
g_PluginSystem.Init();
for (auto& it : g_pPluginSystem->GetInstances())
for (auto& it : g_PluginSystem.GetInstances())
{
if (g_pPluginSystem->LoadInstance(it))
if (g_PluginSystem.LoadInstance(it))
Msg(eDLL_T::ENGINE, "Loaded plugin: '%s'\n", it.m_Name.String());
else
Warning(eDLL_T::ENGINE, "Failed loading plugin: '%s'\n", it.m_Name.String());

View File

@ -45,19 +45,19 @@ int CGame::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
if (wParam == g_pImGuiConfig->m_ConsoleConfig.m_nBind0 ||
wParam == g_pImGuiConfig->m_ConsoleConfig.m_nBind1)
{
g_pConsole->m_bActivate ^= true;
g_Console.m_bActivate ^= true;
ResetInput(); // Disable input to game when console is drawn.
}
if (wParam == g_pImGuiConfig->m_BrowserConfig.m_nBind0 ||
wParam == g_pImGuiConfig->m_BrowserConfig.m_nBind1)
{
g_pBrowser->m_bActivate ^= true;
g_Browser.m_bActivate ^= true;
ResetInput(); // Disable input to game when browser is drawn.
}
}
if (g_pConsole->m_bActivate || g_pBrowser->m_bActivate)
if (g_Console.m_bActivate || g_Browser.m_bActivate)
{//////////////////////////////////////////////////////////////////////////////
g_bBlockInput = true;

View File

@ -98,9 +98,9 @@ void _Con_NPrintf(int pos, const char* fmt, ...)
va_end(args);
}/////////////////////////////
g_pOverlay->m_nCon_NPrintf_Idx = pos;
snprintf(g_pOverlay->m_szCon_NPrintf_Buf,
sizeof(g_pOverlay->m_szCon_NPrintf_Buf), "%s", buf);
g_TextOverlay.m_nCon_NPrintf_Idx = pos;
snprintf(g_TextOverlay.m_szCon_NPrintf_Buf,
sizeof(g_TextOverlay.m_szCon_NPrintf_Buf), "%s", buf);
}
#endif // !DEDICATED

View File

@ -25,7 +25,7 @@
//-----------------------------------------------------------------------------
static SQBool Script_CheckServerIndex(HSQUIRRELVM v, SQInteger iServer)
{
SQInteger iCount = static_cast<SQInteger>(g_pServerListManager->m_vServerList.size());
SQInteger iCount = static_cast<SQInteger>(g_ServerListManager.m_vServerList.size());
if (iServer >= iCount)
{
@ -46,7 +46,7 @@ namespace VScriptCode
SQRESULT RefreshServerList(HSQUIRRELVM v)
{
string serverMessage; // Refresh list.
size_t iCount = g_pServerListManager->RefreshServerList(serverMessage);
size_t iCount = g_ServerListManager.RefreshServerList(serverMessage);
sq_pushinteger(v, static_cast<SQInteger>(iCount));
@ -58,7 +58,7 @@ namespace VScriptCode
//-----------------------------------------------------------------------------
SQRESULT GetServerCount(HSQUIRRELVM v)
{
size_t iCount = g_pServerListManager->m_vServerList.size();
size_t iCount = g_ServerListManager.m_vServerList.size();
sq_pushinteger(v, static_cast<SQInteger>(iCount));
return SQ_OK;
@ -77,7 +77,7 @@ namespace VScriptCode
string hiddenServerRequestMessage;
NetGameServer_t serverListing;
bool result = g_pMasterServer->GetServerByToken(serverListing, hiddenServerRequestMessage, privateToken); // Send token connect request.
bool result = g_MasterServer.GetServerByToken(serverListing, hiddenServerRequestMessage, privateToken); // Send token connect request.
if (!result)
{
if (hiddenServerRequestMessage.empty())
@ -120,7 +120,7 @@ namespace VScriptCode
//-----------------------------------------------------------------------------
SQRESULT GetServerName(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
std::lock_guard<std::mutex> l(g_ServerListManager.m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
if (!Script_CheckServerIndex(v, iServer))
@ -128,7 +128,7 @@ namespace VScriptCode
return SQ_ERROR;
}
const string& serverName = g_pServerListManager->m_vServerList[iServer].m_svHostName;
const string& serverName = g_ServerListManager.m_vServerList[iServer].m_svHostName;
sq_pushstring(v, serverName.c_str(), -1);
return SQ_OK;
@ -139,7 +139,7 @@ namespace VScriptCode
//-----------------------------------------------------------------------------
SQRESULT GetServerDescription(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
std::lock_guard<std::mutex> l(g_ServerListManager.m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
if (!Script_CheckServerIndex(v, iServer))
@ -147,7 +147,7 @@ namespace VScriptCode
return SQ_ERROR;
}
const string& serverDescription = g_pServerListManager->m_vServerList[iServer].m_svDescription;
const string& serverDescription = g_ServerListManager.m_vServerList[iServer].m_svDescription;
sq_pushstring(v, serverDescription.c_str(), -1);
return SQ_OK;
@ -158,7 +158,7 @@ namespace VScriptCode
//-----------------------------------------------------------------------------
SQRESULT GetServerMap(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
std::lock_guard<std::mutex> l(g_ServerListManager.m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
if (!Script_CheckServerIndex(v, iServer))
@ -166,7 +166,7 @@ namespace VScriptCode
return SQ_ERROR;
}
const string& svServerMapName = g_pServerListManager->m_vServerList[iServer].m_svHostMap;
const string& svServerMapName = g_ServerListManager.m_vServerList[iServer].m_svHostMap;
sq_pushstring(v, svServerMapName.c_str(), -1);
return SQ_OK;
@ -177,7 +177,7 @@ namespace VScriptCode
//-----------------------------------------------------------------------------
SQRESULT GetServerPlaylist(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
std::lock_guard<std::mutex> l(g_ServerListManager.m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
if (!Script_CheckServerIndex(v, iServer))
@ -185,7 +185,7 @@ namespace VScriptCode
return SQ_ERROR;
}
const string& serverPlaylist = g_pServerListManager->m_vServerList[iServer].m_svPlaylist;
const string& serverPlaylist = g_ServerListManager.m_vServerList[iServer].m_svPlaylist;
sq_pushstring(v, serverPlaylist.c_str(), -1);
return SQ_OK;
@ -196,7 +196,7 @@ namespace VScriptCode
//-----------------------------------------------------------------------------
SQRESULT GetServerCurrentPlayers(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
std::lock_guard<std::mutex> l(g_ServerListManager.m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
if (!Script_CheckServerIndex(v, iServer))
@ -204,7 +204,7 @@ namespace VScriptCode
return SQ_ERROR;
}
const SQInteger playerCount = g_pServerListManager->m_vServerList[iServer].m_nPlayerCount;
const SQInteger playerCount = g_ServerListManager.m_vServerList[iServer].m_nPlayerCount;
sq_pushinteger(v, playerCount);
return SQ_OK;
@ -215,7 +215,7 @@ namespace VScriptCode
//-----------------------------------------------------------------------------
SQRESULT GetServerMaxPlayers(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
std::lock_guard<std::mutex> l(g_ServerListManager.m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
if (!Script_CheckServerIndex(v, iServer))
@ -223,7 +223,7 @@ namespace VScriptCode
return SQ_ERROR;
}
const SQInteger maxPlayers = g_pServerListManager->m_vServerList[iServer].m_nMaxPlayers;
const SQInteger maxPlayers = g_ServerListManager.m_vServerList[iServer].m_nMaxPlayers;
sq_pushinteger(v, maxPlayers);
return SQ_OK;
@ -295,7 +295,7 @@ namespace VScriptCode
MSEulaData_t eulaData;
string eulaRequestMessage;
if (g_pMasterServer->GetEULA(eulaData, eulaRequestMessage))
if (g_MasterServer.GetEULA(eulaData, eulaRequestMessage))
{
// set EULA version cvar to the newly fetched EULA version
eula_version->SetValue(eulaData.version);
@ -325,7 +325,7 @@ namespace VScriptCode
return SQ_OK;
Msg(eDLL_T::UI, "Connecting to server with ip address '%s' and encryption key '%s'\n", ipAddress, cryptoKey);
g_pServerListManager->ConnectToServer(ipAddress, cryptoKey);
g_ServerListManager.ConnectToServer(ipAddress, cryptoKey);
return SQ_OK;
}
@ -335,7 +335,7 @@ namespace VScriptCode
//-----------------------------------------------------------------------------
SQRESULT ConnectToListedServer(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
std::lock_guard<std::mutex> l(g_ServerListManager.m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
if (!Script_CheckServerIndex(v, iServer))
@ -343,9 +343,9 @@ namespace VScriptCode
return SQ_ERROR;
}
const NetGameServer_t& gameServer = g_pServerListManager->m_vServerList[iServer];
const NetGameServer_t& gameServer = g_ServerListManager.m_vServerList[iServer];
g_pServerListManager->ConnectToServer(gameServer.m_svIpAddress, gameServer.m_nGamePort,
g_ServerListManager.ConnectToServer(gameServer.m_svIpAddress, gameServer.m_nGamePort,
gameServer.m_svEncryptionKey);
return SQ_OK;
@ -364,10 +364,10 @@ namespace VScriptCode
string hiddenServerRequestMessage;
NetGameServer_t netListing;
bool result = g_pMasterServer->GetServerByToken(netListing, hiddenServerRequestMessage, privateToken); // Send token connect request.
bool result = g_MasterServer.GetServerByToken(netListing, hiddenServerRequestMessage, privateToken); // Send token connect request.
if (result)
{
g_pServerListManager->ConnectToServer(netListing.m_svIpAddress, netListing.m_nGamePort, netListing.m_svEncryptionKey);
g_ServerListManager.ConnectToServer(netListing.m_svIpAddress, netListing.m_nGamePort, netListing.m_svEncryptionKey);
}
else
{

View File

@ -43,16 +43,16 @@ namespace VScriptCode
}
// Adjust browser settings.
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
std::lock_guard<std::mutex> l(g_ServerListManager.m_Mutex);
g_pServerListManager->m_Server.m_svHostName = serverName;
g_pServerListManager->m_Server.m_svDescription = serverDescription;
g_pServerListManager->m_Server.m_svHostMap = serverMapName;
g_pServerListManager->m_Server.m_svPlaylist = serverPlaylist;
g_pServerListManager->m_ServerVisibility = eServerVisibility;
g_ServerListManager.m_Server.m_svHostName = serverName;
g_ServerListManager.m_Server.m_svDescription = serverDescription;
g_ServerListManager.m_Server.m_svHostMap = serverMapName;
g_ServerListManager.m_Server.m_svPlaylist = serverPlaylist;
g_ServerListManager.m_ServerVisibility = eServerVisibility;
// Launch server.
g_pServerListManager->LaunchServer(g_pServer->IsActive());
g_ServerListManager.LaunchServer(g_pServer->IsActive());
return SQ_OK;
@ -82,7 +82,7 @@ namespace VScriptCode
if (!VALID_CHARSTAR(reason))
reason = nullptr;
g_pBanSystem->KickPlayerByName(playerName, reason);
g_BanSystem.KickPlayerByName(playerName, reason);
return SQ_OK;
}
@ -99,7 +99,7 @@ namespace VScriptCode
if (!VALID_CHARSTAR(reason))
reason = nullptr;
g_pBanSystem->KickPlayerById(playerHandle, reason);
g_BanSystem.KickPlayerById(playerHandle, reason);
return SQ_OK;
}
@ -116,7 +116,7 @@ namespace VScriptCode
if (!VALID_CHARSTAR(reason))
reason = nullptr;
g_pBanSystem->BanPlayerByName(playerName, reason);
g_BanSystem.BanPlayerByName(playerName, reason);
return SQ_OK;
}
@ -133,7 +133,7 @@ namespace VScriptCode
if (!VALID_CHARSTAR(reason))
reason = nullptr;
g_pBanSystem->BanPlayerById(playerHandle, reason);
g_BanSystem.BanPlayerById(playerHandle, reason);
return SQ_OK;
}
@ -144,7 +144,7 @@ namespace VScriptCode
SQRESULT UnbanPlayer(HSQUIRRELVM v)
{
SQChar* szCriteria = sq_getstring(v, 1);
g_pBanSystem->UnbanPlayer(szCriteria);
g_BanSystem.UnbanPlayer(szCriteria);
return SQ_OK;
}

View File

@ -177,7 +177,7 @@ void CBrowser::RunTask()
{
if (m_bQueryListNonRecursive)
{
std::thread refresh(&CBrowser::RefreshServerList, g_pBrowser);
std::thread refresh(&CBrowser::RefreshServerList, this);
refresh.detach();
m_bQueryListNonRecursive = false;
@ -289,8 +289,8 @@ void CBrowser::BrowserPanel(void)
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthStretch, 5);
ImGui::TableHeadersRow();
g_pServerListManager->m_Mutex.lock();
for (const NetGameServer_t& server : g_pServerListManager->m_vServerList)
g_ServerListManager.m_Mutex.lock();
for (const NetGameServer_t& server : g_ServerListManager.m_vServerList)
{
const char* pszHostName = server.m_svHostName.c_str();
const char* pszHostMap = server.m_svHostMap.c_str();
@ -324,11 +324,11 @@ void CBrowser::BrowserPanel(void)
if (ImGui::Button(svConnectBtn.c_str()))
{
g_pServerListManager->ConnectToServer(server.m_svIpAddress, server.m_nGamePort, server.m_svEncryptionKey);
g_ServerListManager.ConnectToServer(server.m_svIpAddress, server.m_nGamePort, server.m_svEncryptionKey);
}
}
}
g_pServerListManager->m_Mutex.unlock();
g_ServerListManager.m_Mutex.unlock();
ImGui::EndTable();
ImGui::PopStyleVar(nVars);
@ -350,7 +350,7 @@ void CBrowser::BrowserPanel(void)
{
if (m_szServerAddressBuffer[0])
{
g_pServerListManager->ConnectToServer(m_szServerAddressBuffer, m_szServerEncKeyBuffer);
g_ServerListManager.ConnectToServer(m_szServerAddressBuffer, m_szServerEncKeyBuffer);
}
}
@ -372,7 +372,7 @@ void CBrowser::RefreshServerList(void)
Msg(eDLL_T::CLIENT, "Refreshing server list with matchmaking host '%s'\n", pylon_matchmaking_hostname->GetString());
std::string svServerListMessage;
g_pServerListManager->RefreshServerList(svServerListMessage);
g_ServerListManager.RefreshServerList(svServerListMessage);
std::lock_guard<std::mutex> l(m_Mutex);
m_svServerListMessage = svServerListMessage;
@ -439,11 +439,11 @@ void CBrowser::HiddenServersModal(void)
if (!m_svHiddenServerToken.empty())
{
NetGameServer_t server;
bool result = g_pMasterServer->GetServerByToken(server, m_svHiddenServerRequestMessage, m_svHiddenServerToken); // Send token connect request.
bool result = g_MasterServer.GetServerByToken(server, m_svHiddenServerRequestMessage, m_svHiddenServerToken); // Send token connect request.
if (result && !server.m_svHostName.empty())
{
g_pServerListManager->ConnectToServer(server.m_svIpAddress, server.m_nGamePort, server.m_svEncryptionKey); // Connect to the server
g_ServerListManager.ConnectToServer(server.m_svIpAddress, server.m_nGamePort, server.m_svEncryptionKey); // Connect to the server
m_svHiddenServerRequestMessage = Format("Found server: %s", server.m_svHostName.c_str());
m_ivHiddenServerMessageColor = ImVec4(0.00f, 1.00f, 0.00f, 1.00f);
ImGui::CloseCurrentPopup();
@ -497,20 +497,20 @@ void CBrowser::HiddenServersModal(void)
void CBrowser::HostPanel(void)
{
#ifndef CLIENT_DLL
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
std::lock_guard<std::mutex> l(g_ServerListManager.m_Mutex);
ImGui::InputTextWithHint("##ServerHost_ServerName", "Server name (required)", &g_pServerListManager->m_Server.m_svHostName);
ImGui::InputTextWithHint("##ServerHost_ServerDesc", "Server description (optional)", &g_pServerListManager->m_Server.m_svDescription);
ImGui::InputTextWithHint("##ServerHost_ServerName", "Server name (required)", &g_ServerListManager.m_Server.m_svHostName);
ImGui::InputTextWithHint("##ServerHost_ServerDesc", "Server description (optional)", &g_ServerListManager.m_Server.m_svDescription);
ImGui::Spacing();
if (ImGui::BeginCombo("Mode", g_pServerListManager->m_Server.m_svPlaylist.c_str()))
if (ImGui::BeginCombo("Mode", g_ServerListManager.m_Server.m_svPlaylist.c_str()))
{
g_PlaylistsVecMutex.lock();
for (const string& svPlaylist : g_vAllPlaylists)
{
if (ImGui::Selectable(svPlaylist.c_str(), svPlaylist == g_pServerListManager->m_Server.m_svPlaylist))
if (ImGui::Selectable(svPlaylist.c_str(), svPlaylist == g_ServerListManager.m_Server.m_svPlaylist))
{
g_pServerListManager->m_Server.m_svPlaylist = svPlaylist;
g_ServerListManager.m_Server.m_svPlaylist = svPlaylist;
}
}
@ -518,7 +518,7 @@ void CBrowser::HostPanel(void)
ImGui::EndCombo();
}
if (ImGui::BeginCombo("Map", g_pServerListManager->m_Server.m_svHostMap.c_str()))
if (ImGui::BeginCombo("Map", g_ServerListManager.m_Server.m_svHostMap.c_str()))
{
g_InstalledMapsMutex.lock();
@ -527,9 +527,9 @@ void CBrowser::HostPanel(void)
const CUtlString& mapName = g_InstalledMaps[i];
if (ImGui::Selectable(mapName.String(),
mapName.IsEqual_CaseInsensitive(g_pServerListManager->m_Server.m_svHostMap.c_str())))
mapName.IsEqual_CaseInsensitive(g_ServerListManager.m_Server.m_svHostMap.c_str())))
{
g_pServerListManager->m_Server.m_svHostMap = mapName.String();
g_ServerListManager.m_Server.m_svHostMap = mapName.String();
}
}
@ -545,17 +545,17 @@ void CBrowser::HostPanel(void)
ImGui::Text("Server visibility");
if (ImGui::SameLine(); ImGui::RadioButton("offline", g_pServerListManager->m_ServerVisibility == EServerVisibility_t::OFFLINE))
if (ImGui::SameLine(); ImGui::RadioButton("offline", g_ServerListManager.m_ServerVisibility == EServerVisibility_t::OFFLINE))
{
g_pServerListManager->m_ServerVisibility = EServerVisibility_t::OFFLINE;
g_ServerListManager.m_ServerVisibility = EServerVisibility_t::OFFLINE;
}
if (ImGui::SameLine(); ImGui::RadioButton("hidden", g_pServerListManager->m_ServerVisibility == EServerVisibility_t::HIDDEN))
if (ImGui::SameLine(); ImGui::RadioButton("hidden", g_ServerListManager.m_ServerVisibility == EServerVisibility_t::HIDDEN))
{
g_pServerListManager->m_ServerVisibility = EServerVisibility_t::HIDDEN;
g_ServerListManager.m_ServerVisibility = EServerVisibility_t::HIDDEN;
}
if (ImGui::SameLine(); ImGui::RadioButton("public", g_pServerListManager->m_ServerVisibility == EServerVisibility_t::PUBLIC))
if (ImGui::SameLine(); ImGui::RadioButton("public", g_ServerListManager.m_ServerVisibility == EServerVisibility_t::PUBLIC))
{
g_pServerListManager->m_ServerVisibility = EServerVisibility_t::PUBLIC;
g_ServerListManager.m_ServerVisibility = EServerVisibility_t::PUBLIC;
}
ImGui::TextColored(m_HostRequestMessageColor, "%s", m_svHostRequestMessage.c_str());
@ -574,24 +574,24 @@ void CBrowser::HostPanel(void)
{
m_svHostRequestMessage.clear();
bool bEnforceField = g_pServerListManager->m_ServerVisibility == EServerVisibility_t::OFFLINE ? true : !g_pServerListManager->m_Server.m_svHostName.empty();
if (bEnforceField && !g_pServerListManager->m_Server.m_svPlaylist.empty() && !g_pServerListManager->m_Server.m_svHostMap.empty())
bool bEnforceField = g_ServerListManager.m_ServerVisibility == EServerVisibility_t::OFFLINE ? true : !g_ServerListManager.m_Server.m_svHostName.empty();
if (bEnforceField && !g_ServerListManager.m_Server.m_svPlaylist.empty() && !g_ServerListManager.m_Server.m_svHostMap.empty())
{
g_pServerListManager->LaunchServer(bServerActive); // Launch server.
g_ServerListManager.LaunchServer(bServerActive); // Launch server.
}
else
{
if (g_pServerListManager->m_Server.m_svHostName.empty())
if (g_ServerListManager.m_Server.m_svHostName.empty())
{
m_svHostRequestMessage = "Server name is required.";
m_HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
}
else if (g_pServerListManager->m_Server.m_svPlaylist.empty())
else if (g_ServerListManager.m_Server.m_svPlaylist.empty())
{
m_svHostRequestMessage = "Playlist is required.";
m_HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
}
else if (g_pServerListManager->m_Server.m_svHostMap.empty())
else if (g_ServerListManager.m_Server.m_svHostMap.empty())
{
m_svHostRequestMessage = "Level name is required.";
m_HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
@ -611,7 +611,7 @@ void CBrowser::HostPanel(void)
{
g_TaskScheduler->Dispatch([]()
{
g_pBanSystem->LoadList();
g_BanSystem.LoadList();
}, 0);
}
}
@ -629,9 +629,9 @@ void CBrowser::HostPanel(void)
if (ImGui::Button("Change level", ImVec2(ImGui::GetWindowContentRegionWidth(), 32)))
{
if (!g_pServerListManager->m_Server.m_svHostMap.empty())
if (!g_ServerListManager.m_Server.m_svHostMap.empty())
{
g_pServerListManager->LaunchServer(bServerActive);
g_ServerListManager.LaunchServer(bServerActive);
}
else
{
@ -689,10 +689,10 @@ void CBrowser::UpdateHostingStatus(void)
#ifndef CLIENT_DLL
assert(g_pHostState && g_pCVar);
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
g_pServerListManager->m_HostingStatus = g_pServer->IsActive() ? EHostStatus_t::HOSTING : EHostStatus_t::NOT_HOSTING; // Are we hosting a server?
std::lock_guard<std::mutex> l(g_ServerListManager.m_Mutex);
g_ServerListManager.m_HostingStatus = g_pServer->IsActive() ? EHostStatus_t::HOSTING : EHostStatus_t::NOT_HOSTING; // Are we hosting a server?
switch (g_pServerListManager->m_HostingStatus)
switch (g_ServerListManager.m_HostingStatus)
{
case EHostStatus_t::NOT_HOSTING:
{
@ -713,7 +713,7 @@ void CBrowser::UpdateHostingStatus(void)
}
case EHostStatus_t::HOSTING:
{
if (g_pServerListManager->m_ServerVisibility == EServerVisibility_t::OFFLINE)
if (g_ServerListManager.m_ServerVisibility == EServerVisibility_t::OFFLINE)
{
break;
}
@ -723,14 +723,14 @@ void CBrowser::UpdateHostingStatus(void)
break;
}
switch (g_pServerListManager->m_ServerVisibility)
switch (g_ServerListManager.m_ServerVisibility)
{
case EServerVisibility_t::HIDDEN:
g_pServerListManager->m_Server.m_bHidden = true;
g_ServerListManager.m_Server.m_bHidden = true;
break;
case EServerVisibility_t::PUBLIC:
g_pServerListManager->m_Server.m_bHidden = false;
g_ServerListManager.m_Server.m_bHidden = false;
break;
default:
break;
@ -738,12 +738,12 @@ void CBrowser::UpdateHostingStatus(void)
g_TaskScheduler->Dispatch([this]()
{
std::lock_guard<std::mutex> f(g_pServerListManager->m_Mutex);
std::lock_guard<std::mutex> f(g_ServerListManager.m_Mutex);
NetGameServer_t netGameServer
{
g_pServerListManager->m_Server.m_svHostName,
g_pServerListManager->m_Server.m_svDescription,
g_pServerListManager->m_Server.m_bHidden,
g_ServerListManager.m_Server.m_svHostName,
g_ServerListManager.m_Server.m_svDescription,
g_ServerListManager.m_Server.m_bHidden,
g_pHostState->m_levelName,
v_Playlists_GetCurrent(),
hostip->GetString(),
@ -782,7 +782,7 @@ void CBrowser::SendHostingPostRequest(const NetGameServer_t& gameServer)
string svHostToken;
string svHostIp;
bool result = g_pMasterServer->PostServerHost(svHostRequestMessage, svHostToken, svHostIp, gameServer);
bool result = g_MasterServer.PostServerHost(svHostRequestMessage, svHostToken, svHostIp, gameServer);
std::lock_guard<std::mutex> l(m_Mutex);
@ -790,7 +790,7 @@ void CBrowser::SendHostingPostRequest(const NetGameServer_t& gameServer)
m_svHostToken = svHostToken;
if(svHostIp.length() != 0)
g_pMasterServer->SetHostIP(svHostIp);
g_MasterServer.SetHostIP(svHostIp);
if (result)
{
@ -862,4 +862,4 @@ void CBrowser::SetStyleVar(void)
ImGui::SetWindowPos(ImVec2(-500.f, 50.f), ImGuiCond_FirstUseEver);
}
CBrowser* g_pBrowser = new CBrowser();
CBrowser g_Browser;

View File

@ -79,5 +79,5 @@ private:
ImGuiStyle_t m_Style;
};
extern CBrowser* g_pBrowser;
extern CBrowser g_Browser;
#endif

View File

@ -1149,4 +1149,4 @@ void CConsole::SetStyleVar(void)
ImGui::SetWindowPos(ImVec2(-1000, 50), ImGuiCond_FirstUseEver);
}
CConsole* g_pConsole = new CConsole();
CConsole g_Console;

View File

@ -115,5 +115,5 @@ public:
};
///////////////////////////////////////////////////////////////////////////////
extern CConsole* g_pConsole;
extern CConsole g_Console;
#endif // !DEDICATED

View File

@ -8,7 +8,7 @@ bool Localize_LoadLocalizationFileLists(CLocalize* thisptr)
CLocalize__LoadLocalizationFileLists(thisptr);
const CUtlVector<CModSystem::ModInstance_t*>&
modList = g_pModSystem->GetModList();
modList = ModSystem()->GetModList();
FOR_EACH_VEC(modList, i)
{

View File

@ -425,4 +425,4 @@ void CBanSystem::AuthorPlayerById(const char* playerHandle, const bool shouldBan
}
///////////////////////////////////////////////////////////////////////////////
CBanSystem* g_pBanSystem = new CBanSystem();
CBanSystem g_BanSystem;

View File

@ -56,4 +56,4 @@ private:
BannedList_t m_BannedList;
};
extern CBanSystem* g_pBanSystem;
extern CBanSystem g_BanSystem;

View File

@ -35,7 +35,7 @@ CServerListManager::CServerListManager(void)
size_t CServerListManager::RefreshServerList(string& svMessage)
{
ClearServerList();
vector<NetGameServer_t> vServerList = g_pMasterServer->GetServerList(svMessage);
vector<NetGameServer_t> vServerList = g_MasterServer.GetServerList(svMessage);
std::lock_guard<std::mutex> l(m_Mutex);
m_vServerList = vServerList;
@ -137,4 +137,4 @@ void CServerListManager::ProcessCommand(const char* pszCommand) const
//g_TaskScheduler->Dispatch(Cbuf_Execute, 0); // Run in main thread.
}
CServerListManager* g_pServerListManager = new CServerListManager();
CServerListManager g_ServerListManager;

View File

@ -38,5 +38,5 @@ public:
mutable std::mutex m_Mutex;
};
extern CServerListManager* g_pServerListManager;
extern CServerListManager g_ServerListManager;
#endif // LISTMANAGER_H

View File

@ -617,4 +617,4 @@ void CPylon::LogBody(const rapidjson::Document& responseJson) const
}
///////////////////////////////////////////////////////////////////////////////
CPylon* g_pMasterServer(new CPylon());
CPylon g_MasterServer;

View File

@ -52,4 +52,4 @@ private:
string m_HostIP;
string m_Language;
};
extern CPylon* g_pMasterServer;
extern CPylon g_MasterServer;

View File

@ -343,4 +343,4 @@ void CModSystem::ModInstance_t::ParseLocalizationFiles()
}
}
CModSystem* g_pModSystem = new CModSystem();
CModSystem g_ModSystem;

View File

@ -76,4 +76,9 @@ private:
CUtlVector<ModInstance_t*> m_ModList;
};
extern CModSystem* g_pModSystem;
extern CModSystem g_ModSystem;
FORCEINLINE CModSystem* ModSystem()
{
return &g_ModSystem;
}

View File

@ -209,4 +209,4 @@ void* CPluginSystem::HelpWithAnything(PluginHelpWithAnything_t* help)
return nullptr;
}
CPluginSystem* g_pPluginSystem = new CPluginSystem();
CPluginSystem g_PluginSystem;

View File

@ -130,11 +130,11 @@ public:
private:
CUtlVector<PluginInstance_t> m_Instances;
};
extern CPluginSystem* g_pPluginSystem;
extern CPluginSystem g_PluginSystem;
FORCEINLINE CPluginSystem* PluginSystem()
{
return g_pPluginSystem;
return &g_PluginSystem;
}
// Monitor this and performance profile this if fps drops are detected.

View File

@ -21,7 +21,7 @@ int CEngineVGui::Paint(CEngineVGui* thisptr, PaintMode_t mode)
if (/*mode == PaintMode_t::PAINT_UIPANELS ||*/ mode == PaintMode_t::PAINT_INGAMEPANELS) // Render in-main menu and in-game.
{
g_pOverlay->Update();
g_TextOverlay.Update();
}
return result;

View File

@ -296,4 +296,4 @@ Color CTextOverlay::GetLogColorForType(const eDLL_T context) const
}
///////////////////////////////////////////////////////////////////////////////
CTextOverlay* g_pOverlay = new CTextOverlay();
CTextOverlay g_TextOverlay;

View File

@ -50,4 +50,4 @@ public:
};
///////////////////////////////////////////////////////////////////////////////
extern CTextOverlay* g_pOverlay;
extern CTextOverlay g_TextOverlay;

View File

@ -15,7 +15,7 @@
//-----------------------------------------------------------------------------
ConVar* HCFPSPanel_Paint(void* thisptr)
{
g_pOverlay->Update();
g_TextOverlay.Update();
return CFPSPanel__Paint(thisptr);
}

View File

@ -57,7 +57,7 @@ void* CreateInterface(const char* pName, int* pReturnCode)
//---------------------------------------------------------------------------------
IFactorySystem* GetFactorySystem()
{
return g_pFactorySystem;
return &g_FactorySystem;
}
CFactorySystem* g_pFactorySystem = new CFactorySystem();
CFactorySystem g_FactorySystem;

View File

@ -55,7 +55,7 @@ public:
virtual const char* GetVersion(void) const override;
};
extern CFactorySystem* g_pFactorySystem;
extern CFactorySystem g_FactorySystem;
PLATFORM_INTERFACE IFactorySystem* GetFactorySystem();
///////////////////////////////////////////////////////////////////////////////

View File

@ -145,9 +145,9 @@ void CSquirrelVM::SetAsCompiler(RSON::Node_t* rson)
//---------------------------------------------------------------------------------
void CSquirrelVM::CompileModScripts()
{
FOR_EACH_VEC(g_pModSystem->GetModList(), i)
FOR_EACH_VEC(ModSystem()->GetModList(), i)
{
const CModSystem::ModInstance_t* mod = g_pModSystem->GetModList()[i];
const CModSystem::ModInstance_t* mod = ModSystem()->GetModList()[i];
if (!mod->IsEnabled())
continue;

View File

@ -117,11 +117,11 @@ void DrawImGui()
if (GImGui->ConfigNavWindowingKeyPrev)
ImGui::SetShortcutRouting(GImGui->ConfigNavWindowingKeyPrev, ImGuiKeyOwner_None);
g_pBrowser->RunTask();
g_pBrowser->RunFrame();
g_Browser.RunTask();
g_Browser.RunFrame();
g_pConsole->RunTask();
g_pConsole->RunFrame();
g_Console.RunTask();
g_Console.RunFrame();
ImGui::EndFrame();
ImGui::Render();
@ -322,12 +322,12 @@ bool LoadTextureBuffer(unsigned char* buffer, int len, ID3D11ShaderResourceView*
void ResetInput()
{
g_pInputSystem->EnableInput( // Enables the input system when both are not drawn.
!g_pBrowser->m_bActivate && !g_pConsole->m_bActivate);
!g_Browser.m_bActivate && !g_Console.m_bActivate);
}
bool PanelsVisible()
{
if (g_pBrowser->m_bActivate || g_pConsole->m_bActivate)
if (g_Browser.m_bActivate || g_Console.m_bActivate)
{
return true;
}