Access node parameter values directly instead of keeping a copy in SyncedAnimationGraph.
This commit is contained in:
parent
1fca7cfe88
commit
810c6bd9d7
@ -38,15 +38,10 @@ void SyncedAnimationGraph::_update_properties_for_node(const String &p_base_path
|
|||||||
for (PropertyInfo &pinfo : plist) {
|
for (PropertyInfo &pinfo : plist) {
|
||||||
StringName key = pinfo.name;
|
StringName key = pinfo.name;
|
||||||
|
|
||||||
if (!property_map.has(p_base_path + key)) {
|
if (!parameter_to_node_parameter_map.has(p_base_path + key)) {
|
||||||
Pair<Variant, bool> param;
|
parameter_to_node_parameter_map[p_base_path + key] = Pair<Ref<SyncedAnimationNode>, StringName>(p_node, key);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
property_node_map[p_base_path + key] = Pair<Ref<SyncedAnimationNode>, StringName>(p_node, key);
|
|
||||||
|
|
||||||
pinfo.name = p_base_path + key;
|
pinfo.name = p_base_path + key;
|
||||||
properties.push_back(pinfo);
|
properties.push_back(pinfo);
|
||||||
}
|
}
|
||||||
@ -65,8 +60,7 @@ void SyncedAnimationGraph::_update_properties() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
properties.clear();
|
properties.clear();
|
||||||
property_map.clear();
|
parameter_to_node_parameter_map.clear();
|
||||||
property_node_map.clear();
|
|
||||||
|
|
||||||
if (root_animation_node.is_valid()) {
|
if (root_animation_node.is_valid()) {
|
||||||
_update_properties_for_node(Animation::PARAMETERS_BASE_PATH, root_animation_node);
|
_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();
|
_update_properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property_map.has(p_name)) {
|
if (parameter_to_node_parameter_map.has(p_name)) {
|
||||||
if (is_inside_tree() && property_map[p_name].second) {
|
const Pair<Ref<SyncedAnimationNode>, StringName> &property_node = parameter_to_node_parameter_map[p_name];
|
||||||
return false; // Prevent to set property by user.
|
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...
|
property_node.first->set_parameter(property_node.second, p_value);
|
||||||
prop.first = value;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,8 +108,13 @@ bool SyncedAnimationGraph::_get(const StringName &p_name, Variant &r_ret) const
|
|||||||
_update_properties();
|
_update_properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property_map.has(p_name)) {
|
if (parameter_to_node_parameter_map.has(p_name)) {
|
||||||
r_ret = property_map[p_name].first;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,8 +19,7 @@ private:
|
|||||||
AnimationData graph_output;
|
AnimationData graph_output;
|
||||||
|
|
||||||
mutable List<PropertyInfo> properties;
|
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>> parameter_to_node_parameter_map;
|
||||||
mutable AHashMap<StringName, Pair<Ref<SyncedAnimationNode>, StringName>> property_node_map;
|
|
||||||
|
|
||||||
mutable bool properties_dirty = true;
|
mutable bool properties_dirty = true;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user