From 2f9a6636bd3a750e168c2310da27a7401b0af154 Mon Sep 17 00:00:00 2001 From: Yyf2333 <2514537033@qq.com> Date: Tue, 1 Oct 2024 16:27:06 +0800 Subject: [PATCH] Convert Vector to LocalVector in animation system. Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- scene/animation/animation_blend_tree.cpp | 6 ++--- scene/animation/animation_blend_tree.h | 2 +- scene/animation/animation_tree.cpp | 32 ++++++++++++------------ scene/animation/animation_tree.h | 8 +++--- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp index 36cbaaf814d..48ca6710ca9 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -1199,7 +1199,7 @@ bool AnimationNodeTransition::set_input_name(int p_input, const String &p_name) void AnimationNodeTransition::set_input_as_auto_advance(int p_input, bool p_enable) { ERR_FAIL_INDEX(p_input, get_input_count()); - input_data.write[p_input].auto_advance = p_enable; + input_data[p_input].auto_advance = p_enable; } bool AnimationNodeTransition::is_input_set_as_auto_advance(int p_input) const { @@ -1209,7 +1209,7 @@ bool AnimationNodeTransition::is_input_set_as_auto_advance(int p_input) const { void AnimationNodeTransition::set_input_break_loop_at_end(int p_input, bool p_enable) { ERR_FAIL_INDEX(p_input, get_input_count()); - input_data.write[p_input].break_loop_at_end = p_enable; + input_data[p_input].break_loop_at_end = p_enable; } bool AnimationNodeTransition::is_input_loop_broken_at_end(int p_input) const { @@ -1219,7 +1219,7 @@ bool AnimationNodeTransition::is_input_loop_broken_at_end(int p_input) const { void AnimationNodeTransition::set_input_reset(int p_input, bool p_enable) { ERR_FAIL_INDEX(p_input, get_input_count()); - input_data.write[p_input].reset = p_enable; + input_data[p_input].reset = p_enable; } bool AnimationNodeTransition::is_input_reset(int p_input) const { diff --git a/scene/animation/animation_blend_tree.h b/scene/animation/animation_blend_tree.h index 10217e3deb0..0d49d0b2d31 100644 --- a/scene/animation/animation_blend_tree.h +++ b/scene/animation/animation_blend_tree.h @@ -331,7 +331,7 @@ class AnimationNodeTransition : public AnimationNodeSync { bool break_loop_at_end = false; bool reset = true; }; - Vector input_data; + LocalVector input_data; StringName prev_xfading = "prev_xfading"; StringName prev_index = "prev_index"; diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 017b47535a8..3439dcc4765 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -161,7 +161,7 @@ AnimationTree *AnimationNode::get_animation_tree() const { } AnimationNode::NodeTimeInfo AnimationNode::blend_input(int p_input, AnimationMixer::PlaybackInfo p_playback_info, FilterAction p_filter, bool p_sync, bool p_test_only) { - ERR_FAIL_INDEX_V(p_input, inputs.size(), NodeTimeInfo()); + ERR_FAIL_INDEX_V(p_input, (int64_t)inputs.size(), NodeTimeInfo()); AnimationNodeBlendTree *blend_tree = Object::cast_to(node_state.parent); ERR_FAIL_NULL_V(blend_tree, NodeTimeInfo()); @@ -181,12 +181,12 @@ AnimationNode::NodeTimeInfo AnimationNode::blend_input(int p_input, AnimationMix ERR_FAIL_COND_V(node.is_null(), NodeTimeInfo()); real_t activity = 0.0; - Vector *activity_ptr = process_state->tree->input_activity_map.getptr(node_state.base_path); + LocalVector *activity_ptr = process_state->tree->input_activity_map.getptr(node_state.base_path); NodeTimeInfo nti = _blend_node(node, node_name, nullptr, p_playback_info, p_filter, p_sync, p_test_only, &activity); - if (activity_ptr && p_input < activity_ptr->size()) { - activity_ptr->write[p_input].last_pass = process_state->last_pass; - activity_ptr->write[p_input].activity = activity; + if (activity_ptr && p_input < (int64_t)activity_ptr->size()) { + (*activity_ptr)[p_input].last_pass = process_state->last_pass; + (*activity_ptr)[p_input].activity = activity; } return nti; } @@ -202,11 +202,11 @@ AnimationNode::NodeTimeInfo AnimationNode::_blend_node(Ref p_node int blend_count = node_state.track_weights.size(); - if (p_node->node_state.track_weights.size() != blend_count) { + if ((int64_t)p_node->node_state.track_weights.size() != blend_count) { p_node->node_state.track_weights.resize(blend_count); } - real_t *blendw = p_node->node_state.track_weights.ptrw(); + real_t *blendw = p_node->node_state.track_weights.ptr(); const real_t *blendr = node_state.track_weights.ptr(); bool any_valid = false; @@ -333,21 +333,21 @@ bool AnimationNode::add_input(const String &p_name) { } void AnimationNode::remove_input(int p_index) { - ERR_FAIL_INDEX(p_index, inputs.size()); + ERR_FAIL_INDEX(p_index, (int64_t)inputs.size()); inputs.remove_at(p_index); emit_changed(); } bool AnimationNode::set_input_name(int p_input, const String &p_name) { - ERR_FAIL_INDEX_V(p_input, inputs.size(), false); + ERR_FAIL_INDEX_V(p_input, (int64_t)inputs.size(), false); ERR_FAIL_COND_V(p_name.contains_char('.') || p_name.contains_char('/'), false); - inputs.write[p_input].name = p_name; + inputs[p_input].name = p_name; emit_changed(); return true; } String AnimationNode::get_input_name(int p_input) const { - ERR_FAIL_INDEX_V(p_input, inputs.size(), String()); + ERR_FAIL_INDEX_V(p_input, (int64_t)inputs.size(), String()); return inputs[p_input].name; } @@ -357,7 +357,7 @@ int AnimationNode::get_input_count() const { int AnimationNode::find_input(const String &p_name) const { int idx = -1; - for (int i = 0; i < inputs.size(); i++) { + for (int i = 0; i < (int64_t)inputs.size(); i++) { if (inputs[i].name == p_name) { idx = i; break; @@ -653,7 +653,7 @@ bool AnimationTree::_blend_pre_process(double p_delta, int p_track_count, const // Init node state for root AnimationNode. root_animation_node->node_state.track_weights.resize(p_track_count); - real_t *src_blendsw = root_animation_node->node_state.track_weights.ptrw(); + real_t *src_blendsw = root_animation_node->node_state.track_weights.ptr(); for (int i = 0; i < p_track_count; i++) { src_blendsw[i] = 1.0; // By default all go to 1 for the root input. } @@ -769,7 +769,7 @@ void AnimationTree::_update_properties_for_node(const String &p_base_path, Refget_input_count() && !input_activity_map.has(p_base_path)) { - Vector activity; + LocalVector activity; for (int i = 0; i < p_node->get_input_count(); i++) { Activity a; a.activity = 0; @@ -964,9 +964,9 @@ real_t AnimationTree::get_connection_activity(const StringName &p_path, int p_co if (!input_activity_map_get.has(p_path)) { return 0; } - const Vector *activity = input_activity_map_get[p_path]; + const LocalVector *activity = input_activity_map_get[p_path]; - if (!activity || p_connection < 0 || p_connection >= activity->size()) { + if (!activity || p_connection < 0 || p_connection >= (int64_t)activity->size()) { return 0; } diff --git a/scene/animation/animation_tree.h b/scene/animation/animation_tree.h index b5f7199434a..5ac24b49857 100644 --- a/scene/animation/animation_tree.h +++ b/scene/animation/animation_tree.h @@ -59,7 +59,7 @@ public: }; bool closable = false; - Vector inputs; + LocalVector inputs; AHashMap filter; bool filter_enabled = false; @@ -105,7 +105,7 @@ public: public: AnimationNode *parent = nullptr; Vector connections; - Vector track_weights; + LocalVector track_weights; const StringName get_base_path() const { return base_path; @@ -306,8 +306,8 @@ private: uint64_t last_pass = 0; real_t activity = 0.0; }; - mutable HashMap> input_activity_map; - mutable HashMap *> input_activity_map_get; + mutable HashMap> input_activity_map; + mutable HashMap *> input_activity_map_get; NodePath animation_player;