From efe693347e3ce340b64f6869418773339b5249ad Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Tue, 19 Sep 2023 13:43:26 +0200 Subject: [PATCH] Refactor to return enum instead of int in task methods --- bt/tasks/blackboard/bt_check_trigger.cpp | 2 +- bt/tasks/blackboard/bt_check_trigger.h | 2 +- bt/tasks/blackboard/bt_check_var.cpp | 2 +- bt/tasks/blackboard/bt_check_var.h | 2 +- bt/tasks/blackboard/bt_set_var.cpp | 2 +- bt/tasks/blackboard/bt_set_var.h | 2 +- bt/tasks/bt_task.cpp | 15 +++++---- bt/tasks/bt_task.h | 32 +++++++++++++------ bt/tasks/composites/bt_dynamic_selector.cpp | 4 +-- bt/tasks/composites/bt_dynamic_selector.h | 2 +- bt/tasks/composites/bt_dynamic_sequence.cpp | 4 +-- bt/tasks/composites/bt_dynamic_sequence.h | 2 +- bt/tasks/composites/bt_parallel.cpp | 6 ++-- bt/tasks/composites/bt_parallel.h | 2 +- bt/tasks/composites/bt_random_selector.cpp | 4 +-- bt/tasks/composites/bt_random_selector.h | 2 +- bt/tasks/composites/bt_random_sequence.cpp | 4 +-- bt/tasks/composites/bt_random_sequence.h | 2 +- bt/tasks/composites/bt_selector.cpp | 4 +-- bt/tasks/composites/bt_selector.h | 2 +- bt/tasks/composites/bt_sequence.cpp | 4 +-- bt/tasks/composites/bt_sequence.h | 2 +- bt/tasks/decorators/bt_always_fail.cpp | 2 +- bt/tasks/decorators/bt_always_fail.h | 2 +- bt/tasks/decorators/bt_always_succeed.cpp | 2 +- bt/tasks/decorators/bt_always_succeed.h | 2 +- bt/tasks/decorators/bt_cooldown.cpp | 4 +-- bt/tasks/decorators/bt_cooldown.h | 2 +- bt/tasks/decorators/bt_delay.cpp | 2 +- bt/tasks/decorators/bt_delay.h | 2 +- bt/tasks/decorators/bt_for_each.cpp | 4 +-- bt/tasks/decorators/bt_for_each.h | 2 +- bt/tasks/decorators/bt_invert.cpp | 4 +-- bt/tasks/decorators/bt_invert.h | 2 +- bt/tasks/decorators/bt_new_scope.cpp | 2 +- bt/tasks/decorators/bt_new_scope.h | 2 +- bt/tasks/decorators/bt_probability.cpp | 2 +- bt/tasks/decorators/bt_probability.h | 2 +- bt/tasks/decorators/bt_repeat.cpp | 4 +-- bt/tasks/decorators/bt_repeat.h | 2 +- .../decorators/bt_repeat_until_failure.cpp | 2 +- bt/tasks/decorators/bt_repeat_until_failure.h | 2 +- .../decorators/bt_repeat_until_success.cpp | 2 +- bt/tasks/decorators/bt_repeat_until_success.h | 2 +- bt/tasks/decorators/bt_run_limit.cpp | 2 +- bt/tasks/decorators/bt_run_limit.h | 2 +- bt/tasks/decorators/bt_subtree.cpp | 2 +- bt/tasks/decorators/bt_subtree.h | 2 +- bt/tasks/decorators/bt_time_limit.cpp | 4 +-- bt/tasks/decorators/bt_time_limit.h | 2 +- bt/tasks/scene/bt_await_animation.cpp | 2 +- bt/tasks/scene/bt_await_animation.h | 2 +- bt/tasks/scene/bt_call_method.cpp | 2 +- bt/tasks/scene/bt_call_method.h | 2 +- bt/tasks/scene/bt_check_agent_property.cpp | 2 +- bt/tasks/scene/bt_check_agent_property.h | 2 +- bt/tasks/scene/bt_pause_animation.cpp | 2 +- bt/tasks/scene/bt_pause_animation.h | 2 +- bt/tasks/scene/bt_play_animation.cpp | 2 +- bt/tasks/scene/bt_play_animation.h | 2 +- bt/tasks/scene/bt_set_agent_property.cpp | 2 +- bt/tasks/scene/bt_set_agent_property.h | 2 +- bt/tasks/scene/bt_stop_animation.cpp | 2 +- bt/tasks/scene/bt_stop_animation.h | 2 +- bt/tasks/utility/bt_console_print.cpp | 2 +- bt/tasks/utility/bt_console_print.h | 2 +- bt/tasks/utility/bt_fail.cpp | 2 +- bt/tasks/utility/bt_fail.h | 2 +- bt/tasks/utility/bt_random_wait.cpp | 2 +- bt/tasks/utility/bt_random_wait.h | 2 +- bt/tasks/utility/bt_wait.cpp | 2 +- bt/tasks/utility/bt_wait.h | 2 +- bt/tasks/utility/bt_wait_ticks.cpp | 2 +- bt/tasks/utility/bt_wait_ticks.h | 2 +- config.py | 1 + register_types.cpp | 1 + tests/limbo_test.h | 8 ++--- 77 files changed, 121 insertions(+), 106 deletions(-) diff --git a/bt/tasks/blackboard/bt_check_trigger.cpp b/bt/tasks/blackboard/bt_check_trigger.cpp index ef477de..7762d8b 100644 --- a/bt/tasks/blackboard/bt_check_trigger.cpp +++ b/bt/tasks/blackboard/bt_check_trigger.cpp @@ -35,7 +35,7 @@ String BTCheckTrigger::_generate_name() const { return "CheckTrigger " + LimboUtility::get_singleton()->decorate_var(variable); } -int BTCheckTrigger::_tick(double p_delta) { +BT::Status BTCheckTrigger::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(variable.is_empty(), FAILURE, "BBCheckVar: `variable` is not set."); Variant trigger_value = get_blackboard()->get_var(variable, false); if (trigger_value == Variant(true)) { diff --git a/bt/tasks/blackboard/bt_check_trigger.h b/bt/tasks/blackboard/bt_check_trigger.h index e3ca3e0..fafd296 100644 --- a/bt/tasks/blackboard/bt_check_trigger.h +++ b/bt/tasks/blackboard/bt_check_trigger.h @@ -27,7 +27,7 @@ protected: static void _bind_methods(); virtual String _generate_name() const override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: void set_variable(String p_variable); diff --git a/bt/tasks/blackboard/bt_check_var.cpp b/bt/tasks/blackboard/bt_check_var.cpp index 4f2a120..28139f9 100644 --- a/bt/tasks/blackboard/bt_check_var.cpp +++ b/bt/tasks/blackboard/bt_check_var.cpp @@ -54,7 +54,7 @@ String BTCheckVar::_generate_name() const { value.is_valid() ? Variant(value) : Variant("???")); } -int BTCheckVar::_tick(double p_delta) { +BT::Status BTCheckVar::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(variable.is_empty(), FAILURE, "BTCheckVar: `variable` is not set."); ERR_FAIL_COND_V_MSG(!value.is_valid(), FAILURE, "BTCheckVar: `value` is not set."); diff --git a/bt/tasks/blackboard/bt_check_var.h b/bt/tasks/blackboard/bt_check_var.h index ae87574..b84717e 100644 --- a/bt/tasks/blackboard/bt_check_var.h +++ b/bt/tasks/blackboard/bt_check_var.h @@ -30,7 +30,7 @@ protected: static void _bind_methods(); virtual String _generate_name() const override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: virtual PackedStringArray get_configuration_warnings() const override; diff --git a/bt/tasks/blackboard/bt_set_var.cpp b/bt/tasks/blackboard/bt_set_var.cpp index fa39269..768bdc8 100644 --- a/bt/tasks/blackboard/bt_set_var.cpp +++ b/bt/tasks/blackboard/bt_set_var.cpp @@ -24,7 +24,7 @@ String BTSetVar::_generate_name() const { value.is_valid() ? Variant(value) : Variant("???")); } -int BTSetVar::_tick(double p_delta) { +BT::Status BTSetVar::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(variable.is_empty(), FAILURE, "BTSetVar: `variable` is not set."); ERR_FAIL_COND_V_MSG(!value.is_valid(), FAILURE, "BTSetVar: `value` is not set."); Variant error_result = SNAME("Error: BTSetVar failed to get value!"); diff --git a/bt/tasks/blackboard/bt_set_var.h b/bt/tasks/blackboard/bt_set_var.h index 00d35f5..7fcc673 100644 --- a/bt/tasks/blackboard/bt_set_var.h +++ b/bt/tasks/blackboard/bt_set_var.h @@ -30,7 +30,7 @@ protected: static void _bind_methods(); virtual String _generate_name() const override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: virtual PackedStringArray get_configuration_warnings() const override; diff --git a/bt/tasks/bt_task.cpp b/bt/tasks/bt_task.cpp index 31f6ecc..47b4774 100644 --- a/bt/tasks/bt_task.cpp +++ b/bt/tasks/bt_task.cpp @@ -26,6 +26,13 @@ #include "core/templates/hash_map.h" #include "core/variant/variant.h" +void BT::_bind_methods() { + BIND_ENUM_CONSTANT(FRESH); + BIND_ENUM_CONSTANT(RUNNING); + BIND_ENUM_CONSTANT(FAILURE); + BIND_ENUM_CONSTANT(SUCCESS); +} + String BTTask::_generate_name() const { if (get_script_instance()) { if (get_script_instance()->has_method(LimboStringNames::get_singleton()->_generate_name)) { @@ -149,7 +156,7 @@ Ref BTTask::clone() const { return inst; } -int BTTask::execute(double p_delta) { +BT::Status BTTask::execute(double p_delta) { if (data.status != RUNNING) { // Reset children status. if (data.status != FRESH) { @@ -340,12 +347,6 @@ void BTTask::_bind_methods() { GDVIRTUAL_BIND(_tick, "p_delta"); GDVIRTUAL_BIND(_generate_name); GDVIRTUAL_BIND(_get_configuration_warning); - - // Enums. - ClassDB::bind_integer_constant(get_class_static(), "TaskStatus", "FRESH", FRESH); - ClassDB::bind_integer_constant(get_class_static(), "TaskStatus", "RUNNING", RUNNING); - ClassDB::bind_integer_constant(get_class_static(), "TaskStatus", "FAILURE", FAILURE); - ClassDB::bind_integer_constant(get_class_static(), "TaskStatus", "SUCCESS", SUCCESS); } BTTask::BTTask() { diff --git a/bt/tasks/bt_task.h b/bt/tasks/bt_task.h index d363e77..7e2685a 100644 --- a/bt/tasks/bt_task.h +++ b/bt/tasks/bt_task.h @@ -25,17 +25,31 @@ #include "core/variant/dictionary.h" #include "scene/resources/texture.h" -class BTTask : public Resource { - GDCLASS(BTTask, Resource); +/** + * Base class for BTTask. + * Note: In order to properly return Status in the _tick virtual method (GDVIRTUAL1R...) + * we must do VARIANT_ENUM_CAST for Status enum before the actual BTTask class declaration. + */ +class BT : public Resource { + GDCLASS(BT, Resource); public: - enum TaskStatus { + enum Status { FRESH, RUNNING, FAILURE, SUCCESS, }; +protected: + static void _bind_methods(); +}; + +VARIANT_ENUM_CAST(BT::Status) + +class BTTask : public BT { + GDCLASS(BTTask, BT); + private: friend class BehaviorTree; @@ -46,7 +60,7 @@ private: Ref blackboard; BTTask *parent; Vector> children; - int status; + Status status; double elapsed; } data; @@ -60,13 +74,13 @@ protected: virtual void _setup() {} virtual void _enter() {} virtual void _exit() {} - virtual int _tick(double p_delta) { return FAILURE; } + virtual Status _tick(double p_delta) { return FAILURE; } GDVIRTUAL0RC(String, _generate_name); GDVIRTUAL0(_setup); GDVIRTUAL0(_enter); GDVIRTUAL0(_exit); - GDVIRTUAL1R(int, _tick, double); + GDVIRTUAL1R(Status, _tick, double); GDVIRTUAL0RC(PackedStringArray, _get_configuration_warning); public: @@ -88,9 +102,9 @@ public: virtual void initialize(Node *p_agent, const Ref &p_blackboard); virtual PackedStringArray get_configuration_warnings() const; - int execute(double p_delta); + Status execute(double p_delta); void cancel(); - int get_status() const { return data.status; } + Status get_status() const { return data.status; } double get_elapsed_time() const { return data.elapsed; }; Ref get_child(int p_idx) const; @@ -111,6 +125,4 @@ public: ~BTTask(); }; -VARIANT_ENUM_CAST(BTTask::TaskStatus) - #endif // BTTASK_H \ No newline at end of file diff --git a/bt/tasks/composites/bt_dynamic_selector.cpp b/bt/tasks/composites/bt_dynamic_selector.cpp index 0dba426..af63888 100644 --- a/bt/tasks/composites/bt_dynamic_selector.cpp +++ b/bt/tasks/composites/bt_dynamic_selector.cpp @@ -15,8 +15,8 @@ void BTDynamicSelector::_enter() { last_running_idx = 0; } -int BTDynamicSelector::_tick(double p_delta) { - int status = SUCCESS; +BT::Status BTDynamicSelector::_tick(double p_delta) { + Status status = SUCCESS; int i; for (i = 0; i < get_child_count(); i++) { status = get_child(i)->execute(p_delta); diff --git a/bt/tasks/composites/bt_dynamic_selector.h b/bt/tasks/composites/bt_dynamic_selector.h index e1b7246..975952c 100644 --- a/bt/tasks/composites/bt_dynamic_selector.h +++ b/bt/tasks/composites/bt_dynamic_selector.h @@ -23,7 +23,7 @@ private: protected: virtual void _enter() override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; }; #endif // BT_DYNAMIC_SELECTOR_H \ No newline at end of file diff --git a/bt/tasks/composites/bt_dynamic_sequence.cpp b/bt/tasks/composites/bt_dynamic_sequence.cpp index 503fe6f..d3902e4 100644 --- a/bt/tasks/composites/bt_dynamic_sequence.cpp +++ b/bt/tasks/composites/bt_dynamic_sequence.cpp @@ -15,8 +15,8 @@ void BTDynamicSequence::_enter() { last_running_idx = 0; } -int BTDynamicSequence::_tick(double p_delta) { - int status = SUCCESS; +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); diff --git a/bt/tasks/composites/bt_dynamic_sequence.h b/bt/tasks/composites/bt_dynamic_sequence.h index d331eca..f4ac6ee 100644 --- a/bt/tasks/composites/bt_dynamic_sequence.h +++ b/bt/tasks/composites/bt_dynamic_sequence.h @@ -23,7 +23,7 @@ private: protected: virtual void _enter() override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; }; #endif // BT_DYNAMIC_SEQUENCE_H \ No newline at end of file diff --git a/bt/tasks/composites/bt_parallel.cpp b/bt/tasks/composites/bt_parallel.cpp index b10fbc8..74c192e 100644 --- a/bt/tasks/composites/bt_parallel.cpp +++ b/bt/tasks/composites/bt_parallel.cpp @@ -19,12 +19,12 @@ void BTParallel::_enter() { } } -int BTParallel::_tick(double p_delta) { +BT::Status BTParallel::_tick(double p_delta) { int num_succeeded = 0; int num_failed = 0; - int return_status = RUNNING; + BT::Status return_status = RUNNING; for (int i = 0; i < get_child_count(); i++) { - int status = 0; + Status status = BT::FRESH; Ref child = get_child(i); if (!repeat && (child->get_status() == FAILURE || child->get_status() == SUCCESS)) { status = child->get_status(); diff --git a/bt/tasks/composites/bt_parallel.h b/bt/tasks/composites/bt_parallel.h index 40f18e7..634cbca 100644 --- a/bt/tasks/composites/bt_parallel.h +++ b/bt/tasks/composites/bt_parallel.h @@ -27,7 +27,7 @@ protected: static void _bind_methods(); virtual void _enter() override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: int get_num_successes_required() const { return num_successes_required; } diff --git a/bt/tasks/composites/bt_random_selector.cpp b/bt/tasks/composites/bt_random_selector.cpp index 0755421..ffbf75a 100644 --- a/bt/tasks/composites/bt_random_selector.cpp +++ b/bt/tasks/composites/bt_random_selector.cpp @@ -22,8 +22,8 @@ void BTRandomSelector::_enter() { indicies.shuffle(); } -int BTRandomSelector::_tick(double p_delta) { - int status = FAILURE; +BT::Status BTRandomSelector::_tick(double p_delta) { + Status status = FAILURE; for (int i = last_running_idx; i < get_child_count(); i++) { status = get_child(indicies[i])->execute(p_delta); if (status != FAILURE) { diff --git a/bt/tasks/composites/bt_random_selector.h b/bt/tasks/composites/bt_random_selector.h index 710b5e3..54337e2 100644 --- a/bt/tasks/composites/bt_random_selector.h +++ b/bt/tasks/composites/bt_random_selector.h @@ -26,6 +26,6 @@ private: protected: virtual void _enter() override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; }; #endif // BT_RANDOM_SELECTOR_H \ No newline at end of file diff --git a/bt/tasks/composites/bt_random_sequence.cpp b/bt/tasks/composites/bt_random_sequence.cpp index 7e05d05..a6ddeba 100644 --- a/bt/tasks/composites/bt_random_sequence.cpp +++ b/bt/tasks/composites/bt_random_sequence.cpp @@ -22,8 +22,8 @@ void BTRandomSequence::_enter() { indicies.shuffle(); } -int BTRandomSequence::_tick(double p_delta) { - int status = SUCCESS; +BT::Status BTRandomSequence::_tick(double p_delta) { + Status status = SUCCESS; for (int i = last_running_idx; i < get_child_count(); i++) { status = get_child(indicies[i])->execute(p_delta); if (status != SUCCESS) { diff --git a/bt/tasks/composites/bt_random_sequence.h b/bt/tasks/composites/bt_random_sequence.h index 866cb78..caba87b 100644 --- a/bt/tasks/composites/bt_random_sequence.h +++ b/bt/tasks/composites/bt_random_sequence.h @@ -26,6 +26,6 @@ private: protected: virtual void _enter() override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; }; #endif // BT_RANDOM_SEQUENCE_H \ No newline at end of file diff --git a/bt/tasks/composites/bt_selector.cpp b/bt/tasks/composites/bt_selector.cpp index d708fe9..82fb7bb 100644 --- a/bt/tasks/composites/bt_selector.cpp +++ b/bt/tasks/composites/bt_selector.cpp @@ -15,8 +15,8 @@ void BTSelector::_enter() { last_running_idx = 0; } -int BTSelector::_tick(double p_delta) { - int status = FAILURE; +BT::Status BTSelector::_tick(double p_delta) { + Status status = FAILURE; for (int i = last_running_idx; i < get_child_count(); i++) { status = get_child(i)->execute(p_delta); if (status != FAILURE) { diff --git a/bt/tasks/composites/bt_selector.h b/bt/tasks/composites/bt_selector.h index eb3be08..c09a8c4 100644 --- a/bt/tasks/composites/bt_selector.h +++ b/bt/tasks/composites/bt_selector.h @@ -23,6 +23,6 @@ private: protected: virtual void _enter() override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; }; #endif // BT_SELECTOR_H \ No newline at end of file diff --git a/bt/tasks/composites/bt_sequence.cpp b/bt/tasks/composites/bt_sequence.cpp index 6a27068..b734047 100644 --- a/bt/tasks/composites/bt_sequence.cpp +++ b/bt/tasks/composites/bt_sequence.cpp @@ -15,8 +15,8 @@ void BTSequence::_enter() { last_running_idx = 0; } -int BTSequence::_tick(double p_delta) { - int status = SUCCESS; +BT::Status BTSequence::_tick(double p_delta) { + Status status = SUCCESS; for (int i = last_running_idx; i < get_child_count(); i++) { status = get_child(i)->execute(p_delta); if (status != SUCCESS) { diff --git a/bt/tasks/composites/bt_sequence.h b/bt/tasks/composites/bt_sequence.h index 45b61d6..bd11fff 100644 --- a/bt/tasks/composites/bt_sequence.h +++ b/bt/tasks/composites/bt_sequence.h @@ -23,7 +23,7 @@ private: protected: virtual void _enter() override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; }; #endif // BT_SEQUENCE_H \ No newline at end of file diff --git a/bt/tasks/decorators/bt_always_fail.cpp b/bt/tasks/decorators/bt_always_fail.cpp index 9cb98f2..7705858 100644 --- a/bt/tasks/decorators/bt_always_fail.cpp +++ b/bt/tasks/decorators/bt_always_fail.cpp @@ -11,7 +11,7 @@ #include "bt_always_fail.h" -int BTAlwaysFail::_tick(double p_delta) { +BT::Status BTAlwaysFail::_tick(double p_delta) { if (get_child_count() > 0 && get_child(0)->execute(p_delta) == RUNNING) { return RUNNING; } diff --git a/bt/tasks/decorators/bt_always_fail.h b/bt/tasks/decorators/bt_always_fail.h index eed4cf5..4bc1bb6 100644 --- a/bt/tasks/decorators/bt_always_fail.h +++ b/bt/tasks/decorators/bt_always_fail.h @@ -19,7 +19,7 @@ class BTAlwaysFail : public BTDecorator { TASK_CATEGORY(Decorators); protected: - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; }; #endif // BT_ALWAYS_FAIL_H \ No newline at end of file diff --git a/bt/tasks/decorators/bt_always_succeed.cpp b/bt/tasks/decorators/bt_always_succeed.cpp index beff9cb..2640fc9 100644 --- a/bt/tasks/decorators/bt_always_succeed.cpp +++ b/bt/tasks/decorators/bt_always_succeed.cpp @@ -11,7 +11,7 @@ #include "bt_always_succeed.h" -int BTAlwaysSucceed::_tick(double p_delta) { +BT::Status BTAlwaysSucceed::_tick(double p_delta) { if (get_child_count() > 0 && get_child(0)->execute(p_delta) == RUNNING) { return RUNNING; } diff --git a/bt/tasks/decorators/bt_always_succeed.h b/bt/tasks/decorators/bt_always_succeed.h index d8700f2..1ccd8ec 100644 --- a/bt/tasks/decorators/bt_always_succeed.h +++ b/bt/tasks/decorators/bt_always_succeed.h @@ -19,7 +19,7 @@ class BTAlwaysSucceed : public BTDecorator { TASK_CATEGORY(Decorators); protected: - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; }; #endif // BT_ALWAYS_SUCCEED_H \ No newline at end of file diff --git a/bt/tasks/decorators/bt_cooldown.cpp b/bt/tasks/decorators/bt_cooldown.cpp index 77cd179..8c450e0 100644 --- a/bt/tasks/decorators/bt_cooldown.cpp +++ b/bt/tasks/decorators/bt_cooldown.cpp @@ -59,12 +59,12 @@ void BTCooldown::_setup() { } } -int BTCooldown::_tick(double p_delta) { +BT::Status BTCooldown::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child."); if (get_blackboard()->get_var(cooldown_state_var, true)) { return FAILURE; } - int status = get_child(0)->execute(p_delta); + Status status = get_child(0)->execute(p_delta); if (status == SUCCESS || (trigger_on_failure && status == FAILURE)) { _chill(); } diff --git a/bt/tasks/decorators/bt_cooldown.h b/bt/tasks/decorators/bt_cooldown.h index 8ab5979..f7a9773 100644 --- a/bt/tasks/decorators/bt_cooldown.h +++ b/bt/tasks/decorators/bt_cooldown.h @@ -37,7 +37,7 @@ protected: virtual String _generate_name() const override; virtual void _setup() override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: void set_duration(double p_value); diff --git a/bt/tasks/decorators/bt_delay.cpp b/bt/tasks/decorators/bt_delay.cpp index 99e43c6..4e6aacd 100644 --- a/bt/tasks/decorators/bt_delay.cpp +++ b/bt/tasks/decorators/bt_delay.cpp @@ -27,7 +27,7 @@ String BTDelay::_generate_name() const { return vformat("Delay %s sec", Math::snapped(seconds, 0.001)); } -int BTDelay::_tick(double p_delta) { +BT::Status BTDelay::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child."); if (get_elapsed_time() <= seconds) { return RUNNING; diff --git a/bt/tasks/decorators/bt_delay.h b/bt/tasks/decorators/bt_delay.h index ee3eda2..067b8ea 100644 --- a/bt/tasks/decorators/bt_delay.h +++ b/bt/tasks/decorators/bt_delay.h @@ -25,7 +25,7 @@ protected: static void _bind_methods(); virtual String _generate_name() const override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: void set_seconds(double p_value); diff --git a/bt/tasks/decorators/bt_for_each.cpp b/bt/tasks/decorators/bt_for_each.cpp index e0fc28b..35df0fb 100644 --- a/bt/tasks/decorators/bt_for_each.cpp +++ b/bt/tasks/decorators/bt_for_each.cpp @@ -42,7 +42,7 @@ void BTForEach::_enter() { current_idx = 0; } -int BTForEach::_tick(double p_delta) { +BT::Status BTForEach::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "ForEach decorator has no child."); ERR_FAIL_COND_V_MSG(save_var.is_empty(), FAILURE, "ForEach save variable is not set."); ERR_FAIL_COND_V_MSG(array_var.is_empty(), FAILURE, "ForEach array variable is not set."); @@ -54,7 +54,7 @@ int BTForEach::_tick(double p_delta) { Variant elem = arr.get(current_idx); get_blackboard()->set_var(save_var, elem); - int status = get_child(0)->execute(p_delta); + Status status = get_child(0)->execute(p_delta); if (status == RUNNING) { return RUNNING; } else if (status == FAILURE) { diff --git a/bt/tasks/decorators/bt_for_each.h b/bt/tasks/decorators/bt_for_each.h index 527093f..2efd5a1 100644 --- a/bt/tasks/decorators/bt_for_each.h +++ b/bt/tasks/decorators/bt_for_each.h @@ -29,7 +29,7 @@ protected: virtual String _generate_name() const override; virtual void _enter() override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: void set_array_var(String p_value); diff --git a/bt/tasks/decorators/bt_invert.cpp b/bt/tasks/decorators/bt_invert.cpp index 0add106..154c174 100644 --- a/bt/tasks/decorators/bt_invert.cpp +++ b/bt/tasks/decorators/bt_invert.cpp @@ -11,9 +11,9 @@ #include "bt_invert.h" -int BTInvert::_tick(double p_delta) { +BT::Status BTInvert::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child."); - int status = get_child(0)->execute(p_delta); + Status status = get_child(0)->execute(p_delta); if (status == SUCCESS) { status = FAILURE; } else if (status == FAILURE) { diff --git a/bt/tasks/decorators/bt_invert.h b/bt/tasks/decorators/bt_invert.h index cc3f707..f39018c 100644 --- a/bt/tasks/decorators/bt_invert.h +++ b/bt/tasks/decorators/bt_invert.h @@ -19,7 +19,7 @@ class BTInvert : public BTDecorator { TASK_CATEGORY(Decorators); protected: - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; }; #endif // BT_INVERT_H \ No newline at end of file diff --git a/bt/tasks/decorators/bt_new_scope.cpp b/bt/tasks/decorators/bt_new_scope.cpp index 743fa0d..e3ef6c0 100644 --- a/bt/tasks/decorators/bt_new_scope.cpp +++ b/bt/tasks/decorators/bt_new_scope.cpp @@ -29,7 +29,7 @@ void BTNewScope::initialize(Node *p_agent, const Ref &p_blackboard) BTDecorator::initialize(p_agent, bb); } -int BTNewScope::_tick(double p_delta) { +BT::Status BTNewScope::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child."); return get_child(0)->execute(p_delta); } diff --git a/bt/tasks/decorators/bt_new_scope.h b/bt/tasks/decorators/bt_new_scope.h index 060b787..7fcf12e 100644 --- a/bt/tasks/decorators/bt_new_scope.h +++ b/bt/tasks/decorators/bt_new_scope.h @@ -27,7 +27,7 @@ protected: void _set_blackboard_data(const Dictionary &p_value) { blackboard_data = p_value; } Dictionary _get_blackboard_data() const { return blackboard_data; } - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: virtual void initialize(Node *p_agent, const Ref &p_blackboard) override; diff --git a/bt/tasks/decorators/bt_probability.cpp b/bt/tasks/decorators/bt_probability.cpp index e3932fe..890bef7 100644 --- a/bt/tasks/decorators/bt_probability.cpp +++ b/bt/tasks/decorators/bt_probability.cpp @@ -20,7 +20,7 @@ String BTProbability::_generate_name() const { return vformat("Probability %.1f%%", run_chance); } -int BTProbability::_tick(double p_delta) { +BT::Status BTProbability::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child."); if (get_child(0)->get_status() == RUNNING || Math::randf() <= run_chance) { return get_child(0)->execute(p_delta); diff --git a/bt/tasks/decorators/bt_probability.h b/bt/tasks/decorators/bt_probability.h index 0c5689e..e4bf09b 100644 --- a/bt/tasks/decorators/bt_probability.h +++ b/bt/tasks/decorators/bt_probability.h @@ -25,7 +25,7 @@ protected: static void _bind_methods(); virtual String _generate_name() const override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: void set_run_chance(float p_value); diff --git a/bt/tasks/decorators/bt_repeat.cpp b/bt/tasks/decorators/bt_repeat.cpp index 3516183..a4947b1 100644 --- a/bt/tasks/decorators/bt_repeat.cpp +++ b/bt/tasks/decorators/bt_repeat.cpp @@ -31,9 +31,9 @@ void BTRepeat::_enter() { cur_iteration = 1; } -int BTRepeat::_tick(double p_delta) { +BT::Status BTRepeat::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child."); - int status = get_child(0)->execute(p_delta); + Status status = get_child(0)->execute(p_delta); if (status == RUNNING || forever) { return RUNNING; } else if (status == FAILURE && abort_on_failure) { diff --git a/bt/tasks/decorators/bt_repeat.h b/bt/tasks/decorators/bt_repeat.h index b56c14c..37e1866 100644 --- a/bt/tasks/decorators/bt_repeat.h +++ b/bt/tasks/decorators/bt_repeat.h @@ -31,7 +31,7 @@ protected: virtual String _generate_name() const override; virtual void _enter() override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: void set_forever(bool p_forever); diff --git a/bt/tasks/decorators/bt_repeat_until_failure.cpp b/bt/tasks/decorators/bt_repeat_until_failure.cpp index c8f45b0..0fe7e10 100644 --- a/bt/tasks/decorators/bt_repeat_until_failure.cpp +++ b/bt/tasks/decorators/bt_repeat_until_failure.cpp @@ -11,7 +11,7 @@ #include "bt_repeat_until_failure.h" -int BTRepeatUntilFailure::_tick(double p_delta) { +BT::Status BTRepeatUntilFailure::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child."); if (get_child(0)->execute(p_delta) == FAILURE) { return SUCCESS; diff --git a/bt/tasks/decorators/bt_repeat_until_failure.h b/bt/tasks/decorators/bt_repeat_until_failure.h index 0518927..ec6463e 100644 --- a/bt/tasks/decorators/bt_repeat_until_failure.h +++ b/bt/tasks/decorators/bt_repeat_until_failure.h @@ -19,7 +19,7 @@ class BTRepeatUntilFailure : public BTDecorator { TASK_CATEGORY(Decorators); protected: - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; }; #endif // BT_REPEAT_UNTIL_FAILURE_H \ No newline at end of file diff --git a/bt/tasks/decorators/bt_repeat_until_success.cpp b/bt/tasks/decorators/bt_repeat_until_success.cpp index a3dab38..f2c0ab3 100644 --- a/bt/tasks/decorators/bt_repeat_until_success.cpp +++ b/bt/tasks/decorators/bt_repeat_until_success.cpp @@ -11,7 +11,7 @@ #include "bt_repeat_until_success.h" -int BTRepeatUntilSuccess::_tick(double p_delta) { +BT::Status BTRepeatUntilSuccess::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child."); if (get_child(0)->execute(p_delta) == SUCCESS) { return SUCCESS; diff --git a/bt/tasks/decorators/bt_repeat_until_success.h b/bt/tasks/decorators/bt_repeat_until_success.h index d26af61..423b1fa 100644 --- a/bt/tasks/decorators/bt_repeat_until_success.h +++ b/bt/tasks/decorators/bt_repeat_until_success.h @@ -19,7 +19,7 @@ class BTRepeatUntilSuccess : public BTDecorator { TASK_CATEGORY(Decorators); protected: - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; }; #endif // BT_REPEAT_UNTIL_SUCCESS_H \ No newline at end of file diff --git a/bt/tasks/decorators/bt_run_limit.cpp b/bt/tasks/decorators/bt_run_limit.cpp index 3805356..4b8ffa2 100644 --- a/bt/tasks/decorators/bt_run_limit.cpp +++ b/bt/tasks/decorators/bt_run_limit.cpp @@ -20,7 +20,7 @@ String BTRunLimit::_generate_name() const { return vformat("RunLimit x%d", run_limit); } -int BTRunLimit::_tick(double p_delta) { +BT::Status BTRunLimit::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child."); if (get_child(0)->get_status() != RUNNING) { if (num_runs >= run_limit) { diff --git a/bt/tasks/decorators/bt_run_limit.h b/bt/tasks/decorators/bt_run_limit.h index 26d7fa7..9ae93a0 100644 --- a/bt/tasks/decorators/bt_run_limit.h +++ b/bt/tasks/decorators/bt_run_limit.h @@ -26,7 +26,7 @@ protected: static void _bind_methods(); virtual String _generate_name() const override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: void set_run_limit(int p_value); diff --git a/bt/tasks/decorators/bt_subtree.cpp b/bt/tasks/decorators/bt_subtree.cpp index 3d86a5e..aacaf4c 100644 --- a/bt/tasks/decorators/bt_subtree.cpp +++ b/bt/tasks/decorators/bt_subtree.cpp @@ -46,7 +46,7 @@ void BTSubtree::initialize(Node *p_agent, const Ref &p_blackboard) { BTNewScope::initialize(p_agent, p_blackboard); } -int BTSubtree::_tick(double p_delta) { +BT::Status BTSubtree::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator doesn't have a child."); return get_child(0)->execute(p_delta); } diff --git a/bt/tasks/decorators/bt_subtree.h b/bt/tasks/decorators/bt_subtree.h index 3c5a710..dae6e79 100644 --- a/bt/tasks/decorators/bt_subtree.h +++ b/bt/tasks/decorators/bt_subtree.h @@ -27,7 +27,7 @@ protected: static void _bind_methods(); virtual String _generate_name() const override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: void set_subtree(const Ref &p_value); diff --git a/bt/tasks/decorators/bt_time_limit.cpp b/bt/tasks/decorators/bt_time_limit.cpp index 3212e65..6be1044 100644 --- a/bt/tasks/decorators/bt_time_limit.cpp +++ b/bt/tasks/decorators/bt_time_limit.cpp @@ -22,9 +22,9 @@ String BTTimeLimit::_generate_name() const { return vformat("TimeLimit %s sec", Math::snapped(time_limit, 0.001)); } -int BTTimeLimit::_tick(double p_delta) { +BT::Status BTTimeLimit::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child."); - int status = get_child(0)->execute(p_delta); + Status status = get_child(0)->execute(p_delta); if (status == RUNNING && get_elapsed_time() >= time_limit) { get_child(0)->cancel(); return FAILURE; diff --git a/bt/tasks/decorators/bt_time_limit.h b/bt/tasks/decorators/bt_time_limit.h index aa960bf..c6bd855 100644 --- a/bt/tasks/decorators/bt_time_limit.h +++ b/bt/tasks/decorators/bt_time_limit.h @@ -25,7 +25,7 @@ protected: static void _bind_methods(); virtual String _generate_name() const override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: void set_time_limit(double p_value); diff --git a/bt/tasks/scene/bt_await_animation.cpp b/bt/tasks/scene/bt_await_animation.cpp index 35a190a..5c9e882 100644 --- a/bt/tasks/scene/bt_await_animation.cpp +++ b/bt/tasks/scene/bt_await_animation.cpp @@ -69,7 +69,7 @@ void BTAwaitAnimation::_setup() { setup_failed = false; } -int BTAwaitAnimation::_tick(double p_delta) { +BT::Status BTAwaitAnimation::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(setup_failed == true, FAILURE, "BTAwaitAnimation: _setup() failed - returning FAILURE."); // ! Doing this check instead of using signal due to a bug in Godot: https://github.com/godotengine/godot/issues/76127 diff --git a/bt/tasks/scene/bt_await_animation.h b/bt/tasks/scene/bt_await_animation.h index 0c56efd..88a2508 100644 --- a/bt/tasks/scene/bt_await_animation.h +++ b/bt/tasks/scene/bt_await_animation.h @@ -35,7 +35,7 @@ protected: virtual String _generate_name() const override; virtual void _setup() override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: void set_animation_player(Ref p_animation_player); diff --git a/bt/tasks/scene/bt_call_method.cpp b/bt/tasks/scene/bt_call_method.cpp index 5855176..7d828c4 100644 --- a/bt/tasks/scene/bt_call_method.cpp +++ b/bt/tasks/scene/bt_call_method.cpp @@ -55,7 +55,7 @@ String BTCallMethod::_generate_name() const { (node_param.is_valid() && !node_param->to_string().is_empty() ? node_param->to_string() : "???")); } -int BTCallMethod::_tick(double p_delta) { +BT::Status BTCallMethod::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(method == StringName(), FAILURE, "BTCallMethod: Method Name is not set."); ERR_FAIL_COND_V_MSG(node_param.is_null(), FAILURE, "BTCallMethod: Node parameter is not set."); Object *obj = node_param->get_value(get_agent(), get_blackboard()); diff --git a/bt/tasks/scene/bt_call_method.h b/bt/tasks/scene/bt_call_method.h index e1abb8f..74dc99c 100644 --- a/bt/tasks/scene/bt_call_method.h +++ b/bt/tasks/scene/bt_call_method.h @@ -29,7 +29,7 @@ protected: static void _bind_methods(); virtual String _generate_name() const override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: void set_method(StringName p_method_name); diff --git a/bt/tasks/scene/bt_check_agent_property.cpp b/bt/tasks/scene/bt_check_agent_property.cpp index ac219a1..0befedd 100644 --- a/bt/tasks/scene/bt_check_agent_property.cpp +++ b/bt/tasks/scene/bt_check_agent_property.cpp @@ -54,7 +54,7 @@ String BTCheckAgentProperty::_generate_name() const { value.is_valid() ? Variant(value) : Variant("???")); } -int BTCheckAgentProperty::_tick(double p_delta) { +BT::Status BTCheckAgentProperty::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(property == StringName(), FAILURE, "BTCheckAgentProperty: `property` is not set."); ERR_FAIL_COND_V_MSG(!value.is_valid(), FAILURE, "BTCheckAgentProperty: `value` is not set."); diff --git a/bt/tasks/scene/bt_check_agent_property.h b/bt/tasks/scene/bt_check_agent_property.h index 2c50c00..905346a 100644 --- a/bt/tasks/scene/bt_check_agent_property.h +++ b/bt/tasks/scene/bt_check_agent_property.h @@ -32,7 +32,7 @@ protected: static void _bind_methods(); virtual String _generate_name() const override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: void set_property(StringName p_prop); diff --git a/bt/tasks/scene/bt_pause_animation.cpp b/bt/tasks/scene/bt_pause_animation.cpp index 9a45a30..3208ca3 100644 --- a/bt/tasks/scene/bt_pause_animation.cpp +++ b/bt/tasks/scene/bt_pause_animation.cpp @@ -49,7 +49,7 @@ void BTPauseAnimation::_setup() { setup_failed = false; } -int BTPauseAnimation::_tick(double p_delta) { +BT::Status BTPauseAnimation::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(setup_failed == true, FAILURE, "BTPauseAnimation: _setup() failed - returning FAILURE."); animation_player->pause(); return SUCCESS; diff --git a/bt/tasks/scene/bt_pause_animation.h b/bt/tasks/scene/bt_pause_animation.h index 4424e77..385d87b 100644 --- a/bt/tasks/scene/bt_pause_animation.h +++ b/bt/tasks/scene/bt_pause_animation.h @@ -33,7 +33,7 @@ protected: virtual String _generate_name() const override; virtual void _setup() override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: void set_animation_player(Ref p_animation_player); diff --git a/bt/tasks/scene/bt_play_animation.cpp b/bt/tasks/scene/bt_play_animation.cpp index a37fe46..5fc224e 100644 --- a/bt/tasks/scene/bt_play_animation.cpp +++ b/bt/tasks/scene/bt_play_animation.cpp @@ -94,7 +94,7 @@ void BTPlayAnimation::_enter() { } } -int BTPlayAnimation::_tick(double p_delta) { +BT::Status BTPlayAnimation::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(setup_failed == true, FAILURE, "BTPlayAnimation: _setup() failed - returning FAILURE."); // ! Doing this check instead of using signal due to a bug in Godot: https://github.com/godotengine/godot/issues/76127 diff --git a/bt/tasks/scene/bt_play_animation.h b/bt/tasks/scene/bt_play_animation.h index 4c277c2..331a1b6 100644 --- a/bt/tasks/scene/bt_play_animation.h +++ b/bt/tasks/scene/bt_play_animation.h @@ -39,7 +39,7 @@ protected: virtual String _generate_name() const override; virtual void _setup() override; virtual void _enter() override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: void set_animation_player(Ref p_animation_player); diff --git a/bt/tasks/scene/bt_set_agent_property.cpp b/bt/tasks/scene/bt_set_agent_property.cpp index 5860009..16f93df 100644 --- a/bt/tasks/scene/bt_set_agent_property.cpp +++ b/bt/tasks/scene/bt_set_agent_property.cpp @@ -44,7 +44,7 @@ String BTSetAgentProperty::_generate_name() const { value.is_valid() ? Variant(value) : Variant("???")); } -int BTSetAgentProperty::_tick(double p_delta) { +BT::Status BTSetAgentProperty::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(property == StringName(), FAILURE, "BTSetAgentProperty: `property` is not set."); ERR_FAIL_COND_V_MSG(!value.is_valid(), FAILURE, "BTSetAgentProperty: `value` is not set."); diff --git a/bt/tasks/scene/bt_set_agent_property.h b/bt/tasks/scene/bt_set_agent_property.h index 8df6389..65fff0e 100644 --- a/bt/tasks/scene/bt_set_agent_property.h +++ b/bt/tasks/scene/bt_set_agent_property.h @@ -28,7 +28,7 @@ protected: static void _bind_methods(); virtual String _generate_name() const override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: virtual PackedStringArray get_configuration_warnings() const override; diff --git a/bt/tasks/scene/bt_stop_animation.cpp b/bt/tasks/scene/bt_stop_animation.cpp index ca05f00..02a4ab7 100644 --- a/bt/tasks/scene/bt_stop_animation.cpp +++ b/bt/tasks/scene/bt_stop_animation.cpp @@ -64,7 +64,7 @@ void BTStopAnimation::_setup() { setup_failed = false; } -int BTStopAnimation::_tick(double p_delta) { +BT::Status BTStopAnimation::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(setup_failed == true, FAILURE, "BTStopAnimation: _setup() failed - returning FAILURE."); if (animation_player->is_playing() && (animation_name == StringName() || animation_name == animation_player->get_assigned_animation())) { animation_player->stop(keep_state); diff --git a/bt/tasks/scene/bt_stop_animation.h b/bt/tasks/scene/bt_stop_animation.h index 217e10d..d971415 100644 --- a/bt/tasks/scene/bt_stop_animation.h +++ b/bt/tasks/scene/bt_stop_animation.h @@ -35,7 +35,7 @@ protected: virtual String _generate_name() const override; virtual void _setup() override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: void set_animation_player(Ref p_animation_player); diff --git a/bt/tasks/utility/bt_console_print.cpp b/bt/tasks/utility/bt_console_print.cpp index 98b7715..c74605e 100644 --- a/bt/tasks/utility/bt_console_print.cpp +++ b/bt/tasks/utility/bt_console_print.cpp @@ -29,7 +29,7 @@ String BTConsolePrint::_generate_name() const { return vformat("ConsolePrint text: \"%s\"", tx); } -int BTConsolePrint::_tick(double p_delta) { +BT::Status BTConsolePrint::_tick(double p_delta) { switch (bb_format_parameters.size()) { case 0: { print_line(text); diff --git a/bt/tasks/utility/bt_console_print.h b/bt/tasks/utility/bt_console_print.h index dc8d718..1ebc281 100644 --- a/bt/tasks/utility/bt_console_print.h +++ b/bt/tasks/utility/bt_console_print.h @@ -28,7 +28,7 @@ protected: static void _bind_methods(); virtual String _generate_name() const override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: void set_text(String p_value) { diff --git a/bt/tasks/utility/bt_fail.cpp b/bt/tasks/utility/bt_fail.cpp index 74370c7..ee4c435 100644 --- a/bt/tasks/utility/bt_fail.cpp +++ b/bt/tasks/utility/bt_fail.cpp @@ -11,6 +11,6 @@ #include "bt_fail.h" -int BTFail::_tick(double p_delta) { +BT::Status BTFail::_tick(double p_delta) { return FAILURE; } diff --git a/bt/tasks/utility/bt_fail.h b/bt/tasks/utility/bt_fail.h index e1cbb24..48c98f0 100644 --- a/bt/tasks/utility/bt_fail.h +++ b/bt/tasks/utility/bt_fail.h @@ -19,7 +19,7 @@ class BTFail : public BTAction { TASK_CATEGORY(Utility); protected: - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; }; #endif // BT_FAIL_H \ No newline at end of file diff --git a/bt/tasks/utility/bt_random_wait.cpp b/bt/tasks/utility/bt_random_wait.cpp index 8d0958e..90d2727 100644 --- a/bt/tasks/utility/bt_random_wait.cpp +++ b/bt/tasks/utility/bt_random_wait.cpp @@ -23,7 +23,7 @@ void BTRandomWait::_enter() { duration = Math::random(min_duration, max_duration); } -int BTRandomWait::_tick(double p_delta) { +BT::Status BTRandomWait::_tick(double p_delta) { if (get_elapsed_time() < duration) { return RUNNING; } else { diff --git a/bt/tasks/utility/bt_random_wait.h b/bt/tasks/utility/bt_random_wait.h index 5490f6c..af47902 100644 --- a/bt/tasks/utility/bt_random_wait.h +++ b/bt/tasks/utility/bt_random_wait.h @@ -29,7 +29,7 @@ protected: virtual String _generate_name() const override; virtual void _enter() override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: void set_min_duration(double p_max_duration); diff --git a/bt/tasks/utility/bt_wait.cpp b/bt/tasks/utility/bt_wait.cpp index 837f8fc..5dd1776 100644 --- a/bt/tasks/utility/bt_wait.cpp +++ b/bt/tasks/utility/bt_wait.cpp @@ -20,7 +20,7 @@ String BTWait::_generate_name() const { return vformat("Wait %s sec", Math::snapped(duration, 0.001)); } -int BTWait::_tick(double p_delta) { +BT::Status BTWait::_tick(double p_delta) { if (get_elapsed_time() < duration) { return RUNNING; } else { diff --git a/bt/tasks/utility/bt_wait.h b/bt/tasks/utility/bt_wait.h index 9824f9b..462be07 100644 --- a/bt/tasks/utility/bt_wait.h +++ b/bt/tasks/utility/bt_wait.h @@ -25,7 +25,7 @@ protected: static void _bind_methods(); virtual String _generate_name() const override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: void set_duration(double p_value) { diff --git a/bt/tasks/utility/bt_wait_ticks.cpp b/bt/tasks/utility/bt_wait_ticks.cpp index 8b818d1..6d78aca 100644 --- a/bt/tasks/utility/bt_wait_ticks.cpp +++ b/bt/tasks/utility/bt_wait_ticks.cpp @@ -22,7 +22,7 @@ void BTWaitTicks::_enter() { num_passed = 0; } -int BTWaitTicks::_tick(double p_delta) { +BT::Status BTWaitTicks::_tick(double p_delta) { if (num_passed < num_ticks) { num_passed += 1; return RUNNING; diff --git a/bt/tasks/utility/bt_wait_ticks.h b/bt/tasks/utility/bt_wait_ticks.h index 2e5ae50..9682eb8 100644 --- a/bt/tasks/utility/bt_wait_ticks.h +++ b/bt/tasks/utility/bt_wait_ticks.h @@ -28,7 +28,7 @@ protected: virtual String _generate_name() const override; virtual void _enter() override; - virtual int _tick(double p_delta) override; + virtual Status _tick(double p_delta) override; public: void set_num_ticks(int p_value) { diff --git a/config.py b/config.py index 3c1b166..8f47e4c 100644 --- a/config.py +++ b/config.py @@ -57,6 +57,7 @@ def get_doc_classes(): "BehaviorTree", "BehaviorTreeView", "Blackboard", + "BT", "BTAction", "BTAlwaysFail", "BTAlwaysSucceed", diff --git a/register_types.cpp b/register_types.cpp index b9c43c3..4cd9fc3 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -117,6 +117,7 @@ void initialize_limboai_module(ModuleInitializationLevel p_level) { GDREGISTER_CLASS(LimboState); GDREGISTER_CLASS(LimboHSM); + GDREGISTER_ABSTRACT_CLASS(BT); GDREGISTER_ABSTRACT_CLASS(BTTask); GDREGISTER_CLASS(BehaviorTree); GDREGISTER_CLASS(BTPlayer); diff --git a/tests/limbo_test.h b/tests/limbo_test.h index f47c35f..d5b1cad 100644 --- a/tests/limbo_test.h +++ b/tests/limbo_test.h @@ -37,7 +37,7 @@ class BTTestAction : public BTAction { GDCLASS(BTTestAction, BTAction); public: - int ret_status = BTTask::SUCCESS; + Status ret_status = BTTask::SUCCESS; int num_entries = 0; int num_ticks = 0; int num_exits = 0; @@ -46,15 +46,15 @@ protected: virtual void _enter() override { num_entries += 1; } virtual void _exit() override { num_exits += 1; } - virtual int _tick(double p_delta) override { + virtual Status _tick(double p_delta) override { num_ticks += 1; return ret_status; } public: - bool is_status_either(int p_status1, int p_status2) { return (get_status() == p_status1 || get_status() == p_status2); } + bool is_status_either(Status p_status1, Status p_status2) { return (get_status() == p_status1 || get_status() == p_status2); } - BTTestAction(int p_return_status) { ret_status = p_return_status; } + BTTestAction(Status p_return_status) { ret_status = p_return_status; } BTTestAction() {} };