bool KCore::GameFrame() { m_Timer.Frame(); I_Input.Frame(); PreFrame(); Frame(); PostFrame(); return true; }
void CGameWindow::Run() { while (IsOpen()) { CProfiler::BeginFrame(); if (true) { TPROF("CGameWindow::Run"); PreFrame(); if (GameServer()->IsHalting()) { //DestroyGame(); //CreateGame(m_eRestartAction); } float flTime = GetTime(); if (GameServer()) { if (GameServer()->IsLoading()) { // Pump the network CNetwork::Think(); RenderLoading(); continue; } else if (GameServer()->IsClient() && !GameNetwork()->IsConnected()) { //DestroyGame(); //CreateGame(GAMETYPE_MENU); } else { GameServer()->Think(flTime); Render(); } } PostFrame(); } CProfiler::Render(); SwapBuffers(); } }
// Perform one iteration of the main loop in CRuntime::Run() bool CRuntime::Frame(bool present) { // Calculate time delta since old frame, in seconds if (present) { QueryPerformanceCounter((LARGE_INTEGER*)&startTime); timedelta = (double)(startTime - oldTime) / (double)timerFreq; oldTime = startTime; // Apply time scaling (now done in GetTimeDelta) //timedelta *= timeScale; // Kahan summation to minimise rounding errors in timer timerY = (timedelta * timeScale) - timerC; timerT = timer + timerY; timerC = (timerT - timer) - timerY; timer = timerT; // Prevent jumping for modal windows etc. if (GetTimeDelta() >= 1.0) timedelta = 0.0; } #ifndef CONSTRUCT_SDL //Handle all messages while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { // Check for plugin wanting a call to PreTranslateMessage if (!pluginPreMsgHooks.empty()) { list<CRunObject*>::iterator i = pluginPreMsgHooks.begin(); const list<CRunObject*>::const_iterator hooks_end = pluginPreMsgHooks.end(); for ( ; i != hooks_end; ++i) { _D_ENTER(DCS_PLUGIN, *i); // Return 0 from PreTranslateMessage indicates message should be translated/dispatched if ((*i)->PreTranslateMessage(&msg) == 0) { TranslateMessage(&msg); DispatchMessage(&msg); } _D_RUNTIME(); // else, the return was nonzero, indicating the message was translated and should not be dispatched. } } else { TranslateMessage(&msg); DispatchMessage(&msg); } } #ifdef CONSTRUCT_DIRECTX9 // Custom asynchronous window dragging: update if dragging if (dragging) { // End drag when left button up if (!AsyncKeyDown(VK_LBUTTON)) dragging = false; // Still in drag - keep window positioned else { POINT pt; GetCursorPos(&pt); expectedResize = true; SetWindowPos(hWnds.front(), NULL, pt.x - mouseXOffset, pt.y - mouseYOffset, 0, 0, SWP_NOSIZE | SWP_NOZORDER); expectedResize = false; } } #endif // Perform the drawing PreFrame(present); #else SDL_Event Event; //Handle all messages while (SDL_PollEvent(&Event)) { if (Event.type == SDL_QUIT) bRunning = false; } #endif // Quit if (!bRunning) return true; // Is suspended: simply loop round the message pump #ifdef CONSTRUCT_DEBUGGER if (isSuspended) { Sleep(10); return false; } #endif // Run the frame render to window PostFrame(present); // Show windows only after first frame has been rendered if (firstFrame) { WindowIterator w = hWnds.begin(); for ( ; w != hWnds.end(); w++) ShowWindow(*w, SW_SHOW); firstFrame = false; } frameCount++; int clocktimer = clock() - clockOffset; // If set FPS, sleep for any spare time till next frame if (fpsMode == cr::framerate_fixed) { static __int64 fixed_framecount = 0; __int64 userFps64 = userFps; //__int64 tick_time = (__int64)1000 / userFps64; // If more than 2 frames behind scheduled, skip __int64 time_behind_schedule = ((__int64)clock() - clockOffset) - (((__int64)1000 * fixed_framecount) / userFps64); if (time_behind_schedule >= (2 * (__int64)1000) / userFps64) fixed_framecount += (time_behind_schedule * userFps64) / (__int64)1000; // Sleep up to the current scheduled frame, should iron out inaccuracies // with Sleep()'s timing while ((__int64)clock() - clockOffset < ((__int64)1000 * fixed_framecount) / userFps64) Sleep(1); fixed_framecount++; } else if (fpsMode == cr::framerate_vsynced) { // When a vsynced app is hidden, Present() takes no time and it seems to run uncapped. // Cap at 200fps (5ms gaps) __int64 nowTime; QueryPerformanceCounter((LARGE_INTEGER*)&nowTime); while (((nowTime - startTime) * 1000) / timerFreq <= 4) { Sleep(1); QueryPerformanceCounter((LARGE_INTEGER*)&nowTime); } } // New second: update fps counter if (clocktimer >= lastTimer + 1000) { fps = frameCount - lastFrameCount; lastSecondPresentTime = presentTime; presentTime = 0; #ifdef CONSTRUCT_DIRECTX9 if (motionBlur && blurNumSteps != 0) fps /= blurNumSteps; #endif lastFrameCount = frameCount; lastTimer = clocktimer; // Show FPS in caption if specified #if defined(CONSTRUCT_PREVIEW) && !defined(APPRUNTIME) if (fpsInCaption && !fullscreen) { CString caption; char strbuf[256]; GetWindowText(hWnds.front(), strbuf, 256); caption = strbuf; #ifdef CONSTRUCT_DIRECTX9 if (caption.Find("(DX9 runtime") != -1) { caption.Delete(caption.Find("(DX9 runtime"), caption.GetLength()); //if (!motionBlur) // batchesPerPresent = renderer.GetBatchesPerPresent(); CString fpsText; fpsText.Format("(DX9 runtime, %d FPS, %.2f mb VRAM)", fps, (float)renderer.GetTotalTextureMemoryUsage() / 1048576.0f); caption += fpsText; SetWindowText(hWnds.front(), caption); } } #endif #ifdef CONSTRUCT_SDL if (caption.Find("(SDL runtime") != -1) { caption.Delete(caption.Find("(SDL runtime"), caption.GetLength()); CString fpsText; fpsText.Format("(SDL runtime, %d FPS)", fps); caption += fpsText; SDL_WM_SetCaption(caption, NULL); } } #endif #endif }
bool GQuadTree::Frame() { if( !PreFrame() ) return false; DrawFindNode( m_pRootNode ); return true; }