15 #ifndef CORGI_ENTITY_MANAGER_H_
16 #define CORGI_ENTITY_MANAGER_H_
23 #include "corgi/version.h"
45 typedef VectorPool<Entity>::VectorPoolReference
EntityRef;
47 class EntityFactoryInterface;
48 class ComponentInterface;
84 return static_cast<T*
>(
98 return static_cast<const T*
>(
110 template <
typename T>
115 assert(
id < components_.size());
116 return static_cast<T*
>(components_[id]);
127 template <
typename T>
132 assert(
id < components_.size());
133 return static_cast<const T*
>(components_[id]);
146 template <
typename T>
151 assert(
id < components_.size());
165 assert(
id < components_.size());
166 return components_[id];
179 assert(
id < components_.size());
180 return components_[id];
195 template <
typename T>
236 template <
typename T>
238 static_assert(std::is_base_of<ComponentInterface, T>::value,
239 "'new_component' must inherit from ComponentInterface");
242 RegisterComponentHelper(new_component, component_id);
290 entity_factory_ = entity_factory;
368 const void* GetComponentDataAsVoid(
EntityRef entity,
381 std::vector<ComponentInterface*> components_;
391 std::vector<EntityRef> entities_to_delete_;
401 const CorgiVersion* version_;
430 #endif // CORGI_ENTITY_MANAGER_H_
IteratorTemplate< false > Iterator
Definition: vector_pool.h:56
Iterator begin()
Get an Iterator to the first active element in the VectorPool.
Definition: vector_pool.h:642
EntityStorageContainer::Iterator end()
Returns an iterator to the last of the active Entities.
Definition: entity_manager.h:276
void DeleteEntityImmediately(EntityRef entity)
Instantly deletes an Entity.
void UpdateComponents(WorldTime delta_time)
Iterates through all the registered Components and causes them to update.
T * GetComponent()
A helper function for getting a particular Component, given the Component's data type.
Definition: entity_manager.h:111
A templated struct for holding type-dependent data.
Definition: component_id_lookup.h:36
void Clear()
Clears all data from all Components, empties the list of Components themselves, and then empties the ...
The EntityManager is the code that manages all Entities and Components in the game. Normally the game will instantiate EntityManager, and then use it to create and control all of its Entities.
Definition: entity_manager.h:61
EntityRef AllocateNewEntity()
Allocates a new Entity (that is registered with no Components).
VectorPool< Entity > EntityStorageContainer
This is used to track all Entities stored by the EntityManager.
Definition: entity_manager.h:72
int WorldTime
A typedef that represents time in the game.
Definition: entity_common.h:49
T * GetComponentData(const EntityRef &entity)
Helper function for marshalling data from a Component.
Definition: entity_manager.h:83
size_t ComponentCount() const
Returns the number of components that have been registered with the entity manager.
Definition: entity_manager.h:188
void DeleteMarkedEntities()
Deletes all the Entities that are marked for deletion.
void AddEntityToComponent(EntityRef entity)
A helper function for adding a Component to an Entity, given its data type.
Definition: entity_manager.h:147
const T * GetComponentData(const EntityRef &entity) const
A helper function for marshalling data from a Component.
Definition: entity_manager.h:97
const ComponentId kInvalidComponent
A sentinel value to represent an invalid Component.
Definition: entity_common.h:44
Iterator end()
Gets an Iterator to the last active element in the VectorPool.
Definition: vector_pool.h:650
VectorPool< corgi::Entity >::VectorPoolReference EntityRef
A typedef that should be used as the primary way to reference an Entity.
Definition: component_interface.h:49
void DeleteEntity(EntityRef entity)
Deletes an Entity by removing it from the EntityManager's list and clearing any Component data associ...
ComponentId GetComponentId()
A helper function to get the component ID for a given Component.
Definition: entity_manager.h:196
void set_entity_factory(EntityFactoryInterface *entity_factory)
Registers an instance of the EntityFactoryInterface as the factory object to be used when Entities ar...
Definition: entity_manager.h:289
EntityStorageContainer::Iterator begin()
Returns an iterator to the beginning of the active Entities. This is suitable for iterating over ever...
Definition: entity_manager.h:271
virtual EntityRef CreateEntityFromData(const void *data, EntityManager *entity_manager)=0
Creates an Entity with a given EntityManager, registers it with all Components specified, and populates the Component data.
A reference object for pointing into the vector pool. It acts as a pointer for vector pool elements a...
Definition: vector_pool.h:72
An interface for an Entity factory, which creates Entities for a given EntityManager.
Definition: entity_manager.h:408
const T * GetComponent() const
A helper function for getting a particular Component, given the Component's data type.
Definition: entity_manager.h:128
const ComponentInterface * GetComponent(ComponentId id) const
A helper function for getting a particular Component, given a component ID.
Definition: entity_manager.h:178
virtual ~EntityFactoryInterface()
A destructor of the entity factory interface.
Definition: entity_manager.h:411
EntityManager()
Constructor for the EntityManager.
void RemoveAllComponents(EntityRef entity)
Removes all Components for an Entity, destroying any data associated with it.
ComponentId RegisterComponent(T *new_component)
Registers a new Component with the EntityManager.
Definition: entity_manager.h:237
uint16_t ComponentId
This represents the ID of a Component.
Definition: entity_common.h:36
const CorgiVersion * GetCorgiVersion()
Returns the version of the Corgi entity library.
Definition: entity_manager.h:67
An interface that provides basic Component functionality. All Components will inherit from this class...
Definition: component_interface.h:57
ComponentInterface * GetComponent(ComponentId id)
A helper function for getting a particular Component, given the component ID.
Definition: entity_manager.h:164
EntityRef CreateEntityFromData(const void *data)
Creates an Entity from arbitrary data. This is normally invoked only by classes that inherit from Ent...