<Unit filename="src\common\TargetingMode.cpp" />
<Unit filename="src\common\TargetingMode.h" />
<Unit filename="src\common\fwd.h" />
- <Unit filename="src\geometry\Vector.h" />
- <Unit filename="src\geometry\fwd.h" />
<Unit filename="src\graphics\Animation.cpp" />
<Unit filename="src\graphics\Animation.h" />
<Unit filename="src\graphics\Camera.cpp" />
<Unit filename="src\map\Trigger.cpp" />
<Unit filename="src\map\Trigger.h" />
<Unit filename="src\map\fwd.h" />
+ <Unit filename="src\math\Vector.h" />
+ <Unit filename="src\math\fwd.h" />
<Unit filename="src\menu\CapsuleChangeMenu.cpp" />
<Unit filename="src\menu\CapsuleChangeMenu.h" />
<Unit filename="src\menu\CapsuleFeedMenu.cpp" />
#include "AttackTypeMenu.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Sprite.h"
-using geometry::Vector;
+using math::Vector;
namespace battle {
-void AttackTypeMenu::Render(SDL_Surface *screen, const geometry::Vector<int> &position) {
+void AttackTypeMenu::Render(SDL_Surface *screen, const math::Vector<int> &position) {
const Vector<int> &swordOffset(IconSize());
const Vector<int> magicOffset(IconWidth(), 0);
const Vector<int> defendOffset(2 * IconWidth(), IconHeight());
#define BATTLE_ATTACKTYPEMENU_H_
#include "AttackChoice.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Sprite.h"
#include <SDL.h>
public:
void Select(AttackChoice::Type t) { selected = t; }
AttackChoice::Type Selected() const { return selected; }
- void Render(SDL_Surface *screen, const geometry::Vector<int> &position);
+ void Render(SDL_Surface *screen, const math::Vector<int> &position);
int Width() const { return 3 * IconWidth(); }
int Height() const { return 3 * IconHeight(); }
- geometry::Vector<int> Size() const { return 3 * IconSize(); }
+ math::Vector<int> Size() const { return 3 * IconSize(); }
int IconWidth() const { return icons->Width(); }
int IconHeight() const { return icons->Height(); }
- const geometry::Vector<int> &IconSize() const { return icons->Size(); }
+ const math::Vector<int> &IconSize() const { return icons->Size(); }
private:
const graphics::Sprite *icons;
using common::Item;
using common::Spell;
using common::Stats;
-using geometry::Vector;
+using math::Vector;
using graphics::Menu;
using std::rand;
#include "../common/GameConfig.h"
#include "../common/fwd.h"
#include "../common/Stats.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Animation.h"
#include "../graphics/fwd.h"
#include "../graphics/Menu.h"
const Monster &MonsterAt(int index) const { assert(index >= 0 && index < NumHeroes()); return monsters[index]; }
const HeroTag &HeroTagAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroTags[index]; }
- const geometry::Vector<int> &HeroTagPositionAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroTagPositions[index]; }
+ const math::Vector<int> &HeroTagPositionAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroTagPositions[index]; }
Capsule &GetCapsule() { return capsule; }
bool Defeat() const;
public:
- geometry::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
- return geometry::Vector<int>(
+ math::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
+ return math::Vector<int>(
(screen->w - background->w) / 2,
(screen->h - background->h) / 2);
}
int Width() const { return background->w; }
int Height() const { return background->h; }
- geometry::Vector<int> Size() const { return geometry::Vector<int>(Width(), Height()); }
+ math::Vector<int> Size() const { return math::Vector<int>(Width(), Height()); }
- void RenderBackground(SDL_Surface *screen, const geometry::Vector<int> &offset);
- void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
- void RenderHeroes(SDL_Surface *screen, const geometry::Vector<int> &offset);
- void RenderCapsule(SDL_Surface *screen, const geometry::Vector<int> &offset);
- void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
- void RenderSmallHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
+ 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);
private:
virtual void OnEnterState(SDL_Surface *screen);
graphics::Menu<const common::Item *> itemMenu;
HeroTag heroTags[4];
SmallHeroTag smallHeroTags[4];
- geometry::Vector<int> heroTagPositions[4];
- geometry::Vector<int> smallHeroTagPositions[4];
+ math::Vector<int> heroTagPositions[4];
+ math::Vector<int> smallHeroTagPositions[4];
Capsule capsule;
int numHeroes;
int activeHero;
#include "AttackChoice.h"
#include "../common/Stats.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Animation.h"
#include "../graphics/fwd.h"
#include "../graphics/Menu.h"
const graphics::Animation *AttackAnimation() const;
const graphics::Animation *SpellAnimation() const;
- geometry::Vector<int> &Position() { return position; }
- const geometry::Vector<int> &Position() const { return position; }
+ math::Vector<int> &Position() { return position; }
+ const math::Vector<int> &Position() const { return position; }
AttackChoice &GetAttackChoice() { return attackChoice; }
const AttackChoice &GetAttackChoice() const { return attackChoice; }
int health;
graphics::AnimationRunner animation;
- geometry::Vector<int> position;
+ math::Vector<int> position;
AttackChoice attackChoice;
common::Stats stats;
#include "../common/fwd.h"
#include "../common/Hero.h"
#include "../common/Stats.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Animation.h"
#include "../graphics/fwd.h"
#include "../graphics/Menu.h"
const graphics::Animation *AttackAnimation() const { return master->AttackAnimation(); }
const graphics::Animation *SpellAnimation() const { return master->SpellAnimation(); }
- geometry::Vector<int> &Position() { return position; }
- const geometry::Vector<int> &Position() const { return position; }
+ math::Vector<int> &Position() { return position; }
+ const math::Vector<int> &Position() const { return position; }
graphics::Menu<const common::Spell *> &SpellMenu() { return spellMenu; }
const graphics::Menu<const common::Spell *> &SpellMenu() const { return spellMenu; }
graphics::AnimationRunner animation;
- geometry::Vector<int> position;
+ math::Vector<int> position;
graphics::Menu<const common::Spell *> spellMenu;
graphics::Menu<const common::Item *> ikariMenu;
#include "BattleState.h"
#include "Hero.h"
#include "Resources.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Font.h"
#include "../graphics/Frame.h"
#include "../graphics/Gauge.h"
#include "../graphics/Sprite.h"
-using geometry::Vector;
+using math::Vector;
using graphics::Frame;
namespace battle {
#include "fwd.h"
#include "Hero.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/fwd.h"
#include <SDL.h>
public:
const graphics::Sprite *HeroSprite() const;
- geometry::Vector<int> HeroOffset() const;
+ math::Vector<int> HeroOffset() const;
- void Render(SDL_Surface *screen, int width, int height, const geometry::Vector<int> &position, bool active) const;
+ void Render(SDL_Surface *screen, int width, int height, const math::Vector<int> &position, bool active) const;
private:
const BattleState *battle;
#include "AttackChoice.h"
#include "../common/fwd.h"
#include "../common/Stats.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Animation.h"
#include "../graphics/fwd.h"
const graphics::Animation *AttackAnimation() const { return attackAnimation; }
const graphics::Animation *SpellAnimation() const { return spellAnimation; }
- geometry::Vector<int> &Position() { return position; }
- const geometry::Vector<int> &Position() const { return position; }
+ math::Vector<int> &Position() { return position; }
+ const math::Vector<int> &Position() const { return position; }
// temporary setters until loader is implemented
public:
graphics::AnimationRunner animation;
- geometry::Vector<int> position;
+ math::Vector<int> position;
AttackChoice attackChoice;
#include "MoveMenu.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Sprite.h"
-using geometry::Vector;
+using math::Vector;
namespace battle {
-void MoveMenu::Render(SDL_Surface *screen, const geometry::Vector<int> &position) {
+void MoveMenu::Render(SDL_Surface *screen, const math::Vector<int> &position) {
Vector<int> attackOffset(0, IconHeight());
Vector<int> changeOffset(0, 0);
Vector<int> runOffset(0, 2 * IconHeight());
#ifndef BATTLE_MOVEMENU_H_
#define BATTLE_MOVEMENU_H_
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Sprite.h"
namespace battle {
public:
void Select(Icon i) { selected = i; }
Icon Selected() const { return selected; }
- void Render(SDL_Surface *screen, const geometry::Vector<int> &position);
+ void Render(SDL_Surface *screen, const math::Vector<int> &position);
int Width() const { return IconWidth(); }
int Height() const { return 3 * IconHeight(); }
#include "NumberAnimation.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Sprite.h"
using app::State;
-using geometry::Vector;
+using math::Vector;
using graphics::Animation;
using graphics::AnimationRunner;
using graphics::Sprite;
#define BATTLE_NUMBERANIMATION_H_
#include "../app/fwd.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Animation.h"
namespace battle {
int Width() const;
int Height() const;
- void Draw(SDL_Surface *dest, const geometry::Vector<int> &position) const;
+ void Draw(SDL_Surface *dest, const math::Vector<int> &position) const;
private:
int number;
#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
-using geometry::Vector;
+using math::Vector;
using loader::FieldDescription;
using loader::Interpreter;
using loader::TypeDescription;
#ifndef BATTLE_PARTYLAYOUT_H_
#define BATTLE_PARTYLAYOUT_H_
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include <cassert>
#include <vector>
PartyLayout() : positions(0), numPositions(0) { }
public:
- std::vector<geometry::Vector<int> >::size_type NumPositions() const { return numPositions; }
- void CalculatePositions(int width, int height, std::vector<geometry::Vector<int> > &dest) const;
- geometry::Vector<int> CalculatePosition(int index, int width, int height) const;
+ std::vector<math::Vector<int> >::size_type NumPositions() const { return numPositions; }
+ void CalculatePositions(int width, int height, std::vector<math::Vector<int> > &dest) const;
+ math::Vector<int> CalculatePosition(int index, int width, int height) const;
public:
- void SetPositions(const geometry::Vector<int> *p, int num) {
+ void SetPositions(const math::Vector<int> *p, int num) {
positions = p;
numPositions = num;
}
static void Construct(void *);
private:
- const geometry::Vector<int> *positions;
+ const math::Vector<int> *positions;
int numPositions;
};
#include "SmallHeroTag.h"
#include "BattleState.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Font.h"
#include "../graphics/Frame.h"
#include "../graphics/Gauge.h"
-using geometry::Vector;
+using math::Vector;
using graphics::Font;
using graphics::Frame;
using graphics::Sprite;
namespace battle {
-void SmallHeroTag::Render(SDL_Surface *screen, int width, int height, const geometry::Vector<int> &position) const {
+void SmallHeroTag::Render(SDL_Surface *screen, int width, int height, const math::Vector<int> &position) const {
const Resources &r(battle->Res());
const Frame *frame((index == battle->MaxHeroes() - 1) ? r.lastSmallHeroTagFrame : r.smallHeroTagFrame);
const Font *font(r.normalFont);
#define BATTLE_SMALLHEROTAG_H_
#include "fwd.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/fwd.h"
#include <SDL.h>
SmallHeroTag(const BattleState *battle, int heroIndex)
: battle(battle), index(heroIndex) { }
- void Render(SDL_Surface *screen, int width, int height, const geometry::Vector<int> &position) const;
+ void Render(SDL_Surface *screen, int width, int height, const math::Vector<int> &position) const;
private:
const BattleState *battle;
using app::Application;
using app::Input;
-using geometry::Vector;
+using math::Vector;
using graphics::AnimationRunner;
using std::vector;
}
}
-void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
+void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen, const math::Vector<int> &offset) const {
if (!targetAnimation.Valid() || !targetAnimation.Running()) return;
const TargetSelection &ts(battle->CurrentAttackAttackChoice().Selection());
if (ts.TargetsHeroes()) {
#include "../../app/State.h"
#include "../NumberAnimation.h"
-#include "../../geometry/Vector.h"
+#include "../../math/Vector.h"
#include "../../graphics/Animation.h"
#include <vector>
private:
void AddNumberAnimations(const TargetSelection &);
- void RenderTitleBar(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderNumbers(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ 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;
private:
BattleState *battle;
app::Timer<Uint32> titleBarTimer;
app::Timer<Uint32> targetAnimationTimer;
std::vector<NumberAnimation> numberAnimation;
- std::vector<geometry::Vector<int> > numberPosition;
+ std::vector<math::Vector<int> > numberPosition;
int cursor;
};
#include "../BattleState.h"
#include "../../app/Application.h"
#include "../../app/Input.h"
-#include "../../geometry/Vector.h"
+#include "../../math/Vector.h"
#include "../../graphics/Font.h"
#include "../../graphics/Frame.h"
using app::Application;
using app::Input;
-using geometry::Vector;
+using math::Vector;
namespace battle {
#include "../fwd.h"
#include "../../app/State.h"
-#include "../../geometry/Vector.h"
+#include "../../math/Vector.h"
namespace battle {
virtual void OnResize(int width, int height);
private:
- void RenderTitleBar(SDL_Surface *screen, const geometry::Vector<int> &offset);
+ void RenderTitleBar(SDL_Surface *screen, const math::Vector<int> &offset);
private:
BattleState *battle;
using app::Application;
using app::Input;
using common::Item;
-using geometry::Vector;
+using math::Vector;
namespace battle {
#include "../fwd.h"
#include "../../app/State.h"
-#include "../../geometry/Vector.h"
+#include "../../math/Vector.h"
namespace battle {
virtual void OnResize(int width, int height);
private:
- void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset);
+ void RenderMenu(SDL_Surface *screen, const math::Vector<int> &offset);
private:
BattleState *battle;
using app::Application;
using app::Input;
using common::Ikari;
-using geometry::Vector;
+using math::Vector;
using graphics::Frame;
namespace battle {
#include "../fwd.h"
#include "../../app/State.h"
-#include "../../geometry/Vector.h"
+#include "../../math/Vector.h"
namespace battle {
virtual void OnResize(int width, int height);
private:
- void RenderFrame(SDL_Surface *, const geometry::Vector<int> &offset);
- void RenderHeadline(SDL_Surface *, const geometry::Vector<int> &offset);
- void RenderMenu(SDL_Surface *, const geometry::Vector<int> &offset);
+ 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);
private:
BattleState *battle;
using app::Application;
using app::Input;
using common::Item;
-using geometry::Vector;
+using math::Vector;
using graphics::Frame;
namespace battle {
#include "../fwd.h"
#include "../../app/State.h"
-#include "../../geometry/Vector.h"
+#include "../../math/Vector.h"
namespace battle {
virtual void OnResize(int width, int height);
private:
- void RenderFrame(SDL_Surface *, const geometry::Vector<int> &offset);
- void RenderHeadline(SDL_Surface *, const geometry::Vector<int> &offset);
- void RenderMenu(SDL_Surface *, const geometry::Vector<int> &offset);
+ 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);
private:
BattleState *battle;
using app::Application;
using app::Input;
-using geometry::Vector;
+using math::Vector;
namespace battle {
#include "../fwd.h"
#include "../../app/State.h"
-#include "../../geometry/Vector.h"
+#include "../../math/Vector.h"
namespace battle {
virtual void OnResize(int width, int height);
private:
- void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset);
+ void RenderMenu(SDL_Surface *screen, const math::Vector<int> &offset);
private:
BattleState *battle;
using app::Application;
using app::Input;
using common::Spell;
-using geometry::Vector;
+using math::Vector;
using graphics::Frame;
namespace battle {
#include "../fwd.h"
#include "../../app/State.h"
-#include "../../geometry/Vector.h"
+#include "../../math/Vector.h"
namespace battle {
virtual void OnResize(int width, int height);
private:
- void RenderFrame(SDL_Surface *, const geometry::Vector<int> &offset);
- void RenderHeadline(SDL_Surface *, const geometry::Vector<int> &offset);
- void RenderMenu(SDL_Surface *, const geometry::Vector<int> &offset);
+ 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);
private:
BattleState *battle;
using app::Application;
using app::Input;
-using geometry::Vector;
+using math::Vector;
using std::vector;
namespace battle {
RenderCursors(screen, offset);
}
-void SelectTarget::RenderCursors(SDL_Surface *screen, const geometry::Vector<int> &offset) {
+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));
#include "../fwd.h"
#include "../../app/State.h"
-#include "../../geometry/Vector.h"
+#include "../../math/Vector.h"
#include "../../graphics/fwd.h"
namespace battle {
virtual void OnResize(int width, int height);
private:
- void RenderCursors(SDL_Surface *screen, const geometry::Vector<int> &offset);
+ void RenderCursors(SDL_Surface *screen, const math::Vector<int> &offset);
private:
BattleState *battle;
using app::Application;
using app::Input;
-using geometry::Vector;
+using math::Vector;
using std::vector;
namespace battle {
RenderCursors(screen, offset);
}
-void SwapHeroes::RenderCursors(SDL_Surface *screen, const geometry::Vector<int> &offset) {
+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);
#include "../fwd.h"
#include "../../app/State.h"
-#include "../../geometry/Vector.h"
+#include "../../math/Vector.h"
namespace battle {
void MoveLeft();
private:
- void RenderCursors(SDL_Surface *screen, const geometry::Vector<int> &offset);
+ void RenderCursors(SDL_Surface *screen, const math::Vector<int> &offset);
private:
BattleState *battle;
}
#include "../common/Stats.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include <SDL.h>
int MaxClass() const { return maxClass; }
int CurrentClass() const { return curClass; }
- const geometry::Vector<int> &AlignmentOffset() const { return alignmentCursor; }
+ const math::Vector<int> &AlignmentOffset() const { return alignmentCursor; }
const graphics::Sprite *AlignmentSprite() const { return alignmentSprite; }
void UpgradeClass();
const char *name;
const char *alignment;
- geometry::Vector<int> alignmentCursor;
+ math::Vector<int> alignmentCursor;
const graphics::Sprite *alignmentSprite;
int maxHealth;
#include <cstdlib>
-using geometry::Vector;
+using math::Vector;
namespace common {
#include "fwd.h"
#include "Script.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include <SDL.h>
void *AddressRegister(int n) const { return address[n]; }
int IntegerRegister(int n) const { return integer[n]; }
- const geometry::Vector<int> &VectorRegister(int n) const { return vector[n]; }
+ const math::Vector<int> &VectorRegister(int n) const { return vector[n]; }
private:
void Reset();
void *PopAddress();
Script::Code PopCode();
int PopInt();
- const geometry::Vector<int> &PopVector();
+ const math::Vector<int> &PopVector();
void Compare(int, int);
static const int numRegisters = 7;
void *address[numRegisters];
int integer[numRegisters];
- geometry::Vector<int> vector[numRegisters];
+ math::Vector<int> vector[numRegisters];
Uint8 compare;
+++ /dev/null
-#ifndef GEOMETRY_VECTOR_H_
-#define GEOMETRY_VECTOR_H_
-
-#include <cmath>
-#include <limits>
-#include <ostream>
-
-namespace geometry {
-
-/// Basic vector class with emphasis on graphical/computational ease of use
-/// rather than mathematical accuracy ;) .
-template<class Scalar>
-class Vector {
-
-public:
- Vector() : x(0), y(0) { }
- Vector(Scalar x, Scalar y) : x(x), y(y) { }
- template<class T>
- Vector(const Vector<T> &other) : x(other.X()), y(other.Y()) { };
- template<class T>
- Vector(T x, T y) : x(x), y(y) { }
-
-public:
- Scalar X() const { return x; }
- Scalar Y() const { return y; }
-
- Scalar &X() { return x; }
- Scalar &Y() { return y; }
-
- Scalar Index(Scalar lineLength) const { return Y() * lineLength + X(); }
- static Vector<Scalar> FromIndex(Scalar index, Scalar lineLength) {
- return Vector<Scalar>(index % lineLength, index / lineLength);
- }
-
- void Lock(const Vector<Scalar> &to);
-
-private:
- Scalar x, y;
-
-};
-
-
-template<class T>
-inline Vector<T> operator +(const Vector<T> &lhs, const Vector<T> &rhs) {
- return Vector<T>(lhs.X() + rhs.X(), lhs.Y() + rhs.Y());
-}
-template<class T, class U>
-inline Vector<T> operator +(const Vector<T> &lhs, const Vector<U> &rhs) {
- return Vector<T>(lhs.X() + rhs.X(), lhs.Y() + rhs.Y());
-}
-
-template<class T>
-inline Vector<T> &operator +=(Vector<T> &lhs, const Vector<T> &rhs) {
- return lhs = lhs + rhs;
-}
-template<class T, class U>
-inline Vector<T> &operator +=(Vector<T> &lhs, const Vector<U> &rhs) {
- return lhs = lhs + rhs;
-}
-
-template<class T>
-inline Vector<T> operator -(const Vector<T> &lhs, const Vector<T> &rhs) {
- return Vector<T>(lhs.X() - rhs.X(), lhs.Y() - rhs.Y());
-}
-template<class T, class U>
-inline Vector<T> operator -(const Vector<T> &lhs, const Vector<U> &rhs) {
- return Vector<T>(lhs.X() - rhs.X(), lhs.Y() - rhs.Y());
-}
-
-template<class T>
-inline Vector<T> &operator -=(Vector<T> &lhs, const Vector<T> &rhs) {
- return lhs = lhs - rhs;
-}
-template<class T, class U>
-inline Vector<T> &operator -=(Vector<T> &lhs, const Vector<U> &rhs) {
- return lhs = lhs - rhs;
-}
-
-template<class T>
-inline Vector<T> operator -(const Vector<T> &v) {
- return Vector<T>(-v.X(), -v.Y());
-}
-
-template<class T>
-inline Vector<T> operator *(const Vector<T> &v1, const Vector<T> &v2) {
- return Vector<T>(v1.X() * v2.X(), v1.Y() * v2.Y());
-}
-template<class T>
-inline Vector<T> operator *(const Vector<T> &v, T s) {
- return Vector<T>(v.X() * s, v.Y() * s);
-}
-template<class T>
-inline Vector<T> operator *(T s, const Vector<T> &v) {
- return Vector<T>(s * v.X(), s * v.Y());
-}
-
-template<class T>
-inline Vector<T> operator /(const Vector<T> &v1, const Vector<T> &v2) {
- return Vector<T>(v1.X() / v2.X(), v1.Y() / v2.Y());
-}
-template<class T>
-inline Vector<T> operator /(const Vector<T> &v, T s) {
- return Vector<T>(v.X() / s, v.Y() / s);
-}
-template<class T>
-inline Vector<T> operator /(T s, const Vector<T> &v) {
- return Vector<T>(s / v.X(), s / v.Y());
-}
-
-template<class T>
-inline Vector<T> operator %(const Vector<T> &v1, const Vector<T> &v2) {
- return Vector<T>(v1.X() % v2.X(), v1.Y() % v2.Y());
-}
-template<>
-inline Vector<float> operator %(const Vector<float> &v1, const Vector<float> &v2) {
- return Vector<float>(std::fmod(v1.X(), v2.X()), std::fmod(v1.Y(), v2.Y()));
-}
-template<>
-inline Vector<double> operator %(const Vector<double> &v1, const Vector<double> &v2) {
- return Vector<double>(std::fmod(v1.X(), v2.X()), std::fmod(v1.Y(), v2.Y()));
-}
-template<>
-inline Vector<long double> operator %(const Vector<long double> &v1, const Vector<long double> &v2) {
- return Vector<long double>(std::fmod(v1.X(), v2.X()), std::fmod(v1.Y(), v2.Y()));
-}
-template<class T>
-inline Vector<T> operator %(const Vector<T> &v, T s) {
- return Vector<T>(v.X() % s, v.Y() % s);
-}
-template<>
-inline Vector<float> operator %(const Vector<float> &v, float s) {
- return Vector<float>(std::fmod(v.X(), s), std::fmod(v.Y(), s));
-}
-template<>
-inline Vector<double> operator %(const Vector<double> &v, double s) {
- return Vector<double>(std::fmod(v.X(), s), std::fmod(v.Y(), s));
-}
-template<>
-inline Vector<long double> operator %(const Vector<long double> &v, long double s) {
- return Vector<long double>(std::fmod(v.X(), s), std::fmod(v.Y(), s));
-}
-
-template<class T>
-inline bool operator ==(const Vector<T> &lhs, const Vector<T> &rhs) {
- return lhs.X() == rhs.X() && lhs.Y() == rhs.Y();
-}
-
-template<class T>
-inline bool operator !=(const Vector<T> &lhs, const Vector<T> &rhs) {
- return lhs.X() != rhs.X() || lhs.Y() != rhs.Y();
-}
-
-template<class T>
-inline std::ostream &operator <<(std::ostream &out, const Vector<T> &v) {
- out << '<' << v.X() << ", " << v.Y() << '>';
- return out;
-}
-
-
-template <class Scalar>
-void Vector<Scalar>::Lock(const Vector<Scalar> &to) {
- Vector<Scalar> half(to / Scalar(2));
- Vector<Scalar> dist((*this) % to);
-
- if (dist.X() > half.X()) {
- x += (to.X() - dist.X());
- } else {
- x -= dist.X();
- }
-
- if (dist.Y() > half.Y()) {
- y += (to.Y() - dist.Y());
- } else {
- y -= dist.Y();
- }
-}
-
-
-}
-
-#endif /* GEOMETRY_VECTOR_H_ */
+++ /dev/null
-#ifndef GEOMERTY_FWD_H_
-#define GEOMERTY_FWD_H_
-
-namespace geometry {
-
-template<class Scalar>
-class Vector;
-
-}
-
-#endif /* GEOMERTY_FWD_H_ */
}
-void AnimationRunner::Draw(SDL_Surface *dest, geometry::Vector<int> position) const {
+void AnimationRunner::Draw(SDL_Surface *dest, math::Vector<int> position) const {
GetSprite()->Draw(dest,
position + animation->Offset(Frame()),
animation->Col(Frame()) + ColOffset(),
animation->Row(Frame()) + RowOffset());
}
-void AnimationRunner::DrawTopRight(SDL_Surface *dest, geometry::Vector<int> position) const {
- geometry::Vector<int> offset(-GetSprite()->Width(), 0);
+void AnimationRunner::DrawTopRight(SDL_Surface *dest, math::Vector<int> position) const {
+ math::Vector<int> offset(-GetSprite()->Width(), 0);
Draw(dest, position + offset);
}
-void AnimationRunner::DrawCenter(SDL_Surface *dest, geometry::Vector<int> position) const {
+void AnimationRunner::DrawCenter(SDL_Surface *dest, math::Vector<int> position) const {
Draw(dest, position - (GetSprite()->Size() / 2));
}
-void AnimationRunner::DrawCenterBottom(SDL_Surface *dest, geometry::Vector<int> position) const {
- geometry::Vector<int> offset(-GetSprite()->Width() / 2, -GetSprite()->Height());
+void AnimationRunner::DrawCenterBottom(SDL_Surface *dest, math::Vector<int> position) const {
+ math::Vector<int> offset(-GetSprite()->Width() / 2, -GetSprite()->Height());
Draw(dest, position + offset);
}
}
#include "../app/Timer.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include <memory>
#include <SDL.h>
virtual int NumFrames() const = 0;
virtual int Col(int frame) const = 0;
virtual int Row(int frame) const = 0;
- virtual geometry::Vector<int> Offset(int frame) const { return geometry::Vector<int>(); }
+ virtual math::Vector<int> Offset(int frame) const { return math::Vector<int>(); }
static void CreateTypeDescription();
void ChangeSprite(const Sprite *s) { sprite = s; }
const Sprite *GetSprite() const { return sprite ? sprite : animation->GetSprite(); }
- void Draw(SDL_Surface *dest, geometry::Vector<int> position) const;
- void DrawTopRight(SDL_Surface *dest, geometry::Vector<int> position) const;
- void DrawCenter(SDL_Surface *dest, geometry::Vector<int> position) const;
- void DrawCenterBottom(SDL_Surface *dest, geometry::Vector<int> position) const;
+ void Draw(SDL_Surface *dest, math::Vector<int> position) const;
+ void DrawTopRight(SDL_Surface *dest, math::Vector<int> position) const;
+ void DrawCenter(SDL_Surface *dest, math::Vector<int> position) const;
+ void DrawCenterBottom(SDL_Surface *dest, math::Vector<int> position) const;
int Frame() const;
#include <cassert>
-using geometry::Vector;
+using math::Vector;
namespace graphics {
#ifndef GRAPHICS_CAMERA_H_
#define GRAPHICS_CAMERA_H_
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
namespace graphics {
class Camera {
public:
- Camera(int width, int height, const geometry::Vector<float> *target);
+ Camera(int width, int height, const math::Vector<float> *target);
~Camera() { }
public:
void Resize(int w, int h) { halfWidth = w / 2; halfHeight = h / 2; }
- void SetTarget(const geometry::Vector<float> *t);
+ void SetTarget(const math::Vector<float> *t);
- geometry::Vector<int> CalculateOffset() const;
+ math::Vector<int> CalculateOffset() const;
private:
- const geometry::Vector<float> *target;
+ const math::Vector<float> *target;
int halfWidth;
int halfHeight;
#include <cstring>
-using geometry::Vector;
+using math::Vector;
using loader::FieldDescription;
using loader::Interpreter;
using loader::TypeDescription;
#ifndef GRAPHICS_CHARSELECT_H_
#define GRAPHICS_CHARSELECT_H_
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include <SDL.h>
static const int TYPE_ID = 411;
public:
- void Draw(SDL_Surface *screen, const geometry::Vector<int> &position) const;
+ void Draw(SDL_Surface *screen, const math::Vector<int> &position) const;
void NextCol();
void PreviousCol();
#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
-using geometry::Vector;
+using math::Vector;
using loader::FieldDescription;
using loader::Interpreter;
using loader::TypeDescription;
struct FrameProp {
static const int TYPE_ID = 403;
FrameProp() : col(0), row(0) { }
- FrameProp(int col, int row, const geometry::Vector<int> &disposition)
+ FrameProp(int col, int row, const math::Vector<int> &disposition)
: col(col), row(row), disposition(disposition) {}
int col;
int row;
- geometry::Vector<int> disposition;
+ math::Vector<int> disposition;
};
void SetFrames(const FrameProp *f, int num) { frames = f; numFrames = num; }
virtual int NumFrames() const;
virtual int Col(int frame) const;
virtual int Row(int frame) const;
- virtual geometry::Vector<int> Offset(int frame) const;
+ virtual math::Vector<int> Offset(int frame) const;
private:
const FrameProp *frames;
#include <cstring>
#include <iostream>
-using geometry::Vector;
+using math::Vector;
using loader::FieldDescription;
using loader::Interpreter;
using loader::TypeDescription;
#define GRAPHICS_FONT_H_
#include "Sprite.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include <SDL.h>
int StringWidth(const char *) const;
int StringHeight(const char *) const;
- void DrawChar(char c, SDL_Surface *dest, const geometry::Vector<int> &position) const;
- void DrawString(const char *s, SDL_Surface *dest, const geometry::Vector<int> &position, int maxWidth = 0) const;
- void DrawStringRight(const char *s, SDL_Surface *dest, const geometry::Vector<int> &position, int maxWidth = 0) const;
- void DrawDigit(int d, SDL_Surface *dest, const geometry::Vector<int> &position) const;
- void DrawNumber(int n, SDL_Surface *dest, const geometry::Vector<int> &position, int digits = 0) const;
- void DrawNumberRight(int n, SDL_Surface *dest, const geometry::Vector<int> &position, int digits = 0) const;
+ void DrawChar(char c, SDL_Surface *dest, const math::Vector<int> &position) const;
+ void DrawString(const char *s, SDL_Surface *dest, const math::Vector<int> &position, int maxWidth = 0) const;
+ void DrawStringRight(const char *s, SDL_Surface *dest, const math::Vector<int> &position, int maxWidth = 0) const;
+ void DrawDigit(int d, SDL_Surface *dest, const math::Vector<int> &position) const;
+ void DrawNumber(int n, SDL_Surface *dest, const math::Vector<int> &position, int digits = 0) const;
+ void DrawNumberRight(int n, SDL_Surface *dest, const math::Vector<int> &position, int digits = 0) const;
public:
void SetSprite(const Sprite *s) { sprite = s; }
#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
-using geometry::Vector;
+using math::Vector;
using loader::FieldDescription;
using loader::Interpreter;
using loader::TypeDescription;
#ifndef GRAPHICS_FRAME_H_
#define GRAPHICS_FRAME_H_
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include <SDL.h>
int MinHeight() const { return 2 * BorderHeight(); }
int BorderWidth() const { return BorderSize().X(); }
int BorderHeight() const { return BorderSize().Y(); }
- const geometry::Vector<int> BorderSize() const { return borderSize; }
+ const math::Vector<int> BorderSize() const { return borderSize; }
int RepeatWidth() const { return RepeatSize().X(); }
int RepeatHeight() const { return RepeatSize().Y(); }
- const geometry::Vector<int> RepeatSize() const { return repeatSize; }
- void Draw(SDL_Surface *dest, const geometry::Vector<int> &position, int width, int height) const;
+ const math::Vector<int> RepeatSize() const { return repeatSize; }
+ void Draw(SDL_Surface *dest, const math::Vector<int> &position, int width, int height) const;
public:
void SetSurface(SDL_Surface *s) { surface = s; }
- void SetBorderSize(const geometry::Vector<int> &s) { borderSize = s; }
- void SetRepeatSize(const geometry::Vector<int> &s) { repeatSize = s; }
- void SetOffset(const geometry::Vector<int> &o) { offset = o; }
+ void SetBorderSize(const math::Vector<int> &s) { borderSize = s; }
+ void SetRepeatSize(const math::Vector<int> &s) { repeatSize = s; }
+ void SetOffset(const math::Vector<int> &o) { offset = o; }
static void CreateTypeDescription();
static void Construct(void *);
private:
SDL_Surface *surface;
- geometry::Vector<int> borderSize;
- geometry::Vector<int> repeatSize;
- geometry::Vector<int> offset;
+ math::Vector<int> borderSize;
+ math::Vector<int> repeatSize;
+ math::Vector<int> offset;
};
#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
-using geometry::Vector;
+using math::Vector;
using loader::FieldDescription;
using loader::Interpreter;
using loader::TypeDescription;
#ifndef GRAPHICS_GAUGE_H_
#define GRAPHICS_GAUGE_H_
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include <SDL.h>
public:
int MinWidth() const { return startWidth + endWidth; }
int Height() const { return height; }
- void Draw(SDL_Surface *dest, const geometry::Vector<int> &position, int width, Uint8 fill) const;
+ void Draw(SDL_Surface *dest, const math::Vector<int> &position, int width, Uint8 fill) const;
public:
void SetSurface(SDL_Surface *s) { surface = s; }
- void SetFullOffset(const geometry::Vector<int> &o) { fullOffset = o; }
- void SetEmptyOffset(const geometry::Vector<int> &o) { emptyOffset = o; }
+ void SetFullOffset(const math::Vector<int> &o) { fullOffset = o; }
+ void SetEmptyOffset(const math::Vector<int> &o) { emptyOffset = o; }
void SetHeight(int h) { height = h; }
void SetStartWidth(int w) { startWidth = w; }
void SetRepeatWidth(int w) { repeatWidth = w; }
private:
SDL_Surface *surface;
- geometry::Vector<int> fullOffset;
- geometry::Vector<int> emptyOffset;
+ math::Vector<int> fullOffset;
+ math::Vector<int> emptyOffset;
int height;
int startWidth;
int repeatWidth;
#include "Font.h"
#include "fwd.h"
#include "Sprite.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include <algorithm>
#include <vector>
void Clear() { entries.clear(); }
void ClearEntry(int at) { entries[at] = Entry(0, T(), false); }
- void Draw(SDL_Surface *dest, const geometry::Vector<int> &position) const;
+ void Draw(SDL_Surface *dest, const math::Vector<int> &position) const;
private:
int GetRow(int index) const { return index / cols; }
template<class T>
-void Menu<T>::Draw(SDL_Surface *dest, const geometry::Vector<int> &position) const {
+void Menu<T>::Draw(SDL_Surface *dest, const math::Vector<int> &position) const {
int start(topRow * cols);
int slots(rows * cols);
int items(entries.size() - start);
int end(start + (items < slots ? items : slots));
for (int i(0), count(end - start); i < count; ++i) {
if (!entries[start + i].title) continue;
- geometry::Vector<int> iconOffset(
+ math::Vector<int> iconOffset(
(i % cols) * (ColWidth() + colGap),
(i / cols) * RowHeight());
// This fixes the position of the third column of the inventory and capsule menus.
if (thirdColumnHack && i % cols == 2) {
- iconOffset += geometry::Vector<int>(font->CharWidth() * thirdColumnHack, 0);
+ iconOffset += math::Vector<int>(font->CharWidth() * thirdColumnHack, 0);
}
if (entries[start + i].icon) {
entries[start + i].icon->Draw(dest, position + iconOffset);
}
- geometry::Vector<int> textOffset(iconOffset.X() + iconSpace, iconOffset.Y());
+ math::Vector<int> textOffset(iconOffset.X() + iconSpace, iconOffset.Y());
const Font *usedFont(entries[start + i].enabled ? font : disabledFont);
usedFont->DrawString(entries[start + i].title, dest, position + textOffset, charsPerEntry);
- textOffset += geometry::Vector<int>(charsPerEntry * usedFont->CharWidth(), 0);
+ textOffset += math::Vector<int>(charsPerEntry * usedFont->CharWidth(), 0);
if (charsPerAdditionalText) {
- textOffset += geometry::Vector<int>(additionalTextGap, 0);
+ textOffset += math::Vector<int>(additionalTextGap, 0);
if (entries[start + i].additionalText) {
usedFont->DrawString(entries[start + i].additionalText, dest, position + textOffset, charsPerAdditionalText);
}
- textOffset += geometry::Vector<int>(charsPerAdditionalText * usedFont->CharWidth(), 0);
+ textOffset += math::Vector<int>(charsPerAdditionalText * usedFont->CharWidth(), 0);
}
if (charsPerNumber) {
usedFont->DrawChar(delimiter, dest, position + textOffset);
- textOffset += geometry::Vector<int>(usedFont->CharWidth(), 0);
+ textOffset += math::Vector<int>(usedFont->CharWidth(), 0);
usedFont->DrawNumber(entries[start + i].number, dest, position + textOffset, charsPerNumber);
}
}
- geometry::Vector<int> cursorOffset(
+ math::Vector<int> cursorOffset(
(selected % cols) * (ColWidth() + colGap) - cursor->Width(),
((selected - start) / cols) * RowHeight());
// This fixes the position of the third column of the inventory and capsule menus.
if (thirdColumnHack && selected % cols == 2) {
- cursorOffset += geometry::Vector<int>(font->CharWidth() * thirdColumnHack, 0);
+ cursorOffset += math::Vector<int>(font->CharWidth() * thirdColumnHack, 0);
}
switch (state) {
case STATE_INACTIVE:
break;
case STATE_DUAL:
cursor->Draw(dest, position + cursorOffset
- - geometry::Vector<int>(selectedCursor->Width(), 0));
+ - math::Vector<int>(selectedCursor->Width(), 0));
if (secondarySelection >= start && secondarySelection <= end) {
- geometry::Vector<int> secondaryOffset(
+ math::Vector<int> secondaryOffset(
(secondarySelection % cols) * (ColWidth() + colGap) - cursor->Width(),
((secondarySelection - start) / cols) * RowHeight());
selectedCursor->Draw(dest, position + secondaryOffset);
#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
-using geometry::Vector;
+using math::Vector;
using loader::FieldDescription;
using loader::Interpreter;
using loader::TypeDescription;
#ifndef GRAPHICS_SPRITE_H_
#define GRAPHICS_SPRITE_H_
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include <SDL.h>
public:
int Width() const { return size.X(); }
int Height() const { return size.Y(); }
- const geometry::Vector<int> &Size() const { return size; }
- void Draw(SDL_Surface *dest, const geometry::Vector<int> &position, int col = 0, int row = 0) const;
- void DrawTopRight(SDL_Surface *dest, const geometry::Vector<int> &position, int col = 0, int row = 0) const {
- geometry::Vector<int> offset(-Width(), 0);
+ const math::Vector<int> &Size() const { return size; }
+ void Draw(SDL_Surface *dest, const math::Vector<int> &position, int col = 0, int row = 0) const;
+ void DrawTopRight(SDL_Surface *dest, const math::Vector<int> &position, int col = 0, int row = 0) const {
+ math::Vector<int> offset(-Width(), 0);
Draw(dest, position + offset, col, row);
}
- void DrawCenter(SDL_Surface *dest, const geometry::Vector<int> &position, int col = 0, int row = 0) const {
+ void DrawCenter(SDL_Surface *dest, const math::Vector<int> &position, int col = 0, int row = 0) const {
Draw(dest, position - (Size() / 2), col, row);
}
- void DrawCenterBottom(SDL_Surface *dest, const geometry::Vector<int> &position, int col = 0, int row = 0) const {
- geometry::Vector<int> offset(-Width() / 2, -Height());
+ void DrawCenterBottom(SDL_Surface *dest, const math::Vector<int> &position, int col = 0, int row = 0) const {
+ math::Vector<int> offset(-Width() / 2, -Height());
Draw(dest, position + offset, col, row);
}
public:
void SetSurface(SDL_Surface *s) { surface = s; }
- void SetSize(const geometry::Vector<int> &s) { size = s; }
- void SetOffset(const geometry::Vector<int> &o) { offset = o; }
+ void SetSize(const math::Vector<int> &s) { size = s; }
+ void SetOffset(const math::Vector<int> &o) { offset = o; }
static void CreateTypeDescription();
static void Construct(void *);
private:
SDL_Surface *surface;
- geometry::Vector<int> size;
- geometry::Vector<int> offset;
+ math::Vector<int> size;
+ math::Vector<int> offset;
};
#include "../loader/TypeDescription.h"
#include "../sdl/utility.h"
-using geometry::Vector;
+using math::Vector;
using loader::FieldDescription;
using loader::Interpreter;
using loader::TypeDescription;
#ifndef GRAPHICS_TEXTURE_H_
#define GRAPHICS_TEXTURE_H_
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include <SDL.h>
public:
explicit Texture(
SDL_Surface *surface = 0,
- const geometry::Vector<int> &size = geometry::Vector<int>(),
- const geometry::Vector<int> &offset = geometry::Vector<int>());
+ const math::Vector<int> &size = math::Vector<int>(),
+ const math::Vector<int> &offset = math::Vector<int>());
~Texture();
static const int TYPE_ID = 410;
public:
- void Render(SDL_Surface *dest, const geometry::Vector<int> &from, const geometry::Vector<int> &to) const;
+ void Render(SDL_Surface *dest, const math::Vector<int> &from, const math::Vector<int> &to) const;
public:
void SetSurface(SDL_Surface *s) { surface = s; }
- void SetSize(const geometry::Vector<int> &s) { size = s; }
- void SetOffset(const geometry::Vector<int> &o) { offset = o; }
+ void SetSize(const math::Vector<int> &s) { size = s; }
+ void SetOffset(const math::Vector<int> &o) { offset = o; }
static void CreateTypeDescription();
static void Construct(void *);
private:
SDL_Surface *surface;
- geometry::Vector<int> size;
- geometry::Vector<int> offset;
+ math::Vector<int> size;
+ math::Vector<int> offset;
};
using graphics::ComplexAnimation;
using graphics::SimpleAnimation;
using graphics::Sprite;
-using geometry::Vector;
+using math::Vector;
using std::make_pair;
using std::set;
using std::string;
#include "../battle/fwd.h"
#include "../common/fwd.h"
#include "../common/Script.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Color.h"
#include "../graphics/ComplexAnimation.h"
#include "../graphics/fwd.h"
#include "common/Script.h"
#include "common/Spell.h"
#include "common/Stats.h"
-#include "geometry/Vector.h"
+#include "math/Vector.h"
#include "graphics/CharSelect.h"
#include "graphics/ComplexAnimation.h"
#include "graphics/Font.h"
using common::GameState;
using common::Hero;
using common::Spell;
-using geometry::Vector;
+using math::Vector;
using graphics::Texture;
using loader::Caster;
using loader::Interpreter;
#include <stdexcept>
-using geometry::Vector;
+using math::Vector;
using loader::FieldDescription;
using loader::Interpreter;
using loader::TypeDescription;
}
-Tile *Area::TileAt(const geometry::Vector<int> &offset) {
+Tile *Area::TileAt(const math::Vector<int> &offset) {
int tileIndex(offset.Y() * width + offset.X());
if (tileIndex < numTiles) {
return tiles +tileIndex;
}
}
-const Tile *Area::TileAt(const geometry::Vector<int> &offset) const {
+const Tile *Area::TileAt(const math::Vector<int> &offset) const {
int tileIndex(offset.Y() * width + offset.X());
if (tileIndex < numTiles) {
return tiles +tileIndex;
#define MAP_AREA_H_
#include "fwd.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Sprite.h"
#include <SDL.h>
/// Get the height in tiles.
int Height() const { return numTiles / width + (numTiles % width ? 1 : 0); }
/// Get the size in tiles.
- geometry::Vector<int> Size() const { return geometry::Vector<int>(Width(), Height()); }
+ math::Vector<int> Size() const { return math::Vector<int>(Width(), Height()); }
/// Get a tile by tile coordinates (not pixel coordinates!).
- Tile *TileAt(const geometry::Vector<int> &);
- const Tile *TileAt(const geometry::Vector<int> &) const;
+ Tile *TileAt(const math::Vector<int> &);
+ const Tile *TileAt(const math::Vector<int> &) const;
/// Get the default battle background for this area.
SDL_Surface *BattleBackground() { return battlebg; }
- void Render(SDL_Surface *dest, const graphics::Sprite *tileset, const geometry::Vector<int> &offset) const;
- void RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const geometry::Vector<int> &offset) const;
+ void Render(SDL_Surface *dest, const graphics::Sprite *tileset, const math::Vector<int> &offset) const;
+ void RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const math::Vector<int> &offset) const;
static void CreateTypeDescription();
static void Construct(void *);
using battle::PartyLayout;
using graphics::Animation;
using graphics::Sprite;
-using geometry::Vector;
+using math::Vector;
using loader::FieldDescription;
using loader::Interpreter;
using loader::TypeDescription;
}
-bool Entity::TileLock(const geometry::Vector<int> &tileSize) const {
+bool Entity::TileLock(const math::Vector<int> &tileSize) const {
// TODO: change position to point to the top-left corner of a tile
Vector<int> tilePosition(position);
return (tilePosition.X() % tileSize.X() == 0) && (tilePosition.Y() % tileSize.Y() == 0);
#include "../battle/fwd.h"
#include "../battle/Monster.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/fwd.h"
#include "../graphics/Animation.h"
public:
/// Pixel resolved position of the entity's top left corner on the map.
- geometry::Vector<float> &Position() { return position; }
- const geometry::Vector<float> &Position() const { return position; }
+ math::Vector<float> &Position() { return position; }
+ const math::Vector<float> &Position() const { return position; }
/// Velocity of the entity in pixels per second.
- geometry::Vector<float> &Velocity() { return velocity; }
- const geometry::Vector<float> &Velocity() const { return velocity; }
+ math::Vector<float> &Velocity() { return velocity; }
+ const math::Vector<float> &Velocity() const { return velocity; }
/// Offset of the entity's sprite's to left corner relative to Position().
- geometry::Vector<int> &SpriteOffset() { return spriteOffset; }
- const geometry::Vector<int> &SpriteOffset() const { return spriteOffset; }
+ math::Vector<int> &SpriteOffset() { return spriteOffset; }
+ const math::Vector<int> &SpriteOffset() const { return spriteOffset; }
/// Reset the entity to the stored tile coordinates (usually set when
/// loading game data).
- void ResetPosition(const geometry::Vector<int> &tileSize) { position = tilePosition * tileSize; }
+ void ResetPosition(const math::Vector<int> &tileSize) { position = tilePosition * tileSize; }
/// Set the animation to use for animated entities.
/// For orientable entities, the animation should have north, south, east,
void RemoveFollower(Entity *);
/// Check if position locks into grid defined by given tileSize.
- bool TileLock(const geometry::Vector<int> &tileSize) const;
+ bool TileLock(const math::Vector<int> &tileSize) const;
/// Integrate this entity's physical properties over given time interval.
void Update(float deltaT);
- void Render(SDL_Surface *, const geometry::Vector<int> &offset) const;
+ void Render(SDL_Surface *, const math::Vector<int> &offset) const;
static void CreateTypeDescription();
static void Construct(void *);
battle::Monster **monsters;
int numMonsters;
graphics::AnimationRunner runner;
- geometry::Vector<int> spriteOffset;
- geometry::Vector<int> tilePosition;
- geometry::Vector<float> position;
- geometry::Vector<float> velocity;
+ math::Vector<int> spriteOffset;
+ math::Vector<int> tilePosition;
+ math::Vector<float> position;
+ math::Vector<float> velocity;
Orientation orientation;
float speed;
int flags;
#include <stdexcept>
-using geometry::Vector;
+using math::Vector;
using graphics::Sprite;
using loader::FieldDescription;
using loader::Interpreter;
}
}
-Trigger *Map::TriggerAt(const geometry::Vector<int> &offset) {
+Trigger *Map::TriggerAt(const math::Vector<int> &offset) {
// TODO: add support for multiple triggers on a tile?
Vector<int> coords(TileCoordinates(offset));
for (Trigger *i(triggers); i != triggers + numTriggers; ++i) {
return 0;
}
-SDL_Surface *Map::BattleBackgroundAt(const geometry::Vector<int> &position) {
+SDL_Surface *Map::BattleBackgroundAt(const math::Vector<int> &position) {
Tile *tile(TileAt(position));
if (tile && tile->BattleBackground()) {
return tile->BattleBackground();
#include "Entity.h"
#include "fwd.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/fwd.h"
#include <SDL.h>
/// The sprite used as the tileset.
const graphics::Sprite *Tileset() const { return tileset; }
/// Returns the Area at given pixel coordinates or 0 if off the map.
- Area *AreaAt(const geometry::Vector<int> &);
- const Area *AreaAt(const geometry::Vector<int> &) const;
+ Area *AreaAt(const math::Vector<int> &);
+ const Area *AreaAt(const math::Vector<int> &) const;
/// Returns the Tile at given pixel coordinates or 0 if off the map.
- Tile *TileAt(const geometry::Vector<int> &);
- const Tile *TileAt(const geometry::Vector<int> &) const;
+ Tile *TileAt(const math::Vector<int> &);
+ const Tile *TileAt(const math::Vector<int> &) const;
/// Returns the Trigger at given pixel coordinates or 0 if off the map.
/// Multiple triggers are not supported. The first one found is returned.
- Trigger *TriggerAt(const geometry::Vector<int> &);
+ Trigger *TriggerAt(const math::Vector<int> &);
/// The battle background image for this map if neither the tile nor the
/// area has one specified.
- SDL_Surface *BattleBackgroundAt(const geometry::Vector<int> &);
+ SDL_Surface *BattleBackgroundAt(const math::Vector<int> &);
/// Convert coordinates pixel to tile.
- geometry::Vector<int> TileCoordinates(const geometry::Vector<int> &) const;
+ math::Vector<int> TileCoordinates(const math::Vector<int> &) const;
Entity *EntitiesBegin() { return entities; }
Entity *EntitiesEnd() { return entities + numEntities; }
/// Render the map.
/// Entities are not rendered by this function.
- void Render(SDL_Surface *dest, const geometry::Vector<int> &offset) const;
+ void Render(SDL_Surface *dest, const math::Vector<int> &offset) const;
/// Render a debugging overlay that includes collision and trigger
/// information.
- void RenderDebug(SDL_Surface *dest, const geometry::Vector<int> &offset) const;
+ void RenderDebug(SDL_Surface *dest, const math::Vector<int> &offset) const;
static void CreateTypeDescription();
static void Construct(void *);
using app::Input;
using battle::BattleState;
using common::GameConfig;
-using geometry::Vector;
+using math::Vector;
using graphics::ColorFade;
using menu::PartyMenu;
#include "../common/fwd.h"
#include "../common/ScriptHost.h"
#include "../common/ScriptRunner.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Camera.h"
#include <vector>
void SetWalkingSpeed(float s) { walkingSpeed = s; }
- void Transition(Map *, const geometry::Vector<int> &coordinates);
+ void Transition(Map *, const math::Vector<int> &coordinates);
virtual void HandleSyscall(common::ScriptRunner &);
void LoadMap(Map *);
bool CheckBlocking();
- bool CheckBlocking(const geometry::Vector<int> &position, Entity::Orientation direction) const;
+ bool CheckBlocking(const math::Vector<int> &position, Entity::Orientation direction) const;
void OnTileLock();
bool OnGridLock();
Entity *pushed;
common::ScriptRunner runner;
app::Timer<float> moveTimer;
- geometry::Vector<int> lastLock;
+ math::Vector<int> lastLock;
graphics::Camera camera;
std::vector<Entity *> entities;
float walkingSpeed;
#ifndef MAP_TILE_H_
#define MAP_TILE_H_
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include <SDL.h>
SDL_Surface *BattleBackground() { return battlebg; }
- const geometry::Vector<int> &Offset() const { return offset; }
+ const math::Vector<int> &Offset() const { return offset; }
bool BlocksNorth() const { return flags & BLOCK_NORTH; }
bool BlocksEast() const { return flags & BLOCK_EAST; }
// temporary setters
public:
- Tile &SetOffset(const geometry::Vector<int> &o) { offset = o; return *this; }
+ Tile &SetOffset(const math::Vector<int> &o) { offset = o; return *this; }
Tile &SetFlags(Uint32 f) { flags = f; return *this; }
private:
SDL_Surface *battlebg;
- geometry::Vector<int> offset;
+ math::Vector<int> offset;
int flags;
};
using app::Application;
using app::State;
using app::Input;
-using geometry::Vector;
+using math::Vector;
namespace map {
#include "fwd.h"
#include "../app/State.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
namespace map {
: public app::State {
public:
- TransitionState(MapState *, Map *, const geometry::Vector<int> &);
+ TransitionState(MapState *, Map *, const math::Vector<int> &);
virtual ~TransitionState() { }
public:
private:
MapState *ms;
Map *map;
- const geometry::Vector<int> &coordinates;
+ const math::Vector<int> &coordinates;
};
#include "Entity.h"
#include "fwd.h"
#include "../common/Script.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
namespace map {
};
public:
- const geometry::Vector<int> &TilePosition() const { return tilePosition; }
+ const math::Vector<int> &TilePosition() const { return tilePosition; }
Type GetType() const { return Type(type); }
bool HasScript() const { return script; }
common::Script &GetScript() { return *script; }
// temporary setters
public:
- void SetTilePosition(const geometry::Vector<int> &p) { tilePosition = p; }
+ void SetTilePosition(const math::Vector<int> &p) { tilePosition = p; }
void SetType(Type t) { type = t; }
void SetScript(common::Script *s) { script = s; }
private:
common::Script *script;
- geometry::Vector<int> tilePosition;
+ math::Vector<int> tilePosition;
int type;
};
--- /dev/null
+#ifndef MATH_VECTOR_H_
+#define MATH_VECTOR_H_
+
+#include <cmath>
+#include <limits>
+#include <ostream>
+
+namespace math {
+
+/// Basic vector class with emphasis on graphical/computational ease of use
+/// rather than mathematical accuracy ;) .
+template<class Scalar>
+class Vector {
+
+public:
+ Vector() : x(0), y(0) { }
+ Vector(Scalar x, Scalar y) : x(x), y(y) { }
+ template<class T>
+ Vector(const Vector<T> &other) : x(other.X()), y(other.Y()) { };
+ template<class T>
+ Vector(T x, T y) : x(x), y(y) { }
+
+public:
+ Scalar X() const { return x; }
+ Scalar Y() const { return y; }
+
+ Scalar &X() { return x; }
+ Scalar &Y() { return y; }
+
+ Scalar Index(Scalar lineLength) const { return Y() * lineLength + X(); }
+ static Vector<Scalar> FromIndex(Scalar index, Scalar lineLength) {
+ return Vector<Scalar>(index % lineLength, index / lineLength);
+ }
+
+ void Lock(const Vector<Scalar> &to);
+
+private:
+ Scalar x, y;
+
+};
+
+
+template<class T>
+inline Vector<T> operator +(const Vector<T> &lhs, const Vector<T> &rhs) {
+ return Vector<T>(lhs.X() + rhs.X(), lhs.Y() + rhs.Y());
+}
+template<class T, class U>
+inline Vector<T> operator +(const Vector<T> &lhs, const Vector<U> &rhs) {
+ return Vector<T>(lhs.X() + rhs.X(), lhs.Y() + rhs.Y());
+}
+
+template<class T>
+inline Vector<T> &operator +=(Vector<T> &lhs, const Vector<T> &rhs) {
+ return lhs = lhs + rhs;
+}
+template<class T, class U>
+inline Vector<T> &operator +=(Vector<T> &lhs, const Vector<U> &rhs) {
+ return lhs = lhs + rhs;
+}
+
+template<class T>
+inline Vector<T> operator -(const Vector<T> &lhs, const Vector<T> &rhs) {
+ return Vector<T>(lhs.X() - rhs.X(), lhs.Y() - rhs.Y());
+}
+template<class T, class U>
+inline Vector<T> operator -(const Vector<T> &lhs, const Vector<U> &rhs) {
+ return Vector<T>(lhs.X() - rhs.X(), lhs.Y() - rhs.Y());
+}
+
+template<class T>
+inline Vector<T> &operator -=(Vector<T> &lhs, const Vector<T> &rhs) {
+ return lhs = lhs - rhs;
+}
+template<class T, class U>
+inline Vector<T> &operator -=(Vector<T> &lhs, const Vector<U> &rhs) {
+ return lhs = lhs - rhs;
+}
+
+template<class T>
+inline Vector<T> operator -(const Vector<T> &v) {
+ return Vector<T>(-v.X(), -v.Y());
+}
+
+template<class T>
+inline Vector<T> operator *(const Vector<T> &v1, const Vector<T> &v2) {
+ return Vector<T>(v1.X() * v2.X(), v1.Y() * v2.Y());
+}
+template<class T>
+inline Vector<T> operator *(const Vector<T> &v, T s) {
+ return Vector<T>(v.X() * s, v.Y() * s);
+}
+template<class T>
+inline Vector<T> operator *(T s, const Vector<T> &v) {
+ return Vector<T>(s * v.X(), s * v.Y());
+}
+
+template<class T>
+inline Vector<T> operator /(const Vector<T> &v1, const Vector<T> &v2) {
+ return Vector<T>(v1.X() / v2.X(), v1.Y() / v2.Y());
+}
+template<class T>
+inline Vector<T> operator /(const Vector<T> &v, T s) {
+ return Vector<T>(v.X() / s, v.Y() / s);
+}
+template<class T>
+inline Vector<T> operator /(T s, const Vector<T> &v) {
+ return Vector<T>(s / v.X(), s / v.Y());
+}
+
+template<class T>
+inline Vector<T> operator %(const Vector<T> &v1, const Vector<T> &v2) {
+ return Vector<T>(v1.X() % v2.X(), v1.Y() % v2.Y());
+}
+template<>
+inline Vector<float> operator %(const Vector<float> &v1, const Vector<float> &v2) {
+ return Vector<float>(std::fmod(v1.X(), v2.X()), std::fmod(v1.Y(), v2.Y()));
+}
+template<>
+inline Vector<double> operator %(const Vector<double> &v1, const Vector<double> &v2) {
+ return Vector<double>(std::fmod(v1.X(), v2.X()), std::fmod(v1.Y(), v2.Y()));
+}
+template<>
+inline Vector<long double> operator %(const Vector<long double> &v1, const Vector<long double> &v2) {
+ return Vector<long double>(std::fmod(v1.X(), v2.X()), std::fmod(v1.Y(), v2.Y()));
+}
+template<class T>
+inline Vector<T> operator %(const Vector<T> &v, T s) {
+ return Vector<T>(v.X() % s, v.Y() % s);
+}
+template<>
+inline Vector<float> operator %(const Vector<float> &v, float s) {
+ return Vector<float>(std::fmod(v.X(), s), std::fmod(v.Y(), s));
+}
+template<>
+inline Vector<double> operator %(const Vector<double> &v, double s) {
+ return Vector<double>(std::fmod(v.X(), s), std::fmod(v.Y(), s));
+}
+template<>
+inline Vector<long double> operator %(const Vector<long double> &v, long double s) {
+ return Vector<long double>(std::fmod(v.X(), s), std::fmod(v.Y(), s));
+}
+
+template<class T>
+inline bool operator ==(const Vector<T> &lhs, const Vector<T> &rhs) {
+ return lhs.X() == rhs.X() && lhs.Y() == rhs.Y();
+}
+
+template<class T>
+inline bool operator !=(const Vector<T> &lhs, const Vector<T> &rhs) {
+ return lhs.X() != rhs.X() || lhs.Y() != rhs.Y();
+}
+
+template<class T>
+inline std::ostream &operator <<(std::ostream &out, const Vector<T> &v) {
+ out << '<' << v.X() << ", " << v.Y() << '>';
+ return out;
+}
+
+
+template <class Scalar>
+void Vector<Scalar>::Lock(const Vector<Scalar> &to) {
+ Vector<Scalar> half(to / Scalar(2));
+ Vector<Scalar> dist((*this) % to);
+
+ if (dist.X() > half.X()) {
+ x += (to.X() - dist.X());
+ } else {
+ x -= dist.X();
+ }
+
+ if (dist.Y() > half.Y()) {
+ y += (to.Y() - dist.Y());
+ } else {
+ y -= dist.Y();
+ }
+}
+
+
+}
+
+#endif /* GEOMETRY_VECTOR_H_ */
--- /dev/null
+#ifndef MATH_FWD_H_
+#define MATH_FWD_H_
+
+namespace math {
+
+template<class Scalar>
+class Vector;
+
+}
+
+#endif /* MATH_FWD_H_ */
using common::Capsule;
using common::Inventory;
using common::Item;
-using geometry::Vector;
+using math::Vector;
using graphics::Font;
using graphics::Frame;
#include "fwd.h"
#include "../app/State.h"
#include "../common/fwd.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
namespace menu {
virtual void UpdateWorld(float deltaT);
virtual void Render(SDL_Surface *);
- void RenderClasses(SDL_Surface *, const geometry::Vector<int> &) const;
+ void RenderClasses(SDL_Surface *, const math::Vector<int> &) const;
public:
int Width() const;
using common::Capsule;
using common::Inventory;
using common::Item;
-using geometry::Vector;
+using math::Vector;
using graphics::Font;
using graphics::Frame;
#include "fwd.h"
#include "../app/State.h"
#include "../common/fwd.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Menu.h"
namespace menu {
void LoadInventory();
void FeedSelected();
- void RenderName(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderSprite(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderGrowth(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderHunger(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderItems(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderName(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderSprite(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderGrowth(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderHunger(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderMenu(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderItems(SDL_Surface *screen, const math::Vector<int> &offset) const;
private:
CapsuleMenu *parent;
using app::Input;
using common::Capsule;
using common::Stats;
-using geometry::Vector;
+using math::Vector;
using graphics::Font;
using graphics::Frame;
font.DrawNumberRight(capsule.NextLevel(), screen, lineHead);
}
-void CapsuleMenu::RenderStatsLine(SDL_Surface *screen, const geometry::Vector<int> &offset, const char *name, int value) const {
+void CapsuleMenu::RenderStatsLine(SDL_Surface *screen, const math::Vector<int> &offset, const char *name, int value) const {
const Font &font(*Res().statusFont);
const Vector<int> numberOffset(4 * font.CharWidth(), 0);
#include "fwd.h"
#include "../app/State.h"
#include "../common/fwd.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Menu.h"
namespace menu {
virtual void Render(SDL_Surface *);
void RenderBackground(SDL_Surface *screen) const;
- void RenderCapsule(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderInfo(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderWheel(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderStats(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderStatsLine(SDL_Surface *screen, const geometry::Vector<int> &offset, const char *name, int value) const;
- void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderCapsule(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderInfo(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderWheel(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderStats(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderStatsLine(SDL_Surface *screen, const math::Vector<int> &offset, const char *name, int value) const;
+ void RenderMenu(SDL_Surface *screen, const math::Vector<int> &offset) const;
public:
common::GameConfig &Game();
using common::Capsule;
using common::Inventory;
using common::Item;
-using geometry::Vector;
+using math::Vector;
using graphics::Font;
using graphics::Frame;
#include "fwd.h"
#include "../app/State.h"
#include "../common/fwd.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/CharSelect.h"
namespace menu {
void RemoveChar();
void StoreName();
- void RenderName(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderAlphabet(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderName(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderAlphabet(SDL_Surface *screen, const math::Vector<int> &offset) const;
private:
CapsuleMenu *parent;
#include <algorithm>
using app::Input;
-using geometry::Vector;
+using math::Vector;
using std::swap;
namespace menu {
#include "fwd.h"
#include "../app/State.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include <SDL.h>
void SelectedHero(int index);
- void RenderHighlight(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderHighlight(SDL_Surface *screen, const math::Vector<int> &offset) const;
static void OnHeroSelected(void *, int);
using app::Input;
using common::GameState;
-using geometry::Vector;
+using math::Vector;
using graphics::Font;
using graphics::Frame;
RenderMenu(screen, offset + menuOffset);
}
-void ConfigMenu::RenderHeadline(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
+void ConfigMenu::RenderHeadline(SDL_Surface *screen, const math::Vector<int> &offset) const {
const Font &font(*parent->Res().normalFont);
const Frame &frame(*parent->Res().statusFrame);
const Vector<int> textOffset(
font.DrawString(parent->Res().mainMenuConfigText, screen, offset + textOffset, 6);
}
-void ConfigMenu::RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
+void ConfigMenu::RenderMenu(SDL_Surface *screen, const math::Vector<int> &offset) const {
const Resources &res(parent->Res());
const Font &font(*res.normalFont);
const Font &inactiveFont(*res.inactiveFont);
#include "fwd.h"
#include "../app/State.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Menu.h"
namespace menu {
virtual void OnResize(int width, int height);
- void RenderHeadline(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderHeadline(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderMenu(SDL_Surface *screen, const math::Vector<int> &offset) const;
private:
PartyMenu *parent;
using common::Inventory;
using common::Item;
using common::Stats;
-using geometry::Vector;
+using math::Vector;
using graphics::Font;
using graphics::Frame;
#include "fwd.h"
#include "../app/State.h"
#include "../common/fwd.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Menu.h"
namespace menu {
void LoadInventory();
void EquipSelected();
- void RenderStatus(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderStats(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderStatsLine(const char *label, int number, SDL_Surface *screen, const geometry::Vector<int> &position) const;
- void RenderEquipmentMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderActionMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderInventoryMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderStatus(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderStats(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderStatsLine(const char *label, int number, SDL_Surface *screen, const math::Vector<int> &position) const;
+ void RenderEquipmentMenu(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderActionMenu(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderInventoryMenu(SDL_Surface *screen, const math::Vector<int> &offset) const;
private:
PartyMenu *parent;
#include "../graphics/Font.h"
#include "../graphics/Sprite.h"
-using geometry::Vector;
+using math::Vector;
namespace menu {
#include "fwd.h"
#include "../common/fwd.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include <SDL.h>
int Width() const;
int Height() const;
- geometry::Vector<int> Size() const { return geometry::Vector<int>(Width(), Height()); }
+ math::Vector<int> Size() const { return math::Vector<int>(Width(), Height()); }
- void Render(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void Render(SDL_Surface *screen, const math::Vector<int> &offset) const;
private:
const Resources *res;
using app::Input;
using common::Inventory;
using common::Item;
-using geometry::Vector;
+using math::Vector;
using graphics::Font;
using graphics::Frame;
using std::swap;
#include "fwd.h"
#include "../app/State.h"
#include "../common/fwd.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Menu.h"
namespace menu {
void LoadInventory();
- void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderInventory(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderMenu(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderInventory(SDL_Surface *screen, const math::Vector<int> &offset) const;
private:
PartyMenu *parent;
#include "../app/Input.h"
#include "../common/GameConfig.h"
#include "../common/GameState.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Font.h"
#include "../graphics/Frame.h"
#include "../graphics/Texture.h"
using app::Input;
using common::GameConfig;
-using geometry::Vector;
+using math::Vector;
namespace menu {
#include "HeroStatus.h"
#include "../app/State.h"
#include "../common/fwd.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Menu.h"
namespace menu {
public:
void RenderBackground(SDL_Surface *screen) const;
- void RenderHeros(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderInfo(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderHeros(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderMenu(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderInfo(SDL_Surface *screen, const math::Vector<int> &offset) const;
- geometry::Vector<int> StatusOffset(int index) const;
+ math::Vector<int> StatusOffset(int index) const;
const HeroStatus &GetHeroStatus(int index) const { return status[index]; }
static void OnEquipSelect(void *, int);
private:
HeroStatus status[4];
- geometry::Vector<int> statusPositions[4];
+ math::Vector<int> statusPositions[4];
common::GameConfig *game;
graphics::Menu<int> mainMenu;
using app::Input;
using common::Inventory;
using common::Item;
-using geometry::Vector;
+using math::Vector;
using graphics::Font;
using graphics::Frame;
return parent->Height();
}
-void ScenarioMenu::RenderHeadline(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
+void ScenarioMenu::RenderHeadline(SDL_Surface *screen, const math::Vector<int> &offset) const {
const Font &font(*parent->Res().normalFont);
const Frame &frame(*parent->Res().statusFrame);
const Vector<int> textOffset(2 * font.CharWidth(), font.CharHeight());
font.DrawString(parent->Res().scenarioMenuHeadline, screen, offset + textOffset);
}
-void ScenarioMenu::RenderItems(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
+void ScenarioMenu::RenderItems(SDL_Surface *screen, const math::Vector<int> &offset) const {
const Font &font(*parent->Res().normalFont);
const Frame &frame(*parent->Res().statusFrame);
const Vector<int> menuOffset(3 * font.CharWidth(), font.CharHeight() + font.CharHeight() / 4);
#include "fwd.h"
#include "../app/State.h"
#include "../common/fwd.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Menu.h"
namespace menu {
void LoadItems();
- void RenderHeadline(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderItems(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderHeadline(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderItems(SDL_Surface *screen, const math::Vector<int> &offset) const;
private:
PartyMenu *parent;
#include "../common/GameConfig.h"
#include "../common/GameState.h"
#include "../common/Hero.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Sprite.h"
using app::Input;
-using geometry::Vector;
+using math::Vector;
namespace menu {
using app::Input;
using common::Hero;
using common::Spell;
-using geometry::Vector;
+using math::Vector;
using graphics::Font;
using graphics::Frame;
using std::vector;
#include "fwd.h"
#include "../app/State.h"
#include "../common/fwd.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Menu.h"
namespace menu {
void LoadSpells();
- void RenderHighlight(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderSpells(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderHighlight(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderMenu(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderSpells(SDL_Surface *screen, const math::Vector<int> &offset) const;
private:
PartyMenu *parent;
using common::Hero;
using common::Item;
using common::Stats;
-using geometry::Vector;
+using math::Vector;
using graphics::Font;
using graphics::Frame;
}
}
-void StatusMenu::RenderExperience(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
+void StatusMenu::RenderExperience(SDL_Surface *screen, const math::Vector<int> &offset) const {
const Font &font(*parent->Res().statusFont);
font.DrawStringRight(parent->Res().experienceLabel, screen, offset, 10);
font.DrawNumberRight(GetHero().Experience(), screen, numberOffset, 7);
}
-void StatusMenu::RenderNextLevel(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
+void StatusMenu::RenderNextLevel(SDL_Surface *screen, const math::Vector<int> &offset) const {
const Font &font(*parent->Res().statusFont);
font.DrawStringRight(parent->Res().nextLevelLabel, screen, offset, 10);
font.DrawNumberRight(GetHero().NextLevel(), screen, numberOffset, 7);
}
-void StatusMenu::RenderIkari(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
+void StatusMenu::RenderIkari(SDL_Surface *screen, const math::Vector<int> &offset) const {
const Font &font(*parent->Res().statusFont);
font.DrawString(parent->Res().ipLabel, screen, offset, 5);
font.DrawChar('%', screen, percentOffset);
}
-void StatusMenu::RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
+void StatusMenu::RenderMenu(SDL_Surface *screen, const math::Vector<int> &offset) const {
const Font &font(*parent->Res().normalFont);
const Frame &frame(*parent->Res().statusFrame);
#include "fwd.h"
#include "../app/State.h"
#include "../common/fwd.h"
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include "../graphics/Menu.h"
namespace menu {
const common::Hero &GetHero() const;
- void RenderStatus(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderStats(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderStatsLine(const char *label, int number, SDL_Surface *screen, const geometry::Vector<int> &position) const;
- void RenderEquipment(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderEquipmentLine(const common::Item *, SDL_Surface *screen, const geometry::Vector<int> &position) const;
+ void RenderStatus(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderStats(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderStatsLine(const char *label, int number, SDL_Surface *screen, const math::Vector<int> &position) const;
+ void RenderEquipment(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderEquipmentLine(const common::Item *, SDL_Surface *screen, const math::Vector<int> &position) const;
/// @param offset the top right corner!
- void RenderExperience(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderExperience(SDL_Surface *screen, const math::Vector<int> &offset) const;
/// @param offset the top right corner!
- void RenderNextLevel(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderIkari(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
- void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderNextLevel(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderIkari(SDL_Surface *screen, const math::Vector<int> &offset) const;
+ void RenderMenu(SDL_Surface *screen, const math::Vector<int> &offset) const;
private:
PartyMenu *parent;
#include <cmath>
-using geometry::Vector;
+using math::Vector;
namespace sdl {
SDL_FillRect(dst, &destRect, color);
}
-void VerticalLine(SDL_Surface *dst, const geometry::Vector<int> &position, unsigned int length, Uint32 color) {
+void VerticalLine(SDL_Surface *dst, const math::Vector<int> &position, unsigned int length, Uint32 color) {
SDL_Rect destRect;
destRect.x = position.X();
destRect.y = position.Y();
#ifndef SDL_UTILITY_H_
#define SDL_UTILITY_H_
-#include "../geometry/Vector.h"
+#include "../math/Vector.h"
#include <SDL.h>
namespace sdl {
-void HorizontalLine(SDL_Surface *dst, const geometry::Vector<int> &position, unsigned int length, Uint32 color);
-void VerticalLine(SDL_Surface *dst, const geometry::Vector<int> &position, unsigned int length, Uint32 color);
+void HorizontalLine(SDL_Surface *dst, const math::Vector<int> &position, unsigned int length, Uint32 color);
+void VerticalLine(SDL_Surface *dst, const math::Vector<int> &position, unsigned int length, Uint32 color);
-void OutlineRect(SDL_Surface *dst, const geometry::Vector<int> &from, const geometry::Vector<int> &to, Uint32 color);
+void OutlineRect(SDL_Surface *dst, const math::Vector<int> &from, const math::Vector<int> &to, Uint32 color);
void OutlineRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color);
}
+++ /dev/null
-#include "VectorTest.h"
-
-#include <limits>
-
-CPPUNIT_TEST_SUITE_REGISTRATION(test_geometry::VectorTest);
-
-using geometry::Vector;
-
-
-namespace test_geometry {
-
-void VectorTest::setUp() {
-
-}
-
-void VectorTest::tearDown() {
-
-}
-
-
-void VectorTest::testComparison() {
- CPPUNIT_ASSERT_EQUAL(Vector<int>(0, 0), Vector<int>(0, 0));
-
- CPPUNIT_ASSERT(Vector<int>(0, 0) != Vector<int>(0, 1));
- CPPUNIT_ASSERT(Vector<int>(0, 0) != Vector<int>(1, 0));
- CPPUNIT_ASSERT(Vector<int>(0, 0) != Vector<int>(1, 1));
-}
-
-void VectorTest::testSum() {
- CPPUNIT_ASSERT_EQUAL(
- Vector<int>(1, 1),
- Vector<int>(1, 1) + Vector<int>(0, 0));
- CPPUNIT_ASSERT_EQUAL(
- Vector<int>(1, 1),
- Vector<int>(0, 1) + Vector<int>(1, 0));
-
- CPPUNIT_ASSERT_EQUAL(
- Vector<int>(1, 1),
- Vector<int>(1, 1) - Vector<int>(0, 0));
- CPPUNIT_ASSERT_EQUAL(
- Vector<int>(0, 1),
- Vector<int>(1, 1) - Vector<int>(1, 0));
-}
-
-void VectorTest::testProduct() {
- CPPUNIT_ASSERT_EQUAL(
- Vector<int>(2, 3),
- Vector<int>(2, 3) * Vector<int>(1, 1));
- CPPUNIT_ASSERT_EQUAL(
- Vector<int>(10, 12),
- Vector<int>(2, 3) * Vector<int>(5, 4));
- CPPUNIT_ASSERT_EQUAL(
- Vector<int>(2, 3),
- Vector<int>(2, 3) * 1);
- CPPUNIT_ASSERT_EQUAL(
- Vector<int>(4, 6),
- Vector<int>(2, 3) * 2);
- CPPUNIT_ASSERT_EQUAL(
- Vector<int>(2, 3),
- 1 * Vector<int>(2, 3));
- CPPUNIT_ASSERT_EQUAL(
- Vector<int>(4, 6),
- 2 * Vector<int>(2, 3));
-
- CPPUNIT_ASSERT_EQUAL(
- Vector<int>(10, 12),
- Vector<int>(10, 12) / Vector<int>(1, 1));
- CPPUNIT_ASSERT_EQUAL(
- Vector<int>(2, 3),
- Vector<int>(10, 12) / Vector<int>(5, 4));
- CPPUNIT_ASSERT_EQUAL(
- Vector<int>(4, 6),
- Vector<int>(4, 6) / 1);
- CPPUNIT_ASSERT_EQUAL(
- Vector<int>(2, 3),
- Vector<int>(4, 6) / 2);
- CPPUNIT_ASSERT_EQUAL(
- Vector<int>(3, 4),
- 12 / Vector<int>(4, 3));
-}
-
-void VectorTest::testModulo() {
- CPPUNIT_ASSERT_EQUAL(
- Vector<int>(0, 0),
- Vector<int>(1, 2) % Vector<int>(1, 1));
- CPPUNIT_ASSERT_EQUAL(
- Vector<int>(0, 0),
- Vector<int>(1, 2) % 1);
- CPPUNIT_ASSERT_EQUAL(
- Vector<int>(3, 1),
- Vector<int>(3, 5) % Vector<int>(4, 2));
- CPPUNIT_ASSERT_EQUAL(
- Vector<int>(3, 1),
- Vector<int>(3, 5) % 4);
-
- Vector<float> vecf = Vector<float>(4.0f, 5.0f) % Vector<float>(2.0f, 3.0f);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, vecf.X(), std::numeric_limits<float>::epsilon());
- CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0f, vecf.Y(), std::numeric_limits<float>::epsilon());
-
- vecf = Vector<float>(4.0f, 5.0f) % 4.0f;
- CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, vecf.X(), std::numeric_limits<float>::epsilon());
- CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0f, vecf.Y(), std::numeric_limits<float>::epsilon());
-
- Vector<double> vecd = Vector<double>(4.0, 5.0) % Vector<double>(2.0, 3.0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, vecd.X(), std::numeric_limits<double>::epsilon());
- CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, vecd.Y(), std::numeric_limits<double>::epsilon());
-
- vecd = Vector<double>(4.0, 5.0) % 4.0;
- CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, vecd.X(), std::numeric_limits<double>::epsilon());
- CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, vecd.Y(), std::numeric_limits<double>::epsilon());
-}
-
-void VectorTest::testFunctional() {
- const Vector<int> vec(2, 5);
- CPPUNIT_ASSERT_EQUAL(2, vec.X());
- CPPUNIT_ASSERT_EQUAL(5, vec.Y());
- CPPUNIT_ASSERT_EQUAL(52, vec.Index(10));
-
- const Vector<int> indexVec = Vector<int>::FromIndex(52, 10);
- CPPUNIT_ASSERT_EQUAL(vec, indexVec);
-
- Vector<int> lockedVec = Vector<int>(vec);
- lockedVec.Lock(Vector<int>(2, 2));
- CPPUNIT_ASSERT_EQUAL(Vector<int>(2, 4), lockedVec);
-}
-
-}
+++ /dev/null
-#ifndef TEST_GEOMETRY_VECTORTEST_H_
-#define TEST_GEOMETRY_VECTORTEST_H_
-
-#include "../../src/geometry/Vector.h"
-
-#include <cppunit/extensions/HelperMacros.h>
-
-
-namespace test_geometry {
-
-class VectorTest
-: public CppUnit::TestFixture {
-
-CPPUNIT_TEST_SUITE(VectorTest);
-CPPUNIT_TEST(testComparison);
-CPPUNIT_TEST(testSum);
-CPPUNIT_TEST(testProduct);
-CPPUNIT_TEST(testModulo);
-CPPUNIT_TEST(testFunctional);
-CPPUNIT_TEST_SUITE_END();
-
-public:
- void setUp();
- void tearDown();
-
- void testComparison();
- void testSum();
- void testProduct();
- void testModulo();
- void testFunctional();
-
-};
-
-}
-
-#endif
--- /dev/null
+#include "VectorTest.h"
+
+#include <limits>
+
+CPPUNIT_TEST_SUITE_REGISTRATION(test_math::VectorTest);
+
+using math::Vector;
+
+
+namespace test_math {
+
+void VectorTest::setUp() {
+
+}
+
+void VectorTest::tearDown() {
+
+}
+
+
+void VectorTest::testComparison() {
+ CPPUNIT_ASSERT_EQUAL(Vector<int>(0, 0), Vector<int>(0, 0));
+
+ CPPUNIT_ASSERT(Vector<int>(0, 0) != Vector<int>(0, 1));
+ CPPUNIT_ASSERT(Vector<int>(0, 0) != Vector<int>(1, 0));
+ CPPUNIT_ASSERT(Vector<int>(0, 0) != Vector<int>(1, 1));
+}
+
+void VectorTest::testSum() {
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(1, 1),
+ Vector<int>(1, 1) + Vector<int>(0, 0));
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(1, 1),
+ Vector<int>(0, 1) + Vector<int>(1, 0));
+
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(1, 1),
+ Vector<int>(1, 1) - Vector<int>(0, 0));
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(0, 1),
+ Vector<int>(1, 1) - Vector<int>(1, 0));
+}
+
+void VectorTest::testProduct() {
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(2, 3),
+ Vector<int>(2, 3) * Vector<int>(1, 1));
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(10, 12),
+ Vector<int>(2, 3) * Vector<int>(5, 4));
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(2, 3),
+ Vector<int>(2, 3) * 1);
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(4, 6),
+ Vector<int>(2, 3) * 2);
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(2, 3),
+ 1 * Vector<int>(2, 3));
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(4, 6),
+ 2 * Vector<int>(2, 3));
+
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(10, 12),
+ Vector<int>(10, 12) / Vector<int>(1, 1));
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(2, 3),
+ Vector<int>(10, 12) / Vector<int>(5, 4));
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(4, 6),
+ Vector<int>(4, 6) / 1);
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(2, 3),
+ Vector<int>(4, 6) / 2);
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(3, 4),
+ 12 / Vector<int>(4, 3));
+}
+
+void VectorTest::testModulo() {
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(0, 0),
+ Vector<int>(1, 2) % Vector<int>(1, 1));
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(0, 0),
+ Vector<int>(1, 2) % 1);
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(3, 1),
+ Vector<int>(3, 5) % Vector<int>(4, 2));
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(3, 1),
+ Vector<int>(3, 5) % 4);
+
+ Vector<float> vecf = Vector<float>(4.0f, 5.0f) % Vector<float>(2.0f, 3.0f);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, vecf.X(), std::numeric_limits<float>::epsilon());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0f, vecf.Y(), std::numeric_limits<float>::epsilon());
+
+ vecf = Vector<float>(4.0f, 5.0f) % 4.0f;
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, vecf.X(), std::numeric_limits<float>::epsilon());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0f, vecf.Y(), std::numeric_limits<float>::epsilon());
+
+ Vector<double> vecd = Vector<double>(4.0, 5.0) % Vector<double>(2.0, 3.0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, vecd.X(), std::numeric_limits<double>::epsilon());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, vecd.Y(), std::numeric_limits<double>::epsilon());
+
+ vecd = Vector<double>(4.0, 5.0) % 4.0;
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, vecd.X(), std::numeric_limits<double>::epsilon());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, vecd.Y(), std::numeric_limits<double>::epsilon());
+}
+
+void VectorTest::testFunctional() {
+ const Vector<int> vec(2, 5);
+ CPPUNIT_ASSERT_EQUAL(2, vec.X());
+ CPPUNIT_ASSERT_EQUAL(5, vec.Y());
+ CPPUNIT_ASSERT_EQUAL(52, vec.Index(10));
+
+ const Vector<int> indexVec = Vector<int>::FromIndex(52, 10);
+ CPPUNIT_ASSERT_EQUAL(vec, indexVec);
+
+ Vector<int> lockedVec = Vector<int>(vec);
+ lockedVec.Lock(Vector<int>(2, 2));
+ CPPUNIT_ASSERT_EQUAL(Vector<int>(2, 4), lockedVec);
+}
+
+}
--- /dev/null
+#ifndef TEST_MATH_VECTORTEST_H_
+#define TEST_MATH_VECTORTEST_H_
+
+#include "../../src/math/Vector.h"
+
+#include <cppunit/extensions/HelperMacros.h>
+
+
+namespace test_math {
+
+class VectorTest
+: public CppUnit::TestFixture {
+
+CPPUNIT_TEST_SUITE(VectorTest);
+CPPUNIT_TEST(testComparison);
+CPPUNIT_TEST(testSum);
+CPPUNIT_TEST(testProduct);
+CPPUNIT_TEST(testModulo);
+CPPUNIT_TEST(testFunctional);
+CPPUNIT_TEST_SUITE_END();
+
+public:
+ void setUp();
+ void tearDown();
+
+ void testComparison();
+ void testSum();
+ void testProduct();
+ void testModulo();
+ void testFunctional();
+
+};
+
+}
+
+#endif