4 * Created on: Apr 8, 2012
8 #include "Application.h"
16 Application::Application(sdl::InitScreen *screen, State *initialState)
20 , last(SDL_GetTicks()) {
21 assert(screen && "cannot create application without screen");
22 assert(initialState && "cannot create application without initial state");
23 RealPushState(initialState);
26 Application::~Application(void) {
31 State *Application::CurrentState(void) {
35 void Application::ChangeState(State *s) {
40 void Application::PushState(State *s) {
44 void Application::RealPushState(State *s) {
46 s->EnterState(this, screen->Screen());
49 void Application::PopState(void) {
53 void Application::RealPopState(void) {
54 if (states.empty()) return;
55 states.top()->ExitState();
60 void Application::Quit(void) {
64 void Application::PopAllStates(void) {
65 while (!states.empty()) {
71 void Application::Run(void) {
72 while (CurrentState()) {
77 void Application::Loop(void) {
78 Uint32 now(SDL_GetTicks());
79 Uint32 deltaT(now - last);
80 if (deltaT > 34) deltaT = 34;
90 void Application::HandleEvents(void) {
91 if (!CurrentState()) return;
93 while (SDL_PollEvent(&event)) {
99 CurrentState()->HandleEvent(event);
105 void Application::UpdateWorld(Uint32 deltaT) {
106 if (!CurrentState()) return;
107 for (Uint32 i(0); i < deltaT; ++i) {
109 CurrentState()->UpdateWorld(timer);
113 void Application::Render(void) {
114 if (!CurrentState()) return;
115 CurrentState()->Render(screen->Screen());