Netplay: Fix latency increase

This commit is contained in:
Stenzek 2023-05-07 17:48:18 +10:00
parent 1d338abe3b
commit 67801ea271
12 changed files with 43 additions and 5 deletions

View File

@ -453,6 +453,7 @@ GGPO_API GGPOErrorCode __cdecl ggpo_set_frame_delay(GGPOSession *,
* in ggpo_idle. * in ggpo_idle.
*/ */
GGPO_API GGPOErrorCode __cdecl ggpo_idle(GGPOSession *); GGPO_API GGPOErrorCode __cdecl ggpo_idle(GGPOSession *);
GGPO_API GGPOErrorCode __cdecl ggpo_network_idle(GGPOSession *);
/* /*
* ggpo_add_local_input -- * ggpo_add_local_input --

View File

@ -15,6 +15,7 @@ class GGPOSession {
public: public:
virtual ~GGPOSession() { } virtual ~GGPOSession() { }
virtual GGPOErrorCode DoPoll() = 0; virtual GGPOErrorCode DoPoll() = 0;
virtual GGPOErrorCode NetworkIdle() = 0;
virtual GGPOErrorCode AddPlayer(GGPOPlayer *player, GGPOPlayerHandle *handle) = 0; virtual GGPOErrorCode AddPlayer(GGPOPlayer *player, GGPOPlayerHandle *handle) = 0;
virtual GGPOErrorCode AddLocalInput(GGPOPlayerHandle player, void *values, int size) = 0; virtual GGPOErrorCode AddLocalInput(GGPOPlayerHandle player, void *values, int size) = 0;
virtual GGPOErrorCode SyncInput(void *values, int size, int *disconnect_flags) = 0; virtual GGPOErrorCode SyncInput(void *values, int size, int *disconnect_flags) = 0;

View File

@ -140,9 +140,6 @@ Peer2PeerBackend::DoPoll()
{ {
if (!_sync.InRollback()) if (!_sync.InRollback())
{ {
for (UdpProtocol& udp : _endpoints)
udp.OnLoopPoll();
PollUdpProtocolEvents(); PollUdpProtocolEvents();
CheckDesync(); CheckDesync();
if (!_synchronizing) { if (!_synchronizing) {
@ -205,6 +202,14 @@ Peer2PeerBackend::DoPoll()
return GGPO_OK; return GGPO_OK;
} }
GGPOErrorCode Peer2PeerBackend::NetworkIdle()
{
for (UdpProtocol& udp : _endpoints)
udp.NetworkIdle();
return GGPO_OK;
}
int Peer2PeerBackend::Poll2Players(int current_frame) int Peer2PeerBackend::Poll2Players(int current_frame)
{ {
int i; int i;

View File

@ -23,6 +23,7 @@ public:
public: public:
virtual GGPOErrorCode DoPoll() override; virtual GGPOErrorCode DoPoll() override;
virtual GGPOErrorCode NetworkIdle() override;
virtual GGPOErrorCode AddPlayer(GGPOPlayer *player, GGPOPlayerHandle *handle) override; virtual GGPOErrorCode AddPlayer(GGPOPlayer *player, GGPOPlayerHandle *handle) override;
virtual GGPOErrorCode AddLocalInput(GGPOPlayerHandle player, void *values, int size) override; virtual GGPOErrorCode AddLocalInput(GGPOPlayerHandle player, void *values, int size) override;
virtual GGPOErrorCode SyncInput(void *values, int size, int *disconnect_flags) override; virtual GGPOErrorCode SyncInput(void *values, int size, int *disconnect_flags) override;

View File

@ -55,6 +55,12 @@ SpectatorBackend::DoPoll()
return GGPO_OK; return GGPO_OK;
} }
GGPOErrorCode SpectatorBackend::NetworkIdle()
{
_host.NetworkIdle();
return GGPO_OK;
}
GGPOErrorCode GGPOErrorCode
SpectatorBackend::SyncInput(void *values, SpectatorBackend::SyncInput(void *values,
int size, int size,

View File

@ -24,6 +24,7 @@ public:
public: public:
virtual GGPOErrorCode DoPoll(); virtual GGPOErrorCode DoPoll();
virtual GGPOErrorCode NetworkIdle();
virtual GGPOErrorCode AddPlayer(GGPOPlayer *player, GGPOPlayerHandle *handle) { return GGPO_ERRORCODE_UNSUPPORTED; } virtual GGPOErrorCode AddPlayer(GGPOPlayer *player, GGPOPlayerHandle *handle) { return GGPO_ERRORCODE_UNSUPPORTED; }
virtual GGPOErrorCode AddLocalInput(GGPOPlayerHandle player, void *values, int size) { return GGPO_OK; } virtual GGPOErrorCode AddLocalInput(GGPOPlayerHandle player, void *values, int size) { return GGPO_OK; }
virtual GGPOErrorCode SyncInput(void *values, int size, int *disconnect_flags); virtual GGPOErrorCode SyncInput(void *values, int size, int *disconnect_flags);

View File

@ -54,6 +54,12 @@ SyncTestBackend::DoPoll()
return GGPO_OK; return GGPO_OK;
} }
GGPOErrorCode
SyncTestBackend::NetworkIdle()
{
return GGPO_OK;
}
GGPOErrorCode GGPOErrorCode
SyncTestBackend::AddPlayer(GGPOPlayer *player, GGPOPlayerHandle *handle) SyncTestBackend::AddPlayer(GGPOPlayer *player, GGPOPlayerHandle *handle)
{ {

View File

@ -19,6 +19,7 @@ public:
virtual ~SyncTestBackend(); virtual ~SyncTestBackend();
virtual GGPOErrorCode DoPoll(); virtual GGPOErrorCode DoPoll();
virtual GGPOErrorCode NetworkIdle();
virtual GGPOErrorCode AddPlayer(GGPOPlayer *player, GGPOPlayerHandle *handle); virtual GGPOErrorCode AddPlayer(GGPOPlayer *player, GGPOPlayerHandle *handle);
virtual GGPOErrorCode AddLocalInput(GGPOPlayerHandle player, void *values, int size); virtual GGPOErrorCode AddLocalInput(GGPOPlayerHandle player, void *values, int size);
virtual GGPOErrorCode SyncInput(void *values, int size, int *disconnect_flags); virtual GGPOErrorCode SyncInput(void *values, int size, int *disconnect_flags);

View File

@ -100,6 +100,15 @@ ggpo_idle(GGPOSession *ggpo)
return ggpo->DoPoll(); return ggpo->DoPoll();
} }
GGPOErrorCode
ggpo_network_idle(GGPOSession* ggpo)
{
if (!ggpo) {
return GGPO_ERRORCODE_INVALID_SESSION;
}
return ggpo->NetworkIdle();
}
GGPOErrorCode GGPOErrorCode
ggpo_add_local_input(GGPOSession *ggpo, ggpo_add_local_input(GGPOSession *ggpo,
GGPOPlayerHandle player, GGPOPlayerHandle player,

View File

@ -186,7 +186,7 @@ void UdpProtocol::EndPollLoop()
} }
bool bool
UdpProtocol::OnLoopPoll() UdpProtocol::NetworkIdle()
{ {
if (!_peer) { if (!_peer) {
return true; return true;

View File

@ -57,7 +57,7 @@ public:
}; };
public: public:
bool OnLoopPoll(); bool NetworkIdle();
public: public:
UdpProtocol(); UdpProtocol();

View File

@ -588,6 +588,8 @@ void Netplay::Throttle()
{ {
// TODO: make better, we can tell this function to stall until the next frame // TODO: make better, we can tell this function to stall until the next frame
PollEnet(0); PollEnet(0);
ggpo_network_idle(s_ggpo);
PollEnet(0);
current_time = Common::Timer::GetCurrentValue(); current_time = Common::Timer::GetCurrentValue();
if (current_time >= s_next_frame_time) if (current_time >= s_next_frame_time)
@ -650,7 +652,12 @@ void Netplay::AdvanceFrame()
void Netplay::RunFrame() void Netplay::RunFrame()
{ {
// housekeeping // housekeeping
// TODO: get rid of double polling
PollEnet(0);
ggpo_network_idle(s_ggpo);
PollEnet(0);
ggpo_idle(s_ggpo); ggpo_idle(s_ggpo);
// run game // run game
auto result = GGPO_OK; auto result = GGPO_OK;
int disconnect_flags = 0; int disconnect_flags = 0;