Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How to use QPC

This thread is locked; no one can reply to it. rss feed Print
How to use QPC
Road Runner
Member #7,280
May 2006

I've been wanting to use QueryPerformanceCounter for quite some time, and I checked out the Microsoft documentation hoping to find out everything I need to know, but what I found was a bunch of Windows code that didn't make an ounce of sense.
So I guess I need a little help with figuring out how to use QPC with Allegro.

Just so I don't get scolded for not trying to figure it out myself, I'm a busy high schooler who barely has any free time, and I'm used to reading the Allegro docs, which I find very easy to understand, but the Microsoft docs on the other hand...
Anyway, sorry to pester you all with a dumb question, but I really need help.

Paul whoknows
Member #5,081
September 2004
avatar

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

Road Runner
Member #7,280
May 2006

Thanks, that looks good. I think that's all I really need, but I'm new at programming so I really want to understand how to use QPC myself, so that I can wrap it in whatever code I want. Maybe I should have been more specific in the first place. :-/

23yrold3yrold
Member #1,134
March 2001
avatar

1#define WIN_ANIME_TIMERLOOP 0x7fffffffffffffffLL
2__int64 animation_timer;
3__int64 frequency;
4 
5__int64 WinGetAnimationTime() { return animation_timer; }
6 
7void WinInstallAnimationTimer()
8{
9 QueryPerformanceFrequency(( LARGE_INTEGER* )&frequency);
10 // (higher == faster, lower == slower)
11 frequency /= 500;
12 QueryPerformanceCounter(( LARGE_INTEGER* )&animation_timer);
13 animation_timer /= frequency;
14}
15 
16void WinUpdateAnimationTimer()
17{
18 QueryPerformanceCounter(( LARGE_INTEGER* )&animation_timer);
19 animation_timer /= frequency;
20}
21 
22__int64 WinGetRelativeAnimationTime(__int64& oldtime)
23{
24 __int64 t = oldtime;
25 oldtime = animation_timer;
26 
27 if(t > oldtime)
28 return ((WIN_ANIME_TIMERLOOP - t) + oldtime);
29 else
30 return (oldtime - t);
31}

That's more or less how I use it. Shouldn't be hard to decipher. Basically just use QueryPerformanceFrequency() and QueryPerformanceCounter() to make it track the same speed on all systems, and reference it for all your timing needs.

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Road Runner
Member #7,280
May 2006

I'll just use it until I understand how it works then, and yeah, it's pretty simple code, so it shouldn't take long for me to decipher it.

Go to: