|
@@ -242,13 +242,13 @@ void ContactConstraintManager::ManifoldCache::Prepare(uint inExpectedNumBodyPair
|
|
|
mCachedBodyPairs.SetNumBuckets(min(max(cMinBuckets, GetNextPowerOf2(inExpectedNumBodyPairs)), mCachedBodyPairs.GetMaxBuckets()));
|
|
|
}
|
|
|
|
|
|
-const ContactConstraintManager::MKeyValue *ContactConstraintManager::ManifoldCache::Find(const SubShapeIDPair &inKey, size_t inKeyHash) const
|
|
|
+const ContactConstraintManager::MKeyValue *ContactConstraintManager::ManifoldCache::Find(const SubShapeIDPair &inKey, uint64 inKeyHash) const
|
|
|
{
|
|
|
JPH_ASSERT(mIsFinalized);
|
|
|
return mCachedManifolds.Find(inKey, inKeyHash);
|
|
|
}
|
|
|
|
|
|
-ContactConstraintManager::MKeyValue *ContactConstraintManager::ManifoldCache::Create(ContactAllocator &ioContactAllocator, const SubShapeIDPair &inKey, size_t inKeyHash, int inNumContactPoints)
|
|
|
+ContactConstraintManager::MKeyValue *ContactConstraintManager::ManifoldCache::Create(ContactAllocator &ioContactAllocator, const SubShapeIDPair &inKey, uint64 inKeyHash, int inNumContactPoints)
|
|
|
{
|
|
|
JPH_ASSERT(!mIsFinalized);
|
|
|
MKeyValue *kv = mCachedManifolds.Create(ioContactAllocator, inKey, inKeyHash, CachedManifold::sGetRequiredExtraSize(inNumContactPoints));
|
|
@@ -262,7 +262,7 @@ ContactConstraintManager::MKeyValue *ContactConstraintManager::ManifoldCache::Cr
|
|
|
return kv;
|
|
|
}
|
|
|
|
|
|
-ContactConstraintManager::MKVAndCreated ContactConstraintManager::ManifoldCache::FindOrCreate(ContactAllocator &ioContactAllocator, const SubShapeIDPair &inKey, size_t inKeyHash, int inNumContactPoints)
|
|
|
+ContactConstraintManager::MKVAndCreated ContactConstraintManager::ManifoldCache::FindOrCreate(ContactAllocator &ioContactAllocator, const SubShapeIDPair &inKey, uint64 inKeyHash, int inNumContactPoints)
|
|
|
{
|
|
|
MKeyValue *kv = const_cast<MKeyValue *>(mCachedManifolds.Find(inKey, inKeyHash));
|
|
|
if (kv != nullptr)
|
|
@@ -283,13 +283,13 @@ const ContactConstraintManager::MKeyValue *ContactConstraintManager::ManifoldCac
|
|
|
return mCachedManifolds.FromHandle(inHandle);
|
|
|
}
|
|
|
|
|
|
-const ContactConstraintManager::BPKeyValue *ContactConstraintManager::ManifoldCache::Find(const BodyPair &inKey, size_t inKeyHash) const
|
|
|
+const ContactConstraintManager::BPKeyValue *ContactConstraintManager::ManifoldCache::Find(const BodyPair &inKey, uint64 inKeyHash) const
|
|
|
{
|
|
|
JPH_ASSERT(mIsFinalized);
|
|
|
return mCachedBodyPairs.Find(inKey, inKeyHash);
|
|
|
}
|
|
|
|
|
|
-ContactConstraintManager::BPKeyValue *ContactConstraintManager::ManifoldCache::Create(ContactAllocator &ioContactAllocator, const BodyPair &inKey, size_t inKeyHash)
|
|
|
+ContactConstraintManager::BPKeyValue *ContactConstraintManager::ManifoldCache::Create(ContactAllocator &ioContactAllocator, const BodyPair &inKey, uint64 inKeyHash)
|
|
|
{
|
|
|
JPH_ASSERT(!mIsFinalized);
|
|
|
BPKeyValue *kv = mCachedBodyPairs.Create(ioContactAllocator, inKey, inKeyHash, 0);
|
|
@@ -463,7 +463,7 @@ bool ContactConstraintManager::ManifoldCache::RestoreState(const ManifoldCache &
|
|
|
inStream.Read(body_pair_key);
|
|
|
|
|
|
// Create new entry for this body pair
|
|
|
- size_t body_pair_hash = BodyPairHash {} (body_pair_key);
|
|
|
+ uint64 body_pair_hash = body_pair_key.GetHash();
|
|
|
BPKeyValue *bp_kv = Create(contact_allocator, body_pair_key, body_pair_hash);
|
|
|
if (bp_kv == nullptr)
|
|
|
{
|
|
@@ -497,7 +497,7 @@ bool ContactConstraintManager::ManifoldCache::RestoreState(const ManifoldCache &
|
|
|
if (inStream.IsValidating() && j < all_m.size())
|
|
|
sub_shape_key = all_m[j]->GetKey();
|
|
|
inStream.Read(sub_shape_key);
|
|
|
- size_t sub_shape_key_hash = std::hash<SubShapeIDPair> {} (sub_shape_key);
|
|
|
+ uint64 sub_shape_key_hash = sub_shape_key.GetHash();
|
|
|
|
|
|
// Read amount of contact points
|
|
|
uint16 num_contact_points;
|
|
@@ -548,7 +548,7 @@ bool ContactConstraintManager::ManifoldCache::RestoreState(const ManifoldCache &
|
|
|
if (inStream.IsValidating() && j < all_m.size())
|
|
|
sub_shape_key = all_m[j]->GetKey();
|
|
|
inStream.Read(sub_shape_key);
|
|
|
- size_t sub_shape_key_hash = std::hash<SubShapeIDPair> {} (sub_shape_key);
|
|
|
+ uint64 sub_shape_key_hash = sub_shape_key.GetHash();
|
|
|
|
|
|
// Create CCD manifold
|
|
|
MKeyValue *m_kv = Create(contact_allocator, sub_shape_key, sub_shape_key_hash, 0);
|
|
@@ -694,7 +694,7 @@ void ContactConstraintManager::GetContactsFromCache(ContactAllocator &ioContactA
|
|
|
|
|
|
// Find the cached body pair
|
|
|
BodyPair body_pair_key(body1->GetID(), body2->GetID());
|
|
|
- size_t body_pair_hash = BodyPairHash {} (body_pair_key);
|
|
|
+ uint64 body_pair_hash = body_pair_key.GetHash();
|
|
|
const ManifoldCache &read_cache = mCache[mCacheWriteIdx ^ 1];
|
|
|
const BPKeyValue *kv = read_cache.Find(body_pair_key, body_pair_hash);
|
|
|
if (kv == nullptr)
|
|
@@ -761,7 +761,7 @@ void ContactConstraintManager::GetContactsFromCache(ContactAllocator &ioContactA
|
|
|
JPH_ASSERT(input_cm.mNumContactPoints > 0); // There should be contact points in this manifold!
|
|
|
|
|
|
// Create room for manifold in write buffer and copy data
|
|
|
- size_t input_hash = std::hash<SubShapeIDPair> {} (input_key);
|
|
|
+ uint64 input_hash = input_key.GetHash();
|
|
|
MKeyValue *output_kv = write_cache.Create(ioContactAllocator, input_key, input_hash, input_cm.mNumContactPoints);
|
|
|
if (output_kv == nullptr)
|
|
|
break; // Out of cache space
|
|
@@ -881,7 +881,7 @@ ContactConstraintManager::BodyPairHandle ContactConstraintManager::AddBodyPair(C
|
|
|
|
|
|
// Add an entry
|
|
|
BodyPair body_pair_key(body1->GetID(), body2->GetID());
|
|
|
- size_t body_pair_hash = BodyPairHash {} (body_pair_key);
|
|
|
+ uint64 body_pair_hash = body_pair_key.GetHash();
|
|
|
BPKeyValue *body_pair_kv = mCache[mCacheWriteIdx].Create(ioContactAllocator, body_pair_key, body_pair_hash);
|
|
|
if (body_pair_kv == nullptr)
|
|
|
return nullptr; // Out of cache space
|
|
@@ -909,7 +909,7 @@ bool ContactConstraintManager::TemplatedAddContactConstraint(ContactAllocator &i
|
|
|
{
|
|
|
// Calculate hash
|
|
|
SubShapeIDPair key { inBody1.GetID(), inManifold.mSubShapeID1, inBody2.GetID(), inManifold.mSubShapeID2 };
|
|
|
- size_t key_hash = std::hash<SubShapeIDPair> {} (key);
|
|
|
+ uint64 key_hash = key.GetHash();
|
|
|
|
|
|
// Determine number of contact points
|
|
|
int num_contact_points = (int)inManifold.mWorldSpaceContactPointsOn1.size();
|
|
@@ -1212,7 +1212,7 @@ void ContactConstraintManager::OnCCDContactAdded(ContactAllocator &ioContactAllo
|
|
|
|
|
|
// Calculate hash
|
|
|
SubShapeIDPair key { body1->GetID(), manifold->mSubShapeID1, body2->GetID(), manifold->mSubShapeID2 };
|
|
|
- size_t key_hash = std::hash<SubShapeIDPair> {} (key);
|
|
|
+ uint64 key_hash = key.GetHash();
|
|
|
|
|
|
// Check if we already created this contact this physics update
|
|
|
ManifoldCache &write_cache = mCache[mCacheWriteIdx];
|
|
@@ -1263,8 +1263,21 @@ void ContactConstraintManager::SortContacts(uint32 *inConstraintIdxBegin, uint32
|
|
|
sort(inConstraintIdxBegin, inConstraintIdxEnd, [this](uint32 inLHS, uint32 inRHS) {
|
|
|
const ContactConstraint &lhs = mConstraints[inLHS];
|
|
|
const ContactConstraint &rhs = mConstraints[inRHS];
|
|
|
- JPH_ASSERT(lhs.mSortKey != rhs.mSortKey, "Hash collision, ordering will be inconsistent");
|
|
|
- return lhs.mSortKey < rhs.mSortKey;
|
|
|
+
|
|
|
+ // Most of the time the sort key will be different so we sort on that
|
|
|
+ if (lhs.mSortKey != rhs.mSortKey)
|
|
|
+ return lhs.mSortKey < rhs.mSortKey;
|
|
|
+
|
|
|
+ // If they're equal we use the IDs of body 1 to order
|
|
|
+ if (lhs.mBody1 != rhs.mBody1)
|
|
|
+ return lhs.mBody1->GetID() < rhs.mBody1->GetID();
|
|
|
+
|
|
|
+ // If they're still equal we use the IDs of body 2 to order
|
|
|
+ if (lhs.mBody2 != rhs.mBody2)
|
|
|
+ return lhs.mBody2->GetID() < rhs.mBody2->GetID();
|
|
|
+
|
|
|
+ JPH_ASSERT(false, "Hash collision, ordering will be inconsistent");
|
|
|
+ return false;
|
|
|
});
|
|
|
}
|
|
|
|