Advertisement

Lag when calling main game function from event loop.

Started by March 02, 2002 02:24 PM
1 comment, last by yasha 22 years, 6 months ago
When I call my Game_Main function from the event loop the program runs very unevenly. There are long pauses then the program catches up. Game_Main isn''t doing much other than updating the locations of a couple of objects, and blting them to a back buffer then flipping the primary and secondary surfaces. The jerkiness is alleviated and everything appears to run smoothly if I start a timer, even though I don''t do anything with the timer messages. The event loop is:

while(TRUE)
	
	{
	if (PeekMessage( &lpMsg, NULL, 0, 0, PM_REMOVE ) )					// begin the message loop 
		{
			if (lpMsg.message == WM_QUIT)
				break;		
			TranslateMessage( &lpMsg );
			DispatchMessage( &lpMsg );
			Game_Main(NULL, 0);
		}
	}
 
This is being run on Win2K. Any suggestions? Thanks, Aaron
It's because you're only calling the game function if you have received a windows message. You should take the Game_Main call out of that if statement (but keep it in the infinite loop).

When you set a timer, windows will keep sending you messages, which was why it worked when you tried that.

John B

Edited by - JohnBSmall on March 2, 2002 3:37:08 PM
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
Advertisement
Aha!
I knew it was something like that. Thanks! This is the problem with learning all your C++ on Unix/console apps.

-Aaron

This topic is closed to new replies.

Advertisement