-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.cs
41 lines (37 loc) · 1 KB
/
timer.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
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text;
namespace hands_viewer.cs
{
class FPSTimer
{
[DllImport("Kernel32.dll")]
private static extern bool QueryPerformanceCounter(out long data);
[DllImport("Kernel32.dll")]
private static extern bool QueryPerformanceFrequency(out long data);
private MainForm form;
private long freq, last;
private int fps;
public FPSTimer(MainForm mf)
{
form = mf;
QueryPerformanceFrequency(out freq);
fps = 0;
QueryPerformanceCounter(out last);
}
public void Tick()
{
long now;
QueryPerformanceCounter(out now);
fps++;
if (now - last > freq) // update every second
{
last = now;
form.UpdateFPSStatus("FPS=" + fps);
fps = 0;
}
}
}
}