Skip to content

Commit

Permalink
tried rebuilding static tree
Browse files Browse the repository at this point in the history
  • Loading branch information
erincatto committed Oct 6, 2024
1 parent 337788d commit ec8d538
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
3 changes: 3 additions & 0 deletions include/box2d/box2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ B2_API b2Counters b2World_GetCounters( b2WorldId worldId );
/// Dump memory stats to box2d_memory.txt
B2_API void b2World_DumpMemoryStats( b2WorldId worldId );

/// todo testing
B2_API void b2World_RebuildStaticTree( b2WorldId worldId );

/** @} */

/**
Expand Down
9 changes: 3 additions & 6 deletions src/dynamic_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,6 @@ static int32_t b2PartitionMid( int32_t* indices, b2Vec2* centers, int32_t count
return count / 2;
}

// todo SIMD?
b2Vec2 lowerBound = centers[0];
b2Vec2 upperBound = centers[0];

Expand Down Expand Up @@ -1574,15 +1573,13 @@ static int32_t b2PartitionMid( int32_t* indices, b2Vec2* centers, int32_t count
{
return i1;
}
else
{
return count / 2;
}

return count / 2;
}

#else

#define B2_BIN_COUNT 8
#define B2_BIN_COUNT 64

typedef struct b2TreeBin
{
Expand Down
14 changes: 14 additions & 0 deletions src/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -2524,6 +2524,20 @@ void b2World_Explode( b2WorldId worldId, const b2ExplosionDef* explosionDef )
&explosionContext );
}

void b2World_RebuildStaticTree(b2WorldId worldId)
{
b2World* world = b2GetWorldFromId( worldId );
B2_ASSERT( world->locked == false );
if ( world->locked )
{
return;
}

b2DynamicTree* staticTree = world->broadPhase.trees + b2_staticBody;
b2DynamicTree_Rebuild( staticTree, true );
}


#if B2_VALIDATE
// When validating islands ids I have to compare the root island
// ids because islands are not merged until the next time step.
Expand Down

0 comments on commit ec8d538

Please sign in to comment.