Expose additional `BlackboardPlan` methods for custom tooling

This commit is contained in:
Serhii Snitsaruk 2024-03-08 15:33:28 +01:00
parent f4ceb27b35
commit 9957ef2ea7
5 changed files with 109 additions and 6 deletions

View File

@ -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");
}

View File

@ -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<Blackboard> create_blackboard(Node *p_agent);
void populate_blackboard(const Ref<Blackboard> &p_blackboard, bool overwrite, Node *p_node);

View File

@ -41,6 +41,8 @@ Methods
.. table::
:widths: auto
+------+----------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`clear<class_BehaviorTreeView_method_clear>` **(** **)** |
+------+----------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`update_tree<class_BehaviorTreeView_method_update_tree>` **(** :ref:`BehaviorTreeData<class_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

View File

@ -34,11 +34,19 @@ Methods
.. table::
:widths: auto
+-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Blackboard<class_Blackboard>` | :ref:`create_blackboard<class_BlackboardPlan_method_create_blackboard>` **(** Node node **)** |
+-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`populate_blackboard<class_BlackboardPlan_method_populate_blackboard>` **(** :ref:`Blackboard<class_Blackboard>` blackboard, bool overwrite, Node node **)** |
+-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
+---------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Blackboard<class_Blackboard>` | :ref:`create_blackboard<class_BlackboardPlan_method_create_blackboard>` **(** Node node **)** |
+---------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`BlackboardPlan<class_BlackboardPlan>` | :ref:`get_base_plan<class_BlackboardPlan_method_get_base_plan>` **(** **)** |const| |
+---------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| bool | :ref:`is_derived<class_BlackboardPlan_method_is_derived>` **(** **)** |const| |
+---------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`populate_blackboard<class_BlackboardPlan_method_populate_blackboard>` **(** :ref:`Blackboard<class_Blackboard>` blackboard, bool overwrite, Node node **)** |
+---------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`set_base_plan<class_BlackboardPlan_method_set_base_plan>` **(** :ref:`BlackboardPlan<class_BlackboardPlan>` blackboard_plan **)** |
+---------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`sync_with_base_plan<class_BlackboardPlan_method_sync_with_base_plan>` **(** **)** |
+---------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
@ -83,6 +91,30 @@ Constructs a new instance of a :ref:`Blackboard<class_Blackboard>` using this pl
----
.. _class_BlackboardPlan_method_get_base_plan:
.. rst-class:: classref-method
:ref:`BlackboardPlan<class_BlackboardPlan>` **get_base_plan** **(** **)** |const|
Returns the base plan. See :ref:`is_derived<class_BlackboardPlan_method_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<class_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<class_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.)`

View File

@ -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.
</description>
</method>
<method name="get_base_plan" qualifiers="const">
<return type="BlackboardPlan" />
<description>
Returns the base plan. See [method is_derived].
</description>
</method>
<method name="is_derived" qualifiers="const">
<return type="bool" />
<description>
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.
</description>
</method>
<method name="populate_blackboard">
<return type="void" />
<param index="0" name="blackboard" type="Blackboard" />
@ -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.
</description>
</method>
<method name="set_base_plan">
<return type="void" />
<param index="0" name="blackboard_plan" type="BlackboardPlan" />
<description>
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.
</description>
</method>
<method name="sync_with_base_plan">
<return type="void" />
<description>
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.
</description>
</method>
</methods>
<members>
<member name="prefetch_nodepath_vars" type="bool" setter="set_prefetch_nodepath_vars" getter="is_prefetching_nodepath_vars" default="true">