diff --git a/network/net_http_special.c b/network/net_http_special.c index 5f46c27653..8c0622cf43 100644 --- a/network/net_http_special.c +++ b/network/net_http_special.c @@ -74,7 +74,7 @@ int net_http_get(const char **result, size_t *size, const char *url, retro_time_ res = (char*)malloc(length + 1); /* Allocation error. */ - if ( !res ) + if (!res) goto error; memcpy((void*)res, (void*)data, length); @@ -92,11 +92,11 @@ int net_http_get(const char **result, size_t *size, const char *url, retro_time_ *size = length; error: - if ( http ) - net_http_delete( http ); + if (http) + net_http_delete(http); - if ( conn ) - net_http_connection_free( conn ); + if (conn) + net_http_connection_free(conn); if (timeout) { diff --git a/network/netplay/netplay.h b/network/netplay/netplay.h index 6fe9eeb9d5..5c9ddc51bd 100644 --- a/network/netplay/netplay.h +++ b/network/netplay/netplay.h @@ -28,7 +28,8 @@ typedef struct netplay netplay_t; -typedef struct mitm_server { +typedef struct mitm_server +{ const char *name; const char *description; } mitm_server_t; diff --git a/network/netplay/netplay_buf.c b/network/netplay/netplay_buf.c index 4cbb4078ef..ee749c0021 100644 --- a/network/netplay/netplay_buf.c +++ b/network/netplay/netplay_buf.c @@ -25,7 +25,8 @@ static size_t buf_used(struct socket_buffer *sbuf) if (sbuf->end < sbuf->start) { size_t newend = sbuf->end; - while (newend < sbuf->start) newend += sbuf->bufsz; + while (newend < sbuf->start) + newend += sbuf->bufsz; return newend - sbuf->start; } @@ -37,7 +38,8 @@ static size_t buf_unread(struct socket_buffer *sbuf) if (sbuf->end < sbuf->read) { size_t newend = sbuf->end; - while (newend < sbuf->read) newend += sbuf->bufsz; + while (newend < sbuf->read) + newend += sbuf->bufsz; return newend - sbuf->read; } @@ -57,7 +59,7 @@ static size_t buf_remaining(struct socket_buffer *sbuf) bool netplay_init_socket_buffer(struct socket_buffer *sbuf, size_t size) { sbuf->data = (unsigned char*)malloc(size); - if (sbuf->data == NULL) + if (!sbuf->data) return false; sbuf->bufsz = size; sbuf->start = sbuf->read = sbuf->end = 0; @@ -72,7 +74,7 @@ bool netplay_init_socket_buffer(struct socket_buffer *sbuf, size_t size) bool netplay_resize_socket_buffer(struct socket_buffer *sbuf, size_t newsize) { unsigned char *newdata = (unsigned char*)malloc(newsize); - if (newdata == NULL) + if (!newdata) return false; /* Copy in the old data */ @@ -82,9 +84,7 @@ bool netplay_resize_socket_buffer(struct socket_buffer *sbuf, size_t newsize) memcpy(newdata + sbuf->bufsz - sbuf->start, sbuf->data, sbuf->end); } else if (sbuf->end > sbuf->start) - { memcpy(newdata, sbuf->data + sbuf->start, sbuf->end - sbuf->start); - } /* Adjust our read offset */ if (sbuf->read < sbuf->start) @@ -185,7 +185,8 @@ bool netplay_send_flush(struct socket_buffer *sbuf, int sockfd, bool block) /* Usual case: Everything's in order */ if (block) { - if (!socket_send_all_blocking(sockfd, sbuf->data + sbuf->start, buf_used(sbuf), true)) + if (!socket_send_all_blocking( + sockfd, sbuf->data + sbuf->start, buf_used(sbuf), true)) return false; sbuf->start = sbuf->end = 0; @@ -300,9 +301,7 @@ ssize_t netplay_recv(struct socket_buffer *sbuf, int sockfd, void *buf, if (sbuf->read >= sbuf->bufsz) sbuf->read = 0; recvd = unread; - } - } else { @@ -313,8 +312,7 @@ ssize_t netplay_recv(struct socket_buffer *sbuf, int sockfd, void *buf, memcpy(buf, sbuf->data + sbuf->read, chunka); memcpy((unsigned char *) buf + chunka, sbuf->data, chunkb); sbuf->read = chunkb; - recvd = chunka + chunkb; - + recvd = chunka + chunkb; } /* Perhaps block for more data */ diff --git a/network/netplay/netplay_delta.c b/network/netplay/netplay_delta.c index 2b770075ee..5539f8a91a 100644 --- a/network/netplay/netplay_delta.c +++ b/network/netplay/netplay_delta.c @@ -47,16 +47,18 @@ bool netplay_delta_frame_ready(netplay_t *netplay, struct delta_frame *delta, size_t i; if (delta->used) { - if (delta->frame == frame) return true; + if (delta->frame == frame) + return true; + /* We haven't even replayed this frame yet, + * so we can't overwrite it! */ if (netplay->other_frame_count <= delta->frame) - { - /* We haven't even replayed this frame yet, so we can't overwrite it! */ return false; - } } - delta->used = true; + + delta->used = true; delta->frame = frame; - delta->crc = 0; + delta->crc = 0; + for (i = 0; i < MAX_INPUT_DEVICES; i++) { clear_input(delta->resolved_input[i]); @@ -170,20 +172,35 @@ netplay_input_state_t netplay_input_state_for(netplay_input_state_t *list, uint32_t netplay_expected_input_size(netplay_t *netplay, uint32_t devices) { uint32_t ret = 0, device; + for (device = 0; device < MAX_INPUT_DEVICES; device++) { - if (!(devices & (1<config_devices[device]&RETRO_DEVICE_MASK) { /* These are all essentially magic numbers, but each device has a * fixed size, documented in network/netplay/README */ - case RETRO_DEVICE_JOYPAD: ret += 1; break; - case RETRO_DEVICE_MOUSE: ret += 2; break; - case RETRO_DEVICE_KEYBOARD: ret += 5; break; - case RETRO_DEVICE_LIGHTGUN: ret += 2; break; - case RETRO_DEVICE_ANALOG: ret += 3; break; - default: break; /* Unsupported */ + case RETRO_DEVICE_JOYPAD: + ret += 1; + break; + case RETRO_DEVICE_MOUSE: + ret += 2; + break; + case RETRO_DEVICE_KEYBOARD: + ret += 5; + break; + case RETRO_DEVICE_LIGHTGUN: + ret += 2; + break; + case RETRO_DEVICE_ANALOG: + ret += 3; + break; + default: + break; /* Unsupported */ } } + return ret; } diff --git a/network/netplay/netplay_frontend.c b/network/netplay/netplay_frontend.c index c84893179a..4ac2da23c0 100644 --- a/network/netplay/netplay_frontend.c +++ b/network/netplay/netplay_frontend.c @@ -128,21 +128,20 @@ static bool netplay_can_poll(netplay_t *netplay) static bool get_self_input_state(netplay_t *netplay) { unsigned i; - struct delta_frame *ptr = &netplay->buffer[netplay->self_ptr]; - netplay_input_state_t istate = NULL; + struct delta_frame *ptr = &netplay->buffer[netplay->self_ptr]; + netplay_input_state_t istate = NULL; uint32_t devices, used_devices = 0, devi, dev_type, local_device; if (!netplay_delta_frame_ready(netplay, ptr, netplay->self_frame_count)) return false; + /* We've already read this frame! */ if (ptr->have_local) - { - /* We've already read this frame! */ return true; - } - devices = netplay->self_devices; + devices = netplay->self_devices; used_devices = 0; + for (devi = 0; devi < MAX_INPUT_DEVICES; devi++) { if (!(devices & (1<config_devices[devi]&RETRO_DEVICE_MASK; + for (local_device = 0; local_device < MAX_INPUT_DEVICES; local_device++) { - if (used_devices & (1<config_devices[local_device]&RETRO_DEVICE_MASK) == dev_type) break; + if (used_devices & (1<config_devices[local_device]&RETRO_DEVICE_MASK) == dev_type) + break; } + if (local_device == MAX_INPUT_DEVICES) local_device = 0; used_devices |= (1<self_frame_count > 0) { - uint32_t *state = istate->data; + uint32_t *state = istate->data; retro_input_state_t cb = netplay->cbs.state_cb; - unsigned dtype = netplay->config_devices[devi]&RETRO_DEVICE_MASK; + unsigned dtype = netplay->config_devices[devi]&RETRO_DEVICE_MASK; switch (dtype) { @@ -326,13 +329,13 @@ static bool netplay_poll(void) if (netplay_data->frame_run_time_avg || netplay_data->stateless_mode) { /* FIXME: Using fixed 60fps for this calculation */ - unsigned frames_per_frame = netplay_data->frame_run_time_avg ? - (16666/netplay_data->frame_run_time_avg) : - 0; - unsigned frames_ahead = (netplay_data->run_frame_count > netplay_data->unread_frame_count) ? - (netplay_data->run_frame_count - netplay_data->unread_frame_count) : - 0; - settings_t *settings = config_get_ptr(); + unsigned frames_per_frame = netplay_data->frame_run_time_avg ? + (16666 / netplay_data->frame_run_time_avg) : + 0; + unsigned frames_ahead = (netplay_data->run_frame_count > netplay_data->unread_frame_count) ? + (netplay_data->run_frame_count - netplay_data->unread_frame_count) : + 0; + settings_t *settings = config_get_ptr(); int input_latency_frames_min = settings->uints.netplay_input_latency_frames_min - (settings->bools.run_ahead_enabled ? settings->uints.run_ahead_frames : 0); int input_latency_frames_max = input_latency_frames_min + settings->uints.netplay_input_latency_frames_range; @@ -350,18 +353,13 @@ static bool netplay_poll(void) /* In stateless mode, we adjust up if we're "close" and down if we * have a lot of slack */ if (netplay_data->input_latency_frames < input_latency_frames_min || - (netplay_data->unread_frame_count == netplay_data->run_frame_count + 1 && - netplay_data->input_latency_frames < input_latency_frames_max)) - { + (netplay_data->unread_frame_count == netplay_data->run_frame_count + 1 && + netplay_data->input_latency_frames < input_latency_frames_max)) netplay_data->input_latency_frames++; - } else if (netplay_data->input_latency_frames > input_latency_frames_max || - (netplay_data->unread_frame_count > netplay_data->run_frame_count + 2 && - netplay_data->input_latency_frames > input_latency_frames_min)) - { + (netplay_data->unread_frame_count > netplay_data->run_frame_count + 2 && + netplay_data->input_latency_frames > input_latency_frames_min)) netplay_data->input_latency_frames--; - } - } else if (netplay_data->input_latency_frames < input_latency_frames_min || (frames_per_frame < frames_ahead && @@ -384,20 +382,20 @@ static bool netplay_poll(void) switch (netplay_data->stall) { case NETPLAY_STALL_RUNNING_FAST: - { - if (netplay_data->unread_frame_count + NETPLAY_MAX_STALL_FRAMES - 2 - > netplay_data->self_frame_count) { - netplay_data->stall = NETPLAY_STALL_NONE; - for (i = 0; i < netplay_data->connections_size; i++) + if (netplay_data->unread_frame_count + NETPLAY_MAX_STALL_FRAMES - 2 + > netplay_data->self_frame_count) { - struct netplay_connection *connection = &netplay_data->connections[i]; - if (connection->active && connection->stall) - connection->stall = NETPLAY_STALL_NONE; + netplay_data->stall = NETPLAY_STALL_NONE; + for (i = 0; i < netplay_data->connections_size; i++) + { + struct netplay_connection *connection = &netplay_data->connections[i]; + if (connection->active && connection->stall) + connection->stall = NETPLAY_STALL_NONE; + } } + break; } - break; - } case NETPLAY_STALL_SPECTATOR_WAIT: if (netplay_data->self_mode == NETPLAY_CONNECTION_PLAYING || netplay_data->unread_frame_count > netplay_data->self_frame_count) @@ -410,7 +408,6 @@ static bool netplay_poll(void) break; case NETPLAY_STALL_SERVER_REQUESTED: - { /* See if the stall is done */ if (netplay_data->connections[0].stall_frame == 0) { @@ -419,16 +416,11 @@ static bool netplay_poll(void) netplay_data->stall = NETPLAY_STALL_NONE; } else - { netplay_data->connections[0].stall_frame--; - } break; - } - case NETPLAY_STALL_NO_CONNECTION: /* We certainly haven't fixed this */ break; - default: /* not stalling */ break; } @@ -513,7 +505,8 @@ static bool netplay_poll(void) } } - if (fixed) { + if (fixed) + { /* Not stalled now :) */ netplay_data->stall = NETPLAY_STALL_NONE; return true; @@ -609,37 +602,33 @@ static int16_t netplay_input_state(netplay_t *netplay, return ((1 << id) & curr_input_state[0]) ? 1 : 0; case RETRO_DEVICE_ANALOG: - { - uint32_t state; - if (istate->size != 3) - return 0; - state = curr_input_state[1 + idx]; - return (int16_t)(uint16_t)(state >> (id * 16)); - } + { + uint32_t state; + if (istate->size != 3) + return 0; + state = curr_input_state[1 + idx]; + return (int16_t)(uint16_t)(state >> (id * 16)); + } case RETRO_DEVICE_MOUSE: case RETRO_DEVICE_LIGHTGUN: - { if (istate->size != 2) return 0; if (id <= RETRO_DEVICE_ID_MOUSE_Y) return (int16_t)(uint16_t)(curr_input_state[1] >> (id * 16)); return ((1 << id) & curr_input_state[0]) ? 1 : 0; - } - case RETRO_DEVICE_KEYBOARD: - { - unsigned key, word, bit; - key = netplay_key_hton(id); - if (key == NETPLAY_KEY_UNKNOWN) + { + unsigned word, bit; + unsigned key = netplay_key_hton(id); + if (key == NETPLAY_KEY_UNKNOWN) + return 0; + word = key / 32; + bit = key % 32; + if (word <= istate->size) + return ((1U<size) - return ((1U<is_server || is_mitm) && (reannounce % 600 == 0)) netplay_announce(); } + /* Make sure that if announcement is turned on mid-game, it gets announced */ else - { - /* Make sure that if announcement is turned on mid-game, it gets announced */ reannounce = -1; - } /* FIXME: This is an ugly way to learn we're not paused anymore */ if (netplay->local_paused) netplay_frontend_paused(netplay, false); + /* Are we ready now? */ if (netplay->quirks & NETPLAY_QUIRK_INITIALIZATION) - { - /* Are we ready now? */ netplay_try_init_serialization(netplay); - } if (netplay->is_server && !settings->bools.netplay_use_mitm_server) { @@ -1151,18 +1136,21 @@ void netplay_post_frame(netplay_t *netplay) static void netplay_force_future(netplay_t *netplay) { /* Wherever we're inputting, that's where we consider our state to be loaded */ - netplay->run_ptr = netplay->self_ptr; + netplay->run_ptr = netplay->self_ptr; netplay->run_frame_count = netplay->self_frame_count; /* We need to ignore any intervening data from the other side, * and never rewind past this */ netplay_update_unread_ptr(netplay); + if (netplay->unread_frame_count < netplay->run_frame_count) { uint32_t client; for (client = 0; client < MAX_CLIENTS; client++) { - if (!(netplay->connected_players & (1<connected_players & (1<read_frame_count[client] < netplay->run_frame_count) { netplay->read_ptr[client] = netplay->run_ptr; @@ -1271,17 +1259,13 @@ void netplay_load_savestate(netplay_t *netplay, else { if (serial_info->size <= netplay->state_size) - { memcpy(netplay->buffer[netplay->run_ptr].state, serial_info->data_const, serial_info->size); - } } } + /* FIXME: This is a critical failure! */ else - { - /* FIXME: This is a critical failure! */ return; - } } /* Don't send it if we're expected to be desynced */ diff --git a/network/netplay/netplay_handshake.c b/network/netplay/netplay_handshake.c index dcaf4ed5ea..37e1de5be7 100644 --- a/network/netplay/netplay_handshake.c +++ b/network/netplay/netplay_handshake.c @@ -223,7 +223,8 @@ bool netplay_handshake_init_send(netplay_t *netplay, if (simple_rand_next == 1) simple_srand((unsigned int) time(NULL)); connection->salt = simple_rand_uint32(); - if (connection->salt == 0) connection->salt = 1; + if (connection->salt == 0) + connection->salt = 1; header[3] = htonl(connection->salt); } else @@ -626,15 +627,17 @@ bool netplay_handshake_sync(netplay_t *netplay, else nickmangle = nicklen; matchct = 1; - do { + do + { nick_matched = false; for (i = 0; i < netplay->connections_size; i++) { struct netplay_connection *sc = &netplay->connections[i]; - if (sc == connection) continue; + if (sc == connection) + continue; if (sc->active && - sc->mode >= NETPLAY_CONNECTION_CONNECTED && - !strncmp(connection->nick, sc->nick, NETPLAY_NICK_LEN)) + sc->mode >= NETPLAY_CONNECTION_CONNECTED && + !strncmp(connection->nick, sc->nick, NETPLAY_NICK_LEN)) { nick_matched = true; break; @@ -718,12 +721,10 @@ bool netplay_handshake_pre_nick(netplay_t *netplay, { settings_t *settings = config_get_ptr(); + /* There's a password, so just put them in PRE_PASSWORD mode */ if ( settings->paths.netplay_password[0] || settings->paths.netplay_spectate_password[0]) - { - /* There's a password, so just put them in PRE_PASSWORD mode */ connection->mode = NETPLAY_CONNECTION_PRE_PASSWORD; - } else { connection->can_play = true; @@ -733,13 +734,10 @@ bool netplay_handshake_pre_nick(netplay_t *netplay, } } + /* Client needs to wait for INFO */ else - { - /* Client needs to wait for INFO */ connection->mode = NETPLAY_CONNECTION_PRE_INFO; - } - *had_input = true; netplay_recv_flush(&connection->recv_packet_buffer); return true; diff --git a/network/netplay/netplay_io.c b/network/netplay/netplay_io.c index bad62962b2..61a7183b05 100644 --- a/network/netplay/netplay_io.c +++ b/network/netplay/netplay_io.c @@ -276,7 +276,8 @@ static bool send_input_frame(netplay_t *netplay, struct delta_frame *dframe, for (i = 0; i < netplay->connections_size; i++) { struct netplay_connection *connection = &netplay->connections[i]; - if (connection == except) continue; + if (connection == except) + continue; if (connection->active && connection->mode >= NETPLAY_CONNECTION_CONNECTED && (connection->mode != NETPLAY_CONNECTION_PLAYING || @@ -585,11 +586,10 @@ static void announce_play_spectate(netplay_t *netplay, for (device = 0; device < MAX_INPUT_DEVICES; device++) { - if (!(devices & (1<device_clients[device]) continue; - if (netplay->device_share_modes[device] && share_mode) continue; + if (!(devices & (1<device_clients[device]) + continue; + if (netplay->device_share_modes[device] && share_mode) + continue; /* Device already taken and unshareable */ payload[0] = htonl(NETPLAY_CMD_MODE_REFUSED_REASON_NOT_AVAILABLE); @@ -800,7 +804,8 @@ static void handle_play_spectate(netplay_t *netplay, uint32_t client_num, /* Set the share mode on any new devices */ for (device = 0; device < MAX_INPUT_DEVICES; device++) { - if (!(devices & (1<device_clients[device]) netplay->device_share_modes[device] = share_mode; } @@ -864,7 +869,8 @@ static void handle_play_spectate(netplay_t *netplay, uint32_t client_num, netplay->client_devices[client_num] = devices; for (device = 0; device < MAX_INPUT_DEVICES; device++) { - if (!(devices & (1<device_clients[device] |= 1 << client_num; } @@ -1301,12 +1307,14 @@ static bool netplay_get_cmd(netplay_t *netplay, { uint32_t dsize; netplay_input_state_t istate; - if (!(devices & (1<real_input[device], client_num, dsize, false, false); - if (!istate) continue; + if (!istate) + continue; memset(istate->data, 0, dsize*sizeof(uint32_t)); } dframe->have_local = true; @@ -1727,7 +1735,9 @@ static bool netplay_get_cmd(netplay_t *netplay, /* Don't expect earlier data from other clients */ for (client = 0; client < MAX_CLIENTS; client++) { - if (!(netplay->connected_players & (1<connected_players & (1< netplay->read_frame_count[client]) { netplay->read_ptr[client] = load_ptr; diff --git a/network/netplay/netplay_room_parse.c b/network/netplay/netplay_room_parse.c index d0259d7e1d..84f85880f1 100644 --- a/network/netplay/netplay_room_parse.c +++ b/network/netplay/netplay_room_parse.c @@ -353,9 +353,11 @@ static void parse_context_error(Context* pCtx) { if (JSON_Parser_GetError(pCtx->parser) != JSON_Error_AbortedByHandler) { - JSON_Error error = JSON_Parser_GetError(pCtx->parser); + JSON_Error error = JSON_Parser_GetError(pCtx->parser); JSON_Location errorLocation = {0, 0, 0}; + (void)JSON_Parser_GetErrorLocation(pCtx->parser, &errorLocation); + RARCH_ERR("invalid JSON at line %d, column %d (input byte %d) - %s.\n", (int)errorLocation.line + 1, (int)errorLocation.column + 1, @@ -375,7 +377,7 @@ static int json_parse(Context* pCtx, const char *buf) return 1; } -void netplay_rooms_free() +void netplay_rooms_free(void) { if (rooms) { @@ -388,15 +390,11 @@ void netplay_rooms_free() struct netplay_room *next = room->next; free(room); - room = next; } - - free(rooms); } - else - free(rooms); + free(rooms); rooms = NULL; } } @@ -451,7 +449,7 @@ struct netplay_room* netplay_room_get(int index) return room; } -int netplay_rooms_get_count() +int netplay_rooms_get_count(void) { int count = 0; struct netplay_room *room; diff --git a/network/netplay/netplay_sync.c b/network/netplay/netplay_sync.c index 7c94ec3670..e6a7277b01 100644 --- a/network/netplay/netplay_sync.c +++ b/network/netplay/netplay_sync.c @@ -42,41 +42,45 @@ void netplay_update_unread_ptr(netplay_t *netplay) if (netplay->is_server && netplay->connected_players<=1) { /* Nothing at all to read! */ - netplay->unread_ptr = netplay->self_ptr; + netplay->unread_ptr = netplay->self_ptr; netplay->unread_frame_count = netplay->self_frame_count; } else { - size_t new_unread_ptr = 0; + size_t new_unread_ptr = 0; uint32_t new_unread_frame_count = (uint32_t) -1; uint32_t client; for (client = 0; client < MAX_CLIENTS; client++) { - if (!(netplay->connected_players & (1<connected_slaves & (1<connected_players & (1<connected_slaves & (1<read_frame_count[client] < new_unread_frame_count) { - new_unread_ptr = netplay->read_ptr[client]; + new_unread_ptr = netplay->read_ptr[client]; new_unread_frame_count = netplay->read_frame_count[client]; } } - if (!netplay->is_server && netplay->server_frame_count < new_unread_frame_count) + 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; + new_unread_ptr = netplay->server_ptr; + new_unread_frame_count = netplay->server_frame_count; } if (new_unread_frame_count != (uint32_t) -1) { - netplay->unread_ptr = new_unread_ptr; + netplay->unread_ptr = new_unread_ptr; netplay->unread_frame_count = new_unread_frame_count; } else { - netplay->unread_ptr = netplay->self_ptr; + netplay->unread_ptr = netplay->self_ptr; netplay->unread_frame_count = netplay->self_frame_count; } } @@ -96,11 +100,13 @@ struct vote_count { netplay_input_state_t netplay_device_client_state(netplay_t *netplay, struct delta_frame *simframe, uint32_t device, uint32_t client) { - uint32_t dsize = netplay_expected_input_size(netplay, 1 << device); + uint32_t dsize = + netplay_expected_input_size(netplay, 1 << device); netplay_input_state_t simstate = netplay_input_state_for( &simframe->real_input[device], client, dsize, false, true); + if (!simstate) { if (netplay->read_frame_count[client] > simframe->frame) @@ -470,13 +476,16 @@ bool netplay_resolve_input(netplay_t *netplay, size_t sim_ptr, bool resim) /* Most devices have all the digital parts in the first word. */ static const uint32_t digital_common[3] = {~0u, 0u, 0u}; static const uint32_t digital_keyboard[5] = {~0u, ~0u, ~0u, ~0u, ~0u}; - const uint32_t *digital; + const uint32_t *digital = NULL; + if (dtype == RETRO_DEVICE_KEYBOARD) digital = digital_keyboard; else digital = digital_common; + oldresstate = netplay_input_state_for( &simframe->resolved_input[device], 1, dsize, false, false); + if (!oldresstate) continue; memcpy(oldresstate->data, resstate->data, dsize * sizeof(uint32_t)); @@ -658,7 +667,8 @@ bool netplay_sync_pre_frame(netplay_t *netplay) /* Allocate a connection */ for (connection_num = 0; connection_num < netplay->connections_size; connection_num++) if (!netplay->connections[connection_num].active && - netplay->connections[connection_num].mode != NETPLAY_CONNECTION_DELAYED_DISCONNECT) break; + netplay->connections[connection_num].mode != NETPLAY_CONNECTION_DELAYED_DISCONNECT) + break; if (connection_num == netplay->connections_size) { if (connection_num == 0) @@ -696,13 +706,13 @@ bool netplay_sync_pre_frame(netplay_t *netplay) } } - connection = &netplay->connections[connection_num]; + connection = &netplay->connections[connection_num]; /* Set it up */ memset(connection, 0, sizeof(*connection)); connection->active = true; - connection->fd = new_fd; - connection->mode = NETPLAY_CONNECTION_INIT; + connection->fd = new_fd; + connection->mode = NETPLAY_CONNECTION_INIT; if (!netplay_init_socket_buffer(&connection->send_packet_buffer, netplay->packet_buffer_size) || @@ -757,11 +767,12 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled) /* Only relevant if we're connected and not in a desynching operation */ if ((netplay->is_server && (netplay->connected_players<=1)) || - (netplay->self_mode < NETPLAY_CONNECTION_CONNECTED) || + (netplay->self_mode < NETPLAY_CONNECTION_CONNECTED) || (netplay->desync)) { netplay->other_frame_count = netplay->self_frame_count; - netplay->other_ptr = netplay->self_ptr; + netplay->other_ptr = netplay->self_ptr; + /* FIXME: Duplication */ if (netplay->catch_up) { @@ -860,13 +871,13 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled) while (netplay->replay_frame_count < netplay->run_frame_count) { retro_time_t start, tm; - struct delta_frame *ptr = &netplay->buffer[netplay->replay_ptr]; - serial_info.data = ptr->state; - serial_info.size = netplay->state_size; - serial_info.data_const = NULL; - start = cpu_features_get_time_usec(); + serial_info.data = ptr->state; + serial_info.size = netplay->state_size; + serial_info.data_const = NULL; + + start = cpu_features_get_time_usec(); /* Remember the current state */ memset(serial_info.data, 0, serial_info.size); @@ -910,20 +921,20 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled) } /* Average our time */ - netplay->frame_run_time_avg = netplay->frame_run_time_sum / NETPLAY_FRAME_RUN_TIME_WINDOW; + netplay->frame_run_time_avg = netplay->frame_run_time_sum / NETPLAY_FRAME_RUN_TIME_WINDOW; if (netplay->unread_frame_count < netplay->run_frame_count) { - netplay->other_ptr = netplay->unread_ptr; + netplay->other_ptr = netplay->unread_ptr; netplay->other_frame_count = netplay->unread_frame_count; } else { - netplay->other_ptr = netplay->run_ptr; + netplay->other_ptr = netplay->run_ptr; netplay->other_frame_count = netplay->run_frame_count; } - netplay->is_replay = false; - netplay->force_rewind = false; + netplay->is_replay = false; + netplay->force_rewind = false; } if (netplay->is_server) @@ -935,15 +946,14 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled) /* Look for players that are ahead of us */ for (client = 0; client < MAX_CLIENTS; client++) { - if (!(netplay->connected_players & (1<connected_players & (1<read_frame_count[client] > hi_frame_count) hi_frame_count = netplay->read_frame_count[client]; } } else - { lo_frame_count = hi_frame_count = netplay->server_frame_count; - } /* If we're behind, try to catch up */ if (netplay->catch_up)