From 87e3e9b38d7f77e57147ec64f6c0f399812f435b Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Sun, 29 Nov 2026 00:53:27 -0600 Subject: [PATCH] fix(platforms): a time based mover turned round restarts the stretch's clock, as the client Turned round between two waypoints, the client's platform calls ProcessStateChange for the waypoint it was heading to, which zeroes the time travelled: it then takes the whole stretch's time at the whole stretch's speed from where it is, going past the waypoint by as far as it had come. DLU kept the time already travelled. Co-Authored-By: Claude Opus 5.5 --- dGame/dComponents/MovingPlatformComponent.cpp | 11 ++++- .../MovingPlatformComponentTests.cpp | 41 +++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/dGame/dComponents/MovingPlatformComponent.cpp b/dGame/dComponents/MovingPlatformComponent.cpp index e2ebb47c2..e1b59d959 100644 --- a/dGame/dComponents/MovingPlatformComponent.cpp +++ b/dGame/dComponents/MovingPlatformComponent.cpp @@ -460,8 +460,15 @@ void MovingPlatformComponent::PlatformGotoWaypoint(PlatformSubComponent& platfor platform.mPercentBetweenPoints = 1.0f - std::min(percent, 1.0f); platform.mSegmentLength = Vector3::Distance(waypoints[platform.mCurrentWaypointIndex].position, waypoints[platform.mNextWaypointIndex].position); platform.mWaitTime = waypoints[platform.mCurrentWaypointIndex].movingPlatform.wait; - if (platform.mTimeBased) platform.mMoveTimeElapsed = platform.mCurrentSpeed * platform.mPercentBetweenPoints; - else std::swap(platform.mCurrentSpeed, platform.mNextSpeed); + if (platform.mTimeBased) { + // The client's turn round (ProcessStateChange of the waypoint it was heading to, not moving there) starts + // the stretch's clock again: from where it is, it takes the whole stretch's time at the whole stretch's + // speed, so it goes past the waypoint by as far as it had come + platform.mMoveTimeElapsed = 0.0f; + platform.mPercentBetweenPoints = 0.0f; + } else { + std::swap(platform.mCurrentSpeed, platform.mNextSpeed); + } } } PlatformResumeTravelling(platform, false); diff --git a/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp b/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp index 96831593b..e2a2c87e5 100644 --- a/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp +++ b/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp @@ -1462,3 +1462,44 @@ TEST_F(MovingPlatformComponentTest, FireTempleMillstoneTurnsTheShortWay) { EXPECT_NEAR(lowest, -179.0f, 0.1f); EXPECT_NEAR(highest, -1.0f, 0.1f); } + +// A mover on a time based path turned round between two waypoints starts the stretch's clock again, as the client's +// (ProcessStateChange zeroes the time travelled): from where it is it takes the whole stretch's time at the whole +// stretch's speed, so it goes past the waypoint it turned back to by as far as it had come +TEST_F(MovingPlatformComponentTest, TimeBasedMoverTurnedRoundRestartsTheStretch) { + Path path; + path.pathType = PathType::MovingPlatform; + path.pathName = "TestTimeTurnPath"; + path.pathBehavior = PathBehavior::Once; + path.movingPlatform.timeBasedMovement = 1; + PathWaypoint first; + first.position = NiPoint3(0.0f, 0.0f, 0.0f); + first.speed = 5.0f; // seconds to the next waypoint + PathWaypoint second = first; + second.position = NiPoint3(10.0f, 0.0f, 0.0f); + path.pathWaypoints = { first, second }; + const_cast(Game::zoneManager->GetZone())->AddPath(path); + + info.pos = NiPoint3(0.0f, 0.0f, 0.0f); + Entity entity(288300744895900150, info); + entity.AddComponent(-1); + auto* const platform = entity.AddComponent(-1, "TestTimeTurnPath"); + auto* const mover = platform->GetMoverSubComponent(); + platform->GotoWaypoint(1); + for (int32_t i = 0; i < 15 * 3; i++) platform->Run(1.0f / 15.0f); + ASSERT_EQ(mover->mState & 2u, 2u); + const float turnedAt = entity.GetPosition().x; + EXPECT_GT(turnedAt, 3.0f); + EXPECT_LT(turnedAt, 7.0f); + + platform->GotoWaypoint(0); + EXPECT_EQ(mover->mCurrentWaypointIndex, 1u); + EXPECT_EQ(mover->mNextWaypointIndex, 0u); + EXPECT_EQ(mover->mMoveTimeElapsed, 0.0f); + EXPECT_EQ(mover->mPercentBetweenPoints, 0.0f); + // Just before the whole stretch's time is up it has gone nearly the whole stretch back, at the whole stretch's + // speed: past waypoint 0 by nearly as far as it had come (it arrives when the time is up) + for (int32_t i = 0; i < 15 * 5 - 3; i++) platform->Run(1.0f / 15.0f); + EXPECT_NEAR(entity.GetPosition().x, turnedAt - 10.0f * 72.0f / 75.0f, 0.75f); + EXPECT_LT(entity.GetPosition().x, -2.0f); +}