Added comments and clarified headers.
This commit is contained in:
parent
3cc8c93845
commit
77d78b3936
10 changed files with 45 additions and 23 deletions
|
@ -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_ */
|
||||||
|
|
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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_ */
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -13,19 +13,29 @@
|
||||||
/**
|
/**
|
||||||
* 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:
|
// Public functions.
|
||||||
|
public:
|
||||||
/**
|
/**
|
||||||
* Get the instance of this class.
|
* Returns the instance of T.
|
||||||
*/
|
*/
|
||||||
static T& i() {
|
static T& i() {
|
||||||
static T s;
|
static T s;
|
||||||
return s;
|
return s;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DG_SINGLETON_H_ */
|
#endif /* DG_SINGLETON_H_ */
|
||||||
|
|
Reference in a new issue