diff --git a/Makefile.common b/Makefile.common index a9ed73c184..63b6a67e73 100644 --- a/Makefile.common +++ b/Makefile.common @@ -1123,12 +1123,12 @@ ifeq ($(HAVE_NETWORKING), 1) # Netplay DEFINES += -DHAVE_NETWORK_CMD OBJ += network/netplay/netplay_frontend.o \ + network/netplay/netplay_init.o \ network/netplay/netplay_io.o \ network/netplay/netplay_net.o \ network/netplay/netplay_common.o \ network/netplay/netplay_discovery.o \ - network/netplay/netplay_buf.o \ - network/netplay/netplay.o + network/netplay/netplay_buf.o # Retro Achievements (also depends on threads) diff --git a/griffin/griffin.c b/griffin/griffin.c index 6e1d1b736a..55c0fe48ec 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -882,11 +882,11 @@ NETPLAY ============================================================ */ #ifdef HAVE_NETWORKING #include "../network/netplay/netplay_frontend.c" +#include "../network/netplay/netplay_init.c" #include "../network/netplay/netplay_io.c" #include "../network/netplay/netplay_net.c" #include "../network/netplay/netplay_common.c" #include "../network/netplay/netplay_discovery.c" -#include "../network/netplay/netplay.c" #include "../libretro-common/net/net_compat.c" #include "../libretro-common/net/net_socket.c" #include "../libretro-common/net/net_http.c" diff --git a/network/netplay/netplay.c b/network/netplay/netplay_init.c similarity index 80% rename from network/netplay/netplay.c rename to network/netplay/netplay_init.c index 415ff84672..33ca0d65da 100644 --- a/network/netplay/netplay.c +++ b/network/netplay/netplay_init.c @@ -19,23 +19,18 @@ #pragma comment(lib, "ws2_32") #endif +#include #include -#include +#include +#include #include -#include -#include -#include -#include -#include #include "netplay_private.h" + #include "netplay_discovery.h" #include "../../autosave.h" -#include "../../configuration.h" -#include "../../command.h" -#include "../../movie.h" #include "../../runloop.h" #if defined(AF_INET6) && !defined(HAVE_SOCKET_LEGACY) @@ -233,106 +228,6 @@ static bool init_socket(netplay_t *netplay, void *direct_host, const char *serve return true; } -/** - * netplay_update_unread_ptr - * - * Update the global unread_ptr and unread_frame_count to correspond to the - * earliest unread frame count of any connected player */ -void netplay_update_unread_ptr(netplay_t *netplay) -{ - if (netplay->is_server && !netplay->connected_players) - { - /* Nothing at all to read! */ - netplay->unread_ptr = netplay->self_ptr; - netplay->unread_frame_count = netplay->self_frame_count; - - } - else - { - size_t new_unread_ptr = 0; - uint32_t new_unread_frame_count = (uint32_t) -1; - uint32_t player; - - for (player = 0; player < MAX_USERS; player++) - { - if (!(netplay->connected_players & (1<read_frame_count[player] < new_unread_frame_count) - { - new_unread_ptr = netplay->read_ptr[player]; - new_unread_frame_count = netplay->read_frame_count[player]; - } - } - - if (!netplay->is_server && netplay->server_frame_count < new_unread_frame_count) - { - new_unread_ptr = netplay->server_ptr; - new_unread_frame_count = netplay->server_frame_count; - } - - netplay->unread_ptr = new_unread_ptr; - netplay->unread_frame_count = new_unread_frame_count; - } -} - -/** - * netplay_simulate_input: - * @netplay : pointer to netplay object - * @sim_ptr : frame index for which to simulate input - * @resim : are we resimulating, or simulating this frame for the - * first time? - * - * "Simulate" input by assuming it hasn't changed since the last read input. - */ -void netplay_simulate_input(netplay_t *netplay, size_t sim_ptr, bool resim) -{ - uint32_t player; - size_t prev; - struct delta_frame *simframe, *pframe; - - simframe = &netplay->buffer[sim_ptr]; - - for (player = 0; player < MAX_USERS; player++) - { - if (!(netplay->connected_players & (1<have_real[player]) continue; - - prev = PREV_PTR(netplay->read_ptr[player]); - pframe = &netplay->buffer[prev]; - - if (resim) - { - /* In resimulation mode, we only copy the buttons. The reason for this - * is nonobvious: - * - * If we resimulated nothing, then the /duration/ with which any input - * was pressed would be approximately correct, since the original - * simulation came in as the input came in, but the /number of times/ - * the input was pressed would be wrong, as there would be an - * advancing wavefront of real data overtaking the simulated data - * (which is really just real data offset by some frames). - * - * That's acceptable for arrows in most situations, since the amount - * you move is tied to the duration, but unacceptable for buttons, - * which will seem to jerkily be pressed numerous times with those - * wavefronts. - */ - const uint32_t keep = (1U<simulated_input_state[player][0] & keep; - sim_state |= pframe->real_input_state[player][0] & ~keep; - simframe->simulated_input_state[player][0] = sim_state; - } - else - { - memcpy(simframe->simulated_input_state[player], - pframe->real_input_state[player], - WORDS_PER_INPUT * sizeof(uint32_t)); - } - } -} - #ifndef HAVE_SOCKET_LEGACY /* Custom inet_ntop. Win32 doesn't seem to support this ... */ void netplay_log_connection(const struct sockaddr_storage *their_addr, diff --git a/network/netplay/netplay_net.c b/network/netplay/netplay_net.c index dfcb925c32..559417f330 100644 --- a/network/netplay/netplay_net.c +++ b/network/netplay/netplay_net.c @@ -32,6 +32,107 @@ #define DEBUG_NONDETERMINISTIC_CORES #endif + +/** + * netplay_update_unread_ptr + * + * Update the global unread_ptr and unread_frame_count to correspond to the + * earliest unread frame count of any connected player */ +void netplay_update_unread_ptr(netplay_t *netplay) +{ + if (netplay->is_server && !netplay->connected_players) + { + /* Nothing at all to read! */ + netplay->unread_ptr = netplay->self_ptr; + netplay->unread_frame_count = netplay->self_frame_count; + + } + else + { + size_t new_unread_ptr = 0; + uint32_t new_unread_frame_count = (uint32_t) -1; + uint32_t player; + + for (player = 0; player < MAX_USERS; player++) + { + if (!(netplay->connected_players & (1<read_frame_count[player] < new_unread_frame_count) + { + new_unread_ptr = netplay->read_ptr[player]; + new_unread_frame_count = netplay->read_frame_count[player]; + } + } + + if (!netplay->is_server && netplay->server_frame_count < new_unread_frame_count) + { + new_unread_ptr = netplay->server_ptr; + new_unread_frame_count = netplay->server_frame_count; + } + + netplay->unread_ptr = new_unread_ptr; + netplay->unread_frame_count = new_unread_frame_count; + } +} + +/** + * netplay_simulate_input: + * @netplay : pointer to netplay object + * @sim_ptr : frame index for which to simulate input + * @resim : are we resimulating, or simulating this frame for the + * first time? + * + * "Simulate" input by assuming it hasn't changed since the last read input. + */ +void netplay_simulate_input(netplay_t *netplay, size_t sim_ptr, bool resim) +{ + uint32_t player; + size_t prev; + struct delta_frame *simframe, *pframe; + + simframe = &netplay->buffer[sim_ptr]; + + for (player = 0; player < MAX_USERS; player++) + { + if (!(netplay->connected_players & (1<have_real[player]) continue; + + prev = PREV_PTR(netplay->read_ptr[player]); + pframe = &netplay->buffer[prev]; + + if (resim) + { + /* In resimulation mode, we only copy the buttons. The reason for this + * is nonobvious: + * + * If we resimulated nothing, then the /duration/ with which any input + * was pressed would be approximately correct, since the original + * simulation came in as the input came in, but the /number of times/ + * the input was pressed would be wrong, as there would be an + * advancing wavefront of real data overtaking the simulated data + * (which is really just real data offset by some frames). + * + * That's acceptable for arrows in most situations, since the amount + * you move is tied to the duration, but unacceptable for buttons, + * which will seem to jerkily be pressed numerous times with those + * wavefronts. + */ + const uint32_t keep = (1U<simulated_input_state[player][0] & keep; + sim_state |= pframe->real_input_state[player][0] & ~keep; + simframe->simulated_input_state[player][0] = sim_state; + } + else + { + memcpy(simframe->simulated_input_state[player], + pframe->real_input_state[player], + WORDS_PER_INPUT * sizeof(uint32_t)); + } + } +} + static void netplay_handle_frame_hash(netplay_t *netplay, struct delta_frame *delta) { static bool crcs_valid = true;