1
+ using Nanoforge . Misc . Containers ;
1
2
using System . Collections ;
2
3
using System . Diagnostics ;
3
4
using System . Reflection ;
@@ -16,11 +17,31 @@ namespace Nanoforge.App
16
17
17
18
public class FrameData
18
19
{
19
- ///Amount of time this frame that work was being done. Delta time can be larger if the target framerate is slower than the current framerate
20
+ ///Amount of time this frame that work was being done. DeltaTime includes time waiting for target framerate. This doesn't.
20
21
public f32 RealFrameTime ;
21
22
22
23
///Total time elapsed last frame. Includes time waiting until target framerate if there was time to spare
23
24
public f32 DeltaTime ;
25
+
26
+ ///Number of frames to sample AverageFrameTime
27
+ public const int NumFrametimeSamples = 30 ;
28
+
29
+ ///Last N real frametimes. Used to calculate AverageFrameTime
30
+ public append RingBuffer < f32 , 30 > AverageFrametimeSamples ;
31
+
32
+ ///Average of last N RealFrameTime values. Use when you want a more stable value for UI purposes. The real value can fluctuate frame by frame
33
+ public f32 AverageFrameTime
34
+ {
35
+ get
36
+ {
37
+ f32 result = 0.0f ;
38
+ for ( f32 v in AverageFrametimeSamples. [ Friend ] _data) //TODO: Fix the RingBuffer enumerator
39
+ result += v;
40
+
41
+ return result / AverageFrametimeSamples. Size;
42
+ }
43
+ } ;
44
+
24
45
}
25
46
26
47
//System stages. Run each frame in this order.
@@ -116,6 +137,7 @@ namespace Nanoforge.App
116
137
117
138
//Wait until target frametime
118
139
frameData. RealFrameTime = ( f32 ) _frameTimer . ElapsedMicroseconds / 1000000.0f ;
140
+ frameData. AverageFrametimeSamples . Push ( frameData . RealFrameTime ) ;
119
141
while ( ( ( float ) _frameTimer . ElapsedMicroseconds / 1000000.0f ) < _maxFrameRateDelta )
120
142
{
121
143
0 commit comments