mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-20 06:58:20 +00:00
continued work on prediction and game timer
This commit is contained in:
parent
82f9be8ce0
commit
9d3fd4a282
|
@ -28,7 +28,7 @@
|
||||||
#include <mastersrv/mastersrv.h>
|
#include <mastersrv/mastersrv.h>
|
||||||
#include <versionsrv/versionsrv.h>
|
#include <versionsrv/versionsrv.h>
|
||||||
|
|
||||||
const int prediction_margin = 1000/50; /* magic network prediction value */
|
const int prediction_margin = 1000/50/2; /* magic network prediction value */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Server Time
|
Server Time
|
||||||
|
@ -236,8 +236,8 @@ static void st_init(SMOOTHTIME *st, int64 target)
|
||||||
st->snap = time_get();
|
st->snap = time_get();
|
||||||
st->current = target;
|
st->current = target;
|
||||||
st->target = target;
|
st->target = target;
|
||||||
st->adjustspeed[0] = 0.2f;
|
st->adjustspeed[0] = 0.3f;
|
||||||
st->adjustspeed[1] = 0.2f;
|
st->adjustspeed[1] = 0.3f;
|
||||||
graph_init(&st->graph, 0.0f, 0.5f);
|
graph_init(&st->graph, 0.0f, 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,22 +280,28 @@ static void st_update(SMOOTHTIME *st, GRAPH *graph, int64 target, int time_left,
|
||||||
|
|
||||||
if(time_left < 0)
|
if(time_left < 0)
|
||||||
{
|
{
|
||||||
|
int is_spike = 0;
|
||||||
if(time_left < -50)
|
if(time_left < -50)
|
||||||
st->spikecounter += 5;
|
|
||||||
|
|
||||||
if(st->spikecounter > 15)
|
|
||||||
{
|
{
|
||||||
graph_add(graph, time_left, 1,0,0);
|
is_spike = 1;
|
||||||
if(st->adjustspeed[adjust_direction] < 30.0f)
|
|
||||||
st->adjustspeed[adjust_direction] *= 2.0f;
|
st->spikecounter += 5;
|
||||||
|
if(st->spikecounter > 50)
|
||||||
|
st->spikecounter = 50;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if(is_spike && st->spikecounter < 15)
|
||||||
{
|
{
|
||||||
/* ignore this ping spike */
|
/* ignore this ping spike */
|
||||||
update_timer = 0;
|
update_timer = 0;
|
||||||
graph_add(graph, time_left, 1,1,0);
|
graph_add(graph, time_left, 1,1,0);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
graph_add(graph, time_left, 1,0,0);
|
||||||
|
if(st->adjustspeed[adjust_direction] < 30.0f)
|
||||||
|
st->adjustspeed[adjust_direction] *= 2.0f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -305,8 +311,8 @@ static void st_update(SMOOTHTIME *st, GRAPH *graph, int64 target, int time_left,
|
||||||
graph_add(graph, time_left, 0,1,0);
|
graph_add(graph, time_left, 0,1,0);
|
||||||
|
|
||||||
st->adjustspeed[adjust_direction] *= 0.95f;
|
st->adjustspeed[adjust_direction] *= 0.95f;
|
||||||
if(st->adjustspeed[adjust_direction] < 1.0f)
|
if(st->adjustspeed[adjust_direction] < 2.0f)
|
||||||
st->adjustspeed[adjust_direction] = 1.0f;
|
st->adjustspeed[adjust_direction] = 2.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
last_input_timeleft = time_left;
|
last_input_timeleft = time_left;
|
||||||
|
|
|
@ -25,13 +25,15 @@ struct PINGCONFIG
|
||||||
int flux;
|
int flux;
|
||||||
int spike;
|
int spike;
|
||||||
int loss;
|
int loss;
|
||||||
|
int delay;
|
||||||
|
int delay_freq;
|
||||||
};
|
};
|
||||||
|
|
||||||
static PINGCONFIG config_pings[] = {
|
static PINGCONFIG config_pings[] = {
|
||||||
// base flux spike loss
|
// base flux spike loss delay delayfreq
|
||||||
{0, 0, 0, 0},
|
{0, 0, 0, 0, 0, 0},
|
||||||
{40, 20, 0, 0},
|
{40, 20, 100, 0, 0, 0},
|
||||||
{140, 40, 0, 0},
|
{140, 40, 200, 0, 0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
static int config_numpingconfs = sizeof(config_pings)/sizeof(PINGCONFIG);
|
static int config_numpingconfs = sizeof(config_pings)/sizeof(PINGCONFIG);
|
||||||
|
@ -46,6 +48,7 @@ int run(int port, NETADDR dest)
|
||||||
|
|
||||||
char buffer[1024*2];
|
char buffer[1024*2];
|
||||||
int id = 0;
|
int id = 0;
|
||||||
|
int delaycounter = 0;
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
|
@ -114,26 +117,42 @@ int run(int port, NETADDR dest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(delaycounter <= 0)
|
||||||
|
{
|
||||||
|
if(ping.delay)
|
||||||
|
p->timestamp += (time_freq()*1000)/ping.delay;
|
||||||
|
delaycounter = ping.delay_freq;
|
||||||
|
}
|
||||||
|
delaycounter--;
|
||||||
|
|
||||||
if(config_log)
|
if(config_log)
|
||||||
dbg_msg("crapnet", "<< %08d %d.%d.%d.%d:%5d (%d)", p->id, from.ip[0], from.ip[1], from.ip[2], from.ip[3], from.port, p->data_size);
|
dbg_msg("crapnet", "<< %08d %d.%d.%d.%d:%5d (%d)", p->id, from.ip[0], from.ip[1], from.ip[2], from.ip[3], from.port, p->data_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
/*while(1)
|
||||||
|
{*/
|
||||||
|
PACKET *p = 0;
|
||||||
|
PACKET *next = first;
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
if(first && (time_get()-first->timestamp) > current_latency)
|
p = next;
|
||||||
|
if(!p)
|
||||||
|
break;
|
||||||
|
next = p->next;
|
||||||
|
|
||||||
|
if((time_get()-p->timestamp) > current_latency)
|
||||||
{
|
{
|
||||||
PACKET *p = first;
|
|
||||||
char flags[] = " ";
|
char flags[] = " ";
|
||||||
|
|
||||||
if(config_reorder && (rand()%2) == 0 && first->next)
|
if(config_reorder && (rand()%2) == 0 && p->next)
|
||||||
{
|
{
|
||||||
flags[0] = 'R';
|
flags[0] = 'R';
|
||||||
p = first->next;
|
p = first->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(p->next)
|
if(p->next)
|
||||||
p->next->prev = 0;
|
p->next->prev = p->prev;
|
||||||
else
|
else
|
||||||
last = p->prev;
|
last = p->prev;
|
||||||
|
|
||||||
|
@ -142,12 +161,12 @@ int run(int port, NETADDR dest)
|
||||||
else
|
else
|
||||||
first = p->next;
|
first = p->next;
|
||||||
|
|
||||||
PACKET *cur = first;
|
/*PACKET *cur = first;
|
||||||
while(cur)
|
while(cur)
|
||||||
{
|
{
|
||||||
dbg_assert(cur != p, "p still in list");
|
dbg_assert(cur != p, "p still in list");
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// send and remove packet
|
// send and remove packet
|
||||||
//if((rand()%20) != 0) // heavy packetloss
|
//if((rand()%20) != 0) // heavy packetloss
|
||||||
|
@ -177,8 +196,6 @@ int run(int port, NETADDR dest)
|
||||||
|
|
||||||
mem_free(p);
|
mem_free(p);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_sleep(1);
|
thread_sleep(1);
|
||||||
|
|
Loading…
Reference in a new issue