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;
}
Hard question.
if (timeDelta>.02)
{ // do stuff
ptr_display(timeDelta);
lastTime = currTime;
}
else
{ // wait to do stuff
::Sleep( currTime -lastTime );
}
{ // 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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement