AnimationState clean up.

This commit is contained in:
NathanSweet 2017-05-17 02:11:55 +02:00
parent 859dd76f78
commit 6140ea31e9

View File

@ -226,18 +226,16 @@ public class AnimationState {
Object[] timelines = from.animation.timelines.items; Object[] timelines = from.animation.timelines.items;
int[] timelineData = from.timelineData.items; int[] timelineData = from.timelineData.items;
Object[] timelineDipMix = from.timelineDipMix.items; Object[] timelineDipMix = from.timelineDipMix.items;
float alphaDip = from.alpha * to.mixAlpha, alphaMix = alphaDip * (1 - mix);
boolean firstFrame = from.timelinesRotation.size == 0; boolean firstFrame = from.timelinesRotation.size == 0;
if (firstFrame) from.timelinesRotation.setSize(timelineCount << 1); if (firstFrame) from.timelinesRotation.setSize(timelineCount << 1);
float[] timelinesRotation = from.timelinesRotation.items; float[] timelinesRotation = from.timelinesRotation.items;
boolean first;
float alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix), alpha;
for (int i = 0; i < timelineCount; i++) { for (int i = 0; i < timelineCount; i++) {
Timeline timeline = (Timeline)timelines[i]; Timeline timeline = (Timeline)timelines[i];
int data = timelineData[i]; switch (timelineData[i]) {
boolean first;
float alpha;
switch (data) {
case SUBSEQUENT: case SUBSEQUENT:
first = false; first = false;
alpha = alphaMix; alpha = alphaMix;
@ -416,7 +414,7 @@ public class AnimationState {
if (interrupt) queue.interrupt(from); if (interrupt) queue.interrupt(from);
current.mixingFrom = from; current.mixingFrom = from;
current.mixTime = 0; current.mixTime = 0;
current.mixAlpha *= Math.min(1, from.mixTime / from.mixDuration); // Store interrupted mix percentage. current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration); // Store interrupted mix percentage.
from.timelinesRotation.clear(); // Reset rotation for mixing out, in case entry was mixed in. from.timelinesRotation.clear(); // Reset rotation for mixing out, in case entry was mixed in.
} }
@ -576,7 +574,7 @@ public class AnimationState {
entry.timeScale = 1; entry.timeScale = 1;
entry.alpha = 1; entry.alpha = 1;
entry.mixAlpha = 1; entry.interruptAlpha = 1;
entry.mixTime = 0; entry.mixTime = 0;
entry.mixDuration = last == null ? 0 : data.getMix(last.animation, animation); entry.mixDuration = last == null ? 0 : data.getMix(last.animation, animation);
return entry; return entry;
@ -688,7 +686,7 @@ public class AnimationState {
float eventThreshold, attachmentThreshold, drawOrderThreshold; float eventThreshold, attachmentThreshold, drawOrderThreshold;
float animationStart, animationEnd, animationLast, nextAnimationLast; float animationStart, animationEnd, animationLast, nextAnimationLast;
float delay, trackTime, trackLast, nextTrackLast, trackEnd, timeScale; float delay, trackTime, trackLast, nextTrackLast, trackEnd, timeScale;
float alpha, mixTime, mixDuration, mixAlpha; float alpha, mixTime, mixDuration, interruptAlpha;
final IntArray timelineData = new IntArray(); final IntArray timelineData = new IntArray();
final Array<TrackEntry> timelineDipMix = new Array(); final Array<TrackEntry> timelineDipMix = new Array();
final FloatArray timelinesRotation = new FloatArray(); final FloatArray timelinesRotation = new FloatArray();
@ -941,8 +939,7 @@ public class AnimationState {
} }
/** Seconds from 0 to the {@link #getMixDuration()} when mixing from the previous animation to this animation. May be /** Seconds from 0 to the {@link #getMixDuration()} when mixing from the previous animation to this animation. May be
* slightly more than <code>mixDuration</code> when the mix is complete. The mix time can be set manually rather than use * slightly more than <code>mixDuration</code> when the mix is complete. */
* the value from AnimationStateData {@link AnimationStateData#getMix(Animation, Animation)}. */
public float getMixTime () { public float getMixTime () {
return mixTime; return mixTime;
} }
@ -954,8 +951,9 @@ public class AnimationState {
/** Seconds for mixing from the previous animation to this animation. Defaults to the value provided by AnimationStateData /** Seconds for mixing from the previous animation to this animation. Defaults to the value provided by AnimationStateData
* {@link AnimationStateData#getMix(Animation, Animation)} based on the animation before this animation (if any). * {@link AnimationStateData#getMix(Animation, Animation)} based on the animation before this animation (if any).
* <p> * <p>
* The <code>mixDuration</code> must be set for a new track entry before {@link AnimationState#update(float)} is next * The <code>mixDuration</code> can be set manually rather than use the value from
* called. * {@link AnimationStateData#getMix(Animation, Animation)}. In that case, the <code>mixDuration</code> must be set for a new
* track entry before {@link AnimationState#update(float)} is next called.
* <p> * <p>
* When using {@link AnimationState#addAnimation(int, Animation, boolean, float)} with a <code>delay</code> <= 0, note the * When using {@link AnimationState#addAnimation(int, Animation, boolean, float)} with a <code>delay</code> <= 0, note the
* {@link #getDelay()} is set using the mix duration from the {@link AnimationStateData}. */ * {@link #getDelay()} is set using the mix duration from the {@link AnimationStateData}. */