Improve prefetching

This commit is contained in:
Serhii Snitsaruk 2024-03-12 00:30:38 +01:00
parent 7de582c4e6
commit a6e6b53e18
3 changed files with 9 additions and 8 deletions

View File

@ -74,8 +74,7 @@ void Blackboard::unbind_var(const StringName &p_name) {
data[p_name].unbind(); data[p_name].unbind();
} }
void Blackboard::add_var(const StringName &p_name, const BBVariable &p_var) { void Blackboard::assign_var(const StringName &p_name, const BBVariable &p_var) {
ERR_FAIL_COND(data.has(p_name));
data.insert(p_name, p_var); data.insert(p_name, p_var);
} }

View File

@ -54,7 +54,7 @@ public:
void bind_var_to_property(const StringName &p_name, Object *p_object, const StringName &p_property); void bind_var_to_property(const StringName &p_name, Object *p_object, const StringName &p_property);
void unbind_var(const StringName &p_name); void unbind_var(const StringName &p_name);
void add_var(const StringName &p_name, const BBVariable &p_var); void assign_var(const StringName &p_name, const BBVariable &p_var);
// TODO: Add serialization API. // TODO: Add serialization API.
}; };

View File

@ -284,14 +284,16 @@ inline void bb_add_var_dup_with_prefetch(const Ref<Blackboard> &p_blackboard, co
if (n != nullptr) { if (n != nullptr) {
var.set_value(n); var.set_value(n);
} else { } else {
// Print error only if the variable is not present (it can be initialized by the user or in the parent scope). if (p_blackboard->has_var(p_name)) {
if (!p_blackboard->has_var(p_name)) { // Not adding: Assuming variable was initialized by the user or in the parent scope.
return;
}
ERR_PRINT(vformat("BlackboardPlan: Prefetch failed for variable $%s with value: %s", p_name, p_var.get_value())); ERR_PRINT(vformat("BlackboardPlan: Prefetch failed for variable $%s with value: %s", p_name, p_var.get_value()));
var.set_value(Variant());
} }
} p_blackboard->assign_var(p_name, var);
p_blackboard->add_var(p_name, var);
} else { } else {
p_blackboard->add_var(p_name, p_var.duplicate()); p_blackboard->assign_var(p_name, p_var.duplicate());
} }
} }