Removed string/vector typedefs.

This commit is contained in:
Felix Ableitner 2012-12-22 15:10:26 +01:00
parent a157f0857d
commit 7c4eb47f2e
27 changed files with 125 additions and 203 deletions

View file

@ -7,11 +7,12 @@
#include "Game.h" #include "Game.h"
#include <string>
#include <Thor/Graphics.hpp> #include <Thor/Graphics.hpp>
#include "abstract/Character.h" #include "abstract/Character.h"
#include "sprites/Enemy.h" #include "sprites/Enemy.h"
#include "types/String.h"
#include "util/Loader.h" #include "util/Loader.h"
#include "util/ResourceManager.h" #include "util/ResourceManager.h"
@ -23,7 +24,7 @@ const int Game::FPS_GOAL = 60;
*/ */
Game::Game(sf::RenderWindow& window) : Game::Game(sf::RenderWindow& window) :
mWindow(window), mWindow(window),
mView(Vector2f(0, 0), mWindow.getView().getSize()), mView(sf::Vector2f(0, 0), mWindow.getView().getSize()),
mTileManager(mWorld), mTileManager(mWorld),
mQuit(false), mQuit(false),
mPaused(false) { mPaused(false) {
@ -50,10 +51,10 @@ Game::generate() {
mTileManager.setTile(TileManager::TilePosition(x, 4), TileManager::Type::WALL); mTileManager.setTile(TileManager::TilePosition(x, 4), TileManager::Type::WALL);
mWorld.insert(std::shared_ptr<Sprite>(new Enemy(mWorld, mPathfinder, mWorld.insert(std::shared_ptr<Sprite>(new Enemy(mWorld, mPathfinder,
Vector2f(400.0f, 200.0f), Yaml("enemy.yaml")))); sf::Vector2f(400.0f, 200.0f), Yaml("enemy.yaml"))));
mPlayer = std::shared_ptr<Player>(new Player(mWorld, mPathfinder, mPlayer = std::shared_ptr<Player>(new Player(mWorld, mPathfinder,
Vector2f(200.0f, 100.0f), Yaml("player.yaml"))); sf::Vector2f(200.0f, 100.0f), Yaml("player.yaml")));
mWorld.insert(mPlayer); mWorld.insert(mPlayer);
} }
/** /**
@ -172,7 +173,7 @@ Game::keyDown(const sf::Event& event) {
*/ */
sf::Vector2<float> sf::Vector2<float>
Game::convertCoordinates(int x, int y) { Game::convertCoordinates(int x, int y) {
return mWindow.convertCoords(Vector2i(x, y), mView); return mWindow.convertCoords(sf::Vector2i(x, y), mView);
} }
/** /**

View file

@ -8,6 +8,8 @@
#ifndef DG_GAME_H_ #ifndef DG_GAME_H_
#define DG_GAME_H_ #define DG_GAME_H_
#include <string>
#include <SFML/System.hpp> #include <SFML/System.hpp>
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
@ -15,7 +17,6 @@
#include "sprites/TileManager.h" #include "sprites/TileManager.h"
#include "sprites/Player.h" #include "sprites/Player.h"
#include "types/String.h"
#include "World.h" #include "World.h"
#include "util/Pathfinder.h" #include "util/Pathfinder.h"

View file

@ -11,15 +11,15 @@
#include <Thor/Vectors.hpp> #include <Thor/Vectors.hpp>
const String Body::KEY_SIZE = "size"; const std::string Body::KEY_SIZE = "size";
const Vector2i Body::DEFAULT_SIZE = Vector2i(50, 50); const sf::Vector2i Body::DEFAULT_SIZE = sf::Vector2i(50, 50);
/** /**
* Initializes Box2D body. * Initializes Box2D body.
* *
* @param data Data needed for construction. * @param data Data needed for construction.
*/ */
Body::Body(const Data& data, const Yaml& config, const Vector2i& pSize) : Body::Body(const Data& data, const Yaml& config, const sf::Vector2i& pSize) :
mPosition(data.position), mPosition(data.position),
mSize(config.get(KEY_SIZE, DEFAULT_SIZE)), mSize(config.get(KEY_SIZE, DEFAULT_SIZE)),
mAngle(0), mAngle(0),
@ -37,7 +37,7 @@ Body::~Body() {
/** /**
* Initializes container. * Initializes container.
*/ */
Body::Data::Data(const Vector2f& position, float angle, Body::Data::Data(const sf::Vector2f& position, float angle,
Category category, unsigned short maskExclude) : Category category, unsigned short maskExclude) :
position(position), position(position),
angle(angle), angle(angle),
@ -48,7 +48,7 @@ Body::Data::Data(const Vector2f& position, float angle,
/** /**
* Returns the position of the sprite (center). * Returns the position of the sprite (center).
*/ */
Vector2f sf::Vector2f
Body::getPosition() const { Body::getPosition() const {
return mPosition; return mPosition;
} }
@ -56,7 +56,7 @@ Body::getPosition() const {
/** /**
* Returns the movement speed of the body. * Returns the movement speed of the body.
*/ */
Vector2f sf::Vector2f
Body::getSpeed() const { Body::getSpeed() const {
return mSpeed; return mSpeed;
} }
@ -88,7 +88,7 @@ Body::getCategory() const {
/** /**
* Returns the size of the body as a vector. * Returns the size of the body as a vector.
*/ */
Vector2i sf::Vector2i
Body::getSize() const { Body::getSize() const {
return mSize; return mSize;
} }
@ -131,8 +131,8 @@ Body::setDelete(bool value) {
* @param speed The value of the movement speed to be used. * @param speed The value of the movement speed to be used.
*/ */
void void
Body::setSpeed(Vector2f direction, float speed) { Body::setSpeed(sf::Vector2f direction, float speed) {
if (direction != Vector2f()) { if (direction != sf::Vector2f()) {
thor::setLength(direction, speed); thor::setLength(direction, speed);
} }
mSpeed = direction; mSpeed = direction;

View file

@ -8,8 +8,6 @@
#ifndef DG_BODY_H_ #ifndef DG_BODY_H_
#define DG_BODY_H_ #define DG_BODY_H_
#include "../types/String.h"
#include "../types/Vector.h"
#include "../util/Yaml.h" #include "../util/Yaml.h"
class Yaml; class Yaml;
@ -42,8 +40,8 @@ public:
class Data { class Data {
public: public:
Data() = default; Data() = default;
Data(const Vector2f& position, float angle, Category category, unsigned short maskExclude); Data(const sf::Vector2f& position, float angle, Category category, unsigned short maskExclude);
const Vector2f& position; const sf::Vector2f& position;
float angle; float angle;
Category category; Category category;
unsigned short mask; unsigned short mask;
@ -59,35 +57,35 @@ public:
// Public functions. // Public functions.
public: public:
Body(const Data& data, const Yaml& config, const Vector2i& pSize = Vector2i()); Body(const Data& data, const Yaml& config, const sf::Vector2i& pSize = sf::Vector2i());
virtual ~Body() = 0; virtual ~Body() = 0;
Vector2f getPosition() const; sf::Vector2f getPosition() const;
Vector2f getSpeed() const; sf::Vector2f getSpeed() const;
float getAngle() const; float getAngle() const;
bool getDelete() const; bool getDelete() const;
Category getCategory() const; Category getCategory() const;
Vector2i getSize() const; sf::Vector2i getSize() const;
virtual bool doesCollide(Body& other); virtual bool doesCollide(Body& other);
virtual void onCollide(Body& other, Category category); virtual void onCollide(Body& other, Category category);
// Public variables. // Public variables.
public: public:
static const String KEY_SIZE; static const std::string KEY_SIZE;
static const Vector2i DEFAULT_SIZE; static const sf::Vector2i DEFAULT_SIZE;
// Protected functions. // Protected functions.
protected: protected:
void setDelete(bool value); void setDelete(bool value);
void setSpeed(Vector2f direction, float speed); void setSpeed(sf::Vector2f direction, float speed);
void setAngle(float angle); void setAngle(float angle);
// Private variables. // Private variables.
private: private:
Vector2f mPosition; sf::Vector2f mPosition;
Vector2i mSize; sf::Vector2i mSize;
Vector2f mSpeed; sf::Vector2f mSpeed;
float mAngle; float mAngle;
Category mCategory; Category mCategory;
unsigned short mMask; unsigned short mMask;

View file

@ -15,9 +15,9 @@
#include "../sprites/Corpse.h" #include "../sprites/Corpse.h"
#include "../util/Log.h" #include "../util/Log.h"
const String Character::KEY_HEALTH = "health"; const std::string Character::KEY_HEALTH = "health";
const int Character::DEFAULT_HEALTH = 100; const int Character::DEFAULT_HEALTH = 100;
const String Character::KEY_SPEED = "speed"; const std::string Character::KEY_SPEED = "speed";
const float Character::DEFAULT_SPEED = 100; const float Character::DEFAULT_SPEED = 100;
const float Character::POINT_REACHED_DISTANCE = 1.0f; const float Character::POINT_REACHED_DISTANCE = 1.0f;
std::vector<Character*> Character::mCharacterInstances = std::vector<Character*>(); std::vector<Character*> Character::mCharacterInstances = std::vector<Character*>();
@ -116,7 +116,7 @@ Character::fire() {
* @return True if a path was found. * @return True if a path was found.
*/ */
bool bool
Character::setDestination(const Vector2f& destination) { Character::setDestination(const sf::Vector2f& destination) {
mPath = mPathfinder.getPath(*this, destination); mPath = mPathfinder.getPath(*this, destination);
// Make sure we found a path. // Make sure we found a path.
if (mPath.empty()) { if (mPath.empty()) {
@ -146,7 +146,7 @@ Character::move() {
} }
else { else {
LOG_I("Reached destination."); LOG_I("Reached destination.");
setSpeed(Vector2f(), 0); setSpeed(sf::Vector2f(), 0);
} }
} }
} }

View file

@ -8,12 +8,12 @@
#ifndef DG_ACTOR_H_ #ifndef DG_ACTOR_H_
#define DG_ACTOR_H_ #define DG_ACTOR_H_
#include <string>
#include <vector> #include <vector>
#include "Sprite.h" #include "Sprite.h"
#include "../World.h" #include "../World.h"
#include "../items/Weapon.h" #include "../items/Weapon.h"
#include "../types/String.h"
#include "../util/Pathfinder.h" #include "../util/Pathfinder.h"
#include "../util/Yaml.h" #include "../util/Yaml.h"
@ -44,14 +44,14 @@ protected:
virtual void onDeath(); virtual void onDeath();
float getMovementSpeed() const; float getMovementSpeed() const;
void fire(); void fire();
bool setDestination(const Vector2f& destination); bool setDestination(const sf::Vector2f& destination);
void move(); void move();
// Private variables. // Private variables.
private: private:
static const String KEY_HEALTH; static const std::string KEY_HEALTH;
static const int DEFAULT_HEALTH; static const int DEFAULT_HEALTH;
static const String KEY_SPEED; static const std::string KEY_SPEED;
static const float DEFAULT_SPEED; static const float DEFAULT_SPEED;
/// The distance to a point where it is considered reached. /// The distance to a point where it is considered reached.
static const float POINT_REACHED_DISTANCE; static const float POINT_REACHED_DISTANCE;
@ -65,7 +65,7 @@ private:
int mCurrentHealth; //< Current health. Between 0 and mMaxHealth. int mCurrentHealth; //< Current health. Between 0 and mMaxHealth.
const float mMovementSpeed; const float mMovementSpeed;
Weapon mWeapon; Weapon mWeapon;
std::vector<Vector2f> mPath; //< Contains nodes to reach a set destination. std::vector<sf::Vector2f> mPath; //< Contains nodes to reach a set destination.
bool mStartPathfinding; //< True if a movement destination was just set. bool mStartPathfinding; //< True if a movement destination was just set.
}; };

View file

@ -11,18 +11,18 @@
#include "../util/ResourceManager.h" #include "../util/ResourceManager.h"
#include "../util/Log.h" #include "../util/Log.h"
const String Sprite::KEY_TEXTURE = "texture"; const std::string Sprite::KEY_TEXTURE = "texture";
const String Sprite::DEFAULT_TEXTURE = ""; const std::string Sprite::DEFAULT_TEXTURE = "";
/** /**
* Loads sprite from ResourceManager, sets world position. * Loads sprite from ResourceManager, sets world position.
* *
* @param texturePath Relative path to the texture file in the resource folder. * @param texturePath Relative path to the texture file in the resource folder.
*/ */
Sprite::Sprite(const Yaml& config, const Data& data, const Vector2i& size) : Sprite::Sprite(const Yaml& config, const Data& data, const sf::Vector2i& size) :
Body(data, config, size), Body(data, config, size),
mSize(Vector2i(getSize())) { mSize(sf::Vector2i(getSize())) {
String texture = config.get(KEY_TEXTURE, DEFAULT_TEXTURE); std::string texture = config.get(KEY_TEXTURE, DEFAULT_TEXTURE);
if (texture == "") { if (texture == "") {
LOG_E("Failed to read texture from YAML file " << config.getFilename()); LOG_E("Failed to read texture from YAML file " << config.getFilename());
} }
@ -42,10 +42,10 @@ Sprite::~Sprite() {
void void
Sprite::draw(sf::RenderTarget& target, sf::RenderStates states) const { Sprite::draw(sf::RenderTarget& target, sf::RenderStates states) const {
// Create a temporary shape to apply box2d body transformations to. // Create a temporary shape to apply box2d body transformations to.
sf::RectangleShape shape = sf::RectangleShape(Vector2f(mSize)); sf::RectangleShape shape = sf::RectangleShape(sf::Vector2f(mSize));
shape.setTexture(&*mTexture, true); shape.setTexture(&*mTexture, true);
shape.setOrigin(Vector2f(mSize.x / 2, mSize.y / 2)); shape.setOrigin(sf::Vector2f(mSize.x / 2, mSize.y / 2));
shape.setTextureRect(sf::IntRect(Vector2i(0, 0), mSize)); shape.setTextureRect(sf::IntRect(sf::Vector2i(0, 0), mSize));
shape.setPosition(getPosition()); shape.setPosition(getPosition());
shape.setRotation(getAngle()); shape.setRotation(getAngle());

View file

@ -13,8 +13,7 @@
#include <Thor/Resources.hpp> #include <Thor/Resources.hpp>
#include "Body.h" #include "Body.h"
#include "../types/String.h" #include <string>
#include "../types/Vector.h"
#include "../util/Yaml.h" #include "../util/Yaml.h"
class Body; class Body;
@ -28,7 +27,7 @@ class Yaml;
class Sprite : public sf::Drawable, public Body { class Sprite : public sf::Drawable, public Body {
// Public functions. // Public functions.
public: public:
Sprite(const Yaml& config, const Data& data, const Vector2i& size = Vector2i()); Sprite(const Yaml& config, const Data& data, const sf::Vector2i& size = sf::Vector2i());
Sprite(const std::shared_ptr<sf::Texture>& texture, const Data& data); Sprite(const std::shared_ptr<sf::Texture>& texture, const Data& data);
virtual ~Sprite() = 0; virtual ~Sprite() = 0;
@ -38,11 +37,11 @@ protected:
// Private variables. // Private variables.
private: private:
static const String KEY_TEXTURE; static const std::string KEY_TEXTURE;
static const String DEFAULT_TEXTURE; static const std::string DEFAULT_TEXTURE;
std::shared_ptr<sf::Texture> mTexture; std::shared_ptr<sf::Texture> mTexture;
Vector2i mSize; sf::Vector2i mSize;
}; };
#endif /* DG_SPRITE_H_ */ #endif /* DG_SPRITE_H_ */

View file

@ -13,9 +13,9 @@
#include "../util/Loader.h" #include "../util/Loader.h"
#include "../util/ResourceManager.h" #include "../util/ResourceManager.h"
const String Bullet::KEY_DAMAGE = "damage"; const std::string Bullet::KEY_DAMAGE = "damage";
const int Bullet::DEFAULT_DAMAGE = 10; const int Bullet::DEFAULT_DAMAGE = 10;
const String Bullet::KEY_SPEED = "speed"; const std::string Bullet::KEY_SPEED = "speed";
const float Bullet::DEFAULT_SPEED = 500; const float Bullet::DEFAULT_SPEED = 500;
/** /**
@ -25,13 +25,13 @@ const float Bullet::DEFAULT_SPEED = 500;
* @param world Box2d world. * @param world Box2d world.
* @param texture Texture to display for bullet. * @param texture Texture to display for bullet.
*/ */
Bullet::Bullet(const Vector2f& position, Body& shooter, float direction, Bullet::Bullet(const sf::Vector2f& position, Body& shooter, float direction,
const Yaml& config) : const Yaml& config) :
Particle(config, Data(position, 0, CATEGORY_PARTICLE, CATEGORY_PARTICLE)), Particle(config, Data(position, 0, CATEGORY_PARTICLE, CATEGORY_PARTICLE)),
mShooter(shooter), mShooter(shooter),
mDamage(config.get(KEY_DAMAGE, DEFAULT_DAMAGE)), mDamage(config.get(KEY_DAMAGE, DEFAULT_DAMAGE)),
mSpeed(config.get(KEY_SPEED, DEFAULT_SPEED)) { mSpeed(config.get(KEY_SPEED, DEFAULT_SPEED)) {
Vector2f dir(1.0f, 0); sf::Vector2f dir(1.0f, 0);
thor::setPolarAngle(dir, direction); thor::setPolarAngle(dir, direction);
setSpeed(dir, mSpeed); setSpeed(dir, mSpeed);
setAngle(direction); setAngle(direction);

View file

@ -8,8 +8,9 @@
#ifndef DG_BULLET_H_ #ifndef DG_BULLET_H_
#define DG_BULLET_H_ #define DG_BULLET_H_
#include <string>
#include "../particle/Particle.h" #include "../particle/Particle.h"
#include "../types/String.h"
#include "../util/Yaml.h" #include "../util/Yaml.h"
class Particle; class Particle;
@ -21,7 +22,7 @@ class Yaml;
class Bullet : public Particle { class Bullet : public Particle {
// Public functions. // Public functions.
public: public:
Bullet(const Vector2f& position, Body& shooter, float direction, Bullet(const sf::Vector2f& position, Body& shooter, float direction,
const Yaml& config); const Yaml& config);
void onCollide(Body& other, Category category); void onCollide(Body& other, Category category);
@ -29,9 +30,9 @@ public:
// Private variables. // Private variables.
private: private:
static const String KEY_DAMAGE; static const std::string KEY_DAMAGE;
static const int DEFAULT_DAMAGE; static const int DEFAULT_DAMAGE;
static const String KEY_SPEED; static const std::string KEY_SPEED;
static const float DEFAULT_SPEED; static const float DEFAULT_SPEED;
Body& mShooter; Body& mShooter;

View file

@ -14,9 +14,9 @@
#include "../World.h" #include "../World.h"
#include "../effects/Bullet.h" #include "../effects/Bullet.h"
const String Weapon::KEY_BULLET = "bullet"; const std::string Weapon::KEY_BULLET = "bullet";
const String Weapon::DEFAULT_BULLET = "bullet.yaml"; const std::string Weapon::DEFAULT_BULLET = "bullet.yaml";
const String Weapon::KEY_INTERVAL = "interval"; const std::string Weapon::KEY_INTERVAL = "interval";
const int Weapon::DEFAULT_INTERVAL = 250; const int Weapon::DEFAULT_INTERVAL = 250;
Weapon::Weapon(World& world, Body& holder, const Yaml& config) : Weapon::Weapon(World& world, Body& holder, const Yaml& config) :
@ -25,10 +25,10 @@ Weapon::Weapon(World& world, Body& holder, const Yaml& config) :
mHolder(holder), mHolder(holder),
mBullet(config.get(KEY_BULLET, DEFAULT_BULLET)), mBullet(config.get(KEY_BULLET, DEFAULT_BULLET)),
mTimer(sf::milliseconds(config.get(KEY_INTERVAL, DEFAULT_INTERVAL))) { mTimer(sf::milliseconds(config.get(KEY_INTERVAL, DEFAULT_INTERVAL))) {
Vector2i holderSize = mHolder.getSize(); sf::Vector2i holderSize = mHolder.getSize();
Yaml bullet(mBullet); Yaml bullet(mBullet);
Vector2i bulletSize = bullet.get(Body::KEY_SIZE, Vector2i()); sf::Vector2i bulletSize = bullet.get(Body::KEY_SIZE, sf::Vector2i());
mOffset = Vector2f(0, mOffset = sf::Vector2f(0,
std::max(holderSize.x, holderSize.y) / 2 + std::max(holderSize.x, holderSize.y) / 2 +
std::max(bulletSize.x, bulletSize.y) / 2); std::max(bulletSize.x, bulletSize.y) / 2);
} }
@ -48,7 +48,7 @@ Weapon::fire() {
std::shared_ptr<Particle> std::shared_ptr<Particle>
Weapon::createParticle() { Weapon::createParticle() {
// Minus to account for positive y-axis going downwards in SFML. // Minus to account for positive y-axis going downwards in SFML.
Vector2f offset(- mOffset); sf::Vector2f offset(- mOffset);
thor::rotate(offset, mHolder.getAngle()); thor::rotate(offset, mHolder.getAngle());
return std::shared_ptr<Particle>(new Bullet(mHolder.getPosition() + offset, return std::shared_ptr<Particle>(new Bullet(mHolder.getPosition() + offset,
mHolder, mHolder.getAngle(), Yaml(mBullet))); mHolder, mHolder.getAngle(), Yaml(mBullet)));

View file

@ -39,16 +39,16 @@ protected:
// Private variables. // Private variables.
private: private:
static const String KEY_BULLET; static const std::string KEY_BULLET;
static const String DEFAULT_BULLET; static const std::string DEFAULT_BULLET;
static const String KEY_INTERVAL; static const std::string KEY_INTERVAL;
static const int DEFAULT_INTERVAL; static const int DEFAULT_INTERVAL;
World& mWorld; World& mWorld;
Body& mHolder; Body& mHolder;
Vector2f mOffset; //< Offset to the point where bullets are inserted (from holder center). sf::Vector2f mOffset; //< Offset to the point where bullets are inserted (from holder center).
const String mBullet; const std::string mBullet;
Timer mTimer; Timer mTimer;
}; };

View file

@ -7,7 +7,7 @@
#include "Corpse.h" #include "Corpse.h"
Corpse::Corpse(const Vector2f& position, const Yaml& config) : Corpse::Corpse(const sf::Vector2f& position, const Yaml& config) :
Sprite(config, Data(position, 0, CATEGORY_NONSOLID, MASK_NONE)) { Sprite(config, Data(position, 0, CATEGORY_NONSOLID, MASK_NONE)) {
} }

View file

@ -17,7 +17,7 @@ class Yaml;
class Corpse : public Sprite { class Corpse : public Sprite {
// Public functions. // Public functions.
public: public:
Corpse(const Vector2f& position, const Yaml& config); Corpse(const sf::Vector2f& position, const Yaml& config);
}; };
#endif /* DG_CORPSE_H_ */ #endif /* DG_CORPSE_H_ */

View file

@ -10,7 +10,7 @@
#include "Corpse.h" #include "Corpse.h"
Enemy::Enemy(World& collection, Pathfinder& pathfinder, Enemy::Enemy(World& collection, Pathfinder& pathfinder,
const Vector2f& position, const Yaml& config) : const sf::Vector2f& position, const Yaml& config) :
Character(collection, pathfinder, Character(collection, pathfinder,
Data(position, 0, CATEGORY_ACTOR, MASK_ALL), Data(position, 0, CATEGORY_ACTOR, MASK_ALL),
config) { config) {

View file

@ -8,9 +8,10 @@
#ifndef DG_ENEMY_H_ #ifndef DG_ENEMY_H_
#define DG_ENEMY_H #define DG_ENEMY_H
#include <SFML/System.hpp>
#include "../abstract/Character.h" #include "../abstract/Character.h"
#include "../World.h" #include "../World.h"
#include "../types/Vector.h"
#include "../util/Yaml.h" #include "../util/Yaml.h"
class Character; class Character;
@ -22,7 +23,7 @@ class Enemy : public Character {
// Public functions. // Public functions.
public: public:
Enemy(World& collection, Pathfinder& pathfinder, Enemy(World& collection, Pathfinder& pathfinder,
const Vector2f& position, const Yaml& config); const sf::Vector2f& position, const Yaml& config);
// Private functions. // Private functions.
private: private:

View file

@ -7,17 +7,17 @@
#include "Player.h" #include "Player.h"
#include <string>
#include <Thor/Vectors.hpp> #include <Thor/Vectors.hpp>
#include "../items/Weapon.h" #include "../items/Weapon.h"
#include "../types/String.h"
#include "../types/Vector.h"
/** /**
* Initializes Sprite. * Initializes Sprite.
*/ */
Player::Player(World& world, Pathfinder& pathfinder, Player::Player(World& world, Pathfinder& pathfinder,
const Vector2f& position, const Yaml& config) : const sf::Vector2f& position, const Yaml& config) :
Character(world, pathfinder, Character(world, pathfinder,
Data(position, 0, CATEGORY_ACTOR, MASK_ALL), Data(position, 0, CATEGORY_ACTOR, MASK_ALL),
config), config),
@ -30,7 +30,7 @@ Player::Player(World& world, Pathfinder& pathfinder,
* @param Absolute world coordinates of the crosshair. * @param Absolute world coordinates of the crosshair.
*/ */
void void
Player::setCrosshairPosition(const Vector2f& position) { Player::setCrosshairPosition(const sf::Vector2f& position) {
mCrosshairPosition = position - getPosition(); mCrosshairPosition = position - getPosition();
} }
@ -49,7 +49,7 @@ Player::fire() {
* @param destination Absolute world coordinate of the destination point. * @param destination Absolute world coordinate of the destination point.
*/ */
void void
Player::move(const Vector2f& destination) { Player::move(const sf::Vector2f& destination) {
setDestination(destination); setDestination(destination);
} }
@ -68,7 +68,7 @@ Player::setDirection(Direction direction, bool unset) {
mDirection = mDirection | direction; mDirection = mDirection | direction;
} }
// Convert directions into a vector. // Convert directions into a vector.
Vector2f dirVec(0, 0); sf::Vector2f dirVec(0, 0);
if (mDirection & Direction::RIGHT) { if (mDirection & Direction::RIGHT) {
dirVec.x += 1.0f; dirVec.x += 1.0f;
} }
@ -94,7 +94,7 @@ Player::onThink(float elapsedTime) {
Character::move(); Character::move();
} }
// Look towards crosshair. // Look towards crosshair.
if (mCrosshairPosition != Vector2f()) { if (mCrosshairPosition != sf::Vector2f()) {
setAngle(thor::polarAngle(mCrosshairPosition) + 90); setAngle(thor::polarAngle(mCrosshairPosition) + 90);
} }
} }

View file

@ -13,7 +13,6 @@
#include "../abstract/Character.h" #include "../abstract/Character.h"
#include "../items/Weapon.h" #include "../items/Weapon.h"
#include "../types/Vector.h"
#include "../util/Pathfinder.h" #include "../util/Pathfinder.h"
#include "../util/Yaml.h" #include "../util/Yaml.h"
@ -42,11 +41,11 @@ public:
// Public functions. // Public functions.
public: public:
Player(World& world, Pathfinder& pathfinder, Player(World& world, Pathfinder& pathfinder,
const Vector2f& position, const Yaml& config); const sf::Vector2f& position, const Yaml& config);
void setCrosshairPosition(const Vector2f& position); void setCrosshairPosition(const sf::Vector2f& position);
void fire(); void fire();
void move(const Vector2f& destination); void move(const sf::Vector2f& destination);
void setDirection(Direction direction, bool unset); void setDirection(Direction direction, bool unset);
// Private functions. // Private functions.
@ -56,7 +55,7 @@ private:
// Private variables. // Private variables.
private: private:
Vector2f mCrosshairPosition; //< Relative position of the point to fire at (mouse cursor). sf::Vector2f mCrosshairPosition; //< Relative position of the point to fire at (mouse cursor).
unsigned char mDirection; //< Current movement direction for direct control. unsigned char mDirection; //< Current movement direction for direct control.
}; };

View file

@ -7,14 +7,15 @@
#include "TileManager.h" #include "TileManager.h"
#include <string>
#include <Thor/Resources.hpp> #include <Thor/Resources.hpp>
#include "../abstract/Sprite.h" #include "../abstract/Sprite.h"
#include "../types/String.h"
#include "../util/Loader.h" #include "../util/Loader.h"
#include "../util/ResourceManager.h" #include "../util/ResourceManager.h"
const Vector2i TileManager::TILE_SIZE = Vector2i(100, 100); const sf::Vector2i TileManager::TILE_SIZE = sf::Vector2i(100, 100);
/** /**
* Loads tile resources. * Loads tile resources.
@ -34,7 +35,7 @@ TileManager::TileManager(World& world) :
*/ */
TileManager::Tile::Tile(Type type, const TilePosition& position) : TileManager::Tile::Tile(Type type, const TilePosition& position) :
Sprite(Yaml(getConfig(type)), Data( Sprite(Yaml(getConfig(type)), Data(
Vector2f(position.x * TILE_SIZE.x, position.y * TILE_SIZE.y), 0, sf::Vector2f(position.x * TILE_SIZE.x, position.y * TILE_SIZE.y), 0,
CATEGORY_WORLD, (type == Type::FLOOR) ? MASK_NONE : MASK_ALL)), CATEGORY_WORLD, (type == Type::FLOOR) ? MASK_NONE : MASK_ALL)),
mType(type) { mType(type) {
} }
@ -45,9 +46,9 @@ TileManager::Tile::Tile(Type type, const TilePosition& position) :
* @param type The type of tile to load a resource key for. * @param type The type of tile to load a resource key for.
* @return Resource key to the correct texture. * @return Resource key to the correct texture.
*/ */
String std::string
TileManager::Tile::getConfig(Type type) { TileManager::Tile::getConfig(Type type) {
String filename; std::string filename;
switch (type) { switch (type) {
case Type::FLOOR: case Type::FLOOR:
filename = "tile_floor.yaml"; filename = "tile_floor.yaml";

View file

@ -13,8 +13,7 @@
#include "../World.h" #include "../World.h"
#include "../abstract/Sprite.h" #include "../abstract/Sprite.h"
#include "../types/Vector.h" #include <string>
#include "../types/String.h"
class World; class World;
class Sprite; class Sprite;
@ -30,12 +29,12 @@ public:
/** /**
* Uses the length/width of a tile as a unit. * Uses the length/width of a tile as a unit.
*/ */
typedef Vector2i TilePosition; typedef sf::Vector2i TilePosition;
// Public variables. // Public variables.
public: public:
/// The size of a single tile (pixels). /// The size of a single tile (pixels).
static const Vector2i TILE_SIZE; static const sf::Vector2i TILE_SIZE;
// Public functions. // Public functions.
public: public:
@ -68,7 +67,7 @@ public:
Type getType() const; Type getType() const;
TilePosition getTilePosition() const; TilePosition getTilePosition() const;
static String getConfig(Type type); static std::string getConfig(Type type);
// Private variables. // Private variables.
private: private:

View file

@ -1,50 +0,0 @@
/*
* String.h
*
* Created on: 19.07.2012
* Author: Felix
*/
/**
* Use this as a replacement for std::to_string as MingW does not support it.
*/
#ifndef DG_STRING_H_
#define DG_STRING_H_
#include <sstream>
#include <string>
typedef std::string String;
/**
* Converts any value to a string.
*
* @param val Any variable.
* @return val converted to string.
*/
template <typename T>
String
str(T val) {
std::stringstream out;
out << val;
return out.str();
}
/**
* Converts floating point variable to string,
*
* @param val Any floating point variable.
* @param digits Number of decimal places to round to.
* @return val converted to string.
*/
template <typename T>
String
str(T val, int digits) {
std::stringstream out;
out.precision(digits);
out << val;
return out.str();
}
#endif /* DG_STRING_H_ */

View file

@ -1,27 +0,0 @@
/*
* Vector.h
*
* Created on: 03.08.2012
* Author: Felix
*/
#ifndef DG_VECTOR_H_
#define DG_VECTOR_H_
#include <math.h>
#include <SFML/System.hpp>
#include <Thor/Vectors.hpp>
/**
* 2D floating point vector with x/y members.
*/
typedef sf::Vector2f Vector2f;
/**
* 2D integer vector with x/y members.
*/
typedef sf::Vector2i Vector2i;
#endif /* DG_VECTOR_H_ */

View file

@ -10,8 +10,6 @@
#include <iostream> #include <iostream>
#include "../types/Vector.h"
/** /**
* Logging functions for different levels. * Logging functions for different levels.
* *
@ -46,19 +44,19 @@
#define LOG_I(str) std::cout << __FILE__ << ":" << __LINE__ << " " << "Info: " << str << std::endl #define LOG_I(str) std::cout << __FILE__ << ":" << __LINE__ << " " << "Info: " << str << std::endl
/** /**
* Adds an output operator specalization for Vector2f. * Adds an output operator specalization for sf::Vector2f.
*/ */
inline std::ostream& inline std::ostream&
operator<<(std::ostream& os, const Vector2f& vector) { operator<<(std::ostream& os, const sf::Vector2f& vector) {
os << "(" << vector.x << ", " << vector.y << ")"; os << "(" << vector.x << ", " << vector.y << ")";
return os; return os;
} }
/** /**
* Adds an output operator specalization for Vector2i * Adds an output operator specalization for sf::Vector2i
*/ */
inline std::ostream& inline std::ostream&
operator<<(std::ostream& os, const Vector2i& vector) { operator<<(std::ostream& os, const sf::Vector2i& vector) {
os << "(" << vector.x << ", " << vector.y << ")"; os << "(" << vector.x << ", " << vector.y << ")";
return os; return os;
} }

View file

@ -11,7 +11,7 @@
Pathfinder::Pathfinder() { Pathfinder::Pathfinder() {
} }
std::vector<Vector2f> std::vector<sf::Vector2f>
Pathfinder::getPath(Body& physical, const Vector2f& destination) { Pathfinder::getPath(Body& physical, const sf::Vector2f& destination) {
return std::vector<Vector2f>(); return std::vector<sf::Vector2f>();
} }

View file

@ -8,8 +8,9 @@
#ifndef PATHFINDER_H_ #ifndef PATHFINDER_H_
#define PATHFINDER_H_ #define PATHFINDER_H_
#include <SFML/System.hpp>
#include "../abstract/Body.h" #include "../abstract/Body.h"
#include "../types/Vector.h"
class Body; class Body;
@ -18,7 +19,7 @@ class Pathfinder {
public: public:
Pathfinder(); Pathfinder();
std::vector<Vector2f> getPath(Body& physical, const Vector2f& destination); std::vector<sf::Vector2f> getPath(Body& physical, const sf::Vector2f& destination);
}; };
#endif /* PATHFINDER_H_ */ #endif /* PATHFINDER_H_ */

View file

@ -9,13 +9,13 @@
#include "../util/Log.h" #include "../util/Log.h"
String Yaml::mFolder = ""; std::string Yaml::mFolder = "";
/** /**
* Creates a readable object from a YAML file. The path must be relative to the directory * Creates a readable object from a YAML file. The path must be relative to the directory
* set in setFolder(). * set in setFolder().
*/ */
Yaml::Yaml(const String& filename) : Yaml::Yaml(const std::string& filename) :
mFilename(mFolder+filename), mFilename(mFolder+filename),
mFile(mFilename) { mFile(mFilename) {
if (mFile.fail()) { if (mFile.fail()) {
@ -32,7 +32,7 @@ Yaml::~Yaml() {
/** /**
* Return path and name of the file opened in this object. * Return path and name of the file opened in this object.
*/ */
String std::string
Yaml::getFilename() const { Yaml::getFilename() const {
return mFilename; return mFilename;
} }
@ -42,6 +42,6 @@ Yaml::getFilename() const {
* shorter strings as this does not have to be added everywhere. * shorter strings as this does not have to be added everywhere.
*/ */
void void
Yaml::setFolder(const String& folder) { Yaml::setFolder(const std::string& folder) {
mFolder = folder; mFolder = folder;
} }

View file

@ -8,12 +8,12 @@
#ifndef DG_YAML_H_ #ifndef DG_YAML_H_
#define DG_YAML_H_ #define DG_YAML_H_
#include <string>
#include <fstream> #include <fstream>
#include <yaml-cpp/yaml.h> #include <yaml-cpp/yaml.h>
#include "../types/String.h" #include <SFML/System.hpp>
#include "../types/Vector.h"
/** /**
* Interface to a YAML file. * Interface to a YAML file.
@ -21,21 +21,21 @@
class Yaml { class Yaml {
// Public functions. // Public functions.
public: public:
Yaml(const String& filename); Yaml(const std::string& filename);
~Yaml(); ~Yaml();
String getFilename() const; std::string getFilename() const;
static void setFolder(const String& folder); static void setFolder(const std::string& folder);
template <typename T> template <typename T>
T get(const String& key, const T& defaultValue) const; T get(const std::string& key, const T& defaultValue) const;
// Private variables. // Private variables.
private: private:
static String mFolder; static std::string mFolder;
String mFilename; std::string mFilename;
std::ifstream mFile; std::ifstream mFile;
YAML::Node mNode; YAML::Node mNode;
}; };
@ -44,12 +44,12 @@ private:
* Stream output operators to specialize Yaml::get for other types. * Stream output operators to specialize Yaml::get for other types.
*/ */
namespace { namespace {
void operator>>(const YAML::Node& node, Vector2i& vector) { void operator>>(const YAML::Node& node, sf::Vector2i& vector) {
node[0] >> vector.x; node[0] >> vector.x;
node[1] >> vector.y; node[1] >> vector.y;
} }
void operator>>(const YAML::Node& node, Vector2f& vector) { void operator>>(const YAML::Node& node, sf::Vector2f& vector) {
node[0] >> vector.x; node[0] >> vector.x;
node[1] >> vector.y; node[1] >> vector.y;
} }
@ -63,7 +63,7 @@ namespace {
* @return The value of the specified key. * @return The value of the specified key.
*/ */
template <typename T> template <typename T>
T Yaml::get(const String& key, const T& defaultValue) const { T Yaml::get(const std::string& key, const T& defaultValue) const {
if (const YAML::Node* node = mNode.FindValue(key)) { if (const YAML::Node* node = mNode.FindValue(key)) {
T value; T value;
*node >> value; *node >> value;