CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2017
    Posts
    12

    Designing a game loop.

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

    approach #1:

    Code:
        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:

    Code:
        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?

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Designing a game loop.

    Neither of those would work. You've coded a message pump. Ideally, you'd be using different threads, but typically you'd call your message pump from inside a tight loop elsewhere in the program rather than calling your other code from inside the message pump.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured