Access node parameter values directly instead of keeping a copy in SyncedAnimationGraph.

This commit is contained in:
Martin Felis 2025-12-31 16:39:29 +01:00
parent 1fca7cfe88
commit 810c6bd9d7
2 changed files with 17 additions and 28 deletions

View File

@ -38,15 +38,10 @@ void SyncedAnimationGraph::_update_properties_for_node(const String &p_base_path
for (PropertyInfo &pinfo : plist) {
StringName key = pinfo.name;
if (!property_map.has(p_base_path + key)) {
Pair<Variant, bool> param;
param.first = p_node->get_parameter_default_value(key);
param.second = p_node->is_parameter_read_only(key);
property_map[p_base_path + key] = param;
if (!parameter_to_node_parameter_map.has(p_base_path + key)) {
parameter_to_node_parameter_map[p_base_path + key] = Pair<Ref<SyncedAnimationNode>, StringName>(p_node, key);
}
property_node_map[p_base_path + key] = Pair<Ref<SyncedAnimationNode>, StringName>(p_node, key);
pinfo.name = p_base_path + key;
properties.push_back(pinfo);
}
@ -65,8 +60,7 @@ void SyncedAnimationGraph::_update_properties() const {
}
properties.clear();
property_map.clear();
property_node_map.clear();
parameter_to_node_parameter_map.clear();
if (root_animation_node.is_valid()) {
_update_properties_for_node(Animation::PARAMETERS_BASE_PATH, root_animation_node);
@ -89,23 +83,14 @@ bool SyncedAnimationGraph::_set(const StringName &p_name, const Variant &p_value
_update_properties();
}
if (property_map.has(p_name)) {
if (is_inside_tree() && property_map[p_name].second) {
return false; // Prevent to set property by user.
if (parameter_to_node_parameter_map.has(p_name)) {
const Pair<Ref<SyncedAnimationNode>, StringName> &property_node = parameter_to_node_parameter_map[p_name];
if (!property_node.first.is_valid()) {
print_error(vformat("Cannot set property '%s' node not found.", p_name));
return false;
}
Pair<Variant, bool> &prop = property_map[p_name];
Variant value = p_value;
if (Animation::validate_type_match(prop.first, value)) {
Pair<Ref<SyncedAnimationNode>, StringName> property_node = property_node_map[p_name];
if (!property_node.first.is_valid()) {
print_error(vformat("Cannot set property '%s' node not found.", p_name));
return false;
}
property_node.first->set_parameter(property_node.second, value);
// also set value in the graph's copy of the value. Should probably be removed at some point...
prop.first = value;
}
property_node.first->set_parameter(property_node.second, p_value);
return true;
}
@ -123,8 +108,13 @@ bool SyncedAnimationGraph::_get(const StringName &p_name, Variant &r_ret) const
_update_properties();
}
if (property_map.has(p_name)) {
r_ret = property_map[p_name].first;
if (parameter_to_node_parameter_map.has(p_name)) {
const Pair<Ref<SyncedAnimationNode>, StringName> &property_node = parameter_to_node_parameter_map[p_name];
if (!property_node.first.is_valid()) {
print_error(vformat("Cannot get property '%s' node not found.", p_name));
return false;
}
r_ret = property_node.first->get_parameter(property_node.second);
return true;
}

View File

@ -19,8 +19,7 @@ private:
AnimationData graph_output;
mutable List<PropertyInfo> properties;
mutable AHashMap<StringName, Pair<Variant, bool>> property_map; // Property value and read-only flag.
mutable AHashMap<StringName, Pair<Ref<SyncedAnimationNode>, StringName>> property_node_map;
mutable AHashMap<StringName, Pair<Ref<SyncedAnimationNode>, StringName>> parameter_to_node_parameter_map;
mutable bool properties_dirty = true;