Many unconnected worlds

User avatar
squisher
Posts: 11
Joined: Wed Jul 30, 2008 6:08 pm

Many unconnected worlds

Post by squisher »

Hi,

I'm currently using bullet physics for my space game, using a very simple, single world created like so:

Code: Select all

    collisionConf = new btDefaultCollisionConfiguration;
    sweep = new btAxisSweep3(btVector3(-4000, -4000, -4000), btVector3(4000, 4000, 4000));
    dispatcher = new btCollisionDispatcher(collisionConf);
    solver = new btSequentialImpulseConstraintSolver;
    world = new btDiscreteDynamicsWorld(dispatcher, sweep, solver, collisionConf);
I now want to add teleporters which transport you to different worlds. I'm keeping it simple for now: objects in one world cannot travel to another world without being teleported (simply deleted in 1 world and added to another.)

Initially I plan to have lots of unconnected worlds, say a 10x10x10 grid of them, each with 200 or so objects (I'm already starting to realize I may not even have the processing power for this).

I saw in another forum post that multithreading leads to complications, so I'll just stick to a single thread. I also saw that it is best to sequentially call stepSimulation on each world each tick.

My main question is what is the best way to implement multiple unconnected worlds?

Specifically, is there anything that can be shared between worlds to save memory and cpu? I noticed that adding 1 entirely seperate and empty world added 10 MB of memory usage. If I shared the same btDefaultCollisionConfiguration, additional worlds only cost 1 MB. But I am not sure which of (dispatcher, sweep, solver, collisionConf, and misc collision shapes) can be safely shared and what has a specific world-dependant state.

Are there any other optimizations I should make? CPU/Ram is a huge concern, I'm really doubting whether this is even feasible. Will I save a ton of resources if I try and cram all the different sections into a single world?
MaxDZ8
Posts: 149
Joined: Fri Jun 24, 2011 8:53 am

Re: Many unconnected worlds

Post by MaxDZ8 »

For first, do not have a "grid" of unconnected world. What is this good for? Think at it. You know very well how to activate a world instead of another. It's through a teleport.
I strongly suggest to keep every world centered at the origin. Single precision float will begin to get awry if you don't do that. Wrapping to the origin is difficult in general but thanks to your teleporters, the job is done for you. Cheat.

10 MiBs of overhead seems a lot, but don't take this by itself. How many worlds do you need? The cost might be affordable. If each world has about 200 objects, I hardly believe you cannot afford it.

Can you put everything in a single world? Bullet has an internal notion of simulation islands. I'm not 100% sure of how they work but odds are the cost of putting everything in a single world might be less than expected.

Personally, I'd do something like traversing a graph. Given a world, it should be not to difficult to understand what worlds can be loaded and what not. At worse, just load the world you need on the fly. A small 1-sec animation would be enough to hide the fact loading is being carried out.
User avatar
squisher
Posts: 11
Joined: Wed Jul 30, 2008 6:08 pm

Re: Many unconnected worlds

Post by squisher »

Bump... hoping for a more specific answer to: "which of (dispatcher, sweep, solver, collisionConf, and misc collision shapes) can be safely shared" and any other optimizations I can take advantage of.

To the poster above, obviously every world will be centered at the origin. If anyone is confused why I would have multiple worlds, this is for a MMO. The concept of seperate "zones" is standard in almost every MMO. They must all be actively running simultaneously, since each zone has a few people participating in it.