Skip to content

Commit

Permalink
Eluna: Switch eluna event processor to unique pointers
Browse files Browse the repository at this point in the history
Co-Authored-By: Foe <Foereaper@users.noreply.github.com>
  • Loading branch information
Niam5 and Foereaper committed Feb 25, 2025
1 parent f157f97 commit 0c69ffd
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 45 deletions.
27 changes: 5 additions & 22 deletions src/game/Entities/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,24 +1272,13 @@ bool WorldObject::HasStringId(uint32 stringId) const
}

WorldObject::WorldObject() :
#ifdef BUILD_ELUNA
elunaEvents(nullptr),
#endif
m_transport(nullptr), m_transportInfo(nullptr), m_isOnEventNotified(false),
m_visibilityData(this), m_currMap(nullptr),
m_mapId(0), m_InstanceId(0), m_phaseMask(1),
m_isActiveObject(false), m_debugFlags(0), m_castCounter(0)
{
}

#ifdef BUILD_ELUNA
WorldObject::~WorldObject()
{
delete elunaEvents;
elunaEvents = nullptr;
}
#endif

void WorldObject::CleanupsBeforeDelete()
{
m_events.KillAllEvents(false); // non-delatable (currently casted spells) will not deleted now but it will deleted at call in Map::RemoveAllObjectsInRemoveList
Expand Down Expand Up @@ -2103,9 +2092,13 @@ void WorldObject::AddToWorld()
Object::AddToWorld();

#ifdef BUILD_ELUNA
// in multistate mode, always reset in case Eluna is not active on the new map
if (elunaEvents && !sElunaConfig->IsElunaCompatibilityMode())
elunaEvents.reset();

if (Eluna* e = GetEluna())
if (!elunaEvents)
elunaEvents = new ElunaEventProcessor(e, this);
elunaEvents = std::make_unique<ElunaEventProcessor>(e, this);
#endif
}

Expand All @@ -2121,16 +2114,6 @@ void WorldObject::RemoveFromWorld()
m_currMap->RemoveStringIdObject(stringId, this);
}

#ifdef BUILD_ELUNA
// if multistate, delete elunaEvents and set to nullptr. events shouldn't move across states.
// in single state, the timed events should move across maps
if (!sElunaConfig->IsElunaCompatibilityMode())
{
delete elunaEvents;
elunaEvents = nullptr; // set to null in case map doesn't use eluna
}
#endif

Object::RemoveFromWorld();
}

Expand Down
11 changes: 5 additions & 6 deletions src/game/Entities/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "Utilities/EventProcessor.h"
#ifdef BUILD_ELUNA
#include "LuaEngine/LuaValue.h"
#include "LuaEngine/ElunaEventMgr.h"
#endif

#include <set>
Expand Down Expand Up @@ -916,14 +917,12 @@ class WorldObject : public Object
friend struct WorldObjectChangeAccumulator;

public:
virtual ~WorldObject() {}

virtual void Update(const uint32 /*diff*/);
virtual void Heartbeat() {}
virtual uint32 GetHeartbeatDuration() const { return 5000; }
#ifdef BUILD_ELUNA
virtual ~WorldObject();
#else
virtual ~WorldObject() {}
#endif

void _Create(uint32 guidlow, HighGuid guidhigh, uint32 phaseMask = 1);

TransportInfo* GetTransportInfo() const { return m_transportInfo; }
Expand Down Expand Up @@ -1236,7 +1235,7 @@ class WorldObject : public Object
// Spell mod owner: static player whose spell mods apply to this unit (server-side)
virtual Player* GetSpellModOwner() const { return nullptr; }
#ifdef BUILD_ELUNA
ElunaEventProcessor* elunaEvents;
std::unique_ptr<ElunaEventProcessor> elunaEvents;

Eluna* GetEluna() const;

Expand Down
9 changes: 2 additions & 7 deletions src/game/Maps/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ Map::~Map()

for (auto m_Transport : m_transports)
delete m_Transport;

#ifdef BUILD_ELUNA
delete eluna;
eluna = nullptr;
#endif
}

uint32 Map::GetCurrentMSTime() const
Expand Down Expand Up @@ -196,7 +191,7 @@ Map::Map(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode)
eluna = nullptr;

if (sElunaConfig->IsElunaEnabled() && !sElunaConfig->IsElunaCompatibilityMode() && sElunaConfig->ShouldMapLoadEluna(id))
eluna = new Eluna(this);
eluna = std::make_unique<Eluna>(this);
#endif
}

Expand Down Expand Up @@ -3513,7 +3508,7 @@ Eluna* Map::GetEluna() const
if (sElunaConfig->IsElunaCompatibilityMode())
return sWorld.GetEluna();

return eluna;
return eluna.get();
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/game/Maps/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ class Map : public GridRefManager<NGridType>
uint32 m_defaultLight;

#ifdef BUILD_ELUNA
Eluna* eluna;
std::unique_ptr<Eluna> eluna;
#endif
};

Expand Down
8 changes: 1 addition & 7 deletions src/game/World/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,6 @@ World::~World()
{
// it is assumed that no other thread is accessing this data when the destructor is called. therefore, no locks are necessary

#ifdef BUILD_ELUNA
// Delete world Eluna state
delete eluna;
eluna = nullptr;
#endif

///- Empty the kicked session set
for (auto const session : m_sessions)
delete session.second;
Expand Down Expand Up @@ -1535,7 +1529,7 @@ void World::SetInitialWorldSettings()
///- Run eluna scripts.
sLog.outString("Starting Eluna world state...");
// use map id -1 for the global Eluna state
eluna = new Eluna(nullptr, sElunaConfig->IsElunaCompatibilityMode());
eluna = std::make_unique<Eluna>(nullptr, sElunaConfig->IsElunaCompatibilityMode());
sLog.outString();
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/game/World/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,8 @@ class World
void StartBGQueueThread();

#ifdef BUILD_ELUNA
Eluna* GetEluna() const { return eluna; }
Eluna* eluna;
Eluna* GetEluna() const { return eluna.get(); }
std::unique_ptr<Eluna> eluna;
#endif
protected:
void _UpdateGameTime();
Expand Down

0 comments on commit 0c69ffd

Please sign in to comment.