Networking - Start Here

The networking system is responsible for forwarding the input from one player to the other players, with the server acting as the intermediary and authority of important events such as kills/deaths and the position of anything at any point in time.

The game utilizes the concept of "Frames", where each gamestep produces a Frame once the game simulator is done. In a sense, a new game frame is produced by calling something akin to

NewFrame = Simulator.Advance(CurrentFrame, NewInput);

These frames are kept in a ring buffer. As new frames are stored, old ones are tossed out. A frame can be queried either by the frame number or by the time in milliseconds that the frame begun at (starting from 0ms).

Basic Scenario

The server and the clients both keep a historic buffer of frames that they refer to and update as new input comes in. This buffer is currently set at being 1 second long (60 frames per second means 60 buffer entries at any point in time).

Clients apply their own input locally right away and keep simulating the rest of the entities that they currently have. With each player input, an RNG is sent in case we need to apply any randomization to the items that the players use.

When a new packet (which is most often another player input) arrives, the client looks at what frame in the past that input is for, and decides based on some criteria what to do about it.

The server is responsible for deciding when someone has died and applying damage. As such, the clients only really exist to take input and display what is happening.

Reconciliation

If and when the input is applied on a frame, the game is then replayed up to the most recent frame. The newly updated recent frame now becomes the "current frame" that the player sees.

Note that because there is a lot of physics simulation that has to happen each frame, we may want to play around with how many simulations per second we have and find a good spot between accuracy and CPU utilization.

Snapshot Sending

We allow the server to send a full frame to the client that includes the current state of all vehicles (and possibly projectiles?). This could happen when a new player joins, and also when we teleport/recall a player from one area to another and they have no greater context of what is going on around them.

Transport Layer

This is a fairly thin layer that is responsible for client connection states, sending and receiving data without any in-depth payload scanning. It uses enet as the backing UDP library.