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:
@@ -9,6 +9,7 @@
|
||||
## server -> SNAPSHOT (channel 1, unreliable)
|
||||
## u8 type, u32 server tick, u32 baseline tick (0 = none), u32 simulation tick,
|
||||
## u32 newest command tick received from this client plus one (0 = none yet),
|
||||
## u32 the sequence number of the newest WORLD message made (see NetWorld),
|
||||
## varint the entity the client is watching (its own player, or the one it
|
||||
## spectates; 0 = none), u8 match phase, u8 tide phase, s16 sea level in centimetres,
|
||||
## u8 1 if the client's own block follows, then that block (see SELF_BYTES),
|
||||
@@ -31,7 +32,7 @@ const MSG_INPUT: int = 17
|
||||
|
||||
## The server tick counts every tick the server has run and never goes back, so it
|
||||
## orders snapshots across matches. The simulation tick is the one commands name.
|
||||
const HEADER_BYTES: int = 17
|
||||
const HEADER_BYTES: int = 21
|
||||
const MATCH_BYTES: int = 14
|
||||
## The client's own block: what it needs to predict its own player and nobody else is
|
||||
## told. Exact, not quantized, so a prediction made from it matches the server's to the
|
||||
@@ -241,6 +242,7 @@ static func encode_snapshot(header: Dictionary, removed: PackedInt32Array, recor
|
||||
out.put_u32(int(header.get("baseline", 0)) & 0xFFFFFFFF)
|
||||
out.put_u32(int(header.get("sim_tick", 0)) & 0xFFFFFFFF)
|
||||
out.put_u32((int(header.get("command_tick", -1)) + 1) & 0xFFFFFFFF)
|
||||
out.put_u32(int(header.get("world_seq", 0)) & 0xFFFFFFFF)
|
||||
_put_varint(out, int(header.get("own_id", 0)))
|
||||
out.put_u8(int(header.get("match_phase", 0)))
|
||||
out.put_u8(int(header.get("tide_phase", 0)))
|
||||
@@ -285,7 +287,7 @@ static func encode_snapshot(header: Dictionary, removed: PackedInt32Array, recor
|
||||
|
||||
|
||||
## Reads a SNAPSHOT's header and lists, without applying them: {"tick", "baseline",
|
||||
## "sim_tick", "command_tick" (-1 = none yet), "own_id", "match_phase", "tide_phase",
|
||||
## "sim_tick", "command_tick" (-1 = none yet), "world_seq", "own_id", "match_phase", "tide_phase",
|
||||
## "sea_cm", "self": the client's own block as self_of() made it, or empty, "removed":
|
||||
## PackedInt32Array, "records": [[entity ID, archetype, mask, values]]}, where `values`
|
||||
## holds the fields present, in record order. Empty if malformed.
|
||||
@@ -299,7 +301,7 @@ static func decode_snapshot(bytes: PackedByteArray) -> Dictionary:
|
||||
var at: int = cursor[0]
|
||||
var result: Dictionary = {
|
||||
"tick": bytes.decode_u32(1), "baseline": bytes.decode_u32(5), "sim_tick": bytes.decode_u32(9),
|
||||
"command_tick": bytes.decode_u32(13) - 1,
|
||||
"command_tick": bytes.decode_u32(13) - 1, "world_seq": bytes.decode_u32(17),
|
||||
"own_id": own_id, "match_phase": bytes[at], "tide_phase": bytes[at + 1], "sea_cm": bytes.decode_s16(at + 2),
|
||||
}
|
||||
var own: Dictionary = {}
|
||||
|
||||
Reference in New Issue
Block a user