3#include "EntityDefinition.h"
4#include "ComponentFunctions.h"
6#include "Foundation/Collections/Pool.h"
7#include "Foundation/ComponentModel/Component.h"
8#include "Foundation/ComponentModel/Entity.h"
9#include "Foundation/Reflection/Type.h"
11#include <unordered_map>
94 void getEntityDefinitions(std::vector<StringView>& names)
const;
99 void getEntityDefinitionComponents(std::vector<StringView>& components,
const StringView & name)
const;
134 void createEntities(
size_t count, std::vector<EntityPtr> & entities);
135 void createEntities(
size_t count, std::vector<EntityPtr> & entities, std::function<
void(
ComponentModel::Entity *)> destructor);
184 void destroyEntity(
const EntityId
id);
241 EntityPtr getEntity(
const EntityId entityId,
bool logIfNotFound =
true,
bool onlyRegistered =
false)
const;
262 return entities.find(entityId) != entities.end();
268 const std::unordered_map<EntityId, EntityPtr> &
getEntities()
const
287 std::string dumpHierarchy()
const;
309 void addSystem(
const Reflection::TypeId typeId, ComponentCreator creator, ComponentDestroyer destroyer);
326 void addChild(EntityId parent, EntityId child);
337 template<
typename ComponentType>
340 return static_cast<ComponentType *
>(addComponent(entity, Cogs::Reflection::TypeDatabase::getType<ComponentType>().getTypeId()));
345 const std::unordered_map<size_t, EntityDefinition> & getDefinitions()
const
347 return entityDefinitions;
361 void getEntitiesWithComponent(std::vector<EntityId>& entities,
Reflection::TypeId typeId);
363 Context * getContext()
const {
return context; }
366 EntityId getNextEntityId();
370 void createEntityComponents(EntityDefinition & entityDefinition,
const EntityPtr & entity);
373 void compileEntityDefinition(EntityDefinition & entityDefinition);
375 void storeNamedEntity(
const EntityPtr& entity,
StringView name);
378 std::unordered_map<size_t, EntityDefinition> entityDefinitions;
380 std::unordered_map<Reflection::TypeId, ComponentCreator> creators;
381 std::unordered_map<Reflection::TypeId, ComponentDestroyer> destroyers;
382 std::unordered_map<Reflection::TypeId, ComponentSystemBase*> systems;
386 std::unordered_map<EntityId, EntityPtr> entities;
387 std::unordered_map<size_t, WeakEntityPtr> entitiesByName;
390 uint32_t revision = 1;
Base class for Component instances.
Container for components, providing composition of dynamic entities.
Base class for component systems.
Context base contains the parts of a Context that may be instantiated by static scene or model instan...
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Stores top level entities for the engine.
bool hasEntityOwnership(const EntityId entityId) const
Check if the given entityId has global ownership in EntityStore.
size_t getAllocatedEntityCount() const
Return total number of entities allocated.
uint32_t getRevision() const
Returns a number that changes every time an entity is created or destroyed.
const std::unordered_map< EntityId, EntityPtr > & getEntities() const
Return map of entities with global ownership.
Provides a weakly referenced view over the contents of a string.
std::shared_ptr< ComponentModel::Entity > EntityPtr
Smart pointer for Entity access.
EntityFind
Options to findEntity/getEntityFull.
@ NonRecursive
Do not search recursively.
@ MaxFlag
Do not go beyond this flag. Used as bounding value.
@ PartialNameMatch
Search for the first entity that partially contains the specified name.
uint16_t TypeId
Built in type used to uniquely identify a single type instance.
Contains all Cogs related functionality.
Pool used to store elements of ElementType.
Handle to a Component instance.
Holds extra housekeeping data for an Entity instance.
ContextBase * entityContext
Pointer to the ContextBase the entity belongs to.
uint32_t flags
Entity behavior flags.
size_t templateId
Contains the hashed name of a template or entity definition (if any) used to create the instance.
Defines how to construct entities of a certain type by a list of components to instantiate and defaul...