4#include <unordered_map>
6#include "../Datastructures/typemap.h"
7#include "../Systems/invokableSystemManager.h"
8#include "../Systems/system.h"
9#include "../Entity/entity.h"
15class IComponentContainer;
17template<
typename Component>
18class ComponentContainer;
22template<
typename... Component>
28class GameWorld :
public std::enable_shared_from_this<GameWorld> {
62 template<
typename Component,
typename ...Args>
72 template<
typename Component>
84 template<
typename Component>
95 template<
typename Component>
104 template<
typename Component>
111 template<
typename Component>
112 std::shared_ptr<ComponentContainer<Component>>
viewAll();
120 template<
typename... Component>
129 template<
typename... Component>
145 template <
class KeyType>
146 int getTypeId() {
return componentMap.getTypeId<KeyType>(); }
156 template<
typename Event,
typename... DataType>
168 template<
typename Event,
typename... DataType>
169 void deliverEvent(Event event, Entity entity, DataType... args);
180 template<
typename... Component>
186 std::unordered_map<Entity, Signature> entitySignatures;
187 std::unordered_map<Signature, std::shared_ptr<IComponentGroup>> componentGroups;
Effectively a list of tuples each entry containing an Entity and ComponentReference to each of the co...
Definition: componentGroup.h:45
Reference to a component. Will be valid as long as that component exists on a specific Entity,...
Definition: componentReference.h:16
Maintains a game world, where Entity, Component, Systems, and MetaSystems can be added,...
Definition: gameworld.h:28
ComponentReference< Component > getComponent(const Entity entity)
Get a reference to a Component on the specified entity.
Definition: gameworld.inl:44
SystemManager & getSystems()
Get the SystemManager object.
Definition: gameworld.h:137
GameWorld()
Construct a new Game World object.
Definition: gameworld.cpp:7
std::shared_ptr< ComponentContainer< Component > > viewAll()
Definition: gameworld.inl:37
virtual ~GameWorld()
Destroy the Game World object.
Definition: gameworld.cpp:11
int getTypeId()
Get an id for a type, useful for keeping multiple typemaps consistent.
Definition: gameworld.h:146
void removeComponent(const Entity entity)
Remove a component from an Entity.
Definition: gameworld.inl:59
Entity getEntity(Component *component)
Get the Entity from a pointer to a component.
Definition: gameworld.inl:54
void destroyEntity(Entity entity)
Destoy an Entity object.
Definition: gameworld.cpp:22
ComponentReference< Component > emplace(const Entity entity, Args &&...args)
Emplace a component to an Entity. This constructs the component instead of adding them.
Definition: gameworld.inl:12
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 cal...
Definition: gameworld.inl:127
InvokableSystemManager systemManager
where all the systems are stored and can potentially be invoked.
Definition: gameworld.h:183
void broadcastEvent(Event event, DataType... args)
Broadcast an event to the world, so that Systems that listen to the event can be triggered.
Definition: gameworld.inl:122
Signature createSignature()
Create a signature from a list of component types.
Definition: gameworld.inl:114
Entity createEntity()
Create a Entity object.
Definition: gameworld.cpp:15
bool hasComponent(const Entity entity)
Determine if an entity has a specific type of Component attached.
Definition: gameworld.inl:49
std::shared_ptr< ComponentGroup< Component... > > registerGroup()
Register a ComponentGroup.
Definition: gameworld.inl:75
entity_type entity_cnt
number of entities in the world. Useful for assigning new entities.
Definition: gameworld.h:172
std::shared_ptr< ComponentGroup< Component... > > viewGroup()
Compute the view of a Group. It is mandatory that this group is registered before this operation,...
Definition: gameworld.inl:95
A SystemManager where stages and events can be invoked.
Definition: invokableSystemManager.h:12
Manages Systems in the ECS model. Allows for System to be added, but not invoked.
Definition: systemManager.h:17
Map that has Types as key.
Definition: typemap.h:15
std::uint32_t entity_type
Definition: entity.h:7
std::bitset< MAX_COMPONENTS > Signature
Used for determining if an object has a certain component type. Signature [i] is true if it does,...
Definition: signature.h:12