int Client::Run(){ //消息循环 MSG msg; uint32 timeLastUpdate = sTimer.GetStart(); while(true) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { //处理消息 if (msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } else { //处理游戏逻辑 uint32 now = sTimer.GetNow(); uint32 timeElapse = now - timeLastUpdate; if(timeElapse > 30) { sClient.Update(timeElapse); timeLastUpdate = now; } else { ::Sleep(1); } } } UnLoadContent(); return msg.wParam ; }
int __stdcall WinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd) { // 初始化Instance,创建窗口,初始化d3d工作 HRESULT hr = 0; hr = InitInstance(hInstance, g_WndWidth, g_WndHeight, true, false, g_DevType, &g_pDevice); if (FAILED(hr)) { MessageBox(0, "Faile to init instance!", 0, 0); return 0 ; } // 保存窗口句柄 g_hWnd = GetActiveWindow(); if (!g_hWnd) { MessageBox(0, "Failed to get windows handle!", 0, 0); return 0; } // 游戏设置 hr = SetUp(); if (FAILED(hr)) goto Clean; // 加载游戏内容 hr = LoadContent(); if (FAILED(hr)) goto UnLoad; // 游戏循环 EnterMsgLoop(); // 卸载游戏内容 UnLoad: UnLoadContent(); // 清除 Clean: CleanUp(); return 0; }
DeferredLightManager::~DeferredLightManager() { UnLoadContent(); }