mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-17 21:29:19 +02:00
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.
33 lines
1.1 KiB
C++
33 lines
1.1 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
|
|
namespace network
|
|
{
|
|
|
|
// what goes into the digest. bump it whenever the layout changes, so that two builds
|
|
// cannot silently compare digests that mean different things
|
|
constexpr uint32_t STATE_HASH_VERSION = 1;
|
|
|
|
// digest of the gameplay critical state of the world, used to notice that two peers have
|
|
// drifted apart. deliberately order independent: every vehicle is folded in under its own
|
|
// identity and the results are summed, so the order the scenario happened to create them
|
|
// in does not matter. values are quantized, so that harmless float noise does not read as
|
|
// a desync
|
|
//
|
|
// version 1 covers vehicle position, speed, direction and the two brake pressures, plus
|
|
// the simulation clock. positions of switches, memcells and the event queue are the
|
|
// obvious next candidates - they go in when the snapshot work of stage 7 defines them
|
|
uint64_t state_hash();
|
|
|
|
} // namespace network
|