diff --git a/source/Game.cpp b/source/Game.cpp index 1ef888a..2d82f87 100644 --- a/source/Game.cpp +++ b/source/Game.cpp @@ -9,13 +9,13 @@ #include -#include "util/Instances.h" #include "abstract/Character.h" -#include "sprite/Cover.h" -#include "sprite/Enemy.h" +#include "sprites/Cover.h" +#include "sprites/Enemy.h" +#include "types/Instances.h" +#include "types/String.h" #include "util/Loader.h" #include "util/ResourceManager.h" -#include "util/String.h" /// Goal amount of frames per second. const int Game::FPS_GOAL = 60; diff --git a/source/Game.h b/source/Game.h index 5c7e971..4def72a 100644 --- a/source/Game.h +++ b/source/Game.h @@ -15,11 +15,11 @@ #include -#include "Pathfinder.h" -#include "TileManager.h" -#include "sprite/Player.h" +#include "sprites/TileManager.h" +#include "sprites/Player.h" +#include "types/String.h" #include "util/Collection.h" -#include "util/String.h" +#include "util/Pathfinder.h" class Player; class Collection; diff --git a/source/abstract/Character.cpp b/source/abstract/Character.cpp index c92102b..b352f99 100644 --- a/source/abstract/Character.cpp +++ b/source/abstract/Character.cpp @@ -12,7 +12,7 @@ #include -#include "../sprite/Body.h" +#include "../sprites/Body.h" #include "../util/Log.h" const String Character::KEY_HEALTH = "health"; diff --git a/source/abstract/Character.h b/source/abstract/Character.h index c7e1ee1..45532c0 100644 --- a/source/abstract/Character.h +++ b/source/abstract/Character.h @@ -12,8 +12,8 @@ #include "Sprite.h" #include "../items/Weapon.h" -#include "../util/Instances.h" -#include "../util/String.h" +#include "../types/Instances.h" +#include "../types/String.h" #include "../util/Yaml.h" class Weapon; diff --git a/source/abstract/Physical.h b/source/abstract/Physical.h index 5055a8c..b9f67be 100755 --- a/source/abstract/Physical.h +++ b/source/abstract/Physical.h @@ -10,8 +10,8 @@ #include -#include "../util/String.h" -#include "../util/Vector.h" +#include "../types/String.h" +#include "../types/Vector.h" #include "../util/Yaml.h" class Yaml; diff --git a/source/util/Singleton.h b/source/abstract/Singleton.h similarity index 94% rename from source/util/Singleton.h rename to source/abstract/Singleton.h index 4659729..e275ca4 100644 --- a/source/util/Singleton.h +++ b/source/abstract/Singleton.h @@ -1,44 +1,44 @@ -/* - * Singleton.h - * - * Created on: 04.07.2012 - * Author: Felix - */ - -#ifndef DG_SINGLETON_H_ -#define DG_SINGLETON_H_ - -#include - -/** - * Template class for inheriting singleton behaviour. - * - * This uses lazy initialization and should be thread safe in C++11 (untested). - * To use, just make a subclass with only a private default constructor and Singleton - * as friend class. - * - * @code - * class MyClass : public Singleton { - * private: - * friend class Singleton; - * MyClass() = default; - * }; - * @endcode - */ -template -class Singleton : public sf::NonCopyable { -// Public functions. -public: - static T& i(); -}; - -/** -* Returns the instance of T. -*/ -template -T& Singleton::i() { - static T s; - return s; -}; - -#endif /* DG_SINGLETON_H_ */ +/* + * Singleton.h + * + * Created on: 04.07.2012 + * Author: Felix + */ + +#ifndef DG_SINGLETON_H_ +#define DG_SINGLETON_H_ + +#include + +/** + * Template class for inheriting singleton behaviour. + * + * This uses lazy initialization and should be thread safe in C++11 (untested). + * To use, just make a subclass with only a private default constructor and Singleton + * as friend class. + * + * @code + * class MyClass : public Singleton { + * private: + * friend class Singleton; + * MyClass() = default; + * }; + * @endcode + */ +template +class Singleton : public sf::NonCopyable { +// Public functions. +public: + static T& i(); +}; + +/** +* Returns the instance of T. +*/ +template +T& Singleton::i() { + static T s; + return s; +}; + +#endif /* DG_SINGLETON_H_ */ diff --git a/source/abstract/Sprite.h b/source/abstract/Sprite.h index 531731d..6101d67 100644 --- a/source/abstract/Sprite.h +++ b/source/abstract/Sprite.h @@ -13,8 +13,8 @@ #include #include "Physical.h" -#include "../util/String.h" -#include "../util/Vector.h" +#include "../types/String.h" +#include "../types/Vector.h" #include "../util/Yaml.h" class Physical; diff --git a/source/effects/Bullet.h b/source/effects/Bullet.h index 35dcdcd..908af5f 100755 --- a/source/effects/Bullet.h +++ b/source/effects/Bullet.h @@ -9,7 +9,7 @@ #define DG_BULLET_H_ #include "../particle/Particle.h" -#include "../util/String.h" +#include "../types/String.h" #include "../util/Yaml.h" class Particle; diff --git a/source/items/Weapon.h b/source/items/Weapon.h index 2e39241..15f9be8 100755 --- a/source/items/Weapon.h +++ b/source/items/Weapon.h @@ -10,9 +10,9 @@ #include -#include "../util/Instances.h" #include "../abstract/Physical.h" #include "../particle/Emitter.h" +#include "../types/Instances.h" #include "../util/Yaml.h" class Emitter; diff --git a/source/sprite/Body.cpp b/source/sprites/Body.cpp old mode 100755 new mode 100644 similarity index 95% rename from source/sprite/Body.cpp rename to source/sprites/Body.cpp index 989b443..cab4608 --- a/source/sprite/Body.cpp +++ b/source/sprites/Body.cpp @@ -1,13 +1,13 @@ -/* - * Body.cpp - * - * Created on: 13.09.2012 - * Author: Felix - */ - -#include "Body.h" - -Body::Body(b2World& world, const Vector2f& position, const Yaml& config) : - Sprite(config, PhysicalData(position, world, CATEGORY_NONSOLID, MASK_NONE, false)) { -} - +/* + * Body.cpp + * + * Created on: 13.09.2012 + * Author: Felix + */ + +#include "Body.h" + +Body::Body(b2World& world, const Vector2f& position, const Yaml& config) : + Sprite(config, PhysicalData(position, world, CATEGORY_NONSOLID, MASK_NONE, false)) { +} + diff --git a/source/sprite/Body.h b/source/sprites/Body.h old mode 100755 new mode 100644 similarity index 93% rename from source/sprite/Body.h rename to source/sprites/Body.h index 4c69003..0e404ac --- a/source/sprite/Body.h +++ b/source/sprites/Body.h @@ -1,23 +1,23 @@ -/* - * Body.h - * - * Created on: 13.09.2012 - * Author: Felix - */ - -#ifndef DG_BODY_H_ -#define DG_BODY_H_ - -#include "../abstract/Sprite.h" -#include "../util/Yaml.h" - -class Sprite; -class Yaml; - -class Body : public Sprite { -// Public functions. -public: - Body(b2World& world, const Vector2f& position, const Yaml& config); -}; - -#endif /* DG_BODY_H_ */ +/* + * Body.h + * + * Created on: 13.09.2012 + * Author: Felix + */ + +#ifndef DG_BODY_H_ +#define DG_BODY_H_ + +#include "../abstract/Sprite.h" +#include "../util/Yaml.h" + +class Sprite; +class Yaml; + +class Body : public Sprite { +// Public functions. +public: + Body(b2World& world, const Vector2f& position, const Yaml& config); +}; + +#endif /* DG_BODY_H_ */ diff --git a/source/sprite/Cover.cpp b/source/sprites/Cover.cpp old mode 100755 new mode 100644 similarity index 95% rename from source/sprite/Cover.cpp rename to source/sprites/Cover.cpp index 9257b76..4d04770 --- a/source/sprite/Cover.cpp +++ b/source/sprites/Cover.cpp @@ -1,13 +1,13 @@ -/* - * Cover.cpp - * - * Created on: 12.08.2012 - * Author: Felix - */ - -#include "Cover.h" - -Cover::Cover(const Vector2f& position, const Vector2i& size, b2World& world, const Yaml& config) : - Sprite(config, PhysicalData(position, world, CATEGORY_WORLD, MASK_ALL, false), size) { -} - +/* + * Cover.cpp + * + * Created on: 12.08.2012 + * Author: Felix + */ + +#include "Cover.h" + +Cover::Cover(const Vector2f& position, const Vector2i& size, b2World& world, const Yaml& config) : + Sprite(config, PhysicalData(position, world, CATEGORY_WORLD, MASK_ALL, false), size) { +} + diff --git a/source/sprite/Cover.h b/source/sprites/Cover.h old mode 100755 new mode 100644 similarity index 94% rename from source/sprite/Cover.h rename to source/sprites/Cover.h index 1c96952..b5357a9 --- a/source/sprite/Cover.h +++ b/source/sprites/Cover.h @@ -1,26 +1,26 @@ -/* - * Cover.h - * - * Created on: 12.08.2012 - * Author: Felix - */ - -#ifndef DG_COVER_H_ -#define DG_COVER_H_ - -#include "../abstract/Sprite.h" -#include "../util/Yaml.h" - -class Sprite; -class Yaml; - -/** - * A wall that can be placed anywhere (not limited by tiles) and have any (rectangular) size. - */ -class Cover : public Sprite { -// Public functions. -public: - Cover(const Vector2f& position, const Vector2i& size, b2World& world, const Yaml& config); -}; - -#endif /* DG_COVER_H_ */ +/* + * Cover.h + * + * Created on: 12.08.2012 + * Author: Felix + */ + +#ifndef DG_COVER_H_ +#define DG_COVER_H_ + +#include "../abstract/Sprite.h" +#include "../util/Yaml.h" + +class Sprite; +class Yaml; + +/** + * A wall that can be placed anywhere (not limited by tiles) and have any (rectangular) size. + */ +class Cover : public Sprite { +// Public functions. +public: + Cover(const Vector2f& position, const Vector2i& size, b2World& world, const Yaml& config); +}; + +#endif /* DG_COVER_H_ */ diff --git a/source/sprite/Enemy.cpp b/source/sprites/Enemy.cpp similarity index 95% rename from source/sprite/Enemy.cpp rename to source/sprites/Enemy.cpp index b5f3444..094e477 100644 --- a/source/sprite/Enemy.cpp +++ b/source/sprites/Enemy.cpp @@ -1,21 +1,21 @@ -/* - * Enemy.cpp - * - * Created on: 10.09.2012 - * Author: Felix - */ - -#include "Enemy.h" - -#include "Body.h" - -Enemy::Enemy(const Instances& instances, const Vector2f& position, const Yaml& config) : - Character(instances, "enemy.png", PhysicalData(position, instances.world, - CATEGORY_ACTOR, MASK_ALL, true, false, true), config), - mWorld(instances.world), - mCollection(instances.collection) { -} - -void -Enemy::onThink(float elapsedTime) { -} +/* + * Enemy.cpp + * + * Created on: 10.09.2012 + * Author: Felix + */ + +#include "Enemy.h" + +#include "Body.h" + +Enemy::Enemy(const Instances& instances, const Vector2f& position, const Yaml& config) : + Character(instances, "enemy.png", PhysicalData(position, instances.world, + CATEGORY_ACTOR, MASK_ALL, true, false, true), config), + mWorld(instances.world), + mCollection(instances.collection) { +} + +void +Enemy::onThink(float elapsedTime) { +} diff --git a/source/sprite/Enemy.h b/source/sprites/Enemy.h similarity index 85% rename from source/sprite/Enemy.h rename to source/sprites/Enemy.h index afe6b6e..7515acc 100644 --- a/source/sprite/Enemy.h +++ b/source/sprites/Enemy.h @@ -1,37 +1,37 @@ -/* - * Enemy.h - * - * Created on: 10.09.2012 - * Author: Felix - */ - -#ifndef DG_ENEMY_H_ -#define DG_ENEMY_H - -#include "../util/Instances.h" -#include "../abstract/Character.h" -#include "../util/Collection.h" -#include "../util/Vector.h" -#include "../util/Yaml.h" - -class Character; -class Collection; -class Instances; -class Yaml; - -class Enemy : public Character { -// Public functions. -public: - Enemy(const Instances& instances, const Vector2f& position, const Yaml& config); - -// Private functions. -private: - void onThink(float elapsedTime); - -// Private variablese. -private: - b2World& mWorld; - Collection& mCollection; -}; - -#endif /* DG_ENEMY_H_ */ +/* + * Enemy.h + * + * Created on: 10.09.2012 + * Author: Felix + */ + +#ifndef DG_ENEMY_H_ +#define DG_ENEMY_H + +#include "../types/Instances.h" +#include "../abstract/Character.h" +#include "../util/Collection.h" +#include "../types/Vector.h" +#include "../util/Yaml.h" + +class Character; +class Collection; +class Instances; +class Yaml; + +class Enemy : public Character { +// Public functions. +public: + Enemy(const Instances& instances, const Vector2f& position, const Yaml& config); + +// Private functions. +private: + void onThink(float elapsedTime); + +// Private variablese. +private: + b2World& mWorld; + Collection& mCollection; +}; + +#endif /* DG_ENEMY_H_ */ diff --git a/source/sprite/Player.cpp b/source/sprites/Player.cpp similarity index 93% rename from source/sprite/Player.cpp rename to source/sprites/Player.cpp index ea89a35..3ed95c5 100644 --- a/source/sprite/Player.cpp +++ b/source/sprites/Player.cpp @@ -1,106 +1,106 @@ -/* - * Player.cpp - * - * Created on: 21.07.2012 - * Author: Felix - */ - -#include "Player.h" - -#include - -#include "../util/Vector.h" -#include "../items/Weapon.h" -#include "../util/String.h" - -/** - * Initializes Sprite. +/* + * Player.cpp + * + * Created on: 21.07.2012 + * Author: Felix + */ + +#include "Player.h" + +#include + +#include "../items/Weapon.h" +#include "../types/String.h" +#include "../types/Vector.h" + +/** + * Initializes Sprite. + */ +Player::Player(const Instances& instances, const Vector2f& position, const Yaml& config) : + Character(instances, "player.png", PhysicalData(position, instances.world, + CATEGORY_ACTOR, MASK_ALL, true, false, true), config), + mDirection(0) { +} + +/** + * Sets the point where to look and shoot at. + * + * @param Absolute world coordinates of the crosshair. */ -Player::Player(const Instances& instances, const Vector2f& position, const Yaml& config) : - Character(instances, "player.png", PhysicalData(position, instances.world, - CATEGORY_ACTOR, MASK_ALL, true, false, true), config), - mDirection(0) { -} - -/** - * Sets the point where to look and shoot at. - * - * @param Absolute world coordinates of the crosshair. - */ -void -Player::setCrosshairPosition(const Vector2f& position) { - mCrosshairPosition = position - getPosition(); -} - -/** - * Fires the attached Weapon, emitting a Bullet object. - */ -void -Player::fire() { - Character::fire(); -} - -/** - * Moves the player to a destination point. - * Disables any previous calls to Player::setDirection(). - * - * @param destination Absolute world coordinate of the destination point. - */ void -Player::move(const Vector2f& destination) { +Player::setCrosshairPosition(const Vector2f& position) { + mCrosshairPosition = position - getPosition(); +} + +/** + * Fires the attached Weapon, emitting a Bullet object. + */ +void +Player::fire() { + Character::fire(); +} + +/** + * Moves the player to a destination point. + * Disables any previous calls to Player::setDirection(). + * + * @param destination Absolute world coordinate of the destination point. + */ +void +Player::move(const Vector2f& destination) { setDestination(destination); -} - -/** - * Sets the movement direction. This is destined for input via keys (eg. WASD). - * Disables any previous commands via Player::move(). - * - * @param direction The direction to move to. - * @param unset False to start movement into the direction, true to stop it. - */ -void -Player::setDirection(Direction direction, bool unset) { - if (unset) { - mDirection = mDirection & ~(uint8) direction; - } else { - mDirection = mDirection | (uint8) direction; - } - // Convert directions into a vector. - Vector2f dirVec(0, 0); - if (mDirection & (uint8) Direction::RIGHT) { - dirVec.x += 1.0f; - } - if (mDirection & (uint8) Direction::LEFT) { - dirVec.x += - 1.0f; - } - if (mDirection & (uint8) Direction::DOWN) { - dirVec.y += 1.0f; - } - if (mDirection & (uint8) Direction::UP) { - dirVec.y += - 1.0f; - } - setSpeed(dirVec, getMovementSpeed()); -} - -/** - * Check if we arrived at destination, turn towards cursor. - */ -void -Player::onThink(float elapsedTime) { - if (!mDirection) { - // Only use path finding movement if no direct input movement active. - Character::move(); - } - // Look towards crosshair. - setAngle(angle(mCrosshairPosition)); -} - -/** - * Stop movement if we collide with anything except bullets. - */ -void -Player::onCollide(Physical& other, uint16 category) { - if (category != CATEGORY_PARTICLE) { - setDestination(getPosition()); - } -} +} + +/** + * Sets the movement direction. This is destined for input via keys (eg. WASD). + * Disables any previous commands via Player::move(). + * + * @param direction The direction to move to. + * @param unset False to start movement into the direction, true to stop it. + */ +void +Player::setDirection(Direction direction, bool unset) { + if (unset) { + mDirection = mDirection & ~(uint8) direction; + } else { + mDirection = mDirection | (uint8) direction; + } + // Convert directions into a vector. + Vector2f dirVec(0, 0); + if (mDirection & (uint8) Direction::RIGHT) { + dirVec.x += 1.0f; + } + if (mDirection & (uint8) Direction::LEFT) { + dirVec.x += - 1.0f; + } + if (mDirection & (uint8) Direction::DOWN) { + dirVec.y += 1.0f; + } + if (mDirection & (uint8) Direction::UP) { + dirVec.y += - 1.0f; + } + setSpeed(dirVec, getMovementSpeed()); +} + +/** + * Check if we arrived at destination, turn towards cursor. + */ +void +Player::onThink(float elapsedTime) { + if (!mDirection) { + // Only use path finding movement if no direct input movement active. + Character::move(); + } + // Look towards crosshair. + setAngle(angle(mCrosshairPosition)); +} + +/** + * Stop movement if we collide with anything except bullets. + */ +void +Player::onCollide(Physical& other, uint16 category) { + if (category != CATEGORY_PARTICLE) { + setDestination(getPosition()); + } +} diff --git a/source/sprite/Player.h b/source/sprites/Player.h similarity index 89% rename from source/sprite/Player.h rename to source/sprites/Player.h index 03c2960..a7c039f 100644 --- a/source/sprite/Player.h +++ b/source/sprites/Player.h @@ -1,63 +1,63 @@ -/* - * Player.h - * - * Created on: 21.07.2012 - * Author: Felix - */ - -#ifndef DG_PLAYER_H_ -#define DG_PLAYER_H_ - -#include -#include - -#include "../util/Instances.h" -#include "../Pathfinder.h" -#include "../abstract/Character.h" -#include "../items/Weapon.h" -#include "../util/Vector.h" -#include "../util/Yaml.h" - -class Character; -class Instances; -class Pathfinder; -class Weapon; -class Yaml; - -/** - * Player object. - */ -class Player : public Character { -// Public types. -public: - /** - * Movement directions that can be set via Player::setDirection(). - */ - enum class Direction : uint8 { - RIGHT = 1 << 0, - LEFT = 1 << 1, - UP = 1 << 2, - DOWN = 1 << 3 - }; - -// Public functions. +/* + * Player.h + * + * Created on: 21.07.2012 + * Author: Felix + */ + +#ifndef DG_PLAYER_H_ +#define DG_PLAYER_H_ + +#include +#include + +#include "../abstract/Character.h" +#include "../items/Weapon.h" +#include "../types/Instances.h" +#include "../types/Vector.h" +#include "../util/Pathfinder.h" +#include "../util/Yaml.h" + +class Character; +class Instances; +class Pathfinder; +class Weapon; +class Yaml; + +/** + * Player object. + */ +class Player : public Character { +// Public types. +public: + /** + * Movement directions that can be set via Player::setDirection(). + */ + enum class Direction : uint8 { + RIGHT = 1 << 0, + LEFT = 1 << 1, + UP = 1 << 2, + DOWN = 1 << 3 + }; + +// Public functions. public: Player(const Instances& instances, const Vector2f& position, const Yaml& config); - - void setCrosshairPosition(const Vector2f& position); - void fire(); - void move(const Vector2f& destination); - void setDirection(Direction direction, bool unset); - -// Private functions. -private: - void onCollide(Physical& other, uint16 category); - void onThink(float elapsedTime); - -// Private variables. -private: - Vector2f mCrosshairPosition; //< Relative position of the point to fire at (mouse cursor). - uint8 mDirection; //< Current movement direction for direct control. -}; - -#endif /* DG_PLAYER_H_ */ + + void setCrosshairPosition(const Vector2f& position); + void fire(); + void move(const Vector2f& destination); + void setDirection(Direction direction, bool unset); + +// Private functions. +private: + void onCollide(Physical& other, uint16 category); + void onThink(float elapsedTime); + +// Private variables. +private: + Vector2f mCrosshairPosition; //< Relative position of the point to fire at (mouse cursor). + uint8 mDirection; //< Current movement direction for direct control. +}; + +#endif /* DG_PLAYER_H_ */ diff --git a/source/TileManager.cpp b/source/sprites/TileManager.cpp old mode 100755 new mode 100644 similarity index 91% rename from source/TileManager.cpp rename to source/sprites/TileManager.cpp index 3c50622..cc8244f --- a/source/TileManager.cpp +++ b/source/sprites/TileManager.cpp @@ -1,103 +1,103 @@ -/* - * TileManager.cpp - * - * Created on: 08.08.2012 - * Author: Felix - */ - -#include "TileManager.h" - -#include - -#include "abstract/Sprite.h" -#include "util/Loader.h" -#include "util/ResourceManager.h" -#include "util/String.h" - -const Vector2i TileManager::TILE_SIZE = Vector2i(100, 100); - -/** - * Loads tile resources. - * - * @param world Box2D world to create (physical) tiles in. - */ +/* + * TileManager.cpp + * + * Created on: 08.08.2012 + * Author: Felix + */ + +#include "TileManager.h" + +#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); + +/** + * Loads tile resources. + * + * @param world Box2D world to create (physical) tiles in. + */ TileManager::TileManager(b2World& world) : mWorld(world) { -} - -/** - * Constructs a tile. - * - * @param pType Type of the tile to create. - * @param pPosition Position of the tile in tile coordinates. - * @param world Box2D world object. +} + +/** + * Constructs a tile. + * + * @param pType Type of the tile to create. + * @param pPosition Position of the tile in tile coordinates. + * @param world Box2D world object. */ -TileManager::Tile::Tile(Type type, const TilePosition& position, b2World& world) : - Sprite(Yaml(getConfig(type)), PhysicalData(Vector2f(position.x * TILE_SIZE.x, position.y * TILE_SIZE.y), - world, CATEGORY_WORLD, (type == Type::FLOOR) ? MASK_NONE : MASK_ALL, false)), - mType(type) { -} - -/** - * Returns a texture key for a certain tile type. - * - * @param type The type of tile to load a resource key for. - * @return Resource key to the correct texture. - */ -String -TileManager::Tile::getConfig(Type type) { - String filename; - switch (type) { - case Type::FLOOR: - filename = "tile_floor.yaml"; - break; - case Type::WALL: - filename = "tile_wall.yaml"; - break; - default: - throw new aurora::Exception("Invalid tile type."); - } - return filename; -} - -/** - * Returns the Type of this tile. - */ -TileManager::Type -TileManager::Tile::getType() const { - return mType; -} - -/** - * Returns the position of the tile with tile width/height as a unit. - */ -TileManager::TilePosition -TileManager::Tile::getTilePosition() const { +TileManager::Tile::Tile(Type type, const TilePosition& position, b2World& world) : + Sprite(Yaml(getConfig(type)), PhysicalData(Vector2f(position.x * TILE_SIZE.x, position.y * TILE_SIZE.y), + world, CATEGORY_WORLD, (type == Type::FLOOR) ? MASK_NONE : MASK_ALL, false)), + mType(type) { +} + +/** + * Returns a texture key for a certain tile type. + * + * @param type The type of tile to load a resource key for. + * @return Resource key to the correct texture. + */ +String +TileManager::Tile::getConfig(Type type) { + String filename; + switch (type) { + case Type::FLOOR: + filename = "tile_floor.yaml"; + break; + case Type::WALL: + filename = "tile_wall.yaml"; + break; + default: + throw new aurora::Exception("Invalid tile type."); + } + return filename; +} + +/** + * Returns the Type of this tile. + */ +TileManager::Type +TileManager::Tile::getType() const { + return mType; +} + +/** + * Returns the position of the tile with tile width/height as a unit. + */ +TileManager::TilePosition +TileManager::Tile::getTilePosition() const { return TilePosition(getPosition().x / TILE_SIZE.x, getPosition().y / TILE_SIZE.y); -} - -/** - * Insert a tile at the position. Deletes an existing tile first if one is at the position. - * - * @param position Grid coordinate of the tile (not pixel coordinate). - * @param type Type of tile to be inserted. - */ +} + +/** + * Insert a tile at the position. Deletes an existing tile first if one is at the position. + * + * @param position Grid coordinate of the tile (not pixel coordinate). + * @param type Type of tile to be inserted. + */ void -TileManager::setTile(const TilePosition& position, Type type) { - for (auto it = mTiles.begin(); it != mTiles.end(); it++) { - if ((*it)->getTilePosition() == position) { - mTiles.erase(it); - } - } +TileManager::setTile(const TilePosition& position, Type type) { + for (auto it = mTiles.begin(); it != mTiles.end(); it++) { + if ((*it)->getTilePosition() == position) { + mTiles.erase(it); + } + } mTiles.push_back(std::unique_ptr(new Tile(type, position, mWorld))); -} - -/** - * \copydoc sf::Drawable::draw - */ -void -TileManager::draw(sf::RenderTarget& target, sf::RenderStates states) const { - for (auto it = mTiles.begin(); it != mTiles.end(); it++) { - target.draw((**it), states); - } -} +} + +/** + * \copydoc sf::Drawable::draw + */ +void +TileManager::draw(sf::RenderTarget& target, sf::RenderStates states) const { + for (auto it = mTiles.begin(); it != mTiles.end(); it++) { + target.draw((**it), states); + } +} diff --git a/source/TileManager.h b/source/sprites/TileManager.h old mode 100755 new mode 100644 similarity index 88% rename from source/TileManager.h rename to source/sprites/TileManager.h index e198bf3..433d2b2 --- a/source/TileManager.h +++ b/source/sprites/TileManager.h @@ -1,79 +1,79 @@ -/* - * TileManager.h - * - * Created on: 08.08.2012 - * Author: Felix - */ - -#ifndef DG_TILEMANAGER_H_ -#define DG_TILEMANAGER_H_ - -#include -#include -#include - -#include - -#include "util/Vector.h" -#include "abstract/Sprite.h" -#include "util/String.h" - -class Sprite; - -class TileManager : public sf::Drawable { -// Public types. -public: - enum class Type { - FLOOR, - WALL - }; - - /** - * Uses the length/width of a tile as a unit. - */ - typedef Vector2i TilePosition; - -// Public variables. -public: - /// The size of a single tile (pixels). - static const Vector2i TILE_SIZE; - -// Public functions. -public: - TileManager(b2World& world); - - void setTile(const TilePosition& position, Type type); - -// Private types. -private: - class Tile; - -// Private functions. -private: - void draw(sf::RenderTarget& target, sf::RenderStates states) const; - -// Private variables. -private: - b2World& mWorld; - std::vector > mTiles; -}; - -/** - * Holds information about a single tile. - */ -class TileManager::Tile : public Sprite { -// Public functions. -public: - Tile(Type type, const TilePosition& position, b2World& world); - - Type getType() const; - TilePosition getTilePosition() const; - - static String getConfig(Type type); - -// Private variables. +/* + * TileManager.h + * + * Created on: 08.08.2012 + * Author: Felix + */ + +#ifndef DG_TILEMANAGER_H_ +#define DG_TILEMANAGER_H_ + +#include +#include +#include + +#include + +#include "../abstract/Sprite.h" +#include "../types/Vector.h" +#include "../types/String.h" + +class Sprite; + +class TileManager : public sf::Drawable { +// Public types. +public: + enum class Type { + FLOOR, + WALL + }; + + /** + * Uses the length/width of a tile as a unit. + */ + typedef Vector2i TilePosition; + +// Public variables. +public: + /// The size of a single tile (pixels). + static const Vector2i TILE_SIZE; + +// Public functions. +public: + TileManager(b2World& world); + + void setTile(const TilePosition& position, Type type); + +// Private types. +private: + class Tile; + +// Private functions. +private: + void draw(sf::RenderTarget& target, sf::RenderStates states) const; + +// Private variables. +private: + b2World& mWorld; + std::vector > mTiles; +}; + +/** + * Holds information about a single tile. + */ +class TileManager::Tile : public Sprite { +// Public functions. +public: + Tile(Type type, const TilePosition& position, b2World& world); + + Type getType() const; + TilePosition getTilePosition() const; + + static String getConfig(Type type); + +// Private variables. private: Type mType; -}; - -#endif /* DG_TILEMANAGER_H_ */ +}; + +#endif /* DG_TILEMANAGER_H_ */ diff --git a/source/util/Instances.h b/source/types/Instances.h similarity index 85% rename from source/util/Instances.h rename to source/types/Instances.h index ee3b262..2819bca 100644 --- a/source/util/Instances.h +++ b/source/types/Instances.h @@ -10,9 +10,9 @@ #include -#include "../Pathfinder.h" -#include "../TileManager.h" -#include "Collection.h" +#include "../sprites/TileManager.h" +#include "../util/Collection.h" +#include "../util/Pathfinder.h" class Pathfinder; class TileManager; diff --git a/source/util/String.h b/source/types/String.h similarity index 94% rename from source/util/String.h rename to source/types/String.h index ac1f136..7e5bbd6 100644 --- a/source/util/String.h +++ b/source/types/String.h @@ -1,50 +1,50 @@ -/* - * 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_ */ +/* + * 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/util/Vector.h b/source/types/Vector.h old mode 100755 new mode 100644 similarity index 94% rename from source/util/Vector.h rename to source/types/Vector.h index 6df33c9..1205079 --- a/source/util/Vector.h +++ b/source/types/Vector.h @@ -1,84 +1,84 @@ -/* - * Vector.h - * - * Created on: 03.08.2012 - * Author: Felix - */ - -#ifndef VECTOR_H_ -#define VECTOR_H_ - -#include - -#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; - -/** - * Constant for conversion between Box2D vectors and SFML vectors. - */ -static const int PIXELS_PER_METER = 25; - -/** - * Converts a distance from pixels to meters. - */ -inline float -pixelToMeter(float in) { - return in / PIXELS_PER_METER; -} - -/** - * Converts a distance from meters to pixels. - */ -inline float -meterToPixel(float in) { - return in * PIXELS_PER_METER; -} - -/** - * Converts Box2D metric vector to SFML pixel vector. - */ -inline Vector2f -vector(const b2Vec2& in) { - return Vector2f(meterToPixel(in.x), meterToPixel(in.y)); -} - -/** - * Converts SFML pixel vector to Box2D metric vector. - */ -inline b2Vec2 -vector(const Vector2f& in) { - return b2Vec2(pixelToMeter(in.x), pixelToMeter(in.y)); -} - -/** - * Converts a vector to an SFML angle with the same direction. - */ -inline float -angle(Vector2f in) { - return 180 - thor::toDegree(atan2(in.x, in.y)); -} - -/** - * Converts an SFML angle to a unit vector with the same direction. - */ -inline Vector2f -angle(float in) { - in = thor::toRadian(180 - in); - return Vector2f(sin(in), cos(in)); -} - - -#endif /* VECTOR_H_ */ +/* + * Vector.h + * + * Created on: 03.08.2012 + * Author: Felix + */ + +#ifndef VECTOR_H_ +#define VECTOR_H_ + +#include + +#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; + +/** + * Constant for conversion between Box2D vectors and SFML vectors. + */ +static const int PIXELS_PER_METER = 25; + +/** + * Converts a distance from pixels to meters. + */ +inline float +pixelToMeter(float in) { + return in / PIXELS_PER_METER; +} + +/** + * Converts a distance from meters to pixels. + */ +inline float +meterToPixel(float in) { + return in * PIXELS_PER_METER; +} + +/** + * Converts Box2D metric vector to SFML pixel vector. + */ +inline Vector2f +vector(const b2Vec2& in) { + return Vector2f(meterToPixel(in.x), meterToPixel(in.y)); +} + +/** + * Converts SFML pixel vector to Box2D metric vector. + */ +inline b2Vec2 +vector(const Vector2f& in) { + return b2Vec2(pixelToMeter(in.x), pixelToMeter(in.y)); +} + +/** + * Converts a vector to an SFML angle with the same direction. + */ +inline float +angle(Vector2f in) { + return 180 - thor::toDegree(atan2(in.x, in.y)); +} + +/** + * Converts an SFML angle to a unit vector with the same direction. + */ +inline Vector2f +angle(float in) { + in = thor::toRadian(180 - in); + return Vector2f(sin(in), cos(in)); +} + + +#endif /* VECTOR_H_ */ diff --git a/source/util/Loader.h b/source/util/Loader.h index 16e5914..b4801ae 100755 --- a/source/util/Loader.h +++ b/source/util/Loader.h @@ -16,7 +16,7 @@ #include -#include "Singleton.h" +#include "../abstract/Singleton.h" template class Singleton; diff --git a/source/util/Log.h b/source/util/Log.h index 263ec74..140a08d 100644 --- a/source/util/Log.h +++ b/source/util/Log.h @@ -10,7 +10,7 @@ #include -#include "Vector.h" +#include "../types/Vector.h" /** * Logging functions for different levels. diff --git a/source/Pathfinder.cpp b/source/util/Pathfinder.cpp similarity index 99% rename from source/Pathfinder.cpp rename to source/util/Pathfinder.cpp index da1cd74..84b846f 100644 --- a/source/Pathfinder.cpp +++ b/source/util/Pathfinder.cpp @@ -23,8 +23,7 @@ #include #include -#include "util/Log.h" -#include +#include "../util/Log.h" // Boost interface type declarations. enum class Direction; diff --git a/source/Pathfinder.h b/source/util/Pathfinder.h similarity index 90% rename from source/Pathfinder.h rename to source/util/Pathfinder.h index d2a9a3d..f82824d 100644 --- a/source/Pathfinder.h +++ b/source/util/Pathfinder.h @@ -10,8 +10,8 @@ #include -#include "abstract/Physical.h" -#include "util/Vector.h" +#include "../abstract/Physical.h" +#include "../types/Vector.h" /** * Interface class for Boost Graph A* library. diff --git a/source/util/ResourceManager.h b/source/util/ResourceManager.h index 4ef94bf..aa5743d 100644 --- a/source/util/ResourceManager.h +++ b/source/util/ResourceManager.h @@ -12,7 +12,7 @@ #include -#include "Singleton.h" +#include "../abstract/Singleton.h" template class Singleton; diff --git a/source/util/Yaml.h b/source/util/Yaml.h index 02e5240..ca58e80 100644 --- a/source/util/Yaml.h +++ b/source/util/Yaml.h @@ -12,8 +12,8 @@ #include -#include "String.h" -#include "Vector.h" +#include "../types/String.h" +#include "../types/Vector.h" namespace details {};