Delta encoding multiplayer game state
Old Light is a browser strategy game where a tab can stay open for days. The client holds a full copy of the galaxy state it is allowed to see, and the server keeps that copy honest by sending patches: every change arrives as a world.delta message the client merges into what it already has. Sending changes instead of resending state is textbook delta encoding. What that leaves open is what a game…
Old Light is a browser-based strategy game where a player's tab can remain open for days. The game client maintains a complete copy of the galaxy that the player can view, and the server ensures this copy remains accurate by transmitting changes via world.delta messages. This approach of sending changes instead of entire state is a form of delta encoding.
The challenge lies in determining what information should be included in a game state patch, as well as why the patch received by a rival may differ from the one a player receives themselves.
When people refer to delta encoding, they generally mean byte-level differences, where the sender compares two versions of a file and transmits the changes. However, in the case of Old Light, this approach is not feasible. Sending per-client last known state and computing diffs for each change would be more resource-intensive than simply sending the updates directly. Consequently, Old Light's delta patches focus on stating facts about players and sectors rather than performing byte diffs.
A game state patch in Old Light includes various pieces of information, such as players joining or leaving, updates to players or sectors, and changes to the trade board. The server transmits these patches to all connected clients, allowing them to apply the changes to their individual game states. The patches are designed to be idempotent, meaning that if a patch is received multiple times, the client's state will remain consistent upon each application.
This property is essential for ensuring that the game remains stable even when clients experience connectivity issues or gaps in transmission.
One of the key aspects of Old Light's delta encoding is that each player's or sector's update is represented as a new total value, rather than an incremental change. This design choice simplifies the merging process on the client side, as the client replaces the existing value with the new one provided in the patch. For instance, when a player's score changes, the patch contains the updated score, and the client simply replaces the previous score with the new value.
This approach ensures that the patch is both idempotent and easy to apply, regardless of the client's previous state.
In Old Light, the concept of delta encoding collides with the need for information hiding. While certain aspects of a player's empire, such as star ownership, are public knowledge and are included in the scrubbed update sent to the entire galaxy room, other details, such as the composition of buildings, income, and fleet stacks, are only visible to the player themselves.
The server handles this discrepancy by emitting two different patches for each event: a public version for the galaxy-wide room and a private version for the player's own room. This ensures that players only receive the information they are entitled to, while still maintaining a consistent game state across the network.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.