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

void add(std::shared_ptr<EntitySystem> system)

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

void add(std::shared_ptr<Entity> entity)

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.

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.

EntitySystem(const std::shared_ptr<EntityFamily> &family)

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.

virtual void engineEntityAdded(const std::shared_ptr<Entity> &entity)

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.

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()

Construct a new Entity with a random ID.

Entity(int id)

Construct a new Entity object with a specific ID.

Parameters

id – The ID of the Entity

int getId() const

Get the ID of the Entity.

Returns

int the entity’s ID

void add(const std::shared_ptr<Component> &component)

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.

bool hasComponent(const std::string id) const

Check if the Entity has a component of the specified type.

Parameters

id – The ID of the Component type.

Returns

true if the Entity has a component of the specified type.

Returns

false if the Entnity doeso not have a component of the specified type.

std::shared_ptr<Component> getComponent(const std::string id) const

Get the Component object.

Parameters

id

Returns

std::shared_ptr<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

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.