/TGame/TCommon/Entity/EntityManager.h

http://awoe.googlecode.com/ · C Header · 61 lines · 26 code · 10 blank · 25 comment · 0 complexity · 5d97bc0890679ad242d131b5e2280dcd MD5 · raw file

  1. #ifndef __ENTITY_MANAGER_BASE_
  2. #define __ENTITY_MANAGER_BASE_
  3. #include "EntityManagerIf.h"
  4. //
  5. // Entity Manager
  6. //
  7. //
  8. class TCOM_API EntityManager : public IEntityManager
  9. {
  10. public:
  11. EntityManager(bool bLoad = true);
  12. virtual ~EntityManager() {}
  13. virtual IEntity* getEntity(int nID);
  14. //
  15. // add/remove entities
  16. //
  17. // add/remove entities
  18. //
  19. virtual bool addEntity(int nID, IEntity* e);
  20. virtual bool addEntity(int nID, IEntityBuilder* b);
  21. virtual bool rmvEntity(int nID, IEntity*& e);
  22. //
  23. // visit all entities in current manager
  24. //
  25. virtual void forEach(IEntityVisitor& v);
  26. public:
  27. //
  28. // for gene host
  29. //
  30. // add/remove gene to gene host
  31. // Note that gene is organized by group id in gene
  32. //
  33. virtual bool addGene(IGeneCreateData* pDynamicData);
  34. virtual bool addGene(IGene*);
  35. virtual bool rmvGene(int nGrpID);
  36. //
  37. // register/unregister an gene event to gene host
  38. // gene host will broadcast gene event only to those who has already registered it
  39. //
  40. virtual bool addRegEvt(int nEvtGrp, int nEvt, IGene* pGene);
  41. virtual bool rmvRegEvt(int nEvtGrp, int nEvt, IGene* pGene);
  42. //
  43. // fire an gene event to all registered gene on current host
  44. //
  45. virtual bool onEvent(IEvt& evt);
  46. private:
  47. bool m_bLoad;// load entity when adding
  48. typedef stdext::hash_map<int, IEntity*> EntityMap;
  49. EntityMap m_theEntities;
  50. };
  51. #endif