Zzzzrrr wrote:
I've thought about this a little more, and the performance is better because the pyramid is going to sleep much sooner with a higher position iteration count. Something to keep in mind when benchmarking.
I've thought for a while that it would be good to have a standard benchmarking scene for this reason. I've been using a piston test, which creates a bunch of shapes and keeps them churning by punching them up into the air (code below), but it's not ideal because from what I've noticed after a long enough time it actually explodes (I've never tracked down why, maybe the object masses are too high).
What we'd ideally want is a simple benchmark suite, which individually stress tested each type of shape-shape encounter, as well as different joint types, both with and without bullets enabled, making sure that none of the benchmark tests ever sleep (things should constantly be in motion). If anyone wants to take a shot at that, it would be interesting to see the performance differences between all the ports at various tasks.
FWIW, last time I checked, which was probably a year ago, on my computer the piston test below ran at 470 fps (no drawing) in Java 1.6 with -server enabled, and 710 fps in C++ compiled on OS X with gcc in release mode. I never got around to writing an AS3 or Javascript version. But those numbers are stale anyways, as JBox2d has seen a lot of optimizations since then and Box2d itself has changed significantly (JBox2d is far enough behind the C++ version that at the moment a direct comparison is probably not very meaningful anymore).
Code:
static final boolean BULLETS = false;
private RevoluteJoint m_joint1;
private PrismaticJoint m_joint2;
public void create(World world) {
{
// Define crank.
PolygonDef sd = new PolygonDef();
sd.setAsBox(0.5f, 2.0f);
sd.density = 1.0f;
RevoluteJointDef rjd = new RevoluteJointDef();
Body prevBody = world.getGroundBody();
BodyDef bd = new BodyDef();
bd.position.set(0.0f, 7.0f);
Body body = world.createBody(bd);
body.createShape(sd);
body.setMassFromShapes();
rjd.initialize(prevBody, body, Vec2.createVec2(0.0f, 5.0f));
rjd.motorSpeed = 1.0f * 3.1415f;
rjd.maxMotorTorque = Float.MAX_VALUE;
rjd.enableMotor = true;
RevoluteJoint m_joint1 = (RevoluteJoint)world.createJoint(rjd);
prevBody = body;
// Define follower.
sd.setAsBox(0.5f, 4.0f);
bd.position.set(0.0f, 13.0f);
body = world.createBody(bd);
body.createShape(sd);
body.setMassFromShapes();
rjd.initialize(prevBody, body, Vec2.createVec2(0.0f, 9.0f));
rjd.enableMotor = false;
world.createJoint(rjd);
prevBody = body;
// Define piston
sd.setAsBox(5.0f, 1.5f);
bd.position.set(0.0f, 17.0f);
body = world.createBody(bd);
body.createShape(sd);
body.setMassFromShapes();
rjd.initialize(prevBody, body, Vec2.createVec2(0.0f, 17.0f));
world.createJoint(rjd);
PrismaticJointDef pjd = new PrismaticJointDef();
pjd.initialize(world.getGroundBody(), body, Vec2.createVec2(0.0f, 17.0f), Vec2.createVec2(0.0f, 1.0f));
//pjd.maxMotorForce = Float.MAX_VALUE;
pjd.enableMotor = false;
PrismaticJoint m_joint2 = (PrismaticJoint)world.createJoint(pjd);
// Create a payload
for (int i=0; i<100; ++i) {
sd.setAsBox(0.4f,0.3f);
sd.density = 0.1f;
bd.position.set(-1.0f, 23.0f + i);
if (BULLETS) bd.isBullet = true;
else bd.isBullet = false;
body = world.createBody(bd);
body.createShape(sd);
body.setMassFromShapes();
}
CircleDef cd = new CircleDef();
cd.density = 2.0f;
cd.radius = 0.36f;
for (int i=0; i<100; ++i) {
bd.position.set(1.0f, 23.0f + i);
if (BULLETS) bd.isBullet = true;
else bd.isBullet = false;
body = world.createBody(bd);
body.createShape(cd);
body.setMassFromShapes();
}
sd.density = 0.0f;
sd.friction = 0.0f;
sd.setAsBox(1.0f, 100.0f);
bd = new BodyDef();
bd.position.set(-6.1f,50.0f);
Body bod = world.createBody(bd);
bod.createShape(sd);
bd.position.set(6.1f,50.0f);
bod = world.createBody(bd);
bod.createShape(sd);
}
}