void BaseApp::Run() { CStopwatch timer; int sum = 0; int counter = 0; int deltaTime = 0; while (1) { timer.Start(); if (kbhit()) { KeyPressed (getch()); if (!FlushConsoleInputBuffer(mConsoleIn)) cout<<"FlushConsoleInputBuffer failed with error "<<GetLastError(); } UpdateF((float)deltaTime / 1000.0f); Render(); Sleep(1); while (1) { deltaTime = timer.Now(); if (deltaTime > 20) break; } sum += deltaTime; counter++; if (sum >= 1000) { TCHAR szbuff[255]; StringCchPrintf(szbuff, 255, TEXT("FPS: %d"), counter); SetConsoleTitle(szbuff); counter = 0; sum = 0; } } }
void CEngine::RunGameLoop() { // Enter the message loop MSG msg; ZeroMemory(&msg, sizeof(msg)); #ifdef USE_DISP_FPS char text[256] = {"\0"}; #endif while (msg.message != WM_QUIT) { if (PeekMessage(&msg, nullptr, 0U, 0U, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { #ifdef USE_DISP_FPS CStopwatch sw; sw.Start(); #endif GameTime().Update(); //キー入力を更新。 m_keyInput.Update(); m_skinModelDataResources.Update(); m_physicsWorld.Update(); CRenderContext& topRenderContext = m_renderContextArray[0]; CRenderContext& lastRenderContext = m_renderContextArray[m_numRenderContext - 1]; topRenderContext.SetRenderTarget(0, &m_mainRenderTarget[m_currentMainRenderTarget]); //topRenderContext.SetRenderTarget(0, &m_backBufferRT); topRenderContext.SetRenderTarget(1, NULL); CGameObjectManager& goMgr = CGameObjectManager::Instance(); goMgr.Execute( m_renderContextArray.get(), m_numRenderContext, m_renderContextMap.get(), m_preRender, m_postEffect ); lastRenderContext.SetRenderTarget(0, &m_backBufferRT); lastRenderContext.Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_RGBA(0, 0, 0, 0), 1.0f, 0 ); CopyMainRenderTargetToBackBuffer(lastRenderContext); m_pD3DDevice->BeginScene(); //レンダリングコマンドのサブミット for( int i = 0; i < m_numRenderContext; i++ ){ m_renderContextArray[i].SubmitCommandBuffer(); } // 描画 #ifdef USE_DISP_FPS m_fpsFont.Draw(text, 0, 0); #endif m_pD3DDevice->EndScene(); m_pD3DDevice->Present(nullptr, nullptr, nullptr, nullptr); // #ifdef USE_DISP_FPS sw.Stop(); sprintf(text, "fps = %lf\n", 1.0f / sw.GetElapsed()); #endif } } }