Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed makefiles, removed copy of hello from Bench2d.cpp. Confirmed th…

…at emscripten compile works fine on Linux.
  • Loading branch information...
commit 078bbe795ef6923f3736bb9bb4219bb164ec91d5 1 parent 73384fb
Joel Webber authored
Showing with 123 additions and 200 deletions.
  1. +10 −88 c/Bench2d.cpp
  2. +68 −67 c/bench2d.js.mk
  3. +45 −45 c/bench2d.mk
View
98 c/Bench2d.cpp
@@ -5,11 +5,13 @@
using namespace std;
-#if 1
-#define WARMUP 0
+// Turn this on to include the y-position of the top box in the output.
+#define DEBUG 0
+
+#define WARMUP 64
#define FRAMES 256
-const int e_count = 2;
+const int e_count = 40;
void bench() {
// Define the gravity vector.
@@ -28,7 +30,7 @@ void bench() {
ground->CreateFixture(&shape, 0.0f);
}
-b2Body* topBody;
+ b2Body* topBody;
{
float32 a = 0.5f;
@@ -50,7 +52,7 @@ b2Body* topBody;
b2Body* body = world.CreateBody(&bd);
body->CreateFixture(&shape, 5.0f);
-topBody = body;
+ topBody = body;
y += deltaY;
}
@@ -69,7 +71,9 @@ topBody = body;
world.Step(1.0f/60.0f, 3, 3);
clock_t end = clock();
times[i] = end - start;
-printf("%f :: ", topBody->GetPosition().y);
+#if DEBUG
+ printf("%f :: ", topBody->GetPosition().y);
+#endif
printf("%f\n", (float32)(end - start) / CLOCKS_PER_SEC * 1000);
}
@@ -87,85 +91,3 @@ int main(int argc, char** argv) {
return 0;
}
-#else
-
-int main(int argc, char** argv)
-{
- B2_NOT_USED(argc);
- B2_NOT_USED(argv);
-
- // Define the gravity vector.
- b2Vec2 gravity(0.0f, -10.0f);
-
- // Construct a world object, which will hold and simulate the rigid bodies.
- b2World world(gravity);
-
- // Define the ground body.
- b2BodyDef groundBodyDef;
- groundBodyDef.position.Set(0.0f, -10.0f);
-
- // Call the body factory which allocates memory for the ground body
- // from a pool and creates the ground box shape (also from a pool).
- // The body is also added to the world.
- b2Body* groundBody = world.CreateBody(&groundBodyDef);
-
- // Define the ground box shape.
- b2PolygonShape groundBox;
-
- // The extents are the half-widths of the box.
- groundBox.SetAsBox(50.0f, 10.0f);
-
- // Add the ground fixture to the ground body.
- groundBody->CreateFixture(&groundBox, 0.0f);
-
- // Define the dynamic body. We set its position and call the body factory.
- b2BodyDef bodyDef;
- bodyDef.type = b2_dynamicBody;
- bodyDef.position.Set(0.0f, 4.0f);
- b2Body* body = world.CreateBody(&bodyDef);
-
- // Define another box shape for our dynamic body.
- b2PolygonShape dynamicBox;
- dynamicBox.SetAsBox(1.0f, 1.0f);
-
- // Define the dynamic body fixture.
- b2FixtureDef fixtureDef;
- fixtureDef.shape = &dynamicBox;
-
- // Set the box density to be non-zero, so it will be dynamic.
- fixtureDef.density = 1.0f;
-
- // Override the default friction.
- fixtureDef.friction = 0.3f;
-
- // Add the shape to the body.
- body->CreateFixture(&fixtureDef);
-
- // Prepare for simulation. Typically we use a time step of 1/60 of a
- // second (60Hz) and 10 iterations. This provides a high quality simulation
- // in most game scenarios.
- float32 timeStep = 1.0f / 60.0f;
- int32 velocityIterations = 6;
- int32 positionIterations = 2;
-
- // This is our little game loop.
- for (int32 i = 0; i < 60; ++i)
- {
- // Instruct the world to perform a single step of simulation.
- // It is generally best to keep the time step and iterations fixed.
- world.Step(timeStep, velocityIterations, positionIterations);
-
- // Now print the position and angle of the body.
- b2Vec2 position = body->GetPosition();
- float32 angle = body->GetAngle();
-
- printf("%4.2f %4.2f %4.2f\n", position.x, position.y, angle);
- }
-
- // When the world destructor is called, all bodies and joints are freed. This can
- // create orphaned pointers, so be careful about your world management.
-
- return 0;
-}
-#endif
-
View
135 c/bench2d.js.mk
@@ -1,78 +1,79 @@
-EMMAKEN=/Users/jgw/src/emscripten/tools/emmaken.py -IBox2D_v2.2.1
-EMSCRIPTEN=/Users/jgw/src/emscripten/emscripten.py
-LLVM_LINK=/Users/jgw/llvm/bin/llvm-link
-LLVM_OPT=/Users/jgw/llvm/bin/opt
+# Makefile for generating Javascript from the C++ source, using Emscripten.
+
+# You'll likely need to edit these for your particular directory layout.
+EMMAKEN=~/src/emscripten/tools/emmaken.py -IBox2D_v2.2.1
+EMSCRIPTEN=~/src/emscripten/emscripten.py
+LLVM_LINK=~/llvm/bin/llvm-link
+LLVM_OPT=~/llvm/bin/opt
# This set of flags has been chosen by the "cargo cult" method -- I picked them
# mostly from the ammo.js build file, and tweaked them until I got the best
# results. It's entirely possible I've missed something important here.
EMSCRIPTEN_FLAGS = \
-#-s ASSERTIONS=0 \
-#--optimize \
-#-s USE_TYPED_ARRAYS=1 \
-#-s RELOOP=1 \
-#-s SAFE_HEAP=0 \
-#-s QUANTUM_SIZE=1 \
-#-s SKIP_STACK_IN_SMALL=1 \
-#-s INIT_STACK=0 \
-#-s PGO=0 \
-#-s CHECK_OVERFLOWS=0 \
-#-s CHECK_SIGNED_OVERFLOWS=0 \
-#-s CORRECT_OVERFLOWS=0 \
-#-s CHCK_SIGNS=0 \
-#-s CORRECT_SIGNS=0 \
-#-s DISABLE_EXCEPTION_CATCHING=1 \
-#-s RUNTYPE_TYPE_INFO=0 \
-#-s CORRECT_ROUNDINGS=0 \
-#-s MICRO_OPTS=0
+--optimize \
+-s USE_TYPED_ARRAYS=1 \
+-s ASSERTIONS=0 \
+-s RELOOP=1 \
+-s SAFE_HEAP=0 \
+-s QUANTUM_SIZE=1 \
+-s SKIP_STACK_IN_SMALL=1 \
+-s INIT_STACK=0 \
+-s CHECK_OVERFLOWS=0 \
+-s CHECK_SIGNED_OVERFLOWS=0 \
+-s CORRECT_OVERFLOWS=0 \
+-s CHECK_SIGNS=0 \
+-s CORRECT_SIGNS=0 \
+-s DISABLE_EXCEPTION_CATCHING=1 \
+-s RUNTYPE_TYPE_INFO=0 \
+-s CORRECT_ROUNDINGS=0
OBJECTS = \
Bench2d.bc \
-Box2D_v2.2.1/Box2d/Collision/b2BroadPhase.bc \
-Box2D_v2.2.1/Box2d/Collision/b2CollideCircle.bc \
-Box2D_v2.2.1/Box2d/Collision/b2CollideEdge.bc \
-Box2D_v2.2.1/Box2d/Collision/b2CollidePolygon.bc \
-Box2D_v2.2.1/Box2d/Collision/b2Collision.bc \
-Box2D_v2.2.1/Box2d/Collision/b2Distance.bc \
-Box2D_v2.2.1/Box2d/Collision/b2DynamicTree.bc \
-Box2D_v2.2.1/Box2d/Collision/b2TimeOfImpact.bc \
-Box2D_v2.2.1/Box2d/Collision/Shapes/b2ChainShape.bc \
-Box2D_v2.2.1/Box2d/Collision/Shapes/b2CircleShape.bc \
-Box2D_v2.2.1/Box2d/Collision/Shapes/b2EdgeShape.bc \
-Box2D_v2.2.1/Box2d/Collision/Shapes/b2PolygonShape.bc \
-Box2D_v2.2.1/Box2d/Common/b2BlockAllocator.bc \
-Box2D_v2.2.1/Box2d/Common/b2Draw.bc \
-Box2D_v2.2.1/Box2d/Common/b2Math.bc \
-Box2D_v2.2.1/Box2d/Common/b2Settings.bc \
-Box2D_v2.2.1/Box2d/Common/b2StackAllocator.bc \
-Box2D_v2.2.1/Box2d/Common/b2Timer.bc \
-Box2D_v2.2.1/Box2d/Dynamics/b2Body.bc \
-Box2D_v2.2.1/Box2d/Dynamics/b2ContactManager.bc \
-Box2D_v2.2.1/Box2d/Dynamics/b2Fixture.bc \
-Box2D_v2.2.1/Box2d/Dynamics/b2Island.bc \
-Box2D_v2.2.1/Box2d/Dynamics/b2World.bc \
-Box2D_v2.2.1/Box2d/Dynamics/b2WorldCallbacks.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Contacts/b2ChainAndCircleContact.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Contacts/b2ChainAndPolygonContact.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Contacts/b2CircleContact.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Contacts/b2Contact.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Contacts/b2ContactSolver.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Contacts/b2EdgeAndCircleContact.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Contacts/b2EdgeAndPolygonContact.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Contacts/b2PolygonAndCircleContact.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Contacts/b2PolygonContact.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2DistanceJoint.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2FrictionJoint.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2GearJoint.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2Joint.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2MouseJoint.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2PrismaticJoint.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2PulleyJoint.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2RevoluteJoint.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2RopeJoint.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2WeldJoint.bc \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2WheelJoint.bc \
-Box2D_v2.2.1/Box2d/Rope/b2Rope.bc
+Box2D_v2.2.1/Box2D/Collision/b2BroadPhase.bc \
+Box2D_v2.2.1/Box2D/Collision/b2CollideCircle.bc \
+Box2D_v2.2.1/Box2D/Collision/b2CollideEdge.bc \
+Box2D_v2.2.1/Box2D/Collision/b2CollidePolygon.bc \
+Box2D_v2.2.1/Box2D/Collision/b2Collision.bc \
+Box2D_v2.2.1/Box2D/Collision/b2Distance.bc \
+Box2D_v2.2.1/Box2D/Collision/b2DynamicTree.bc \
+Box2D_v2.2.1/Box2D/Collision/b2TimeOfImpact.bc \
+Box2D_v2.2.1/Box2D/Collision/Shapes/b2ChainShape.bc \
+Box2D_v2.2.1/Box2D/Collision/Shapes/b2CircleShape.bc \
+Box2D_v2.2.1/Box2D/Collision/Shapes/b2EdgeShape.bc \
+Box2D_v2.2.1/Box2D/Collision/Shapes/b2PolygonShape.bc \
+Box2D_v2.2.1/Box2D/Common/b2BlockAllocator.bc \
+Box2D_v2.2.1/Box2D/Common/b2Draw.bc \
+Box2D_v2.2.1/Box2D/Common/b2Math.bc \
+Box2D_v2.2.1/Box2D/Common/b2Settings.bc \
+Box2D_v2.2.1/Box2D/Common/b2StackAllocator.bc \
+Box2D_v2.2.1/Box2D/Common/b2Timer.bc \
+Box2D_v2.2.1/Box2D/Dynamics/b2Body.bc \
+Box2D_v2.2.1/Box2D/Dynamics/b2ContactManager.bc \
+Box2D_v2.2.1/Box2D/Dynamics/b2Fixture.bc \
+Box2D_v2.2.1/Box2D/Dynamics/b2Island.bc \
+Box2D_v2.2.1/Box2D/Dynamics/b2World.bc \
+Box2D_v2.2.1/Box2D/Dynamics/b2WorldCallbacks.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Contacts/b2ChainAndCircleContact.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Contacts/b2ChainAndPolygonContact.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Contacts/b2CircleContact.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Contacts/b2Contact.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Contacts/b2ContactSolver.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Contacts/b2PolygonContact.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2DistanceJoint.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2FrictionJoint.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2GearJoint.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2Joint.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2MouseJoint.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2PrismaticJoint.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2PulleyJoint.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2RevoluteJoint.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2RopeJoint.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2WeldJoint.bc \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2WheelJoint.bc \
+Box2D_v2.2.1/Box2D/Rope/b2Rope.bc
all: bench2d.js
View
90 c/bench2d.mk
@@ -3,51 +3,51 @@ CFLAGS = -g -O3 -IBox2D_v2.2.1 -DNDEBUG=1
LFLAGS = -lstdc++
OBJECTS = Bench2d.o \
-Box2D_v2.2.1/Box2d/Collision/b2BroadPhase.o \
-Box2D_v2.2.1/Box2d/Collision/b2CollideCircle.o \
-Box2D_v2.2.1/Box2d/Collision/b2CollideEdge.o \
-Box2D_v2.2.1/Box2d/Collision/b2CollidePolygon.o \
-Box2D_v2.2.1/Box2d/Collision/b2Collision.o \
-Box2D_v2.2.1/Box2d/Collision/b2Distance.o \
-Box2D_v2.2.1/Box2d/Collision/b2DynamicTree.o \
-Box2D_v2.2.1/Box2d/Collision/b2TimeOfImpact.o \
-Box2D_v2.2.1/Box2d/Collision/Shapes/b2ChainShape.o \
-Box2D_v2.2.1/Box2d/Collision/Shapes/b2CircleShape.o \
-Box2D_v2.2.1/Box2d/Collision/Shapes/b2EdgeShape.o \
-Box2D_v2.2.1/Box2d/Collision/Shapes/b2PolygonShape.o \
-Box2D_v2.2.1/Box2d/Common/b2BlockAllocator.o \
-Box2D_v2.2.1/Box2d/Common/b2Draw.o \
-Box2D_v2.2.1/Box2d/Common/b2Math.o \
-Box2D_v2.2.1/Box2d/Common/b2Settings.o \
-Box2D_v2.2.1/Box2d/Common/b2StackAllocator.o \
-Box2D_v2.2.1/Box2d/Common/b2Timer.o \
-Box2D_v2.2.1/Box2d/Dynamics/b2Body.o \
-Box2D_v2.2.1/Box2d/Dynamics/b2ContactManager.o \
-Box2D_v2.2.1/Box2d/Dynamics/b2Fixture.o \
-Box2D_v2.2.1/Box2d/Dynamics/b2Island.o \
-Box2D_v2.2.1/Box2d/Dynamics/b2World.o \
-Box2D_v2.2.1/Box2d/Dynamics/b2WorldCallbacks.o \
-Box2D_v2.2.1/Box2d/Dynamics/Contacts/b2ChainAndCircleContact.o \
-Box2D_v2.2.1/Box2d/Dynamics/Contacts/b2ChainAndPolygonContact.o \
-Box2D_v2.2.1/Box2d/Dynamics/Contacts/b2CircleContact.o \
-Box2D_v2.2.1/Box2d/Dynamics/Contacts/b2Contact.o \
-Box2D_v2.2.1/Box2d/Dynamics/Contacts/b2ContactSolver.o \
-Box2D_v2.2.1/Box2d/Dynamics/Contacts/b2EdgeAndCircleContact.o \
-Box2D_v2.2.1/Box2d/Dynamics/Contacts/b2EdgeAndPolygonContact.o \
-Box2D_v2.2.1/Box2d/Dynamics/Contacts/b2PolygonAndCircleContact.o \
-Box2D_v2.2.1/Box2d/Dynamics/Contacts/b2PolygonContact.o \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2DistanceJoint.o \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2FrictionJoint.o \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2GearJoint.o \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2Joint.o \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2MouseJoint.o \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2PrismaticJoint.o \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2PulleyJoint.o \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2RevoluteJoint.o \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2RopeJoint.o \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2WeldJoint.o \
-Box2D_v2.2.1/Box2d/Dynamics/Joints/b2WheelJoint.o \
-Box2D_v2.2.1/Box2d/Rope/b2Rope.o
+Box2D_v2.2.1/Box2D/Collision/b2BroadPhase.o \
+Box2D_v2.2.1/Box2D/Collision/b2CollideCircle.o \
+Box2D_v2.2.1/Box2D/Collision/b2CollideEdge.o \
+Box2D_v2.2.1/Box2D/Collision/b2CollidePolygon.o \
+Box2D_v2.2.1/Box2D/Collision/b2Collision.o \
+Box2D_v2.2.1/Box2D/Collision/b2Distance.o \
+Box2D_v2.2.1/Box2D/Collision/b2DynamicTree.o \
+Box2D_v2.2.1/Box2D/Collision/b2TimeOfImpact.o \
+Box2D_v2.2.1/Box2D/Collision/Shapes/b2ChainShape.o \
+Box2D_v2.2.1/Box2D/Collision/Shapes/b2CircleShape.o \
+Box2D_v2.2.1/Box2D/Collision/Shapes/b2EdgeShape.o \
+Box2D_v2.2.1/Box2D/Collision/Shapes/b2PolygonShape.o \
+Box2D_v2.2.1/Box2D/Common/b2BlockAllocator.o \
+Box2D_v2.2.1/Box2D/Common/b2Draw.o \
+Box2D_v2.2.1/Box2D/Common/b2Math.o \
+Box2D_v2.2.1/Box2D/Common/b2Settings.o \
+Box2D_v2.2.1/Box2D/Common/b2StackAllocator.o \
+Box2D_v2.2.1/Box2D/Common/b2Timer.o \
+Box2D_v2.2.1/Box2D/Dynamics/b2Body.o \
+Box2D_v2.2.1/Box2D/Dynamics/b2ContactManager.o \
+Box2D_v2.2.1/Box2D/Dynamics/b2Fixture.o \
+Box2D_v2.2.1/Box2D/Dynamics/b2Island.o \
+Box2D_v2.2.1/Box2D/Dynamics/b2World.o \
+Box2D_v2.2.1/Box2D/Dynamics/b2WorldCallbacks.o \
+Box2D_v2.2.1/Box2D/Dynamics/Contacts/b2ChainAndCircleContact.o \
+Box2D_v2.2.1/Box2D/Dynamics/Contacts/b2ChainAndPolygonContact.o \
+Box2D_v2.2.1/Box2D/Dynamics/Contacts/b2CircleContact.o \
+Box2D_v2.2.1/Box2D/Dynamics/Contacts/b2Contact.o \
+Box2D_v2.2.1/Box2D/Dynamics/Contacts/b2ContactSolver.o \
+Box2D_v2.2.1/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.o \
+Box2D_v2.2.1/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.o \
+Box2D_v2.2.1/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.o \
+Box2D_v2.2.1/Box2D/Dynamics/Contacts/b2PolygonContact.o \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2DistanceJoint.o \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2FrictionJoint.o \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2GearJoint.o \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2Joint.o \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2MouseJoint.o \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2PrismaticJoint.o \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2PulleyJoint.o \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2RevoluteJoint.o \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2RopeJoint.o \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2WeldJoint.o \
+Box2D_v2.2.1/Box2D/Dynamics/Joints/b2WheelJoint.o \
+Box2D_v2.2.1/Box2D/Rope/b2Rope.o
all: bench2d
Please sign in to comment.
Something went wrong with that request. Please try again.