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