Skip to content

Commit

Permalink
Merge pull request #3 from Foereaper/multistate-merge
Browse files Browse the repository at this point in the history
Switch to ElunaConfig instead of native config loading
  • Loading branch information
Niam5 authored Jan 29, 2024
2 parents d9986e9 + bacbcaf commit 272eac1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/game/Entities/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "MotionGenerators/PathFinder.h"
#ifdef BUILD_ELUNA
#include "LuaEngine/LuaEngine.h"
#include "LuaEngine/ElunaConfig.h"
#include "LuaEngine/ElunaEventMgr.h"
#endif

Expand Down Expand Up @@ -1983,8 +1984,7 @@ void WorldObject::SetMap(Map* map)

// if multistate, delete elunaEvents and set to nullptr. events shouldn't move across states.
// in single state, the timed events should move across maps
bool compatMode = sWorld.getConfig(CONFIG_BOOL_ELUNA_COMPATIBILITY);
if (!compatMode)
if (!sElunaConfig->IsElunaCompatibilityMode())
{
delete elunaEvents;
elunaEvents = nullptr; // set to null in case map doesn't use eluna
Expand Down
21 changes: 8 additions & 13 deletions src/game/Maps/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "AI/ScriptDevAI/ScriptDevAIMgr.h"
#ifdef BUILD_ELUNA
#include "LuaEngine/LuaEngine.h"
#include "LuaEngine/ElunaConfig.h"
#include "LuaEngine/ElunaLoader.h"
#endif

Expand Down Expand Up @@ -176,16 +177,12 @@ Map::Map(uint32 id, time_t expiry, uint32 InstanceId)
#ifdef BUILD_ELUNA
// lua state begins uninitialized
eluna = nullptr;
bool elunaEnabled = sWorld.getConfig(CONFIG_BOOL_ELUNA_ENABLED);
if (elunaEnabled)
{
bool compatMode = sWorld.getConfig(CONFIG_BOOL_ELUNA_COMPATIBILITY);
if (sElunaLoader->ShouldMapLoadEluna(id) && !compatMode)
eluna = new Eluna(this);

if (Eluna* e = GetEluna())
e->OnCreate(this);
}
if (sElunaConfig->IsElunaEnabled() && !sElunaConfig->IsElunaCompatibilityMode() && sElunaLoader->ShouldMapLoadEluna(id))
eluna = new Eluna(this);

if (Eluna* e = GetEluna())
e->OnCreate(this);
#endif
}

Expand Down Expand Up @@ -949,8 +946,7 @@ void Map::Update(const uint32& t_diff)
#ifdef BUILD_ELUNA
if (Eluna* e = GetEluna())
{
bool compatMode = sWorld.getConfig(CONFIG_BOOL_ELUNA_COMPATIBILITY);
if (!compatMode)
if (!sElunaConfig->IsElunaCompatibilityMode())
e->UpdateEluna(t_diff);

e->OnUpdate(this, t_diff);
Expand Down Expand Up @@ -2961,8 +2957,7 @@ void Map::RemoveFromSpawnCount(const ObjectGuid& guid)
#ifdef BUILD_ELUNA
Eluna* Map::GetEluna() const
{
bool compatMode = sWorld.getConfig(CONFIG_BOOL_ELUNA_COMPATIBILITY);
if (compatMode)
if (sElunaConfig->IsElunaCompatibilityMode())
return sWorld.GetEluna();

return eluna;
Expand Down
9 changes: 7 additions & 2 deletions src/game/Maps/MapManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#include "Maps/MapWorkers.h"
#include <future>

#ifdef BUILD_ELUNA
#include "LuaEngine/ElunaConfig.h"
#endif

#define CLASS_LOCK MaNGOS::ClassLevelLockable<MapManager, std::recursive_mutex>
INSTANTIATE_SINGLETON_2(MapManager, CLASS_LOCK);
INSTANTIATE_CLASS_MUTEX(MapManager, std::recursive_mutex);
Expand All @@ -55,13 +59,14 @@ void MapManager::Initialize()

int num_threads(sWorld.getConfig(CONFIG_UINT32_NUM_MAP_THREADS));

bool compatMode = sWorld.getConfig(CONFIG_BOOL_ELUNA_COMPATIBILITY);
if (compatMode && num_threads > 1)
#ifdef BUILD_ELUNA
if (sElunaConfig->IsElunaEnabled() && sElunaConfig->IsElunaCompatibilityMode() && 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.
sLog.outError("Map update threads set to %i, when Eluna in compatibility mode only allows 1, changing to 1", num_threads);
num_threads = 1;
}
#endif

if (num_threads > 0)
m_updater.activate(num_threads);
Expand Down
32 changes: 16 additions & 16 deletions src/game/World/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

#ifdef BUILD_ELUNA
#include "LuaEngine/LuaEngine.h"
#include "LuaEngine/ElunaConfig.h"
#include "LuaEngine/ElunaLoader.h"
#endif

Expand Down Expand Up @@ -823,10 +824,8 @@ void World::LoadConfigSettings(bool reload)
setConfig(CONFIG_BOOL_PATH_FIND_NORMALIZE_Z, "PathFinder.NormalizeZ", false);

#ifdef BUILD_ELUNA
setConfig(CONFIG_BOOL_ELUNA_ENABLED, "Eluna.Enabled", true);
setConfig(CONFIG_BOOL_ELUNA_COMPATIBILITY, "Eluna.CompatibilityMode", true);
if (eluna && reload)
eluna->OnConfigLoad(reload);
if (Eluna* e = GetEluna())
e->OnConfigLoad(reload);
#endif

#ifdef BUILD_SOLOCRAFT
Expand Down Expand Up @@ -1007,8 +1006,10 @@ void World::SetInitialWorldSettings()
sLog.outString();

#ifdef BUILD_ELUNA
bool elunaEnabled = sWorld.getConfig(CONFIG_BOOL_ELUNA_ENABLED);
if (elunaEnabled)
sLog.outString("Loading Eluna config...");
sElunaConfig->Initialize();

if (sElunaConfig->IsElunaEnabled())
{
///- Initialize Lua Engine
sLog.outString("Loading Lua scripts...");
Expand Down Expand Up @@ -1499,13 +1500,12 @@ void World::SetInitialWorldSettings()
// lua state begins uninitialized
eluna = nullptr;

if (elunaEnabled)
if (sElunaConfig->IsElunaEnabled())
{
///- Run eluna scripts.
sLog.outString("Starting Eluna world state...");
// use map id -1 for the global Eluna state
bool compatMode = sWorld.getConfig(CONFIG_BOOL_ELUNA_COMPATIBILITY);
eluna = new Eluna(nullptr, compatMode);
eluna = new Eluna(nullptr, sElunaConfig->IsElunaCompatibilityMode());

eluna->OnConfigLoad(false); // Must be done after Eluna is initialized and scripts have run
sLog.outString();
Expand Down Expand Up @@ -1656,10 +1656,10 @@ void World::Update(uint32 diff)

#ifdef BUILD_ELUNA
///- used by eluna
if (eluna)
if (Eluna* e = GetEluna())
{
eluna->UpdateEluna(diff);
eluna->OnWorldUpdate(diff);
e->UpdateEluna(diff);
e->OnWorldUpdate(diff);
}
#endif
///- Update groups with offline leaders
Expand Down Expand Up @@ -2143,8 +2143,8 @@ void World::ShutdownServ(uint32 time, uint32 options, uint8 exitcode)
}
#ifdef BUILD_ELUNA
///- Used by Eluna
if (eluna)
eluna->OnShutdownInitiate(ShutdownExitCode(exitcode), ShutdownMask(options));
if (Eluna* e = GetEluna())
e->OnShutdownInitiate(ShutdownExitCode(exitcode), ShutdownMask(options));
#endif
}

Expand Down Expand Up @@ -2191,8 +2191,8 @@ void World::ShutdownCancel()

#ifdef BUILD_ELUNA
///- Used by Eluna
if (eluna)
eluna->OnShutdownCancel();
if (Eluna* e = GetEluna())
e->OnShutdownCancel();
#endif
}

Expand Down
4 changes: 0 additions & 4 deletions src/game/World/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,6 @@ enum eConfigBoolValues
CONFIG_BOOL_PET_ATTACK_FROM_BEHIND,
CONFIG_BOOL_AUTO_DOWNRANK,
CONFIG_BOOL_MMAP_ENABLED,
#ifdef BUILD_ELUNA
CONFIG_BOOL_ELUNA_ENABLED,
CONFIG_BOOL_ELUNA_COMPATIBILITY,
#endif
#ifdef BUILD_SOLOCRAFT
CONFIG_BOOL_SOLOCRAFT_ENABLED,
CONFIG_BOOL_SOLOCRAFT_ANNOUNCE,
Expand Down

0 comments on commit 272eac1

Please sign in to comment.