Windows Game Loop双核上有50%CPU [英] Windows Game Loop 50% CPU on Dual Core

查看:82
本文介绍了Windows Game Loop双核上有50%CPU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅游戏循环就占用了50%的CPU使用率,我还没有完成任何渲染工作.我在这里做什么?

The game loop alone is using 50% of CPU Usage, I haven't done any rendering work yet. What I'm doing here?

        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正在忙于检查(并无限检查广告)消息.您需要以阻塞的方式等待消息,或者更有可能的是,使用计时器定期唤醒您的游戏线程以使其正常工作.然后,游戏线程将消失,直到下一次唤醒为止.

Classic busy/wait loop. Your CPU is busily checking (and rechecking ad infinitum) for messages. You need to wait for messages in a blocking way or, more likely, use a timer that periodically wakes up your game thread so it can do its work. The game thread would then go away until the next time it is woken up.

这篇关于Windows Game Loop双核上有50%CPU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆