From 9957ef2ea76f408646e95fc3c9d3ffbdc1fd9a94 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Fri, 8 Mar 2024 15:33:28 +0100 Subject: [PATCH] Expose additional `BlackboardPlan` methods for custom tooling --- blackboard/blackboard_plan.cpp | 5 ++ blackboard/blackboard_plan.h | 2 +- doc/source/classes/class_behaviortreeview.rst | 14 ++++ doc/source/classes/class_blackboardplan.rst | 68 +++++++++++++++++-- doc_classes/BlackboardPlan.xml | 26 +++++++ 5 files changed, 109 insertions(+), 6 deletions(-) diff --git a/blackboard/blackboard_plan.cpp b/blackboard/blackboard_plan.cpp index 0229e3c..6308112 100644 --- a/blackboard/blackboard_plan.cpp +++ b/blackboard/blackboard_plan.cpp @@ -319,9 +319,14 @@ void BlackboardPlan::_bind_methods() { ClassDB::bind_method(D_METHOD("set_prefetch_nodepath_vars", "enable"), &BlackboardPlan::set_prefetch_nodepath_vars); ClassDB::bind_method(D_METHOD("is_prefetching_nodepath_vars"), &BlackboardPlan::is_prefetching_nodepath_vars); + ClassDB::bind_method(D_METHOD("set_base_plan", "blackboard_plan"), &BlackboardPlan::set_base_plan); + ClassDB::bind_method(D_METHOD("get_base_plan"), &BlackboardPlan::get_base_plan); + ClassDB::bind_method(D_METHOD("is_derived"), &BlackboardPlan::is_derived); + ClassDB::bind_method(D_METHOD("sync_with_base_plan"), &BlackboardPlan::sync_with_base_plan); ClassDB::bind_method(D_METHOD("create_blackboard", "node"), &BlackboardPlan::create_blackboard); ClassDB::bind_method(D_METHOD("populate_blackboard", "blackboard", "overwrite", "node"), &BlackboardPlan::populate_blackboard); + // To avoid cluttering the member namespace, we do not export unnecessary properties in this class. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "prefetch_nodepath_vars", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_prefetch_nodepath_vars", "is_prefetching_nodepath_vars"); } diff --git a/blackboard/blackboard_plan.h b/blackboard/blackboard_plan.h index 6df1a21..83fdd45 100644 --- a/blackboard/blackboard_plan.h +++ b/blackboard/blackboard_plan.h @@ -70,7 +70,7 @@ public: void move_var(int p_index, int p_new_index); void sync_with_base_plan(); - bool is_derived() const { return base.is_valid(); } + _FORCE_INLINE_ bool is_derived() const { return base.is_valid(); } Ref create_blackboard(Node *p_agent); void populate_blackboard(const Ref &p_blackboard, bool overwrite, Node *p_node); diff --git a/doc/source/classes/class_behaviortreeview.rst b/doc/source/classes/class_behaviortreeview.rst index 13f2e60..55b0cc7 100644 --- a/doc/source/classes/class_behaviortreeview.rst +++ b/doc/source/classes/class_behaviortreeview.rst @@ -41,6 +41,8 @@ Methods .. table:: :widths: auto + +------+----------------------------------------------------------------------------------------------------------------------------------------------+ + | void | :ref:`clear` **(** **)** | +------+----------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`update_tree` **(** :ref:`BehaviorTreeData` behavior_tree_data **)** | +------+----------------------------------------------------------------------------------------------------------------------------------------------+ @@ -93,6 +95,18 @@ Minimum delay between two updates (in milliseconds). Set to higher values for a Method Descriptions ------------------- +.. _class_BehaviorTreeView_method_clear: + +.. rst-class:: classref-method + +void **clear** **(** **)** + +Clears the tree view. + +.. rst-class:: classref-item-separator + +---- + .. _class_BehaviorTreeView_method_update_tree: .. rst-class:: classref-method diff --git a/doc/source/classes/class_blackboardplan.rst b/doc/source/classes/class_blackboardplan.rst index 7bddb32..f19a4c7 100644 --- a/doc/source/classes/class_blackboardplan.rst +++ b/doc/source/classes/class_blackboardplan.rst @@ -34,11 +34,19 @@ Methods .. table:: :widths: auto - +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - | :ref:`Blackboard` | :ref:`create_blackboard` **(** Node node **)** | - +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - | void | :ref:`populate_blackboard` **(** :ref:`Blackboard` blackboard, bool overwrite, Node node **)** | - +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+ + +---------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+ + | :ref:`Blackboard` | :ref:`create_blackboard` **(** Node node **)** | + +---------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+ + | :ref:`BlackboardPlan` | :ref:`get_base_plan` **(** **)** |const| | + +---------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+ + | bool | :ref:`is_derived` **(** **)** |const| | + +---------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+ + | void | :ref:`populate_blackboard` **(** :ref:`Blackboard` blackboard, bool overwrite, Node node **)** | + +---------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+ + | void | :ref:`set_base_plan` **(** :ref:`BlackboardPlan` blackboard_plan **)** | + +---------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+ + | void | :ref:`sync_with_base_plan` **(** **)** | + +---------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator @@ -83,6 +91,30 @@ Constructs a new instance of a :ref:`Blackboard` using this pl ---- +.. _class_BlackboardPlan_method_get_base_plan: + +.. rst-class:: classref-method + +:ref:`BlackboardPlan` **get_base_plan** **(** **)** |const| + +Returns the base plan. See :ref:`is_derived`. + +.. rst-class:: classref-item-separator + +---- + +.. _class_BlackboardPlan_method_is_derived: + +.. rst-class:: classref-method + +bool **is_derived** **(** **)** |const| + +Returns ``true`` if this plan is derived from another, i.e., the base plan is not ``null``. A derived plan can only contain variables that are present in the base plan, and only variable values can be different. + +.. rst-class:: classref-item-separator + +---- + .. _class_BlackboardPlan_method_populate_blackboard: .. rst-class:: classref-method @@ -91,6 +123,32 @@ void **populate_blackboard** **(** :ref:`Blackboard` blackboar Populates ``blackboard`` with the variables from this plan. If ``overwrite`` is ``true``, existing variables with the same names will be overwritten. If ``NodePath`` prefetching is enabled, ``node`` will be used to retrieve node instances for ``NodePath`` variables and substitute their values. +.. rst-class:: classref-item-separator + +---- + +.. _class_BlackboardPlan_method_set_base_plan: + +.. rst-class:: classref-method + +void **set_base_plan** **(** :ref:`BlackboardPlan` blackboard_plan **)** + +Sets the base plan. If assigned, this plan will be derived from the base plan. + +Use with caution, as it will remove variables not present in the base plan. Only use this for custom tooling. + +.. rst-class:: classref-item-separator + +---- + +.. _class_BlackboardPlan_method_sync_with_base_plan: + +.. rst-class:: classref-method + +void **sync_with_base_plan** **(** **)** + +Synchronizes this plan with the base plan: removes variables not present in the base plan, and updates type information. Only use this for custom tooling. + .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` diff --git a/doc_classes/BlackboardPlan.xml b/doc_classes/BlackboardPlan.xml index fa40124..2be4080 100644 --- a/doc_classes/BlackboardPlan.xml +++ b/doc_classes/BlackboardPlan.xml @@ -15,6 +15,18 @@ Constructs a new instance of a [Blackboard] using this plan. If [NodePath] prefetching is enabled, [param node] will be used to retrieve node instances for [NodePath] variables and substitute their values. + + + + Returns the base plan. See [method is_derived]. + + + + + + Returns [code]true[/code] if this plan is derived from another, i.e., the base plan is not [code]null[/code]. A derived plan can only contain variables that are present in the base plan, and only variable values can be different. + + @@ -24,6 +36,20 @@ Populates [param blackboard] with the variables from this plan. If [param overwrite] is [code]true[/code], existing variables with the same names will be overwritten. If [NodePath] prefetching is enabled, [param node] will be used to retrieve node instances for [NodePath] variables and substitute their values. + + + + + Sets the base plan. If assigned, this plan will be derived from the base plan. + Use with caution, as it will remove variables not present in the base plan. Only use this for custom tooling. + + + + + + Synchronizes this plan with the base plan: removes variables not present in the base plan, and updates type information. Only use this for custom tooling. + +