因為項目的原因,需要用游戲引擎HGE,于是分析了一下。
總結(jié):簡單有效,但也過于簡單了,下面是System_Start的注釋!
bool CALL HGE_Impl::System_Start()
{
MSG msg;
POINT pt;
RECT rc;
if(!hwnd) //如果系統(tǒng)沒有初始化
{
_PostError("System_Start: System_Initiate wasn't called");
return false;
}
if(!procFrameFunc) //如果幀函數(shù),沒有實現(xiàn)
{
_PostError("System_Start: No frame function defined");
return false;
}
bActive=true; //HGE進入活動狀態(tài)
for(;;)
{
if(!hwndParent) //如果沒有父句柄
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message == WM_QUIT) break;
// TranslateMessage(&msg);
DispatchMessage(&msg);
continue;
}
}
//取光標的位置,這個光標是屏
GetCursorPos(&pt);
//取客戶端區(qū)域
GetClientRect(hwnd, &rc);
//當光標切換為當前窗口所對應的坐標
MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
//判斷鼠標是否在當前窗口
if(bCaptured || (PtInRect(&rc, pt) && WindowFromPoint(pt)==hwnd)) bMouseOver=true;
else bMouseOver=false;
//
if(bActive || bDontSuspend)
{
do
{
dt = timeGetTime() - t0; //t0以來經(jīng)過的毫秒數(shù),要確定要超過ms退出(相當于等待ms)
}
while(dt < 1);
if( dt >= nFixedDelta ) //如果到了幀的時間
{
fDeltaTime = dt / 1000.0f;
if( fDeltaTime > 0.2f ) //如果超過.2秒
{
if(nFixedDelta) fDeltaTime = nFixedDelta/1000.0f;
else fDeltaTime = 0.01f;
}
fTime += fDeltaTime; //累計游戲的時間
t0 = timeGetTime(); //當前幀處理的時間
if( t0 - t0fps < 1000) cfps++; //小于毫秒時,幀數(shù)加
else //如果超過毫秒時
{
nFPS = cfps; //設置當前秒幀計數(shù)
cfps = 0; //計數(shù)器清
t0fps = t0; //重設計數(shù)時間
}
if( procFrameFunc() ) break; //執(zhí)得幀
if( procRenderFunc ) procRenderFunc(); //如果有渲染,則執(zhí)得渲染
if( hwndParent ) break;
_ClearQueue();
if(!bWindowed && nHGEFPS == HGEFPS_VSYNC) Sleep(1);
}
else
{
if(nFixedDelta && dt+3 < nFixedDelta) Sleep(1);
}
}
else Sleep(1);
}
_ClearQueue(); //清除沒有處理的事件
bActive=false;
return true;
}
本文來自CSDN博客,轉(zhuǎn)載請標明出處:http://blog.csdn.net/zdhsoft/archive/2009/04/24/4106748.aspx