Jump to content
  • Advertisement
Sign in to follow this  
Sync Views

problem with windows

This topic is 3892 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

For some reason the windows "close" button is highly unresponsive. I need to click it several times before it ends the game. If I right click the program in the task bar and click close it closes instantly. I made it so that the message loop runs 100 times a second even though every thing else is capped to 30 but that doesn't seem to have helped... What can I do to make this work propley?
	while (game_run)
	{
		//if (PeekMessage (&msg,NULL,0,0,PM_REMOVE))
		if (PeekMessage (&msg, hwnd, NULL, NULL, PM_REMOVE))
		{
			if (msg.message == WM_QUIT) break;
			TranslateMessage (&msg);
			DispatchMessage (&msg);
        }
		
		TranslateMessage(&msg);
		DispatchMessage(&msg);

		//allows the message loop to keep running by only delay 10ms max		
		time_wait = (1000/game_speed) - (clock() - time_last);
		if (time_wait > 0 && time_wait > 10) Sleep(10);
		else if (time_wait > 0 && time_wait < 10)
		{
			Sleep(time_wait);
			time_wait = 0;
		}
		else time_wait = 0;

		//only run if delay is over
		if (time_wait == 0)
		{
			time_last = clock();
			
			if (getdimmer)
			{
				background_r -= 1;
				background_g -= 1;
				background_b -= 1;
			}
			else
			{
				background_r += 1;
				background_g += 1;
				background_b += 1;
			}
			if      (background_r == 0)   getdimmer = false;
			else if (background_r == 255) getdimmer = true;
			game_draw();
		}
	}

Share this post


Link to post
Share on other sites
Advertisement
1)
Remove the hwnd from PeekMessage. You won't get WM_QUIT if you provide a HWND

2)
Remove the second Translate/DispatchMessage pair outside the if. If PeekMessage did not return a message you end up trying to process the last message again and again.


Show your WindowProc, there might be a problem as well.
Also 10ms is quite slow, there's a hell of a lot of messages being sent, esp. with mouse controls.

Share this post


Link to post
Share on other sites
At the end of the while loop place a sleep(1); to allow the OS to catch messages.
Here is my sample main loop that has served me well in all my applications so far to date.

while (msg.message != WM_QUIT) {
if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) {
if (!IsWindow(hwnd) || !IsDialogMessage(hwnd, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} else {

}

Sleep(1);
}

Share this post


Link to post
Share on other sites
Process all pending messages before updating your game. Currently, you only process one message per iteration.

Share this post


Link to post
Share on other sites
It's not the issue here (suggestions above should solve your problem nicely, unless wndproc has something awful in it) but if you're running something pretty hardware intensive in a window and you're doing a lot of processing in the same thread as you're handling messages, be prepared for a little bit of lag on the windows UI stuff. I'm not advocating multi-threading here (though obviously it has its perks if you have extra processing units) -- just making a point that there's a finite period of time that things require to be executed -- so a little bit of unresponsive windows UI is mostly acceptable :)

OTOH; making the UI -really- unresponsive (delaying WM_QUIT message processing...) scares users -- people like responsive things.

~Shiny

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!