Jump to content
  • Advertisement
Sign in to follow this  
luasitdown

Hard question.

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

 	MSG msg;
	::ZeroMemory(&msg, sizeof(MSG));

	static float lastTime = (float)timeGetTime(); 

	while(msg.message != WM_QUIT)
	{
		if(::PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
		{
			::TranslateMessage(&msg);
			::DispatchMessage(&msg);
		}
		else
        {	
		float currTime  = (float)timeGetTime();
			float timeDelta = (currTime - lastTime)*0.001f;
			
			if (timeDelta>.02)
			{ptr_display(timeDelta);
			lastTime = currTime;} 
        }
    }
    return msg.wParam;
}
How to make cpu idle ? I try to do ,can not find a solution. I see someone game cpu ocuppy only 1%. Mulitthread ? or...............

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
if (timeDelta>.02)
{ // do stuff
ptr_display(timeDelta);
lastTime = currTime;
}
else
{ // wait to do stuff
::Sleep( currTime -lastTime );
}

Share this post


Link to post
Share on other sites
Just call Sleep in your main loops. It takes 1 parameter which is the number of milliseconds to sleep. Even passing it a 1 will make a HUGE difference without really impacting on your program. You can even pass it 0 if you like, to only give time to threads of a higher priority class.

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!