Archived

This topic is now archived and is closed to further replies.

Eponick

Main loop problems?

Recommended Posts

I was wondering why my window seems to be going EXTREEMLY slow with my main game loop? heres the code for the DoMessage class:
void NEWWINDOW::DoMessage()
{
	while(1)
	{
		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
				break;

			MainLoop();

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			MainLoop();
		}
	}
} 
And inside my main loop is just a thing to draw some simple graphics and flip the backbuffer to the front. Its never done this in any of my other games, but now that im implementing the loop straight into my game core its being very slow.

Share this post


Link to post
Share on other sites
What about if someones hitting a key?
Then it wont do the MainLoop will it?

Well, I took it out and its still doing the same thing.

[edited by - Eponick on July 5, 2003 3:23:45 AM]

Share this post


Link to post
Share on other sites
Here's my main loop:

//=========================================================
// Game Code Complete reference: Chapter 7, page 227
//=========================================================

MSG msg;
ZeroMemory( &msg, sizeof(msg) );
while( msg.message!=WM_QUIT )
{
// Part 1: Do idle work until a message is seen in the message queue
while (!PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE))
{
g_App.MainLoop();
}

// Part 2: Pump messages until the queue is empty
do
{
if (GetMessage(&msg, NULL, NULL, NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

} while (PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE));
}



Also, inside the call to MainLoop(), I call Win32's Sleep() API to keep the game from sucking up all the CPU time. I find calling it with 2ms - Sleep(2) - seems to work well.

This might not solve your speed problem, but it should solve user interface response time issues. If you have a framerate issue you might begin your search for the problem inside your main loop.

I hope this helps!


Cheers,

Mike McShaffry
===================================================
mrmike@mcshaffry.com (http://www.mcshaffry.com)



[edited by - mrmike on July 5, 2003 2:11:13 PM]

[edited by - mrmike on July 5, 2003 2:12:31 PM]

[edited by - mrmike on July 5, 2003 2:13:21 PM]

[edited by - mrmike on July 5, 2003 2:14:12 PM]

Share this post


Link to post
Share on other sites