Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
AnimationCurveEvaluatorDirectGroup.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using SiliconStudio.Core.Collections;
5 
6 namespace SiliconStudio.Paradox.DataModel
7 {
8  public abstract class AnimationCurveEvaluatorDirectGroup<T> : AnimationCurveEvaluatorGroup
9  {
10  FastListStruct<Channel> channels = new FastListStruct<Channel>(8);
11 
12  public void Initialize()
13  {
14 
15  }
16 
17  public void Cleanup()
18  {
19  channels.Clear();
20  }
21 
22  public void AddChannel(AnimationCurve curve, int offset)
23  {
24  channels.Add(new Channel { Offset = offset, Curve = (AnimationCurve<T>)curve, InterpolationType = curve.InterpolationType });
25  }
26 
27  public override void Evaluate(CompressedTimeSpan newTime, IntPtr location)
28  {
29  var channelCount = channels.Count;
30  var channelItems = channels.Items;
31 
32  for (int i = 0; i < channelCount; ++i)
33  {
34  ProcessChannel(ref channelItems[i], newTime, location);
35  }
36  }
37 
38  public override void Evaluate(CompressedTimeSpan newTime, object[] results)
39  {
40  throw new NotImplementedException();
41  }
42 
43  protected static void SetTime(ref Channel channel, CompressedTimeSpan newTime)
44  {
45  var currentTime = channel.CurrentTime;
46  if (newTime == currentTime)
47  return;
48 
49  var currentIndex = channel.CurrentIndex;
50  var keyFrames = channel.Curve.KeyFrames;
51 
52  var keyFramesItems = keyFrames.Items;
53  var keyFramesCount = keyFrames.Count;
54 
55  if (newTime > currentTime)
56  {
57  while (currentIndex + 1 < keyFramesCount - 1 && newTime >= keyFramesItems[currentIndex + 1].Time)
58  {
59  ++currentIndex;
60  }
61  }
62  else if (newTime <= keyFramesItems[0].Time)
63  {
64  // Special case: fast rewind to beginning of animation
65  currentIndex = 0;
66  }
67  else // newTime < currentTime
68  {
69  while (currentIndex - 1 >= 0 && newTime < keyFramesItems[currentIndex].Time)
70  {
71  --currentIndex;
72  }
73  }
74 
75  channel.CurrentIndex = currentIndex;
76  channel.CurrentTime = newTime;
77  }
78 
79  protected abstract void ProcessChannel(ref Channel channel, CompressedTimeSpan newTime, IntPtr location);
80 
81  protected struct Channel
82  {
83  public int Offset;
86  public int CurrentIndex;
88  }
89  }
90 }
AnimationCurveInterpolationType
Describes how a curve should be interpolated.
AnimationCurveInterpolationType InterpolationType
Gets or sets the interpolation type.
Untyped base class for animation curves.
override void Evaluate(CompressedTimeSpan newTime, object[] results)
static void SetTime(ref Channel channel, CompressedTimeSpan newTime)