Merge branch 'netplay' into netplay_dev

This commit is contained in:
HeatXD 2023-04-18 13:28:44 +02:00
commit 93def6b1dc
No known key found for this signature in database
GPG Key ID: BF30D71B2F1305C7
3 changed files with 16 additions and 7 deletions

View File

@ -44,7 +44,6 @@ static void SetSettings();
// l = local, r = remote
static s32 Start(s32 lhandle, u16 lport, std::string& raddr, u16 rport, s32 ldelay, u32 pred);
static void Close();
static void AdvanceFrame(u16 checksum = 0);
static void RunFrame();
@ -139,8 +138,10 @@ s32 Netplay::Start(s32 lhandle, u16 lport, std::string& raddr, u16 rport, s32 ld
return result;
}
void Netplay::Close()
void Netplay::CloseSession()
{
Assert(IsActive());
ggpo_close_session(s_ggpo);
s_ggpo = nullptr;
s_save_buffer_pool.clear();
@ -210,7 +211,7 @@ void Netplay::HandleTimeSyncEvent(float frame_delta, int update_interval)
float iterations_per_frame = 1.0f / s_frame_period;
s_target_speed = (s_frame_period + added_time_per_frame) * iterations_per_frame;
s_next_timesync_recovery_frame = CurrentFrame() + std::ceil(static_cast<float>(update_interval) * 0.8f);
s_next_timesync_recovery_frame = CurrentFrame() + static_cast<s32>(std::ceil(static_cast<float>(update_interval) * 0.8f));
UpdateThrottlePeriod();
@ -381,7 +382,8 @@ void Netplay::StopNetplaySession()
if (!IsActive())
return;
Close();
// This will call back to us.
System::ShutdownSystem(false);
}
void Netplay::NetplayAdvanceFrame(Netplay::Input inputs[], int disconnect_flags)
@ -393,13 +395,13 @@ void Netplay::NetplayAdvanceFrame(Netplay::Input inputs[], int disconnect_flags)
void Netplay::ExecuteNetplay()
{
while (System::IsValid())
while (System::IsRunning())
{
Netplay::RunFrame();
// this can shut us down
Host::PumpMessagesOnCPUThread();
if (!System::IsValid() || !Netplay::IsActive())
if (!System::IsValid())
break;
System::PresentFrame();

View File

@ -19,6 +19,10 @@ void StopNetplaySession();
bool IsActive();
/// Frees up resources associated with the current netplay session.
/// Should only be called by System::ShutdownSystem().
void CloseSession();
/// Runs the VM and netplay loop. when the netplay loop cancels it switches to normal execute mode.
void ExecuteNetplay();

View File

@ -1532,7 +1532,7 @@ void System::Execute()
// this can shut us down
Host::PumpMessagesOnCPUThread();
if (!IsValid() || Netplay::IsActive())
if (!IsValid())
return;
if (s_frame_step_request)
@ -3741,6 +3741,9 @@ void System::ShutdownSystem(bool save_resume_state)
if (!IsValid())
return;
if (Netplay::IsActive())
Netplay::CloseSession();
if (save_resume_state)
SaveResumeState();