From 506d8aa967cfa73b50ca7ad05d74a3ffe7f41c43 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Wed, 1 May 2024 23:32:44 +0200 Subject: [PATCH] Use `scene_root` with `BBParam` --- blackboard/bb_param/bb_node.cpp | 10 ++++------ blackboard/bb_param/bb_node.h | 2 +- blackboard/bb_param/bb_param.cpp | 4 ++-- blackboard/bb_param/bb_param.h | 2 +- bt/tasks/blackboard/bt_check_var.cpp | 2 +- bt/tasks/blackboard/bt_set_var.cpp | 2 +- bt/tasks/scene/bt_await_animation.cpp | 2 +- bt/tasks/scene/bt_check_agent_property.cpp | 2 +- bt/tasks/scene/bt_pause_animation.cpp | 2 +- bt/tasks/scene/bt_play_animation.cpp | 2 +- bt/tasks/scene/bt_set_agent_property.cpp | 2 +- bt/tasks/scene/bt_stop_animation.cpp | 2 +- bt/tasks/utility/bt_call_method.cpp | 6 +++--- bt/tasks/utility/bt_evaluate_expression.cpp | 4 ++-- 14 files changed, 21 insertions(+), 23 deletions(-) diff --git a/blackboard/bb_param/bb_node.cpp b/blackboard/bb_param/bb_node.cpp index 3110712..d305f4b 100644 --- a/blackboard/bb_param/bb_node.cpp +++ b/blackboard/bb_param/bb_node.cpp @@ -20,9 +20,9 @@ #include #endif // LIMBOAI_GDEXTENSION -Variant BBNode::get_value(Object *p_agent, const Ref &p_blackboard, const Variant &p_default) { - ERR_FAIL_COND_V(p_agent == nullptr, Variant()); - ERR_FAIL_COND_V(!p_blackboard.is_valid(), Variant()); +Variant BBNode::get_value(Node *p_scene_root, const Ref &p_blackboard, const Variant &p_default) { + ERR_FAIL_NULL_V_MSG(p_scene_root, Variant(), "BBNode: get_value() failed - scene_root is null."); + ERR_FAIL_NULL_V_MSG(p_blackboard, Variant(), "BBNode: get_value() failed - blackboard is null."); Variant val; if (get_value_source() == SAVED_VALUE) { @@ -32,9 +32,7 @@ Variant BBNode::get_value(Object *p_agent, const Ref &p_blackboard, } if (val.get_type() == Variant::NODE_PATH) { - Node *agent = Object::cast_to(p_agent); - ERR_FAIL_COND_V_MSG(agent == nullptr, Variant(), "BBNode: p_agent must be a Node."); - return agent->get_node_or_null(val); + return p_scene_root->get_node_or_null(val); } else { Object *obj = val; if (unlikely(obj == nullptr && val.get_type() != Variant::NIL)) { diff --git a/blackboard/bb_param/bb_node.h b/blackboard/bb_param/bb_node.h index e6db0c8..ce6c0ee 100644 --- a/blackboard/bb_param/bb_node.h +++ b/blackboard/bb_param/bb_node.h @@ -21,7 +21,7 @@ protected: virtual Variant::Type get_type() const override { return Variant::NODE_PATH; } public: - virtual Variant get_value(Object *p_agent, const Ref &p_blackboard, const Variant &p_default = Variant()) override; + virtual Variant get_value(Node *p_scene_root, const Ref &p_blackboard, const Variant &p_default = Variant()) override; }; #endif // BB_NODE_H diff --git a/blackboard/bb_param/bb_param.cpp b/blackboard/bb_param/bb_param.cpp index 88ad5e7..c5308c1 100644 --- a/blackboard/bb_param/bb_param.cpp +++ b/blackboard/bb_param/bb_param.cpp @@ -75,7 +75,7 @@ String BBParam::_to_string() { } } -Variant BBParam::get_value(Object *p_agent, const Ref &p_blackboard, const Variant &p_default) { +Variant BBParam::get_value(Node *p_scene_root, const Ref &p_blackboard, const Variant &p_default) { ERR_FAIL_COND_V(!p_blackboard.is_valid(), p_default); if (value_source == SAVED_VALUE) { @@ -105,7 +105,7 @@ void BBParam::_bind_methods() { ClassDB::bind_method(D_METHOD("set_variable", "variable_name"), &BBParam::set_variable); ClassDB::bind_method(D_METHOD("get_variable"), &BBParam::get_variable); ClassDB::bind_method(D_METHOD("get_type"), &BBParam::get_type); - ClassDB::bind_method(D_METHOD("get_value", "agent", "blackboard", "default"), &BBParam::get_value, Variant()); + ClassDB::bind_method(D_METHOD("get_value", "scene_root", "blackboard", "default"), &BBParam::get_value, Variant()); ADD_PROPERTY(PropertyInfo(Variant::INT, "value_source", PROPERTY_HINT_ENUM, "Saved Value,Blackboard Var"), "set_value_source", "get_value_source"); ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "variable", PROPERTY_HINT_NONE, "", 0), "set_variable", "get_variable"); diff --git a/blackboard/bb_param/bb_param.h b/blackboard/bb_param/bb_param.h index 7d75884..98a96cb 100644 --- a/blackboard/bb_param/bb_param.h +++ b/blackboard/bb_param/bb_param.h @@ -66,7 +66,7 @@ public: virtual String _to_string(); #endif - virtual Variant get_value(Object *p_agent, const Ref &p_blackboard, const Variant &p_default = Variant()); + virtual Variant get_value(Node *p_scene_root, const Ref &p_blackboard, const Variant &p_default = Variant()); BBParam(); }; diff --git a/bt/tasks/blackboard/bt_check_var.cpp b/bt/tasks/blackboard/bt_check_var.cpp index 96ea05e..14962dc 100644 --- a/bt/tasks/blackboard/bt_check_var.cpp +++ b/bt/tasks/blackboard/bt_check_var.cpp @@ -57,7 +57,7 @@ BT::Status BTCheckVar::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(!get_blackboard()->has_var(variable), FAILURE, vformat("BTCheckVar: Blackboard variable doesn't exist: \"%s\". Returning FAILURE.", variable)); Variant left_value = get_blackboard()->get_var(variable, Variant()); - Variant right_value = value->get_value(get_agent(), get_blackboard()); + Variant right_value = value->get_value(get_scene_root(), get_blackboard()); return LimboUtility::get_singleton()->perform_check(check_type, left_value, right_value) ? SUCCESS : FAILURE; } diff --git a/bt/tasks/blackboard/bt_set_var.cpp b/bt/tasks/blackboard/bt_set_var.cpp index 67adef5..4b44d1d 100644 --- a/bt/tasks/blackboard/bt_set_var.cpp +++ b/bt/tasks/blackboard/bt_set_var.cpp @@ -26,7 +26,7 @@ BT::Status BTSetVar::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(!value.is_valid(), FAILURE, "BTSetVar: `value` is not set."); Variant result; Variant error_result = LW_NAME(error_value); - Variant right_value = value->get_value(get_agent(), get_blackboard(), error_result); + Variant right_value = value->get_value(get_scene_root(), get_blackboard(), error_result); ERR_FAIL_COND_V_MSG(right_value == error_result, FAILURE, "BTSetVar: Failed to get parameter value. Returning FAILURE."); if (operation == LimboUtility::OPERATION_NONE) { result = right_value; diff --git a/bt/tasks/scene/bt_await_animation.cpp b/bt/tasks/scene/bt_await_animation.cpp index 67cee8e..a511cdf 100644 --- a/bt/tasks/scene/bt_await_animation.cpp +++ b/bt/tasks/scene/bt_await_animation.cpp @@ -62,7 +62,7 @@ String BTAwaitAnimation::_generate_name() { void BTAwaitAnimation::_setup() { setup_failed = true; ERR_FAIL_COND_MSG(animation_player_param.is_null(), "BTAwaitAnimation: AnimationPlayer parameter is not set."); - animation_player = Object::cast_to(animation_player_param->get_value(get_agent(), get_blackboard())); + animation_player = Object::cast_to(animation_player_param->get_value(get_scene_root(), get_blackboard())); ERR_FAIL_COND_MSG(animation_player == nullptr, "BTAwaitAnimation: Failed to get AnimationPlayer."); ERR_FAIL_COND_MSG(animation_name == StringName(), "BTAwaitAnimation: Animation Name is not set."); ERR_FAIL_COND_MSG(!animation_player->has_animation(animation_name), vformat("BTAwaitAnimation: Animation not found: %s", animation_name)); diff --git a/bt/tasks/scene/bt_check_agent_property.cpp b/bt/tasks/scene/bt_check_agent_property.cpp index 31e4c4b..7ac0c4d 100644 --- a/bt/tasks/scene/bt_check_agent_property.cpp +++ b/bt/tasks/scene/bt_check_agent_property.cpp @@ -62,7 +62,7 @@ BT::Status BTCheckAgentProperty::_tick(double p_delta) { Variant left_value = get_agent()->get(property); #endif - Variant right_value = value->get_value(get_agent(), get_blackboard()); + Variant right_value = value->get_value(get_scene_root(), get_blackboard()); return LimboUtility::get_singleton()->perform_check(check_type, left_value, right_value) ? SUCCESS : FAILURE; } diff --git a/bt/tasks/scene/bt_pause_animation.cpp b/bt/tasks/scene/bt_pause_animation.cpp index 86e3958..4f1dd3c 100644 --- a/bt/tasks/scene/bt_pause_animation.cpp +++ b/bt/tasks/scene/bt_pause_animation.cpp @@ -44,7 +44,7 @@ String BTPauseAnimation::_generate_name() { void BTPauseAnimation::_setup() { setup_failed = true; ERR_FAIL_COND_MSG(animation_player_param.is_null(), "BTPauseAnimation: AnimationPlayer parameter is not set."); - animation_player = Object::cast_to(animation_player_param->get_value(get_agent(), get_blackboard())); + animation_player = Object::cast_to(animation_player_param->get_value(get_scene_root(), get_blackboard())); ERR_FAIL_COND_MSG(animation_player == nullptr, "BTPauseAnimation: Failed to get AnimationPlayer."); setup_failed = false; } diff --git a/bt/tasks/scene/bt_play_animation.cpp b/bt/tasks/scene/bt_play_animation.cpp index e2de77d..f373e5f 100644 --- a/bt/tasks/scene/bt_play_animation.cpp +++ b/bt/tasks/scene/bt_play_animation.cpp @@ -77,7 +77,7 @@ String BTPlayAnimation::_generate_name() { void BTPlayAnimation::_setup() { setup_failed = true; ERR_FAIL_COND_MSG(animation_player_param.is_null(), "BTPlayAnimation: AnimationPlayer parameter is not set."); - animation_player = Object::cast_to(animation_player_param->get_value(get_agent(), get_blackboard())); + animation_player = Object::cast_to(animation_player_param->get_value(get_scene_root(), get_blackboard())); ERR_FAIL_COND_MSG(animation_player == nullptr, "BTPlayAnimation: Failed to get AnimationPlayer."); ERR_FAIL_COND_MSG(animation_name != StringName() && !animation_player->has_animation(animation_name), vformat("BTPlayAnimation: Animation not found: %s", animation_name)); if (animation_name == StringName() && await_completion > 0.0) { diff --git a/bt/tasks/scene/bt_set_agent_property.cpp b/bt/tasks/scene/bt_set_agent_property.cpp index f104a98..600e138 100644 --- a/bt/tasks/scene/bt_set_agent_property.cpp +++ b/bt/tasks/scene/bt_set_agent_property.cpp @@ -55,7 +55,7 @@ BT::Status BTSetAgentProperty::_tick(double p_delta) { Variant result; StringName error_value = LW_NAME(error_value); - Variant right_value = value->get_value(get_agent(), get_blackboard(), error_value); + Variant right_value = value->get_value(get_scene_root(), get_blackboard(), error_value); ERR_FAIL_COND_V_MSG(right_value == Variant(error_value), FAILURE, "BTSetAgentProperty: Couldn't get value of value-parameter."); bool r_valid; if (operation == LimboUtility::OPERATION_NONE) { diff --git a/bt/tasks/scene/bt_stop_animation.cpp b/bt/tasks/scene/bt_stop_animation.cpp index 20e7f41..0bc247b 100644 --- a/bt/tasks/scene/bt_stop_animation.cpp +++ b/bt/tasks/scene/bt_stop_animation.cpp @@ -56,7 +56,7 @@ String BTStopAnimation::_generate_name() { void BTStopAnimation::_setup() { setup_failed = true; ERR_FAIL_COND_MSG(animation_player_param.is_null(), "BTStopAnimation: AnimationPlayer parameter is not set."); - animation_player = Object::cast_to(animation_player_param->get_value(get_agent(), get_blackboard())); + animation_player = Object::cast_to(animation_player_param->get_value(get_scene_root(), get_blackboard())); ERR_FAIL_COND_MSG(animation_player == nullptr, "BTStopAnimation: Failed to get AnimationPlayer."); if (animation_name != StringName()) { ERR_FAIL_COND_MSG(!animation_player->has_animation(animation_name), vformat("BTStopAnimation: Animation not found: %s", animation_name)); diff --git a/bt/tasks/utility/bt_call_method.cpp b/bt/tasks/utility/bt_call_method.cpp index 0d3f36d..f559d2e 100644 --- a/bt/tasks/utility/bt_call_method.cpp +++ b/bt/tasks/utility/bt_call_method.cpp @@ -83,7 +83,7 @@ String BTCallMethod::_generate_name() { BT::Status BTCallMethod::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(method == StringName(), FAILURE, "BTCallMethod: Method Name is not set."); ERR_FAIL_COND_V_MSG(node_param.is_null(), FAILURE, "BTCallMethod: Node parameter is not set."); - Object *obj = node_param->get_value(get_agent(), get_blackboard()); + Object *obj = node_param->get_value(get_scene_root(), get_blackboard()); ERR_FAIL_COND_V_MSG(obj == nullptr, FAILURE, "BTCallMethod: Failed to get object: " + node_param->to_string()); Variant result; @@ -101,7 +101,7 @@ BT::Status BTCallMethod::_tick(double p_delta) { } for (int i = 0; i < args.size(); i++) { Ref param = args[i]; - call_args.push_back(param->get_value(get_agent(), get_blackboard())); + call_args.push_back(param->get_value(get_scene_root(), get_blackboard())); argptrs[i + int(include_delta)] = &call_args[i]; } } @@ -117,7 +117,7 @@ BT::Status BTCallMethod::_tick(double p_delta) { } for (int i = 0; i < args.size(); i++) { Ref param = args[i]; - call_args.push_back(param->get_value(get_agent(), get_blackboard())); + call_args.push_back(param->get_value(get_scene_root(), get_blackboard())); } // TODO: Unsure how to detect call error, so we return SUCCESS for now... diff --git a/bt/tasks/utility/bt_evaluate_expression.cpp b/bt/tasks/utility/bt_evaluate_expression.cpp index bea39dc..b6ab59b 100644 --- a/bt/tasks/utility/bt_evaluate_expression.cpp +++ b/bt/tasks/utility/bt_evaluate_expression.cpp @@ -107,7 +107,7 @@ String BTEvaluateExpression::_generate_name() { BT::Status BTEvaluateExpression::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(expression_string.is_empty(), FAILURE, "BTEvaluateExpression: Expression String is not set."); ERR_FAIL_COND_V_MSG(node_param.is_null(), FAILURE, "BTEvaluateExpression: Node parameter is not set."); - Object *obj = node_param->get_value(get_agent(), get_blackboard()); + Object *obj = node_param->get_value(get_scene_root(), get_blackboard()); ERR_FAIL_COND_V_MSG(obj == nullptr, FAILURE, "BTEvaluateExpression: Failed to get object: " + node_param->to_string()); ERR_FAIL_COND_V_MSG(is_parsed != Error::OK, FAILURE, "BTEvaluateExpression: Failed to parse expression: " + expression.get_error_text()); @@ -116,7 +116,7 @@ BT::Status BTEvaluateExpression::_tick(double p_delta) { } for (int i = 0; i < input_values.size(); ++i) { const Ref &bb_variant = input_values[i]; - processed_input_values[i + int(input_include_delta)] = bb_variant->get_value(get_agent(), get_blackboard()); + processed_input_values[i + int(input_include_delta)] = bb_variant->get_value(get_scene_root(), get_blackboard()); } Variant result = expression.execute(processed_input_values, obj, false);