#include <Entities/EntityMemoryPool.h>

#include <Entities/Entity.h>
#include <cstddef>
#include <vector>
#include <utility.h>

EntityMemoryPool::EntityMemoryPool()
{
	std::apply([=](auto&&... args) {((args.reserve(util::MAX_ENTITIES)), ...); }, m_components);
	m_tags.reserve(util::MAX_ENTITIES);
	m_aliveStates.reserve(util::MAX_ENTITIES);
}

EntityMemoryPool& EntityMemoryPool::instance()
{
	static EntityMemoryPool pool{};
	return pool;
}

template<typename T>
bool EntityMemoryPool::hasComponent(EntityIndex index) const
{
	return std::get<std::vector<T>>(m_components)[index].active;
}

template<typename T>
T& EntityMemoryPool::getComponent(EntityIndex index) const
{
	return std::get<std::vector<T>>(m_components)[index];
}

template<typename T>
T& EntityMemoryPool::getComponent(EntityIndex index)
{
	return std::get<std::vector<T>>(m_components)[index];
}

EntityTag EntityMemoryPool::getTag(EntityIndex index) const 
{
	return m_tags[index];
}

bool EntityMemoryPool::getAlive(EntityIndex index) const
{
	return m_aliveStates[index];
}

size_t EntityMemoryPool::getId(EntityIndex index) const 
{
	return m_ids[index];
}

void EntityMemoryPool::removeEntity(EntityIndex index)
{
	m_aliveStates[index] = false;
	return;
}