From f54f14328e2f342a4ce9216a36d7820dd16ebb0b Mon Sep 17 00:00:00 2001 From: Edmond Mondor Date: Wed, 4 May 2022 20:16:58 -0700 Subject: [PATCH] PR from Huru to prevent dynamics from moving during age initilization --- .../Plasma/PubUtilLib/plPhysX/plPXPhysical.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.cpp b/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.cpp index 03996b27..17669f5d 100644 --- a/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.cpp +++ b/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.cpp @@ -1328,15 +1328,15 @@ void plPXPhysical::GetSyncState(hsPoint3& pos, hsQuat& rot, hsVector3& linV, hsV void plPXPhysical::SetSyncState(hsPoint3* pos, hsQuat* rot, hsVector3* linV, hsVector3* angV) { - bool initialSync = plNetClientApp::GetInstance()->IsLoadingInitialAgeState() && - plNetClientApp::GetInstance()->GetJoinOrder() == 0; - + bool isLoading = plNetClientApp::GetInstance()->IsLoadingInitialAgeState(); + bool isFirstIn = plNetClientApp::GetInstance()->GetJoinOrder() == 0; + bool initialSync = isLoading && isFirstIn; // If the physical has fallen out of the sim, and this is initial age state, and we're // the first person in, reset it to the original position. (ie, prop the default state // we've got right now) if (pos && pos->fZ < kMaxNegativeZPos && initialSync) { - SimLog("Physical %s loaded out of range state. Forcing initial state to server.", GetKeyName()); + SimLog("Physical %s loaded out of range state. Forcing initial state to server.", GetKeyName().c_str()); DirtySynchState(kSDLPhysical, plSynchedObject::kBCastToClients); return; } @@ -1350,6 +1350,13 @@ void plPXPhysical::SetSyncState(hsPoint3* pos, hsQuat* rot, hsVector3* linV, hsV SetLinearVelocitySim(*linV); if (angV) SetAngularVelocitySim(*angV); + // If we're loading the age, then we should ensure the objects stay asleep if they're supposed to be asleep. + // NOTE: We should only do this if the objects are not at their initial locations. Otherwise, they might + // sleep inside each other and explode or float randomly in midair + if (isLoading && GetProperty(plSimulationInterface::kStartInactive) && !fActor->readBodyFlag(NX_BF_KINEMATIC)) { + if (!pos && !rot) + fActor->putToSleep(); + } SendNewLocation(false, true); }