diff --git a/dGame/dGameMessages/MovementMessages.cpp b/dGame/dGameMessages/MovementMessages.cpp index 19ebc90fd..0879f0ff9 100644 --- a/dGame/dGameMessages/MovementMessages.cpp +++ b/dGame/dGameMessages/MovementMessages.cpp @@ -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,10 +92,10 @@ 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; } diff --git a/dGame/dGameMessages/MovementMessages.h b/dGame/dGameMessages/MovementMessages.h index 6b8bf680f..53a2c61ad 100644 --- a/dGame/dGameMessages/MovementMessages.h +++ b/dGame/dGameMessages/MovementMessages.h @@ -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 }; }; diff --git a/tests/dGameTests/dGameMessagesTests/RemainingMessagesTests.cpp b/tests/dGameTests/dGameMessagesTests/RemainingMessagesTests.cpp index e105a031a..4c3a034ef 100644 --- a/tests/dGameTests/dGameMessagesTests/RemainingMessagesTests.cpp +++ b/tests/dGameTests/dGameMessagesTests/RemainingMessagesTests.cpp @@ -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) {