(Netplay) Cleanups

This commit is contained in:
twinaphex 2020-01-28 14:56:05 +01:00
parent 096f992cc0
commit 646eba5a92

View File

@ -81,10 +81,8 @@ extern bool discord_is_inited;
**/ **/
static bool netplay_is_alive(netplay_t *netplay) static bool netplay_is_alive(netplay_t *netplay)
{ {
if (!netplay)
return false;
return (netplay->is_server) || return (netplay->is_server) ||
(!netplay->is_server && netplay->self_mode >= NETPLAY_CONNECTION_CONNECTED); (netplay->self_mode >= NETPLAY_CONNECTION_CONNECTED);
} }
/** /**
@ -99,9 +97,9 @@ static bool netplay_is_alive(netplay_t *netplay)
**/ **/
static bool netplay_should_skip(netplay_t *netplay) static bool netplay_should_skip(netplay_t *netplay)
{ {
if (!netplay) if (netplay)
return false; return netplay->is_replay && (netplay->self_mode >= NETPLAY_CONNECTION_CONNECTED);
return netplay->is_replay && (netplay->self_mode >= NETPLAY_CONNECTION_CONNECTED); return false;
} }
/** /**
@ -111,9 +109,9 @@ static bool netplay_should_skip(netplay_t *netplay)
*/ */
static bool netplay_can_poll(netplay_t *netplay) static bool netplay_can_poll(netplay_t *netplay)
{ {
if (!netplay) if (netplay)
return false; return netplay->can_poll;
return netplay->can_poll; return false;
} }
/** /**
@ -566,16 +564,12 @@ static int16_t netplay_input_state(netplay_t *netplay,
unsigned port, unsigned device, unsigned port, unsigned device,
unsigned idx, unsigned id) unsigned idx, unsigned id)
{ {
size_t ptr = netplay->is_replay ?
netplay->replay_ptr : netplay->run_ptr;
struct delta_frame *delta;
netplay_input_state_t istate; netplay_input_state_t istate;
size_t ptr = netplay->is_replay ?
netplay->replay_ptr : netplay->run_ptr;
struct delta_frame *delta = NULL;
const uint32_t *curr_input_state = NULL; const uint32_t *curr_input_state = NULL;
if (port >= MAX_INPUT_DEVICES)
return 0;
/* If the port doesn't seem to correspond to the device, "correct" it. This /* If the port doesn't seem to correspond to the device, "correct" it. This
* is common with devices that typically only have one instance, such as * is common with devices that typically only have one instance, such as
* keyboards, mice and lightguns. */ * keyboards, mice and lightguns. */
@ -896,7 +890,7 @@ int16_t input_state_net(unsigned port, unsigned device,
unsigned idx, unsigned id) unsigned idx, unsigned id)
{ {
netplay_t *netplay = netplay_data; netplay_t *netplay = netplay_data;
if (netplay_is_alive(netplay)) if (netplay && netplay_is_alive(netplay) && port < MAX_INPUT_DEVICES)
return netplay_input_state(netplay, port, device, idx, id); return netplay_input_state(netplay, port, device, idx, id);
return netplay->cbs.state_cb(port, device, idx, id); return netplay->cbs.state_cb(port, device, idx, id);
} }