Hi everyone. Recently I moved over to a sort of dejitter buffer which has been working wonderfully on LAN play tests, which due to slight timing problems wasn't so happy with my last implementation.
consume_move = self.buffer.popleft
# When we run out of moves, wait till we have enough
buffer_length = len(self.buffer)
# Ensure we don't over fill due to network jitter
buffer_limit = (self.buffer_length + self.buffer_padding)
# If we have 0 moves in the buffer
if not buffer_length:
print("Waiting for enough inputs ...")
self.buffer_filling = True
# Prevent too many items filling buffer
# Otherwise we may move to the past slowly and it causes long-term issues
elif buffer_length > buffer_limit:
print("Received too many inputs, dropping ...")
for _ in range(buffer_length - self.buffer_length):
consume_move()
# Clear buffer filling status when we have enough
if self.buffer_filling:
if len(self.buffer) < self.buffer_length:
return
self.buffer_filling = False
# New debug feature, needs clamping at safe maximum
# Ping is the RTT, and we add 1 to ensure the time is at least 1 tick
self.buffer_length += WorldInfo.to_ticks(self.info.ping / 2) + 1
try:
buffered_move = self.buffer[0]
except IndexError:
print("Ran out of moves!")
return
move_tick = buffered_move.tick
# Run the move at the present time (it's valid)
consume_move()
Here is my update code in the main update function for a player (controller)
When running over the internet (using my NAT's external IP and connecting from the machine), it isn't happy with 100 ms dejittering, and when I added the simple increment in the "if self.buffer_filling" branch, it seems happy at around 13 -> 16 ticks, which is around 400 ms. Surely this doesn't seem reasonable?
This seems far too high for a) my internet connection and b) most internet connections. I could have reason to suspect my provider as they're not the best in my opinion, but it seems unusual that so many packets are delayed, as they are each sent individually.
I printed out the number of items in the buffer each tick and it would read something like:
13
12
13
12
12
13
13
13
12
12
13
12
11
10
9
8
7
6
5
4
3
2
1
0
No moves!
14
13
12
13
13
Also, I do seem to notice that every so often a packet is dropped. What would be an expected packet loss statistic for a 4 Mb/s, latency 60ms, internet connection in the UK?
I'm trying to determine if it is some deeper level network code issue (in my codebase) or just life.