BTPlayer: Fix `updated` signal and deprecate `behavior_tree_finished` signal

This commit is contained in:
Serhii Snitsaruk 2024-08-03 16:11:47 +02:00
parent 869b6465b9
commit 63ef3e0555
No known key found for this signature in database
GPG Key ID: A965EF8799FFEC2D
5 changed files with 25 additions and 16 deletions

View File

@ -51,6 +51,7 @@ void BTPlayer::_load_tree() {
Node *scene_root = get_owner(); Node *scene_root = get_owner();
ERR_FAIL_NULL_MSG(scene_root, "BTPlayer: Initialization failed - can't get scene root (make sure the BTPlayer's owner property is set)."); ERR_FAIL_NULL_MSG(scene_root, "BTPlayer: Initialization failed - can't get scene root (make sure the BTPlayer's owner property is set).");
bt_instance = behavior_tree->instantiate(agent, blackboard, this); bt_instance = behavior_tree->instantiate(agent, blackboard, this);
ERR_FAIL_COND_MSG(bt_instance.is_null(), "BTPlayer: Failed to instantiate behavior tree.");
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
bt_instance->set_monitor_performance(monitor_performance); bt_instance->set_monitor_performance(monitor_performance);
bt_instance->register_with_debugger(); bt_instance->register_with_debugger();
@ -118,7 +119,13 @@ void BTPlayer::update(double p_delta) {
} }
if (active) { if (active) {
bt_instance->update(p_delta); BT::Status status = bt_instance->update(p_delta);
emit_signal(LW_NAME(updated), status);
#ifndef DISABLE_DEPRECATED
if (status == BTTask::SUCCESS || status == BTTask::FAILURE) {
emit_signal(LW_NAME(behavior_tree_finished), status);
}
#endif // DISABLE_DEPRECATED
} }
} }
@ -222,9 +229,12 @@ void BTPlayer::_bind_methods() {
BIND_ENUM_CONSTANT(PHYSICS); BIND_ENUM_CONSTANT(PHYSICS);
BIND_ENUM_CONSTANT(MANUAL); BIND_ENUM_CONSTANT(MANUAL);
ADD_SIGNAL(MethodInfo("behavior_tree_finished", PropertyInfo(Variant::INT, "status")));
ADD_SIGNAL(MethodInfo("updated", PropertyInfo(Variant::INT, "status"))); ADD_SIGNAL(MethodInfo("updated", PropertyInfo(Variant::INT, "status")));
#ifndef DISABLE_DEPRECATED
ADD_SIGNAL(MethodInfo("behavior_tree_finished", PropertyInfo(Variant::INT, "status")));
#endif
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
ClassDB::bind_method(D_METHOD("_set_monitor_performance", "enable"), &BTPlayer::_set_monitor_performance); ClassDB::bind_method(D_METHOD("_set_monitor_performance", "enable"), &BTPlayer::_set_monitor_performance);
ClassDB::bind_method(D_METHOD("_get_monitor_performance"), &BTPlayer::_get_monitor_performance); ClassDB::bind_method(D_METHOD("_get_monitor_performance"), &BTPlayer::_get_monitor_performance);

View File

@ -121,7 +121,7 @@ Stores and manages variables that will be used in constructing new :ref:`Blackbo
- |void| **set_description**\ (\ value\: ``String``\ ) - |void| **set_description**\ (\ value\: ``String``\ )
- ``String`` **get_description**\ (\ ) - ``String`` **get_description**\ (\ )
User-provided description of the BehaviorTree. User-provided description of the **BehaviorTree**.
.. rst-class:: classref-section-separator .. rst-class:: classref-section-separator
@ -174,11 +174,7 @@ Returns the root task of the BehaviorTree resource.
:ref:`BTInstance<class_BTInstance>` **instantiate**\ (\ agent\: ``Node``, blackboard\: :ref:`Blackboard<class_Blackboard>`, instance_owner\: ``Node``\ ) |const| :ref:`🔗<class_BehaviorTree_method_instantiate>` :ref:`BTInstance<class_BTInstance>` **instantiate**\ (\ agent\: ``Node``, blackboard\: :ref:`Blackboard<class_Blackboard>`, instance_owner\: ``Node``\ ) |const| :ref:`🔗<class_BehaviorTree_method_instantiate>`
Instantiates the behavior tree and returns :ref:`BTInstance<class_BTInstance>`. Instantiates the behavior tree and returns :ref:`BTInstance<class_BTInstance>`. ``instance_owner`` should be the scene node that will own the behavior tree instance. This is typically a :ref:`BTPlayer<class_BTPlayer>`, :ref:`BTState<class_BTState>`, or a custom player node that controls the behavior tree execution.
\ ``instance_owner`` should be the scene node that will own the behavior tree instance.
This is typically a :ref:`BTPlayer<class_BTPlayer>`, :ref:`BTState<class_BTState>`, or a custom player node that controls the behavior tree execution.
.. rst-class:: classref-item-separator .. rst-class:: classref-item-separator

View File

@ -12,9 +12,14 @@ BTInstance
**Inherits:** **Inherits:**
.. container:: contribute Represents a runtime instance of a :ref:`BehaviorTree<class_BehaviorTree>` resource.
There is currently no description for this class. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`! .. rst-class:: classref-introduction-group
Description
-----------
Can be created using the :ref:`BehaviorTree.instantiate<class_BehaviorTree_method_instantiate>` method.
.. rst-class:: classref-reftable-group .. rst-class:: classref-reftable-group
@ -178,11 +183,7 @@ Registers the behavior tree instance with the debugger.
|void| **unregister_with_debugger**\ (\ ) :ref:`🔗<class_BTInstance_method_unregister_with_debugger>` |void| **unregister_with_debugger**\ (\ ) :ref:`🔗<class_BTInstance_method_unregister_with_debugger>`
Unregisters the behavior tree instance from the debugger. This is typically Unregisters the behavior tree instance from the debugger. This is typically not necessary, as the debugger will automatically unregister the instance when it is freed.
not necessary, as the debugger will automatically unregister the instance
when it is freed.
.. rst-class:: classref-item-separator .. rst-class:: classref-item-separator

View File

@ -78,6 +78,8 @@ Signals
**behavior_tree_finished**\ (\ status\: ``int``\ ) :ref:`🔗<class_BTPlayer_signal_behavior_tree_finished>` **behavior_tree_finished**\ (\ status\: ``int``\ ) :ref:`🔗<class_BTPlayer_signal_behavior_tree_finished>`
**Deprecated:** Use :ref:`updated<class_BTPlayer_signal_updated>` signal instead.
Emitted when the behavior tree has finished executing and returned ``SUCCESS`` or ``FAILURE``. Emitted when the behavior tree has finished executing and returned ``SUCCESS`` or ``FAILURE``.
Argument ``status`` holds the status returned by the behavior tree. See :ref:`Status<enum_BT_Status>`. Argument ``status`` holds the status returned by the behavior tree. See :ref:`Status<enum_BT_Status>`.

View File

@ -54,7 +54,7 @@
</member> </member>
</members> </members>
<signals> <signals>
<signal name="behavior_tree_finished"> <signal name="behavior_tree_finished" deprecated="Use [signal updated] signal instead.">
<param index="0" name="status" type="int" /> <param index="0" name="status" type="int" />
<description> <description>
Emitted when the behavior tree has finished executing and returned [code]SUCCESS[/code] or [code]FAILURE[/code]. Emitted when the behavior tree has finished executing and returned [code]SUCCESS[/code] or [code]FAILURE[/code].