Jump to content
  • Advertisement
  • entries
    37
  • comments
    65
  • views
    47042

Replicating a simulation with Box2d, part 2.

Sign in to follow this  
desdemian

817 views

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.

Sign in to follow this  


1 Comment


Recommended Comments

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

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!