Most efficient way to handle multiple physics worlds

David20321
Posts: 17
Joined: Sat Mar 13, 2010 10:08 pm

Most efficient way to handle multiple physics worlds

Post by David20321 »

I often find myself creating new bullet worlds for specific effects in my game -- for example, if I want to have floppy rabbit ears that don't collide with anything, it seems most intuitive to just create a new world for each rabbit. If I want to perform proximity collision, I make a world populated by promixity spheres so I can check for collisions between them. However, creating the dispatchers and other structures for a world seems to take a lot of RAM, up to 10 MB. So my question is, what would be the most efficient way to handle this kind of case, in terms of memory and CPU cycles?

Would it be best to put everything in one world, and use a custom broadphase callback to sort out all of the different collision groups? I'm worried that there will still be extra CPU overhead from sorting all the objects even though they don't collide. A general solution might be to provide some kind of "collision layer" integer along with the collision bitmask, and only check collisions if the layer and the bitmask both match.
cgripeos
Posts: 20
Joined: Mon Sep 24, 2007 5:45 am

Re: Most efficient way to handle multiple physics worlds

Post by cgripeos »

>> "A general solution might be to provide some kind of "collision layer" integer along with the collision bitmask, and only check collisions if the layer and the bitmask both match."

If you look at the btDynamicsWorld::addRigidBody() you'll notice the second and third parameter are the collision filters used to enable/disable collisions between touching Rigid Bodies.

You can even change the default behaviour of how this collision filter works via callbacks...

myBroadphase->getOverlappingPairCache()->setOverlapFilterCallback( myCustomCollisionFilterTest )

... where myBroadphase is a btDbvtBroadphase (or any other btBroadphaseInterface you might be using when creating your Bullet world)
MaxDZ8
Posts: 149
Joined: Fri Jun 24, 2011 8:53 am

Re: Most efficient way to handle multiple physics worlds

Post by MaxDZ8 »

In my experience broadphase masks are super extra fast. That's because they're really tested anyway even when you don't use them so they can only SAVE work.