feat: a rotator sent to a waypoint turns that way

The client has no handler for GoToWaypoint on any platform: the server
sends platforms on. Its rotator can be sent forwards or backwards: it
travels, and sent against the way it turns it turns round. Nothing in the
client calls either, so they are for the server to use.

GoToWaypoint on a rotator now does that: a waypoint ahead of where it is
on its path sends it forwards, one behind backwards. It never arrives, as
a rotator never does. The client takes a rotator's direction only from its
path or a PlatformResync, so a rotator that turned round is resynced.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-11-11 18:22:37 -06:00
parent be49a2e4b7
commit cdef894628
3 changed files with 103 additions and 1 deletions

View File

@@ -399,8 +399,13 @@ void MovingPlatformComponent::GotoWaypoint(uint32_t index, bool stopAtWaypoint)
// (the NJ falling tiles): a mover at a waypoint first waits there (9, or 25 at an end, with the desired waypoint), then
// leaves (2).
void MovingPlatformComponent::PlatformGotoWaypoint(PlatformSubComponent& platform, const uint32_t index, const bool stopAtWaypoint) {
if (platform.GetType() == eMoverSubComponentType::rotater) return;
if (platform.mPath == nullptr || index >= platform.mPath->pathWaypoints.size()) return;
if (platform.GetType() == eMoverSubComponentType::rotater) {
platform.mDesiredWaypointIndex = static_cast<int32_t>(index);
platform.mShouldStopAtDesiredWaypoint = stopAtWaypoint;
RotatorSetMoving(static_cast<RotatorSubComponent&>(platform), index < platform.mCurrentWaypointIndex);
return;
}
const auto& waypoints = platform.mPath->pathWaypoints;
const bool atWaypoint = (platform.mState & ReachedDesiredWaypoint) != 0;
if (atWaypoint && platform.mCurrentWaypointIndex == index) {
@@ -449,6 +454,32 @@ void MovingPlatformComponent::PlatformGotoWaypoint(PlatformSubComponent& platfor
SerializePlatform(platform);
}
// A rotator sent forwards or backwards, as the client's rotator has it (nothing in the client sends it either way: the
// client has no handler for GoToWaypoint, the server sends platforms on). It travels; set the way it already turns
// it starts turning, and set the other way it turns round and turns at the same rate the other way. It never gets to a
// waypoint: one ahead of where it is on its path sends it forwards, one behind backwards.
// The client's rotator only takes its direction from its path or from a PlatformResync, never from a serialization, so
// a rotator that turned round is resynced: the client's platform then puts its object in the waypoint's rotation and
// turns from there, as the object here is. An object's resync goes to all of its platforms, so one that also has a
// mover is not resynced: its clients keep the rotator's old direction.
void MovingPlatformComponent::RotatorSetMoving(RotatorSubComponent& rotator, const bool reverse) {
if (rotator.mPath == nullptr) return;
StartTravelling(rotator);
if (rotator.mInReverse != reverse) {
rotator.mInReverse = reverse;
if (m_SubComponents.size() == 1) {
SetObjectTransform(m_Parent->GetPosition(), rotator.mPath->pathWaypoints[rotator.mCurrentWaypointIndex].rotation);
GameMessages::PlatformResync resync;
resync.target = m_Parent->GetObjectID();
if (FillResync(resync)) resync.Send(UNASSIGNED_SYSTEM_ADDRESS);
}
} else {
// Setting off drops the two "reached" bits
rotator.mState &= MovementMask;
}
Game::entityManager->SerializeEntity(m_Parent);
}
void MovingPlatformComponent::StartPathing() {
for (size_t i = 0; i < m_SubComponents.size(); i++) PlatformStart(*m_SubComponents[i]);
}

View File

@@ -381,6 +381,8 @@ private:
// Tells the scripts, then a platform that travels on waits at the waypoint
bool PlatformHandleWaypointArrived(PlatformSubComponent& platform, uint32_t index, bool atDesiredWaypoint, bool atLastWaypoint);
void PlatformGotoWaypoint(PlatformSubComponent& platform, uint32_t index, bool stopAtWaypoint);
// Sends a rotator forwards or backwards
void RotatorSetMoving(RotatorSubComponent& rotator, bool reverse);
void PlatformStart(PlatformSubComponent& platform);
void PlatformStop(PlatformSubComponent& platform);
void PlatformWarpToWaypoint(PlatformSubComponent& platform, size_t index);

View File

@@ -664,6 +664,75 @@ TEST_F(MovingPlatformComponentTest, RotatorTurnsItsObject) {
EXPECT_EQ(entity.GetPosition(), NiPoint3(1.0f, 2.0f, 3.0f));
}
// A rotator sent to a waypoint never gets there: one ahead sends it forwards, one behind backwards, as the client's
// rotator is sent either way. Sent the way it turns it (again) travels; sent the other way it turns round and its
// object, put in the waypoint's rotation as a resynced client's is, turns the other way.
TEST_F(MovingPlatformComponentTest, RotatorSentToAWaypointTurnsThatWay) {
Path path;
path.pathType = PathType::MovingPlatform;
path.pathName = "TestRotatorWaypointPath";
path.pathBehavior = PathBehavior::Loop;
PathWaypoint first;
first.position = NiPoint3(1.0f, 2.0f, 3.0f);
PathWaypoint second = first;
second.position = NiPoint3(10.0f, 2.0f, 3.0f);
PathWaypoint third = first;
third.position = NiPoint3(20.0f, 2.0f, 3.0f);
path.pathWaypoints = { first, second, third };
const_cast<Zone*>(Game::zoneManager->GetZone())->AddPath(path);
info.pos = NiPoint3(10.0f, 2.0f, 3.0f);
info.rot = QuatUtils::IDENTITY;
info.settings.Insert<bool>(u"platformIsRotater", true);
info.settings.Insert<float>(u"rotY", 0.5f);
info.settings.Insert<float>(u"rate", 2.0f);
info.settings.Insert<int32_t>(u"attached_path_start", 1);
info.settings.Insert<bool>(u"startPathingOnLoad", false);
Entity entity(288300744895900125, info);
info.settings.values.clear();
entity.AddComponent<SimplePhysicsComponent>(-1);
auto* const platform = entity.AddComponent<MovingPlatformComponent>(-1, "TestRotatorWaypointPath");
auto* const rotator = platform->GetSubComponent(eMoverSubComponentType::rotater);
ASSERT_NE(rotator, nullptr);
EXPECT_EQ(rotator->mState, 12u);
EXPECT_EQ(rotator->mCurrentWaypointIndex, 1u);
platform->Run(1.0f);
EXPECT_EQ(entity.GetRotation(), QuatUtils::IDENTITY);
// Forwards, the way it is set: it travels and turns
platform->GotoWaypoint(2);
EXPECT_EQ(rotator->mState, 2u);
EXPECT_FALSE(rotator->mInReverse);
EXPECT_EQ(rotator->mDesiredWaypointIndex, 2);
platform->Run(1.0f);
EXPECT_NEAR(entity.GetRotation().w, 0.7071f, 0.001f);
EXPECT_NEAR(entity.GetRotation().y, -0.7071f, 0.001f);
EXPECT_EQ(rotator->mCurrentWaypointIndex, 1u);
// Backwards: it turns round, from the waypoint's rotation
platform->GotoWaypoint(0);
EXPECT_EQ(rotator->mState & 7u, 2u);
EXPECT_TRUE(rotator->mInReverse);
EXPECT_EQ(entity.GetRotation(), QuatUtils::IDENTITY);
GameMessages::PlatformResync resync;
ASSERT_TRUE(platform->FillResync(resync));
EXPECT_TRUE(resync.bReverse);
EXPECT_EQ(resync.iIndex, 1);
platform->Run(1.0f);
EXPECT_NEAR(entity.GetRotation().w, 0.7071f, 0.001f);
EXPECT_NEAR(entity.GetRotation().y, 0.7071f, 0.001f);
// Stopped, and sent backwards again: it travels on the way it was
platform->StopPathing();
EXPECT_EQ(rotator->mState & 7u, 4u);
platform->GotoWaypoint(0);
EXPECT_EQ(rotator->mState, 2u);
EXPECT_TRUE(rotator->mInReverse);
platform->Run(1.0f);
EXPECT_NEAR(std::abs(entity.GetRotation().y), 1.0f, 0.001f);
EXPECT_EQ(entity.GetPosition(), NiPoint3(10.0f, 2.0f, 3.0f));
}
// An object with both a mover and a rotator (platformIsMover and platformIsRotater): the client makes both and runs
// both. The mover carries the object along the path while the rotator turns it; where the mover arrives the object is
// put in the waypoint's rotation, and the rotator turns it on from there.