]> git.localhorst.tv Git - l2e.git/blobdiff - src/app/State.h
store an application handle in each state
[l2e.git] / src / app / State.h
index a84afde9941a26b0809cdd20c884f9e6ab0920be..2a4b5e1bfd93176b8b9b4ebea58dfcfe9f519e8c 100644 (file)
@@ -19,6 +19,7 @@ namespace app {
 class State {
 
 public:
+       State();
        virtual ~State();
 
 public:
@@ -41,6 +42,13 @@ public:
        /// Draw a picture of the world.
        virtual void Render(SDL_Surface *) = 0;
 
+protected:
+       /// Get a handle to the application this state is running on.
+       /// Do not call this while the state is off the stack (e.g. in c'tor/d'tor)
+       /// or you'll get a std::domain_error (potentially evil in d'tor)!
+       Application &Ctrl();
+       const Application &Ctrl() const;
+
 private:
        /// Do some setup that needs an application and/or screen handle and thus
        /// can not be done by the constructor.
@@ -72,6 +80,7 @@ public:
        Timers<float> &PhysicsTimers() { return physicsTimers; }
 
 private:
+       Application *ctrl;
        Timers<Uint32> graphicsTimers;
        Timers<float> physicsTimers;