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

mlange-42 / arche / 4846030190

30 Apr 2023 07:29PM CUT coverage: 100.0%. Remained the same
4846030190

push

github

GitHub
Lock registered filters, partial recompile (#241)

136 of 136 new or added lines in 2 files covered. (100.0%)

3095 of 3095 relevant lines covered (100.0%)

2585.35 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 the interface for logic filters.
4
// Filters are required to query entities using [World.Query].
5
//
6
// See [Mask] and [MaskFilter] for basic filters.
7
// For type-safe generics queries, see package [github.com/mlange-42/arche/generic].
8
// For advanced filtering, see package [github.com/mlange-42/arche/filter].
9
type Filter interface {
10
        // Matches the filter against a bitmask, i.e. a component composition.
11
        Matches(bits Mask, relation *Entity) bool
12
}
13

14
// MaskFilter is a [Filter] for including and excluding certain components.
15
// See [All] and [Mask.Without].
16
type MaskFilter struct {
17
        Include Mask // Components to include.
18
        Exclude Mask // Components to exclude.
19
}
20

21
// Matches matches a filter against a mask.
22
func (f *MaskFilter) Matches(bits Mask, relation *Entity) bool {
32✔
23
        return bits.Contains(f.Include) && (f.Exclude.IsZero() || !bits.ContainsAny(f.Exclude))
32✔
24
}
32✔
25

26
// RelationFilter is a [Filter] for a relation target, in addition to components.
27
type RelationFilter struct {
28
        Filter Filter // Components filter.
29
        Target Entity // Relation target entity.
30
}
31

32
// Matches matches a filter against a mask.
33
func (f *RelationFilter) Matches(bits Mask, relation *Entity) bool {
1,423✔
34
        return f.Filter.Matches(bits, relation) && f.Target == *relation
1,423✔
35
}
1,423✔
36

37
// CachedFilter is a filter that is cached by the world.
38
//
39
// Create it using [Cache.Register].
40
type CachedFilter struct {
41
        filter Filter
42
        id     ID
43
}
44

45
// Matches matches a filter against a mask.
46
func (f *CachedFilter) Matches(bits Mask, relation *Entity) bool {
2✔
47
        return f.filter.Matches(bits, relation)
2✔
48
}
2✔
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