Libretro: Enable frame skipping during fast forward

This commit is contained in:
Sour 2020-02-07 18:23:23 -05:00
parent d76921e9ce
commit 5101ad4d05
5 changed files with 683 additions and 179 deletions

View file

@ -1448,6 +1448,7 @@ void Ppu::SendFrame()
_console->GetNotificationManager()->SendNotification(ConsoleNotificationType::PpuFrameDone); _console->GetNotificationManager()->SendNotification(ConsoleNotificationType::PpuFrameDone);
bool isRewinding = _console->GetRewindManager()->IsRewinding(); bool isRewinding = _console->GetRewindManager()->IsRewinding();
#ifdef LIBRETRO #ifdef LIBRETRO
_console->GetVideoDecoder()->UpdateFrameSync(_currentBuffer, width, height, _frameCount, isRewinding); _console->GetVideoDecoder()->UpdateFrameSync(_currentBuffer, width, height, _frameCount, isRewinding);
#else #else
@ -1456,11 +1457,11 @@ void Ppu::SendFrame()
} else { } else {
_console->GetVideoDecoder()->UpdateFrame(_currentBuffer, width, height, _frameCount); _console->GetVideoDecoder()->UpdateFrame(_currentBuffer, width, height, _frameCount);
} }
#endif
if(!_skipRender) { if(!_skipRender) {
_frameSkipTimer.Reset(); _frameSkipTimer.Reset();
} }
#endif
} }

View file

@ -80,6 +80,7 @@ extern "C" {
_messageManager.reset(new LibretroMessageManager(logCallback, retroEnv)); _messageManager.reset(new LibretroMessageManager(logCallback, retroEnv));
AudioConfig audioConfig = _console->GetSettings()->GetAudioConfig(); AudioConfig audioConfig = _console->GetSettings()->GetAudioConfig();
audioConfig.DisableDynamicSampleRate = true;
audioConfig.SampleRate = 32000; audioConfig.SampleRate = 32000;
_console->GetSettings()->SetAudioConfig(audioConfig); _console->GetSettings()->SetAudioConfig(audioConfig);
@ -422,6 +423,16 @@ extern "C" {
update_settings(); update_settings();
} }
bool isFastForward = false;
EmulationConfig cfg = _console->GetSettings()->GetEmulationConfig();
if(retroEnv(RETRO_ENVIRONMENT_GET_FASTFORWARDING, &isFastForward) && isFastForward) {
//Allow core to skip frame rendering during fast forwarding
cfg.EmulationSpeed = 0;
} else {
cfg.EmulationSpeed = 100;
}
_console->GetSettings()->SetEmulationConfig(cfg);
_console->RunSingleFrame(); _console->RunSingleFrame();
if(updated) { if(updated) {

File diff suppressed because it is too large Load diff

View file

@ -1,42 +1,10 @@
#include "stdafx.h" #include "stdafx.h"
#include "Timer.h" #include "Timer.h"
#ifndef LIBRETRO
#include <thread> #include <thread>
#include <chrono>
#ifdef _WIN32 using namespace std::chrono;
#include <Windows.h>
Timer::Timer()
{
LARGE_INTEGER li;
if(!QueryPerformanceFrequency(&li)) {
throw;
}
_frequency = double(li.QuadPart) / 1000.0;
QueryPerformanceCounter(&li);
_start = li.QuadPart;
}
void Timer::Reset()
{
LARGE_INTEGER li;
QueryPerformanceCounter(&li);
_start = li.QuadPart;
}
double Timer::GetElapsedMS()
{
LARGE_INTEGER li;
QueryPerformanceCounter(&li);
return double(li.QuadPart - _start) / _frequency;
}
#else
#include <time.h>
Timer::Timer() Timer::Timer()
{ {
@ -45,25 +13,17 @@ Timer::Timer()
void Timer::Reset() void Timer::Reset()
{ {
timespec start; _start = high_resolution_clock::now();
clock_gettime(CLOCK_MONOTONIC, &start);
_start = start.tv_sec * 1000000000 + start.tv_nsec;
} }
double Timer::GetElapsedMS() double Timer::GetElapsedMS()
{ {
timespec end; high_resolution_clock::time_point end = high_resolution_clock::now();
clock_gettime(CLOCK_MONOTONIC, &end); duration<double> span = duration_cast<duration<double>>(end - _start);
return span.count() * 1000.0;
uint64_t currentTime = end.tv_sec * 1000000000 + end.tv_nsec;
return (double)(currentTime - _start) / 1000000.0;
} }
#endif void Timer::WaitUntil(double targetMillisecond)
void Timer::WaitUntil(double targetMillisecond)
{ {
if(targetMillisecond > 0) { if(targetMillisecond > 0) {
double elapsedTime = GetElapsedMS(); double elapsedTime = GetElapsedMS();
@ -72,26 +32,3 @@ void Timer::WaitUntil(double targetMillisecond)
} }
} }
} }
#else
//This is not used by Libretro port, remove its dependencies
Timer::Timer()
{
}
void Timer::Reset()
{
}
double Timer::GetElapsedMS()
{
return 0.0;
}
void Timer::WaitUntil(double targetMillisecond)
{
}
#endif

View file

@ -1,16 +1,14 @@
#pragma once #pragma once
#include "stdafx.h" #include "stdafx.h"
#include <chrono>
using namespace std::chrono;
class Timer class Timer
{ {
private: private:
#ifndef LIBRETRO high_resolution_clock::time_point _start;
#ifdef WIN32
double _frequency = 0.0; public:
#endif
uint64_t _start;
#endif
public:
Timer(); Timer();
void Reset(); void Reset();
double GetElapsedMS(); double GetElapsedMS();