Merge pull request #98706 from Nazarwadim/fix_capture_cache_was_not_cached

Fix `capture_cache.animation` was not cached
This commit is contained in:
Thaddeus Crews 2024-11-13 08:33:54 -06:00
commit 370c692bcb
No known key found for this signature in database
GPG Key ID: 62181B86FE9E5D84
3 changed files with 29 additions and 14 deletions

View File

@ -622,10 +622,11 @@ public:
} }
// Inserts an element without checking if it already exists. // Inserts an element without checking if it already exists.
void insert_new(const TKey &p_key, const TValue &p_value) { Iterator insert_new(const TKey &p_key, const TValue &p_value) {
DEV_ASSERT(!has(p_key)); DEV_ASSERT(!has(p_key));
uint32_t hash = _hash(p_key); uint32_t hash = _hash(p_key);
_insert_element(p_key, p_value, hash); uint32_t pos = _insert_element(p_key, p_value, hash);
return Iterator(elements + pos, elements, elements + num_elements);
} }
/* Array methods. */ /* Array methods. */

View File

@ -600,6 +600,22 @@ void AnimationMixer::_init_root_motion_cache() {
root_motion_scale_accumulator = Vector3(1, 1, 1); root_motion_scale_accumulator = Vector3(1, 1, 1);
} }
void AnimationMixer::_create_track_num_to_track_cashe_for_animation(Ref<Animation> &p_animation) {
ERR_FAIL_COND(animation_track_num_to_track_cashe.has(p_animation));
LocalVector<TrackCache *> &track_num_to_track_cashe = animation_track_num_to_track_cashe.insert_new(p_animation, LocalVector<TrackCache *>())->value;
const Vector<Animation::Track *> &tracks = p_animation->get_tracks();
track_num_to_track_cashe.resize(tracks.size());
for (int i = 0; i < tracks.size(); i++) {
TrackCache **track_ptr = track_cache.getptr(tracks[i]->thash);
if (track_ptr == nullptr) {
track_num_to_track_cashe[i] = nullptr;
} else {
track_num_to_track_cashe[i] = *track_ptr;
}
}
}
bool AnimationMixer::_update_caches() { bool AnimationMixer::_update_caches() {
setup_pass++; setup_pass++;
@ -928,20 +944,9 @@ bool AnimationMixer::_update_caches() {
} }
animation_track_num_to_track_cashe.clear(); animation_track_num_to_track_cashe.clear();
LocalVector<TrackCache *> track_num_to_track_cashe;
for (const StringName &E : sname_list) { for (const StringName &E : sname_list) {
Ref<Animation> anim = get_animation(E); Ref<Animation> anim = get_animation(E);
const Vector<Animation::Track *> tracks = anim->get_tracks(); _create_track_num_to_track_cashe_for_animation(anim);
track_num_to_track_cashe.resize(tracks.size());
for (int i = 0; i < tracks.size(); i++) {
TrackCache **track_ptr = track_cache.getptr(tracks[i]->thash);
if (track_ptr == nullptr) {
track_num_to_track_cashe[i] = nullptr;
} else {
track_num_to_track_cashe[i] = *track_ptr;
}
}
animation_track_num_to_track_cashe.insert(anim, track_num_to_track_cashe);
} }
track_count = idx; track_count = idx;
@ -1074,6 +1079,9 @@ void AnimationMixer::blend_capture(double p_delta) {
capture_cache.remain -= p_delta * capture_cache.step; capture_cache.remain -= p_delta * capture_cache.step;
if (Animation::is_less_or_equal_approx(capture_cache.remain, 0)) { if (Animation::is_less_or_equal_approx(capture_cache.remain, 0)) {
if (capture_cache.animation.is_valid()) {
animation_track_num_to_track_cashe.erase(capture_cache.animation);
}
capture_cache.clear(); capture_cache.clear();
return; return;
} }
@ -2205,6 +2213,9 @@ void AnimationMixer::capture(const StringName &p_name, double p_duration, Tween:
capture_cache.step = 1.0 / p_duration; capture_cache.step = 1.0 / p_duration;
capture_cache.trans_type = p_trans_type; capture_cache.trans_type = p_trans_type;
capture_cache.ease_type = p_ease_type; capture_cache.ease_type = p_ease_type;
if (capture_cache.animation.is_valid()) {
animation_track_num_to_track_cashe.erase(capture_cache.animation);
}
capture_cache.animation.instantiate(); capture_cache.animation.instantiate();
bool is_valid = false; bool is_valid = false;
@ -2228,6 +2239,8 @@ void AnimationMixer::capture(const StringName &p_name, double p_duration, Tween:
} }
if (!is_valid) { if (!is_valid) {
capture_cache.clear(); capture_cache.clear();
} else {
_create_track_num_to_track_cashe_for_animation(capture_cache.animation);
} }
} }

View File

@ -321,6 +321,7 @@ protected:
void _clear_playing_caches(); void _clear_playing_caches();
void _init_root_motion_cache(); void _init_root_motion_cache();
bool _update_caches(); bool _update_caches();
void _create_track_num_to_track_cashe_for_animation(Ref<Animation> &p_animation);
/* ---- Audio ---- */ /* ---- Audio ---- */
AudioServer::PlaybackType playback_type; AudioServer::PlaybackType playback_type;