-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFPSCounter.cs
52 lines (47 loc) · 1.35 KB
/
FPSCounter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace ActionGame
{
class FPSCounter
{
private List<double> tmp = new List<double>();
public int bufferSize=30;
private int fpsResult=0;
private int count=0;
// System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
public float getDeltaTime(GameTime gameTime)
{
var delta = (float)gameTime.ElapsedGameTime.Milliseconds;
// Console.WriteLine(n);
// sw.Stop();
// double res = sw.ElapsedMilliseconds ;
// sw.Reset();
// sw.Start();
return delta;
}
public int fpsCounter(double delta)
{
tmp.Add(1/delta*1000);
if (count == bufferSize)
{
int total=0;
foreach (int i in tmp)
{
total += i;
}
fpsResult = total / bufferSize;
if (fpsResult < 0) fpsResult = 0;
tmp.Clear();
count = 0;
}
count++;
return fpsResult;
}
}
}