4 * Created on: Apr 8, 2012
8 #include "Application.h"
16 Application::Application(SDL_Surface *screen, State *initialState)
19 , last(SDL_GetTicks()) {
20 assert(screen && "cannot create application without screen");
21 assert(initialState && "cannot create application without initial state");
22 RealPushState(initialState);
25 Application::~Application(void) {
30 State *Application::CurrentState(void) {
34 void Application::ChangeState(State *s) {
39 void Application::PushState(State *s) {
43 void Application::RealPushState(State *s) {
45 s->EnterState(*this, screen);
48 void Application::PopState(void) {
52 void Application::RealPopState(void) {
53 if (states.empty()) return;
54 states.top()->ExitState();
59 void Application::Quit(void) {
63 void Application::PopAllStates(void) {
64 while (!states.empty()) {
70 void Application::Run(void) {
71 while (CurrentState()) {
76 void Application::Loop(void) {
77 Uint32 now(SDL_GetTicks());
78 Uint32 deltaT(now - last);
79 if (deltaT > 34) deltaT = 34;
89 void Application::HandleEvents(void) {
90 if (!CurrentState()) return;
92 while (SDL_PollEvent(&event)) {
98 CurrentState()->HandleEvent(event);
104 void Application::UpdateWorld(Uint32 deltaT) {
105 if (!CurrentState()) return;
106 for (Uint32 i(0); i < deltaT; ++i) {
107 CurrentState()->UpdateWorld(0.001f);
111 void Application::Render(void) {
112 if (!CurrentState()) return;
113 CurrentState()->Render(screen);