1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-29 16:16:38 +00:00

Jolt: Update to 5.3.0

This commit is contained in:
Mikael Hermansson
2025-03-21 17:17:55 +01:00
parent 6810fc05e6
commit 5d00161040
109 changed files with 2238 additions and 1242 deletions

View File

@@ -249,9 +249,14 @@ void ContactConstraintManager::CachedBodyPair::RestoreState(StateRecorder &inStr
void ContactConstraintManager::ManifoldCache::Init(uint inMaxBodyPairs, uint inMaxContactConstraints, uint inCachedManifoldsSize)
{
mAllocator.Init(inMaxBodyPairs * sizeof(BodyPairMap::KeyValue) + inCachedManifoldsSize);
uint max_body_pairs = min(inMaxBodyPairs, cMaxBodyPairsLimit);
JPH_ASSERT(max_body_pairs == inMaxBodyPairs, "Cannot support this many body pairs!");
JPH_ASSERT(inMaxContactConstraints <= cMaxContactConstraintsLimit); // Should have been enforced by caller
mAllocator.Init(uint(min(uint64(max_body_pairs) * sizeof(BodyPairMap::KeyValue) + inCachedManifoldsSize, uint64(~uint(0)))));
mCachedManifolds.Init(GetNextPowerOf2(inMaxContactConstraints));
mCachedBodyPairs.Init(GetNextPowerOf2(inMaxBodyPairs));
mCachedBodyPairs.Init(GetNextPowerOf2(max_body_pairs));
}
void ContactConstraintManager::ManifoldCache::Clear()
@@ -676,14 +681,18 @@ ContactConstraintManager::~ContactConstraintManager()
void ContactConstraintManager::Init(uint inMaxBodyPairs, uint inMaxContactConstraints)
{
mMaxConstraints = inMaxContactConstraints;
// Limit the number of constraints so that the allocation size fits in an unsigned integer
mMaxConstraints = min(inMaxContactConstraints, cMaxContactConstraintsLimit);
JPH_ASSERT(mMaxConstraints == inMaxContactConstraints, "Cannot support this many contact constraints!");
// Calculate worst case cache usage
uint cached_manifolds_size = inMaxContactConstraints * (sizeof(CachedManifold) + (MaxContactPoints - 1) * sizeof(CachedContactPoint));
constexpr uint cMaxManifoldSizePerConstraint = sizeof(CachedManifold) + (MaxContactPoints - 1) * sizeof(CachedContactPoint);
static_assert(cMaxManifoldSizePerConstraint < sizeof(ContactConstraint)); // If not true, then the next line can overflow
uint cached_manifolds_size = mMaxConstraints * cMaxManifoldSizePerConstraint;
// Init the caches
mCache[0].Init(inMaxBodyPairs, inMaxContactConstraints, cached_manifolds_size);
mCache[1].Init(inMaxBodyPairs, inMaxContactConstraints, cached_manifolds_size);
mCache[0].Init(inMaxBodyPairs, mMaxConstraints, cached_manifolds_size);
mCache[1].Init(inMaxBodyPairs, mMaxConstraints, cached_manifolds_size);
}
void ContactConstraintManager::PrepareConstraintBuffer(PhysicsUpdateContext *inContext)