tangled
alpha
login
or
join now
keii.dev
/
osu-framework
A game framework written with osu! in mind.
0
fork
atom
overview
issues
pulls
pipelines
Add generic easing pathway for ValueAt
smoogipoo
6 years ago
6077d830
9ad2877a
+114
-30
1 changed file
expand all
collapse all
unified
split
osu.Framework
Utils
Interpolation.cs
+114
-30
osu.Framework/Utils/Interpolation.cs
···
127
return numerator / denominator;
128
}
129
0
0
130
public static ColourInfo ValueAt(double time, ColourInfo startColour, ColourInfo endColour, double startTime, double endTime, Easing easing = Easing.None)
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
131
{
132
if (startColour.HasSingleColour && endColour.HasSingleColour)
133
return ValueAt(time, (Color4)startColour, (Color4)endColour, startTime, endTime, easing);
···
141
};
142
}
143
144
-
public static EdgeEffectParameters ValueAt(double time, EdgeEffectParameters startParams, EdgeEffectParameters endParams, double startTime, double endTime, Easing easing = Easing.None) =>
145
-
new EdgeEffectParameters
0
146
{
147
Type = startParams.Type,
148
Hollow = startParams.Hollow,
···
152
Roundness = ValueAt(time, startParams.Roundness, endParams.Roundness, startTime, endTime, easing),
153
};
154
155
-
public static SRGBColour ValueAt(double time, SRGBColour startColour, SRGBColour endColour, double startTime, double endTime, Easing easing = Easing.None) =>
156
-
ValueAt(time, (Color4)startColour, (Color4)endColour, startTime, endTime, easing);
0
157
158
-
public static Color4 ValueAt(double time, Color4 startColour, Color4 endColour, double startTime, double endTime, Easing easing = Easing.None)
0
159
{
160
if (startColour == endColour)
161
return startColour;
···
175
startColour.A + t * (endColour.A - startColour.A));
176
}
177
178
-
public static byte ValueAt(double time, byte val1, byte val2, double startTime, double endTime, Easing easing = Easing.None) =>
179
-
(byte)Math.Round(ValueAt(time, (double)val1, val2, startTime, endTime, easing));
0
180
181
-
public static sbyte ValueAt(double time, sbyte val1, sbyte val2, double startTime, double endTime, Easing easing = Easing.None) =>
182
-
(sbyte)Math.Round(ValueAt(time, (double)val1, val2, startTime, endTime, easing));
0
183
184
-
public static short ValueAt(double time, short val1, short val2, double startTime, double endTime, Easing easing = Easing.None) =>
185
-
(short)Math.Round(ValueAt(time, (double)val1, val2, startTime, endTime, easing));
0
186
187
-
public static ushort ValueAt(double time, ushort val1, ushort val2, double startTime, double endTime, Easing easing = Easing.None) =>
188
-
(ushort)Math.Round(ValueAt(time, (double)val1, val2, startTime, endTime, easing));
0
189
190
-
public static int ValueAt(double time, int val1, int val2, double startTime, double endTime, Easing easing = Easing.None) =>
191
-
(int)Math.Round(ValueAt(time, (double)val1, val2, startTime, endTime, easing));
0
192
193
-
public static uint ValueAt(double time, uint val1, uint val2, double startTime, double endTime, Easing easing = Easing.None) =>
194
-
(uint)Math.Round(ValueAt(time, (double)val1, val2, startTime, endTime, easing));
0
195
196
-
public static long ValueAt(double time, long val1, long val2, double startTime, double endTime, Easing easing = Easing.None) =>
197
-
(long)Math.Round(ValueAt(time, (double)val1, val2, startTime, endTime, easing));
0
198
199
-
public static ulong ValueAt(double time, ulong val1, ulong val2, double startTime, double endTime, Easing easing = Easing.None) =>
200
-
(ulong)Math.Round(ValueAt(time, (double)val1, val2, startTime, endTime, easing));
0
201
202
-
public static float ValueAt(double time, float val1, float val2, double startTime, double endTime, Easing easing = Easing.None) =>
203
-
(float)ValueAt(time, (double)val1, val2, startTime, endTime, easing);
0
204
205
-
public static decimal ValueAt(double time, decimal val1, decimal val2, double startTime, double endTime, Easing easing = Easing.None) =>
206
-
(decimal)ValueAt(time, (double)val1, (double)val2, startTime, endTime, easing);
0
207
208
-
public static double ValueAt(double time, double val1, double val2, double startTime, double endTime, Easing easing = Easing.None)
0
209
{
210
if (val1 == val2)
211
return val1;
···
222
return val1 + t * (val2 - val1);
223
}
224
225
-
public static Vector2 ValueAt(double time, Vector2 val1, Vector2 val2, double startTime, double endTime, Easing easing = Easing.None)
0
226
{
227
float current = (float)(time - startTime);
228
float duration = (float)(endTime - startTime);
···
234
return val1 + t * (val2 - val1);
235
}
236
237
-
public static RectangleF ValueAt(double time, RectangleF val1, RectangleF val2, double startTime, double endTime, Easing easing = Easing.None)
0
238
{
239
float current = (float)(time - startTime);
240
float duration = (float)(endTime - startTime);
···
251
val1.Height + t * (val2.X - val1.Height));
252
}
253
254
-
public static TValue ValueAt<TValue>(double time, TValue startValue, TValue endValue, double startTime, double endTime, Easing easing = Easing.None)
0
255
=> GenericInterpolation<TValue>.FUNCTION(time, startValue, endValue, startTime, endTime, easing);
0
0
256
257
public static double ApplyEasing(Easing easing, double time)
258
-
=> new DefaultEasingFunction(easing).ApplyEasing(time);
0
0
0
0
259
260
private static class GenericInterpolation<TValue>
261
{
···
127
return numerator / denominator;
128
}
129
130
+
#region ValueAt
131
+
132
public static ColourInfo ValueAt(double time, ColourInfo startColour, ColourInfo endColour, double startTime, double endTime, Easing easing = Easing.None)
133
+
=> ValueAt(time, startColour, endColour, startTime, endTime, new DefaultEasingFunction(easing));
134
+
135
+
public static EdgeEffectParameters ValueAt(double time, EdgeEffectParameters startParams, EdgeEffectParameters endParams, double startTime, double endTime, Easing easing = Easing.None)
136
+
=> ValueAt(time, startParams, endParams, startTime, endTime, new DefaultEasingFunction(easing));
137
+
138
+
public static SRGBColour ValueAt(double time, SRGBColour startColour, SRGBColour endColour, double startTime, double endTime, Easing easing = Easing.None)
139
+
=> ValueAt(time, startColour, endColour, startTime, endTime, new DefaultEasingFunction(easing));
140
+
141
+
public static Color4 ValueAt(double time, Color4 startColour, Color4 endColour, double startTime, double endTime, Easing easing = Easing.None)
142
+
=> ValueAt(time, startColour, endColour, startTime, endTime, new DefaultEasingFunction(easing));
143
+
144
+
public static byte ValueAt(double time, byte val1, byte val2, double startTime, double endTime, Easing easing = Easing.None)
145
+
=> ValueAt(time, val1, val2, startTime, endTime, new DefaultEasingFunction(easing));
146
+
147
+
public static sbyte ValueAt(double time, sbyte val1, sbyte val2, double startTime, double endTime, Easing easing = Easing.None)
148
+
=> ValueAt(time, val1, val2, startTime, endTime, new DefaultEasingFunction(easing));
149
+
150
+
public static short ValueAt(double time, short val1, short val2, double startTime, double endTime, Easing easing = Easing.None)
151
+
=> ValueAt(time, val1, val2, startTime, endTime, new DefaultEasingFunction(easing));
152
+
153
+
public static ushort ValueAt(double time, ushort val1, ushort val2, double startTime, double endTime, Easing easing = Easing.None)
154
+
=> ValueAt(time, val1, val2, startTime, endTime, new DefaultEasingFunction(easing));
155
+
156
+
public static int ValueAt(double time, int val1, int val2, double startTime, double endTime, Easing easing = Easing.None)
157
+
=> ValueAt(time, val1, val2, startTime, endTime, new DefaultEasingFunction(easing));
158
+
159
+
public static uint ValueAt(double time, uint val1, uint val2, double startTime, double endTime, Easing easing = Easing.None)
160
+
=> ValueAt(time, val1, val2, startTime, endTime, new DefaultEasingFunction(easing));
161
+
162
+
public static long ValueAt(double time, long val1, long val2, double startTime, double endTime, Easing easing = Easing.None)
163
+
=> ValueAt(time, val1, val2, startTime, endTime, new DefaultEasingFunction(easing));
164
+
165
+
public static ulong ValueAt(double time, ulong val1, ulong val2, double startTime, double endTime, Easing easing = Easing.None)
166
+
=> ValueAt(time, val1, val2, startTime, endTime, new DefaultEasingFunction(easing));
167
+
168
+
public static float ValueAt(double time, float val1, float val2, double startTime, double endTime, Easing easing = Easing.None)
169
+
=> ValueAt(time, val1, val2, startTime, endTime, new DefaultEasingFunction(easing));
170
+
171
+
public static decimal ValueAt(double time, decimal val1, decimal val2, double startTime, double endTime, Easing easing = Easing.None)
172
+
=> ValueAt(time, val1, val2, startTime, endTime, new DefaultEasingFunction(easing));
173
+
174
+
public static double ValueAt(double time, double val1, double val2, double startTime, double endTime, Easing easing = Easing.None)
175
+
=> ValueAt(time, val1, val2, startTime, endTime, new DefaultEasingFunction(easing));
176
+
177
+
public static Vector2 ValueAt(double time, Vector2 val1, Vector2 val2, double startTime, double endTime, Easing easing = Easing.None)
178
+
=> ValueAt(time, val1, val2, startTime, endTime, new DefaultEasingFunction(easing));
179
+
180
+
public static RectangleF ValueAt(double time, RectangleF val1, RectangleF val2, double startTime, double endTime, Easing easing = Easing.None)
181
+
=> ValueAt(time, val1, val2, startTime, endTime, new DefaultEasingFunction(easing));
182
+
183
+
public static TValue ValueAt<TValue>(double time, TValue startValue, TValue endValue, double startTime, double endTime, Easing easing = Easing.None)
184
+
=> ValueAt(time, startValue, endValue, startTime, endTime, new DefaultEasingFunction(easing));
185
+
186
+
#endregion
187
+
188
+
#region ValueAt<TEasing>
189
+
190
+
public static ColourInfo ValueAt<TEasing>(double time, ColourInfo startColour, ColourInfo endColour, double startTime, double endTime, in TEasing easing)
191
+
where TEasing : IEasingFunction
192
{
193
if (startColour.HasSingleColour && endColour.HasSingleColour)
194
return ValueAt(time, (Color4)startColour, (Color4)endColour, startTime, endTime, easing);
···
202
};
203
}
204
205
+
public static EdgeEffectParameters ValueAt<TEasing>(double time, EdgeEffectParameters startParams, EdgeEffectParameters endParams, double startTime, double endTime, in TEasing easing)
206
+
where TEasing : IEasingFunction
207
+
=> new EdgeEffectParameters
208
{
209
Type = startParams.Type,
210
Hollow = startParams.Hollow,
···
214
Roundness = ValueAt(time, startParams.Roundness, endParams.Roundness, startTime, endTime, easing),
215
};
216
217
+
public static SRGBColour ValueAt<TEasing>(double time, SRGBColour startColour, SRGBColour endColour, double startTime, double endTime, in TEasing easing)
218
+
where TEasing : IEasingFunction
219
+
=> ValueAt(time, (Color4)startColour, (Color4)endColour, startTime, endTime, easing);
220
221
+
public static Color4 ValueAt<TEasing>(double time, Color4 startColour, Color4 endColour, double startTime, double endTime, in TEasing easing)
222
+
where TEasing : IEasingFunction
223
{
224
if (startColour == endColour)
225
return startColour;
···
239
startColour.A + t * (endColour.A - startColour.A));
240
}
241
242
+
public static byte ValueAt<TEasing>(double time, byte val1, byte val2, double startTime, double endTime, in TEasing easing)
243
+
where TEasing : IEasingFunction
244
+
=> (byte)Math.Round(ValueAt(time, (double)val1, val2, startTime, endTime, easing));
245
246
+
public static sbyte ValueAt<TEasing>(double time, sbyte val1, sbyte val2, double startTime, double endTime, in TEasing easing)
247
+
where TEasing : IEasingFunction
248
+
=> (sbyte)Math.Round(ValueAt(time, (double)val1, val2, startTime, endTime, easing));
249
250
+
public static short ValueAt<TEasing>(double time, short val1, short val2, double startTime, double endTime, in TEasing easing)
251
+
where TEasing : IEasingFunction
252
+
=> (short)Math.Round(ValueAt(time, (double)val1, val2, startTime, endTime, easing));
253
254
+
public static ushort ValueAt<TEasing>(double time, ushort val1, ushort val2, double startTime, double endTime, in TEasing easing)
255
+
where TEasing : IEasingFunction
256
+
=> (ushort)Math.Round(ValueAt(time, (double)val1, val2, startTime, endTime, easing));
257
258
+
public static int ValueAt<TEasing>(double time, int val1, int val2, double startTime, double endTime, in TEasing easing)
259
+
where TEasing : IEasingFunction
260
+
=> (int)Math.Round(ValueAt(time, (double)val1, val2, startTime, endTime, easing));
261
262
+
public static uint ValueAt<TEasing>(double time, uint val1, uint val2, double startTime, double endTime, in TEasing easing)
263
+
where TEasing : IEasingFunction
264
+
=> (uint)Math.Round(ValueAt(time, (double)val1, val2, startTime, endTime, easing));
265
266
+
public static long ValueAt<TEasing>(double time, long val1, long val2, double startTime, double endTime, in TEasing easing)
267
+
where TEasing : IEasingFunction
268
+
=> (long)Math.Round(ValueAt(time, (double)val1, val2, startTime, endTime, easing));
269
270
+
public static ulong ValueAt<TEasing>(double time, ulong val1, ulong val2, double startTime, double endTime, in TEasing easing)
271
+
where TEasing : IEasingFunction
272
+
=> (ulong)Math.Round(ValueAt(time, (double)val1, val2, startTime, endTime, easing));
273
274
+
public static float ValueAt<TEasing>(double time, float val1, float val2, double startTime, double endTime, in TEasing easing)
275
+
where TEasing : IEasingFunction
276
+
=> (float)ValueAt(time, (double)val1, val2, startTime, endTime, easing);
277
278
+
public static decimal ValueAt<TEasing>(double time, decimal val1, decimal val2, double startTime, double endTime, in TEasing easing)
279
+
where TEasing : IEasingFunction
280
+
=> (decimal)ValueAt(time, (double)val1, (double)val2, startTime, endTime, easing);
281
282
+
public static double ValueAt<TEasing>(double time, double val1, double val2, double startTime, double endTime, in TEasing easing)
283
+
where TEasing : IEasingFunction
284
{
285
if (val1 == val2)
286
return val1;
···
297
return val1 + t * (val2 - val1);
298
}
299
300
+
public static Vector2 ValueAt<TEasing>(double time, Vector2 val1, Vector2 val2, double startTime, double endTime, in TEasing easing)
301
+
where TEasing : IEasingFunction
302
{
303
float current = (float)(time - startTime);
304
float duration = (float)(endTime - startTime);
···
310
return val1 + t * (val2 - val1);
311
}
312
313
+
public static RectangleF ValueAt<TEasing>(double time, RectangleF val1, RectangleF val2, double startTime, double endTime, in TEasing easing)
314
+
where TEasing : IEasingFunction
315
{
316
float current = (float)(time - startTime);
317
float duration = (float)(endTime - startTime);
···
328
val1.Height + t * (val2.X - val1.Height));
329
}
330
331
+
public static TValue ValueAt<TValue, TEasing>(double time, TValue startValue, TValue endValue, double startTime, double endTime, in TEasing easing)
332
+
where TEasing : IEasingFunction
333
=> GenericInterpolation<TValue>.FUNCTION(time, startValue, endValue, startTime, endTime, easing);
334
+
335
+
#endregion
336
337
public static double ApplyEasing(Easing easing, double time)
338
+
=> ApplyEasing(new DefaultEasingFunction(easing), time);
339
+
340
+
public static double ApplyEasing<TEasing>(TEasing easing, double time)
341
+
where TEasing : IEasingFunction
342
+
=> easing.ApplyEasing(time);
343
344
private static class GenericInterpolation<TValue>
345
{