Skip to content

Commit

Permalink
Example for World.Mask, showing how check for filter "contains" an …
Browse files Browse the repository at this point in the history
…entity (#428)
  • Loading branch information
mlange-42 authored Sep 10, 2024
1 parent ae21e73 commit c2a5173
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [[unpublished]](https://github.com/mlange-42/arche/compare/v0.13.2...main)

### Documentation

* Adds an example for `World.Mask`, showing how to check whether a filter "contains" an entity (#428)

## [[v0.13.2]](https://github.com/mlange-42/arche/compare/v0.13.1...v0.13.2)

### Bugfixes
Expand Down
2 changes: 1 addition & 1 deletion ecs/entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestEntityAsIndex(t *testing.T) {
entity := Entity{1, 0}
entity := Entity{id: 1}
arr := []int{0, 1, 2}

val := arr[entity.id]
Expand Down
20 changes: 20 additions & 0 deletions ecs/world_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,26 @@ func ExampleWorld_Batch() {
// Output:
}

func ExampleWorld_Mask() {
world := ecs.NewWorld()
posID := ecs.ComponentID[Position](&world)
velID := ecs.ComponentID[Velocity](&world)

e1 := world.NewEntity(posID)
e2 := world.NewEntity(velID)

filter := ecs.All(posID)

// Use the entity's mask to check whether it is in the filter:
m1 := world.Mask(e1)
m2 := world.Mask(e2)
fmt.Println(filter.Matches(&m1))
fmt.Println(filter.Matches(&m2))
// Output:
//true
//false
}

func ExampleWorld_SetListener() {
world := ecs.NewWorld()

Expand Down

0 comments on commit c2a5173

Please sign in to comment.