ICT290 / src / scene / AIController / Messaging / EntityManager.h
EntityManager.h
Raw
#pragma once

#include <cassert>
#include <map>
#include "../BasicEntity.h"

class BasicEntity;

// provide easy access
#define EntityMgr EntityManager::Instance()

class EntityManager {
   private:
    typedef std::map<int, BasicEntity*> EntityMap;

   private:
    // to facilitate quick lookup the entities are stored in a std::map, in
    // which pointers to entities are cross referenced by their identifying
    // number
    EntityMap m_EntityMap;

    EntityManager() = default;

    // copy ctor and assignment should be private
    EntityManager(const EntityManager&);
    EntityManager& operator=(const EntityManager&);

   public:
    static EntityManager* Instance();

    // this method stores a pointer to the entity in the std::vector
    // m_Entities at the index position indicated by the entity's ID
    //(makes for faster access)
    void registerEntity(BasicEntity* newEntity);

    // returns a pointer to the entity with the ID given as a parameter
    BasicEntity* getEntityFromID(int id) const;

    // this method removes the entity from the list
    void removeEntity(BasicEntity* entity);

    // clears all entities from the entity map
    void Reset() { m_EntityMap.clear(); }
};