fix(moving platform): a mover's states as the client and live: 12 stopped, 9 and 25 waiting, 28 stopped at an end

The state bits were named the wrong way round: 1 is waiting and 4 is stopped (LWOPlatform::StartTravelling 0x0058b170, StopTravelling 0x0058b1d0), and the client only stops on 4 (LWOPlatform::Deserialize 0x00c870e0), so a mover stopped on its way kept moving on the client. The mover now runs as LWOPlatform::RunPlatform 0x00c86e10, ArrivedAtWaypoint 0x00c86c30, HandleWaypointArrived 0x00c17bc0 and ResumeTravelling 0x00c86b90, which gives the states of the live captures: 12 until started, 9 waiting at a waypoint (25 at an end), 2 on its way, 28 stopped at an end of a path run once. A GoToWaypoint at a waypoint waits there first with the desired waypoint, as the NJ falling tiles did, and a mover that stops is not serialized for it. A quick build's mover does not run until it is built.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-11-10 13:32:00 -06:00
parent 0a0e37e96f
commit 3112379387
3 changed files with 260 additions and 96 deletions

View File

@@ -20,6 +20,8 @@
#include "Entity.h"
#include "ObjectLoadState.h"
#include "MovementAIComponent.h"
#include "QuickBuildComponent.h"
#include "eQuickBuildState.h"
void PlatformSubComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
outBitStream.Write<bool>(true);
@@ -163,8 +165,8 @@ void MovingPlatformComponent::LoadConfigData() {
LOG("Path not found: %s", pathName.c_str());
}
// A mover starts at its attached_path_start waypoint, waiting there, and leaves after the waypoint's wait unless
// startPathingOnLoad is false (live: 25 with the time waited in the constructions)
// LWOPlatform::SetupPath: a mover is at its attached_path_start waypoint, stopped (12, as live constructed movers
// nothing had started). Unless startPathingOnLoad is false it then waits the waypoint's wait and leaves (live: 9).
if (IsMover()) {
auto* const mover = GetMoverSubComponent();
mover->mTimeBased = m_Path->movingPlatform.timeBasedMovement != 0;
@@ -172,12 +174,12 @@ void MovingPlatformComponent::LoadConfigData() {
m_StartWaypoint = start >= 0 && static_cast<size_t>(start) < m_Path->pathWaypoints.size() ? start : 0;
MoverProcessStateChange(m_StartWaypoint);
const bool startOnLoad = !m_Parent->HasVar(u"startPathingOnLoad") || m_Parent->GetVar<bool>(u"startPathingOnLoad");
MoverStopAtWaypoint(startOnLoad);
if (startOnLoad) MoverResumeTravelling();
} else if (m_MoverSubComponentType == eMoverSubComponentType::rotater) {
// LWOPlatformRotator: it only spins (rotX/rotY/rotZ at rate, its own path never arrives anywhere: its
// HandleStoppedLogic 0x00bdc660 only keeps the angular velocity), while travelling
const bool startOnLoad = !m_Parent->HasVar(u"startPathingOnLoad") || m_Parent->GetVar<bool>(u"startPathingOnLoad");
GetMoverSubComponent()->mState = startOnLoad ? ePlatformStateFlag::Travelling : ePlatformStateFlag::Stopped;
if (startOnLoad) GetMoverSubComponent()->mState = ePlatformStateFlag::Travelling;
}
// Live constructed every moving platform with simple physics as keyframed
@@ -269,7 +271,9 @@ void MovingPlatformComponent::SetMovementState(eMovementPlatformState value) {
Game::entityManager->SerializeEntity(m_Parent);
}
// Sends the mover to a waypoint, stopping there when stopAtWaypoint: it turns round if the waypoint is behind it
// Sends the mover to a waypoint, stopping there when stopAtWaypoint: it turns round if the waypoint is behind it. Live
// (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::GotoWaypoint(uint32_t index, bool stopAtWaypoint) {
if (m_MoverSubComponentType == eMoverSubComponentType::simpleMover) {
SimpleMoverGotoWaypoint(static_cast<int32_t>(index));
@@ -282,7 +286,9 @@ void MovingPlatformComponent::GotoWaypoint(uint32_t index, bool stopAtWaypoint)
// Already there
mover->mDesiredWaypointIndex = -1;
mover->mShouldStopAtDesiredWaypoint = false;
if (stopAtWaypoint) MoverStopAtWaypoint(false);
if (stopAtWaypoint) {
mover->mState = (mover->mState & ~(ePlatformStateFlag::Waiting | ePlatformStateFlag::Travelling)) | ePlatformStateFlag::Stopped;
}
FireArrivalHooks(index, true, index == m_Path->pathWaypoints.size() - 1);
return;
}
@@ -307,11 +313,14 @@ void MovingPlatformComponent::GotoWaypoint(uint32_t index, bool stopAtWaypoint)
mover->mNextWaypointIndex = mover->mCurrentWaypointIndex;
mover->mCurrentWaypointIndex = heading;
mover->mPercentBetweenPoints = 1.0f - std::min(percent, 1.0f);
mover->mSegmentLength = Vector3::Distance(m_Path->pathWaypoints[mover->mCurrentWaypointIndex].position, m_Path->pathWaypoints[mover->mNextWaypointIndex].position);
mover->mWaitTime = m_Path->pathWaypoints[mover->mCurrentWaypointIndex].movingPlatform.wait;
if (mover->mTimeBased) mover->mMoveTimeElapsed = mover->mCurrentSpeed * mover->mPercentBetweenPoints;
else std::swap(mover->mCurrentSpeed, mover->mNextSpeed);
}
}
MoverDepart();
MoverResumeTravelling();
Game::entityManager->SerializeEntity(m_Parent);
}
void MovingPlatformComponent::StartPathing() {
@@ -332,36 +341,33 @@ void MovingPlatformComponent::StartPathing() {
if ((mover->mState & ePlatformStateFlag::Travelling) != 0) return;
// LWOPlatform::ResumeTravelling: stopped between two waypoints it carries on; at a waypoint it first waits there
// for the waypoint's wait (issue 964: the AG monument elevator waited about 2 s before rising)
if ((mover->mState & ePlatformStateFlag::ReachedDesiredWaypoint) != 0) {
MoverStopAtWaypoint(true);
Game::entityManager->SerializeEntity(m_Parent);
return;
}
MoverDepart();
MoverResumeTravelling();
Game::entityManager->SerializeEntity(m_Parent);
}
void MovingPlatformComponent::StopPathing() {
if (m_MoverSubComponentType == eMoverSubComponentType::simpleMover) {
// LWOPlatformSimpleMover::StopPlatform: it stops where it is, no longer travelling
// LWOPlatformSimpleMover::StopPlatform 0x00cce1e0: at an end it is stopped; on its way it goes on to the end it
// was heading for, where its path (run once) stops it anyway
auto* const simpleMover = GetSimpleMoverSubComponent();
m_MoveGeneration++;
simpleMover->mState = ePlatformStateFlag::Stopped;
if ((simpleMover->mState & ePlatformStateFlag::ReachedDesiredWaypoint) == 0) return;
simpleMover->mState = (simpleMover->mState & ~(ePlatformStateFlag::Waiting | ePlatformStateFlag::Travelling)) | ePlatformStateFlag::Stopped;
simpleMover->mDirtyState = true;
Game::entityManager->SerializeEntity(m_Parent);
return;
}
if (m_MoverSubComponentType == eMoverSubComponentType::rotater) {
// LWOPlatformRotator::StopPlatform: no longer spinning
GetMoverSubComponent()->mState = ePlatformStateFlag::Stopped;
auto* const rotator = GetMoverSubComponent();
rotator->mState = (rotator->mState & ~(ePlatformStateFlag::Waiting | ePlatformStateFlag::Travelling)) | ePlatformStateFlag::Stopped;
Game::entityManager->SerializeEntity(m_Parent);
return;
}
if (!IsMover()) return;
m_PathingStopped = true;
auto* const mover = GetMoverSubComponent();
// LWOPlatform::StopPlatform: stopped where it is, not leaving after a wait
mover->mState = (mover->mState & ~(ePlatformStateFlag::Travelling | ePlatformStateFlag::Waiting)) | ePlatformStateFlag::Stopped;
mover->mDepartAfterWait = false;
// LWOPlatform::StopPlatform 0x00c86b70: stopped where it is (the client stops on the stopped bit, 4)
mover->mState = (mover->mState & ~(ePlatformStateFlag::Waiting | ePlatformStateFlag::Travelling)) | ePlatformStateFlag::Stopped;
mover->mDesiredWaypointIndex = -1;
mover->mShouldStopAtDesiredWaypoint = false;
Game::entityManager->SerializeEntity(m_Parent);
@@ -404,6 +410,7 @@ void MovingPlatformComponent::MoverProcessStateChange(const uint32_t index) {
mover->mCurrentWaypointIndex = current;
mover->mNextWaypointIndex = next;
mover->mWaitTime = waypoints[current].movingPlatform.wait;
mover->mPercentBetweenPoints = 0.0f;
mover->mMoveTimeElapsed = 0.0f;
mover->mPosition = waypoints[current].position;
@@ -419,74 +426,155 @@ void MovingPlatformComponent::MoverProcessStateChange(const uint32_t index) {
}
}
void MovingPlatformComponent::MoverStopAtWaypoint(const bool depart) {
void MovingPlatformComponent::MoverSetWaitingTime(const float waitTime, const float idleTimeElapsed) {
auto* const mover = GetMoverSubComponent();
const auto last = static_cast<uint32_t>(m_Path->pathWaypoints.size() - 1);
const bool atEnd = mover->mCurrentWaypointIndex == 0 || mover->mCurrentWaypointIndex == last;
mover->mState = ePlatformStateFlag::Stopped | ePlatformStateFlag::ReachedDesiredWaypoint | (atEnd ? ePlatformStateFlag::ReachedFinalDestination : 0);
mover->mIdleTimeElapsed = 0.0f;
// LWOPlatform::SetWaitingTime: at least 0.1 s
mover->mTimeToWait = std::max(0.1f, m_Path->pathWaypoints[mover->mCurrentWaypointIndex].movingPlatform.wait);
mover->mDepartAfterWait = depart;
mover->mTimeToWait = std::max(0.1f, waitTime);
mover->mIdleTimeElapsed = idleTimeElapsed;
mover->mWaitSet = true;
}
void MovingPlatformComponent::MoverDepart() {
void MovingPlatformComponent::MoverResumeTravelling() {
auto* const mover = GetMoverSubComponent();
mover->mState = ePlatformStateFlag::Travelling;
mover->mIdleTimeElapsed = 0.0f;
mover->mDepartAfterWait = false;
Game::entityManager->SerializeEntity(m_Parent);
if ((mover->mState & ePlatformStateFlag::Stopped) != 0 && (mover->mState & ePlatformStateFlag::ReachedDesiredWaypoint) == 0) {
// LWOPlatform::StartTravelling 0x0058b170
mover->mState = (mover->mState & ~(ePlatformStateFlag::Waiting | ePlatformStateFlag::Stopped)) | ePlatformStateFlag::Travelling;
}
if ((mover->mState & ePlatformStateFlag::Travelling) != 0) {
// LWOPlatform::UpdateVelocities
mover->mState &= ePlatformStateFlag::MovementMask;
} else {
mover->mState = (mover->mState & ~(ePlatformStateFlag::Travelling | ePlatformStateFlag::Stopped)) | ePlatformStateFlag::Waiting;
MoverSetWaitingTime(mover->mWaitTime, 0.0f);
}
}
// LWOPlatform::ArrivedAtWaypoint and HandleWaypointArrived: at the next waypoint, it stops there if it was sent there
// to stop, or at an end of a path run once (which turns it round); otherwise it waits there and goes on
void MovingPlatformComponent::MoverArrive() {
void MovingPlatformComponent::MoverArrivedAtWaypoint() {
auto* const mover = GetMoverSubComponent();
// A platform with nowhere to go (one waypoint, or at the end of a path run once) is not arriving
if (mover->mCurrentWaypointIndex == mover->mNextWaypointIndex) return;
const auto& next = m_Path->pathWaypoints[mover->mNextWaypointIndex].position;
bool closeEnough{};
if (mover->mTimeBased) {
// LWOPlatform::CheckEnoughTimeElapsedAtWaypoint 0x00bdc720
closeEnough = std::abs(mover->mCurrentSpeed - mover->mMoveTimeElapsed) < 0.02f;
} else {
// LWOPlatform::CloseToNextWaypoint 0x00bd4140: within 0.01 of it, or past it
const auto offset = next - mover->mPosition;
const auto direction = next - m_Path->pathWaypoints[mover->mCurrentWaypointIndex].position;
closeEnough = offset.SquaredLength() <= 0.0001f || direction.DotProduct(offset) <= 0.0f;
}
if (!closeEnough) return;
const auto arrived = mover->mNextWaypointIndex;
const auto last = static_cast<uint32_t>(m_Path->pathWaypoints.size() - 1);
const bool atEnd = arrived == last;
const bool atDesired = mover->mDesiredWaypointIndex == static_cast<int32_t>(arrived);
bool stop = false;
if (atDesired) {
stop = mover->mShouldStopAtDesiredWaypoint;
const bool atLastWaypoint = arrived == static_cast<uint32_t>(m_Path->pathWaypoints.size() - 1);
bool atDesiredWaypoint = false;
bool stopAtDesiredWaypoint = false;
bool turnedAtEnd = false;
mover->mState = ePlatformStateFlag::ReachedDesiredWaypoint;
if (mover->mDesiredWaypointIndex == static_cast<int32_t>(arrived)) {
atDesiredWaypoint = true;
stopAtDesiredWaypoint = mover->mShouldStopAtDesiredWaypoint;
mover->mShouldStopAtDesiredWaypoint = false;
mover->mDesiredWaypointIndex = -1;
}
if ((arrived == 0 || atEnd) && static_cast<PathBehavior>(m_Path->pathBehavior) == PathBehavior::Once) {
stop = true;
mover->mInReverse = !mover->mInReverse;
if (arrived == 0 || atLastWaypoint) {
mover->mState |= ePlatformStateFlag::ReachedFinalDestination;
if (static_cast<PathBehavior>(m_Path->pathBehavior) == PathBehavior::Once) {
turnedAtEnd = true;
mover->mInReverse = !mover->mInReverse;
}
}
if (stopAtDesiredWaypoint || turnedAtEnd) {
mover->mState = (mover->mState & ~(ePlatformStateFlag::Waiting | ePlatformStateFlag::Travelling)) | ePlatformStateFlag::Stopped;
} else {
mover->mState = (mover->mState & ~(ePlatformStateFlag::Waiting | ePlatformStateFlag::Stopped)) | ePlatformStateFlag::Travelling;
}
MoverProcessStateChange(arrived);
MoverStopAtWaypoint(!stop);
Game::entityManager->SerializeEntity(m_Parent);
FireArrivalHooks(arrived, atDesired, atEnd);
MoverHandleWaypointArrived(arrived, atDesiredWaypoint, atLastWaypoint);
}
void MovingPlatformComponent::MoverHandleWaypointArrived(const uint32_t index, const bool atDesiredWaypoint, const bool atLastWaypoint) {
FireArrivalHooks(index, atDesiredWaypoint, atLastWaypoint);
// The scripts may have taken the platform or its object away
auto* const mover = GetMoverSubComponent();
if (!mover || !IsMover()) return;
if ((mover->mState & ePlatformStateFlag::Travelling) != 0) {
mover->mState = (mover->mState & ~(ePlatformStateFlag::Travelling | ePlatformStateFlag::Stopped)) | ePlatformStateFlag::Waiting;
MoverSetWaitingTime(mover->mWaitTime, 0.0f);
}
// Live serialized a platform that waits at the waypoint it arrived at (it leaves again), not one that stopped there
if ((mover->mState & ePlatformStateFlag::Stopped) == 0) Game::entityManager->SerializeEntity(m_Parent);
}
// LWOPlatform::Run 0x00c87080 and RunPlatform 0x00c86e10. The client's platform is moved by its physics, at the
// velocity SetLinearVelocity 0x00be9200 gives it; the server moves it here by the same speed.
void MovingPlatformComponent::Run(const float deltaTime) {
if (!IsMover()) return;
auto* const mover = GetMoverSubComponent();
if ((mover->mState & ePlatformStateFlag::Travelling) != 0) {
// LWOPlatform::Run / RunPlatform: time based paths count the time travelled; others move at the speed between
// the two waypoints' (CalculateSpeed), the client by its physics
if (mover->mTimeBased) {
mover->mMoveTimeElapsed += deltaTime;
mover->mPercentBetweenPoints = mover->mCurrentSpeed > 0.0f ? std::min(mover->mMoveTimeElapsed, mover->mCurrentSpeed) / mover->mCurrentSpeed : 1.0f;
} else if (mover->mSegmentLength > 0.0f) {
auto* mover = GetMoverSubComponent();
// LWOPlatform::SetupPath 0x00c17d10 and SendMessage 0x00bdc930 (RebuildNotifyState): a quick build's platform does not
// run until it is built, nor once the quick build is open again
if (!m_CheckedQuickBuild) {
m_CheckedQuickBuild = true;
m_QuickBuild = m_Parent->GetComponent<QuickBuildComponent>();
if (m_QuickBuild) mover->mActive = false;
}
if (m_QuickBuild) {
const auto quickBuildState = m_QuickBuild->GetState();
if (quickBuildState == eQuickBuildState::OPEN) mover->mActive = false;
else if (quickBuildState == eQuickBuildState::COMPLETED) mover->mActive = true;
}
if (!mover->mActive || mover->mState == 0) return;
const bool travelling = (mover->mState & ePlatformStateFlag::Travelling) != 0;
const auto& from = m_Path->pathWaypoints[mover->mCurrentWaypointIndex].position;
const auto& to = m_Path->pathWaypoints[mover->mNextWaypointIndex].position;
if (mover->mTimeBased) {
// LWOPlatform::TimeBasedCalculatePercentToNextWaypoint 0x00bd4090: mCurrentSpeed is the seconds to the next waypoint
if (travelling) mover->mMoveTimeElapsed += deltaTime;
mover->mMoveTimeElapsed = std::min(mover->mMoveTimeElapsed, mover->mCurrentSpeed);
mover->mPercentBetweenPoints = mover->mCurrentSpeed > 0.0f ? mover->mMoveTimeElapsed / mover->mCurrentSpeed : 1.0f;
if (travelling) mover->mPosition = from + (to - from) * mover->mPercentBetweenPoints;
} else if (travelling) {
// LWOPlatform::GetSpeed 0x00bd40e0: from the waypoint's speed to the next one's along the way
if (mover->mSegmentLength > 0.0f) {
const float speed = mover->mCurrentSpeed + (mover->mNextSpeed - mover->mCurrentSpeed) * mover->mPercentBetweenPoints;
mover->mPercentBetweenPoints += std::max(speed, 0.0f) * deltaTime / mover->mSegmentLength;
const float travelled = mover->mPercentBetweenPoints * mover->mSegmentLength + std::max(speed, 0.0f) * deltaTime;
mover->mPercentBetweenPoints = std::min(travelled / mover->mSegmentLength, 1.0f);
} else {
mover->mPercentBetweenPoints = 1.0f;
}
const auto& from = m_Path->pathWaypoints[mover->mCurrentWaypointIndex].position;
const auto& to = m_Path->pathWaypoints[mover->mNextWaypointIndex].position;
const float percent = std::min(mover->mPercentBetweenPoints, 1.0f);
mover->mPosition = from + (to - from) * percent;
if (mover->mPercentBetweenPoints >= 1.0f) MoverArrive();
} else if (mover->mDepartAfterWait) {
mover->mIdleTimeElapsed += deltaTime;
if (mover->mIdleTimeElapsed >= mover->mTimeToWait) MoverDepart();
} else if ((mover->mState & ePlatformStateFlag::ReachedDesiredWaypoint) != 0) {
mover->mPosition = from + (to - from) * mover->mPercentBetweenPoints;
}
const bool stopped = (mover->mState & ePlatformStateFlag::Stopped) != 0;
// LWOPlatform::IncrementWaitingTime 0x00bd4370
bool doneWaiting = false;
if ((mover->mState & ePlatformStateFlag::Waiting) != 0 && mover->mWaitSet) {
mover->mIdleTimeElapsed += deltaTime;
if (mover->mIdleTimeElapsed >= mover->mTimeToWait) {
mover->mIdleTimeElapsed = 0.0f;
doneWaiting = true;
}
}
if (doneWaiting) {
mover->mState = (mover->mState & ~(ePlatformStateFlag::Waiting | ePlatformStateFlag::Stopped)) | ePlatformStateFlag::Travelling;
} else if (!stopped && travelling) {
// LWOPlatform::HandleStoppedLogic 0x00bd16a0. The client also checks while it waits, which only matters where
// two waypoints are in one place: there it would arrive every frame.
MoverArrivedAtWaypoint();
// A script told of the arrival may have put the platform on another path
mover = GetMoverSubComponent();
if (!IsMover()) return;
}
if ((mover->mState & ePlatformStateFlag::Travelling) != 0 && (doneWaiting || mover->mCurrentSpeed != mover->mNextSpeed)) {
mover->mState &= ePlatformStateFlag::MovementMask;
// Live serialized a platform leaving its waypoint
if (doneWaiting) Game::entityManager->SerializeEntity(m_Parent);
}
}
@@ -535,7 +623,9 @@ void MovingPlatformComponent::WarpToWaypoint(size_t index) {
if (!IsMover() || index >= m_Path->pathWaypoints.size()) return;
const auto& waypoint = m_Path->pathWaypoints[index];
MoverProcessStateChange(static_cast<uint32_t>(index));
MoverStopAtWaypoint(false);
auto* const mover = GetMoverSubComponent();
const bool atEnd = index == 0 || index == m_Path->pathWaypoints.size() - 1;
mover->mState = ePlatformStateFlag::Stopped | ePlatformStateFlag::ReachedDesiredWaypoint | (atEnd ? ePlatformStateFlag::ReachedFinalDestination : 0);
m_Parent->SetPosition(waypoint.position);
m_Parent->SetRotation(waypoint.rotation);

View File

@@ -48,14 +48,18 @@ enum class eMoverSubComponentType : uint32_t {
};
/**
* The client's platform state flags (LWOPlatform)
* The client's platform state flags (LWOPlatform), as live sent them: a platform that was never started is stopped at
* its waypoint (12), one waiting out a waypoint's wait is 9 (25 at either end of its path), one on its way is 2 and
* one that stopped at an end of a path run once is 28.
*/
namespace ePlatformStateFlag {
constexpr uint32_t Stopped = 1;
constexpr uint32_t Waiting = 1;
constexpr uint32_t Travelling = 2;
constexpr uint32_t Waiting = 4;
constexpr uint32_t Stopped = 4;
constexpr uint32_t ReachedDesiredWaypoint = 8;
constexpr uint32_t ReachedFinalDestination = 16;
// What LWOPlatform::UpdateVelocities 0x00bd4330 keeps when the platform sets off (it drops the two "reached" bits)
constexpr uint32_t MovementMask = Waiting | Travelling | Stopped;
};
/**
@@ -94,11 +98,16 @@ public:
NiPoint3 mPosition{};
uint32_t mCurrentWaypointIndex = 0;
uint32_t mNextWaypointIndex = 0;
// Time spent at the waypoint, and how long it waits there (the waypoint's wait, at least 0.1 s)
// Time spent at the waypoint, and how long it waits there (LWOPlatform::SetWaitingTime 0x00bdc860: the waypoint's
// wait, at least 0.1 s); the wait only counts once it was set
float mIdleTimeElapsed = 0;
float mTimeToWait = 0;
// Whether it leaves when the wait is over (false: stopped until told otherwise)
bool mDepartAfterWait = false;
bool mWaitSet = false;
// The current waypoint's wait
float mWaitTime = 0;
// Whether it runs: a quick build's platform does not until it is built, nor while the quick build is open again
// (LWOPlatform::SendMessage 0x00bdc930, RebuildNotifyState)
bool mActive = true;
// Time travelled since the current waypoint (time based paths only)
float mMoveTimeElapsed = 0;
// The current and next waypoints' speeds; time based paths: the seconds from one to the next in mCurrentSpeed
@@ -111,11 +120,10 @@ public:
/**
* A mover along its path (4), as the client's LWOPlatformMover, run by the server as live ran it: the client's
* LWOPlatform logic (ArrivedAtWaypoint 0x00c86c30, ProcessStateChange 0x00cce380, GetNextWaypoint 0x00bd4490 /
* GetNextReversedWaypoint 0x00bd4420, the speeds of GetWaypointSpeed 0x00be90d0), with live's states: it travels (2),
* and at a waypoint it is stopped (1) with ReachedDesiredWaypoint (8), and ReachedFinalDestination (16) at either end,
* while it waits the waypoint's wait time; each arrival and departure is serialized (NT movers in the live captures:
* 25 on arrival, 2 on departure).
* LWOPlatform logic (RunPlatform 0x00c86e10, ArrivedAtWaypoint 0x00c86c30, HandleWaypointArrived 0x00c17bc0,
* ResumeTravelling 0x00c86b90, ProcessStateChange 0x00cce380, GetNextWaypoint 0x00bd4490 / GetNextReversedWaypoint
* 0x00bd4420, the speeds of GetWaypointSpeed 0x00be90d0). Live serialized it when it began waiting at a waypoint and
* when it left one, not when it stopped (the client stops by itself).
*/
class MoverSubComponent final : public PlatformSubComponent {
public:
@@ -136,10 +144,12 @@ public:
/**
* A simple mover (5), as the client's LWOPlatformSimpleMover: between a start point and that point moved by
* platformMove (in the start rotation), taking platformMoveTime seconds, as GenerateSimpleMoverPath builds its two
* waypoint path. Live constructed simple movers stopped at their desired waypoint.
* waypoint path. At an end it has stopped there (28), as any platform on a path run once.
*/
class SimpleMoverSubComponent final : public PlatformSubComponent {
public:
// Live constructed the NJ counterweights waiting at their waypoint (9)
SimpleMoverSubComponent() { mState = ePlatformStateFlag::Waiting | ePlatformStateFlag::ReachedDesiredWaypoint; }
eMoverSubComponentType GetType() const override { return eMoverSubComponentType::simpleMover; }
// LWOPlatformSimpleMover::Deserialize: a dirty bit, then whether there is a starting point with its position and
@@ -295,6 +305,10 @@ private:
*/
std::vector<std::unique_ptr<PlatformSubComponent>> m_SubComponents;
// The object's quick build, looked up when the platform first runs
class QuickBuildComponent* m_QuickBuild = nullptr;
bool m_CheckedQuickBuild = false;
/**
* Counts sends so an arrival timer from an older send does nothing
*/
@@ -304,13 +318,16 @@ private:
void FireArrivalHooks(uint32_t index, bool atDesiredWaypoint, bool atLastWaypoint);
// The mover: index becomes the current waypoint (the next from the path's behavior and direction), at it
// LWOPlatform::ProcessStateChange: index becomes the current waypoint (the next from the path's behavior and direction)
void MoverProcessStateChange(uint32_t index);
// At its current waypoint, stopped; it leaves after the waypoint's wait when depart
void MoverStopAtWaypoint(bool depart);
// Leaves (or carries on) towards the next waypoint
void MoverDepart();
void MoverArrive();
// 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
void MoverResumeTravelling();
// LWOPlatform::ArrivedAtWaypoint: once it is at its next waypoint
void MoverArrivedAtWaypoint();
// LWOPlatform::HandleWaypointArrived: tells the scripts, then a platform that travels on waits at the waypoint
void MoverHandleWaypointArrived(uint32_t index, bool atDesiredWaypoint, bool atLastWaypoint);
public:
void Run(float deltaTime) override;

View File

@@ -89,7 +89,7 @@ TEST_F(MovingPlatformComponentTest, OneSubcomponentPerSetting) {
}
// Live: 1 (subcomponents), 1 (dirty), 0 (no path), 1, type 5, the starting point (the object's position and
// rotation, w first), state 9 (stopped at its desired waypoint), waypoint 0, not reversing, then the ending 0 bit
// rotation, w first), state 9 (waiting at its desired waypoint), waypoint 0, not reversing, then the ending 0 bit
TEST_F(MovingPlatformComponentTest, SimpleMoverConstructionMatchesLive) {
info.lot = 16141;
info.pos = NiPoint3(Float(0xc2e02255), Float(0x436d1992), Float(0xc32347e8));
@@ -167,9 +167,9 @@ TEST_F(MovingPlatformComponentTest, RotaterIsWrittenAsTypeSix) {
EXPECT_EQ(bits.back(), '0');
}
// A mover runs on the server as live ran it (the NT movers in the live captures): stopped at its first waypoint with
// the time waited (25), travelling after the waypoint's wait (2), arriving at the other end stopped there (25, turned
// round on a bounce path), and a GoToWaypoint that stops keeps it there
// A mover runs on the server as live ran it: it waits at its first waypoint (9: waiting at a waypoint, as the GF
// shooting gallery targets were constructed), travels after the waypoint's wait (2), waits at the other end (25, turned
// round on a bounce path); sent to a waypoint to stop it waits with the desired waypoint, leaves and stops there (28)
TEST_F(MovingPlatformComponentTest, MoverRunsLikeLive) {
Path path;
path.pathType = PathType::MovingPlatform;
@@ -189,12 +189,12 @@ TEST_F(MovingPlatformComponentTest, MoverRunsLikeLive) {
auto* const platform = entity.AddComponent<MovingPlatformComponent>(-1, "TestMoverPath");
ASSERT_TRUE(platform->IsMover());
auto* const mover = platform->GetMoverSubComponent();
EXPECT_EQ(mover->mState, 25u);
EXPECT_EQ(mover->mState, 9u);
EXPECT_EQ(mover->mCurrentWaypointIndex, 0u);
EXPECT_EQ(mover->mNextWaypointIndex, 1u);
platform->Run(1.9f);
EXPECT_EQ(mover->mState, 25u);
EXPECT_EQ(mover->mState, 9u);
EXPECT_FLOAT_EQ(mover->mIdleTimeElapsed, 1.9f);
platform->Run(0.2f);
EXPECT_EQ(mover->mState, 2u);
@@ -217,28 +217,85 @@ TEST_F(MovingPlatformComponentTest, MoverRunsLikeLive) {
EXPECT_TRUE(mover->mInReverse);
EXPECT_EQ(mover->mPercentBetweenPoints, 0.0f);
// Sent back to the start to stop there: it leaves at once and stays
// Sent back to the start to stop there: it waits out the waypoint's wait, leaves and stays
platform->GotoWaypoint(0, true);
EXPECT_EQ(mover->mState, 25u);
EXPECT_EQ(mover->mDesiredWaypointIndex, 0);
EXPECT_TRUE(mover->mShouldStopAtDesiredWaypoint);
platform->Run(1.1f);
EXPECT_EQ(mover->mState, 2u);
EXPECT_EQ(mover->mDesiredWaypointIndex, 0);
platform->Run(2.5f);
EXPECT_EQ(mover->mState, 25u);
EXPECT_EQ(mover->mState, 28u);
EXPECT_EQ(mover->mCurrentWaypointIndex, 0u);
EXPECT_EQ(mover->mDesiredWaypointIndex, -1);
platform->Run(10.0f);
EXPECT_EQ(mover->mState, 25u);
EXPECT_EQ(mover->mState, 28u);
// Started at a waypoint it first waits there (issue 964), then stopped mid way and started again
// Started at a waypoint it first waits there (issue 964), then stopped mid way (4, the bit the client stops on) and
// started again
platform->StartPathing();
EXPECT_EQ(mover->mState, 25u);
platform->Run(2.1f);
EXPECT_EQ(mover->mState, 2u);
platform->Run(1.0f);
platform->StopPathing();
EXPECT_EQ(mover->mState & 1u, 1u);
EXPECT_EQ(mover->mState, 4u);
const auto percent = mover->mPercentBetweenPoints;
platform->Run(1.0f);
EXPECT_EQ(mover->mPercentBetweenPoints, percent);
platform->StartPathing();
EXPECT_EQ(mover->mState, 2u);
}
// The NJ falling tiles in the live captures (LOT 14335, a two waypoint path run once, not started on load): 12 until
// stepped on, sent to waypoint 1 it waits (9) and leaves (2); there it has stopped and turned round (28), and sent back
// it waits (25, reversed, towards 0) and leaves (2), to stop at the start as live constructed used tiles (28, forwards)
TEST_F(MovingPlatformComponentTest, MoverOnceLikeLiveFallingTile) {
Path path;
path.pathType = PathType::MovingPlatform;
path.pathName = "TestDropPath";
path.pathBehavior = PathBehavior::Once;
PathWaypoint first;
first.position = NiPoint3(0.0f, 10.0f, 0.0f);
first.speed = 5.0f;
PathWaypoint second = first;
second.position = NiPoint3(0.0f, 0.0f, 0.0f);
path.pathWaypoints = { first, second };
const_cast<Zone*>(Game::zoneManager->GetZone())->AddPath(path);
info.settings.Insert<bool>(u"startPathingOnLoad", false);
Entity entity(288300744895900109, info);
info.settings.values.clear();
auto* const platform = entity.AddComponent<MovingPlatformComponent>(-1, "TestDropPath");
auto* const mover = platform->GetMoverSubComponent();
EXPECT_EQ(mover->mState, 12u);
platform->Run(5.0f);
EXPECT_EQ(mover->mState, 12u);
platform->GotoWaypoint(1);
EXPECT_EQ(mover->mState, 9u);
EXPECT_EQ(mover->mDesiredWaypointIndex, 1);
EXPECT_TRUE(mover->mShouldStopAtDesiredWaypoint);
platform->Run(0.11f);
EXPECT_EQ(mover->mState, 2u);
platform->Run(1.0f);
EXPECT_EQ(mover->mState, 2u);
platform->Run(1.1f);
EXPECT_EQ(mover->mState, 28u);
EXPECT_EQ(mover->mCurrentWaypointIndex, 1u);
EXPECT_EQ(mover->mNextWaypointIndex, 0u);
EXPECT_TRUE(mover->mInReverse);
EXPECT_EQ(mover->mDesiredWaypointIndex, -1);
platform->GotoWaypoint(0);
EXPECT_EQ(mover->mState, 25u);
EXPECT_EQ(mover->mDesiredWaypointIndex, 0);
platform->Run(0.11f);
EXPECT_EQ(mover->mState, 2u);
platform->Run(2.1f);
EXPECT_EQ(mover->mState, 28u);
EXPECT_EQ(mover->mCurrentWaypointIndex, 0u);
EXPECT_EQ(mover->mNextWaypointIndex, 1u);
EXPECT_FALSE(mover->mInReverse);
}