Skip to content

Commit c46c36e

Browse files
[Core] Add Time frameDeltaTime;
[Dependencies] Update Windows BGFX redist with fix regarding discarding;
1 parent b9d7fd5 commit c46c36e

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

Engine/Core/Player/Time.cs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Numerics;
23

34
namespace Staple;
45

@@ -47,18 +48,25 @@ public static class Time
4748
/// </summary>
4849
public static int FPS { get; internal set; }
4950

51+
/// <summary>
52+
/// Frame Delta Time
53+
/// </summary>
54+
public static (float min, float max, float average) frameDeltaTime { get; internal set; }
55+
5056
/// <summary>
5157
/// The current time accumulator
5258
/// </summary>
53-
internal static float Accumulator { get; private set; }
59+
internal static float accumulator { get; private set; }
5460

5561
/// <summary>
5662
/// Called when the accumulator triggers
5763
/// </summary>
58-
internal static Action OnAccumulatorFinished { get; set; }
64+
internal static Action onAccumulatorFinished { get; set; }
5965

6066
private static int frames;
6167
private static float frameTimer;
68+
private static Vector3 frameDelta;
69+
private static float frameDeltaTimer;
6270

6371
/// <summary>
6472
/// Updates the clock
@@ -76,28 +84,45 @@ internal static void UpdateClock(DateTime current, DateTime last)
7684
delta = maximumDeltaTime;
7785
}
7886

79-
Accumulator += delta;
87+
accumulator += delta;
8088

8189
unscaledDeltaTime = delta;
8290

83-
var previousAccumulator = Accumulator;
91+
var previousAccumulator = accumulator;
8492

8593
if(fixedDeltaTime > 0)
8694
{
87-
while (Accumulator >= fixedDeltaTime)
95+
while (accumulator >= fixedDeltaTime)
8896
{
89-
Accumulator -= fixedDeltaTime;
97+
accumulator -= fixedDeltaTime;
9098
}
9199
}
92100

93-
if(Accumulator < previousAccumulator)
101+
if(accumulator < previousAccumulator)
94102
{
95-
OnAccumulatorFinished?.Invoke();
103+
onAccumulatorFinished?.Invoke();
96104
}
97105

98106
frames++;
99107
frameTimer += delta;
100108

109+
frameDeltaTimer += delta;
110+
111+
frameDelta.X = Math.Min(delta, frameDelta.X);
112+
frameDelta.Y = Math.Max(delta, frameDelta.Y);
113+
frameDelta.Z += delta;
114+
115+
if(frameDeltaTimer >= 2.0f)
116+
{
117+
frameDeltaTimer = 0;
118+
119+
frameDelta.Z /= frames;
120+
121+
frameDeltaTime = (frameDelta.X, frameDelta.Y, frameDelta.Z);
122+
123+
frameDelta = new Vector3(999, 0, 0);
124+
}
125+
101126
if(frameTimer >= 1.0f)
102127
{
103128
FPS = frames;

Engine/Core/Rendering/RenderSystem/RenderSystem+Internal.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void Startup()
167167

168168
LightSystem.Enabled = AppSettings.Current?.enableLighting ?? true;
169169

170-
Time.OnAccumulatorFinished += () =>
170+
Time.onAccumulatorFinished += () =>
171171
{
172172
needsDrawCalls = true;
173173
};
@@ -524,7 +524,7 @@ private void UpdateAccumulator()
524524
needsDrawCalls = false;
525525
}
526526

527-
accumulator = Time.Accumulator;
527+
accumulator = Time.accumulator;
528528
}
529529
#endregion
530530

512 Bytes
Binary file not shown.
1 KB
Binary file not shown.

0 commit comments

Comments
 (0)