Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. what do you think of my message loop for DirectX proj

what do you think of my message loop for DirectX proj

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsgame-devdiscussion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tom_dx
    wrote on last edited by
    #1

    MSG msg; while( TRUE ) { if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { if ( msg.message == WM_QUIT ) { break; } TranslateMessage( &msg ); DispatchMessage( &msg ); } } IM PROUD TO BE A GMAIL;

    C S 2 Replies Last reply
    0
    • T tom_dx

      MSG msg; while( TRUE ) { if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { if ( msg.message == WM_QUIT ) { break; } TranslateMessage( &msg ); DispatchMessage( &msg ); } } IM PROUD TO BE A GMAIL;

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Yes, it's a message loop and ...??? What is EXACTLY the question ?

      T 1 Reply Last reply
      0
      • C Cedric Moonen

        Yes, it's a message loop and ...??? What is EXACTLY the question ?

        T Offline
        T Offline
        tom_dx
        wrote on last edited by
        #3

        do you think this would be substantially enough for a DX game? IM PROUD TO BE A GMAIL;

        1 Reply Last reply
        0
        • T tom_dx

          MSG msg; while( TRUE ) { if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { if ( msg.message == WM_QUIT ) { break; } TranslateMessage( &msg ); DispatchMessage( &msg ); } } IM PROUD TO BE A GMAIL;

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #4

          Because you're using PeekMessage rather then GetMessage your loop spins in the outer while loop even when there is no message to process. Unless you have an else not show in the code above in the if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) statement this code is needlessly inefficient. I would suggest you replace it with a GetMessage and watch the CPU usage go down. Steve

          T 1 Reply Last reply
          0
          • S Stephen Hewitt

            Because you're using PeekMessage rather then GetMessage your loop spins in the outer while loop even when there is no message to process. Unless you have an else not show in the code above in the if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) statement this code is needlessly inefficient. I would suggest you replace it with a GetMessage and watch the CPU usage go down. Steve

            T Offline
            T Offline
            tom_dx
            wrote on last edited by
            #5

            thank you for the comment, and yes I do have an else statement in the block but forgot to write it in. so you think it will still be good if it has an else block or should i stick with getmessage? IM PROUD TO BE A GMAIL;

            S 1 Reply Last reply
            0
            • T tom_dx

              thank you for the comment, and yes I do have an else statement in the block but forgot to write it in. so you think it will still be good if it has an else block or should i stick with getmessage? IM PROUD TO BE A GMAIL;

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              Normally you'd use PeekMessage and perform some idle time processing in the else part. I'm not sure what's going on in the else bit but it looks ok to me. I find myself a little concerned that you may be busy waiting but I'd have to see the else bit to be sure. Steve

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups