diff --git a/bt/bt_state.cpp b/bt/bt_state.cpp index 9620687..e482e27 100644 --- a/bt/bt_state.cpp +++ b/bt/bt_state.cpp @@ -37,6 +37,16 @@ void BTState::set_behavior_tree(const Ref &p_tree) { _update_blackboard_plan(); } +#ifdef DEBUG_ENABLED +void BTState::_set_monitor_performance(bool p_monitor) { + monitor_performance = p_monitor; + + if (bt_instance.is_valid()) { + bt_instance->set_monitor_performance(monitor_performance); + } +} +#endif // DEBUG_ENABLED + void BTState::_update_blackboard_plan() { if (get_blackboard_plan().is_null()) { set_blackboard_plan(memnew(BlackboardPlan)); @@ -58,6 +68,7 @@ void BTState::_setup() { #ifdef DEBUG_ENABLED bt_instance->register_with_debugger(); + bt_instance->set_monitor_performance(monitor_performance); #endif } @@ -92,6 +103,7 @@ void BTState::_notification(int p_notification) { case NOTIFICATION_ENTER_TREE: { if (bt_instance.is_valid()) { bt_instance->register_with_debugger(); + bt_instance->set_monitor_performance(monitor_performance); } } break; #endif // DEBUG_ENABLED @@ -99,7 +111,9 @@ void BTState::_notification(int p_notification) { #ifdef DEBUG_ENABLED if (bt_instance.is_valid()) { bt_instance->unregister_with_debugger(); + bt_instance->set_monitor_performance(false); } + #endif // DEBUG_ENABLED if (Engine::get_singleton()->is_editor_hint()) { @@ -126,6 +140,12 @@ void BTState::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "behavior_tree", PROPERTY_HINT_RESOURCE_TYPE, "BehaviorTree"), "set_behavior_tree", "get_behavior_tree"); ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "success_event"), "set_success_event", "get_success_event"); ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "failure_event"), "set_failure_event", "get_failure_event"); + +#ifdef DEBUG_ENABLED + ClassDB::bind_method(D_METHOD("_set_monitor_performance", "enable"), &BTState::_set_monitor_performance); + ClassDB::bind_method(D_METHOD("_get_monitor_performance"), &BTState::_get_monitor_performance); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "monitor_performance"), "_set_monitor_performance", "_get_monitor_performance"); +#endif // DEBUG_ENABLED } BTState::BTState() { diff --git a/bt/bt_state.h b/bt/bt_state.h index 94b1c4f..f601917 100644 --- a/bt/bt_state.h +++ b/bt/bt_state.h @@ -51,6 +51,14 @@ public: StringName get_failure_event() const { return failure_event; } BTState(); + +#ifdef DEBUG_ENABLED +private: + bool monitor_performance = false; + + void _set_monitor_performance(bool p_monitor); + bool _get_monitor_performance() const { return monitor_performance; } +#endif }; #endif // BT_STATE_H diff --git a/doc/source/classes/class_btstate.rst b/doc/source/classes/class_btstate.rst index dd6c5fd..c72c2a3 100644 --- a/doc/source/classes/class_btstate.rst +++ b/doc/source/classes/class_btstate.rst @@ -29,13 +29,15 @@ Properties .. table:: :widths: auto - +-----------------------------------------+------------------------------------------------------------+----------------+ - | :ref:`BehaviorTree` | :ref:`behavior_tree` | | - +-----------------------------------------+------------------------------------------------------------+----------------+ - | ``StringName`` | :ref:`failure_event` | ``&"failure"`` | - +-----------------------------------------+------------------------------------------------------------+----------------+ - | ``StringName`` | :ref:`success_event` | ``&"success"`` | - +-----------------------------------------+------------------------------------------------------------+----------------+ + +-----------------------------------------+------------------------------------------------------------------------+----------------+ + | :ref:`BehaviorTree` | :ref:`behavior_tree` | | + +-----------------------------------------+------------------------------------------------------------------------+----------------+ + | ``StringName`` | :ref:`failure_event` | ``&"failure"`` | + +-----------------------------------------+------------------------------------------------------------------------+----------------+ + | ``bool`` | :ref:`monitor_performance` | ``false`` | + +-----------------------------------------+------------------------------------------------------------------------+----------------+ + | ``StringName`` | :ref:`success_event` | ``&"success"`` | + +-----------------------------------------+------------------------------------------------------------------------+----------------+ .. rst-class:: classref-reftable-group @@ -92,6 +94,18 @@ HSM event that will be dispatched when the behavior tree results in ``FAILURE``. ---- +.. _class_BTState_property_monitor_performance: + +.. rst-class:: classref-property + +``bool`` **monitor_performance** = ``false`` :ref:`🔗` + +If ``true``, adds a performance monitor to "Debugger->Monitors" for each instance of this **BTState** node. + +.. rst-class:: classref-item-separator + +---- + .. _class_BTState_property_success_event: .. rst-class:: classref-property diff --git a/doc_classes/BTState.xml b/doc_classes/BTState.xml index 9824b37..7c72b13 100644 --- a/doc_classes/BTState.xml +++ b/doc_classes/BTState.xml @@ -23,6 +23,9 @@ HSM event that will be dispatched when the behavior tree results in [code]FAILURE[/code]. See [method LimboState.dispatch]. + + If [code]true[/code], adds a performance monitor to "Debugger->Monitors" for each instance of this [BTState] node. + HSM event that will be dispatched when the behavior tree results in [code]SUCCESS[/code]. See [method LimboState.dispatch].