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