Optimizations (#168)

- Optimize contact prepare
- Back to post restitution stage
- Optimize solver math
- Bug fixes
This commit is contained in:
Erin Catto 2026-09-24 12:21:17 -07:00 • committed by GitHub
commit 79fc55976a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
55 changed files with 3248 additions and 1519 deletions

View file

@ -327,6 +327,8 @@ b3WorldId b3CreateWorld( const b3WorldDef* def )
world->gravity = def->gravity;
world->hitEventThreshold = def->hitEventThreshold;
world->restitutionThreshold = def->restitutionThreshold;
world->restitutionIterations = b3ClampInt( def->restitutionIterations, 0, B3_MAX_RESTITUTION_ITERATIONS );
world->enableRestitutionPropagation = def->enableRestitutionPropagation;
world->maxLinearSpeed = def->maximumLinearSpeed;
world->contactSpeed = def->contactSpeed;
world->contactHertz = def->contactHertz;
@ -714,6 +716,7 @@ static void b3CollideTask( int startIndex, int endIndex, int workerIndex, void*
b3Vec3 rB = b3MulMV( matrixB, mp->anchorB );
b3Vec3 dp = b3Add( dc, b3Sub( rB, rA ) );
mp->separation = mp->baseSeparation + b3Dot( dp, normal );
mp->normalVelocity = 0.0f;
mp->persisted = true;
}
}
@ -1125,7 +1128,6 @@ void b3World_Step( b3WorldId worldId, float timeStep, int subStepCount )
context.contactSoftness = b3MakeSoft( contactHertz, world->contactDampingRatio, context.h );
context.staticSoftness = b3MakeSoft( 2.0f * contactHertz, 0.5f * world->contactDampingRatio, context.h );
context.restitutionThreshold = world->restitutionThreshold;
context.maxLinearVelocity = world->maxLinearSpeed;
context.enableWarmStarting = world->enableWarmStarting;
@ -1261,7 +1263,7 @@ static bool DrawQueryCallback( int proxyId, uint64_t userData, void* context )
{
rgb = b3_colorWheat;
}
else if ( body->flags & b3_hadTimeOfImpact )
else if ( bodySim->flags & b3_hadTimeOfImpact )
{
rgb = b3_colorLime;
}
@ -2079,6 +2081,55 @@ float b3World_GetRestitutionThreshold( b3WorldId worldId )
return world->restitutionThreshold;
}
void b3World_SetRestitutionIterations( b3WorldId worldId, int iterations )
{
b3World* world = b3GetUnlockedWorldFromId( worldId );
if ( world == NULL )
{
return;
}
iterations = b3ClampInt( iterations, 0, B3_MAX_RESTITUTION_ITERATIONS );
if ( iterations == world->restitutionIterations )
{
return;
}
B3_REC( world, WorldSetRestitutionIterations, worldId, iterations );
world->restitutionIterations = iterations;
}
int b3World_GetRestitutionIterations( b3WorldId worldId )
{
b3World* world = b3GetWorldFromId( worldId );
return world->restitutionIterations;
}
void b3World_EnableRestitutionPropagation( b3WorldId worldId, bool flag )
{
b3World* world = b3GetUnlockedWorldFromId( worldId );
if ( world == NULL )
{
return;
}
if ( flag == world->enableRestitutionPropagation )
{
return;
}
B3_REC( world, WorldEnableRestitutionPropagation, worldId, flag );
world->enableRestitutionPropagation = flag;
}
bool b3World_IsRestitutionPropagationEnabled( b3WorldId worldId )
{
b3World* world = b3GetWorldFromId( worldId );
return world->enableRestitutionPropagation;
}
void b3World_SetHitEventThreshold( b3WorldId worldId, float value )
{
b3World* world = b3GetUnlockedWorldFromId( worldId );