initial commit
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
#ifndef HYDRAENTITYMANAGER
|
||||
#define HYDRAENTITYMANAGER
|
||||
#include "../engine/HydraObject.h"
|
||||
#include "HydraEntity.h"
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
|
||||
class HydraEntityManager : public HydraObject
|
||||
{
|
||||
private:
|
||||
std::array<HydraSignature, MAX_ACTORS> m_entities;
|
||||
std::mutex m_mutex;
|
||||
std::queue<HydraID> m_available_entity_ids;
|
||||
uint32_t m_entities_created;
|
||||
public:
|
||||
HydraEntityManager()
|
||||
{
|
||||
for(uint32_t i = 0; i < MAX_ACTORS; i ++)
|
||||
{
|
||||
m_available_entity_ids.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
HydraID CreateEntity()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
assert(m_entities_created < MAX_ACTORS && "Too many entities created");
|
||||
|
||||
HydraID entity_id = m_available_entity_ids.front();
|
||||
m_available_entity_ids.pop();
|
||||
m_entities_created++;
|
||||
return entity_id;
|
||||
}
|
||||
|
||||
void DeleteEntity(HydraID entity_id)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
assert(entity_id < MAX_ACTORS && "Entity ID out of range");
|
||||
|
||||
m_available_entity_ids.push(entity_id);
|
||||
m_entities[entity_id].reset();
|
||||
m_entities_created--;
|
||||
}
|
||||
|
||||
void SetSignature(HydraID entity_id, HydraSignature signature)
|
||||
{
|
||||
assert(entity_id < MAX_ACTORS && "Invalid entity it");
|
||||
m_entities[entity_id] = signature;
|
||||
}
|
||||
|
||||
HydraSignature GetSignature(HydraID entity_id)
|
||||
{
|
||||
assert(entity_id < MAX_ACTORS && "Invalid entity it");
|
||||
return m_entities[entity_id];
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* HYDRAENTITYMANAGER */
|
||||
Reference in New Issue
Block a user