Skip to content

Commit

Permalink
improved tree insertion SAH heuristic
Browse files Browse the repository at this point in the history
  • Loading branch information
erincatto committed Jul 24, 2023
1 parent 71da0e2 commit a077e8e
Show file tree
Hide file tree
Showing 7 changed files with 478 additions and 225 deletions.
3 changes: 3 additions & 0 deletions include/box2d/dynamic_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define b2_defaultMaskBits (0xFFFFFFFF)

// A node in the dynamic tree. The client does not interact with this directly.
// 16 + 16 + 8 + pad(8)
typedef struct b2TreeNode
{
// Enlarged AABB
Expand All @@ -38,6 +39,8 @@ typedef struct b2TreeNode

bool enlarged; // 1
bool moved; // 1

char pad[8];
} b2TreeNode;

/// A dynamic AABB tree broad-phase, inspired by Nathanael Presson's btDbvt.
Expand Down
2 changes: 1 addition & 1 deletion samples/collection/sample_dynamic_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class DynamicTree : public Sample
memset(&m_tree, 0, sizeof(m_tree));
BuildTree();
m_timeStamp = 0;
m_updateType = Update_PartialRebuild;
m_updateType = Update_Incremental;

m_startPoint = {0.0f, 0.0f};
m_endPoint = {0.0f, 0.0f};
Expand Down
4 changes: 2 additions & 2 deletions src/allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void* b2Alloc(int32_t size)
return ptr;
}

void* ptr = malloc(size);
void* ptr = _aligned_malloc(size, 16);
b2TracyCAlloc(ptr, size);
return ptr;
}
Expand All @@ -70,7 +70,7 @@ void b2Free(void* mem, int32_t size)
}
else
{
free(mem);
_aligned_free(mem);
}

atomic_fetch_sub_explicit(&b2_byteCount, size, memory_order_relaxed);
Expand Down
3 changes: 1 addition & 2 deletions src/broad_phase.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ void b2BroadPhase_EnlargeProxy(b2BroadPhase* bp, int32_t proxyKey, b2AABB aabb,
B2_ASSERT(typeIndex == b2_dynamicBody || typeIndex == b2_kinematicBody);

bool shouldBuffer = b2DynamicTree_EnlargeProxy(bp->trees + typeIndex, proxyId, aabb, outFatAABB);

if (shouldBuffer)
{
b2BufferMove(bp, proxyKey);
Expand Down Expand Up @@ -335,7 +334,7 @@ void b2BroadPhase_UpdatePairs(b2World* world)

if (b2_parallel)
{
int32_t minRange = 8;
int32_t minRange = 64;
world->enqueueTask(&b2FindPairsTask, moveCount, minRange, world, world->userTaskContext);
world->finishTasks(world->userTaskContext);
}
Expand Down
Loading

0 comments on commit a077e8e

Please sign in to comment.