[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
Chipmunk Physics • View topic - Chipmunk repeatability

Chipmunk repeatability

Official forum for the .

Chipmunk repeatability

Postby B3DY » Sun Jun 30, 2013 3:35 am

I am currently part way through developing my first game with chipmunk2D on the iOS platforms.

One problem I have encountered however is the lack of repeatability within the chipmunk environment. For example, I can have a fairly simple (<20 blocks) setup and yet every time physics is applied to the body's they react in slightly differant ways. The ways they react are never violently differant yet they are differant enough to the point where it is game breaking for me.

When creating the chipmunk bodys/shapes/spaces I am including size, mass, moment, friction, and elasticity. I believe I am including everything there.

Does chipmunk use some randomization in its physics code? If not (or even if it does) What is the best way to fix this randomization
B3DY
 
Posts: 13
Joined: Sun Jun 30, 2013 3:32 am

Re: Chipmunk repeatability

Postby OandO » Sun Jun 30, 2013 2:46 pm

Are you using a variable timestep perhaps? From a user's point of view, I've not seen any evidence of randomisation, scenes play out the same way every time for me.
OandO
 
Posts: 8
Joined: Tue Jun 04, 2013 10:48 am

Re: Chipmunk repeatability

Postby B3DY » Sun Jun 30, 2013 10:29 pm

That is a possibility but I do not believe so. So far everything is setup as described in this tutorial: http://www.raywenderlich.com/3128/how-t ... s-tutorial
B3DY
 
Posts: 13
Joined: Sun Jun 30, 2013 3:32 am

Re: Chipmunk repeatability

Postby slembcke » Sun Jun 30, 2013 11:13 pm

Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Chipmunk repeatability

Postby B3DY » Mon Jul 01, 2013 2:20 am

ahhh that seems like it would be the culprit! I am however having problem implementing this function into my code.

Currently I have a CCLayer where the simulation is taking place. I have tried clearing the shape counter with cpResetShapeIdCounter(); in numerous places in the layers init method and yet none seems to completely get rid of the 'random' factor.

What is the correct way to use this function? and where should it be called? I apologize for this but want to thank you for all your help!
B3DY
 
Posts: 13
Joined: Sun Jun 30, 2013 3:32 am

Re: Chipmunk repeatability

Postby slembcke » Mon Jul 01, 2013 10:34 am

I guess I'd call it right in the same place where you recreate the space.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Chipmunk repeatability

Postby B3DY » Mon Jul 01, 2013 3:52 pm

I have tried calling it everywhere I can think and yet I can still not get rid of the 'randomness' :(

Edit:

Should I be setting something equal to the function or just calling it?
B3DY
 
Posts: 13
Joined: Sun Jun 30, 2013 3:32 am

Re: Chipmunk repeatability

Postby B3DY » Sat Jul 06, 2013 2:36 pm

I have now tried to run the exact same simulation on two devices, side by side, and both simulations produce different results. As a developer this is extremely frustrating as physics should by nature be 'repeatable'. Does anyone know if box2d is more reliable in this aspect?
B3DY
 
Posts: 13
Joined: Sun Jun 30, 2013 3:32 am

Re: Chipmunk repeatability

Postby slembcke » Sat Jul 06, 2013 10:25 pm

Ooof. So that is a much bigger can of worms that you realize. I thought you meant on the same device.

It's not a physics engine problem really, it's a floating point number problem. Basically, you cannot expect any code that uses floating point numbers to give you the same results if you use a different compiler, change compiler settings, compile for a different OS, compile for a different ABI, or compile for a different CPU. Floating point numbers are not exact, so any little change to the code or the order of the machine instructions is going to give you different results. It's even worse with something like a physics library because each frame is based on the calculations of the previous frame. So any little error builds up over time. You aren't going to find that any particular "version" of the simulation is more or less correct, but they will all be slightly different. A different library isn't going to fix that.

You *cannot* rely on a simulation to be repeatable unless run within the same exact executable and with the same exact starting conditions. If you need the simulation to be the same across different devices (such as in a networked game) then you need to make sure that you compensate for that in your code. Usually this is done by making one of the simulations the server and constantly resynchronizing all of the other simulations to it. Only what happens on the server's copy of the simulation matters.

If you *really* want deterministic simulations across devices you can force software (integer) based floating point math, or implement fixed precision math. It's not really worth it though in my opinion (I certainly haven't done it). The resulting code would be much much more work and much much slower than using the (lossy) native floating point hardware and dealing with inaccuracies.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Chipmunk repeatability

Postby B3DY » Sat Jul 06, 2013 11:28 pm

So say I have an app running on ios. If the exact same binary is running on two iphone, and the two iphones sync the exact same initial simulation conditions, they simulations will still not be the same?

I guess once you describe it in the sense that the floating point math can slightly vary from machine to machine makes a lot of sense. This isn't something I took into account simply because I did not originally realize it! I suppose I will now attempt to use the server/host setup as you mentioned, hopefully with very little noticeable lag!

Thanks for all your help, everything is much clearer now when it comes to simulations!
B3DY
 
Posts: 13
Joined: Sun Jun 30, 2013 3:32 am

Next

Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 0 guests

cron