mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
Physics timing
This commit is contained in:
parent
8a39f5e7b6
commit
714362fc60
|
|
@ -123,8 +123,8 @@ void BtWorld::tickPhysics( U32 elapsedMs )
|
|||
// Convert it to seconds.
|
||||
const F32 elapsedSec = (F32)elapsedMs * 0.001f;
|
||||
|
||||
// Simulate... it is recommended to always use Bullet's default fixed timestep/
|
||||
mDynamicsWorld->stepSimulation( elapsedSec * mEditorTimeScale );
|
||||
// Simulate
|
||||
mDynamicsWorld->stepSimulation( elapsedSec * mEditorTimeScale, smPhysicsMaxSubSteps, smPhysicsStepTime);
|
||||
|
||||
mIsSimulating = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@
|
|||
#include "platform/platform.h"
|
||||
#include "T3D/physics/physicsWorld.h"
|
||||
|
||||
//Physics timing
|
||||
F32 PhysicsWorld::smPhysicsStepTime = 1.0f / 60.f; //default 60fps
|
||||
U32 PhysicsWorld::smPhysicsMaxSubSteps = 4;
|
||||
|
||||
PhysicsWorld::PhysicsWorld()
|
||||
: mGravity( 0, 0, -20.0f ) // NOTE: This matches the gravity used for player objects.
|
||||
|
|
|
|||
|
|
@ -111,6 +111,10 @@ public:
|
|||
virtual PhysicsBody* castRay( const Point3F &start, const Point3F &end, U32 bodyTypes = BT_All ) = 0;
|
||||
|
||||
virtual void explosion( const Point3F &pos, F32 radius, F32 forceMagnitude ) = 0;
|
||||
|
||||
/// Physics timing
|
||||
static F32 smPhysicsStepTime;
|
||||
static U32 smPhysicsMaxSubSteps;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -50,9 +50,6 @@ physx::PxDefaultCpuDispatcher* Px3World::smCpuDispatcher=NULL;
|
|||
Px3ConsoleStream* Px3World::smErrorCallback = NULL;
|
||||
physx::PxVisualDebuggerConnection* Px3World::smPvdConnection=NULL;
|
||||
physx::PxDefaultAllocator Px3World::smMemoryAlloc;
|
||||
//Physics timing
|
||||
F32 Px3World::smPhysicsStepTime = 1.0f/(F32)TickMs;
|
||||
U32 Px3World::smPhysicsMaxIterations = 4;
|
||||
|
||||
Px3World::Px3World(): mScene( NULL ),
|
||||
mProcessList( NULL ),
|
||||
|
|
@ -76,12 +73,6 @@ physx::PxCooking *Px3World::getCooking()
|
|||
return smCooking;
|
||||
}
|
||||
|
||||
void Px3World::setTiming(F32 stepTime,U32 maxIterations)
|
||||
{
|
||||
smPhysicsStepTime = stepTime;
|
||||
smPhysicsMaxIterations = maxIterations;
|
||||
}
|
||||
|
||||
bool Px3World::restartSDK( bool destroyOnly, Px3World *clientWorld, Px3World *serverWorld)
|
||||
{
|
||||
// If either the client or the server still exist
|
||||
|
|
@ -246,20 +237,20 @@ bool Px3World::initWorld( bool isServer, ProcessList *processList )
|
|||
// Most of this borrowed from bullet physics library, see btDiscreteDynamicsWorld.cpp
|
||||
bool Px3World::_simulate(const F32 dt)
|
||||
{
|
||||
int numSimulationSubSteps = 0;
|
||||
S32 numSimulationSubSteps = 0;
|
||||
//fixed timestep with interpolation
|
||||
mAccumulator += dt;
|
||||
if (mAccumulator >= smPhysicsStepTime)
|
||||
{
|
||||
numSimulationSubSteps = int(mAccumulator / smPhysicsStepTime);
|
||||
numSimulationSubSteps = S32(mAccumulator / smPhysicsStepTime);
|
||||
mAccumulator -= numSimulationSubSteps * smPhysicsStepTime;
|
||||
}
|
||||
if (numSimulationSubSteps)
|
||||
{
|
||||
//clamp the number of substeps, to prevent simulation grinding spiralling down to a halt
|
||||
int clampedSimulationSteps = (numSimulationSubSteps > smPhysicsMaxIterations)? smPhysicsMaxIterations : numSimulationSubSteps;
|
||||
S32 clampedSimulationSteps = (numSimulationSubSteps > smPhysicsMaxSubSteps)? smPhysicsMaxSubSteps : numSimulationSubSteps;
|
||||
|
||||
for (int i=0;i<clampedSimulationSteps;i++)
|
||||
for (S32 i=0;i<clampedSimulationSteps;i++)
|
||||
{
|
||||
mScene->fetchResults(true);
|
||||
mScene->simulate(smPhysicsStepTime);
|
||||
|
|
@ -618,8 +609,3 @@ void Px3World::onDebugDraw( const SceneRenderState *state )
|
|||
}
|
||||
|
||||
}
|
||||
//set simulation timing via script
|
||||
DefineEngineFunction( physx3SetSimulationTiming, void, ( F32 stepTime, U32 maxSteps ),, "Set simulation timing of the PhysX 3 plugin" )
|
||||
{
|
||||
Px3World::setTiming(stepTime,maxSteps);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,8 +69,6 @@ protected:
|
|||
static physx::PxProfileZoneManager* smProfileZoneManager;
|
||||
static physx::PxDefaultCpuDispatcher* smCpuDispatcher;
|
||||
static physx::PxVisualDebuggerConnection* smPvdConnection;
|
||||
static F32 smPhysicsStepTime;
|
||||
static U32 smPhysicsMaxIterations;
|
||||
F32 mAccumulator;
|
||||
bool _simulate(const F32 dt);
|
||||
|
||||
|
|
@ -103,7 +101,6 @@ public:
|
|||
static bool restartSDK( bool destroyOnly = false, Px3World *clientWorld = NULL, Px3World *serverWorld = NULL );
|
||||
static void releaseWriteLocks();
|
||||
static physx::PxCooking *getCooking();
|
||||
static void setTiming(F32 stepTime,U32 maxIterations);
|
||||
static void lockScenes();
|
||||
static void unlockScenes();
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue