forked from ElunaLuaEngine/Eluna
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElunaEventMgr.h
More file actions
97 lines (77 loc) · 2.18 KB
/
Copy pathElunaEventMgr.h
File metadata and controls
97 lines (77 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright (C) 2010 - 2015 Eluna Lua Engine <http://emudevs.com/>
* This program is free software licensed under GPL version 3
* Please see the included DOCS/LICENSE.md for more information
*/
#ifndef _ELUNA_EVENT_MGR_H
#define _ELUNA_EVENT_MGR_H
#include "ElunaUtility.h"
#include "Common.h"
#include <map>
#include <unordered_map>
#ifdef TRINITY
#include "Define.h"
#else
#include "Platform/Define.h"
#endif
class Eluna;
class EventMgr;
class ElunaEventProcessor;
class WorldObject;
struct LuaEvent
{
LuaEvent(int funcRef, uint32 delay, uint32 repeats) :
delay(delay), repeats(repeats), funcRef(funcRef), abort(false)
{
}
LuaEvent() :
delay(0), repeats(0), funcRef(0), abort(true)
{
}
uint32 delay; // Delay between event calls
uint32 repeats; // Amount of repeats to make, 0 for infinite
int funcRef; // Lua function reference ID, also used as event ID
bool abort;
};
class ElunaEventProcessor
{
friend class EventMgr;
public:
ElunaEventProcessor() : m_time(0)
{
}
// obj can be nullptr for global events
void Update(uint32 diff, Eluna* E, WorldObject* obj);
void AddEvent(LuaEvent const& luaEvent, bool reschedule = false);
void AddEvent(int funcRef, uint32 delay, uint32 repeats);
private:
typedef std::multimap<uint64, LuaEvent*> EventList;
typedef std::unordered_map<int, LuaEvent> EventMap;
EventList eventList;
EventMap eventMap;
uint64 m_time;
};
class EventMgr
{
friend class ElunaEventProcessor;
private:
typedef std::unordered_map<ObjectGuid, ElunaEventProcessor> ProcessorMap;
ProcessorMap processorMap;
ElunaEventProcessor globalProcessor;
Eluna* owner;
public:
EventMgr(Eluna* eluna) : owner(eluna)
{
ASSERT(eluna);
}
void DeleteAll();
void Delete(ObjectGuid const& guid, int funcref);
void Delete(ObjectGuid const& guid);
void DeleteGlobal(int funcref);
void DeleteGlobal();
void Update(uint32 diff, WorldObject* obj);
void UpdateGlobal(uint32 diff);
void AddEvent(ObjectGuid const& guid, int funcRef, uint32 delay, uint32 repeats);
void AddGlobalEvent(int funcRef, uint32 delay, uint32 repeats);
};
#endif