Skip to content

Commit 71e0aa7

Browse files
committed
PR cleanup
1 parent 6dcd7e7 commit 71e0aa7

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

ElunaEventMgr.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,19 @@ extern "C"
1818
#include "lauxlib.h"
1919
};
2020

21-
ElunaEventProcessor::ElunaEventProcessor(Eluna* _E, WorldObject* _obj) : m_time(0), obj(_obj), E(_E)
22-
{
23-
}
24-
2521
ElunaEventProcessor::~ElunaEventProcessor()
2622
{
27-
RemoveEvents_internal();
23+
ClearAllEvents();
2824
}
2925

3026
void ElunaEventProcessor::Update(uint32 diff)
3127
{
3228
isUpdating = true;
3329

3430
m_time += diff;
35-
for (EventList::iterator it = eventList.begin(); it != eventList.end() && it->first <= m_time; it = eventList.begin())
31+
while (!eventList.empty() && eventList.begin()->first <= m_time)
3632
{
33+
auto it = eventList.begin();
3734
LuaEvent* luaEvent = it->second;
3835
eventList.erase(it);
3936

@@ -47,13 +44,15 @@ void ElunaEventProcessor::Update(uint32 diff)
4744
if (!remove)
4845
AddEvent(luaEvent); // may be deferred if we recurse into Update
4946

47+
// Call the timed event
5048
if (!obj || (obj && obj->IsInWorld()))
51-
E->OnTimedEvent(luaEvent->funcRef, delay, luaEvent->repeats ? luaEvent->repeats-- : luaEvent->repeats, obj);
49+
mgr->E->OnTimedEvent(luaEvent->funcRef, delay, luaEvent->repeats ? luaEvent->repeats-- : luaEvent->repeats, obj);
5250

5351
if (!remove)
5452
continue;
5553
}
5654

55+
// Event should be deleted (executed last time or set to be aborted)
5756
RemoveEvent(luaEvent);
5857
}
5958

@@ -76,7 +75,7 @@ void ElunaEventProcessor::SetStates(LuaEventState state)
7675
eventMap.clear();
7776
}
7877

79-
void ElunaEventProcessor::RemoveEvents_internal()
78+
void ElunaEventProcessor::ClearAllEvents()
8079
{
8180
if (isUpdating)
8281
{
@@ -117,7 +116,7 @@ void ElunaEventProcessor::AddEvent(LuaEvent* luaEvent)
117116
}
118117

119118
luaEvent->GenerateDelay();
120-
eventList.insert(std::make_pair(m_time + luaEvent->delay, luaEvent));
119+
eventList.emplace(m_time + luaEvent->delay, luaEvent);
121120
eventMap[luaEvent->funcRef] = luaEvent;
122121
}
123122

@@ -129,10 +128,10 @@ void ElunaEventProcessor::AddEvent(int funcRef, uint32 min, uint32 max, uint32 r
129128
void ElunaEventProcessor::RemoveEvent(LuaEvent* luaEvent)
130129
{
131130
// Unreference if should and if Eluna was not yet uninitialized and if the lua state still exists
132-
if (luaEvent->state != LUAEVENT_STATE_ERASE && E->HasLuaState())
131+
if (luaEvent->state != LUAEVENT_STATE_ERASE && mgr->E->HasLuaState())
133132
{
134133
// Free lua function ref
135-
luaL_unref(E->L, LUA_REGISTRYINDEX, luaEvent->funcRef);
134+
luaL_unref(mgr->E->L, LUA_REGISTRYINDEX, luaEvent->funcRef);
136135
}
137136
delete luaEvent;
138137
}
@@ -172,7 +171,7 @@ void ElunaEventProcessor::ProcessDeferredOps()
172171
break;
173172

174173
case DeferredOpType::ClearAll:
175-
RemoveEvents_internal();
174+
ClearAllEvents();
176175
break;
177176
}
178177
}
@@ -186,7 +185,7 @@ ElunaProcessorInfo::~ElunaProcessorInfo()
186185

187186
EventMgr::EventMgr(Eluna* _E) : E(_E)
188187
{
189-
auto gp = std::make_unique<ElunaEventProcessor>(E, nullptr);
188+
auto gp = std::make_unique<ElunaEventProcessor>(this, nullptr);
190189
processors.insert(gp.get());
191190
globalProcessors.emplace(GLOBAL_EVENTS, std::move(gp));
192191
}
@@ -235,7 +234,7 @@ ElunaEventProcessor* EventMgr::GetGlobalProcessor(GlobalEventSpace space)
235234
uint64 EventMgr::CreateObjectProcessor(WorldObject* obj)
236235
{
237236
uint64 id = obj->GetGUID().GetRawValue();
238-
auto proc = std::make_unique<ElunaEventProcessor>(E, obj);
237+
auto proc = std::make_unique<ElunaEventProcessor>(this, obj);
239238
ElunaEventProcessor* raw = proc.get();
240239

241240
processors.insert(raw);

ElunaEventMgr.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ enum GlobalEventSpace
4343

4444
struct LuaEvent
4545
{
46-
LuaEvent(int _funcRef, uint32 _min, uint32 _max, uint32 _repeats) :
47-
min(_min), max(_max), delay(0), repeats(_repeats), funcRef(_funcRef), state(LUAEVENT_STATE_RUN)
48-
{
49-
}
46+
LuaEvent(int _funcRef, uint32 _min, uint32 _max, uint32 _repeats) : min(_min), max(_max), delay(0), repeats(_repeats), funcRef(_funcRef), state(LUAEVENT_STATE_RUN) { }
5047

5148
void SetState(LuaEventState _state)
5249
{
@@ -75,7 +72,7 @@ class ElunaEventProcessor
7572
typedef std::multimap<uint64, LuaEvent*> EventList;
7673
typedef std::unordered_map<int, LuaEvent*> EventMap;
7774

78-
ElunaEventProcessor(Eluna* _E, WorldObject* _obj);
75+
ElunaEventProcessor(EventMgr* mgr, WorldObject* obj) : m_time(0), obj(obj), mgr(mgr) { }
7976
~ElunaEventProcessor();
8077

8178
void Update(uint32 diff);
@@ -102,7 +99,7 @@ class ElunaEventProcessor
10299
LuaEventState state = LUAEVENT_STATE_RUN;
103100
};
104101

105-
void RemoveEvents_internal();
102+
void ClearAllEvents();
106103
void AddEvent(LuaEvent* luaEvent);
107104
void RemoveEvent(LuaEvent* luaEvent);
108105

@@ -118,17 +115,13 @@ class ElunaEventProcessor
118115
bool pendingDeletion = false;
119116

120117
WorldObject* obj;
121-
Eluna* E;
118+
EventMgr* mgr;
122119
};
123120

124121
class ElunaProcessorInfo
125122
{
126123
public:
127-
ElunaProcessorInfo(EventMgr* mgr, uint64 processorId)
128-
: mgr(mgr), processorId(processorId)
129-
{
130-
}
131-
124+
ElunaProcessorInfo(EventMgr* mgr, uint64 processorId) : mgr(mgr), processorId(processorId) { }
132125
~ElunaProcessorInfo();
133126

134127
uint64 GetProcessorId() const { return processorId; }
@@ -148,9 +141,10 @@ class EventMgr
148141
void SetAllEventStates(LuaEventState state);
149142
void SetEventState(int eventId, LuaEventState state);
150143

144+
// Global (per state) processors
151145
ElunaEventProcessor* GetGlobalProcessor(GlobalEventSpace space);
152146

153-
// Per-object processors (keyed by internal processorId)
147+
// Per-object processors
154148
uint64 CreateObjectProcessor(WorldObject* obj);
155149
ElunaEventProcessor* GetObjectProcessor(uint64 processorId);
156150
void FlagObjectProcessorForDeletion(uint64 processorId);

0 commit comments

Comments
 (0)