diff --git a/src/Arch.SourceGen/Fundamentals/Has.cs b/src/Arch.SourceGen/Fundamentals/Has.cs index ec39eabb..8f7a1327 100644 --- a/src/Arch.SourceGen/Fundamentals/Has.cs +++ b/src/Arch.SourceGen/Fundamentals/Has.cs @@ -31,7 +31,7 @@ public static StringBuilder AppendChunkHas(this StringBuilder sb, int amount) var ifs = new StringBuilder(); for (var index = 0; index <= amount; index++) { - ifs.AppendLine($"if (ComponentIdToArrayIndex[t{index}ComponentId] != 1) return false;"); + ifs.AppendLine($"if (ComponentIdToArrayIndex[t{index}ComponentId] == -1) return false;"); } var template = diff --git a/src/Arch.Tests/ChunkTest.cs b/src/Arch.Tests/ChunkTest.cs index 13f511a2..8c1490a0 100644 --- a/src/Arch.Tests/ChunkTest.cs +++ b/src/Arch.Tests/ChunkTest.cs @@ -116,4 +116,28 @@ public void ChunkRemoveAndSetAgain() That(_chunk.Entities[0].Id, Is.EqualTo(2)); // Needs to be 1, because it will be the last one getting removed and being moved to that position That(_chunk.Entities[1].Id, Is.EqualTo(1)); // Needs to be 1, because it will be the last one getting removed and being moved to that position } + + /// + /// Checks if chunk has a component. + /// + [Test] + public void ChunkHas() + { + _chunk = new Chunk(1000, _types); + + for (var index = 0; index < _chunk.Capacity; index++) + { + var entity = new Entity(index, 0); + _chunk.Add(entity); + + var t = new Transform(); + var r = new Rotation(); + _chunk.Set(index, t); + _chunk.Set(index, r); + } + + That(_chunk.Has(), Is.True); + That(_chunk.Has(), Is.False); + That(_chunk.Has(), Is.True); + } } diff --git a/src/Arch/Core/Chunk.cs b/src/Arch/Core/Chunk.cs index 3cf8890f..ce0b2621 100644 --- a/src/Arch/Core/Chunk.cs +++ b/src/Arch/Core/Chunk.cs @@ -116,7 +116,7 @@ public void Set(int index, in T cmp) public bool Has() { var id = Component.ComponentType.Id; - return id < ComponentIdToArrayIndex.Length && ComponentIdToArrayIndex[id] != 1; + return id < ComponentIdToArrayIndex.Length && ComponentIdToArrayIndex[id] != -1; } ///