From 8d4078b7b59faaceb9ebf78c705b6253fa7c64fa Mon Sep 17 00:00:00 2001 From: "Silc Lizard (Tokage) Renew" <61938263+TokageItLab@users.noreply.github.com> Date: Tue, 18 Jul 2023 17:39:25 +0900 Subject: [PATCH] Make AnimationNodeBlendTree use OrderedHashMap insteads Map --- scene/animation/animation_blend_tree.cpp | 21 +++++++++------------ scene/animation/animation_blend_tree.h | 3 ++- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp index 5ec707372..8007ebc83 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -849,7 +849,7 @@ Ref AnimationNodeBlendTree::get_node(const StringName &p_name) co } StringName AnimationNodeBlendTree::get_node_name(const Ref &p_node) const { - for (RBMap::Element *E = nodes.front(); E; E = E->next()) { + for (NodeMap::Element *E = nodes.front(); E; E = E->next()) { if (E->get().node == p_node) { return E->key(); } @@ -871,12 +871,10 @@ Vector2 AnimationNodeBlendTree::get_node_position(const StringName &p_node) cons void AnimationNodeBlendTree::get_child_nodes(List *r_child_nodes) { Vector ns; - for (RBMap::Element *E = nodes.front(); E; E = E->next()) { + for (NodeMap::Element *E = nodes.front(); E; E = E->next()) { ns.push_back(E->key()); } - ns.sort_custom(); - for (int i = 0; i < ns.size(); i++) { ChildNode cn; cn.name = ns[i]; @@ -905,7 +903,7 @@ void AnimationNodeBlendTree::remove_node(const StringName &p_name) { nodes.erase(p_name); //erase connections to name - for (RBMap::Element *E = nodes.front(); E; E = E->next()) { + for (NodeMap::Element *E = nodes.front(); E; E = E->next()) { for (int i = 0; i < E->get().connections.size(); i++) { if (E->get().connections[i] == p_name) { E->get().connections.write[i] = StringName(); @@ -929,7 +927,7 @@ void AnimationNodeBlendTree::rename_node(const StringName &p_name, const StringN nodes.erase(p_name); //rename connections - for (RBMap::Element *E = nodes.front(); E; E = E->next()) { + for (NodeMap::Element *E = nodes.front(); E; E = E->next()) { for (int i = 0; i < E->get().connections.size(); i++) { if (E->get().connections[i] == p_name) { E->get().connections.write[i] = p_new_name; @@ -951,7 +949,7 @@ void AnimationNodeBlendTree::connect_node(const StringName &p_input_node, int p_ Ref input = nodes[p_input_node].node; ERR_FAIL_INDEX(p_input_index, nodes[p_input_node].connections.size()); - for (RBMap::Element *E = nodes.front(); E; E = E->next()) { + for (NodeMap::Element *E = nodes.front(); E; E = E->next()) { for (int i = 0; i < E->get().connections.size(); i++) { StringName output = E->get().connections[i]; ERR_FAIL_COND(output == p_output_node); @@ -995,7 +993,7 @@ AnimationNodeBlendTree::ConnectionError AnimationNodeBlendTree::can_connect_node return CONNECTION_ERROR_CONNECTION_EXISTS; } - for (RBMap::Element *E = nodes.front(); E; E = E->next()) { + for (NodeMap::Element *E = nodes.front(); E; E = E->next()) { for (int i = 0; i < E->get().connections.size(); i++) { StringName output = E->get().connections[i]; if (output == p_output_node) { @@ -1007,7 +1005,7 @@ AnimationNodeBlendTree::ConnectionError AnimationNodeBlendTree::can_connect_node } void AnimationNodeBlendTree::get_node_connections(List *r_connections) const { - for (RBMap::Element *E = nodes.front(); E; E = E->next()) { + for (NodeMap::Element *E = nodes.front(); E; E = E->next()) { for (int i = 0; i < E->get().connections.size(); i++) { StringName output = E->get().connections[i]; if (output != StringName()) { @@ -1031,7 +1029,7 @@ float AnimationNodeBlendTree::process(float p_time, bool p_seek) { } void AnimationNodeBlendTree::get_node_list(List *r_list) { - for (RBMap::Element *E = nodes.front(); E; E = E->next()) { + for (NodeMap::Element *E = nodes.front(); E; E = E->next()) { r_list->push_back(E->key()); } } @@ -1122,10 +1120,9 @@ bool AnimationNodeBlendTree::_get(const StringName &p_name, Variant &r_ret) cons } void AnimationNodeBlendTree::_get_property_list(List *p_list) const { List names; - for (RBMap::Element *E = nodes.front(); E; E = E->next()) { + for (NodeMap::Element *E = nodes.front(); E; E = E->next()) { names.push_back(E->key()); } - names.sort_custom(); for (List::Element *E = names.front(); E; E = E->next()) { String name = E->get(); diff --git a/scene/animation/animation_blend_tree.h b/scene/animation/animation_blend_tree.h index edc12d886..a2091f269 100644 --- a/scene/animation/animation_blend_tree.h +++ b/scene/animation/animation_blend_tree.h @@ -338,7 +338,8 @@ class AnimationNodeBlendTree : public AnimationRootNode { Vector connections; }; - RBMap nodes; + typedef RBMap NodeMap; + NodeMap nodes; Vector2 graph_offset;