mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 02:27:40 -04:00
@ -1287,7 +1287,20 @@ void plClient::IProgressMgrCallbackProc(plOperationProgress * progress)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
fInstance->fMessagePumpProc();
|
fInstance->fMessagePumpProc();
|
||||||
fInstance->IDraw();
|
|
||||||
|
// HACK HACK HACK HACK!
|
||||||
|
// Yes, this is the ORIGINAL, EVIL famerate limit from plClient::IDraw (except I bumped it to 60fps)
|
||||||
|
// As it so happens, this callback is happening in the main resource loading thread
|
||||||
|
// Without this NASTY ASS HACK, we draw after loading every KO, which starves the loader.
|
||||||
|
// At some point, a better solution should be found... Like running the loader in a separate thread.
|
||||||
|
static float lastDrawTime;
|
||||||
|
static const float kMaxFrameRate = 1.f/60.f;
|
||||||
|
float currTime = (float) hsTimer::GetSeconds();
|
||||||
|
if ((currTime - lastDrawTime) > kMaxFrameRate)
|
||||||
|
{
|
||||||
|
fInstance->IDraw();
|
||||||
|
lastDrawTime = currTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
@ -1847,22 +1860,6 @@ hsBool plClient::IDrawProgress() {
|
|||||||
|
|
||||||
hsBool plClient::IDraw()
|
hsBool plClient::IDraw()
|
||||||
{
|
{
|
||||||
// Limit framerate
|
|
||||||
static float lastDrawTime;
|
|
||||||
static const float kMaxFrameRate = 1.f/30.f;
|
|
||||||
float currTime = (float) hsTimer::GetSeconds();
|
|
||||||
if (!fPipeline->IsDebugFlagSet(plPipeDbg::kFlagNVPerfHUD))
|
|
||||||
{
|
|
||||||
// If we're using NVPerfHUD to step through draw calls,
|
|
||||||
// We're going to have a frame delta of zero. In that
|
|
||||||
// case we need to draw no matter what, and we don't
|
|
||||||
// care as much about starving other threads because
|
|
||||||
// we're presumably just debugging a graphics glitch.
|
|
||||||
if ((currTime - lastDrawTime) < kMaxFrameRate)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
lastDrawTime = currTime;
|
|
||||||
|
|
||||||
// If we're shutting down, don't attempt to draw. Doing so
|
// If we're shutting down, don't attempt to draw. Doing so
|
||||||
// tends to cause a device reload each frame.
|
// tends to cause a device reload each frame.
|
||||||
if (fDone)
|
if (fDone)
|
||||||
|
@ -347,8 +347,6 @@ 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())
|
||||||
@ -422,16 +420,20 @@ 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);
|
||||||
@ -605,25 +607,25 @@ void plSimulationMgr::Advance(float delSecs)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
fAccumulator += delSecs;
|
fAccumulator += delSecs;
|
||||||
if (fAccumulator < fStepSize)
|
if (fAccumulator < kDefaultStepSize)
|
||||||
{
|
{
|
||||||
// Not enough time has passed to perform a substep.
|
// Not enough time has passed to perform a substep.
|
||||||
plPXPhysicalControllerCore::UpdateNonPhysical(fAccumulator / fStepSize);
|
plPXPhysicalControllerCore::UpdateNonPhysical(fAccumulator / kDefaultStepSize);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (fAccumulator > fMaxDelta)
|
else if (fAccumulator > kDefaultMaxDelta)
|
||||||
{
|
{
|
||||||
if (fExtraProfile)
|
if (fExtraProfile)
|
||||||
Log("Step clamped from %f to limit of %f", fAccumulator, fMaxDelta);
|
Log("Step clamped from %f to limit of %f", fAccumulator, kDefaultMaxDelta);
|
||||||
fAccumulator = fMaxDelta;
|
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 / fStepSize + 0.000001f);
|
int numSubSteps = (int)(fAccumulator / kDefaultStepSize + 0.000001f);
|
||||||
float delta = numSubSteps * fStepSize;
|
float delta = numSubSteps * kDefaultStepSize;
|
||||||
fAccumulator -= delta;
|
fAccumulator -= delta;
|
||||||
|
|
||||||
plProfile_IncCount(StepLen, (int)(delta*1000));
|
plProfile_IncCount(StepLen, (int)(delta*1000));
|
||||||
plProfile_BeginTiming(Step);
|
plProfile_BeginTiming(Step);
|
||||||
@ -649,7 +651,7 @@ void plSimulationMgr::Advance(float delSecs)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plPXPhysicalControllerCore::Update(numSubSteps, fAccumulator / fStepSize);
|
plPXPhysicalControllerCore::Update(numSubSteps, fAccumulator / kDefaultStepSize);
|
||||||
|
|
||||||
//sending off and clearing the Collision Messages generated by scene->simulate
|
//sending off and clearing the Collision Messages generated by scene->simulate
|
||||||
IDispatchCollisionMessages();
|
IDispatchCollisionMessages();
|
||||||
@ -773,26 +775,6 @@ void plSimulationMgr::ISendUpdates()
|
|||||||
//
|
//
|
||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
if (friction == 0.5f && restitution == 0.5f)
|
if (friction == 0.5f && restitution == 0.5f)
|
||||||
|
@ -115,20 +115,6 @@ protected:
|
|||||||
plSimulationMgr();
|
plSimulationMgr();
|
||||||
virtual ~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.
|
// Walk through the synchronization requests and send them as appropriate.
|
||||||
void IProcessSynchs();
|
void IProcessSynchs();
|
||||||
|
|
||||||
@ -157,10 +143,7 @@ protected:
|
|||||||
// but nothing will move.
|
// but nothing will move.
|
||||||
bool fSuspended;
|
bool fSuspended;
|
||||||
|
|
||||||
float fMaxDelta;
|
|
||||||
float fStepSize;
|
|
||||||
float fAccumulator;
|
float fAccumulator;
|
||||||
|
|
||||||
UInt32 fStepCount;
|
UInt32 fStepCount;
|
||||||
|
|
||||||
// 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.
|
||||||
|
Reference in New Issue
Block a user