Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

hi-res counter

Name: Anonymous 2008-10-25 23:17

So I'm coding a game and trying to maintain a steady game speed (ie. framerate) and I found some Windows functions called QueryPerformanceCounter and QueryPerformanceFrequency.

Using these looks more reliable for controlling a game loop than say, clock() shit from time.h or something.  The only problem is that I've seen this:

>If the installed hardware supports a high-resolution performance counter

I've tried it and it works 100% fine on my machine.  But I'm wondering what sort of hardware would NOT support this?  Is it likely that if I distributed my game that many users would not have the performance counter?

Name: Anonymous 2008-10-26 1:37

Use OpenGL, it has a FPS feature built in.

Name: Anonymous 2008-10-26 3:25

If it's a Pentium or newer, it has the performance counters. However, they're not reliable if the system's clock frequency changes (eg. if you have something like SpeedStep active). There's also some issues with SMP systems.

Name: Anonymous 2008-10-26 12:32

>>3
However, they're not reliable if the system's clock frequency changes (eg. if you have something like SpeedStep active).

That is ungodly annoying. Ever try to play Deus Ex on a modern system? You've got to set you CPU to some constant speed or it goes all to shit.

Name: Anonymous 2008-10-26 13:05

>>3
Shitty.  So other than that OpenGL feature that >>2 mentioned, what could I use for reliable timing?

Name: Anonymous 2008-10-26 13:11

>>5
On Windows you can use timeGetTime. It supports a resolution of 1ms.

Name: Anonymous 2008-10-26 13:35

Oh boy, this sure is fucking stupid.

Someone link me to a good tutorial on writing a game-loop because Google only gives me SHIT and I'm getting tired of juggling stupid variables and trying to figure this out.

Name: Bro 2008-10-26 14:04

Bro, DIY, bro.

Name: Anonymous 2008-10-26 15:24

>>8
Word.

I've got most of it figured out.  I just need to make sure that my shit (ie. drawing and handling game input/state) is only performed x number of times per second.

Name: Anonymous 2008-10-26 17:30

alright, finally got over the framerate issues.

Unfortunately SDL_BlitSurface crashes no matter what I fucking do but eh...  maybe I'll work out the problem after another good 15 hours of slaving over it

Name: Anonymous 2008-10-26 17:45

>>10
Read SICP and use HSDL.

Name: Anonymous 2008-10-26 18:04

>>1

QueryPerformanceFrequency and Counter do not work on multiprocessor machines unless you do something like call

SetProcessAffinityMask(GetCurrentProcess(), 1L);

But I dunno because I only have 1 processor.

Name: Anonymous 2008-10-26 19:27

>>12
IIRC they work if you have a HPET, and your OS supports it. Of course, you can't rely on that.

And of course setting the affinity mask is fairly retarded. Imagine if everything did that.

Name: Anonymous 2008-10-26 19:33

>>12,13
Alright thanks, I think I'm just going to stick with GetTickCount() as someone suggested because it's working great for me and I don't want to break my code again.

Name: Anonymous 2008-10-26 20:30

>>14
Make sure to also support GetTickCount64 where possible. Otherwise, the counter rolls back every 49.7 days.

Name: Anonymous 2011-02-03 6:11

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List