convert Vector to LocalVector in animation system

This commit is contained in:
Yyf2333 2024-10-01 16:27:06 +08:00
parent e3213aaef5
commit 19a8e5ae3e
4 changed files with 24 additions and 24 deletions

View file

@ -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 {

View file

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

View file

@ -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<AnimationNodeBlendTree>(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<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);
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<AnimationNode> 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, Ref<A
}
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++) {
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> *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;
}

View file

@ -59,7 +59,7 @@ public:
};
bool closable = false;
Vector<Input> inputs;
LocalVector<Input> inputs;
HashMap<NodePath, bool> filter;
bool filter_enabled = false;
@ -100,7 +100,7 @@ public:
StringName base_path;
AnimationNode *parent = nullptr;
Vector<StringName> connections;
Vector<real_t> track_weights;
LocalVector<real_t> 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<StringName, Vector<Activity>> input_activity_map;
HashMap<StringName, Vector<Activity> *> input_activity_map_get;
HashMap<StringName, LocalVector<Activity>> input_activity_map;
HashMap<StringName, LocalVector<Activity> *> input_activity_map_get;
NodePath animation_player;