Use `scene_root` with `BBParam`
This commit is contained in:
parent
5dff2e537b
commit
506d8aa967
|
@ -20,9 +20,9 @@
|
|||
#include <godot_cpp/classes/node.hpp>
|
||||
#endif // LIMBOAI_GDEXTENSION
|
||||
|
||||
Variant BBNode::get_value(Object *p_agent, const Ref<Blackboard> &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<Blackboard> &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<Blackboard> &p_blackboard,
|
|||
}
|
||||
|
||||
if (val.get_type() == Variant::NODE_PATH) {
|
||||
Node *agent = Object::cast_to<Node>(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)) {
|
||||
|
|
|
@ -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<Blackboard> &p_blackboard, const Variant &p_default = Variant()) override;
|
||||
virtual Variant get_value(Node *p_scene_root, const Ref<Blackboard> &p_blackboard, const Variant &p_default = Variant()) override;
|
||||
};
|
||||
|
||||
#endif // BB_NODE_H
|
||||
|
|
|
@ -75,7 +75,7 @@ String BBParam::_to_string() {
|
|||
}
|
||||
}
|
||||
|
||||
Variant BBParam::get_value(Object *p_agent, const Ref<Blackboard> &p_blackboard, const Variant &p_default) {
|
||||
Variant BBParam::get_value(Node *p_scene_root, const Ref<Blackboard> &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");
|
||||
|
|
|
@ -66,7 +66,7 @@ public:
|
|||
virtual String _to_string();
|
||||
#endif
|
||||
|
||||
virtual Variant get_value(Object *p_agent, const Ref<Blackboard> &p_blackboard, const Variant &p_default = Variant());
|
||||
virtual Variant get_value(Node *p_scene_root, const Ref<Blackboard> &p_blackboard, const Variant &p_default = Variant());
|
||||
|
||||
BBParam();
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<AnimationPlayer>(animation_player_param->get_value(get_agent(), get_blackboard()));
|
||||
animation_player = Object::cast_to<AnimationPlayer>(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));
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<AnimationPlayer>(animation_player_param->get_value(get_agent(), get_blackboard()));
|
||||
animation_player = Object::cast_to<AnimationPlayer>(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;
|
||||
}
|
||||
|
|
|
@ -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<AnimationPlayer>(animation_player_param->get_value(get_agent(), get_blackboard()));
|
||||
animation_player = Object::cast_to<AnimationPlayer>(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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<AnimationPlayer>(animation_player_param->get_value(get_agent(), get_blackboard()));
|
||||
animation_player = Object::cast_to<AnimationPlayer>(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));
|
||||
|
|
|
@ -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<BBVariant> 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<BBVariant> 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...
|
||||
|
|
|
@ -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<BBVariant> &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);
|
||||
|
|
Loading…
Reference in New Issue