From 7c40364752665c3ab22feea38f0acbc16e6a4b7d Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 17 Jan 2012 22:24:53 -0500 Subject: [PATCH 1/4] Fix some more incorrect PhysX Api calls for Kinematic Actors As I discovered several months ago, Cyan used the incorrect NxActor::setGlobal(Pose/Position) function(s) to transform kinematic actors. This is incorrect but was apparently allowed in PhysX 2.6.0. PhysX 2.6.4 enforces the correct moveGlobal(Pose/Position) functionality, so we MUST use that. --- .../plPhysX/plPXPhysicalControllerCore.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalControllerCore.cpp b/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalControllerCore.cpp index d3b31e42..58c53d19 100644 --- a/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalControllerCore.cpp +++ b/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalControllerCore.cpp @@ -401,7 +401,7 @@ void plPXPhysicalControllerCore::IMatchKinematicToController() kinPos.z = (NxReal)cPos.z; if (plSimulationMgr::fExtraProfile) SimLog("Match setting kinematic from %f,%f,%f to %f,%f,%f",prevKinPos.x,prevKinPos.y,prevKinPos.z,kinPos.x,kinPos.y,kinPos.z ); - fKinematicActor->setGlobalPosition(kinPos); + fKinematicActor->moveGlobalPosition(kinPos); } } void plPXPhysicalControllerCore::UpdateControllerAndPhysicalRep() @@ -412,7 +412,7 @@ void plPXPhysicalControllerCore::UpdateControllerAndPhysicalRep() {//this means we are moving the controller and then synchnig the kin NxExtendedVec3 ControllerPos= fController->getPosition(); NxVec3 NewKinPos((NxReal)ControllerPos.x, (NxReal)ControllerPos.y, (NxReal)ControllerPos.z); - if (fEnabled || fKinematic) + if (fEnabled && fKinematicActor->readBodyFlag(NX_BF_KINEMATIC)) { if (plSimulationMgr::fExtraProfile) SimLog("Moving kinematic to %f,%f,%f",NewKinPos.x, NewKinPos.y, NewKinPos.z ); @@ -420,7 +420,7 @@ void plPXPhysicalControllerCore::UpdateControllerAndPhysicalRep() fKinematicActor->moveGlobalPosition(NewKinPos); } - else + else if (fEnabled) { if (plSimulationMgr::fExtraProfile) SimLog("Setting kinematic to %f,%f,%f", NewKinPos.x, NewKinPos.y, NewKinPos.z ); @@ -452,14 +452,14 @@ void plPXPhysicalControllerCore::MoveKinematicToController(hsPoint3& pos) newPos.x = (NxReal)pos.fX; newPos.y = (NxReal)pos.fY; newPos.z = (NxReal)pos.fZ+kPhysZOffset; - if ((fEnabled || fKinematic) && fBehavingLikeAnimatedPhys) + if (fEnabled && fKinematicActor->readBodyFlag(NX_BF_KINEMATIC)) { if (plSimulationMgr::fExtraProfile) SimLog("Moving kinematic from %f,%f,%f to %f,%f,%f",pos.fX,pos.fY,pos.fZ+kPhysZOffset,kinPos.x,kinPos.y,kinPos.z ); // use the position fKinematicActor->moveGlobalPosition(newPos); } - else + else if (fEnabled) { if (plSimulationMgr::fExtraProfile) SimLog("Setting kinematic from %f,%f,%f to %f,%f,%f",pos.fX,pos.fY,pos.fZ+kPhysZOffset,kinPos.x,kinPos.y,kinPos.z ); @@ -494,9 +494,9 @@ void plPXPhysicalControllerCore::ISetKinematicLoc(const hsMatrix44& l2w) // add z offset kPos.fZ += kPhysZOffset; // Update the physical position of kinematic - if (fEnabled|| fKinematic) + if (fEnabled && fKinematicActor->readBodyFlag(NX_BF_KINEMATIC)) fKinematicActor->moveGlobalPosition(plPXConvert::Point(kPos)); - else + else if (fEnabled) fKinematicActor->setGlobalPosition(plPXConvert::Point(kPos)); } void plPXPhysicalControllerCore::IGetPositionSim(hsPoint3& pos) const @@ -568,7 +568,7 @@ NxScene* scene = plSimulationMgr::GetInstance()->GetScene(fWorldKey); fKinematicActor->raiseActorFlag(NX_AF_DISABLE_COLLISION); #endif // set the matrix to be the same as the controller's actor... that should orient it to be the same - fKinematicActor->setGlobalPose(actor->getGlobalPose()); + fKinematicActor->moveGlobalPose(actor->getGlobalPose()); // the proxy for the debug display //hsAssert(!fProxyGen, "Already have proxy gen, double read?"); From 64a0c49439873ebdc26850636916eecc8bc71fd8 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 17 Jan 2012 22:28:54 -0500 Subject: [PATCH 2/4] Bonus: Some cleanups for collision message handling and slightly improved logging --- .../PubUtilLib/plModifier/plDetectorLog.cpp | 8 ++++ .../PubUtilLib/plModifier/plDetectorLog.h | 1 + .../plPhysX/plPXPhysicalControllerCore.cpp | 33 +++------------ .../plPhysX/plPXPhysicalControllerCore.h | 1 - .../PubUtilLib/plPhysX/plSimulationMgr.cpp | 40 +++---------------- .../PubUtilLib/plPhysX/plSimulationMgr.h | 6 --- 6 files changed, 20 insertions(+), 69 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plModifier/plDetectorLog.cpp b/Sources/Plasma/PubUtilLib/plModifier/plDetectorLog.cpp index 23246e5b..306837c5 100644 --- a/Sources/Plasma/PubUtilLib/plModifier/plDetectorLog.cpp +++ b/Sources/Plasma/PubUtilLib/plModifier/plDetectorLog.cpp @@ -48,6 +48,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com void DetectorLog(const char* format, ...) {} void DetectorLogSpecial(const char* format, ...) {} void DetectorLogRed(const char* format, ...) {} +void DetectorLogYellow(const char* format, ...) {} #else @@ -90,5 +91,12 @@ void DetectorLogRed(const char* format, ...) va_end(args); } +void DetectorLogYellow(const char* format, ...) +{ + va_list args; + va_start(args, format); + gLog->AddLineV(plStatusLog::kYellow, format, args); + va_end(args); +} #endif // PLASMA_EXTERNAL_RELEASE diff --git a/Sources/Plasma/PubUtilLib/plModifier/plDetectorLog.h b/Sources/Plasma/PubUtilLib/plModifier/plDetectorLog.h index 3e3c7590..50c3cafa 100644 --- a/Sources/Plasma/PubUtilLib/plModifier/plDetectorLog.h +++ b/Sources/Plasma/PubUtilLib/plModifier/plDetectorLog.h @@ -45,6 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com void DetectorLog(const char* format, ...); void DetectorLogSpecial(const char* format, ...); void DetectorLogRed(const char* format, ...); +void DetectorLogYellow(const char* format, ...); void DetectorDoLogfile(); #endif // plDetectorLog_h_inc \ No newline at end of file diff --git a/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalControllerCore.cpp b/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalControllerCore.cpp index 58c53d19..f4a79da7 100644 --- a/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalControllerCore.cpp +++ b/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalControllerCore.cpp @@ -40,6 +40,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "plPXPhysicalControllerCore.h" +#include "plgDispatch.h" #include "plSimulationMgr.h" #include "plPXPhysical.h" #include "plPXConvert.h" @@ -372,13 +373,6 @@ void plPXPhysicalControllerCore::ISetGlobalLoc(const hsMatrix44& l2w) plPXPhysicalControllerCore::~plPXPhysicalControllerCore() { IDeleteController(); - //need to make sure my queued messages are released - for(int j=0;jAddReceiver(physical->GetObjectKey()); if(!deferUntilNextSim) { -#ifndef PLASMA_EXTERNAL_RELEASE - DetectorLog("Sending an %s msg to %s" , entering? "entering":"exit", physical->GetObjectKey()->GetName()); -#endif - msg->Send(); + DetectorLog("Sending an %s msg to %s" , entering? "entering":"exit", physical->GetObjectKey()->GetName()); + msg->Send(); } else { -#ifndef PLASMA_EXTERNAL_RELEASE - DetectorLog("Queuing an %s msg to %s, which will be sent after the next simstep" , entering? "entering":"exit", physical->GetObjectKey()->GetName()); -#endif - //these will be fired in update prestep on the next lap - fQueuedCollideMsgs.Append(msg); + DetectorLog("Queuing an %s msg to %s, which will be sent after the client update" , entering? "entering":"exit", physical->GetObjectKey()->GetName()); + plgDispatch::Dispatch()->MsgQueue(msg); } } } } } -#ifndef PLASMA_EXTERNAL_RELEASE DetectorLog("Done informing from plPXPhysicalControllerCore::IInformDetectors"); -#endif } } void plPXPhysicalControllerCore::Move(hsVector3 displacement, unsigned int collideWith, unsigned int &collisionResults) @@ -932,16 +919,6 @@ void plPXPhysicalControllerCore::UpdatePrestep(hsScalar delSecs) if(ac) { if(ac->fNeedsResize)ac->IHandleResize(); - int storedCollideMsgs=ac->fQueuedCollideMsgs.GetCount(); - if(storedCollideMsgs) - { - plSimulationMgr* simMgr=plSimulationMgr::GetInstance(); - for(int j=0; jAddCollisionMsg(ac->fQueuedCollideMsgs[j]); - } - ac->fQueuedCollideMsgs.SetCount(0); - } ac->Apply(delSecs); } #ifndef PLASMA_EXTERNAL_RELEASE diff --git a/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalControllerCore.h b/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalControllerCore.h index 4795cba4..8a99e59c 100644 --- a/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalControllerCore.h +++ b/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalControllerCore.h @@ -151,7 +151,6 @@ protected: void IDrawDebugDisplay(); #endif void IHandleResize(); - hsTArray fQueuedCollideMsgs; hsScalar fPreferedRadius; hsScalar fPreferedHeight; // The global position and rotation of the avatar last time we set it (so we diff --git a/Sources/Plasma/PubUtilLib/plPhysX/plSimulationMgr.cpp b/Sources/Plasma/PubUtilLib/plPhysX/plSimulationMgr.cpp index 895e09dc..52d5320e 100644 --- a/Sources/Plasma/PubUtilLib/plPhysX/plSimulationMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plPhysX/plSimulationMgr.cpp @@ -43,6 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include +#include "plgDispatch.h" #include "hsTimer.h" #include "plProfile.h" #include "plPXPhysical.h" @@ -206,13 +207,13 @@ class SensorReport : public NxUserTriggerReport void SendCollisionMsg(plKey receiver, plKey hitter, hsBool entering) { + DetectorLogYellow("Collision: %s was triggered by %s. Sending an %s msg", receiver->GetName(), + hitter ? hitter->GetName() : "(nil)" , entering ? "'enter'" : "'exit'"); plCollideMsg* msg = TRACKED_NEW plCollideMsg; msg->fOtherKey = hitter; msg->fEntering = entering; msg->AddReceiver(receiver); -// msg->Send();\ - //placing message in a list to be fired off after sim step - plSimulationMgr::GetInstance()->AddCollisionMsg(msg); + plgDispatch::Dispatch()->MsgQueue(msg); // Sends the msg on the next client update } } gSensorReport; @@ -536,6 +537,8 @@ void plSimulationMgr::ReleaseScene(plKey world) void plSimulationMgr::ISendCollisionMsg(plKey receiver, plKey hitter, hsBool entering) { + DetectorLogYellow("Collision: %s is inside %s. Sending an %s msg", hitter ? hitter->GetName() : "(nil)", + receiver->GetName(), entering ? "'enter'" : "'exit'"); plCollideMsg* msg = TRACKED_NEW plCollideMsg; msg->fOtherKey = hitter; msg->fEntering = entering; @@ -543,34 +546,6 @@ void plSimulationMgr::ISendCollisionMsg(plKey receiver, plKey hitter, hsBool ent msg->Send(); } -void plSimulationMgr::AddCollisionMsg(plCollideMsg* msg) -{ - fCollisionMessages.Append(msg); -} -void plSimulationMgr::IDispatchCollisionMessages() -{ - if(fCollisionMessages.GetCount()) - { -#ifndef PLASMA_EXTERNAL_RELEASE - DetectorLog("--------------------------------------------------"); - DetectorLog("Dispatching collision messages from last sim step"); -#endif - for(int i=0; iGetReceiver(0)->GetName(), - fCollisionMessages[i]->GetSender()?fCollisionMessages[i]->GetSender()->GetName():"An Avatar", - fCollisionMessages[i]->fEntering? "enter" : "exit"); -#endif - fCollisionMessages[i]->Send(); - } -#ifndef PLASMA_EXTERNAL_RELEASE - DetectorLog("--------------------------------------------------"); -#endif - fCollisionMessages.SetCount(0); - } -} - void plSimulationMgr::UpdateDetectorsInScene(plKey world, plKey avatar, hsPoint3& pos, bool entering) { // search thru the actors in a scene looking for convex hull detectors and see if the avatar is inside it @@ -679,9 +654,6 @@ void plSimulationMgr::Advance(float delSecs) } } plPXPhysicalControllerCore::UpdatePostSimStep(delSecs); - - //sending off and clearing the Collision Messages generated by scene->simulate - IDispatchCollisionMessages(); plProfile_EndTiming(Step); #ifndef PLASMA_EXTERNAL_RELEASE diff --git a/Sources/Plasma/PubUtilLib/plPhysX/plSimulationMgr.h b/Sources/Plasma/PubUtilLib/plPhysX/plSimulationMgr.h index 67843266..18448172 100644 --- a/Sources/Plasma/PubUtilLib/plPhysX/plSimulationMgr.h +++ b/Sources/Plasma/PubUtilLib/plPhysX/plSimulationMgr.h @@ -139,12 +139,6 @@ protected: plPhysicsSoundMgr* fSoundMgr; - //a list of collision messages generated by the simulation steps. Added to by AddCollisionMsg(plCollideMsg* msg) - //cleared by IDispatchCollisionMessages when done - hsTArray fCollisionMessages; - - void IDispatchCollisionMessages(); - // A mapping from a key to a PhysX scene. The key is either the // SimulationMgr key, for the main world, or a SceneObject key if it's a // subworld. From 3bf8df58d8fe3244523618fbca0909a22b12f9e1 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Thu, 19 Jan 2012 00:19:48 -0500 Subject: [PATCH 3/4] Band-aid for the "Michael Jackson" bug --- Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp index d49a2834..0b750b84 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp @@ -1302,7 +1302,7 @@ hsBool plArmatureMod::MsgReceive(plMessage* msg) if(spawnSO) { hsMatrix44 l2w = spawnSO->GetLocalToWorld(); - plWarpMsg *warpM = TRACKED_NEW plWarpMsg(nil, GetTarget(0)->GetKey(), 0, l2w); + plWarpMsg *warpM = TRACKED_NEW plWarpMsg(nil, GetTarget(0)->GetKey(), plWarpMsg::kFlushTransform, l2w); warpM->Send(); fWaitFlags &= ~kNeedSpawn; } From b4e1dc352e33a6f866021ee8547c1572e7efdb66 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Thu, 19 Jan 2012 00:59:56 -0500 Subject: [PATCH 4/4] Fix player and CGZ marker games --- .../Plasma/FeatureLib/pfCharacter/pfMarkerInfo.cpp | 1 + Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.cpp | 11 ++--------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfCharacter/pfMarkerInfo.cpp b/Sources/Plasma/FeatureLib/pfCharacter/pfMarkerInfo.cpp index b4895463..270c96b0 100644 --- a/Sources/Plasma/FeatureLib/pfCharacter/pfMarkerInfo.cpp +++ b/Sources/Plasma/FeatureLib/pfCharacter/pfMarkerInfo.cpp @@ -151,6 +151,7 @@ void pfMarkerInfo::Show(bool show) plEnableMsg* msg = TRACKED_NEW plEnableMsg; msg->SetBCastFlag(plMessage::kPropagateToChildren); msg->SetCmd(plEnableMsg::kDrawable); + msg->SetCmd(plEnableMsg::kPhysical); msg->SetCmd(show ? plEnableMsg::kEnable : plEnableMsg::kDisable); msg->SetSender(pfMarkerMgr::Instance()->GetKey()); msg->Send(fKey); diff --git a/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.cpp b/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.cpp index 343d757c..99a210df 100644 --- a/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.cpp +++ b/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.cpp @@ -827,6 +827,7 @@ void plPXPhysical::ApplyHitForce() void plPXPhysical::ISetTransformGlobal(const hsMatrix44& l2w) { hsAssert(fActor->isDynamic(), "Shouldn't move a static actor"); + fActor->wakeUp(); NxMat34 mat; @@ -1000,15 +1001,7 @@ plKey plPXPhysical::GetSceneNode() const void plPXPhysical::SetSceneNode(plKey newNode) { -#ifdef HS_DEBUGGING - plKey oldNode = GetSceneNode(); - char msg[1024]; - if (newNode) - sprintf(msg,"Physical object %s cannot change scenes. Already in %s, trying to switch to %s.",fObjectKey->GetName(),oldNode->GetName(),newNode->GetName()); - else - sprintf(msg,"Physical object %s cannot change scenes. Already in %s, trying to switch to .",fObjectKey->GetName(),oldNode->GetName()); - hsAssert(oldNode == newNode, msg); -#endif // HS_DEBUGGING + // Not Supported } /////////////////////////////////////////////////////////////////////