43 lines
689 B
C++
43 lines
689 B
C++
#include "gamestate.h"
|
|
|
|
unsigned int GameState::FPS = 60;
|
|
|
|
GameState::GameState(stack<GameState*>* state_stack, SDL_Surface* display)
|
|
{
|
|
this->state_stack = state_stack;
|
|
this->display = display;
|
|
init_done = false;
|
|
}
|
|
|
|
|
|
bool GameState::init()
|
|
{
|
|
timer.start();
|
|
init_done = true;
|
|
return true;
|
|
}
|
|
|
|
|
|
void GameState::execute() throw(StateExit)
|
|
{
|
|
timer.start();
|
|
|
|
SDL_Event event;
|
|
while(SDL_PollEvent(&event))
|
|
handle_event(&event);
|
|
iterate();
|
|
render();
|
|
|
|
// Let's avoid using *too* much of the CPU...
|
|
if (timer.get_ticks() < 1000/FPS)
|
|
{
|
|
SDL_Delay((1000/FPS) - timer.get_ticks());
|
|
}
|
|
}
|
|
|
|
|
|
void GameState::on_exit()
|
|
{
|
|
throw StateExit();
|
|
}
|