Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix capture_cache.animation was not cached #98706

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions core/templates/a_hash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,11 @@ class AHashMap {
}

// 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));
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. */
Expand Down
37 changes: 25 additions & 12 deletions scene/animation/animation_mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,22 @@ void AnimationMixer::_init_root_motion_cache() {
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() {
setup_pass++;

Expand Down Expand Up @@ -928,20 +944,9 @@ bool AnimationMixer::_update_caches() {
}

animation_track_num_to_track_cashe.clear();
LocalVector<TrackCache *> track_num_to_track_cashe;
for (const StringName &E : sname_list) {
Ref<Animation> anim = get_animation(E);
const Vector<Animation::Track *> tracks = anim->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;
}
}
animation_track_num_to_track_cashe.insert(anim, track_num_to_track_cashe);
_create_track_num_to_track_cashe_for_animation(anim);
}

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

capture_cache.remain -= p_delta * capture_cache.step;
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();
return;
}
Expand Down Expand Up @@ -2205,6 +2213,9 @@ void AnimationMixer::capture(const StringName &p_name, double p_duration, Tween:
capture_cache.step = 1.0 / p_duration;
capture_cache.trans_type = p_trans_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();

bool is_valid = false;
Expand All @@ -2228,6 +2239,8 @@ void AnimationMixer::capture(const StringName &p_name, double p_duration, Tween:
}
if (!is_valid) {
capture_cache.clear();
} else {
_create_track_num_to_track_cashe_for_animation(capture_cache.animation);
}
}

Expand Down
1 change: 1 addition & 0 deletions scene/animation/animation_mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ class AnimationMixer : public Node {
void _clear_playing_caches();
void _init_root_motion_cache();
bool _update_caches();
void _create_track_num_to_track_cashe_for_animation(Ref<Animation> &p_animation);

/* ---- Audio ---- */
AudioServer::PlaybackType playback_type;
Expand Down
Loading