N5: Replicate building, world damage, tide and loot
Built pieces, props' health, opened chests and the tide's schedule now reach clients as WORLD messages on the reliable channel, and each player is told what they carry as OWN messages. - NetWorld: the WORLD and OWN wire formats, and world_hash(), a digest of everything replicated this way. - WorldSender: one message after each tick in which something changed, the same for everyone, and the whole state for someone joining or a new match. StructureSet and PropSet keep the change lists it reads. - ClientWorld: applies them to the client's world, so pieces and broken props are solid for prediction. A piece's health follows from its building and damage, so building costs nothing on the wire. - Placing ahead of the server: a provisional piece goes up with the command and is replaced by the server's, or taken back once a snapshot shows the server had its chance. Snapshots carry the newest WORLD number for that. - Protocol version 3. A test plays a whole scripted match on a real island with a ClientGame attached and compares the two worlds' hashes throughout. Closes #36 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+54
-6
@@ -155,7 +155,7 @@ A snapshot is a binary, little-endian packet on channel 1, unreliable:
|
||||
|
||||
| Part | Contents |
|
||||
|---|---|
|
||||
| Header | Message type (u8), server tick (u32), baseline tick (u32, 0 = builds on nothing), simulation tick (u32), the newest command tick received from this client plus one (u32, 0 = none yet), the entity the client is watching (varint) |
|
||||
| Header | Message type (u8), server tick (u32), baseline tick (u32, 0 = builds on nothing), simulation tick (u32), the newest command tick received from this client plus one (u32, 0 = none yet), the number of the newest world message made (u32), the entity the client is watching (varint) |
|
||||
| Match and tide | Match phase (u8), tide phase (u8), sea level in centimetres (s16) |
|
||||
| Own block | A flag (u8), then, while the client's own player is alive and is who it watches, 37 bytes nobody else is sent: position and velocity as f32, the water level around the player as f64, which of the nine flood cells around the player that water reaches (u16), swimming stamina (u16) and state flags (u8) |
|
||||
| Removed | Count (u8), then IDs (varint) |
|
||||
@@ -196,8 +196,55 @@ the newest tick it has received in every snapshot, taken or not.
|
||||
**Match notice.** On joining and at every change of phase the server sends, reliably
|
||||
on channel 0, the match phase, index and seed, so the client can generate the island.
|
||||
|
||||
Building changes will also travel on a reliable ordered event stream (N5), since a
|
||||
dropped wall is a gameplay lie.
|
||||
## World messages
|
||||
|
||||
Built pieces, props, chests and the tide's schedule aren't entities and don't go in
|
||||
snapshots. A wall the client never heard about is a lie it would keep walking into,
|
||||
so they travel on channel 0, reliably and in order, as **WORLD** messages (`NetWorld`,
|
||||
`src/net/`).
|
||||
|
||||
| Part | Contents |
|
||||
|---|---|
|
||||
| Header | Message type (u8), flags (u8: whole state, loot placed, tide follows), sequence number (u32), simulation tick (u32) |
|
||||
| Tide | Only when it starts: the tick it started (u32) and each phase's level (f32) |
|
||||
| New pieces | ID, kind, material and facing in one byte, slot (s16, s8, s16, u8), owner, tick placed (u32), ticks of building done, damage taken |
|
||||
| Damaged pieces | ID and damage taken so far |
|
||||
| Removed pieces | IDs |
|
||||
| Props | Prop and health left, for each one damaged |
|
||||
| Chests | Indices of chests opened |
|
||||
|
||||
Counts and IDs are varints. `WorldSender` makes one message after each tick in which
|
||||
something changed and everyone is sent the same one; a quiet tick makes none. The
|
||||
simulation keeps the lists it reads (`StructureSet.changed` and `.removed`,
|
||||
`PropSet.changed`), so nothing is scanned. Someone joining is sent the **whole state**
|
||||
in one message after the MATCH notice, and so is everyone when a new match's
|
||||
simulation appears.
|
||||
|
||||
What isn't sent: props, chests' places and their contents, which the client rolls
|
||||
itself from the seed, as it does the island; and a piece's health, which follows from
|
||||
how far its building had got, the ticks since, and the damage it has taken. So a
|
||||
piece being built costs nothing on the wire. A scripted match of 12,198 ticks with 24
|
||||
players made 121 messages, 2.3 KB in all. Bots don't build yet, so a match of people
|
||||
building will make far more: a new piece is about 16 bytes to each client.
|
||||
|
||||
`ClientWorld` applies them to the client's world. `NetWorld.world_hash()` covers
|
||||
everything replicated this way, and a client that has applied every message up to a
|
||||
tick agrees with the server's simulation at that tick, which a test checks through a
|
||||
whole match.
|
||||
|
||||
Each player is also told what they carry, as an **OWN** message on the same channel
|
||||
whenever it changes: held selection, materials, the five slots and ammunition.
|
||||
|
||||
**Placing ahead of the server.** When the player's command places a piece and the
|
||||
client's own run of `Building.check` passes, `ClientWorld` puts a provisional piece
|
||||
in its world at once, under an ID the server never uses, and holds its cost back from
|
||||
the materials shown. The server's piece arriving in that slot replaces it. Every
|
||||
snapshot carries the number of the newest WORLD message made, so the client knows
|
||||
when it has heard everything that snapshot's world had in it: once a snapshot from
|
||||
after the placing tick has come, and the world messages up to its number have too,
|
||||
and no piece came, the server turned it down (or never got the command) and the
|
||||
provisional piece is taken away. Losing a race for a slot ends the same way, with
|
||||
the winner's piece standing.
|
||||
|
||||
## Lag compensation
|
||||
|
||||
@@ -260,9 +307,10 @@ which is the normal case. If not, the copy is put where the server says, every c
|
||||
since is run again, and the distance the player's present position moved is the
|
||||
correction. A correction is never shown at once: the drawn position keeps an offset
|
||||
that fades at `NET_CORRECTION_SMOOTH_RATE`, unless it is over 3 m, which is shown as
|
||||
the teleport it is. What the client can't predict yet: built pieces and broken props
|
||||
(not replicated until N5), a basin still filling after a breach, and anything another
|
||||
player does to it.
|
||||
the teleport it is. Built pieces and broken props are solid on the client as soon as
|
||||
their WORLD message arrives, a moment after they are on the server, so a client
|
||||
running into a wall that new is corrected. What the client can't predict: a basin
|
||||
still filling after a breach, and anything another player does to it.
|
||||
|
||||
**Interpolation.** `SnapshotInterpolator` draws every other entity
|
||||
`Tuning.NET_INTERP_DELAY_TICKS` (4 ticks, two snapshots) in the past, on a straight
|
||||
|
||||
Reference in New Issue
Block a user