Skip to content

Commit

Permalink
fix index chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
andreakarasho committed Mar 3, 2024
1 parent 7eb87a7 commit a648357
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Archetype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,17 @@ ComponentComparer comparer
public int Count => _count;
public readonly ImmutableArray<EcsComponent> Components;
internal Span<ArchetypeChunk> Chunks => _chunks.AsSpan(0, (_count + CHUNK_THRESHOLD - 1) / CHUNK_THRESHOLD);
internal int EmptyChunks => _chunks.Length - Chunks.Length;

[SkipLocalsInit]
internal ref ArchetypeChunk GetChunk(int index)
{
index /= CHUNK_THRESHOLD;

if (index >= _chunks.Length)
Array.Resize(ref _chunks, _chunks.Length * 2);

ref var chunk = ref _chunks[index / CHUNK_THRESHOLD];
ref var chunk = ref _chunks[index];
if (chunk.Components == null)
{
chunk.Entities = new EntityView[CHUNK_THRESHOLD];
Expand Down

0 comments on commit a648357

Please sign in to comment.