3 #include "engine/typedefs.h"
4 #include "util/make_unique.h"
7 #include <unordered_set>
12 class ComponentCollection;
13 class ComponentFactory;
15 class StorageContainer;
54 std::unique_ptr<Component> component
76 std::unique_ptr<C> component
78 return static_cast<C*
>(
81 std::unique_ptr<Component>(std::move(component))
97 std::unordered_set<EntityId>
125 ComponentTypeId typeId
147 template<
class ComponentType>
154 ComponentType::TYPE_ID
156 return static_cast<ComponentType*
>(component);
168 ComponentTypeId typeId
189 const std::string& name,
190 bool forceNew =
false
211 template<
typename C,
typename... Args>
217 auto component = this->getComponent<C>(id);
219 auto newComponent = make_unique<C>(args...);
220 component = newComponent.get();
244 std::unordered_set<ComponentTypeId>
270 const std::string& name
334 ComponentTypeId typeId
459 EntityId oldEntityId,
460 EntityId newEntityId,
465 struct Implementation;
466 std::unique_ptr<Implementation> m_impl;
C * getOrCreateComponent(EntityId id, Args &&...args)
Retrieves a component, creating it if necessary.
Definition: entity_manager.h:213
void removeComponent(EntityId entityId, ComponentTypeId typeId)
Removes a component.
Definition: entity_manager.cpp:227
void processRemovals()
Removes all components queued for removal.
Definition: entity_manager.cpp:188
void setVolatile(EntityId id, bool isVolatile)
Sets the volatile flag for an entity.
Definition: entity_manager.cpp:375
EntityManager()
Constructor.
Definition: entity_manager.cpp:52
void removeEntity(EntityId entityId)
Removes all components of an entity.
Definition: entity_manager.cpp:235
Base class for components.
Definition: component.h:31
bool hasChildren(EntityId entityId) const
Returns whether an entity has any children.
Definition: entity_manager.cpp:354
ComponentCollection & getComponentCollection(ComponentTypeId typeId)
Returns a component collection.
Definition: entity_manager.cpp:128
Manages entities and their components.
Definition: entity_manager.h:23
EntityId getNamedId(const std::string &name, bool forceNew=false)
Returns the id of a named entity.
Definition: entity_manager.cpp:136
A factory for components.
Definition: component_factory.h:19
void processTransfers()
Transfers all components queued for transfer.
void clear()
Removes all components.
Definition: entity_manager.cpp:81
const std::string * getNameMappingFor(EntityId entityId)
Gets the name for a given entityId if it exists.
Definition: entity_manager.cpp:362
void restore(const StorageContainer &storage, const ComponentFactory &factory)
Restores the entity manager from a storage container.
Definition: entity_manager.cpp:298
std::unordered_set< EntityId > entities()
Returns a set of entity ids that have at least one components.
Definition: entity_manager.cpp:94
Component * getComponent(EntityId entityId, ComponentTypeId typeId)
Retrieves a component.
Definition: entity_manager.cpp:118
Definition: bullet_ogre_conversion.h:6
C * addComponent(EntityId entityId, std::unique_ptr< C > component)
Adds a component.
Definition: entity_manager.h:74
Component * addComponent(EntityId entityId, std::unique_ptr< Component > component)
Adds a component.
Definition: entity_manager.cpp:61
void stealName(EntityId entityId, const std::string &name)
Rebinds a name to this entity.
Definition: entity_manager.cpp:167
bool exists(EntityId entityId) const
Checks whether an entity exists.
Definition: entity_manager.cpp:104
ComponentType * getComponent(EntityId entityId)
Convenience template overload.
Definition: entity_manager.h:149
void addChild(EntityId child, EntityId parent)
Sets an entity as another entities child.
Definition: entity_manager.cpp:343
std::unordered_set< ComponentTypeId > nonEmptyCollections() const
Returns the set of non-empty collection ids.
Definition: entity_manager.cpp:176
EntityId generateNewId()
Generates a new, unique entity id.
Definition: entity_manager.cpp:112
The heart of the game.
Definition: engine.h:55
StorageContainer storage(const ComponentFactory &factory) const
Serializes the current non-volatile components into a storage container.
Definition: entity_manager.cpp:388
A key-value storage for serialization.
Definition: serialization.h:36
EntityId loadEntity(StorageContainer storage, const ComponentFactory &componentFactory)
Loads an entity into this entity manager.
Definition: entity_manager.cpp:284
Utility class for the EntityManager.
Definition: component_collection.h:23
~EntityManager()
Destructor.
Definition: entity_manager.cpp:57
bool isVolatile(EntityId id) const
Returns the volatile flag for an entity.
Definition: entity_manager.cpp:160
StorageContainer storeEntity(EntityId entityId) const
Stores a single entity.
Definition: entity_manager.cpp:265