Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
EntityManager.cpp
Go to the documentation of this file.
1
7
8
9#include "EntityManager.h"
10
11namespace ECS
12{
14 m_PendingDestroyedEntities(1024),
15 m_NumPendingDestroyedEntities(0),
16 m_ComponentManagerInstance(componentManagerInstance)
17 {
18 DEFINE_LOGGER("EntityManager");
19 LOG_INFO("Initialize EntityManager!","");
20 }
21
23 {
24 for (auto ec : this->m_EntityRegistry)
25 {
26 LOG_DEBUG("Releasing remaining entities of type '{}' ...", ec.second->GetEntityContainerTypeName());
27 delete ec.second;
28 ec.second = nullptr;
29 }
30
31 LOG_INFO("Release EntityManager!","");
32 }
33
35 {
36 return this->m_EntityHandleTable.AcquireHandle(entity);
37 }
38
40 {
42 }
43
45 {
46 IEntity* entity = this->m_EntityHandleTable[id];
47
48 const EntityTypeId ETID = entity->GetStaticEntityTypeID();
49
50 // get appropriate entity container and destroy entity
51 auto it = this->m_EntityRegistry.find(ETID);
52 if (it != this->m_EntityRegistry.end())
53 {
54 // release entity's components
56
57 it->second->DestroyEntity(entity);
58 }
59
60 // free entity id
61 this->ReleaseEntityId(id);
62 }
63
65 {
67
68 for (size_t i = 0; i < this->m_NumPendingDestroyedEntities; ++i)
69 {
70 EntityId entityId = this->m_PendingDestroyedEntities[i];
71 RemoveDestroyedEntity(entityId);
72 }
73
74 this->m_NumPendingDestroyedEntities = 0;
75 }
76
77
78} // namespace ECS
#define DEFINE_LOGGER(name)
Definition: LoggerMacro.h:18
#define LOG_INFO(format,...)
Definition: LoggerMacro.h:25
#define LOG_DEBUG(format,...)
Definition: LoggerMacro.h:24
#define PROFILE_SCOPE_AUTO(CATEGORY)
Definition: Profiler.h:87
void RemoveAllComponents(const EntityId entityId)
void RemoveDestroyedEntity(EntityId id)
EntityRegistry m_EntityRegistry
EntityHandleTable m_EntityHandleTable
void ReleaseEntityId(EntityId id)
EntityManager(const EntityManager &)=delete
ComponentManager * m_ComponentManagerInstance
Summary: The component manager instance.
EntityId AqcuireEntityId(IEntity *entity)
void RemoveDestroyedEntities()
size_t m_NumPendingDestroyedEntities
PendingDestroyedEntities m_PendingDestroyedEntities
virtual EntityTypeId GetStaticEntityTypeID() const =0
void ReleaseHandle(Handle handle)
Definition: Handle.h:166
Handle AcquireHandle(T *rawObject)
Definition: Handle.h:142
constexpr Optick::Category::Type GameLogic
Definition: Profiler.h:63
TypeID EntityTypeId
Definition: IEntity.h:15