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 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-11-29 00:53:27 -06:00
parent c55519cf2f
commit 87e3e9b38d
2 changed files with 50 additions and 2 deletions

View File

@@ -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);

View File

@@ -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<Zone*>(Game::zoneManager->GetZone())->AddPath(path);
info.pos = NiPoint3(0.0f, 0.0f, 0.0f);
Entity entity(288300744895900150, info);
entity.AddComponent<SimplePhysicsComponent>(-1);
auto* const platform = entity.AddComponent<MovingPlatformComponent>(-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);
}