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

mlange-42 / ark / 14375286522

10 Apr 2025 07:57AM CUT coverage: 99.832%. Remained the same
14375286522

Pull #232

github

web-flow
Merge 20666eb9b into b10a54964
Pull Request #232: Use Go 1.24 range loops instead of counting loops

7 of 7 new or added lines in 6 files covered. (100.0%)

8298 of 8312 relevant lines covered (99.83%)

19355.36 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
// UnsafeFilter 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 UnsafeFilter struct {
8
        world *World
9
        filter
10
}
11

12
// NewUnsafeFilter creates a new [UnsafeFilter] matching the given components.
13
func NewUnsafeFilter(world *World, ids ...ID) UnsafeFilter {
22✔
14
        return UnsafeFilter{
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 UnsafeFilter) Without(ids ...ID) UnsafeFilter {
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 UnsafeFilter) Exclusive() UnsafeFilter {
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 UnsafeFilter) Query(relations ...RelationID) UnsafeQuery {
14✔
36
        return UnsafeQuery{
14✔
37
                world:     f.world,
14✔
38
                filter:    f.filter,
14✔
39
                relations: relations,
14✔
40
                lock:      f.world.lock(),
14✔
41
                cursor: cursor{
14✔
42
                        archetype: -1,
14✔
43
                        table:     -1,
14✔
44
                        index:     0,
14✔
45
                        maxIndex:  -1,
14✔
46
                },
14✔
47
        }
14✔
48
}
14✔
49

50
type filter struct {
51
        mask       bitMask
52
        without    bitMask
53
        hasWithout bool
54
}
55

56
func newFilter(ids ...ID) filter {
1,293✔
57
        return filter{
1,293✔
58
                mask: newMask(ids...),
1,293✔
59
        }
1,293✔
60
}
1,293✔
61

62
func (f *filter) matches(mask *bitMask) bool {
3,729✔
63
        return mask.Contains(&f.mask) && (!f.hasWithout || !mask.ContainsAny(&f.without))
3,729✔
64
}
3,729✔
65

66
// Without specifies components to exclude.
67
// Resets previous excludes.
68
func (f filter) Without(ids ...ID) filter {
4✔
69
        f.without = newMask(ids...)
4✔
70
        f.hasWithout = true
4✔
71
        return f
4✔
72
}
4✔
73

74
// Exclusive makes the filter exclusive in the sense that the component composition is matched exactly,
75
// and no other components are allowed.
76
func (f filter) Exclusive() filter {
13✔
77
        f.without = f.mask.Not()
13✔
78
        f.hasWithout = true
13✔
79
        return f
13✔
80
}
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