From 6c794d6a7e41cf72af705438db80095f799ddd0a Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Sat, 3 Aug 2024 11:47:05 +0200 Subject: [PATCH] Refactor BTInstance.update() --- bt/bt_instance.cpp | 5 +++-- bt/bt_instance.h | 6 +++--- bt/bt_state.cpp | 3 +-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bt/bt_instance.cpp b/bt/bt_instance.cpp index 74997fe..50011b8 100644 --- a/bt/bt_instance.cpp +++ b/bt/bt_instance.cpp @@ -35,8 +35,8 @@ Ref BTInstance::create(Ref p_root_task, String p_source_bt_p return inst; } -void BTInstance::update(double p_delta) { - ERR_FAIL_COND(!root_task.is_valid()); +BT::Status BTInstance::update(double p_delta) { + ERR_FAIL_COND_V(!root_task.is_valid(), BT::FRESH); #ifdef DEBUG_ENABLED double start = Time::get_singleton()->get_ticks_usec(); @@ -50,6 +50,7 @@ void BTInstance::update(double p_delta) { update_time_acc += (end - start); update_time_n += 1.0; #endif + return last_status; } void BTInstance::set_monitor_performance(bool p_monitor) { diff --git a/bt/bt_instance.h b/bt/bt_instance.h index dbace83..d68c92a 100644 --- a/bt/bt_instance.h +++ b/bt/bt_instance.h @@ -20,7 +20,7 @@ private: Ref root_task; uint64_t owner_node_id; String source_bt_path; - BTTask::Status last_status = BTTask::FRESH; + BT::Status last_status = BT::FRESH; #ifdef DEBUG_ENABLED bool monitor_performance = false; @@ -40,11 +40,11 @@ protected: public: _FORCE_INLINE_ Ref get_root_task() const { return root_task; } _FORCE_INLINE_ Node *get_owner_node() const { return Object::cast_to(OBJECT_DB_GET_INSTANCE(owner_node_id)); } - _FORCE_INLINE_ BTTask::Status get_last_status() const { return last_status; } + _FORCE_INLINE_ BT::Status get_last_status() const { return last_status; } _FORCE_INLINE_ bool is_instance_valid() const { return root_task.is_valid(); } _FORCE_INLINE_ String get_source_bt_path() const { return source_bt_path; } - void update(double p_delta); + BT::Status update(double p_delta); void set_monitor_performance(bool p_monitor); bool get_monitor_performance() const; diff --git a/bt/bt_state.cpp b/bt/bt_state.cpp index cd44d21..1457f00 100644 --- a/bt/bt_state.cpp +++ b/bt/bt_state.cpp @@ -77,8 +77,7 @@ void BTState::_update(double p_delta) { return; } ERR_FAIL_NULL(bt_instance); - bt_instance->update(p_delta); - BTTask::Status status = bt_instance->get_last_status(); + BT::Status status = bt_instance->update(p_delta); if (status == BTTask::SUCCESS) { get_root()->dispatch(success_event, Variant()); } else if (status == BTTask::FAILURE) {