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;
42 /// Number of milliseconds per simulation frame.
43 Uint32 Timestep() const { return timestep; }
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;
52 /// Set the number of milliseconds per simulation frame.
53 void Timestep(Uint32 t) { timestep = t; }
56 /// Do some setup that needs an application and/or screen handle and thus
57 /// can not be done by the constructor.
58 /// Called when the state first enters the stack.
59 /// @param ctrl the Application running the state
60 virtual void OnEnterState(SDL_Surface *screen) = 0;
62 /// Called when the state is popped from the stack.
63 virtual void OnExitState(SDL_Surface *screen) = 0;
64 /// Called when the state becomes the active one.
65 virtual void OnResumeState(SDL_Surface *screen) = 0;
66 /// Called when the state becomes inactive.
67 virtual void OnPauseState(SDL_Surface *screen) = 0;
69 /// Adapt the state's graphics to given dimensions.
70 /// NOTE: currently, this is only called for the stack top and not
71 /// propagated on stack changes.
72 /// Will be fixed sometime ;).
73 virtual void OnResize(int width, int height) = 0;
76 /// Timers handle intended for graphics, sync'ed with render time.
77 /// These timers are only updated for the stack top and thus appear paused
78 /// when the state is invisible (roughly).
79 Timers<Uint32> &GraphicsTimers() { return graphicsTimers; }
80 /// Timers handle intended for graphics, sync'ed with world time.
81 /// These timers are only updated for the stack top and thus appear paused
82 /// when the state is invisible (roughly).
83 Timers<Uint32> &PhysicsTimers() { return physicsTimers; }
87 Timers<Uint32> graphicsTimers;
88 Timers<Uint32> physicsTimers;