Added comments and clarified headers.

This commit is contained in:
Felix Ableitner 2012-09-16 20:45:12 +02:00
parent 3cc8c93845
commit 77d78b3936
10 changed files with 45 additions and 23 deletions

View file

@ -22,7 +22,7 @@
class Sprite; class Sprite;
class TileManager : public sf::Drawable { class TileManager : public sf::Drawable {
// Public constants. // Public variables.
public: public:
/// The size of a single tile (pixels). /// The size of a single tile (pixels).
static const Vector2i TILE_SIZE; static const Vector2i TILE_SIZE;
@ -76,6 +76,4 @@ private:
Type mType; Type mType;
}; };
#endif /* DG_TILEMANAGER_H_ */ #endif /* DG_TILEMANAGER_H_ */

View file

@ -43,13 +43,15 @@ public:
bool moving; bool moving;
/// True if the object is a bullet. /// True if the object is a bullet.
bool bullet; bool bullet;
/// True if the body collides as a circle. Radius is side length / 2, both sides must be equal. /// True if the body collides as a circle. Radius is side length / 2,
/// both sides must be equal.
bool circle; bool circle;
}; };
/** /**
* Categories of physical objects, for Box2D collision filtering. * Categories of physical objects, for Box2D collision filtering.
* The order of categories is also used for render order. * The order of categories is also used for render order in Collection::draw()
* (higher number on top).
* *
* @warning An object may only have one category. * @warning An object may only have one category.
*/ */
@ -61,7 +63,7 @@ public:
}; };
/** /**
* Common Box2D collision masking values. * Common collision masking values.
*/ */
enum Mask { enum Mask {
MASK_NONE = 0xffff, //< Disables any collisions. MASK_NONE = 0xffff, //< Disables any collisions.
@ -88,13 +90,10 @@ protected:
void setSpeed(Vector2f direction, float speed); void setSpeed(Vector2f direction, float speed);
void setAngle(float angle); void setAngle(float angle);
// Protected variables.
protected:
// Currently protected to allow for (debug only) direct player input.
b2Body* mBody;
// Private variables. // Private variables.
private: private:
b2Body* mBody;
bool mDelete; bool mDelete;
}; };

View file

@ -8,7 +8,6 @@
#include "Sprite.h" #include "Sprite.h"
#include "../util/Loader.h" #include "../util/Loader.h"
#include "../util/Log.h"
#include "../util/String.h" #include "../util/String.h"
#include "../util/ResourceManager.h" #include "../util/ResourceManager.h"

View file

@ -23,14 +23,18 @@ class Physical;
* Handles drawing to world. * Handles drawing to world.
*/ */
class Sprite : public sf::Drawable, public Physical { class Sprite : public sf::Drawable, public Physical {
// Public functions.
public: public:
Sprite(const sf::String& texturePath, const PhysicalData& data); Sprite(const sf::String& texturePath, const PhysicalData& data);
Sprite(const std::shared_ptr<sf::Texture>& texture, const PhysicalData& data); Sprite(const std::shared_ptr<sf::Texture>& texture, const PhysicalData& data);
virtual ~Sprite() = 0; virtual ~Sprite() = 0;
private: // Protected functions.
protected:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
// Private variables.
private:
std::shared_ptr<sf::Texture> mTexture; std::shared_ptr<sf::Texture> mTexture;
Vector2i mSize; Vector2i mSize;
}; };

View file

@ -16,6 +16,7 @@ class Sprite;
* Prototype for a particle. * Prototype for a particle.
*/ */
class Particle : public Sprite { class Particle : public Sprite {
// Public functions.
public: public:
Particle(const std::shared_ptr<sf::Texture>& texture, const PhysicalData& data); Particle(const std::shared_ptr<sf::Texture>& texture, const PhysicalData& data);
virtual ~Particle(); virtual ~Particle();

View file

@ -16,6 +16,7 @@ class Sprite;
* A wall that can be placed anywhere (not limited by tiles) and have any (rectangular) size. * A wall that can be placed anywhere (not limited by tiles) and have any (rectangular) size.
*/ */
class Cover : public Sprite { class Cover : public Sprite {
// Public functions.
public: public:
Cover(const Vector2f& position, const Vector2i& size, b2World& world); Cover(const Vector2f& position, const Vector2i& size, b2World& world);
}; };

View file

@ -21,6 +21,7 @@ class Sprite;
* A collection of sprites, which can be put into different layers. * A collection of sprites, which can be put into different layers.
* *
* Uses Sprite instead of sf::Drawable to also manage deleting objects. * Uses Sprite instead of sf::Drawable to also manage deleting objects.
* Render order is determined by Physical::Category (higher number on top).
*/ */
class Collection : public sf::Drawable { class Collection : public sf::Drawable {
// Public functions. // Public functions.

View file

@ -10,28 +10,37 @@
#include <iostream> #include <iostream>
/**
* Logging functions for different levels.
*
* @code
* LOG_E("something bad happened");
* LOG_I("takeoff" << 3 << 2 << 1);
* @endcode
*/
/** /**
* \def LOG_E(str) * \def LOG_E(str)
* Log an error to the error stream. * Log an error to the error stream.
*/ */
#define LOG_E(str) std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " \"" << str << "\"" << std::endl #define LOG_E(str) std::cout << __FILE__ << ":" << __LINE__ << " " << "Error: " << str << "\"" << std::endl
/** /**
* \def LOG_E(str) * \def LOG_E(str)
* Log a warning to the output stream. * Log a warning to the output stream.
*/ */
#define LOG_W(str) std::cout << "Warning: " << __FILE__ << ":" << __LINE__ << " \"" << str << "\"" << std::endl #define LOG_W(str) std::cout << __FILE__ << ":" << __LINE__ << " " << "Warning: " << str << "\"" << std::endl
/** /**
* \def LOG_E(str) * \def LOG_E(str)
* Log a debug message to the output stream. * Log a debug message to the output stream.
*/ */
#define LOG_D(str) std::cout << "Debug: " << __FILE__ << ":" << __LINE__ << " \"" << str << "\"" << std::endl #define LOG_D(str) std::cout << __FILE__ << ":" << __LINE__ << " " << "Debug: " << str << "" << std::endl
/** /**
* \def LOG_E(str) * \def LOG_E(str)
* Log an info to the output stream. * Log an info to the output stream.
*/ */
#define LOG_I(str) std::cout << "Info: " << __FILE__ << ":" << __LINE__ << " \"" << str << "\"" << std::endl #define LOG_I(str) std::cout << __FILE__ << ":" << __LINE__ << " " << "Info: " << str << "\"" << std::endl
#endif /* DG_LOG_H_ */ #endif /* DG_LOG_H_ */

View file

@ -17,11 +17,11 @@
template <class T> template <class T>
class Singleton; class Singleton;
/** /**
* Loads and manages all resources by providing Singleton access to Thor ResourceManager. * Loads and manages all resources by providing Singleton access to Thor ResourceManager.
*/ */
class ResourceManager : public thor::MultiResourceCache, public Singleton<ResourceManager> { class ResourceManager : public thor::MultiResourceCache, public Singleton<ResourceManager> {
// Private functions.
private: private:
friend class Singleton<ResourceManager>; friend class Singleton<ResourceManager>;
ResourceManager() = default; ResourceManager() = default;

View file

@ -13,14 +13,24 @@
/** /**
* Template class for inheriting singleton behaviour. * 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<T> * To use, just make a subclass with only a private default constructor and Singleton<T>
* as friend class. * as friend class.
*
* @code
* class MyClass : public Singleton<MyClass> {
* private:
* friend class Singleton<MyClass>;
* MyClass() = default;
* };
* @endcode
*/ */
template <class T> template <class T>
class Singleton : public sf::NonCopyable { class Singleton : public sf::NonCopyable {
// Public functions.
public: public:
/** /**
* Get the instance of this class. * Returns the instance of T.
*/ */
static T& i() { static T& i() {
static T s; static T s;