Skip to content

Commit c4e98f1

Browse files
authored
Timed event rework (#515)
* Refactor timed event processing, ran by Eluna state update loop instead of by individual objects * Only process events if the object is currently in the world * Re-queue skipped events instead of not triggering
1 parent b8247b2 commit c4e98f1

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

ElunaEventMgr.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ void ElunaEventProcessor::Update(uint32 diff)
4747

4848
if (luaEvent->state == LUAEVENT_STATE_RUN)
4949
{
50+
bool shouldSkipTick = obj && !obj->IsInWorld();
51+
if (shouldSkipTick)
52+
{
53+
AddEvent(luaEvent, false);
54+
continue;
55+
}
56+
5057
uint32 delay = luaEvent->delay;
5158
bool remove = luaEvent->repeats == 1;
5259
if (!remove)
@@ -89,10 +96,12 @@ void ElunaEventProcessor::SetState(int eventId, LuaEventState state)
8996
eventMap.erase(eventId);
9097
}
9198

92-
void ElunaEventProcessor::AddEvent(LuaEvent* luaEvent)
99+
void ElunaEventProcessor::AddEvent(LuaEvent* luaEvent, bool reschedule)
93100
{
94-
luaEvent->GenerateDelay();
95-
eventList.insert(std::pair<uint64, LuaEvent*>(m_time + luaEvent->delay, luaEvent));
101+
if (reschedule)
102+
luaEvent->GenerateDelay();
103+
104+
eventList.insert(std::pair<uint64, LuaEvent*>(m_time + reschedule ? luaEvent->delay : 0, luaEvent));
96105
eventMap[luaEvent->funcRef] = luaEvent;
97106
}
98107

@@ -125,6 +134,14 @@ EventMgr::~EventMgr()
125134
globalProcessor->RemoveEvents_internal();
126135
}
127136

137+
void EventMgr::UpdateProcessors(uint32 diff)
138+
{
139+
if (!processors.empty())
140+
for (ProcessorSet::const_iterator it = processors.begin(); it != processors.end(); ++it) // loop processors
141+
(*it)->Update(diff);
142+
globalProcessor->Update(diff);
143+
}
144+
128145
void EventMgr::SetStates(LuaEventState state)
129146
{
130147
if (!processors.empty())

ElunaEventMgr.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class ElunaEventProcessor
8383

8484
private:
8585
void RemoveEvents_internal();
86-
void AddEvent(LuaEvent* luaEvent);
86+
void AddEvent(LuaEvent* luaEvent, bool reschedule = true);
8787
void RemoveEvent(LuaEvent* luaEvent);
8888
EventList eventList;
8989
uint64 m_time;
@@ -109,6 +109,8 @@ class EventMgr
109109
// Sets the eventId's state in all processors
110110
// Execute only in safe env
111111
void SetState(int eventId, LuaEventState state);
112+
113+
void UpdateProcessors(uint32 diff);
112114
};
113115

114116
#endif

LuaEngine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ void Eluna::UpdateEluna(uint32 diff)
876876
#endif
877877
_ReloadEluna();
878878

879-
eventMgr->globalProcessor->Update(diff);
879+
eventMgr->UpdateProcessors(diff);
880880
#if defined ELUNA_TRINITY
881881
GetQueryProcessor().ProcessReadyCallbacks();
882882
#endif

0 commit comments

Comments
 (0)