]> git.localhorst.tv Git - l2e.git/commitdiff
cached some of the battle coordinates
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 29 Jan 2013 23:05:09 +0000 (00:05 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 30 Jan 2013 19:34:30 +0000 (20:34 +0100)
20 files changed:
src/battle/BattleState.cpp
src/battle/BattleState.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

index 66097fbd46d05a8d5315196fb161fef1bc5a34cb..57ff3270d170daab546e8c51c461bcb6195b5ba3 100644 (file)
@@ -73,7 +73,9 @@ void BattleState::SwapHeroes(int lhs, int rhs) {
 
 
 void BattleState::OnResize(int w, int h) {
-
+       offset = Vector<int>(
+                               (w - background->w) / 2,
+                               (h - background->h) / 2);
 }
 
 
@@ -111,6 +113,8 @@ void BattleState::OnEnterState(SDL_Surface *screen) {
        smallHeroTagPositions[2] = Vector<int>(xOffset + tagWidth, yOffset);
        smallHeroTagPositions[3] = Vector<int>(xOffset + 3 * tagWidth, yOffset);
 
+       OnResize(screen->w, screen->h);
+
        itemMenu = *res->itemMenuProperties;
        LoadInventory();
        ClearAllAttacks();
@@ -396,12 +400,11 @@ void BattleState::UpdateWorld(Uint32 deltaT) {
 
 void BattleState::Render(SDL_Surface *screen) {
        assert(screen);
-       Vector<int> offset(CalculateScreenOffset(screen));
-       RenderBackground(screen, offset);
-       RenderMonsters(screen, offset);
+       RenderBackground(screen);
+       RenderMonsters(screen);
 }
 
-void BattleState::RenderBackground(SDL_Surface *screen, const Vector<int> &offset) {
+void BattleState::RenderBackground(SDL_Surface *screen) {
        assert(screen);
        // black for now
        SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
@@ -413,7 +416,7 @@ void BattleState::RenderBackground(SDL_Surface *screen, const Vector<int> &offse
        SDL_BlitSurface(background, 0, screen, &destRect);
 }
 
-void BattleState::RenderMonsters(SDL_Surface *screen, const Vector<int> &offset) {
+void BattleState::RenderMonsters(SDL_Surface *screen) {
        assert(screen);
        for (vector<Monster>::size_type i(0), end(monsters.size()); i < end; ++i) {
                if (MonsterPositionOccupied(i)) {
@@ -426,7 +429,7 @@ void BattleState::RenderMonsters(SDL_Surface *screen, const Vector<int> &offset)
        }
 }
 
-void BattleState::RenderHeroes(SDL_Surface *screen, const Vector<int> &offset) {
+void BattleState::RenderHeroes(SDL_Surface *screen) {
        assert(screen);
        for (int i(0); i < numHeroes; ++i) {
                if (heroes[i].GetAnimation().Running()) {
@@ -438,7 +441,7 @@ void BattleState::RenderHeroes(SDL_Surface *screen, const Vector<int> &offset) {
        }
 }
 
-void BattleState::RenderCapsule(SDL_Surface *screen, const Vector<int> &offset) {
+void BattleState::RenderCapsule(SDL_Surface *screen) {
        if (!capsule.Active() || capsule.Health() <= 0) return;
        if (capsule.GetAnimation().Running()) {
                capsule.GetAnimation().DrawCenter(screen, capsule.Position() + offset);
@@ -447,7 +450,7 @@ void BattleState::RenderCapsule(SDL_Surface *screen, const Vector<int> &offset)
        }
 }
 
-void BattleState::RenderHeroTags(SDL_Surface *screen, const Vector<int> &offset) {
+void BattleState::RenderHeroTags(SDL_Surface *screen) {
        assert(screen);
        int tagHeight(attackTypeMenu.Height());
        int tagWidth(attackTypeMenu.Width() * 2 + attackTypeMenu.Width() / 2);
@@ -457,7 +460,7 @@ void BattleState::RenderHeroTags(SDL_Surface *screen, const Vector<int> &offset)
        }
 }
 
-void BattleState::RenderSmallHeroTags(SDL_Surface *screen, const Vector<int> &offset) {
+void BattleState::RenderSmallHeroTags(SDL_Surface *screen) {
        assert(screen);
        int tagHeight(res->normalFont->CharHeight() * 4 + res->smallHeroTagFrame->BorderHeight() * 2);
        int tagWidth(res->normalFont->CharWidth() * 6 + res->smallHeroTagFrame->BorderWidth() * 2);
index 8eb8f8d239ae3b5ac541aebbf862c13c13ec1c2c..cff0e43b01a0a53d9e75111dd60c39e9fe8b134f 100644 (file)
@@ -129,21 +129,17 @@ public:
        bool Defeat() const;
 
 public:
-       math::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
-               return math::Vector<int>(
-                               (screen->w - background->w) / 2,
-                               (screen->h - background->h) / 2);
-       }
+       const math::Vector<int> &ScreenOffset() const { return offset; }
        int Width() const { return background->w; }
        int Height() const { return background->h; }
        math::Vector<int> Size() const { return math::Vector<int>(Width(), Height()); }
 
-       void RenderBackground(SDL_Surface *screen, const math::Vector<int> &offset);
-       void RenderMonsters(SDL_Surface *screen, const math::Vector<int> &offset);
-       void RenderHeroes(SDL_Surface *screen, const math::Vector<int> &offset);
-       void RenderCapsule(SDL_Surface *screen, const math::Vector<int> &offset);
-       void RenderHeroTags(SDL_Surface *screen, const math::Vector<int> &offset);
-       void RenderSmallHeroTags(SDL_Surface *screen, const math::Vector<int> &offset);
+       void RenderBackground(SDL_Surface *screen);
+       void RenderMonsters(SDL_Surface *screen);
+       void RenderHeroes(SDL_Surface *screen);
+       void RenderCapsule(SDL_Surface *screen);
+       void RenderHeroTags(SDL_Surface *screen);
+       void RenderSmallHeroTags(SDL_Surface *screen);
 
 private:
        virtual void OnEnterState(SDL_Surface *screen);
@@ -177,6 +173,9 @@ private:
        SmallHeroTag smallHeroTags[4];
        math::Vector<int> heroTagPositions[4];
        math::Vector<int> smallHeroTagPositions[4];
+
+       math::Vector<int> offset;
+
        Capsule capsule;
        int numHeroes;
        int activeHero;
index bc6a11894dc0d369cacad07dd6a63c3a80cd2670..92e5185cf70488a5ce8baf9a330011ef7ba51934 100644 (file)
@@ -27,6 +27,7 @@ void PerformAttacks::OnEnterState(SDL_Surface *screen) {
        battle->CalculateAttackOrder();
        numberAnimation.reserve(battle->MaxMonsters() > battle->NumHeroes() + 1 ? battle->MaxMonsters() : battle->NumHeroes() + 1);
        numberPosition.reserve(numberAnimation.size());
+       OnResize(screen->w, screen->h);
 }
 
 void PerformAttacks::OnExitState(SDL_Surface *screen) {
@@ -43,7 +44,11 @@ void PerformAttacks::OnPauseState(SDL_Surface *screen) {
 
 
 void PerformAttacks::OnResize(int width, int height) {
-
+       const Resources &res = battle->Res();
+       framePosition = battle->ScreenOffset();
+       frameSize = Vector<int>(
+                       battle->Width(),
+                       res.titleFrame->BorderHeight() * 2 + res.titleFont->CharHeight());
 }
 
 
@@ -119,7 +124,12 @@ void PerformAttacks::HandleEvents(const Input &input) {
                }
        }
 
-       if (titleBarText) titleBarTimer = GraphicsTimers().StartCountdown(850);
+       if (titleBarText) {
+               titleBarTimer = GraphicsTimers().StartCountdown(850);
+               textPosition = battle->ScreenOffset() + Vector<int>(
+                               (battle->Width() - std::strlen(titleBarText) * battle->Res().titleFont->CharWidth()) / 2,
+                               battle->Res().titleFrame->BorderHeight());
+       }
        if (moveAnimation.Valid()) {
                moveAnimation.Start(*this);
                if (battle->CurrentAttack().IsMonster()) {
@@ -143,11 +153,11 @@ void PerformAttacks::AddNumberAnimations(const TargetSelection &ts) {
                        if (ts.IsBad(i)) {
                                numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite));
                                numberPosition.push_back(
-                                               battle->MonsterAt(i).Position());
+                                               battle->MonsterAt(i).Position() + battle->ScreenOffset());
                        } else if (ts.IsGood(i)) {
                                numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().greenNumberSprite));
                                numberPosition.push_back(
-                                               battle->MonsterAt(i).Position());
+                                               battle->MonsterAt(i).Position() + battle->ScreenOffset());
                        }
                }
        } else {
@@ -155,11 +165,11 @@ void PerformAttacks::AddNumberAnimations(const TargetSelection &ts) {
                        if (ts.IsBad(i)) {
                                numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite));
                                numberPosition.push_back(
-                                               battle->HeroAt(i).Position());
+                                               battle->HeroAt(i).Position() + battle->ScreenOffset());
                        } else if (ts.IsGood(i)) {
                                numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().greenNumberSprite));
                                numberPosition.push_back(
-                                               battle->HeroAt(i).Position());
+                                               battle->HeroAt(i).Position() + battle->ScreenOffset());
                        }
                }
        }
@@ -215,51 +225,46 @@ void PerformAttacks::UpdateWorld(Uint32 deltaT) {
 }
 
 void PerformAttacks::Render(SDL_Surface *screen) {
-       Vector<int> offset(battle->CalculateScreenOffset(screen));
-       battle->RenderBackground(screen, offset);
-       battle->RenderMonsters(screen, offset);
-       battle->RenderHeroes(screen, offset);
-       battle->RenderCapsule(screen, offset);
-       battle->RenderSmallHeroTags(screen, offset);
-       RenderTitleBar(screen, offset);
-       RenderNumbers(screen, offset);
-       RenderTargetAnimation(screen, offset);
+       battle->RenderBackground(screen);
+       battle->RenderMonsters(screen);
+       battle->RenderHeroes(screen);
+       battle->RenderCapsule(screen);
+       battle->RenderSmallHeroTags(screen);
+       RenderTitleBar(screen);
+       RenderNumbers(screen);
+       RenderTargetAnimation(screen);
 }
 
-void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector<int> &offset) const {
+void PerformAttacks::RenderTitleBar(SDL_Surface *screen) const {
        if (!titleBarText || !titleBarTimer.Running()) return;
 
-       int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight());
-       battle->Res().titleFrame->Draw(screen, offset, battle->Width(), height);
+       battle->Res().titleFrame->Draw(screen, framePosition, frameSize.X(), frameSize.Y());
 
-       Vector<int> textPosition(
-                       (battle->Width() - (std::strlen(titleBarText) * battle->Res().titleFont->CharWidth())) / 2,
-                       battle->Res().titleFrame->BorderHeight());
-       battle->Res().titleFont->DrawString(titleBarText, screen, textPosition + offset);
+       battle->Res().titleFont->DrawString(titleBarText, screen, textPosition);
 }
 
-void PerformAttacks::RenderNumbers(SDL_Surface *screen, const Vector<int> &offset) const {
+void PerformAttacks::RenderNumbers(SDL_Surface *screen) const {
        for (vector<NumberAnimation>::size_type i(0), end(numberAnimation.size()); i < end; ++i) {
                if (numberAnimation[i].Running()) {
                        Vector<int> align(numberAnimation[i].Width() / -2, numberAnimation[i].Height() * -3 / 4);
-                       numberAnimation[i].Draw(screen, numberPosition[i] + align + offset);
+                       numberAnimation[i].Draw(screen, numberPosition[i] + align);
                }
        }
 }
 
-void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen, const math::Vector<int> &offset) const {
+void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen) const {
        if (!targetAnimation.Valid() || !targetAnimation.Running()) return;
        const TargetSelection &ts(battle->CurrentAttackAttackChoice().Selection());
        if (ts.TargetsHeroes()) {
                for (vector<Vector<int> >::size_type i(0), end(battle->NumHeroes()); i < end; ++i) {
                        if (ts.IsSelected(i)) {
-                               targetAnimation.DrawCenter(screen, battle->HeroAt(i).Position() + offset);
+                               targetAnimation.DrawCenter(screen, battle->HeroAt(i).Position() + battle->ScreenOffset());
                        }
                }
        } else {
                for (vector<Vector<int> >::size_type i(0), end(battle->MaxMonsters()); i < end; ++i) {
                        if (ts.IsSelected(i)) {
-                               targetAnimation.DrawCenter(screen, battle->MonsterAt(i).Position() + offset);
+                               targetAnimation.DrawCenter(screen, battle->MonsterAt(i).Position() + battle->ScreenOffset());
                        }
                }
        }
index ab1552595bca018ae5694b593aaf93c56e5f07c7..3d8b2ff6d5e23d6b7853cc4931c7356d49bdbd59 100644 (file)
@@ -42,9 +42,9 @@ private:
 private:
        void AddNumberAnimations(const TargetSelection &);
 
-       void RenderTitleBar(SDL_Surface *screen, const math::Vector<int> &offset) const;
-       void RenderNumbers(SDL_Surface *screen, const math::Vector<int> &offset) const;
-       void RenderTargetAnimation(SDL_Surface *screen, const math::Vector<int> &offset) const;
+       void RenderTitleBar(SDL_Surface *screen) const;
+       void RenderNumbers(SDL_Surface *screen) const;
+       void RenderTargetAnimation(SDL_Surface *screen) const;
 
 private:
        BattleState *battle;
@@ -55,6 +55,9 @@ private:
        app::Timer<Uint32> targetAnimationTimer;
        std::vector<NumberAnimation> numberAnimation;
        std::vector<math::Vector<int> > numberPosition;
+       math::Vector<int> framePosition;
+       math::Vector<int> frameSize;
+       math::Vector<int> textPosition;
        int cursor;
 
 };
index 7e7dfc49b5ceb04262287a8c04886d39cd9027ed..7fbb78347c5ad5c2cf76912a9414685b6cabc7b0 100644 (file)
@@ -16,7 +16,7 @@ using math::Vector;
 namespace battle {
 
 void RunState::OnEnterState(SDL_Surface *screen) {
-
+       OnResize(screen->w, screen->h);
 }
 
 void RunState::OnExitState(SDL_Surface *screen) {
@@ -33,7 +33,14 @@ void RunState::OnPauseState(SDL_Surface *screen) {
 
 
 void RunState::OnResize(int width, int height) {
+       framePosition = battle->ScreenOffset();
+       frameSize = Vector<int> (
+                       battle->Width(),
+                       battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight());
 
+       textPosition = Vector<int>(
+                       (battle->Width() - std::strlen(battle->Res().escapeText) * battle->Res().titleFont->CharWidth()) / 2,
+                       battle->Res().titleFrame->BorderHeight());
 }
 
 
@@ -50,22 +57,17 @@ void RunState::UpdateWorld(Uint32 deltaT) {
 }
 
 void RunState::Render(SDL_Surface *screen) {
-       Vector<int> offset(battle->CalculateScreenOffset(screen));
-       battle->RenderBackground(screen, offset);
-       battle->RenderMonsters(screen, offset);
-       battle->RenderHeroes(screen, offset);
-       battle->RenderSmallHeroTags(screen, offset);
-       RenderTitleBar(screen, offset);
+       battle->RenderBackground(screen);
+       battle->RenderMonsters(screen);
+       battle->RenderHeroes(screen);
+       battle->RenderSmallHeroTags(screen);
+       RenderTitleBar(screen);
 }
 
-void RunState::RenderTitleBar(SDL_Surface *screen, const Vector<int> &offset) {
-       int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight());
-       battle->Res().titleFrame->Draw(screen, offset, battle->Width(), height);
-
-       Vector<int> textPosition(
-                       (battle->Width() - (std::strlen(battle->Res().escapeText) * battle->Res().titleFont->CharWidth())) / 2,
-                       battle->Res().titleFrame->BorderHeight());
-       battle->Res().titleFont->DrawString(battle->Res().escapeText, screen, textPosition + offset);
+void RunState::RenderTitleBar(SDL_Surface *screen) {
+const Resources &res = battle->Res();
+       res.titleFrame->Draw(screen, framePosition, frameSize.X(), frameSize.Y());
+       res.titleFont->DrawString(res.escapeText, screen, textPosition);
 }
 
 }
index d3411978ff49656e392463ff6bdd66e8e24c6cce..f94bd3e324414e960731977e1199ab35c8ed8e64 100644 (file)
@@ -4,12 +4,9 @@
 namespace battle {
        class BattleState;
 }
-namespace math {
-       template<class>
-       class Vector;
-}
 
 #include "../../app/State.h"
+#include "../../math/Vector.h"
 
 namespace battle {
 
@@ -35,11 +32,14 @@ private:
        virtual void OnResize(int width, int height);
 
 private:
-       void RenderTitleBar(SDL_Surface *screen, const math::Vector<int> &offset);
+       void RenderTitleBar(SDL_Surface *screen);
 
 private:
        BattleState *battle;
        app::Timer<Uint32> timer;
+       math::Vector<int> framePosition;
+       math::Vector<int> frameSize;
+       math::Vector<int> textPosition;
 
 };
 
index 20ab7a4db4f05b90271797217940d0622553d49e..b4f5dcc73f69a071bc4877d682dc27d2c52da2c4 100644 (file)
@@ -22,7 +22,7 @@ using math::Vector;
 namespace battle {
 
 void SelectAttackType::OnEnterState(SDL_Surface *screen) {
-
+       OnResize(screen->w, screen->h);
 }
 
 void SelectAttackType::OnExitState(SDL_Surface *screen) {
@@ -46,7 +46,11 @@ void SelectAttackType::OnPauseState(SDL_Surface *screen) {
 
 
 void SelectAttackType::OnResize(int width, int height) {
-
+       Vector<int> offset(battle->ScreenOffset());
+       Vector<int> position(
+                       (battle->Width() - battle->GetAttackTypeMenu().Width()) / 2,
+                       battle->Height() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2);
+       menuOffset = offset + position;
 }
 
 
@@ -120,18 +124,14 @@ void SelectAttackType::UpdateWorld(Uint32 deltaT) {
 }
 
 void SelectAttackType::Render(SDL_Surface *screen) {
-       Vector<int> offset(battle->CalculateScreenOffset(screen));
-       battle->RenderBackground(screen, offset);
-       battle->RenderMonsters(screen, offset);
-       battle->RenderHeroTags(screen, offset);
-       RenderMenu(screen, offset);
+       battle->RenderBackground(screen);
+       battle->RenderMonsters(screen);
+       battle->RenderHeroTags(screen);
+       RenderMenu(screen);
 }
 
-void SelectAttackType::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
-       Vector<int> position(
-                       (battle->Width() - battle->GetAttackTypeMenu().Width()) / 2,
-                       battle->Height() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2);
-       battle->GetAttackTypeMenu().Render(screen, position + offset);
+void SelectAttackType::RenderMenu(SDL_Surface *screen) {
+       battle->GetAttackTypeMenu().Render(screen, menuOffset);
 }
 
 }
index b7903a7766c02beae5ff6264841788e2379b8973..8794a48c2f45cbbcbc945bd32aec188ba6b0c16b 100644 (file)
@@ -4,12 +4,9 @@
 namespace battle {
        class BattleState;
 }
-namespace math {
-       template<class>
-       class Vector;
-}
 
 #include "../../app/State.h"
+#include "../../math/Vector.h"
 
 namespace battle {
 
@@ -34,10 +31,11 @@ private:
        virtual void OnResize(int width, int height);
 
 private:
-       void RenderMenu(SDL_Surface *screen, const math::Vector<int> &offset);
+       void RenderMenu(SDL_Surface *screen);
 
 private:
        BattleState *battle;
+       math::Vector<int> menuOffset;
 
 };
 
index 8d2006a4269597802aa287a68cd19341d6082c58..2ab66a95dc002bec89458e297a0d5e7f7872dc00 100644 (file)
@@ -19,7 +19,7 @@ using graphics::Frame;
 namespace battle {
 
 void SelectIkari::OnEnterState(SDL_Surface *screen) {
-
+       OnResize(screen->w, screen->h);
 }
 
 void SelectIkari::OnExitState(SDL_Surface *screen) {
@@ -40,7 +40,23 @@ void SelectIkari::OnPauseState(SDL_Surface *screen) {
 
 
 void SelectIkari::OnResize(int width, int height) {
+       const Vector<int> offset = battle->ScreenOffset();
+
+       const Resources &res = battle->Res();
+       const Frame &frame = *res.selectFrame;
+
+       framePosition = offset + frame.BorderSize();
+       frameSize = Vector<int>(
+                       battle->Width() - 2 * frame.BorderWidth(),
+                       res.normalFont->CharHeight() * 13);
+
+       headlinePosition = offset + Vector<int>(
+                       2 * frame.BorderWidth() + res.normalFont->CharWidth(),
+                       2 * frame.BorderHeight());
 
+       menuPosition = offset + Vector<int>(
+                       2 * frame.BorderWidth() + res.normalFont->CharWidth(),
+                       2 * frame.BorderHeight() + 2 * res.normalFont->CharHeight());
 }
 
 
@@ -93,34 +109,23 @@ void SelectIkari::UpdateWorld(Uint32 deltaT) {
 
 void SelectIkari::Render(SDL_Surface *screen) {
        parent->Render(screen);
-       Vector<int> offset(battle->CalculateScreenOffset(screen));
-       RenderFrame(screen, offset);
-       RenderHeadline(screen, offset);
-       RenderMenu(screen, offset);
+       RenderFrame(screen);
+       RenderHeadline(screen);
+       RenderMenu(screen);
 }
 
-void SelectIkari::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
-       const Frame *frame(battle->Res().selectFrame);
-       Vector<int> position(frame->BorderSize());
-       int width(battle->Width() - 2 * frame->BorderWidth());
-       int height(battle->Res().normalFont->CharHeight() * 13);
-       frame->Draw(screen, position + offset, width, height);
+void SelectIkari::RenderFrame(SDL_Surface *screen) {
+       const Frame &frame = *battle->Res().selectFrame;
+       frame.Draw(screen, framePosition, frameSize.X(), frameSize.Y());
 }
 
-void SelectIkari::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
-       const Resources &res(battle->Res());
-       Vector<int> position(
-                       2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
-                       2 * res.selectFrame->BorderHeight());
-       res.normalFont->DrawString(res.ikariMenuHeadline, screen, position + offset);
+void SelectIkari::RenderHeadline(SDL_Surface *screen) {
+       const Resources &res = battle->Res();
+       res.normalFont->DrawString(res.ikariMenuHeadline, screen, headlinePosition);
 }
 
-void SelectIkari::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
-       const Resources &res(battle->Res());
-       Vector<int> position(
-                       2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
-                       2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
-       battle->ActiveHero().IkariMenu().Draw(screen, position + offset);
+void SelectIkari::RenderMenu(SDL_Surface *screen) {
+       battle->ActiveHero().IkariMenu().Draw(screen, menuPosition);
 }
 
 }
index 43fa0cf1b4de65901e9505410082bccb6541294e..254da726baa71831fac9fcf7713bf1d83dd362c3 100644 (file)
@@ -5,12 +5,9 @@ namespace battle {
        class BattleState;
        class SelectAttackType;
 }
-namespace math {
-       template<class>
-       class Vector;
-}
 
 #include "../../app/State.h"
+#include "../../math/Vector.h"
 
 namespace battle {
 
@@ -36,13 +33,17 @@ private:
        virtual void OnResize(int width, int height);
 
 private:
-       void RenderFrame(SDL_Surface *, const math::Vector<int> &offset);
-       void RenderHeadline(SDL_Surface *, const math::Vector<int> &offset);
-       void RenderMenu(SDL_Surface *, const math::Vector<int> &offset);
+       void RenderFrame(SDL_Surface *);
+       void RenderHeadline(SDL_Surface *);
+       void RenderMenu(SDL_Surface *);
 
 private:
        BattleState *battle;
        SelectAttackType *parent;
+       math::Vector<int> framePosition;
+       math::Vector<int> frameSize;
+       math::Vector<int> headlinePosition;
+       math::Vector<int> menuPosition;
 
 };
 
index 2a90b0336a32417233ce769cd9f33b164ddde05c..0aaf7a36a79776ee9023a7162115aa7e49704a42 100644 (file)
@@ -18,7 +18,7 @@ using graphics::Frame;
 namespace battle {
 
 void SelectItem::OnEnterState(SDL_Surface *screen) {
-
+       OnResize(screen->w, screen->h);
 }
 
 void SelectItem::OnExitState(SDL_Surface *screen) {
@@ -39,7 +39,23 @@ void SelectItem::OnPauseState(SDL_Surface *screen) {
 
 
 void SelectItem::OnResize(int width, int height) {
+       const Vector<int> offset = battle->ScreenOffset();
+
+       const Resources &res = battle->Res();
+       const Frame &frame = *res.selectFrame;
+
+       framePosition = offset + frame.BorderSize();
+       frameSize = Vector<int>(
+                       battle->Width() - 2 * frame.BorderWidth(),
+                       res.normalFont->CharHeight() * 13);
+
+       headlinePosition = offset + Vector<int>(
+                       2 * frame.BorderWidth() + res.normalFont->CharWidth(),
+                       2 * frame.BorderHeight());
 
+       menuPosition = offset + Vector<int>(
+                       2 * frame.BorderWidth() + res.normalFont->CharWidth(),
+                       2 * frame.BorderHeight() + 2 * res.normalFont->CharHeight());
 }
 
 
@@ -92,34 +108,23 @@ void SelectItem::UpdateWorld(Uint32 deltaT) {
 
 void SelectItem::Render(SDL_Surface *screen) {
        parent->Render(screen);
-       Vector<int> offset(battle->CalculateScreenOffset(screen));
-       RenderFrame(screen, offset);
-       RenderHeadline(screen, offset);
-       RenderMenu(screen, offset);
+       RenderFrame(screen);
+       RenderHeadline(screen);
+       RenderMenu(screen);
 }
 
-void SelectItem::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
-       const Frame *frame(battle->Res().selectFrame);
-       Vector<int> position(frame->BorderSize());
-       int width(battle->Width() - 2 * frame->BorderWidth());
-       int height(battle->Res().normalFont->CharHeight() * 13);
-       frame->Draw(screen, position + offset, width, height);
+void SelectItem::RenderFrame(SDL_Surface *screen) {
+       const Frame &frame = *battle->Res().selectFrame;
+       frame.Draw(screen, framePosition, frameSize.X(), frameSize.Y());
 }
 
-void SelectItem::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
-       const Resources &res(battle->Res());
-       Vector<int> position(
-                       2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
-                       2 * res.selectFrame->BorderHeight());
-       res.normalFont->DrawString(res.itemMenuHeadline, screen, position + offset);
+void SelectItem::RenderHeadline(SDL_Surface *screen) {
+       const Resources &res = battle->Res();
+       res.normalFont->DrawString(res.itemMenuHeadline, screen, headlinePosition);
 }
 
-void SelectItem::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
-       const Resources &res(battle->Res());
-       Vector<int> position(
-                       2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
-                       2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
-       battle->ItemMenu().Draw(screen, position + offset);
+void SelectItem::RenderMenu(SDL_Surface *screen) {
+       battle->ItemMenu().Draw(screen, menuPosition);
 }
 
 }
index e9a30d8a76347611428775bd9b5d7839ee2e471f..9e9bcd0458536bd1dd0b71f38a51b8ea4787522a 100644 (file)
@@ -5,12 +5,9 @@ namespace battle {
        class BattleState;
        class SelectAttackType;
 }
-namespace math {
-       template<class>
-       class Vector;
-}
 
 #include "../../app/State.h"
+#include "../../math/Vector.h"
 
 namespace battle {
 
@@ -35,13 +32,17 @@ private:
        virtual void OnResize(int width, int height);
 
 private:
-       void RenderFrame(SDL_Surface *, const math::Vector<int> &offset);
-       void RenderHeadline(SDL_Surface *, const math::Vector<int> &offset);
-       void RenderMenu(SDL_Surface *, const math::Vector<int> &offset);
+       void RenderFrame(SDL_Surface *);
+       void RenderHeadline(SDL_Surface *);
+       void RenderMenu(SDL_Surface *);
 
 private:
        BattleState *battle;
        SelectAttackType *parent;
+       math::Vector<int> framePosition;
+       math::Vector<int> frameSize;
+       math::Vector<int> headlinePosition;
+       math::Vector<int> menuPosition;
 
 };
 
index d7898742be336598aec7946c4ea9e4badaa2373a..c8405da7968340d01aa58f5c6c4ee7ee48f7697b 100644 (file)
@@ -16,7 +16,7 @@ using math::Vector;
 namespace battle {
 
 void SelectMoveAction::OnEnterState(SDL_Surface *screen) {
-
+       OnResize(screen->w, screen->h);
 }
 
 void SelectMoveAction::OnExitState(SDL_Surface *screen) {
@@ -33,7 +33,9 @@ void SelectMoveAction::OnPauseState(SDL_Surface *screen) {
 
 
 void SelectMoveAction::OnResize(int width, int height) {
-
+       position = battle->ScreenOffset() + Vector<int>(
+                       (battle->Width() - battle->GetMoveMenu().Width()) / 2,
+                       battle->Height() - battle->GetMoveMenu().Height() - battle->GetMoveMenu().Height() / 2);
 }
 
 
@@ -67,18 +69,14 @@ void SelectMoveAction::UpdateWorld(Uint32 deltaT) {
 }
 
 void SelectMoveAction::Render(SDL_Surface *screen) {
-       Vector<int> offset(battle->CalculateScreenOffset(screen));
-       battle->RenderBackground(screen, offset);
-       battle->RenderMonsters(screen, offset);
-       battle->RenderHeroTags(screen, offset);
-       RenderMenu(screen, offset);
+       battle->RenderBackground(screen);
+       battle->RenderMonsters(screen);
+       battle->RenderHeroTags(screen);
+       RenderMenu(screen);
 }
 
-void SelectMoveAction::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
-       Vector<int> position(
-                       (battle->Width() - battle->GetMoveMenu().Width()) / 2,
-                       battle->Height() - battle->GetMoveMenu().Height() - battle->GetMoveMenu().Height() / 2);
-       battle->GetMoveMenu().Render(screen, position + offset);
+void SelectMoveAction::RenderMenu(SDL_Surface *screen) {
+       battle->GetMoveMenu().Render(screen, position);
 }
 
 }
index 1eb7a48d8fb254da7b586d6ad64cbb272fa7eba7..eb299ad828eae589c091fb2002439ecbf8f06432 100644 (file)
@@ -4,12 +4,9 @@
 namespace battle {
        class BattleState;
 }
-namespace math {
-       template<class>
-       class Vector;
-}
 
 #include "../../app/State.h"
+#include "../../math/Vector.h"
 
 namespace battle {
 
@@ -34,10 +31,11 @@ private:
        virtual void OnResize(int width, int height);
 
 private:
-       void RenderMenu(SDL_Surface *screen, const math::Vector<int> &offset);
+       void RenderMenu(SDL_Surface *screen);
 
 private:
        BattleState *battle;
+       math::Vector<int> position;
 
 };
 
index b1053d00eedf071cc2f52112b00b55a156a70482..7b918b4c98c762b71015c4213870bcf093c6bf4f 100644 (file)
@@ -19,7 +19,7 @@ using graphics::Frame;
 namespace battle {
 
 void SelectSpell::OnEnterState(SDL_Surface *screen) {
-
+       OnResize(screen->w, screen->h);
 }
 
 void SelectSpell::OnExitState(SDL_Surface *screen) {
@@ -40,7 +40,23 @@ void SelectSpell::OnPauseState(SDL_Surface *screen) {
 
 
 void SelectSpell::OnResize(int width, int height) {
+       const Vector<int> offset = battle->ScreenOffset();
+
+       const Resources &res = battle->Res();
+       const Frame &frame = *res.selectFrame;
+
+       framePosition = offset + frame.BorderSize();
+       frameSize = Vector<int>(
+                       battle->Width() - 2 * frame.BorderWidth(),
+                       res.normalFont->CharHeight() * 13);
+
+       headlinePosition = offset + Vector<int>(
+                       2 * frame.BorderWidth() + res.normalFont->CharWidth(),
+                       2 * frame.BorderHeight());
 
+       menuPosition = offset + Vector<int>(
+                       2 * frame.BorderWidth() + res.normalFont->CharWidth(),
+                       2 * frame.BorderHeight() + 2 * res.normalFont->CharHeight());
 }
 
 
@@ -93,34 +109,23 @@ void SelectSpell::UpdateWorld(Uint32 deltaT) {
 
 void SelectSpell::Render(SDL_Surface *screen) {
        parent->Render(screen);
-       Vector<int> offset(battle->CalculateScreenOffset(screen));
-       RenderFrame(screen, offset);
-       RenderHeadline(screen, offset);
-       RenderMenu(screen, offset);
+       RenderFrame(screen);
+       RenderHeadline(screen);
+       RenderMenu(screen);
 }
 
-void SelectSpell::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
-       const Frame *frame(battle->Res().selectFrame);
-       Vector<int> position(frame->BorderSize());
-       int width(battle->Width() - 2 * frame->BorderWidth());
-       int height(battle->Res().normalFont->CharHeight() * 13);
-       frame->Draw(screen, position + offset, width, height);
+void SelectSpell::RenderFrame(SDL_Surface *screen) {
+       const Frame &frame = *battle->Res().selectFrame;
+       frame.Draw(screen, framePosition, frameSize.X(), frameSize.Y());
 }
 
-void SelectSpell::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
-       const Resources &res(battle->Res());
-       Vector<int> position(
-                       2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
-                       2 * res.selectFrame->BorderHeight());
-       res.normalFont->DrawString(res.spellMenuHeadline, screen, position + offset);
+void SelectSpell::RenderHeadline(SDL_Surface *screen) {
+       const Resources &res = battle->Res();
+       res.normalFont->DrawString(res.spellMenuHeadline, screen, headlinePosition);
 }
 
-void SelectSpell::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
-       const Resources &res(battle->Res());
-       Vector<int> position(
-                       2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
-                       2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
-       battle->ActiveHero().SpellMenu().Draw(screen, position + offset);
+void SelectSpell::RenderMenu(SDL_Surface *screen) {
+       battle->ActiveHero().SpellMenu().Draw(screen, menuPosition);
 }
 
 }
index 1087b3fd1b7bc53b86124a8a1d88cdb577cd169f..64cc85206c8c24f424d241d37d79f1c8454b513a 100644 (file)
@@ -5,12 +5,9 @@ namespace battle {
        class BattleState;
        class SelectAttackType;
 }
-namespace math {
-       template<class>
-       class Vector;
-}
 
 #include "../../app/State.h"
+#include "../../math/Vector.h"
 
 namespace battle {
 
@@ -35,13 +32,17 @@ private:
        virtual void OnResize(int width, int height);
 
 private:
-       void RenderFrame(SDL_Surface *, const math::Vector<int> &offset);
-       void RenderHeadline(SDL_Surface *, const math::Vector<int> &offset);
-       void RenderMenu(SDL_Surface *, const math::Vector<int> &offset);
+       void RenderFrame(SDL_Surface *);
+       void RenderHeadline(SDL_Surface *);
+       void RenderMenu(SDL_Surface *);
 
 private:
        BattleState *battle;
        SelectAttackType *parent;
+       math::Vector<int> framePosition;
+       math::Vector<int> frameSize;
+       math::Vector<int> headlinePosition;
+       math::Vector<int> menuPosition;
 
 };
 
index 800c2335e53460cda706440e1ae0bcefc7de8858..dc8c1239145f9a7cfbd95828a2c16612eea25e27 100644 (file)
@@ -14,7 +14,7 @@ using std::vector;
 namespace battle {
 
 void SelectTarget::OnEnterState(SDL_Surface *screen) {
-
+       OnResize(screen->w, screen->h);
 }
 
 void SelectTarget::OnExitState(SDL_Surface *screen) {
@@ -31,7 +31,22 @@ void SelectTarget::OnPauseState(SDL_Surface *screen) {
 
 
 void SelectTarget::OnResize(int width, int height) {
+       Vector<int> offset(battle->ScreenOffset());
+       cursorOffset = Vector<int>(cursorIcon->Width() / -2, cursorIcon->Height()) + offset;
+       // offset the indicator by 1/8th to the right and top
+       indicatorOffset = cursorOffset + Vector<int>(cursorIcon->Width() / 8, cursorIcon->Height() / -8);
 
+       monsterPositions.clear();
+       monsterPositions.reserve(battle->MaxMonsters());
+       for (int i(0), end(battle->MaxMonsters()); i < end; ++i) {
+               monsterPositions.push_back(battle->MonsterAt(i).Position());
+       }
+
+       heroPositions.clear();
+       heroPositions.reserve(battle->NumHeroes());
+       for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
+               heroPositions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset());
+       }
 }
 
 
@@ -74,34 +89,25 @@ void SelectTarget::UpdateWorld(Uint32 deltaT) {
 }
 
 void SelectTarget::Render(SDL_Surface *screen) {
-       Vector<int> offset(battle->CalculateScreenOffset(screen));
        parent->Render(screen);
-       RenderCursors(screen, offset);
+       RenderCursors(screen);
 }
 
-void SelectTarget::RenderCursors(SDL_Surface *screen, const math::Vector<int> &offset) {
-       Vector<int> cursorOffset(cursorIcon->Width() / -2, cursorIcon->Height());
-       // offset the indicator by 1/8th to the right and top
-       Vector<int> indicatorOffset(cursorOffset + Vector<int>(cursorIcon->Width() / 8, cursorIcon->Height() / -8));
-       vector<Vector<int> > positions;
-       if (selection->TargetsMonsters()) {
-               for (int i(0), end(battle->MaxMonsters()); i < end; ++i) {
-                       positions.push_back(battle->MonsterAt(i).Position());
-               }
-       } else {
-               for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
-                       positions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset());
-               }
-       }
+void SelectTarget::RenderCursors(SDL_Surface *screen) {
+       vector<Vector<int> > &positions = selection->TargetsMonsters()
+                       ? monsterPositions
+                       : heroPositions;
+
        if (flipFlop) {
-               for (vector<Vector<int> >::size_type i(0); i < positions.size(); ++i) {
+               for (vector<Vector<int> >::size_type i(0), end(positions.size());
+                               i != end; ++i) {
                        if (selection->IsSelected(i)) {
-                               cursorIcon->DrawTopRight(screen, positions[i] + indicatorOffset + offset);
+                               cursorIcon->DrawTopRight(screen, positions[i] + indicatorOffset);
                        }
                }
        }
        flipFlop = !flipFlop;
-       cursorIcon->DrawTopRight(screen, positions[selection->Current()] + offset + cursorOffset);
+       cursorIcon->DrawTopRight(screen, positions[selection->Current()] + cursorOffset);
 }
 
 }
index 4d53c3c76f76491abdb8e2815e5ae8e43d217300..9bdc470519a7d1ce98e2006f2ffff954547cc2fe 100644 (file)
@@ -6,15 +6,14 @@ namespace battle {
        class SelectAttackType;
        class TargetSelection;
 }
-namespace math {
-       template<class>
-       class Vector;
-}
 namespace graphics {
        class Sprite;
 }
 
 #include "../../app/State.h"
+#include "../../math/Vector.h"
+
+#include <vector>
 
 namespace battle {
 
@@ -39,13 +38,17 @@ private:
        virtual void OnResize(int width, int height);
 
 private:
-       void RenderCursors(SDL_Surface *screen, const math::Vector<int> &offset);
+       void RenderCursors(SDL_Surface *screen);
 
 private:
        BattleState *battle;
        SelectAttackType *parent;
        TargetSelection *selection;
        const graphics::Sprite *cursorIcon;
+       std::vector<math::Vector<int> > monsterPositions;
+       std::vector<math::Vector<int> > heroPositions;
+       math::Vector<int> cursorOffset;
+       math::Vector<int> indicatorOffset;
        bool flipFlop;
 
 };
index 74770277c808eedead551aa5c5f6f49ba274f38d..af867477bc3d44477ebf933dddbc67656e3bc94e 100644 (file)
@@ -14,7 +14,7 @@ using std::vector;
 namespace battle {
 
 void SwapHeroes::OnEnterState(SDL_Surface *screen) {
-
+       OnResize(screen->w, screen->h);
 }
 
 void SwapHeroes::OnExitState(SDL_Surface *screen) {
@@ -31,7 +31,24 @@ void SwapHeroes::OnPauseState(SDL_Surface *screen) {
 
 
 void SwapHeroes::OnResize(int width, int height) {
+       Vector<int> offset(battle->ScreenOffset());
+       // offset the cursor by 1/8th to the left and bottom
+       cursorOffset = Vector<int>(battle->Res().swapCursor->Width() / -8, battle->Res().swapCursor->Height() / 8);
+       indicatorOffset = Vector<int>(0, 0);
 
+       positions.clear();
+       positions.reserve(battle->NumHeroes());
+       for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
+               Vector<int> positionCorrection(
+                               battle->Res().swapCursor->Width() / 2,
+                               battle->HeroTagAt(i).HeroSprite()->Height() - battle->Res().swapCursor->Height() / 2);
+               // indicator offsets are inverted for heroes
+               positionCorrection -= cursorOffset;
+               positions.push_back(battle->HeroTagPositionAt(i)
+                               + battle->HeroTagAt(i).HeroOffset()
+                               + positionCorrection
+                               + offset);
+       }
 }
 
 
@@ -109,31 +126,21 @@ void SwapHeroes::UpdateWorld(Uint32 deltaT) {
 }
 
 void SwapHeroes::Render(SDL_Surface *screen) {
-       Vector<int> offset(battle->CalculateScreenOffset(screen));
        parent->Render(screen);
-       RenderCursors(screen, offset);
+       RenderCursors(screen);
 }
 
-void SwapHeroes::RenderCursors(SDL_Surface *screen, const math::Vector<int> &offset) {
-       // offset the cursor by 1/8th to the left and bottom
-       Vector<int> cursorOffset(battle->Res().swapCursor->Width() / -8, battle->Res().swapCursor->Height() / 8);
-       Vector<int> indicatorOffset(0, 0);
-       vector<Vector<int> > positions;
-       for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
-               Vector<int> positionCorrection(battle->Res().swapCursor->Width() / 2, battle->HeroTagAt(i).HeroSprite()->Height() - battle->Res().swapCursor->Height() / 2);
-               // indicator offsets are inverted for heroes
-               positionCorrection -= cursorOffset;
-               positions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset() + positionCorrection);
-       }
+void SwapHeroes::RenderCursors(SDL_Surface *screen) {
        if (flipFlop) {
-               for (vector<Vector<int> >::size_type i(0); i < positions.size(); ++i) {
+               for (vector<Vector<int> >::size_type i(0), end(positions.size());
+                               i != end; ++i) {
                        if (selected == int(i)) {
-                               battle->Res().swapCursor->DrawTopRight(screen, positions[i] + offset);
+                               battle->Res().swapCursor->DrawTopRight(screen, positions[i]);
                        }
                }
        }
        flipFlop = !flipFlop;
-       battle->Res().swapCursor->DrawTopRight(screen, positions[cursor] + offset + cursorOffset);
+       battle->Res().swapCursor->DrawTopRight(screen, positions[cursor] + cursorOffset);
 }
 
 }
index eec03917aa9006dc7e12bc2a9917ecc663643a09..1f98772a1952e208844c422c38f6d5c0761ed457 100644 (file)
@@ -5,12 +5,11 @@ namespace battle {
        class BattleState;
        class SelectMoveAction;
 }
-namespace math {
-       template<class>
-       class Vector;
-}
 
 #include "../../app/State.h"
+#include "../../math/Vector.h"
+
+#include <vector>
 
 namespace battle {
 
@@ -41,11 +40,14 @@ private:
        void MoveLeft();
 
 private:
-       void RenderCursors(SDL_Surface *screen, const math::Vector<int> &offset);
+       void RenderCursors(SDL_Surface *screen);
 
 private:
        BattleState *battle;
        SelectMoveAction *parent;
+       std::vector<math::Vector<int> > positions;
+       math::Vector<int> cursorOffset;
+       math::Vector<int> indicatorOffset;
        int cursor;
        int selected;
        bool flipFlop;