Skip to content

Commit

Permalink
removed need for box2d_export header
Browse files Browse the repository at this point in the history
  • Loading branch information
erincatto committed Dec 29, 2023
1 parent 04b136d commit 57a5798
Show file tree
Hide file tree
Showing 17 changed files with 258 additions and 239 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ IncludeCategories:

IndentExternBlock: NoIndent
IndentCaseLabels: true
IndentPPDirectives: BeforeHash
IndentAccessModifiers: false
AccessModifierOffset: -4

Expand Down
2 changes: 1 addition & 1 deletion docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
26 changes: 19 additions & 7 deletions include/box2d/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,26 @@

#pragma once

#include "box2d_export.h"

#include <stdint.h>

#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.
Expand All @@ -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);
256 changes: 128 additions & 128 deletions include/box2d/box2d.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion include/box2d/callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions include/box2d/distance.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
38 changes: 19 additions & 19 deletions include/box2d/dynamic_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,38 +64,38 @@ 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
typedef bool b2TreeQueryCallbackFcn(int32_t proxyId, int32_t userData, 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_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.
Expand All @@ -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
Expand All @@ -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
Expand Down
52 changes: 26 additions & 26 deletions include/box2d/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
4 changes: 2 additions & 2 deletions include/box2d/hull.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
10 changes: 5 additions & 5 deletions include/box2d/id.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
4 changes: 2 additions & 2 deletions include/box2d/joint_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Loading

0 comments on commit 57a5798

Please sign in to comment.