mirror of
https://github.com/libretro/RetroArch
synced 2025-04-09 21:45:45 +00:00
Move driver->netplay_data to netplay.c
This commit is contained in:
parent
6abb01e973
commit
6d71ea6529
2
driver.h
2
driver.h
@ -181,8 +181,6 @@ typedef struct driver
|
|||||||
{
|
{
|
||||||
struct retro_callbacks retro_ctx;
|
struct retro_callbacks retro_ctx;
|
||||||
|
|
||||||
void *netplay_data;
|
|
||||||
|
|
||||||
/* Set this to true if the platform in question needs to 'own'
|
/* Set this to true if the platform in question needs to 'own'
|
||||||
* the respective handle and therefore skip regular RetroArch
|
* the respective handle and therefore skip regular RetroArch
|
||||||
* driver teardown/reiniting procedure.
|
* driver teardown/reiniting procedure.
|
||||||
|
69
netplay.c
69
netplay.c
@ -40,6 +40,21 @@
|
|||||||
#define HAVE_IPV6
|
#define HAVE_IPV6
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define UDP_FRAME_PACKETS 16
|
||||||
|
#define MAX_SPECTATORS 16
|
||||||
|
|
||||||
|
#define PREV_PTR(x) ((x) == 0 ? netplay->buffer_size - 1 : (x) - 1)
|
||||||
|
#define NEXT_PTR(x) ((x + 1) % netplay->buffer_size)
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
CMD_OPT_ALLOWED_IN_SPECTATE_MODE = 0x1,
|
||||||
|
CMD_OPT_REQUIRE_ACK = 0x2,
|
||||||
|
CMD_OPT_HOST_ONLY = 0x4,
|
||||||
|
CMD_OPT_CLIENT_ONLY = 0x8,
|
||||||
|
CMD_OPT_REQUIRE_SYNC = 0x10
|
||||||
|
};
|
||||||
|
|
||||||
struct delta_frame
|
struct delta_frame
|
||||||
{
|
{
|
||||||
void *state;
|
void *state;
|
||||||
@ -52,12 +67,6 @@ struct delta_frame
|
|||||||
bool used_real;
|
bool used_real;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define UDP_FRAME_PACKETS 16
|
|
||||||
#define MAX_SPECTATORS 16
|
|
||||||
|
|
||||||
#define PREV_PTR(x) ((x) == 0 ? netplay->buffer_size - 1 : (x) - 1)
|
|
||||||
#define NEXT_PTR(x) ((x + 1) % netplay->buffer_size)
|
|
||||||
|
|
||||||
struct netplay
|
struct netplay
|
||||||
{
|
{
|
||||||
char nick[32];
|
char nick[32];
|
||||||
@ -130,14 +139,7 @@ struct netplay
|
|||||||
uint32_t pause_frame;
|
uint32_t pause_frame;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
static void *netplay_data;
|
||||||
{
|
|
||||||
CMD_OPT_ALLOWED_IN_SPECTATE_MODE = 0x1,
|
|
||||||
CMD_OPT_REQUIRE_ACK = 0x2,
|
|
||||||
CMD_OPT_HOST_ONLY = 0x4,
|
|
||||||
CMD_OPT_CLIENT_ONLY = 0x8,
|
|
||||||
CMD_OPT_REQUIRE_SYNC = 0x10
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* warn_hangup:
|
* warn_hangup:
|
||||||
@ -551,8 +553,7 @@ static bool netplay_poll(netplay_t *netplay)
|
|||||||
|
|
||||||
void input_poll_net(void)
|
void input_poll_net(void)
|
||||||
{
|
{
|
||||||
driver_t *driver = driver_get_ptr();
|
netplay_t *netplay = (netplay_t*)netplay_data;
|
||||||
netplay_t *netplay = (netplay_t*)driver->netplay_data;
|
|
||||||
if (!netplay_should_skip(netplay) && netplay_can_poll(netplay))
|
if (!netplay_should_skip(netplay) && netplay_can_poll(netplay))
|
||||||
netplay_poll(netplay);
|
netplay_poll(netplay);
|
||||||
}
|
}
|
||||||
@ -560,24 +561,21 @@ void input_poll_net(void)
|
|||||||
void video_frame_net(const void *data, unsigned width,
|
void video_frame_net(const void *data, unsigned width,
|
||||||
unsigned height, size_t pitch)
|
unsigned height, size_t pitch)
|
||||||
{
|
{
|
||||||
driver_t *driver = driver_get_ptr();
|
netplay_t *netplay = (netplay_t*)netplay_data;
|
||||||
netplay_t *netplay = (netplay_t*)driver->netplay_data;
|
|
||||||
if (!netplay_should_skip(netplay))
|
if (!netplay_should_skip(netplay))
|
||||||
netplay->cbs.frame_cb(data, width, height, pitch);
|
netplay->cbs.frame_cb(data, width, height, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio_sample_net(int16_t left, int16_t right)
|
void audio_sample_net(int16_t left, int16_t right)
|
||||||
{
|
{
|
||||||
driver_t *driver = driver_get_ptr();
|
netplay_t *netplay = (netplay_t*)netplay_data;
|
||||||
netplay_t *netplay = (netplay_t*)driver->netplay_data;
|
|
||||||
if (!netplay_should_skip(netplay))
|
if (!netplay_should_skip(netplay))
|
||||||
netplay->cbs.sample_cb(left, right);
|
netplay->cbs.sample_cb(left, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t audio_sample_batch_net(const int16_t *data, size_t frames)
|
size_t audio_sample_batch_net(const int16_t *data, size_t frames)
|
||||||
{
|
{
|
||||||
driver_t *driver = driver_get_ptr();
|
netplay_t *netplay = (netplay_t*)netplay_data;
|
||||||
netplay_t *netplay = (netplay_t*)driver->netplay_data;
|
|
||||||
if (!netplay_should_skip(netplay))
|
if (!netplay_should_skip(netplay))
|
||||||
return netplay->cbs.sample_batch_cb(data, frames);
|
return netplay->cbs.sample_batch_cb(data, frames);
|
||||||
return frames;
|
return frames;
|
||||||
@ -632,8 +630,7 @@ static int16_t netplay_input_state(netplay_t *netplay, bool port, unsigned devic
|
|||||||
int16_t input_state_net(unsigned port, unsigned device,
|
int16_t input_state_net(unsigned port, unsigned device,
|
||||||
unsigned idx, unsigned id)
|
unsigned idx, unsigned id)
|
||||||
{
|
{
|
||||||
driver_t *driver = driver_get_ptr();
|
netplay_t *netplay = (netplay_t*)netplay_data;
|
||||||
netplay_t *netplay = (netplay_t*)driver->netplay_data;
|
|
||||||
if (netplay_is_alive(netplay))
|
if (netplay_is_alive(netplay))
|
||||||
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);
|
||||||
@ -1470,8 +1467,7 @@ static void netplay_set_spectate_input(netplay_t *netplay, int16_t input)
|
|||||||
int16_t input_state_spectate(unsigned port, unsigned device,
|
int16_t input_state_spectate(unsigned port, unsigned device,
|
||||||
unsigned idx, unsigned id)
|
unsigned idx, unsigned id)
|
||||||
{
|
{
|
||||||
driver_t *driver = driver_get_ptr();
|
netplay_t *netplay = (netplay_t*)netplay_data;
|
||||||
netplay_t *netplay = (netplay_t*)driver->netplay_data;
|
|
||||||
int16_t res = netplay->cbs.state_cb(port, device, idx, id);
|
int16_t res = netplay->cbs.state_cb(port, device, idx, id);
|
||||||
|
|
||||||
netplay_set_spectate_input(netplay, res);
|
netplay_set_spectate_input(netplay, res);
|
||||||
@ -1496,8 +1492,7 @@ static int16_t netplay_get_spectate_input(netplay_t *netplay, bool port,
|
|||||||
int16_t input_state_spectate_client(unsigned port, unsigned device,
|
int16_t input_state_spectate_client(unsigned port, unsigned device,
|
||||||
unsigned idx, unsigned id)
|
unsigned idx, unsigned id)
|
||||||
{
|
{
|
||||||
driver_t *driver = driver_get_ptr();
|
return netplay_get_spectate_input((netplay_t*)netplay_data, port,
|
||||||
return netplay_get_spectate_input((netplay_t*)driver->netplay_data, port,
|
|
||||||
device, idx, id);
|
device, idx, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1733,11 +1728,10 @@ void netplay_post_frame(netplay_t *netplay)
|
|||||||
|
|
||||||
void deinit_netplay(void)
|
void deinit_netplay(void)
|
||||||
{
|
{
|
||||||
driver_t *driver = driver_get_ptr();
|
netplay_t *netplay = (netplay_t*)netplay_data;
|
||||||
netplay_t *netplay = (netplay_t*)driver->netplay_data;
|
|
||||||
if (netplay)
|
if (netplay)
|
||||||
netplay_free(netplay);
|
netplay_free(netplay);
|
||||||
driver->netplay_data = NULL;
|
netplay_data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define RARCH_DEFAULT_PORT 55435
|
#define RARCH_DEFAULT_PORT 55435
|
||||||
@ -1755,7 +1749,6 @@ void deinit_netplay(void)
|
|||||||
bool init_netplay(void)
|
bool init_netplay(void)
|
||||||
{
|
{
|
||||||
struct retro_callbacks cbs = {0};
|
struct retro_callbacks cbs = {0};
|
||||||
driver_t *driver = driver_get_ptr();
|
|
||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
global_t *global = global_get_ptr();
|
global_t *global = global_get_ptr();
|
||||||
|
|
||||||
@ -1778,13 +1771,13 @@ bool init_netplay(void)
|
|||||||
else
|
else
|
||||||
RARCH_LOG("Waiting for client...\n");
|
RARCH_LOG("Waiting for client...\n");
|
||||||
|
|
||||||
driver->netplay_data = (netplay_t*)netplay_new(
|
netplay_data = (netplay_t*)netplay_new(
|
||||||
global->netplay.is_client ? global->netplay.server : NULL,
|
global->netplay.is_client ? global->netplay.server : NULL,
|
||||||
global->netplay.port ? global->netplay.port : RARCH_DEFAULT_PORT,
|
global->netplay.port ? global->netplay.port : RARCH_DEFAULT_PORT,
|
||||||
global->netplay.sync_frames, &cbs, global->netplay.is_spectate,
|
global->netplay.sync_frames, &cbs, global->netplay.is_spectate,
|
||||||
settings->username);
|
settings->username);
|
||||||
|
|
||||||
if (driver->netplay_data)
|
if (netplay_data)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
global->netplay.is_client = false;
|
global->netplay.is_client = false;
|
||||||
@ -1798,9 +1791,7 @@ bool init_netplay(void)
|
|||||||
|
|
||||||
bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
|
bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
|
||||||
{
|
{
|
||||||
driver_t *driver = driver_get_ptr();
|
if (!netplay_data)
|
||||||
|
|
||||||
if (!driver->netplay_data)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (state)
|
switch (state)
|
||||||
@ -1808,10 +1799,10 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
|
|||||||
case RARCH_NETPLAY_CTL_IS_DATA_INITED:
|
case RARCH_NETPLAY_CTL_IS_DATA_INITED:
|
||||||
return true;
|
return true;
|
||||||
case RARCH_NETPLAY_CTL_POST_FRAME:
|
case RARCH_NETPLAY_CTL_POST_FRAME:
|
||||||
netplay_post_frame((netplay_t*)driver->netplay_data);
|
netplay_post_frame((netplay_t*)netplay_data);
|
||||||
break;
|
break;
|
||||||
case RARCH_NETPLAY_CTL_PRE_FRAME:
|
case RARCH_NETPLAY_CTL_PRE_FRAME:
|
||||||
netplay_pre_frame((netplay_t*)driver->netplay_data);
|
netplay_pre_frame((netplay_t*)netplay_data);
|
||||||
break;
|
break;
|
||||||
case RARCH_NETPLAY_CTL_FLIP_PLAYERS:
|
case RARCH_NETPLAY_CTL_FLIP_PLAYERS:
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user