Skip to content

Commit

Permalink
Fixed tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
genaray committed Oct 17, 2024
1 parent 742ca00 commit 24d8687
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Arch.Tests/WorldTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public void TrimExcess()
var archetype = world.Archetypes[0];
That(world.Size, Is.EqualTo(1));
That(world.Capacity, Is.EqualTo(archetype.EntitiesPerChunk));
That(archetype.ChunkCount, Is.EqualTo(1));
That(archetype.ChunkCount, Is.EqualTo(0));
That(archetype.ChunkCapacity, Is.EqualTo(1));

// Recycled ids must be trimmed too so that the newest created entity is not out of bounds!
Expand Down
6 changes: 4 additions & 2 deletions src/Arch/Core/Archetype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -480,18 +480,19 @@ public void AddAll(Span<Entity> entities, int amount)
EnsureEntityCapacity(EntityCount + amount);

var created = 0;
for(var index = ChunkCount; index < ChunkCapacity && created < amount; index++)
for(var index = Count; index < ChunkCapacity && created < amount; index++)
{
ref var chunk = ref GetChunk(index);
var fillAmount = Math.Min(chunk.Buffer, amount - created);

Chunk.Copy(ref entities, created, ref chunk, chunk.Count, fillAmount);
chunk.Count += fillAmount;

Count = chunk.IsFull ? ChunkCount + 1 : ChunkCount;
Count = chunk.IsFull ? Count + 1 : Count;
created += fillAmount;
}

Count--;
EntityCount += amount;
}

Expand Down Expand Up @@ -747,6 +748,7 @@ internal void EnsureEntityCapacity(int newCapacity)
/// </summary>
internal void TrimExcess()
{
Chunks.Count = Count; // By setting the Count we will assure that unnecessary chunks are trimmed.
Chunks.TrimExcess();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Arch/Core/Chunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public Chunks(int capacity = 1)

public Array<Chunk> Items { get; set; }
public int Count { get; set; }
public int Capacity { get; set; }
public int Capacity { get; private set; }

public void Add(in Chunk chunk)
{
Debug.Assert(Count+1 <= Capacity, "Capacity exceeded.");
Debug.Assert(Count + 1 <= Capacity, "Capacity exceeded.");
Items[Count++] = chunk;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Arch/Core/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public void TrimExcess()
}

archetype.TrimExcess();
Capacity += archetype.ChunkCount * archetype.EntitiesPerChunk; // Since always one chunk always exists.
Capacity += archetype.EntityCapacity;
}

// Traverse recycled ids and remove all that are higher than the current capacity.
Expand Down

0 comments on commit 24d8687

Please sign in to comment.