From fcf3a09418099c86843f05d8291b45b4b62b5eca Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 21 Jan 2024 21:29:23 +0100 Subject: [PATCH] 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. --- r5dev/common/callback.cpp | 28 +++--- r5dev/core/logger.cpp | 4 +- r5dev/engine/client/client.cpp | 2 +- r5dev/engine/client/clientstate.cpp | 2 +- r5dev/engine/host.cpp | 2 +- r5dev/engine/host_state.cpp | 14 +-- r5dev/engine/sdk_dll.cpp | 6 +- r5dev/engine/sdk_dll.h | 2 +- r5dev/engine/server/server.cpp | 6 +- r5dev/engine/server/sv_main.cpp | 4 +- r5dev/engine/sys_dll.cpp | 26 ++--- r5dev/engine/sys_mainwind.cpp | 6 +- r5dev/engine/sys_utils.cpp | 6 +- r5dev/game/client/vscript_client.cpp | 46 ++++----- r5dev/game/server/vscript_server.cpp | 24 ++--- r5dev/gameui/IBrowser.cpp | 94 +++++++++---------- r5dev/gameui/IBrowser.h | 2 +- r5dev/gameui/IConsole.cpp | 2 +- r5dev/gameui/IConsole.h | 2 +- r5dev/localize/localize.cpp | 2 +- r5dev/networksystem/bansystem.cpp | 2 +- r5dev/networksystem/bansystem.h | 2 +- r5dev/networksystem/listmanager.cpp | 4 +- r5dev/networksystem/listmanager.h | 2 +- r5dev/networksystem/pylon.cpp | 2 +- r5dev/networksystem/pylon.h | 2 +- r5dev/pluginsystem/modsystem.cpp | 2 +- r5dev/pluginsystem/modsystem.h | 7 +- r5dev/pluginsystem/pluginsystem.cpp | 2 +- r5dev/pluginsystem/pluginsystem.h | 4 +- r5dev/vgui/vgui_baseui_interface.cpp | 2 +- r5dev/vgui/vgui_debugpanel.cpp | 2 +- r5dev/vgui/vgui_debugpanel.h | 2 +- r5dev/vgui/vgui_fpspanel.cpp | 2 +- r5dev/vpc/interfaces.cpp | 4 +- r5dev/vpc/interfaces.h | 2 +- .../languages/squirrel_re/vsquirrel.cpp | 4 +- r5dev/windows/id3dx.cpp | 12 +-- 38 files changed, 172 insertions(+), 167 deletions(-) diff --git a/r5dev/common/callback.cpp b/r5dev/common/callback.cpp index 58d3b706..6f363a82 100644 --- a/r5dev/common/callback.cpp +++ b/r5dev/common/callback.cpp @@ -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 vHistory = g_pConsole->GetHistory(); + const vector 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); } } diff --git a/r5dev/core/logger.cpp b/r5dev/core/logger.cpp index de5703e9..e6d34f2f 100644 --- a/r5dev/core/logger.cpp +++ b/r5dev/core/logger.cpp @@ -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 } diff --git a/r5dev/engine/client/client.cpp b/r5dev/engine/client/client.cpp index c841078c..326beac0 100644 --- a/r5dev/engine/client/client.cpp +++ b/r5dev/engine/client/client.cpp @@ -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()); diff --git a/r5dev/engine/client/clientstate.cpp b/r5dev/engine/client/clientstate.cpp index e22707dc..dec06da1 100644 --- a/r5dev/engine/client/clientstate.cpp +++ b/r5dev/engine/client/clientstate.cpp @@ -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()); diff --git a/r5dev/engine/host.cpp b/r5dev/engine/host.cpp index e65129b5..1390ce80 100644 --- a/r5dev/engine/host.cpp +++ b/r5dev/engine/host.cpp @@ -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); diff --git a/r5dev/engine/host_state.cpp b/r5dev/engine/host_state.cpp index b93557c3..87909b88 100644 --- a/r5dev/engine/host_state.cpp +++ b/r5dev/engine/host_state.cpp @@ -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(); diff --git a/r5dev/engine/sdk_dll.cpp b/r5dev/engine/sdk_dll.cpp index 7d858922..99cecdee 100644 --- a/r5dev/engine/sdk_dll.cpp +++ b/r5dev/engine/sdk_dll.cpp @@ -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; diff --git a/r5dev/engine/sdk_dll.h b/r5dev/engine/sdk_dll.h index 3830f242..154ff3ba 100644 --- a/r5dev/engine/sdk_dll.h +++ b/r5dev/engine/sdk_dll.h @@ -7,6 +7,6 @@ public: void FixedFrame(); }; -extern CEngineSDK* g_EngineSDK; +extern CEngineSDK g_EngineSDK; #endif // SDK_DLL_H diff --git a/r5dev/engine/server/server.cpp b/r5dev/engine/server/server.cpp index d65a651f..900751e3 100644 --- a/r5dev/engine/server/server.cpp +++ b/r5dev/engine/server/server.cpp @@ -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)) { diff --git a/r5dev/engine/server/sv_main.cpp b/r5dev/engine/server/sv_main.cpp index 705d6e77..998e5ee0 100644 --- a/r5dev/engine/server/sv_main.cpp +++ b/r5dev/engine/server/sv_main.cpp @@ -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) diff --git a/r5dev/engine/sys_dll.cpp b/r5dev/engine/sys_dll.cpp index e7b6973b..70f1635e 100644 --- a/r5dev/engine/sys_dll.cpp +++ b/r5dev/engine/sys_dll.cpp @@ -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()); diff --git a/r5dev/engine/sys_mainwind.cpp b/r5dev/engine/sys_mainwind.cpp index 04697ab3..2df00d2a 100644 --- a/r5dev/engine/sys_mainwind.cpp +++ b/r5dev/engine/sys_mainwind.cpp @@ -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; diff --git a/r5dev/engine/sys_utils.cpp b/r5dev/engine/sys_utils.cpp index f6788901..4da106dc 100644 --- a/r5dev/engine/sys_utils.cpp +++ b/r5dev/engine/sys_utils.cpp @@ -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 diff --git a/r5dev/game/client/vscript_client.cpp b/r5dev/game/client/vscript_client.cpp index 4bf9214e..e5d398b0 100644 --- a/r5dev/game/client/vscript_client.cpp +++ b/r5dev/game/client/vscript_client.cpp @@ -25,7 +25,7 @@ //----------------------------------------------------------------------------- static SQBool Script_CheckServerIndex(HSQUIRRELVM v, SQInteger iServer) { - SQInteger iCount = static_cast(g_pServerListManager->m_vServerList.size()); + SQInteger iCount = static_cast(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(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(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 l(g_pServerListManager->m_Mutex); + std::lock_guard 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 l(g_pServerListManager->m_Mutex); + std::lock_guard 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 l(g_pServerListManager->m_Mutex); + std::lock_guard 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 l(g_pServerListManager->m_Mutex); + std::lock_guard 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 l(g_pServerListManager->m_Mutex); + std::lock_guard 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 l(g_pServerListManager->m_Mutex); + std::lock_guard 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 l(g_pServerListManager->m_Mutex); + std::lock_guard 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 { diff --git a/r5dev/game/server/vscript_server.cpp b/r5dev/game/server/vscript_server.cpp index a3e0bada..a0dc559e 100644 --- a/r5dev/game/server/vscript_server.cpp +++ b/r5dev/game/server/vscript_server.cpp @@ -43,16 +43,16 @@ namespace VScriptCode } // Adjust browser settings. - std::lock_guard l(g_pServerListManager->m_Mutex); + std::lock_guard 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; } diff --git a/r5dev/gameui/IBrowser.cpp b/r5dev/gameui/IBrowser.cpp index 4439bccc..bf6dd7c2 100644 --- a/r5dev/gameui/IBrowser.cpp +++ b/r5dev/gameui/IBrowser.cpp @@ -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 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 l(g_pServerListManager->m_Mutex); + std::lock_guard 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 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 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 f(g_pServerListManager->m_Mutex); + std::lock_guard 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 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(); \ No newline at end of file +CBrowser g_Browser; \ No newline at end of file diff --git a/r5dev/gameui/IBrowser.h b/r5dev/gameui/IBrowser.h index 6bf195da..f03be79f 100644 --- a/r5dev/gameui/IBrowser.h +++ b/r5dev/gameui/IBrowser.h @@ -79,5 +79,5 @@ private: ImGuiStyle_t m_Style; }; -extern CBrowser* g_pBrowser; +extern CBrowser g_Browser; #endif \ No newline at end of file diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index f61fee30..58390b2f 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -1149,4 +1149,4 @@ void CConsole::SetStyleVar(void) ImGui::SetWindowPos(ImVec2(-1000, 50), ImGuiCond_FirstUseEver); } -CConsole* g_pConsole = new CConsole(); +CConsole g_Console; diff --git a/r5dev/gameui/IConsole.h b/r5dev/gameui/IConsole.h index 2d2ea343..a8b383ef 100644 --- a/r5dev/gameui/IConsole.h +++ b/r5dev/gameui/IConsole.h @@ -115,5 +115,5 @@ public: }; /////////////////////////////////////////////////////////////////////////////// -extern CConsole* g_pConsole; +extern CConsole g_Console; #endif // !DEDICATED diff --git a/r5dev/localize/localize.cpp b/r5dev/localize/localize.cpp index d75e7ad9..cae020eb 100644 --- a/r5dev/localize/localize.cpp +++ b/r5dev/localize/localize.cpp @@ -8,7 +8,7 @@ bool Localize_LoadLocalizationFileLists(CLocalize* thisptr) CLocalize__LoadLocalizationFileLists(thisptr); const CUtlVector& - modList = g_pModSystem->GetModList(); + modList = ModSystem()->GetModList(); FOR_EACH_VEC(modList, i) { diff --git a/r5dev/networksystem/bansystem.cpp b/r5dev/networksystem/bansystem.cpp index 748fea68..a91357e7 100644 --- a/r5dev/networksystem/bansystem.cpp +++ b/r5dev/networksystem/bansystem.cpp @@ -425,4 +425,4 @@ void CBanSystem::AuthorPlayerById(const char* playerHandle, const bool shouldBan } /////////////////////////////////////////////////////////////////////////////// -CBanSystem* g_pBanSystem = new CBanSystem(); +CBanSystem g_BanSystem; diff --git a/r5dev/networksystem/bansystem.h b/r5dev/networksystem/bansystem.h index aa0f6b3a..54390093 100644 --- a/r5dev/networksystem/bansystem.h +++ b/r5dev/networksystem/bansystem.h @@ -56,4 +56,4 @@ private: BannedList_t m_BannedList; }; -extern CBanSystem* g_pBanSystem; +extern CBanSystem g_BanSystem; diff --git a/r5dev/networksystem/listmanager.cpp b/r5dev/networksystem/listmanager.cpp index 951818d8..85b4a54f 100644 --- a/r5dev/networksystem/listmanager.cpp +++ b/r5dev/networksystem/listmanager.cpp @@ -35,7 +35,7 @@ CServerListManager::CServerListManager(void) size_t CServerListManager::RefreshServerList(string& svMessage) { ClearServerList(); - vector vServerList = g_pMasterServer->GetServerList(svMessage); + vector vServerList = g_MasterServer.GetServerList(svMessage); std::lock_guard 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(); \ No newline at end of file +CServerListManager g_ServerListManager; \ No newline at end of file diff --git a/r5dev/networksystem/listmanager.h b/r5dev/networksystem/listmanager.h index b6377682..dc2b0870 100644 --- a/r5dev/networksystem/listmanager.h +++ b/r5dev/networksystem/listmanager.h @@ -38,5 +38,5 @@ public: mutable std::mutex m_Mutex; }; -extern CServerListManager* g_pServerListManager; +extern CServerListManager g_ServerListManager; #endif // LISTMANAGER_H diff --git a/r5dev/networksystem/pylon.cpp b/r5dev/networksystem/pylon.cpp index a3bd7d66..ec807001 100644 --- a/r5dev/networksystem/pylon.cpp +++ b/r5dev/networksystem/pylon.cpp @@ -617,4 +617,4 @@ void CPylon::LogBody(const rapidjson::Document& responseJson) const } /////////////////////////////////////////////////////////////////////////////// -CPylon* g_pMasterServer(new CPylon()); +CPylon g_MasterServer; diff --git a/r5dev/networksystem/pylon.h b/r5dev/networksystem/pylon.h index aad96a3e..2f98f045 100644 --- a/r5dev/networksystem/pylon.h +++ b/r5dev/networksystem/pylon.h @@ -52,4 +52,4 @@ private: string m_HostIP; string m_Language; }; -extern CPylon* g_pMasterServer; +extern CPylon g_MasterServer; diff --git a/r5dev/pluginsystem/modsystem.cpp b/r5dev/pluginsystem/modsystem.cpp index 28ff2fcb..4fa65932 100644 --- a/r5dev/pluginsystem/modsystem.cpp +++ b/r5dev/pluginsystem/modsystem.cpp @@ -343,4 +343,4 @@ void CModSystem::ModInstance_t::ParseLocalizationFiles() } } -CModSystem* g_pModSystem = new CModSystem(); +CModSystem g_ModSystem; diff --git a/r5dev/pluginsystem/modsystem.h b/r5dev/pluginsystem/modsystem.h index 8fb3df9a..accc701a 100644 --- a/r5dev/pluginsystem/modsystem.h +++ b/r5dev/pluginsystem/modsystem.h @@ -76,4 +76,9 @@ private: CUtlVector m_ModList; }; -extern CModSystem* g_pModSystem; +extern CModSystem g_ModSystem; + +FORCEINLINE CModSystem* ModSystem() +{ + return &g_ModSystem; +} diff --git a/r5dev/pluginsystem/pluginsystem.cpp b/r5dev/pluginsystem/pluginsystem.cpp index 63196ecc..8f5b2e0a 100644 --- a/r5dev/pluginsystem/pluginsystem.cpp +++ b/r5dev/pluginsystem/pluginsystem.cpp @@ -209,4 +209,4 @@ void* CPluginSystem::HelpWithAnything(PluginHelpWithAnything_t* help) return nullptr; } -CPluginSystem* g_pPluginSystem = new CPluginSystem(); +CPluginSystem g_PluginSystem; diff --git a/r5dev/pluginsystem/pluginsystem.h b/r5dev/pluginsystem/pluginsystem.h index b5325f1e..6b60e848 100644 --- a/r5dev/pluginsystem/pluginsystem.h +++ b/r5dev/pluginsystem/pluginsystem.h @@ -130,11 +130,11 @@ public: private: CUtlVector 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. diff --git a/r5dev/vgui/vgui_baseui_interface.cpp b/r5dev/vgui/vgui_baseui_interface.cpp index 6ab13f79..6d9d6842 100644 --- a/r5dev/vgui/vgui_baseui_interface.cpp +++ b/r5dev/vgui/vgui_baseui_interface.cpp @@ -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; diff --git a/r5dev/vgui/vgui_debugpanel.cpp b/r5dev/vgui/vgui_debugpanel.cpp index 0882f17f..7825bccc 100644 --- a/r5dev/vgui/vgui_debugpanel.cpp +++ b/r5dev/vgui/vgui_debugpanel.cpp @@ -296,4 +296,4 @@ Color CTextOverlay::GetLogColorForType(const eDLL_T context) const } /////////////////////////////////////////////////////////////////////////////// -CTextOverlay* g_pOverlay = new CTextOverlay(); +CTextOverlay g_TextOverlay; diff --git a/r5dev/vgui/vgui_debugpanel.h b/r5dev/vgui/vgui_debugpanel.h index bab1e87f..72f7a1ba 100644 --- a/r5dev/vgui/vgui_debugpanel.h +++ b/r5dev/vgui/vgui_debugpanel.h @@ -50,4 +50,4 @@ public: }; /////////////////////////////////////////////////////////////////////////////// -extern CTextOverlay* g_pOverlay; +extern CTextOverlay g_TextOverlay; diff --git a/r5dev/vgui/vgui_fpspanel.cpp b/r5dev/vgui/vgui_fpspanel.cpp index c9308992..3152e85c 100644 --- a/r5dev/vgui/vgui_fpspanel.cpp +++ b/r5dev/vgui/vgui_fpspanel.cpp @@ -15,7 +15,7 @@ //----------------------------------------------------------------------------- ConVar* HCFPSPanel_Paint(void* thisptr) { - g_pOverlay->Update(); + g_TextOverlay.Update(); return CFPSPanel__Paint(thisptr); } diff --git a/r5dev/vpc/interfaces.cpp b/r5dev/vpc/interfaces.cpp index dfb2e205..c02a5bbb 100644 --- a/r5dev/vpc/interfaces.cpp +++ b/r5dev/vpc/interfaces.cpp @@ -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; diff --git a/r5dev/vpc/interfaces.h b/r5dev/vpc/interfaces.h index 3f43f1c4..92f0e281 100644 --- a/r5dev/vpc/interfaces.h +++ b/r5dev/vpc/interfaces.h @@ -55,7 +55,7 @@ public: virtual const char* GetVersion(void) const override; }; -extern CFactorySystem* g_pFactorySystem; +extern CFactorySystem g_FactorySystem; PLATFORM_INTERFACE IFactorySystem* GetFactorySystem(); /////////////////////////////////////////////////////////////////////////////// diff --git a/r5dev/vscript/languages/squirrel_re/vsquirrel.cpp b/r5dev/vscript/languages/squirrel_re/vsquirrel.cpp index 26244bff..416f563f 100644 --- a/r5dev/vscript/languages/squirrel_re/vsquirrel.cpp +++ b/r5dev/vscript/languages/squirrel_re/vsquirrel.cpp @@ -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; diff --git a/r5dev/windows/id3dx.cpp b/r5dev/windows/id3dx.cpp index a9d261fb..e8e8542e 100644 --- a/r5dev/windows/id3dx.cpp +++ b/r5dev/windows/id3dx.cpp @@ -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; }