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

Refactor process of animation to retrive keys more exactly #69336

Merged

Conversation

TokageItLab
Copy link
Member

@TokageItLab TokageItLab commented Nov 29, 2022

Follow up #68992.

Fixes #61853 (completely!)
Fixes #69415

Fundamentally change the process of retrieving keys in animations.

Here is the current key retrieving process:

  1. when using discrete keys, it always gets the current frame's key
  2. instead, it cannot process the end frame, so it uses a hack to get the discrete key at the end frame

Due to reason 2, there was a problem as #64644. This has been fixed by #68992 for now.

However, there is a problem with getting duplicate keys by 1. So it conflicts with the elimination of the seek and playback delays that was the problem in #52518.

This fix changes it so that it does not always get the value of the frame where it is currently located. Whenever an animation is played from a stopped state, there is always some method. So it will be no problem by getting the key of the first frame there.

This also eliminates the need to hack to get the key of the end frame. Compared to before, it should now be possible to retrieve keys in a much more stable.

Includes removal of some unnecessary code and clarify of arguments. For example, check (int)Math::floor(abs(p_delta) / length) % 2 == 0 is to correctly calculate the pingpong if the delta length is longer than the animation length. However, this is an extreme corner case and affects performance, so it has been removed.

Copy link
Member Author

@TokageItLab TokageItLab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some explanations for some changes to make the review easier.

@@ -75,9 +75,10 @@
<param index="3" name="seeked" type="bool" />
<param index="4" name="is_external_seeking" type="bool" />
<param index="5" name="blend" type="float" />
<param index="6" name="pingponged" type="int" default="0" />
<param index="6" name="looped_flag" type="int" enum="Animation.LoopedFlag" default="0" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed it because this is available in linear loop as well as pingpong. In addition, the enum is now properly defined.

Comment on lines +2771 to +2778
if (!p_is_backward) {
for (int i = from; i <= to; i++) {
p_indices->push_back(i);
}
} else {
for (int i = to; i >= to; i--) {
p_indices->push_back(i);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reworked _track_get_key_indices_in_range(). Also, for reverse playback, the order in which keys are stored should be reversed.

@@ -2879,207 +2964,209 @@ void Animation::track_get_key_indices_in_range(int p_track, double p_time, doubl
to_time = Math::pingpong(to_time, length);
}

if ((int)Math::floor(abs(p_delta) / length) % 2 == 0) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in the overview, this check for extreme corner case should not be a concern.

Comment on lines +2836 to +2842
if (!is_backward) {
_track_get_key_indices_in_range(tt->positions, from_time, anim_end, p_indices, is_backward);
_track_get_key_indices_in_range(tt->positions, anim_start, to_time, p_indices, is_backward);
} else {
_track_get_key_indices_in_range(tt->positions, anim_start, to_time, p_indices, is_backward);
_track_get_key_indices_in_range(tt->positions, from_time, anim_end, p_indices, is_backward);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just like what it do in _track_get_key_indices_in_range(), we need to care about the order in which the keys are stored outside of it.

@akien-mga akien-mga merged commit 10e9a85 into godotengine:master Dec 2, 2022
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants