仅游戏循环就使用了 50% 的 CPU 使用率,我还没有做任何渲染工作。我在这里做什么?
while(true)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT ||
msg.message == WM_CLOSE ||
msg.message == WM_DESTROY)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
//Run game code, break out of loop when the game is over
}
}
最佳答案
经典的忙/等待循环。您的 CPU 正忙于检查(并无止境地重新检查)消息。您需要以阻塞方式等待消息,或者更有可能使用一个定时器来定期唤醒您的游戏线程,以便它可以完成其工作。然后游戏线程将消失,直到下一次被唤醒。
关于winapi - Windows 游戏循环 50% CPU 双核,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2363206/