Removed unneeded comments, improved documentation.
This commit is contained in:
parent
a094c01d55
commit
273153709c
18 changed files with 30 additions and 75 deletions
|
@ -11,7 +11,6 @@
|
|||
#include "sprites/Player.h"
|
||||
#include "util/Yaml.h"
|
||||
|
||||
/// Goal amount of frames per second.
|
||||
const int Game::FPS_GOAL = 60;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<float> convertCoordinates(int x, int y);
|
||||
|
||||
// Private variables.
|
||||
private:
|
||||
static const int FPS_GOAL;
|
||||
|
||||
|
@ -55,5 +52,4 @@ private:
|
|||
bool mPaused;
|
||||
};
|
||||
|
||||
|
||||
#endif /* DG_GAME_H_ */
|
||||
|
|
|
@ -130,45 +130,48 @@ World::astarArea(Area* start, Area* end) const {
|
|||
return std::vector<World::Portal*>();
|
||||
}
|
||||
|
||||
std::unordered_set<Area*> closedset; // The set of nodes already evaluated.
|
||||
// Set of nodes to be evaluated, with corresponding estimated cost start -> area -> goal
|
||||
std::unordered_map<Area*, float> openset;
|
||||
// The map of navigated nodes, with previous, lowest cost Area/Portal.
|
||||
std::unordered_map<Area*, std::pair<Area*, Portal*>> came_from;
|
||||
std::unordered_map<Area*, float> g_score; // Cost from start along best known path.
|
||||
std::unordered_set<Area*> closed;
|
||||
std::unordered_map<Area*, float> openAreasEstimatedCost;
|
||||
// Navigated areas with previous area/portal.
|
||||
std::unordered_map<Area*, std::pair<Area*, Portal*>> previousAreaAndPortal;
|
||||
std::unordered_map<Area*, float> 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<Portal*> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Sprite> drawable);
|
||||
void remove(std::shared_ptr<Sprite> drawable);
|
||||
|
@ -35,7 +34,6 @@ public:
|
|||
std::vector<std::shared_ptr<Character> >
|
||||
getCharacters(const sf::Vector2f& position, float maxDistance) const;
|
||||
|
||||
// Private types.
|
||||
private:
|
||||
struct Area;
|
||||
/**
|
||||
|
@ -58,7 +56,6 @@ private:
|
|||
std::vector<Portal> portals;
|
||||
};
|
||||
|
||||
// Private functions.
|
||||
private:
|
||||
void draw(sf::RenderTarget& target, sf::RenderStates states) const;
|
||||
bool testCollision(std::shared_ptr<Sprite> spriteA, std::shared_ptr<Sprite> spriteB,
|
||||
|
@ -67,7 +64,6 @@ private:
|
|||
float heuristic_cost_estimate(Area* start, Area* end) const;
|
||||
std::vector<Portal*> astarArea(Area* start, Area* end) const;
|
||||
|
||||
// Private variables.
|
||||
private:
|
||||
std::map<Sprite::Category, std::vector<std::shared_ptr<Sprite> > > mDrawables;
|
||||
std::vector<Area> mAreas; //< This has to be a vector as objects are compared by address.
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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<std::shared_ptr<Character> > getCharacters(float maxDistance) const;
|
||||
|
||||
// Private variables.
|
||||
private:
|
||||
static const std::string KEY_HEALTH;
|
||||
static const int DEFAULT_HEALTH;
|
||||
|
|
|
@ -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<Sprite> other);
|
||||
|
||||
// Private variables.
|
||||
private:
|
||||
static const std::string KEY_DAMAGE;
|
||||
static const int DEFAULT_DAMAGE;
|
||||
|
|
|
@ -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<Sprite> createParticle();
|
||||
|
||||
// Private variables.
|
||||
private:
|
||||
static const std::string KEY_BULLET;
|
||||
static const std::string DEFAULT_BULLET;
|
||||
|
|
|
@ -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<Sprite> createParticle() = 0;
|
||||
|
||||
// Private variables.
|
||||
private:
|
||||
World& mWorld;
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
class Yaml;
|
||||
|
||||
class Corpse : public Sprite {
|
||||
// Public functions.
|
||||
public:
|
||||
explicit Corpse(const sf::Vector2f& position, const Yaml& config);
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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<std::shared_ptr<Tile> > 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;
|
||||
};
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
* @endcode
|
||||
*/
|
||||
class Loader : public Singleton<Loader> {
|
||||
// Public functions.
|
||||
public:
|
||||
/**
|
||||
* Sets the general resource folder path.
|
||||
|
@ -60,7 +59,6 @@ public:
|
|||
return static_cast<SpecificLoader<T>* >(getLoader<T>().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<std::type_index, std::unique_ptr<LoaderBase> > mLoaders;
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
class ResourceManager : public thor::MultiResourceCache,
|
||||
public Singleton<ResourceManager> {
|
||||
// Private functions.
|
||||
private:
|
||||
friend class Singleton<ResourceManager>;
|
||||
ResourceManager() {
|
||||
|
|
|
@ -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 <typename T>
|
||||
T get(const std::string& key, const T& defaultValue) const;
|
||||
|
||||
// Private variables.
|
||||
private:
|
||||
static std::string mFolder;
|
||||
|
||||
|
|
Reference in a new issue