Untitled Game engine no.5
1.0
|
5 #include <unordered_map>
22 std::vector<Ref<T>> m_DataArray;
24 std::unordered_map<EntityID, size_t> m_EntityMap;
37 m_EntityMap.emplace(
id, m_nextIdx);
38 m_DataArray.push_back(c);
51 auto itr = m_EntityMap.find(
id);
52 if (itr != m_EntityMap.end())
53 return m_DataArray[itr->second];
55 m_EntityMap.emplace(
id, m_nextIdx);
56 Ref<T> data = CreateRef<T>(c);
57 m_DataArray.push_back(data);
66 auto itr = m_EntityMap.find(
id);
67 if (itr == m_EntityMap.end())
70 size_t idx = itr->second;
72 m_DataArray.erase(m_DataArray.begin() + idx);
73 m_EntityMap.erase(itr);
81 auto itr = m_EntityMap.find(
id);
82 if (itr == m_EntityMap.end())
85 size_t idx = itr->second;
87 return m_DataArray[idx];
std::shared_ptr< T > Ref
Has stuff for making references a lot more easily shared smart pointer.
Definition: Base.hpp:21
ComponentDataArray()
Constructor.
Definition: ComponentArray.hpp:31
Ref< T > Insert(EntityID id, T c)
Definition: ComponentArray.hpp:47
An array of components of type T.
Definition: ComponentArray.hpp:16
Ref< T > GetComp(EntityID id)
Definition: ComponentArray.hpp:80
Interface for an array of components.
Definition: ComponentArray.hpp:8
virtual void EntityDestroyed(EntityID entity)=0
Ref< T > Insert(EntityID id, Ref< T > c)
Definition: ComponentArray.hpp:36
Definition: Animation.hpp:14
void EntityDestroyed(EntityID id)
Definition: ComponentArray.hpp:92
void Remove(EntityID id)
Definition: ComponentArray.hpp:64