Skip to content

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
genaray committed Oct 21, 2024
1 parent 4728be1 commit dc9b9c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions src/Arch.Tests/EnumeratorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,17 @@ public void QueryArchetypeEmptyEnumeration()
[Test]
public void QueryChunkEnumeration()
{
var counter = 0;
var counter = _world.CountEntities(in _description);
var chunkCounter = 0;

var query = _world.Query(in _description);
foreach (ref var chunk in query)
{
counter++;
counter -= chunk.Count;
chunkCounter++;
}

var archetype1ChunkCount = _world.Archetypes[0].ChunkCount;
var archetype2ChunkCount = _world.Archetypes[1].ChunkCount;
That(counter, Is.EqualTo(archetype1ChunkCount + archetype2ChunkCount));
That(counter, Is.EqualTo(0));
That(chunkCounter, Is.EqualTo(_world.Archetypes[0].ChunkCount + _world.Archetypes[1].ChunkCount));
}
}
8 changes: 4 additions & 4 deletions src/Arch/Core/Enumerators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public QueryChunkEnumerator(Span<Archetype> archetypes)
// Make it move once, otherwhise we can not check directly for Current.Size which results in bad behaviour
if (_archetypeEnumerator.MoveNext())
{
_index = _archetypeEnumerator.Current.ChunkCount;
_index = _archetypeEnumerator.Current.Count+1;
}
}

Expand All @@ -202,7 +202,7 @@ public bool MoveNext()
unchecked
{
// Decrease chunk till its zero, skip empty chunks -> otherwhise entity query might fail since it tries to acess that chunk
if (--_index >= 0 && Current.Count > 0)
if (--_index >= 0)
{
return true;
}
Expand All @@ -213,7 +213,7 @@ public bool MoveNext()
return false;
}

_index = _archetypeEnumerator.Current.ChunkCount-1;
_index = _archetypeEnumerator.Current.Count;
return true;
}
}
Expand All @@ -230,7 +230,7 @@ public void Reset()
// Make it move once, otherwhise we can not check directly for Current.Size which results in bad behaviour
if (_archetypeEnumerator.MoveNext())
{
_index = _archetypeEnumerator.Current.ChunkCount;
_index = _archetypeEnumerator.Current.Count + 1;
}
}

Expand Down

0 comments on commit dc9b9c6

Please sign in to comment.