Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
metalgearsloth committed Aug 24, 2024
1 parent f6e1ef7 commit 88ae4c0
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Robust.Shared/Physics/Systems/SharedPhysicsSystem.Contacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using System.Buffers;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using JetBrains.Annotations;
using Microsoft.Extensions.ObjectPool;
Expand Down Expand Up @@ -791,27 +792,32 @@ public int GetTouchingContacts(Entity<FixturesComponent?> entity, string? ignore
[Pure]
public ContactEnumerator GetContacts(Entity<FixturesComponent?> entity)
{
if (!_fixturesQuery.Resolve(entity.Owner, ref entity.Comp))
return ContactEnumerator.Empty;

_fixturesQuery.Resolve(entity.Owner, ref entity.Comp);
return new ContactEnumerator(entity.Comp);
}
}

public record struct ContactEnumerator
{
public static readonly ContactEnumerator Empty = new();
public static readonly ContactEnumerator Empty = new(null);

private Dictionary<string, Fixture>.ValueCollection.Enumerator _fixtureEnumerator;
private Dictionary<Fixture, Contact>.ValueCollection.Enumerator _contactEnumerator;

public ContactEnumerator(FixturesComponent fixtures)
public ContactEnumerator(FixturesComponent? fixtures)
{
if (fixtures == null || fixtures.Fixtures.Count == 0)
{
this = Empty;
return;
}

_fixtureEnumerator = fixtures.Fixtures.Values.GetEnumerator();
_fixtureEnumerator.MoveNext();
_contactEnumerator = _fixtureEnumerator.Current.Contacts.Values.GetEnumerator();
}

public bool MoveNext(out Contact? contact)
public bool MoveNext([NotNullWhen(true)] out Contact? contact)
{
if (!_contactEnumerator.MoveNext())
{
Expand All @@ -822,6 +828,7 @@ public bool MoveNext(out Contact? contact)
}

_contactEnumerator = _fixtureEnumerator.Current.Contacts.Values.GetEnumerator();
return MoveNext(out contact);
}

contact = _contactEnumerator.Current;
Expand Down

0 comments on commit 88ae4c0

Please sign in to comment.