mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
Merge exp/platforms-5: simple movers and rotators run as platforms, resync answers, pathless movers
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -23,7 +23,7 @@
|
||||
|
||||
struct ObjectLoadState;
|
||||
|
||||
class Path;
|
||||
struct Path;
|
||||
namespace GameMessages { struct PlatformResync; }
|
||||
|
||||
/**
|
||||
@@ -49,7 +49,7 @@ enum class eMoverSubComponentType : uint32_t {
|
||||
};
|
||||
|
||||
/**
|
||||
* The client's platform state flags (LWOPlatform), as live sent them: a platform that was never started is stopped at
|
||||
* The client's platform state flags, 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.
|
||||
*/
|
||||
@@ -59,24 +59,24 @@ namespace ePlatformStateFlag {
|
||||
constexpr uint32_t Stopped = 4;
|
||||
constexpr uint32_t ReachedDesiredWaypoint = 8;
|
||||
constexpr uint32_t ReachedFinalDestination = 16;
|
||||
// What LWOPlatform::UpdateVelocities keeps when the platform sets off (it drops the two "reached" bits)
|
||||
// What a platform keeps when it sets off (it drops the two "reached" bits)
|
||||
constexpr uint32_t MovementMask = Waiting | Travelling | Stopped;
|
||||
};
|
||||
|
||||
/**
|
||||
* How the client picks the subcomponents (LWOMovingPlatformComponent::LoadConfigData and SetupPlatform): one for each
|
||||
* How the client picks the subcomponents: one for each
|
||||
* of the platformIsMover, platformIsSimpleMover and platformIsRotater settings that is true, in that order, and when
|
||||
* none is set a mover for a platform with no registry component (set up from its attached path) or a simple mover for
|
||||
* one with a registry component.
|
||||
*/
|
||||
std::vector<eMoverSubComponentType> ChooseSubComponentTypes(int32_t componentID, const Entity& entity);
|
||||
|
||||
// The first of ChooseSubComponentTypes (none when there are none): the one the server runs
|
||||
// The first of ChooseSubComponentTypes (none when there are none)
|
||||
eMoverSubComponentType ChooseMoverSubComponentType(int32_t componentID, const Entity& entity);
|
||||
|
||||
/**
|
||||
* The base of the platform subcomponents, as the client's LWOPlatform (mover, simple mover and rotator are built on
|
||||
* it): the platform's state between the waypoints of its path, which LWOPlatform::Deserialize reads.
|
||||
* The base of the platform subcomponents, as the client's (mover, simple mover and rotator are built on it): the
|
||||
* platform's state between the waypoints of its path.
|
||||
*/
|
||||
class PlatformSubComponent {
|
||||
public:
|
||||
@@ -84,10 +84,12 @@ public:
|
||||
|
||||
virtual eMoverSubComponentType GetType() const = 0;
|
||||
|
||||
// LWOPlatform::Deserialize: a dirty bit, the state, desired waypoint, whether to stop there, reverse, the
|
||||
// percent between the waypoints, where it is, the current and next waypoints, the time waited and the time travelled
|
||||
// A dirty bit, the state, desired waypoint, whether to stop there, reverse, the percent between the waypoints,
|
||||
// where it is, the current and next waypoints, the time waited and the time travelled
|
||||
virtual void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate);
|
||||
|
||||
// The path it runs on: the object's attached path, or a simple mover's own between its two ends
|
||||
const Path* mPath = nullptr;
|
||||
// ePlatformStateFlag bits
|
||||
uint32_t mState = ePlatformStateFlag::Stopped | ePlatformStateFlag::ReachedDesiredWaypoint;
|
||||
int32_t mDesiredWaypointIndex = -1;
|
||||
@@ -95,23 +97,22 @@ public:
|
||||
bool mShouldStopAtDesiredWaypoint = false;
|
||||
// From the current waypoint (0) to the next (1)
|
||||
float mPercentBetweenPoints = 0;
|
||||
// Where it is now: its object's position, which its linear velocity moves
|
||||
// Where it is now: its object's position, which its linear velocity moves. Nowhere (0, 0, 0) without a path.
|
||||
NiPoint3 mPosition{};
|
||||
// The linear velocity LWOPlatform::SetLinearVelocity gave its object when it last set off (or last looked,
|
||||
// between waypoints of different speeds). It is only taken away where the platform stops and at either end of the
|
||||
// path (SetWaitingTime), so through a wait at a waypoint in between the object goes on as it came.
|
||||
// The linear velocity the platform gave its object when it last set off (or last looked, between waypoints of
|
||||
// different speeds). It is only taken away where the platform stops and at either end of the path, so through a
|
||||
// wait at a waypoint in between the object goes on as it came.
|
||||
NiPoint3 mVelocity{};
|
||||
uint32_t mCurrentWaypointIndex = 0;
|
||||
uint32_t mNextWaypointIndex = 0;
|
||||
// Time spent at the waypoint, and how long it waits there (LWOPlatform::SetWaitingTime: the waypoint's
|
||||
// wait, at least 0.1 s); the wait only counts once it was set
|
||||
// Time spent at the waypoint, and how long it waits there (the waypoint's wait, at least 0.1 s); the wait only
|
||||
// counts once it was set
|
||||
float mIdleTimeElapsed = 0;
|
||||
float mTimeToWait = 0;
|
||||
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, RebuildNotifyState)
|
||||
bool mActive = true;
|
||||
// Time travelled since the current waypoint (time based paths only)
|
||||
float mMoveTimeElapsed = 0;
|
||||
@@ -124,62 +125,58 @@ 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 (RunPlatform, ArrivedAtWaypoint, HandleWaypointArrived,
|
||||
* ResumeTravelling, ProcessStateChange, GetNextWaypoint / GetNextReversedWaypoint
|
||||
* the speeds of GetWaypointSpeed). Live serialized it when it began waiting at a waypoint and
|
||||
* when it left one, not when it stopped (the client stops by itself).
|
||||
* A mover along its path (4), run by the server as live ran it, with the client's platform logic: it waits at a
|
||||
* waypoint, travels to the next, arrives, and stops or turns round as the path and what it was sent to do say. 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:
|
||||
MoverSubComponent(const NiPoint3& startPos) { mPosition = startPos; }
|
||||
eMoverSubComponentType GetType() const override { return eMoverSubComponentType::mover; }
|
||||
};
|
||||
|
||||
/**
|
||||
* The angular velocity of a rotator, as the client's LWOPlatformRotator::SetAngularVelocity works it out:
|
||||
* the rotation NiMatrix3::FromEulerAnglesXYZ makes of the three angles (radians; the matrix about x times
|
||||
* the one about y times the one about z, each turning the other way round than the usual right-handed one), as a
|
||||
* quaternion (NiQuaternion::FromRotation), and the velocity that turns from no rotation to it (from it to none in
|
||||
* reverse) in half the rate, by the shortest way (hkpKeyFrameUtility::KeyFrameInfo::setUsingPositionOrientationPair
|
||||
* the axis times the angle, at most half a turn, over the time). Angles that add up to whole turns give
|
||||
* no velocity. The client divides by a rate of 0; here that gives none.
|
||||
* The angular velocity of a rotator, as the client works it out: the rotation made of the three angles (radians; the
|
||||
* matrix about x times the one about y times the one about z, each turning the other way round than the usual
|
||||
* right-handed one), as a quaternion, and the velocity that turns from no rotation to it (from it to none in reverse)
|
||||
* in half the rate, by the shortest way (the axis times the angle, at most half a turn, over the time). Angles that
|
||||
* add up to whole turns give no velocity. The client divides by a rate of 0; here that gives none.
|
||||
*/
|
||||
NiPoint3 CalcRotatorAngularVelocity(float rotX, float rotY, float rotZ, float rate, bool reverse);
|
||||
|
||||
/**
|
||||
* A rotator (6), as the client's LWOPlatformRotator: on its path it does not move, it turns at its angular velocity
|
||||
* while travelling (rotX/rotY/rotZ in half turns, at rate), and never waits or arrives (IncrementWaitingTime
|
||||
* HandleStoppedLogic); it sends the LWOPlatform data a mover sends.
|
||||
* A rotator (6), as the client's: on its path it does not move, it turns at its angular velocity while travelling
|
||||
* (rotX/rotY/rotZ in half turns, at rate), and never waits or arrives; it sends the data a mover sends.
|
||||
*/
|
||||
class RotatorSubComponent final : public PlatformSubComponent {
|
||||
public:
|
||||
RotatorSubComponent(const NiPoint3& startPos) { mPosition = startPos; }
|
||||
eMoverSubComponentType GetType() const override { return eMoverSubComponentType::rotater; }
|
||||
|
||||
// LWOPlatformRotator::LoadConfigData: rotX, rotY and rotZ times pi, and rate (seconds)
|
||||
// rotX, rotY and rotZ times pi, and rate (seconds)
|
||||
float mRotationX = 0.0f;
|
||||
float mRotationY = 0.0f;
|
||||
float mRotationZ = 0.0f;
|
||||
float mRate = 0.0f;
|
||||
// Whether its object was put at its waypoint (LWOPlatform::ProcessStateChange, from SetupPath)
|
||||
// Whether its object was put at its waypoint
|
||||
bool mPlaced = false;
|
||||
|
||||
NiPoint3 GetAngularVelocity() const { return CalcRotatorAngularVelocity(mRotationX, mRotationY, mRotationZ, mRate, mInReverse); }
|
||||
};
|
||||
|
||||
/**
|
||||
* 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. At an end it has stopped there (28), as any platform on a path run once. Like a mover it is made
|
||||
* stopped at its waypoint (12) and, unless startPathingOnLoad is false, waits there (9, as live constructed the NJ
|
||||
* counterweights) the shortest wait before it sets off for its other end, a quick build's once it is built.
|
||||
* A simple mover (5), as the client's: a platform on a path of its own, run once, between a start point and that
|
||||
* point moved by platformMove (in the start rotation), which takes it platformMoveTime seconds. At an end it has
|
||||
* stopped there (28), as any platform on a path run once. Like a mover it is made stopped at its waypoint (12) and,
|
||||
* unless startPathingOnLoad is false, waits there (9, as live constructed the NJ counterweights) the shortest wait
|
||||
* before it sets off for its other end, a quick build's once it is built.
|
||||
*/
|
||||
class SimpleMoverSubComponent final : public PlatformSubComponent {
|
||||
public:
|
||||
SimpleMoverSubComponent();
|
||||
~SimpleMoverSubComponent() override;
|
||||
eMoverSubComponentType GetType() const override { return eMoverSubComponentType::simpleMover; }
|
||||
|
||||
// LWOPlatformSimpleMover::Deserialize: a dirty bit, then whether there is a starting point with its position and
|
||||
// A dirty bit, then whether there is a starting point with its position and
|
||||
// rotation (w, x, y, z); a dirty bit, then the state, the current waypoint and whether it is reversing
|
||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
@@ -196,6 +193,14 @@ public:
|
||||
* The world position of a waypoint (0 the start, 1 the end)
|
||||
*/
|
||||
NiPoint3 GetWaypointPosition(int32_t index) const;
|
||||
|
||||
/**
|
||||
* Builds its path from the start point, platformMove and platformMoveTime
|
||||
*/
|
||||
void GeneratePath();
|
||||
|
||||
private:
|
||||
std::unique_ptr<Path> mOwnPath;
|
||||
};
|
||||
|
||||
|
||||
@@ -291,12 +296,17 @@ public:
|
||||
size_t GetLastWaypointIndex() const;
|
||||
|
||||
/**
|
||||
* The mover or rotator the server runs (the first subcomponent), if it is one
|
||||
* The subcomponent of a type, if the platform has one
|
||||
*/
|
||||
PlatformSubComponent* GetSubComponent(eMoverSubComponentType type) const;
|
||||
|
||||
/**
|
||||
* The mover, or without one the rotator, if the platform has one
|
||||
*/
|
||||
PlatformSubComponent* GetMoverSubComponent() const;
|
||||
|
||||
/**
|
||||
* Returns the simple mover sub component, if this platform is a simple mover
|
||||
* The simple mover, if the platform has one
|
||||
*/
|
||||
SimpleMoverSubComponent* GetSimpleMoverSubComponent() const;
|
||||
|
||||
@@ -308,12 +318,6 @@ public:
|
||||
*/
|
||||
void AddPlatformAtLastWaypointCallback(const std::function<void()>& callback);
|
||||
|
||||
/**
|
||||
* Called when a simple mover gets to the waypoint it was sent to: the client's LWOPlatform::ArrivedAtWaypoint
|
||||
* and HandleWaypointArrived (Arrived, then ArrivedAtDesiredWaypoint and PlatformAtLastWaypoint)
|
||||
*/
|
||||
void OnSimpleMoverArrived(int32_t index);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
@@ -326,11 +330,6 @@ private:
|
||||
*/
|
||||
std::u16string m_PathName;
|
||||
|
||||
/**
|
||||
* Whether the platform has stopped pathing
|
||||
*/
|
||||
bool m_PathingStopped = false;
|
||||
|
||||
// The waypoint the path starts at (attached_path_start), written with the path
|
||||
uint32_t m_StartWaypoint = 0;
|
||||
// Whether it runs the path backwards from there (SetCurrentPath), written with the path
|
||||
@@ -339,7 +338,7 @@ private:
|
||||
bool m_DirtyPath = false;
|
||||
|
||||
/**
|
||||
* The type of the first subcomponent, the one the server runs (none without one)
|
||||
* The type of the first subcomponent (none without one)
|
||||
*/
|
||||
eMoverSubComponentType m_MoverSubComponentType = eMoverSubComponentType::none;
|
||||
|
||||
@@ -354,47 +353,56 @@ private:
|
||||
class QuickBuildComponent* m_QuickBuild = nullptr;
|
||||
bool m_CheckedQuickBuild = false;
|
||||
|
||||
/**
|
||||
* Counts sends so an arrival timer from an older send does nothing
|
||||
*/
|
||||
uint32_t m_MoveGeneration = 0;
|
||||
|
||||
void SimpleMoverGotoWaypoint(int32_t index);
|
||||
// Counts the times the platforms were made anew (SetCurrentPath), so what was running one of before stops
|
||||
uint32_t m_SetupGeneration = 0;
|
||||
|
||||
void FireArrivalHooks(uint32_t index, bool atDesiredWaypoint, bool atLastWaypoint);
|
||||
|
||||
// LWOPlatform::ProcessStateChange: index becomes the current waypoint (the next from the path's behavior and direction)
|
||||
void MoverProcessStateChange(uint32_t index);
|
||||
// Whether the platform starts by itself (startPathingOnLoad, true unless set false)
|
||||
bool StartsOnLoad() const;
|
||||
// A simple mover's settings from the level config, its path, and where it is on it
|
||||
void SetupSimpleMover(SimpleMoverSubComponent& simpleMover);
|
||||
// The mover at its starting waypoint on the path, started unless startPathingOnLoad is false
|
||||
void SetupMoverPath();
|
||||
// Puts the object where the mover is, without a serialization of its physics
|
||||
void MoveObject();
|
||||
// A simple mover's wait at its waypoint before it sets off by itself
|
||||
void RunSimpleMover(float deltaTime);
|
||||
void SetupMoverPath(PlatformSubComponent& mover);
|
||||
// A rotator's settings from the level config, and where it is on its path
|
||||
void SetupRotator();
|
||||
void SetupRotator(RotatorSubComponent& rotator);
|
||||
// Serializes the object with the platform's state
|
||||
void SerializePlatform(PlatformSubComponent& platform);
|
||||
// Index becomes the platform's current waypoint (the next from the path's behavior and direction)
|
||||
void PlatformProcessStateChange(PlatformSubComponent& platform, uint32_t index);
|
||||
// Starts a wait of at least 0.1 s
|
||||
void PlatformSetWaitingTime(PlatformSubComponent& platform, float waitTime, float idleTimeElapsed);
|
||||
// The velocity towards the next waypoint at the speed for where it is
|
||||
void PlatformUpdateVelocities(PlatformSubComponent& platform);
|
||||
// Stopped between two waypoints it travels on; at a waypoint it first waits there
|
||||
void PlatformResumeTravelling(PlatformSubComponent& platform, bool force);
|
||||
// Once it is at its next waypoint
|
||||
bool PlatformArrivedAtWaypoint(PlatformSubComponent& platform);
|
||||
// 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);
|
||||
// Puts the object where the platform is, without a serialization of its physics
|
||||
void MoveObject(const PlatformSubComponent& platform, bool atWaypoint = false);
|
||||
void SetObjectTransform(const NiPoint3& position, const NiQuaternion& rotation);
|
||||
// A platform (mover or simple mover) on its path
|
||||
bool RunPlatform(PlatformSubComponent& platform, float deltaTime);
|
||||
// Turns a travelling rotator's object by its angular velocity
|
||||
void RunRotator(float deltaTime);
|
||||
// LWOPlatform::SetupPath and SendMessage (RebuildNotifyState): whether the platform of a quick build runs yet
|
||||
bool UpdateActive(PlatformSubComponent& platform);
|
||||
// LWOPlatform::SetWaitingTime: starts a wait of at least 0.1 s
|
||||
void MoverSetWaitingTime(float waitTime, float idleTimeElapsed);
|
||||
// LWOPlatform::UpdateVelocities: the velocity towards the next waypoint at the speed for where it is
|
||||
void MoverUpdateVelocities();
|
||||
// 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);
|
||||
void RunRotator(RotatorSubComponent& rotator, float deltaTime);
|
||||
// Whether the platforms of a quick build run yet
|
||||
void UpdateActive();
|
||||
|
||||
public:
|
||||
void Run(float deltaTime) override;
|
||||
|
||||
// The mover's state as a PlatformResync gives it (RequestPlatformResync)
|
||||
void FillResync(GameMessages::PlatformResync& resync) const;
|
||||
// The platform's state as a PlatformResync gives it (the answer to RequestPlatformResync); false without a platform
|
||||
bool FillResync(GameMessages::PlatformResync& resync) const;
|
||||
|
||||
// A mover on a path, run by the server (a rotater only spins: no waypoints)
|
||||
// Whether the platform has a mover on a path
|
||||
bool IsMover() const;
|
||||
|
||||
// Whether the platform follows a path (its attached_path); a simple mover without one has no waypoints
|
||||
|
||||
@@ -66,10 +66,10 @@ namespace GameMessages {
|
||||
const bool hasRotation = qUnexpectedRotation != QuatUtils::IDENTITY;
|
||||
bitStream.Write(hasRotation);
|
||||
if (hasRotation) {
|
||||
bitStream.Write(qUnexpectedRotation.w);
|
||||
bitStream.Write(qUnexpectedRotation.x);
|
||||
bitStream.Write(qUnexpectedRotation.y);
|
||||
bitStream.Write(qUnexpectedRotation.z);
|
||||
bitStream.Write(qUnexpectedRotation.w);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,26 +92,25 @@ namespace GameMessages {
|
||||
VALIDATE_READ(bitStream.Read(hasRotation));
|
||||
qUnexpectedRotation = QuatUtils::IDENTITY;
|
||||
if (hasRotation) {
|
||||
VALIDATE_READ(bitStream.Read(qUnexpectedRotation.w));
|
||||
VALIDATE_READ(bitStream.Read(qUnexpectedRotation.x));
|
||||
VALIDATE_READ(bitStream.Read(qUnexpectedRotation.y));
|
||||
VALIDATE_READ(bitStream.Read(qUnexpectedRotation.z));
|
||||
VALIDATE_READ(bitStream.Read(qUnexpectedRotation.w));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RequestPlatformResync::Handle(Entity& entity, const SystemAddress& sysAddr) {
|
||||
// A mover answers with where the server has it (live: travelling 2 with its percent and position, or waiting at
|
||||
// a waypoint with the time waited)
|
||||
// The client asks once for each platform of an object whose physics are ready, and live answered every one: a
|
||||
// mover with where it was (travelling 2 with its percent and position, or waiting at a waypoint), a NJ
|
||||
// counterweight (a simple mover) waiting at its start, and a mover without a path waiting at waypoint 0 of none.
|
||||
// The client's simple mover takes its waypoints from the answer and is put at the first; a mover without a
|
||||
// path does nothing with it.
|
||||
auto* const platform = entity.GetComponent<MovingPlatformComponent>();
|
||||
if (!platform || !platform->IsMover()) {
|
||||
// Nothing else has waypoints to resync to: the client's simple mover reads them from its own two point path
|
||||
// (LWOPlatformSimpleMover::Resync, a crash without one) and would set off on a travelling state
|
||||
return;
|
||||
}
|
||||
if (!platform) return;
|
||||
PlatformResync resync;
|
||||
resync.target = entity.GetObjectID();
|
||||
platform->FillResync(resync);
|
||||
if (!platform->FillResync(resync)) return;
|
||||
resync.Send(sysAddr);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,8 @@ namespace GameMessages {
|
||||
int32_t iIndex{ 0 };
|
||||
int32_t iNextIndex{ 1 };
|
||||
NiPoint3 ptUnexpectedLocation{ NiPoint3Constant::ZERO };
|
||||
// optional (default identity), written x, y, z, w
|
||||
// optional (default identity), written w, x, y, z: the order the client reads and live sent (a NJ counterweight's
|
||||
// resync began with its w, 0.936)
|
||||
NiQuaternion qUnexpectedRotation{ QuatUtils::IDENTITY };
|
||||
};
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ protected:
|
||||
void TearDown() override { TearDownDependencies(); }
|
||||
};
|
||||
|
||||
// LWOMovingPlatformComponent::LoadConfigData: no setting means a mover without a registry component, a simple mover
|
||||
// How the client chooses: no setting means a mover without a registry component, a simple mover
|
||||
// with one; the settings choose otherwise
|
||||
TEST_F(MovingPlatformComponentTest, SubcomponentTypeFromLevelConfig) {
|
||||
Entity pathOnly(288300744895900100, info);
|
||||
@@ -80,7 +80,7 @@ TEST_F(MovingPlatformComponentTest, SubcomponentTypeFromLevelConfig) {
|
||||
info.settings.values.clear();
|
||||
}
|
||||
|
||||
// LWOMovingPlatformComponent::SetupPlatform: one subcomponent per setting that is true, mover, simple mover, rotater
|
||||
// The client makes one subcomponent per setting that is true, mover, simple mover, rotater
|
||||
TEST_F(MovingPlatformComponentTest, OneSubcomponentPerSetting) {
|
||||
info.settings.Insert<bool>(u"platformIsRotater", true);
|
||||
info.settings.Insert<bool>(u"platformIsMover", true);
|
||||
@@ -113,8 +113,85 @@ TEST_F(MovingPlatformComponentTest, SimpleMoverConstructionMatchesLive) {
|
||||
EXPECT_EQ(Bits(idle), "00");
|
||||
}
|
||||
|
||||
// Sent to its end it serializes travelling from waypoint 0, and after platformMoveTime it has arrived: stopped at its
|
||||
// desired and final waypoint 1, moved by platformMove
|
||||
// The client reads a simple mover's own settings first and its MovingPlatforms row after, so the row's platformMove
|
||||
// and platformMoveTime win unless the object sets dbonly false; db only, its own are not read at all. Without a row
|
||||
// dbonly means nothing and its own always count.
|
||||
TEST_F(MovingPlatformComponentTest, SimpleMoverSettingsInTheClientsOrder) {
|
||||
info.lot = 16141;
|
||||
const auto move = [this](const int32_t componentID, const LWOOBJID id) {
|
||||
Entity entity(id, info);
|
||||
auto* const platform = entity.AddComponent<MovingPlatformComponent>(componentID, "");
|
||||
const auto* const simpleMover = platform->GetSimpleMoverSubComponent();
|
||||
return simpleMover ? std::pair(simpleMover->mMove.y, simpleMover->mMoveTime) : std::pair(-1000.0f, -1000.0f);
|
||||
};
|
||||
info.settings.Insert<float>(u"platformMoveY", 5.0f);
|
||||
info.settings.Insert<float>(u"platformMoveTime", 3.0f);
|
||||
EXPECT_EQ(move(41, 288300744895900126), std::pair(-2.5f, 1.0f));
|
||||
info.settings.Insert<bool>(u"dbonly", false);
|
||||
EXPECT_EQ(move(41, 288300744895900127), std::pair(5.0f, 3.0f));
|
||||
info.settings.values.clear();
|
||||
info.settings.Insert<float>(u"platformMoveY", 5.0f);
|
||||
info.settings.Insert<float>(u"platformMoveTime", 3.0f);
|
||||
info.settings.Insert<bool>(u"dbonly", true);
|
||||
EXPECT_EQ(move(41, 288300744895900128), std::pair(-2.5f, 1.0f));
|
||||
// No row: a simple mover by its setting
|
||||
info.settings.Insert<bool>(u"platformIsSimpleMover", true);
|
||||
EXPECT_EQ(move(-1, 288300744895900129), std::pair(5.0f, 3.0f));
|
||||
info.settings.values.clear();
|
||||
}
|
||||
|
||||
// Live answered every RequestPlatformResync. A NJ counterweight (the one constructed above) got: state 9, not
|
||||
// reversing, no desired waypoint, waypoints 0 and 1, percent 0, no times, its start position and its start rotation.
|
||||
// A mover without a path got: state 9, waypoints 0 and 0, no position and no rotation.
|
||||
TEST_F(MovingPlatformComponentTest, ResyncAnswersLikeLive) {
|
||||
info.lot = 16141;
|
||||
info.pos = NiPoint3(Float(0xc2e02255), Float(0x436d1992), Float(0xc32347e8));
|
||||
info.rot = NiQuaternion(Float(0x3f6fa199), 0.0f, Float(0x3eb42497), 0.0f);
|
||||
Entity counterweight(288300744895900123, info);
|
||||
auto* const platform = counterweight.AddComponent<MovingPlatformComponent>(41, "");
|
||||
GameMessages::PlatformResync resync;
|
||||
ASSERT_TRUE(platform->FillResync(resync));
|
||||
EXPECT_EQ(static_cast<uint32_t>(resync.eState), 9u);
|
||||
EXPECT_FALSE(resync.bReverse);
|
||||
EXPECT_FALSE(resync.bStopAtDesiredWaypoint);
|
||||
EXPECT_EQ(resync.iDesiredWaypointIndex, -1);
|
||||
EXPECT_EQ(resync.iIndex, 0);
|
||||
EXPECT_EQ(resync.iNextIndex, 1);
|
||||
EXPECT_EQ(resync.fPercentBetweenPoints, 0.0f);
|
||||
EXPECT_EQ(resync.fIdleTimeElapsed, 0.0f);
|
||||
EXPECT_EQ(resync.fMoveTimeElapsed, 0.0f);
|
||||
EXPECT_EQ(resync.ptUnexpectedLocation, info.pos);
|
||||
EXPECT_EQ(resync.qUnexpectedRotation, info.rot);
|
||||
|
||||
// On its way: travelling from 0 to 1, where it is
|
||||
platform->Run(0.11f);
|
||||
platform->Run(0.5f);
|
||||
GameMessages::PlatformResync travelling;
|
||||
ASSERT_TRUE(platform->FillResync(travelling));
|
||||
EXPECT_EQ(static_cast<uint32_t>(travelling.eState), 2u);
|
||||
EXPECT_EQ(travelling.iIndex, 0);
|
||||
EXPECT_EQ(travelling.iNextIndex, 1);
|
||||
EXPECT_NEAR(travelling.fPercentBetweenPoints, 0.5f, 0.001f);
|
||||
EXPECT_NEAR(travelling.ptUnexpectedLocation.y, info.pos.y - 1.25f, 0.001f);
|
||||
|
||||
info.lot = 2349;
|
||||
info.pos = NiPoint3(10.0f, 20.0f, 30.0f);
|
||||
Entity pathless(288300744895900124, info);
|
||||
auto* const mover = pathless.AddComponent<MovingPlatformComponent>(-1, "");
|
||||
GameMessages::PlatformResync none;
|
||||
ASSERT_TRUE(mover->FillResync(none));
|
||||
EXPECT_EQ(static_cast<uint32_t>(none.eState), 9u);
|
||||
EXPECT_EQ(none.iDesiredWaypointIndex, -1);
|
||||
EXPECT_EQ(none.iIndex, 0);
|
||||
EXPECT_EQ(none.iNextIndex, 0);
|
||||
EXPECT_EQ(none.ptUnexpectedLocation, NiPoint3(0.0f, 0.0f, 0.0f));
|
||||
EXPECT_EQ(none.qUnexpectedRotation, QuatUtils::IDENTITY);
|
||||
info.rot = QuatUtils::IDENTITY;
|
||||
}
|
||||
|
||||
// A simple mover is a platform on its own two waypoint path, run once. Sent to its end it waits the shortest wait at
|
||||
// waypoint 0 (9), serializes travelling from it (2), and after platformMoveTime it has arrived: stopped at its final
|
||||
// waypoint 1 (28), moved by platformMove, and turned round
|
||||
TEST_F(MovingPlatformComponentTest, SimpleMoverTripTiming) {
|
||||
info.lot = 16141;
|
||||
info.pos = NiPoint3(10.0f, 20.0f, 30.0f);
|
||||
@@ -123,36 +200,129 @@ TEST_F(MovingPlatformComponentTest, SimpleMoverTripTiming) {
|
||||
counterweight.AddComponent<SimplePhysicsComponent>(-1);
|
||||
auto* const platform = counterweight.AddComponent<MovingPlatformComponent>(41, "");
|
||||
auto* const mover = platform->GetSimpleMoverSubComponent();
|
||||
ASSERT_NE(mover->mPath, nullptr);
|
||||
ASSERT_EQ(mover->mPath->pathWaypoints.size(), 2u);
|
||||
EXPECT_EQ(mover->mPath->pathBehavior, PathBehavior::Once);
|
||||
EXPECT_EQ(mover->mPath->pathWaypoints[1].position, NiPoint3(10.0f, 17.5f, 30.0f));
|
||||
EXPECT_FLOAT_EQ(mover->mPath->pathWaypoints[0].speed, 2.5f);
|
||||
|
||||
platform->GotoWaypoint(1);
|
||||
counterweight.Update(0.0f); // timers added now start on the next update
|
||||
EXPECT_EQ(mover->mState, ePlatformStateFlag::Travelling);
|
||||
EXPECT_EQ(mover->mCurrentWaypointIndex, 0);
|
||||
EXPECT_FALSE(mover->mInReverse);
|
||||
EXPECT_EQ(mover->mState, 9u);
|
||||
EXPECT_EQ(mover->mDesiredWaypointIndex, 1);
|
||||
RakNet::BitStream waiting;
|
||||
platform->Serialize(waiting, false);
|
||||
// 1, not dirty, 1, type 5, no starting point, the state: waiting at 0 forwards, then the ending 0
|
||||
EXPECT_EQ(Bits(waiting), "101" "00000101000000000000000000000000" "0" "1" "00001001000000000000000000000000" "00000000000000000000000000000000" "0" "0");
|
||||
|
||||
platform->Run(0.11f);
|
||||
EXPECT_EQ(mover->mState, ePlatformStateFlag::Travelling);
|
||||
EXPECT_EQ(mover->mCurrentWaypointIndex, 0u);
|
||||
EXPECT_FALSE(mover->mInReverse);
|
||||
RakNet::BitStream sent;
|
||||
platform->Serialize(sent, false);
|
||||
// 1, not dirty, 1, type 5, no starting point, the state: travelling from 0 forwards, then the ending 0
|
||||
EXPECT_EQ(Bits(sent), "101" "00000101000000000000000000000000" "0" "1" "00000010000000000000000000000000" "00000000000000000000000000000000" "0" "0");
|
||||
|
||||
counterweight.Update(0.5f);
|
||||
platform->Run(0.5f);
|
||||
EXPECT_EQ(mover->mState, ePlatformStateFlag::Travelling);
|
||||
counterweight.Update(0.6f);
|
||||
EXPECT_NEAR(counterweight.GetPosition().y, 18.75f, 0.001f);
|
||||
EXPECT_NEAR(mover->mPercentBetweenPoints, 0.5f, 0.001f);
|
||||
platform->Run(0.6f);
|
||||
EXPECT_EQ(mover->mState, ePlatformStateFlag::Stopped | ePlatformStateFlag::ReachedDesiredWaypoint | ePlatformStateFlag::ReachedFinalDestination);
|
||||
EXPECT_EQ(mover->mCurrentWaypointIndex, 1);
|
||||
EXPECT_EQ(counterweight.GetPosition(), NiPoint3(10.0f, 17.5f, 30.0f));
|
||||
|
||||
// And back
|
||||
platform->GotoWaypoint(0);
|
||||
counterweight.Update(0.0f);
|
||||
EXPECT_EQ(mover->mCurrentWaypointIndex, 1);
|
||||
EXPECT_EQ(mover->mCurrentWaypointIndex, 1u);
|
||||
EXPECT_EQ(mover->mNextWaypointIndex, 0u);
|
||||
EXPECT_TRUE(mover->mInReverse);
|
||||
counterweight.Update(1.1f);
|
||||
EXPECT_EQ(mover->mCurrentWaypointIndex, 0);
|
||||
EXPECT_EQ(mover->mDesiredWaypointIndex, -1);
|
||||
EXPECT_EQ(counterweight.GetPosition(), NiPoint3(10.0f, 17.5f, 30.0f));
|
||||
// Stopped there it was not serialized: each client's arrives by itself
|
||||
RakNet::BitStream arrived;
|
||||
platform->Serialize(arrived, false);
|
||||
EXPECT_EQ(Bits(arrived), "00");
|
||||
|
||||
// And back: it waits at its end (25), reversed
|
||||
platform->GotoWaypoint(0);
|
||||
EXPECT_EQ(mover->mState, 25u);
|
||||
EXPECT_EQ(mover->mCurrentWaypointIndex, 1u);
|
||||
EXPECT_TRUE(mover->mInReverse);
|
||||
platform->Run(0.11f);
|
||||
EXPECT_EQ(mover->mState, 2u);
|
||||
platform->Run(1.1f);
|
||||
EXPECT_EQ(mover->mState, 28u);
|
||||
EXPECT_EQ(mover->mCurrentWaypointIndex, 0u);
|
||||
EXPECT_FALSE(mover->mInReverse);
|
||||
EXPECT_EQ(counterweight.GetPosition(), NiPoint3(10.0f, 20.0f, 30.0f));
|
||||
}
|
||||
|
||||
// A rotater's subcomponent is type 6 with a mover's data (LWOPlatform::Deserialize reads both)
|
||||
// The client's simple mover only turns at a waypoint. Sent back while on its way it goes on to the end it was heading
|
||||
// for, stops there, and then sets off for the waypoint it was sent to. Stopped on its way it stops at that end.
|
||||
TEST_F(MovingPlatformComponentTest, SimpleMoverOnlyTurnsAtAWaypoint) {
|
||||
info.lot = 16141;
|
||||
info.pos = NiPoint3(10.0f, 20.0f, 30.0f);
|
||||
info.rot = QuatUtils::IDENTITY;
|
||||
info.settings.Insert<bool>(u"startPathingOnLoad", false);
|
||||
Entity counterweight(288300744895900120, info);
|
||||
info.settings.values.clear();
|
||||
counterweight.AddComponent<SimplePhysicsComponent>(-1);
|
||||
auto* const platform = counterweight.AddComponent<MovingPlatformComponent>(41, "");
|
||||
auto* const mover = platform->GetSimpleMoverSubComponent();
|
||||
EXPECT_EQ(mover->mState, 12u);
|
||||
|
||||
platform->GotoWaypoint(1);
|
||||
platform->Run(0.11f);
|
||||
platform->Run(0.4f);
|
||||
EXPECT_EQ(mover->mState, 2u);
|
||||
platform->GotoWaypoint(0);
|
||||
EXPECT_EQ(mover->mState, 2u);
|
||||
EXPECT_FALSE(mover->mInReverse);
|
||||
EXPECT_EQ(mover->mNextWaypointIndex, 1u);
|
||||
platform->Run(0.4f);
|
||||
EXPECT_NEAR(counterweight.GetPosition().y, 18.0f, 0.001f);
|
||||
// At its end it waits to go back
|
||||
platform->Run(0.3f);
|
||||
EXPECT_EQ(mover->mState, 25u);
|
||||
EXPECT_EQ(mover->mCurrentWaypointIndex, 1u);
|
||||
EXPECT_EQ(mover->mDesiredWaypointIndex, 0);
|
||||
platform->Run(0.11f);
|
||||
EXPECT_EQ(mover->mState, 2u);
|
||||
platform->Run(0.5f);
|
||||
// Stopped on its way: it goes on to the end it was heading for
|
||||
platform->StopPathing();
|
||||
EXPECT_EQ(mover->mState, 2u);
|
||||
platform->Run(0.6f);
|
||||
EXPECT_EQ(mover->mState, 28u);
|
||||
EXPECT_EQ(mover->mCurrentWaypointIndex, 0u);
|
||||
EXPECT_EQ(mover->mDesiredWaypointIndex, -1);
|
||||
EXPECT_EQ(counterweight.GetPosition(), NiPoint3(10.0f, 20.0f, 30.0f));
|
||||
platform->Run(1.0f);
|
||||
EXPECT_EQ(mover->mState, 28u);
|
||||
}
|
||||
|
||||
// One that starts at its end (platformStartAtEnd) is there, turned round: the client takes the direction it is
|
||||
// constructed with, and goes back from there
|
||||
TEST_F(MovingPlatformComponentTest, SimpleMoverStartsAtItsEnd) {
|
||||
info.lot = 16141;
|
||||
info.pos = NiPoint3(10.0f, 20.0f, 30.0f);
|
||||
info.rot = QuatUtils::IDENTITY;
|
||||
info.settings.Insert<bool>(u"platformStartAtEnd", true);
|
||||
Entity counterweight(288300744895900121, info);
|
||||
info.settings.values.clear();
|
||||
counterweight.AddComponent<SimplePhysicsComponent>(-1);
|
||||
auto* const platform = counterweight.AddComponent<MovingPlatformComponent>(41, "");
|
||||
auto* const mover = platform->GetSimpleMoverSubComponent();
|
||||
EXPECT_EQ(mover->mState, 9u);
|
||||
EXPECT_EQ(mover->mCurrentWaypointIndex, 1u);
|
||||
EXPECT_EQ(mover->mNextWaypointIndex, 0u);
|
||||
EXPECT_TRUE(mover->mInReverse);
|
||||
platform->Run(0.05f);
|
||||
EXPECT_EQ(counterweight.GetPosition(), NiPoint3(10.0f, 17.5f, 30.0f));
|
||||
platform->Run(0.06f);
|
||||
EXPECT_EQ(mover->mState, 2u);
|
||||
platform->Run(1.1f);
|
||||
EXPECT_EQ(mover->mState, 28u);
|
||||
EXPECT_EQ(mover->mCurrentWaypointIndex, 0u);
|
||||
EXPECT_EQ(counterweight.GetPosition(), NiPoint3(10.0f, 20.0f, 30.0f));
|
||||
}
|
||||
|
||||
// A rotater's subcomponent is type 6 with a mover's data (the client reads both the same way)
|
||||
TEST_F(MovingPlatformComponentTest, RotaterIsWrittenAsTypeSix) {
|
||||
info.settings.Insert<bool>(u"platformIsRotater", true);
|
||||
Entity rotater(288300744895900107, info);
|
||||
@@ -307,7 +477,7 @@ TEST_F(MovingPlatformComponentTest, MoverOnceLikeLiveFallingTile) {
|
||||
EXPECT_FALSE(mover->mInReverse);
|
||||
}
|
||||
|
||||
// The object goes with its mover on the server (LWOPlatform moves it ignoring the dirty flags), turned between the
|
||||
// The object goes with its mover on the server (the client's platform 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;
|
||||
@@ -438,7 +608,7 @@ TEST_F(MovingPlatformComponentTest, BuiltSimpleMoverSetsOffLikeLive) {
|
||||
EXPECT_EQ(Bits(arrived), "00");
|
||||
}
|
||||
|
||||
// LWOPlatformRotator::SetAngularVelocity: the velocity that turns from no rotation to the configured one in
|
||||
// The client's rotator: the velocity that turns from no rotation to the configured one in
|
||||
// half the rate. The client's matrices about an axis turn the other way round than the usual ones, so a quarter turn
|
||||
// about x in 1 s is -pi/2 about x; in reverse it is the other way. Whole turns have no axis and give no velocity. Half
|
||||
// a turn can go either way round: the float pi is a little over pi, so the shortest way is the usual direction.
|
||||
@@ -521,8 +691,148 @@ 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.
|
||||
TEST_F(MovingPlatformComponentTest, MoverAndRotatorBothRun) {
|
||||
Path path;
|
||||
path.pathType = PathType::MovingPlatform;
|
||||
path.pathName = "TestMoverRotatorPath";
|
||||
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);
|
||||
path.pathWaypoints = { first, second };
|
||||
const_cast<Zone*>(Game::zoneManager->GetZone())->AddPath(path);
|
||||
|
||||
info.pos = NiPoint3(0.0f, 0.0f, 0.0f);
|
||||
info.rot = QuatUtils::IDENTITY;
|
||||
info.settings.Insert<bool>(u"platformIsMover", true);
|
||||
info.settings.Insert<bool>(u"platformIsRotater", true);
|
||||
info.settings.Insert<float>(u"rotY", 0.5f);
|
||||
info.settings.Insert<float>(u"rate", 2.0f);
|
||||
Entity entity(288300744895900122, info);
|
||||
info.settings.values.clear();
|
||||
entity.AddComponent<SimplePhysicsComponent>(-1);
|
||||
auto* const platform = entity.AddComponent<MovingPlatformComponent>(-1, "TestMoverRotatorPath");
|
||||
auto* const mover = platform->GetSubComponent(eMoverSubComponentType::mover);
|
||||
auto* const rotator = platform->GetSubComponent(eMoverSubComponentType::rotater);
|
||||
ASSERT_NE(mover, nullptr);
|
||||
ASSERT_NE(rotator, nullptr);
|
||||
EXPECT_TRUE(platform->IsMover());
|
||||
EXPECT_EQ(mover->mState, 9u);
|
||||
EXPECT_EQ(rotator->mState, 2u);
|
||||
|
||||
// Both are written: the path, then type 4 and type 6 with a platform's data each
|
||||
RakNet::BitStream stream;
|
||||
platform->Serialize(stream, true);
|
||||
const auto bits = Bits(stream);
|
||||
const std::string moverType = "1" "00000100000000000000000000000000";
|
||||
const std::string rotatorType = "1" "00000110000000000000000000000000";
|
||||
const auto moverAt = bits.find(moverType);
|
||||
ASSERT_NE(moverAt, std::string::npos);
|
||||
EXPECT_NE(bits.find(rotatorType, moverAt + moverType.size()), std::string::npos);
|
||||
|
||||
// The mover waits its 0.1 s; the rotator turns from the start: a quarter turn a second
|
||||
platform->Run(0.11f);
|
||||
EXPECT_EQ(mover->mState, 2u);
|
||||
platform->Run(0.89f);
|
||||
EXPECT_NEAR(entity.GetPosition().x, 4.45f, 0.001f);
|
||||
EXPECT_NEAR(entity.GetRotation().w, 0.7071f, 0.001f);
|
||||
EXPECT_NEAR(entity.GetRotation().y, -0.7071f, 0.001f);
|
||||
|
||||
// At the end of the path the mover stops and the object is in the waypoint's rotation; the rotator goes on from it
|
||||
platform->Run(1.2f);
|
||||
EXPECT_EQ(mover->mState, 28u);
|
||||
EXPECT_EQ(rotator->mState, 2u);
|
||||
EXPECT_EQ(entity.GetPosition(), NiPoint3(10.0f, 0.0f, 0.0f));
|
||||
const float angle = 1.2f * 3.14159265f / 2.0f;
|
||||
EXPECT_NEAR(entity.GetRotation().w, std::cos(angle / 2.0f), 0.001f);
|
||||
EXPECT_NEAR(entity.GetRotation().y, -std::sin(angle / 2.0f), 0.001f);
|
||||
platform->Run(1.0f);
|
||||
EXPECT_EQ(entity.GetPosition(), NiPoint3(10.0f, 0.0f, 0.0f));
|
||||
|
||||
// Stopped, neither goes on
|
||||
platform->StopPathing();
|
||||
EXPECT_EQ(rotator->mState & 7u, 4u);
|
||||
const auto rotation = entity.GetRotation();
|
||||
platform->Run(1.0f);
|
||||
EXPECT_EQ(entity.GetRotation(), rotation);
|
||||
}
|
||||
|
||||
// Live's movers at a waypoint between the ends of their path: the object is put at the waypoint and serialized waiting
|
||||
// there (9), keeps the velocity it came with for the wait (LWOPlatform::SetWaitingTime only takes it away at
|
||||
// there (9), keeps the velocity it came with for the wait (the client only takes it away at
|
||||
// an end or when stopped), and is serialized leaving (2) from where that took it, with the part of the next stretch it
|
||||
// is from the waypoint: the GF shooting gallery subs (speed 15, no wait, so the shortest, 0.1 s: two of live's frames)
|
||||
// left 2 units past each waypoint. From there it goes the next stretch's direction and arrives as it passes the
|
||||
@@ -641,6 +951,9 @@ TEST_F(MovingPlatformComponentTest, OnceOnlyMoverGoesOnItsSpinnersEvent) {
|
||||
script.OnFireEventServerSide(&entity, &entity, "blades_on", 0, 0, 0);
|
||||
EXPECT_EQ(mover->mState, 12u);
|
||||
script.OnFireEventServerSide(&entity, &entity, "blades_off", 0, 0, 0);
|
||||
EXPECT_EQ(mover->mState, 9u);
|
||||
EXPECT_EQ(mover->mDesiredWaypointIndex, 1);
|
||||
platform->Run(0.11f);
|
||||
EXPECT_EQ(mover->mState, 2u);
|
||||
EXPECT_EQ(mover->mCurrentWaypointIndex, 0u);
|
||||
}
|
||||
|
||||
@@ -706,8 +706,26 @@ TEST_F(ReplicaConstructionTest, MovingPlatformEndsItsSubcomponentList) {
|
||||
uint32_t type{};
|
||||
ASSERT_TRUE(stream.Read(type));
|
||||
EXPECT_EQ(type, 4u); // mover
|
||||
// The mover: a 1 bit, state, desired waypoint, 2 flags, percent, position, current and next waypoint, 2 times
|
||||
stream.IgnoreBits(1 + 32 + 32 + 2 + 32 + 96 + 32 + 32 + 32 + 32);
|
||||
// The mover: a 1 bit, state, desired waypoint, 2 flags, percent, position, current and next waypoint, 2 times.
|
||||
// Live constructed a mover without a path (this LOT among them) waiting (9) at waypoint 0, at no position.
|
||||
ASSERT_TRUE(stream.Read(bit));
|
||||
EXPECT_TRUE(bit);
|
||||
uint32_t state{};
|
||||
int32_t desiredWaypoint{};
|
||||
ASSERT_TRUE(stream.Read(state));
|
||||
EXPECT_EQ(state, 9u);
|
||||
ASSERT_TRUE(stream.Read(desiredWaypoint));
|
||||
EXPECT_EQ(desiredWaypoint, -1);
|
||||
ASSERT_TRUE(stream.Read(bit));
|
||||
EXPECT_FALSE(bit); // not stopping at the desired waypoint
|
||||
ASSERT_TRUE(stream.Read(bit));
|
||||
EXPECT_FALSE(bit); // not reversing
|
||||
for (int32_t i = 0; i < 8; i++) {
|
||||
// percent, position, current and next waypoint, time waited and travelled: all nothing
|
||||
uint32_t value{};
|
||||
ASSERT_TRUE(stream.Read(value));
|
||||
EXPECT_EQ(value, 0u);
|
||||
}
|
||||
ASSERT_TRUE(stream.Read(bit));
|
||||
EXPECT_FALSE(bit); // no more subcomponents
|
||||
EXPECT_EQ(stream.GetNumberOfUnreadBits(), 0u);
|
||||
|
||||
@@ -116,6 +116,20 @@ TEST_F(RemainingMessagesTests, StartPathingAndPlatformResyncMatchLegacy) {
|
||||
rotated.qUnexpectedRotation = NiQuaternion(0.5f, 0.5f, -0.5f, 0.5f);
|
||||
const auto copy = RoundTrip(rotated);
|
||||
EXPECT_EQ(copy.qUnexpectedRotation, rotated.qUnexpectedRotation);
|
||||
|
||||
// The rotation goes w first, as live sent a NJ counterweight's (w 0.936, y 0.352)
|
||||
GameMessages::PlatformResync counterweight;
|
||||
counterweight.qUnexpectedRotation = NiQuaternion(0.936f, 0.0f, 0.352f, 0.0f);
|
||||
RakNet::BitStream stream;
|
||||
counterweight.Serialize(stream);
|
||||
// two flags, nine 32 bit values, the location and the flag for a rotation
|
||||
stream.IgnoreBits(2 + 9 * 32 + 3 * 32 + 1);
|
||||
float first{}, second{}, third{}, fourth{};
|
||||
ASSERT_TRUE(stream.Read(first) && stream.Read(second) && stream.Read(third) && stream.Read(fourth));
|
||||
EXPECT_FLOAT_EQ(first, 0.936f);
|
||||
EXPECT_FLOAT_EQ(second, 0.0f);
|
||||
EXPECT_FLOAT_EQ(third, 0.352f);
|
||||
EXPECT_FLOAT_EQ(fourth, 0.0f);
|
||||
}
|
||||
|
||||
TEST_F(RemainingMessagesTests, SmallMovementMessagesMatchLegacy) {
|
||||
|
||||
Reference in New Issue
Block a user