- API to query compounds directly. - Fix some uninitialized stuff (thanks MSAN). - Fix for store impulses on overflow. - AABB margin reduced for small shapes - body contact recycling option - angular threshold for contact recycling - reduce AABB margin on smaller shapes - fix for hull vs tri when axis aligned - fully locked rotation uses zero inverse inertia
113 lines
2.3 KiB
C
113 lines
2.3 KiB
C
// SPDX-FileCopyrightText: 2025 Erin Catto
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#include "box3d/box3d.h"
|
|
#include "determinism.h"
|
|
#include "test_macros.h"
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#ifdef BOX3D_PROFILE
|
|
#include <tracy/TracyC.h>
|
|
#else
|
|
#define TracyCFrameMark
|
|
#endif
|
|
|
|
#define EXPECTED_SLEEP_STEP 300
|
|
#define EXPECTED_HASH 0x2A58F9D0
|
|
|
|
static int SingleMultithreadingTest( int workerCount )
|
|
{
|
|
b3WorldDef worldDef = b3DefaultWorldDef();
|
|
worldDef.workerCount = workerCount;
|
|
|
|
b3WorldId worldId = b3CreateWorld( &worldDef );
|
|
|
|
FallingRagdollData data = CreateFallingRagdolls( worldId );
|
|
|
|
float timeStep = 1.0f / 60.0f;
|
|
|
|
int stepLimit = 500;
|
|
for ( int i = 0; i < stepLimit; ++i )
|
|
{
|
|
int subStepCount = 4;
|
|
b3World_Step( worldId, timeStep, subStepCount );
|
|
TracyCFrameMark;
|
|
|
|
bool done = UpdateFallingRagdolls( worldId, &data );
|
|
if ( done )
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
b3DestroyWorld( worldId );
|
|
|
|
if ( data.sleepStep != EXPECTED_SLEEP_STEP || data.hash != EXPECTED_HASH )
|
|
{
|
|
printf( " workers=%d sleepStep=%d hash=0x%08X\n", workerCount, data.sleepStep, data.hash );
|
|
}
|
|
|
|
ENSURE( data.sleepStep == EXPECTED_SLEEP_STEP );
|
|
ENSURE( data.hash == EXPECTED_HASH );
|
|
|
|
DestroyFallingRagdolls( &data );
|
|
|
|
return 0;
|
|
}
|
|
|
|
// Test multithreaded determinism.
|
|
static int MultithreadingTest( void )
|
|
{
|
|
for ( int workerCount = 1; workerCount < 6; ++workerCount )
|
|
{
|
|
int result = SingleMultithreadingTest( workerCount );
|
|
ENSURE( result == 0 );
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
// Test cross platform determinism.
|
|
static int CrossPlatformTest( void )
|
|
{
|
|
b3WorldDef worldDef = b3DefaultWorldDef();
|
|
b3WorldId worldId = b3CreateWorld( &worldDef );
|
|
|
|
FallingRagdollData data = CreateFallingRagdolls( worldId );
|
|
|
|
float timeStep = 1.0f / 60.0f;
|
|
|
|
bool done = false;
|
|
while ( done == false )
|
|
{
|
|
int subStepCount = 4;
|
|
b3World_Step( worldId, timeStep, subStepCount );
|
|
TracyCFrameMark;
|
|
|
|
done = UpdateFallingRagdolls( worldId, &data );
|
|
}
|
|
|
|
if ( data.sleepStep != EXPECTED_SLEEP_STEP || data.hash != EXPECTED_HASH )
|
|
{
|
|
printf( " cross-platform sleepStep=%d hash=0x%08X\n", data.sleepStep, data.hash );
|
|
}
|
|
|
|
ENSURE( data.sleepStep == EXPECTED_SLEEP_STEP );
|
|
ENSURE( data.hash == EXPECTED_HASH );
|
|
|
|
DestroyFallingRagdolls( &data );
|
|
|
|
b3DestroyWorld( worldId );
|
|
|
|
return 0;
|
|
}
|
|
|
|
int DeterminismTest( void )
|
|
{
|
|
RUN_SUBTEST( MultithreadingTest );
|
|
RUN_SUBTEST( CrossPlatformTest );
|
|
|
|
return 0;
|
|
}
|