All the lesson samples use 100% CPU

Started by
2 comments, last by yukuang 15 years, 2 months ago
(I'm sorry for my poor English) After searching all the webpages on Gamedev.net, two solutions were mainly metioned: 1. Sleep(...). It's the worst way and it caused lower performance. 2. Use Timer. It seems not the fundamental solution. I want to know in the popular games, such as CS, how to resolve it. Much obliged.
Advertisement
Quote:Original post by yukuang
I want to know in the popular games, such as CS, how to resolve it.
They use 100% of the CPU. If the game is running fullscreen, then the player is obviously playing it so using 100% of the CPU is perfectly fine. Similarly if it's in windowed mode and the window is in focus.

When the game is minimized, you could switch to using GetMessage() instead of PeekMessage() in your main loop, which will cause you to drop to 0% CPU usage until the game is restored.
Or you can catch WM_ACTIVATE messages and set a flag when the application is deactived and stop rendering etc. until the app is activated again.

http://msdn.microsoft.com/en-us/library/ms632614.aspx

Here is how it looks in a message loop :
WPARAM WndApp::messageLoop()    {	    MSG msg;initApplication();			            while(m_Running){		    if(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)){			    if (msg.message == WM_QUIT){				    m_Running		= false;				                                 }			    TranslateMessage(&msg);					    DispatchMessage(&msg);		    }		    else{			    if(WndApp::m_ApplicationActive == false){				    WaitMessage();			    }			    else{				    mainLoop();			    }		    }	    }	    return (msg.wParam);    }
Thanks to Evil Steve and Black Knight. I'm awfully sorry about my inexplicit expression in the topic. In fact I'm trying to design a window game(NOT fullscreen), and this my plan:
a) when it's active, the window is continuously being rendered.
b) when NEITHER active nor minimal, for example partially coverd by another appliction, the window is still constantly being rendered because part of it is seen by us.
I've learned the lessons01-10 from nehe.gamedev.net, but Its examples always use 100% CPU either active or deactive(even minimised). In my item (b) it seems can't be tolerated because it causes another application which is being simultaneously used lower performance. How to design my "message loop"?

Another uncertain question, in OpenGL if we have to MANUALLY render the context by using for(;;) loop or timer? Are there any auto mechanism to do this?

I really appreciate your help, and any suggestions are costful.

This topic is closed to new replies.

Advertisement