|
|
|
|
@@ -20,6 +20,9 @@
|
|
|
|
|
#include "Entity.h"
|
|
|
|
|
#include "ObjectLoadState.h"
|
|
|
|
|
#include "MovementAIComponent.h"
|
|
|
|
|
#include "QuickBuildComponent.h"
|
|
|
|
|
#include "PhantomPhysicsComponent.h"
|
|
|
|
|
#include "eQuickBuildState.h"
|
|
|
|
|
|
|
|
|
|
void PlatformSubComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
|
|
|
|
outBitStream.Write<bool>(true);
|
|
|
|
|
@@ -154,6 +157,18 @@ void MovingPlatformComponent::LoadConfigData() {
|
|
|
|
|
if (m_Parent->HasVar(u"platformMoveTime")) simpleMover->mMoveTime = m_Parent->GetVar<float>(u"platformMoveTime");
|
|
|
|
|
}
|
|
|
|
|
simpleMover->mCurrentWaypointIndex = simpleMover->mStartAtEnd ? 1 : 0;
|
|
|
|
|
|
|
|
|
|
// As a mover on its path (LWOPlatform::ResumeTravelling 0x00c86b90 and SetWaitingTime 0x00bdc860): unless
|
|
|
|
|
// startPathingOnLoad is false it waits at its waypoint (9), for the shortest wait as its waypoints have none.
|
|
|
|
|
// Live's scripts for the NJ spinners, which are simple movers that only move when used, stop them when they
|
|
|
|
|
// start up (L_NJ_SPINNER_SERVER: StopPathing), and the simple movers that wait for an event without such a script
|
|
|
|
|
// have startPathingOnLoad 0.
|
|
|
|
|
const bool startOnLoad = !m_Parent->HasVar(u"startPathingOnLoad") || m_Parent->GetVar<bool>(u"startPathingOnLoad");
|
|
|
|
|
if (startOnLoad) {
|
|
|
|
|
simpleMover->mState = ePlatformStateFlag::Waiting | ePlatformStateFlag::ReachedDesiredWaypoint;
|
|
|
|
|
simpleMover->mTimeToWait = 0.1f;
|
|
|
|
|
simpleMover->mWaitSet = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto pathName = GeneralUtils::UTF16ToWTF8(m_PathName);
|
|
|
|
|
@@ -163,21 +178,14 @@ 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)
|
|
|
|
|
if (IsMover()) {
|
|
|
|
|
auto* const mover = GetMoverSubComponent();
|
|
|
|
|
mover->mTimeBased = m_Path->movingPlatform.timeBasedMovement != 0;
|
|
|
|
|
const auto start = m_Parent->HasVar(u"attached_path_start") ? m_Parent->GetVar<int32_t>(u"attached_path_start") : 0;
|
|
|
|
|
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);
|
|
|
|
|
SetupMoverPath();
|
|
|
|
|
} 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;
|
|
|
|
|
const auto start = m_Parent->HasVar(u"attached_path_start") ? m_Parent->GetVar<int32_t>(u"attached_path_start") : 0;
|
|
|
|
|
m_StartWaypoint = start >= 0 ? start : 0;
|
|
|
|
|
SetupRotator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Live constructed every moving platform with simple physics as keyframed
|
|
|
|
|
@@ -185,6 +193,71 @@ void MovingPlatformComponent::LoadConfigData() {
|
|
|
|
|
if (simplePhysics && !m_Parent->HasVar(u"motionType")) simplePhysics->SetPhysicsMotionState(SimplePhysicsComponent::MOTION_TYPE_KEYFRAMED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// LWOPlatform::SetupPath 0x00c17d10: a mover is at its starting 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).
|
|
|
|
|
void MovingPlatformComponent::SetupMoverPath() {
|
|
|
|
|
auto* const mover = GetMoverSubComponent();
|
|
|
|
|
mover->mTimeBased = m_Path->movingPlatform.timeBasedMovement != 0;
|
|
|
|
|
mover->mInReverse = m_PathReverse;
|
|
|
|
|
MoverProcessStateChange(m_StartWaypoint);
|
|
|
|
|
const bool startOnLoad = !m_Parent->HasVar(u"startPathingOnLoad") || m_Parent->GetVar<bool>(u"startPathingOnLoad");
|
|
|
|
|
if (startOnLoad) MoverResumeTravelling();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// LWOPlatformRotator: on its path it only turns (rotX/rotY/rotZ at rate; its HandleStoppedLogic 0x00bdc660 only keeps
|
|
|
|
|
// the angular velocity, so it never arrives anywhere), while travelling. Only one on a path runs
|
|
|
|
|
// (LWOMovingPlatformComponent::SetupPlatform 0x00ccea50), and the client reads a platform that is not at a waypoint
|
|
|
|
|
// from its path (LWOPlatform::Deserialize 0x00c870e0), so one without a path stays as it was made (12). The client's
|
|
|
|
|
// rotator starts turning when it is sent travelling (Deserialize: StartTravelling, ResumeTravelling, UpdateVelocities).
|
|
|
|
|
void MovingPlatformComponent::SetupRotator() {
|
|
|
|
|
auto* const rotator = static_cast<RotatorSubComponent*>(GetMoverSubComponent());
|
|
|
|
|
// LWOPlatformRotator::LoadConfigData 0x00c33e10
|
|
|
|
|
constexpr float pi = 3.14159265358979323846f;
|
|
|
|
|
if (m_Parent->HasVar(u"rotX")) rotator->mRotationX = m_Parent->GetVarAs<float>(u"rotX") * pi;
|
|
|
|
|
if (m_Parent->HasVar(u"rotY")) rotator->mRotationY = m_Parent->GetVarAs<float>(u"rotY") * pi;
|
|
|
|
|
if (m_Parent->HasVar(u"rotZ")) rotator->mRotationZ = m_Parent->GetVarAs<float>(u"rotZ") * pi;
|
|
|
|
|
rotator->mRate = m_Parent->GetVarAs<float>(u"rate");
|
|
|
|
|
|
|
|
|
|
if (m_Path == nullptr || m_Path->pathWaypoints.empty()) return;
|
|
|
|
|
// LWOPlatform::SetupPath 0x00c17d10
|
|
|
|
|
rotator->mTimeBased = m_Path->movingPlatform.timeBasedMovement != 0;
|
|
|
|
|
rotator->mInReverse = m_PathReverse;
|
|
|
|
|
if (static_cast<size_t>(m_StartWaypoint) >= m_Path->pathWaypoints.size()) m_StartWaypoint = 0;
|
|
|
|
|
MoverProcessStateChange(m_StartWaypoint);
|
|
|
|
|
const bool startOnLoad = !m_Parent->HasVar(u"startPathingOnLoad") || m_Parent->GetVar<bool>(u"startPathingOnLoad");
|
|
|
|
|
if (startOnLoad) rotator->mState = ePlatformStateFlag::Travelling;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// LWOMovingPlatformComponent::SetCurrentPath 0x00d0f570 (the SetCurrentPath game message, 0x00d0f5d0): the path, the
|
|
|
|
|
// waypoint it starts at and its direction, then SetupPlatform 0x00ccea50 makes the subcomponents anew and a mover takes
|
|
|
|
|
// the path. Live wrote the path to the clients with the mover (the GF shooting gallery's targets), whose
|
|
|
|
|
// LWOMovingPlatformComponent::Deserialize 0x00c88000 does the same there.
|
|
|
|
|
bool MovingPlatformComponent::SetCurrentPath(const std::string& pathName, const uint32_t startPoint, const bool reverse) {
|
|
|
|
|
m_PathName = GeneralUtils::ASCIIToUTF16(pathName);
|
|
|
|
|
m_Path = Game::zoneManager->GetZone()->GetPath(pathName);
|
|
|
|
|
m_PathReverse = reverse;
|
|
|
|
|
m_DirtyPath = true;
|
|
|
|
|
m_PathingStopped = false;
|
|
|
|
|
|
|
|
|
|
for (auto& subComponent : m_SubComponents) {
|
|
|
|
|
if (subComponent->GetType() == eMoverSubComponentType::mover) subComponent = std::make_unique<MoverSubComponent>(m_Parent->GetPosition());
|
|
|
|
|
else if (subComponent->GetType() == eMoverSubComponentType::rotater) subComponent = std::make_unique<RotatorSubComponent>(m_Parent->GetPosition());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bool mover = IsMover();
|
|
|
|
|
if (mover) {
|
|
|
|
|
m_StartWaypoint = static_cast<size_t>(startPoint) < m_Path->pathWaypoints.size() ? startPoint : 0;
|
|
|
|
|
SetupMoverPath();
|
|
|
|
|
MoveObject();
|
|
|
|
|
} else {
|
|
|
|
|
m_StartWaypoint = startPoint;
|
|
|
|
|
if (m_Path == nullptr) LOG("Cannot setup platform on path %s", pathName.c_str());
|
|
|
|
|
else if (m_MoverSubComponentType == eMoverSubComponentType::rotater) SetupRotator();
|
|
|
|
|
}
|
|
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
|
|
|
|
return mover;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MovingPlatformComponent::~MovingPlatformComponent() = default;
|
|
|
|
|
|
|
|
|
|
void MovingPlatformComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
|
|
|
|
@@ -207,11 +280,13 @@ void MovingPlatformComponent::Serialize(RakNet::BitStream& outBitStream, bool bI
|
|
|
|
|
|
|
|
|
|
// LWOMovingPlatformComponent::Deserialize: whether subcomponents follow, whether the path changed (then whether
|
|
|
|
|
// there is one: its name, starting waypoint and reverse), then the subcomponents. Live wrote the path with the
|
|
|
|
|
// construction and the mover's state with every serialization.
|
|
|
|
|
// construction and the mover's state with every serialization; a path set later (SetCurrentPath) is written once.
|
|
|
|
|
outBitStream.Write<bool>(true);
|
|
|
|
|
|
|
|
|
|
outBitStream.Write(bIsInitialUpdate);
|
|
|
|
|
if (bIsInitialUpdate) {
|
|
|
|
|
const bool writePath = bIsInitialUpdate || m_DirtyPath;
|
|
|
|
|
outBitStream.Write(writePath);
|
|
|
|
|
if (writePath) {
|
|
|
|
|
if (!bIsInitialUpdate) m_DirtyPath = false;
|
|
|
|
|
const auto hasPath = !m_PathName.empty() && m_Path != nullptr;
|
|
|
|
|
outBitStream.Write(hasPath);
|
|
|
|
|
if (hasPath) {
|
|
|
|
|
@@ -220,7 +295,7 @@ void MovingPlatformComponent::Serialize(RakNet::BitStream& outBitStream, bool bI
|
|
|
|
|
outBitStream.Write<uint16_t>(c);
|
|
|
|
|
}
|
|
|
|
|
outBitStream.Write<uint32_t>(m_StartWaypoint);
|
|
|
|
|
outBitStream.Write<bool>(false);
|
|
|
|
|
outBitStream.Write<bool>(m_PathReverse);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -246,6 +321,11 @@ void MovingPlatformComponent::OnQuickBuildInitilized() {
|
|
|
|
|
|
|
|
|
|
void MovingPlatformComponent::OnCompleteQuickBuild() {
|
|
|
|
|
if (m_MoverSubComponentType == eMoverSubComponentType::simpleMover) {
|
|
|
|
|
// Live (the NJ counterweights, LOT 16141): the built simple mover is serialized waiting at its waypoint (9) and
|
|
|
|
|
// about 0.1 s later travelling (2) to its other end, where it stops without a serialization and
|
|
|
|
|
// PlatformAtLastWaypoint tells the scripts. It is the client's LWOPlatform at work: active once its quick build
|
|
|
|
|
// is complete (SendMessage 0x00bdc930), it waits the shortest wait (SetWaitingTime 0x00bdc860) and sets off
|
|
|
|
|
// (RunPlatform 0x00c86e10): RunSimpleMover.
|
|
|
|
|
GetSimpleMoverSubComponent()->mDirtyState = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
@@ -269,7 +349,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 +364,10 @@ 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;
|
|
|
|
|
mover->mVelocity = NiPoint3Constant::ZERO;
|
|
|
|
|
}
|
|
|
|
|
FireArrivalHooks(index, true, index == m_Path->pathWaypoints.size() - 1);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
@@ -307,11 +392,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() {
|
|
|
|
|
@@ -321,7 +409,8 @@ void MovingPlatformComponent::StartPathing() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (m_MoverSubComponentType == eMoverSubComponentType::rotater) {
|
|
|
|
|
// LWOPlatformRotator::StartLinearMovement: spinning again
|
|
|
|
|
// LWOPlatformRotator::StartLinearMovement: spinning again (only on a path, as above)
|
|
|
|
|
if (m_Path == nullptr) return;
|
|
|
|
|
GetMoverSubComponent()->mState = ePlatformStateFlag::Travelling;
|
|
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
|
|
|
|
return;
|
|
|
|
|
@@ -332,36 +421,34 @@ 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->mVelocity = NiPoint3Constant::ZERO;
|
|
|
|
|
mover->mDesiredWaypointIndex = -1;
|
|
|
|
|
mover->mShouldStopAtDesiredWaypoint = false;
|
|
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
|
|
|
|
@@ -404,6 +491,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,75 +507,312 @@ 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;
|
|
|
|
|
// Only at an end of the path, or stopped, does the object lose its velocities here. Waiting at a waypoint in between
|
|
|
|
|
// it keeps them: live's platforms went on as they came for the wait (the GF shooting gallery subs 2 units past each
|
|
|
|
|
// waypoint, the FV dragons 5.33; a dragon met 2.2 s into a 5 s wait was 88 past its waypoint).
|
|
|
|
|
if ((mover->mState & (ePlatformStateFlag::ReachedFinalDestination | ePlatformStateFlag::Stopped)) != 0) mover->mVelocity = NiPoint3Constant::ZERO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MovingPlatformComponent::MoverDepart() {
|
|
|
|
|
void MovingPlatformComponent::MoverUpdateVelocities() {
|
|
|
|
|
auto* const mover = GetMoverSubComponent();
|
|
|
|
|
mover->mState = ePlatformStateFlag::Travelling;
|
|
|
|
|
mover->mIdleTimeElapsed = 0.0f;
|
|
|
|
|
mover->mDepartAfterWait = false;
|
|
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
|
|
|
|
auto direction = m_Path->pathWaypoints[mover->mNextWaypointIndex].position - m_Path->pathWaypoints[mover->mCurrentWaypointIndex].position;
|
|
|
|
|
const float distance = direction.Length();
|
|
|
|
|
if (distance > 0.0f) direction = direction / distance;
|
|
|
|
|
// LWOPlatform::GetSpeed 0x00bd40e0: a time based path's mCurrentSpeed is the seconds to the next waypoint; else from
|
|
|
|
|
// the waypoint's speed to the next one's along the way
|
|
|
|
|
float speed{};
|
|
|
|
|
if (mover->mTimeBased) speed = mover->mCurrentSpeed > 0.0f ? distance / mover->mCurrentSpeed : 0.0f;
|
|
|
|
|
else speed = mover->mCurrentSpeed + (mover->mNextSpeed - mover->mCurrentSpeed) * mover->mPercentBetweenPoints;
|
|
|
|
|
mover->mVelocity = direction * speed;
|
|
|
|
|
mover->mState &= ePlatformStateFlag::MovementMask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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::MoverResumeTravelling() {
|
|
|
|
|
auto* const mover = GetMoverSubComponent();
|
|
|
|
|
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) {
|
|
|
|
|
MoverUpdateVelocities();
|
|
|
|
|
} else {
|
|
|
|
|
mover->mState = (mover->mState & ~(ePlatformStateFlag::Travelling | ePlatformStateFlag::Stopped)) | ePlatformStateFlag::Waiting;
|
|
|
|
|
MoverSetWaitingTime(mover->mWaitTime, 0.0f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
mover->mVelocity = NiPoint3Constant::ZERO;
|
|
|
|
|
} 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::Run(const float deltaTime) {
|
|
|
|
|
if (!IsMover()) return;
|
|
|
|
|
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) {
|
|
|
|
|
// 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) {
|
|
|
|
|
const float speed = mover->mCurrentSpeed + (mover->mNextSpeed - mover->mCurrentSpeed) * mover->mPercentBetweenPoints;
|
|
|
|
|
mover->mPercentBetweenPoints += std::max(speed, 0.0f) * deltaTime / mover->mSegmentLength;
|
|
|
|
|
} 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->mIdleTimeElapsed += deltaTime;
|
|
|
|
|
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 moves its object with SetPosition and SetRotation ignoring the dirty flags (ProcessStateChange 0x00cce380,
|
|
|
|
|
// Resync 0x00be9310), 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<SimplePhysicsComponent>()) {
|
|
|
|
|
simplePhysics->SetPositionAndRotationIgnoringDirtyFlags(mover->mPosition, rotation);
|
|
|
|
|
}
|
|
|
|
|
if (auto* const phantomPhysics = m_Parent->GetComponent<PhantomPhysicsComponent>()) {
|
|
|
|
|
phantomPhysics->SetPositionAndRotationIgnoringDirtyFlags(mover->mPosition, rotation);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
bool MovingPlatformComponent::UpdateActive(PlatformSubComponent& platform) {
|
|
|
|
|
if (!m_CheckedQuickBuild) {
|
|
|
|
|
m_CheckedQuickBuild = true;
|
|
|
|
|
m_QuickBuild = m_Parent->GetComponent<QuickBuildComponent>();
|
|
|
|
|
if (m_QuickBuild) platform.mActive = false;
|
|
|
|
|
}
|
|
|
|
|
if (m_QuickBuild) {
|
|
|
|
|
const auto quickBuildState = m_QuickBuild->GetState();
|
|
|
|
|
if (quickBuildState == eQuickBuildState::OPEN) platform.mActive = false;
|
|
|
|
|
else if (quickBuildState == eQuickBuildState::COMPLETED) platform.mActive = true;
|
|
|
|
|
}
|
|
|
|
|
return platform.mActive;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NiPoint3 CalcRotatorAngularVelocity(const float rotX, const float rotY, const float rotZ, const float rate, const bool reverse) {
|
|
|
|
|
// NiMatrix3::MakeXRotation 0x0116c070, MakeYRotation 0x0116c020 and MakeZRotation 0x0116bfd0
|
|
|
|
|
const float sx = static_cast<float>(std::sin(static_cast<double>(rotX))), cx = static_cast<float>(std::cos(static_cast<double>(rotX)));
|
|
|
|
|
const float sy = static_cast<float>(std::sin(static_cast<double>(rotY))), cy = static_cast<float>(std::cos(static_cast<double>(rotY)));
|
|
|
|
|
const float sz = static_cast<float>(std::sin(static_cast<double>(rotZ))), cz = static_cast<float>(std::cos(static_cast<double>(rotZ)));
|
|
|
|
|
const float x[3][3] = { { 1.0f, 0.0f, 0.0f }, { 0.0f, cx, sx }, { 0.0f, -sx, cx } };
|
|
|
|
|
const float y[3][3] = { { cy, 0.0f, -sy }, { 0.0f, 1.0f, 0.0f }, { sy, 0.0f, cy } };
|
|
|
|
|
const float z[3][3] = { { cz, sz, 0.0f }, { -sz, cz, 0.0f }, { 0.0f, 0.0f, 1.0f } };
|
|
|
|
|
// NiMatrix3::FromEulerAnglesXYZ 0x0116c3a0: x * (y * z)
|
|
|
|
|
float yz[3][3]{};
|
|
|
|
|
float m[3][3]{};
|
|
|
|
|
for (int32_t i = 0; i < 3; i++) for (int32_t j = 0; j < 3; j++) for (int32_t k = 0; k < 3; k++) yz[i][j] += y[i][k] * z[k][j];
|
|
|
|
|
for (int32_t i = 0; i < 3; i++) for (int32_t j = 0; j < 3; j++) for (int32_t k = 0; k < 3; k++) m[i][j] += x[i][k] * yz[k][j];
|
|
|
|
|
|
|
|
|
|
// NiQuaternion::FromRotation
|
|
|
|
|
float q[4]{}; // x, y, z, w
|
|
|
|
|
const float trace = m[0][0] + m[1][1] + m[2][2];
|
|
|
|
|
if (trace > 0.0f) {
|
|
|
|
|
float root = std::sqrt(trace + 1.0f);
|
|
|
|
|
q[3] = 0.5f * root;
|
|
|
|
|
root = 0.5f / root;
|
|
|
|
|
q[0] = (m[2][1] - m[1][2]) * root;
|
|
|
|
|
q[1] = (m[0][2] - m[2][0]) * root;
|
|
|
|
|
q[2] = (m[1][0] - m[0][1]) * root;
|
|
|
|
|
} else {
|
|
|
|
|
constexpr int32_t next[3] = { 1, 2, 0 };
|
|
|
|
|
int32_t i = 0;
|
|
|
|
|
if (m[1][1] > m[0][0]) i = 1;
|
|
|
|
|
if (m[2][2] > m[i][i]) i = 2;
|
|
|
|
|
const int32_t j = next[i];
|
|
|
|
|
const int32_t k = next[j];
|
|
|
|
|
float root = std::sqrt(m[i][i] - m[j][j] - m[k][k] + 1.0f);
|
|
|
|
|
q[i] = 0.5f * root;
|
|
|
|
|
root = 0.5f / root;
|
|
|
|
|
q[3] = (m[k][j] - m[j][k]) * root;
|
|
|
|
|
q[j] = (m[j][i] + m[i][j]) * root;
|
|
|
|
|
q[k] = (m[k][i] + m[i][k]) * root;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// hkpKeyFrameUtility::KeyFrameInfo::setUsingPositionOrientationPair 0x012a4050: the rotation from the first to the
|
|
|
|
|
// second (the rotation itself, or its inverse in reverse), normalized; without an axis there is no velocity; else
|
|
|
|
|
// the axis (the other way for a negative w) times twice the arc cosine of |w| over the time
|
|
|
|
|
if (reverse) {
|
|
|
|
|
q[0] = -q[0];
|
|
|
|
|
q[1] = -q[1];
|
|
|
|
|
q[2] = -q[2];
|
|
|
|
|
}
|
|
|
|
|
const float length = std::sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]);
|
|
|
|
|
if (length <= 0.0f || rate == 0.0f) return NiPoint3Constant::ZERO;
|
|
|
|
|
for (auto& part : q) part /= length;
|
|
|
|
|
const float axisLength = std::sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2]);
|
|
|
|
|
if (!(axisLength > std::numeric_limits<float>::epsilon())) return NiPoint3Constant::ZERO;
|
|
|
|
|
const float angle = 2.0f * std::acos(std::min(std::abs(q[3]), 1.0f));
|
|
|
|
|
const float scale = (q[3] < 0.0f ? -1.0f : 1.0f) / axisLength * angle * (1.0f / (rate * 0.5f));
|
|
|
|
|
return NiPoint3(q[0] * scale, q[1] * scale, q[2] * scale);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// LWOPlatform::RunPlatform 0x00c86e10 for a simple mover waiting at its waypoint: once the wait is over it sets off for
|
|
|
|
|
// its other end (LWOPlatform::IncrementWaitingTime 0x00bd4370, StartTravelling 0x0058b170). A quick build's does not
|
|
|
|
|
// run until it is built (LWOPlatform::SendMessage 0x00bdc930). Live: a built counterweight was serialized waiting (9)
|
|
|
|
|
// and about 0.1 s later travelling (2).
|
|
|
|
|
void MovingPlatformComponent::RunSimpleMover(const float deltaTime) {
|
|
|
|
|
auto* const simpleMover = GetSimpleMoverSubComponent();
|
|
|
|
|
if (!UpdateActive(*simpleMover)) return;
|
|
|
|
|
if ((simpleMover->mState & ePlatformStateFlag::Waiting) == 0 || !simpleMover->mWaitSet) return;
|
|
|
|
|
simpleMover->mIdleTimeElapsed += deltaTime;
|
|
|
|
|
if (simpleMover->mIdleTimeElapsed < simpleMover->mTimeToWait) return;
|
|
|
|
|
simpleMover->mIdleTimeElapsed = 0.0f;
|
|
|
|
|
SimpleMoverGotoWaypoint(simpleMover->mCurrentWaypointIndex == 0 ? 1 : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// LWOPlatform::RunPlatform 0x00c86e10 for a rotator: its wait never ends (IncrementWaitingTime 0x004a0390) and it never
|
|
|
|
|
// arrives (HandleStoppedLogic 0x00bdc660 keeps the object's angular velocity at the rotator's); it has no linear
|
|
|
|
|
// velocity (SetLinearVelocity 0x00bd1660). The client's physics turn the object at that velocity; the server turns its
|
|
|
|
|
// object here, without a serialization of its physics, as a mover's.
|
|
|
|
|
void MovingPlatformComponent::RunRotator(const float deltaTime) {
|
|
|
|
|
auto* const rotator = static_cast<RotatorSubComponent*>(GetMoverSubComponent());
|
|
|
|
|
if (!rotator || m_Path == nullptr || m_Path->pathWaypoints.empty()) return;
|
|
|
|
|
|
|
|
|
|
auto rotation = m_Parent->GetRotation();
|
|
|
|
|
bool moved = false;
|
|
|
|
|
if (!rotator->mPlaced) {
|
|
|
|
|
// LWOPlatform::ProcessStateChange 0x00cce380 from SetupPath: the object is put at its waypoint
|
|
|
|
|
rotator->mPlaced = true;
|
|
|
|
|
rotation = m_Path->pathWaypoints[rotator->mCurrentWaypointIndex].rotation;
|
|
|
|
|
moved = true;
|
|
|
|
|
}
|
|
|
|
|
if (UpdateActive(*rotator) && (rotator->mState & ePlatformStateFlag::Travelling) != 0) {
|
|
|
|
|
const auto velocity = rotator->GetAngularVelocity();
|
|
|
|
|
const float speed = velocity.Length();
|
|
|
|
|
if (speed > 0.0f && std::isfinite(speed)) {
|
|
|
|
|
const glm::vec3 axis(velocity.x / speed, velocity.y / speed, velocity.z / speed);
|
|
|
|
|
rotation = glm::normalize(glm::angleAxis(speed * deltaTime, axis) * rotation);
|
|
|
|
|
moved = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!moved) return;
|
|
|
|
|
if (auto* const simplePhysics = m_Parent->GetComponent<SimplePhysicsComponent>()) {
|
|
|
|
|
simplePhysics->SetPositionAndRotationIgnoringDirtyFlags(rotator->mPosition, rotation);
|
|
|
|
|
}
|
|
|
|
|
if (auto* const phantomPhysics = m_Parent->GetComponent<PhantomPhysicsComponent>()) {
|
|
|
|
|
phantomPhysics->SetPositionAndRotationIgnoringDirtyFlags(rotator->mPosition, rotation);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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 (m_MoverSubComponentType == eMoverSubComponentType::rotater) {
|
|
|
|
|
RunRotator(deltaTime);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (m_MoverSubComponentType == eMoverSubComponentType::simpleMover) {
|
|
|
|
|
RunSimpleMover(deltaTime);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!IsMover()) return;
|
|
|
|
|
auto* mover = GetMoverSubComponent();
|
|
|
|
|
UpdateActive(*mover);
|
|
|
|
|
if (!mover->mActive) {
|
|
|
|
|
// RebuildNotifyState: an open quick build's platform loses its velocities
|
|
|
|
|
mover->mVelocity = NiPoint3Constant::ZERO;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (mover->mState == 0) return;
|
|
|
|
|
|
|
|
|
|
const bool travelling = (mover->mState & ePlatformStateFlag::Travelling) != 0;
|
|
|
|
|
if (mover->mTimeBased && travelling) mover->mMoveTimeElapsed += deltaTime;
|
|
|
|
|
// The object's physics: it goes at its velocity, travelling or not
|
|
|
|
|
mover->mPosition = mover->mPosition + mover->mVelocity * deltaTime;
|
|
|
|
|
|
|
|
|
|
if (mover->mTimeBased) {
|
|
|
|
|
// LWOPlatform::TimeBasedCalculatePercentToNextWaypoint 0x00bd4090: mCurrentSpeed is the seconds to the next waypoint
|
|
|
|
|
mover->mMoveTimeElapsed = std::min(mover->mMoveTimeElapsed, mover->mCurrentSpeed);
|
|
|
|
|
mover->mPercentBetweenPoints = mover->mCurrentSpeed > 0.0f ? mover->mMoveTimeElapsed / mover->mCurrentSpeed : 1.0f;
|
|
|
|
|
} else {
|
|
|
|
|
// LWOPlatform::CalculatePercentTravelledToWaypoint 0x00be9050: how far the object is from the current waypoint,
|
|
|
|
|
// over the way to the next (live sent 1.219 for a dragon that far past its waypoint)
|
|
|
|
|
const auto& from = m_Path->pathWaypoints[mover->mCurrentWaypointIndex].position;
|
|
|
|
|
mover->mPercentBetweenPoints = mover->mSegmentLength > 0.0f ? Vector3::Distance(from, mover->mPosition) / mover->mSegmentLength : 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MoveObject();
|
|
|
|
|
|
|
|
|
|
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 || mover->mSegmentLength > 0.0f)) {
|
|
|
|
|
// LWOPlatform::HandleStoppedLogic 0x00bd16a0: a platform that has not stopped looks whether it arrived, also while
|
|
|
|
|
// it waits. Live's FV dragons, going on as they came through the 5 s wait at their waypoint 4, were at waypoint 5
|
|
|
|
|
// (waiting there, then going on in the direction they came to 4 in) without ever having left 4. Where two
|
|
|
|
|
// waypoints are in one place the client arrives every frame of the wait; here only a travelling one arrives there.
|
|
|
|
|
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)) {
|
|
|
|
|
MoverUpdateVelocities();
|
|
|
|
|
// Live serialized a platform leaving its waypoint, where it then was: as far past the waypoint as the wait took it
|
|
|
|
|
if (doneWaiting) Game::entityManager->SerializeEntity(m_Parent);
|
|
|
|
|
}
|
|
|
|
|
if (IsMover()) MoveObject();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MovingPlatformComponent::FillResync(GameMessages::PlatformResync& resync) const {
|
|
|
|
|
@@ -535,7 +860,10 @@ 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);
|
|
|
|
|
mover->mVelocity = NiPoint3Constant::ZERO;
|
|
|
|
|
|
|
|
|
|
m_Parent->SetPosition(waypoint.position);
|
|
|
|
|
m_Parent->SetRotation(waypoint.rotation);
|
|
|
|
|
@@ -582,13 +910,19 @@ void MovingPlatformComponent::OnSimpleMoverArrived(const int32_t index) {
|
|
|
|
|
auto* const simpleMover = GetSimpleMoverSubComponent();
|
|
|
|
|
if (!simpleMover) return;
|
|
|
|
|
|
|
|
|
|
// LWOPlatform::ArrivedAtWaypoint: both ends are the path's ends, and a path run once stops there
|
|
|
|
|
// LWOPlatform::ArrivedAtWaypoint: both ends are the path's ends, and a path run once stops there (28) and turns
|
|
|
|
|
// round. Live did not serialize it (each client's simple mover arrives by itself), and the object is moved ignoring
|
|
|
|
|
// the dirty flags (ProcessStateChange 0x00cce380).
|
|
|
|
|
simpleMover->mCurrentWaypointIndex = index;
|
|
|
|
|
simpleMover->mState = ePlatformStateFlag::Stopped | ePlatformStateFlag::ReachedDesiredWaypoint | ePlatformStateFlag::ReachedFinalDestination;
|
|
|
|
|
simpleMover->mInReverse = index == 1;
|
|
|
|
|
simpleMover->mDirtyState = true;
|
|
|
|
|
m_Parent->SetPosition(simpleMover->GetWaypointPosition(index));
|
|
|
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
|
|
|
|
const auto position = simpleMover->GetWaypointPosition(index);
|
|
|
|
|
if (auto* const simplePhysics = m_Parent->GetComponent<SimplePhysicsComponent>()) {
|
|
|
|
|
simplePhysics->SetPositionAndRotationIgnoringDirtyFlags(position, simpleMover->mStartRotation);
|
|
|
|
|
}
|
|
|
|
|
if (auto* const phantomPhysics = m_Parent->GetComponent<PhantomPhysicsComponent>()) {
|
|
|
|
|
phantomPhysics->SetPositionAndRotationIgnoringDirtyFlags(position, simpleMover->mStartRotation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FireArrivalHooks(index, true, index == 1);
|
|
|
|
|
}
|
|
|
|
|
@@ -599,7 +933,16 @@ void MovingPlatformComponent::FireArrivalHooks(const uint32_t index, const bool
|
|
|
|
|
auto* const script = m_Parent->GetScript();
|
|
|
|
|
script->OnWaypointReached(m_Parent, index);
|
|
|
|
|
if (atDesiredWaypoint) script->OnArrivedAtDesiredWaypoint(m_Parent, index);
|
|
|
|
|
if (atLastWaypoint) script->OnPlatformAtLastWaypoint(m_Parent);
|
|
|
|
|
if (atLastWaypoint) {
|
|
|
|
|
script->OnPlatformAtLastWaypoint(m_Parent);
|
|
|
|
|
// A callback may add another
|
|
|
|
|
const auto callbacks = m_AtLastWaypointCallbacks;
|
|
|
|
|
for (const auto& callback : callbacks) callback();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MovingPlatformComponent::AddPlatformAtLastWaypointCallback(const std::function<void()>& callback) {
|
|
|
|
|
m_AtLastWaypointCallbacks.push_back(callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MovingPlatformComponent::Allocator(Entity& entity, ObjectLoadState& state) {
|
|
|
|
|
|