I have seen different "basic" game loops both from books like "Introduction to 3D game programming with DX11" or online tutorial ( Rastertek ) and if we take off all the fancy stuff to control framerate and more they all look roughly like this :
while (msg != WM_QUIT) //
{
if (PeekMessage(&msg,0,0,0,PM_REMOVE)
{
// Translate and dispatch message
}
else
{
// Do update, rendering and all the real game loop stuff
}
}
If you run it this way it works perfectly, but the thing that i do not understand is the else. If i look naively at the loop i might think that if the system keeps sending events ( key presses, mouse clicks and more ) the else part will never be executed, am i wrong ? ( yes!! i am but this is exactly the point, i don't understand why! ).
I'd like to understand why the loop works this way. If the messages were strictly related to the window ( resizing,moving,closing ) i'd understand it, but they are not. Let's say that i keep pressing any key a WM_KEYDOWN message is repeatedly sent and a message is peeked, thus never allowing the else part to execute
I have not a lot of experience with the Win32 library and i'm probably missing something^^.
Thank you for your time and happy coding!