mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
fix: every platform answers a resync request, as live did
The client asks for a resync once for each platform of an object whose physics are ready. Live answered every request in the captures: movers on a path, the NJ counterweights (simple movers: waiting at waypoint 0 of their own path, at their start position and rotation) and movers without a path (waiting at waypoint 0 of none, at no position). The server only answered movers on a path. The answer is now made from whichever platform the object has. A simple mover has a position on its way now, so its answer says where it is. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -868,22 +868,30 @@ void MovingPlatformComponent::Run(const float deltaTime) {
|
||||
}
|
||||
}
|
||||
|
||||
void MovingPlatformComponent::FillResync(GameMessages::PlatformResync& resync) const {
|
||||
auto* const mover = GetSubComponent(eMoverSubComponentType::mover);
|
||||
resync.bReverse = mover->mInReverse;
|
||||
resync.bStopAtDesiredWaypoint = mover->mShouldStopAtDesiredWaypoint;
|
||||
resync.eState = static_cast<eMovementPlatformState>(mover->mState);
|
||||
resync.fIdleTimeElapsed = mover->mIdleTimeElapsed;
|
||||
resync.fMoveTimeElapsed = mover->mMoveTimeElapsed;
|
||||
resync.fPercentBetweenPoints = std::min(mover->mPercentBetweenPoints, 1.0f);
|
||||
resync.iDesiredWaypointIndex = mover->mDesiredWaypointIndex;
|
||||
resync.iIndex = static_cast<int32_t>(mover->mCurrentWaypointIndex);
|
||||
resync.iNextIndex = static_cast<int32_t>(mover->mNextWaypointIndex);
|
||||
resync.ptUnexpectedLocation = mover->mPosition;
|
||||
const auto& from = mover->mPath->pathWaypoints[mover->mCurrentWaypointIndex].rotation;
|
||||
const auto& to = mover->mPath->pathWaypoints[mover->mNextWaypointIndex].rotation;
|
||||
const auto rotation = glm::slerp(glm::quat(from.w, from.x, from.y, from.z), glm::quat(to.w, to.x, to.y, to.z), resync.fPercentBetweenPoints);
|
||||
resync.qUnexpectedRotation = NiQuaternion(rotation.w, rotation.x, rotation.y, rotation.z);
|
||||
// What live answered a client's request with: the state of the platform (a mover's, a simple mover's on its own path,
|
||||
// or a mover's without a path: waiting at waypoint 0 of none, at no position and with no rotation), where it is, and
|
||||
// the rotation between its two waypoints'. The client gives the message to every platform of the object; the first
|
||||
// one's state is sent.
|
||||
bool MovingPlatformComponent::FillResync(GameMessages::PlatformResync& resync) const {
|
||||
if (m_SubComponents.empty()) return false;
|
||||
const auto& platform = *m_SubComponents.front();
|
||||
resync.bReverse = platform.mInReverse;
|
||||
resync.bStopAtDesiredWaypoint = platform.mShouldStopAtDesiredWaypoint;
|
||||
resync.eState = static_cast<eMovementPlatformState>(platform.mState);
|
||||
resync.fIdleTimeElapsed = platform.mIdleTimeElapsed;
|
||||
resync.fMoveTimeElapsed = platform.mMoveTimeElapsed;
|
||||
resync.fPercentBetweenPoints = std::min(platform.mPercentBetweenPoints, 1.0f);
|
||||
resync.iDesiredWaypointIndex = platform.mDesiredWaypointIndex;
|
||||
resync.iIndex = static_cast<int32_t>(platform.mCurrentWaypointIndex);
|
||||
resync.iNextIndex = static_cast<int32_t>(platform.mNextWaypointIndex);
|
||||
resync.ptUnexpectedLocation = platform.mPosition;
|
||||
resync.qUnexpectedRotation = QuatUtils::IDENTITY;
|
||||
if (platform.mPath != nullptr) {
|
||||
const auto& from = platform.mPath->pathWaypoints[platform.mCurrentWaypointIndex].rotation;
|
||||
const auto& to = platform.mPath->pathWaypoints[platform.mNextWaypointIndex].rotation;
|
||||
resync.qUnexpectedRotation = from == to ? from : glm::slerp(from, to, resync.fPercentBetweenPoints);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void MovingPlatformComponent::SetSerialized(bool value) {
|
||||
|
||||
@@ -397,8 +397,8 @@ private:
|
||||
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;
|
||||
|
||||
// Whether the platform has a mover on a path
|
||||
bool IsMover() const;
|
||||
|
||||
@@ -101,17 +101,16 @@ namespace GameMessages {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -113,6 +113,55 @@ TEST_F(MovingPlatformComponentTest, SimpleMoverConstructionMatchesLive) {
|
||||
EXPECT_EQ(Bits(idle), "00");
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user