Replicating a simulation with Box2d, part 2.

Published November 27, 2017
Advertisement

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:

  1. To replay a cool sequence.
  2. To predict the future.
  3. To go back in time.
  4. To save the current game.
  5. 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...

rdDjgtV.png


You make two copies, run one and save the second one. That way, the second copy will be identical to the first one.

EXsi2nb.png


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.

1 likes 1 comments

Comments

ongamex92

Ah, so smart! :D In the previous post i was thinking "omg how will he solve it", and then this splendid idea :D

November 28, 2017 07:41 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement