mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 02:27:40 -04:00
Initial Commit of CyanWorlds.com Engine Open Source Client/Plugin
This commit is contained in:
@ -0,0 +1,296 @@
|
||||
/*==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/>.
|
||||
|
||||
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==*/
|
||||
#include "plLOSDispatch.h"
|
||||
#include "plSimulationMgr.h"
|
||||
#include "plgDispatch.h"
|
||||
#include "../plMessage/plLOSRequestMsg.h"
|
||||
#include "../plMessage/plLOSHitMsg.h"
|
||||
#include "../pnKeyedObject/plFixedKey.h"
|
||||
#include "../pnSceneObject/plSceneObject.h"
|
||||
#include "../plModifier/plLogicModifier.h"
|
||||
#include "plPXPhysical.h"
|
||||
#include "plPXPhysicalControllerCore.h"
|
||||
#include "plPXConvert.h"
|
||||
|
||||
#include "../plAvatar/plAvatarMgr.h"
|
||||
#include "../plAvatar/plArmatureMod.h"
|
||||
|
||||
#include "NxPhysics.h"
|
||||
|
||||
#include "plProfile.h"
|
||||
plProfile_Extern(LineOfSight);
|
||||
|
||||
class myRaycastReport : public NxUserRaycastReport
|
||||
{
|
||||
public:
|
||||
void InitCast(plSimDefs::plLOSDB db, plLOSRequestMsg::TestType type)
|
||||
{
|
||||
fDB = db;
|
||||
fType = type;
|
||||
fHitObj = nil;
|
||||
fNormal.Set(0, 0, 0);
|
||||
fPoint.Set(0, 0, 0);
|
||||
fDist = FLT_MAX;
|
||||
}
|
||||
|
||||
bool GotHit() { return fDist != FLT_MAX; }
|
||||
plKey GetObj() { return fHitObj; }
|
||||
hsScalar GetDistance() { return fDist; }
|
||||
const hsVector3& GetNormal() { return fNormal; }
|
||||
const hsPoint3& GetPoint() { return fPoint; }
|
||||
void ResetHitObj(){fHitObj=nil;}
|
||||
private:
|
||||
virtual bool onHit(const NxRaycastHit& hit)
|
||||
{
|
||||
NxActor& hitActor = hit.shape->getActor();
|
||||
plPXPhysical* phys = (plPXPhysical*)hitActor.userData;
|
||||
|
||||
plKey objKey = nil;
|
||||
UInt16 objDB = plSimDefs::kLOSDBNone;
|
||||
|
||||
if (phys)
|
||||
{
|
||||
objKey = phys->GetObjectKey();
|
||||
objDB = phys->GetAllLOSDBs();
|
||||
}
|
||||
else
|
||||
{
|
||||
bool isController;
|
||||
plPXPhysicalControllerCore* controller = plPXPhysicalControllerCore::GetController(hitActor,&isController);
|
||||
if (controller)
|
||||
{
|
||||
objKey = controller->GetOwner();
|
||||
objDB = controller->GetLOSDB();
|
||||
}
|
||||
}
|
||||
|
||||
// is the object's physic enabled and is it in the database that we are looking for?
|
||||
if ( !phys || !phys->GetProperty(plSimulationInterface::kDisable) )
|
||||
{
|
||||
if ( (fDB & objDB) != 0)
|
||||
{
|
||||
if (fType == plLOSRequestMsg::kTestAny || hit.distance < fDist)
|
||||
{
|
||||
// need one more test... if it is a clickable need to see if it is enabled
|
||||
bool disabled = false;
|
||||
if ( objKey )
|
||||
{
|
||||
plSceneObject* so = plSceneObject::ConvertNoRef( objKey->GetObjectPtr() );
|
||||
if (so)
|
||||
{
|
||||
int i;
|
||||
for ( i=0; i < so->GetNumModifiers(); i++)
|
||||
{
|
||||
plLogicModifier* lo = (plLogicModifier*)plLogicModifier::ConvertNoRef(so->GetModifier(i) );
|
||||
if (lo)
|
||||
{
|
||||
disabled = lo->Disabled();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!disabled)
|
||||
{
|
||||
fHitObj = objKey;
|
||||
fNormal.Set(hit.worldNormal.x, hit.worldNormal.y, hit.worldNormal.z);
|
||||
fPoint.Set(hit.worldImpact.x, hit.worldImpact.y, hit.worldImpact.z);
|
||||
fDist = hit.distance;
|
||||
|
||||
if (fType == plLOSRequestMsg::kTestAny)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
plSimDefs::plLOSDB fDB;
|
||||
plLOSRequestMsg::TestType fType;
|
||||
|
||||
plKey fHitObj;
|
||||
hsVector3 fNormal;
|
||||
hsPoint3 fPoint;
|
||||
hsScalar fDist;
|
||||
} gMyReport;
|
||||
|
||||
plLOSDispatch::plLOSDispatch()
|
||||
{
|
||||
RegisterAs(kLOSObject_KEY);
|
||||
plgDispatch::Dispatch()->RegisterForExactType(plLOSRequestMsg::Index(), GetKey());
|
||||
}
|
||||
|
||||
plLOSDispatch::~plLOSDispatch()
|
||||
{
|
||||
plgDispatch::Dispatch()->UnRegisterForExactType(plLOSRequestMsg::Index(), GetKey());
|
||||
}
|
||||
|
||||
hsBool plLOSDispatch::MsgReceive(plMessage* msg)
|
||||
{
|
||||
|
||||
plLOSRequestMsg* requestMsg = plLOSRequestMsg::ConvertNoRef(msg);
|
||||
if (requestMsg)
|
||||
{
|
||||
plProfile_BeginTiming(LineOfSight);
|
||||
|
||||
plSimulationMgr* sim = plSimulationMgr::GetInstance();
|
||||
|
||||
plKey worldKey = requestMsg->fWorldKey;
|
||||
if (!worldKey)
|
||||
{
|
||||
plArmatureMod* av = plAvatarMgr::GetInstance()->GetLocalAvatar();
|
||||
if ( av && av->GetController() )
|
||||
worldKey = av->GetController()->GetSubworld();
|
||||
}
|
||||
|
||||
hsPoint3 from = requestMsg->fFrom;
|
||||
hsPoint3 at = requestMsg->fTo;
|
||||
|
||||
// requests are always sent in world space, but they might
|
||||
// need to be converted to subworld space
|
||||
hsMatrix44 l2w, w2l;
|
||||
if (worldKey)
|
||||
{
|
||||
plSceneObject* so = plSceneObject::ConvertNoRef(worldKey->ObjectIsLoaded());
|
||||
if (so)
|
||||
{
|
||||
l2w = so->GetLocalToWorld();
|
||||
w2l = so->GetWorldToLocal();
|
||||
from = w2l * from;
|
||||
at = w2l * at;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
l2w.Reset();
|
||||
w2l.Reset();
|
||||
}
|
||||
|
||||
NxScene* scene = sim->GetScene(worldKey);
|
||||
|
||||
gMyReport.InitCast(requestMsg->GetRequestType(), requestMsg->GetTestType());
|
||||
|
||||
hsVector3 norm = hsVector3(at - from);
|
||||
hsScalar dist = norm.Magnitude();
|
||||
norm.Normalize();
|
||||
|
||||
NxRay worldRay;
|
||||
worldRay.dir = plPXConvert::Vector(norm);
|
||||
worldRay.orig = plPXConvert::Point(from);
|
||||
//PhysX will complain to log if ray distance is less than or equal to Zero, besides shouldn't bother throwing
|
||||
// a point, and if we have negative we have some serious problems
|
||||
if(dist>0.0f)
|
||||
{
|
||||
scene->raycastAllShapes(worldRay, gMyReport, NX_ALL_SHAPES, 0xffffffff, dist, NX_RAYCAST_DISTANCE | NX_RAYCAST_IMPACT | NX_RAYCAST_NORMAL);
|
||||
}
|
||||
else{
|
||||
SimLog("%s sent out a LOS request with a ray length of %d.", requestMsg->GetSender()->GetName(), dist);
|
||||
}
|
||||
if (gMyReport.GotHit())
|
||||
{
|
||||
// We got a hit, save off the info
|
||||
plMessage* hitMsg = ICreateHitMsg(requestMsg, l2w);
|
||||
|
||||
if (requestMsg->GetCullDB() != plSimDefs::kLOSDBNone)
|
||||
{
|
||||
// If we have a cull db, adjust the length of the raycast to be from the
|
||||
// original point to the object we hit. If we find anything from the cull
|
||||
// db in there, the cast fails.
|
||||
hsScalar dist = gMyReport.GetDistance();
|
||||
if(dist!=0.0)
|
||||
{
|
||||
gMyReport.InitCast(requestMsg->GetCullDB(), plLOSRequestMsg::kTestAny);
|
||||
scene->raycastAllShapes(worldRay, gMyReport, NX_ALL_SHAPES, 0xffffffff, dist, NX_RAYCAST_DISTANCE | NX_RAYCAST_IMPACT | NX_RAYCAST_NORMAL);
|
||||
|
||||
if (gMyReport.GotHit())
|
||||
{
|
||||
delete hitMsg;
|
||||
hitMsg = nil;
|
||||
|
||||
if (requestMsg->GetReportType() == plLOSRequestMsg::kReportMiss ||
|
||||
requestMsg->GetReportType() == plLOSRequestMsg::kReportHitOrMiss)
|
||||
{
|
||||
ICreateMissMsg(requestMsg)->Send();
|
||||
}
|
||||
}
|
||||
}
|
||||
else// we are right on top of the object I assume that means we hit it
|
||||
{// since PhysX would have complained we will log it anyways. Just so we have a better idea, where this
|
||||
//was happening previously
|
||||
SimLog("%s sent out a LOS request. The second cast for culling was of length 0. ABORTING and assuming hit.", requestMsg->GetSender()->GetName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (hitMsg &&
|
||||
(requestMsg->GetReportType() == plLOSRequestMsg::kReportHit ||
|
||||
requestMsg->GetReportType() == plLOSRequestMsg::kReportHitOrMiss))
|
||||
hitMsg->Send();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (requestMsg->GetReportType() == plLOSRequestMsg::kReportMiss ||
|
||||
requestMsg->GetReportType() == plLOSRequestMsg::kReportHitOrMiss)
|
||||
{
|
||||
ICreateMissMsg(requestMsg)->Send();
|
||||
}
|
||||
}
|
||||
|
||||
plProfile_EndTiming(LineOfSight);
|
||||
gMyReport.ResetHitObj();
|
||||
return true;
|
||||
}
|
||||
|
||||
return hsKeyedObject::MsgReceive(msg);
|
||||
}
|
||||
|
||||
plMessage* plLOSDispatch::ICreateHitMsg(plLOSRequestMsg* requestMsg, hsMatrix44& l2w)
|
||||
{
|
||||
plKey ourKey = GetKey();
|
||||
plKey rcvKey = requestMsg->GetSender();
|
||||
plLOSHitMsg* hitMsg = TRACKED_NEW plLOSHitMsg(ourKey, rcvKey, nil);
|
||||
hitMsg->fNoHit = false;
|
||||
hitMsg->fObj = gMyReport.GetObj();
|
||||
hitMsg->fDistance = gMyReport.GetDistance();
|
||||
hitMsg->fNormal = l2w * gMyReport.GetNormal();
|
||||
hitMsg->fHitPoint = l2w * gMyReport.GetPoint();
|
||||
hitMsg->fRequestID = requestMsg->GetRequestID();
|
||||
return hitMsg;
|
||||
}
|
||||
|
||||
plMessage* plLOSDispatch::ICreateMissMsg(plLOSRequestMsg* requestMsg)
|
||||
{
|
||||
plKey ourKey = GetKey();
|
||||
plKey rcvKey = requestMsg->GetSender();
|
||||
plLOSHitMsg* missMsg = TRACKED_NEW plLOSHitMsg(ourKey, rcvKey, nil);
|
||||
missMsg->fNoHit = true;
|
||||
missMsg->fObj = nil;
|
||||
missMsg->fRequestID = requestMsg->GetRequestID();
|
||||
return missMsg;
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*==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/>.
|
||||
|
||||
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==*/
|
||||
#include "../pnKeyedObject/hsKeyedObject.h"
|
||||
|
||||
class plLOSRequestMsg;
|
||||
struct hsMatrix44;
|
||||
|
||||
/** \class plLOSDispatch
|
||||
Line-of-sight requests are sent to this guy, who then hands them
|
||||
to the appropriate solvers, which can vary depending on such
|
||||
criteria as which subworld the player is currently in.
|
||||
Eventually we will have more variants of requests, such as
|
||||
"search all subworlds," etc. */
|
||||
class plLOSDispatch : public hsKeyedObject
|
||||
{
|
||||
public:
|
||||
plLOSDispatch();
|
||||
~plLOSDispatch();
|
||||
|
||||
CLASSNAME_REGISTER(plLOSDispatch);
|
||||
GETINTERFACE_ANY(plLOSDispatch, hsKeyedObject);
|
||||
|
||||
virtual hsBool MsgReceive(plMessage* msg);
|
||||
|
||||
protected:
|
||||
plMessage* ICreateHitMsg(plLOSRequestMsg* requestMsg, hsMatrix44& l2w);
|
||||
plMessage* ICreateMissMsg(plLOSRequestMsg* requestMsg);
|
||||
};
|
@ -0,0 +1,66 @@
|
||||
/*==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/>.
|
||||
|
||||
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==*/
|
||||
#include "plPXConvert.h"
|
||||
|
||||
bool plPXConvert::Validate()
|
||||
{
|
||||
NxVec3 nxVec;
|
||||
hsVector3 plVec;
|
||||
|
||||
int nxVecXOffset = ((char*)&nxVec.x) - ((char*)&nxVec);
|
||||
int nxVecYOffset = ((char*)&nxVec.y) - ((char*)&nxVec);
|
||||
int nxVecZOffset = ((char*)&nxVec.z) - ((char*)&nxVec);
|
||||
|
||||
int plVecXOffset = ((char*)&plVec.fX) - ((char*)&plVec);
|
||||
int plVecYOffset = ((char*)&plVec.fY) - ((char*)&plVec);
|
||||
int plVecZOffset = ((char*)&plVec.fZ) - ((char*)&plVec);
|
||||
|
||||
NxQuat nxQuat;
|
||||
hsQuat plQuat;
|
||||
|
||||
int nxQuatXOffset = ((char*)&nxQuat.x) - ((char*)&nxQuat);
|
||||
int nxQuatYOffset = ((char*)&nxQuat.y) - ((char*)&nxQuat);
|
||||
int nxQuatZOffset = ((char*)&nxQuat.z) - ((char*)&nxQuat);
|
||||
int nxQuatWOffset = ((char*)&nxQuat.w) - ((char*)&nxQuat);
|
||||
|
||||
int plQuatXOffset = ((char*)&plQuat.fX) - ((char*)&plQuat);
|
||||
int plQuatYOffset = ((char*)&plQuat.fY) - ((char*)&plQuat);
|
||||
int plQuatZOffset = ((char*)&plQuat.fZ) - ((char*)&plQuat);
|
||||
int plQuatWOffset = ((char*)&plQuat.fW) - ((char*)&plQuat);
|
||||
|
||||
bool offsetsOK =
|
||||
nxVecXOffset == plVecXOffset &&
|
||||
nxVecYOffset == plVecYOffset &&
|
||||
nxVecZOffset == plVecZOffset &&
|
||||
nxQuatXOffset == plQuatXOffset &&
|
||||
nxQuatYOffset == plQuatYOffset &&
|
||||
nxQuatZOffset == plQuatZOffset &&
|
||||
nxQuatWOffset == plQuatWOffset;
|
||||
|
||||
hsAssert(offsetsOK, "PhysX or Plasma offsets have changed, need to rewrite conversion code");
|
||||
|
||||
return offsetsOK;
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*==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/>.
|
||||
|
||||
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 plPXConvert_h_inc
|
||||
#define plPXConvert_h_inc
|
||||
|
||||
#include "hsGeometry3.h"
|
||||
#include "hsQuat.h"
|
||||
#include "hsMatrix44.h"
|
||||
|
||||
#include "NxVec3.h"
|
||||
#include "NxQuat.h"
|
||||
#include "NxMat34.h"
|
||||
|
||||
// Converts to and from the PhysX types
|
||||
namespace plPXConvert
|
||||
{
|
||||
// The following conversions are just casts, due to the fact that the Plasma
|
||||
// and PhysX vector and quat classes don't have any virtual fuctions and have
|
||||
// all their data in the same offsets.
|
||||
inline NxVec3& Point(hsPoint3& vec) { return *((NxVec3*)&vec); }
|
||||
inline const NxVec3& Point(const hsPoint3& vec) { return *((NxVec3*)&vec); }
|
||||
inline hsPoint3& Point(NxVec3& vec) { return *((hsPoint3*)&vec); }
|
||||
inline const hsPoint3& Point(const NxVec3& vec) { return *((hsPoint3*)&vec); }
|
||||
|
||||
inline NxVec3& Vector(hsVector3& vel) { return *((NxVec3*)&vel); }
|
||||
inline const NxVec3& Vector(const hsVector3& vel){ return *((NxVec3*)&vel); }
|
||||
inline hsVector3& Vector(NxVec3& vec) { return *((hsVector3*)&vec); }
|
||||
inline const hsVector3& Vector(const NxVec3& vec) { return *((hsVector3*)&vec); }
|
||||
|
||||
inline const NxQuat& Quat(const hsQuat& quat) { return *((NxQuat*)&quat); }
|
||||
inline const hsQuat& Quat(const NxQuat& quat) { return *((hsQuat*)&quat); }
|
||||
|
||||
// The matrix data doesn't match up, so we have to convert it
|
||||
inline void Matrix(const hsMatrix44& fromMat, NxMat34& toMat) { toMat.setRowMajor44(&fromMat.fMap[0][0]); }
|
||||
inline void Matrix(const NxMat34& fromMat, hsMatrix44& toMat) { toMat.NotIdentity(); fromMat.getRowMajor44(&toMat.fMap[0][0]); }
|
||||
|
||||
bool Validate();
|
||||
};
|
||||
|
||||
#endif // plPXConvert_h_inc
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,277 @@
|
||||
/*==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/>.
|
||||
|
||||
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 plPXPhysical_h_inc
|
||||
#define plPXPhysical_h_inc
|
||||
|
||||
#include "plPhysical.h"
|
||||
#include "hsMatrix44.h"
|
||||
#include "../plPhysical/plSimDefs.h"
|
||||
#include "hsBitVector.h"
|
||||
#include "hsUtils.h"
|
||||
|
||||
class NxActor;
|
||||
class NxConvexMesh;
|
||||
class NxTriangleMesh;
|
||||
|
||||
struct hsPoint3;
|
||||
class hsQuat;
|
||||
class plPhysicalProxy;
|
||||
class plDrawableSpans;
|
||||
class hsGMaterial;
|
||||
struct hsPlane3;
|
||||
|
||||
class plMessage;
|
||||
class plLOSHit;
|
||||
class plSimulationMsg;
|
||||
class plSDLModifier;
|
||||
class plPhysicalSndGroup;
|
||||
class plGenRefMsg;
|
||||
class plSceneObject;
|
||||
class hsVectorStream;
|
||||
class NxCapsule;
|
||||
|
||||
class PhysRecipe
|
||||
{
|
||||
public:
|
||||
PhysRecipe();
|
||||
|
||||
hsScalar mass;
|
||||
hsScalar friction;
|
||||
hsScalar restitution;
|
||||
plSimDefs::Bounds bounds;
|
||||
plSimDefs::Group group;
|
||||
UInt32 reportsOn;
|
||||
plKey objectKey;
|
||||
plKey sceneNode;
|
||||
plKey worldKey;
|
||||
|
||||
// The local to subworld matrix (or local to world if worldKey is nil)
|
||||
hsMatrix44 l2s;
|
||||
|
||||
NxConvexMesh* convexMesh;
|
||||
NxTriangleMesh* triMesh;
|
||||
|
||||
// For spheres only
|
||||
hsScalar radius;
|
||||
hsPoint3 offset;
|
||||
|
||||
// For Boxes
|
||||
hsPoint3 bDimensions;
|
||||
hsPoint3 bOffset;
|
||||
|
||||
// For export time only. The original data used to create the mesh
|
||||
hsVectorStream* meshStream;
|
||||
};
|
||||
|
||||
class plPXPhysical : public plPhysical
|
||||
{
|
||||
public:
|
||||
friend class plSimulationMgr;
|
||||
|
||||
enum PhysRefType
|
||||
{
|
||||
kPhysRefWorld,
|
||||
kPhysRefSndGroup
|
||||
};
|
||||
|
||||
plPXPhysical();
|
||||
virtual ~plPXPhysical();
|
||||
|
||||
CLASSNAME_REGISTER(plPXPhysical);
|
||||
GETINTERFACE_ANY(plPXPhysical, plPhysical);
|
||||
|
||||
// Export time and internal use only
|
||||
hsBool Init(PhysRecipe& recipe);
|
||||
|
||||
virtual void Read(hsStream* s, hsResMgr* mgr);
|
||||
virtual void Write(hsStream* s, hsResMgr* mgr);
|
||||
|
||||
virtual hsBool MsgReceive(plMessage* msg);
|
||||
|
||||
//
|
||||
// From plPhysical
|
||||
//
|
||||
virtual plPhysical& SetProperty(int prop, hsBool b);
|
||||
virtual hsBool GetProperty(int prop) const { return fProps.IsBitSet(prop) != 0; }
|
||||
|
||||
virtual void SetObjectKey(plKey key) { fObjectKey = key; }
|
||||
virtual plKey GetObjectKey() const { return fObjectKey; }
|
||||
|
||||
virtual void SetSceneNode(plKey node);
|
||||
virtual plKey GetSceneNode() const;
|
||||
|
||||
virtual hsBool GetLinearVelocitySim(hsVector3& vel) const;
|
||||
virtual void SetLinearVelocitySim(const hsVector3& vel);
|
||||
virtual void ClearLinearVelocity();
|
||||
|
||||
virtual hsBool GetAngularVelocitySim(hsVector3& vel) const;
|
||||
virtual void SetAngularVelocitySim(const hsVector3& vel);
|
||||
|
||||
virtual void SetTransform(const hsMatrix44& l2w, const hsMatrix44& w2l, hsBool force=false);
|
||||
virtual void GetTransform(hsMatrix44& l2w, hsMatrix44& w2l);
|
||||
|
||||
virtual int GetGroup() const { return fGroup; }
|
||||
|
||||
virtual void AddLOSDB(UInt16 flag) { hsSetBits(fLOSDBs, flag); }
|
||||
virtual void RemoveLOSDB(UInt16 flag) { hsClearBits(fLOSDBs, flag); }
|
||||
virtual UInt16 GetAllLOSDBs() { return fLOSDBs; }
|
||||
virtual hsBool IsInLOSDB(UInt16 flag) { return hsCheckBits(fLOSDBs, flag); }
|
||||
|
||||
virtual hsBool DoDetectorHullWorkaround() { return fSaveTriangles ? true : false; }
|
||||
virtual hsBool Should_I_Trigger(hsBool enter, hsPoint3& pos);
|
||||
virtual hsBool IsObjectInsideHull(const hsPoint3& pos);
|
||||
virtual void SetInsideConvexHull(hsBool inside) { fInsideConvexHull = inside; }
|
||||
|
||||
virtual plKey GetWorldKey() const { return fWorldKey; }
|
||||
|
||||
virtual plPhysicalSndGroup* GetSoundGroup() const { return fSndGroup; }
|
||||
|
||||
virtual void GetPositionSim(hsPoint3& pos) const { IGetPositionSim(pos); }
|
||||
|
||||
virtual void SendNewLocation(hsBool synchTransform = false, hsBool isSynchUpdate = false);
|
||||
|
||||
virtual void SetHitForce(const hsVector3& force, const hsPoint3& pos) { fWeWereHit=true; fHitForce = force; fHitPos = pos; }
|
||||
virtual void ApplyHitForce();
|
||||
virtual void ResetHitForce() { fWeWereHit=false; fHitForce.Set(0,0,0); fHitPos.Set(0,0,0); }
|
||||
|
||||
virtual void GetSyncState(hsPoint3& pos, hsQuat& rot, hsVector3& linV, hsVector3& angV);
|
||||
virtual void SetSyncState(hsPoint3* pos, hsQuat* rot, hsVector3* linV, hsVector3* angV);
|
||||
|
||||
virtual void ExcludeRegionHack(hsBool cleared);
|
||||
|
||||
virtual plDrawableSpans* CreateProxy(hsGMaterial* mat, hsTArray<UInt32>& idx, plDrawableSpans* addTo);
|
||||
|
||||
hsBool DoReportOn(plSimDefs::Group group) const { return hsCheckBits(fReportsOn, 1<<group); }
|
||||
|
||||
// Returns true if this object is *really* dynamic. We can have physicals
|
||||
// that are in the dynamic group but are actually animated or something.
|
||||
// This weeds those out.
|
||||
hsBool IsDynamic() const;
|
||||
|
||||
//Hack to check if there is an overlap with the capsule
|
||||
//this partially for exclude regions vs avatar capsule
|
||||
virtual hsBool OverlapWithCapsule(NxCapsule& cap);
|
||||
|
||||
virtual hsScalar GetMass() {return fMass;}
|
||||
protected:
|
||||
void IGetPositionSim(hsPoint3& pos) const;
|
||||
void IGetRotationSim(hsQuat& rot) const;
|
||||
void ISetPositionSim(const hsPoint3& pos);
|
||||
void ISetRotationSim(const hsQuat& rot);
|
||||
|
||||
/** Handle messages about our references. */
|
||||
hsBool HandleRefMsg(plGenRefMsg * refM);
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// WORLDS, SUBWORLDS && CONTEXTS
|
||||
//
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
void IConvertGroups(UInt32 memberOf, UInt32 reportsOn, UInt32 collideWith);
|
||||
|
||||
/** See if the object is in a valid, non-overlapping position.
|
||||
A valid overlap is one which is approved by the collision
|
||||
masking code, i.e. my memberOf has no intersection with your
|
||||
bounceOff and vice-versa
|
||||
*/
|
||||
// Set overlapText to get a string naming all the overlapping physicals (that you must delete)
|
||||
hsBool CheckValidPosition(char** overlapText=nil);
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// NETWORK SYNCHRONIZATION
|
||||
//
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
/** Remember that we need to do a synch soon. */
|
||||
hsBool DirtySynchState(const char* SDLStateName, UInt32 synchFlags );
|
||||
|
||||
double GetLastSyncTime() { return fLastSyncTime; }
|
||||
|
||||
/** Get the simulation transform of the physical, in world
|
||||
coordinates (factoring in the subworld if necessary */
|
||||
void IGetTransformGlobal(hsMatrix44 &l2w) const;
|
||||
void ISetTransformGlobal(const hsMatrix44& l2w);
|
||||
|
||||
// Enable/disable collisions and dynamic movement
|
||||
void IEnable(hsBool enable);
|
||||
|
||||
void IMakeHull(NxConvexMesh* convexMesh, hsMatrix44 l2w);
|
||||
|
||||
NxActor* fActor;
|
||||
plKey fWorldKey; // either a subworld or nil
|
||||
|
||||
plSimDefs::Bounds fBoundsType;
|
||||
plSimDefs::Group fGroup;
|
||||
UInt32 fReportsOn; // bit vector for groups we report interactions with
|
||||
UInt16 fLOSDBs; // Which LOS databases we get put into
|
||||
hsBitVector fProps; // plSimulationInterface::plSimulationProperties kept here
|
||||
float fMass;
|
||||
|
||||
plKey fObjectKey; // the key to our scene object
|
||||
plKey fSceneNode; // the room we're in
|
||||
|
||||
// PHYSX FIXME - need to create a plasma hull so that we can determine if inside
|
||||
hsPlane3* fWorldHull;
|
||||
UInt32 fHullNumberPlanes;
|
||||
hsPoint3* fSaveTriangles;
|
||||
hsBool fInsideConvexHull;
|
||||
void ISetHullToWorldWTriangles();
|
||||
inline hsBool ITestPlane(const hsPoint3 &pos, const hsPlane3 &plane)
|
||||
{
|
||||
hsScalar dis = plane.fN.InnerProduct(pos);
|
||||
dis += plane.fD;
|
||||
if (dis == 0.f)
|
||||
return false;
|
||||
if( dis >= 0.f )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// we need to remember the last matrices we sent to the coordinate interface
|
||||
// so that we can recognize them when we send them back and not reapply them,
|
||||
// which would reactivate our body. inelegant but effective
|
||||
hsMatrix44 fCachedLocal2World;
|
||||
|
||||
// Syncronization
|
||||
double fLastSyncTime;
|
||||
plSDLModifier* fSDLMod;
|
||||
|
||||
plPhysicalSndGroup* fSndGroup;
|
||||
|
||||
hsBool fWeWereHit;
|
||||
hsVector3 fHitForce;
|
||||
hsPoint3 fHitPos;
|
||||
|
||||
plPhysicalProxy* fProxyGen; // visual proxy for debugging
|
||||
|
||||
static int fNumberAnimatedPhysicals;
|
||||
static int fNumberAnimatedActivators;
|
||||
};
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,195 @@
|
||||
/*==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/>.
|
||||
|
||||
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;
|
||||
hsBool 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>& 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 hsBool 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
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,145 @@
|
||||
/*==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/>.
|
||||
|
||||
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==*/
|
||||
#include "../plAvatar/plPhysicalControllerCore.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;
|
||||
class plSceneObject;
|
||||
class PXControllerHitReportWalk;
|
||||
class plCollideMsg;
|
||||
#ifndef PLASMA_EXTERNAL_RELEASE
|
||||
|
||||
class plDbgCollisionInfo
|
||||
{
|
||||
public:
|
||||
plSceneObject *fSO;
|
||||
hsVector3 fNormal;
|
||||
hsBool fOverlap;
|
||||
};
|
||||
#endif // PLASMA_EXTERNAL_RELEASE
|
||||
class plPXPhysicalControllerCore: public plPhysicalControllerCore
|
||||
{
|
||||
friend PXControllerHitReportWalk;
|
||||
public:
|
||||
plPXPhysicalControllerCore(plKey ownerSO, hsScalar height, hsScalar 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.
|
||||
virtual void Enable(bool enable);
|
||||
|
||||
virtual void SetSubworld(plKey world) ;
|
||||
virtual const plCoordinateInterface* GetSubworldCI() const ;
|
||||
// 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(hsScalar radius, hsScalar height);
|
||||
virtual void LeaveAge();
|
||||
virtual void UpdateControllerAndPhysicalRep();
|
||||
|
||||
//////////////////////////////////////////
|
||||
//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
|
||||
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(hsScalar delSecs);
|
||||
static void UpdatePoststep(hsScalar delSecs);
|
||||
static void UpdatePostSimStep(hsScalar delSecs);
|
||||
virtual plDrawableSpans* CreateProxy(hsGMaterial* mat, hsTArray<UInt32>& idx, plDrawableSpans* addTo);
|
||||
#ifndef PLASMA_EXTERNAL_RELEASE
|
||||
static hsBool fDebugDisplay;
|
||||
#endif // PLASMA_EXTERNAL_RELEASE
|
||||
static void plPXPhysicalControllerCore::SetMaxNumberOfControllers(int max) { fPXControllersMax = max; }
|
||||
static int fPXControllersMax;
|
||||
virtual int SweepControllerPath(const hsPoint3& startPos, const hsPoint3& endPos, hsBool vsDynamics, hsBool vsStatics, UInt32& vsSimGroups, std::multiset< plControllerSweepRecord >& WhatWasHitOut);
|
||||
virtual void BehaveLikeAnimatedPhysical(hsBool actLikeAnAnimatedPhys);
|
||||
virtual hsBool 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 hsScalar angvel);
|
||||
virtual void SetVelocities(const hsVector3& linearVel, hsScalar angVel);
|
||||
|
||||
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);
|
||||
void plPXPhysicalControllerCore::ICreateController(const hsPoint3& pos);
|
||||
NxActor* fKinematicActor;
|
||||
NxCapsuleController* fController;
|
||||
#ifndef PLASMA_EXTERNAL_RELEASE
|
||||
hsTArray<plDbgCollisionInfo> fDbgCollisionInfo;
|
||||
void IDrawDebugDisplay();
|
||||
#endif
|
||||
void plPXPhysicalControllerCore::IHandleResize();
|
||||
hsTArray<plCollideMsg*> fQueuedCollideMsgs;
|
||||
hsScalar fPreferedRadius;
|
||||
hsScalar fPreferedHeight;
|
||||
// The global position and rotation of the avatar last time we set it (so we
|
||||
// can detect if someone else moves him)
|
||||
plPhysicalProxy* fProxyGen;
|
||||
hsBool fBehavingLikeAnimatedPhys;
|
||||
};
|
@ -0,0 +1,57 @@
|
||||
/*==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/>.
|
||||
|
||||
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 plPXStream_h_inc
|
||||
#define plPXStream_h_inc
|
||||
|
||||
#include "hsStream.h"
|
||||
#include "NxPhysics.h"
|
||||
#include "NxStream.h"
|
||||
|
||||
// A super simple wrapper to convert a Plasma stream into a PhysX one
|
||||
class plPXStream : public NxStream
|
||||
{
|
||||
public:
|
||||
plPXStream(hsStream* s) : fStream(s) {}
|
||||
|
||||
virtual NxU8 readByte() const { return fStream->ReadByte(); }
|
||||
virtual NxU16 readWord() const { return fStream->ReadSwap16(); }
|
||||
virtual NxU32 readDword() const { return fStream->ReadSwap32(); }
|
||||
virtual float readFloat() const { return fStream->ReadSwapScalar(); }
|
||||
virtual double readDouble() const { return fStream->ReadSwapDouble(); }
|
||||
virtual void readBuffer(void* buffer, NxU32 size) const { fStream->Read(size, buffer); }
|
||||
|
||||
virtual NxStream& storeByte(NxU8 b) { fStream->WriteByte(b); return *this; }
|
||||
virtual NxStream& storeWord(NxU16 w) { fStream->WriteSwap16(w); return *this; }
|
||||
virtual NxStream& storeDword(NxU32 d) { fStream->WriteSwap32(d); return *this; }
|
||||
virtual NxStream& storeFloat(NxReal f) { fStream->WriteSwapScalar(f); return *this; }
|
||||
virtual NxStream& storeDouble(NxF64 f) { fStream->WriteSwapDouble(f); return *this; }
|
||||
virtual NxStream& storeBuffer(const void* buffer, NxU32 size) { fStream->Write(size, buffer); return *this; }
|
||||
|
||||
protected:
|
||||
hsStream* fStream;
|
||||
};
|
||||
|
||||
#endif // plPXStream_h_inc
|
@ -0,0 +1,55 @@
|
||||
/*==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/>.
|
||||
|
||||
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 plPhysXCreatable_inc
|
||||
#define plPhysXCreatable_inc
|
||||
|
||||
#include "../pnFactory/plCreator.h"
|
||||
|
||||
#include "plPXPhysical.h"
|
||||
|
||||
REGISTER_CREATABLE(plPXPhysical);
|
||||
|
||||
//#include "plHKSimulationSynchMsg.h"
|
||||
//REGISTER_CREATABLE(plHKSimulationSynchMsg);
|
||||
|
||||
//#include "plHavokConstraintTools.h"
|
||||
//REGISTER_NONCREATABLE(plHavokConstraintsMod);
|
||||
//REGISTER_CREATABLE(plHingeConstraintMod);
|
||||
//REGISTER_CREATABLE(plStrongSpringConstraintMod);
|
||||
//REGISTER_CREATABLE(plWheelConstraintMod);
|
||||
|
||||
|
||||
#include "plLOSDispatch.h"
|
||||
REGISTER_CREATABLE( plLOSDispatch );
|
||||
|
||||
#include "plSimulationMgr.h"
|
||||
REGISTER_CREATABLE( plSimulationMgr );
|
||||
|
||||
//#include "plVehicleModifier.h"
|
||||
//REGISTER_CREATABLE(plVehicleModifier);
|
||||
|
||||
|
||||
#endif // plPhysXCreatable_inc
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,193 @@
|
||||
/*==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/>.
|
||||
|
||||
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 plSimulationMgr_H
|
||||
#define plSimulationMgr_H
|
||||
|
||||
#include "hsStlUtils.h"
|
||||
#include "../pnKeyedObject/hsKeyedObject.h"
|
||||
#include "hsTemplates.h"
|
||||
|
||||
class plPXPhysical;
|
||||
class plLOSDispatch;
|
||||
class plStatusLog;
|
||||
class plPhysicsSoundMgr;
|
||||
class NxPhysicsSDK;
|
||||
class NxScene;
|
||||
class plCollideMsg;
|
||||
struct hsPoint3;
|
||||
|
||||
class plSimulationMgr : public hsKeyedObject
|
||||
{
|
||||
public:
|
||||
CLASSNAME_REGISTER(plSimulationMgr);
|
||||
GETINTERFACE_ANY(plSimulationMgr, hsKeyedObject);
|
||||
|
||||
static plSimulationMgr* GetInstance();
|
||||
static void Init();
|
||||
static void Shutdown();
|
||||
|
||||
static bool fExtraProfile;
|
||||
static bool fSubworldOptimization;
|
||||
static bool fDoClampingOnStep;
|
||||
|
||||
// initialiation of the PhysX simulation
|
||||
virtual bool InitSimulation();
|
||||
|
||||
// Advance the simulation by the given number of seconds
|
||||
void Advance(float delSecs);
|
||||
|
||||
hsBool MsgReceive(plMessage* msg);
|
||||
|
||||
// The simulation won't run at all if it is suspended
|
||||
void Suspend() { fSuspended = true; }
|
||||
void Resume() { fSuspended = false; }
|
||||
bool IsSuspended() { return fSuspended; }
|
||||
|
||||
// Output the given debug text to the simulation log.
|
||||
static void Log(const char* formatStr, ...);
|
||||
static void LogV(const char* formatStr, va_list args);
|
||||
static void ClearLog();
|
||||
|
||||
// We've detected a collision, which may be grounds for synchronizing the involved
|
||||
// physicals over the network.
|
||||
void ConsiderSynch(plPXPhysical *physical, plPXPhysical *other);
|
||||
|
||||
NxPhysicsSDK* GetSDK() const { return fSDK; }
|
||||
NxScene* GetScene(plKey world);
|
||||
// Called when an actor is removed from a scene, checks if it's time to delete
|
||||
// the scene
|
||||
void ReleaseScene(plKey world);
|
||||
|
||||
int GetMaterialIdx(NxScene* scene, hsScalar friction, hsScalar restitution);
|
||||
|
||||
// PHYSX FIXME - walk thru all the convex hull detector regions to see if we are in any... we're either coming or going
|
||||
void UpdateDetectorsInScene(plKey world, plKey avatar, hsPoint3& pos, bool entering);
|
||||
void UpdateAvatarInDetector(plKey world, plPXPhysical* detector);
|
||||
//Fix to Move collision messages and their handling out of the simulation step
|
||||
void AddCollisionMsg(plCollideMsg* msg);
|
||||
#ifndef PLASMA_EXTERNAL_RELEASE
|
||||
static bool fDisplayAwakeActors;
|
||||
#endif //PLASMA_EXTERNAL_RELEASE
|
||||
protected:
|
||||
friend class ContactReport;
|
||||
|
||||
void ISendUpdates();
|
||||
|
||||
plSimulationMgr();
|
||||
virtual ~plSimulationMgr();
|
||||
|
||||
// Set the maximum amount of time (in seconds) that the physics will advance
|
||||
// between frames. If a frame-to-frame delta is bigger than this, we'll
|
||||
// clamp it to this value.
|
||||
// WARNING: animation doesn't do this, so if we clamp the time animated
|
||||
// physicals and the avatar may move at a faster rate than usual.
|
||||
void SetMaxDelta(float maxDelta);
|
||||
float GetMaxDelta() const;
|
||||
|
||||
// Set the number of steps per second that physics will advance.
|
||||
// The more steps per second, the less fallthough and more accurate
|
||||
// simulation response.
|
||||
void SetStepsPerSecond(int stepsPerSecond);
|
||||
int GetStepsPerSecond();
|
||||
|
||||
// Walk through the synchronization requests and send them as appropriate.
|
||||
void IProcessSynchs();
|
||||
|
||||
// PHYSX FIXME send a collision message - should only be used with UpdateDetectorsInScene
|
||||
void ISendCollisionMsg(plKey receiver, plKey hitter, hsBool entering);
|
||||
|
||||
NxPhysicsSDK* fSDK;
|
||||
|
||||
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
|
||||
// SimulationMgr key, for the main world, or a SceneObject key if it's a
|
||||
// subworld.
|
||||
typedef std::map<plKey, NxScene*> SceneMap;
|
||||
SceneMap fScenes;
|
||||
|
||||
plLOSDispatch* fLOSDispatch;
|
||||
|
||||
// Is the entire physics world suspended? If so, the clock can still advance
|
||||
// but nothing will move.
|
||||
bool fSuspended;
|
||||
|
||||
float fMaxDelta;
|
||||
float fStepSize;
|
||||
|
||||
// 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.
|
||||
class SynchRequest
|
||||
{
|
||||
public:
|
||||
double fTime; // when to synch
|
||||
plKey fKey; // key of the object to be synched, so we can make sure it still lives
|
||||
|
||||
static const double kDefaultTime;
|
||||
SynchRequest() : fTime(kDefaultTime) {};
|
||||
};
|
||||
|
||||
// All currently pending synch requests. Keyed by the physical in question
|
||||
// so we can quickly eliminate redundant requests, which are very common.
|
||||
typedef std::map<plPXPhysical*, SynchRequest> PhysSynchMap;
|
||||
PhysSynchMap fPendingSynchs;
|
||||
|
||||
plStatusLog *fLog;
|
||||
#ifndef PLASMA_EXTERNAL_RELEASE
|
||||
void IDrawActiveActorList();
|
||||
#endif //PLASMA_EXTERNAL_RELEASE
|
||||
};
|
||||
|
||||
#define SIM_VERBOSE
|
||||
|
||||
#ifdef SIM_VERBOSE
|
||||
#include <stdarg.h> // only include when we need to call plSimulationMgr::Log
|
||||
|
||||
inline void SimLog(const char *str, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, str);
|
||||
plSimulationMgr::LogV(str, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
inline void SimLog(const char *str, ...)
|
||||
{
|
||||
// will get stripped out
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user