limboai/bt/tasks/composites/bt_dynamic_sequence.cpp

35 lines
978 B
C++
Raw Normal View History

/**
* bt_dynamic_sequence.cpp
* =============================================================================
2024-03-21 20:38:57 +00:00
* Copyright 2021-2024 Serhii Snitsaruk
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
* =============================================================================
*/
#include "bt_dynamic_sequence.h"
void BTDynamicSequence::_enter() {
last_running_idx = 0;
}
BT::Status BTDynamicSequence::_tick(double p_delta) {
Status status = SUCCESS;
int i;
for (i = 0; i < get_child_count(); i++) {
status = get_child(i)->execute(p_delta);
if (status != SUCCESS) {
break;
}
}
// If the last node ticked is earlier in the tree than the previous runner,
// cancel previous runner.
if (last_running_idx > i && get_child(last_running_idx)->get_status() == RUNNING) {
get_child(last_running_idx)->abort();
}
last_running_idx = i;
return status;
2024-01-13 16:10:42 +00:00
}