Timing

Hi there!

I'm reading about timing, and I'm wondering if I got this right.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <Windows.h>

int main()
{
	int FPS = 60;
	LARGE_INTEGER frequency;
	QueryPerformanceFrequency(&frequency);
	LARGE_INTEGER counter;
	QueryPerformanceCounter(&counter);
	LARGE_INTEGER lastUpdate = counter;

	while (true)
	{
		QueryPerformanceCounter(&counter);
		if (counter.QuadPart > (lastUpdate.QuadPart + (frequency.QuadPart / FPS)))
		{
			lastUpdate = counter;

			// ...
			// Are things in here happening every 60 second? \(^o^)/
		}
	}
}


Will this limit Things to exactly 60 FPS, and will it change correctly when I change the FPS variable?

I'm not quite sure how I can measure if it works, because if I add code to show the FPS somehow, that code would rely on what I'm trying to do, which would make it wrong if the code is wrong >:D
Topic archived. No new replies allowed.