Skip to content

Commit 8890b94

Browse files
committed
Refactor and improve deathmatch loading
1 parent a744cd1 commit 8890b94

13 files changed

+239
-398
lines changed

Client/cefweb/CWebCore.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ std::unordered_set<SString> CWebCore::AllowPendingPages(bool bRemember)
409409
}
410410

411411
// Trigger an event now
412-
auto pCurrentMod = g_pCore->GetModManager()->GetCurrentMod();
412+
auto pCurrentMod = g_pCore->GetModManager()->GetClient();
413413
if (!pCurrentMod)
414414
return std::unordered_set<SString>();
415415

Client/core/CChat.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,11 +699,11 @@ bool CChat::CharacterKeyHandler(CGUIKeyEventArgs KeyboardArgs)
699699
SString strPlayerNamePart = strCurrentInput.substr(iFound);
700700

701701
CModManager* pModManager = CModManager::GetSingletonPtr();
702-
if (pModManager && pModManager->GetCurrentMod())
702+
if (pModManager && pModManager->IsLoaded())
703703
{
704704
// Create vector and get playernames from deathmatch module
705705
std::vector<SString> vPlayerNames;
706-
pModManager->GetCurrentMod()->GetPlayerNames(vPlayerNames);
706+
pModManager->GetClient()->GetPlayerNames(vPlayerNames);
707707

708708
for (std::vector<SString>::iterator iter = vPlayerNames.begin(); iter != vPlayerNames.end(); ++iter)
709709
{

Client/core/CCommandFuncs.cpp

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -167,36 +167,13 @@ void CCommandFuncs::Clear(const char* szParameters)
167167

168168
void CCommandFuncs::Load(const char* szParameters)
169169
{
170-
if (!szParameters)
171-
{
172-
CCore::GetSingleton().GetConsole()->Printf("* Syntax: load <mod-name> [<arguments>]");
173-
return;
174-
}
175-
176-
// Copy the buffer
177-
char* szTemp = new char[strlen(szParameters) + 1];
178-
strcpy(szTemp, szParameters);
179-
180-
// Split it up into mod name and the arguments
181-
char* szModName = strtok(szTemp, " ");
182-
char* szArguments = strtok(NULL, "\0");
183-
184-
if (szModName)
185-
{
186-
// Load the mod with the given arguments
187-
CModManager::GetSingleton().RequestLoad(szModName, szArguments);
188-
}
189-
else
190-
CCore::GetSingleton().GetConsole()->Printf("* Syntax: load <mod-name> [<arguments>]");
191-
192-
// Free the temp buffer
193-
delete[] szTemp;
170+
CModManager::GetSingleton().RequestLoad(szParameters);
194171
}
195172

196173
void CCommandFuncs::Unload(const char* szParameters)
197174
{
198175
// Any mod loaded?
199-
if (CModManager::GetSingleton().GetCurrentMod())
176+
if (CModManager::GetSingleton().IsLoaded())
200177
{
201178
// Unload it
202179
CModManager::GetSingleton().RequestUnload();
@@ -264,7 +241,7 @@ void CCommandFuncs::Connect(const char* szParameters)
264241
CModManager::GetSingleton().Unload();
265242

266243
// Only connect if there is no mod loaded
267-
if (!CModManager::GetSingleton().GetCurrentMod())
244+
if (!CModManager::GetSingleton().IsLoaded())
268245
{
269246
// Start the connect
270247
if (CCore::GetSingleton().GetConnectManager()->Connect(szHost, usPort, strNick.c_str(), szPass))
@@ -284,7 +261,7 @@ void CCommandFuncs::Connect(const char* szParameters)
284261

285262
void CCommandFuncs::ReloadNews(const char* szParameters)
286263
{
287-
if (CModManager::GetSingleton().GetCurrentMod())
264+
if (CModManager::GetSingleton().IsLoaded())
288265
{
289266
CCore::GetSingleton().GetConsole()->Print("reloadnews: can't do this whilst connected to server");
290267
return;
@@ -309,7 +286,7 @@ void CCommandFuncs::Reconnect(const char* szParameters)
309286
CModManager::GetSingleton().Unload();
310287

311288
// Any mod loaded?
312-
if (!CModManager::GetSingleton().GetCurrentMod())
289+
if (!CModManager::GetSingleton().IsLoaded())
313290
{
314291
// Verify and convert the port number
315292
if (uiPort <= 0 || uiPort > 0xFFFF)

Client/core/CConnectManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ bool CConnectManager::StaticProcessPacket(unsigned char ucPacketID, NetBitStream
364364
// Process packet data
365365
CCore::GetSingleton().GetNetwork()->SetServerBitStreamVersion(usServerBitStreamVersion);
366366

367-
if (strModName != "")
367+
if (strModName == "deathmatch")
368368
{
369369
// Populate the arguments to pass it (-c host port nick)
370370
SString strArguments("%s %s", g_pConnectManager->m_strNick.c_str(), g_pConnectManager->m_strPassword.c_str());
@@ -399,7 +399,7 @@ bool CConnectManager::StaticProcessPacket(unsigned char ucPacketID, NetBitStream
399399
g_pConnectManager->m_tConnectStarted = 0;
400400

401401
// Load the mod
402-
if (!CModManager::GetSingleton().Load(strModName, strArguments))
402+
if (!CModManager::GetSingleton().Load(strArguments))
403403
{
404404
// Failed loading the mod
405405
strArguments.Format(_("No such mod installed (%s)"), strModName.c_str());

Client/core/CCore.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ void CCore::EnableChatInput(char* szCommand, DWORD dwColor)
515515
{
516516
if (m_pLocalGUI)
517517
{
518-
if (m_pGame->GetSystemState() == 9 /* GS_PLAYING_GAME */ && m_pModManager->GetCurrentMod() != NULL && !IsOfflineMod() && !m_pGame->IsAtMenu() &&
518+
if (m_pGame->GetSystemState() == 9 /* GS_PLAYING_GAME */ && m_pModManager->IsLoaded() && !IsOfflineMod() && !m_pGame->IsAtMenu() &&
519519
!m_pLocalGUI->GetMainMenu()->IsVisible() && !m_pLocalGUI->GetConsole()->IsVisible() && !m_pLocalGUI->IsChatBoxInputEnabled())
520520
{
521521
CChat* pChat = m_pLocalGUI->GetChat();
@@ -1262,17 +1262,7 @@ void CCore::DoPostFramePulse()
12621262
{
12631263
// We want to load a mod?
12641264
const char* szOptionValue;
1265-
if (szOptionValue = GetCommandLineOption("l"))
1266-
{
1267-
// Try to load the mod
1268-
if (!m_pModManager->Load(szOptionValue, m_szCommandLineArgs))
1269-
{
1270-
SString strTemp(_("Error running mod specified in command line ('%s')"), szOptionValue);
1271-
ShowMessageBox(_("Error") + _E("CC42"), strTemp, MB_BUTTON_OK | MB_ICON_ERROR); // Command line Mod load failed
1272-
}
1273-
}
1274-
// We want to connect to a server?
1275-
else if (szOptionValue = GetCommandLineOption("c"))
1265+
if (szOptionValue = GetCommandLineOption("c"))
12761266
{
12771267
CCommandFuncs::Connect(szOptionValue);
12781268
}
@@ -2195,8 +2185,9 @@ void CCore::HandleIdlePulse()
21952185
DoPreFramePulse();
21962186
DoPostFramePulse();
21972187
}
2198-
if (m_pModManager->GetCurrentMod())
2199-
m_pModManager->GetCurrentMod()->IdleHandler();
2188+
2189+
if (m_pModManager->IsLoaded())
2190+
m_pModManager->GetClient()->IdleHandler();
22002191
}
22012192

22022193
//

Client/core/CCrashDumpWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ long WINAPI CCrashDumpWriter::HandleExceptionGlobal(_EXCEPTION_POINTERS* pExcept
194194
if (pModManager)
195195
{
196196
// Got a client?
197-
if (pModManager->GetCurrentMod())
197+
if (pModManager->IsLoaded())
198198
{
199199
// Protect us from "double-faults"
200200
try
201201
{
202202
// Let the client handle it. If it could, continue the execution
203-
if (pModManager->GetCurrentMod()->HandleException(pExceptionInformation))
203+
if (pModManager->GetClient()->HandleException(pExceptionInformation))
204204
{
205205
// Delete the exception record and continue to search the exception stack
206206
delete pExceptionInformation;

Client/core/CMainMenu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ bool CMainMenu::OnHostGameButtonClick()
944944
return false;
945945

946946
// Load deathmatch, but with local play
947-
CModManager::GetSingleton().RequestLoad("deathmatch", "local");
947+
CModManager::GetSingleton().RequestLoad("local");
948948

949949
return true;
950950
}
@@ -956,7 +956,7 @@ bool CMainMenu::OnEditorButtonClick()
956956
return false;
957957

958958
// Load deathmatch, but with local play
959-
CModManager::GetSingleton().RequestLoad("deathmatch", "editor");
959+
CModManager::GetSingleton().RequestLoad("editor");
960960

961961
return true;
962962
}

Client/core/CMessageLoopHook.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,8 @@ LRESULT CALLBACK CMessageLoopHook::ProcessMessage(HWND hwnd, UINT uMsg, WPARAM w
131131

132132
if (pModManager && pModManager->IsLoaded())
133133
{
134-
CClientBase* pBase = pModManager->GetCurrentMod();
135-
136-
if (pBase)
137-
{
138-
bool bFocus = (wState == WA_CLICKACTIVE) || (wState == WA_ACTIVE);
139-
pBase->OnWindowFocusChange(bFocus);
140-
}
134+
bool bFocus = (wState == WA_CLICKACTIVE) || (wState == WA_ACTIVE);
135+
pModManager->GetClient()->OnWindowFocusChange(bFocus);
141136
}
142137

143138
switch (wState)

0 commit comments

Comments
 (0)