-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cpp
35 lines (28 loc) · 1.13 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
35
#include "Game.hpp"
#include "SplashScreenState.hpp"
Game::Game(int width, int height, std::string title) {
_data->window.create(sf::VideoMode(width, height), title, sf::Style::Close | sf::Style::Titlebar);
_data->window.setFramerateLimit(60);
_data->machine.AddState( StateRef(new SplashScreenState(this->_data)) );
this->Run();
}
void Game::Run() {
float newTime, frameTime, interpolation;
float currentTime = this->_clock.getElapsedTime().asSeconds();
float accumulator = 0.0f;
while( this->_data->window.isOpen()) {
this->_data->machine.ProcessStateChanges( );
newTime = this->_clock.getElapsedTime().asSeconds();
frameTime = newTime - currentTime;
frameTime = frameTime > 0.25f ? 0.25 : frameTime;
currentTime = newTime;
accumulator += frameTime;
while(accumulator >= dt) {
this->_data->machine.GetAtciveState()->HandleInput( );
this->_data->machine.GetAtciveState()->Update(dt);
accumulator-=dt;
}
interpolation = accumulator / dt;
this->_data->machine.GetAtciveState()->Draw(interpolation);
}
}