48 lines
1.0 KiB
C++
48 lines
1.0 KiB
C++
#include <Entities/EntityMemoryPool.h>
|
|
|
|
#include <Entities/Entity.h>
|
|
#include <Globals.h>
|
|
//#include <cstddef>
|
|
#include <vector>
|
|
|
|
EntityMemoryPool::EntityMemoryPool()
|
|
{
|
|
std::apply([=](auto&&... args) {((args.reserve(Global::MAX_ENTITIES)), ...); }, m_components);
|
|
m_tags.reserve(Global::MAX_ENTITIES);
|
|
m_aliveStates.reserve(Global::MAX_ENTITIES);
|
|
|
|
}
|
|
|
|
EntityMemoryPool& EntityMemoryPool::instance()
|
|
{
|
|
static EntityMemoryPool pool{};
|
|
return pool;
|
|
}
|
|
|
|
template<typename T>
|
|
bool EntityMemoryPool::hasComponent(EntityIndex id) const
|
|
{
|
|
return std::get<std::vector<T>>(m_components)[id].active;
|
|
}
|
|
|
|
template<typename T>
|
|
T& EntityMemoryPool::getComponent(EntityIndex id) const
|
|
{
|
|
return std::get<std::vector<T>>(m_components)[id];
|
|
}
|
|
|
|
template<typename T>
|
|
T& EntityMemoryPool::getComponent(EntityIndex id)
|
|
{
|
|
return std::get<std::vector<T>>(m_components)[id];
|
|
}
|
|
|
|
EntityTag EntityMemoryPool::getTag(EntityIndex id) const
|
|
{
|
|
return m_tags[id];
|
|
}
|
|
|
|
bool EntityMemoryPool::getAlive(EntityIndex id) const
|
|
{
|
|
return m_aliveStates[id];
|
|
} |