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

mlange-42 / arche / 4874413404

03 May 2023 04:46PM CUT coverage: 100.0%. Remained the same
4874413404

push

github

GitHub
Batch-set entity relation, RelationFilter to function (#265)

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

3764 of 3764 relevant lines covered (100.0%)

97404.29 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 {
51✔
23
        return bits.Contains(f.Include) && (f.Exclude.IsZero() || !bits.ContainsAny(f.Exclude))
51✔
24
}
51✔
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
// RelationFilter creates a new [Relation] filter.
33
// It is a [Filter] for a [Relation] target, in addition to components.
34
//
35
// See [Relation] for details and examples.
36
func RelationFilter(filter Filter, target Entity) Filter {
25,041✔
37
        return &relationFilter{
25,041✔
38
                Filter: filter,
25,041✔
39
                Target: target,
25,041✔
40
        }
25,041✔
41
}
25,041✔
42

43
// Matches matches a filter against a mask.
44
func (f *relationFilter) Matches(bits Mask, relation *Entity) bool {
2,575,213✔
45
        return f.Filter.Matches(bits, relation) && (relation == nil || f.Target == *relation)
2,575,213✔
46
}
2,575,213✔
47

48
// CachedFilter is a filter that is cached by the world.
49
//
50
// Create it using [Cache.Register].
51
type CachedFilter struct {
52
        filter Filter
53
        id     uint32
54
}
55

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