Simple CPP Game Class Documentation
For the full class documentation, see the full Doxygen output.
EntityEngine
-
class EntityEngine
A engine for handling a component entity system.
Public Functions
Adds a system to the engine.
Adds the provided system to the engine. The call site and the engine will share ownership of the system through the shared_ptr created by the copy constructor when calling this method. Systems will have update() called on them each frame in the same order they are added to the engine, so if processing order is important, care should be taken when organizing calls to add().
- Parameters
system – the system to be added to the engine
Adds an entity to the engine.
Adds the provided entity to the engine. The call site, the engine, and any systems that choose to will share ownership of the entity through copies of the shared_ptr. Systems will only be informed of the addition of an entity if EntityEngine::add(std::shared_ptr<Entity> entity) is called after EntityEngine::add(std::shared_ptr<EntitySystem> system), so take care with ordering calls during initialization
- Parameters
entity – the entity to add to the engine
-
void update(const sf::Time deltaTime)
Updates all systems in the engine.
See also
- Parameters
deltaTime – The amount of time that has passed since the last update.
EntitySystem
-
class EntitySystem
A class representing a system that processes groups of Entity in an EntityEngine.
An abstract class to be extended by specific implementations.
Subclassed by IteratingSystem
Public Functions
-
EntitySystem()
Construct a new default EntitySystem.
This creates an EntitySystem that processes all Entities added to the EntityEngine if EntitySystem::engineEngineEntityAdded is not overridden.
Construct a new EntitySystem that acts on a specified family.
- Parameters
family – The family of entities that this system will act on. The EntitySystem implementation of EntitySystem::engineEntityAdded adds all entities to the system for which this family’s implementation of EntityFamily::isInFamily returns true.
Performs any operations required after an entity has been added to an EntityEngine the system is a part of.
The default implementation adds the Entity to the Entities property (EntitySystem::getEntities) if the default constructor was called or the Entity is in the family provided to the family constructor.
- Parameters
entity – The Entity recently added to the EntityEngine.
-
virtual void update(const sf::Time deltaTime) = 0
Performs any operations necessary in routine processing.
This method is pure virtual in EntitySystem.
- Parameters
deltaTime – The time that has passed since update() was last called.
-
EntitySystem()
Entity
-
class Entity
An entity in the game’s component entity system.
The Entity represents a collection of attributes, called Components, that together are acted upon by EntitySystem objects that form a complete game world.
Public Functions
-
Entity(int id)
Construct a new Entity object with a specific ID.
- Parameters
id – The ID of the Entity
Adds the provided component to the entity.
The entity will create a new std::shared_ptr pointing to the Component using the copy constructor that will stay in scope with the entity.
- Parameters
component – The Component to add to this Entity.
-
class Component
A component of an entity in the game’s component entity system.
Components represent an aspect of an Entity. They store state information, such as position and sprite data, as well as mark the Entity as belong to a certain class of object, like being the player or an AI opponent.
Component types are identified with their ID, which is passed to the constructor. To avoid odd bugs and behavior, all instances of the same Component subclass should have the same ID, which is usually declared as a static member of the class or a preprocessor constant in the header file.
Subclassed by BallComponent, EnemyComponent, LocationComponent, PlayerComponent, RenderComponent, VelocityComponent
Public Functions
-
Component(const std::string id)
Construct a new Component object.
- Parameters
id – The Component’s ID
-
virtual ~Component()
This is only declared to make the class polymorphic so that dymaic_cast between Component types works.
-
const std::string getId() const
Get the ID of the component. This will return the same value for all instances of a class of Component.
-
Component(const std::string id)
-
Entity(int id)
Component
-
class Component
A component of an entity in the game’s component entity system.
Components represent an aspect of an Entity. They store state information, such as position and sprite data, as well as mark the Entity as belong to a certain class of object, like being the player or an AI opponent.
Component types are identified with their ID, which is passed to the constructor. To avoid odd bugs and behavior, all instances of the same Component subclass should have the same ID, which is usually declared as a static member of the class or a preprocessor constant in the header file.
Subclassed by BallComponent, EnemyComponent, LocationComponent, PlayerComponent, RenderComponent, VelocityComponent
Public Functions
-
Component(const std::string id)
Construct a new Component object.
- Parameters
id – The Component’s ID
-
virtual ~Component()
This is only declared to make the class polymorphic so that dymaic_cast between Component types works.
-
const std::string getId() const
Get the ID of the component. This will return the same value for all instances of a class of Component.
-
Component(const std::string id)