From 8d295df943ad4b34558abd8c2a727e8e2a8e4f01 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 1 Oct 2012 09:41:38 +0200 Subject: [PATCH] Replaced enum with enum class where possible. --- source/Game.cpp | 16 ++++++++-------- source/TileManager.cpp | 10 +++++----- source/TileManager.h | 6 +++--- source/sprite/Player.cpp | 12 ++++++------ source/sprite/Player.h | 10 +++++----- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/source/Game.cpp b/source/Game.cpp index 7edaa97..19f7c87 100644 --- a/source/Game.cpp +++ b/source/Game.cpp @@ -134,16 +134,16 @@ Game::keyUp(const sf::Event& event) { mPaused = !mPaused; break; case sf::Keyboard::W: - mPlayer.setDirection(Player::DIRECTION_UP, true); + mPlayer.setDirection(Player::Direction::UP, true); break; case sf::Keyboard::S: - mPlayer.setDirection(Player::DIRECTION_DOWN, true); + mPlayer.setDirection(Player::Direction::DOWN, true); break; case sf::Keyboard::A: - mPlayer.setDirection(Player::DIRECTION_LEFT, true); + mPlayer.setDirection(Player::Direction::LEFT, true); break; case sf::Keyboard::D: - mPlayer.setDirection(Player::DIRECTION_RIGHT, true); + mPlayer.setDirection(Player::Direction::RIGHT, true); break; default: break; @@ -157,16 +157,16 @@ void Game::keyDown(const sf::Event& event) { switch (event.key.code) { case sf::Keyboard::W: - mPlayer.setDirection(Player::DIRECTION_UP, false); + mPlayer.setDirection(Player::Direction::UP, false); break; case sf::Keyboard::S: - mPlayer.setDirection(Player::DIRECTION_DOWN, false); + mPlayer.setDirection(Player::Direction::DOWN, false); break; case sf::Keyboard::A: - mPlayer.setDirection(Player::DIRECTION_LEFT, false); + mPlayer.setDirection(Player::Direction::LEFT, false); break; case sf::Keyboard::D: - mPlayer.setDirection(Player::DIRECTION_RIGHT, false); + mPlayer.setDirection(Player::Direction::RIGHT, false); break; default: break; diff --git a/source/TileManager.cpp b/source/TileManager.cpp index c31d5c7..c946a13 100755 --- a/source/TileManager.cpp +++ b/source/TileManager.cpp @@ -33,7 +33,7 @@ TileManager::TileManager(b2World& world) : */ TileManager::Tile::Tile(Type type, const TilePosition& position, b2World& world) : Sprite(getTexture(type), PhysicalData(Vector2f(position.x * TILE_SIZE.x, position.y * TILE_SIZE.y), - TILE_SIZE, world, CATEGORY_WORLD, (type == TYPE_FLOOR) ? MASK_NONE : MASK_ALL, false)), + TILE_SIZE, world, CATEGORY_WORLD, (type == Type::FLOOR) ? MASK_NONE : MASK_ALL, false)), mType(type) { } @@ -47,10 +47,10 @@ std::shared_ptr TileManager::Tile::getTexture(Type type) { sf::String filename; switch (type) { - case TYPE_FLOOR: + case Type::FLOOR: filename = "floor.png"; break; - case TYPE_WALL: + case Type::WALL: filename = "wall.png"; break; default: @@ -82,11 +82,11 @@ void TileManager::generate() { for (int x = 0; x < 10; x++) for (int y = 0; y < 10; y++) - setTile(TilePosition(x, y), TYPE_WALL); + setTile(TilePosition(x, y), Type::WALL); for (int x = 1; x < 9; x++) for (int y = 1; y < 9; y++) - setTile(TilePosition(x, y), TYPE_FLOOR); + setTile(TilePosition(x, y), Type::FLOOR); } /** diff --git a/source/TileManager.h b/source/TileManager.h index c54cd5d..fc18847 100755 --- a/source/TileManager.h +++ b/source/TileManager.h @@ -35,9 +35,9 @@ public: // Private types. private: - enum Type { - TYPE_FLOOR, - TYPE_WALL + enum class Type { + FLOOR, + WALL }; /** diff --git a/source/sprite/Player.cpp b/source/sprite/Player.cpp index 0f8caf9..915052f 100644 --- a/source/sprite/Player.cpp +++ b/source/sprite/Player.cpp @@ -76,22 +76,22 @@ Player::move(const Vector2f& destination) { void Player::setDirection(Direction direction, bool unset) { if (unset) { - mDirection = mDirection & ~direction; + mDirection = mDirection & ~(uint8) direction; } else { - mDirection = mDirection | direction; + mDirection = mDirection | (uint8) direction; } // Convert directions into a vector. Vector2f dirVec(0, 0); - if (mDirection & DIRECTION_RIGHT) { + if (mDirection & (uint8) Direction::RIGHT) { dirVec.x += 1.0f; } - if (mDirection & DIRECTION_LEFT) { + if (mDirection & (uint8) Direction::LEFT) { dirVec.x += - 1.0f; } - if (mDirection & DIRECTION_DOWN) { + if (mDirection & (uint8) Direction::DOWN) { dirVec.y += 1.0f; } - if (mDirection & DIRECTION_UP) { + if (mDirection & (uint8) Direction::UP) { dirVec.y += - 1.0f; } setSpeed(dirVec, SPEED); diff --git a/source/sprite/Player.h b/source/sprite/Player.h index 8dd65f1..ae9d71f 100644 --- a/source/sprite/Player.h +++ b/source/sprite/Player.h @@ -31,11 +31,11 @@ public: /** * Movement directions that can be set via Player::setDirection(). */ - enum Direction { - DIRECTION_RIGHT = 1 << 0, - DIRECTION_LEFT = 1 << 1, - DIRECTION_UP = 1 << 2, - DIRECTION_DOWN = 1 << 3 + enum class Direction : uint8 { + RIGHT = 1 << 0, + LEFT = 1 << 1, + UP = 1 << 2, + DOWN = 1 << 3 }; // Public functions.