0
\$\begingroup\$

I'm developing a simple Win game. Here is my 2 similar implementations of the game loop (in c++):

approach #1:

while (Msg.message != WM_QUIT) {

        if (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE) > 0) {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
        else {
            // Do update, rendering and all the real game loop stuff
        }
}

approach #2:

while (Msg.message != WM_QUIT) {

        if (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE) > 0) {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
        
        // Do update, rendering and all the real game loop stuff
        
}}

My question is which one is better and which one should i choose? Is it better to do the update and rendering stuff in the else closure as in the #1 approach or just in the while loop block as in the #2 approach?

\$\endgroup\$
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.