Replay fixes (#17)

Fixes to work with our game.
Replay fixes and improvements.
Removed shape names (save memory).
B3_DEFAULT_CATEGORY_BITS  is now UINT64_MAX to make selection easier.
This commit is contained in:
Erin Catto 2026-06-26 21:10:10 -07:00 • committed by GitHub
commit 0c8ef46931
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
51 changed files with 5653 additions and 3853 deletions

View file

@ -419,7 +419,8 @@ B3_API void b3RecPlayer_SetDebugShapeCallbacks( b3RecPlayer* player, b3CreateDeb
/// @param player a valid player handle
/// @param draw debug draw callbacks
/// @param queryIndex index of the frame query to draw, or -1 to draw all of them
B3_API void b3RecPlayer_DrawFrameQueries( b3RecPlayer* player, b3DebugDraw* draw, int queryIndex );
/// @param selectedIndex index of the query to emphasize (reserved color plus a label), or -1 for none
B3_API void b3RecPlayer_DrawFrameQueries( b3RecPlayer* player, b3DebugDraw* draw, int queryIndex, int selectedIndex );
/// The kind of a recorded spatial query, matching the public query and cast functions.
typedef enum b3RecQueryType
@ -438,10 +439,13 @@ typedef struct b3RecQueryInfo
{
b3RecQueryType type;
b3QueryFilter filter;
b3AABB aabb; // overlap AABB, world space
b3AABB aabb; // world-space bounds of the query, swept for casts
b3Pos origin; // query origin (zero for overlap AABB)
b3Vec3 translation; // ray and cast translation
int hitCount; // number of recorded results
uint64_t key; // identity key, the hash of (id, name), 0 if untagged
uint64_t id; // query id, 0 if none
const char* name; // query label, NULL if none
} b3RecQueryInfo;
/// One result of a recorded spatial query.
@ -834,12 +838,6 @@ B3_API b3WorldId b3Shape_GetWorld( b3ShapeId shapeId );
/// Returns true if the shape is a sensor
B3_API bool b3Shape_IsSensor( b3ShapeId shapeId );
/// Set the shape name. Up to B3_NAME_LENGTH characters including null termination.
B3_API void b3Shape_SetName( b3ShapeId shapeId, const char* name );
/// Get the shape name.
B3_API const char* b3Shape_GetName( b3ShapeId shapeId );
/// Set the user data for a shape
B3_API void b3Shape_SetUserData( b3ShapeId shapeId, void* userData );

View file

@ -14,6 +14,12 @@ B3_API void b3SetLengthUnitsPerMeter( float lengthUnits );
/// Get the current length units per meter.
B3_API float b3GetLengthUnitsPerMeter( void );
/// Set the threshold for logging stalls.
B3_API void b3SetStallThreshold( float seconds );
/// Get the threshold for logging stalls.
B3_API float b3GetStallThreshold( void );
// Used to detect bad values. In float mode positions greater than about 16km have precision
// problems, so 100km is a safe limit. Large world mode keeps coordinates accurate much farther
// from the origin, so the sanity limit widens to keep valid far-field positions from tripping it.

View file

@ -562,6 +562,28 @@ B3_API b3Quat b3MakeQuatFromMatrix( const b3Matrix3* m );
/// Find a quaternion that rotates one vector to another.
B3_API b3Quat b3ComputeQuatBetweenUnitVectors( b3Vec3 v1, b3Vec3 v2 );
/// Twist angle around the z-axis, used for twist limit and revolute angle limit
B3_INLINE float b3GetTwistAngle( b3Quat q )
{
// Account for polarity to keep the twist angle in range.
// This is simpler than asking the user to check polarity or unwinding.
float twist = q.s < 0.0f ? b3Atan2( -q.v.z, -q.s ) : b3Atan2( q.v.z, q.s );
twist *= 2.0f;
B3_ASSERT( -B3_PI <= twist && twist <= B3_PI );
return twist;
}
/// Swing angle used for cone limit
B3_INLINE float b3GetSwingAngle( b3Quat q )
{
// Polarity should not matter because all terms are squared.
float x = sqrtf( q.v.z * q.v.z + q.s * q.s );
float y = sqrtf( q.v.x * q.v.x + q.v.y * q.v.y );
float swing = 2.0f * b3Atan2( y, x );
B3_ASSERT( 0.0f <= swing && swing <= B3_PI );
return swing;
}
/// Linearly interpolate and normalize between two quaternions
B3_INLINE b3Quat b3NLerp( b3Quat q1, b3Quat q2, float alpha )
{
@ -1033,6 +1055,24 @@ B3_INLINE b3Vec3 b3ClosestPointToAABB( b3Vec3 point, b3AABB a )
return b3Clamp( point, a.lowerBound, a.upperBound );
}
/// The closest points between to segments or infinite lines.
typedef struct b3SegmentDistanceResult
{
b3Vec3 point1;
float fraction1;
b3Vec3 point2;
float fraction2;
} b3SegmentDistanceResult;
/// Compute the closest point on the segment a-b to the target q.
B3_API b3Vec3 b3PointToSegmentDistance( b3Vec3 a, b3Vec3 b, b3Vec3 q );
/// Compute the closest points on two infinite lines.
B3_API b3SegmentDistanceResult b3LineDistance( b3Vec3 p1, b3Vec3 d1, b3Vec3 p2, b3Vec3 d2 );
/// Compute the closest points on two line segments.
B3_API b3SegmentDistanceResult b3SegmentDistance( b3Vec3 p1, b3Vec3 q1, b3Vec3 p2, b3Vec3 q2 );
/// Is this a valid number? Not NaN or infinity.
B3_API bool b3IsValidFloat( float a );

View file

@ -10,7 +10,7 @@
#include <stdint.h>
#define B3_DEFAULT_CATEGORY_BITS 1
#define B3_DEFAULT_CATEGORY_BITS UINT64_MAX
#define B3_DEFAULT_MASK_BITS UINT64_MAX
/// Task interface
@ -451,9 +451,6 @@ typedef enum b3ShapeType
/// @ingroup shape
typedef struct b3ShapeDef
{
/// Optional body name for debugging. Up to B3_NAME_LENGTH characters (including null termination)
const char* name;
/// Use this to store application specific shape data.
void* userData;
@ -1287,6 +1284,16 @@ typedef struct b3QueryFilter
/// The collision mask bits. This states the shape categories that this
/// query would accept for collision.
uint64_t maskBits;
/// Optional id combined with @ref name to identify this query in a recording, e.g. an entity id.
/// Need not be unique on its own. 0 with a null name means untagged. Ignored when not recording.
uint64_t id;
/// Optional label combined with @ref id to identify this query, e.g. "bullet". Need not be unique
/// on its own. The recorder hashes (id, name) into one stable key the viewer tracks the query by,
/// so the same id and name pair identifies the same query across frames. NULL means none. Ignored
/// when not recording.
const char* name;
} b3QueryFilter;
/// Use this to initialize your query filter
@ -1449,6 +1456,7 @@ typedef struct b3WorldCastOutput
#else
/// Same type in single precision.
typedef b3CastOutput b3WorldCastOutput;
#endif
@ -1699,7 +1707,7 @@ typedef struct b3TreeNode
} b3TreeNode;
/// Dynamic tree version for compatibility testing.
#define B3_DYNAMIC_TREE_VERSION 0x8E867C390754064Bull
#define B3_DYNAMIC_TREE_VERSION 0x93EDAF889FD30B4Aull
/// The dynamic tree structure. This should be considered private data.
/// It is placed here for performance reasons.
@ -1944,7 +1952,7 @@ typedef struct b3HullFace
} b3HullFace;
/// 64-bit hull version. Useful for validating serialized data.
#define B3_HULL_VERSION 0x8F5034CF987D4FD9ull
#define B3_HULL_VERSION 0x9D4716CE3793900Eull
/// A convex hull.
/// @note This data structure has data hanging off the end and cannot be directly copied.
@ -2062,7 +2070,7 @@ typedef struct b3MeshDef
} b3MeshDef;
/// 64-bit mesh version. Useful for validating serialized data.
#define B3_MESH_VERSION 0x4A1E7B2C8D5F3091ull
#define B3_MESH_VERSION 0xABD11AB62A6E886Dull
/// Triangle mesh edge flags.
typedef enum b3MeshEdgeFlags
@ -2240,7 +2248,7 @@ typedef struct b3HeightFieldDef
#define B3_HEIGHT_FIELD_HOLE 0xFF
/// 64-bit height-field version. Useful for validating serialized data.
#define B3_HEIGHT_FIELD_VERSION 0x3D9A1F6C24E87B05ull
#define B3_HEIGHT_FIELD_VERSION 0x8B18CBD138A6BC84ull
/// A height field with compressed storage.
/// @note This data structure has data hanging off the end and cannot be directly copied.
@ -2387,7 +2395,7 @@ typedef struct b3CompoundDef
} b3CompoundDef;
/// The compound version depends on the tree, mesh, and hull versions.
#define B3_COMPOUND_VERSION ( 0x902AC5D34D9BD452ull ^ B3_DYNAMIC_TREE_VERSION ^ B3_MESH_VERSION ^ B3_HULL_VERSION )
#define B3_COMPOUND_VERSION ( 0x830778DB07086EB4ull ^ B3_DYNAMIC_TREE_VERSION ^ B3_MESH_VERSION ^ B3_HULL_VERSION )
/// Meshes used in compounds have limited space for materials. If you have
/// a mesh with many materials, you can use it outside of the compound.
@ -2949,6 +2957,9 @@ typedef struct b3DebugDraw
/// Draw a sphere.
void ( *DrawSphereFcn )( b3Pos p, float radius, b3HexColor color, float alpha, void* context );
/// Draw a capsule.
void ( *DrawCapsuleFcn )( b3Pos p1, b3Pos p2, float radius, b3HexColor color, float alpha, void* context );
/// Draw a bounding box.
void ( *DrawBoundsFcn )( b3AABB aabb, b3HexColor color, void* context );