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. 1402
      Sources/Plasma/PubUtilLib/plPhysX/plPXPhysicalControllerCore.cpp
  5. 154
      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
{
bool isController;
plPXPhysicalControllerCore* controller = plPXPhysicalControllerCore::GetController(hitActor,&isController);
plPXPhysicalControllerCore* controller = plPXPhysicalControllerCore::GetController(hitActor);
if (controller)
{
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

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

File diff suppressed because it is too large Load Diff

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

@ -40,22 +40,19 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include "plAvatar/plPhysicalControllerCore.h"
#include "hsQuat.h"
#define PHYSX_ONLY_TRIGGER_FROM_KINEMATIC 1
class NxController;
class NxCapsuleController;
class NxActor;
class plCoordinateInterface;
class NxCapsule;
class PXControllerHitReport;
class plPhysicalProxy;
class plDrawableSpans;
class hsGMaterial;
class NxCapsule;
class plSceneObject;
class PXControllerHitReportWalk;
class plPXPhysical;
class plCollideMsg;
#ifndef PLASMA_EXTERNAL_RELEASE
#ifndef PLASMA_EXTERNAL_RELEASE
class plDbgCollisionInfo
{
public:
@ -64,97 +61,112 @@ public:
bool fOverlap;
};
#endif // PLASMA_EXTERNAL_RELEASE
class plPXPhysicalControllerCore: public plPhysicalControllerCore
{
friend class PXControllerHitReportWalk;
public:
plPXPhysicalControllerCore(plKey ownerSO, float height, float radius);
~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);
// A disabled avatar doesn't move or accumulate air time if he's off the ground.
// An ArmatureMod has its own idea about when physics should be enabled/disabled.
// Use plArmatureModBase::EnablePhysics() instead.
virtual void Enable(bool enable);
virtual void SetSubworld(plKey world) ;
virtual const plCoordinateInterface* GetSubworldCI() const ;
// Subworld
virtual void SetSubworld(plKey world);
// For the avatar SDL only
virtual void GetState(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);
virtual bool IsKinematic();
virtual void GetKinematicPosition(hsPoint3& pos);
virtual const hsMatrix44& GetPrevSubworldW2L(){ return fPrevSubworldW2L; }
//when seeking no longer want to interact with exclusion regions
virtual void GetWorldSpaceCapsule(NxCapsule& cap) const;
static void RebuildCache();
virtual const hsMatrix44& GetLastGlobalLoc(){return fLastGlobalLoc;}
virtual void SetKinematicLoc(const hsMatrix44& l2w){ISetKinematicLoc(l2w);}
virtual void SetGlobalLoc(const hsMatrix44& l2w){ISetGlobalLoc(l2w);}
virtual void HandleEnableChanged();
virtual void HandleKinematicChanged();
virtual void HandleKinematicEnableNextUpdate();
virtual void GetPositionSim(hsPoint3& pos){IGetPositionSim(pos);}
virtual void MoveKinematicToController(hsPoint3& pos);
virtual const hsPoint3& GetLocalPosition(){return fLocalPosition;}
virtual void SetControllerDimensions(float radius, float height);
// Movement strategy
virtual void SetMovementStrategy(plMovementStrategy* strategy);
// Global location
virtual void SetGlobalLoc(const hsMatrix44& l2w);
// Local Sim Position
virtual void GetPositionSim(hsPoint3& pos);
// Move kinematic controller
virtual void Move(hsVector3 displacement, unsigned int collideWith, unsigned int &collisionResults);
// Set linear velocity on dynamic controller
virtual void SetLinearVelocitySim(const hsVector3& linearVel);
// Sweep the controller path from startPos through endPos
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 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
////////////////////////////////////////
// Used by the LOS mgr to find the controller for an actor it hit
static plPXPhysicalControllerCore* GetController(NxActor& actor, bool* isController);
// test to see if there are any controllers (i.e. avatars) in this subworld
// Call pre-sim to apply movement to controllers
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 int NumControllers();
static int GetControllersInThisSubWorld(plKey world, int maxToReturn,
plPXPhysicalControllerCore** bufferout);
static int GetNumberOfControllersInThisSubWorld(plKey world);
static void UpdatePrestep(float delSecs);
static void UpdatePoststep(float delSecs);
static void UpdatePostSimStep(float delSecs);
virtual plDrawableSpans* CreateProxy(hsGMaterial* mat, hsTArray<uint32_t>& idx, plDrawableSpans* addTo);
#ifndef PLASMA_EXTERNAL_RELEASE
static bool fDebugDisplay;
#endif // PLASMA_EXTERNAL_RELEASE
static int GetControllersInThisSubWorld(plKey world, int maxToReturn, plPXPhysicalControllerCore** bufferout);
// Controller count
static int NumControllers();
static void SetMaxNumberOfControllers(int max) { fPXControllersMax = max; }
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);
//should actually be a 3 vector but everywhere else it is assumed to be just around Z
virtual void SetAngularVelocity(const float angvel);
virtual void SetVelocities(const hsVector3& linearVel, float angVel);
#ifndef PLASMA_EXTERNAL_RELEASE
static bool fDebugDisplay;
#endif
protected:
friend class PXControllerHitReport;
static plPXPhysicalControllerCore* FindController(NxController* controller);
void ISetGlobalLoc(const hsMatrix44& l2w);
void IMatchKinematicToController();
void IMatchControllerToKinematic();
void ISetKinematicLoc(const hsMatrix44& l2w);
void IGetPositionSim(hsPoint3& pos) const;
void ICreateController();
void IDeleteController();
void IInformDetectors(bool entering,bool deferUntilNextSim);
virtual void IHandleEnableChanged();
void IInformDetectors(bool entering);
void ICreateController(const hsPoint3& pos);
NxActor* fKinematicActor;
NxCapsuleController* fController;
void IDeleteController();
void IDispatchQueuedMsgs();
void IProcessDynamicHits();
#ifndef PLASMA_EXTERNAL_RELEASE
hsTArray<plDbgCollisionInfo> fDbgCollisionInfo;
void IDrawDebugDisplay();
hsTArray<plDbgCollisionInfo> fDbgCollisionInfo;
#endif
void IHandleResize();
float fPreferedRadius;
float fPreferedHeight;
// The global position and rotation of the avatar last time we set it (so we
// can detect if someone else moves him)
std::vector<plCollideMsg*> fQueuedCollideMsgs;
std::vector<plPXPhysical*> fDynamicHits;
NxCapsuleController* fController;
NxActor* fActor;
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)
{
// 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;
hsPoint3 otherPos = plPXConvert::Point(otherShape.getGlobalPosition());
bool doReport = false;
if (plSimulationMgr::fExtraProfile)
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);
// Get our trigger physical. This should definitely have a plPXPhysical
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;
if (otherPhys)
{
otherKey = otherPhys->GetObjectKey();
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
{
bool isController;
plPXPhysicalControllerCore* controller = plPXPhysicalControllerCore::GetController(otherShape.getActor(),&isController);
plPXPhysicalControllerCore* controller = plPXPhysicalControllerCore::GetController(otherShape.getActor());
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();
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 kDefaultStepSize 1.f / 60.f // default simulation freqency is 60hz
#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
/////////////////////////////////////////////////////////////////
//
@ -378,6 +324,7 @@ plSimulationMgr* plSimulationMgr::GetInstance()
plSimulationMgr::plSimulationMgr()
: fSuspended(true)
, fAccumulator(0.0f)
, fLOSDispatch(new plLOSDispatch())
, fSoundMgr(new plPhysicsSoundMgr)
, fLog(nil)
@ -470,6 +417,7 @@ NxScene* plSimulationMgr::GetScene(plKey world)
scene->setGroupCollisionFlag(i, plSimDefs::kGroupDynamicBlocker, false);
scene->setGroupCollisionFlag(i, plSimDefs::kGroupLOSOnly, 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::kGroupAvatarBlocker, true);
@ -478,6 +426,10 @@ NxScene* plSimulationMgr::GetScene(plKey world)
scene->setGroupCollisionFlag( plSimDefs::kGroupStatic, plSimDefs::kGroupAvatar, 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
// a callback for whenever a dynamic touches something.
scene->setActorGroupPairFlags(0, 1, NX_NOTIFY_ON_TOUCH);
@ -564,8 +516,7 @@ void plSimulationMgr::UpdateAvatarInDetector(plKey world, plPXPhysical* detector
if ( actors[i]->userData == nil )
{
// we go a controller
bool isController;
plPXPhysicalControllerCore* controller = plPXPhysicalControllerCore::GetController(*actors[i],&isController);
plPXPhysicalControllerCore* controller = plPXPhysicalControllerCore::GetController(*actors[i]);
if (controller && controller->IsEnabled())
{
plKey avatar = controller->GetOwner();
@ -614,20 +565,39 @@ void plSimulationMgr::AddCollisionMsg(plKey hitee, plKey hitter, bool enter)
pMsg->fEntering = enter;
fCollideMsgs.push_back(pMsg);
}
void plSimulationMgr::AddCollisionMsg(plCollideMsg* msg)
{
fCollideMsgs.push_back(msg);
}
void plSimulationMgr::Advance(float delSecs)
{
if (fSuspended)
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;
}
#ifndef PLASMA_EXTERNAL_RELASE
uint32_t stepTime = hsTimer::GetPrecTickCount();
#endif
// Perform as many whole substeps as possible saving the remainder in our accumulator.
int numSubSteps = (int)(fAccumulator / kDefaultStepSize);
float delta = numSubSteps * kDefaultStepSize;
fAccumulator -= delta;
plProfile_IncCount(StepLen, (int)(delta*1000));
plProfile_BeginTiming(Step);
plPXPhysicalControllerCore::UpdatePrestep(delSecs);
plPXPhysicalControllerCore::UpdatePoststep( delSecs);
plPXPhysicalControllerCore::Apply(delta);
for (SceneMap::iterator it = fScenes.begin(); it != fScenes.end(); it++)
{
@ -642,12 +612,13 @@ void plSimulationMgr::Advance(float delSecs)
}
if (do_advance)
{
scene->simulate(delSecs);
scene->simulate(delta);
scene->flushStream();
scene->fetchResults(NX_RIGID_BODY_FINISHED, true);
}
}
plPXPhysicalControllerCore::UpdatePostSimStep(delSecs);
plPXPhysicalControllerCore::Update(numSubSteps, fAccumulator / kDefaultStepSize);
plProfile_EndTiming(Step);
#ifndef PLASMA_EXTERNAL_RELEASE
@ -730,9 +701,6 @@ void plSimulationMgr::ISendUpdates()
plPXPhysical* physical = (plPXPhysical*)actors[i]->userData;
if (physical)
{
// apply any hit forces
physical->ApplyHitForce();
if (physical->GetSceneNode())
{
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
void AddCollisionMsg(plKey hitee, plKey hitter, bool entering);
void AddCollisionMsg(plCollideMsg* msg);
#ifndef PLASMA_EXTERNAL_RELEASE
static bool fDisplayAwakeActors;
@ -144,6 +145,8 @@ protected:
// but nothing will move.
bool fSuspended;
float fAccumulator;
// 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)
// 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,
//kExcludeRegion setting up so only blocks avatars and only when not in seek mode
kGroupExcludeRegion,
// A kinematic avatar only interacts with dynamics and detectors
kGroupAvatarKinematic,
// Just for error checking
kGroupMax,
kGroupMax
};
/** Different types of line-of-sight requests. */

Loading…
Cancel
Save