Attempt to improve save/load during frame advance

master
Hamish Milne 2020-04-11 22:25:57 +07:00
parent 19872b599b
commit 77c4b26e6c
4 changed files with 46 additions and 37 deletions

@ -706,6 +706,7 @@ void GMainWindow::ConnectMenuEvents() {
if (emulation_running) {
ui.action_Enable_Frame_Advancing->setChecked(true);
ui.action_Advance_Frame->setEnabled(true);
Core::System::GetInstance().frame_limiter.SetFrameAdvancing(true);
Core::System::GetInstance().frame_limiter.AdvanceFrame();
}
});
@ -1640,6 +1641,7 @@ void GMainWindow::OnSaveState() {
assert(action);
Core::System::GetInstance().SendSignal(Core::System::Signal::Save, action->data().toUInt());
Core::System::GetInstance().frame_limiter.AdvanceFrame();
newest_slot = action->data().toUInt();
}
@ -1648,6 +1650,7 @@ void GMainWindow::OnLoadState() {
assert(action);
Core::System::GetInstance().SendSignal(Core::System::Signal::Load, action->data().toUInt());
Core::System::GetInstance().frame_limiter.AdvanceFrame();
}
void GMainWindow::OnConfigure() {

@ -89,6 +89,40 @@ System::ResultStatus System::RunLoop(bool tight_loop) {
}
}
Signal signal{Signal::None};
u32 param{};
{
std::lock_guard lock{signal_mutex};
if (current_signal != Signal::None) {
signal = current_signal;
param = signal_param;
current_signal = Signal::None;
}
}
switch (signal) {
case Signal::Reset:
Reset();
return ResultStatus::Success;
case Signal::Shutdown:
return ResultStatus::ShutdownRequested;
case Signal::Load: {
LOG_INFO(Core, "Begin load");
System::LoadState(param);
LOG_INFO(Core, "Load completed");
frame_limiter.WaitOnce();
return ResultStatus::Success;
}
case Signal::Save: {
LOG_INFO(Core, "Begin save");
System::SaveState(param);
LOG_INFO(Core, "Save completed");
frame_limiter.WaitOnce();
return ResultStatus::Success;
}
default:
break;
}
// All cores should have executed the same amount of ticks. If this is not the case an event was
// scheduled with a cycles_into_future smaller then the current downcount.
// So we have to get those cores to the same global time first
@ -163,39 +197,6 @@ System::ResultStatus System::RunLoop(bool tight_loop) {
HW::Update();
Reschedule();
Signal signal{Signal::None};
u32 param{};
{
std::lock_guard lock{signal_mutex};
if (current_signal != Signal::None) {
signal = current_signal;
param = signal_param;
current_signal = Signal::None;
}
}
switch (signal) {
case Signal::Reset:
Reset();
break;
case Signal::Shutdown:
return ResultStatus::ShutdownRequested;
break;
case Signal::Load: {
LOG_INFO(Core, "Begin load");
System::LoadState(param);
LOG_INFO(Core, "Load completed");
break;
}
case Signal::Save: {
LOG_INFO(Core, "Begin save");
System::SaveState(param);
LOG_INFO(Core, "Save completed");
break;
}
default:
break;
}
return status;
}

@ -117,6 +117,14 @@ double PerfStats::GetLastFrameTimeScale() {
return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH;
}
void FrameLimiter::WaitOnce() {
if (frame_advancing_enabled) {
// Frame advancing is enabled: wait on event instead of doing framelimiting
frame_advance_event.Wait();
frame_advance_event.Reset();
}
}
void FrameLimiter::DoFrameLimiting(microseconds current_system_time_us) {
if (frame_advancing_enabled) {
// Frame advancing is enabled: wait on event instead of doing framelimiting
@ -164,10 +172,6 @@ void FrameLimiter::SetFrameAdvancing(bool value) {
}
void FrameLimiter::AdvanceFrame() {
if (!frame_advancing_enabled) {
// Start frame advancing
frame_advancing_enabled = true;
}
frame_advance_event.Set();
}

@ -98,6 +98,7 @@ public:
*/
void SetFrameAdvancing(bool value);
void AdvanceFrame();
void WaitOnce();
private:
/// Emulated system time (in microseconds) at the last limiter invocation