Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BlackboardPlan arrays shouldn't be shared between instanced agents #158

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions blackboard/bb_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,16 @@ String BBVariable::get_hint_string() const {
return data->hint_string;
}

BBVariable BBVariable::duplicate() const {
BBVariable BBVariable::duplicate(bool p_deep) const {
BBVariable var;
var.data->hint = data->hint;
var.data->hint_string = data->hint_string;
var.data->type = data->type;
var.data->value = data->value;
if (p_deep) {
var.data->value = data->value.duplicate(p_deep);
} else {
var.data->value = data->value;
}
var.data->binding_path = data->binding_path;
var.data->bound_object = data->bound_object;
var.data->bound_property = data->bound_property;
Expand Down
2 changes: 1 addition & 1 deletion blackboard/bb_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class BBVariable {
void set_hint_string(const String &p_hint_string);
String get_hint_string() const;

BBVariable duplicate() const;
BBVariable duplicate(bool p_deep = false) const;

_FORCE_INLINE_ bool is_value_changed() const { return data->value_changed; }
_FORCE_INLINE_ void reset_value_changed() { data->value_changed = false; }
Expand Down
4 changes: 2 additions & 2 deletions blackboard/blackboard_plan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ void BlackboardPlan::sync_with_base_plan() {
inline void bb_add_var_dup_with_prefetch(const Ref<Blackboard> &p_blackboard, const StringName &p_name, const BBVariable &p_var, bool p_prefetch, Node *p_node) {
if (unlikely(p_prefetch && p_var.get_type() == Variant::NODE_PATH)) {
Node *n = p_node->get_node_or_null(p_var.get_value());
BBVariable var = p_var.duplicate();
BBVariable var = p_var.duplicate(true);
if (n != nullptr) {
var.set_value(n);
} else {
Expand All @@ -404,7 +404,7 @@ inline void bb_add_var_dup_with_prefetch(const Ref<Blackboard> &p_blackboard, co
}
p_blackboard->assign_var(p_name, var);
} else {
p_blackboard->assign_var(p_name, p_var.duplicate());
p_blackboard->assign_var(p_name, p_var.duplicate(true));
}
}

Expand Down
Loading