Game Networking (6) — Event, Input, Command Ring/Buffer/priority/Queue

Daposto
2 min readJul 3, 2020

For event-driven games (see this article) there is a concept called ‘buffering’. Like any other concept, there are different names for this approach. let’s call it ‘buffer’ for now. There are two types of buffers, the ones on the server and the one on the client.

Server Buffer

The basic idea is simple. The server maintains a buffer which is a priority queue of “tick number” mapping to “events” for this player. Any incoming events that have a tick in the past or far future will be discarded. The buffer adds latency to the calculation and is a place were events are buffered until the appropriate tick happens whereafter it will be applied to the server game world. Furthermore, this buffer can be used to supply input events on a steady base to the server.

Client Buffer

The client also maintains one or even two buffers of commands.

One buffer batches outgoing commands for the server, this one contains the tick and command. For reducing packet size one might prefer to bach commands and sent them at some steady interval. The buffer can be implemented as a queue, priority queue (some packets have priority over others), or ring buffer. The implementation is up to the programmer to choose from.

The other one is used for server authority purposes. When a change is made it should be stored such that this change can be matched against the server calculation (server authority). When the client sends a command the server will eventually respond with its predicted state. If the stored state does not match the server version then one needs to simulate the client state from that error point on. This buffer will not grow very big, from what I can tell, you can remove any entry that has been validated by the server.

There is way more to this buffer concept, however, as with the other do your own research here. A possible implementation can be found in my following article.

part 0 (intro)
part 1 (Interval and ticks)
part 2 (Time, Tick, Clock Synchronisation)
part 3 (RTT, PING, latency, lag)
part 4 (Client-Side Extrapolation a.k.a. Dead Reckoning/ Interpolation)
part 5 (Compression, delta encoding, interest management, bit packing)
part 6 (Event, Input, Command Ring/Buffer/priority/Queue)
part 7 (Deterministic vs State)
part 8 (Present, past future where am I)
part 9 (Bonus, Overwatch Model)

--

--

Daposto

Programmer, problem solver, learning everyday. I write about anything mainly to straighten my own thoughts.