void EntityManager::UpdatePhysics( float frametime ) { PROFILE_FUNCTION(); // frametime *= 0.5f; Scalar total_time = frametime + m_PhysOverlapTime; if (total_time > 0.1f) total_time = 0.1f; // split the timestep into fixed size chunks int num_loops = (int) (total_time / m_PhysTimestep); Scalar timestep = m_PhysTimestep; if ( false /*m_allow_smaller_timesteps*/ ) { if (num_loops == 0) num_loops = 1; timestep = total_time / num_loops; } m_PhysOverlapTime = total_time - num_loops * timestep; // TCPreAllocDynamicLinkList<CJL_PhysicsActor>& rActorList = m_pStage->m_pPhysicsManager->GetActorList(); // TCPreAllocDynamicLinkList<CJL_PhysicsActor>::LinkListIterator itrActor; int i; for (i=0 ; i<num_loops ; ++i) { // m_physics_time += timestep; // apply gravity /* for( itrActor = rActorList.Begin(); itrActor != rActorList.End(); itrActor++ ) { if( !(itrActor->GetActorFlag() & JL_ACTOR_STATIC) ) itrActor->AddWorldForce( itrActor->GetMass() * Vector3(0,-9.8f,0) ); } */ ProfileBegin( "Entity Update (Physics)" ); // update physics properties that are specific to each entity // DO NOT CONFUSE THIS WITH CCopyEntity::UpdatePhysics() CCopyEntity *pEntity; for( pEntity = m_pEntityInUse.get(); pEntity != NULL; pEntity = pEntity->m_pNextRawPtr ) { if( pEntity->GetEntityFlags() & BETYPE_COPY_PARENT_POSE ) pEntity->CopyParentPose(); // if( pEntity->inuse && pEntity->pPhysicsActor ) if( pEntity->inuse && 0 < pEntity->m_vecpPhysicsActor.size() ) pEntity->pBaseEntity->UpdatePhysics( pEntity, timestep ); UpdateEntityAfterMoving( pEntity ); } ProfileEnd( "Entity Update (Physics)" ); { PROFILE_SCOPE( "Physics Simulation" ); // handle the motions and collisions of rigid body entities // m_pStage->m_pPhysicsManager->Integrate( timestep ); m_pStage->GetPhysicsScene()->Simulate( timestep ); while( !m_pStage->GetPhysicsScene()->FetchResults( physics::SimulationStatus::RigidBodyFinished ) ) {} } // clear forces on actors /* for( itrActor = rActorList.Begin(); itrActor != rActorList.End(); itrActor++ ) { itrActor->ClearForces(); } */ } }