So, in the previous post I said the main problem about duplicating a box2d world. The worlds differ.
Why would you want to duplicate a box2d world?
There are several reasons:
To replay a cool sequence.
To predict the future.
To go back in time.
To save the current game.
To send the current world to another player.
How do you solve this?
There is a very simple way of going around the box2d issue. Instead of trying to make a copy of the original world, and hope for the best, you make two copies, and then destroy the original.
So instead of running the original world and save the copy...
You make two copies, run one and save the second one. That way, the second copy will be identical to the first one.
So the solution is: everytime you want to save the current world, you are actually destroying it and making two copies. The players will continue to play on copy number #1 (they will not realise the change) and you store copy number 2, in case you ever need to get back to that instant.
This is a very simple solution that can be applied to almost every case. My game turned out to be one of those special cases that required dipping into the source code. I'll talk about it in the next post. If you want to know more about my game and why I had to dance around box2d cloning issues: Posable Heroes now has a steam store page.
↧