Skip to content

Commit 983bb7a

Browse files
authored
Eluna timed event rewrite (#30)
Required core changes for ElunaLuaEngine/Eluna@4790ef8
1 parent 30adde1 commit 983bb7a

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

src/server/game/Entities/Object/Object.cpp

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,21 +1809,9 @@ void WorldObject::SetMap(Map* map)
18091809
m_mapId = map->GetId();
18101810
m_InstanceId = map->GetInstanceId();
18111811
#ifdef ELUNA
1812-
// always reset Map events, then recreate the Map events procesor if Eluna is enabled for the map
1813-
auto& events = GetElunaEvents(m_mapId);
1814-
if (events)
1815-
events.reset();
1816-
1817-
if (Eluna* e = map->GetEluna())
1818-
events = std::make_unique<ElunaEventProcessor>(e, this);
1819-
1820-
// create the World events processor
1821-
if (Eluna* e = sWorld->GetEluna())
1822-
{
1823-
auto& events = GetElunaEvents(-1);
1824-
if (!events)
1825-
events = std::make_unique<ElunaEventProcessor>(e, this);
1826-
}
1812+
// Reset MAP processor
1813+
if (elunaMapEvents)
1814+
elunaMapEvents.reset();
18271815
#endif
18281816
if (IsStoredInWorldObjectGridContainer())
18291817
m_currMap->AddWorldObject(this);
@@ -3634,6 +3622,29 @@ Eluna* WorldObject::GetEluna() const
36343622

36353623
return nullptr;
36363624
}
3625+
3626+
ElunaEventProcessor* WorldObject::GetElunaEvents(int32 mapId)
3627+
{
3628+
Eluna* eluna = mapId == -1 ? sWorld->GetEluna() : GetEluna();
3629+
if (!eluna)
3630+
return nullptr;
3631+
3632+
EventMgr* mgr = eluna->eventMgr.get();
3633+
if (!mgr)
3634+
return nullptr;
3635+
3636+
// Select the correct ProcessorInfo slot
3637+
std::unique_ptr<ElunaProcessorInfo>& info = (mapId == -1) ? elunaWorldEvents : elunaMapEvents;
3638+
3639+
// Lazily create processor + ProcessorInfo handle
3640+
if (!info)
3641+
{
3642+
uint64 id = mgr->CreateObjectProcessor(this);
3643+
info = std::make_unique<ElunaProcessorInfo>(mgr, id);
3644+
}
3645+
3646+
return mgr->GetObjectProcessor(info->GetProcessorId());
3647+
}
36373648
#endif
36383649

36393650
template TC_GAME_API void WorldObject::GetGameObjectListWithEntryInGrid(std::list<GameObject*>&, uint32, float) const;

src/server/game/Entities/Object/Object.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class WorldObject;
6262
class WorldPacket;
6363
class ZoneScript;
6464
#ifdef ELUNA
65+
class ElunaEventProcessorInfo;
6566
class ElunaEventProcessor;
6667
class Eluna;
6768
#endif
@@ -568,12 +569,12 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
568569
uint32 LastUsedScriptID;
569570

570571
#ifdef ELUNA
571-
std::unique_ptr <ElunaEventProcessor> elunaMapEvents;
572-
std::unique_ptr <ElunaEventProcessor> elunaWorldEvents;
572+
std::unique_ptr<ElunaProcessorInfo> elunaMapEvents;
573+
std::unique_ptr<ElunaProcessorInfo> elunaWorldEvents;
573574

574575
Eluna* GetEluna() const;
575576

576-
std::unique_ptr<ElunaEventProcessor>& GetElunaEvents(int32 mapId) { return (mapId == -1) ? elunaWorldEvents : elunaMapEvents; }
577+
ElunaEventProcessor* GetElunaEvents(int32 mapId);
577578

578579
LuaVal lua_data = LuaVal({});
579580
#endif

0 commit comments

Comments
 (0)