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