From e70ebb74f9ea6db6078198cde84ed4af949f755c Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Tue, 10 Nov 2026 13:34:49 -0600 Subject: [PATCH] feat(moving platform): the object goes with its mover on the server LWOPlatform moves its object with SetPosition and SetRotation ignoring the dirty flags (ProcessStateChange), turned between the two waypoints' rotations, and live serialized a moving platform's mover data without its physics. The server's object stayed where it spawned, so anything that asks where a platform is (the lightning orbs' knockback of issue 1352, phantoms riding a platform) had the start of its path. Co-Authored-By: Claude Opus 5.5 --- dGame/dComponents/MovingPlatformComponent.cpp | 20 ++++++++++ dGame/dComponents/MovingPlatformComponent.h | 2 + dGame/dComponents/Physics/PhysicsComponent.h | 8 ++++ .../MovingPlatformComponentTests.cpp | 38 +++++++++++++++++++ 4 files changed, 68 insertions(+) diff --git a/dGame/dComponents/MovingPlatformComponent.cpp b/dGame/dComponents/MovingPlatformComponent.cpp index 21db9f9ef..0aef74a6e 100644 --- a/dGame/dComponents/MovingPlatformComponent.cpp +++ b/dGame/dComponents/MovingPlatformComponent.cpp @@ -21,6 +21,7 @@ #include "ObjectLoadState.h" #include "MovementAIComponent.h" #include "QuickBuildComponent.h" +#include "PhantomPhysicsComponent.h" #include "eQuickBuildState.h" void PlatformSubComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) { @@ -509,6 +510,22 @@ void MovingPlatformComponent::MoverHandleWaypointArrived(const uint32_t index, c if ((mover->mState & ePlatformStateFlag::Stopped) == 0) Game::entityManager->SerializeEntity(m_Parent); } +// LWOPlatform moves its object with SetPosition and SetRotation ignoring the dirty flags (ProcessStateChange, +// Resync), and its physics carry it between waypoints: live did not serialize a mover's physics for it, each +// client moves its own. The server's object goes with the mover, turned between the two waypoints' rotations. +void MovingPlatformComponent::MoveObject() { + const auto* const mover = GetMoverSubComponent(); + const auto& from = m_Path->pathWaypoints[mover->mCurrentWaypointIndex].rotation; + const auto& to = m_Path->pathWaypoints[mover->mNextWaypointIndex].rotation; + const auto rotation = from == to ? from : glm::slerp(from, to, std::min(mover->mPercentBetweenPoints, 1.0f)); + if (auto* const simplePhysics = m_Parent->GetComponent()) { + simplePhysics->SetPositionAndRotationIgnoringDirtyFlags(mover->mPosition, rotation); + } + if (auto* const phantomPhysics = m_Parent->GetComponent()) { + phantomPhysics->SetPositionAndRotationIgnoringDirtyFlags(mover->mPosition, rotation); + } +} + // LWOPlatform::Run and RunPlatform. The client's platform is moved by its physics, at the // velocity SetLinearVelocity gives it; the server moves it here by the same speed. void MovingPlatformComponent::Run(const float deltaTime) { @@ -550,6 +567,8 @@ void MovingPlatformComponent::Run(const float deltaTime) { mover->mPosition = from + (to - from) * mover->mPercentBetweenPoints; } + MoveObject(); + const bool stopped = (mover->mState & ePlatformStateFlag::Stopped) != 0; // LWOPlatform::IncrementWaitingTime bool doneWaiting = false; @@ -576,6 +595,7 @@ void MovingPlatformComponent::Run(const float deltaTime) { // Live serialized a platform leaving its waypoint if (doneWaiting) Game::entityManager->SerializeEntity(m_Parent); } + if (IsMover()) MoveObject(); } void MovingPlatformComponent::FillResync(GameMessages::PlatformResync& resync) const { diff --git a/dGame/dComponents/MovingPlatformComponent.h b/dGame/dComponents/MovingPlatformComponent.h index 6893a86e2..79f1d51ee 100644 --- a/dGame/dComponents/MovingPlatformComponent.h +++ b/dGame/dComponents/MovingPlatformComponent.h @@ -320,6 +320,8 @@ private: // LWOPlatform::ProcessStateChange: index becomes the current waypoint (the next from the path's behavior and direction) void MoverProcessStateChange(uint32_t index); + // Puts the object where the mover is, without a serialization of its physics + void MoveObject(); // LWOPlatform::SetWaitingTime: starts a wait of at least 0.1 s void MoverSetWaitingTime(float waitTime, float idleTimeElapsed); // LWOPlatform::ResumeTravelling: stopped between two waypoints it travels on; at a waypoint it first waits there diff --git a/dGame/dComponents/Physics/PhysicsComponent.h b/dGame/dComponents/Physics/PhysicsComponent.h index cc91a4095..7b4b1dcbf 100644 --- a/dGame/dComponents/Physics/PhysicsComponent.h +++ b/dGame/dComponents/Physics/PhysicsComponent.h @@ -37,6 +37,14 @@ public: const NiQuaternion& GetRotation() const { return m_Rotation; } virtual void SetRotation(const NiQuaternion& rot) { if (m_Rotation == rot) return; m_Rotation = rot; m_DirtyPosition = true; } + // As the client's SetPosition and SetRotation with bIgnoreDirtyFlags: moved without being serialized for it + void SetPositionAndRotationIgnoringDirtyFlags(const NiPoint3& pos, const NiQuaternion& rot) { + const bool dirty = m_DirtyPosition; + SetPosition(pos); + SetRotation(rot); + m_DirtyPosition = dirty; + } + int32_t GetCollisionGroup() const noexcept { return m_CollisionGroup; } void SetCollisionGroup(int32_t group) noexcept { m_CollisionGroup = group; } diff --git a/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp b/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp index 883b5f29d..db210ca28 100644 --- a/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp +++ b/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp @@ -299,3 +299,41 @@ TEST_F(MovingPlatformComponentTest, MoverOnceLikeLiveFallingTile) { EXPECT_EQ(mover->mNextWaypointIndex, 1u); EXPECT_FALSE(mover->mInReverse); } + +// The object goes with its mover on the server (LWOPlatform moves it ignoring the dirty flags), turned between the +// waypoints' rotations, and its physics are not serialized for it: live sent a moving target's mover data only +TEST_F(MovingPlatformComponentTest, MoverCarriesItsObject) { + Path path; + path.pathType = PathType::MovingPlatform; + path.pathName = "TestCarryPath"; + path.pathBehavior = PathBehavior::Once; + PathWaypoint first; + first.position = NiPoint3(0.0f, 0.0f, 0.0f); + first.speed = 5.0f; + PathWaypoint second = first; + second.position = NiPoint3(10.0f, 0.0f, 0.0f); + second.rotation = NiQuaternion(0.0f, 0.0f, 1.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(288300744895900110, info); + auto* const simplePhysics = entity.AddComponent(-1); + auto* const platform = entity.AddComponent(-1, "TestCarryPath"); + + RakNet::BitStream before; + simplePhysics->Serialize(before, false); + platform->Run(0.11f); + platform->Run(1.0f); + EXPECT_NEAR(entity.GetPosition().x, 5.0f, 0.01f); + EXPECT_NEAR(std::abs(entity.GetRotation().y), 0.7071f, 0.001f); + + RakNet::BitStream moved; + simplePhysics->Serialize(moved, false); + // No position and rotation (seven floats) in it + EXPECT_LT(moved.GetNumberOfBitsUsed(), 7u * 32u); + + platform->Run(1.1f); + EXPECT_EQ(entity.GetPosition(), NiPoint3(10.0f, 0.0f, 0.0f)); + EXPECT_NEAR(std::abs(entity.GetRotation().y), 1.0f, 0.001f); +}