Skip to main content
gamedev.net
🔒 Locked

message loop

Started by idinkin May 7, 2004 at 1:34 PM 4 replies 1k views
Original Post
idinkin
idinkin
while(!bDone)
	{
		if(PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
		{
			if(msg.message==WM_QUIT)
			{
				bDone=TRUE;
			}
			else
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}
		else
		{
			if(keys[VK_ESCAPE]) //<------- o_O
			{
				bDone=TRUE;
			}
			else
			{
				DrawScene();
				SwapBuffers(hDC);
			}
		}
	}
 
The problem is the program never gets to the pointed line. And when I start the application it uses 90% of my CPU... The only way not to get there is to have an infinite number of messages in the queue but why????

It does not matter what you will reach in your life, but the way you will reach it
Sometimes movement is a result of a kick in the ass!
Oluseyi
Oluseyi
With PM_NOREMOVE you''ll be handling the same message - whichever is sent to the applications various message queues first - forever. With a NULL HWND parameter, there''s no need to test msg.message separately; use the return value of PeekMessage to determine when to exit the loop.

Obviously, because PeekMessage returns a non-zero value when there''s a message waiting, that portion of the loop will always get executed while the else clause never does.

As for using 99% of CPU, PeekMessage doesn''t block. Any insistently executing loop will max out CPU load.
idinkin
idinkin
Thanks, now it works...
But I have another problem - I have got very low fps...
I think 0.1 fps and I don't draw anything. Why?



It does not matter what you will reach in your life, but the way you will reach it

[edited by - idinkin on May 7, 2004 3:17:47 PM]
Sometimes movement is a result of a kick in the ass!
idinkin
idinkin
I tried running the glExtensionViewer tests and I have got 0 fps in each of them. I've seen only the first frames of those. NeHe tutorials are running the same. What might be the problem?

[edited by - idinkin on May 8, 2004 1:22:55 AM]
Sometimes movement is a result of a kick in the ass!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.