mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
feat: simple movers run as platforms on their own path
The client's simple mover is a platform like the mover: it builds itself a two waypoint path run once (start, and start moved by platformMove, at the speed that takes platformMoveTime) and runs the same waiting, travelling and arriving logic on it. The server did it with a timer instead, so a simple mover had no position on its way and its states differed from a mover's. The platform logic now takes the subcomponent it runs and that subcomponent's path, and the simple mover runs on it: - sent to a waypoint it first waits the shortest wait there (9, or 25 at its end), then travels (2), as live's movers and counterweights did; - the object goes with it on its way and is put at the waypoint on arrival; - at an end it stops (28) and turns round, without a serialization; - it only takes a new direction at a waypoint, as the client's does: sent back on its way it goes on to the end it was heading for and sets off from there; stopped on its way it stops at that end; - one that starts at its end is constructed there, reversed. Comments in the component describe behaviour only. 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,12 +59,12 @@ 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.
|
||||
@@ -75,8 +75,8 @@ std::vector<eMoverSubComponentType> ChooseSubComponentTypes(int32_t componentID,
|
||||
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;
|
||||
@@ -97,21 +99,20 @@ public:
|
||||
float mPercentBetweenPoints = 0;
|
||||
// Where it is now: its object's position, which its linear velocity moves
|
||||
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,11 +125,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 (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:
|
||||
@@ -137,49 +137,48 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 +195,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;
|
||||
};
|
||||
|
||||
|
||||
@@ -308,12 +315,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 +327,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
|
||||
@@ -354,39 +350,43 @@ 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);
|
||||
// Puts the object where the platform is, without a serialization of its physics
|
||||
void MoveObject(const PlatformSubComponent& platform);
|
||||
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;
|
||||
|
||||
@@ -113,8 +113,9 @@ 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
|
||||
// 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,32 +124,125 @@ 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));
|
||||
}
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
@@ -641,6 +735,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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user