mirror of
https://github.com/libretro/RetroArch
synced 2025-04-16 08:43:10 +00:00
(netplay_frontend.c) Cleanups
This commit is contained in:
parent
3d510bcaba
commit
d0a2315098
@ -71,6 +71,10 @@ static bool netplay_disconnect(netplay_t *netplay);
|
|||||||
extern bool discord_is_inited;
|
extern bool discord_is_inited;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define NETPLAY_ENABLE_CLIENT() \
|
||||||
|
netplay_enabled = true; \
|
||||||
|
netplay_is_client = true
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* netplay_is_alive:
|
* netplay_is_alive:
|
||||||
* @netplay : pointer to netplay object
|
* @netplay : pointer to netplay object
|
||||||
@ -139,13 +143,14 @@ static bool get_self_input_state(netplay_t *netplay, struct delta_frame *ptr)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Find an appropriate local device */
|
/* Find an appropriate local device */
|
||||||
dev_type = netplay->config_devices[devi]&RETRO_DEVICE_MASK;
|
dev_type = netplay->config_devices[devi] & RETRO_DEVICE_MASK;
|
||||||
|
|
||||||
for (local_device = 0; local_device < MAX_INPUT_DEVICES; local_device++)
|
for (local_device = 0; local_device < MAX_INPUT_DEVICES; local_device++)
|
||||||
{
|
{
|
||||||
if (used_devices & (1 << local_device))
|
if (used_devices & (1 << local_device))
|
||||||
continue;
|
continue;
|
||||||
if ((netplay->config_devices[local_device]&RETRO_DEVICE_MASK) == dev_type)
|
if ((netplay->config_devices[local_device] & RETRO_DEVICE_MASK)
|
||||||
|
== dev_type)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +175,8 @@ static bool get_self_input_state(netplay_t *netplay, struct delta_frame *ptr)
|
|||||||
{
|
{
|
||||||
uint32_t *state = istate->data;
|
uint32_t *state = istate->data;
|
||||||
retro_input_state_t cb = netplay->cbs.state_cb;
|
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)
|
switch (dtype)
|
||||||
{
|
{
|
||||||
@ -219,8 +225,9 @@ static bool get_self_input_state(netplay_t *netplay, struct delta_frame *ptr)
|
|||||||
for (key = 1; key < NETPLAY_KEY_LAST; key++)
|
for (key = 1; key < NETPLAY_KEY_LAST; key++)
|
||||||
{
|
{
|
||||||
state[word] |=
|
state[word] |=
|
||||||
cb(local_device, RETRO_DEVICE_KEYBOARD, 0, netplay_key_ntoh(key)) ?
|
cb(local_device, RETRO_DEVICE_KEYBOARD,
|
||||||
(1U << bit) : 0;
|
0, netplay_key_ntoh(key)) ?
|
||||||
|
(1U << bit) : 0;
|
||||||
bit++;
|
bit++;
|
||||||
if (bit >= 32)
|
if (bit >= 32)
|
||||||
{
|
{
|
||||||
@ -239,16 +246,19 @@ static bool get_self_input_state(netplay_t *netplay, struct delta_frame *ptr)
|
|||||||
ptr->have_local = true;
|
ptr->have_local = true;
|
||||||
if (netplay->self_mode == NETPLAY_CONNECTION_PLAYING)
|
if (netplay->self_mode == NETPLAY_CONNECTION_PLAYING)
|
||||||
{
|
{
|
||||||
ptr->have_real[netplay->self_client_num] = true;
|
ptr->have_real[netplay->self_client_num] = true;
|
||||||
netplay->read_ptr[netplay->self_client_num] = NEXT_PTR(netplay->self_ptr);
|
netplay->read_ptr[netplay->self_client_num] =
|
||||||
netplay->read_frame_count[netplay->self_client_num] = netplay->self_frame_count + 1;
|
NEXT_PTR(netplay->self_ptr);
|
||||||
|
netplay->read_frame_count[netplay->self_client_num] =
|
||||||
|
netplay->self_frame_count + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* And send this input to our peers */
|
/* And send this input to our peers */
|
||||||
for (i = 0; i < netplay->connections_size; i++)
|
for (i = 0; i < netplay->connections_size; i++)
|
||||||
{
|
{
|
||||||
struct netplay_connection *connection = &netplay->connections[i];
|
struct netplay_connection *connection = &netplay->connections[i];
|
||||||
if (connection->active && connection->mode >= NETPLAY_CONNECTION_CONNECTED)
|
if ( connection->active &&
|
||||||
|
connection->mode >= NETPLAY_CONNECTION_CONNECTED)
|
||||||
netplay_send_cur_input(netplay, &netplay->connections[i]);
|
netplay_send_cur_input(netplay, &netplay->connections[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,7 +273,8 @@ bool init_netplay_deferred(const char* server, unsigned port)
|
|||||||
{
|
{
|
||||||
if (!string_is_empty(server) && port != 0)
|
if (!string_is_empty(server) && port != 0)
|
||||||
{
|
{
|
||||||
strlcpy(server_address_deferred, server, sizeof(server_address_deferred));
|
strlcpy(server_address_deferred, server,
|
||||||
|
sizeof(server_address_deferred));
|
||||||
server_port_deferred = port;
|
server_port_deferred = port;
|
||||||
netplay_client_deferred = true;
|
netplay_client_deferred = true;
|
||||||
}
|
}
|
||||||
@ -379,23 +390,23 @@ static bool netplay_poll(netplay_t *netplay)
|
|||||||
switch (netplay->stall)
|
switch (netplay->stall)
|
||||||
{
|
{
|
||||||
case NETPLAY_STALL_RUNNING_FAST:
|
case NETPLAY_STALL_RUNNING_FAST:
|
||||||
|
if (netplay->unread_frame_count + NETPLAY_MAX_STALL_FRAMES - 2
|
||||||
|
> netplay->self_frame_count)
|
||||||
{
|
{
|
||||||
if (netplay->unread_frame_count + NETPLAY_MAX_STALL_FRAMES - 2
|
netplay->stall = NETPLAY_STALL_NONE;
|
||||||
> netplay->self_frame_count)
|
for (i = 0; i < netplay->connections_size; i++)
|
||||||
{
|
{
|
||||||
netplay->stall = NETPLAY_STALL_NONE;
|
struct netplay_connection *connection =
|
||||||
for (i = 0; i < netplay->connections_size; i++)
|
&netplay->connections[i];
|
||||||
{
|
if (connection->active && connection->stall)
|
||||||
struct netplay_connection *connection = &netplay->connections[i];
|
connection->stall = NETPLAY_STALL_NONE;
|
||||||
if (connection->active && connection->stall)
|
|
||||||
connection->stall = NETPLAY_STALL_NONE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case NETPLAY_STALL_SPECTATOR_WAIT:
|
case NETPLAY_STALL_SPECTATOR_WAIT:
|
||||||
if (netplay->self_mode == NETPLAY_CONNECTION_PLAYING || netplay->unread_frame_count > netplay->self_frame_count)
|
if (netplay->self_mode == NETPLAY_CONNECTION_PLAYING
|
||||||
|
|| netplay->unread_frame_count > netplay->self_frame_count)
|
||||||
netplay->stall = NETPLAY_STALL_NONE;
|
netplay->stall = NETPLAY_STALL_NONE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -410,7 +421,7 @@ static bool netplay_poll(netplay_t *netplay)
|
|||||||
{
|
{
|
||||||
/* Stop stalling! */
|
/* Stop stalling! */
|
||||||
netplay->connections[0].stall = NETPLAY_STALL_NONE;
|
netplay->connections[0].stall = NETPLAY_STALL_NONE;
|
||||||
netplay->stall = NETPLAY_STALL_NONE;
|
netplay->stall = NETPLAY_STALL_NONE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
netplay->connections[0].stall_frame--;
|
netplay->connections[0].stall_frame--;
|
||||||
@ -430,7 +441,7 @@ static bool netplay_poll(netplay_t *netplay)
|
|||||||
netplay->connected_players &&
|
netplay->connected_players &&
|
||||||
netplay->run_frame_count + netplay->input_latency_frames > netplay->self_frame_count)
|
netplay->run_frame_count + netplay->input_latency_frames > netplay->self_frame_count)
|
||||||
{
|
{
|
||||||
netplay->stall = NETPLAY_STALL_INPUT_LATENCY;
|
netplay->stall = NETPLAY_STALL_INPUT_LATENCY;
|
||||||
netplay->stall_time = 0;
|
netplay->stall_time = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -449,13 +460,15 @@ static bool netplay_poll(netplay_t *netplay)
|
|||||||
struct netplay_connection *connection;
|
struct netplay_connection *connection;
|
||||||
if (!(netplay->connected_players & (1 << client)))
|
if (!(netplay->connected_players & (1 << client)))
|
||||||
continue;
|
continue;
|
||||||
if (netplay->read_frame_count[client] > netplay->unread_frame_count)
|
if (netplay->read_frame_count[client]
|
||||||
|
> netplay->unread_frame_count)
|
||||||
continue;
|
continue;
|
||||||
connection = &netplay->connections[client-1];
|
connection = &netplay->connections[client-1];
|
||||||
|
|
||||||
if (connection->active &&
|
if (connection->active &&
|
||||||
connection->mode == NETPLAY_CONNECTION_PLAYING)
|
connection->mode == NETPLAY_CONNECTION_PLAYING)
|
||||||
{
|
{
|
||||||
connection->stall = NETPLAY_STALL_RUNNING_FAST;
|
connection->stall = NETPLAY_STALL_RUNNING_FAST;
|
||||||
connection->stall_time = netplay->stall_time;
|
connection->stall_time = netplay->stall_time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -469,7 +482,7 @@ static bool netplay_poll(netplay_t *netplay)
|
|||||||
netplay->self_mode == NETPLAY_CONNECTION_SLAVE) &&
|
netplay->self_mode == NETPLAY_CONNECTION_SLAVE) &&
|
||||||
netplay->unread_frame_count <= netplay->self_frame_count)
|
netplay->unread_frame_count <= netplay->self_frame_count)
|
||||||
{
|
{
|
||||||
netplay->stall = NETPLAY_STALL_SPECTATOR_WAIT;
|
netplay->stall = NETPLAY_STALL_SPECTATOR_WAIT;
|
||||||
netplay->stall_time = cpu_features_get_time_usec();
|
netplay->stall_time = cpu_features_get_time_usec();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -483,34 +496,34 @@ static bool netplay_poll(netplay_t *netplay)
|
|||||||
if (netplay->remote_paused)
|
if (netplay->remote_paused)
|
||||||
netplay->stall_time = now;
|
netplay->stall_time = now;
|
||||||
else if (now - netplay->stall_time >=
|
else if (now - netplay->stall_time >=
|
||||||
(netplay->is_server ? MAX_SERVER_STALL_TIME_USEC :
|
(netplay->is_server
|
||||||
MAX_CLIENT_STALL_TIME_USEC))
|
? MAX_SERVER_STALL_TIME_USEC
|
||||||
|
: MAX_CLIENT_STALL_TIME_USEC)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
|
bool fixed = false;
|
||||||
/* Stalled out! */
|
/* Stalled out! */
|
||||||
if (netplay->is_server)
|
if (!netplay->is_server)
|
||||||
{
|
goto catastrophe;
|
||||||
bool fixed = false;
|
|
||||||
for (i = 0; i < netplay->connections_size; i++)
|
|
||||||
{
|
|
||||||
struct netplay_connection *connection = &netplay->connections[i];
|
|
||||||
if (connection->active &&
|
|
||||||
connection->mode == NETPLAY_CONNECTION_PLAYING &&
|
|
||||||
connection->stall)
|
|
||||||
{
|
|
||||||
netplay_hangup(netplay, connection);
|
|
||||||
fixed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fixed)
|
for (i = 0; i < netplay->connections_size; i++)
|
||||||
|
{
|
||||||
|
struct netplay_connection *connection = &netplay->connections[i];
|
||||||
|
if (connection->active &&
|
||||||
|
connection->mode == NETPLAY_CONNECTION_PLAYING &&
|
||||||
|
connection->stall)
|
||||||
{
|
{
|
||||||
/* Not stalled now :) */
|
netplay_hangup(netplay, connection);
|
||||||
netplay->stall = NETPLAY_STALL_NONE;
|
fixed = true;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
goto catastrophe;
|
if (fixed)
|
||||||
|
{
|
||||||
|
/* Not stalled now :) */
|
||||||
|
netplay->stall = NETPLAY_STALL_NONE;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -676,8 +689,8 @@ static void netplay_announce_cb(retro_task_t *task,
|
|||||||
if (!string_is_empty(line))
|
if (!string_is_empty(line))
|
||||||
{
|
{
|
||||||
struct string_list *kv = string_split(line, "=");
|
struct string_list *kv = string_split(line, "=");
|
||||||
const char *key = NULL;
|
const char *key = NULL;
|
||||||
const char *val = NULL;
|
const char *val = NULL;
|
||||||
|
|
||||||
if (!kv)
|
if (!kv)
|
||||||
continue;
|
continue;
|
||||||
@ -757,14 +770,14 @@ static void netplay_announce_cb(retro_task_t *task,
|
|||||||
port_len = (unsigned)strlen(mitm_port);
|
port_len = (unsigned)strlen(mitm_port);
|
||||||
|
|
||||||
/* Enable Netplay client mode */
|
/* Enable Netplay client mode */
|
||||||
if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_DATA_INITED, NULL))
|
if (netplay_data)
|
||||||
{
|
{
|
||||||
command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
|
command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
|
||||||
is_mitm = true;
|
is_mitm = true;
|
||||||
host_room->host_method = NETPLAY_HOST_METHOD_MITM;
|
host_room->host_method = NETPLAY_HOST_METHOD_MITM;
|
||||||
}
|
}
|
||||||
|
|
||||||
netplay_driver_ctl(RARCH_NETPLAY_CTL_ENABLE_CLIENT, NULL);
|
NETPLAY_ENABLE_CLIENT();
|
||||||
|
|
||||||
host_string = (char*)calloc(1, ip_len + port_len + 2);
|
host_string = (char*)calloc(1, ip_len + port_len + 2);
|
||||||
|
|
||||||
@ -853,9 +866,10 @@ static void netplay_announce(void)
|
|||||||
net_http_urlencode(&username, discord_get_own_username());
|
net_http_urlencode(&username, discord_get_own_username());
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
net_http_urlencode(&username, settings->paths.username);
|
net_http_urlencode(&username, settings->paths.username);
|
||||||
net_http_urlencode(&corename, system->library_name);
|
|
||||||
net_http_urlencode(&coreversion, system->library_version);
|
net_http_urlencode(&corename, system->library_name);
|
||||||
|
net_http_urlencode(&coreversion, system->library_version);
|
||||||
net_http_urlencode(&frontend_ident, frontend_architecture);
|
net_http_urlencode(&frontend_ident, frontend_architecture);
|
||||||
|
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
@ -871,7 +885,8 @@ static void netplay_announce(void)
|
|||||||
*settings->paths.netplay_spectate_password ? 1 : 0,
|
*settings->paths.netplay_spectate_password ? 1 : 0,
|
||||||
settings->bools.netplay_use_mitm_server,
|
settings->bools.netplay_use_mitm_server,
|
||||||
PACKAGE_VERSION, frontend_architecture, subsystemname);
|
PACKAGE_VERSION, frontend_architecture, subsystemname);
|
||||||
task_push_http_post_transfer(url, buf, true, NULL, netplay_announce_cb, NULL);
|
task_push_http_post_transfer(url, buf, true, NULL,
|
||||||
|
netplay_announce_cb, NULL);
|
||||||
|
|
||||||
if (username)
|
if (username)
|
||||||
free(username);
|
free(username);
|
||||||
@ -895,32 +910,6 @@ int16_t input_state_net(unsigned port, unsigned device,
|
|||||||
}
|
}
|
||||||
/* ^^^ Netplay polling callbacks */
|
/* ^^^ Netplay polling callbacks */
|
||||||
|
|
||||||
/**
|
|
||||||
* netplay_command:
|
|
||||||
* @netplay : pointer to netplay object
|
|
||||||
* @cmd : command to send
|
|
||||||
* @data : data to send as argument
|
|
||||||
* @sz : size of data
|
|
||||||
* @command_str : name of action
|
|
||||||
* @success_msg : message to display upon success
|
|
||||||
*
|
|
||||||
* Sends a single netplay command and waits for response. Only actually used
|
|
||||||
* for player flipping. FIXME: Should probably just be removed.
|
|
||||||
*/
|
|
||||||
bool netplay_command(netplay_t* netplay, struct netplay_connection *connection,
|
|
||||||
enum netplay_cmd cmd, void* data, size_t sz, const char* command_str,
|
|
||||||
const char* success_msg)
|
|
||||||
{
|
|
||||||
retro_assert(netplay);
|
|
||||||
|
|
||||||
if (!netplay_send_raw_cmd(netplay, connection, cmd, data, sz))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
runloop_msg_queue_push(success_msg, 1, 180, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* netplay_frontend_paused
|
* netplay_frontend_paused
|
||||||
* @netplay : pointer to netplay object
|
* @netplay : pointer to netplay object
|
||||||
@ -985,7 +974,7 @@ static void netplay_frontend_paused(netplay_t *netplay, bool paused)
|
|||||||
* Returns: true (1) if the frontend is cleared to emulate the frame, false (0)
|
* Returns: true (1) if the frontend is cleared to emulate the frame, false (0)
|
||||||
* if we're stalled or paused
|
* if we're stalled or paused
|
||||||
**/
|
**/
|
||||||
bool netplay_pre_frame(netplay_t *netplay)
|
static bool netplay_pre_frame(netplay_t *netplay)
|
||||||
{
|
{
|
||||||
bool sync_stalled = false;
|
bool sync_stalled = false;
|
||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
@ -1063,7 +1052,7 @@ bool netplay_pre_frame(netplay_t *netplay)
|
|||||||
* We check if we have new input and replay from recorded input.
|
* We check if we have new input and replay from recorded input.
|
||||||
* Call this after running retro_run().
|
* Call this after running retro_run().
|
||||||
**/
|
**/
|
||||||
void netplay_post_frame(netplay_t *netplay)
|
static void netplay_post_frame(netplay_t *netplay)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
retro_assert(netplay);
|
retro_assert(netplay);
|
||||||
@ -1139,7 +1128,7 @@ static void netplay_force_future(netplay_t *netplay)
|
|||||||
* Send a loaded savestate to those connected peers using the given compression
|
* Send a loaded savestate to those connected peers using the given compression
|
||||||
* scheme.
|
* scheme.
|
||||||
*/
|
*/
|
||||||
void netplay_send_savestate(netplay_t *netplay,
|
static void netplay_send_savestate(netplay_t *netplay,
|
||||||
retro_ctx_serialize_info_t *serial_info, uint32_t cx,
|
retro_ctx_serialize_info_t *serial_info, uint32_t cx,
|
||||||
struct compression_transcoder *z)
|
struct compression_transcoder *z)
|
||||||
{
|
{
|
||||||
@ -1496,13 +1485,12 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
|
|||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case RARCH_NETPLAY_CTL_ENABLE_SERVER:
|
case RARCH_NETPLAY_CTL_ENABLE_SERVER:
|
||||||
netplay_enabled = true;
|
netplay_enabled = true;
|
||||||
netplay_is_client = false;
|
netplay_is_client = false;
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
case RARCH_NETPLAY_CTL_ENABLE_CLIENT:
|
case RARCH_NETPLAY_CTL_ENABLE_CLIENT:
|
||||||
netplay_enabled = true;
|
NETPLAY_ENABLE_CLIENT();
|
||||||
netplay_is_client = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RARCH_NETPLAY_CTL_DISABLE:
|
case RARCH_NETPLAY_CTL_DISABLE:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user