cleanup_system.cpp 727 B

1234567891011121314151617181920212223242526272829
  1. #include "cleanup_system.h"
  2. #include "../core/component.h"
  3. #include "../core/world.h"
  4. #include "core/entity.h"
  5. #include <vector>
  6. namespace Game::Systems {
  7. void CleanupSystem::update(Engine::Core::World *world, float) {
  8. removeDeadEntities(world);
  9. }
  10. void CleanupSystem::removeDeadEntities(Engine::Core::World *world) {
  11. std::vector<Engine::Core::EntityID> entities_to_remove;
  12. auto entities =
  13. world->getEntitiesWith<Engine::Core::PendingRemovalComponent>();
  14. entities_to_remove.reserve(entities.size());
  15. for (auto *entity : entities) {
  16. entities_to_remove.push_back(entity->getId());
  17. }
  18. for (auto entity_id : entities_to_remove) {
  19. world->destroyEntity(entity_id);
  20. }
  21. }
  22. } // namespace Game::Systems