From 7b89705cc5c491b60dab923e2f8079cfc1f4bce1 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 15 Oct 2015 21:14:04 +0300 Subject: Convert BlockType into strong typed enum. --- src/being/actorsprite.h | 2 +- src/being/being.h | 2 +- src/enums/resources/map/blocktype.h | 28 ++++++++++++++-------------- src/resources/beinginfo.h | 6 +++--- src/resources/map/map.cpp | 6 +++--- src/resources/map/map.h | 4 ++-- 6 files changed, 24 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/being/actorsprite.h b/src/being/actorsprite.h index a1f0993b6..93fddedce 100644 --- a/src/being/actorsprite.h +++ b/src/being/actorsprite.h @@ -80,7 +80,7 @@ class ActorSprite notfinal : public CompoundSprite, public Actor /** * Gets the way the object blocks pathfinding for other objects */ - virtual BlockType::BlockType getBlockType() const A_WARN_UNUSED + virtual BlockTypeT getBlockType() const A_WARN_UNUSED { return BlockType::NONE; } /** diff --git a/src/being/being.h b/src/being/being.h index 3105edc0e..8253cca55 100644 --- a/src/being/being.h +++ b/src/being/being.h @@ -400,7 +400,7 @@ class Being notfinal : public ActorSprite, /** * Gets the way the monster blocks pathfinding for other objects */ - BlockType::BlockType getBlockType() const override A_WARN_UNUSED + BlockTypeT getBlockType() const override A_WARN_UNUSED { if (!mInfo) return BlockType::NONE; diff --git a/src/enums/resources/map/blocktype.h b/src/enums/resources/map/blocktype.h index 5909703cb..0b5ee9179 100644 --- a/src/enums/resources/map/blocktype.h +++ b/src/enums/resources/map/blocktype.h @@ -23,20 +23,20 @@ #ifndef ENUMS_RESOURCES_MAP_BLOCKTYPE_H #define ENUMS_RESOURCES_MAP_BLOCKTYPE_H -namespace BlockType +#include "enums/simpletypes/enumdefines.h" + +enumStart(BlockType) { - enum BlockType - { - NONE = -1, - WALL, - CHARACTER, - MONSTER, - AIR, - WATER, - GROUND, - GROUNDTOP, - NB_BLOCKTYPES - }; -} // namespace BlockType + NONE = -1, + WALL, + CHARACTER, + MONSTER, + AIR, + WATER, + GROUND, + GROUNDTOP, + NB_BLOCKTYPES +} +enumEnd(BlockType); #endif // ENUMS_RESOURCES_MAP_BLOCKTYPE_H diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h index ad5f35a85..a4ee2a750 100644 --- a/src/resources/beinginfo.h +++ b/src/resources/beinginfo.h @@ -119,10 +119,10 @@ class BeingInfo final unsigned char getBlockWalkMask() const A_WARN_UNUSED { return mBlockWalkMask; } - void setBlockType(const BlockType::BlockType &blockType) + void setBlockType(const BlockTypeT &blockType) { mBlockType = blockType; } - BlockType::BlockType getBlockType() const A_WARN_UNUSED + BlockTypeT getBlockType() const A_WARN_UNUSED { return mBlockType; } void setTargetOffsetX(const int n) @@ -338,7 +338,7 @@ class BeingInfo final Attacks mAttacks; std::vector mMenu; unsigned char mBlockWalkMask; - BlockType::BlockType mBlockType; + BlockTypeT mBlockType; const std::map *mColors; int mTargetOffsetX; int mTargetOffsetY; diff --git a/src/resources/map/map.cpp b/src/resources/map/map.cpp index e206edef2..e1407af91 100644 --- a/src/resources/map/map.cpp +++ b/src/resources/map/map.cpp @@ -148,7 +148,7 @@ Map::Map(const int width, const int height, mDrawOnlyFringe(false) { const int size = mWidth * mHeight; - for (int i = 0; i < BlockType::NB_BLOCKTYPES; i++) + for (size_t i = 0; i < static_cast(BlockType::NB_BLOCKTYPES); i++) { mOccupation[i] = new unsigned[static_cast(size)]; memset(mOccupation[i], 0, static_cast(size) @@ -171,7 +171,7 @@ Map::~Map() CHECKLISTENERS delete [] mMetaTiles; - for (int i = 0; i < BlockType::NB_BLOCKTYPES; i++) + for (size_t i = 0; i < static_cast(BlockType::NB_BLOCKTYPES); i++) delete [] mOccupation[i]; if (mWalkLayer) @@ -690,7 +690,7 @@ const Tileset *Map::getTilesetWithGid(const int gid) const } void Map::blockTile(const int x, const int y, - const BlockType::BlockType type) + const BlockTypeT type) { if (type == BlockType::NONE || !contains(x, y)) return; diff --git a/src/resources/map/map.h b/src/resources/map/map.h index 33b819c04..49e0459f2 100644 --- a/src/resources/map/map.h +++ b/src/resources/map/map.h @@ -146,7 +146,7 @@ class Map final : public Properties, public ConfigListener * Marks a tile as occupied. */ void blockTile(const int x, const int y, - const BlockType::BlockType type); + const BlockTypeT type); /** * Gets walkability for a tile with a blocking bitmask. When called @@ -378,7 +378,7 @@ class Map final : public Properties, public ConfigListener /** * Blockmasks for different entities */ - unsigned *mOccupation[BlockType::NB_BLOCKTYPES]; + unsigned *mOccupation[static_cast(BlockType::NB_BLOCKTYPES)]; const int mWidth; const int mHeight; -- cgit v1.2.3-70-g09d2