use unsigned integers instead of integers in some collision code
This commit is contained in:
@@ -21,8 +21,8 @@
|
||||
b3BroadPhase::b3BroadPhase()
|
||||
{
|
||||
m_moveBufferCapacity = 16;
|
||||
m_moveBuffer = (i32*)b3Alloc(m_moveBufferCapacity * sizeof(i32));
|
||||
memset(m_moveBuffer, 0, m_moveBufferCapacity * sizeof(i32));
|
||||
m_moveBuffer = (u32*)b3Alloc(m_moveBufferCapacity * sizeof(u32));
|
||||
memset(m_moveBuffer, 0, m_moveBufferCapacity * sizeof(u32));
|
||||
m_moveBufferCount = 0;
|
||||
|
||||
m_pairCapacity = 16;
|
||||
@@ -37,7 +37,7 @@ b3BroadPhase::~b3BroadPhase()
|
||||
b3Free(m_pairs);
|
||||
}
|
||||
|
||||
void b3BroadPhase::BufferMove(i32 proxyId)
|
||||
void b3BroadPhase::BufferMove(u32 proxyId)
|
||||
{
|
||||
// The proxy has been moved. Add it to the buffer of moved proxies.
|
||||
// Check capacity.
|
||||
@@ -46,9 +46,9 @@ void b3BroadPhase::BufferMove(i32 proxyId)
|
||||
// Duplicate capacity.
|
||||
m_moveBufferCapacity *= 2;
|
||||
|
||||
i32* oldMoveBuffer = m_moveBuffer;
|
||||
m_moveBuffer = (i32*)b3Alloc(m_moveBufferCapacity * sizeof(i32));
|
||||
memcpy(m_moveBuffer, oldMoveBuffer, m_moveBufferCount * sizeof(i32));
|
||||
u32* oldMoveBuffer = m_moveBuffer;
|
||||
m_moveBuffer = (u32*)b3Alloc(m_moveBufferCapacity * sizeof(u32));
|
||||
memcpy(m_moveBuffer, oldMoveBuffer, m_moveBufferCount * sizeof(u32));
|
||||
b3Free(oldMoveBuffer);
|
||||
}
|
||||
|
||||
@@ -57,12 +57,12 @@ void b3BroadPhase::BufferMove(i32 proxyId)
|
||||
++m_moveBufferCount;
|
||||
}
|
||||
|
||||
bool b3BroadPhase::TestOverlap(i32 proxy1, i32 proxy2) const
|
||||
bool b3BroadPhase::TestOverlap(u32 proxy1, u32 proxy2) const
|
||||
{
|
||||
return m_tree.TestOverlap(proxy1, proxy2);
|
||||
}
|
||||
|
||||
i32 b3BroadPhase::CreateProxy(const b3AABB3& aabb, void* userData)
|
||||
u32 b3BroadPhase::CreateProxy(const b3AABB3& aabb, void* userData)
|
||||
{
|
||||
// Later, if the node aabb has changed then it should be reinserted into the tree.
|
||||
// However, this can be expansive due to the hierarchy reconstruction.
|
||||
@@ -70,17 +70,17 @@ i32 b3BroadPhase::CreateProxy(const b3AABB3& aabb, void* userData)
|
||||
// so we can check later if the new (original) AABB is inside the old (fat) AABB.
|
||||
b3AABB3 fatAABB = aabb;
|
||||
fatAABB.Extend(B3_AABB_EXTENSION);
|
||||
i32 proxyId = m_tree.InsertNode(fatAABB, userData);
|
||||
u32 proxyId = m_tree.InsertNode(fatAABB, userData);
|
||||
BufferMove(proxyId);
|
||||
return proxyId;
|
||||
}
|
||||
|
||||
void b3BroadPhase::DestroyProxy(i32 proxyId)
|
||||
void b3BroadPhase::DestroyProxy(u32 proxyId)
|
||||
{
|
||||
return m_tree.RemoveNode(proxyId);
|
||||
}
|
||||
|
||||
bool b3BroadPhase::MoveProxy(i32 proxyId, const b3AABB3& aabb, const b3Vec3& displacement)
|
||||
bool b3BroadPhase::MoveProxy(u32 proxyId, const b3AABB3& aabb, const b3Vec3& displacement)
|
||||
{
|
||||
if (m_tree.GetAABB(proxyId).Contains(aabb))
|
||||
{
|
||||
@@ -133,7 +133,7 @@ bool b3BroadPhase::MoveProxy(i32 proxyId, const b3AABB3& aabb, const b3Vec3& dis
|
||||
return true;
|
||||
}
|
||||
|
||||
bool b3BroadPhase::Report(i32 proxyId)
|
||||
bool b3BroadPhase::Report(u32 proxyId)
|
||||
{
|
||||
if (proxyId == m_queryProxyId)
|
||||
{
|
||||
@@ -160,4 +160,4 @@ bool b3BroadPhase::Report(i32 proxyId)
|
||||
|
||||
// Keep looking for overlapping pairs.
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -21,7 +21,7 @@
|
||||
|
||||
b3DynamicTree::b3DynamicTree()
|
||||
{
|
||||
m_root = NULL_NODE;
|
||||
m_root = B3_NULL_NODE_D;
|
||||
|
||||
// Preallocate 32 nodes.
|
||||
m_nodeCapacity = 32;
|
||||
@@ -40,9 +40,11 @@ b3DynamicTree::~b3DynamicTree()
|
||||
}
|
||||
|
||||
// Return a node from the pool.
|
||||
i32 b3DynamicTree::AllocateNode()
|
||||
u32 b3DynamicTree::AllocateNode()
|
||||
{
|
||||
if (m_freeList == NULL_NODE)
|
||||
B3_ASSERT(m_nodeCapacity > 0);
|
||||
|
||||
if (m_freeList == B3_NULL_NODE_D)
|
||||
{
|
||||
B3_ASSERT(m_nodeCount == m_nodeCapacity);
|
||||
|
||||
@@ -60,13 +62,13 @@ i32 b3DynamicTree::AllocateNode()
|
||||
}
|
||||
|
||||
// Grab the free node.
|
||||
i32 node = m_freeList;
|
||||
u32 node = m_freeList;
|
||||
|
||||
m_freeList = m_nodes[node].next;
|
||||
|
||||
m_nodes[node].parent = NULL_NODE;
|
||||
m_nodes[node].child1 = NULL_NODE;
|
||||
m_nodes[node].child2 = NULL_NODE;
|
||||
m_nodes[node].parent = B3_NULL_NODE_D;
|
||||
m_nodes[node].child1 = B3_NULL_NODE_D;
|
||||
m_nodes[node].child2 = B3_NULL_NODE_D;
|
||||
m_nodes[node].height = 0;
|
||||
m_nodes[node].userData = NULL;
|
||||
|
||||
@@ -75,35 +77,37 @@ i32 b3DynamicTree::AllocateNode()
|
||||
return node;
|
||||
}
|
||||
|
||||
void b3DynamicTree::FreeNode(i32 node)
|
||||
void b3DynamicTree::FreeNode(u32 node)
|
||||
{
|
||||
B3_ASSERT(node != NULL_NODE && node < m_nodeCapacity);
|
||||
B3_ASSERT(node != B3_NULL_NODE_D && node < m_nodeCapacity);
|
||||
m_nodes[node].next = m_freeList;
|
||||
m_nodes[node].height = -1;
|
||||
m_freeList = node;
|
||||
--m_nodeCount;
|
||||
}
|
||||
|
||||
void b3DynamicTree::AddToFreeList(i32 node)
|
||||
void b3DynamicTree::AddToFreeList(u32 node)
|
||||
{
|
||||
B3_ASSERT(m_nodeCapacity > 0);
|
||||
|
||||
// Starting from the given node, relink the linked list of nodes.
|
||||
for (i32 i = node; i < m_nodeCapacity - 1; ++i)
|
||||
for (u32 i = node; i < m_nodeCapacity - 1; ++i)
|
||||
{
|
||||
m_nodes[i].next = i + 1;
|
||||
m_nodes[i].height = -1;
|
||||
}
|
||||
|
||||
m_nodes[m_nodeCapacity - 1].next = NULL_NODE;
|
||||
m_nodes[m_nodeCapacity - 1].next = B3_NULL_NODE_D;
|
||||
m_nodes[m_nodeCapacity - 1].height = -1;
|
||||
|
||||
// Make the node available for the next allocation.
|
||||
m_freeList = node;
|
||||
}
|
||||
|
||||
i32 b3DynamicTree::InsertNode(const b3AABB3& aabb, void* userData)
|
||||
u32 b3DynamicTree::InsertNode(const b3AABB3& aabb, void* userData)
|
||||
{
|
||||
// Insert into the array.
|
||||
i32 node = AllocateNode();
|
||||
u32 node = AllocateNode();
|
||||
m_nodes[node].aabb = aabb;
|
||||
m_nodes[node].userData = userData;
|
||||
m_nodes[node].height = 0;
|
||||
@@ -115,7 +119,7 @@ i32 b3DynamicTree::InsertNode(const b3AABB3& aabb, void* userData)
|
||||
return node;
|
||||
}
|
||||
|
||||
void b3DynamicTree::RemoveNode(i32 proxyId)
|
||||
void b3DynamicTree::RemoveNode(u32 proxyId)
|
||||
{
|
||||
// Remove from the tree.
|
||||
RemoveLeaf(proxyId);
|
||||
@@ -123,9 +127,9 @@ void b3DynamicTree::RemoveNode(i32 proxyId)
|
||||
FreeNode(proxyId);
|
||||
}
|
||||
|
||||
void b3DynamicTree::UpdateNode(i32 proxyId, const b3AABB3& aabb)
|
||||
void b3DynamicTree::UpdateNode(u32 proxyId, const b3AABB3& aabb)
|
||||
{
|
||||
B3_ASSERT(m_root != NULL_NODE);
|
||||
B3_ASSERT(m_root != B3_NULL_NODE_D);
|
||||
B3_ASSERT(m_nodes[proxyId].IsLeaf());
|
||||
// Remove old AABB from the tree.
|
||||
RemoveLeaf(proxyId);
|
||||
@@ -134,13 +138,9 @@ void b3DynamicTree::UpdateNode(i32 proxyId, const b3AABB3& aabb)
|
||||
InsertLeaf(proxyId);
|
||||
}
|
||||
|
||||
i32 b3DynamicTree::FindBest(const b3AABB3& leafAABB) const
|
||||
u32 b3DynamicTree::FindBest(const b3AABB3& leafAABB) const
|
||||
{
|
||||
// To find a good branch node, the manhattan distance could be used as heuristic.
|
||||
// However, the current propagated node and the leaf node volume are incompletely considerable.
|
||||
// Therefore, an approximation of the surface are heuristic (SAH) is used.
|
||||
|
||||
i32 index = m_root;
|
||||
u32 index = m_root;
|
||||
while (!m_nodes[index].IsLeaf())
|
||||
{
|
||||
float32 branchArea = m_nodes[index].aabb.SurfaceArea();
|
||||
@@ -155,8 +155,8 @@ i32 b3DynamicTree::FindBest(const b3AABB3& leafAABB) const
|
||||
float32 inheritanceCost = 2.0f * (combinedArea - branchArea);
|
||||
|
||||
// The branch node child nodes cost.
|
||||
i32 child1 = m_nodes[index].child1;
|
||||
i32 child2 = m_nodes[index].child2;
|
||||
u32 child1 = m_nodes[index].child1;
|
||||
u32 child2 = m_nodes[index].child2;
|
||||
|
||||
// Cost of descending onto child1.
|
||||
float32 childCost1 = 0.0f;
|
||||
@@ -201,14 +201,14 @@ i32 b3DynamicTree::FindBest(const b3AABB3& leafAABB) const
|
||||
return index;
|
||||
}
|
||||
|
||||
void b3DynamicTree::InsertLeaf(i32 leaf)
|
||||
void b3DynamicTree::InsertLeaf(u32 leaf)
|
||||
{
|
||||
if (m_root == NULL_NODE)
|
||||
if (m_root == B3_NULL_NODE_D)
|
||||
{
|
||||
// If this tree root node is empty then just set the leaf
|
||||
// node to it.
|
||||
m_root = leaf;
|
||||
m_nodes[m_root].parent = NULL_NODE;
|
||||
m_nodes[m_root].parent = B3_NULL_NODE_D;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -216,12 +216,12 @@ void b3DynamicTree::InsertLeaf(i32 leaf)
|
||||
b3AABB3 leafAabb = m_nodes[leaf].aabb;
|
||||
|
||||
// Search for the best branch node of this tree starting from the tree root node.
|
||||
i32 sibling = FindBest(leafAabb);
|
||||
u32 sibling = FindBest(leafAabb);
|
||||
|
||||
i32 oldParent = m_nodes[sibling].parent;
|
||||
u32 oldParent = m_nodes[sibling].parent;
|
||||
|
||||
// Create and setup new parent.
|
||||
i32 newParent = AllocateNode();
|
||||
u32 newParent = AllocateNode();
|
||||
m_nodes[newParent].parent = oldParent;
|
||||
m_nodes[newParent].child1 = sibling;
|
||||
m_nodes[sibling].parent = newParent;
|
||||
@@ -231,7 +231,7 @@ void b3DynamicTree::InsertLeaf(i32 leaf)
|
||||
m_nodes[newParent].aabb = b3Combine(leafAabb, m_nodes[sibling].aabb);
|
||||
m_nodes[newParent].height = m_nodes[sibling].height + 1;
|
||||
|
||||
if (oldParent != NULL_NODE)
|
||||
if (oldParent != B3_NULL_NODE_D)
|
||||
{
|
||||
// The sibling was not the root.
|
||||
// Find which child node of the old parent is the sibling
|
||||
@@ -256,17 +256,17 @@ void b3DynamicTree::InsertLeaf(i32 leaf)
|
||||
WalkBackNodeAndCombineVolumes(newParent);
|
||||
}
|
||||
|
||||
void b3DynamicTree::RemoveLeaf(i32 leaf)
|
||||
void b3DynamicTree::RemoveLeaf(u32 leaf)
|
||||
{
|
||||
if (leaf == m_root)
|
||||
{
|
||||
m_root = NULL_NODE;
|
||||
m_root = B3_NULL_NODE_D;
|
||||
return;
|
||||
}
|
||||
|
||||
i32 parent = m_nodes[leaf].parent;
|
||||
i32 grandParent = m_nodes[parent].parent;
|
||||
i32 sibling;
|
||||
u32 parent = m_nodes[leaf].parent;
|
||||
u32 grandParent = m_nodes[parent].parent;
|
||||
u32 sibling;
|
||||
if (m_nodes[parent].child1 == leaf)
|
||||
{
|
||||
sibling = m_nodes[parent].child2;
|
||||
@@ -276,7 +276,7 @@ void b3DynamicTree::RemoveLeaf(i32 leaf)
|
||||
sibling = m_nodes[parent].child1;
|
||||
}
|
||||
|
||||
if (grandParent != NULL_NODE)
|
||||
if (grandParent != B3_NULL_NODE_D)
|
||||
{
|
||||
if (m_nodes[grandParent].child1 == parent)
|
||||
{
|
||||
@@ -297,23 +297,23 @@ void b3DynamicTree::RemoveLeaf(i32 leaf)
|
||||
else
|
||||
{
|
||||
m_root = sibling;
|
||||
m_nodes[sibling].parent = NULL_NODE;
|
||||
m_nodes[sibling].parent = B3_NULL_NODE_D;
|
||||
// Remove parent node.
|
||||
FreeNode(parent);
|
||||
}
|
||||
}
|
||||
|
||||
void b3DynamicTree::WalkBackNodeAndCombineVolumes(i32 node)
|
||||
void b3DynamicTree::WalkBackNodeAndCombineVolumes(u32 node)
|
||||
{
|
||||
while (node != NULL_NODE)
|
||||
while (node != B3_NULL_NODE_D)
|
||||
{
|
||||
//@todo node = Balance(node);
|
||||
|
||||
i32 child1 = m_nodes[node].child1;
|
||||
i32 child2 = m_nodes[node].child2;
|
||||
u32 child1 = m_nodes[node].child1;
|
||||
u32 child2 = m_nodes[node].child2;
|
||||
|
||||
B3_ASSERT(child1 != NULL_NODE);
|
||||
B3_ASSERT(child2 != NULL_NODE);
|
||||
B3_ASSERT(child1 != B3_NULL_NODE_D);
|
||||
B3_ASSERT(child2 != B3_NULL_NODE_D);
|
||||
|
||||
m_nodes[node].height = 1 + b3Max(m_nodes[child1].height, m_nodes[child2].height);
|
||||
m_nodes[node].aabb = b3Combine(m_nodes[child1].aabb, m_nodes[child2].aabb);
|
||||
@@ -322,9 +322,9 @@ void b3DynamicTree::WalkBackNodeAndCombineVolumes(i32 node)
|
||||
}
|
||||
}
|
||||
|
||||
void b3DynamicTree::Validate(i32 nodeID) const
|
||||
void b3DynamicTree::Validate(u32 nodeID) const
|
||||
{
|
||||
if (nodeID == NULL_NODE)
|
||||
if (nodeID == B3_NULL_NODE_D)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -332,19 +332,19 @@ void b3DynamicTree::Validate(i32 nodeID) const
|
||||
// The root node has no parent.
|
||||
if (nodeID == m_root)
|
||||
{
|
||||
B3_ASSERT(m_nodes[nodeID].parent == NULL_NODE);
|
||||
B3_ASSERT(m_nodes[nodeID].parent == B3_NULL_NODE_D);
|
||||
}
|
||||
|
||||
const b3Node* node = m_nodes + nodeID;
|
||||
|
||||
i32 child1 = node->child1;
|
||||
i32 child2 = node->child2;
|
||||
u32 child1 = node->child1;
|
||||
u32 child2 = node->child2;
|
||||
|
||||
if (node->IsLeaf())
|
||||
{
|
||||
// Leaf nodes has no children and its height is zero.
|
||||
B3_ASSERT(child1 == NULL_NODE);
|
||||
B3_ASSERT(child2 == NULL_NODE);
|
||||
B3_ASSERT(child1 == B3_NULL_NODE_D);
|
||||
B3_ASSERT(child2 == B3_NULL_NODE_D);
|
||||
B3_ASSERT(node->height == 0);
|
||||
}
|
||||
else
|
||||
@@ -370,15 +370,15 @@ void b3DynamicTree::Draw() const
|
||||
return;
|
||||
}
|
||||
|
||||
b3Stack<i32, 256> stack;
|
||||
b3Stack<u32, 256> stack;
|
||||
stack.Push(m_root);
|
||||
|
||||
while (!stack.IsEmpty())
|
||||
{
|
||||
i32 nodeIndex = stack.Top();
|
||||
u32 nodeIndex = stack.Top();
|
||||
stack.Pop();
|
||||
|
||||
if (nodeIndex == NULL_NODE)
|
||||
if (nodeIndex == B3_NULL_NODE_D)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@@ -120,7 +120,7 @@ void b3StaticTree::Build(const b3AABB3* set, b3Node* node, u32* ids, u32 count,
|
||||
if (count <= minObjectsPerLeaf)
|
||||
{
|
||||
++leafCount;
|
||||
node->child1 = NULL_NODE_S;
|
||||
node->child1 = B3_NULL_NODE_S;
|
||||
node->index = ids[0];
|
||||
}
|
||||
else
|
||||
|
@@ -83,7 +83,6 @@ b3Body::b3Body(const b3BodyDef& def, b3World* world)
|
||||
m_angularDamping = def.angularDamping;
|
||||
m_gravityScale = def.gravityScale;
|
||||
m_userData = def.userData;
|
||||
m_islandID = -1;
|
||||
m_sleepTime = 0.0f;
|
||||
}
|
||||
|
||||
@@ -464,7 +463,7 @@ void b3Body::SetType(b3BodyType type)
|
||||
|
||||
void b3Body::Dump() const
|
||||
{
|
||||
i32 bodyIndex = m_islandID;
|
||||
u32 bodyIndex = m_islandID;
|
||||
|
||||
b3Log(" {\n");
|
||||
b3Log(" b3BodyDef bd;\n");
|
||||
|
@@ -154,7 +154,7 @@ void b3ContactManager::SynchronizeShapes()
|
||||
// Find potentially overlapping shape pairs.
|
||||
void b3ContactManager::FindNewContacts()
|
||||
{
|
||||
m_broadPhase.FindNewPairs(this);
|
||||
m_broadPhase.FindPairs(this);
|
||||
|
||||
b3MeshContactLink* c = m_meshContactList.m_head;
|
||||
while (c)
|
||||
@@ -175,11 +175,11 @@ void b3ContactManager::UpdateContacts()
|
||||
b3OverlappingPair* pair = &c->m_pair;
|
||||
|
||||
b3Shape* shapeA = pair->shapeA;
|
||||
i32 proxyA = shapeA->m_broadPhaseID;
|
||||
u32 proxyA = shapeA->m_broadPhaseID;
|
||||
b3Body* bodyA = shapeA->m_body;
|
||||
|
||||
b3Shape* shapeB = pair->shapeB;
|
||||
i32 proxyB = shapeB->m_broadPhaseID;
|
||||
u32 proxyB = shapeB->m_broadPhaseID;
|
||||
b3Body* bodyB = shapeB->m_body;
|
||||
|
||||
// Check if the bodies must not collide with each other.
|
||||
|
@@ -384,7 +384,7 @@ bool b3HullShape::RayCast(b3RayCastOutput* output, const b3RayCastInput& input,
|
||||
float32 lower = 0.0f;
|
||||
float32 upper = input.maxFraction;
|
||||
|
||||
i32 index = -1;
|
||||
u32 index = B3_MAX_U32;
|
||||
|
||||
// s(lower) = p1 + lower * d, 0 <= lower <= kupper
|
||||
// The segment intersects the plane if a 'lower' exists
|
||||
@@ -451,7 +451,7 @@ bool b3HullShape::RayCast(b3RayCastOutput* output, const b3RayCastInput& input,
|
||||
|
||||
B3_ASSERT(lower >= 0.0f && lower <= input.maxFraction);
|
||||
|
||||
if (index >= 0)
|
||||
if (index != B3_MAX_U32)
|
||||
{
|
||||
output->fraction = lower;
|
||||
output->normal = b3Mul(xf.rotation, planes[index].normal);
|
||||
|
@@ -65,7 +65,7 @@ void b3Shape::DestroyContacts()
|
||||
}
|
||||
}
|
||||
|
||||
void b3Shape::Dump(i32 bodyIndex) const
|
||||
void b3Shape::Dump(u32 bodyIndex) const
|
||||
{
|
||||
switch (m_type)
|
||||
{
|
||||
|
@@ -312,7 +312,7 @@ void b3World::Solve(float32 dt, u32 velocityIterations, u32 positionIterations)
|
||||
|
||||
struct b3RayCastCallback
|
||||
{
|
||||
float32 Report(const b3RayCastInput& input, i32 proxyId)
|
||||
float32 Report(const b3RayCastInput& input, u32 proxyId)
|
||||
{
|
||||
// Get shape associated with the proxy.
|
||||
void* userData = broadPhase->GetUserData(proxyId);
|
||||
@@ -360,7 +360,7 @@ void b3World::RayCast(b3RayCastListener* listener, const b3Vec3& p1, const b3Vec
|
||||
|
||||
struct b3RayCastSingleCallback
|
||||
{
|
||||
float32 Report(const b3RayCastInput& input, i32 proxyId)
|
||||
float32 Report(const b3RayCastInput& input, u32 proxyId)
|
||||
{
|
||||
// Get shape associated with the proxy.
|
||||
void* userData = broadPhase->GetUserData(proxyId);
|
||||
@@ -425,7 +425,7 @@ bool b3World::RayCastSingle(b3RayCastSingleOutput* output, const b3Vec3& p1, con
|
||||
|
||||
struct b3QueryAABBCallback
|
||||
{
|
||||
bool Report(i32 proxyID)
|
||||
bool Report(u32 proxyID)
|
||||
{
|
||||
b3Shape* shape = (b3Shape*)broadPhase->GetUserData(proxyID);
|
||||
return listener->ReportShape(shape);
|
||||
|
Reference in New Issue
Block a user