mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Co-authored-by: DrSmugleaf <drsmugleaf@gmail.com> Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
49 lines
932 B
C#
49 lines
932 B
C#
using Arch.Core;
|
|
|
|
namespace Robust.Shared.GameObjects;
|
|
|
|
internal struct EntityIterator
|
|
{
|
|
private readonly Chunk _chunk;
|
|
|
|
internal EntityIterator(in Chunk chunk)
|
|
{
|
|
_chunk = chunk;
|
|
}
|
|
|
|
public EntityEnumerator GetEnumerator()
|
|
{
|
|
return new EntityEnumerator(_chunk);
|
|
}
|
|
}
|
|
|
|
internal struct EntityEnumerator
|
|
{
|
|
private readonly Chunk _chunk;
|
|
private int _entityIndex;
|
|
public Entity Current { get; private set; }
|
|
|
|
public EntityEnumerator(in Chunk chunk)
|
|
{
|
|
_chunk = chunk;
|
|
}
|
|
|
|
public bool MoveNext()
|
|
{
|
|
if (_entityIndex >= _chunk.Entities.Length)
|
|
return false;
|
|
|
|
Current = _chunk.Entities[_entityIndex];
|
|
_entityIndex++;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
internal static partial class QueryExtensions
|
|
{
|
|
internal static EntityIterator ChunkIterator(this in Chunk chunk)
|
|
{
|
|
return new EntityIterator(chunk);
|
|
}
|
|
}
|