Refactor BTInstance.update()

This commit is contained in:
Serhii Snitsaruk 2024-08-03 11:47:05 +02:00
parent 47ad95b265
commit 6c794d6a7e
No known key found for this signature in database
GPG Key ID: A965EF8799FFEC2D
3 changed files with 7 additions and 7 deletions

View File

@ -35,8 +35,8 @@ Ref<BTInstance> BTInstance::create(Ref<BTTask> p_root_task, String p_source_bt_p
return inst; return inst;
} }
void BTInstance::update(double p_delta) { BT::Status BTInstance::update(double p_delta) {
ERR_FAIL_COND(!root_task.is_valid()); ERR_FAIL_COND_V(!root_task.is_valid(), BT::FRESH);
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
double start = Time::get_singleton()->get_ticks_usec(); 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_acc += (end - start);
update_time_n += 1.0; update_time_n += 1.0;
#endif #endif
return last_status;
} }
void BTInstance::set_monitor_performance(bool p_monitor) { void BTInstance::set_monitor_performance(bool p_monitor) {

View File

@ -20,7 +20,7 @@ private:
Ref<BTTask> root_task; Ref<BTTask> root_task;
uint64_t owner_node_id; uint64_t owner_node_id;
String source_bt_path; String source_bt_path;
BTTask::Status last_status = BTTask::FRESH; BT::Status last_status = BT::FRESH;
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
bool monitor_performance = false; bool monitor_performance = false;
@ -40,11 +40,11 @@ protected:
public: public:
_FORCE_INLINE_ Ref<BTTask> get_root_task() const { return root_task; } _FORCE_INLINE_ Ref<BTTask> get_root_task() const { return root_task; }
_FORCE_INLINE_ Node *get_owner_node() const { return Object::cast_to<Node>(OBJECT_DB_GET_INSTANCE(owner_node_id)); } _FORCE_INLINE_ Node *get_owner_node() const { return Object::cast_to<Node>(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_ bool is_instance_valid() const { return root_task.is_valid(); }
_FORCE_INLINE_ String get_source_bt_path() const { return source_bt_path; } _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); void set_monitor_performance(bool p_monitor);
bool get_monitor_performance() const; bool get_monitor_performance() const;

View File

@ -77,8 +77,7 @@ void BTState::_update(double p_delta) {
return; return;
} }
ERR_FAIL_NULL(bt_instance); ERR_FAIL_NULL(bt_instance);
bt_instance->update(p_delta); BT::Status status = bt_instance->update(p_delta);
BTTask::Status status = bt_instance->get_last_status();
if (status == BTTask::SUCCESS) { if (status == BTTask::SUCCESS) {
get_root()->dispatch(success_event, Variant()); get_root()->dispatch(success_event, Variant());
} else if (status == BTTask::FAILURE) { } else if (status == BTTask::FAILURE) {