4 * Created on: Apr 8, 2012
8 #ifndef APP_APPLICATIONSTATE_H_
9 #define APP_APPLICATIONSTATE_H_
18 /// Application state base class for use with app::Application.
26 /// Called by Application when pushing this state.
27 void EnterState(Application &ctrl, SDL_Surface *screen);
28 /// Called by Application when popping this state.
29 void ExitState(Application &ctrl, SDL_Surface *screen);
30 /// Called by Application when this state becomes the top state.
31 void ResumeState(SDL_Surface *screen);
32 /// Called by Application when this state no longer is the top state.
33 void PauseState(SDL_Surface *screen);
35 /// Called by Application on SDL window resize events.
36 void Resize(int width, int height);
38 /// Handle interactive events such as input and timers.
39 virtual void HandleEvents(const Input &) = 0;
40 /// Update the time-dependant world representation.
41 virtual void UpdateWorld(float deltaT) = 0;
42 /// Draw a picture of the world.
43 virtual void Render(SDL_Surface *) = 0;
46 /// Get a handle to the application this state is running on.
47 /// Do not call this while the state is off the stack (e.g. in c'tor/d'tor)
48 /// or you'll get a std::domain_error (potentially evil in d'tor)!
50 const Application &Ctrl() const;
53 /// Do some setup that needs an application and/or screen handle and thus
54 /// can not be done by the constructor.
55 /// Called when the state first enters the stack.
56 /// @param ctrl the Application running the state
57 virtual void OnEnterState(SDL_Surface *screen) = 0;
59 /// Called when the state is popped from the stack.
60 virtual void OnExitState(SDL_Surface *screen) = 0;
61 /// Called when the state becomes the active one.
62 virtual void OnResumeState(SDL_Surface *screen) = 0;
63 /// Called when the state becomes inactive.
64 virtual void OnPauseState(SDL_Surface *screen) = 0;
66 /// Adapt the state's graphics to given dimensions.
67 /// NOTE: currently, this is only called for the stack top and not
68 /// propagated on stack changes.
69 /// Will be fixed soom ;).
70 virtual void OnResize(int width, int height) = 0;
73 /// Timers handle intended for graphics, sync'ed with render time.
74 /// These timers are only updated for the stack top and thus appear paused
75 /// when the state is visible (roughly).
76 Timers<Uint32> &GraphicsTimers() { return graphicsTimers; }
77 /// Timers handle intended for graphics, sync'ed with world time.
78 /// These timers are only updated for the stack top and thus appear paused
79 /// when the state is visible (roughly).
80 Timers<float> &PhysicsTimers() { return physicsTimers; }
84 Timers<Uint32> graphicsTimers;
85 Timers<float> physicsTimers;
91 #endif /* APP_STATE_H_ */