From 19a8e5ae3e369d43517dc6976e889c1793a0a097 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 --- 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 a96417738f8..28a02f4e31c 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -1148,7 +1148,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 { @@ -1158,7 +1158,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 { @@ -1168,7 +1168,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 2add35d0098..fa25b574678 100644 --- a/scene/animation/animation_blend_tree.h +++ b/scene/animation/animation_blend_tree.h @@ -317,7 +317,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 19080e61dec..1a203841ed2 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -147,7 +147,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()); @@ -167,12 +167,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->ptr()[p_input].last_pass = process_state->last_pass; + activity_ptr->ptr()[p_input].activity = activity; } return nti; } @@ -188,11 +188,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; @@ -319,21 +319,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(".") || p_name.contains("/"), 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; } @@ -343,7 +343,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; @@ -623,7 +623,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. } @@ -739,7 +739,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; @@ -934,9 +934,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 d4b7bf31c9d..a45a424aae6 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; HashMap filter; bool filter_enabled = false; @@ -100,7 +100,7 @@ public: StringName base_path; AnimationNode *parent = nullptr; Vector connections; - Vector track_weights; + LocalVector track_weights; } node_state; // Temporary state for blending process which needs to be started in the AnimationTree, pass through the AnimationNodes, and then return to the AnimationTree. @@ -267,8 +267,8 @@ private: uint64_t last_pass = 0; real_t activity = 0.0; }; - HashMap> input_activity_map; - HashMap *> input_activity_map_get; + HashMap> input_activity_map; + HashMap *> input_activity_map_get; NodePath animation_player;