Browse Source

Bonus: Some cleanups for collision message handling and slightly improved

logging
Adam Johnson 13 years ago
parent
commit
64a0c49439
  1. 8
      Sources/Plasma/PubUtilLib/plModifier/plDetectorLog.cpp
  2. 1
      Sources/Plasma/PubUtilLib/plModifier/plDetectorLog.h
  3. 29
      Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalControllerCore.cpp
  4. 1
      Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalControllerCore.h
  5. 40
      Sources/Plasma/PubUtilLib/plPhysX/plSimulationMgr.cpp
  6. 6
      Sources/Plasma/PubUtilLib/plPhysX/plSimulationMgr.h

8
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 DetectorLog(const char* format, ...) {}
void DetectorLogSpecial(const char* format, ...) {} void DetectorLogSpecial(const char* format, ...) {}
void DetectorLogRed(const char* format, ...) {} void DetectorLogRed(const char* format, ...) {}
void DetectorLogYellow(const char* format, ...) {}
#else #else
@ -90,5 +91,12 @@ void DetectorLogRed(const char* format, ...)
va_end(args); 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 #endif // PLASMA_EXTERNAL_RELEASE

1
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 DetectorLog(const char* format, ...);
void DetectorLogSpecial(const char* format, ...); void DetectorLogSpecial(const char* format, ...);
void DetectorLogRed(const char* format, ...); void DetectorLogRed(const char* format, ...);
void DetectorLogYellow(const char* format, ...);
void DetectorDoLogfile(); void DetectorDoLogfile();
#endif // plDetectorLog_h_inc #endif // plDetectorLog_h_inc

29
Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalControllerCore.cpp

@ -40,6 +40,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/ *==LICENSE==*/
#include "plPXPhysicalControllerCore.h" #include "plPXPhysicalControllerCore.h"
#include "plgDispatch.h"
#include "plSimulationMgr.h" #include "plSimulationMgr.h"
#include "plPXPhysical.h" #include "plPXPhysical.h"
#include "plPXConvert.h" #include "plPXConvert.h"
@ -372,13 +373,6 @@ void plPXPhysicalControllerCore::ISetGlobalLoc(const hsMatrix44& l2w)
plPXPhysicalControllerCore::~plPXPhysicalControllerCore() plPXPhysicalControllerCore::~plPXPhysicalControllerCore()
{ {
IDeleteController(); IDeleteController();
//need to make sure my queued messages are released
for(int j=0;j<fQueuedCollideMsgs.GetCount();j++)
{
delete fQueuedCollideMsgs[j];
fQueuedCollideMsgs[j]=nil;
}
fQueuedCollideMsgs.SetCount(0);
for (int i = 0; i < gControllers.size(); i++) for (int i = 0; i < gControllers.size(); i++)
{ {
if (gControllers[i] == this) if (gControllers[i] == this)
@ -706,26 +700,19 @@ void plPXPhysicalControllerCore::IInformDetectors(bool entering,bool deferUntilN
msg->AddReceiver(physical->GetObjectKey()); msg->AddReceiver(physical->GetObjectKey());
if(!deferUntilNextSim) if(!deferUntilNextSim)
{ {
#ifndef PLASMA_EXTERNAL_RELEASE
DetectorLog("Sending an %s msg to %s" , entering? "entering":"exit", physical->GetObjectKey()->GetName()); DetectorLog("Sending an %s msg to %s" , entering? "entering":"exit", physical->GetObjectKey()->GetName());
#endif
msg->Send(); msg->Send();
} }
else else
{ {
#ifndef PLASMA_EXTERNAL_RELEASE DetectorLog("Queuing an %s msg to %s, which will be sent after the client update" , entering? "entering":"exit", physical->GetObjectKey()->GetName());
DetectorLog("Queuing an %s msg to %s, which will be sent after the next simstep" , entering? "entering":"exit", physical->GetObjectKey()->GetName()); plgDispatch::Dispatch()->MsgQueue(msg);
#endif
//these will be fired in update prestep on the next lap
fQueuedCollideMsgs.Append(msg);
} }
} }
} }
} }
} }
#ifndef PLASMA_EXTERNAL_RELEASE
DetectorLog("Done informing from plPXPhysicalControllerCore::IInformDetectors"); DetectorLog("Done informing from plPXPhysicalControllerCore::IInformDetectors");
#endif
} }
} }
void plPXPhysicalControllerCore::Move(hsVector3 displacement, unsigned int collideWith, unsigned int &collisionResults) void plPXPhysicalControllerCore::Move(hsVector3 displacement, unsigned int collideWith, unsigned int &collisionResults)
@ -932,16 +919,6 @@ void plPXPhysicalControllerCore::UpdatePrestep(hsScalar delSecs)
if(ac) if(ac)
{ {
if(ac->fNeedsResize)ac->IHandleResize(); if(ac->fNeedsResize)ac->IHandleResize();
int storedCollideMsgs=ac->fQueuedCollideMsgs.GetCount();
if(storedCollideMsgs)
{
plSimulationMgr* simMgr=plSimulationMgr::GetInstance();
for(int j=0; j<storedCollideMsgs;j++)
{
simMgr->AddCollisionMsg(ac->fQueuedCollideMsgs[j]);
}
ac->fQueuedCollideMsgs.SetCount(0);
}
ac->Apply(delSecs); ac->Apply(delSecs);
} }
#ifndef PLASMA_EXTERNAL_RELEASE #ifndef PLASMA_EXTERNAL_RELEASE

1
Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalControllerCore.h

@ -151,7 +151,6 @@ protected:
void IDrawDebugDisplay(); void IDrawDebugDisplay();
#endif #endif
void IHandleResize(); void IHandleResize();
hsTArray<plCollideMsg*> fQueuedCollideMsgs;
hsScalar fPreferedRadius; hsScalar fPreferedRadius;
hsScalar fPreferedHeight; hsScalar fPreferedHeight;
// The global position and rotation of the avatar last time we set it (so we // The global position and rotation of the avatar last time we set it (so we

40
Sources/Plasma/PubUtilLib/plPhysX/plSimulationMgr.cpp

@ -43,6 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <NxPhysics.h> #include <NxPhysics.h>
#include "plgDispatch.h"
#include "hsTimer.h" #include "hsTimer.h"
#include "plProfile.h" #include "plProfile.h"
#include "plPXPhysical.h" #include "plPXPhysical.h"
@ -206,13 +207,13 @@ class SensorReport : public NxUserTriggerReport
void SendCollisionMsg(plKey receiver, plKey hitter, hsBool entering) 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; plCollideMsg* msg = TRACKED_NEW plCollideMsg;
msg->fOtherKey = hitter; msg->fOtherKey = hitter;
msg->fEntering = entering; msg->fEntering = entering;
msg->AddReceiver(receiver); msg->AddReceiver(receiver);
// msg->Send();\ plgDispatch::Dispatch()->MsgQueue(msg); // Sends the msg on the next client update
//placing message in a list to be fired off after sim step
plSimulationMgr::GetInstance()->AddCollisionMsg(msg);
} }
} gSensorReport; } gSensorReport;
@ -536,6 +537,8 @@ void plSimulationMgr::ReleaseScene(plKey world)
void plSimulationMgr::ISendCollisionMsg(plKey receiver, plKey hitter, hsBool entering) 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; plCollideMsg* msg = TRACKED_NEW plCollideMsg;
msg->fOtherKey = hitter; msg->fOtherKey = hitter;
msg->fEntering = entering; msg->fEntering = entering;
@ -543,34 +546,6 @@ void plSimulationMgr::ISendCollisionMsg(plKey receiver, plKey hitter, hsBool ent
msg->Send(); 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; i<fCollisionMessages.GetCount();i++)
{
#ifndef PLASMA_EXTERNAL_RELEASE
DetectorLog("%s was hit by %s. Sending an %s message",fCollisionMessages[i]->GetReceiver(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) 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 // search thru the actors in a scene looking for convex hull detectors and see if the avatar is inside it
@ -680,9 +655,6 @@ void plSimulationMgr::Advance(float delSecs)
} }
plPXPhysicalControllerCore::UpdatePostSimStep(delSecs); plPXPhysicalControllerCore::UpdatePostSimStep(delSecs);
//sending off and clearing the Collision Messages generated by scene->simulate
IDispatchCollisionMessages();
plProfile_EndTiming(Step); plProfile_EndTiming(Step);
#ifndef PLASMA_EXTERNAL_RELEASE #ifndef PLASMA_EXTERNAL_RELEASE
if(plSimulationMgr::fDisplayAwakeActors)IDrawActiveActorList(); if(plSimulationMgr::fDisplayAwakeActors)IDrawActiveActorList();

6
Sources/Plasma/PubUtilLib/plPhysX/plSimulationMgr.h

@ -139,12 +139,6 @@ protected:
plPhysicsSoundMgr* fSoundMgr; plPhysicsSoundMgr* fSoundMgr;
//a list of collision messages generated by the simulation steps. Added to by AddCollisionMsg(plCollideMsg* msg)
//cleared by IDispatchCollisionMessages when done
hsTArray<plCollideMsg*> fCollisionMessages;
void IDispatchCollisionMessages();
// A mapping from a key to a PhysX scene. The key is either the // 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 // SimulationMgr key, for the main world, or a SceneObject key if it's a
// subworld. // subworld.

Loading…
Cancel
Save