Determinism/Repeatable (revisited with a twist)

Official forum for the Chipmunk2D Physics Library.
Post Reply
dlpdx
Posts: 3
Joined: Thu Jun 10, 2010 11:22 am
Contact:

Determinism/Repeatable (revisited with a twist)

Post by dlpdx »

I've been very pleased with how well Chipmunk works, but I have one perplexing problem to resolve.

I'm trying to put together a (mildly) complicated simulation by iterativerly adding bodies/constraints. What I mean by that is that I want to have 50 bodies/constraints carefully positioned so that the outcome is repeatable. By resetting the Id count, and watching the values I pass to Chipmunk each time, I've found it to be 100% repeatable (on one platform, against one compiler. etc.) every time I run the simulation. Awesome, exactly as I'd like.

However, now I'd like to add the 51st object, which does not even have any interaction with anything in the space other than perhaps static bodies (which have infinite mass and moi). I initialize the cpSpace with the first 50 objects exactly as I did before, then add the new body last, and run the simulation. But now the simulation now runs differently. Even though the new body had no direct or indirect interaction with anything other than a static body (among the first 50), collisions/etc. in other parts of the space are now solving different.

Is this expected behavior?
If yes, does anyone know how to minimize/eliminate it?
If no, any clues to where to start to look? I've verified that every value I pass to chipmunk is identical for the first 50 objects.

Any suggestions would be welcome - thanks.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Determinism/Repeatable (revisited with a twist)

Post by slembcke »

Adding objects to the space can change the iteration order of the hash sets that back the collision detection. This means that collisions are found and then solved in a different order.

The differences are already pretty minimal, so trying to minimize it further isn't really going to help for complicated simulations.

It could maybe be considered a design flaw, but very few people want that level of determinism at the expense of efficiency. Game physics libraries mostly try to provide high performance, plausible looking and stable simulations, with a reasonable amount of accuracy as a secondary goal.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
dlpdx
Posts: 3
Joined: Thu Jun 10, 2010 11:22 am
Contact:

Re: Determinism/Repeatable (revisited with a twist)

Post by dlpdx »

Thanks for quick reply, and no, I do not consider it a design flaw.

But, for purposes of what I'm working on, it's something I need resolve one way or another. *If* the collisions were solved in the same order, such that the newest object's collisions were solved after the initial 50, would you conjecture that this issue would go away ? I'm assuming that it would only interact with static bodies in the original 50.

I'm trying to decide if it's worth my time to delve deeply into Chipmunk to see if I can impose some ordering via caching the collisions, sorting them based upon some criteria, then solving them. Or, whether this is the proverbial onion, where once I solve the compute order, there'll only be another issue.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Determinism/Repeatable (revisited with a twist)

Post by slembcke »

I dunno, I can't really think of an easy way to get around this. Determinism wasn't one of Chipmunk's original design goals. Obviously it has gotten some attention, but not enough to cover more complicated scenarios.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests