Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove gc pressure in debug build #183

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 11 additions & 23 deletions src/Jitter2/World.Step.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,6 @@ private unsafe void IterateSmallConstraintsCallback(Parallel.Batch batch)
ref RigidBodyData b1 = ref constraint.Body1.Data;
ref RigidBodyData b2 = ref constraint.Body2.Data;

AssertConstraint(ref b1, ref b2);

if (constraint.Iterate == null) continue;

LockTwoBody(ref b1, ref b2);
Expand Down Expand Up @@ -371,8 +369,6 @@ private unsafe void IterateConstraintsCallback(Parallel.Batch batch)
ref RigidBodyData b1 = ref constraint.Body1.Data;
ref RigidBodyData b2 = ref constraint.Body2.Data;

AssertConstraint(ref b1, ref b2);

if (constraint.Iterate == null) continue;

LockTwoBody(ref b1, ref b2);
Expand All @@ -391,8 +387,6 @@ private void IterateContactsCallback(Parallel.Batch batch)
ref RigidBodyData b1 = ref c.Body1.Data;
ref RigidBodyData b2 = ref c.Body2.Data;

AssertConstraint(ref b1, ref b2);

LockTwoBody(ref b1, ref b2);
c.Iterate();
UnlockTwoBody(ref b1, ref b2);
Expand All @@ -418,23 +412,6 @@ private void DetectCollisionsCallback(Parallel.Batch batch)
}
}

private void AssertConstraint(ref RigidBodyData rb1, ref RigidBodyData rb2)
{
Debug.Assert(!(rb1.IsStaticOrInactive && rb2.IsStaticOrInactive));

if (rb1.IsStatic)
{
Debug.Assert(rb1.InverseMass == 0.0f);
Debug.Assert(rb1.InverseInertiaWorld.Equals(JMatrix.Zero));
}

if (rb2.IsStatic)
{
Debug.Assert(rb2.InverseMass == 0.0f);
Debug.Assert(rb2.InverseInertiaWorld.Equals(JMatrix.Zero));
}
}

private void AssertNullBody()
{
ref RigidBodyData rigidBody = ref NullBody.Data;
Expand All @@ -458,6 +435,17 @@ private void ForeachActiveShape(bool multiThread)

private void ForeachActiveBody(bool multiThread)
{
#if DEBUG
foreach (var body in bodies)
{
if (body.IsStatic)
{
System.Diagnostics.Debug.Assert(MathHelper.UnsafeIsZero(body.Data.InverseInertiaWorld));
System.Diagnostics.Debug.Assert(body.Data.InverseMass == 0.0f);
}
}
#endif

if (multiThread)
{
bodies.ParallelForBatch(256, updateBodies);
Expand Down
Loading