]> git.localhorst.tv Git - l2e.git/blob - src/app/State.h
wrapped some virtual State methods in non-virtual calls
[l2e.git] / src / app / State.h
1 /*
2  * State.h
3  *
4  *  Created on: Apr 8, 2012
5  *      Author: holy
6  */
7
8 #ifndef APP_APPLICATIONSTATE_H_
9 #define APP_APPLICATIONSTATE_H_
10
11 #include "fwd.h"
12 #include "Timer.h"
13
14 #include <SDL.h>
15
16 namespace app {
17
18 /// Application state base class for use with app::Application.
19 class State {
20
21 public:
22         virtual ~State();
23
24 public:
25         /// Called by Application when pushing this state.
26         void EnterState(Application &ctrl, SDL_Surface *screen);
27         /// Called by Application when popping this state.
28         void ExitState(Application &ctrl, SDL_Surface *screen);
29         /// Called by Application when this state becomes the top state.
30         void ResumeState(Application &ctrl, SDL_Surface *screen);
31         /// Called by Application when this state no longer is the top state.
32         void PauseState(Application &ctrl, SDL_Surface *screen);
33
34         /// Called by Application on SDL window resize events.
35         void Resize(int width, int height);
36
37         /// Handle interactive events such as input and timers.
38         virtual void HandleEvents(const Input &) = 0;
39         /// Update the time-dependant world representation.
40         virtual void UpdateWorld(float deltaT) = 0;
41         /// Draw a picture of the world.
42         virtual void Render(SDL_Surface *) = 0;
43
44 private:
45         /// Do some setup that needs an application and/or screen handle and thus
46         /// can not be done by the constructor.
47         /// Called when the state first enters the stack.
48         /// @param ctrl the Application running the state
49         virtual void OnEnterState(Application &ctrl, SDL_Surface *screen) = 0;
50         /// Do some cleanup.
51         /// Called when the state is popped from the stack.
52         virtual void OnExitState(Application &ctrl, SDL_Surface *screen) = 0;
53         /// Called when the state becomes the active one.
54         virtual void OnResumeState(Application &ctrl, SDL_Surface *screen) = 0;
55         /// Called when the state becomes inactive.
56         virtual void OnPauseState(Application &ctrl, SDL_Surface *screen) = 0;
57
58         /// Adapt the state's graphics to given dimensions.
59         /// NOTE: currently, this is only called for the stack top and not
60         ///       propagated on stack changes.
61         ///       Will be fixed soom ;).
62         virtual void OnResize(int width, int height) = 0;
63
64 public:
65         /// Timers handle intended for graphics, sync'ed with render time.
66         /// These timers are only updated for the stack top and thus appear paused
67         /// when the state is visible (roughly).
68         Timers<Uint32> &GraphicsTimers() { return graphicsTimers; }
69         /// Timers handle intended for graphics, sync'ed with world time.
70         /// These timers are only updated for the stack top and thus appear paused
71         /// when the state is visible (roughly).
72         Timers<float> &PhysicsTimers() { return physicsTimers; }
73
74 private:
75         Timers<Uint32> graphicsTimers;
76         Timers<float> physicsTimers;
77
78 };
79
80 }
81
82 #endif /* APP_STATE_H_ */