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

mlange-42 / ark / 13751358310

09 Mar 2025 06:32PM CUT coverage: 99.43%. Remained the same
13751358310

push

github

web-flow
Add Zenodo DOI and how to cite (#168)

6456 of 6493 relevant lines covered (99.43%)

27231.61 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
        filter
9
        world *World
10
}
11

12
// NewFilter creates a new [Filter] matching the given components.
13
func NewFilter(world *World, ids ...ID) Filter {
22✔
14
        return Filter{
22✔
15
                world:  world,
22✔
16
                filter: newFilter(ids...),
22✔
17
        }
22✔
18
}
22✔
19

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

27
// Exclusive makes the filter exclusive in the sense that the component composition is matched exactly,
28
// and no other components are allowed.
29
func (f Filter) Exclusive() Filter {
4✔
30
        f.filter = f.filter.Exclusive()
4✔
31
        return f
4✔
32
}
4✔
33

34
// Query returns a new query matching this filter and the given entity relation targets.
35
func (f Filter) Query(relations ...RelationID) Query {
14✔
36
        return newQuery(f.world, f.filter, relations)
14✔
37
}
14✔
38

39
type filter struct {
40
        mask       bitMask
41
        without    bitMask
42
        hasWithout bool
43
}
44

45
func newFilter(ids ...ID) filter {
1,262✔
46
        return filter{
1,262✔
47
                mask: newMask(ids...),
1,262✔
48
        }
1,262✔
49
}
1,262✔
50

51
func (f *filter) matches(mask *bitMask) bool {
3,249✔
52
        return mask.Contains(&f.mask) && (!f.hasWithout || !mask.ContainsAny(&f.without))
3,249✔
53
}
3,249✔
54

55
// Without specifies components to exclude.
56
// Resets previous excludes.
57
func (f filter) Without(ids ...ID) filter {
4✔
58
        f.without = newMask(ids...)
4✔
59
        f.hasWithout = true
4✔
60
        return f
4✔
61
}
4✔
62

63
// Exclusive makes the filter exclusive in the sense that the component composition is matched exactly,
64
// and no other components are allowed.
65
func (f filter) Exclusive() filter {
13✔
66
        f.without = f.mask.Not()
13✔
67
        f.hasWithout = true
13✔
68
        return f
13✔
69
}
13✔
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