From 273153709cb4ab51bd3002f8c69ed15b959e9b7b Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 4 Apr 2013 23:00:52 +0200 Subject: [PATCH] Removed unneeded comments, improved documentation. --- source/Game.cpp | 1 - source/Game.h | 4 --- source/World.cpp | 49 +++++++++++++++++++---------------- source/World.h | 4 --- source/abstract/Character.cpp | 2 +- source/abstract/Character.h | 3 --- source/effects/Bullet.h | 2 -- source/items/Weapon.h | 7 ++--- source/particle/Emitter.h | 3 --- source/particle/Particle.h | 1 - source/sprites/Corpse.h | 1 - source/sprites/Enemy.h | 1 - source/sprites/Player.cpp | 5 ---- source/sprites/Player.h | 4 --- source/sprites/TileManager.h | 11 +------- source/util/Loader.h | 4 --- source/util/ResourceManager.h | 1 - source/util/Yaml.h | 2 -- 18 files changed, 30 insertions(+), 75 deletions(-) diff --git a/source/Game.cpp b/source/Game.cpp index 952a239..6d3f9be 100644 --- a/source/Game.cpp +++ b/source/Game.cpp @@ -11,7 +11,6 @@ #include "sprites/Player.h" #include "util/Yaml.h" -/// Goal amount of frames per second. const int Game::FPS_GOAL = 60; /** diff --git a/source/Game.h b/source/Game.h index 85996ea..fbf5953 100644 --- a/source/Game.h +++ b/source/Game.h @@ -19,14 +19,12 @@ class World; * Use vertex for tiles. */ class Game : private sf::NonCopyable { -// Public functions. public: explicit Game(sf::RenderWindow& window); ~Game(); void loop(); -// Private functions. private: void input(); void render(); @@ -39,7 +37,6 @@ private: void generate(); sf::Vector2 convertCoordinates(int x, int y); -// Private variables. private: static const int FPS_GOAL; @@ -55,5 +52,4 @@ private: bool mPaused; }; - #endif /* DG_GAME_H_ */ diff --git a/source/World.cpp b/source/World.cpp index 3e812f6..404581d 100755 --- a/source/World.cpp +++ b/source/World.cpp @@ -130,45 +130,48 @@ World::astarArea(Area* start, Area* end) const { return std::vector(); } - std::unordered_set closedset; // The set of nodes already evaluated. - // Set of nodes to be evaluated, with corresponding estimated cost start -> area -> goal - std::unordered_map openset; - // The map of navigated nodes, with previous, lowest cost Area/Portal. - std::unordered_map> came_from; - std::unordered_map g_score; // Cost from start along best known path. + std::unordered_set closed; + std::unordered_map openAreasEstimatedCost; + // Navigated areas with previous area/portal. + std::unordered_map> previousAreaAndPortal; + std::unordered_map bestPathCost; - openset[start] = heuristic_cost_estimate(start, end); - g_score[start] = 0; + openAreasEstimatedCost[start] = heuristic_cost_estimate(start, end); + bestPathCost[start] = 0; - while (!openset.empty()) { - // the node in openset having the lowest f_score value. - Area* current = std::min_element(openset.begin(), openset.end())->first; + while (!openAreasEstimatedCost.empty()) { + Area* current = std::min_element(openAreasEstimatedCost.begin(), + openAreasEstimatedCost.end())->first; if (current == end) { std::vector path; auto previous = current; while (previous != start) { - path.push_back(came_from[previous].second); - previous = came_from[previous].first; + path.push_back(previousAreaAndPortal[previous].second); + previous = previousAreaAndPortal[previous].first; } return path; } - openset.erase(current); - closedset.insert(current); + openAreasEstimatedCost.erase(current); + closed.insert(current); for (Portal& portal : current->portals) { Area* neighbor = portal.area; - // Use edge weight instead of heuristic cost estimate? - float tentative_g_score = g_score[current] + heuristic_cost_estimate(current,neighbor); - if (closedset.find(neighbor) != closedset.end()) { - if (tentative_g_score >= g_score[neighbor]) { + float tentative_g_score = bestPathCost[current] + + heuristic_cost_estimate(current,neighbor); + if (closed.find(neighbor) != closed.end()) { + if (tentative_g_score >= bestPathCost[neighbor]) { continue; } } - if ((openset.find(neighbor) == openset.end()) || (tentative_g_score < g_score[neighbor])) { - came_from[neighbor] = std::make_pair(current, &portal); - g_score[neighbor] = tentative_g_score; - openset[neighbor] = g_score[neighbor] + heuristic_cost_estimate(neighbor, end); + if ((openAreasEstimatedCost.find(neighbor) == + openAreasEstimatedCost.end()) || + (tentative_g_score < bestPathCost[neighbor])) { + previousAreaAndPortal[neighbor] = std::make_pair(current, + &portal); + bestPathCost[neighbor] = tentative_g_score; + openAreasEstimatedCost[neighbor] = bestPathCost[neighbor] + + heuristic_cost_estimate(neighbor, end); } } } diff --git a/source/World.h b/source/World.h index 6d7a301..2a9742c 100755 --- a/source/World.h +++ b/source/World.h @@ -21,7 +21,6 @@ class Sprite; * Render order is determined by Physical::Category (higher number on top). */ class World : public sf::Drawable { -// Public functions. public: void insert(std::shared_ptr drawable); void remove(std::shared_ptr drawable); @@ -35,7 +34,6 @@ public: std::vector > getCharacters(const sf::Vector2f& position, float maxDistance) const; -// Private types. private: struct Area; /** @@ -58,7 +56,6 @@ private: std::vector portals; }; -// Private functions. private: void draw(sf::RenderTarget& target, sf::RenderStates states) const; bool testCollision(std::shared_ptr spriteA, std::shared_ptr spriteB, @@ -67,7 +64,6 @@ private: float heuristic_cost_estimate(Area* start, Area* end) const; std::vector astarArea(Area* start, Area* end) const; -// Private variables. private: std::map > > mDrawables; std::vector mAreas; //< This has to be a vector as objects are compared by address. diff --git a/source/abstract/Character.cpp b/source/abstract/Character.cpp index 0a67dde..16b02a7 100644 --- a/source/abstract/Character.cpp +++ b/source/abstract/Character.cpp @@ -118,7 +118,7 @@ Character::setDestination(const sf::Vector2f& destination) { /** * Move towards a destination. Call setDestination() for setting the destination. - * This should be called from think(). + * This should be called from think() if path finding is to be used. */ void Character::move() { diff --git a/source/abstract/Character.h b/source/abstract/Character.h index edbf222..633cc91 100644 --- a/source/abstract/Character.h +++ b/source/abstract/Character.h @@ -18,14 +18,12 @@ class Yaml; * Provides think function for AI, manages health, drops body on death. */ class Character : public Sprite { -// Public functions. public: explicit Character(World& world, const Data& data, const Yaml& config); virtual ~Character() = 0; void onDamage(int damage); -// Protected functions. protected: virtual void onThink(int elapsed); virtual void onDeath(); @@ -36,7 +34,6 @@ protected: void move(); std::vector > getCharacters(float maxDistance) const; -// Private variables. private: static const std::string KEY_HEALTH; static const int DEFAULT_HEALTH; diff --git a/source/effects/Bullet.h b/source/effects/Bullet.h index 5dacf39..2c7e728 100755 --- a/source/effects/Bullet.h +++ b/source/effects/Bullet.h @@ -16,14 +16,12 @@ class Yaml; * Bullet particle fired by a weapon, may damage actors. */ class Bullet : public Particle { -// Public functions. public: explicit Bullet(const sf::Vector2f& position, Sprite& shooter, sf::Vector2f direction, const Yaml& config); void onCollide(std::shared_ptr other); -// Private variables. private: static const std::string KEY_DAMAGE; static const int DEFAULT_DAMAGE; diff --git a/source/items/Weapon.h b/source/items/Weapon.h index d3d5f7d..ca98387 100755 --- a/source/items/Weapon.h +++ b/source/items/Weapon.h @@ -24,20 +24,17 @@ class Particle; * - pass enum value and load mapped xml * - pass xml filename */ -class Weapon : public Emitter { -// Public functions. +class Weapon : public Emitter { public: explicit Weapon(World& world, Sprite& holder, const Yaml& config); void pullTrigger(); void releaseTrigger(); void onThink(int elapsed); - -// Protected functions. + protected: std::shared_ptr createParticle(); -// Private variables. private: static const std::string KEY_BULLET; static const std::string DEFAULT_BULLET; diff --git a/source/particle/Emitter.h b/source/particle/Emitter.h index 75cda73..2d3bb02 100755 --- a/source/particle/Emitter.h +++ b/source/particle/Emitter.h @@ -15,18 +15,15 @@ class Particle; class Sprite; class Emitter { -// Public functions. public: explicit Emitter(World& world); virtual ~Emitter(); -// Protected functions. protected: void emit(); /// Creates a particle. Allows to use a user-defined particle class and custom settings. virtual std::shared_ptr createParticle() = 0; -// Private variables. private: World& mWorld; }; diff --git a/source/particle/Particle.h b/source/particle/Particle.h index e5f4b45..1a91b72 100755 --- a/source/particle/Particle.h +++ b/source/particle/Particle.h @@ -16,7 +16,6 @@ class Yaml; * Prototype for a particle. */ class Particle : public Sprite { -// Public functions. public: explicit Particle(const Yaml& config, const Data& data); virtual ~Particle(); diff --git a/source/sprites/Corpse.h b/source/sprites/Corpse.h index d00d28e..074e01b 100644 --- a/source/sprites/Corpse.h +++ b/source/sprites/Corpse.h @@ -13,7 +13,6 @@ class Yaml; class Corpse : public Sprite { -// Public functions. public: explicit Corpse(const sf::Vector2f& position, const Yaml& config); }; diff --git a/source/sprites/Enemy.h b/source/sprites/Enemy.h index 809b8ab..d61ed3d 100644 --- a/source/sprites/Enemy.h +++ b/source/sprites/Enemy.h @@ -14,7 +14,6 @@ class World; class Yaml; class Enemy : public Character { -// Public functions. public: explicit Enemy(World& world, const sf::Vector2f& position, const Yaml& config); }; diff --git a/source/sprites/Player.cpp b/source/sprites/Player.cpp index 0c0a126..24ff903 100644 --- a/source/sprites/Player.cpp +++ b/source/sprites/Player.cpp @@ -81,10 +81,5 @@ Player::setDirection(Direction direction, bool unset) { void Player::onThink(int elapsed) { Character::onThink(elapsed); - if (!mDirection) { - // Only use path finding movement if no direct input movement active. - Character::move(); - } - // Look towards crosshair. Sprite::setDirection(mCrosshairPosition); } diff --git a/source/sprites/Player.h b/source/sprites/Player.h index 9501423..fb5e632 100644 --- a/source/sprites/Player.h +++ b/source/sprites/Player.h @@ -17,7 +17,6 @@ class World; * Player object. */ class Player : public Character { -// Public types. public: /** * Movement directions that can be set via Player::setDirection(). @@ -29,7 +28,6 @@ public: DOWN = 1 << 3 }; -// Public functions. public: explicit Player(World& world, const sf::Vector2f& position, const Yaml& config); @@ -38,11 +36,9 @@ public: void releaseTrigger(); void setDirection(Direction direction, bool unset); -// Private functions. private: void onThink(int elapsed); -// Private variables. private: 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.h b/source/sprites/TileManager.h index 0d116cf..4377a66 100644 --- a/source/sprites/TileManager.h +++ b/source/sprites/TileManager.h @@ -13,7 +13,6 @@ class World; class TileManager : public sf::Drawable { -// Public types. public: enum class Type { FLOOR, @@ -25,12 +24,9 @@ public: */ typedef sf::Vector2i TilePosition; -// Public variables. public: - /// The size of a single tile (pixels). - static const sf::Vector2i TILE_SIZE; + static const sf::Vector2i TILE_SIZE; //< Tile size in pixels. -// Public functions. public: explicit TileManager(World& world); @@ -39,15 +35,12 @@ public: bool raycast(const sf::Vector2f& lineStart, const sf::Vector2f& lineEnd) const; -// Private types. private: class Tile; -// Private functions. private: void draw(sf::RenderTarget& target, sf::RenderStates states) const; -// Private variables. private: World& mWorld; std::vector > mTiles; @@ -57,7 +50,6 @@ private: * Holds information about a single tile. */ class TileManager::Tile : public Sprite { -// Public functions. public: explicit Tile(Type type, const TilePosition& position); @@ -66,7 +58,6 @@ public: static std::string getConfig(Type type); -// Private variables. private: Type mType; }; diff --git a/source/util/Loader.h b/source/util/Loader.h index fe29035..b1cf85e 100755 --- a/source/util/Loader.h +++ b/source/util/Loader.h @@ -37,7 +37,6 @@ * @endcode */ class Loader : public Singleton { -// Public functions. public: /** * Sets the general resource folder path. @@ -60,7 +59,6 @@ public: return static_cast* >(getLoader().get())->fromFile(mFolder, file); } -// Private types. private: /** * We need this to save templates of different types in the same container. @@ -99,7 +97,6 @@ private: std::string mSubfolder; }; -// Private functions. private: /** * For Singleton behaviour. @@ -122,7 +119,6 @@ private: } }; -// Private variables. private: std::string mFolder; std::map > mLoaders; diff --git a/source/util/ResourceManager.h b/source/util/ResourceManager.h index b045b8a..e9a797a 100644 --- a/source/util/ResourceManager.h +++ b/source/util/ResourceManager.h @@ -16,7 +16,6 @@ */ class ResourceManager : public thor::MultiResourceCache, public Singleton { -// Private functions. private: friend class Singleton; ResourceManager() { diff --git a/source/util/Yaml.h b/source/util/Yaml.h index 9871c98..742b8ba 100644 --- a/source/util/Yaml.h +++ b/source/util/Yaml.h @@ -21,7 +21,6 @@ * Interface to a YAML file. */ class Yaml { -// Public functions. public: explicit Yaml(const std::string& filename); ~Yaml(); @@ -33,7 +32,6 @@ public: template T get(const std::string& key, const T& defaultValue) const; -// Private variables. private: static std::string mFolder;