Browse Source

More optimizations.

pull/1793/head
Jumar Macato 8 years ago
parent
commit
cfabbe9b65
No known key found for this signature in database GPG Key ID: B19884DAC3A5BF3F
  1. 12
      src/Avalonia.Animation/AnimatorStateMachine`1.cs
  2. 21
      src/Avalonia.Animation/Timing.cs

12
src/Avalonia.Animation/AnimatorStateMachine`1.cs

@ -163,16 +163,16 @@ namespace Avalonia.Animation
animationDirection == PlaybackDirection.AlternateReverse ? (currentIteration % 2 == 0) ? true : false :
animationDirection == PlaybackDirection.Reverse ? true : false;
double x1 = delayFC;
double x2 = x1 + durationFC;
double delayEndpoint = delayFC;
double iterationEndpoint = delayEndpoint + durationFC;
if (delayFC > 0 & t >= 0 & t <= x1)
if (delayFC > 0 & t >= 0 & t <= delayEndpoint)
{
if (currentIteration == 0 && delayBetweenIterations)
if (currentIteration == 0 || delayBetweenIterations)
DoDelay();
}
else if (t >= x1 & t <= x2)
else if (t >= delayEndpoint & t <= iterationEndpoint)
{
var interpVal = t / durationFC;
@ -184,7 +184,7 @@ namespace Avalonia.Animation
lastInterpValue = Interpolator(easedTime, neutralValue);
targetObserver.OnNext(lastInterpValue);
}
else if (t > x2 & (currentIteration + 1 > repeatCount & !isLooping))
else if (t > iterationEndpoint & (currentIteration + 1 > repeatCount & !isLooping))
{
DoComplete();
}

21
src/Avalonia.Animation/Timing.cs

@ -15,15 +15,17 @@ namespace Avalonia.Animation
/// </summary>
public static class Timing
{
static ulong _transitionsFrameCount;
static long _tickStartTimeStamp;
static PlayState _globalState = PlayState.Run;
static long TicksPerFrame = Stopwatch.Frequency / FramesPerSecond;
/// <summary>
/// The number of frames per second.
/// </summary>
public const int FramesPerSecond = 60;
/// <summary>
/// The time span of each frame.
/// </summary>
@ -39,17 +41,18 @@ namespace Avalonia.Animation
var globalTimer = Observable.Interval(FrameTick, AvaloniaScheduler.Instance);
AnimationStateTimer = globalTimer
.Select(_ =>
{
return (_globalState, (Stopwatch.GetTimestamp() - _tickStartTimeStamp)
/ (Stopwatch.Frequency / FramesPerSecond));
/ TicksPerFrame);
})
.Publish()
.RefCount();
TransitionsTimer = globalTimer
.Select(p => _transitionsFrameCount++)
.Select(p => p)
.Publish()
.RefCount();
}
@ -95,7 +98,7 @@ namespace Avalonia.Animation
/// The parameter passed to a subsciber is the number of frames since the animation system was
/// initialized.
/// </remarks>
public static IObservable<ulong> TransitionsTimer
public static IObservable<long> TransitionsTimer
{
get;
}
@ -113,16 +116,14 @@ namespace Avalonia.Animation
/// </remarks>
public static IObservable<double> GetTransitionsTimer(Animatable control, TimeSpan duration, TimeSpan delay = default(TimeSpan))
{
var startTime = _transitionsFrameCount;
var _duration = (ulong)(duration.Ticks / FrameTick.Ticks);
var endTime = startTime + _duration;
var _duration = (duration.Ticks / FrameTick.Ticks);
var endTime = _duration;
return TransitionsTimer
.TakeWhile(x => x < endTime)
.Select(x => (double)(x - startTime) / _duration)
.Select(x => (double)x / _duration)
.StartWith(0.0)
.Concat(Observable.Return(1.0));
}
}
}
}
Loading…
Cancel
Save