Hello all. I'm working on a GAPI library to use in my games going forward (I prefer writing my own for numerous reasons). The question I have isn't really GAPI-related, but it's probably pretty basic...
In the game I'm working on, I use the following main game loop:
A pretty standard "real-time" game loop I think. Now, my problem is this... I just today added the timer checks because this loop without it runs at ridiculous speeds (200+ in the emulator, >100 on my real E-125). Obviously I need to throttle it. So, I added what you see there.
Now, the line where I add 10 to LastTickCount I was thinking I should just divide 1000 by the desired FPS (30 FPS in this case), and that's what I plug in there. My logic being, 1000 milliseconds in a second, and since I want 30 FPS, I want a frame generated every 33 milliseconds.
Well, doing the math on 30 FPS means I should add 33, but that didn't work out right, it was too slow, so I trial-and-error'ed it down to 10, which gives me ~45 on the emulator very steadily, so even though I figure it's the overhead of the rest of the loop making the math not work out right, that's not even actually my problem!
My problem is that even though as I said I get 45 FPS steady in the emulator, my E-125 still runs far faster than it should be (60+ on some screens, 50 on some others, etc). It doesn't seem to make sense like it does in the emulator (even ignoring the math for a moment, at least it's a steady frame rate there all the time).
So, after a huge explanation, my question boils down to this: assuming I'm doing the loop right in the first place, which I think I am having read a number of things on it, how can I accurately and reliably throttle that loop down to s epecified frame rate, assuming the call to MainLoopHandler(), which is where I do all my game logic and screen updating, can generate the frame rate (which it can in this case) and be sure it works across most if not all current PocketPC devices? (I say that because I know about QueryPerformanceCounter, but that seems to be OEM-specific and therefore probably not safe to rely on).
ANY and ALL help is greatly appreciated on this!
In the game I'm working on, I use the following main game loop:
- Code:
DWORD LastTickCount = GetTickCount();
DWORD CurrentTickCount = LastTickCount;
PeekMessage(&msg;, NULL, 0, 0, PM_NOREMOVE);
while (msg.message != WM_QUIT) {
if (PeekMessage(&msg;, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg;);
DispatchMessage(&msg;);
} else {
CurrentTickCount = GetTickCount();
if (CurrentTickCount > (LastTickCount + 10)) {
LastTickCount = CurrentTickCount;
MainLoopHandler();
}
}
}
A pretty standard "real-time" game loop I think. Now, my problem is this... I just today added the timer checks because this loop without it runs at ridiculous speeds (200+ in the emulator, >100 on my real E-125). Obviously I need to throttle it. So, I added what you see there.
Now, the line where I add 10 to LastTickCount I was thinking I should just divide 1000 by the desired FPS (30 FPS in this case), and that's what I plug in there. My logic being, 1000 milliseconds in a second, and since I want 30 FPS, I want a frame generated every 33 milliseconds.
Well, doing the math on 30 FPS means I should add 33, but that didn't work out right, it was too slow, so I trial-and-error'ed it down to 10, which gives me ~45 on the emulator very steadily, so even though I figure it's the overhead of the rest of the loop making the math not work out right, that's not even actually my problem!
My problem is that even though as I said I get 45 FPS steady in the emulator, my E-125 still runs far faster than it should be (60+ on some screens, 50 on some others, etc). It doesn't seem to make sense like it does in the emulator (even ignoring the math for a moment, at least it's a steady frame rate there all the time).
So, after a huge explanation, my question boils down to this: assuming I'm doing the loop right in the first place, which I think I am having read a number of things on it, how can I accurately and reliably throttle that loop down to s epecified frame rate, assuming the call to MainLoopHandler(), which is where I do all my game logic and screen updating, can generate the frame rate (which it can in this case) and be sure it works across most if not all current PocketPC devices? (I say that because I know about QueryPerformanceCounter, but that seems to be OEM-specific and therefore probably not safe to rely on).
ANY and ALL help is greatly appreciated on this!