Skip to content

Commit 24870b0

Browse files
committed
Stream.Filtered now uses Archetype.MatchSignature instead of Archetype.Signature. Fixes #37
1 parent 37ae5ab commit 24870b0

File tree

5 files changed

+62
-4
lines changed

5 files changed

+62
-4
lines changed

fennecs.tests/Query/QueryFilterTests.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,64 @@ public void Exclude_ShouldNarrowDownResults()
5959
//Ensure count is reduced
6060
Assert.Single(results);
6161
}
62+
63+
[Fact]
64+
public void Exclude_ShouldNarrowDownResults_EntityAny()
65+
{
66+
using var world = new World();
67+
68+
// Arrange
69+
var target = world.Spawn();
70+
var entity1 = world.Spawn().Add(new ComponentA());
71+
var entity2 = world.Spawn().Add(new ComponentA()).Add(new ComponentB(), target);
72+
73+
var stream = world.Query<ComponentA>().Stream();
74+
75+
// Act
76+
var filtered = stream with
77+
{
78+
Exclude = [Comp<ComponentB>.Matching(Match.Entity)]
79+
};
80+
81+
var results = new List<Entity>();
82+
filtered.For((in Entity entity, ref ComponentA _) => results.Add(entity));
83+
84+
// Assert
85+
Assert.Contains(entity1, results);
86+
Assert.DoesNotContain(entity2, results);
87+
88+
//Ensure count is reduced
89+
Assert.Single(results);
90+
}
91+
92+
[Fact]
93+
public void Exclude_ShouldNarrowDownResults_MatchAny()
94+
{
95+
using var world = new World();
96+
97+
// Arrange
98+
var target = world.Spawn();
99+
var entity1 = world.Spawn().Add(new ComponentA());
100+
var entity2 = world.Spawn().Add(new ComponentA()).Add(new ComponentB(), target);
101+
102+
var stream = world.Query<ComponentA>().Stream();
103+
104+
// Act
105+
var filtered = stream with
106+
{
107+
Exclude = [Comp<ComponentB>.Matching(Match.Any)]
108+
};
109+
110+
var results = new List<Entity>();
111+
filtered.For((in Entity entity, ref ComponentA _) => results.Add(entity));
112+
113+
// Assert
114+
Assert.Contains(entity1, results);
115+
Assert.DoesNotContain(entity2, results);
116+
117+
//Ensure count is reduced
118+
Assert.Single(results);
119+
}
62120
}
63121

64122

fennecs/Stream.1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public record Stream<C0>(Query Query, Match Match0) : IEnumerable<(Entity, C0)>,
2222
/// </summary>
2323
protected SortedSet<Archetype> Filtered => Subset.IsEmpty && Exclude.IsEmpty
2424
? Archetypes
25-
: new(Archetypes.Where(a => (Subset.IsEmpty || a.Signature.Matches(Subset)) && !a.Signature.Matches(Exclude)));
25+
: new(Archetypes.Where(a => (Subset.IsEmpty || a.MatchSignature.Matches(Subset)) && !a.MatchSignature.Matches(Exclude)));
2626

2727
/// <summary>
2828
/// Creates a builder for a Batch Operation on the Stream's underyling Query.

fennecs/expressions/Component.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public readonly record struct Comp<T>(Match match = default)
174174
internal int SIMDsize => Expression.SIMDsize;
175175

176176
/// <summary>
177-
/// Component Expression for a blittable type with a specific relation target (match expression).
177+
/// Component Expression for a type with a specific relation target (match expression).
178178
/// </summary>
179179
public static Comp<T> Matching(Match target) => new(target);
180180

fennecs/expressions/Signature.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace fennecs;
2222

2323
public bool Matches(IReadOnlySet<TypeExpression> types) => Overlaps(types);
2424

25-
internal bool Matches(IReadOnlySet<Comp> subset) => Overlaps(subset.Select(component => component.Expression).ToImmutableSortedSet());
25+
internal bool Matches(IReadOnlySet<Comp> subset) => Overlaps(subset.Select(component => component.Expression));
2626

2727
/// <summary>
2828
/// Creates a new <see cref="Signature"/> from the given values.

fennecs/fennecs.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<PackageId>fennecs</PackageId>
8-
<Version>0.5.15-beta</Version>
8+
<Version>0.5.16-beta</Version>
99
<Title>fennecs</Title>
1010
<Product>fennecs Entity-Component System</Product>
1111
<Authors>Moritz Voss, Aaron Winter</Authors>

0 commit comments

Comments
 (0)