Skip to content

Commit

Permalink
Add compatibility mode (single threaded)
Browse files Browse the repository at this point in the history
This should work like stock Eluna
  • Loading branch information
Foereaper committed Jan 15, 2024
1 parent cfa7a98 commit b96533a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/server/game/LuaEngine
Submodule LuaEngine updated 2 files
+0 −15 ElunaLoader.cpp
+0 −2 ElunaLoader.h
13 changes: 12 additions & 1 deletion src/server/game/Maps/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -299,7 +300,8 @@ i_scriptLock(false), _respawnTimes(std::make_unique<RespawnListContainer>()), _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
Expand Down Expand Up @@ -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<AllMapStoredObjectTypes, ObjectGuid>;
2 changes: 1 addition & 1 deletion src/server/game/Maps/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
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
Expand Down
10 changes: 10 additions & 0 deletions src/server/game/Maps/MapManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "MapManager.h"
#include "InstanceSaveMgr.h"
#include "Config.h"
#include "DatabaseEnv.h"
#include "Log.h"
#include "ObjectAccessor.h"
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/server/game/Scripting/ScriptMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/server/game/World/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
28 changes: 15 additions & 13 deletions src/server/worldserver/worldserver.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit b96533a

Please sign in to comment.