Rename BTTask::cancel() to abort() and expose it.

This commit is contained in:
Serhii Snitsaruk 2023-10-26 16:20:33 +02:00
parent 14c162de39
commit 166cc8b1d9
10 changed files with 15 additions and 14 deletions

View File

@ -90,7 +90,7 @@ void BTPlayer::update(double p_delta) {
}
void BTPlayer::restart() {
tree_instance->cancel();
tree_instance->abort();
set_active(true);
}

View File

@ -30,7 +30,7 @@ void BTState::_setup() {
void BTState::_exit() {
ERR_FAIL_COND(tree_instance == nullptr);
tree_instance->cancel();
tree_instance->abort();
}
void BTState::_update(double p_delta) {

View File

@ -161,7 +161,7 @@ BT::Status BTTask::execute(double p_delta) {
// Reset children status.
if (data.status != FRESH) {
for (int i = 0; i < get_child_count(); i++) {
data.children.get(i)->cancel();
data.children.get(i)->abort();
}
}
if (!GDVIRTUAL_CALL(_enter)) {
@ -184,9 +184,9 @@ BT::Status BTTask::execute(double p_delta) {
return data.status;
}
void BTTask::cancel() {
void BTTask::abort() {
for (int i = 0; i < data.children.size(); i++) {
get_child(i)->cancel();
get_child(i)->abort();
}
if (data.status == RUNNING) {
if (!GDVIRTUAL_CALL(_exit)) {
@ -320,8 +320,7 @@ void BTTask::_bind_methods() {
ClassDB::bind_method(D_METHOD("next_sibling"), &BTTask::next_sibling);
ClassDB::bind_method(D_METHOD("print_tree", "p_initial_tabs"), &BTTask::print_tree, Variant(0));
ClassDB::bind_method(D_METHOD("get_task_name"), &BTTask::get_task_name);
ClassDB::bind_method(D_METHOD("get_custom_name"), &BTTask::get_custom_name);
ClassDB::bind_method(D_METHOD("set_custom_name", "p_name"), &BTTask::set_custom_name);
ClassDB::bind_method(D_METHOD("abort"), &BTTask::abort);
// Properties, setters and getters.
ClassDB::bind_method(D_METHOD("get_agent"), &BTTask::get_agent);
@ -332,6 +331,8 @@ void BTTask::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_parent"), &BTTask::get_parent);
ClassDB::bind_method(D_METHOD("get_status"), &BTTask::get_status);
ClassDB::bind_method(D_METHOD("get_elapsed_time"), &BTTask::get_elapsed_time);
ClassDB::bind_method(D_METHOD("get_custom_name"), &BTTask::get_custom_name);
ClassDB::bind_method(D_METHOD("set_custom_name", "p_name"), &BTTask::set_custom_name);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "custom_name"), "set_custom_name", "get_custom_name");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "agent", PROPERTY_HINT_RESOURCE_TYPE, "Node", PROPERTY_USAGE_NONE), "set_agent", "get_agent");

View File

@ -103,7 +103,7 @@ public:
virtual PackedStringArray get_configuration_warnings() const;
Status execute(double p_delta);
void cancel();
void abort();
Status get_status() const { return data.status; }
double get_elapsed_time() const { return data.elapsed; };

View File

@ -27,7 +27,7 @@ BT::Status BTDynamicSelector::_tick(double p_delta) {
// 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)->cancel();
get_child(last_running_idx)->abort();
}
last_running_idx = i;
return status;

View File

@ -27,7 +27,7 @@ BT::Status BTDynamicSequence::_tick(double p_delta) {
// 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)->cancel();
get_child(last_running_idx)->abort();
}
last_running_idx = i;
return status;

View File

@ -15,7 +15,7 @@
void BTParallel::_enter() {
for (int i = 0; i < get_child_count(); i++) {
get_child(i)->cancel();
get_child(i)->abort();
}
}

View File

@ -26,7 +26,7 @@ BT::Status BTTimeLimit::_tick(double p_delta) {
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child.");
Status status = get_child(0)->execute(p_delta);
if (status == RUNNING && get_elapsed_time() >= time_limit) {
get_child(0)->cancel();
get_child(0)->abort();
return FAILURE;
}
return status;

View File

@ -185,7 +185,7 @@ TEST_CASE("[Modules][LimboAI] BTTask") {
CHECK(task->get_elapsed_time() == 0.0);
}
SUBCASE("When cancelled") {
task->cancel();
task->abort();
CHECK(task->get_elapsed_time() == 0.0);
}
}

View File

@ -102,7 +102,7 @@ TEST_CASE("[Modules][LimboAI] BTRandomWait") {
num_undefined += 1;
} break;
}
wait->cancel();
wait->abort();
}
// * Expected ~500/500 SUCCESS/RUNNING.