summaryrefslogtreecommitdiff
path: root/ui/mainApplication.cpp
blob: 08f49a4664109696d81f6ec97694dffb57001293 (plain)
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
#include "mainApplication.h"
#include "game/gamestate.h"
#include "game/worldobject.h"

void
MainApplication::mainLoop()
{
	auto t_start = std::chrono::high_resolution_clock::now();
	while (isRunning) {
		processInputs();
		const auto t_end = std::chrono::high_resolution_clock::now();
		const auto t_passed = std::chrono::duration_cast<TickDuration>(t_end - t_start);

		if (gameState) {
			gameState->world.apply(&WorldObject::tick, t_passed);
		}
		windows.apply(&Window::tick, t_passed);
		windows.apply(&Window::refresh);

		t_start = t_end;
	}
}

void
MainApplication::processInputs()
{
	for (SDL_Event e; SDL_PollEvent(&e);) {
		if (e.type == SDL_QUIT) {
			isRunning = false;
			return;
		}
		windows.applyOne(&Window::handleInput, e);
	}
}