Assert the advertised position data is up to date when serializing

Deserialize reconstructs the last advertised data from the current
position. Assert the equality when serializing, so a future code path
changing the position without advertising fails loudly instead of
desyncing rejoined clients silently.

Asked-by: vladislavbelov on #8978

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
josue 2026-06-12 17:07:29 +02:00
parent fc6a908775
commit b222db28fc

View file

@ -195,6 +195,14 @@ public:
void Serialize(ISerializer& serialize) override
{
// Deserialize reconstructs the last advertised data from the current
// position, which relies on every change to the advertised data being
// advertised before the simulation can serialize.
ENSURE(m_LastAdvertisedInWorld == m_InWorld &&
m_LastAdvertisedX == (m_InWorld ? m_X : entity_pos_t::Zero()) &&
m_LastAdvertisedZ == (m_InWorld ? m_Z : entity_pos_t::Zero()) &&
m_LastAdvertisedRotY == (m_InWorld ? m_RotY : entity_angle_t::Zero()));
serialize.Bool("in world", m_InWorld);
if (m_InWorld)
{