]> git.localhorst.tv Git - l2e.git/commitdiff
store an application handle in each state
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 17 Oct 2012 19:14:31 +0000 (21:14 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 17 Oct 2012 19:14:31 +0000 (21:14 +0200)
26 files changed:
src/app/State.cpp
src/app/State.h
src/battle/states/PerformAttacks.cpp
src/battle/states/PerformAttacks.h
src/battle/states/RunState.cpp
src/battle/states/RunState.h
src/battle/states/SelectAttackType.cpp
src/battle/states/SelectAttackType.h
src/battle/states/SelectIkari.cpp
src/battle/states/SelectIkari.h
src/battle/states/SelectItem.cpp
src/battle/states/SelectItem.h
src/battle/states/SelectMoveAction.cpp
src/battle/states/SelectMoveAction.h
src/battle/states/SelectSpell.cpp
src/battle/states/SelectSpell.h
src/battle/states/SelectTarget.cpp
src/battle/states/SelectTarget.h
src/battle/states/SwapHeroes.cpp
src/battle/states/SwapHeroes.h
src/graphics/ColorFade.cpp
src/graphics/ColorFade.h
src/map/MapState.cpp
src/map/MapState.h
src/map/TransitionState.cpp
src/map/TransitionState.h

index 50b5bf601bc52c7027ce7408cc9410f3e767815d..f1c7712b01a63101c004a47e32b6e6be23bf78d3 100644 (file)
@@ -7,19 +7,30 @@
 
 #include "State.h"
 
+#include <stdexcept>
+
+using std::domain_error;
+
 namespace app {
 
+State::State()
+: ctrl(0) {
+
+}
+
 State::~State() {
 
 }
 
 
-void State::EnterState(Application &ctrl, SDL_Surface *screen) {
-       OnEnterState(ctrl, screen);
+void State::EnterState(Application &c, SDL_Surface *screen) {
+       ctrl = &c;
+       OnEnterState(c, screen);
 }
 
-void State::ExitState(Application &ctrl, SDL_Surface *screen) {
-       OnExitState(ctrl, screen);
+void State::ExitState(Application &c, SDL_Surface *screen) {
+       OnExitState(c, screen);
+       ctrl = 0;
 }
 
 void State::ResumeState(Application &ctrl, SDL_Surface *screen) {
@@ -34,4 +45,21 @@ void State::Resize(int width, int height) {
        OnResize(width, height);
 }
 
+
+Application &State::Ctrl() {
+       if (ctrl) {
+               return *ctrl;
+       } else {
+               throw domain_error("call to app::State::Ctrl() without application context");
+       }
+}
+
+const Application &State::Ctrl() const {
+       if (ctrl) {
+               return *ctrl;
+       } else {
+               throw domain_error("call to app::State::Ctrl() without application context");
+       }
+}
+
 }
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;
 
index 50c7b1443ad9b4dd1e3ccafaefac567755df9df3..a1a5b8b260226a5ad816765b1d14e419417f9582 100644 (file)
@@ -30,7 +30,6 @@ using std::vector;
 namespace battle {
 
 void PerformAttacks::OnEnterState(Application &c, SDL_Surface *screen) {
-       ctrl = &c;
        battle->CalculateAttackOrder();
        numberAnimation.reserve(battle->MaxMonsters() > battle->NumHeroes() + 1 ? battle->MaxMonsters() : battle->NumHeroes() + 1);
        numberPosition.reserve(numberAnimation.size());
@@ -38,7 +37,6 @@ void PerformAttacks::OnEnterState(Application &c, SDL_Surface *screen) {
 
 void PerformAttacks::OnExitState(Application &c, SDL_Surface *screen) {
        battle->ClearAllAttacks();
-       ctrl = 0;
 }
 
 void PerformAttacks::OnResumeState(Application &ctrl, SDL_Surface *screen) {
@@ -62,7 +60,7 @@ void PerformAttacks::HandleEvents(const Input &input) {
        battle->ApplyDamage();
        battle->NextAttack();
        if (battle->AttacksFinished()) {
-               ctrl->PopState();
+               Ctrl().PopState();
                return;
        }
 
index e52160c077c930848a958d8db82401a05ea82df2..2fe9a06b9c5d31367d08d32489152a21a07b4747 100644 (file)
@@ -24,7 +24,7 @@ class PerformAttacks
 
 public:
        explicit PerformAttacks(BattleState *battle)
-       : ctrl(0), battle(battle), moveAnimation(0), targetAnimation(0), titleBarText(0), cursor(-1) { }
+       : battle(battle), moveAnimation(0), targetAnimation(0), titleBarText(0), cursor(-1) { }
 
 public:
        virtual void HandleEvents(const app::Input &);
@@ -52,7 +52,6 @@ private:
        void RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
 
 private:
-       app::Application *ctrl;
        BattleState *battle;
        graphics::AnimationRunner moveAnimation;
        graphics::AnimationRunner targetAnimation;
index dbf38680d55671ab69ba6057e5bc23eaab0e0398..cf113f24f5a41b6aa433191f64365b14b4176f1e 100644 (file)
@@ -23,11 +23,11 @@ using geometry::Vector;
 namespace battle {
 
 void RunState::OnEnterState(Application &c, SDL_Surface *screen) {
-       ctrl = &c;
+
 }
 
 void RunState::OnExitState(Application &c, SDL_Surface *screen) {
-       ctrl = 0;
+
 }
 
 void RunState::OnResumeState(Application &ctrl, SDL_Surface *screen) {
@@ -47,7 +47,7 @@ void RunState::OnResize(int width, int height) {
 void RunState::HandleEvents(const Input &input) {
        if (timer.Finished()) {
                battle->SetRunaway();
-               ctrl->PopState(); // pop self
+               Ctrl().PopState(); // pop self
        }
 }
 
index 0f2818df8f60ede3d291cd6ed9e1069c35e99a40..9cee764776e59df9062658db3c415f19b1b969a1 100644 (file)
@@ -19,7 +19,7 @@ class RunState
 
 public:
        explicit RunState(BattleState *battle)
-       : ctrl(0), battle(battle){ }
+       : battle(battle){ }
 
 public:
 
@@ -39,7 +39,6 @@ private:
        void RenderTitleBar(SDL_Surface *screen, const geometry::Vector<int> &offset);
 
 private:
-       app::Application *ctrl;
        BattleState *battle;
        app::Timer<Uint32> timer;
 
index c41eb67bec8d39e17da1ae3abad743acdcdeb6d7..31a0be0e2e853a6ddb90e623156d3621486981e8 100644 (file)
@@ -28,11 +28,11 @@ using geometry::Vector;
 namespace battle {
 
 void SelectAttackType::OnEnterState(Application &c, SDL_Surface *screen) {
-       ctrl = &c;
+
 }
 
 void SelectAttackType::OnExitState(Application &c, SDL_Surface *screen) {
-       ctrl = 0;
+
 }
 
 void SelectAttackType::OnResumeState(Application &ctrl, SDL_Surface *screen) {
@@ -86,11 +86,11 @@ void SelectAttackType::HandleEvents(const Input &input) {
                                        ac.Selection().SetSingle();
                                }
                                ac.Selection().Reset();
-                               ctrl->PushState(new SelectTarget(battle, this, &ac.Selection(), battle->Res().weaponTargetCursor));
+                               Ctrl().PushState(new SelectTarget(battle, this, &ac.Selection(), battle->Res().weaponTargetCursor));
                                break;
                        case AttackChoice::MAGIC:
                                if (battle->ActiveHero().CanUseMagic()) {
-                                       ctrl->PushState(new SelectSpell(battle, this));
+                                       Ctrl().PushState(new SelectSpell(battle, this));
                                }
                                break;
                        case AttackChoice::DEFEND:
@@ -98,10 +98,10 @@ void SelectAttackType::HandleEvents(const Input &input) {
                                battle->NextHero();
                                break;
                        case AttackChoice::IKARI:
-                               ctrl->PushState(new SelectIkari(battle, this));
+                               Ctrl().PushState(new SelectIkari(battle, this));
                                break;
                        case AttackChoice::ITEM:
-                               ctrl->PushState(new SelectItem(battle, this));
+                               Ctrl().PushState(new SelectItem(battle, this));
                                break;
                        default:
                                throw std::logic_error("selected invalid attack type");
@@ -110,14 +110,14 @@ void SelectAttackType::HandleEvents(const Input &input) {
                ac.Reset();
                battle->PreviousHero();
                if (battle->BeforeFirstHero()) {
-                       ctrl->ChangeState(new SelectMoveAction(battle));
+                       Ctrl().ChangeState(new SelectMoveAction(battle));
                } else {
                        battle->ActiveHero().GetAttackChoice().Reset();
                }
        }
 
        if (battle->AttackSelectionDone()) {
-               ctrl->PopState();
+               Ctrl().PopState();
        }
 }
 
index 557602f50248f0379d7285233fd4e2e55d01ea1c..3f9832777a5364d6711aad908d99084331366057 100644 (file)
@@ -19,7 +19,7 @@ class SelectAttackType
 
 public:
        explicit SelectAttackType(BattleState *battle)
-       : ctrl(0), battle(battle) { }
+       : battle(battle) { }
 
 public:
        virtual void HandleEvents(const app::Input &);
@@ -38,7 +38,6 @@ private:
        void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset);
 
 private:
-       app::Application *ctrl;
        BattleState *battle;
 
 };
index 1a36e41c86ed9483e54ac4f7ae7646932eae7aea..604689c998d28dbd258f2c8f4636cfc68d1489b2 100644 (file)
@@ -25,11 +25,11 @@ using graphics::Frame;
 namespace battle {
 
 void SelectIkari::OnEnterState(Application &c, SDL_Surface *screen) {
-       ctrl = &c;
+
 }
 
 void SelectIkari::OnExitState(Application &c, SDL_Surface *screen) {
-       ctrl = 0;
+
 }
 
 void SelectIkari::OnResumeState(Application &ctrl, SDL_Surface *screen) {
@@ -65,19 +65,19 @@ void SelectIkari::HandleEvents(const Input &input) {
                                ac.SetType(AttackChoice::IKARI);
                                ac.SetItem(battle->ActiveHero().IkariMenu().Selected());
                                battle->NextHero();
-                               ctrl->PopState();
+                               Ctrl().PopState();
                        } else {
                                if (ikari->GetTargetingMode().TargetsSingle()) {
                                        ac.Selection().SetSingle();
                                } else {
                                        ac.Selection().SetMultiple();
                                }
-                               ctrl->PushState(new SelectTarget(battle, parent, &ac.Selection(), ikari->IsMagical() ? battle->Res().magicTargetCursor : battle->Res().weaponTargetCursor));
+                               Ctrl().PushState(new SelectTarget(battle, parent, &ac.Selection(), ikari->IsMagical() ? battle->Res().magicTargetCursor : battle->Res().weaponTargetCursor));
                        }
                }
        }
        if (input.JustPressed(Input::ACTION_B)) {
-               ctrl->PopState(); // return control to parent
+               Ctrl().PopState(); // return control to parent
        }
        if (input.JustPressed(Input::PAD_UP)) {
                battle->ActiveHero().IkariMenu().PreviousRow();
index a7383a0535fd690b6f38b063b06366852f8acf71..136436f6c680b251cbe8e743ef7d6a4c8a1a2ff5 100644 (file)
@@ -20,7 +20,7 @@ class SelectIkari
 
 public:
        SelectIkari(BattleState *battle, SelectAttackType *parent)
-       : ctrl(0), battle(battle), parent(parent) { }
+       : battle(battle), parent(parent) { }
 
 public:
        virtual void HandleEvents(const app::Input &);
@@ -41,7 +41,6 @@ private:
        void RenderMenu(SDL_Surface *, const geometry::Vector<int> &offset);
 
 private:
-       app::Application *ctrl;
        BattleState *battle;
        SelectAttackType *parent;
 
index 35a0c61ca9262bf2deebb68f6805133d9aa7f04a..fe6ce7b3ba7dc9fa8e1addc5382883012317e3d0 100644 (file)
@@ -24,11 +24,11 @@ using graphics::Frame;
 namespace battle {
 
 void SelectItem::OnEnterState(Application &c, SDL_Surface *screen) {
-       ctrl = &c;
+
 }
 
 void SelectItem::OnExitState(Application &c, SDL_Surface *screen) {
-       ctrl = 0;
+
 }
 
 void SelectItem::OnResumeState(Application &ctrl, SDL_Surface *screen) {
@@ -64,19 +64,19 @@ void SelectItem::HandleEvents(const Input &input) {
                                ac.SetType(AttackChoice::ITEM);
                                ac.SetItem(item);
                                battle->NextHero();
-                               ctrl->PopState();
+                               Ctrl().PopState();
                        } else {
                                if (item->GetTargetingMode().TargetsSingle()) {
                                        ac.Selection().SetSingle();
                                } else {
                                        ac.Selection().SetMultiple();
                                }
-                               ctrl->PushState(new SelectTarget(battle, parent, &ac.Selection(), battle->Res().itemTargetCursor));
+                               Ctrl().PushState(new SelectTarget(battle, parent, &ac.Selection(), battle->Res().itemTargetCursor));
                        }
                }
        }
        if (input.JustPressed(Input::ACTION_B)) {
-               ctrl->PopState(); // return control to parent
+               Ctrl().PopState(); // return control to parent
        }
        if (input.JustPressed(Input::PAD_UP)) {
                battle->ItemMenu().PreviousRow();
index e3d2168777573bb3e9066aab229f24faeecde37e..52429aa5c9d9d15bad4f319d183c44eddedff179 100644 (file)
@@ -19,7 +19,7 @@ class SelectItem
 
 public:
        SelectItem(BattleState *battle, SelectAttackType *parent)
-       : ctrl(0), battle(battle), parent(parent) { }
+       : battle(battle), parent(parent) { }
 
 public:
        virtual void HandleEvents(const app::Input &);
@@ -40,7 +40,6 @@ private:
        void RenderMenu(SDL_Surface *, const geometry::Vector<int> &offset);
 
 private:
-       app::Application *ctrl;
        BattleState *battle;
        SelectAttackType *parent;
 
index 072b03d229791c55ad9d57d93b736f552b503952..bb7148727d77246e250d362fe323e19d6c639373 100644 (file)
@@ -22,11 +22,11 @@ using geometry::Vector;
 namespace battle {
 
 void SelectMoveAction::OnEnterState(Application &c, SDL_Surface *screen) {
-       ctrl = &c;
+
 }
 
 void SelectMoveAction::OnExitState(Application &c, SDL_Surface *screen) {
-       ctrl = 0;
+
 }
 
 void SelectMoveAction::OnResumeState(Application &ctrl, SDL_Surface *screen) {
@@ -55,14 +55,14 @@ void SelectMoveAction::HandleEvents(const Input &input) {
        if (input.JustPressed(Input::ACTION_A)) {
                switch (battle->GetMoveMenu().Selected()) {
                        case MoveMenu::ATTACK:
-                               ctrl->ChangeState(new SelectAttackType(battle));
+                               Ctrl().ChangeState(new SelectAttackType(battle));
                                battle->NextHero();
                                break;
                        case MoveMenu::CHANGE:
-                               ctrl->PushState(new SwapHeroes(battle, this));
+                               Ctrl().PushState(new SwapHeroes(battle, this));
                                break;
                        case MoveMenu::RUN:
-                               ctrl->ChangeState(new RunState(battle));
+                               Ctrl().ChangeState(new RunState(battle));
                                break;
                }
        }
index bb04fb51e3a20cc1700236c571179dd76c33c329..cd54aed1e0f38c22aa39ea66a2d9dfcb00bf0d86 100644 (file)
@@ -19,7 +19,7 @@ class SelectMoveAction
 
 public:
        explicit SelectMoveAction(BattleState *battle)
-       : ctrl(0), battle(battle) { }
+       : battle(battle) { }
 
 public:
        virtual void HandleEvents(const app::Input &);
@@ -38,7 +38,6 @@ private:
        void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset);
 
 private:
-       app::Application *ctrl;
        BattleState *battle;
 
 };
index 6ea4675efcbbe1c381d4c70148ddec5414a630e0..623181e81265339c855fdf57cc1e1b86c661d923 100644 (file)
@@ -25,11 +25,11 @@ using graphics::Frame;
 namespace battle {
 
 void SelectSpell::OnEnterState(Application &c, SDL_Surface *screen) {
-       ctrl = &c;
+
 }
 
 void SelectSpell::OnExitState(Application &c, SDL_Surface *screen) {
-       ctrl = 0;
+
 }
 
 void SelectSpell::OnResumeState(Application &ctrl, SDL_Surface *screen) {
@@ -65,19 +65,19 @@ void SelectSpell::HandleEvents(const Input &input) {
                                ac.SetType(AttackChoice::MAGIC);
                                ac.SetSpell(spell);
                                battle->NextHero();
-                               ctrl->PopState();
+                               Ctrl().PopState();
                        } else {
                                if (spell->GetTargetingMode().TargetsSingle()) {
                                        ac.Selection().SetSingle();
                                } else {
                                        ac.Selection().SetMultiple();
                                }
-                               ctrl->PushState(new SelectTarget(battle, parent, &ac.Selection(), battle->Res().magicTargetCursor));
+                               Ctrl().PushState(new SelectTarget(battle, parent, &ac.Selection(), battle->Res().magicTargetCursor));
                        }
                }
        }
        if (input.JustPressed(Input::ACTION_B)) {
-               ctrl->PopState(); // return control to parent
+               Ctrl().PopState(); // return control to parent
        }
        if (input.JustPressed(Input::PAD_UP)) {
                battle->ActiveHero().SpellMenu().PreviousRow();
index 7a0bad417bd5ba799ebf9cb19d29858e6f6609ae..a1bbac78dda90d830346b4cb21a8f9e351047f5d 100644 (file)
@@ -19,7 +19,7 @@ class SelectSpell
 
 public:
        SelectSpell(BattleState *battle, SelectAttackType *parent)
-       : ctrl(0), battle(battle), parent(parent) { }
+       : battle(battle), parent(parent) { }
 
 public:
        virtual void HandleEvents(const app::Input &);
@@ -40,7 +40,6 @@ private:
        void RenderMenu(SDL_Surface *, const geometry::Vector<int> &offset);
 
 private:
-       app::Application *ctrl;
        BattleState *battle;
        SelectAttackType *parent;
 
index 4645f6debd37dfaf50ad2c450c6725800b35c52d..740e46c355065da33fcfb2c27640a3976c129376 100644 (file)
@@ -20,11 +20,11 @@ using std::vector;
 namespace battle {
 
 void SelectTarget::OnEnterState(Application &c, SDL_Surface *screen) {
-       ctrl = &c;
+
 }
 
 void SelectTarget::OnExitState(Application &c, SDL_Surface *screen) {
-       ctrl = 0;
+
 }
 
 void SelectTarget::OnResumeState(Application &ctrl, SDL_Surface *screen) {
@@ -44,11 +44,11 @@ void SelectTarget::OnResize(int width, int height) {
 void SelectTarget::HandleEvents(const Input &input) {
        if (input.JustPressed(Input::ACTION_A)) {
                if (selection->CurrentIsSelected()) {
-                       ctrl->PopState(); // return control to parent
+                       Ctrl().PopState(); // return control to parent
                } else {
                        selection->Select();
                        if (selection->SelectSingle()) {
-                               ctrl->PopState(); // return control to parent
+                               Ctrl().PopState(); // return control to parent
                        }
                }
        }
@@ -57,7 +57,7 @@ void SelectTarget::HandleEvents(const Input &input) {
                        selection->Unselect();
                } else {
                        selection->UnselectAll();
-                       ctrl->PopState(); // return control to parent
+                       Ctrl().PopState(); // return control to parent
                }
        }
 
index 454903672fb4846462e1b4685b6d6fbd73286915..01ebba72315dffee10258c84b8daabcf59f0e747 100644 (file)
@@ -20,7 +20,7 @@ class SelectTarget
 
 public:
        SelectTarget(BattleState *battle, SelectAttackType *parent, TargetSelection *selection, const graphics::Sprite *cursorIcon)
-       : ctrl(0), battle(battle), parent(parent), selection(selection), cursorIcon(cursorIcon), flipFlop(true) { }
+       : battle(battle), parent(parent), selection(selection), cursorIcon(cursorIcon), flipFlop(true) { }
 
 public:
        virtual void HandleEvents(const app::Input &);
@@ -39,7 +39,6 @@ private:
        void RenderCursors(SDL_Surface *screen, const geometry::Vector<int> &offset);
 
 private:
-       app::Application *ctrl;
        BattleState *battle;
        SelectAttackType *parent;
        TargetSelection *selection;
index 678b5c8bfdf3b53dd1f0e180cb6661db3a74b9ad..0dcd0bd4ea837bda9e30f340a6a9f947f00ad38c 100644 (file)
@@ -20,11 +20,11 @@ using std::vector;
 namespace battle {
 
 void SwapHeroes::OnEnterState(Application &c, SDL_Surface *screen) {
-       ctrl = &c;
+
 }
 
 void SwapHeroes::OnExitState(Application &c, SDL_Surface *screen) {
-       ctrl = 0;
+
 }
 
 void SwapHeroes::OnResumeState(Application &ctrl, SDL_Surface *screen) {
@@ -54,7 +54,7 @@ void SwapHeroes::HandleEvents(const Input &input) {
                if (cursor == selected) {
                        selected = -1;
                } else {
-                       ctrl->PopState();
+                       Ctrl().PopState();
                }
        }
 
index a5f5c62379399043f0148988068c52439e0ff392..1710721e85f5f6d0657173f0dce5e796bccf85e4 100644 (file)
@@ -19,7 +19,7 @@ class SwapHeroes
 
 public:
        SwapHeroes(BattleState *battle, SelectMoveAction *parent)
-       : ctrl(0), battle(battle), parent(parent), cursor(0), selected(-1), flipFlop(true) { }
+       : battle(battle), parent(parent), cursor(0), selected(-1), flipFlop(true) { }
 
 public:
        virtual void HandleEvents(const app::Input &);
@@ -44,7 +44,6 @@ private:
        void RenderCursors(SDL_Surface *screen, const geometry::Vector<int> &offset);
 
 private:
-       app::Application *ctrl;
        BattleState *battle;
        SelectMoveAction *parent;
        int cursor;
index 196b0d8386f3d6aff03268ababc15a800c412b72..f194665d1daecb35694880474e2b35dba549f2e8 100644 (file)
@@ -16,8 +16,7 @@ using app::Input;
 namespace graphics {
 
 ColorFade::ColorFade(State *slave, Uint32 color, int duration, bool in, bool interactive)
-: ctrl(0)
-, slave(slave)
+: slave(slave)
 , blinds(0)
 , color(color)
 , duration(duration)
@@ -31,7 +30,6 @@ ColorFade::ColorFade(State *slave, Uint32 color, int duration, bool in, bool int
 }
 
 void ColorFade::OnEnterState(Application &c, SDL_Surface *screen) {
-       ctrl = &c;
        if (leadIn > 0) {
                timer = GraphicsTimers().StartCountdown(leadIn);
        } else {
@@ -94,10 +92,10 @@ void ColorFade::HandleEvents(const Input &input) {
                        if (leadOut > 0) {
                                timer = GraphicsTimers().StartCountdown(leadOut);
                        } else {
-                               ctrl->PopState();
+                               Ctrl().PopState();
                        }
                } else {
-                       ctrl->PopState();
+                       Ctrl().PopState();
                }
        }
 }
index 26942726e5c6d7e772c313e634b318fc4a0b9b29..5e146636eada502d3d39f53a3a767806af9aba1d 100644 (file)
@@ -45,7 +45,6 @@ private:
 
 private:
        app::Timer<Uint32> timer;
-       app::Application *ctrl;
        app::State *slave;
        SDL_Surface *blinds;
        Uint32 color;
index 7e42e13a1779ef5041d64fbf57ecf4ef410fbda8..8e70acd19dbbccf0adf08601790a693162962db9 100644 (file)
@@ -31,7 +31,6 @@ namespace map {
 
 MapState::MapState(GameConfig *g, Map *map)
 : game(g)
-, ctrl(0)
 , map(map)
 , controlled(0)
 , pushed(0)
@@ -48,7 +47,6 @@ MapState::MapState(GameConfig *g, Map *map)
 
 
 void MapState::OnEnterState(Application &c, SDL_Surface *screen) {
-       ctrl = &c;
        camera.Resize(screen->w, screen->h);
        LoadMap(map);
 }
@@ -307,9 +305,9 @@ bool MapState::CheckMonster() {
                                ColorFade *fadeOut(new ColorFade(this, 0, 500));
                                fadeOut->SetLeadOutTime(500);
 
-                               ctrl->PushState(fadeIn);
-                               ctrl->PushState(battleState);
-                               ctrl->PushState(fadeOut);
+                               Ctrl().PushState(fadeIn);
+                               Ctrl().PushState(battleState);
+                               Ctrl().PushState(fadeOut);
                                // TODO: move entity erase to happen after the transition or battle
                                entities.erase(e);
                                return true;
@@ -445,11 +443,11 @@ bool MapState::ZCompare(const Entity *lhs, const Entity *rhs) {
 void MapState::HandleSyscall(common::ScriptRunner &r) {
        switch (r.Integer0()) {
                case TRANSITION: {
-                       ctrl->PushState(new ColorFade(this, 0, 500, true));
-                       ctrl->PushState(new TransitionState(this, reinterpret_cast<Map *>(r.Address0()), r.Vector0()));
+                       Ctrl().PushState(new ColorFade(this, 0, 500, true));
+                       Ctrl().PushState(new TransitionState(this, reinterpret_cast<Map *>(r.Address0()), r.Vector0()));
                        ColorFade *fadeOut(new ColorFade(this, 0, 500, false));
                        fadeOut->SetLeadOutTime(500);
-                       ctrl->PushState(fadeOut);
+                       Ctrl().PushState(fadeOut);
                        break;
                }
        }
index fcea893c0980f82f2728f1597885d2f8dc87b87c..9cff10cbfa5cbd248b7188d7bd3bfb762342ae92 100644 (file)
@@ -82,7 +82,6 @@ private:
 
 private:
        common::GameConfig *game;
-       app::Application *ctrl;
        Map *map;
        Entity *controlled;
        Entity *pushed;
index 1a2afb50854e6a2d8485fd0b912ba09076aea06c..b339381001fd711a4d0ce614ed5698fabeb60add 100644 (file)
@@ -18,15 +18,14 @@ using geometry::Vector;
 namespace map {
 
 TransitionState::TransitionState(MapState *ms, Map *map, const Vector<int> &coordinates)
-: ctrl(0)
-, ms(ms)
+: ms(ms)
 , map(map)
 , coordinates(coordinates) {
 
 }
 
 void TransitionState::OnEnterState(Application &c, SDL_Surface *screen) {
-       ctrl = &c;
+
 }
 
 void TransitionState::OnExitState(Application &, SDL_Surface *screen) {
@@ -49,7 +48,7 @@ void TransitionState::OnResize(int width, int height) {
 
 void TransitionState::HandleEvents(const Input &input) {
        ms->Transition(map, coordinates);
-       ctrl->PopState();
+       Ctrl().PopState();
 }
 
 
index 0dfa7cf5e1d7aed97cec1c64ef6fa5b9f2e7abd5..134e54a505de8cd97d76f6c8b18d288c850e8a5d 100644 (file)
@@ -35,7 +35,6 @@ private:
        virtual void OnResize(int width, int height);
 
 private:
-       app::Application *ctrl;
        MapState *ms;
        Map *map;
        const geometry::Vector<int> &coordinates;