From a269ce0cc7ab68e2536aa13f4c54fb9552f54913 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Tue, 10 Nov 2026 13:09:43 -0600 Subject: [PATCH] fix: a simple physics construction keeps pending changes for the update LWOSimplePhysicsComponent::Deserialize (0x00be4b00) reads the velocity and the motion state each behind its own flag bit. DLU cleared both dirty flags when it wrote a construction, which goes only to the client the object came into range of, so the clients already watching it never got a change that was waiting for the next update. Co-Authored-By: Claude Opus 5.5 --- .../Physics/SimplePhysicsComponent.cpp | 5 ++-- .../SimplePhysicsComponentTests.cpp | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/dGame/dComponents/Physics/SimplePhysicsComponent.cpp b/dGame/dComponents/Physics/SimplePhysicsComponent.cpp index a3fb23ae5..5df12647c 100644 --- a/dGame/dComponents/Physics/SimplePhysicsComponent.cpp +++ b/dGame/dComponents/Physics/SimplePhysicsComponent.cpp @@ -73,13 +73,14 @@ void SimplePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIs outBitStream.Write(m_Velocity); outBitStream.Write(m_AngularVelocity); } - if (writeVelocity || bIsInitialUpdate) m_DirtyVelocity = false; + // A construction goes to the one client the object came into range of; the others still need the change + if (writeVelocity && !bIsInitialUpdate) m_DirtyVelocity = false; // Physics motion state outBitStream.Write(m_DirtyPhysicsMotionState || bIsInitialUpdate); if (m_DirtyPhysicsMotionState || bIsInitialUpdate) { outBitStream.Write(m_PhysicsMotionState); - m_DirtyPhysicsMotionState = false; + if (!bIsInitialUpdate) m_DirtyPhysicsMotionState = false; } PhysicsComponent::Serialize(outBitStream, bIsInitialUpdate); } diff --git a/tests/dGameTests/dComponentsTests/SimplePhysicsComponentTests.cpp b/tests/dGameTests/dComponentsTests/SimplePhysicsComponentTests.cpp index 32d0d26c8..88c9c3889 100644 --- a/tests/dGameTests/dComponentsTests/SimplePhysicsComponentTests.cpp +++ b/tests/dGameTests/dComponentsTests/SimplePhysicsComponentTests.cpp @@ -131,6 +131,35 @@ TEST_F(SimplePhysicsTest, SimplePhysicsConstructionTest) { ASSERT_EQ(rotation, NiQuaternion(1.0f, 2.0f, 3.0f, 4.0f)); } +// A construction (the object coming into one player's range) doesn't use up a velocity or motion state change the +// players already watching it still have to get. LWOSimplePhysicsComponent::Deserialize (0x00be4b00) reads each +// behind its own flag bit. +TEST_F(SimplePhysicsTest, AConstructionKeepsPendingChangesForTheNextUpdate) { + RakNet::BitStream construction; + simplePhysicsComponent->Serialize(construction, true); + + simplePhysicsComponent->Serialize(bitStream, false); + bool hasVelocity{}; + bitStream.Read(hasVelocity); + ASSERT_TRUE(hasVelocity); + NiPoint3 velocity; + NiPoint3 angularVelocity; + bitStream.Read(velocity); + bitStream.Read(angularVelocity); + EXPECT_EQ(velocity, NiPoint3(5.0f, 6.0f, 7.0f)); + bool hasMotionState{}; + bitStream.Read(hasMotionState); + ASSERT_TRUE(hasMotionState); + uint32_t motionState{}; + bitStream.Read(motionState); + EXPECT_EQ(motionState, 2u); + + // Written once + RakNet::BitStream again; + simplePhysicsComponent->Serialize(again, false); + EXPECT_EQ(again.GetNumberOfBitsUsed(), 3u); +} + TEST_F(SimplePhysicsTest, SimplePhysicsGettersAndSettersTest) { ASSERT_EQ(simplePhysicsComponent->GetClimabbleType(), eClimbableType::CLIMBABLE_TYPE_WALL); ASSERT_EQ(simplePhysicsComponent->GetPosition(), NiPoint3(1.0f, 2.0f, 3.0f));