Rebuild AABB trees to consistent state

Official forum for the Chipmunk2D Physics Library.

Rebuild AABB trees to consistent state

Postby froggerjohn » Fri Jun 03, 2016 5:33 pm

I've been using ChipmunkJS on a multiplayer Pool (billiards) game that requires simulations to be in sync on different devices. It's almost complete, but one issue remains.

Players can leave and rejoin between shots, and when they do that, their simulation diverges from a player that remained in the game the whole time.

I've tracked down the cause, and it's due to the list of arbiters being in a different order, which causes collisions to be processed in a different order. (And that makes collisions propagate differently across the space).

It looks like the reason for this, is that the BBTree "activeShapes" is (understandably) in a different configuration in a running instance compared to one freshly built for a new world.

So my question, is that since I need to have an identical starting state at the beginning of each shot (whether starting fresh or continuing from the previous shot), is there an easy way to get a matching tree structure?

Note that I tried space.activeShapes.reindex(), but that actually made things diverge even earlier.
Posts: 7
Joined: Sat Jan 17, 2015 10:11 am

Re: Rebuild AABB trees to consistent state

Postby froggerjohn » Mon Jun 06, 2016 10:10 am


In addition to the AABB tree, cached arbiters were also affecting collisions. Cleaning up both of them seems to have solved my problem, and so far, I'm now getting consistent simulations when players rejoin.

This is what I ended up using between turns (in JavaScript version, but should be adaptable).

Code: Select all
Space.prototype.clean = function()
    this.arbiters.length = 0;
    this.cachedArbiters = {};
    this.eachBody(function(body) {
        body.arbiterList = null;
    this.stamp = 0;
Posts: 7
Joined: Sat Jan 17, 2015 10:11 am

Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 1 guest