From e2621a84742aebee5bd80afe7efebdeadc6403b4 Mon Sep 17 00:00:00 2001 From: Bernhard Schelling <14200249+schellingb@users.noreply.github.com> Date: Sat, 24 Jun 2023 02:46:50 +0900 Subject: [PATCH] Add enum netplay_modus --- network/netplay/netplay_private.h | 16 ++++++++++++++++ retroarch.c | 4 ++++ runloop.c | 10 ++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/network/netplay/netplay_private.h b/network/netplay/netplay_private.h index 05257b77bf..2e7a6744a9 100644 --- a/network/netplay/netplay_private.h +++ b/network/netplay/netplay_private.h @@ -268,6 +268,19 @@ enum rarch_netplay_stall_reason NETPLAY_STALL_SERVER_REQUESTED }; +enum netplay_modus +{ + /* Netplay operates by having all participants send input data every + frame and run cores deterministically in sync on all connected devices. + It will rewind frames when input data from the past arrives. */ + NETPLAY_MODUS_INPUT_FRAME_SYNC = 0, + + /* Netplay operates by having the active core send and receive custom + packets once connection setup and handshake has been completed. + Time skips (pausing, fast forward, save state loading) are refused. */ + NETPLAY_MODUS_CORE_PACKET_INTERFACE = 1, +}; + /* Input state for a particular client-device pair */ typedef struct netplay_input_state { @@ -607,6 +620,9 @@ struct netplay /* Are we stalled? */ enum rarch_netplay_stall_reason stall; + /* Netplay mode of operation (cannot change at runtime) */ + enum netplay_modus modus; + /* Keyboard mapping (network and host) */ uint16_t mapping_hton[RETROK_LAST]; uint16_t mapping_ntoh[NETPLAY_KEY_LAST]; diff --git a/retroarch.c b/retroarch.c index 723d9ff856..025085ad1f 100644 --- a/retroarch.c +++ b/retroarch.c @@ -2915,6 +2915,10 @@ bool command_event(enum event_command cmd, void *data) #ifdef HAVE_CHEEVOS if (rcheevos_hardcore_active()) return false; +#endif +#ifdef HAVE_NETWORKING + if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_ALLOW_TIMESKIP, NULL)) + return false; #endif if (rewind_enable) { diff --git a/runloop.c b/runloop.c index 62813f6753..8f2e14c2a7 100644 --- a/runloop.c +++ b/runloop.c @@ -3487,9 +3487,15 @@ bool runloop_environment_cb(unsigned cmd, void *data) case RETRO_ENVIRONMENT_SET_NETPACKET_INTERFACE: #ifdef HAVE_NETWORKING RARCH_LOG("[Environ]: RETRO_ENVIRONMENT_SET_NETPACKET_INTERFACE.\n"); - netplay_driver_ctl(RARCH_NETPLAY_CTL_SET_CORE_PACKET_INTERFACE, data); -#endif + if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_SET_CORE_PACKET_INTERFACE, data)) + { + RARCH_ERR("[Environ] RETRO_ENVIRONMENT_SET_NETPACKET_INTERFACE set too late\n"); + return false; + } break; +#else + return false; +#endif default: RARCH_LOG("[Environ]: UNSUPPORTED (#%u).\n", cmd);