Convert Vector to LocalVector in animation system.

Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
This commit is contained in:
Yyf2333 2024-10-01 16:27:06 +08:00 committed by Yufeng Ying
parent 216b3302f3
commit 2f9a6636bd
4 changed files with 24 additions and 24 deletions

View file

@ -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) { void AnimationNodeTransition::set_input_as_auto_advance(int p_input, bool p_enable) {
ERR_FAIL_INDEX(p_input, get_input_count()); 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 { 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) { void AnimationNodeTransition::set_input_break_loop_at_end(int p_input, bool p_enable) {
ERR_FAIL_INDEX(p_input, get_input_count()); 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 { 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) { void AnimationNodeTransition::set_input_reset(int p_input, bool p_enable) {
ERR_FAIL_INDEX(p_input, get_input_count()); 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 { bool AnimationNodeTransition::is_input_reset(int p_input) const {

View file

@ -331,7 +331,7 @@ class AnimationNodeTransition : public AnimationNodeSync {
bool break_loop_at_end = false; bool break_loop_at_end = false;
bool reset = true; bool reset = true;
}; };
Vector<InputData> input_data; LocalVector<InputData> input_data;
StringName prev_xfading = "prev_xfading"; StringName prev_xfading = "prev_xfading";
StringName prev_index = "prev_index"; StringName prev_index = "prev_index";

View file

@ -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) { 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<AnimationNodeBlendTree>(node_state.parent); AnimationNodeBlendTree *blend_tree = Object::cast_to<AnimationNodeBlendTree>(node_state.parent);
ERR_FAIL_NULL_V(blend_tree, NodeTimeInfo()); 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()); ERR_FAIL_COND_V(node.is_null(), NodeTimeInfo());
real_t activity = 0.0; real_t activity = 0.0;
Vector<AnimationTree::Activity> *activity_ptr = process_state->tree->input_activity_map.getptr(node_state.base_path); LocalVector<AnimationTree::Activity> *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); 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()) { if (activity_ptr && p_input < (int64_t)activity_ptr->size()) {
activity_ptr->write[p_input].last_pass = process_state->last_pass; (*activity_ptr)[p_input].last_pass = process_state->last_pass;
activity_ptr->write[p_input].activity = activity; (*activity_ptr)[p_input].activity = activity;
} }
return nti; return nti;
} }
@ -202,11 +202,11 @@ AnimationNode::NodeTimeInfo AnimationNode::_blend_node(Ref<AnimationNode> p_node
int blend_count = node_state.track_weights.size(); 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); 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(); const real_t *blendr = node_state.track_weights.ptr();
bool any_valid = false; bool any_valid = false;
@ -333,21 +333,21 @@ bool AnimationNode::add_input(const String &p_name) {
} }
void AnimationNode::remove_input(int p_index) { 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); inputs.remove_at(p_index);
emit_changed(); emit_changed();
} }
bool AnimationNode::set_input_name(int p_input, const String &p_name) { 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); 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(); emit_changed();
return true; return true;
} }
String AnimationNode::get_input_name(int p_input) const { 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; 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 AnimationNode::find_input(const String &p_name) const {
int idx = -1; 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) { if (inputs[i].name == p_name) {
idx = i; idx = i;
break; break;
@ -653,7 +653,7 @@ bool AnimationTree::_blend_pre_process(double p_delta, int p_track_count, const
// Init node state for root AnimationNode. // Init node state for root AnimationNode.
root_animation_node->node_state.track_weights.resize(p_track_count); 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++) { for (int i = 0; i < p_track_count; i++) {
src_blendsw[i] = 1.0; // By default all go to 1 for the root input. 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, Ref<A
} }
if (p_node->get_input_count() && !input_activity_map.has(p_base_path)) { if (p_node->get_input_count() && !input_activity_map.has(p_base_path)) {
Vector<Activity> activity; LocalVector<Activity> activity;
for (int i = 0; i < p_node->get_input_count(); i++) { for (int i = 0; i < p_node->get_input_count(); i++) {
Activity a; Activity a;
a.activity = 0; 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)) { if (!input_activity_map_get.has(p_path)) {
return 0; return 0;
} }
const Vector<Activity> *activity = input_activity_map_get[p_path]; const LocalVector<Activity> *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; return 0;
} }

View file

@ -59,7 +59,7 @@ public:
}; };
bool closable = false; bool closable = false;
Vector<Input> inputs; LocalVector<Input> inputs;
AHashMap<NodePath, bool> filter; AHashMap<NodePath, bool> filter;
bool filter_enabled = false; bool filter_enabled = false;
@ -105,7 +105,7 @@ public:
public: public:
AnimationNode *parent = nullptr; AnimationNode *parent = nullptr;
Vector<StringName> connections; Vector<StringName> connections;
Vector<real_t> track_weights; LocalVector<real_t> track_weights;
const StringName get_base_path() const { const StringName get_base_path() const {
return base_path; return base_path;
@ -306,8 +306,8 @@ private:
uint64_t last_pass = 0; uint64_t last_pass = 0;
real_t activity = 0.0; real_t activity = 0.0;
}; };
mutable HashMap<StringName, Vector<Activity>> input_activity_map; mutable HashMap<StringName, LocalVector<Activity>> input_activity_map;
mutable HashMap<StringName, Vector<Activity> *> input_activity_map_get; mutable HashMap<StringName, LocalVector<Activity> *> input_activity_map_get;
NodePath animation_player; NodePath animation_player;