mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 22:48:18 +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 <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
|
||||
|
@ -236,8 +236,8 @@ static void st_init(SMOOTHTIME *st, int64 target)
|
|||
st->snap = time_get();
|
||||
st->current = target;
|
||||
st->target = target;
|
||||
st->adjustspeed[0] = 0.2f;
|
||||
st->adjustspeed[1] = 0.2f;
|
||||
st->adjustspeed[0] = 0.3f;
|
||||
st->adjustspeed[1] = 0.3f;
|
||||
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)
|
||||
{
|
||||
int is_spike = 0;
|
||||
if(time_left < -50)
|
||||
st->spikecounter += 5;
|
||||
|
||||
if(st->spikecounter > 15)
|
||||
{
|
||||
graph_add(graph, time_left, 1,0,0);
|
||||
if(st->adjustspeed[adjust_direction] < 30.0f)
|
||||
st->adjustspeed[adjust_direction] *= 2.0f;
|
||||
is_spike = 1;
|
||||
|
||||
st->spikecounter += 5;
|
||||
if(st->spikecounter > 50)
|
||||
st->spikecounter = 50;
|
||||
}
|
||||
else
|
||||
|
||||
if(is_spike && st->spikecounter < 15)
|
||||
{
|
||||
/* ignore this ping spike */
|
||||
update_timer = 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
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
st->adjustspeed[adjust_direction] *= 0.95f;
|
||||
if(st->adjustspeed[adjust_direction] < 1.0f)
|
||||
st->adjustspeed[adjust_direction] = 1.0f;
|
||||
if(st->adjustspeed[adjust_direction] < 2.0f)
|
||||
st->adjustspeed[adjust_direction] = 2.0f;
|
||||
}
|
||||
|
||||
last_input_timeleft = time_left;
|
||||
|
|
|
@ -25,13 +25,15 @@ struct PINGCONFIG
|
|||
int flux;
|
||||
int spike;
|
||||
int loss;
|
||||
int delay;
|
||||
int delay_freq;
|
||||
};
|
||||
|
||||
static PINGCONFIG config_pings[] = {
|
||||
// base flux spike loss
|
||||
{0, 0, 0, 0},
|
||||
{40, 20, 0, 0},
|
||||
{140, 40, 0, 0},
|
||||
// base flux spike loss delay delayfreq
|
||||
{0, 0, 0, 0, 0, 0},
|
||||
{40, 20, 100, 0, 0, 0},
|
||||
{140, 40, 200, 0, 0, 0},
|
||||
};
|
||||
|
||||
static int config_numpingconfs = sizeof(config_pings)/sizeof(PINGCONFIG);
|
||||
|
@ -46,6 +48,7 @@ int run(int port, NETADDR dest)
|
|||
|
||||
char buffer[1024*2];
|
||||
int id = 0;
|
||||
int delaycounter = 0;
|
||||
|
||||
while(1)
|
||||
{
|
||||
|
@ -97,7 +100,7 @@ int run(int port, NETADDR dest)
|
|||
}
|
||||
last = p;
|
||||
|
||||
// set data in packet
|
||||
// set data in packet
|
||||
p->timestamp = time_get();
|
||||
p->data_size = bytes;
|
||||
p->id = id++;
|
||||
|
@ -113,27 +116,43 @@ int run(int port, NETADDR dest)
|
|||
p->data_size = 6;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(delaycounter <= 0)
|
||||
{
|
||||
if(ping.delay)
|
||||
p->timestamp += (time_freq()*1000)/ping.delay;
|
||||
delaycounter = ping.delay_freq;
|
||||
}
|
||||
delaycounter--;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
//
|
||||
/*while(1)
|
||||
{*/
|
||||
PACKET *p = 0;
|
||||
PACKET *next = first;
|
||||
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[] = " ";
|
||||
|
||||
if(config_reorder && (rand()%2) == 0 && first->next)
|
||||
if(config_reorder && (rand()%2) == 0 && p->next)
|
||||
{
|
||||
flags[0] = 'R';
|
||||
p = first->next;
|
||||
}
|
||||
|
||||
if(p->next)
|
||||
p->next->prev = 0;
|
||||
p->next->prev = p->prev;
|
||||
else
|
||||
last = p->prev;
|
||||
|
||||
|
@ -142,12 +161,12 @@ int run(int port, NETADDR dest)
|
|||
else
|
||||
first = p->next;
|
||||
|
||||
PACKET *cur = first;
|
||||
/*PACKET *cur = first;
|
||||
while(cur)
|
||||
{
|
||||
dbg_assert(cur != p, "p still in list");
|
||||
cur = cur->next;
|
||||
}
|
||||
}*/
|
||||
|
||||
// send and remove packet
|
||||
//if((rand()%20) != 0) // heavy packetloss
|
||||
|
@ -177,10 +196,8 @@ int run(int port, NETADDR dest)
|
|||
|
||||
mem_free(p);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
thread_sleep(1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue