From 1a389d7319b259d543941782e930f0c64fac3c24 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Wed, 11 Nov 2026 18:23:44 -0600 Subject: [PATCH] fix: a simple mover's settings are read in the client's order The client reads a simple mover's own level settings first and its MovingPlatforms row after them. So with a row the row's platformMove and platformMoveTime win, unless the object sets dbonly false (then the row is not read); db only, the object's own are not read at all. Without a row dbonly means nothing and the object's own always count. platformStartAtEnd is never taken from the row. The server read the row first and the object's settings over it, so an object with a row, settings of its own and no dbonly moved by its own settings, and one without a row and dbonly true ignored them. Co-Authored-By: Claude Fable 5.2 --- dGame/dComponents/MovingPlatformComponent.cpp | 49 ++++++++++--------- .../MovingPlatformComponentTests.cpp | 27 ++++++++++ 2 files changed, 52 insertions(+), 24 deletions(-) diff --git a/dGame/dComponents/MovingPlatformComponent.cpp b/dGame/dComponents/MovingPlatformComponent.cpp index abc89aefe..8c24b4abc 100644 --- a/dGame/dComponents/MovingPlatformComponent.cpp +++ b/dGame/dComponents/MovingPlatformComponent.cpp @@ -130,29 +130,13 @@ MovingPlatformComponent::MovingPlatformComponent(Entity* parent, const int32_t c m_NoAutoStart = false; } -// The subcomponents (one per type, in the client's order), and a simple mover's MovingPlatforms row +// The subcomponents (one per type, in the client's order) void MovingPlatformComponent::LoadDataFromTemplate() { for (const auto type : ChooseSubComponentTypes(m_ComponentID, *m_Parent)) { if (type == eMoverSubComponentType::simpleMover) { auto simpleMover = std::make_unique(); simpleMover->mStartPosition = m_Parent->GetDefaultPosition(); simpleMover->mStartRotation = m_Parent->GetDefaultRotation(); - - // The MovingPlatforms row, unless the object sets dbonly false - const bool dbOnly = m_Parent->GetVar(u"dbonly"); - if (m_ComponentID > 0 && (!m_Parent->HasVar(u"dbonly") || dbOnly)) { - auto query = CDClientDatabase::CreatePreppedStmt( - "SELECT platformMoveX, platformMoveY, platformMoveZ, platformMoveTime, platformStartAtEnd FROM MovingPlatforms WHERE id = ?;"); - query.bind(1, m_ComponentID); - auto result = query.execQuery(); - if (!result.eof()) { - simpleMover->mMove = NiPoint3(result.getFloatField(0), result.getFloatField(1), result.getFloatField(2)); - simpleMover->mMoveTime = result.getFloatField(3); - simpleMover->mStartAtEnd = result.getIntField(4) != 0; - } else { - LOG("LOT %i couldn't find simple mover %i in MovingPlatforms", m_Parent->GetLOT(), m_ComponentID); - } - } m_SubComponents.push_back(std::move(simpleMover)); } else if (type == eMoverSubComponentType::rotater) { m_SubComponents.push_back(std::make_unique()); @@ -211,14 +195,18 @@ bool MovingPlatformComponent::StartsOnLoad() const { return !m_Parent->HasVar(u"startPathingOnLoad") || m_Parent->GetVar(u"startPathingOnLoad"); } -// The object's settings go over the table's, unless it is db only. The simple mover then gets its own path, between -// its two ends, and is at the end it starts at: a platform like any other on a path run once. Made stopped at its -// waypoint (12), it waits there (9, as live constructed the NJ counterweights) unless startPathingOnLoad is false, -// for the shortest wait as its waypoints have none, and sets off for its other end. Live's scripts for the NJ -// spinners, which are simple movers that only move when used, stop them when they start up, and the simple movers -// that wait for an event without such a script have startPathingOnLoad 0. +// A simple mover's settings, read in the client's order: the object's own first (not its platformMove ones when it +// has a MovingPlatforms row and is db only), then the row's platformMove and platformMoveTime over them, unless the +// object sets dbonly false. So with a row the object's own only count with dbonly false, and without a row dbonly +// means nothing. Whether it starts at its end only comes from the object. +// The simple mover then gets its own path, between its two ends, and is at the end it starts at: a platform like any +// other on a path run once. Made stopped at its waypoint (12), it waits there (9, as live constructed the NJ +// counterweights) unless startPathingOnLoad is false, for the shortest wait as its waypoints have none, and sets off +// for its other end. Live's scripts for the NJ spinners, which are simple movers that only move when used, stop them +// when they start up, and the simple movers that wait for an event without such a script have startPathingOnLoad 0. void MovingPlatformComponent::SetupSimpleMover(SimpleMoverSubComponent& simpleMover) { - const bool dbOnly = m_Parent->GetVar(u"dbonly"); + const bool hasRow = m_ComponentID > 0; + const bool dbOnly = hasRow && m_Parent->GetVar(u"dbonly"); if (m_Parent->HasVar(u"attached_path_start")) simpleMover.mStartAtEnd = m_Parent->GetVar(u"attached_path_start") != 0; if (m_Parent->HasVar(u"platformStartAtEnd")) simpleMover.mStartAtEnd = m_Parent->GetVar(u"platformStartAtEnd"); if (!dbOnly) { @@ -228,6 +216,19 @@ void MovingPlatformComponent::SetupSimpleMover(SimpleMoverSubComponent& simpleMo if (m_Parent->HasVar(u"platformMoveTime")) simpleMover.mMoveTime = m_Parent->GetVar(u"platformMoveTime"); } + if (hasRow && (!m_Parent->HasVar(u"dbonly") || dbOnly)) { + auto query = CDClientDatabase::CreatePreppedStmt( + "SELECT platformMoveX, platformMoveY, platformMoveZ, platformMoveTime FROM MovingPlatforms WHERE id = ?;"); + query.bind(1, m_ComponentID); + auto result = query.execQuery(); + if (!result.eof()) { + simpleMover.mMove = NiPoint3(result.getFloatField(0), result.getFloatField(1), result.getFloatField(2)); + simpleMover.mMoveTime = result.getFloatField(3); + } else { + LOG("LOT %i couldn't find simple mover %i in MovingPlatforms", m_Parent->GetLOT(), m_ComponentID); + } + } + simpleMover.GeneratePath(); // One that starts at its end goes back from there: the client takes the direction it is constructed with simpleMover.mInReverse = simpleMover.mStartAtEnd; diff --git a/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp b/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp index 63652c1f3..2f0d40168 100644 --- a/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp +++ b/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp @@ -113,6 +113,33 @@ TEST_F(MovingPlatformComponentTest, SimpleMoverConstructionMatchesLive) { EXPECT_EQ(Bits(idle), "00"); } +// The client reads a simple mover's own settings first and its MovingPlatforms row after, so the row's platformMove +// and platformMoveTime win unless the object sets dbonly false; db only, its own are not read at all. Without a row +// dbonly means nothing and its own always count. +TEST_F(MovingPlatformComponentTest, SimpleMoverSettingsInTheClientsOrder) { + info.lot = 16141; + const auto move = [this](const int32_t componentID, const LWOOBJID id) { + Entity entity(id, info); + auto* const platform = entity.AddComponent(componentID, ""); + const auto* const simpleMover = platform->GetSimpleMoverSubComponent(); + return simpleMover ? std::pair(simpleMover->mMove.y, simpleMover->mMoveTime) : std::pair(-1000.0f, -1000.0f); + }; + info.settings.Insert(u"platformMoveY", 5.0f); + info.settings.Insert(u"platformMoveTime", 3.0f); + EXPECT_EQ(move(41, 288300744895900126), std::pair(-2.5f, 1.0f)); + info.settings.Insert(u"dbonly", false); + EXPECT_EQ(move(41, 288300744895900127), std::pair(5.0f, 3.0f)); + info.settings.values.clear(); + info.settings.Insert(u"platformMoveY", 5.0f); + info.settings.Insert(u"platformMoveTime", 3.0f); + info.settings.Insert(u"dbonly", true); + EXPECT_EQ(move(41, 288300744895900128), std::pair(-2.5f, 1.0f)); + // No row: a simple mover by its setting + info.settings.Insert(u"platformIsSimpleMover", true); + EXPECT_EQ(move(-1, 288300744895900129), std::pair(5.0f, 3.0f)); + info.settings.values.clear(); +} + // Live answered every RequestPlatformResync. A NJ counterweight (the one constructed above) got: state 9, not // reversing, no desired waypoint, waypoints 0 and 1, percent 0, no times, its start position and its start rotation. // A mover without a path got: state 9, waypoints 0 and 0, no position and no rotation.