|
@@ -87,10 +87,10 @@ class Registry
|
|
|
private:
|
|
|
uint32_t numEntities = 0;
|
|
|
|
|
|
- std::vector<IPool*> componentPools;
|
|
|
+ std::vector<std::shared_ptr<IPool>> componentPools;
|
|
|
std::vector<Signature> entityComponentSignatures;
|
|
|
|
|
|
- std::unordered_map<std::type_index, System*> systems;
|
|
|
+ std::unordered_map<std::type_index, std::shared_ptr<System>> systems;
|
|
|
|
|
|
std::set<Entity> entitiesToBeAdded;
|
|
|
std::set<Entity> entitiesToBeKilled;
|
|
@@ -122,7 +122,7 @@ template<typename T, typename ...TArgs> void Registry::addComponent(Entity entit
|
|
|
{
|
|
|
const auto componentId = Component<T>::getId();
|
|
|
const auto entityId = entity.getId();
|
|
|
- Pool<T> *componentPool;
|
|
|
+ std::shared_ptr<Pool<T>> componentPool;
|
|
|
/* Check the pool is big enough */
|
|
|
if (componentId >= this->componentPools.size())
|
|
|
{
|
|
@@ -132,10 +132,10 @@ template<typename T, typename ...TArgs> void Registry::addComponent(Entity entit
|
|
|
/* Is this component exist in the pool? */
|
|
|
if (!this->componentPools[componentId])
|
|
|
{
|
|
|
- this->componentPools[componentId] = new Pool<T>();
|
|
|
+ this->componentPools[componentId] = std::make_shared<Pool<T>>();
|
|
|
}
|
|
|
|
|
|
- componentPool = this->componentPools[componentId];
|
|
|
+ componentPool = std::static_pointer_cast<Pool<T>>(this->componentPools[componentId]);
|
|
|
|
|
|
if (entityId >= componentPool->getSize())
|
|
|
{
|
|
@@ -145,7 +145,7 @@ template<typename T, typename ...TArgs> void Registry::addComponent(Entity entit
|
|
|
T newComponent(std::forward<TArgs>(args)...);
|
|
|
|
|
|
componentPool->set(entityId, newComponent);
|
|
|
- entityComponentSignatures[entityId].set(componentId);
|
|
|
+ this->entityComponentSignatures[entityId].set(componentId);
|
|
|
}
|
|
|
|
|
|
template <typename T> void Registry::removeComponent(Entity entity)
|
|
@@ -153,7 +153,7 @@ template <typename T> void Registry::removeComponent(Entity entity)
|
|
|
const auto componentId = Component<T>::getId();
|
|
|
const auto entityId = entity.getId();
|
|
|
|
|
|
- entityComponentSignatures[entityId].set(componentId, false);
|
|
|
+ this->entityComponentSignatures[entityId].set(componentId, false);
|
|
|
}
|
|
|
|
|
|
template <typename T> bool Registry::hasComponent(Entity entity)
|
|
@@ -161,13 +161,12 @@ template <typename T> bool Registry::hasComponent(Entity entity)
|
|
|
const auto componentId = Component<T>::getId();
|
|
|
const auto entityId = entity.getId();
|
|
|
|
|
|
- return entityComponentSignatures[entityId].test(componentId);
|
|
|
+ return this->entityComponentSignatures[entityId].test(componentId);
|
|
|
}
|
|
|
|
|
|
template<typename T, typename ...TArgs> void Registry::addSystem(TArgs&& ...args)
|
|
|
{
|
|
|
- T *newSystem(new T(std::forward<TArgs>(args)...));
|
|
|
-
|
|
|
+ std::shared_ptr<T> newSystem = std::make_shared<T>(std::forward<TArgs>(args)...);
|
|
|
this->systems.insert(std::make_pair(std::type_index(typeid(T)), newSystem));
|
|
|
}
|
|
|
|