2023-07-21 09:50:06 +00:00
|
|
|
/**
|
|
|
|
* bt_dynamic_sequence.cpp
|
|
|
|
* =============================================================================
|
|
|
|
* Copyright 2021-2023 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.
|
|
|
|
* =============================================================================
|
|
|
|
*/
|
2022-08-28 21:36:21 +00:00
|
|
|
|
|
|
|
#include "bt_dynamic_sequence.h"
|
|
|
|
|
|
|
|
void BTDynamicSequence::_enter() {
|
|
|
|
last_running_idx = 0;
|
|
|
|
}
|
|
|
|
|
2023-09-19 11:43:26 +00:00
|
|
|
BT::Status BTDynamicSequence::_tick(double p_delta) {
|
|
|
|
Status status = SUCCESS;
|
2022-08-28 21:36:21 +00:00
|
|
|
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) {
|
2023-10-26 14:20:33 +00:00
|
|
|
get_child(last_running_idx)->abort();
|
2022-08-28 21:36:21 +00:00
|
|
|
}
|
|
|
|
last_running_idx = i;
|
|
|
|
return status;
|
|
|
|
}
|