if(SUCCEEDED(initD3D(hWnd)))
{
if(SUCCEEDED(init_graphics()))
{
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
MSG msg;
ZeroMemory(&msg, sizeof(MSG));
while(msg.message != WM_QUIT)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
render_frame();
// check the 'escape' key
//if(KEY_DOWN(VK_ESCAPE))
//PostMessage(hWnd, WM_DESTROY, 0, 0);
}
// clean up DirectX and COM
cleanD3D();
}
}
I'm using Win32 API. And when I run the application, the CPU load is loud. And I was wondering how do I get it not be so loud. Heres the loop. Oh its not loud when it's visible, but when you minimize it or put it behind another window that covers it, its loud.
This might not work, but try putting a Sleep(0); after DispatchMessage. It will give up the remainder of the time slice to other processes running. Peek Message is non-blocking, so it will run it as fast as it can. You might also try it after the entire If/Else block.
Quote:Original post by Kiryn
I'm using Win32 API. And when I run the application, the CPU load is loud. And I was wondering how do I get it not be so loud. Heres the loop. Oh its not loud when it's visible, but when you minimize it or put it behind another window that covers it, its loud.
*** Source Snippet Removed ***
Translation of your code snippet:
while(game is running){ if(any messages from Windows) { Use CPU } else { Use CPU }}
No matter what you do, you're using 100% of the CPU.
Catch the WM_SIZE event for when you minimize and start performing short sleep events - say 20-50ms or so. That should stop your application going into a crazily tight loop yet also allow it to respond quick enough to the restore/maximize event...
hth
Jack
hth
Jack
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement