💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.5 KiB

  1. /*
  2. * Copyright (C) 2017-2019 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper Source Code.
  5. *
  6. * Antkeeper Source Code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper Source Code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper Source Code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ENTITY_MANAGER_HPP
  20. #define ENTITY_MANAGER_HPP
  21. #include "entity-id.hpp"
  22. #include "entity-id-pool.hpp"
  23. class ComponentManager;
  24. /**
  25. * Manages the creation and destruction of entities.
  26. */
  27. class EntityManager
  28. {
  29. public:
  30. /**
  31. * Creates an entity manager.
  32. *
  33. * @param componentManager Component manager with which to associate this entity manag.er
  34. */
  35. EntityManager(ComponentManager* componentManager);
  36. /**
  37. * Destroys an entity manager.
  38. */
  39. ~EntityManager();
  40. /**
  41. * Creates an entity with the next available ID.
  42. *
  43. * @return ID of the created entity.
  44. */
  45. EntityID createEntity();
  46. /**
  47. * Creates an entity with the specified ID.
  48. *
  49. * @param id ID of the entity to be created.
  50. * @return `true` if the entity was created, and `false` if an entity with the specified ID already exists.
  51. */
  52. bool createEntity(EntityID id);
  53. /**
  54. * Destroys an entity with the specified ID.
  55. *
  56. * @param id ID of the entity to be destroyed.
  57. *
  58. * @return `true` if the entity was destroyed, and `false` if an invalid ID was supplied.
  59. */
  60. bool destroyEntity(EntityID id);
  61. /**
  62. * Returns the component manager associated with this entity manager.
  63. */
  64. const ComponentManager* getComponentManager() const;
  65. /// @copydoc EntityManager::getComponentManager() const
  66. ComponentManager* getComponentManager();
  67. private:
  68. EntityManager(const EntityManager&) = delete;
  69. EntityManager& operator=(const EntityManager&) = delete;
  70. EntityIDPool idPool;
  71. ComponentManager* componentManager;
  72. };
  73. inline const ComponentManager* EntityManager::getComponentManager() const
  74. {
  75. return componentManager;
  76. }
  77. inline ComponentManager* EntityManager::getComponentManager()
  78. {
  79. return componentManager;
  80. }
  81. #endif // ENTITY_MANAGER_HPP