]> git.localhorst.tv Git - l2e.git/blobdiff - src/app/Application.h
removed stupid file headers that eclipse put in
[l2e.git] / src / app / Application.h
index dcc5e006c0dc36d28b65859bcbb048761cfc96be..62d9740b943aa41107d78c32f704671f427a9392 100644 (file)
@@ -1,14 +1,9 @@
-/*
- * Application.h
- *
- *  Created on: Apr 8, 2012
- *      Author: holy
- */
-
 #ifndef APP_APPLICATION_H_
 #define APP_APPLICATION_H_
 
+#include "fwd.h"
 #include "Input.h"
+#include "Timer.h"
 #include "../sdl/InitScreen.h"
 
 #include <stack>
 
 namespace app {
 
-class State;
-
+/// Application controller class.
+/// Operates on a state stack that can be modified via ChangeState, PushState,
+/// and PopState.
+/// All state changes are delayed until the looping mechanism gets control again
+/// (i.e. after a top level state function returns, not during).
+/// SDL key events are preprocessed, see app::Input.
+/// The quit event (typically window closed or signal received) is caught and
+/// results in immediate (that is, after the next input loop) termination.
+/// Popped states will be deleted via the plain delete operator on an app::State
+/// pointer.
+/// Timers created by GlobalTimers() operate on actual application time and are
+/// not paused when the current state is paused (as are the timers started by
+/// the app::State members).
 class Application {
 
 public:
-       Application(sdl::InitScreen *screen, State *initialState);
+       Application(sdl::InitScreen &screen, State *initialState);
        ~Application();
 private:
        Application(const Application &);
@@ -40,10 +46,21 @@ public:
        void Quit();
        Input &Buttons() { return input; }
        const Input &Buttons() const { return input; }
+       Timers<Uint32> &GlobalTimers() { return globalTimers; }
+
+private:
+       struct StateCommand {
+               enum Type {
+                       PUSH, POP, CHANGE
+               } type;
+               State *state;
+       };
 
 private:
        State *CurrentState();
+       bool StateChangePending() const { return !stateChanges.empty(); }
        void UpdateState();
+       void RealChangeState(State *);
        void RealPushState(State *);
        void RealPopState();
        void PopAllStates();
@@ -54,12 +71,13 @@ private:
        void Render();
 
 private:
-       sdl::InitScreen *screen;
+       sdl::InitScreen &screen;
        std::stack<State *> states;
-       std::queue<State *> toPush;
+       std::queue<StateCommand> stateChanges;
+       Timers<Uint32> globalTimers;
        Input input;
        Uint32 last;
-       int toPop;
+       bool inStateChage;
 
 };