I'm banging my head against a wall.
I'm using a 3d graphics engine that is calling the following inside of its own render loop:
Code: Select all
void sio2PhysicRender( SIO2physic *_SIO2physic,
SIO2window *_SIO2window )
{
if( _SIO2physic->state == SIO2_PHYSIC_PLAY )
{ _SIO2physic->_btDiscreteDynamicsWorld->stepSimulation( (btScalar)( 1.0f / _SIO2window->fps ), 0 ); }
}
Code: Select all
virtual int stepSimulation( btScalar timeStep,int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.));
Code: Select all
int btDiscreteDynamicsWorld::stepSimulation( btScalar timeStep,int maxSubSteps, btScalar fixedTimeStep)
{
startProfiling(timeStep);
BT_PROFILE("stepSimulation");
int numSimulationSubSteps = 0;
//NSLog(@"maxSubSteps=%i", maxSubSteps);
if (maxSubSteps)
{
//fixed timestep with interpolation
m_localTime += timeStep;
if (m_localTime >= fixedTimeStep)
{
numSimulationSubSteps = int( m_localTime / fixedTimeStep);
m_localTime -= numSimulationSubSteps * fixedTimeStep;
}
} else
{
//variable timestep
fixedTimeStep = timeStep;
m_localTime = timeStep;
if (btFuzzyZero(timeStep))
{
numSimulationSubSteps = 0;
maxSubSteps = 0;
} else
{
numSimulationSubSteps = 1;
maxSubSteps = 1;
}
}
//process some debugging flags
if (getDebugDrawer())
{
gDisableDeactivation = (getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_NoDeactivation) != 0;
}
if (numSimulationSubSteps)
{
saveKinematicState(fixedTimeStep);
applyGravity();
//clamp the number of substeps, to prevent simulation grinding spiralling down to a halt
int clampedSimulationSteps = (numSimulationSubSteps > maxSubSteps)? maxSubSteps : numSimulationSubSteps;
for (int i=0;i<clampedSimulationSteps;i++)
{
internalSingleStepSimulation(fixedTimeStep);
synchronizeMotionStates();
}
}
synchronizeMotionStates();
clearForces();
#ifndef BT_NO_PROFILE
CProfileManager::Increment_Frame_Counter();
#endif //BT_NO_PROFILE
return numSimulationSubSteps;
}
Now, my problem begins when I log the 3D engine's frameRate. It struggles to get up to 10+fps, but then occasionally spikes up around 30, and also drags down to 4+fps when a dynamic icosphere collides with a static triangle mesh.
In my 3d world I have about 14 static triangle shapes with (right now) about 250 faces. Meaning, I have a large amount of faces (~15000).
I cannot get the animation of the ball flying towards the static triangle mesh targets (they are CONCAVE perhaps there's a better shape and memory solution?) at the right "speed"....
The thing drags, lags, speeds up, slows down....
Is this a function of the 3d engine or with the specific stepSimulation numbers with bullet?
I kind of dove into this head first, so any thoughts/ideas/suggestions on how to "optimize" this thing would be greatly appreciated...