summaryrefslogtreecommitdiffstats
path: root/src/ThreadGame.cpp
blob: 03c2c148828eefba4b4a82953af5c44ad6d76b4e (plain) (blame)
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
#include "ThreadGame.hpp"


ThreadGame::ThreadGame() {

}

ThreadGame::~ThreadGame() {

}

void ThreadGame::Execute() {

	EventListener listener;

	listener.RegisterHandler(EventType::GlobalAppState, [this](EventData eventData) {
		auto data = std::get<GlobalAppStateData>(eventData);
		state = data.state;
	});

	listener.RegisterHandler(EventType::ConnectionSuccessfull, [this](EventData eventData) {
		auto data = std::get<ConnectionSuccessfullData>(eventData);
		gs = new GameState(data.ptr);
	});

	LoopExecutionTimeController timer(std::chrono::milliseconds(int(1.0f / 60.0f * 1000.0f)));

	while (state != GlobalState::Exiting) {
		listener.HandleEvent();
		if (gs != nullptr)
			gs->Update(timer.GetDeltaMs());
		timer.Update();
	}
	delete gs;
}