]> git.localhorst.tv Git - l2e.git/blob - src/app/Application.h
start/stop animation of player character
[l2e.git] / src / app / Application.h
1 /*
2  * Application.h
3  *
4  *  Created on: Apr 8, 2012
5  *      Author: holy
6  */
7
8 #ifndef APP_APPLICATION_H_
9 #define APP_APPLICATION_H_
10
11 #include "fwd.h"
12 #include "Input.h"
13 #include "Timer.h"
14 #include "../sdl/InitScreen.h"
15
16 #include <stack>
17 #include <queue>
18 #include <SDL.h>
19
20
21 namespace app {
22
23 class Application {
24
25 public:
26         Application(sdl::InitScreen *screen, State *initialState);
27         ~Application();
28 private:
29         Application(const Application &);
30         Application &operator =(const Application &);
31
32 public:
33         void Run();
34         void Loop();
35
36 public:
37         void ChangeState(State *);
38         void PushState(State *);
39         void PopState();
40         void Quit();
41         Input &Buttons() { return input; }
42         const Input &Buttons() const { return input; }
43         Timers<Uint32> &GlobalTimers() { return globalTimers; }
44
45 private:
46         struct StateCommand {
47                 enum Type {
48                         PUSH, POP, CHANGE
49                 } type;
50                 State *state;
51         };
52
53 private:
54         State *CurrentState();
55         bool StateChangePending() const { return !stateChanges.empty(); }
56         void UpdateState();
57         void RealChangeState(State *);
58         void RealPushState(State *);
59         void RealPopState();
60         void PopAllStates();
61
62 private:
63         void HandleEvents();
64         void UpdateWorld(Uint32 deltaT);
65         void Render();
66
67 private:
68         sdl::InitScreen *screen;
69         std::stack<State *> states;
70         std::queue<StateCommand> stateChanges;
71         Timers<Uint32> globalTimers;
72         Input input;
73         Uint32 last;
74
75 };
76
77 }
78
79 #endif /* APP_APPLICATION_H_ */