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

mlange-42 / arche / 4835368405

28 Apr 2023 10:44PM CUT coverage: 100.0%. Remained the same
4835368405

Pull #231

github

GitHub
Merge db7a79cd0 into c9fbc3a05
Pull Request #231: Entity relations

124 of 124 new or added lines in 9 files covered. (100.0%)

2814 of 2814 relevant lines covered (100.0%)

4178.32 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 {
55✔
23
        return bits.Contains(f.Include) && (f.Exclude.IsZero() || !bits.ContainsAny(f.Exclude))
55✔
24
}
55✔
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 {
15✔
34
        // TODO handle dead targets!
15✔
35
        return f.Filter.Matches(bits, relation) && f.Target.id == relation.id
15✔
36
}
15✔
37

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

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