From 7c4eb47f2ebae9affe53bb101996f6ae09a26ea7 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Sat, 22 Dec 2012 15:10:26 +0100 Subject: [PATCH] Removed string/vector typedefs. --- source/Game.cpp | 13 +++++---- source/Game.h | 3 +- source/abstract/Body.cpp | 18 ++++++------ source/abstract/Body.h | 26 ++++++++---------- source/abstract/Character.cpp | 8 +++--- source/abstract/Character.h | 10 +++---- source/abstract/Sprite.cpp | 16 +++++------ source/abstract/Sprite.h | 11 ++++---- source/effects/Bullet.cpp | 8 +++--- source/effects/Bullet.h | 9 +++--- source/items/Weapon.cpp | 14 +++++----- source/items/Weapon.h | 10 +++---- source/sprites/Corpse.cpp | 2 +- source/sprites/Corpse.h | 2 +- source/sprites/Enemy.cpp | 2 +- source/sprites/Enemy.h | 5 ++-- source/sprites/Player.cpp | 14 +++++----- source/sprites/Player.h | 9 +++--- source/sprites/TileManager.cpp | 11 ++++---- source/sprites/TileManager.h | 9 +++--- source/types/String.h | 50 ---------------------------------- source/types/Vector.h | 27 ------------------ source/util/Log.h | 10 +++---- source/util/Pathfinder.cpp | 6 ++-- source/util/Pathfinder.h | 5 ++-- source/util/Yaml.cpp | 8 +++--- source/util/Yaml.h | 22 +++++++-------- 27 files changed, 125 insertions(+), 203 deletions(-) delete mode 100644 source/types/String.h delete mode 100644 source/types/Vector.h diff --git a/source/Game.cpp b/source/Game.cpp index 33783e6..50e60ea 100644 --- a/source/Game.cpp +++ b/source/Game.cpp @@ -7,11 +7,12 @@ #include "Game.h" +#include + #include #include "abstract/Character.h" -#include "sprites/Enemy.h" -#include "types/String.h" +#include "sprites/Enemy.h" #include "util/Loader.h" #include "util/ResourceManager.h" @@ -23,7 +24,7 @@ const int Game::FPS_GOAL = 60; */ Game::Game(sf::RenderWindow& window) : mWindow(window), - mView(Vector2f(0, 0), mWindow.getView().getSize()), + mView(sf::Vector2f(0, 0), mWindow.getView().getSize()), mTileManager(mWorld), mQuit(false), mPaused(false) { @@ -50,10 +51,10 @@ Game::generate() { mTileManager.setTile(TileManager::TilePosition(x, 4), TileManager::Type::WALL); mWorld.insert(std::shared_ptr(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(new Player(mWorld, mPathfinder, - Vector2f(200.0f, 100.0f), Yaml("player.yaml"))); + sf::Vector2f(200.0f, 100.0f), Yaml("player.yaml"))); mWorld.insert(mPlayer); } /** @@ -172,7 +173,7 @@ Game::keyDown(const sf::Event& event) { */ sf::Vector2 Game::convertCoordinates(int x, int y) { - return mWindow.convertCoords(Vector2i(x, y), mView); + return mWindow.convertCoords(sf::Vector2i(x, y), mView); } /** diff --git a/source/Game.h b/source/Game.h index c8fd530..2cc3d47 100644 --- a/source/Game.h +++ b/source/Game.h @@ -8,6 +8,8 @@ #ifndef DG_GAME_H_ #define DG_GAME_H_ +#include + #include #include @@ -15,7 +17,6 @@ #include "sprites/TileManager.h" #include "sprites/Player.h" -#include "types/String.h" #include "World.h" #include "util/Pathfinder.h" diff --git a/source/abstract/Body.cpp b/source/abstract/Body.cpp index 8be5c53..def7944 100755 --- a/source/abstract/Body.cpp +++ b/source/abstract/Body.cpp @@ -11,15 +11,15 @@ #include -const String Body::KEY_SIZE = "size"; -const Vector2i Body::DEFAULT_SIZE = Vector2i(50, 50); +const std::string Body::KEY_SIZE = "size"; +const sf::Vector2i Body::DEFAULT_SIZE = sf::Vector2i(50, 50); /** * Initializes Box2D body. * * @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), mSize(config.get(KEY_SIZE, DEFAULT_SIZE)), mAngle(0), @@ -37,7 +37,7 @@ Body::~Body() { /** * Initializes container. */ -Body::Data::Data(const Vector2f& position, float angle, +Body::Data::Data(const sf::Vector2f& position, float angle, Category category, unsigned short maskExclude) : position(position), angle(angle), @@ -48,7 +48,7 @@ Body::Data::Data(const Vector2f& position, float angle, /** * Returns the position of the sprite (center). */ -Vector2f +sf::Vector2f Body::getPosition() const { return mPosition; } @@ -56,7 +56,7 @@ Body::getPosition() const { /** * Returns the movement speed of the body. */ -Vector2f +sf::Vector2f Body::getSpeed() const { return mSpeed; } @@ -88,7 +88,7 @@ Body::getCategory() const { /** * Returns the size of the body as a vector. */ -Vector2i +sf::Vector2i Body::getSize() const { return mSize; } @@ -131,8 +131,8 @@ Body::setDelete(bool value) { * @param speed The value of the movement speed to be used. */ void -Body::setSpeed(Vector2f direction, float speed) { - if (direction != Vector2f()) { +Body::setSpeed(sf::Vector2f direction, float speed) { + if (direction != sf::Vector2f()) { thor::setLength(direction, speed); } mSpeed = direction; diff --git a/source/abstract/Body.h b/source/abstract/Body.h index 00b69c6..f7fc375 100755 --- a/source/abstract/Body.h +++ b/source/abstract/Body.h @@ -8,8 +8,6 @@ #ifndef DG_BODY_H_ #define DG_BODY_H_ -#include "../types/String.h" -#include "../types/Vector.h" #include "../util/Yaml.h" class Yaml; @@ -42,8 +40,8 @@ public: class Data { public: Data() = default; - Data(const Vector2f& position, float angle, Category category, unsigned short maskExclude); - const Vector2f& position; + Data(const sf::Vector2f& position, float angle, Category category, unsigned short maskExclude); + const sf::Vector2f& position; float angle; Category category; unsigned short mask; @@ -59,35 +57,35 @@ public: // Public functions. 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; - Vector2f getPosition() const; - Vector2f getSpeed() const; + sf::Vector2f getPosition() const; + sf::Vector2f getSpeed() const; float getAngle() const; bool getDelete() const; Category getCategory() const; - Vector2i getSize() const; + sf::Vector2i getSize() const; virtual bool doesCollide(Body& other); virtual void onCollide(Body& other, Category category); // Public variables. public: - static const String KEY_SIZE; - static const Vector2i DEFAULT_SIZE; + static const std::string KEY_SIZE; + static const sf::Vector2i DEFAULT_SIZE; // Protected functions. protected: void setDelete(bool value); - void setSpeed(Vector2f direction, float speed); + void setSpeed(sf::Vector2f direction, float speed); void setAngle(float angle); // Private variables. private: - Vector2f mPosition; - Vector2i mSize; - Vector2f mSpeed; + sf::Vector2f mPosition; + sf::Vector2i mSize; + sf::Vector2f mSpeed; float mAngle; Category mCategory; unsigned short mMask; diff --git a/source/abstract/Character.cpp b/source/abstract/Character.cpp index ca1f3bf..1f350ab 100644 --- a/source/abstract/Character.cpp +++ b/source/abstract/Character.cpp @@ -15,9 +15,9 @@ #include "../sprites/Corpse.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 String Character::KEY_SPEED = "speed"; +const std::string Character::KEY_SPEED = "speed"; const float Character::DEFAULT_SPEED = 100; const float Character::POINT_REACHED_DISTANCE = 1.0f; std::vector Character::mCharacterInstances = std::vector(); @@ -116,7 +116,7 @@ Character::fire() { * @return True if a path was found. */ bool -Character::setDestination(const Vector2f& destination) { +Character::setDestination(const sf::Vector2f& destination) { mPath = mPathfinder.getPath(*this, destination); // Make sure we found a path. if (mPath.empty()) { @@ -146,7 +146,7 @@ Character::move() { } else { LOG_I("Reached destination."); - setSpeed(Vector2f(), 0); + setSpeed(sf::Vector2f(), 0); } } } diff --git a/source/abstract/Character.h b/source/abstract/Character.h index 0c08b69..0bddb52 100644 --- a/source/abstract/Character.h +++ b/source/abstract/Character.h @@ -8,12 +8,12 @@ #ifndef DG_ACTOR_H_ #define DG_ACTOR_H_ +#include #include #include "Sprite.h" #include "../World.h" #include "../items/Weapon.h" -#include "../types/String.h" #include "../util/Pathfinder.h" #include "../util/Yaml.h" @@ -44,14 +44,14 @@ protected: virtual void onDeath(); float getMovementSpeed() const; void fire(); - bool setDestination(const Vector2f& destination); + bool setDestination(const sf::Vector2f& destination); void move(); // Private variables. private: - static const String KEY_HEALTH; + static const std::string KEY_HEALTH; static const int DEFAULT_HEALTH; - static const String KEY_SPEED; + static const std::string KEY_SPEED; static const float DEFAULT_SPEED; /// The distance to a point where it is considered reached. static const float POINT_REACHED_DISTANCE; @@ -65,7 +65,7 @@ private: int mCurrentHealth; //< Current health. Between 0 and mMaxHealth. const float mMovementSpeed; Weapon mWeapon; - std::vector mPath; //< Contains nodes to reach a set destination. + std::vector mPath; //< Contains nodes to reach a set destination. bool mStartPathfinding; //< True if a movement destination was just set. }; diff --git a/source/abstract/Sprite.cpp b/source/abstract/Sprite.cpp index ac7a2bc..71b1545 100644 --- a/source/abstract/Sprite.cpp +++ b/source/abstract/Sprite.cpp @@ -11,18 +11,18 @@ #include "../util/ResourceManager.h" #include "../util/Log.h" -const String Sprite::KEY_TEXTURE = "texture"; -const String Sprite::DEFAULT_TEXTURE = ""; +const std::string Sprite::KEY_TEXTURE = "texture"; +const std::string Sprite::DEFAULT_TEXTURE = ""; /** * Loads sprite from ResourceManager, sets world position. * * @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), - mSize(Vector2i(getSize())) { - String texture = config.get(KEY_TEXTURE, DEFAULT_TEXTURE); + mSize(sf::Vector2i(getSize())) { + std::string texture = config.get(KEY_TEXTURE, DEFAULT_TEXTURE); if (texture == "") { LOG_E("Failed to read texture from YAML file " << config.getFilename()); } @@ -42,10 +42,10 @@ Sprite::~Sprite() { void Sprite::draw(sf::RenderTarget& target, sf::RenderStates states) const { // 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.setOrigin(Vector2f(mSize.x / 2, mSize.y / 2)); - shape.setTextureRect(sf::IntRect(Vector2i(0, 0), mSize)); + shape.setOrigin(sf::Vector2f(mSize.x / 2, mSize.y / 2)); + shape.setTextureRect(sf::IntRect(sf::Vector2i(0, 0), mSize)); shape.setPosition(getPosition()); shape.setRotation(getAngle()); diff --git a/source/abstract/Sprite.h b/source/abstract/Sprite.h index 2a2736c..afdae73 100644 --- a/source/abstract/Sprite.h +++ b/source/abstract/Sprite.h @@ -13,8 +13,7 @@ #include #include "Body.h" -#include "../types/String.h" -#include "../types/Vector.h" +#include #include "../util/Yaml.h" class Body; @@ -28,7 +27,7 @@ class Yaml; class Sprite : public sf::Drawable, public Body { // Public functions. 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& texture, const Data& data); virtual ~Sprite() = 0; @@ -38,11 +37,11 @@ protected: // Private variables. private: - static const String KEY_TEXTURE; - static const String DEFAULT_TEXTURE; + static const std::string KEY_TEXTURE; + static const std::string DEFAULT_TEXTURE; std::shared_ptr mTexture; - Vector2i mSize; + sf::Vector2i mSize; }; #endif /* DG_SPRITE_H_ */ diff --git a/source/effects/Bullet.cpp b/source/effects/Bullet.cpp index 8d8ba8f..4c71534 100755 --- a/source/effects/Bullet.cpp +++ b/source/effects/Bullet.cpp @@ -13,9 +13,9 @@ #include "../util/Loader.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 String Bullet::KEY_SPEED = "speed"; +const std::string Bullet::KEY_SPEED = "speed"; const float Bullet::DEFAULT_SPEED = 500; /** @@ -25,13 +25,13 @@ const float Bullet::DEFAULT_SPEED = 500; * @param world Box2d world. * @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) : Particle(config, Data(position, 0, CATEGORY_PARTICLE, CATEGORY_PARTICLE)), mShooter(shooter), mDamage(config.get(KEY_DAMAGE, DEFAULT_DAMAGE)), mSpeed(config.get(KEY_SPEED, DEFAULT_SPEED)) { - Vector2f dir(1.0f, 0); + sf::Vector2f dir(1.0f, 0); thor::setPolarAngle(dir, direction); setSpeed(dir, mSpeed); setAngle(direction); diff --git a/source/effects/Bullet.h b/source/effects/Bullet.h index 5bf1c2f..c59ae3b 100755 --- a/source/effects/Bullet.h +++ b/source/effects/Bullet.h @@ -8,8 +8,9 @@ #ifndef DG_BULLET_H_ #define DG_BULLET_H_ +#include + #include "../particle/Particle.h" -#include "../types/String.h" #include "../util/Yaml.h" class Particle; @@ -21,7 +22,7 @@ class Yaml; class Bullet : public Particle { // Public functions. public: - Bullet(const Vector2f& position, Body& shooter, float direction, + Bullet(const sf::Vector2f& position, Body& shooter, float direction, const Yaml& config); void onCollide(Body& other, Category category); @@ -29,9 +30,9 @@ public: // Private variables. private: - static const String KEY_DAMAGE; + static const std::string KEY_DAMAGE; static const int DEFAULT_DAMAGE; - static const String KEY_SPEED; + static const std::string KEY_SPEED; static const float DEFAULT_SPEED; Body& mShooter; diff --git a/source/items/Weapon.cpp b/source/items/Weapon.cpp index 88affdd..42bdc6f 100755 --- a/source/items/Weapon.cpp +++ b/source/items/Weapon.cpp @@ -14,9 +14,9 @@ #include "../World.h" #include "../effects/Bullet.h" -const String Weapon::KEY_BULLET = "bullet"; -const String Weapon::DEFAULT_BULLET = "bullet.yaml"; -const String Weapon::KEY_INTERVAL = "interval"; +const std::string Weapon::KEY_BULLET = "bullet"; +const std::string Weapon::DEFAULT_BULLET = "bullet.yaml"; +const std::string Weapon::KEY_INTERVAL = "interval"; const int Weapon::DEFAULT_INTERVAL = 250; Weapon::Weapon(World& world, Body& holder, const Yaml& config) : @@ -25,10 +25,10 @@ Weapon::Weapon(World& world, Body& holder, const Yaml& config) : mHolder(holder), mBullet(config.get(KEY_BULLET, DEFAULT_BULLET)), mTimer(sf::milliseconds(config.get(KEY_INTERVAL, DEFAULT_INTERVAL))) { - Vector2i holderSize = mHolder.getSize(); + sf::Vector2i holderSize = mHolder.getSize(); Yaml bullet(mBullet); - Vector2i bulletSize = bullet.get(Body::KEY_SIZE, Vector2i()); - mOffset = Vector2f(0, + sf::Vector2i bulletSize = bullet.get(Body::KEY_SIZE, sf::Vector2i()); + mOffset = sf::Vector2f(0, std::max(holderSize.x, holderSize.y) / 2 + std::max(bulletSize.x, bulletSize.y) / 2); } @@ -48,7 +48,7 @@ Weapon::fire() { std::shared_ptr Weapon::createParticle() { // Minus to account for positive y-axis going downwards in SFML. - Vector2f offset(- mOffset); + sf::Vector2f offset(- mOffset); thor::rotate(offset, mHolder.getAngle()); return std::shared_ptr(new Bullet(mHolder.getPosition() + offset, mHolder, mHolder.getAngle(), Yaml(mBullet))); diff --git a/source/items/Weapon.h b/source/items/Weapon.h index 4021ae6..b884396 100755 --- a/source/items/Weapon.h +++ b/source/items/Weapon.h @@ -39,16 +39,16 @@ protected: // Private variables. private: - static const String KEY_BULLET; - static const String DEFAULT_BULLET; - static const String KEY_INTERVAL; + static const std::string KEY_BULLET; + static const std::string DEFAULT_BULLET; + static const std::string KEY_INTERVAL; static const int DEFAULT_INTERVAL; World& mWorld; Body& mHolder; - Vector2f mOffset; //< Offset to the point where bullets are inserted (from holder center). - const String mBullet; + sf::Vector2f mOffset; //< Offset to the point where bullets are inserted (from holder center). + const std::string mBullet; Timer mTimer; }; diff --git a/source/sprites/Corpse.cpp b/source/sprites/Corpse.cpp index 05ea2f8..47f1b37 100644 --- a/source/sprites/Corpse.cpp +++ b/source/sprites/Corpse.cpp @@ -7,7 +7,7 @@ #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)) { } diff --git a/source/sprites/Corpse.h b/source/sprites/Corpse.h index b453301..7ed8bd0 100644 --- a/source/sprites/Corpse.h +++ b/source/sprites/Corpse.h @@ -17,7 +17,7 @@ class Yaml; class Corpse : public Sprite { // Public functions. public: - Corpse(const Vector2f& position, const Yaml& config); + Corpse(const sf::Vector2f& position, const Yaml& config); }; #endif /* DG_CORPSE_H_ */ diff --git a/source/sprites/Enemy.cpp b/source/sprites/Enemy.cpp index 282771f..f7615c2 100644 --- a/source/sprites/Enemy.cpp +++ b/source/sprites/Enemy.cpp @@ -10,7 +10,7 @@ #include "Corpse.h" Enemy::Enemy(World& collection, Pathfinder& pathfinder, - const Vector2f& position, const Yaml& config) : + const sf::Vector2f& position, const Yaml& config) : Character(collection, pathfinder, Data(position, 0, CATEGORY_ACTOR, MASK_ALL), config) { diff --git a/source/sprites/Enemy.h b/source/sprites/Enemy.h index acf5ac2..1a85bb8 100644 --- a/source/sprites/Enemy.h +++ b/source/sprites/Enemy.h @@ -8,9 +8,10 @@ #ifndef DG_ENEMY_H_ #define DG_ENEMY_H +#include + #include "../abstract/Character.h" #include "../World.h" -#include "../types/Vector.h" #include "../util/Yaml.h" class Character; @@ -22,7 +23,7 @@ class Enemy : public Character { // Public functions. public: Enemy(World& collection, Pathfinder& pathfinder, - const Vector2f& position, const Yaml& config); + const sf::Vector2f& position, const Yaml& config); // Private functions. private: diff --git a/source/sprites/Player.cpp b/source/sprites/Player.cpp index 8703020..df0ceb4 100644 --- a/source/sprites/Player.cpp +++ b/source/sprites/Player.cpp @@ -7,17 +7,17 @@ #include "Player.h" +#include + #include #include "../items/Weapon.h" -#include "../types/String.h" -#include "../types/Vector.h" /** * Initializes Sprite. */ Player::Player(World& world, Pathfinder& pathfinder, - const Vector2f& position, const Yaml& config) : + const sf::Vector2f& position, const Yaml& config) : Character(world, pathfinder, Data(position, 0, CATEGORY_ACTOR, MASK_ALL), config), @@ -30,7 +30,7 @@ Player::Player(World& world, Pathfinder& pathfinder, * @param Absolute world coordinates of the crosshair. */ void -Player::setCrosshairPosition(const Vector2f& position) { +Player::setCrosshairPosition(const sf::Vector2f& position) { mCrosshairPosition = position - getPosition(); } @@ -49,7 +49,7 @@ Player::fire() { * @param destination Absolute world coordinate of the destination point. */ void -Player::move(const Vector2f& destination) { +Player::move(const sf::Vector2f& destination) { setDestination(destination); } @@ -68,7 +68,7 @@ Player::setDirection(Direction direction, bool unset) { mDirection = mDirection | direction; } // Convert directions into a vector. - Vector2f dirVec(0, 0); + sf::Vector2f dirVec(0, 0); if (mDirection & Direction::RIGHT) { dirVec.x += 1.0f; } @@ -94,7 +94,7 @@ Player::onThink(float elapsedTime) { Character::move(); } // Look towards crosshair. - if (mCrosshairPosition != Vector2f()) { + if (mCrosshairPosition != sf::Vector2f()) { setAngle(thor::polarAngle(mCrosshairPosition) + 90); } } diff --git a/source/sprites/Player.h b/source/sprites/Player.h index 58d3742..c340d85 100644 --- a/source/sprites/Player.h +++ b/source/sprites/Player.h @@ -13,7 +13,6 @@ #include "../abstract/Character.h" #include "../items/Weapon.h" -#include "../types/Vector.h" #include "../util/Pathfinder.h" #include "../util/Yaml.h" @@ -42,11 +41,11 @@ public: // Public functions. public: 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 move(const Vector2f& destination); + void move(const sf::Vector2f& destination); void setDirection(Direction direction, bool unset); // Private functions. @@ -56,7 +55,7 @@ private: // Private variables. 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. }; diff --git a/source/sprites/TileManager.cpp b/source/sprites/TileManager.cpp index e1f8a7c..2991076 100644 --- a/source/sprites/TileManager.cpp +++ b/source/sprites/TileManager.cpp @@ -7,14 +7,15 @@ #include "TileManager.h" +#include + #include #include "../abstract/Sprite.h" -#include "../types/String.h" #include "../util/Loader.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. @@ -34,7 +35,7 @@ TileManager::TileManager(World& world) : */ TileManager::Tile::Tile(Type type, const TilePosition& position) : 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)), 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. * @return Resource key to the correct texture. */ -String +std::string TileManager::Tile::getConfig(Type type) { - String filename; + std::string filename; switch (type) { case Type::FLOOR: filename = "tile_floor.yaml"; diff --git a/source/sprites/TileManager.h b/source/sprites/TileManager.h index 7d22850..947839f 100644 --- a/source/sprites/TileManager.h +++ b/source/sprites/TileManager.h @@ -13,8 +13,7 @@ #include "../World.h" #include "../abstract/Sprite.h" -#include "../types/Vector.h" -#include "../types/String.h" +#include class World; class Sprite; @@ -30,12 +29,12 @@ public: /** * Uses the length/width of a tile as a unit. */ - typedef Vector2i TilePosition; + typedef sf::Vector2i TilePosition; // Public variables. public: /// The size of a single tile (pixels). - static const Vector2i TILE_SIZE; + static const sf::Vector2i TILE_SIZE; // Public functions. public: @@ -68,7 +67,7 @@ public: Type getType() const; TilePosition getTilePosition() const; - static String getConfig(Type type); + static std::string getConfig(Type type); // Private variables. private: diff --git a/source/types/String.h b/source/types/String.h deleted file mode 100644 index 7e5bbd6..0000000 --- a/source/types/String.h +++ /dev/null @@ -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 -#include - -typedef std::string String; - -/** - * Converts any value to a string. - * - * @param val Any variable. - * @return val converted to string. - */ -template -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 -String -str(T val, int digits) { - std::stringstream out; - out.precision(digits); - out << val; - return out.str(); -} - -#endif /* DG_STRING_H_ */ diff --git a/source/types/Vector.h b/source/types/Vector.h deleted file mode 100644 index a054abe..0000000 --- a/source/types/Vector.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Vector.h - * - * Created on: 03.08.2012 - * Author: Felix - */ - -#ifndef DG_VECTOR_H_ -#define DG_VECTOR_H_ - -#include - -#include - -#include - -/** - * 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_ */ diff --git a/source/util/Log.h b/source/util/Log.h index 140a08d..f364eea 100644 --- a/source/util/Log.h +++ b/source/util/Log.h @@ -10,8 +10,6 @@ #include -#include "../types/Vector.h" - /** * Logging functions for different levels. * @@ -46,19 +44,19 @@ #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& -operator<<(std::ostream& os, const Vector2f& vector) { +operator<<(std::ostream& os, const sf::Vector2f& vector) { os << "(" << vector.x << ", " << vector.y << ")"; return os; } /** - * Adds an output operator specalization for Vector2i + * Adds an output operator specalization for sf::Vector2i */ inline std::ostream& -operator<<(std::ostream& os, const Vector2i& vector) { +operator<<(std::ostream& os, const sf::Vector2i& vector) { os << "(" << vector.x << ", " << vector.y << ")"; return os; } diff --git a/source/util/Pathfinder.cpp b/source/util/Pathfinder.cpp index 97df82a..7702419 100644 --- a/source/util/Pathfinder.cpp +++ b/source/util/Pathfinder.cpp @@ -11,7 +11,7 @@ Pathfinder::Pathfinder() { } -std::vector -Pathfinder::getPath(Body& physical, const Vector2f& destination) { - return std::vector(); +std::vector +Pathfinder::getPath(Body& physical, const sf::Vector2f& destination) { + return std::vector(); } diff --git a/source/util/Pathfinder.h b/source/util/Pathfinder.h index 01b043d..3d0f6b8 100644 --- a/source/util/Pathfinder.h +++ b/source/util/Pathfinder.h @@ -8,8 +8,9 @@ #ifndef PATHFINDER_H_ #define PATHFINDER_H_ +#include + #include "../abstract/Body.h" -#include "../types/Vector.h" class Body; @@ -18,7 +19,7 @@ class Pathfinder { public: Pathfinder(); - std::vector getPath(Body& physical, const Vector2f& destination); + std::vector getPath(Body& physical, const sf::Vector2f& destination); }; #endif /* PATHFINDER_H_ */ diff --git a/source/util/Yaml.cpp b/source/util/Yaml.cpp index a90a81b..48af081 100644 --- a/source/util/Yaml.cpp +++ b/source/util/Yaml.cpp @@ -9,13 +9,13 @@ #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 * set in setFolder(). */ -Yaml::Yaml(const String& filename) : +Yaml::Yaml(const std::string& filename) : mFilename(mFolder+filename), mFile(mFilename) { if (mFile.fail()) { @@ -32,7 +32,7 @@ Yaml::~Yaml() { /** * Return path and name of the file opened in this object. */ -String +std::string Yaml::getFilename() const { return mFilename; } @@ -42,6 +42,6 @@ Yaml::getFilename() const { * shorter strings as this does not have to be added everywhere. */ void -Yaml::setFolder(const String& folder) { +Yaml::setFolder(const std::string& folder) { mFolder = folder; } diff --git a/source/util/Yaml.h b/source/util/Yaml.h index 58a9997..60eaf94 100644 --- a/source/util/Yaml.h +++ b/source/util/Yaml.h @@ -8,12 +8,12 @@ #ifndef DG_YAML_H_ #define DG_YAML_H_ +#include #include #include -#include "../types/String.h" -#include "../types/Vector.h" +#include /** * Interface to a YAML file. @@ -21,21 +21,21 @@ class Yaml { // Public functions. public: - Yaml(const String& filename); + Yaml(const std::string& filename); ~Yaml(); - String getFilename() const; + std::string getFilename() const; - static void setFolder(const String& folder); + static void setFolder(const std::string& folder); template - T get(const String& key, const T& defaultValue) const; + T get(const std::string& key, const T& defaultValue) const; // Private variables. private: - static String mFolder; + static std::string mFolder; - String mFilename; + std::string mFilename; std::ifstream mFile; YAML::Node mNode; }; @@ -44,12 +44,12 @@ private: * Stream output operators to specialize Yaml::get for other types. */ namespace { - void operator>>(const YAML::Node& node, Vector2i& vector) { + void operator>>(const YAML::Node& node, sf::Vector2i& vector) { node[0] >> vector.x; 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[1] >> vector.y; } @@ -63,7 +63,7 @@ namespace { * @return The value of the specified key. */ template -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)) { T value; *node >> value;