-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cpp
34 lines (31 loc) · 1.17 KB
/
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
#include "Game.hpp"
#include "SplashState.hpp"
namespace Checkers {
Game::Game(int width, int height, std::string title) {
_data->window.create(sf::VideoMode(width, height), title, sf::Style::Close | sf::Style::Titlebar);
_data->machine.addState(StateRef(new SplashState(_data)));
run();
}
void Game::run() {
float newTime, frameTime, interpolation;
float currentTime = _clock.getElapsedTime().asSeconds();
float accumulator = 0.0f;
while (_data->window.isOpen()) {
_data->machine.processStateChanges();
newTime = _clock.getElapsedTime().asSeconds();
frameTime = newTime - currentTime;
if (frameTime > 0.25f) {
frameTime = 0.25f;
}
currentTime = newTime;
accumulator += frameTime;
while (accumulator >= dt) {
_data->machine.getActiveState()->handleInput();
_data->machine.getActiveState()->update(dt);
accumulator -= dt;
}
interpolation = accumulator / dt;
_data->machine.getActiveState()->render(interpolation);
}
}
}