Skip to content

Commit

Permalink
more testing
Browse files Browse the repository at this point in the history
add vector includes
  • Loading branch information
erincatto committed Oct 18, 2024
1 parent c8379a9 commit ed78f91
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 13 deletions.
16 changes: 8 additions & 8 deletions include/box2d/id.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,52 +92,52 @@ static const b2JointId b2_nullJointId = B2_ZERO_INIT;
/// Store a body id into a uint64_t.
B2_INLINE uint64_t b2StoreBodyId( b2BodyId id )
{
return ( (uint64_t)id.index1 << 8 ) | ( (uint64_t)id.world0 ) << 4 | (uint64_t)id.revision;
return ( (uint64_t)id.index1 << 32 ) | ( (uint64_t)id.world0 ) << 16 | (uint64_t)id.revision;
}

/// Load a uint64_t into a body id.
B2_INLINE b2BodyId b2LoadBodyId( uint64_t x )
{
b2BodyId id = { (int32_t)( x >> 8 ), (uint16_t)( x >> 4 ), (uint16_t)( x ) };
b2BodyId id = { (int32_t)( x >> 32 ), (uint16_t)( x >> 16 ), (uint16_t)( x ) };
return id;
}

/// Store a shape id into a uint64_t.
B2_INLINE uint64_t b2StoreShapeId( b2ShapeId id )
{
return ( (uint64_t)id.index1 << 8 ) | ( (uint64_t)id.world0 ) << 4 | (uint64_t)id.revision;
return ( (uint64_t)id.index1 << 32 ) | ( (uint64_t)id.world0 ) << 16 | (uint64_t)id.revision;
}

/// Load a uint64_t into a shape id.
B2_INLINE b2ShapeId b2LoadShapeId( uint64_t x )
{
b2ShapeId id = { (int32_t)( x >> 8 ), (uint16_t)( x >> 4 ), (uint16_t)( x ) };
b2ShapeId id = { (int32_t)( x >> 32 ), (uint16_t)( x >> 16 ), (uint16_t)( x ) };
return id;
}

/// Store a chain id into a uint64_t.
B2_INLINE uint64_t b2StoreChainId( b2ChainId id )
{
return ( (uint64_t)id.index1 << 8 ) | ( (uint64_t)id.world0 ) << 4 | (uint64_t)id.revision;
return ( (uint64_t)id.index1 << 32 ) | ( (uint64_t)id.world0 ) << 16 | (uint64_t)id.revision;
}

/// Load a uint64_t into a chain id.
B2_INLINE b2ChainId b2LoadChainId( uint64_t x )
{
b2ChainId id = { (int32_t)( x >> 8 ), (uint16_t)( x >> 4 ), (uint16_t)( x ) };
b2ChainId id = { (int32_t)( x >> 32 ), (uint16_t)( x >> 16 ), (uint16_t)( x ) };
return id;
}

/// Store a joint id into a uint64_t.
B2_INLINE uint64_t b2StoreJointId( b2JointId id )
{
return ( (uint64_t)id.index1 << 8 ) | ( (uint64_t)id.world0 ) << 4 | (uint64_t)id.revision;
return ( (uint64_t)id.index1 << 32 ) | ( (uint64_t)id.world0 ) << 16 | (uint64_t)id.revision;
}

/// Load a uint64_t into a joint id.
B2_INLINE b2JointId b2LoadJointId( uint64_t x )
{
b2JointId id = { (int32_t)( x >> 8 ), (uint16_t)( x >> 4 ), (uint16_t)( x ) };
b2JointId id = { (int32_t)( x >> 32 ), (uint16_t)( x >> 16 ), (uint16_t)( x ) };
return id;
}

Expand Down
7 changes: 4 additions & 3 deletions samples/sample_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <GLFW/glfw3.h>
#include <imgui.h>
#include <vector>

// Note: resetting the scene is non-deterministic because the world uses freelists
class BenchmarkBarrel : public Sample
Expand Down Expand Up @@ -2071,17 +2072,17 @@ class BenchmarkSpinner : public Sample
int remainder = i % 3;
if ( remainder == 0 )
{
shapeDef.customColor = b2_colorYellow;
//shapeDef.customColor = b2_colorYellow;
b2CreateCapsuleShape( bodyId, &shapeDef, &capsule );
}
else if ( remainder == 1 )
{
shapeDef.customColor = b2_colorYellowGreen;
//shapeDef.customColor = b2_colorYellowGreen;
b2CreateCircleShape( bodyId, &shapeDef, &circle );
}
else if ( remainder == 2 )
{
shapeDef.customColor = b2_colorGreenYellow;
//shapeDef.customColor = b2_colorGreenYellow;
b2CreatePolygonShape( bodyId, &shapeDef, &square );
}

Expand Down
1 change: 1 addition & 0 deletions samples/sample_shapes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <GLFW/glfw3.h>
#include <imgui.h>
#include <vector>

class ChainShape : public Sample
{
Expand Down
1 change: 1 addition & 0 deletions samples/sample_stacking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <GLFW/glfw3.h>
#include <imgui.h>
#include <vector>

class SingleBox : public Sample
{
Expand Down
6 changes: 6 additions & 0 deletions src/solver.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ static void b2FinalizeBodiesTask( int startIndex, int endIndex, uint32_t threadI
{
// The AABB is updated after continuous collision.
// Add to moved shapes regardless of AABB changes.
// todo_erin this blocks predicted AABB extension from helping
shape->isFast = true;

// Bit-set to keep the move array sorted
Expand Down Expand Up @@ -1894,6 +1895,7 @@ void b2Solve( b2World* world, b2StepContext* stepContext )
else if ( shape->isFast )
{
// Shape is fast. It's aabb will be enlarged in continuous collision.
// todo_erin can this be deferred? This breaks AABB extension benefits.
b2BufferMove( broadPhase, shape->proxyKey );
}

Expand Down Expand Up @@ -1933,6 +1935,8 @@ void b2Solve( b2World* world, b2StepContext* stepContext )
// Serially enlarge broad-phase proxies for fast shapes
// Doing this here so that bullet shapes see them
{
b2TracyCZoneNC( continuous_enlarge, "Enlarge Proxies", b2_colorDarkTurquoise, true );

b2BroadPhase* broadPhase = &world->broadPhase;
b2DynamicTree* dynamicTree = broadPhase->trees + b2_dynamicBody;

Expand Down Expand Up @@ -1986,6 +1990,8 @@ void b2Solve( b2World* world, b2StepContext* stepContext )
shapeId = shape->nextShapeId;
}
}

b2TracyCZoneEnd( continuous_enlarge );
}

if ( stepContext->bulletBodyCount > 0 )
Expand Down
3 changes: 3 additions & 0 deletions test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ int main( void )
// How to break at the leaking allocation, in the watch window enter this variable
// and set it to the allocation number in {}. Do this at the first line in main.
// {,,ucrtbased.dll}_crtBreakAlloc = <allocation number> 3970
// Note:
// Just _crtBreakAlloc in static link
// Tracy Profile server leaks

_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDERR );
Expand Down
4 changes: 2 additions & 2 deletions test/test_determinism.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ static int CrossPlatformTest(void)
}

ENSURE( stepCount < maxSteps );
ENSURE( sleepStep == 313 );
ENSURE( hash == 0x1fc667fa );
ENSURE( sleepStep == 0x13f );
ENSURE( hash == 0x049eb491 );

free( bodies );

Expand Down
47 changes: 47 additions & 0 deletions test/test_world.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "test_macros.h"

#include "core.h"

#include "box2d/box2d.h"
#include "box2d/collision.h"
#include "box2d/math_functions.h"
Expand Down Expand Up @@ -295,13 +297,58 @@ int TestForAmy( void )
return 0;
}

#define WORLD_COUNT (b2_maxWorlds/2)

int TestWorldRecycle( void )
{
_Static_assert( WORLD_COUNT > 0, "world count" );

int count = 100;

b2WorldId worldIds[WORLD_COUNT];

for (int i = 0; i < count; ++i)
{
b2WorldDef worldDef = b2DefaultWorldDef();
for (int j = 0; j < WORLD_COUNT; ++j)
{
worldIds[j] = b2CreateWorld( &worldDef );
ENSURE( b2World_IsValid( worldIds[j] ) == true );

b2BodyDef bodyDef = b2DefaultBodyDef();
b2CreateBody( worldIds[j], &bodyDef );
}

for (int j = 0; j < WORLD_COUNT; ++j)
{
float timeStep = 1.0f / 60.0f;
int subStepCount = 1;

for ( int k = 0; k < 10; ++k )
{
b2World_Step( worldIds[j], timeStep, subStepCount );
}
}

for ( int j = WORLD_COUNT - 1; j >= 0; --j )
{
b2DestroyWorld( worldIds[j] );
ENSURE( b2World_IsValid( worldIds[j] ) == false );
worldIds[j] = b2_nullWorldId;
}
}

return 0;
}

int WorldTest( void )
{
RUN_SUBTEST( TestForAmy );
RUN_SUBTEST( HelloWorld );
RUN_SUBTEST( EmptyWorld );
RUN_SUBTEST( DestroyAllBodiesWorld );
RUN_SUBTEST( TestIsValid );
RUN_SUBTEST( TestWorldRecycle );

return 0;
}

0 comments on commit ed78f91

Please sign in to comment.