2d-platformer/include/Entities/EntityMemoryPool.h

45 lines
800 B
C++

#pragma once
#include <tuple>
#include <vector>
#include <Entities/Components.h>
#include <Entities/Entity.h>
using ComponentVectorTuple = std::tuple
<
std::vector<Transform>,
std::vector<Texture>,
std::vector<BoundingBox>
>;
class EntityMemoryPool
{
private:
ComponentVectorTuple m_components;
std::vector<EntityTag> m_tags;
std::vector<bool> m_aliveStates;
private:
EntityMemoryPool();
EntityMemoryPool(const EntityMemoryPool&) = delete;
public:
static EntityMemoryPool& instance();
template<typename T>
bool hasComponent(EntityIndex) const;
template<typename T>
T& getComponent(EntityIndex) const;
template<typename T>
T& getComponent(EntityIndex);
EntityTag getTag(EntityIndex) const;
bool getAlive(EntityIndex) const;
void removeEntity(EntityIndex);
};