void FrameSkipper::update() { // for the first frame if (initialTicks == 0) { initialTicks = ticksGetTicks(); return; } unsigned int elapsed = ticksGetTicks() - initialTicks; unsigned int realCount = elapsed * targetFPS / 1000; virtualCount++; if (realCount >= virtualCount) { if (realCount > virtualCount && skipType == AUTO && skipCounter < maxSkips) { skipCounter++; } else { virtualCount = realCount; if (skipType == AUTO) skipCounter = 0; } } if (skipType == MANUAL) { if (++skipCounter > maxSkips) skipCounter = 0; } }
void new_vi(void) { int Dif; unsigned int CurrentFPSTime; static unsigned int LastFPSTime = 0; static unsigned int CounterTime = 0; static unsigned int CalculatedTime ; static int VI_Counter = 0; //playAudio(); double AdjustedLimit = VILimitMilliseconds * 100.0 / l_SpeedFactor; // adjust for selected emulator speed int time; start_section(IDLE_SECTION); VI_Counter++; #ifdef DBG if(g_DebuggerActive) DebuggerCallback(DEBUG_UI_VI, 0); #endif if(LastFPSTime == 0) { LastFPSTime = CounterTime = ticksGetTicks(); return; } CurrentFPSTime = ticksGetTicks(); Dif = CurrentFPSTime - LastFPSTime; if (Dif < AdjustedLimit) { CalculatedTime = (unsigned int) (CounterTime + AdjustedLimit * VI_Counter); time = (int)(CalculatedTime - CurrentFPSTime); if (time > 0) { usleep(time * 1000); } CurrentFPSTime = CurrentFPSTime + time; } if (CurrentFPSTime - CounterTime >= 1000.0 ) { CounterTime = ticksGetTicks(); VI_Counter = 0 ; } LastFPSTime = CurrentFPSTime ; end_section(IDLE_SECTION); }
static void runEmulator() { const bool soundOn = (soundEnabled && audioPlayer); if (soundOn) audioPlayer->start(); const int fps = currentGame->fps; const unsigned int frameTime = 1000 / fps; const unsigned int initialTicks = ticksGetTicks(); unsigned int lastTicks = initialTicks; unsigned int virtualFrameCount = 0; int frameSkipCounter = 0; while (emuState == EMUSTATE_RUNNING) { unsigned int now = ticksGetTicks(); unsigned int realFrameCount = (now - initialTicks) * fps / 1000; virtualFrameCount++; if (realFrameCount >= virtualFrameCount) { if (realFrameCount > virtualFrameCount && autoFrameSkip && frameSkipCounter < maxFrameSkips) { frameSkipCounter++; } else { virtualFrameCount = realFrameCount; if (autoFrameSkip) frameSkipCounter = 0; } } else { unsigned int delta = now - lastTicks; if (delta < frameTime) usleep((frameTime - delta) * 1000); } if (!autoFrameSkip) { if (++frameSkipCounter > maxFrameSkips) frameSkipCounter = 0; } lastTicks = now; engine->runFrame(frameSkipCounter > 0); //showFPS(); } if (soundOn) audioPlayer->pause(); }
static void showFPS() { static int frames; static unsigned int last; unsigned int now = ticksGetTicks(); frames++; if (now - last >= 1000) { LOGD("fps: %d", frames * 1000 / (now - last)); last = now; frames = 0; } }
static void runEmulator() { const bool soundOn = soundEnabled; if (soundOn) media->audioStart(emuThreadEnv); const int fps = (int) (currentGame->fps * gameSpeed); const int maxSkips = (int) (maxFrameSkips * gameSpeed); const unsigned int frameTime = 1000 / fps; const unsigned int refreshTime = (refreshRate ? (1000 / refreshRate) : 0); unsigned int initialTicks = ticksGetTicks(); unsigned int lastTicks = initialTicks; unsigned int lastFrameDrawnTime = 0; unsigned int virtualFrameCount = 0; int skipCounter = 0; while (emuState == EMUSTATE_RUNNING) { unsigned int now = ticksGetTicks(); unsigned int realFrameCount = (now - initialTicks) * fps / 1000; // frame skips virtualFrameCount++; if (realFrameCount >= virtualFrameCount) { if (realFrameCount > virtualFrameCount && autoFrameSkip && skipCounter < maxSkips) { skipCounter++; } else { virtualFrameCount = realFrameCount; if (autoFrameSkip) skipCounter = 0; } } else { unsigned int delta = now - lastTicks; if (delta < frameTime) usleep((frameTime - delta) * 1000); } if (!autoFrameSkip) { if (++skipCounter > maxSkips) skipCounter = 0; } lastTicks = now; // trackball events unsigned int states = updateTrackballStates(keyStates); // FrameUpdateListener.onFrameUpdate(states); if (jFrameUpdateListener != NULL) { states = emuThreadEnv->CallIntMethod(jFrameUpdateListener, midOnFrameUpdate, states); if (emuThreadEnv->ExceptionOccurred()) { emuThreadEnv->ExceptionClear(); break; } } // Consider refresh rate bool skip = (skipCounter > 0); if (!skip && refreshTime) { if (now - lastFrameDrawnTime < refreshTime) skip = true; else lastFrameDrawnTime = now; } engine->runFrame(states, skip); //showFPS(); } if (soundOn) media->audioPause(emuThreadEnv); }
void GBI_ProfileEnd(u32 cmd) { unsigned int i = 256*GBI.current->type + cmd; GBI.profileNum[i]++; GBI.profileTimer[i] += ticksGetTicks() - GBI.profileTmp; }
void GBI_ProfileBegin(u32 cmd) { GBI.profileTmp = ticksGetTicks(); }