From 387495589faf38228e8488ed61b60f5a1e78a89d Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 28 Oct 2024 23:41:13 +0100 Subject: [PATCH] Added test and fixed create-all. --- src/Arch.Tests/WorldTest.cs | 56 ++++++++++++++++++++++++++ src/Arch/Core/Archetype.cs | 2 +- src/Arch/Templates/World.CreateBulk.tt | 2 +- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/Arch.Tests/WorldTest.cs b/src/Arch.Tests/WorldTest.cs index 130c7b9..d662b99 100644 --- a/src/Arch.Tests/WorldTest.cs +++ b/src/Arch.Tests/WorldTest.cs @@ -73,6 +73,62 @@ public void Create() True(world.IsAlive(entity)); } + /// + /// Checks if the creates correctly. + /// + [Test] + public void CreateAll() + { + var size = 1024; + using var world = World.Create(); + + var transform = new Transform { X = size, Y = size }; + var rotation = new Rotation{ X = size, Y = size, W = size, Z = size}; + world.Create(size, transform , rotation); + + var queryDesc = new QueryDescription().WithAll(); + world.Query(queryDesc, (Entity entity, ref Transform entityTransform, ref Rotation entityRotation) => + { + That(world.IsAlive(entity)); + That(world.Version(entity), Is.EqualTo(1)); + That(world.HasRange(entity, _entityGroup)); + + That(world.Get(entity).X, Is.EqualTo(size)); + That(world.Get(entity).X, Is.EqualTo(size)); + That(entityTransform.X, Is.EqualTo(size)); + That(entityRotation.X, Is.EqualTo(size)); + }); + + That(world.Size, Is.EqualTo(size)); + That(world.Capacity, Is.EqualTo(world.Archetypes[0].EntityCapacity)); + } + + /// + /// Checks if the creates correctly. + /// + [Test] + public void CreateAll_By_Signature() + { + var size = 1024; + using var world = World.Create(); + + var createdEntities = (Span)stackalloc Entity[size]; + world.Create(createdEntities, _entityGroup, size); + + var index = 0; + foreach (var entity in createdEntities) + { + That(entity.Id, Is.EqualTo(index)); + That(world.IsAlive(entity)); + That(world.Version(entity), Is.EqualTo(1)); + That(world.HasRange(entity, _entityGroup)); + index++; + } + + That(world.Size, Is.EqualTo(size)); + That(world.Capacity, Is.EqualTo(world.Archetypes[0].EntityCapacity)); + } + /// /// Checks if the destroys correctly. /// diff --git a/src/Arch/Core/Archetype.cs b/src/Arch/Core/Archetype.cs index a9f0306..95f4523 100644 --- a/src/Arch/Core/Archetype.cs +++ b/src/Arch/Core/Archetype.cs @@ -802,7 +802,7 @@ public static int GetChunkCapacityFor(int entitiesPerChunk, int entityAmount) internal static int GetNextSlots(Archetype archetype, Span slots, int amount) { var next = 0; - for (var chunkIndex = archetype.ChunkCount-1; chunkIndex < archetype.ChunkCapacity && amount > 0; chunkIndex++) + for (var chunkIndex = archetype.Count; chunkIndex < archetype.ChunkCapacity && amount > 0; chunkIndex++) { ref var chunk = ref archetype.GetChunk(chunkIndex); var chunkSize = chunk.Count; diff --git a/src/Arch/Templates/World.CreateBulk.tt b/src/Arch/Templates/World.CreateBulk.tt index b162777..bf42c08 100644 --- a/src/Arch/Templates/World.CreateBulk.tt +++ b/src/Arch/Templates/World.CreateBulk.tt @@ -42,7 +42,7 @@ for (var index = 2; index < Amount; index++) // Fill entities var firstSlot = entityData[0].Slot; var lastSlot = entityData[amount - 1].Slot; - archetype.SetRange<<#= generics #>>(in firstSlot, in lastSlot, <#= inParameters #>); + archetype.SetRange<<#= generics #>>(in lastSlot, in firstSlot, <#= inParameters #>); // Add entities to entityinfo AddEntityData(entities, entityData, amount);