mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-22 17:39:42 +00:00
Bullet optimization: Don't update AABBs of static objects every frame
This commit is contained in:
parent
ff0b4e0583
commit
bdab3fa321
2 changed files with 22 additions and 3 deletions
|
@ -40,7 +40,7 @@ using namespace Ogre;
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
void animateCollisionShapes (std::map<OEngine::Physic::RigidBody*, OEngine::Physic::AnimatedShapeInstance>& map)
|
void animateCollisionShapes (std::map<OEngine::Physic::RigidBody*, OEngine::Physic::AnimatedShapeInstance>& map, btDynamicsWorld* dynamicsWorld)
|
||||||
{
|
{
|
||||||
for (std::map<OEngine::Physic::RigidBody*, OEngine::Physic::AnimatedShapeInstance>::iterator it = map.begin();
|
for (std::map<OEngine::Physic::RigidBody*, OEngine::Physic::AnimatedShapeInstance>::iterator it = map.begin();
|
||||||
it != map.end(); ++it)
|
it != map.end(); ++it)
|
||||||
|
@ -79,6 +79,9 @@ void animateCollisionShapes (std::map<OEngine::Physic::RigidBody*, OEngine::Phys
|
||||||
compound->getChildShape(shapeIt->second)->setLocalScaling(BtOgre::Convert::toBullet(bone->_getDerivedScale()));
|
compound->getChildShape(shapeIt->second)->setLocalScaling(BtOgre::Convert::toBullet(bone->_getDerivedScale()));
|
||||||
compound->updateChildTransform(shapeIt->second, trans);
|
compound->updateChildTransform(shapeIt->second, trans);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// needed because we used btDynamicsWorld::setForceUpdateAllAabbs(false)
|
||||||
|
dynamicsWorld->updateSingleAabb(it->first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -670,11 +673,18 @@ namespace MWWorld
|
||||||
const Ogre::Vector3 &position = node->getPosition();
|
const Ogre::Vector3 &position = node->getPosition();
|
||||||
|
|
||||||
if(OEngine::Physic::RigidBody *body = mEngine->getRigidBody(handle))
|
if(OEngine::Physic::RigidBody *body = mEngine->getRigidBody(handle))
|
||||||
|
{
|
||||||
body->getWorldTransform().setOrigin(btVector3(position.x,position.y,position.z));
|
body->getWorldTransform().setOrigin(btVector3(position.x,position.y,position.z));
|
||||||
|
mEngine->mDynamicsWorld->updateSingleAabb(body);
|
||||||
|
}
|
||||||
|
|
||||||
if(OEngine::Physic::RigidBody *body = mEngine->getRigidBody(handle, true))
|
if(OEngine::Physic::RigidBody *body = mEngine->getRigidBody(handle, true))
|
||||||
|
{
|
||||||
body->getWorldTransform().setOrigin(btVector3(position.x,position.y,position.z));
|
body->getWorldTransform().setOrigin(btVector3(position.x,position.y,position.z));
|
||||||
|
mEngine->mDynamicsWorld->updateSingleAabb(body);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actors update their AABBs every frame (DISABLE_DEACTIVATION), so no need to do it manually
|
||||||
if(OEngine::Physic::PhysicActor *physact = mEngine->getCharacter(handle))
|
if(OEngine::Physic::PhysicActor *physact = mEngine->getCharacter(handle))
|
||||||
physact->setPosition(position);
|
physact->setPosition(position);
|
||||||
}
|
}
|
||||||
|
@ -696,6 +706,7 @@ namespace MWWorld
|
||||||
body->getWorldTransform().setRotation(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w));
|
body->getWorldTransform().setRotation(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w));
|
||||||
else
|
else
|
||||||
mEngine->boxAdjustExternal(handleToMesh[handle], body, node->getScale().x, node->getPosition(), rotation);
|
mEngine->boxAdjustExternal(handleToMesh[handle], body, node->getScale().x, node->getPosition(), rotation);
|
||||||
|
mEngine->mDynamicsWorld->updateSingleAabb(body);
|
||||||
}
|
}
|
||||||
if (OEngine::Physic::RigidBody* body = mEngine->getRigidBody(handle, true))
|
if (OEngine::Physic::RigidBody* body = mEngine->getRigidBody(handle, true))
|
||||||
{
|
{
|
||||||
|
@ -703,6 +714,7 @@ namespace MWWorld
|
||||||
body->getWorldTransform().setRotation(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w));
|
body->getWorldTransform().setRotation(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w));
|
||||||
else
|
else
|
||||||
mEngine->boxAdjustExternal(handleToMesh[handle], body, node->getScale().x, node->getPosition(), rotation);
|
mEngine->boxAdjustExternal(handleToMesh[handle], body, node->getScale().x, node->getPosition(), rotation);
|
||||||
|
mEngine->mDynamicsWorld->updateSingleAabb(body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -864,8 +876,8 @@ namespace MWWorld
|
||||||
|
|
||||||
void PhysicsSystem::stepSimulation(float dt)
|
void PhysicsSystem::stepSimulation(float dt)
|
||||||
{
|
{
|
||||||
animateCollisionShapes(mEngine->mAnimatedShapes);
|
animateCollisionShapes(mEngine->mAnimatedShapes, mEngine->mDynamicsWorld);
|
||||||
animateCollisionShapes(mEngine->mAnimatedRaycastingShapes);
|
animateCollisionShapes(mEngine->mAnimatedRaycastingShapes, mEngine->mDynamicsWorld);
|
||||||
|
|
||||||
mEngine->stepSimulation(dt);
|
mEngine->stepSimulation(dt);
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,8 @@ namespace Physic
|
||||||
(0,0, mShape.get());
|
(0,0, mShape.get());
|
||||||
mBody = new RigidBody(CI, name);
|
mBody = new RigidBody(CI, name);
|
||||||
mBody->mPlaceable = false;
|
mBody->mPlaceable = false;
|
||||||
|
mBody->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||||
|
mBody->setActivationState(DISABLE_DEACTIVATION);
|
||||||
|
|
||||||
setPosition(position);
|
setPosition(position);
|
||||||
setRotation(rotation);
|
setRotation(rotation);
|
||||||
|
@ -233,6 +235,11 @@ namespace Physic
|
||||||
|
|
||||||
// The world.
|
// The world.
|
||||||
mDynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
|
mDynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
|
||||||
|
|
||||||
|
// Don't update AABBs of all objects every frame. Most objects in MW are static, so we don't need this.
|
||||||
|
// Should a "static" object ever be moved, we have to update its AABB manually using DynamicsWorld::updateSingleAabb.
|
||||||
|
mDynamicsWorld->setForceUpdateAllAabbs(false);
|
||||||
|
|
||||||
mDynamicsWorld->setGravity(btVector3(0,0,-10));
|
mDynamicsWorld->setGravity(btVector3(0,0,-10));
|
||||||
|
|
||||||
if(BulletShapeManager::getSingletonPtr() == NULL)
|
if(BulletShapeManager::getSingletonPtr() == NULL)
|
||||||
|
|
Loading…
Reference in a new issue