A game framework written with osu! in mind.

Add generic easing pathway for ValueAt

+114 -30
+114 -30
osu.Framework/Utils/Interpolation.cs
··· 127 127 return numerator / denominator; 128 128 } 129 129 130 + #region ValueAt 131 + 130 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 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 - public static EdgeEffectParameters ValueAt(double time, EdgeEffectParameters startParams, EdgeEffectParameters endParams, double startTime, double endTime, Easing easing = Easing.None) => 145 - new EdgeEffectParameters 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 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 - 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); 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); 157 220 158 - public static Color4 ValueAt(double time, Color4 startColour, Color4 endColour, double startTime, double endTime, Easing easing = Easing.None) 221 + public static Color4 ValueAt<TEasing>(double time, Color4 startColour, Color4 endColour, double startTime, double endTime, in TEasing easing) 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 - 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)); 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)); 180 245 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)); 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)); 183 249 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)); 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)); 186 253 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)); 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)); 189 257 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)); 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)); 192 261 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)); 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)); 195 265 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)); 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)); 198 269 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)); 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)); 201 273 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); 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); 204 277 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); 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); 207 281 208 - public static double ValueAt(double time, double val1, double val2, double startTime, double endTime, Easing easing = Easing.None) 282 + public static double ValueAt<TEasing>(double time, double val1, double val2, double startTime, double endTime, in TEasing easing) 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 - public static Vector2 ValueAt(double time, Vector2 val1, Vector2 val2, double startTime, double endTime, Easing easing = Easing.None) 300 + public static Vector2 ValueAt<TEasing>(double time, Vector2 val1, Vector2 val2, double startTime, double endTime, in TEasing easing) 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 - public static RectangleF ValueAt(double time, RectangleF val1, RectangleF val2, double startTime, double endTime, Easing easing = Easing.None) 313 + public static RectangleF ValueAt<TEasing>(double time, RectangleF val1, RectangleF val2, double startTime, double endTime, in TEasing easing) 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 - public static TValue ValueAt<TValue>(double time, TValue startValue, TValue endValue, double startTime, double endTime, Easing easing = Easing.None) 331 + public static TValue ValueAt<TValue, TEasing>(double time, TValue startValue, TValue endValue, double startTime, double endTime, in TEasing easing) 332 + where TEasing : IEasingFunction 255 333 => GenericInterpolation<TValue>.FUNCTION(time, startValue, endValue, startTime, endTime, easing); 334 + 335 + #endregion 256 336 257 337 public static double ApplyEasing(Easing easing, double time) 258 - => new DefaultEasingFunction(easing).ApplyEasing(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); 259 343 260 344 private static class GenericInterpolation<TValue> 261 345 {