Original Post
I'm looking through a friend's source (I believe he originally based it from someone's book?) as he's using up 100% of his cpu cycles when running a very simple app. I'm certain it comes from this chunk as when I added the "else { Sleep(iTickTrigger ... " lines it dropped significantly. Anyway, is this the best way to handle it? It seems so to me but I don't want to misinform. Thanks ahead.
[edited by - kordova on May 3, 2003 2:34:42 PM]
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
MSG msg;
static int iTickTrigger = 0;
int iTickCount;
if (GameInitialize(hInstance))
{
// Initialize the game engine
if (!GameEngine::GetEngine()->Initialize(iCmdShow))
return FALSE;
// Enter the main message loop
while (TRUE)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
// Process the message
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
// Make sure the game engine isn't sleeping
if (!GameEngine::GetEngine()->GetSleep())
{
// Check the tick count to see if a game cycle has elapsed
iTickCount = GetTickCount();
if (iTickCount > iTickTrigger)
{
iTickTrigger = iTickCount +
GameEngine::GetEngine()->GetFrameDelay();
GameCycle();
}
else {
Sleep((iTickTrigger-iTickCount));
}
}
}
}
return (int)msg.wParam;
}
// End the game
GameEnd();
return TRUE;
}
