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

48 lines
939 B
C++

#pragma once
#include <cstddef>
#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;
size_t m_entityCount; // for debugging purposes, should not be included in release version
bool m_holePresent{false};
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);
};