
Originally Posted by
Pix
By "message pump" I meant the translatemessage/dispatchmessage loop, not wndproc.
So did I.
This is a fairly standard game loop.
Code:
//the message pump
while (true)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
Sleep(1); //do not max out processor
Renderer.Render();
}
}
Where the render function would handle updating your position and timer, and drawing to the screen. It will throw up a new frame once per loop, presuming there are no pending messages going through (which, 99% of the time, there won't be).
At any rate, so let's say I wanted, like i said, a simple planet orbiting a sun, and let's say that 60hz updates are good enough: I could set up a 60hz wm_timer, and then update the position of the planet, and then i render frames in, what, wm_enteridle? Or am I barking up the wrong tree here?
Is there such a message? I hadn't heard of that one, heh. Nah, use the "else" part of the message pump to catch your idle time. Safer that way (once you get into D3D, messages are something you should stay away from for most things. The WndProc part of typical game programs is very short).
I mentioned wm_timer because I don't know how to use the high precision timers yet.
Check into the QueryPerformanceCounter and QueryPerformanceFrequency functions. They are not really very difficult to use. They do have their own set of bugs on some CPUs, but you can probably ignore them (most people do).
You can use another timer (like GetTickCount()) easier, I suppose, but I think you will probably have to check for 0 time passed and make sure you don't get any divide by zero errors from them. I'd imagine (because of their imprecision) you might get a little bit of jerkyness/jitter in your animations from them. But you'd have to try it out to see what happens.