-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEventHandler.cpp
63 lines (54 loc) · 1.09 KB
/
EventHandler.cpp
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
/*
* EventHandler.cpp
*
* Created on: Feb 16, 2015
* Author: rmin
*/
#include "EventHandler.h"
#include "Parser.h"
#include <chrono>
#include <future>
EventHandler::EventHandler(Network *network)
{
this->network = network;
isThreadCall = false;
thr = NULL;
}
bool EventHandler::getIsThreadCall()
{
return isThreadCall;
}
std::thread * EventHandler::getThr()
{
return thr;
}
EventHandler::~EventHandler()
{
}
void EventHandler::handling()
{
while (events.getSize() != 0)
{
handleEvent(events.pop());
}
isThreadCall = false;
}
void EventHandler::addEvent(GameEvent* event) {
events.push(event);
if (!isThreadCall) {
isThreadCall = true;
thr = new std::thread(&EventHandler::handling,this);
}
}
void EventHandler::handleEvent(GameEvent *eve)
{
Message result, event;
result.addNode(Constants::MESSAGE_KEY_NAME, Constants::MESSAGE_KEY_EVENT);
parser.generateEvent(event, *eve);
std::vector<Message> eventsJson;
eventsJson.push_back(event);
result.addArray(Constants::MESSAGE_KEY_ARGS, eventsJson);
network->sendMessage(result);
delete eve;
}
EventHandler* eventHandler;