On the windows phone platform / XNA 4.
My game takes place on a ship that allows travel between decks. I have a Space with a number of boxes & spheres in it. When I change to another deck in the ship Im not sure what the best way to handle the Bepu Space & associated entities is (You can revisit an existing deck btw).
If I create a new Space without removing any entities in it, can I re-add them to another space again safely? I think they wont get updated so this is ok to do?
Would it be better to just remove all entities and create new ones every deck? If so whats the correct way of doing this?
I assume I could create multiple Spaces. If so I need minimum overhead so how do I freeze the Spaces im not using? Is there a built in way of doing this? (I think this would be my prefered method if its cheap on CPU/memory).
Thanks for the advice.
Correct way to suspend Space / clean up entities?
Re: Correct way to suspend Space / clean up entities?
I'm not 100% clear on the situation, but if the end result is having an entity belong to more than one space a time, it will not work. It won't even allow adding an entity to a second space.If I create a new Space without removing any entities in it, can I re-add them to another space again safely? I think they wont get updated so this is ok to do?
That's a possibility, but the process of going through and removing every entity from a space and recreating a bunch of new ones will take more than a couple of milliseconds depending on how many objects are involved.Would it be better to just remove all entities and create new ones every deck? If so whats the correct way of doing this?
If you can go back and forth between spaces, using multiple spaces, each with their own set of entities, is probably the best bet. Memorywise, it's not really that expensive (unless there's a whole bunch of objects). It would eliminate almost all of the load time while switching, since not really anything that has to be done from a physics standpoint to switch. Simply stop calling update on the old space, and start calling update on the new space.I assume I could create multiple Spaces. If so I need minimum overhead so how do I freeze the Spaces im not using? Is there a built in way of doing this? (I think this would be my prefered method if its cheap on CPU/memory).
There's one issue to watch out for if you're using multithreading, though. This isn't an issue on the phone yet, but if you create a bunch of spaces and add threads to every single one of their thread managers, it will cause some overhead. Instead, add threads to a single thread manager, and share that single thread manager between all of the spaces by setting their ThreadManager properties.