4 using SiliconStudio.Core;
5 using SiliconStudio.Core.Collections;
6 using SiliconStudio.Core.Extensions;
8 namespace SiliconStudio.
Paradox.DataModel
12 private int animationSortedIndex;
15 private FastListStruct<Channel> channels =
new FastListStruct<Channel>(8);
19 this.animationData = animationData;
21 foreach (var channel
in animationData.AnimationInitialValues)
23 channels.Add(
new Channel { InterpolationType = channel.InterpolationType });
27 currentTime = CompressedTimeSpan.MaxValue;
38 var targetKeys = animationData.TargetKeys;
39 for (
int i = 0; i < targetKeys.Length; ++i)
41 if (targetKeys[i] == name)
43 var channel = channels.Items[i];
44 channel.Offset = offset;
45 channels.Items[i] = channel;
53 if (animationData == null)
58 var channelCount = channels.Count;
59 var channelItems = channels.Items;
61 for (
int i = 0; i < channelCount; ++i)
63 ProcessChannel(ref channelItems[i], newTime, location);
69 throw new NotImplementedException();
74 var startTime = channel.ValueStart.Time;
77 if (currentTime <= startTime)
79 Utilities.UnsafeWrite(location + channel.Offset, ref channel.ValueStart.Value);
83 var endTime = channel.ValueEnd.Time;
86 if (currentTime >= endTime)
88 Utilities.UnsafeWrite(location + channel.Offset, ref channel.ValueEnd.Value);
92 float factor = (float)(currentTime.
Ticks - startTime.Ticks) / (float)(endTime.Ticks - startTime.Ticks);
94 ProcessChannel(ref channel, currentTime, location, factor);
97 protected abstract void ProcessChannel(ref Channel channel,
CompressedTimeSpan currentTime, IntPtr location,
float factor);
103 if (timeSpan < currentTime)
106 animationSortedIndex = 0;
107 for (
int channelIndex = 0; channelIndex < animationData.AnimationInitialValues.Length; ++channelIndex)
109 InitializeAnimation(ref channels.Items[channelIndex], ref animationData.AnimationInitialValues[channelIndex]);
113 currentTime = timeSpan;
114 var animationSortedValueCount = animationData.AnimationSortedValueCount;
115 var animationSortedValues = animationData.AnimationSortedValues;
117 if (animationSortedValueCount == 0)
121 while (animationSortedIndex < animationSortedValueCount
122 && animationSortedValues[animationSortedIndex / AnimationData.AnimationSortedValueBlock][animationSortedIndex % AnimationData.AnimationSortedValueBlock].RequiredTime <= currentTime)
125 UpdateAnimation(ref animationSortedValues[animationSortedIndex / AnimationData.AnimationSortedValueBlock][animationSortedIndex % AnimationData.AnimationSortedValueBlock]);
126 animationSortedIndex++;
129 currentTime = timeSpan;
132 private static void InitializeAnimation(ref Channel animationChannel, ref AnimationInitialValues<T> animationValue)
134 animationChannel.ValuePrev = animationValue.Value1;
135 animationChannel.ValueStart = animationValue.Value1;
136 animationChannel.ValueEnd = animationValue.Value1;
137 animationChannel.ValueNext = animationValue.Value2;
140 private void UpdateAnimation(ref AnimationKeyValuePair<T> animationValue)
142 UpdateAnimation(ref channels.Items[animationValue.ChannelIndex], ref animationValue.Value);
145 private static void UpdateAnimation(ref Channel animationChannel, ref KeyFrameData<T> animationValue)
147 animationChannel.ValuePrev = animationChannel.ValueStart;
148 animationChannel.ValueStart = animationChannel.ValueEnd;
149 animationChannel.ValueEnd = animationChannel.ValueNext;
150 animationChannel.ValueNext = animationValue;
153 protected struct Channel
KeyFrameData< T > ValueStart
override void Evaluate(CompressedTimeSpan newTime, IntPtr location)
void AddChannel(string name, int offset)
AnimationCurveInterpolationType InterpolationType
KeyFrameData< T > ValuePrev
AnimationCurveInterpolationType
Describes how a curve should be interpolated.
override void Evaluate(CompressedTimeSpan newTime, object[] results)
KeyFrameData< T > ValueEnd
KeyFrameData< T > ValueNext
void ProcessChannel(ref Channel channel, CompressedTimeSpan currentTime, IntPtr location)
void Initialize(AnimationData< T > animationData)
A single key frame value.