From dee3a2b3cf758e008c339d9f6e45e1f091be0790 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 7 Apr 2007 03:58:20 +0000 Subject: [PATCH] added some levelchange functions to SMGlobalClass to get rid of some messy crap --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40679 --- core/AdminCache.cpp | 6 ++++++ core/AdminCache.h | 1 + core/Logger.cpp | 5 +++++ core/Logger.h | 1 + core/TimerSys.cpp | 5 +++++ core/TimerSys.h | 1 + core/Translator.cpp | 8 ++++++++ core/Translator.h | 1 + core/sm_globals.h | 14 ++++++++++++++ core/sourcemod.cpp | 23 ++++++++++++++--------- 10 files changed, 56 insertions(+), 9 deletions(-) diff --git a/core/AdminCache.cpp b/core/AdminCache.cpp index 666164db..e5ddaa75 100644 --- a/core/AdminCache.cpp +++ b/core/AdminCache.cpp @@ -84,6 +84,12 @@ void AdminCache::OnSourceModShutdown() m_pCacheFwd = NULL; } +void AdminCache::OnSourceModPluginsLoaded() +{ + DumpAdminCache(AdminCache_Overrides, true); + DumpAdminCache(AdminCache_Groups, true); +} + void AdminCache::AddCommandOverride(const char *cmd, OverrideType type, FlagBits flags) { Trie *pTrie = NULL; diff --git a/core/AdminCache.h b/core/AdminCache.h index eb40a5cf..e75e653d 100644 --- a/core/AdminCache.h +++ b/core/AdminCache.h @@ -88,6 +88,7 @@ public: //SMGlobalClass void OnSourceModStartup(bool late); void OnSourceModAllInitialized(); void OnSourceModShutdown(); + void OnSourceModPluginsLoaded(); public: //IAdminSystem /** Command cache stuff */ void AddCommandOverride(const char *cmd, OverrideType type, FlagBits flags); diff --git a/core/Logger.cpp b/core/Logger.cpp index 1af6a9a7..5ffea1c4 100644 --- a/core/Logger.cpp +++ b/core/Logger.cpp @@ -83,6 +83,11 @@ void Logger::OnSourceModAllShutdown() CloseLogger(); } +void Logger::OnSourceModLevelChange(const char *mapName) +{ + MapChange(mapName); +} + void Logger::_NewMapFile() { if (!m_Active) diff --git a/core/Logger.h b/core/Logger.h index b469c71b..30246296 100644 --- a/core/Logger.h +++ b/core/Logger.h @@ -49,6 +49,7 @@ public: //SMGlobalClass size_t maxlength); void OnSourceModStartup(bool late); void OnSourceModAllShutdown(); + void OnSourceModLevelChange(const char *mapName); public: void InitLogger(LoggingMode mode); void CloseLogger(); diff --git a/core/TimerSys.cpp b/core/TimerSys.cpp index 1b35b410..3ce7839d 100644 --- a/core/TimerSys.cpp +++ b/core/TimerSys.cpp @@ -42,6 +42,11 @@ void TimerSystem::OnSourceModAllInitialized() g_ShareSys.AddInterface(NULL, this); } +void TimerSystem::OnSourceModLevelChange(const char *mapName) +{ + MapChange(); +} + void TimerSystem::RunFrame() { ITimer *pTimer; diff --git a/core/TimerSys.h b/core/TimerSys.h index 0da497ce..4078b6a3 100644 --- a/core/TimerSys.h +++ b/core/TimerSys.h @@ -48,6 +48,7 @@ public: ~TimerSystem(); public: //SMGlobalClass void OnSourceModAllInitialized(); + void OnSourceModLevelChange(const char *mapName); public: //ITimerSystem ITimer *CreateTimer(ITimedEvent *pCallbacks, float fInterval, void *pData, int flags); void KillTimer(ITimer *pTimer); diff --git a/core/Translator.cpp b/core/Translator.cpp index 022b0b04..52070e8a 100644 --- a/core/Translator.cpp +++ b/core/Translator.cpp @@ -632,6 +632,14 @@ ConfigResult Translator::OnSourceModConfigChanged(const char *key, return ConfigResult_Ignore; } +void Translator::OnSourceModLevelChange(const char *mapName) +{ + /* Refresh language stuff */ + char path[PLATFORM_MAX_PATH]; + g_SourceMod.BuildPath(Path_SM, path, sizeof(path), "configs/languages.cfg"); + RebuildLanguageDatabase(path); +} + void Translator::OnSourceModAllInitialized() { AddLanguage("en", "English"); diff --git a/core/Translator.h b/core/Translator.h index 92cf610f..63498f62 100644 --- a/core/Translator.h +++ b/core/Translator.h @@ -108,6 +108,7 @@ public: // SMGlobalClass char *error, size_t maxlength); void OnSourceModAllInitialized(); + void OnSourceModLevelChange(const char *mapName); public: // ITextListener_SMC void ReadSMC_ParseStart(); SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes); diff --git a/core/sm_globals.h b/core/sm_globals.h index 2a2b312b..6636fbe1 100644 --- a/core/sm_globals.h +++ b/core/sm_globals.h @@ -97,6 +97,20 @@ public: { return ConfigResult_Ignore; } + + /** + * @brief Called when the level changes. + */ + virtual void OnSourceModLevelChange(const char *mapName) + { + } + + /** + * @brief Called after plugins are loaded on mapchange. + */ + virtual void OnSourceModPluginsLoaded() + { + } private: SMGlobalClass *m_pGlobalClassNext; static SMGlobalClass *head; diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index 10f8ef5c..b1dda3d9 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -233,20 +233,25 @@ bool SourceModBase::LevelInit(char const *pMapName, char const *pMapEntities, ch g_LastTime = 0.0f; g_LastAuthCheck = 0.0f; - g_Logger.MapChange(pMapName); - g_Timers.MapChange(); - - /* Refresh language stuff */ - char path[PLATFORM_MAX_PATH]; - BuildPath(Path_SM, path, sizeof(path), "configs/languages.cfg"); - g_Translator.RebuildLanguageDatabase(path); + /* Notify! */ + SMGlobalClass *pBase = SMGlobalClass::head; + while (pBase) + { + pBase->OnSourceModLevelChange(pMapName); + pBase = pBase->m_pGlobalClassNext; + } DoGlobalPluginLoads(); m_IsMapLoading = false; - g_Admins.DumpAdminCache(AdminCache_Overrides, true); - g_Admins.DumpAdminCache(AdminCache_Groups, true); + /* Notify! */ + pBase = SMGlobalClass::head; + while (pBase) + { + pBase->OnSourceModPluginsLoaded(); + pBase = pBase->m_pGlobalClassNext; + } if (!g_pOnGameFrame) {