Browse Source

Updated plPXPhysicalControllerCore

While based heavily on the old implementation, this is essentially a rewrite.

Notable changes -
Controllers are now updated at the same fixed frequency as the simulation.
Resulting output is interpolated between steps to precisely match the frame delta.
Physics work is only done when enough time has passed to perform a step.

The kinematic actor that followed around the controller has been removed.
The underlying kinematic actor created by the NxController is now used for triggering.
A new sim group was added for a kinematically controlled avatar.

2 unused files removed -
plPXPhysicalController.h & plPXPhysicalController.cpp
Skoader 13 years ago committed by Adam Johnson
parent
commit
70e766ae5b
  1. 3
      Sources/Plasma/PubUtilLib/plPhysX/plLOSDispatch.cpp
  2. 1280
      Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalController.cpp
  3. 211
      Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalController.h
  4. 1382
      Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalControllerCore.cpp
  5. 152
      Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalControllerCore.h
  6. 116
      Sources/Plasma/PubUtilLib/plPhysX/plSimulationMgr.cpp
  7. 3
      Sources/Plasma/PubUtilLib/plPhysX/plSimulationMgr.h
  8. 4
      Sources/Plasma/PubUtilLib/plPhysical/plSimDefs.h

3
Sources/Plasma/PubUtilLib/plPhysX/plLOSDispatch.cpp

@ -94,8 +94,7 @@ private:
} }
else else
{ {
bool isController; plPXPhysicalControllerCore* controller = plPXPhysicalControllerCore::GetController(hitActor);
plPXPhysicalControllerCore* controller = plPXPhysicalControllerCore::GetController(hitActor,&isController);
if (controller) if (controller)
{ {
objKey = controller->GetOwner(); objKey = controller->GetOwner();

1280
Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalController.cpp

File diff suppressed because it is too large Load Diff

211
Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalController.h

@ -1,211 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef plPXPhysicalController_h_inc
#define plPXPhysicalController_h_inc
#include "plAvatar/plAvCallbackAction.h"
#include "hsQuat.h"
#define PHYSX_ONLY_TRIGGER_FROM_KINEMATIC 1
class NxController;
class NxCapsuleController;
class NxActor;
class plCoordinateInterface;
class plPhysicalProxy;
class plDrawableSpans;
class hsGMaterial;
class NxCapsule;
#ifndef PLASMA_EXTERNAL_RELEASE
class plDbgCollisionInfo
{
public:
plSceneObject *fSO;
hsVector3 fNormal;
bool fOverlap;
};
#endif // PLASMA_EXTERNAL_RELEASE
class plPXPhysicalController : public plPhysicalController
{
public:
plPXPhysicalController(plKey ownerSO, hsScalar height, hsScalar radius);
virtual ~plPXPhysicalController();
virtual void Enable(bool enable);
virtual bool IsEnabled() const { return fEnable; }
virtual void SetLOSDB(plSimDefs::plLOSDB losDB) { fLOSDB = losDB; }
plSimDefs::plLOSDB GetLOSDB() const { return fLOSDB; }
virtual void SetVelocities(const hsVector3& linearVel, hsScalar angVel)
{
fLinearVelocity = linearVel;
fAngularVelocity = angVel;
}
virtual const hsVector3& GetLinearVelocity() const { return fAchievedLinearVelocity; }
virtual void ResetAchievedLinearVelocity() { fAchievedLinearVelocity.Set(0.f, 0.f, 0.f); }
virtual plKey GetSubworld() const { return fWorldKey; }
virtual void SetSubworld(plKey world);
virtual bool IsOnGround() const { return fTimeInAir < kAirTimeThreshold || fFalseGround; }
virtual bool IsOnFalseGround() const { return fFalseGround && !fGroundHit; }
virtual void GroundHit() { fGroundHit = true; }
virtual hsScalar GetAirTime() const { return fTimeInAir; }
virtual void ResetAirTime() { fTimeInAir = 0.f; }
virtual void AddSlidingNormal(hsVector3 vec);
virtual hsTArray<hsVector3>* GetSlidingNormals() { return &fSlidingNormals; }
virtual plPhysical* GetPushingPhysical() const { return fPushingPhysical; }
virtual bool GetFacingPushingPhysical() const { return fFacingPushingPhysical; }
virtual const plCoordinateInterface* GetSubworldCI() const;
virtual void GetState(hsPoint3& pos, float& zRot);
virtual void SetState(const hsPoint3& pos, float zRot);
plKey GetOwner() const { return fOwner; }
// Called by the simulation mgr each frame
static void Update(bool prestep, hsScalar delSecs);
// Used by the LOS mgr to find the controller for an actor it hit
static plPXPhysicalController* GetController(NxActor& actor, bool* isController);
// test to see if there are any controllers (i.e. avatars) in this subworld
static bool plPXPhysicalController::AnyControllersInThisWorld(plKey world);
static int plPXPhysicalController::NumControllers();
static int plPXPhysicalController::GetControllersInThisSubWorld(plKey world, int maxToReturn,
plPXPhysicalController** bufferout);
static int plPXPhysicalController::GetNumberOfControllersInThisSubWorld(plKey world);
// Call this if a static physical in the scene has changed (unloaded,
// collision enabled/disabled, etc)
static void RebuildCache();
virtual void GetPositionSim(hsPoint3& pos) const { IGetPositionSim(pos); }
virtual void Kinematic(bool state);
virtual bool IsKinematic();
virtual void GetKinematicPosition(hsPoint3& pos);
virtual plDrawableSpans* CreateProxy(hsGMaterial* mat, hsTArray<uint32_t>& idx, plDrawableSpans* addTo);
virtual const hsMatrix44& GetPrevSubworldW2L() { return fPrevSubworldW2L; }
virtual void SetSeek(bool seek){fSeeking=seek;}
virtual void GetWorldSpaceCapsule(NxCapsule& cap);
#ifndef PLASMA_EXTERNAL_RELEASE
static bool fDebugDisplay;
#endif // PLASMA_EXTERNAL_RELEASE
protected:
static const hsScalar kAirTimeThreshold;
friend class PXControllerHitReport;
static plPXPhysicalController* FindController(NxController* controller);
void IApply(hsScalar delSecs);
void ISendUpdates(hsScalar delSecs);
void ICheckForFalseGround();
void ISetGlobalLoc(const hsMatrix44& l2w);
void IMatchKinematicToController();
void IMoveKinematicToController(hsPoint3& pos);
void ISetKinematicLoc(const hsMatrix44& l2w);
void IGetPositionSim(hsPoint3& pos) const;
void ICreateController();
void IDeleteController();
void IInformDetectors(bool entering);
plKey fOwner;
plKey fWorldKey;
hsScalar fRadius, fHeight;
NxCapsuleController* fController;
// this is the kinematic actor for triggering things when the avatar is collision-less during behaviors
NxActor* fKinematicActor;
hsVector3 fLinearVelocity;
hsScalar fAngularVelocity;
hsVector3 fAchievedLinearVelocity;
// The global position and rotation of the avatar last time we set it (so we
// can detect if someone else moves him)
hsMatrix44 fLastGlobalLoc;
//
hsPoint3 fLocalPosition;
hsQuat fLocalRotation;
hsMatrix44 fPrevSubworldW2L;
bool fEnable;
bool fEnableChanged;
plSimDefs::plLOSDB fLOSDB;
bool fKinematic;
bool fKinematicChanged;
bool fKinematicEnableNextUpdate;
bool fGroundHit;
bool fFalseGround;
hsScalar fTimeInAir;
hsTArray<hsVector3> fSlidingNormals;
hsTArray<hsVector3> fPrevSlidingNormals;
#ifndef PLASMA_EXTERNAL_RELEASE
hsTArray<plDbgCollisionInfo> fDbgCollisionInfo;
void IDrawDebugDisplay();
#endif // PLASMA_EXTERNAL_RELEASE
plPhysical* fPushingPhysical;
bool fFacingPushingPhysical;
plPhysicalProxy* fProxyGen; // visual proxy for debugging
bool fHitHead;
bool fSeeking;
};
#endif // plPXPhysicalController_h_inc

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

File diff suppressed because it is too large Load Diff

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

@ -40,22 +40,19 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/ *==LICENSE==*/
#include "plAvatar/plPhysicalControllerCore.h" #include "plAvatar/plPhysicalControllerCore.h"
#include "hsQuat.h"
#define PHYSX_ONLY_TRIGGER_FROM_KINEMATIC 1
class NxController;
class NxCapsuleController; class NxCapsuleController;
class NxActor; class NxActor;
class plCoordinateInterface; class NxCapsule;
class PXControllerHitReport;
class plPhysicalProxy; class plPhysicalProxy;
class plDrawableSpans; class plDrawableSpans;
class hsGMaterial; class hsGMaterial;
class NxCapsule;
class plSceneObject; class plSceneObject;
class PXControllerHitReportWalk; class plPXPhysical;
class plCollideMsg; class plCollideMsg;
#ifndef PLASMA_EXTERNAL_RELEASE
#ifndef PLASMA_EXTERNAL_RELEASE
class plDbgCollisionInfo class plDbgCollisionInfo
{ {
public: public:
@ -64,97 +61,112 @@ public:
bool fOverlap; bool fOverlap;
}; };
#endif // PLASMA_EXTERNAL_RELEASE #endif // PLASMA_EXTERNAL_RELEASE
class plPXPhysicalControllerCore: public plPhysicalControllerCore class plPXPhysicalControllerCore: public plPhysicalControllerCore
{ {
friend class PXControllerHitReportWalk;
public: public:
plPXPhysicalControllerCore(plKey ownerSO, float height, float radius); plPXPhysicalControllerCore(plKey ownerSO, float height, float radius);
~plPXPhysicalControllerCore(); ~plPXPhysicalControllerCore();
//should actually be a 3 vector but everywhere else it is assumed to be just around Z
inline virtual void Move(hsVector3 displacement, unsigned int collideWith, unsigned int &collisionResults); // An ArmatureMod has its own idea about when physics should be enabled/disabled.
// A disabled avatar doesn't move or accumulate air time if he's off the ground. // Use plArmatureModBase::EnablePhysics() instead.
virtual void Enable(bool enable); virtual void Enable(bool enable);
// Subworld
virtual void SetSubworld(plKey world); virtual void SetSubworld(plKey world);
virtual const plCoordinateInterface* GetSubworldCI() const ;
// For the avatar SDL only // For the avatar SDL only
virtual void GetState(hsPoint3& pos, float& zRot); virtual void GetState(hsPoint3& pos, float& zRot);
virtual void SetState(const hsPoint3& pos, float zRot); virtual void SetState(const hsPoint3& pos, float zRot);
// kinematic stuff .... should be just for when playing a behavior...
virtual void Kinematic(bool state); // Movement strategy
virtual bool IsKinematic(); virtual void SetMovementStrategy(plMovementStrategy* strategy);
virtual void GetKinematicPosition(hsPoint3& pos);
virtual const hsMatrix44& GetPrevSubworldW2L(){ return fPrevSubworldW2L; } // Global location
//when seeking no longer want to interact with exclusion regions virtual void SetGlobalLoc(const hsMatrix44& l2w);
virtual void GetWorldSpaceCapsule(NxCapsule& cap) const;
static void RebuildCache(); // Local Sim Position
virtual const hsMatrix44& GetLastGlobalLoc(){return fLastGlobalLoc;} virtual void GetPositionSim(hsPoint3& pos);
virtual void SetKinematicLoc(const hsMatrix44& l2w){ISetKinematicLoc(l2w);}
virtual void SetGlobalLoc(const hsMatrix44& l2w){ISetGlobalLoc(l2w);} // Move kinematic controller
virtual void HandleEnableChanged(); virtual void Move(hsVector3 displacement, unsigned int collideWith, unsigned int &collisionResults);
virtual void HandleKinematicChanged();
virtual void HandleKinematicEnableNextUpdate(); // Set linear velocity on dynamic controller
virtual void GetPositionSim(hsPoint3& pos){IGetPositionSim(pos);} virtual void SetLinearVelocitySim(const hsVector3& linearVel);
virtual void MoveKinematicToController(hsPoint3& pos);
virtual const hsPoint3& GetLocalPosition(){return fLocalPosition;} // Sweep the controller path from startPos through endPos
virtual void SetControllerDimensions(float radius, float height); virtual int SweepControllerPath(const hsPoint3& startPos, const hsPoint3& endPos, bool vsDynamics,
bool vsStatics, uint32_t& vsSimGroups, std::vector<plControllerSweepRecord>& hits);
// any clean up for the controller should go here
virtual void LeaveAge(); virtual void LeaveAge();
virtual void UpdateControllerAndPhysicalRep();
// Capsule
void GetWorldSpaceCapsule(NxCapsule& cap) const;
// Create Proxy for debug rendering
plDrawableSpans* CreateProxy(hsGMaterial* mat, hsTArray<uint32_t>& idx, plDrawableSpans* addTo);
// Dynamic hits
void AddDynamicHit(plPXPhysical* phys);
////////////////////////////////////////// //////////////////////////////////////////
//Static Helper Functions //Static Helper Functions
//////////////////////////////////////// ////////////////////////////////////////
// Used by the LOS mgr to find the controller for an actor it hit
static plPXPhysicalControllerCore* GetController(NxActor& actor, bool* isController); // Call pre-sim to apply movement to controllers
// test to see if there are any controllers (i.e. avatars) in this subworld static void Apply(float delSecs);
// Call post-sim to update controllers
static void Update(int numSubSteps, float alpha);
// Update controllers when not performing a physics step
static void UpdateNonPhysical(float alpha);
// Rebuild the controller cache, required when a static actor in the scene has changed.
static void RebuildCache();
// Returns the plPXPhysicalControllerCore associated with the given NxActor
static plPXPhysicalControllerCore* GetController(NxActor& actor);
// Subworld controller queries
static bool AnyControllersInThisWorld(plKey world); static bool AnyControllersInThisWorld(plKey world);
static int NumControllers();
static int GetControllersInThisSubWorld(plKey world, int maxToReturn,
plPXPhysicalControllerCore** bufferout);
static int GetNumberOfControllersInThisSubWorld(plKey world); static int GetNumberOfControllersInThisSubWorld(plKey world);
static void UpdatePrestep(float delSecs); static int GetControllersInThisSubWorld(plKey world, int maxToReturn, plPXPhysicalControllerCore** bufferout);
static void UpdatePoststep(float delSecs);
static void UpdatePostSimStep(float delSecs); // Controller count
virtual plDrawableSpans* CreateProxy(hsGMaterial* mat, hsTArray<uint32_t>& idx, plDrawableSpans* addTo); static int NumControllers();
#ifndef PLASMA_EXTERNAL_RELEASE
static bool fDebugDisplay;
#endif // PLASMA_EXTERNAL_RELEASE
static void SetMaxNumberOfControllers(int max) { fPXControllersMax = max; } static void SetMaxNumberOfControllers(int max) { fPXControllersMax = max; }
static int fPXControllersMax; static int fPXControllersMax;
virtual int SweepControllerPath(const hsPoint3& startPos, const hsPoint3& endPos, bool vsDynamics, bool vsStatics, uint32_t& vsSimGroups, std::multiset< plControllerSweepRecord >& WhatWasHitOut);
virtual void BehaveLikeAnimatedPhysical(bool actLikeAnAnimatedPhys);
virtual bool BehavingLikeAnAnimatedPhysical();
virtual const hsVector3& GetLinearVelocity();
virtual void SetLinearVelocity(const hsVector3& linearVel); #ifndef PLASMA_EXTERNAL_RELEASE
//should actually be a 3 vector but everywhere else it is assumed to be just around Z static bool fDebugDisplay;
virtual void SetAngularVelocity(const float angvel); #endif
virtual void SetVelocities(const hsVector3& linearVel, float angVel);
protected: protected:
friend class PXControllerHitReport; friend class PXControllerHitReport;
static plPXPhysicalControllerCore* FindController(NxController* controller);
void ISetGlobalLoc(const hsMatrix44& l2w); virtual void IHandleEnableChanged();
void IMatchKinematicToController();
void IMatchControllerToKinematic(); void IInformDetectors(bool entering);
void ISetKinematicLoc(const hsMatrix44& l2w);
void IGetPositionSim(hsPoint3& pos) const;
void ICreateController();
void IDeleteController();
void IInformDetectors(bool entering,bool deferUntilNextSim);
void ICreateController(const hsPoint3& pos); void ICreateController(const hsPoint3& pos);
NxActor* fKinematicActor; void IDeleteController();
NxCapsuleController* fController;
void IDispatchQueuedMsgs();
void IProcessDynamicHits();
#ifndef PLASMA_EXTERNAL_RELEASE #ifndef PLASMA_EXTERNAL_RELEASE
hsTArray<plDbgCollisionInfo> fDbgCollisionInfo;
void IDrawDebugDisplay(); void IDrawDebugDisplay();
hsTArray<plDbgCollisionInfo> fDbgCollisionInfo;
#endif #endif
void IHandleResize();
float fPreferedRadius; std::vector<plCollideMsg*> fQueuedCollideMsgs;
float fPreferedHeight; std::vector<plPXPhysical*> fDynamicHits;
// The global position and rotation of the avatar last time we set it (so we
// can detect if someone else moves him) NxCapsuleController* fController;
NxActor* fActor;
plPhysicalProxy* fProxyGen; plPhysicalProxy* fProxyGen;
bool fBehavingLikeAnimatedPhys; bool fKinematicCCT;
}; };

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

@ -70,80 +70,26 @@ class SensorReport : public NxUserTriggerReport
{ {
virtual void onTrigger(NxShape& triggerShape, NxShape& otherShape, NxTriggerFlag status) virtual void onTrigger(NxShape& triggerShape, NxShape& otherShape, NxTriggerFlag status)
{ {
// Get our trigger physical. This should definitely have a plPXPhysical
plPXPhysical* triggerPhys = (plPXPhysical*)triggerShape.getActor().userData;
bool doReport = false;
// Get the triggerer. This may be an avatar, which doesn't have a
// plPXPhysical, so we have to extract the necessary info.
plKey otherKey = nil; plKey otherKey = nil;
hsPoint3 otherPos = plPXConvert::Point(otherShape.getGlobalPosition()); bool doReport = false;
if (plSimulationMgr::fExtraProfile) // Get our trigger physical. This should definitely have a plPXPhysical
DetectorLogRed("-->%s %s (status=%x) other@(%f,%f,%f)",triggerPhys->GetObjectKey()->GetName().c_str(),status & NX_TRIGGER_ON_ENTER ? "enter" : "exit",status,otherPos.fX,otherPos.fY,otherPos.fZ); plPXPhysical* triggerPhys = (plPXPhysical*)triggerShape.getActor().userData;
// Get the triggerer. If it doesn't have a plPXPhyscial, it's an avatar
plPXPhysical* otherPhys = (plPXPhysical*)otherShape.getActor().userData; plPXPhysical* otherPhys = (plPXPhysical*)otherShape.getActor().userData;
if (otherPhys) if (otherPhys)
{ {
otherKey = otherPhys->GetObjectKey(); otherKey = otherPhys->GetObjectKey();
doReport = triggerPhys->DoReportOn((plSimDefs::Group)otherPhys->GetGroup()); doReport = triggerPhys->DoReportOn((plSimDefs::Group)otherPhys->GetGroup());
if (!doReport)
{
if (plSimulationMgr::fExtraProfile)
DetectorLogRed("<--Kill collision %s :failed group. US=%x OTHER=(%s)%x",triggerPhys->GetObjectKey()->GetName().c_str(),triggerPhys->GetGroup(),otherPhys->GetObjectKey()->GetName().c_str(),otherPhys->GetGroup());
}
} }
else else
{ {
bool isController; plPXPhysicalControllerCore* controller = plPXPhysicalControllerCore::GetController(otherShape.getActor());
plPXPhysicalControllerCore* controller = plPXPhysicalControllerCore::GetController(otherShape.getActor(),&isController);
if (controller) if (controller)
{ {
if (isController)
{
#ifdef PHYSX_ONLY_TRIGGER_FROM_KINEMATIC
if (plSimulationMgr::fExtraProfile)
DetectorLogRed("<--Kill collision %s : ignoring controller events.",triggerPhys->GetObjectKey()->GetName().c_str());
return;
#else // else if trigger on both controller and kinematic
// only suppress controller collision 'enters' when disabled but let 'exits' continue
// ...this is because there are detector regions that are on the edge on ladders that the exit gets missed.
if ( ( !controller->IsEnabled() /*&& (status & NX_TRIGGER_ON_ENTER)*/ ) || controller->IsKinematic() )
{
if (plSimulationMgr::fExtraProfile)
DetectorLogRed("<--Kill collision %s : controller is not enabled.",triggerPhys->GetObjectKey()->GetName().c_str());
return;
}
#endif // PHYSX_ONLY_TRIGGER_FROM_KINEMATIC
}
#ifndef PHYSX_ONLY_TRIGGER_FROM_KINEMATIC // if triggering only kinematics, then all should trigger
else
{
// only suppress kinematic collision 'enters' when disabled but let 'exits' continue
// ...this is because there are detector regions that are on the edge on ladders that the exit gets missed.
if ( !controller->IsKinematic() /*&& (status & NX_TRIGGER_ON_ENTER) */ )
{
if (plSimulationMgr::fExtraProfile)
DetectorLogRed("<--Kill collision %s : kinematic is not enabled.",triggerPhys->GetObjectKey()->GetName().c_str());
return;
}
}
#endif // PHYSX_ONLY_TRIGGER_FROM_KINEMATIC
otherKey = controller->GetOwner(); otherKey = controller->GetOwner();
doReport = triggerPhys->DoReportOn(plSimDefs::kGroupAvatar); doReport = triggerPhys->DoReportOn(plSimDefs::kGroupAvatar);
if (plSimulationMgr::fExtraProfile )
{
if (!doReport)
{
DetectorLogRed("<--Kill collision %s :failed group. US=%x OTHER=(NotAvatar)",triggerPhys->GetObjectKey()->GetName().c_str(),triggerPhys->GetGroup());
}
else
{
hsPoint3 avpos;
controller->GetPositionSim(avpos);
DetectorLogRed("-->Avatar at (%f,%f,%f)",avpos.fX,avpos.fY,avpos.fZ);
}
}
} }
} }
@ -289,8 +235,8 @@ class ErrorStream : public NxUserOutputStream
// //
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
#define kDefaultMaxDelta 0.1 // if the step is greater than .1 seconds, clamp to that #define kDefaultMaxDelta (0.1) // if the step is greater than .1 seconds, clamp to that
#define kDefaultStepSize 1.f / 60.f // default simulation freqency is 60hz #define kDefaultStepSize (1.f / 60.f) // default simulation freqency is 60hz
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// //
@ -378,6 +324,7 @@ plSimulationMgr* plSimulationMgr::GetInstance()
plSimulationMgr::plSimulationMgr() plSimulationMgr::plSimulationMgr()
: fSuspended(true) : fSuspended(true)
, fAccumulator(0.0f)
, fLOSDispatch(new plLOSDispatch()) , fLOSDispatch(new plLOSDispatch())
, fSoundMgr(new plPhysicsSoundMgr) , fSoundMgr(new plPhysicsSoundMgr)
, fLog(nil) , fLog(nil)
@ -470,6 +417,7 @@ NxScene* plSimulationMgr::GetScene(plKey world)
scene->setGroupCollisionFlag(i, plSimDefs::kGroupDynamicBlocker, false); scene->setGroupCollisionFlag(i, plSimDefs::kGroupDynamicBlocker, false);
scene->setGroupCollisionFlag(i, plSimDefs::kGroupLOSOnly, false); scene->setGroupCollisionFlag(i, plSimDefs::kGroupLOSOnly, false);
scene->setGroupCollisionFlag(plSimDefs::kGroupLOSOnly, i, false); scene->setGroupCollisionFlag(plSimDefs::kGroupLOSOnly, i, false);
scene->setGroupCollisionFlag(i, plSimDefs::kGroupAvatarKinematic, false);
} }
scene->setGroupCollisionFlag(plSimDefs::kGroupAvatar, plSimDefs::kGroupAvatar, false); scene->setGroupCollisionFlag(plSimDefs::kGroupAvatar, plSimDefs::kGroupAvatar, false);
scene->setGroupCollisionFlag(plSimDefs::kGroupAvatar, plSimDefs::kGroupAvatarBlocker, true); scene->setGroupCollisionFlag(plSimDefs::kGroupAvatar, plSimDefs::kGroupAvatarBlocker, true);
@ -478,6 +426,10 @@ NxScene* plSimulationMgr::GetScene(plKey world)
scene->setGroupCollisionFlag( plSimDefs::kGroupStatic, plSimDefs::kGroupAvatar, true); scene->setGroupCollisionFlag( plSimDefs::kGroupStatic, plSimDefs::kGroupAvatar, true);
scene->setGroupCollisionFlag(plSimDefs::kGroupAvatar, plSimDefs::kGroupDynamic, true); scene->setGroupCollisionFlag(plSimDefs::kGroupAvatar, plSimDefs::kGroupDynamic, true);
// Kinematically controlled avatars interact with detectors and dynamics
scene->setGroupCollisionFlag(plSimDefs::kGroupAvatarKinematic, plSimDefs::kGroupDetector, true);
scene->setGroupCollisionFlag(plSimDefs::kGroupAvatarKinematic, plSimDefs::kGroupDynamic, true);
// The dynamics are in actor group 1, everything else is in 0. Request // The dynamics are in actor group 1, everything else is in 0. Request
// a callback for whenever a dynamic touches something. // a callback for whenever a dynamic touches something.
scene->setActorGroupPairFlags(0, 1, NX_NOTIFY_ON_TOUCH); scene->setActorGroupPairFlags(0, 1, NX_NOTIFY_ON_TOUCH);
@ -564,8 +516,7 @@ void plSimulationMgr::UpdateAvatarInDetector(plKey world, plPXPhysical* detector
if ( actors[i]->userData == nil ) if ( actors[i]->userData == nil )
{ {
// we go a controller // we go a controller
bool isController; plPXPhysicalControllerCore* controller = plPXPhysicalControllerCore::GetController(*actors[i]);
plPXPhysicalControllerCore* controller = plPXPhysicalControllerCore::GetController(*actors[i],&isController);
if (controller && controller->IsEnabled()) if (controller && controller->IsEnabled())
{ {
plKey avatar = controller->GetOwner(); plKey avatar = controller->GetOwner();
@ -614,20 +565,39 @@ void plSimulationMgr::AddCollisionMsg(plKey hitee, plKey hitter, bool enter)
pMsg->fEntering = enter; pMsg->fEntering = enter;
fCollideMsgs.push_back(pMsg); fCollideMsgs.push_back(pMsg);
} }
void plSimulationMgr::AddCollisionMsg(plCollideMsg* msg)
{
fCollideMsgs.push_back(msg);
}
void plSimulationMgr::Advance(float delSecs) void plSimulationMgr::Advance(float delSecs)
{ {
if (fSuspended) if (fSuspended)
return; return;
plProfile_IncCount(StepLen, (int)(delSecs*1000)); fAccumulator += delSecs;
if (fAccumulator < kDefaultStepSize)
{
// Not enough time has passed to perform a substep.
plPXPhysicalControllerCore::UpdateNonPhysical(fAccumulator / kDefaultStepSize);
return;
}
else if (fAccumulator > kDefaultMaxDelta)
{
if (fExtraProfile)
Log("Step clamped from %f to limit of %f", fAccumulator, kDefaultMaxDelta);
fAccumulator = kDefaultMaxDelta;
}
// Perform as many whole substeps as possible saving the remainder in our accumulator.
int numSubSteps = (int)(fAccumulator / kDefaultStepSize);
float delta = numSubSteps * kDefaultStepSize;
fAccumulator -= delta;
#ifndef PLASMA_EXTERNAL_RELASE plProfile_IncCount(StepLen, (int)(delta*1000));
uint32_t stepTime = hsTimer::GetPrecTickCount();
#endif
plProfile_BeginTiming(Step); plProfile_BeginTiming(Step);
plPXPhysicalControllerCore::UpdatePrestep(delSecs);
plPXPhysicalControllerCore::UpdatePoststep( delSecs); plPXPhysicalControllerCore::Apply(delta);
for (SceneMap::iterator it = fScenes.begin(); it != fScenes.end(); it++) for (SceneMap::iterator it = fScenes.begin(); it != fScenes.end(); it++)
{ {
@ -642,12 +612,13 @@ void plSimulationMgr::Advance(float delSecs)
} }
if (do_advance) if (do_advance)
{ {
scene->simulate(delSecs); scene->simulate(delta);
scene->flushStream(); scene->flushStream();
scene->fetchResults(NX_RIGID_BODY_FINISHED, true); scene->fetchResults(NX_RIGID_BODY_FINISHED, true);
} }
} }
plPXPhysicalControllerCore::UpdatePostSimStep(delSecs);
plPXPhysicalControllerCore::Update(numSubSteps, fAccumulator / kDefaultStepSize);
plProfile_EndTiming(Step); plProfile_EndTiming(Step);
#ifndef PLASMA_EXTERNAL_RELEASE #ifndef PLASMA_EXTERNAL_RELEASE
@ -730,9 +701,6 @@ void plSimulationMgr::ISendUpdates()
plPXPhysical* physical = (plPXPhysical*)actors[i]->userData; plPXPhysical* physical = (plPXPhysical*)actors[i]->userData;
if (physical) if (physical)
{ {
// apply any hit forces
physical->ApplyHitForce();
if (physical->GetSceneNode()) if (physical->GetSceneNode())
{ {
physical->SendNewLocation(); physical->SendNewLocation();

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

@ -105,6 +105,7 @@ public:
//Fix to Move collision messages and their handling out of the simulation step //Fix to Move collision messages and their handling out of the simulation step
void AddCollisionMsg(plKey hitee, plKey hitter, bool entering); void AddCollisionMsg(plKey hitee, plKey hitter, bool entering);
void AddCollisionMsg(plCollideMsg* msg);
#ifndef PLASMA_EXTERNAL_RELEASE #ifndef PLASMA_EXTERNAL_RELEASE
static bool fDisplayAwakeActors; static bool fDisplayAwakeActors;
@ -144,6 +145,8 @@ protected:
// but nothing will move. // but nothing will move.
bool fSuspended; bool fSuspended;
float fAccumulator;
// A utility class to keep track of a request for a physical synchronization. // A utility class to keep track of a request for a physical synchronization.
// These requests must pass a certain criteria (see the code for the latest) // These requests must pass a certain criteria (see the code for the latest)
// before they are actually either sent over the network or rejected. // before they are actually either sent over the network or rejected.

4
Sources/Plasma/PubUtilLib/plPhysical/plSimDefs.h

@ -68,8 +68,10 @@ namespace plSimDefs
kGroupLOSOnly, kGroupLOSOnly,
//kExcludeRegion setting up so only blocks avatars and only when not in seek mode //kExcludeRegion setting up so only blocks avatars and only when not in seek mode
kGroupExcludeRegion, kGroupExcludeRegion,
// A kinematic avatar only interacts with dynamics and detectors
kGroupAvatarKinematic,
// Just for error checking // Just for error checking
kGroupMax, kGroupMax
}; };
/** Different types of line-of-sight requests. */ /** Different types of line-of-sight requests. */

Loading…
Cancel
Save