ai_executor.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "ai_executor.h"
  2. #include "systems/ai_system/ai_behavior.h"
  3. #include "systems/ai_system/ai_behavior_registry.h"
  4. #include "systems/ai_system/ai_types.h"
  5. #include <vector>
  6. namespace Game::Systems::AI {
  7. void AIExecutor::run(const AISnapshot &snapshot, AIContext &context,
  8. float delta_time, AIBehaviorRegistry &registry,
  9. std::vector<AICommand> &out_commands) {
  10. bool exclusive_behavior_executed = false;
  11. registry.for_each([&](AIBehavior &behavior) {
  12. if (exclusive_behavior_executed && !behavior.can_run_concurrently()) {
  13. return;
  14. }
  15. bool const should_exec = behavior.should_execute(snapshot, context);
  16. if (should_exec) {
  17. size_t commands_before = out_commands.size();
  18. behavior.execute(snapshot, context, delta_time, out_commands);
  19. size_t commands_after = out_commands.size();
  20. context.debug_info.total_commands_issued +=
  21. static_cast<int>(commands_after - commands_before);
  22. if (!behavior.can_run_concurrently()) {
  23. exclusive_behavior_executed = true;
  24. }
  25. }
  26. });
  27. }
  28. } // namespace Game::Systems::AI