mirror of
https://github.com/libretro/RetroArch
synced 2025-03-03 04:14:00 +00:00
Separating local mode from remote mode.
This commit is contained in:
parent
775584cdac
commit
3908e25895
@ -272,7 +272,7 @@ static void hangup(netplay_t *netplay)
|
||||
{
|
||||
if (!netplay)
|
||||
return;
|
||||
if (netplay->mode == NETPLAY_CONNECTION_NONE)
|
||||
if (netplay->remote_mode == NETPLAY_CONNECTION_NONE)
|
||||
return;
|
||||
|
||||
RARCH_WARN("Netplay has disconnected. Will continue without connection ...\n");
|
||||
@ -290,8 +290,12 @@ static void hangup(netplay_t *netplay)
|
||||
runloop_msg_queue_push("Failed to reinitialize Netplay.", 0, 480, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
netplay->self_mode = NETPLAY_CONNECTION_NONE;
|
||||
}
|
||||
|
||||
netplay->mode = NETPLAY_CONNECTION_NONE;
|
||||
netplay->remote_mode = NETPLAY_CONNECTION_NONE;
|
||||
|
||||
/* Reset things that will behave oddly if we get a new connection */
|
||||
netplay->remote_paused = false;
|
||||
@ -319,7 +323,7 @@ static bool netplay_should_skip(netplay_t *netplay)
|
||||
{
|
||||
if (!netplay)
|
||||
return false;
|
||||
return netplay->is_replay && (netplay->mode == NETPLAY_CONNECTION_PLAYING);
|
||||
return netplay->is_replay && (netplay->self_mode == NETPLAY_CONNECTION_PLAYING);
|
||||
}
|
||||
|
||||
static bool netplay_can_poll(netplay_t *netplay)
|
||||
@ -334,7 +338,7 @@ static bool netplay_can_poll(netplay_t *netplay)
|
||||
static void send_input(netplay_t *netplay)
|
||||
{
|
||||
if (!netplay->spectate.enabled && /* Spectate sends in its own way */
|
||||
netplay->mode == NETPLAY_CONNECTION_PLAYING)
|
||||
netplay->self_mode == NETPLAY_CONNECTION_PLAYING)
|
||||
{
|
||||
netplay->input_packet_buffer[2] = htonl(netplay->self_frame_count);
|
||||
if (!netplay_send(&netplay->send_packet_buffer, netplay->fd,
|
||||
@ -480,7 +484,7 @@ static bool netplay_get_cmd(netplay_t *netplay, bool *had_input)
|
||||
ssize_t recvd;
|
||||
|
||||
/* We don't handle the initial handshake here */
|
||||
switch (netplay->mode)
|
||||
switch (netplay->self_mode)
|
||||
{
|
||||
case NETPLAY_CONNECTION_NONE:
|
||||
/* Huh?! */
|
||||
@ -925,7 +929,7 @@ static bool netplay_poll(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (netplay_data->mode == NETPLAY_CONNECTION_NONE)
|
||||
if (netplay_data->remote_mode == NETPLAY_CONNECTION_NONE)
|
||||
return false;
|
||||
|
||||
netplay_data->can_poll = false;
|
||||
@ -1027,7 +1031,7 @@ static bool netplay_is_alive(void)
|
||||
{
|
||||
if (!netplay_data)
|
||||
return false;
|
||||
return (netplay_data->mode == NETPLAY_CONNECTION_PLAYING);
|
||||
return (netplay_data->remote_mode == NETPLAY_CONNECTION_PLAYING);
|
||||
}
|
||||
|
||||
static bool netplay_flip_port(netplay_t *netplay, bool port)
|
||||
@ -1393,6 +1397,10 @@ netplay_t *netplay_new(void *direct_host, const char *server, uint16_t port,
|
||||
netplay->delay_frames = delay_frames;
|
||||
netplay->check_frames = check_frames;
|
||||
netplay->quirks = quirks;
|
||||
netplay->remote_mode = NETPLAY_CONNECTION_NONE;
|
||||
netplay->self_mode = netplay->is_server ?
|
||||
NETPLAY_CONNECTION_PLAYING :
|
||||
NETPLAY_CONNECTION_NONE;
|
||||
|
||||
strlcpy(netplay->nick, nick[0] ? nick : RARCH_DEFAULT_NICK, sizeof(netplay->nick));
|
||||
|
||||
@ -1589,7 +1597,7 @@ bool netplay_pre_frame(netplay_t *netplay)
|
||||
if (!netplay->net_cbs->pre_frame(netplay))
|
||||
return false;
|
||||
|
||||
return ((netplay->mode != NETPLAY_CONNECTION_PLAYING) ||
|
||||
return ((netplay->remote_mode != NETPLAY_CONNECTION_PLAYING) ||
|
||||
(!netplay->stall && !netplay->remote_paused));
|
||||
}
|
||||
|
||||
@ -1623,7 +1631,7 @@ void netplay_frontend_paused(netplay_t *netplay, bool paused)
|
||||
return;
|
||||
|
||||
netplay->local_paused = paused;
|
||||
if (netplay->mode != NETPLAY_CONNECTION_NONE &&
|
||||
if (netplay->remote_mode != NETPLAY_CONNECTION_NONE &&
|
||||
!netplay->spectate.enabled)
|
||||
{
|
||||
netplay_send_raw_cmd(netplay, paused
|
||||
@ -1651,7 +1659,7 @@ void netplay_load_savestate(netplay_t *netplay,
|
||||
retro_ctx_serialize_info_t tmp_serial_info;
|
||||
uint32_t rd, wn;
|
||||
|
||||
if (netplay->mode != NETPLAY_CONNECTION_PLAYING)
|
||||
if (netplay->remote_mode != NETPLAY_CONNECTION_PLAYING)
|
||||
return;
|
||||
|
||||
/* Record it in our own buffer */
|
||||
@ -1747,7 +1755,7 @@ void netplay_load_savestate(netplay_t *netplay,
|
||||
**/
|
||||
bool netplay_disconnect(netplay_t *netplay)
|
||||
{
|
||||
if (!netplay || (netplay->mode == NETPLAY_CONNECTION_NONE))
|
||||
if (!netplay || (netplay->remote_mode == NETPLAY_CONNECTION_NONE))
|
||||
return true;
|
||||
hangup(netplay);
|
||||
return true;
|
||||
|
@ -286,7 +286,7 @@ bool netplay_handshake_init(netplay_t *netplay, bool *had_input)
|
||||
return false;
|
||||
|
||||
/* Move on to the next mode */
|
||||
netplay->mode = NETPLAY_CONNECTION_PRE_NICK;
|
||||
netplay->self_mode = NETPLAY_CONNECTION_PRE_NICK;
|
||||
*had_input = true;
|
||||
netplay_recv_flush(&netplay->recv_packet_buffer);
|
||||
return true;
|
||||
@ -328,7 +328,7 @@ static void netplay_handshake_ready(netplay_t *netplay)
|
||||
if (netplay->stall == RARCH_NETPLAY_STALL_NO_CONNECTION)
|
||||
netplay->stall = 0;
|
||||
|
||||
netplay->mode = NETPLAY_CONNECTION_PLAYING;
|
||||
netplay->remote_mode = NETPLAY_CONNECTION_PLAYING;
|
||||
}
|
||||
|
||||
bool netplay_handshake_pre_nick(netplay_t *netplay, bool *had_input)
|
||||
@ -365,7 +365,7 @@ bool netplay_handshake_pre_nick(netplay_t *netplay, bool *had_input)
|
||||
if (netplay->is_server)
|
||||
{
|
||||
/* If we're the server, now we send sync info */
|
||||
uint32_t cmd[3];
|
||||
uint32_t cmd[4];
|
||||
retro_ctx_memory_info_t mem_info;
|
||||
|
||||
mem_info.id = RETRO_MEMORY_SAVE_RAM;
|
||||
@ -374,6 +374,7 @@ bool netplay_handshake_pre_nick(netplay_t *netplay, bool *had_input)
|
||||
cmd[0] = htonl(NETPLAY_CMD_SYNC);
|
||||
cmd[1] = htonl(sizeof(uint32_t) + mem_info.size);
|
||||
cmd[2] = htonl(netplay->self_frame_count);
|
||||
cmd[3] = htonl(1);
|
||||
|
||||
if (!netplay_send(&netplay->send_packet_buffer, netplay->fd, cmd,
|
||||
sizeof(cmd)))
|
||||
@ -397,7 +398,7 @@ bool netplay_handshake_pre_nick(netplay_t *netplay, bool *had_input)
|
||||
else
|
||||
{
|
||||
/* Client needs to wait for sync info */
|
||||
netplay->mode = NETPLAY_CONNECTION_PRE_SYNC;
|
||||
netplay->self_mode = NETPLAY_CONNECTION_PRE_SYNC;
|
||||
|
||||
}
|
||||
|
||||
@ -410,7 +411,7 @@ bool netplay_handshake_pre_sync(netplay_t *netplay, bool *had_input)
|
||||
{
|
||||
uint32_t cmd[2];
|
||||
uint32_t local_sram_size, remote_sram_size;
|
||||
uint32_t new_frame_count;
|
||||
uint32_t new_frame_count, self_connection_num;
|
||||
size_t i;
|
||||
ssize_t recvd;
|
||||
retro_ctx_memory_info_t mem_info;
|
||||
@ -420,7 +421,7 @@ bool netplay_handshake_pre_sync(netplay_t *netplay, bool *had_input)
|
||||
|
||||
/* Only expecting a sync command */
|
||||
if (ntohl(cmd[0]) != NETPLAY_CMD_SYNC ||
|
||||
ntohl(cmd[1]) < sizeof(uint32_t))
|
||||
ntohl(cmd[1]) < 2*sizeof(uint32_t))
|
||||
{
|
||||
RARCH_ERR("%s\n",
|
||||
msg_hash_to_str(MSG_FAILED_TO_RECEIVE_SRAM_DATA_FROM_HOST));
|
||||
@ -432,6 +433,11 @@ bool netplay_handshake_pre_sync(netplay_t *netplay, bool *had_input)
|
||||
return false;
|
||||
new_frame_count = ntohl(new_frame_count);
|
||||
|
||||
/* And the connection number */
|
||||
RECV(&self_connection_num, sizeof(self_connection_num))
|
||||
return false;
|
||||
netplay->self_connection_num = ntohl(self_connection_num);
|
||||
|
||||
/* Reset our frame buffer so it's consistent between server and client */
|
||||
netplay->self_frame_count = netplay->other_frame_count =
|
||||
netplay->read_frame_count = new_frame_count;
|
||||
@ -456,7 +462,7 @@ bool netplay_handshake_pre_sync(netplay_t *netplay, bool *had_input)
|
||||
core_get_memory(&mem_info);
|
||||
|
||||
local_sram_size = mem_info.size;
|
||||
remote_sram_size = ntohl(cmd[1]) - sizeof(uint32_t);
|
||||
remote_sram_size = ntohl(cmd[1]) - 2*sizeof(uint32_t);
|
||||
|
||||
if (local_sram_size != 0 && local_sram_size == remote_sram_size)
|
||||
{
|
||||
@ -489,6 +495,7 @@ bool netplay_handshake_pre_sync(netplay_t *netplay, bool *had_input)
|
||||
}
|
||||
|
||||
/* We're ready! */
|
||||
netplay->self_mode = NETPLAY_CONNECTION_PLAYING;
|
||||
netplay_handshake_ready(netplay);
|
||||
*had_input = true;
|
||||
netplay_recv_flush(&netplay->recv_packet_buffer);
|
||||
|
@ -105,13 +105,13 @@ static bool netplay_net_pre_frame(netplay_t *netplay)
|
||||
}
|
||||
|
||||
/* If we can't transmit savestates, we must stall until the client is ready */
|
||||
if (netplay->mode != NETPLAY_CONNECTION_PLAYING &&
|
||||
if (netplay->remote_mode != NETPLAY_CONNECTION_PLAYING &&
|
||||
netplay->self_frame_count > 0 &&
|
||||
(netplay->quirks & (NETPLAY_QUIRK_NO_SAVESTATES|NETPLAY_QUIRK_NO_TRANSMISSION)))
|
||||
netplay->stall = RARCH_NETPLAY_STALL_NO_CONNECTION;
|
||||
}
|
||||
|
||||
if (netplay->is_server && netplay->mode == NETPLAY_CONNECTION_NONE)
|
||||
if (netplay->is_server && netplay->remote_mode == NETPLAY_CONNECTION_NONE)
|
||||
{
|
||||
fd_set fds;
|
||||
struct timeval tmp_tv = {0};
|
||||
@ -168,7 +168,7 @@ static bool netplay_net_pre_frame(netplay_t *netplay)
|
||||
}
|
||||
|
||||
netplay_handshake_init_send(netplay);
|
||||
netplay->mode = NETPLAY_CONNECTION_INIT;
|
||||
netplay->remote_mode = NETPLAY_CONNECTION_INIT;
|
||||
|
||||
}
|
||||
}
|
||||
@ -192,7 +192,7 @@ static void netplay_net_post_frame(netplay_t *netplay)
|
||||
netplay->self_frame_count++;
|
||||
|
||||
/* Only relevant if we're connected */
|
||||
if (netplay->mode != NETPLAY_CONNECTION_PLAYING)
|
||||
if (netplay->remote_mode != NETPLAY_CONNECTION_PLAYING)
|
||||
{
|
||||
netplay->read_frame_count = netplay->other_frame_count = netplay->self_frame_count;
|
||||
netplay->read_ptr = netplay->other_ptr = netplay->self_ptr;
|
||||
@ -321,7 +321,7 @@ static bool netplay_net_info_cb(netplay_t* netplay, unsigned frames)
|
||||
if (!netplay_is_server(netplay))
|
||||
{
|
||||
netplay_handshake_init_send(netplay);
|
||||
netplay->mode = NETPLAY_CONNECTION_INIT;
|
||||
netplay->remote_mode = netplay->self_mode = NETPLAY_CONNECTION_INIT;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -229,8 +229,11 @@ struct netplay
|
||||
char other_nick[32];
|
||||
struct sockaddr_storage other_addr;
|
||||
|
||||
/* Our connection number */
|
||||
uint32_t self_connection_num;
|
||||
|
||||
/* Status of our connection */
|
||||
enum rarch_netplay_connection_mode mode;
|
||||
enum rarch_netplay_connection_mode remote_mode, self_mode;
|
||||
|
||||
struct retro_callbacks cbs;
|
||||
/* TCP connection for state sending, etc. Also used for commands */
|
||||
|
@ -285,7 +285,7 @@ static bool netplay_spectate_info_cb(netplay_t* netplay, unsigned frames)
|
||||
return false;
|
||||
}
|
||||
|
||||
netplay->mode = NETPLAY_CONNECTION_PLAYING;
|
||||
netplay->remote_mode = netplay->self_mode = NETPLAY_CONNECTION_PLAYING;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user