@@ -29,7 +29,7 @@ typedef struct b2Hull b2Hull;
2929/// don't use more vertices.
3030#define b2_maxPolygonVertices 8
3131
32- /// Low level ray- cast input data
32+ /// Low level ray cast input data
3333typedef struct b2RayCastInput
3434{
3535 /// Start point of the ray cast
@@ -63,7 +63,7 @@ typedef struct b2ShapeCastInput
6363 float maxFraction ;
6464} b2ShapeCastInput ;
6565
66- /// Low level ray- cast or shape-cast output data
66+ /// Low level ray cast or shape-cast output data
6767typedef struct b2CastOutput
6868{
6969 /// The surface normal at the hit point
@@ -566,16 +566,16 @@ B2_API b2Manifold b2CollideSegmentAndPolygon( const b2Segment* segmentA, b2Trans
566566 b2Transform xfB );
567567
568568/// Compute the contact manifold between a chain segment and a circle
569- B2_API b2Manifold b2CollideChainSegmentAndCircle ( const b2ChainSegment * segmentA , b2Transform xfA ,
570- const b2Circle * circleB , b2Transform xfB );
569+ B2_API b2Manifold b2CollideChainSegmentAndCircle ( const b2ChainSegment * segmentA , b2Transform xfA , const b2Circle * circleB ,
570+ b2Transform xfB );
571571
572572/// Compute the contact manifold between a chain segment and a capsule
573- B2_API b2Manifold b2CollideChainSegmentAndCapsule ( const b2ChainSegment * segmentA , b2Transform xfA ,
574- const b2Capsule * capsuleB , b2Transform xfB , b2DistanceCache * cache );
573+ B2_API b2Manifold b2CollideChainSegmentAndCapsule ( const b2ChainSegment * segmentA , b2Transform xfA , const b2Capsule * capsuleB ,
574+ b2Transform xfB , b2DistanceCache * cache );
575575
576576/// Compute the contact manifold between a chain segment and a rounded polygon
577- B2_API b2Manifold b2CollideChainSegmentAndPolygon ( const b2ChainSegment * segmentA , b2Transform xfA ,
578- const b2Polygon * polygonB , b2Transform xfB , b2DistanceCache * cache );
577+ B2_API b2Manifold b2CollideChainSegmentAndPolygon ( const b2ChainSegment * segmentA , b2Transform xfA , const b2Polygon * polygonB ,
578+ b2Transform xfB , b2DistanceCache * cache );
579579
580580/**@}*/
581581
@@ -602,8 +602,7 @@ B2_API b2Manifold b2CollideChainSegmentAndPolygon( const b2ChainSegment* segment
602602/// The default category bit for a tree proxy. Used for collision filtering.
603603#define b2_defaultCategoryBits ( 1 )
604604
605- /// Convenience mask bits to use when you don't need collision filtering and just want
606- /// all results.
605+ /// Convenience mask bits to use when you don't need collision filtering and just want all results.
607606#define b2_defaultMaskBits ( UINT64_MAX )
608607
609608/// A node in the dynamic tree. This is private data placed here for performance reasons.
@@ -617,31 +616,27 @@ typedef struct b2TreeNode
617616
618617 union
619618 {
620- /// The node parent index
619+ /// The node parent index (allocated node)
621620 int32_t parent ;
622621
623- /// The node freelist next index
622+ /// The node freelist next index (free node)
624623 int32_t next ;
625624 }; // 4
626625
627- /// Child 1 index
626+ /// Child 1 index (internal node)
628627 int32_t child1 ; // 4
629628
630- /// Child 2 index
631- int32_t child2 ; // 4
632-
633- /// User data
634- // todo could be union with child index
635- int32_t userData ; // 4
636-
637- /// Leaf = 0, free node = -1
638- int16_t height ; // 2
629+ union
630+ {
631+ /// Child 2 index (internal node)
632+ int32_t child2 ;
639633
640- /// Has the AABB been enlarged?
641- bool enlarged ; // 1
634+ /// User data (leaf node)
635+ int32_t userData ;
636+ }; // 4
642637
643- /// Padding for clarity
644- char pad [ 5 ];
638+ uint16_t height ; // 2
639+ uint16_t flags ; // 2
645640} b2TreeNode ;
646641
647642/// The dynamic tree structure. This should be considered private data.
@@ -682,6 +677,16 @@ typedef struct b2DynamicTree
682677 int32_t rebuildCapacity ;
683678} b2DynamicTree ;
684679
680+ /// These are performance results returned by dynamic tree queries.
681+ typedef struct b2TreeStats
682+ {
683+ /// Number of internal nodes visited during the query
684+ int32_t nodeVisits ;
685+
686+ /// Number of leaf nodes visited during the query
687+ int32_t leafVisits ;
688+ } b2TreeStats ;
689+
685690/// Constructing the tree initializes the node pool.
686691B2_API b2DynamicTree b2DynamicTree_Create ( void );
687692
@@ -705,49 +710,53 @@ B2_API void b2DynamicTree_EnlargeProxy( b2DynamicTree* tree, int32_t proxyId, b2
705710typedef bool b2TreeQueryCallbackFcn ( int32_t proxyId , int32_t userData , void * context );
706711
707712/// Query an AABB for overlapping proxies. The callback class is called for each proxy that overlaps the supplied AABB.
708- B2_API void b2DynamicTree_Query ( const b2DynamicTree * tree , b2AABB aabb , uint64_t maskBits , b2TreeQueryCallbackFcn * callback ,
709- void * context );
713+ /// @return performance data
714+ B2_API b2TreeStats b2DynamicTree_Query ( const b2DynamicTree * tree , b2AABB aabb , uint64_t maskBits ,
715+ b2TreeQueryCallbackFcn * callback , void * context );
710716
711- /// This function receives clipped raycast input for a proxy. The function
717+ /// This function receives clipped ray cast input for a proxy. The function
712718/// returns the new ray fraction.
713719/// - return a value of 0 to terminate the ray cast
714720/// - return a value less than input->maxFraction to clip the ray
715721/// - return a value of input->maxFraction to continue the ray cast without clipping
716722typedef float b2TreeRayCastCallbackFcn ( const b2RayCastInput * input , int32_t proxyId , int32_t userData , void * context );
717723
718- /// Ray- cast against the proxies in the tree. This relies on the callback
719- /// to perform a exact ray- cast in the case were the proxy contains a shape.
724+ /// Ray cast against the proxies in the tree. This relies on the callback
725+ /// to perform a exact ray cast in the case were the proxy contains a shape.
720726/// The callback also performs the any collision filtering. This has performance
721727/// roughly equal to k * log(n), where k is the number of collisions and n is the
722728/// number of proxies in the tree.
723729/// Bit-wise filtering using mask bits can greatly improve performance in some scenarios.
730+ /// However, this filtering may be approximate, so the user should still apply filtering to results.
724731/// @param tree the dynamic tree to ray cast
725- /// @param input the ray- cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1)
726- /// @param maskBits filter bits : `bool accept = (maskBits & node->categoryBits) != 0;`
732+ /// @param input the ray cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1)
733+ /// @param maskBits mask bit hint : `bool accept = (maskBits & node->categoryBits) != 0;`
727734/// @param callback a callback class that is called for each proxy that is hit by the ray
728735/// @param context user context that is passed to the callback
729- B2_API void b2DynamicTree_RayCast ( const b2DynamicTree * tree , const b2RayCastInput * input , uint64_t maskBits ,
730- b2TreeRayCastCallbackFcn * callback , void * context );
736+ /// @return performance data
737+ B2_API b2TreeStats b2DynamicTree_RayCast ( const b2DynamicTree * tree , const b2RayCastInput * input , uint64_t maskBits ,
738+ b2TreeRayCastCallbackFcn * callback , void * context );
731739
732- /// This function receives clipped ray- cast input for a proxy. The function
740+ /// This function receives clipped ray cast input for a proxy. The function
733741/// returns the new ray fraction.
734- /// - return a value of 0 to terminate the ray- cast
742+ /// - return a value of 0 to terminate the ray cast
735743/// - return a value less than input->maxFraction to clip the ray
736744/// - return a value of input->maxFraction to continue the ray cast without clipping
737745typedef float b2TreeShapeCastCallbackFcn ( const b2ShapeCastInput * input , int32_t proxyId , int32_t userData , void * context );
738746
739- /// Ray- cast against the proxies in the tree. This relies on the callback
740- /// to perform a exact ray- cast in the case were the proxy contains a shape.
747+ /// Ray cast against the proxies in the tree. This relies on the callback
748+ /// to perform a exact ray cast in the case were the proxy contains a shape.
741749/// The callback also performs the any collision filtering. This has performance
742750/// roughly equal to k * log(n), where k is the number of collisions and n is the
743751/// number of proxies in the tree.
744752/// @param tree the dynamic tree to ray cast
745- /// @param input the ray- cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
753+ /// @param input the ray cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
746754/// @param maskBits filter bits: `bool accept = (maskBits & node->categoryBits) != 0;`
747755/// @param callback a callback class that is called for each proxy that is hit by the shape
748756/// @param context user context that is passed to the callback
749- B2_API void b2DynamicTree_ShapeCast ( const b2DynamicTree * tree , const b2ShapeCastInput * input , uint64_t maskBits ,
750- b2TreeShapeCastCallbackFcn * callback , void * context );
757+ /// @return performance data
758+ B2_API b2TreeStats b2DynamicTree_ShapeCast ( const b2DynamicTree * tree , const b2ShapeCastInput * input , uint64_t maskBits ,
759+ b2TreeShapeCastCallbackFcn * callback , void * context );
751760
752761/// Validate this tree. For testing.
753762B2_API void b2DynamicTree_Validate ( const b2DynamicTree * tree );
@@ -781,7 +790,6 @@ B2_API void b2DynamicTree_ShiftOrigin( b2DynamicTree* tree, b2Vec2 newOrigin );
781790B2_API int b2DynamicTree_GetByteCount ( const b2DynamicTree * tree );
782791
783792/// Get proxy user data
784- /// @return the proxy user data or 0 if the id is invalid
785793B2_INLINE int32_t b2DynamicTree_GetUserData ( const b2DynamicTree * tree , int32_t proxyId )
786794{
787795 return tree -> nodes [proxyId ].userData ;
0 commit comments