Browse Source

Add `require_results` and change some of the wrapper to return a slice

gingerBill 11 months ago
parent
commit
c98c95fcf0
1 changed files with 35 additions and 22 deletions
  1. 35 22
      vendor/box2d/box2d.odin

+ 35 - 22
vendor/box2d/box2d.odin

@@ -68,7 +68,7 @@ when ODIN_OS == .Windows {
 	}
 	}
 }
 }
 
 
-@(link_prefix="b2", default_calling_convention="c")
+@(link_prefix="b2", default_calling_convention="c", require_results)
 foreign lib {
 foreign lib {
 	// This allows the user to override the allocation functions. These should be
 	// This allows the user to override the allocation functions. These should be
 	//	set during application startup.
 	//	set during application startup.
@@ -98,7 +98,7 @@ foreign lib {
 	GetLengthUnitsPerMeter :: proc() -> f32 ---
 	GetLengthUnitsPerMeter :: proc() -> f32 ---
 }
 }
 
 
-@(link_prefix="b2", default_calling_convention="c")
+@(link_prefix="b2", default_calling_convention="c", require_results)
 foreign lib {
 foreign lib {
 	// Use this to initialize your world definition
 	// Use this to initialize your world definition
 	// @ingroup world
 	// @ingroup world
@@ -155,7 +155,7 @@ foreign lib {
 
 
 
 
 
 
-@(link_prefix="b2", default_calling_convention="c")
+@(link_prefix="b2", default_calling_convention="c", require_results)
 foreign lib {
 foreign lib {
 	// Validate ray cast input data (NaN, etc)
 	// Validate ray cast input data (NaN, etc)
 	IsValidRay         :: proc(#by_ptr input: RayCastInput) -> bool ---
 	IsValidRay         :: proc(#by_ptr input: RayCastInput) -> bool ---
@@ -248,6 +248,7 @@ foreign lib {
 // - more than maxPolygonVertices points
 // - more than maxPolygonVertices points
 // This welds close points and removes collinear points.
 // This welds close points and removes collinear points.
 //	@warning Do not modify a hull once it has been computed
 //	@warning Do not modify a hull once it has been computed
+@(require_results)
 ComputeHull :: proc "c" (points: []Vec2) -> Hull {
 ComputeHull :: proc "c" (points: []Vec2) -> Hull {
 	foreign lib {
 	foreign lib {
 		b2ComputeHull :: proc "c" (points: [^]Vec2, count: i32) -> Hull ---
 		b2ComputeHull :: proc "c" (points: [^]Vec2, count: i32) -> Hull ---
@@ -256,7 +257,7 @@ ComputeHull :: proc "c" (points: []Vec2) -> Hull {
 }
 }
 
 
 
 
-@(link_prefix="b2", default_calling_convention="c")
+@(link_prefix="b2", default_calling_convention="c", require_results)
 foreign lib {
 foreign lib {
 	// This determines if a hull is valid. Checks for:
 	// This determines if a hull is valid. Checks for:
 	// - convexity
 	// - convexity
@@ -265,7 +266,7 @@ foreign lib {
 	ValidateHull :: proc(#by_ptr hull: Hull) -> bool ---
 	ValidateHull :: proc(#by_ptr hull: Hull) -> bool ---
 }
 }
 
 
-@(link_prefix="b2", default_calling_convention="c")
+@(link_prefix="b2", default_calling_convention="c", require_results)
 foreign lib {
 foreign lib {
 	// Compute the distance between two line segments, clamping at the end points if needed.
 	// Compute the distance between two line segments, clamping at the end points if needed.
 	SegmentDistance :: proc(p1, q1: Vec2, p2, q2: Vec2) -> SegmentDistanceResult ---
 	SegmentDistance :: proc(p1, q1: Vec2, p2, q2: Vec2) -> SegmentDistanceResult ---
@@ -274,6 +275,7 @@ foreign lib {
 // Compute the closest points between two shapes represented as point clouds.
 // Compute the closest points between two shapes represented as point clouds.
 // DistanceCache cache is input/output. On the first call set DistanceCache.count to zero.
 // DistanceCache cache is input/output. On the first call set DistanceCache.count to zero.
 //	The underlying GJK algorithm may be debugged by passing in debug simplexes and capacity. You may pass in NULL and 0 for these.
 //	The underlying GJK algorithm may be debugged by passing in debug simplexes and capacity. You may pass in NULL and 0 for these.
+@(require_results)
 ShapeDistance :: proc "c" (cache: ^DistanceCache, #by_ptr input: DistanceInput, simplexes: []Simplex) -> DistanceOutput {
 ShapeDistance :: proc "c" (cache: ^DistanceCache, #by_ptr input: DistanceInput, simplexes: []Simplex) -> DistanceOutput {
 	foreign lib {
 	foreign lib {
 		b2ShapeDistance :: proc "c" (cache: ^DistanceCache, #by_ptr input: DistanceInput, simplexes: [^]Simplex, simplexCapacity: c.int) -> DistanceOutput ---
 		b2ShapeDistance :: proc "c" (cache: ^DistanceCache, #by_ptr input: DistanceInput, simplexes: [^]Simplex, simplexCapacity: c.int) -> DistanceOutput ---
@@ -283,6 +285,7 @@ ShapeDistance :: proc "c" (cache: ^DistanceCache, #by_ptr input: DistanceInput,
 
 
 
 
 // Make a proxy for use in GJK and related functions.
 // Make a proxy for use in GJK and related functions.
+@(require_results)
 MakeProxy :: proc "c" (vertices: []Vec2, radius: f32) -> DistanceProxy {
 MakeProxy :: proc "c" (vertices: []Vec2, radius: f32) -> DistanceProxy {
 	foreign lib {
 	foreign lib {
 		b2MakeProxy :: proc "c" (vertices: [^]Vec2, count: i32, radius: f32) -> DistanceProxy ---
 		b2MakeProxy :: proc "c" (vertices: [^]Vec2, count: i32, radius: f32) -> DistanceProxy ---
@@ -291,7 +294,7 @@ MakeProxy :: proc "c" (vertices: []Vec2, radius: f32) -> DistanceProxy {
 }
 }
 
 
 
 
-@(link_prefix="b2", default_calling_convention="c")
+@(link_prefix="b2", default_calling_convention="c", require_results)
 foreign lib {
 foreign lib {
 	// Perform a linear shape cast of shape B moving and shape A fixed. Determines the hit point, normal, and translation fraction.
 	// Perform a linear shape cast of shape B moving and shape A fixed. Determines the hit point, normal, and translation fraction.
 	ShapeCast :: proc(#by_ptr input: ShapeCastPairInput) -> CastOutput ---
 	ShapeCast :: proc(#by_ptr input: ShapeCastPairInput) -> CastOutput ---
@@ -306,7 +309,7 @@ foreign lib {
 	TimeOfImpact :: proc(#by_ptr input: TOIInput) -> TOIOutput ---
 	TimeOfImpact :: proc(#by_ptr input: TOIInput) -> TOIOutput ---
 }
 }
 
 
-@(link_prefix="b2", default_calling_convention="c")
+@(link_prefix="b2", default_calling_convention="c", require_results)
 foreign lib {
 foreign lib {
 	// Compute the contact manifold between two circles
 	// Compute the contact manifold between two circles
 	CollideCircles                 :: proc(#by_ptr circleA: Circle, xfA: Transform, #by_ptr circleB: Circle, xfB: Transform) -> Manifold ---
 	CollideCircles                 :: proc(#by_ptr circleA: Circle, xfA: Transform, #by_ptr circleB: Circle, xfB: Transform) -> Manifold ---
@@ -347,7 +350,7 @@ foreign lib {
 
 
 
 
 
 
-@(link_prefix="b2", default_calling_convention="c")
+@(link_prefix="b2", default_calling_convention="c", require_results)
 foreign lib {
 foreign lib {
 	// Constructing the tree initializes the node pool.
 	// Constructing the tree initializes the node pool.
 	DynamicTree_Create          :: proc() -> DynamicTree ---
 	DynamicTree_Create          :: proc() -> DynamicTree ---
@@ -430,18 +433,20 @@ foreign lib {
 
 
 // Get proxy user data
 // Get proxy user data
 // @return the proxy user data or 0 if the id is invalid
 // @return the proxy user data or 0 if the id is invalid
+@(require_results)
 DynamicTree_GetUserData :: #force_inline proc "contextless" (tree: DynamicTree, proxyId: i32) -> i32 {
 DynamicTree_GetUserData :: #force_inline proc "contextless" (tree: DynamicTree, proxyId: i32) -> i32 {
 	return tree.nodes[proxyId].userData
 	return tree.nodes[proxyId].userData
 }
 }
 
 
 // Get the AABB of a proxy
 // Get the AABB of a proxy
+@(require_results)
 DynamicTree_GetAABB :: #force_inline proc "contextless" (tree: DynamicTree, proxyId: i32) -> AABB {
 DynamicTree_GetAABB :: #force_inline proc "contextless" (tree: DynamicTree, proxyId: i32) -> AABB {
 	return tree.nodes[proxyId].aabb
 	return tree.nodes[proxyId].aabb
 }
 }
 
 
 
 
 
 
-@(link_prefix="b2", default_calling_convention="c")
+@(link_prefix="b2", default_calling_convention="c", require_results)
 foreign lib {
 foreign lib {
 	/**
 	/**
 	 * @defgroup world World
 	 * @defgroup world World
@@ -584,7 +589,7 @@ foreign lib {
 }
 }
 
 
 
 
-@(link_prefix="b2", default_calling_convention="c")
+@(link_prefix="b2", default_calling_convention="c", require_results)
 foreign lib {
 foreign lib {
 	/**
 	/**
 	 * @defgroup body Body
 	 * @defgroup body Body
@@ -825,35 +830,41 @@ foreign lib {
 }
 }
 
 
 // Get the shape ids for all shapes on this body, up to the provided capacity.
 // Get the shape ids for all shapes on this body, up to the provided capacity.
-//	@returns the number of shape ids stored in the user array
-Body_GetShapes :: proc "c" (bodyId: BodyId, shapeArray: []ShapeId) -> c.int {
+//	@returns the shape ids stored in the user array
+@(require_results)
+Body_GetShapes :: proc "c" (bodyId: BodyId, shapeArray: []ShapeId) -> []ShapeId {
 	foreign lib {
 	foreign lib {
 		b2Body_GetShapes :: proc "c" (bodyId: BodyId, shapeArray: [^]ShapeId, capacity: c.int) -> c.int ---
 		b2Body_GetShapes :: proc "c" (bodyId: BodyId, shapeArray: [^]ShapeId, capacity: c.int) -> c.int ---
 	}
 	}
-	return b2Body_GetShapes(bodyId, raw_data(shapeArray), c.int(len(shapeArray)))
+	n := b2Body_GetShapes(bodyId, raw_data(shapeArray), c.int(len(shapeArray)))
+	return shapeArray[:n]
 
 
 }
 }
 
 
 // Get the joint ids for all joints on this body, up to the provided capacity
 // Get the joint ids for all joints on this body, up to the provided capacity
-//	@returns the number of joint ids stored in the user array
-Body_GetJoints :: proc "c" (bodyId: BodyId, jointArray: []JointId) -> c.int {
+//	@returns the joint ids stored in the user array
+@(require_results)
+Body_GetJoints :: proc "c" (bodyId: BodyId, jointArray: []JointId) -> []JointId {
 	foreign lib {
 	foreign lib {
 		b2Body_GetJoints :: proc "c" (bodyId: BodyId, jointArray: [^]JointId, capacity: c.int) -> c.int ---
 		b2Body_GetJoints :: proc "c" (bodyId: BodyId, jointArray: [^]JointId, capacity: c.int) -> c.int ---
 	}
 	}
-	return b2Body_GetJoints(bodyId, raw_data(jointArray), c.int(len(jointArray)))
+	n := b2Body_GetJoints(bodyId, raw_data(jointArray), c.int(len(jointArray)))
+	return jointArray[:n]
 
 
 }
 }
 
 
 // Get the touching contact data for a body
 // Get the touching contact data for a body
-Body_GetContactData :: proc "c" (bodyId: BodyId, contactData: []ContactData) -> c.int {
+@(require_results)
+Body_GetContactData :: proc "c" (bodyId: BodyId, contactData: []ContactData) -> []ContactData {
 	foreign lib {
 	foreign lib {
 		b2Body_GetContactData :: proc "c" (bodyId: BodyId, contactData: [^]ContactData, capacity: c.int) -> c.int ---
 		b2Body_GetContactData :: proc "c" (bodyId: BodyId, contactData: [^]ContactData, capacity: c.int) -> c.int ---
 	}
 	}
-	return b2Body_GetContactData(bodyId, raw_data(contactData), c.int(len(contactData)))
+	n := b2Body_GetContactData(bodyId, raw_data(contactData), c.int(len(contactData)))
+	return contactData[:n]
 
 
 }
 }
 
 
-@(link_prefix="b2", default_calling_convention="c")
+@(link_prefix="b2", default_calling_convention="c", require_results)
 foreign lib {
 foreign lib {
 	/**
 	/**
 	 * @defgroup shape Shape
 	 * @defgroup shape Shape
@@ -1016,15 +1027,17 @@ foreign lib {
 }
 }
 
 
 // Get the touching contact data for a shape. The provided shapeId will be either shapeIdA or shapeIdB on the contact data.
 // Get the touching contact data for a shape. The provided shapeId will be either shapeIdA or shapeIdB on the contact data.
-Shape_GetContactData :: proc "c" (shapeId: ShapeId, contactData: []ContactData) -> c.int {
+@(require_results)
+Shape_GetContactData :: proc "c" (shapeId: ShapeId, contactData: []ContactData) -> []ContactData {
 	foreign lib {
 	foreign lib {
 		b2Shape_GetContactData :: proc "c" (shapeId: ShapeId, contactData: [^]ContactData, capacity: c.int) -> c.int ---
 		b2Shape_GetContactData :: proc "c" (shapeId: ShapeId, contactData: [^]ContactData, capacity: c.int) -> c.int ---
 	}
 	}
-	return b2Shape_GetContactData(shapeId, raw_data(contactData), c.int(len(contactData)))
+	n := b2Shape_GetContactData(shapeId, raw_data(contactData), c.int(len(contactData)))
+	return contactData[:n]
 }
 }
 
 
 
 
-@(link_prefix="b2", default_calling_convention="c")
+@(link_prefix="b2", default_calling_convention="c", require_results)
 foreign lib {
 foreign lib {
 	// Chain Shape
 	// Chain Shape