Merge pull request #3740 from GregorR/netplay-bugfixes

Netplay bugfixes
This commit is contained in:
Twinaphex 2016-10-05 16:10:18 +02:00 committed by GitHub
commit 2d7265e0d5
3 changed files with 61 additions and 11 deletions

View File

@ -898,6 +898,7 @@ void netplay_log_connection(const struct sockaddr_storage *their_addr,
const char *str = NULL; const char *str = NULL;
char buf_v4[INET_ADDRSTRLEN] = {0}; char buf_v4[INET_ADDRSTRLEN] = {0};
char buf_v6[INET6_ADDRSTRLEN] = {0}; char buf_v6[INET6_ADDRSTRLEN] = {0};
char msg[512] = {0};
u.storage = their_addr; u.storage = their_addr;
@ -937,14 +938,34 @@ void netplay_log_connection(const struct sockaddr_storage *their_addr,
if (str) if (str)
{ {
char msg[512] = {0}; snprintf(msg, sizeof(msg), "Got connection from: \"%s (%s)\"",
nick, str);
snprintf(msg, sizeof(msg), "Got connection from: \"%s (%s)\" (#%u)",
nick, str, slot);
runloop_msg_queue_push(msg, 1, 180, false); runloop_msg_queue_push(msg, 1, 180, false);
RARCH_LOG("%s\n", msg); RARCH_LOG("%s\n", msg);
} }
else
{
snprintf(msg, sizeof(msg), "Got connection from: \"%s\"",
nick);
runloop_msg_queue_push(msg, 1, 180, false);
RARCH_LOG("%s\n", msg);
} }
RARCH_LOG("Connection slot %u\n", slot);
}
#else
void netplay_log_connection(const struct sockaddr_storage *their_addr,
unsigned slot, const char *nick)
{
char msg[512] = {0};
snprintf(msg, sizeof(msg), "Got connection from: \"%s\"",
nick);
runloop_msg_queue_push(msg, 1, 180, false);
RARCH_LOG("%s\n", msg);
RARCH_LOG("Connection slot %u\n", slot);
}
#endif #endif

View File

@ -339,9 +339,7 @@ bool netplay_get_info(netplay_t *netplay)
} }
} }
#ifndef HAVE_SOCKET_LEGACY
netplay_log_connection(&netplay->other_addr, 0, netplay->other_nick); netplay_log_connection(&netplay->other_addr, 0, netplay->other_nick);
#endif
return true; return true;
} }

View File

@ -27,29 +27,42 @@
#include "../../autosave.h" #include "../../autosave.h"
#define TOO_EARLY_TO_SAVE 60 #if 0
#define DEBUG_NONDETERMINISTIC_CORES
#endif
static void netplay_handle_frame_hash(netplay_t *netplay, struct delta_frame *delta) static void netplay_handle_frame_hash(netplay_t *netplay, struct delta_frame *delta)
{ {
static bool crcs_valid = true;
if (netplay_is_server(netplay)) if (netplay_is_server(netplay))
{ {
if (netplay->check_frames && delta->frame % netplay->check_frames == 0) if (netplay->check_frames &&
(delta->frame % netplay->check_frames == 0 || delta->frame == 1))
{ {
delta->crc = netplay_delta_frame_crc(netplay, delta); delta->crc = netplay_delta_frame_crc(netplay, delta);
netplay_cmd_crc(netplay, delta); netplay_cmd_crc(netplay, delta);
} }
} }
else if (delta->crc) else if (delta->crc && crcs_valid)
{ {
/* We have a remote CRC, so check it */ /* We have a remote CRC, so check it */
uint32_t local_crc = netplay_delta_frame_crc(netplay, delta); uint32_t local_crc = netplay_delta_frame_crc(netplay, delta);
if (local_crc != delta->crc) if (local_crc != delta->crc)
{
if (delta->frame == 1)
{
/* We check frame 1 just to make sure the CRCs make sense at all.
* If we've diverged at frame 1, we assume CRCs are not useful. */
crcs_valid = false;
}
else if (crcs_valid)
{ {
/* Fix this! */ /* Fix this! */
netplay_cmd_request_savestate(netplay); netplay_cmd_request_savestate(netplay);
} }
} }
} }
}
/** /**
* netplay_net_pre_frame: * netplay_net_pre_frame:
@ -184,6 +197,7 @@ static void netplay_net_post_frame(netplay_t *netplay)
return; return;
} }
#ifndef DEBUG_NONDETERMINISTIC_CORES
if (!netplay->force_rewind) if (!netplay->force_rewind)
{ {
/* Skip ahead if we predicted correctly. /* Skip ahead if we predicted correctly.
@ -202,6 +216,7 @@ static void netplay_net_post_frame(netplay_t *netplay)
netplay->other_frame_count++; netplay->other_frame_count++;
} }
} }
#endif
/* Now replay the real input if we've gotten ahead of it */ /* Now replay the real input if we've gotten ahead of it */
if (netplay->force_rewind || if (netplay->force_rewind ||
@ -246,6 +261,22 @@ static void netplay_net_post_frame(netplay_t *netplay)
autosave_unlock(); autosave_unlock();
netplay->replay_ptr = NEXT_PTR(netplay->replay_ptr); netplay->replay_ptr = NEXT_PTR(netplay->replay_ptr);
netplay->replay_frame_count++; netplay->replay_frame_count++;
#ifdef DEBUG_NONDETERMINISTIC_CORES
if (ptr->have_remote && netplay_delta_frame_ready(netplay, &netplay->buffer[netplay->replay_ptr], netplay->replay_frame_count))
{
RARCH_LOG("PRE %u: %X\n", netplay->replay_frame_count-1, netplay_delta_frame_crc(netplay, ptr));
if (netplay->is_server)
RARCH_LOG("INP %X %X\n", ptr->real_input_state[0], ptr->self_state[0]);
else
RARCH_LOG("INP %X %X\n", ptr->self_state[0], ptr->real_input_state[0]);
ptr = &netplay->buffer[netplay->replay_ptr];
serial_info.data = ptr->state;
memset(serial_info.data, 0, serial_info.size);
core_serialize(&serial_info);
RARCH_LOG("POST %u: %X\n", netplay->replay_frame_count-1, netplay_delta_frame_crc(netplay, ptr));
}
#endif
} }
if (netplay->read_frame_count < netplay->self_frame_count) if (netplay->read_frame_count < netplay->self_frame_count)