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

mlange-42 / arche / 4859967421

02 May 2023 10:03AM CUT coverage: 100.0%. Remained the same
4859967421

push

github

GitHub
Document entity relations (#256)

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

3407 of 3407 relevant lines covered (100.0%)

1878.66 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 {
46✔
23
        return bits.Contains(f.Include) && (f.Exclude.IsZero() || !bits.ContainsAny(f.Exclude))
46✔
24
}
46✔
25

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

34
// Matches matches a filter against a mask.
35
func (f *RelationFilter) Matches(bits Mask, relation *Entity) bool {
200✔
36
        return f.Filter.Matches(bits, relation) && (relation == nil || f.Target == *relation)
200✔
37
}
200✔
38

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

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