From 71909648b79c452fec5941f0381e3969a7807728 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Wed, 22 Nov 2023 13:41:28 +0100 Subject: [PATCH] Add "inline" optimizations --- bt/tasks/bt_task.cpp | 13 ------------- bt/tasks/bt_task.h | 28 ++++++++++++++++++---------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/bt/tasks/bt_task.cpp b/bt/tasks/bt_task.cpp index 4490b5e..3cdad3f 100644 --- a/bt/tasks/bt_task.cpp +++ b/bt/tasks/bt_task.cpp @@ -199,15 +199,6 @@ void BTTask::abort() { data.elapsed = 0.0; } -Ref BTTask::get_child(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, data.children.size(), nullptr); - return data.children.get(p_idx); -} - -int BTTask::get_child_count() const { - return data.children.size(); -} - int BTTask::get_child_count_excluding_comments() const { int count = 0; for (int i = 0; i < data.children.size(); i++) { @@ -263,10 +254,6 @@ void BTTask::remove_child_at_index(int p_idx) { emit_changed(); } -bool BTTask::has_child(const Ref &p_child) const { - return data.children.find(p_child) != -1; -} - bool BTTask::is_descendant_of(const Ref &p_task) const { const BTTask *task = this; while (task != nullptr) { diff --git a/bt/tasks/bt_task.h b/bt/tasks/bt_task.h index 806bf71..15f3d80 100644 --- a/bt/tasks/bt_task.h +++ b/bt/tasks/bt_task.h @@ -88,17 +88,14 @@ protected: public: virtual bool editor_can_reload_from_file() override { return false; } - Node *get_agent() const { return data.agent; } + _FORCE_INLINE_ Node *get_agent() const { return data.agent; } void set_agent(Node *p_agent) { data.agent = p_agent; } String get_custom_name() const { return data.custom_name; } void set_custom_name(const String &p_name); String get_task_name() const; - Ref get_blackboard() const { return data.blackboard; } - Ref get_parent() const { return Ref(data.parent); } Ref get_root() const; - bool is_root() const { return data.parent == nullptr; } virtual Ref clone() const; virtual void initialize(Node *p_agent, const Ref &p_blackboard); @@ -106,19 +103,30 @@ public: Status execute(double p_delta); void abort(); - Status get_status() const { return data.status; } - double get_elapsed_time() const { return data.elapsed; }; - Ref get_child(int p_idx) const; - int get_child_count() const; + _FORCE_INLINE_ Ref get_parent() const { return Ref(data.parent); } + _FORCE_INLINE_ bool is_root() const { return data.parent == nullptr; } + _FORCE_INLINE_ Ref get_blackboard() const { return data.blackboard; } + _FORCE_INLINE_ Status get_status() const { return data.status; } + _FORCE_INLINE_ double get_elapsed_time() const { return data.elapsed; }; + + _FORCE_INLINE_ Ref get_child(int p_idx) const { + ERR_FAIL_INDEX_V(p_idx, data.children.size(), nullptr); + return data.children.get(p_idx); + } + + _FORCE_INLINE_ int get_child_count() const { return data.children.size(); } int get_child_count_excluding_comments() const; + void add_child(Ref p_child); void add_child_at_index(Ref p_child, int p_idx); void remove_child(Ref p_child); void remove_child_at_index(int p_idx); - bool has_child(const Ref &p_child) const; - bool is_descendant_of(const Ref &p_task) const; + + _FORCE_INLINE_ bool has_child(const Ref &p_child) const { return data.children.find(p_child) != -1; } _FORCE_INLINE_ int get_index() const { return data.index; } + + bool is_descendant_of(const Ref &p_task) const; Ref next_sibling() const; void print_tree(int p_initial_tabs = 0) const;