diff --git a/include/box2d/types.h b/include/box2d/types.h index e5d3b5fe..e653c716 100644 --- a/include/box2d/types.h +++ b/include/box2d/types.h @@ -156,32 +156,39 @@ typedef struct b2WorldDef /// Stack allocator capacity. This controls how much space box2d reserves for per-frame calculations. /// Larger worlds require more space. b2Counters can be used to determine a good capacity for your /// application. - int32_t stackAllocatorCapacity; + int32_t arenaAllocatorCapacity; /// task system hookup uint32_t workerCount; + + /// function to spawn task b2EnqueueTaskCallback* enqueueTask; + + /// function to finish a task b2FinishTaskCallback* finishTask; + + /// User context that is provided to enqueueTask and finishTask void* userTaskContext; } b2WorldDef; /// Use this to initialize your world definition -static inline b2WorldDef b2DefaultWorldDef(void) -{ - b2WorldDef def = B2_ZERO_INIT; - def.gravity = B2_LITERAL(b2Vec2){0.0f, -10.0f}; - def.restitutionThreshold = 1.0f * b2_lengthUnitsPerMeter; - def.contactPushoutVelocity = 3.0f * b2_lengthUnitsPerMeter; - def.contactHertz = 30.0f; - def.contactDampingRatio = 1.0f; - def.enableSleep = true; - def.bodyCapacity = 8; - def.shapeCapacity = 8; - def.contactCapacity = 8; - def.jointCapacity = 8; - def.stackAllocatorCapacity = 1024 * 1024; - return def; -} +static const b2WorldDef b2_defaultWorldDef = { + {0.0f, -10.0f}, // gravity + 1.0f * b2_lengthUnitsPerMeter, // restitutionThreshold + 3.0f * b2_lengthUnitsPerMeter, // contactPushoutVelocity + 30.0, // contactHertz + 1.0f, // contactDampingRatio + true, // enableSleep + 0, // bodyCapacity + 0, // shapeCapacity + 0, // contactCapacity + 0, // jointCapacity + 1024 * 1024, // arenaAllocatorCapacity + 0, // workerCount + NULL, // enqueueTask + NULL, // finishTask + NULL, // userTaskContext +}; /// The body type. /// static: zero mass, zero velocity, may be manually moved @@ -248,7 +255,19 @@ typedef struct b2BodyDef /// Use this to initialize your body definition static const b2BodyDef b2_defaultBodyDef = { - b2_staticBody, {0.0f, 0.0f}, 0.0f, {0.0f, 0.0f}, 0.0f, 0.0f, 0.0f, 1.0f, NULL, true, true, false, true, + b2_staticBody, // bodyType + {0.0f, 0.0f}, // position + 0.0f, // angle + {0.0f, 0.0f}, // linearVelocity + 0.0f, // angularVelocity + 0.0f, // linearDamping + 0.0f, // angularDamping + 1.0f, // gravityScale + NULL, // userData + true, // enableSleep + true, // isAwake + false, // fixedRotation + true, // isEnabled }; /// This holds contact filtering data. @@ -330,7 +349,15 @@ typedef struct b2ShapeDef /// Use this to initialize your shape definition static const b2ShapeDef b2_defaultShapeDef = { - NULL, 0.6f, 0.0f, 1.0f, {0x00000001, 0xFFFFFFFF, 0}, false, true, true, false, + NULL, // userData + 0.6f, // friction + 0.0f, // restitution + 1.0f, // density + {0x00000001, 0xFFFFFFFF, 0}, // filter + false, // isSensor + true, // enableSensorEvents + true, // enableContactEvents + false, // enablePreSolveEvents }; /// Used to create a chain of edges. This is designed to eliminate ghost collisions with some limitations. @@ -370,7 +397,15 @@ typedef struct b2ChainDef } b2ChainDef; /// Use this to initialize your chain definition -static const b2ChainDef b2_defaultChainDef = {NULL, 0, false, NULL, 0.6f, 0.0f, {0x00000001, 0xFFFFFFFF, 0}}; +static const b2ChainDef b2_defaultChainDef = { + NULL, // points + 0, // count + false, // loop + NULL, // userData + 0.6f, // friction + 0.0f, // restitution + {0x00000001, 0xFFFFFFFF, 0} // filter +}; /// Profiling data. Times are in milliseconds. typedef struct b2Profile diff --git a/samples/sample.cpp b/samples/sample.cpp index a2060ec7..772e4fd2 100644 --- a/samples/sample.cpp +++ b/samples/sample.cpp @@ -56,7 +56,7 @@ Sample::Sample(const Settings& settings) m_scheduler.Initialize(settings.workerCount); m_taskCount = 0; - b2WorldDef worldDef = b2DefaultWorldDef(); + b2WorldDef worldDef = b2_defaultWorldDef; worldDef.workerCount = settings.workerCount; worldDef.enqueueTask = &EnqueueTask; worldDef.finishTask = &FinishTask; @@ -66,7 +66,7 @@ Sample::Sample(const Settings& settings) // These are not ideal, but useful for testing Box2D worldDef.bodyCapacity = 2; worldDef.contactCapacity = 2; - worldDef.stackAllocatorCapacity = 0; + worldDef.arenaAllocatorCapacity = 0; m_worldId = b2CreateWorld(&worldDef); m_textLine = 30; diff --git a/src/world.c b/src/world.c index e8c97032..7f6b411c 100644 --- a/src/world.c +++ b/src/world.c @@ -93,7 +93,7 @@ b2WorldId b2CreateWorld(const b2WorldDef* def) world->index = id.index; world->blockAllocator = b2CreateBlockAllocator(); - world->stackAllocator = b2CreateStackAllocator(def->stackAllocatorCapacity); + world->stackAllocator = b2CreateStackAllocator(def->arenaAllocatorCapacity); b2CreateBroadPhase(&world->broadPhase); b2CreateGraph(&world->graph, def->bodyCapacity, def->contactCapacity, def->jointCapacity); diff --git a/test/test_determinism.c b/test/test_determinism.c index 731e2f11..e3807750 100644 --- a/test/test_determinism.c +++ b/test/test_determinism.c @@ -101,7 +101,7 @@ void TiltedStacks(int testIndex, int workerCount) b2Vec2 gravity = {0.0f, -10.0f}; // Construct a world object, which will hold and simulate the rigid bodies. - b2WorldDef worldDef = b2DefaultWorldDef(); + b2WorldDef worldDef = b2_defaultWorldDef; worldDef.gravity = gravity; worldDef.enqueueTask = EnqueueTask; worldDef.finishTask = FinishTask; diff --git a/test/test_world.c b/test/test_world.c index 99ca0b9f..a2b48a4a 100644 --- a/test/test_world.c +++ b/test/test_world.c @@ -19,7 +19,7 @@ int HelloWorld(void) b2Vec2 gravity = {0.0f, -10.0f}; // Construct a world object, which will hold and simulate the rigid bodies. - b2WorldDef worldDef = b2DefaultWorldDef(); + b2WorldDef worldDef = b2_defaultWorldDef; worldDef.gravity = gravity; b2WorldId worldId = b2CreateWorld(&worldDef); @@ -98,7 +98,7 @@ int HelloWorld(void) int EmptyWorld(void) { - b2WorldDef worldDef = b2DefaultWorldDef(); + b2WorldDef worldDef = b2_defaultWorldDef; b2WorldId worldId = b2CreateWorld(&worldDef); ENSURE(b2World_IsValid(worldId) == true);