|
|
@ -347,6 +347,8 @@ plSimulationMgr* plSimulationMgr::GetInstance() |
|
|
|
|
|
|
|
|
|
|
|
plSimulationMgr::plSimulationMgr() |
|
|
|
plSimulationMgr::plSimulationMgr() |
|
|
|
: fSuspended(true) |
|
|
|
: fSuspended(true) |
|
|
|
|
|
|
|
, fMaxDelta(kDefaultMaxDelta) |
|
|
|
|
|
|
|
, fStepSize(kDefaultStepSize) |
|
|
|
, fAccumulator(0.0f) |
|
|
|
, fAccumulator(0.0f) |
|
|
|
, fStepCount(0) |
|
|
|
, fStepCount(0) |
|
|
|
, fLOSDispatch(TRACKED_NEW plLOSDispatch()) |
|
|
|
, fLOSDispatch(TRACKED_NEW plLOSDispatch()) |
|
|
@ -420,20 +422,16 @@ NxScene* plSimulationMgr::GetScene(plKey world) |
|
|
|
|
|
|
|
|
|
|
|
if (!scene) |
|
|
|
if (!scene) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
UInt32 maxSteps = (UInt32)hsCeil(fMaxDelta / fStepSize); |
|
|
|
|
|
|
|
|
|
|
|
NxSceneDesc sceneDesc; |
|
|
|
NxSceneDesc sceneDesc; |
|
|
|
sceneDesc.gravity.set(0, 0, -32.174049f); |
|
|
|
sceneDesc.gravity.set(0, 0, -32.174049f); |
|
|
|
sceneDesc.userTriggerReport = &gSensorReport; |
|
|
|
sceneDesc.userTriggerReport = &gSensorReport; |
|
|
|
sceneDesc.userContactReport = &gContactReport; |
|
|
|
sceneDesc.userContactReport = &gContactReport; |
|
|
|
|
|
|
|
sceneDesc.maxTimestep = fStepSize; |
|
|
|
|
|
|
|
sceneDesc.maxIter = maxSteps; |
|
|
|
scene = fSDK->createScene(sceneDesc); |
|
|
|
scene = fSDK->createScene(sceneDesc); |
|
|
|
|
|
|
|
|
|
|
|
// See "Advancing The Simulation State" in the PhysX SDK Documentation
|
|
|
|
|
|
|
|
// This will cause PhysX to only update for our step size. If we call simulate
|
|
|
|
|
|
|
|
// faster than that, PhysX will return immediately. If we call it slower than that,
|
|
|
|
|
|
|
|
// PhysX will do some extra steps for us (isn't that nice?).
|
|
|
|
|
|
|
|
// Anyway, this should be a good way to make us independent of the framerate.
|
|
|
|
|
|
|
|
// If not, I blame the usual suspects
|
|
|
|
|
|
|
|
scene->setTiming(kDefaultStepSize); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Most physicals use the default friction and restitution values, so we
|
|
|
|
// Most physicals use the default friction and restitution values, so we
|
|
|
|
// make them the default.
|
|
|
|
// make them the default.
|
|
|
|
NxMaterial* mat = scene->getMaterialFromIndex(0); |
|
|
|
NxMaterial* mat = scene->getMaterialFromIndex(0); |
|
|
@ -607,24 +605,24 @@ void plSimulationMgr::Advance(float delSecs) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
fAccumulator += delSecs; |
|
|
|
fAccumulator += delSecs; |
|
|
|
if (fAccumulator < kDefaultStepSize) |
|
|
|
if (fAccumulator < fStepSize) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Not enough time has passed to perform a substep.
|
|
|
|
// Not enough time has passed to perform a substep.
|
|
|
|
plPXPhysicalControllerCore::UpdateNonPhysical(fAccumulator / kDefaultStepSize); |
|
|
|
plPXPhysicalControllerCore::UpdateNonPhysical(fAccumulator / fStepSize); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (fAccumulator > kDefaultMaxDelta) |
|
|
|
else if (fAccumulator > fMaxDelta) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (fExtraProfile) |
|
|
|
if (fExtraProfile) |
|
|
|
Log("Step clamped from %f to limit of %f", fAccumulator, kDefaultMaxDelta); |
|
|
|
Log("Step clamped from %f to limit of %f", fAccumulator, fMaxDelta); |
|
|
|
fAccumulator = kDefaultMaxDelta; |
|
|
|
fAccumulator = kDefaultMaxDelta; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
++fStepCount; |
|
|
|
++fStepCount; |
|
|
|
|
|
|
|
|
|
|
|
// Perform as many whole substeps as possible saving the remainder in our accumulator.
|
|
|
|
// Perform as many whole substeps as possible saving the remainder in our accumulator.
|
|
|
|
int numSubSteps = (int)(fAccumulator / kDefaultStepSize + 0.000001f); |
|
|
|
int numSubSteps = (int)(fAccumulator / fStepSize + 0.000001f); |
|
|
|
float delta = numSubSteps * kDefaultStepSize; |
|
|
|
float delta = numSubSteps * fStepSize; |
|
|
|
fAccumulator -= delta; |
|
|
|
fAccumulator -= delta; |
|
|
|
|
|
|
|
|
|
|
|
plProfile_IncCount(StepLen, (int)(delta*1000)); |
|
|
|
plProfile_IncCount(StepLen, (int)(delta*1000)); |
|
|
@ -651,7 +649,7 @@ void plSimulationMgr::Advance(float delSecs) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
plPXPhysicalControllerCore::Update(numSubSteps, fAccumulator / kDefaultStepSize); |
|
|
|
plPXPhysicalControllerCore::Update(numSubSteps, fAccumulator / fStepSize); |
|
|
|
|
|
|
|
|
|
|
|
//sending off and clearing the Collision Messages generated by scene->simulate
|
|
|
|
//sending off and clearing the Collision Messages generated by scene->simulate
|
|
|
|
IDispatchCollisionMessages(); |
|
|
|
IDispatchCollisionMessages(); |
|
|
@ -774,6 +772,22 @@ void plSimulationMgr::ISendUpdates() |
|
|
|
// RESOLUTION & TIMEOUT PARAMETERS
|
|
|
|
// RESOLUTION & TIMEOUT PARAMETERS
|
|
|
|
//
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void plSimulationMgr::SetMaxDelta(float maxDelta) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
fMaxDelta = maxDelta; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
float plSimulationMgr::GetMaxDelta() const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return fMaxDelta; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void plSimulationMgr::SetStepsPerSecond(int stepsPerSecond) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
fStepSize = 1.0f / (float)stepsPerSecond; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
int plSimulationMgr::GetStepsPerSecond() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return (int)((1.0 / fStepSize) + 0.5f); // round to nearest int
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int plSimulationMgr::GetMaterialIdx(NxScene* scene, hsScalar friction, hsScalar restitution) |
|
|
|
int plSimulationMgr::GetMaterialIdx(NxScene* scene, hsScalar friction, hsScalar restitution) |
|
|
|
{ |
|
|
|
{ |
|
|
|