ai_executor.cpp 905 B

1234567891011121314151617181920212223242526272829303132
  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> &outCommands) {
  10. bool exclusive_behavior_executed = false;
  11. registry.forEach([&](AIBehavior &behavior) {
  12. if (exclusive_behavior_executed && !behavior.canRunConcurrently()) {
  13. return;
  14. }
  15. bool const should_exec = behavior.should_execute(snapshot, context);
  16. if (should_exec) {
  17. behavior.execute(snapshot, context, delta_time, outCommands);
  18. if (!behavior.canRunConcurrently()) {
  19. exclusive_behavior_executed = true;
  20. }
  21. }
  22. });
  23. }
  24. } // namespace Game::Systems::AI