Sorry if this has been brought up and/or fixed, I'm late to the party and only on day 20 or so. Plus the forums has no search as far as I can tell which is a bit of a bummer.
So in day 18 Casey sets up the game loop as something looking very roughly like:
| while(running) {
Win32GameUpdateAndRender()
Sleep()
Win32DisplayBufferInWindow()
}
|
My question is, doesn't this add what is effectively a frame of input delay and can we deal with that at all?
Here's the example in my mind:
| Game calculates information to display frame 1
Game sleeps for ~1/30th of a second
Game displays frame 2
*almost immediately* Game calculates information to display frame 2
User reacts to game frame 2 that is now displayed and begins input
Game sleeps for ~1/30th of a second (user input continues)
Game displays frame 3
Game calculates information to display frame 4 (includes the user input during previous sleep)
|
The problem is the user input was intended to affect frame 3, but it's not processed until frame 4. The time between frame 2 being displayed and input for frame 3 being collected into the game input struct is near instant. Effectively the user has no time to react to the displayed frame (well sort of, humans have >100ms delay anyways so they would be behind no matter what)
Without the majority of time being spent between rendering one frame and starting the update of the next frame most of the user's input will "miss" making it in to the update for the frame after the one being displayed.
A possible loop without this issue might look like:
| Game Renders frame 1
Game sleeps for ~1/30th of a second
Game calculates information to display frame 2
Game Renders frame 2
|
Except the problem here is any time spent updating the game cannot be accounted for by the sleep duration like the loop used by HH (as of day 18) does.
Now this is a
very minor delay all things considered; many monitors will introduce an equal or longer delay than this anyways. There's also very few games where such minor timings could possibly even matter (Fighting Games being the prime example). It's hardly a big issue and I'd imagine many games have such delay baked in, but since Handmade Hero is all about digging deep into the low level stuff I'd thought I'd bring it up and see if people know how to make the loop tighter, why I'm wrong and there's no delay, or whatever other comments people have.