diff --git a/fennecs.tests/ArchetypeTests.cs b/fennecs.tests/ArchetypeTests.cs index 3657e618..58fccfea 100644 --- a/fennecs.tests/ArchetypeTests.cs +++ b/fennecs.tests/ArchetypeTests.cs @@ -278,4 +278,18 @@ public void IsComparable_Same_As_Signature() Assert.True(table1.CompareTo(null) == table1.Signature.CompareTo(default)); } + [Fact] + public void Has_Signature_HashCode() + { + using var world = new World(); + var entity1 = world.Spawn().Add("foo").Add(123).Add(17.0f).Id; + var entity2 = world.Spawn().Add(123).Add(17.0f).Id; + + var table1 = world.GetEntityMeta(entity1).Archetype; + var table2 = world.GetEntityMeta(entity2).Archetype; + + Assert.True(table1.GetHashCode() == table1.Signature.GetHashCode()); + Assert.True(table2.GetHashCode() == table2.Signature.GetHashCode()); + Assert.NotEqual(table1.GetHashCode(), table2.GetHashCode()); + } } \ No newline at end of file diff --git a/fennecs.tests/Entity/EntityTests.cs b/fennecs.tests/Entity/EntityTests.cs index 59f1b37c..413ef9c2 100644 --- a/fennecs.tests/Entity/EntityTests.cs +++ b/fennecs.tests/Entity/EntityTests.cs @@ -432,5 +432,21 @@ public void Can_Get_Link_Objects_via_Get() Assert.Contains(helloWorld2, strings); Assert.Equal(2, strings.Length); } + + + [Fact] + public void Truthy() + { + using var world = new World(); + + var entity = world.Spawn(); + Assert.True(entity); + + entity.Despawn(); + Assert.False(entity); + + entity = default; + Assert.False(entity); + } } \ No newline at end of file diff --git a/fennecs.tests/ExpressionTests.cs b/fennecs.tests/ExpressionTests.cs index 6ab41027..ab521982 100644 --- a/fennecs.tests/ExpressionTests.cs +++ b/fennecs.tests/ExpressionTests.cs @@ -270,4 +270,23 @@ public static void SIMDsizeIsAccurate() var comp3 = Comp.Plain; Assert.Equal(0, comp3.SIMDsize); } + + [Fact] + public static void Comp_Virtual() + { + var comp = Comp.Virtual(typeof(int), Match.Any); + var test = Comp.Matching(Match.Any); + + Assert.Equal(comp, test); + Assert.Equal(test, comp); + } + + [Fact] + public static void Relate_Entity_Operator() + { + using var world = new World(); + var entity = world.Spawn(); + var to = Relate.To(entity); + Assert.Equal(to, entity); + } } diff --git a/fennecs.tests/Stream/Stream.1.Tests.cs b/fennecs.tests/Stream/Stream.1.Tests.cs index 39105d66..ae54483d 100644 --- a/fennecs.tests/Stream/Stream.1.Tests.cs +++ b/fennecs.tests/Stream/Stream.1.Tests.cs @@ -243,4 +243,24 @@ public void Streams_Can_Despawn() Assert.Empty(world.Query().Compile()); } + + [Fact] + public void MatchAll_Overloads() + { + using var world = new World(); + world.Spawn().Add("69").Add(420).Add(1.0f).Add(new object()).Add('a'); + + var query = world.All; + var stream1 = query.Stream(Match.Any); + var stream2 = query.Stream(Match.Any); + var stream3 = query.Stream(Match.Any); + var stream4 = query.Stream(Match.Any); + var stream5 = query.Stream(Match.Any); + + Assert.Single(stream1); + Assert.Single(stream2); + Assert.Single(stream3); + Assert.Single(stream4); + Assert.Single(stream5); + } } diff --git a/fennecs.tests/Stream/World.Stream.Tests.cs b/fennecs.tests/Stream/World.Stream.Tests.cs index bcfabf69..95f9c4f2 100644 --- a/fennecs.tests/Stream/World.Stream.Tests.cs +++ b/fennecs.tests/Stream/World.Stream.Tests.cs @@ -91,4 +91,94 @@ public void Stream_5() Assert.NotEmpty(world); Assert.NotEmpty(stream); } + + [Fact] + public void Stream_1Match() + { + using var world = new World(); + var stream = world.Stream(Match.Any); + + Assert.Empty(world); + Assert.Empty(stream); + + Assert.Equal(0, stream.Count); + + world.Spawn().Add("a"); + Assert.Equal(1, stream.Count); + + Assert.NotEmpty(world); + Assert.NotEmpty(stream); + } + + [Fact] + public void Stream_2Match() + { + using var world = new World(); + var stream = world.Stream(Match.Any); + + Assert.Empty(world); + Assert.Empty(stream); + + Assert.Equal(0, stream.Count); + + world.Spawn().Add("a").Add(1); + Assert.Equal(1, stream.Count); + + Assert.NotEmpty(world); + Assert.NotEmpty(stream); + } + + [Fact] + public void Stream_3Match() + { + using var world = new World(); + var stream = world.Stream(Match.Any); + + Assert.Empty(world); + Assert.Empty(stream); + + Assert.Equal(0, stream.Count); + + world.Spawn().Add("a").Add(1).Add(1.0f); + Assert.Equal(1, stream.Count); + + Assert.NotEmpty(world); + Assert.NotEmpty(stream); + } + + [Fact] + public void Stream_4Match() + { + using var world = new World(); + var stream = world.Stream(Match.Any); + + Assert.Empty(world); + Assert.Empty(stream); + + Assert.Equal(0, stream.Count); + + world.Spawn().Add("a").Add(1).Add(1.0f).Add(new object()); + Assert.Equal(1, stream.Count); + + Assert.NotEmpty(world); + Assert.NotEmpty(stream); + } + + [Fact] + public void Stream_5Match() + { + using var world = new World(); + var stream = world.Stream(Match.Any); + + Assert.Empty(world); + Assert.Empty(stream); + + Assert.Equal(0, stream.Count); + + world.Spawn().Add("a").Add(1).Add(1.0f).Add(new object()).Add('a'); + Assert.Equal(1, stream.Count); + + Assert.NotEmpty(world); + Assert.NotEmpty(stream); + } } diff --git a/fennecs/Query.cs b/fennecs/Query.cs index 96be76f7..6ae907f9 100644 --- a/fennecs/Query.cs +++ b/fennecs/Query.cs @@ -94,7 +94,7 @@ internal void ForgetArchetype(Archetype archetype) /// This query's currently matched Archetypes. /// (affected by filters) /// - internal readonly SortedSet Archetypes = []; + internal readonly SortedSet Archetypes; /// /// The World this Query is associated with. diff --git a/fennecs/World.Streamable.cs b/fennecs/World.Streamable.cs index 1228add1..66bcc60e 100644 --- a/fennecs/World.Streamable.cs +++ b/fennecs/World.Streamable.cs @@ -8,24 +8,24 @@ public partial class World : Streamable /// Compile an internal Query specifically for the requested Stream Types, and return a Stream View for it. /// - public Stream Stream(Match match0, Match match1) where C0 : notnull where C1 : notnull + public Stream Stream(Match match0, Match match1) where C0 : notnull where C1 : notnull => Query(match0, match1).Stream(); /// Compile an internal Query specifically for the requested Stream Types, and return a Stream View for it. /// public Stream Stream(Match matchAll = default) where C0 : notnull where C1 : notnull - => Query(matchAll).Stream(); + => Stream(matchAll, matchAll); /// Compile an internal Query specifically for the requested Stream Types, and return a Stream View for it. /// public Stream Stream(Match match0, Match match1, Match match2) where C0 : notnull where C1 : notnull where C2 : notnull - => Query(match0, match1, match2).Stream(); + => Query(match0, match1, match2).Stream(); /// Compile an internal Query specifically for the requested Stream Types, and return a Stream View for it. /// public Stream Stream(Match matchAll = default) where C0 : notnull where C1 : notnull where C2 : notnull - => Query(matchAll).Stream(); - + => Stream(matchAll, matchAll, matchAll); + /// Compile an internal Query specifically for the requested Stream Types, and return a Stream View for it. /// public Stream Stream(Match match0, Match match1, Match match2, Match match3) where C0 : notnull where C1 : notnull where C2 : notnull where C3 : notnull @@ -34,15 +34,16 @@ public Stream Stream(Match match0, Match match1, /// Compile an internal Query specifically for the requested Stream Types, and return a Stream View for it. /// public Stream Stream(Match matchAll = default) where C0 : notnull where C1 : notnull where C2 : notnull where C3 : notnull - => Query(matchAll).Stream(); - + => Stream(matchAll, matchAll, matchAll, matchAll); + /// Compile an internal Query specifically for the requested Stream Types, and return a Stream View for it. /// - public Stream Stream(Match match0, Match match1, Match match2, Match match3, Match match4) where C0 : notnull where C1 : notnull where C2 : notnull where C3 : notnull where C4 : notnull + public Stream Stream(Match match0, Match match1, Match match2, Match match3, Match match4) + where C0 : notnull where C1 : notnull where C2 : notnull where C3 : notnull where C4 : notnull => Query(match0, match1, match2, match3, match4).Stream(); - + /// Compile an internal Query specifically for the requested Stream Types, and return a Stream View for it. /// public Stream Stream(Match matchAll = default) where C0 : notnull where C1 : notnull where C2 : notnull where C3 : notnull where C4 : notnull - => Query(matchAll).Stream(); + => Stream(matchAll, matchAll, matchAll, matchAll, matchAll); }