mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-13 11:38:19 +00:00
improved crapnet so it changes between different ping configurations. improved the game timer
This commit is contained in:
parent
38a9e32efd
commit
f0760ac0d3
|
@ -270,7 +270,8 @@ static SMOOTHTIME game_time;
|
|||
static SMOOTHTIME predicted_time;
|
||||
|
||||
/* graphs */
|
||||
static GRAPH input_late_graph;
|
||||
static GRAPH inputtime_margin_graph;
|
||||
static GRAPH gametime_margin_graph;
|
||||
static GRAPH fps_graph;
|
||||
|
||||
/* -- snapshot handling --- */
|
||||
|
@ -586,7 +587,8 @@ void client_connect(const char *server_address_str)
|
|||
netclient_connect(net, &server_address);
|
||||
client_set_state(CLIENTSTATE_CONNECTING);
|
||||
|
||||
graph_init(&input_late_graph, 0.0f, 1.0f);
|
||||
graph_init(&inputtime_margin_graph, -150.0f, 150.0f);
|
||||
graph_init(&gametime_margin_graph, -150.0f, 150.0f);
|
||||
}
|
||||
|
||||
void client_disconnect_with_reason(const char *reason)
|
||||
|
@ -734,7 +736,8 @@ static void client_debug_render()
|
|||
graph_scale_max(&fps_graph);
|
||||
graph_scale_min(&fps_graph);
|
||||
graph_render(&fps_graph, x, sp*5, w, h, "FPS");
|
||||
graph_render(&input_late_graph, x, sp*5+h+sp, w, h, "Input Margin");
|
||||
graph_render(&inputtime_margin_graph, x, sp*5+h+sp, w, h, "Prediction Margin");
|
||||
graph_render(&gametime_margin_graph, x, sp*5+h+sp+h+sp, w, h, "Gametime Margin");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1069,17 +1072,13 @@ static void client_process_packet(NETCHUNK *packet)
|
|||
|
||||
if(time_left < 0)
|
||||
{
|
||||
graph_add(&input_late_graph, time_left/100.0f+0.5f, 1,0,0);
|
||||
|
||||
if(config.debug)
|
||||
dbg_msg("client", "input was late with %d ms", time_left);
|
||||
|
||||
graph_add(&inputtime_margin_graph, time_left, 1,0,0);
|
||||
if(predicted_time.up_adjustspeed < 30.0f)
|
||||
predicted_time.up_adjustspeed *= 2.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
graph_add(&input_late_graph, time_left/100.0f+0.5f, 0,1,0);
|
||||
graph_add(&inputtime_margin_graph, time_left, 0,1,0);
|
||||
|
||||
predicted_time.up_adjustspeed *= 0.95f;
|
||||
if(predicted_time.up_adjustspeed < 1.0f)
|
||||
|
@ -1240,6 +1239,31 @@ static void client_process_packet(NETCHUNK *packet)
|
|||
|
||||
/* add new */
|
||||
snapstorage_add(&snapshot_storage, game_tick, time_get(), snapsize, (SNAPSHOT*)tmpbuffer3, 1);
|
||||
|
||||
/* adjust gametime timer */
|
||||
{
|
||||
int64 now = st_get(&game_time, time_get());
|
||||
int64 tickstart = game_tick*time_freq()/50;
|
||||
int64 time_left = (tickstart-now)*1000 / time_freq();
|
||||
|
||||
if(time_left < 0)
|
||||
{
|
||||
graph_add(&gametime_margin_graph, time_left, 1,0,0);
|
||||
if(game_time.down_adjustspeed < 30.0f)
|
||||
{
|
||||
game_time.down_adjustspeed *= 2.0f;
|
||||
dbg_msg("", "%f", game_time.down_adjustspeed);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
graph_add(&gametime_margin_graph, time_left, 0,1,0);
|
||||
|
||||
game_time.down_adjustspeed *= 0.95f;
|
||||
if(game_time.down_adjustspeed < 1.0f)
|
||||
game_time.down_adjustspeed = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
/* add snapshot to demo */
|
||||
if(demorec_isrecording())
|
||||
|
@ -1463,8 +1487,6 @@ static void client_update()
|
|||
intratick = (now - prevtick_start) / (float)(curtick_start-prevtick_start);
|
||||
ticktime = (now - prevtick_start) / (float)freq; /*(float)SERVER_TICK_SPEED);*/
|
||||
|
||||
/*graph_add(&intra_graph, intratick*0.25f);*/
|
||||
|
||||
curtick_start = new_pred_tick*time_freq()/50;
|
||||
prevtick_start = prev_pred_tick*time_freq()/50;
|
||||
predintratick = (pred_now - prevtick_start) / (float)(curtick_start-prevtick_start);
|
||||
|
|
|
@ -19,11 +19,24 @@ static PACKET *first = (PACKET *)0;
|
|||
static PACKET *last = (PACKET *)0;
|
||||
static int current_latency = 0;
|
||||
|
||||
struct PINGCONFIG
|
||||
{
|
||||
int base;
|
||||
int flux;
|
||||
int spike;
|
||||
int loss;
|
||||
};
|
||||
|
||||
static PINGCONFIG config_pings[] = {
|
||||
// base flux spike loss
|
||||
{0, 0, 0, 0},
|
||||
{40, 20, 0, 0},
|
||||
{140, 40, 0, 0},
|
||||
};
|
||||
|
||||
static int config_numpingconfs = sizeof(config_pings)/sizeof(PINGCONFIG);
|
||||
static int config_interval = 10; /* seconds between different pingconfigs */
|
||||
static int config_log = 0;
|
||||
static int config_ping = 40;
|
||||
static int config_pingflux = 20;
|
||||
static int config_pingspike = 0;
|
||||
static int config_packetloss = 1; // in percent
|
||||
static int config_reorder = 0;
|
||||
|
||||
int run(int port, NETADDR dest)
|
||||
|
@ -36,6 +49,14 @@ int run(int port, NETADDR dest)
|
|||
|
||||
while(1)
|
||||
{
|
||||
static int lastcfg = 0;
|
||||
int n = ((time_get()/time_freq())/config_interval) % config_numpingconfs;
|
||||
PINGCONFIG ping = config_pings[n];
|
||||
|
||||
if(n != lastcfg)
|
||||
dbg_msg("crapnet", "cfg = %d", n);
|
||||
lastcfg = n;
|
||||
|
||||
// handle incomming packets
|
||||
while(1)
|
||||
{
|
||||
|
@ -46,7 +67,7 @@ int run(int port, NETADDR dest)
|
|||
if(bytes <= 0)
|
||||
break;
|
||||
|
||||
if((rand()%100) < config_packetloss) // drop the packet
|
||||
if((rand()%100) < ping.loss) // drop the packet
|
||||
{
|
||||
if(config_log)
|
||||
dbg_msg("crapnet", "dropped packet");
|
||||
|
@ -134,9 +155,9 @@ int run(int port, NETADDR dest)
|
|||
|
||||
// update lag
|
||||
double flux = rand()/(double)RAND_MAX;
|
||||
int ms_spike = config_pingspike;
|
||||
int ms_flux = config_pingflux;
|
||||
int ms_ping = config_ping;
|
||||
int ms_spike = ping.spike;
|
||||
int ms_flux = ping.flux;
|
||||
int ms_ping = ping.base;
|
||||
current_latency = ((time_freq()*ms_ping)/1000) + (int64)(((time_freq()*ms_flux)/1000)*flux); // 50ms
|
||||
|
||||
if(ms_spike && (p->id%100) == 0)
|
||||
|
|
Loading…
Reference in a new issue