diff --git a/dep/ggpo-x/include/ggponet.h b/dep/ggpo-x/include/ggponet.h index 88b99346c..cfce0b07e 100644 --- a/dep/ggpo-x/include/ggponet.h +++ b/dep/ggpo-x/include/ggponet.h @@ -453,6 +453,7 @@ GGPO_API GGPOErrorCode __cdecl ggpo_set_frame_delay(GGPOSession *, * in ggpo_idle. */ GGPO_API GGPOErrorCode __cdecl ggpo_idle(GGPOSession *); +GGPO_API GGPOErrorCode __cdecl ggpo_network_idle(GGPOSession *); /* * ggpo_add_local_input -- diff --git a/dep/ggpo-x/src/backends/backend.h b/dep/ggpo-x/src/backends/backend.h index 6296a1128..6fc9cc081 100644 --- a/dep/ggpo-x/src/backends/backend.h +++ b/dep/ggpo-x/src/backends/backend.h @@ -15,6 +15,7 @@ class GGPOSession { public: virtual ~GGPOSession() { } virtual GGPOErrorCode DoPoll() = 0; + virtual GGPOErrorCode NetworkIdle() = 0; virtual GGPOErrorCode AddPlayer(GGPOPlayer *player, GGPOPlayerHandle *handle) = 0; virtual GGPOErrorCode AddLocalInput(GGPOPlayerHandle player, void *values, int size) = 0; virtual GGPOErrorCode SyncInput(void *values, int size, int *disconnect_flags) = 0; diff --git a/dep/ggpo-x/src/backends/p2p.cpp b/dep/ggpo-x/src/backends/p2p.cpp index ae3a3e3b0..cfd1a3e1e 100644 --- a/dep/ggpo-x/src/backends/p2p.cpp +++ b/dep/ggpo-x/src/backends/p2p.cpp @@ -140,9 +140,6 @@ Peer2PeerBackend::DoPoll() { if (!_sync.InRollback()) { - for (UdpProtocol& udp : _endpoints) - udp.OnLoopPoll(); - PollUdpProtocolEvents(); CheckDesync(); if (!_synchronizing) { @@ -205,6 +202,14 @@ Peer2PeerBackend::DoPoll() return GGPO_OK; } +GGPOErrorCode Peer2PeerBackend::NetworkIdle() +{ + for (UdpProtocol& udp : _endpoints) + udp.NetworkIdle(); + + return GGPO_OK; +} + int Peer2PeerBackend::Poll2Players(int current_frame) { int i; diff --git a/dep/ggpo-x/src/backends/p2p.h b/dep/ggpo-x/src/backends/p2p.h index 70964deeb..d11ad7094 100644 --- a/dep/ggpo-x/src/backends/p2p.h +++ b/dep/ggpo-x/src/backends/p2p.h @@ -23,6 +23,7 @@ public: public: virtual GGPOErrorCode DoPoll() override; + virtual GGPOErrorCode NetworkIdle() override; virtual GGPOErrorCode AddPlayer(GGPOPlayer *player, GGPOPlayerHandle *handle) override; virtual GGPOErrorCode AddLocalInput(GGPOPlayerHandle player, void *values, int size) override; virtual GGPOErrorCode SyncInput(void *values, int size, int *disconnect_flags) override; diff --git a/dep/ggpo-x/src/backends/spectator.cpp b/dep/ggpo-x/src/backends/spectator.cpp index 82580a6eb..ebf7c6955 100644 --- a/dep/ggpo-x/src/backends/spectator.cpp +++ b/dep/ggpo-x/src/backends/spectator.cpp @@ -55,6 +55,12 @@ SpectatorBackend::DoPoll() return GGPO_OK; } +GGPOErrorCode SpectatorBackend::NetworkIdle() +{ + _host.NetworkIdle(); + return GGPO_OK; +} + GGPOErrorCode SpectatorBackend::SyncInput(void *values, int size, diff --git a/dep/ggpo-x/src/backends/spectator.h b/dep/ggpo-x/src/backends/spectator.h index cc5d30444..a0e39c2ef 100644 --- a/dep/ggpo-x/src/backends/spectator.h +++ b/dep/ggpo-x/src/backends/spectator.h @@ -24,6 +24,7 @@ public: public: virtual GGPOErrorCode DoPoll(); + virtual GGPOErrorCode NetworkIdle(); 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 SyncInput(void *values, int size, int *disconnect_flags); diff --git a/dep/ggpo-x/src/backends/synctest.cpp b/dep/ggpo-x/src/backends/synctest.cpp index a8fbe0884..39c858aef 100644 --- a/dep/ggpo-x/src/backends/synctest.cpp +++ b/dep/ggpo-x/src/backends/synctest.cpp @@ -54,6 +54,12 @@ SyncTestBackend::DoPoll() return GGPO_OK; } +GGPOErrorCode +SyncTestBackend::NetworkIdle() +{ + return GGPO_OK; +} + GGPOErrorCode SyncTestBackend::AddPlayer(GGPOPlayer *player, GGPOPlayerHandle *handle) { diff --git a/dep/ggpo-x/src/backends/synctest.h b/dep/ggpo-x/src/backends/synctest.h index 95ffec59a..e425d9c5f 100644 --- a/dep/ggpo-x/src/backends/synctest.h +++ b/dep/ggpo-x/src/backends/synctest.h @@ -19,6 +19,7 @@ public: virtual ~SyncTestBackend(); virtual GGPOErrorCode DoPoll(); + virtual GGPOErrorCode NetworkIdle(); virtual GGPOErrorCode AddPlayer(GGPOPlayer *player, GGPOPlayerHandle *handle); virtual GGPOErrorCode AddLocalInput(GGPOPlayerHandle player, void *values, int size); virtual GGPOErrorCode SyncInput(void *values, int size, int *disconnect_flags); diff --git a/dep/ggpo-x/src/main.cpp b/dep/ggpo-x/src/main.cpp index de7c853f0..e1ac2ce47 100644 --- a/dep/ggpo-x/src/main.cpp +++ b/dep/ggpo-x/src/main.cpp @@ -100,6 +100,15 @@ ggpo_idle(GGPOSession *ggpo) return ggpo->DoPoll(); } +GGPOErrorCode +ggpo_network_idle(GGPOSession* ggpo) +{ + if (!ggpo) { + return GGPO_ERRORCODE_INVALID_SESSION; + } + return ggpo->NetworkIdle(); +} + GGPOErrorCode ggpo_add_local_input(GGPOSession *ggpo, GGPOPlayerHandle player, diff --git a/dep/ggpo-x/src/network/udp_proto.cpp b/dep/ggpo-x/src/network/udp_proto.cpp index be3a4967e..5b8d4543c 100644 --- a/dep/ggpo-x/src/network/udp_proto.cpp +++ b/dep/ggpo-x/src/network/udp_proto.cpp @@ -186,7 +186,7 @@ void UdpProtocol::EndPollLoop() } bool -UdpProtocol::OnLoopPoll() +UdpProtocol::NetworkIdle() { if (!_peer) { return true; diff --git a/dep/ggpo-x/src/network/udp_proto.h b/dep/ggpo-x/src/network/udp_proto.h index 4b1cf6301..e04719485 100644 --- a/dep/ggpo-x/src/network/udp_proto.h +++ b/dep/ggpo-x/src/network/udp_proto.h @@ -57,7 +57,7 @@ public: }; public: - bool OnLoopPoll(); + bool NetworkIdle(); public: UdpProtocol(); diff --git a/src/core/netplay.cpp b/src/core/netplay.cpp index 7a664e2be..09667027e 100644 --- a/src/core/netplay.cpp +++ b/src/core/netplay.cpp @@ -588,6 +588,8 @@ void Netplay::Throttle() { // TODO: make better, we can tell this function to stall until the next frame PollEnet(0); + ggpo_network_idle(s_ggpo); + PollEnet(0); current_time = Common::Timer::GetCurrentValue(); if (current_time >= s_next_frame_time) @@ -650,7 +652,12 @@ void Netplay::AdvanceFrame() void Netplay::RunFrame() { // housekeeping + // TODO: get rid of double polling + PollEnet(0); + ggpo_network_idle(s_ggpo); + PollEnet(0); ggpo_idle(s_ggpo); + // run game auto result = GGPO_OK; int disconnect_flags = 0;