From b96533a52fffa969c20cd91ab9b1bee97e191ee5 Mon Sep 17 00:00:00 2001 From: Foereaper Date: Mon, 15 Jan 2024 19:20:19 +0100 Subject: [PATCH] Add compatibility mode (single threaded) This should work like stock Eluna --- src/server/game/LuaEngine | 2 +- src/server/game/Maps/Map.cpp | 13 ++++++++- src/server/game/Maps/Map.h | 2 +- src/server/game/Maps/MapManager.cpp | 10 +++++++ src/server/game/Scripting/ScriptMgr.cpp | 5 +++- src/server/game/World/World.cpp | 11 ++++---- src/server/worldserver/worldserver.conf.dist | 28 +++++++++++--------- 7 files changed, 49 insertions(+), 22 deletions(-) diff --git a/src/server/game/LuaEngine b/src/server/game/LuaEngine index bbf3e41056..1292ba993d 160000 --- a/src/server/game/LuaEngine +++ b/src/server/game/LuaEngine @@ -1 +1 @@ -Subproject commit bbf3e41056c278f1bfb947b9054af0d2ed5bd8fd +Subproject commit 1292ba993df1c192b52816e68b2491534bc36d8c diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 746aaf1458..e945c716b5 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -18,6 +18,7 @@ #include "Map.h" #include "Battleground.h" #include "CellImpl.h" +#include "Config.h" #include "DatabaseEnv.h" #include "DisableMgr.h" #include "DynamicTree.h" @@ -299,7 +300,8 @@ i_scriptLock(false), _respawnTimes(std::make_unique()), _r // lua state begins uninitialized eluna = nullptr; - if (sElunaLoader->ShouldMapLoadEluna(id)) + bool compatMode = sConfigMgr->GetBoolDefault("Eluna.CompatibilityMode", true); + if (sElunaLoader->ShouldMapLoadEluna(id) && !compatMode) if (!IsParentMap() || (IsParentMap() && !Instanceable())) eluna = new Eluna(id); #endif @@ -4901,4 +4903,13 @@ std::string InstanceMap::GetDebugInfo() const return sstr.str(); } +Eluna *Map::GetEluna() const +{ + bool compatMode = sConfigMgr->GetBoolDefault("Eluna.CompatibilityMode", true); + if(compatMode) + return sWorld->GetEluna(); + + return eluna; +} + template class TC_GAME_API TypeUnorderedMapContainer; diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index 909dbf4be7..2216ccbc78 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -823,7 +823,7 @@ class TC_GAME_API Map : public GridRefManager void AddFarSpellCallback(FarSpellCallback&& callback); bool IsParentMap() const { return GetParent() == this; } #ifdef ELUNA - Eluna* GetEluna() const { return eluna; } + Eluna* GetEluna() const; LuaVal lua_data = LuaVal({}); #endif diff --git a/src/server/game/Maps/MapManager.cpp b/src/server/game/Maps/MapManager.cpp index a47729cf26..0d82087970 100644 --- a/src/server/game/Maps/MapManager.cpp +++ b/src/server/game/Maps/MapManager.cpp @@ -17,6 +17,7 @@ #include "MapManager.h" #include "InstanceSaveMgr.h" +#include "Config.h" #include "DatabaseEnv.h" #include "Log.h" #include "ObjectAccessor.h" @@ -51,6 +52,15 @@ void MapManager::Initialize() Map::InitStateMachine(); int num_threads(sWorld->getIntConfig(CONFIG_NUMTHREADS)); +#if ELUNA + bool compatMode = sConfigMgr->GetBoolDefault("Eluna.CompatibilityMode", true); + if (compatMode && num_threads > 1) + { + // Force 1 thread for Eluna if compatibility mode is enabled. Compatibility mode is single state and does not allow more update threads. + TC_LOG_ERROR("maps", "Map update threads set to {}, when Eluna in compatibility mode only allows 1, changing to 1", num_threads); + num_threads = 1; + } +#endif // Start mtmaps if needed. if (num_threads > 0) diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index ad70206fee..5a5e3a8168 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -1551,7 +1551,10 @@ void ScriptMgr::OnMapUpdate(Map* map, uint32 diff) #ifdef ELUNA if (Eluna* e = map->GetEluna()) { - e->UpdateEluna(diff); + bool compatMode = sConfigMgr->GetBoolDefault("Eluna.CompatibilityMode", true); + if(!compatMode) + e->UpdateEluna(diff); + e->OnUpdate(map, diff); } #endif diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index e6f4aaeea7..5378e65fea 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -1608,10 +1608,6 @@ void World::SetInitialWorldSettings() ///- Initialize Lua Engine TC_LOG_INFO("server.loading", "Loading Lua scripts..."); sElunaLoader->LoadScripts(); - - TC_LOG_INFO("server.loading", "Starting Eluna world state..."); - // use map id -1 for the global Eluna state - eluna = new Eluna(-1); #endif ///- Initialize pool manager @@ -2098,6 +2094,12 @@ void World::SetInitialWorldSettings() TC_LOG_INFO("server.loading", "Loading Creature Text Locales..."); sCreatureTextMgr->LoadCreatureTextLocales(); +#ifdef ELUNA + TC_LOG_INFO("server.loading", "Starting Eluna world state..."); + // use map id -1 for the global Eluna state + eluna = new Eluna(-1); +#endif + TC_LOG_INFO("server.loading", "Initializing Scripts..."); sScriptMgr->Initialize(); sScriptMgr->OnConfigLoad(false); // must be done after the ScriptMgr has been properly initialized @@ -2234,7 +2236,6 @@ void World::SetInitialWorldSettings() #ifdef ELUNA eluna->OnConfigLoad(false); // Must be done after Eluna is initialized and scripts have run. - sElunaLoader->PreloadElunaMaps(); #endif // Preload all cells, if required for the base maps diff --git a/src/server/worldserver/worldserver.conf.dist b/src/server/worldserver/worldserver.conf.dist index d53072b98c..58ca194a57 100644 --- a/src/server/worldserver/worldserver.conf.dist +++ b/src/server/worldserver/worldserver.conf.dist @@ -3867,34 +3867,36 @@ AuctionHouseBot.Buyer.Recheck.Interval = 20 # # Eluna.Enabled # Description: Enable or disable Eluna LuaEngine -# Default: true - (enabled) -# false - (disabled) +# Default: true - (enabled) +# false - (disabled) +# +# Eluna.CompatibilityMode +# Description: Toggles Eluna between compatibility mode (single-threaded) or multistate mode. +# Compatibility mode limits the core to a single map update thread. +# Default: true - (enabled) +# false - (disabled) # # Eluna.OnlyOnMaps # Description: When Eluna is enabled, a state will only be created for a list of specified maps -# Default: "" - (enabled on all maps) -# "0,1,2,..." - (enabled on specific maps only) -# -# Eluna.PreloadOnlyOnMaps -# Description: When Eluna is enabled, the parent map for every map listed in Eluna.OnlyOnMaps will be created during World loading. -# Default: false - (not enabled) -# true - (enabled) +# This only works for multistate mode. +# Default: "" - (enabled on all maps) +# "0,1,2,..." - (enabled on specific maps only) # # Eluna.TraceBack # Description: Sets whether to use debug.traceback function on a lua error or not. # Notice that you can redefine the function. -# Default: false - (use default error output) -# true - (use debug.traceback function) +# Default: false - (use default error output) +# true - (use debug.traceback function) # # Eluna.ScriptPath # Description: Sets the location of the script folder to load scripts from # The path can be relative or absolute. -# Default: "lua_scripts" +# Default: "lua_scripts" # Eluna.Enabled = true +Eluna.CompatibilityMode = true Eluna.OnlyOnMaps = "" -Eluna.PreloadOnlyOnMaps = false Eluna.TraceBack = false Eluna.ScriptPath = "lua_scripts"