Jump to content
  • Advertisement

Archived

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

Eponick

Main loop problems?

This topic is 5641 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Why are you putting your MainLoop() twice? Your MainLoop() should only be in the else{} part of that statement.

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
Hey, thanks! It was just taking up craploads of CPU time is why windows was working slow.
I used that Sleep(2); and now everything is fine :D

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!