Skip to content

Commit

Permalink
Added comments about latency estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerenaux committed Mar 18, 2017
1 parent e26c4c2 commit c5d7f20
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ io.on('connection',function(socket){
var ss = server.getShortStamp();
var delta = (ss - sentStamp)/2;
if(delta < 0) delta = 0;
socket.pings.push(delta);
if(socket.pings.length > 20) socket.pings.shift();
socket.latency = server.quickMedian(socket.pings.slice(0));
socket.pings.push(delta); // socket.pings is the list of the 20 last latencies
if(socket.pings.length > 20) socket.pings.shift(); // keep the size down to 20
socket.latency = server.quickMedian(socket.pings.slice(0)); // quickMedian used the quickselect algorithm to compute the median of a list of values
});

socket.on('init-world',function(data){
Expand Down

0 comments on commit c5d7f20

Please sign in to comment.