static bool netplay_init_buffers(netplay_t *netplay, unsigned frames) { if (!netplay) return false; /* * 2 + 1 because: * Self sits in the middle, * Other is allowed to drift as much as 'frames' frames behind * Read is allowed to drift as much as 'frames' frames ahead */ netplay->buffer_size = frames * 2 + 1; netplay->buffer = (struct delta_frame*)calloc(netplay->buffer_size, sizeof(*netplay->buffer)); if (!netplay->buffer) return false; if (!(netplay->quirks & NETPLAY_QUIRK_INITIALIZATION)) netplay_init_serialization(netplay); return true; }
bool netplay_try_init_serialization(netplay_t *netplay) { retro_ctx_serialize_info_t serial_info; if (netplay->state_size) return true; if (!netplay_init_serialization(netplay)) return false; /* Check if we can actually save */ serial_info.data_const = NULL; serial_info.data = netplay->buffer[netplay->self_ptr].state; serial_info.size = netplay->state_size; if (!core_serialize(&serial_info)) return false; /* Once initialized, we no longer exhibit this quirk */ netplay->quirks &= ~((uint64_t) NETPLAY_QUIRK_INITIALIZATION); return true; }
static bool netplay_init_buffers(netplay_t *netplay) { if (!netplay) return false; /* Enough to get ahead or behind by MAX_STALL_FRAMES frames */ netplay->buffer_size = NETPLAY_MAX_STALL_FRAMES + 1; /* If we're the server, we need enough to get ahead AND behind by * MAX_STALL_FRAMES frame */ if (netplay->is_server) netplay->buffer_size *= 2; netplay->buffer = (struct delta_frame*)calloc(netplay->buffer_size, sizeof(*netplay->buffer)); if (!netplay->buffer) return false; if (!(netplay->quirks & (NETPLAY_QUIRK_NO_SAVESTATES|NETPLAY_QUIRK_INITIALIZATION))) netplay_init_serialization(netplay); return netplay_init_socket_buffers(netplay); }