mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
removed input timing from the snapshot messages and put them in a separate message so we don't loose them if the input were late
This commit is contained in:
parent
b42eb55794
commit
599708824f
|
@ -97,6 +97,7 @@ static int prev_tick = 0;
|
|||
/* predicted time */
|
||||
static int current_predtick = 0;
|
||||
static float predintratick = 0;
|
||||
static int last_input_timeleft = 0;
|
||||
|
||||
static struct /* TODO: handle input better */
|
||||
{
|
||||
|
@ -646,6 +647,7 @@ static void client_debug_render()
|
|||
recv_packets, recv_bytes, recv_packets*42, recv_total, (recv_total*8)/1024, recv_bytes/recv_packets);
|
||||
gfx_quads_text(2, 14, 16, buffer);
|
||||
}
|
||||
|
||||
/* render rates */
|
||||
{
|
||||
int y = 0;
|
||||
|
@ -661,6 +663,9 @@ static void client_debug_render()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
str_format(buffer, sizeof(buffer), "input time left: %d", last_input_timeleft);
|
||||
gfx_quads_text(2, 70, 16, buffer);
|
||||
|
||||
/* render graphs */
|
||||
if(config.dbg_graphs)
|
||||
|
@ -993,6 +998,31 @@ static void client_process_packet(NETCHUNK *packet)
|
|||
}
|
||||
else if(msg == NETMSG_PING_REPLY)
|
||||
dbg_msg("client/network", "latency %.2f", (time_get() - ping_start_time)*1000 / (float)time_freq());
|
||||
else if(msg == NETMSG_INPUTTIMING)
|
||||
{
|
||||
int input_predtick = msg_unpack_int();
|
||||
int time_left = msg_unpack_int();
|
||||
|
||||
/* adjust our prediction time */
|
||||
int k;
|
||||
|
||||
graph_add(&input_late_graph, time_left/100.0f+0.5f);
|
||||
|
||||
if(time_left < 0)
|
||||
dbg_msg("client", "input was late with %d ms", time_left);
|
||||
last_input_timeleft = time_left;
|
||||
|
||||
for(k = 0; k < 200; k++) /* TODO: do this better */
|
||||
{
|
||||
if(inputs[k].tick == input_predtick)
|
||||
{
|
||||
/*-1000/50 prediction_margin */
|
||||
int64 target = inputs[k].game_time + (time_get() - inputs[k].time);
|
||||
st_update(&predicted_time, target - (int64)(((time_left-prediction_margin)/1000.0f)*time_freq()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(msg == NETMSG_SNAP || msg == NETMSG_SNAPSINGLE || msg == NETMSG_SNAPEMPTY)
|
||||
{
|
||||
/*dbg_msg("client/network", "got snapshot"); */
|
||||
|
@ -1000,8 +1030,6 @@ static void client_process_packet(NETCHUNK *packet)
|
|||
int part = 0;
|
||||
int game_tick = msg_unpack_int();
|
||||
int delta_tick = game_tick-msg_unpack_int();
|
||||
int input_predtick = msg_unpack_int();
|
||||
int time_left = msg_unpack_int();
|
||||
int part_size = 0;
|
||||
int crc = 0;
|
||||
int complete_size = 0;
|
||||
|
@ -1027,29 +1055,7 @@ static void client_process_packet(NETCHUNK *packet)
|
|||
|
||||
if(msg_unpack_error())
|
||||
return;
|
||||
|
||||
/* TODO: adjust our prediction time */
|
||||
if(time_left)
|
||||
{
|
||||
int k;
|
||||
|
||||
graph_add(&input_late_graph, time_left/100.0f+0.5f);
|
||||
|
||||
if(time_left < 0)
|
||||
dbg_msg("client", "input was late with %d ms", time_left);
|
||||
|
||||
for(k = 0; k < 200; k++) /* TODO: do this better */
|
||||
{
|
||||
if(inputs[k].tick == input_predtick)
|
||||
{
|
||||
/*-1000/50 prediction_margin */
|
||||
int64 target = inputs[k].game_time + (time_get() - inputs[k].time);
|
||||
st_update(&predicted_time, target - (int64)(((time_left-prediction_margin)/1000.0f)*time_freq()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(game_tick >= current_recv_tick)
|
||||
{
|
||||
if(game_tick != current_recv_tick)
|
||||
|
|
|
@ -39,6 +39,7 @@ enum
|
|||
NETMSG_SNAPEMPTY, /* empty snapshot */
|
||||
NETMSG_SNAPSINGLE, /* ? */
|
||||
NETMSG_SNAPSMALL, /* */
|
||||
NETMSG_INPUTTIMING, /* reports how off the input was */
|
||||
NETMSG_RCON_AUTH_STATUS,/* result of the authentication */
|
||||
NETMSG_RCON_LINE, /* line that should be printed to the remote console */
|
||||
|
||||
|
|
|
@ -82,9 +82,7 @@ enum
|
|||
typedef struct
|
||||
{
|
||||
int data[MAX_INPUT_SIZE];
|
||||
int pred_tick; /* tick that the client predicted for the input */
|
||||
int game_tick; /* the tick that was chosen for the input */
|
||||
int64 timeleft; /* how much time in ms there were left before this should be applied */
|
||||
} CLIENT_INPUT;
|
||||
|
||||
/* */
|
||||
|
@ -363,7 +361,7 @@ int server_send_msg(int client_id)
|
|||
|
||||
static void server_do_snap()
|
||||
{
|
||||
int i, k;
|
||||
int i;
|
||||
|
||||
{
|
||||
static PERFORMACE_INFO scope = {"presnap", 0};
|
||||
|
@ -412,8 +410,6 @@ static void server_do_snap()
|
|||
SNAPSHOT *deltashot = &emptysnap;
|
||||
int deltashot_size;
|
||||
int delta_tick = -1;
|
||||
int input_predtick = -1;
|
||||
int64 timeleft = 0;
|
||||
int deltasize;
|
||||
static PERFORMACE_INFO scope = {"build", 0};
|
||||
perf_start(&scope);
|
||||
|
@ -454,16 +450,6 @@ static void server_do_snap()
|
|||
}
|
||||
}
|
||||
|
||||
for(k = 0; k < 200; k++) /* TODO: do this better */
|
||||
{
|
||||
if(clients[i].inputs[k].game_tick == current_tick)
|
||||
{
|
||||
timeleft = clients[i].inputs[k].timeleft;
|
||||
input_predtick = clients[i].inputs[k].pred_tick;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* create delta */
|
||||
{
|
||||
static PERFORMACE_INFO scope = {"delta", 0};
|
||||
|
@ -507,8 +493,6 @@ static void server_do_snap()
|
|||
|
||||
msg_pack_int(current_tick);
|
||||
msg_pack_int(current_tick-delta_tick); /* compressed with */
|
||||
msg_pack_int(input_predtick);
|
||||
msg_pack_int((timeleft*1000)/time_freq());
|
||||
|
||||
if(numpackets != 1)
|
||||
{
|
||||
|
@ -528,8 +512,6 @@ static void server_do_snap()
|
|||
msg_pack_start_system(NETMSG_SNAPEMPTY, MSGFLAG_FLUSH);
|
||||
msg_pack_int(current_tick);
|
||||
msg_pack_int(current_tick-delta_tick); /* compressed with */
|
||||
msg_pack_int(input_predtick);
|
||||
msg_pack_int((timeleft*1000)/time_freq());
|
||||
msg_pack_end();
|
||||
server_send_msg(i);
|
||||
}
|
||||
|
@ -547,10 +529,7 @@ static void reset_client(int cid)
|
|||
/* reset input */
|
||||
int i;
|
||||
for(i = 0; i < 200; i++)
|
||||
{
|
||||
clients[cid].inputs[i].game_tick = -1;
|
||||
clients[cid].inputs[i].pred_tick = -1;
|
||||
}
|
||||
clients[cid].current_input = 0;
|
||||
mem_zero(&clients[cid].latestinput, sizeof(clients[cid].latestinput));
|
||||
|
||||
|
@ -730,9 +709,14 @@ static void server_process_client_packet(NETCHUNK *packet)
|
|||
if(snapstorage_get(&clients[cid].snapshots, clients[cid].last_acked_snapshot, &tagtime, 0, 0) >= 0)
|
||||
clients[cid].latency = (int)(((time_get()-tagtime)*1000)/time_freq());
|
||||
|
||||
/* add message to report the input timing */
|
||||
msg_pack_start_system(NETMSG_INPUTTIMING, MSGFLAG_VITAL);
|
||||
msg_pack_int(tick);
|
||||
msg_pack_int(((server_tick_start_time(tick)-time_get())*1000) / time_freq());
|
||||
msg_pack_end();
|
||||
server_send_msg(cid);
|
||||
|
||||
input = &clients[cid].inputs[clients[cid].current_input];
|
||||
input->timeleft = server_tick_start_time(tick)-time_get();
|
||||
input->pred_tick = tick;
|
||||
|
||||
if(tick <= server_tick())
|
||||
tick = server_tick()+1;
|
||||
|
|
Loading…
Reference in a new issue