Skip to content

Commit 717d453

Browse files
committed
PR cleanup 2
1 parent 9cc6067 commit 717d453

File tree

2 files changed

+22
-33
lines changed

2 files changed

+22
-33
lines changed

ElunaEventMgr.cpp

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -151,29 +151,18 @@ void ElunaEventProcessor::ProcessDeferredOps()
151151
if (deferredOps.empty())
152152
return;
153153

154-
std::vector<DeferredOp> ops;
155-
ops.swap(deferredOps);
156-
157-
for (DeferredOp& op : ops)
154+
using Handler = void(*)(ElunaEventProcessor*, DeferredOp&);
155+
static constexpr Handler handlers[] =
158156
{
159-
switch (op.type)
160-
{
161-
case DeferredOpType::AddEvent:
162-
AddEvent(op.event);
163-
break;
164-
165-
case DeferredOpType::SetState:
166-
SetState(op.eventId, op.state);
167-
break;
157+
[](ElunaEventProcessor* self, DeferredOp& op) { self->AddEvent(op.event); },
158+
[](ElunaEventProcessor* self, DeferredOp& op) { self->SetState(op.eventId, op.state); },
159+
[](ElunaEventProcessor* self, DeferredOp& op) { self->SetStates(op.state); },
160+
[](ElunaEventProcessor* self, DeferredOp& /*op*/) { self->ClearAllEvents(); }
161+
};
168162

169-
case DeferredOpType::SetStates:
170-
SetStates(op.state);
171-
break;
172-
173-
case DeferredOpType::ClearAll:
174-
ClearAllEvents();
175-
break;
176-
}
163+
for (DeferredOp& op : deferredOps)
164+
{
165+
handlers[op.type](this, op);
177166
}
178167
}
179168

ElunaEventMgr.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,22 @@ class EventMgr;
2929
class ElunaEventProcessor;
3030
class WorldObject;
3131

32-
enum LuaEventState
32+
enum LuaEventState : uint8
3333
{
3434
LUAEVENT_STATE_RUN, // On next call run the function normally
3535
LUAEVENT_STATE_ABORT, // On next call unregisters reffed function and erases the data
3636
LUAEVENT_STATE_ERASE, // On next call just erases the data
3737
};
3838

39-
enum GlobalEventSpace
39+
enum DeferredOpType : uint8
40+
{
41+
AddEvent,
42+
SetState,
43+
SetStates,
44+
ClearAll
45+
};
46+
47+
enum GlobalEventSpace : uint8
4048
{
4149
GLOBAL_EVENTS
4250
};
@@ -83,20 +91,12 @@ class ElunaEventProcessor
8391
void AddEvent(int funcRef, uint32 min, uint32 max, uint32 repeats);
8492

8593
private:
86-
enum class DeferredOpType
87-
{
88-
AddEvent,
89-
SetState,
90-
SetStates,
91-
ClearAll
92-
};
93-
9494
struct DeferredOp
9595
{
96-
DeferredOpType type;
97-
LuaEvent* event = nullptr;
9896
int eventId = 0;
97+
DeferredOpType type;
9998
LuaEventState state = LUAEVENT_STATE_RUN;
99+
LuaEvent* event = nullptr;
100100
};
101101

102102
void ClearAllEvents();

0 commit comments

Comments
 (0)