Repository: mlange-42/arche
Pull request #188 (2023-03-29 13:42:21)

Rename Mask.Exact to Mask.Exclusive
Makes the intent more clear.


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e4c76d5..96a760c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,7 +14,7 @@
 
 * Adds method `World.Reset()`, to allow for more efficient systematic simulations (#138)
 * Adds `World.Batch()` helper for performing optimized batch-creation and batch-removal of entities (#149)
-* Adds method `Mask.Exact()` to create a filter matching an exact component composition (#149)
+* Adds method `Mask.Exclusive()` to create a filter matching an exact component composition (#149, #188)
 * Generic mappers (`Map1`, ...) have methods `NewEntities`, `NewEntitiesWith` and `RemoveEntities` for batch operations (#151)
 * Batch-creation methods (ID-based and generic) have variants like `NewEntitiesQuery` that return a query over the created entities (#152)
 * Notification during batch-creation is delayed until the resp. query is closed (#157)
diff --git a/ecs/batch.go b/ecs/batch.go
index 82fa045..ce47be4 100644
--- a/ecs/batch.go
+++ b/ecs/batch.go
@@ -138,7 +138,7 @@ func (b *Batch) NewEntitiesWithQuery(count int, comps ...Component) Query {
 //
 //	world.Batch().NewEntities(10_000, posID, velID)
 //
-//	filter := All(posID, velID).Exact()
+//	filter := All(posID, velID).Exclusive()
 //	world.Batch().RemoveEntities(filter)
 func (b *Batch) RemoveEntities(filter Filter) int {
 	return b.world.removeEntities(filter)
diff --git a/ecs/bitmask.go b/ecs/bitmask.go
index 79cd8c5..ad45866 100644
--- a/ecs/bitmask.go
+++ b/ecs/bitmask.go
@@ -27,7 +27,7 @@ type Mask struct {
 // All creates a new Mask from a list of IDs.
 // Matches al entities that have the respective components, and potentially further components.
 //
-// See also [Mask.Without] and [Mask.Exact]
+// See also [Mask.Without] and [Mask.Exclusive]
 //
 // If any [ID] is bigger or equal [MaskTotalBits], it'll not be added to the mask.
 func All(ids ...ID) Mask {
@@ -61,7 +61,7 @@ func (b Mask) Without(comps ...ID) MaskFilter {
 	}
 }
 
-// Exact creates a [MaskFilter] which filters for exactly the mask's components.
+// Exclusive creates a [MaskFilter] which filters for exactly the mask's components.
 // Matches only entities that have exactly the given components, and no other.
 //
 // # Example
@@ -70,9 +70,9 @@ func (b Mask) Without(comps ...ID) MaskFilter {
 //	posID := ComponentID[Position](&world)
 //	velID := ComponentID[Velocity](&world)
 //
-//	filter := All(posID, velID).Exact()
+//	filter := All(posID, velID).Exclusive()
 //	query := world.Query(filter)
-func (b Mask) Exact() MaskFilter {
+func (b Mask) Exclusive() MaskFilter {
 	return MaskFilter{
 		Include: b,
 		Exclude: b.Not(),
diff --git a/examples/batch_ops/main.go b/examples/batch_ops/main.go
index 63c5495..773275f 100644
--- a/examples/batch_ops/main.go
+++ b/examples/batch_ops/main.go
@@ -48,8 +48,8 @@ func run(w *ecs.World) {
 	}
 
 	// Batch-remove all entities with exactly the given components.
-	filterExact := ecs.All(posID, velID).Exact()
-	w.Batch().RemoveEntities(&filterExact)
+	filterExcl := ecs.All(posID, velID).Exclusive()
+	w.Batch().RemoveEntities(&filterExcl)
 
 	// Batch-remove all entities with the given components (and potentially further components).
 	filter := ecs.All(posID, velID)
diff --git a/generic/generate/map.go.txt b/generic/generate/map.go.txt
index d46dbbd..93359a6 100644
--- a/generic/generate/map.go.txt
+++ b/generic/generate/map.go.txt
@@ -130,9 +130,9 @@ func (m *Map{{ .Index }}{{ .Types }}) Remove(entity ecs.Entity) {
 // Returns the number of removed entities.
 //
 // See also [ecs.World.NewEntityWith].
-func (m *Map{{ .Index }}{{ .Types }}) RemoveEntities(exact bool) int {
-	if exact {
-		filter := m.mask.Exact()
+func (m *Map{{ .Index }}{{ .Types }}) RemoveEntities(exclusive bool) int {
+	if exclusive {
+		filter := m.mask.Exclusive()
 		return m.world.Batch().RemoveEntities(&filter)
 	}
 	return m.world.Batch().RemoveEntities(m.mask)
diff --git a/generic/map_generated.go b/generic/map_generated.go
index 92e3141..0d8d4aa 100644
--- a/generic/map_generated.go
+++ b/generic/map_generated.go
@@ -134,9 +134,9 @@ func (m *Map1[A]) Remove(entity ecs.Entity) {
 // Returns the number of removed entities.
 //
 // See also [ecs.World.NewEntityWith].
-func (m *Map1[A]) RemoveEntities(exact bool) int {
-	if exact {
-		filter := m.mask.Exact()
+func (m *Map1[A]) RemoveEntities(exclusive bool) int {
+	if exclusive {
+		filter := m.mask.Exclusive()
 		return m.world.Batch().RemoveEntities(&filter)
 	}
 	return m.world.Batch().RemoveEntities(m.mask)
@@ -281,9 +281,9 @@ func (m *Map2[A, B]) Remove(entity ecs.Entity) {
 // Returns the number of removed entities.
 //
 // See also [ecs.World.NewEntityWith].
-func (m *Map2[A, B]) RemoveEntities(exact bool) int {
-	if exact {
-		filter := m.mask.Exact()
+func (m *Map2[A, B]) RemoveEntities(exclusive bool) int {
+	if exclusive {
+		filter := m.mask.Exclusive()
 		return m.world.Batch().RemoveEntities(&filter)
 	}
 	return m.world.Batch().RemoveEntities(m.mask)
@@ -437,9 +437,9 @@ func (m *Map3[A, B, C]) Remove(entity ecs.Entity) {
 // Returns the number of removed entities.
 //
 // See also [ecs.World.NewEntityWith].
-func (m *Map3[A, B, C]) RemoveEntities(exact bool) int {
-	if exact {
-		filter := m.mask.Exact()
+func (m *Map3[A, B, C]) RemoveEntities(exclusive bool) int {
+	if exclusive {
+		filter := m.mask.Exclusive()
 		return m.world.Batch().RemoveEntities(&filter)
 	}
 	return m.world.Batch().RemoveEntities(m.mask)
@@ -602,9 +602,9 @@ func (m *Map4[A, B, C, D]) Remove(entity ecs.Entity) {
 // Returns the number of removed entities.
 //
 // See also [ecs.World.NewEntityWith].
-func (m *Map4[A, B, C, D]) RemoveEntities(exact bool) int {
-	if exact {
-		filter := m.mask.Exact()
+func (m *Map4[A, B, C, D]) RemoveEntities(exclusive bool) int {
+	if exclusive {
+		filter := m.mask.Exclusive()
 		return m.world.Batch().RemoveEntities(&filter)
 	}
 	return m.world.Batch().RemoveEntities(m.mask)
@@ -776,9 +776,9 @@ func (m *Map5[A, B, C, D, E]) Remove(entity ecs.Entity) {
 // Returns the number of removed entities.
 //
 // See also [ecs.World.NewEntityWith].
-func (m *Map5[A, B, C, D, E]) RemoveEntities(exact bool) int {
-	if exact {
-		filter := m.mask.Exact()
+func (m *Map5[A, B, C, D, E]) RemoveEntities(exclusive bool) int {
+	if exclusive {
+		filter := m.mask.Exclusive()
 		return m.world.Batch().RemoveEntities(&filter)
 	}
 	return m.world.Batch().RemoveEntities(m.mask)
@@ -959,9 +959,9 @@ func (m *Map6[A, B, C, D, E, F]) Remove(entity ecs.Entity) {
 // Returns the number of removed entities.
 //
 // See also [ecs.World.NewEntityWith].
-func (m *Map6[A, B, C, D, E, F]) RemoveEntities(exact bool) int {
-	if exact {
-		filter := m.mask.Exact()
+func (m *Map6[A, B, C, D, E, F]) RemoveEntities(exclusive bool) int {
+	if exclusive {
+		filter := m.mask.Exclusive()
 		return m.world.Batch().RemoveEntities(&filter)
 	}
 	return m.world.Batch().RemoveEntities(m.mask)
@@ -1151,9 +1151,9 @@ func (m *Map7[A, B, C, D, E, F, G]) Remove(entity ecs.Entity) {
 // Returns the number of removed entities.
 //
 // See also [ecs.World.NewEntityWith].
-func (m *Map7[A, B, C, D, E, F, G]) RemoveEntities(exact bool) int {
-	if exact {
-		filter := m.mask.Exact()
+func (m *Map7[A, B, C, D, E, F, G]) RemoveEntities(exclusive bool) int {
+	if exclusive {
+		filter := m.mask.Exclusive()
 		return m.world.Batch().RemoveEntities(&filter)
 	}
 	return m.world.Batch().RemoveEntities(m.mask)
@@ -1352,9 +1352,9 @@ func (m *Map8[A, B, C, D, E, F, G, H]) Remove(entity ecs.Entity) {
 // Returns the number of removed entities.
 //
 // See also [ecs.World.NewEntityWith].
-func (m *Map8[A, B, C, D, E, F, G, H]) RemoveEntities(exact bool) int {
-	if exact {
-		filter := m.mask.Exact()
+func (m *Map8[A, B, C, D, E, F, G, H]) RemoveEntities(exclusive bool) int {
+	if exclusive {
+		filter := m.mask.Exclusive()
 		return m.world.Batch().RemoveEntities(&filter)
 	}
 	return m.world.Batch().RemoveEntities(m.mask)


Test patch:
diff --git a/ecs/batch_test.go b/ecs/batch_test.go
index da1f422..798d686 100644
--- a/ecs/batch_test.go
+++ b/ecs/batch_test.go
@@ -23,12 +23,12 @@ func TestBatch(t *testing.T) {
 	b.NewEntities(100, posID)
 	b.NewEntitiesWith(100, comps...)
 
-	filter1 := All(posID).Exact()
+	filter1 := All(posID).Exclusive()
 	q := world.Query(&filter1)
 	assert.Equal(t, 100, q.Count())
 	q.Close()
 
-	filter2 := All(posID, rotID).Exact()
+	filter2 := All(posID, rotID).Exclusive()
 	q = world.Query(&filter2)
 	assert.Equal(t, 100, q.Count())
 	q.Close()
@@ -53,12 +53,12 @@ func TestBatchQuery(t *testing.T) {
 	q = b.NewEntitiesWithQuery(100, comps...)
 	q.Close()
 
-	filter1 := All(posID).Exact()
+	filter1 := All(posID).Exclusive()
 	q = world.Query(&filter1)
 	assert.Equal(t, 100, q.Count())
 	q.Close()
 
-	filter2 := All(posID, rotID).Exact()
+	filter2 := All(posID, rotID).Exclusive()
 	q = world.Query(&filter2)
 	assert.Equal(t, 100, q.Count())
 	q.Close()
diff --git a/ecs/bitmask_test.go b/ecs/bitmask_test.go
index 7864c28..acb5483 100644
--- a/ecs/bitmask_test.go
+++ b/ecs/bitmask_test.go
@@ -43,7 +43,7 @@ func TestBitMask(t *testing.T) {
 	assert.False(t, mask.ContainsAny(other2))
 }
 
-func TestBitMaskWithoutExact(t *testing.T) {
+func TestBitMaskWithoutExclusive(t *testing.T) {
 	mask := All(ID(1), ID(2), ID(13))
 	assert.True(t, mask.Matches(All(ID(1), ID(2), ID(13))))
 	assert.True(t, mask.Matches(All(ID(1), ID(2), ID(13), ID(27))))
@@ -58,11 +58,11 @@ func TestBitMaskWithoutExact(t *testing.T) {
 	assert.False(t, without.Matches(All(ID(1), ID(2), ID(3), ID(13))))
 	assert.False(t, without.Matches(All(ID(1), ID(2))))
 
-	exact := mask.Exact()
+	excl := mask.Exclusive()
 
-	assert.True(t, exact.Matches(All(ID(1), ID(2), ID(13))))
-	assert.False(t, exact.Matches(All(ID(1), ID(2), ID(13), ID(27))))
-	assert.False(t, exact.Matches(All(ID(1), ID(2), ID(3), ID(13))))
+	assert.True(t, excl.Matches(All(ID(1), ID(2), ID(13))))
+	assert.False(t, excl.Matches(All(ID(1), ID(2), ID(13), ID(27))))
+	assert.False(t, excl.Matches(All(ID(1), ID(2), ID(3), ID(13))))
 }
 
 func TestBitMask128(t *testing.T) {
diff --git a/ecs/world_test.go b/ecs/world_test.go
index de79282..0be654a 100644
--- a/ecs/world_test.go
+++ b/ecs/world_test.go
@@ -534,7 +534,7 @@ func TestWorldRemoveEntities(t *testing.T) {
 	assert.Equal(t, 200, query.Count())
 	query.Close()
 
-	filter := All(posID).Exact()
+	filter := All(posID).Exclusive()
 	cnt := world.removeEntities(&filter)
 	assert.Equal(t, 100, cnt)
 	assert.Equal(t, 300, len(events))