Saga
Saga Game Engine
Loading...
Searching...
No Matches
Saga::GameWorld Class Reference

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>

Inheritance diagram for Saga::GameWorld:
Collaboration diagram for Saga::GameWorld:

Public Member Functions

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

Protected Member Functions

template<typename... Component>
Signature createSignature ()
 Create a signature from a list of component types.
 

Protected Attributes

entity_type entity_cnt
 number of entities in the world. Useful for assigning new entities.
 
InvokableSystemManager systemManager
 where all the systems are stored and can potentially be invoked.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ GameWorld()

Saga::GameWorld::GameWorld ( )

Construct a new Game World object.

◆ ~GameWorld()

Saga::GameWorld::~GameWorld ( )
virtual

Destroy the Game World object.

Member Function Documentation

◆ 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
Eventcan be anything castable to an int.
DataTypethe type of parameters used to broadcast the event, and also the types that the Systems will receive.
Parameters
event
argsarguments for the Systems that are listening to this event.
Here is the call graph for this function:

◆ createEntity()

Entity Saga::GameWorld::createEntity ( )

Create a Entity object.

Returns
Entity

◆ createSignature()

template<typename... Component>
Signature Saga::GameWorld::createSignature
protected

Create a signature from a list of component types.

Template Parameters
Componenta 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
Eventanything castable to an int.
DataTypethe type of parameters used in the delivery.
Parameters
event
entitythe entity to deliver the event to.
argsarguments for the Systems that are listening to this event.
Here is the call graph for this function:

◆ destroyEntity()

void Saga::GameWorld::destroyEntity ( Entity  entity)

Destoy an Entity object.

Parameters
entity

◆ 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
ComponentThe type of the Component.
ArgsThe type of the parameters used to construct the Component.
Parameters
entity
argsthe arguments used the construct the Component
Returns
ComponentReference<Component> a reference to the Component.
Exceptions
std::invalid_argumentif the entity already has that Component. For this reason, it is good to check give if the component exists.
Here is the call graph for this function:

◆ getComponent()

template<typename Component >
ComponentReference< Component > Saga::GameWorld::getComponent ( const Entity  entity)

Get a reference to a Component on the specified entity.

Template Parameters
Componentthe type of the component to look for.
Parameters
entity
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
Componentthe type of component you use.
Parameters
component
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()

SystemManager & Saga::GameWorld::getSystems ( )
inline

Get the SystemManager object.

Returns
SystemManager&

◆ getTypeId()

template<class KeyType >
int Saga::GameWorld::getTypeId ( )
inline

Get an id for a type, useful for keeping multiple typemaps consistent.

Template Parameters
KeyTypethe type.
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
Componentthe type of the Component.
Parameters
entity
Returns
true if it does.
false otherwise.

◆ registerGroup()

template<typename... Component>
std::shared_ptr< ComponentGroup< Component... > > Saga::GameWorld::registerGroup

Register a ComponentGroup.

Template Parameters
Componenta list of components entities in the group must have, in alphabetical order.
Returns
std::shared_ptr<ComponentGroup<Component...>> a shared_ptr to that group.
Here is the call graph for this function:

◆ removeComponent()

template<typename Component >
void Saga::GameWorld::removeComponent ( const Entity  entity)

Remove a component from an Entity.

Template Parameters
Componenttype of the component.
Parameters
entity

◆ viewAll()

template<typename Component >
std::shared_ptr< ComponentContainer< Component > > Saga::GameWorld::viewAll
Template Parameters
Componenttype 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
Componentthe 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.
Here is the call graph for this function:

Member Data Documentation

◆ entity_cnt

entity_type Saga::GameWorld::entity_cnt
protected

number of entities in the world. Useful for assigning new entities.

◆ systemManager

InvokableSystemManager Saga::GameWorld::systemManager
protected

where all the systems are stored and can potentially be invoked.


The documentation for this class was generated from the following files: