]> git.localhorst.tv Git - l2e.git/blob - src/app/Application.h
removed stupid file headers that eclipse put in
[l2e.git] / src / app / Application.h
1 #ifndef APP_APPLICATION_H_
2 #define APP_APPLICATION_H_
3
4 #include "fwd.h"
5 #include "Input.h"
6 #include "Timer.h"
7 #include "../sdl/InitScreen.h"
8
9 #include <stack>
10 #include <queue>
11 #include <SDL.h>
12
13
14 namespace app {
15
16 /// Application controller class.
17 /// Operates on a state stack that can be modified via ChangeState, PushState,
18 /// and PopState.
19 /// All state changes are delayed until the looping mechanism gets control again
20 /// (i.e. after a top level state function returns, not during).
21 /// SDL key events are preprocessed, see app::Input.
22 /// The quit event (typically window closed or signal received) is caught and
23 /// results in immediate (that is, after the next input loop) termination.
24 /// Popped states will be deleted via the plain delete operator on an app::State
25 /// pointer.
26 /// Timers created by GlobalTimers() operate on actual application time and are
27 /// not paused when the current state is paused (as are the timers started by
28 /// the app::State members).
29 class Application {
30
31 public:
32         Application(sdl::InitScreen &screen, State *initialState);
33         ~Application();
34 private:
35         Application(const Application &);
36         Application &operator =(const Application &);
37
38 public:
39         void Run();
40         void Loop();
41
42 public:
43         void ChangeState(State *);
44         void PushState(State *);
45         void PopState();
46         void Quit();
47         Input &Buttons() { return input; }
48         const Input &Buttons() const { return input; }
49         Timers<Uint32> &GlobalTimers() { return globalTimers; }
50
51 private:
52         struct StateCommand {
53                 enum Type {
54                         PUSH, POP, CHANGE
55                 } type;
56                 State *state;
57         };
58
59 private:
60         State *CurrentState();
61         bool StateChangePending() const { return !stateChanges.empty(); }
62         void UpdateState();
63         void RealChangeState(State *);
64         void RealPushState(State *);
65         void RealPopState();
66         void PopAllStates();
67
68 private:
69         void HandleEvents();
70         void UpdateWorld(Uint32 deltaT);
71         void Render();
72
73 private:
74         sdl::InitScreen &screen;
75         std::stack<State *> states;
76         std::queue<StateCommand> stateChanges;
77         Timers<Uint32> globalTimers;
78         Input input;
79         Uint32 last;
80         bool inStateChage;
81
82 };
83
84 }
85
86 #endif /* APP_APPLICATION_H_ */