17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 14:29:20 +02:00

multiplayer stage 6: a logical simulation tick and a real state digest

The protocol hung off whatever frame the renderer happened to be drawing, and
the only thing standing in for synchronisation was the sum of every vehicle's
coordinates with a random number added on top - a value that cannot be equal on
two machines and therefore reported a desync on every single step.

- Global.simulation_tick: the authority counts the steps, a client takes the
  number from the authoritative frame it is executing. FRAME_INFO and the
  command requests carry it, so the network timeline has one unambiguous order
  independent of frame rates
- network/statehash: a versioned FNV digest of the gameplay critical state -
  vehicle position, speed, direction, brake pipe and cylinder pressure, plus the
  clock. Values are quantized so that float noise is not mistaken for drift, and
  vehicles are folded in under their own identity and summed, so the digest does
  not depend on the order the scenario created them in. Switches, memcells and
  the event queue are the next candidates; they go in when stage 7 pins down
  what a snapshot contains
- a client compares its own digest against the authoritative one and reports the
  drift when it starts and then only now and then, rather than every step; the
  overlay says how long it has been out of step and at which tick
- refusing to compare at all when the two builds disagree on the digest layout

EU07_NETWORK_VERSION is now 4.
This commit is contained in:
2026-09-06 19:21:12 +00:00
parent 4870935983
commit b255c8120a
13 changed files with 223 additions and 47 deletions

View File

@@ -143,6 +143,7 @@ void network::crew_update::deserialize(std::istream &stream)
void ::network::request_command::serialize(std::ostream &stream) const
{
sn_utils::ls_uint64(stream, tick);
sn_utils::ls_uint32(stream, commands.size());
for (auto const &kv : commands)
{
@@ -167,6 +168,8 @@ void ::network::request_command::serialize(std::ostream &stream) const
void network::request_command::deserialize(std::istream &stream)
{
tick = sn_utils::ld_uint64(stream);
uint32_t commands_size = sn_utils::ld_uint32(stream);
for (uint32_t i = 0; i < commands_size; i++)
{
@@ -200,7 +203,8 @@ void network::frame_info::serialize(std::ostream &stream) const
{
sn_utils::ls_float64(stream, render_dt);
sn_utils::ls_float64(stream, dt);
sn_utils::ls_float64(stream, sync);
sn_utils::ls_uint64(stream, state_hash);
sn_utils::ls_uint32(stream, state_hash_version);
request_command::serialize(stream);
}
@@ -209,7 +213,8 @@ void network::frame_info::deserialize(std::istream &stream)
{
render_dt = sn_utils::ld_float64(stream);
dt = sn_utils::ld_float64(stream);
sync = sn_utils::ld_float64(stream);
state_hash = sn_utils::ld_uint64(stream);
state_hash_version = sn_utils::ld_uint32(stream);
request_command::deserialize(stream);
}