diff --git a/.clang-format b/.clang-format index 73b59dd4..7f08d921 100644 --- a/.clang-format +++ b/.clang-format @@ -33,6 +33,7 @@ IncludeCategories: IndentExternBlock: NoIndent IndentCaseLabels: true +IndentPPDirectives: BeforeHash IndentAccessModifiers: false AccessModifierOffset: -4 diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 67c132e0..d281f91e 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -5,7 +5,7 @@ set(DOXYGEN_FILE_PATTERNS *.h) set(DOXYGEN_ENABLE_PREPROCESSING YES) set(DOXYGEN_MACRO_EXPANSION YES) set(DOXYGEN_EXPAND_ONLY_PREDEF YES) -set(DOXYGEN_PREDEFINED BOX2D_API=) +set(DOXYGEN_PREDEFINED B2_API=) set(DOXYGEN_IMAGE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/images") set(DOXYGEN_HTML_EXTRA_STYLESHEET "${CMAKE_CURRENT_SOURCE_DIR}/extra.css") diff --git a/include/box2d/api.h b/include/box2d/api.h index 0fadb4ce..d2008681 100644 --- a/include/box2d/api.h +++ b/include/box2d/api.h @@ -3,14 +3,26 @@ #pragma once -#include "box2d_export.h" - #include +#if defined(_WIN32) && defined(box2d_EXPORTS) + // building the Box2D DLL + #define BOX2D_EXPORT __declspec(dllexport) +#elif defined(_WIN32) && defined(BOX2D_DLL) + // using the Box2D DLL + #define BOX2D_EXPORT __declspec(dllimport) +#elif defined(__GNUC__) && defined(box2d_EXPORTS) + // building the Box2D shared library + #define BOX2D_EXPORT __attribute__((visibility("default"))) +#else + // static library + #define BOX2D_EXPORT +#endif + #ifdef __cplusplus -#define BOX2D_API extern "C" BOX2D_EXPORT + #define B2_API extern "C" BOX2D_EXPORT #else -#define BOX2D_API BOX2D_EXPORT + #define B2_API BOX2D_EXPORT #endif /// Prototype for user allocation function. @@ -24,14 +36,14 @@ typedef void b2FreeFcn(void* mem); /// This allows the user to override the allocation functions. These should be /// set during application startup. -BOX2D_API void b2SetAllocator(b2AllocFcn* allocFcn, b2FreeFcn* freeFcn); +B2_API void b2SetAllocator(b2AllocFcn* allocFcn, b2FreeFcn* freeFcn); /// Total bytes allocated by Box2D -BOX2D_API uint32_t b2GetByteCount(void); +B2_API uint32_t b2GetByteCount(void); /// Prototype for the user assert callback. Return 0 to skip the debugger break. typedef int b2AssertFcn(const char* condition, const char* fileName, int lineNumber); /// Override the default assert callback. /// @param assertFcn a non-null assert callback -BOX2D_API void b2SetAssertFcn(b2AssertFcn* assertFcn); +B2_API void b2SetAssertFcn(b2AssertFcn* assertFcn); diff --git a/include/box2d/box2d.h b/include/box2d/box2d.h index 37a47358..2d5d027a 100644 --- a/include/box2d/box2d.h +++ b/include/box2d/box2d.h @@ -19,7 +19,7 @@ typedef struct b2Segment b2Segment; /** * \defgroup WorldAPI Worlds - * This is the main Box2D API. With this API you can create a simulation world. You can then add bodies and + * These functions allow you to create a simulation world. You can then add bodies and * joints to the world and run the simulation. You can get contact information to get contact points * and normals as well as events. You can query to world, checking for overlaps and casting rays or shapes. * There is also debugging information such as debug draw, timing information, and counters. @@ -27,40 +27,40 @@ typedef struct b2Segment b2Segment; */ /// Create a world for rigid body simulation. This contains all the bodies, shapes, and constraints. -BOX2D_API b2WorldId b2CreateWorld(const b2WorldDef* def); +B2_API b2WorldId b2CreateWorld(const b2WorldDef* def); /// Destroy a world. -BOX2D_API void b2DestroyWorld(b2WorldId worldId); +B2_API void b2DestroyWorld(b2WorldId worldId); /// Take a time step. This performs collision detection, integration, /// and constraint solution. /// @param timeStep the amount of time to simulate, this should not vary. /// @param velocityIterations for the velocity constraint solver. /// @param relaxIterations for reducing constraint bounce solver. -BOX2D_API void b2World_Step(b2WorldId worldId, float timeStep, int32_t velocityIterations, int32_t relaxIterations); +B2_API void b2World_Step(b2WorldId worldId, float timeStep, int32_t velocityIterations, int32_t relaxIterations); /// Call this to draw shapes and other debug draw data. This is intentionally non-const. -BOX2D_API void b2World_Draw(b2WorldId worldId, b2DebugDraw* debugDraw); +B2_API void b2World_Draw(b2WorldId worldId, b2DebugDraw* debugDraw); /// Get sensor events for the current time step. The event data is transient. Do not store a reference to this data. -BOX2D_API b2SensorEvents b2World_GetSensorEvents(b2WorldId worldId); +B2_API b2SensorEvents b2World_GetSensorEvents(b2WorldId worldId); /// Get contact events for this current time step. The event data is transient. Do not store a reference to this data. -BOX2D_API b2ContactEvents b2World_GetContactEvents(b2WorldId worldId); +B2_API b2ContactEvents b2World_GetContactEvents(b2WorldId worldId); /// Query the world for all shapes that potentially overlap the provided AABB. -BOX2D_API void b2World_QueryAABB(b2WorldId worldId, b2QueryResultFcn* fcn, b2AABB aabb, b2QueryFilter filter, void* context); +B2_API void b2World_QueryAABB(b2WorldId worldId, b2QueryResultFcn* fcn, b2AABB aabb, b2QueryFilter filter, void* context); /// Query the world for all shapes that overlap the provided circle. -BOX2D_API void b2World_OverlapCircle(b2WorldId worldId, b2QueryResultFcn* fcn, const b2Circle* circle, b2Transform transform, +B2_API void b2World_OverlapCircle(b2WorldId worldId, b2QueryResultFcn* fcn, const b2Circle* circle, b2Transform transform, b2QueryFilter filter, void* context); /// Query the world for all shapes that overlap the provided capsule. -BOX2D_API void b2World_OverlapCapsule(b2WorldId worldId, b2QueryResultFcn* fcn, const b2Capsule* capsule, b2Transform transform, +B2_API void b2World_OverlapCapsule(b2WorldId worldId, b2QueryResultFcn* fcn, const b2Capsule* capsule, b2Transform transform, b2QueryFilter filter, void* context); /// Query the world for all shapes that overlap the provided polygon. -BOX2D_API void b2World_OverlapPolygon(b2WorldId worldId, b2QueryResultFcn* fcn, const b2Polygon* polygon, b2Transform transform, +B2_API void b2World_OverlapPolygon(b2WorldId worldId, b2QueryResultFcn* fcn, const b2Polygon* polygon, b2Transform transform, b2QueryFilter filter, void* context); /// Ray-cast the world for all shapes in the path of the ray. Your callback @@ -69,48 +69,48 @@ BOX2D_API void b2World_OverlapPolygon(b2WorldId worldId, b2QueryResultFcn* fcn, /// @param callback a user implemented callback class. /// @param point1 the ray starting point /// @param point2 the ray ending point -BOX2D_API void b2World_RayCast(b2WorldId worldId, b2Vec2 origin, b2Vec2 translation, b2QueryFilter filter, b2RayResultFcn* fcn, +B2_API void b2World_RayCast(b2WorldId worldId, b2Vec2 origin, b2Vec2 translation, b2QueryFilter filter, b2RayResultFcn* fcn, void* context); /// Ray-cast closest hit. Convenience function. This is less general than b2World_RayCast and does not allow for custom filtering. -BOX2D_API b2RayResult b2World_RayCastClosest(b2WorldId worldId, b2Vec2 origin, b2Vec2 translation, b2QueryFilter filter); +B2_API b2RayResult b2World_RayCastClosest(b2WorldId worldId, b2Vec2 origin, b2Vec2 translation, b2QueryFilter filter); /// Cast a circle through the world. Similar to a ray-cast except that a circle is cast instead of a point. -BOX2D_API void b2World_CircleCast(b2WorldId worldId, const b2Circle* circle, b2Transform originTransform, b2Vec2 translation, +B2_API void b2World_CircleCast(b2WorldId worldId, const b2Circle* circle, b2Transform originTransform, b2Vec2 translation, b2QueryFilter filter, b2RayResultFcn* fcn, void* context); /// Cast a capsule through the world. Similar to a ray-cast except that a capsule is cast instead of a point. -BOX2D_API void b2World_CapsuleCast(b2WorldId worldId, const b2Capsule* capsule, b2Transform originTransform, b2Vec2 translation, +B2_API void b2World_CapsuleCast(b2WorldId worldId, const b2Capsule* capsule, b2Transform originTransform, b2Vec2 translation, b2QueryFilter filter, b2RayResultFcn* fcn, void* context); /// Cast a capsule through the world. Similar to a ray-cast except that a polygon is cast instead of a point. -BOX2D_API void b2World_PolygonCast(b2WorldId worldId, const b2Polygon* polygon, b2Transform originTransform, b2Vec2 translation, +B2_API void b2World_PolygonCast(b2WorldId worldId, const b2Polygon* polygon, b2Transform originTransform, b2Vec2 translation, b2QueryFilter filter, b2RayResultFcn* fcn, void* context); /// Enable/disable sleep. Advanced feature for testing. -BOX2D_API void b2World_EnableSleeping(b2WorldId worldId, bool flag); +B2_API void b2World_EnableSleeping(b2WorldId worldId, bool flag); /// Enable/disable constraint warm starting. Advanced feature for testing. -BOX2D_API void b2World_EnableWarmStarting(b2WorldId worldId, bool flag); +B2_API void b2World_EnableWarmStarting(b2WorldId worldId, bool flag); /// Enable/disable continuous collision. Advanced feature for testing. -BOX2D_API void b2World_EnableContinuous(b2WorldId worldId, bool flag); +B2_API void b2World_EnableContinuous(b2WorldId worldId, bool flag); /// Adjust the restitution threshold. Advanced feature for testing. -BOX2D_API void b2World_SetRestitutionThreshold(b2WorldId worldId, float value); +B2_API void b2World_SetRestitutionThreshold(b2WorldId worldId, float value); /// Adjust contact tuning parameters: /// - hertz is the contact stiffness (cycles per second) /// - damping ratio is the contact bounciness with 1 being critical damping (non-dimensional) /// - push velocity is the maximum contact constraint push out velocity (meters per second) /// Advanced feature -BOX2D_API void b2World_SetContactTuning(b2WorldId worldId, float hertz, float dampingRatio, float pushVelocity); +B2_API void b2World_SetContactTuning(b2WorldId worldId, float hertz, float dampingRatio, float pushVelocity); /// Get the current profile -BOX2D_API b2Profile b2World_GetProfile(b2WorldId worldId); +B2_API b2Profile b2World_GetProfile(b2WorldId worldId); /// Get counters and sizes -BOX2D_API b2Counters b2World_GetCounters(b2WorldId worldId); +B2_API b2Counters b2World_GetCounters(b2WorldId worldId); /** @} */ @@ -122,56 +122,56 @@ BOX2D_API b2Counters b2World_GetCounters(b2WorldId worldId); /// Create a rigid body given a definition. No reference to the definition is retained. /// @warning This function is locked during callbacks. -BOX2D_API b2BodyId b2CreateBody(b2WorldId worldId, const b2BodyDef* def); +B2_API b2BodyId b2CreateBody(b2WorldId worldId, const b2BodyDef* def); /// Destroy a rigid body given an id. /// @warning This function is locked during callbacks. -BOX2D_API void b2DestroyBody(b2BodyId bodyId); +B2_API void b2DestroyBody(b2BodyId bodyId); /// Get the type of a body -BOX2D_API b2BodyType b2Body_GetType(b2BodyId bodyId); +B2_API b2BodyType b2Body_GetType(b2BodyId bodyId); /// Set the type of a body. This has a similar cost to re-creating the body. -BOX2D_API void b2Body_SetType(b2BodyId bodyId, b2BodyType type); +B2_API void b2Body_SetType(b2BodyId bodyId, b2BodyType type); /// Get the user data stored in a body -BOX2D_API void* b2Body_GetUserData(b2BodyId bodyId); +B2_API void* b2Body_GetUserData(b2BodyId bodyId); /// Get the world position of a body. This is the location of the body origin. -BOX2D_API b2Vec2 b2Body_GetPosition(b2BodyId bodyId); +B2_API b2Vec2 b2Body_GetPosition(b2BodyId bodyId); /// Get the world angle of a body in radians. -BOX2D_API float b2Body_GetAngle(b2BodyId bodyId); +B2_API float b2Body_GetAngle(b2BodyId bodyId); /// Get the world transform of a body. -BOX2D_API b2Transform b2Body_GetTransform(b2BodyId bodyId); +B2_API b2Transform b2Body_GetTransform(b2BodyId bodyId); /// Set the world transform of a body. This acts as a teleport and is fairly expensive. -BOX2D_API void b2Body_SetTransform(b2BodyId bodyId, b2Vec2 position, float angle); +B2_API void b2Body_SetTransform(b2BodyId bodyId, b2Vec2 position, float angle); /// Get a local point on a body given a world point -BOX2D_API b2Vec2 b2Body_GetLocalPoint(b2BodyId bodyId, b2Vec2 worldPoint); +B2_API b2Vec2 b2Body_GetLocalPoint(b2BodyId bodyId, b2Vec2 worldPoint); /// Get a world point on a body given a local point -BOX2D_API b2Vec2 b2Body_GetWorldPoint(b2BodyId bodyId, b2Vec2 localPoint); +B2_API b2Vec2 b2Body_GetWorldPoint(b2BodyId bodyId, b2Vec2 localPoint); /// Get a local vector on a body given a world vector -BOX2D_API b2Vec2 b2Body_GetLocalVector(b2BodyId bodyId, b2Vec2 worldVector); +B2_API b2Vec2 b2Body_GetLocalVector(b2BodyId bodyId, b2Vec2 worldVector); /// Get a world vector on a body given a local vector -BOX2D_API b2Vec2 b2Body_GetWorldVector(b2BodyId bodyId, b2Vec2 localVector); +B2_API b2Vec2 b2Body_GetWorldVector(b2BodyId bodyId, b2Vec2 localVector); /// Get the linear velocity of a body's center of mass -BOX2D_API b2Vec2 b2Body_GetLinearVelocity(b2BodyId bodyId); +B2_API b2Vec2 b2Body_GetLinearVelocity(b2BodyId bodyId); /// Get the angular velocity of a body in radians per second -BOX2D_API float b2Body_GetAngularVelocity(b2BodyId bodyId); +B2_API float b2Body_GetAngularVelocity(b2BodyId bodyId); /// Set the linear velocity of a body -BOX2D_API void b2Body_SetLinearVelocity(b2BodyId bodyId, b2Vec2 linearVelocity); +B2_API void b2Body_SetLinearVelocity(b2BodyId bodyId, b2Vec2 linearVelocity); /// Set the angular velocity of a body in radians per second -BOX2D_API void b2Body_SetAngularVelocity(b2BodyId bodyId, float angularVelocity); +B2_API void b2Body_SetAngularVelocity(b2BodyId bodyId, float angularVelocity); /// Apply a force at a world point. If the force is not /// applied at the center of mass, it will generate a torque and @@ -179,18 +179,18 @@ BOX2D_API void b2Body_SetAngularVelocity(b2BodyId bodyId, float angularVelocity) /// @param force the world force vector, usually in Newtons (N). /// @param point the world position of the point of application. /// @param wake also wake up the body -BOX2D_API void b2Body_ApplyForce(b2BodyId bodyId, b2Vec2 force, b2Vec2 point, bool wake); +B2_API void b2Body_ApplyForce(b2BodyId bodyId, b2Vec2 force, b2Vec2 point, bool wake); /// Apply a force to the center of mass. This wakes up the body. /// @param force the world force vector, usually in Newtons (N). /// @param wake also wake up the body -BOX2D_API void b2Body_ApplyForceToCenter(b2BodyId bodyId, b2Vec2 force, bool wake); +B2_API void b2Body_ApplyForceToCenter(b2BodyId bodyId, b2Vec2 force, bool wake); /// Apply a torque. This affects the angular velocity /// without affecting the linear velocity of the center of mass. /// @param torque about the z-axis (out of the screen), usually in N-m. /// @param wake also wake up the body -BOX2D_API void b2Body_ApplyTorque(b2BodyId bodyId, float torque, bool wake); +B2_API void b2Body_ApplyTorque(b2BodyId bodyId, float torque, bool wake); /// Apply an impulse at a point. This immediately modifies the velocity. /// It also modifies the angular velocity if the point of application @@ -198,59 +198,59 @@ BOX2D_API void b2Body_ApplyTorque(b2BodyId bodyId, float torque, bool wake); /// @param impulse the world impulse vector, usually in N-seconds or kg-m/s. /// @param point the world position of the point of application. /// @param wake also wake up the body -BOX2D_API void b2Body_ApplyLinearImpulse(b2BodyId bodyId, b2Vec2 impulse, b2Vec2 point, bool wake); +B2_API void b2Body_ApplyLinearImpulse(b2BodyId bodyId, b2Vec2 impulse, b2Vec2 point, bool wake); /// Apply an impulse to the center of mass. This immediately modifies the velocity. /// @param impulse the world impulse vector, usually in N-seconds or kg-m/s. /// @param wake also wake up the body -BOX2D_API void b2Body_ApplyLinearImpulseToCenter(b2BodyId bodyId, b2Vec2 impulse, bool wake); +B2_API void b2Body_ApplyLinearImpulseToCenter(b2BodyId bodyId, b2Vec2 impulse, bool wake); /// Apply an angular impulse. /// @param impulse the angular impulse in units of kg*m*m/s /// @param wake also wake up the body -BOX2D_API void b2Body_ApplyAngularImpulse(b2BodyId bodyId, float impulse, bool wake); +B2_API void b2Body_ApplyAngularImpulse(b2BodyId bodyId, float impulse, bool wake); /// Get the mass of the body (kilograms) -BOX2D_API float b2Body_GetMass(b2BodyId bodyId); +B2_API float b2Body_GetMass(b2BodyId bodyId); /// Get the inertia tensor of the body. In 2D this is a single number. (kilograms * meters^2) -BOX2D_API float b2Body_GetInertiaTensor(b2BodyId bodyId); +B2_API float b2Body_GetInertiaTensor(b2BodyId bodyId); /// Get the center of mass position of the body in local space. -BOX2D_API b2Vec2 b2Body_GetLocalCenterOfMass(b2BodyId bodyId); +B2_API b2Vec2 b2Body_GetLocalCenterOfMass(b2BodyId bodyId); /// Get the center of mass position of the body in world space. -BOX2D_API b2Vec2 b2Body_GetWorldCenterOfMass(b2BodyId bodyId); +B2_API b2Vec2 b2Body_GetWorldCenterOfMass(b2BodyId bodyId); /// Override the body's mass properties. Normally this is computed automatically using the /// shape geometry and density. This information is lost if a shape is added or removed or if the /// body type changes. -BOX2D_API void b2Body_SetMassData(b2BodyId bodyId, b2MassData massData); +B2_API void b2Body_SetMassData(b2BodyId bodyId, b2MassData massData); /// Is this body awake? -BOX2D_API bool b2Body_IsAwake(b2BodyId bodyId); +B2_API bool b2Body_IsAwake(b2BodyId bodyId); /// Wake a body from sleep. This wakes the entire island the body is touching. -BOX2D_API void b2Body_Wake(b2BodyId bodyId); +B2_API void b2Body_Wake(b2BodyId bodyId); /// Is this body enabled? -BOX2D_API bool b2Body_IsEnabled(b2BodyId bodyId); +B2_API bool b2Body_IsEnabled(b2BodyId bodyId); /// Disable a body by removing it completely from the simulation -BOX2D_API void b2Body_Disable(b2BodyId bodyId); +B2_API void b2Body_Disable(b2BodyId bodyId); /// Enable a body by adding it to the simulation -BOX2D_API void b2Body_Enable(b2BodyId bodyId); +B2_API void b2Body_Enable(b2BodyId bodyId); /// Iterate over shapes on a body -BOX2D_API b2ShapeId b2Body_GetFirstShape(b2BodyId bodyId); -BOX2D_API b2ShapeId b2Body_GetNextShape(b2ShapeId shapeId); +B2_API b2ShapeId b2Body_GetFirstShape(b2BodyId bodyId); +B2_API b2ShapeId b2Body_GetNextShape(b2ShapeId shapeId); /// Get the maximum capacity required for retrieving all the touching contacts on a body -BOX2D_API int32_t b2Body_GetContactCapacity(b2BodyId bodyId); +B2_API int32_t b2Body_GetContactCapacity(b2BodyId bodyId); /// Get the touching contact data for a body -BOX2D_API int32_t b2Body_GetContactData(b2BodyId bodyId, b2ContactData* contactData, int32_t capacity); +B2_API int32_t b2Body_GetContactData(b2BodyId bodyId, b2ContactData* contactData, int32_t capacity); /** @} */ @@ -263,82 +263,82 @@ BOX2D_API int32_t b2Body_GetContactData(b2BodyId bodyId, b2ContactData* contactD /// Create a circle shape and attach it to a body. The shape defintion and geometry are fully cloned. /// Contacts are not created until the next time step. /// @return the shape id for accessing the shape -BOX2D_API b2ShapeId b2CreateCircleShape(b2BodyId bodyId, const b2ShapeDef* def, const b2Circle* circle); +B2_API b2ShapeId b2CreateCircleShape(b2BodyId bodyId, const b2ShapeDef* def, const b2Circle* circle); /// Create a line segment shape and attach it to a body. The shape defintion and geometry are fully cloned. /// Contacts are not created until the next time step. /// @return the shape id for accessing the shape -BOX2D_API b2ShapeId b2CreateSegmentShape(b2BodyId bodyId, const b2ShapeDef* def, const b2Segment* segment); +B2_API b2ShapeId b2CreateSegmentShape(b2BodyId bodyId, const b2ShapeDef* def, const b2Segment* segment); /// Create a capsule shape and attach it to a body. The shape defintion and geometry are fully cloned. /// Contacts are not created until the next time step. /// @return the shape id for accessing the shape -BOX2D_API b2ShapeId b2CreateCapsuleShape(b2BodyId bodyId, const b2ShapeDef* def, const b2Capsule* capsule); +B2_API b2ShapeId b2CreateCapsuleShape(b2BodyId bodyId, const b2ShapeDef* def, const b2Capsule* capsule); /// Create a polygon shape and attach it to a body. The shape defintion and geometry are fully cloned. /// Contacts are not created until the next time step. /// @return the shape id for accessing the shape -BOX2D_API b2ShapeId b2CreatePolygonShape(b2BodyId bodyId, const b2ShapeDef* def, const b2Polygon* polygon); +B2_API b2ShapeId b2CreatePolygonShape(b2BodyId bodyId, const b2ShapeDef* def, const b2Polygon* polygon); /// Destroy any shape type -BOX2D_API void b2DestroyShape(b2ShapeId shapeId); +B2_API void b2DestroyShape(b2ShapeId shapeId); /// Create a chain shape /// @see b2ChainDef for details -BOX2D_API b2ChainId b2CreateChain(b2BodyId bodyId, const b2ChainDef* def); +B2_API b2ChainId b2CreateChain(b2BodyId bodyId, const b2ChainDef* def); /// Destroy a chain shape -BOX2D_API void b2DestroyChain(b2ChainId chainId); +B2_API void b2DestroyChain(b2ChainId chainId); /// Get the body that a shape is attached to -BOX2D_API b2BodyId b2Shape_GetBody(b2ShapeId shapeId); +B2_API b2BodyId b2Shape_GetBody(b2ShapeId shapeId); /// Get the user data for a shape. This is useful when you get a shape id /// from an event or query -BOX2D_API void* b2Shape_GetUserData(b2ShapeId shapeId); +B2_API void* b2Shape_GetUserData(b2ShapeId shapeId); /// Test a point for overlap with a shape -BOX2D_API bool b2Shape_TestPoint(b2ShapeId shapeId, b2Vec2 point); +B2_API bool b2Shape_TestPoint(b2ShapeId shapeId, b2Vec2 point); /// Set the friction on a shape. Normally this is specified in b2ShapeDef. -BOX2D_API void b2Shape_SetFriction(b2ShapeId shapeId, float friction); +B2_API void b2Shape_SetFriction(b2ShapeId shapeId, float friction); /// Set the restitution (bounciness) on a shape. Normally this is specified in b2ShapeDef. -BOX2D_API void b2Shape_SetRestitution(b2ShapeId shapeId, float restitution); +B2_API void b2Shape_SetRestitution(b2ShapeId shapeId, float restitution); /// Get the type of a shape. -BOX2D_API b2ShapeType b2Shape_GetType(b2ShapeId shapeId); +B2_API b2ShapeType b2Shape_GetType(b2ShapeId shapeId); /// Access the circle geometry of a shape. -BOX2D_API const b2Circle* b2Shape_GetCircle(b2ShapeId shapeId); +B2_API const b2Circle* b2Shape_GetCircle(b2ShapeId shapeId); /// Access the line segment geometry of a shape. -BOX2D_API const b2Segment* b2Shape_GetSegment(b2ShapeId shapeId); +B2_API const b2Segment* b2Shape_GetSegment(b2ShapeId shapeId); /// Access the smooth line segment geometry of a shape. These come from chain shapes. -BOX2D_API const b2SmoothSegment* b2Shape_GetSmoothSegment(b2ShapeId shapeId); +B2_API const b2SmoothSegment* b2Shape_GetSmoothSegment(b2ShapeId shapeId); /// Access the capsule geometry of a shape. -BOX2D_API const b2Capsule* b2Shape_GetCapsule(b2ShapeId shapeId); +B2_API const b2Capsule* b2Shape_GetCapsule(b2ShapeId shapeId); /// Access the convex polygon geometry of a shape. -BOX2D_API const b2Polygon* b2Shape_GetPolygon(b2ShapeId shapeId); +B2_API const b2Polygon* b2Shape_GetPolygon(b2ShapeId shapeId); /// If the type is b2_smoothSegmentShape then you can get the parent chain id. /// If the shape is not a smooth segment then this will return b2_nullChainId. -BOX2D_API b2ChainId b2Shape_GetParentChain(b2ShapeId shapeId); +B2_API b2ChainId b2Shape_GetParentChain(b2ShapeId shapeId); /// Set the friction of a chain. Normally this is set in b2ChainDef. -BOX2D_API void b2Chain_SetFriction(b2ChainId chainId, float friction); +B2_API void b2Chain_SetFriction(b2ChainId chainId, float friction); /// Set the restitution (bounciness) on a chain. Normally this is specified in b2ChainDef. -BOX2D_API void b2Chain_SetRestitution(b2ChainId chainId, float restitution); +B2_API void b2Chain_SetRestitution(b2ChainId chainId, float restitution); /// Get the maximum capacity required for retrieving all the touching contacts on a shape -BOX2D_API int32_t b2Shape_GetContactCapacity(b2ShapeId shapeId); +B2_API int32_t b2Shape_GetContactCapacity(b2ShapeId shapeId); /// Get the touching contact data for a shape. The provided shapeId will be either shapeIdA or shapeIdB on the contact data. -BOX2D_API int32_t b2Shape_GetContactData(b2ShapeId shapeId, b2ContactData* contactData, int32_t capacity); +B2_API int32_t b2Shape_GetContactData(b2ShapeId shapeId, b2ContactData* contactData, int32_t capacity); /** @} */ @@ -350,146 +350,146 @@ BOX2D_API int32_t b2Shape_GetContactData(b2ShapeId shapeId, b2ContactData* conta /// Create a distance joint /// @see b2DistanceJointDef for details -BOX2D_API b2JointId b2CreateDistanceJoint(b2WorldId worldId, const b2DistanceJointDef* def); +B2_API b2JointId b2CreateDistanceJoint(b2WorldId worldId, const b2DistanceJointDef* def); /// Create a motor joint /// @see b2MotorJointDef for details -BOX2D_API b2JointId b2CreateMotorJoint(b2WorldId worldId, const b2MotorJointDef* def); +B2_API b2JointId b2CreateMotorJoint(b2WorldId worldId, const b2MotorJointDef* def); /// Create a mouse joint /// @see b2MouseJointDef for details -BOX2D_API b2JointId b2CreateMouseJoint(b2WorldId worldId, const b2MouseJointDef* def); +B2_API b2JointId b2CreateMouseJoint(b2WorldId worldId, const b2MouseJointDef* def); /// Create a prismatic (slider) joint /// @see b2PrismaticJointDef for details -BOX2D_API b2JointId b2CreatePrismaticJoint(b2WorldId worldId, const b2PrismaticJointDef* def); +B2_API b2JointId b2CreatePrismaticJoint(b2WorldId worldId, const b2PrismaticJointDef* def); /// Create a revolute (hinge) joint /// @see b2RevoluteJointDef for details -BOX2D_API b2JointId b2CreateRevoluteJoint(b2WorldId worldId, const b2RevoluteJointDef* def); +B2_API b2JointId b2CreateRevoluteJoint(b2WorldId worldId, const b2RevoluteJointDef* def); /// Create a weld joint /// @see b2WeldJointDef for details -BOX2D_API b2JointId b2CreateWeldJoint(b2WorldId worldId, const b2WeldJointDef* def); +B2_API b2JointId b2CreateWeldJoint(b2WorldId worldId, const b2WeldJointDef* def); /// Create a wheel joint /// @see b2WheelJointDef for details -BOX2D_API b2JointId b2CreateWheelJoint(b2WorldId worldId, const b2WheelJointDef* def); +B2_API b2JointId b2CreateWheelJoint(b2WorldId worldId, const b2WheelJointDef* def); /// Destroy any joint type -BOX2D_API void b2DestroyJoint(b2JointId jointId); +B2_API void b2DestroyJoint(b2JointId jointId); /// Get body A on a joint -BOX2D_API b2BodyId b2Joint_GetBodyA(b2JointId jointId); +B2_API b2BodyId b2Joint_GetBodyA(b2JointId jointId); /// Get body B on a joint -BOX2D_API b2BodyId b2Joint_GetBodyB(b2JointId jointId); +B2_API b2BodyId b2Joint_GetBodyB(b2JointId jointId); /// Get the constraint force on a distance joint -BOX2D_API float b2DistanceJoint_GetConstraintForce(b2JointId jointId, float timeStep); +B2_API float b2DistanceJoint_GetConstraintForce(b2JointId jointId, float timeStep); /// Set the length parameters of a distance joint /// @see b2DistanceJointDef for details -BOX2D_API void b2DistanceJoint_SetLength(b2JointId jointId, float length, float minLength, float maxLength); +B2_API void b2DistanceJoint_SetLength(b2JointId jointId, float length, float minLength, float maxLength); /// Get the current length of a distance joint -BOX2D_API float b2DistanceJoint_GetCurrentLength(b2JointId jointId); +B2_API float b2DistanceJoint_GetCurrentLength(b2JointId jointId); /// Adjust the softness of a distance joint /// @see b2DistanceJointDef for details -BOX2D_API void b2DistanceJoint_SetTuning(b2JointId jointId, float hertz, float dampingRatio); +B2_API void b2DistanceJoint_SetTuning(b2JointId jointId, float hertz, float dampingRatio); /// Set the linear offset target for a motor joint -BOX2D_API void b2MotorJoint_SetLinearOffset(b2JointId jointId, b2Vec2 linearOffset); +B2_API void b2MotorJoint_SetLinearOffset(b2JointId jointId, b2Vec2 linearOffset); /// Set the angular offset target for a motor joint in radians -BOX2D_API void b2MotorJoint_SetAngularOffset(b2JointId jointId, float angularOffset); +B2_API void b2MotorJoint_SetAngularOffset(b2JointId jointId, float angularOffset); /// Set the maximum force for a motor joint -BOX2D_API void b2MotorJoint_SetMaxForce(b2JointId jointId, float maxForce); +B2_API void b2MotorJoint_SetMaxForce(b2JointId jointId, float maxForce); /// Set the maximum torque for a motor joint -BOX2D_API void b2MotorJoint_SetMaxTorque(b2JointId jointId, float maxTorque); +B2_API void b2MotorJoint_SetMaxTorque(b2JointId jointId, float maxTorque); /// Set the correction factor for a motor joint -BOX2D_API void b2MotorJoint_SetCorrectionFactor(b2JointId jointId, float correctionFactor); +B2_API void b2MotorJoint_SetCorrectionFactor(b2JointId jointId, float correctionFactor); /// Get the current constraint force for a motor joint -BOX2D_API b2Vec2 b2MotorJoint_GetConstraintForce(b2JointId jointId, float inverseTimeStep); +B2_API b2Vec2 b2MotorJoint_GetConstraintForce(b2JointId jointId, float inverseTimeStep); /// Get the current constraint torque for a motor joint -BOX2D_API float b2MotorJoint_GetConstraintTorque(b2JointId jointId, float inverseTimeStep); +B2_API float b2MotorJoint_GetConstraintTorque(b2JointId jointId, float inverseTimeStep); /// Set the target for a mouse joint -BOX2D_API void b2MouseJoint_SetTarget(b2JointId jointId, b2Vec2 target); +B2_API void b2MouseJoint_SetTarget(b2JointId jointId, b2Vec2 target); /// Enable/disable a prismatic joint limit -BOX2D_API void b2PrismaticJoint_EnableLimit(b2JointId jointId, bool enableLimit); +B2_API void b2PrismaticJoint_EnableLimit(b2JointId jointId, bool enableLimit); /// Enable/disable a prismatic joint motor -BOX2D_API void b2PrismaticJoint_EnableMotor(b2JointId jointId, bool enableMotor); +B2_API void b2PrismaticJoint_EnableMotor(b2JointId jointId, bool enableMotor); /// Set the motor speed for a prismatic joint -BOX2D_API void b2PrismaticJoint_SetMotorSpeed(b2JointId jointId, float motorSpeed); +B2_API void b2PrismaticJoint_SetMotorSpeed(b2JointId jointId, float motorSpeed); /// Get the current motor force for a prismatic joint -BOX2D_API float b2PrismaticJoint_GetMotorForce(b2JointId jointId, float inverseTimeStep); +B2_API float b2PrismaticJoint_GetMotorForce(b2JointId jointId, float inverseTimeStep); /// Set the maximum force for a pristmatic joint motor -BOX2D_API void b2PrismaticJoint_SetMaxMotorForce(b2JointId jointId, float force); +B2_API void b2PrismaticJoint_SetMaxMotorForce(b2JointId jointId, float force); /// Get the current constraint force for a prismatic joint -BOX2D_API b2Vec2 b2PrismaticJoint_GetConstraintForce(b2JointId jointId, float inverseTimeStep); +B2_API b2Vec2 b2PrismaticJoint_GetConstraintForce(b2JointId jointId, float inverseTimeStep); /// Get the current constraint torque for a prismatic joint -BOX2D_API float b2PrismaticJoint_GetConstraintTorque(b2JointId jointId, float inverseTimeStep); +B2_API float b2PrismaticJoint_GetConstraintTorque(b2JointId jointId, float inverseTimeStep); /// Enable/disable a revolute joint limit -BOX2D_API void b2RevoluteJoint_EnableLimit(b2JointId jointId, bool enableLimit); +B2_API void b2RevoluteJoint_EnableLimit(b2JointId jointId, bool enableLimit); /// Enable/disable a revolute joint motor -BOX2D_API void b2RevoluteJoint_EnableMotor(b2JointId jointId, bool enableMotor); +B2_API void b2RevoluteJoint_EnableMotor(b2JointId jointId, bool enableMotor); /// Set the motor speed for a revolute joint in radians per second -BOX2D_API void b2RevoluteJoint_SetMotorSpeed(b2JointId jointId, float motorSpeed); +B2_API void b2RevoluteJoint_SetMotorSpeed(b2JointId jointId, float motorSpeed); /// Get the current motor torque for a revolute joint -BOX2D_API float b2RevoluteJoint_GetMotorTorque(b2JointId jointId, float inverseTimeStep); +B2_API float b2RevoluteJoint_GetMotorTorque(b2JointId jointId, float inverseTimeStep); /// Set the maximum torque for a revolute joint motor -BOX2D_API void b2RevoluteJoint_SetMaxMotorTorque(b2JointId jointId, float torque); +B2_API void b2RevoluteJoint_SetMaxMotorTorque(b2JointId jointId, float torque); /// Get the current constraint force for a revolute joint -BOX2D_API b2Vec2 b2RevoluteJoint_GetConstraintForce(b2JointId jointId, float inverseTimeStep); +B2_API b2Vec2 b2RevoluteJoint_GetConstraintForce(b2JointId jointId, float inverseTimeStep); /// Get the current constraint torque for a revolute joint -BOX2D_API float b2RevoluteJoint_GetConstraintTorque(b2JointId jointId, float inverseTimeStep); +B2_API float b2RevoluteJoint_GetConstraintTorque(b2JointId jointId, float inverseTimeStep); /// Set the wheel joint stiffness -BOX2D_API void b2WheelJoint_SetStiffness(b2JointId jointId, float stiffness); +B2_API void b2WheelJoint_SetStiffness(b2JointId jointId, float stiffness); /// Set the wheel joint damping -BOX2D_API void b2WheelJoint_SetDamping(b2JointId jointId, float damping); +B2_API void b2WheelJoint_SetDamping(b2JointId jointId, float damping); /// Enable/disable the wheel joint limit -BOX2D_API void b2WheelJoint_EnableLimit(b2JointId jointId, bool enableLimit); +B2_API void b2WheelJoint_EnableLimit(b2JointId jointId, bool enableLimit); /// Enable/disable the wheel joint motor -BOX2D_API void b2WheelJoint_EnableMotor(b2JointId jointId, bool enableMotor); +B2_API void b2WheelJoint_EnableMotor(b2JointId jointId, bool enableMotor); /// Set the wheel joint motor speed in radians per second -BOX2D_API void b2WheelJoint_SetMotorSpeed(b2JointId jointId, float motorSpeed); +B2_API void b2WheelJoint_SetMotorSpeed(b2JointId jointId, float motorSpeed); /// Get the wheel joint current motor torque -BOX2D_API float b2WheelJoint_GetMotorTorque(b2JointId jointId, float inverseTimeStep); +B2_API float b2WheelJoint_GetMotorTorque(b2JointId jointId, float inverseTimeStep); /// Set the wheel joint maximum motor torque -BOX2D_API void b2WheelJoint_SetMaxMotorTorque(b2JointId jointId, float torque); +B2_API void b2WheelJoint_SetMaxMotorTorque(b2JointId jointId, float torque); /// Get the current wheel joint constraint force -BOX2D_API b2Vec2 b2WheelJoint_GetConstraintForce(b2JointId jointId, float inverseTimeStep); +B2_API b2Vec2 b2WheelJoint_GetConstraintForce(b2JointId jointId, float inverseTimeStep); /// Get the current wheel joint constraint torque -BOX2D_API float b2WheelJoint_GetConstraintTorque(b2JointId jointId, float inverseTimeStep); +B2_API float b2WheelJoint_GetConstraintTorque(b2JointId jointId, float inverseTimeStep); /** @} */ diff --git a/include/box2d/callbacks.h b/include/box2d/callbacks.h index a9cea917..28b2f85c 100644 --- a/include/box2d/callbacks.h +++ b/include/box2d/callbacks.h @@ -23,7 +23,7 @@ typedef struct b2Manifold b2Manifold; typedef bool b2PreSolveFcn(b2ShapeId shapeIdA, b2ShapeId shapeIdB, b2Manifold* manifold, void* context); /// Register the pre-solve callback. This is optional. -BOX2D_API void b2World_SetPreSolveCallback(b2WorldId worldId, b2PreSolveFcn* fcn, void* context); +B2_API void b2World_SetPreSolveCallback(b2WorldId worldId, b2PreSolveFcn* fcn, void* context); /// Prototype callback for AABB queries. /// See b2World_Query diff --git a/include/box2d/distance.h b/include/box2d/distance.h index 3b72a1d4..e4a4b44e 100644 --- a/include/box2d/distance.h +++ b/include/box2d/distance.h @@ -17,7 +17,7 @@ typedef struct b2SegmentDistanceResult } b2SegmentDistanceResult; /// Compute the distance between two line segments, clamping at the end points if needed. -BOX2D_API b2SegmentDistanceResult b2SegmentDistance(b2Vec2 p1, b2Vec2 q1, b2Vec2 p2, b2Vec2 q2); +B2_API b2SegmentDistanceResult b2SegmentDistance(b2Vec2 p1, b2Vec2 q1, b2Vec2 p2, b2Vec2 q2); /// A distance proxy is used by the GJK algorithm. It encapsulates any shape. typedef struct b2DistanceProxy @@ -63,7 +63,7 @@ typedef struct b2DistanceOutput /// Compute the closest points between two shapes. Supports any combination of: /// b2Circle, b2Polygon, b2EdgeShape. The simplex cache is input/output. /// On the first call set b2SimplexCache.count to zero. -BOX2D_API b2DistanceOutput b2ShapeDistance(b2DistanceCache* cache, const b2DistanceInput* input); +B2_API b2DistanceOutput b2ShapeDistance(b2DistanceCache* cache, const b2DistanceInput* input); /// Input parameters for b2ShapeCast typedef struct b2ShapeCastPairInput @@ -78,10 +78,10 @@ typedef struct b2ShapeCastPairInput /// Perform a linear shape cast of shape B moving and shape A fixed. Determines the hit point, normal, and translation fraction. /// @returns true if hit, false if there is no hit or an initial overlap -BOX2D_API b2RayCastOutput b2ShapeCast(const b2ShapeCastPairInput* input); +B2_API b2RayCastOutput b2ShapeCast(const b2ShapeCastPairInput* input); /// Make a proxy for use in GJK and related functions. -BOX2D_API b2DistanceProxy b2MakeProxy(const b2Vec2* vertices, int32_t count, float radius); +B2_API b2DistanceProxy b2MakeProxy(const b2Vec2* vertices, int32_t count, float radius); /// This describes the motion of a body/shape for TOI computation. Shapes are defined with respect to the body origin, /// which may not coincide with the center of mass. However, to support dynamics we must interpolate the center of mass @@ -98,7 +98,7 @@ typedef struct b2Sweep float a1, a2; } b2Sweep; -BOX2D_API b2Transform b2GetSweepTransform(const b2Sweep* sweep, float time); +B2_API b2Transform b2GetSweepTransform(const b2Sweep* sweep, float time); /// Input parameters for b2TimeOfImpact typedef struct b2TOIInput @@ -133,4 +133,4 @@ typedef struct b2TOIOutput /// a fraction between [0,tMax]. This uses a swept separating axis and may miss some intermediate, /// non-tunneling collisions. If you change the time interval, you should call this function /// again. -BOX2D_API b2TOIOutput b2TimeOfImpact(const b2TOIInput* input); +B2_API b2TOIOutput b2TimeOfImpact(const b2TOIInput* input); diff --git a/include/box2d/dynamic_tree.h b/include/box2d/dynamic_tree.h index 64c60b3c..eb15a731 100644 --- a/include/box2d/dynamic_tree.h +++ b/include/box2d/dynamic_tree.h @@ -64,25 +64,25 @@ typedef struct b2DynamicTree } b2DynamicTree; /// Constructing the tree initializes the node pool. -BOX2D_API b2DynamicTree b2DynamicTree_Create(void); +B2_API b2DynamicTree b2DynamicTree_Create(void); /// Destroy the tree, freeing the node pool. -BOX2D_API void b2DynamicTree_Destroy(b2DynamicTree* tree); +B2_API void b2DynamicTree_Destroy(b2DynamicTree* tree); /// Create a proxy. Provide a tight fitting AABB and a userData value. -BOX2D_API int32_t b2DynamicTree_CreateProxy(b2DynamicTree* tree, b2AABB aabb, uint32_t categoryBits, int32_t userData); +B2_API int32_t b2DynamicTree_CreateProxy(b2DynamicTree* tree, b2AABB aabb, uint32_t categoryBits, int32_t userData); /// Destroy a proxy. This asserts if the id is invalid. -BOX2D_API void b2DynamicTree_DestroyProxy(b2DynamicTree* tree, int32_t proxyId); +B2_API void b2DynamicTree_DestroyProxy(b2DynamicTree* tree, int32_t proxyId); // Clone one tree to another, reusing storage in the outTree if possible -BOX2D_API void b2DynamicTree_Clone(b2DynamicTree* outTree, const b2DynamicTree* inTree); +B2_API void b2DynamicTree_Clone(b2DynamicTree* outTree, const b2DynamicTree* inTree); /// Move a proxy to a new AABB by removing and reinserting into the tree. -BOX2D_API void b2DynamicTree_MoveProxy(b2DynamicTree* tree, int32_t proxyId, b2AABB aabb); +B2_API void b2DynamicTree_MoveProxy(b2DynamicTree* tree, int32_t proxyId, b2AABB aabb); /// Enlarge a proxy and enlarge ancestors as necessary. -BOX2D_API void b2DynamicTree_EnlargeProxy(b2DynamicTree* tree, int32_t proxyId, b2AABB aabb); +B2_API void b2DynamicTree_EnlargeProxy(b2DynamicTree* tree, int32_t proxyId, b2AABB aabb); /// This function receives proxies found in the AABB query. /// @return true if the query should continue @@ -90,12 +90,12 @@ typedef bool b2TreeQueryCallbackFcn(int32_t proxyId, int32_t userData, void* con /// Query an AABB for overlapping proxies. The callback class /// is called for each proxy that overlaps the supplied AABB. -BOX2D_API void b2DynamicTree_QueryFiltered(const b2DynamicTree* tree, b2AABB aabb, uint32_t maskBits, +B2_API void b2DynamicTree_QueryFiltered(const b2DynamicTree* tree, b2AABB aabb, uint32_t maskBits, b2TreeQueryCallbackFcn* callback, void* context); /// Query an AABB for overlapping proxies. The callback class /// is called for each proxy that overlaps the supplied AABB. -BOX2D_API void b2DynamicTree_Query(const b2DynamicTree* tree, b2AABB aabb, b2TreeQueryCallbackFcn* callback, void* context); +B2_API void b2DynamicTree_Query(const b2DynamicTree* tree, b2AABB aabb, b2TreeQueryCallbackFcn* callback, void* context); /// This function receives clipped raycast input for a proxy. The function /// returns the new ray fraction. @@ -111,7 +111,7 @@ typedef float b2TreeRayCastCallbackFcn(const b2RayCastInput* input, int32_t prox /// number of proxies in the tree. /// @param input the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1). /// @param callback a callback class that is called for each proxy that is hit by the ray. -BOX2D_API void b2DynamicTree_RayCast(const b2DynamicTree* tree, const b2RayCastInput* input, uint32_t maskBits, +B2_API void b2DynamicTree_RayCast(const b2DynamicTree* tree, const b2RayCastInput* input, uint32_t maskBits, b2TreeRayCastCallbackFcn* callback, void* context); /// This function receives clipped raycast input for a proxy. The function @@ -128,35 +128,35 @@ typedef float b2TreeShapeCastCallbackFcn(const b2ShapeCastInput* input, int32_t /// number of proxies in the tree. /// @param input the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1). /// @param callback a callback class that is called for each proxy that is hit by the ray. -BOX2D_API void b2DynamicTree_ShapeCast(const b2DynamicTree* tree, const b2ShapeCastInput* input, uint32_t maskBits, +B2_API void b2DynamicTree_ShapeCast(const b2DynamicTree* tree, const b2ShapeCastInput* input, uint32_t maskBits, b2TreeShapeCastCallbackFcn* callback, void* context); /// Validate this tree. For testing. -BOX2D_API void b2DynamicTree_Validate(const b2DynamicTree* tree); +B2_API void b2DynamicTree_Validate(const b2DynamicTree* tree); /// Compute the height of the binary tree in O(N) time. Should not be /// called often. -BOX2D_API int32_t b2DynamicTree_GetHeight(const b2DynamicTree* tree); +B2_API int32_t b2DynamicTree_GetHeight(const b2DynamicTree* tree); /// Get the maximum balance of the tree. The balance is the difference in height of the two children of a node. -BOX2D_API int32_t b2DynamicTree_GetMaxBalance(const b2DynamicTree* tree); +B2_API int32_t b2DynamicTree_GetMaxBalance(const b2DynamicTree* tree); /// Get the ratio of the sum of the node areas to the root area. -BOX2D_API float b2DynamicTree_GetAreaRatio(const b2DynamicTree* tree); +B2_API float b2DynamicTree_GetAreaRatio(const b2DynamicTree* tree); /// Build an optimal tree. Very expensive. For testing. -BOX2D_API void b2DynamicTree_RebuildBottomUp(b2DynamicTree* tree); +B2_API void b2DynamicTree_RebuildBottomUp(b2DynamicTree* tree); /// Get the number of proxies created -BOX2D_API int32_t b2DynamicTree_GetProxyCount(const b2DynamicTree* tree); +B2_API int32_t b2DynamicTree_GetProxyCount(const b2DynamicTree* tree); /// Rebuild the tree while retaining subtrees that haven't changed. Returns the number of boxes sorted. -BOX2D_API int32_t b2DynamicTree_Rebuild(b2DynamicTree* tree, bool fullBuild); +B2_API int32_t b2DynamicTree_Rebuild(b2DynamicTree* tree, bool fullBuild); /// Shift the world origin. Useful for large worlds. /// The shift formula is: position -= newOrigin /// @param newOrigin the new origin with respect to the old origin -BOX2D_API void b2DynamicTree_ShiftOrigin(b2DynamicTree* tree, b2Vec2 newOrigin); +B2_API void b2DynamicTree_ShiftOrigin(b2DynamicTree* tree, b2Vec2 newOrigin); /// Get proxy user data /// @return the proxy user data or 0 if the id is invalid diff --git a/include/box2d/geometry.h b/include/box2d/geometry.h index ce08bfd8..a39dfe69 100644 --- a/include/box2d/geometry.h +++ b/include/box2d/geometry.h @@ -78,80 +78,80 @@ typedef struct b2SmoothSegment } b2SmoothSegment; /// Validate ray cast input data (NaN, etc) -BOX2D_API bool b2IsValidRay(const b2RayCastInput* input); +B2_API bool b2IsValidRay(const b2RayCastInput* input); /// Make a convex polygon from a convex hull. This will assert if the hull is not valid. -BOX2D_API b2Polygon b2MakePolygon(const b2Hull* hull, float radius); +B2_API b2Polygon b2MakePolygon(const b2Hull* hull, float radius); /// Make an offset convex polygon from a convex hull. This will assert if the hull is not valid. -BOX2D_API b2Polygon b2MakeOffsetPolygon(const b2Hull* hull, float radius, b2Transform transform); +B2_API b2Polygon b2MakeOffsetPolygon(const b2Hull* hull, float radius, b2Transform transform); /// Make a square polygon, bypassing the need for a convex hull. -BOX2D_API b2Polygon b2MakeSquare(float h); +B2_API b2Polygon b2MakeSquare(float h); /// Make a box (rectangle) polygon, bypassing the need for a convex hull. -BOX2D_API b2Polygon b2MakeBox(float hx, float hy); +B2_API b2Polygon b2MakeBox(float hx, float hy); /// Make a rounded box, bypassing the need for a convex hull. -BOX2D_API b2Polygon b2MakeRoundedBox(float hx, float hy, float radius); +B2_API b2Polygon b2MakeRoundedBox(float hx, float hy, float radius); /// Make an offset box, bypassing the need for a convex hull. -BOX2D_API b2Polygon b2MakeOffsetBox(float hx, float hy, b2Vec2 center, float angle); +B2_API b2Polygon b2MakeOffsetBox(float hx, float hy, b2Vec2 center, float angle); /// Transform a polygon. This is useful for transfering a shape from one body to another. -BOX2D_API b2Polygon b2TransformPolygon(b2Transform transform, const b2Polygon* polygon); +B2_API b2Polygon b2TransformPolygon(b2Transform transform, const b2Polygon* polygon); /// Compute mass properties of a circle -BOX2D_API b2MassData b2ComputeCircleMass(const b2Circle* shape, float density); +B2_API b2MassData b2ComputeCircleMass(const b2Circle* shape, float density); /// Compute mass properties of a capsule -BOX2D_API b2MassData b2ComputeCapsuleMass(const b2Capsule* shape, float density); +B2_API b2MassData b2ComputeCapsuleMass(const b2Capsule* shape, float density); /// Compute mass properties of a polygon -BOX2D_API b2MassData b2ComputePolygonMass(const b2Polygon* shape, float density); +B2_API b2MassData b2ComputePolygonMass(const b2Polygon* shape, float density); /// Compute the bounding box of a transformed circle -BOX2D_API b2AABB b2ComputeCircleAABB(const b2Circle* shape, b2Transform transform); +B2_API b2AABB b2ComputeCircleAABB(const b2Circle* shape, b2Transform transform); /// Compute the bounding box of a transformed capsule -BOX2D_API b2AABB b2ComputeCapsuleAABB(const b2Capsule* shape, b2Transform transform); +B2_API b2AABB b2ComputeCapsuleAABB(const b2Capsule* shape, b2Transform transform); /// Compute the bounding box of a transformed polygon -BOX2D_API b2AABB b2ComputePolygonAABB(const b2Polygon* shape, b2Transform transform); +B2_API b2AABB b2ComputePolygonAABB(const b2Polygon* shape, b2Transform transform); /// Compute the bounding box of a transformed line segment -BOX2D_API b2AABB b2ComputeSegmentAABB(const b2Segment* shape, b2Transform transform); +B2_API b2AABB b2ComputeSegmentAABB(const b2Segment* shape, b2Transform transform); /// Test a point for overlap with a circle in local space -BOX2D_API bool b2PointInCircle(b2Vec2 point, const b2Circle* shape); +B2_API bool b2PointInCircle(b2Vec2 point, const b2Circle* shape); /// Test a point for overlap with a capsule in local space -BOX2D_API bool b2PointInCapsule(b2Vec2 point, const b2Capsule* shape); +B2_API bool b2PointInCapsule(b2Vec2 point, const b2Capsule* shape); /// Test a point for overlap with a convex polygon in local space -BOX2D_API bool b2PointInPolygon(b2Vec2 point, const b2Polygon* shape); +B2_API bool b2PointInPolygon(b2Vec2 point, const b2Polygon* shape); /// Ray cast versus circle in shape local space. Initial overlap is treated as a miss. -BOX2D_API b2RayCastOutput b2RayCastCircle(const b2RayCastInput* input, const b2Circle* shape); +B2_API b2RayCastOutput b2RayCastCircle(const b2RayCastInput* input, const b2Circle* shape); /// Ray cast versus capsule in shape local space. Initial overlap is treated as a miss. -BOX2D_API b2RayCastOutput b2RayCastCapsule(const b2RayCastInput* input, const b2Capsule* shape); +B2_API b2RayCastOutput b2RayCastCapsule(const b2RayCastInput* input, const b2Capsule* shape); /// Ray cast versus segment in shape local space. Optionally treat the segment as one-sided with hits from /// the left side being treated as a miss. -BOX2D_API b2RayCastOutput b2RayCastSegment(const b2RayCastInput* input, const b2Segment* shape, bool oneSided); +B2_API b2RayCastOutput b2RayCastSegment(const b2RayCastInput* input, const b2Segment* shape, bool oneSided); /// Ray cast versus polygon in shape local space. Initial overlap is treated as a miss. -BOX2D_API b2RayCastOutput b2RayCastPolygon(const b2RayCastInput* input, const b2Polygon* shape); +B2_API b2RayCastOutput b2RayCastPolygon(const b2RayCastInput* input, const b2Polygon* shape); /// Shape cast versus a circle. Initial overlap is treated as a miss. -BOX2D_API b2RayCastOutput b2ShapeCastCircle(const b2ShapeCastInput* input, const b2Circle* shape); +B2_API b2RayCastOutput b2ShapeCastCircle(const b2ShapeCastInput* input, const b2Circle* shape); /// Shape cast versus a capsule. Initial overlap is treated as a miss. -BOX2D_API b2RayCastOutput b2ShapeCastCapsule(const b2ShapeCastInput* input, const b2Capsule* shape); +B2_API b2RayCastOutput b2ShapeCastCapsule(const b2ShapeCastInput* input, const b2Capsule* shape); /// Shape cast versus a line segment. Initial overlap is treated as a miss. -BOX2D_API b2RayCastOutput b2ShapeCastSegment(const b2ShapeCastInput* input, const b2Segment* shape); +B2_API b2RayCastOutput b2ShapeCastSegment(const b2ShapeCastInput* input, const b2Segment* shape); /// Shape cast versus a convex polygon. Initial overlap is treated as a miss. -BOX2D_API b2RayCastOutput b2ShapeCastPolygon(const b2ShapeCastInput* input, const b2Polygon* shape); +B2_API b2RayCastOutput b2ShapeCastPolygon(const b2ShapeCastInput* input, const b2Polygon* shape); diff --git a/include/box2d/hull.h b/include/box2d/hull.h index 5afbd586..1468dd29 100644 --- a/include/box2d/hull.h +++ b/include/box2d/hull.h @@ -21,10 +21,10 @@ typedef struct b2Hull /// - less than 3 points /// - more than b2_maxPolygonVertices points /// This welds close points and removes collinear points. -BOX2D_API b2Hull b2ComputeHull(const b2Vec2* points, int32_t count); +B2_API b2Hull b2ComputeHull(const b2Vec2* points, int32_t count); /// This determines if a hull is valid. Checks for: /// - convexity /// - collinear points /// This is expensive and should not be called at runtime. -BOX2D_API bool b2ValidateHull(const b2Hull* hull); +B2_API bool b2ValidateHull(const b2Hull* hull); diff --git a/include/box2d/id.h b/include/box2d/id.h index 14921630..260ec848 100644 --- a/include/box2d/id.h +++ b/include/box2d/id.h @@ -70,16 +70,16 @@ static const b2ChainId b2_nullChainId = {-1, -1, 0}; #define B2_ID_EQUALS(id1, id2) (id1.index == id2.index && id1.world == id2.world && id1.revision == id2.revision) /// World identifier validation. Provides validation for up to 64K allocations. -BOX2D_API bool b2World_IsValid(b2WorldId id); +B2_API bool b2World_IsValid(b2WorldId id); /// Body identifier validation. Provides validation for up to 64K allocations. -BOX2D_API bool b2Body_IsValid(b2BodyId id); +B2_API bool b2Body_IsValid(b2BodyId id); /// Shape identifier validation. Provides validation for up to 64K allocations. -BOX2D_API bool b2Shape_IsValid(b2ShapeId id); +B2_API bool b2Shape_IsValid(b2ShapeId id); /// Chain identifier validation. Provides validation for up to 64K allocations. -BOX2D_API bool b2Chain_IsValid(b2ChainId id); +B2_API bool b2Chain_IsValid(b2ChainId id); /// Joint identifier validation. Provides validation for up to 64K allocations. -BOX2D_API bool b2Joint_IsValid(b2JointId id); +B2_API bool b2Joint_IsValid(b2JointId id); diff --git a/include/box2d/joint_util.h b/include/box2d/joint_util.h index 622e0084..0509603d 100644 --- a/include/box2d/joint_util.h +++ b/include/box2d/joint_util.h @@ -7,9 +7,9 @@ #include "id.h" /// Utility to compute linear stiffness values from frequency and damping ratio -BOX2D_API void b2LinearStiffness(float* stiffness, float* damping, float frequencyHertz, float dampingRatio, b2BodyId bodyA, +B2_API void b2LinearStiffness(float* stiffness, float* damping, float frequencyHertz, float dampingRatio, b2BodyId bodyA, b2BodyId bodyB); /// Utility to compute angular stiffness values from frequency and damping ratio -BOX2D_API void b2AngularStiffness(float* stiffness, float* damping, float frequencyHertz, float dampingRatio, b2BodyId bodyA, +B2_API void b2AngularStiffness(float* stiffness, float* damping, float frequencyHertz, float dampingRatio, b2BodyId bodyA, b2BodyId bodyB); diff --git a/include/box2d/manifold.h b/include/box2d/manifold.h index 56926f7c..d8f491db 100644 --- a/include/box2d/manifold.h +++ b/include/box2d/manifold.h @@ -51,48 +51,48 @@ typedef struct b2Manifold static const b2Manifold b2_emptyManifold = B2_ZERO_INIT; /// Compute the collision manifold between two circles. -BOX2D_API b2Manifold b2CollideCircles(const b2Circle* circleA, b2Transform xfA, const b2Circle* circleB, b2Transform xfB); +B2_API b2Manifold b2CollideCircles(const b2Circle* circleA, b2Transform xfA, const b2Circle* circleB, b2Transform xfB); /// Compute the collision manifold between a capsule and circle -BOX2D_API b2Manifold b2CollideCapsuleAndCircle(const b2Capsule* capsuleA, b2Transform xfA, const b2Circle* circleB, +B2_API b2Manifold b2CollideCapsuleAndCircle(const b2Capsule* capsuleA, b2Transform xfA, const b2Circle* circleB, b2Transform xfB); /// Compute the collision manifold between an segment and a circle. -BOX2D_API b2Manifold b2CollideSegmentAndCircle(const b2Segment* segmentA, b2Transform xfA, const b2Circle* circleB, +B2_API b2Manifold b2CollideSegmentAndCircle(const b2Segment* segmentA, b2Transform xfA, const b2Circle* circleB, b2Transform xfB); /// Compute the collision manifold between a polygon and a circle. -BOX2D_API b2Manifold b2CollidePolygonAndCircle(const b2Polygon* polygonA, b2Transform xfA, const b2Circle* circleB, +B2_API b2Manifold b2CollidePolygonAndCircle(const b2Polygon* polygonA, b2Transform xfA, const b2Circle* circleB, b2Transform xfB); /// Compute the collision manifold between a capsule and circle -BOX2D_API b2Manifold b2CollideCapsules(const b2Capsule* capsuleA, b2Transform xfA, const b2Capsule* capsuleB, b2Transform xfB, +B2_API b2Manifold b2CollideCapsules(const b2Capsule* capsuleA, b2Transform xfA, const b2Capsule* capsuleB, b2Transform xfB, b2DistanceCache* cache); /// Compute the collision manifold between an segment and a capsule. -BOX2D_API b2Manifold b2CollideSegmentAndCapsule(const b2Segment* segmentA, b2Transform xfA, const b2Capsule* capsuleB, +B2_API b2Manifold b2CollideSegmentAndCapsule(const b2Segment* segmentA, b2Transform xfA, const b2Capsule* capsuleB, b2Transform xfB, b2DistanceCache* cache); /// Compute the collision manifold between a polygon and capsule -BOX2D_API b2Manifold b2CollidePolygonAndCapsule(const b2Polygon* polygonA, b2Transform xfA, const b2Capsule* capsuleB, +B2_API b2Manifold b2CollidePolygonAndCapsule(const b2Polygon* polygonA, b2Transform xfA, const b2Capsule* capsuleB, b2Transform xfB, b2DistanceCache* cache); /// Compute the collision manifold between two polygons. -BOX2D_API b2Manifold b2CollidePolygons(const b2Polygon* polyA, b2Transform xfA, const b2Polygon* polyB, b2Transform xfB, +B2_API b2Manifold b2CollidePolygons(const b2Polygon* polyA, b2Transform xfA, const b2Polygon* polyB, b2Transform xfB, b2DistanceCache* cache); /// Compute the collision manifold between an segment and a polygon. -BOX2D_API b2Manifold b2CollideSegmentAndPolygon(const b2Segment* segmentA, b2Transform xfA, const b2Polygon* polygonB, +B2_API b2Manifold b2CollideSegmentAndPolygon(const b2Segment* segmentA, b2Transform xfA, const b2Polygon* polygonB, b2Transform xfB, b2DistanceCache* cache); /// Compute the collision manifold between a smooth segment and a circle. -BOX2D_API b2Manifold b2CollideSmoothSegmentAndCircle(const b2SmoothSegment* smoothSegmentA, b2Transform xfA, +B2_API b2Manifold b2CollideSmoothSegmentAndCircle(const b2SmoothSegment* smoothSegmentA, b2Transform xfA, const b2Circle* circleB, b2Transform xfB); /// Compute the collision manifold between an segment and a capsule. -BOX2D_API b2Manifold b2CollideSmoothSegmentAndCapsule(const b2SmoothSegment* segmentA, b2Transform xfA, const b2Capsule* capsuleB, +B2_API b2Manifold b2CollideSmoothSegmentAndCapsule(const b2SmoothSegment* segmentA, b2Transform xfA, const b2Capsule* capsuleB, b2Transform xfB, b2DistanceCache* cache); /// Compute the collision manifold between a smooth segment and a rounded polygon. -BOX2D_API b2Manifold b2CollideSmoothSegmentAndPolygon(const b2SmoothSegment* segmentA, b2Transform xfA, const b2Polygon* polygonB, +B2_API b2Manifold b2CollideSmoothSegmentAndPolygon(const b2SmoothSegment* segmentA, b2Transform xfA, const b2Polygon* polygonB, b2Transform xfB, b2DistanceCache* cache); diff --git a/include/box2d/math.h b/include/box2d/math.h index 37615519..f7938cee 100644 --- a/include/box2d/math.h +++ b/include/box2d/math.h @@ -313,13 +313,13 @@ static inline bool b2AABB_Contains(b2AABB a, b2AABB b) return s; } -BOX2D_API bool b2IsValid(float a); -BOX2D_API bool b2IsValidVec2(b2Vec2 v); +B2_API bool b2IsValid(float a); +B2_API bool b2IsValidVec2(b2Vec2 v); /// Convert this vector into a unit vector -BOX2D_API b2Vec2 b2Normalize(b2Vec2 v); +B2_API b2Vec2 b2Normalize(b2Vec2 v); /// This asserts of the vector is too short -BOX2D_API b2Vec2 b2NormalizeChecked(b2Vec2 v); +B2_API b2Vec2 b2NormalizeChecked(b2Vec2 v); -BOX2D_API b2Vec2 b2GetLengthAndNormalize(float* length, b2Vec2 v); +B2_API b2Vec2 b2GetLengthAndNormalize(float* length, b2Vec2 v); diff --git a/include/box2d/timer.h b/include/box2d/timer.h index 89ed4fea..ff566fb0 100644 --- a/include/box2d/timer.h +++ b/include/box2d/timer.h @@ -18,11 +18,11 @@ typedef struct b2Timer #endif } b2Timer; -BOX2D_API b2Timer b2CreateTimer(void); -BOX2D_API int64_t b2GetTicks(b2Timer* timer); -BOX2D_API float b2GetMilliseconds(const b2Timer* timer); -BOX2D_API float b2GetMillisecondsAndReset(b2Timer* timer); -BOX2D_API void b2SleepMilliseconds(float milliseconds); +B2_API b2Timer b2CreateTimer(void); +B2_API int64_t b2GetTicks(b2Timer* timer); +B2_API float b2GetMilliseconds(const b2Timer* timer); +B2_API float b2GetMillisecondsAndReset(b2Timer* timer); +B2_API void b2SleepMilliseconds(float milliseconds); /// Tracy profiler instrumentation /// https://github.com/wolfpld/tracy diff --git a/samples/main.cpp b/samples/main.cpp index 669fd8de..af0b7522 100644 --- a/samples/main.cpp +++ b/samples/main.cpp @@ -565,7 +565,7 @@ int main(int, char**) // MSAA glfwWindowHint(GLFW_SAMPLES, 4); - snprintf(buffer, 128, "Box2D Version %d.%d.%d Smooth", b2_version.major, b2_version.minor, b2_version.revision); + snprintf(buffer, 128, "Box2D Version %d.%d.%d (alpha)", b2_version.major, b2_version.minor, b2_version.revision); if (GLFWmonitor* primaryMonitor = glfwGetPrimaryMonitor()) { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eba33982..2c57b989 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -88,8 +88,9 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) add_library(box2d ${BOX2D_SOURCE_FILES} ${BOX2D_API_FILES}) # Generate box2d_export.h to handles shared library builds -include(GenerateExportHeader) -generate_export_header(box2d) +# turned this off to make Box2D easier to use without cmake +# include(GenerateExportHeader) +# generate_export_header(box2d) target_include_directories(box2d PUBLIC @@ -112,7 +113,27 @@ set_target_properties(box2d PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} ) +if (BOX2D_PROFILE) + target_compile_definitions(box2d PRIVATE BOX2D_PROFILE) + + FetchContent_Declare( + tracy + GIT_REPOSITORY https://github.com/wolfpld/tracy.git + GIT_TAG master + GIT_SHALLOW TRUE + GIT_PROGRESS TRUE + ) + FetchContent_MakeAvailable(tracy) + + target_link_libraries(box2d PUBLIC TracyClient) +endif() + if (MSVC) + if (BUILD_SHARED_LIBS) + # this is needed by DLL users to import Box2D symbols + target_compile_definitions(box2d INTERFACE BOX2D_DLL) + endif() + # Visual Studio won't load the natvis unless it is in the project target_sources(box2d PRIVATE box2d.natvis) @@ -136,21 +157,6 @@ elseif (APPLE) # target_compile_options(box2d PRIVATE) endif() -if (BOX2D_PROFILE) - target_compile_definitions(box2d PRIVATE BOX2D_PROFILE) - - FetchContent_Declare( - tracy - GIT_REPOSITORY https://github.com/wolfpld/tracy.git - GIT_TAG master - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE - ) - FetchContent_MakeAvailable(tracy) - - target_link_libraries(box2d PUBLIC TracyClient) -endif() - source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "src" FILES ${BOX2D_SOURCE_FILES}) source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/../include" PREFIX "include" FILES ${BOX2D_API_FILES}) diff --git a/src/body.c b/src/body.c index 189100b6..045b2a93 100644 --- a/src/body.c +++ b/src/body.c @@ -189,7 +189,7 @@ static void b2DisableBody(b2World* world, b2Body* body) } } -BOX2D_API b2BodyId b2CreateBody(b2WorldId worldId, const b2BodyDef* def) +B2_API b2BodyId b2CreateBody(b2WorldId worldId, const b2BodyDef* def) { b2World* world = b2GetWorldFromId(worldId); B2_ASSERT(world->locked == false); @@ -331,7 +331,7 @@ void b2DestroyBodyInternal(b2World* world, b2Body* body) b2FreeObject(&world->bodyPool, &body->object); } -BOX2D_API void b2DestroyBody(b2BodyId bodyId) +B2_API void b2DestroyBody(b2BodyId bodyId) { b2World* world = b2GetWorldFromIndex(bodyId.world); B2_ASSERT(world->locked == false);