From 4a78062f5438ff55d14f9607dc40e32c6e776cc3 Mon Sep 17 00:00:00 2001 From: Matt <5415177+ZehMatt@users.noreply.github.com> Date: Sun, 17 Nov 2024 19:49:47 +0200 Subject: [PATCH] Fix #23206: Desyncs when using uncapped FPS Because the position is one tick behind the spatial mapping was incorrect, it's not allowed to modify that during interpolation. --- distribution/changelog.txt | 1 + src/openrct2/entity/EntityRegistry.cpp | 20 ++++++++++---------- src/openrct2/entity/EntityRegistry.h | 1 - src/openrct2/entity/EntityTweener.cpp | 6 +----- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 758103600b..7411f41770 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -3,6 +3,7 @@ - Feature: [#23166] Add Galician translation. - Improved: [#23051] Add large sloped turns and new inversions to the Twister, Vertical Drop, Hyper and Flying Roller Coasters. - Improved: [#23123] Improve sorting of roller coasters in build new ride menu. +- Fix: [#23206] Multiplayer desyncs when FPS is uncapped. 0.4.16 (2024-11-03) ------------------------------------------------------------------------ diff --git a/src/openrct2/entity/EntityRegistry.cpp b/src/openrct2/entity/EntityRegistry.cpp index b3a5f76991..4d7e883689 100644 --- a/src/openrct2/entity/EntityRegistry.cpp +++ b/src/openrct2/entity/EntityRegistry.cpp @@ -481,6 +481,16 @@ void EntityBase::SetLocation(const CoordsXYZ& newLocation) SpatialIndex |= kSpatialIndexDirtyMask; } +static void EntitySetCoordinates(const CoordsXYZ& entityPos, EntityBase* entity) +{ + auto screenCoords = Translate3DTo2DWithZ(GetCurrentRotation(), entityPos); + + entity->SpriteData.SpriteRect = ScreenRect( + screenCoords - ScreenCoordsXY{ entity->SpriteData.Width, entity->SpriteData.HeightMin }, + screenCoords + ScreenCoordsXY{ entity->SpriteData.Width, entity->SpriteData.HeightMax }); + entity->SetLocation(entityPos); +} + void EntityBase::MoveTo(const CoordsXYZ& newLocation) { if (x != kLocationNull) @@ -506,16 +516,6 @@ void EntityBase::MoveTo(const CoordsXYZ& newLocation) } } -void EntitySetCoordinates(const CoordsXYZ& entityPos, EntityBase* entity) -{ - auto screenCoords = Translate3DTo2DWithZ(GetCurrentRotation(), entityPos); - - entity->SpriteData.SpriteRect = ScreenRect( - screenCoords - ScreenCoordsXY{ entity->SpriteData.Width, entity->SpriteData.HeightMin }, - screenCoords + ScreenCoordsXY{ entity->SpriteData.Width, entity->SpriteData.HeightMax }); - entity->SetLocation(entityPos); -} - /** * Frees any dynamically attached memory to the entity, such as peep name. */ diff --git a/src/openrct2/entity/EntityRegistry.h b/src/openrct2/entity/EntityRegistry.h index b33230e710..a370f38f44 100644 --- a/src/openrct2/entity/EntityRegistry.h +++ b/src/openrct2/entity/EntityRegistry.h @@ -67,7 +67,6 @@ void ResetAllEntities(); void ResetEntitySpatialIndices(); void UpdateAllMiscEntities(); void UpdateMoneyEffect(); -void EntitySetCoordinates(const CoordsXYZ& entityPos, EntityBase* entity); void EntityRemove(EntityBase* entity); uint16_t RemoveFloatingEntities(); void UpdateEntitiesSpatialIndex(); diff --git a/src/openrct2/entity/EntityTweener.cpp b/src/openrct2/entity/EntityTweener.cpp index 52bc453237..acd5e38ccf 100644 --- a/src/openrct2/entity/EntityTweener.cpp +++ b/src/openrct2/entity/EntityTweener.cpp @@ -101,8 +101,6 @@ void EntityTweener::Tween(float alpha) static_cast(std::round(posB.y * alpha + posA.y * inv)), static_cast(std::round(posB.z * alpha + posA.z * inv)) }); } - - UpdateEntitiesSpatialIndex(); } void EntityTweener::Restore() @@ -113,9 +111,7 @@ void EntityTweener::Restore() if (ent == nullptr) continue; - ent->Invalidate(); - EntitySetCoordinates(PostPos[i], ent); - ent->Invalidate(); + ent->MoveTo(PostPos[i]); } }