diff --git a/src/world.c b/src/world.c index f983461d8..30806119a 100644 --- a/src/world.c +++ b/src/world.c @@ -177,7 +177,7 @@ b2WorldId b2CreateWorld( const b2WorldDef* def ) world->gravity = def->gravity; world->hitEventThreshold = def->hitEventThreshold; world->restitutionThreshold = def->restitutionThreshold; - world->maxLinearVelocity = def->maximumLinearSpeed; + world->maxLinearSpeed = def->maximumLinearSpeed; world->contactPushSpeed = def->contactPushSpeed; world->contactHertz = def->contactHertz; world->contactDampingRatio = def->contactDampingRatio; @@ -757,7 +757,7 @@ void b2World_Step( b2WorldId worldId, float timeStep, int subStepCount ) context.jointSoftness = b2MakeSoft( jointHertz, world->jointDampingRatio, context.h ); context.restitutionThreshold = world->restitutionThreshold; - context.maxLinearVelocity = world->maxLinearVelocity; + context.maxLinearVelocity = world->maxLinearSpeed; context.enableWarmStarting = world->enableWarmStarting; // Update contacts @@ -1739,9 +1739,9 @@ void b2World_SetJointTuning( b2WorldId worldId, float hertz, float dampingRatio world->jointDampingRatio = b2ClampFloat( dampingRatio, 0.0f, FLT_MAX ); } -void b2World_SetMaximumLinearSpeed( b2WorldId worldId, float maximumLinearVelocity ) +void b2World_SetMaximumLinearSpeed( b2WorldId worldId, float maximumLinearSpeed ) { - B2_ASSERT( b2IsValidFloat( maximumLinearVelocity ) && maximumLinearVelocity > 0.0f ); + B2_ASSERT( b2IsValidFloat( maximumLinearSpeed ) && maximumLinearSpeed > 0.0f ); b2World* world = b2GetWorldFromId( worldId ); B2_ASSERT( world->locked == false ); @@ -1750,13 +1750,13 @@ void b2World_SetMaximumLinearSpeed( b2WorldId worldId, float maximumLinearVeloci return; } - world->maxLinearVelocity = maximumLinearVelocity; + world->maxLinearSpeed = maximumLinearSpeed; } -float b2World_GetMaximumLinearVelocity( b2WorldId worldId ) +float b2World_GetMaximumLinearSpeed( b2WorldId worldId ) { b2World* world = b2GetWorldFromId( worldId ); - return world->maxLinearVelocity; + return world->maxLinearSpeed; } b2Profile b2World_GetProfile( b2WorldId worldId ) diff --git a/src/world.h b/src/world.h index 9ab4daefc..8c2e3bebb 100644 --- a/src/world.h +++ b/src/world.h @@ -126,7 +126,7 @@ typedef struct b2World b2Vec2 gravity; float hitEventThreshold; float restitutionThreshold; - float maxLinearVelocity; + float maxLinearSpeed; float contactPushSpeed; float contactHertz; float contactDampingRatio; diff --git a/test/test_world.c b/test/test_world.c index b29bfd674..f7dbde977 100644 --- a/test/test_world.c +++ b/test/test_world.c @@ -2,6 +2,7 @@ // SPDX-License-Identifier: MIT #include "constants.h" +#include "core.h" #include "test_macros.h" #include "box2d/box2d.h" @@ -340,6 +341,88 @@ int TestWorldRecycle( void ) return 0; } +static bool CustomFilter( b2ShapeId shapeIdA, b2ShapeId shapeIdB, void* context ) +{ + (void)shapeIdA; + (void)shapeIdB; + ENSURE( context == NULL ); + return true; +} + +static bool PreSolveStatic( b2ShapeId shapeIdA, b2ShapeId shapeIdB, b2Manifold* manifold, void* context ) +{ + (void)shapeIdA; + (void)shapeIdB; + (void)manifold; + ENSURE( context == NULL ); + return false; +} + +// This test is here to ensure all API functions link correctly. +int TestWorldCoverage( void ) +{ + b2WorldDef worldDef = b2DefaultWorldDef(); + + b2WorldId worldId = b2CreateWorld( &worldDef ); + ENSURE( b2World_IsValid( worldId ) ); + + b2World_EnableSleeping( worldId, true ); + b2World_EnableSleeping( worldId, false ); + bool flag = b2World_IsSleepingEnabled( worldId ); + ENSURE( flag == false ); + + b2World_EnableContinuous( worldId, false ); + b2World_EnableContinuous( worldId, true ); + flag = b2World_IsContinuousEnabled( worldId ); + ENSURE( flag == true ); + + b2World_SetRestitutionThreshold( worldId, 0.0f ); + b2World_SetRestitutionThreshold( worldId, 2.0f ); + float value = b2World_GetRestitutionThreshold( worldId ); + ENSURE( value == 2.0f ); + + b2World_SetHitEventThreshold( worldId, 0.0f ); + b2World_SetHitEventThreshold( worldId, 100.0f ); + value = b2World_GetHitEventThreshold( worldId ); + ENSURE( value == 100.0f ); + + b2World_SetCustomFilterCallback( worldId, CustomFilter, NULL ); + b2World_SetPreSolveCallback( worldId, PreSolveStatic, NULL ); + + b2Vec2 g = { 1.0f, 2.0f }; + b2World_SetGravity( worldId, g ); + b2Vec2 v = b2World_GetGravity( worldId ); + ENSURE( v.x == g.x ); + ENSURE( v.y == g.y ); + + b2ExplosionDef explosionDef = b2DefaultExplosionDef(); + b2World_Explode( worldId, &explosionDef ); + + b2World_SetContactTuning( worldId, 10.0f, 2.0f, 4.0f ); + b2World_SetJointTuning( worldId, 10.0f, 2.0f ); + + b2World_SetMaximumLinearSpeed( worldId, 10.0f ); + value = b2World_GetMaximumLinearSpeed( worldId ); + ENSURE( value == 10.0f ); + + b2World_EnableWarmStarting( worldId, true ); + flag = b2World_IsWarmStartingEnabled( worldId ); + ENSURE( flag == true ); + + int count = b2World_GetAwakeBodyCount( worldId ); + ENSURE( count == 0 ); + + b2World_SetUserData( worldId, &value ); + void* userData = b2World_GetUserData( worldId ); + ENSURE( userData == &value ); + + b2World_Step( worldId, 1.0f, 1 ); + + b2DestroyWorld( worldId ); + + return 0; +} + int WorldTest( void ) { RUN_SUBTEST( TestForAmy ); @@ -348,6 +431,7 @@ int WorldTest( void ) RUN_SUBTEST( DestroyAllBodiesWorld ); RUN_SUBTEST( TestIsValid ); RUN_SUBTEST( TestWorldRecycle ); + RUN_SUBTEST( TestWorldCoverage ); return 0; }