mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 22:20:21 +00:00
input_latency_frames is now configurable and has a range
This commit is contained in:
parent
5f5a8dc6d7
commit
55157e934d
@ -964,6 +964,8 @@ static struct config_int_setting *populate_settings_int(settings_t *settings, in
|
||||
#ifdef HAVE_NETWORKING
|
||||
SETTING_INT("netplay_ip_port", &settings->netplay.port, true, RARCH_DEFAULT_PORT, false);
|
||||
SETTING_INT("netplay_check_frames", (unsigned*)&settings->netplay.check_frames, true, netplay_check_frames, false);
|
||||
SETTING_INT("netplay_input_latency_frames_min",&settings->netplay.input_latency_frames_min, true, 0, false);
|
||||
SETTING_INT("netplay_input_latency_frames_range",&settings->netplay.input_latency_frames_range, true, 0, false);
|
||||
#endif
|
||||
#ifdef HAVE_LANGEXTRA
|
||||
SETTING_INT("user_language", &settings->user_language, true, RETRO_LANGUAGE_ENGLISH, false);
|
||||
|
@ -407,6 +407,8 @@ typedef struct settings
|
||||
unsigned port;
|
||||
bool stateless_mode;
|
||||
int check_frames;
|
||||
unsigned input_latency_frames_min;
|
||||
unsigned input_latency_frames_range;
|
||||
bool swap_input;
|
||||
bool nat_traversal;
|
||||
char password[128];
|
||||
|
@ -220,12 +220,49 @@ static bool netplay_poll(void)
|
||||
/* Simulate the input if we don't have real input */
|
||||
netplay_simulate_input(netplay_data, netplay_data->run_ptr, false);
|
||||
|
||||
netplay_update_unread_ptr(netplay_data);
|
||||
|
||||
/* Figure out how many frames of input latency we should be using to hide
|
||||
* network latency */
|
||||
if (netplay_data->frame_run_time_avg)
|
||||
{
|
||||
/* FIXME: Using fixed 60fps for this calculation */
|
||||
unsigned frames_per_frame = 16666/netplay_data->frame_run_time_avg;
|
||||
unsigned frames_ahead = (netplay_data->run_frame_count > netplay_data->unread_frame_count) ?
|
||||
(netplay_data->run_frame_count - netplay_data->unread_frame_count) :
|
||||
0;
|
||||
settings_t *settings = config_get_ptr();
|
||||
unsigned input_latency_frames_min = settings->netplay.input_latency_frames_min;
|
||||
unsigned input_latency_frames_max = input_latency_frames_min + settings->netplay.input_latency_frames_range;
|
||||
|
||||
/* Assume we need a couple frames worth of time to actually run the
|
||||
* current frame */
|
||||
if (frames_per_frame > 2)
|
||||
frames_per_frame -= 2;
|
||||
else
|
||||
frames_per_frame = 0;
|
||||
|
||||
/* Shall we adjust our latency? */
|
||||
if (frames_per_frame < frames_ahead &&
|
||||
netplay_data->input_latency_frames < input_latency_frames_max)
|
||||
{
|
||||
/* We can't hide this much network latency with replay, so hide some
|
||||
* with input latency */
|
||||
netplay_data->input_latency_frames++;
|
||||
}
|
||||
else if (frames_per_frame > frames_ahead + 2 &&
|
||||
netplay_data->input_latency_frames > input_latency_frames_min)
|
||||
{
|
||||
/* We don't need this much latency (any more) */
|
||||
netplay_data->input_latency_frames--;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we're stalled, consider unstalling */
|
||||
switch (netplay_data->stall)
|
||||
{
|
||||
case NETPLAY_STALL_RUNNING_FAST:
|
||||
{
|
||||
netplay_update_unread_ptr(netplay_data);
|
||||
if (netplay_data->unread_frame_count + NETPLAY_MAX_STALL_FRAMES - 2
|
||||
> netplay_data->input_frame_count)
|
||||
{
|
||||
@ -272,12 +309,10 @@ static bool netplay_poll(void)
|
||||
/* If we're not stalled, consider stalling */
|
||||
if (!netplay_data->stall)
|
||||
{
|
||||
netplay_update_unread_ptr(netplay_data);
|
||||
|
||||
/* Have we not reat enough latency frames? */
|
||||
if (netplay_data->self_mode == NETPLAY_CONNECTION_PLAYING &&
|
||||
netplay_data->connected_players &&
|
||||
netplay_data->run_frame_count + NETPLAY_INPUT_LATENCY_FRAMES > netplay_data->input_frame_count)
|
||||
netplay_data->run_frame_count + netplay_data->input_latency_frames > netplay_data->input_frame_count)
|
||||
{
|
||||
netplay_data->stall = NETPLAY_STALL_INPUT_LATENCY;
|
||||
netplay_data->stall_time = 0;
|
||||
|
@ -50,9 +50,6 @@
|
||||
#define NETPLAY_MAX_REQ_STALL_TIME 60
|
||||
#define NETPLAY_MAX_REQ_STALL_FREQUENCY 120
|
||||
|
||||
/* TEMPORARY */
|
||||
#define NETPLAY_INPUT_LATENCY_FRAMES 5
|
||||
|
||||
#define PREV_PTR(x) ((x) == 0 ? netplay->buffer_size - 1 : (x) - 1)
|
||||
#define NEXT_PTR(x) ((x + 1) % netplay->buffer_size)
|
||||
|
||||
@ -445,6 +442,9 @@ struct netplay
|
||||
int frame_run_time_ptr;
|
||||
retro_time_t frame_run_time_sum, frame_run_time_avg;
|
||||
|
||||
/* Latency frames and limits */
|
||||
unsigned input_latency_frames;
|
||||
|
||||
/* Are we stalled? */
|
||||
enum rarch_netplay_stall_reason stall;
|
||||
|
||||
|
@ -374,7 +374,7 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled)
|
||||
|
||||
/* We've finished an input frame even if we're stalling, unless we're too
|
||||
* far ahead of ourselves */
|
||||
if (netplay->input_frame_count < netplay->run_frame_count + NETPLAY_INPUT_LATENCY_FRAMES)
|
||||
if (netplay->input_frame_count < netplay->run_frame_count + netplay->input_latency_frames)
|
||||
{
|
||||
netplay->input_ptr = NEXT_PTR(netplay->input_ptr);
|
||||
netplay->input_frame_count++;
|
||||
|
Loading…
x
Reference in New Issue
Block a user