Skip to content

Commit 370c692

Browse files
committed
Merge pull request #98706 from Nazarwadim/fix_capture_cache_was_not_cached
Fix `capture_cache.animation` was not cached
2 parents eb92f72 + d1dc7af commit 370c692

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

core/templates/a_hash_map.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,11 @@ class AHashMap {
622622
}
623623

624624
// Inserts an element without checking if it already exists.
625-
void insert_new(const TKey &p_key, const TValue &p_value) {
625+
Iterator insert_new(const TKey &p_key, const TValue &p_value) {
626626
DEV_ASSERT(!has(p_key));
627627
uint32_t hash = _hash(p_key);
628-
_insert_element(p_key, p_value, hash);
628+
uint32_t pos = _insert_element(p_key, p_value, hash);
629+
return Iterator(elements + pos, elements, elements + num_elements);
629630
}
630631

631632
/* Array methods. */

scene/animation/animation_mixer.cpp

+25-12
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,22 @@ void AnimationMixer::_init_root_motion_cache() {
600600
root_motion_scale_accumulator = Vector3(1, 1, 1);
601601
}
602602

603+
void AnimationMixer::_create_track_num_to_track_cashe_for_animation(Ref<Animation> &p_animation) {
604+
ERR_FAIL_COND(animation_track_num_to_track_cashe.has(p_animation));
605+
LocalVector<TrackCache *> &track_num_to_track_cashe = animation_track_num_to_track_cashe.insert_new(p_animation, LocalVector<TrackCache *>())->value;
606+
const Vector<Animation::Track *> &tracks = p_animation->get_tracks();
607+
608+
track_num_to_track_cashe.resize(tracks.size());
609+
for (int i = 0; i < tracks.size(); i++) {
610+
TrackCache **track_ptr = track_cache.getptr(tracks[i]->thash);
611+
if (track_ptr == nullptr) {
612+
track_num_to_track_cashe[i] = nullptr;
613+
} else {
614+
track_num_to_track_cashe[i] = *track_ptr;
615+
}
616+
}
617+
}
618+
603619
bool AnimationMixer::_update_caches() {
604620
setup_pass++;
605621

@@ -928,20 +944,9 @@ bool AnimationMixer::_update_caches() {
928944
}
929945

930946
animation_track_num_to_track_cashe.clear();
931-
LocalVector<TrackCache *> track_num_to_track_cashe;
932947
for (const StringName &E : sname_list) {
933948
Ref<Animation> anim = get_animation(E);
934-
const Vector<Animation::Track *> tracks = anim->get_tracks();
935-
track_num_to_track_cashe.resize(tracks.size());
936-
for (int i = 0; i < tracks.size(); i++) {
937-
TrackCache **track_ptr = track_cache.getptr(tracks[i]->thash);
938-
if (track_ptr == nullptr) {
939-
track_num_to_track_cashe[i] = nullptr;
940-
} else {
941-
track_num_to_track_cashe[i] = *track_ptr;
942-
}
943-
}
944-
animation_track_num_to_track_cashe.insert(anim, track_num_to_track_cashe);
949+
_create_track_num_to_track_cashe_for_animation(anim);
945950
}
946951

947952
track_count = idx;
@@ -1074,6 +1079,9 @@ void AnimationMixer::blend_capture(double p_delta) {
10741079

10751080
capture_cache.remain -= p_delta * capture_cache.step;
10761081
if (Animation::is_less_or_equal_approx(capture_cache.remain, 0)) {
1082+
if (capture_cache.animation.is_valid()) {
1083+
animation_track_num_to_track_cashe.erase(capture_cache.animation);
1084+
}
10771085
capture_cache.clear();
10781086
return;
10791087
}
@@ -2205,6 +2213,9 @@ void AnimationMixer::capture(const StringName &p_name, double p_duration, Tween:
22052213
capture_cache.step = 1.0 / p_duration;
22062214
capture_cache.trans_type = p_trans_type;
22072215
capture_cache.ease_type = p_ease_type;
2216+
if (capture_cache.animation.is_valid()) {
2217+
animation_track_num_to_track_cashe.erase(capture_cache.animation);
2218+
}
22082219
capture_cache.animation.instantiate();
22092220

22102221
bool is_valid = false;
@@ -2228,6 +2239,8 @@ void AnimationMixer::capture(const StringName &p_name, double p_duration, Tween:
22282239
}
22292240
if (!is_valid) {
22302241
capture_cache.clear();
2242+
} else {
2243+
_create_track_num_to_track_cashe_for_animation(capture_cache.animation);
22312244
}
22322245
}
22332246

scene/animation/animation_mixer.h

+1
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ class AnimationMixer : public Node {
321321
void _clear_playing_caches();
322322
void _init_root_motion_cache();
323323
bool _update_caches();
324+
void _create_track_num_to_track_cashe_for_animation(Ref<Animation> &p_animation);
324325

325326
/* ---- Audio ---- */
326327
AudioServer::PlaybackType playback_type;

0 commit comments

Comments
 (0)