mirror of
https://github.com/libretro/RetroArch
synced 2025-04-07 13:23:32 +00:00
Now that we don't have to start at frame 0, use the server frame count
This commit is contained in:
parent
b3092f6fde
commit
f89e54fcb7
@ -494,8 +494,10 @@ static bool netplay_get_cmd(netplay_t *netplay, bool *had_input)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
case RARCH_NETPLAY_CONNECTION_PRE_SRAM:
|
case RARCH_NETPLAY_CONNECTION_PRE_SRAM:
|
||||||
|
return netplay_handshake_pre_sram(netplay, had_input);
|
||||||
|
case RARCH_NETPLAY_CONNECTION_PRE_FRAME:
|
||||||
{
|
{
|
||||||
bool ret = netplay_handshake_pre_sram(netplay, had_input);
|
bool ret = netplay_handshake_pre_frame(netplay, had_input);
|
||||||
send_input(netplay);
|
send_input(netplay);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -305,24 +305,6 @@ static void netplay_handshake_ready(netplay_t *netplay)
|
|||||||
size_t i;
|
size_t i;
|
||||||
char msg[512];
|
char msg[512];
|
||||||
|
|
||||||
/* Reset our frame count so it's consistent between server and client */
|
|
||||||
netplay->self_frame_count = netplay->other_frame_count = netplay->read_frame_count = 0;
|
|
||||||
for (i = 0; i < netplay->buffer_size; i++)
|
|
||||||
{
|
|
||||||
if (i == netplay->self_ptr)
|
|
||||||
{
|
|
||||||
struct delta_frame *ptr = &netplay->buffer[i];
|
|
||||||
if (!ptr->used)
|
|
||||||
netplay_delta_frame_ready(netplay, ptr, 0);
|
|
||||||
ptr->frame = 0;
|
|
||||||
netplay->other_ptr = netplay->read_ptr = i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
netplay->buffer[i].used = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (netplay->is_server)
|
if (netplay->is_server)
|
||||||
{
|
{
|
||||||
netplay_log_connection(&netplay->other_addr, 0, netplay->other_nick);
|
netplay_log_connection(&netplay->other_addr, 0, netplay->other_nick);
|
||||||
@ -382,8 +364,8 @@ bool netplay_handshake_pre_nick(netplay_t *netplay, bool *had_input)
|
|||||||
|
|
||||||
if (netplay->is_server)
|
if (netplay->is_server)
|
||||||
{
|
{
|
||||||
/* If we're the server, now we send our SRAM */
|
/* If we're the server, now we send our SRAM and frame number */
|
||||||
uint32_t cmd[2];
|
uint32_t cmd[3];
|
||||||
retro_ctx_memory_info_t mem_info;
|
retro_ctx_memory_info_t mem_info;
|
||||||
|
|
||||||
mem_info.id = RETRO_MEMORY_SAVE_RAM;
|
mem_info.id = RETRO_MEMORY_SAVE_RAM;
|
||||||
@ -393,10 +375,17 @@ bool netplay_handshake_pre_nick(netplay_t *netplay, bool *had_input)
|
|||||||
cmd[1] = htonl(mem_info.size);
|
cmd[1] = htonl(mem_info.size);
|
||||||
|
|
||||||
if (!netplay_send(&netplay->send_packet_buffer, netplay->fd, cmd,
|
if (!netplay_send(&netplay->send_packet_buffer, netplay->fd, cmd,
|
||||||
sizeof(cmd)))
|
2*sizeof(uint32_t)))
|
||||||
return false;
|
return false;
|
||||||
if (!netplay_send(&netplay->send_packet_buffer, netplay->fd,
|
if (!netplay_send(&netplay->send_packet_buffer, netplay->fd,
|
||||||
mem_info.data, mem_info.size) ||
|
mem_info.data, mem_info.size))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
cmd[0] = htonl(NETPLAY_CMD_FRAME);
|
||||||
|
cmd[1] = htonl(sizeof(uint32_t));
|
||||||
|
cmd[2] = htonl(netplay->self_frame_count);
|
||||||
|
if (!netplay_send(&netplay->send_packet_buffer, netplay->fd, cmd,
|
||||||
|
sizeof(cmd)) ||
|
||||||
!netplay_send_flush(&netplay->send_packet_buffer, netplay->fd,
|
!netplay_send_flush(&netplay->send_packet_buffer, netplay->fd,
|
||||||
false))
|
false))
|
||||||
return false;
|
return false;
|
||||||
@ -471,6 +460,51 @@ bool netplay_handshake_pre_sram(netplay_t *netplay, bool *had_input)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Finally, wait for the frame number */
|
||||||
|
netplay->status = RARCH_NETPLAY_CONNECTION_PRE_FRAME;
|
||||||
|
*had_input = true;
|
||||||
|
netplay_recv_flush(&netplay->recv_packet_buffer);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool netplay_handshake_pre_frame(netplay_t *netplay, bool *had_input)
|
||||||
|
{
|
||||||
|
uint32_t cmd[3];
|
||||||
|
ssize_t recvd;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
RECV(cmd, sizeof(cmd))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* Only expecting an frame command */
|
||||||
|
if (ntohl(cmd[0]) != NETPLAY_CMD_FRAME ||
|
||||||
|
ntohl(cmd[1]) != sizeof(uint32_t))
|
||||||
|
{
|
||||||
|
/* FIXME: Correct error message */
|
||||||
|
RARCH_ERR("%s\n",
|
||||||
|
msg_hash_to_str(MSG_FAILED_TO_RECEIVE_SRAM_DATA_FROM_HOST));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reset our frame count so it's consistent between server and client */
|
||||||
|
netplay->self_frame_count = netplay->other_frame_count =
|
||||||
|
netplay->read_frame_count = ntohl(cmd[2]);
|
||||||
|
for (i = 0; i < netplay->buffer_size; i++)
|
||||||
|
{
|
||||||
|
if (i == netplay->self_ptr)
|
||||||
|
{
|
||||||
|
struct delta_frame *ptr = &netplay->buffer[i];
|
||||||
|
if (!ptr->used)
|
||||||
|
netplay_delta_frame_ready(netplay, ptr, 0);
|
||||||
|
ptr->frame = netplay->self_frame_count;
|
||||||
|
netplay->other_ptr = netplay->read_ptr = i;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
netplay->buffer[i].used = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* We're ready! */
|
/* We're ready! */
|
||||||
netplay_handshake_ready(netplay);
|
netplay_handshake_ready(netplay);
|
||||||
*had_input = true;
|
*had_input = true;
|
||||||
|
@ -102,11 +102,14 @@ enum netplay_cmd
|
|||||||
/* Send SRAM data (must be second command from server) */
|
/* Send SRAM data (must be second command from server) */
|
||||||
NETPLAY_CMD_SRAM = 0x0021,
|
NETPLAY_CMD_SRAM = 0x0021,
|
||||||
|
|
||||||
|
/* Inform client of current frame number (must be third command from server) */
|
||||||
|
NETPLAY_CMD_FRAME = 0x0022,
|
||||||
|
|
||||||
/* Join spectator mode */
|
/* Join spectator mode */
|
||||||
NETPLAY_CMD_SPECTATE = 0x0022,
|
NETPLAY_CMD_SPECTATE = 0x0023,
|
||||||
|
|
||||||
/* Join play mode */
|
/* Join play mode */
|
||||||
NETPLAY_CMD_PLAY = 0x0023,
|
NETPLAY_CMD_PLAY = 0x0024,
|
||||||
|
|
||||||
/* Loading and synchronization */
|
/* Loading and synchronization */
|
||||||
|
|
||||||
@ -165,6 +168,7 @@ enum rarch_netplay_connection_status
|
|||||||
RARCH_NETPLAY_CONNECTION_INIT, /* Waiting for header */
|
RARCH_NETPLAY_CONNECTION_INIT, /* Waiting for header */
|
||||||
RARCH_NETPLAY_CONNECTION_PRE_NICK, /* Waiting for nick */
|
RARCH_NETPLAY_CONNECTION_PRE_NICK, /* Waiting for nick */
|
||||||
RARCH_NETPLAY_CONNECTION_PRE_SRAM, /* Waiting for SRAM */
|
RARCH_NETPLAY_CONNECTION_PRE_SRAM, /* Waiting for SRAM */
|
||||||
|
RARCH_NETPLAY_CONNECTION_PRE_FRAME, /* Waiting for frame number */
|
||||||
RARCH_NETPLAY_CONNECTION_PLAYING /* Normal ready state */
|
RARCH_NETPLAY_CONNECTION_PLAYING /* Normal ready state */
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -439,6 +443,7 @@ bool netplay_handshake_init_send(netplay_t *netplay);
|
|||||||
bool netplay_handshake_init(netplay_t *netplay, bool *had_input);
|
bool netplay_handshake_init(netplay_t *netplay, bool *had_input);
|
||||||
bool netplay_handshake_pre_nick(netplay_t *netplay, bool *had_input);
|
bool netplay_handshake_pre_nick(netplay_t *netplay, bool *had_input);
|
||||||
bool netplay_handshake_pre_sram(netplay_t *netplay, bool *had_input);
|
bool netplay_handshake_pre_sram(netplay_t *netplay, bool *had_input);
|
||||||
|
bool netplay_handshake_pre_frame(netplay_t *netplay, bool *had_input);
|
||||||
|
|
||||||
uint32_t netplay_impl_magic(void);
|
uint32_t netplay_impl_magic(void);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user