-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cpp
54 lines (45 loc) · 915 Bytes
/
Game.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
#include "Game.h"
#include "Screen.h"
#include "RenderingEngine.h"
Game::Game() : _screen(800, 600, string("Test"), char(154)), _engine(&_screen, this), _world()
{
running = false;
}
void Game::Start()
{
_world.init(_screen);
_engine.start();
running = true;
Run();
}
void Game::Run()
{
system_clock::time_point lastTick = system_clock::now();
while (running)
{
running = !_screen.isScreenClosed();
_engine.getGraphicEngine()->render(&_world);
auto passedTime = duration_cast<chrono::milliseconds>(system_clock::now() - lastTick);
if (passedTime.count() < 16)
this_thread::sleep_for(milliseconds(16) - passedTime);
}
}
void Game::Terminate()
{
running = false;
}
void Game::addObject(EngineObject & object)
{
_world.addObj(&object);
}
void Game::load(RessourceHandler& loader)
{
_world.load(loader);
}
void Game::update(ThreadManager& mgr)
{
_world.update( mgr);
}
Game::~Game()
{
}