Hard question.

Started by
1 comment, last by iMalc 18 years, 7 months ago
 	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...............
Advertisement
if (timeDelta>.02)
{ // do stuff
ptr_display(timeDelta);
lastTime = currTime;
}
else
{ // wait to do stuff
::Sleep( currTime -lastTime );
}
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.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

This topic is closed to new replies.

Advertisement