• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / ark / 13683680318

05 Mar 2025 07:11PM CUT coverage: 99.318% (+0.002%) from 99.316%
13683680318

Pull #136

github

web-flow
Merge 0b4eff22d into c73c750d7
Pull Request #136: Add World.NewEntities

14 of 14 new or added lines in 1 file covered. (100.0%)

5824 of 5864 relevant lines covered (99.32%)

35696.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/ecs/filter.go
1
package ecs
2

3
// Filter is a filter for components.
4
//
5
// It is significantly slower than type-safe generic filters like [Filter2],
6
// and should only be used when component types are not known at compile time.
7
type Filter struct {
8
        mask       Mask
9
        without    Mask
10
        hasWithout bool
11
}
12

13
// NewFilter creates a new [Filter] matching the given components.
14
func NewFilter(ids ...ID) Filter {
1,251✔
15
        return Filter{
1,251✔
16
                mask: NewMask(ids...),
1,251✔
17
        }
1,251✔
18
}
1,251✔
19

20
// Without specifies components to exclude.
21
// Resets previous excludes.
22
func (f Filter) Without(ids ...ID) Filter {
4✔
23
        f.without = NewMask(ids...)
4✔
24
        f.hasWithout = true
4✔
25
        return f
4✔
26
}
4✔
27

28
// Exclusive makes the filter exclusive in the sense that the component composition is matched exactly,
29
// and no other components are allowed.
30
func (f Filter) Exclusive() Filter {
13✔
31
        f.without = f.mask.Not()
13✔
32
        f.hasWithout = true
13✔
33
        return f
13✔
34
}
13✔
35

36
// Query returns a new query matching this filter and the given entity relation targets.
37
// This is a synonym for [Unsafe.Query].
38
func (f Filter) Query(world *World, relations ...RelationID) Query {
6✔
39
        return newQuery(world, f, relations)
6✔
40
}
6✔
41

42
func (f *Filter) matches(mask *Mask) bool {
3,202✔
43
        return mask.Contains(&f.mask) && (!f.hasWithout || !mask.ContainsAny(&f.without))
3,202✔
44
}
3,202✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc