Maintains a game world, where Entity, Component, Systems, and MetaSystems can be added, and events such as Startup, Update, FixedUpdate, and Draw can be invoked.
More...
#include <gameworld.h>
|
| GameWorld () |
| Construct a new Game World object.
|
|
virtual | ~GameWorld () |
| Destroy the Game World object.
|
|
Entity | createEntity () |
| Create a Entity object.
|
|
void | destroyEntity (Entity entity) |
| Destoy an Entity object.
|
|
template<typename Component , typename ... Args> |
ComponentReference< Component > | emplace (const Entity entity, Args &&...args) |
| Emplace a component to an Entity. This constructs the component instead of adding them.
|
|
template<typename Component > |
ComponentReference< Component > | getComponent (const Entity entity) |
| Get a reference to a Component on the specified entity.
|
|
template<typename Component > |
Entity | getEntity (Component *component) |
| Get the Entity from a pointer to a component.
|
|
template<typename Component > |
bool | hasComponent (const Entity entity) |
| Determine if an entity has a specific type of Component attached.
|
|
template<typename Component > |
void | removeComponent (const Entity entity) |
| Remove a component from an Entity.
|
|
template<typename Component > |
std::shared_ptr< ComponentContainer< Component > > | viewAll () |
|
template<typename... Component> |
std::shared_ptr< ComponentGroup< Component... > > | registerGroup () |
| Register a ComponentGroup.
|
|
template<typename... Component> |
std::shared_ptr< ComponentGroup< Component... > > | viewGroup () |
| Compute the view of a Group. It is mandatory that this group is registered before this operation, and before any components were added to the world.
|
|
SystemManager & | getSystems () |
| Get the SystemManager object.
|
|
template<class KeyType > |
int | getTypeId () |
| Get an id for a type, useful for keeping multiple typemaps consistent.
|
|
template<typename Event , typename... DataType> |
void | broadcastEvent (Event event, DataType... args) |
| Broadcast an event to the world, so that Systems that listen to the event can be triggered.
|
|
template<typename Event , typename... DataType> |
void | deliverEvent (Event event, Entity entity, DataType... args) |
| Deliver an event to a specific object. Only System that registers to that specific object will be called.
|
|
Maintains a game world, where Entity, Component, Systems, and MetaSystems can be added, and events such as Startup, Update, FixedUpdate, and Draw can be invoked.
◆ GameWorld()
Saga::GameWorld::GameWorld |
( |
| ) |
|
Construct a new Game World object.
◆ ~GameWorld()
Saga::GameWorld::~GameWorld |
( |
| ) |
|
|
virtual |
Destroy the Game World object.
◆ broadcastEvent()
template<typename Event , typename... DataType>
void Saga::GameWorld::broadcastEvent |
( |
Event |
event, |
|
|
DataType... |
args |
|
) |
| |
Broadcast an event to the world, so that Systems that listen to the event can be triggered.
- Template Parameters
-
Event | can be anything castable to an int. |
DataType | the type of parameters used to broadcast the event, and also the types that the Systems will receive. |
- Parameters
-
event | |
args | arguments for the Systems that are listening to this event. |
◆ createEntity()
Entity Saga::GameWorld::createEntity |
( |
| ) |
|
Create a Entity object.
- Returns
- Entity
◆ createSignature()
template<typename... Component>
Create a signature from a list of component types.
- Template Parameters
-
Component | a list of component types, in alphabetical order. |
- Returns
- Signature the correponding signature.
◆ deliverEvent()
template<typename Event , typename... DataType>
void Saga::GameWorld::deliverEvent |
( |
Event |
event, |
|
|
Entity |
entity, |
|
|
DataType... |
args |
|
) |
| |
Deliver an event to a specific object. Only System that registers to that specific object will be called.
- Template Parameters
-
Event | anything castable to an int. |
DataType | the type of parameters used in the delivery. |
- Parameters
-
event | |
entity | the entity to deliver the event to. |
args | arguments for the Systems that are listening to this event. |
◆ destroyEntity()
void Saga::GameWorld::destroyEntity |
( |
Entity |
entity | ) |
|
Destoy an Entity object.
- Parameters
-
◆ emplace()
template<typename Component , typename... Args>
ComponentReference< Component > Saga::GameWorld::emplace |
( |
const Entity |
entity, |
|
|
Args &&... |
args |
|
) |
| |
Emplace a component to an Entity. This constructs the component instead of adding them.
- Template Parameters
-
Component | The type of the Component. |
Args | The type of the parameters used to construct the Component. |
- Parameters
-
entity | |
args | the arguments used the construct the Component |
- Returns
- ComponentReference<Component> a reference to the Component.
- Exceptions
-
std::invalid_argument | if the entity already has that Component. For this reason, it is good to check give if the component exists. |
◆ getComponent()
template<typename Component >
Get a reference to a Component on the specified entity.
- Template Parameters
-
Component | the type of the component to look for. |
- Parameters
-
- Returns
- ComponentReference<Component> a reference to that component. This reference can be a non-reference, which evaluates to nullptr.
◆ getEntity()
template<typename Component >
Entity Saga::GameWorld::getEntity |
( |
Component * |
component | ) |
|
Get the Entity from a pointer to a component.
- Template Parameters
-
Component | the type of component you use. |
- Parameters
-
- Returns
- Entity the entity, or -1 if none exists.
- Warning
- this runs in O(n), where n is the number of components of that type.
◆ getSystems()
◆ getTypeId()
template<class KeyType >
int Saga::GameWorld::getTypeId |
( |
| ) |
|
|
inline |
Get an id for a type, useful for keeping multiple typemaps consistent.
- Template Parameters
-
- Returns
- int
◆ hasComponent()
template<typename Component >
bool Saga::GameWorld::hasComponent |
( |
const Entity |
entity | ) |
|
Determine if an entity has a specific type of Component attached.
- Template Parameters
-
Component | the type of the Component. |
- Parameters
-
- Returns
- true if it does.
-
false otherwise.
◆ registerGroup()
template<typename... Component>
std::shared_ptr< ComponentGroup< Component... > > Saga::GameWorld::registerGroup |
Register a ComponentGroup.
- Template Parameters
-
Component | a list of components entities in the group must have, in alphabetical order. |
- Returns
- std::shared_ptr<ComponentGroup<Component...>> a shared_ptr to that group.
◆ removeComponent()
template<typename Component >
void Saga::GameWorld::removeComponent |
( |
const Entity |
entity | ) |
|
Remove a component from an Entity.
- Template Parameters
-
Component | type of the component. |
- Parameters
-
◆ viewAll()
template<typename Component >
- Template Parameters
-
Component | type of component to look for. |
- Returns
- std::shared_ptr<ComponentContainer<Component>> a container of components that can be iterated through.
◆ viewGroup()
template<typename... Component>
std::shared_ptr< ComponentGroup< Component... > > Saga::GameWorld::viewGroup |
Compute the view of a Group. It is mandatory that this group is registered before this operation, and before any components were added to the world.
- Template Parameters
-
Component | the types of components the group has, in alphabetical order. |
- Returns
- std::shared_ptr<ComponentGroup<Component...>> a group that can be iterated through, containing all the entities with the specified group.
◆ entity_cnt
number of entities in the world. Useful for assigning new entities.
◆ systemManager
where all the systems are stored and can potentially be invoked.
The documentation for this class was generated from the following files: