Client LuaCsForBarotrauma
Timing.cs
1 using Microsoft.Xna.Framework;
2 using System;
3 
4 namespace Barotrauma
5 {
6  static class Timing
7  {
8  private static double alpha;
9 
13  public static double TotalTime;
17  public static double TotalTimeUnpaused;
18 
19  public static double Accumulator;
20  public const int FixedUpdateRate = 60;
21  public const double Step = 1.0 / FixedUpdateRate;
22  public static double AccumulatorMax = 0.25f;
23 
27  public static int FrameLimit => GameSettings.CurrentConfig.Graphics.FrameLimit;
28 
29  public static double Alpha
30  {
31  get { return alpha; }
32  set { alpha = Math.Min(Math.Max(value, 0.0), 1.0); }
33  }
34 
35  public static double Interpolate(double previous, double current)
36  {
37  return current * alpha + previous * (1.0 - alpha);
38  }
39 
40  public static float Interpolate(float previous, float current)
41  {
42  return current * (float)alpha + previous * (1.0f - (float)alpha);
43  }
44 
45  public static float InterpolateRotation(float previous, float current)
46  {
47  //use a somewhat high epsilon - very small differences aren't visible
48  if (MathUtils.NearlyEqual(previous, current, epsilon: 0.02f)) { return current; }
49  float angleDiff = MathUtils.GetShortestAngle(previous, current);
50  return previous + angleDiff * (float)alpha;
51  }
52 
53  public static Vector2 Interpolate(Vector2 previous, Vector2 current)
54  {
55  return new Vector2(
56  Interpolate(previous.X, current.X),
57  Interpolate(previous.Y, current.Y));
58  }
59  }
60 }