From ec8d53888677502e3052b27d603bc8d6fce21311 Mon Sep 17 00:00:00 2001 From: Erin Catto Date: Sat, 5 Oct 2024 23:01:34 -0700 Subject: [PATCH] tried rebuilding static tree --- include/box2d/box2d.h | 3 +++ src/dynamic_tree.c | 9 +++------ src/world.c | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/box2d/box2d.h b/include/box2d/box2d.h index af3eec88a..2d2b688c2 100644 --- a/include/box2d/box2d.h +++ b/include/box2d/box2d.h @@ -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 ); + /** @} */ /** diff --git a/src/dynamic_tree.c b/src/dynamic_tree.c index 28bf972a6..7f188aec8 100644 --- a/src/dynamic_tree.c +++ b/src/dynamic_tree.c @@ -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]; @@ -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 { diff --git a/src/world.c b/src/world.c index 1a89e193f..a6426ecc1 100644 --- a/src/world.c +++ b/src/world.c @@ -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.