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

mlange-42 / ark / 13528862241

25 Feb 2025 07:00PM CUT coverage: 94.795% (+0.008%) from 94.787%
13528862241

push

github

web-flow
Add Map.GetRelationUnchecked (#75)

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

3406 of 3593 relevant lines covered (94.8%)

51323.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.15
/ecs/relation.go
1
package ecs
2

3
import "fmt"
4

5
var relationType = typeOf[Relation]()
6

7
// Relation is a marker for entity relation components.
8
// It must be embedded as first field of a component that represent an entity relation
9
// (see the example).
10
//
11
// Entity relations allow for fast queries using entity relationships.
12
// E.g. to iterate over all entities that are the child of a certain parent entity.
13
// Currently, each entity can only have a single relation component.
14
type Relation struct{}
15

16
type relationID struct {
17
        component ID
18
        target    Entity
19
}
20

21
// RelationIndex specifies an entity relation target by component index.
22
//
23
// Note that the index refers to the position of the component in the generics
24
// of e.g. a [Map2] or [Filter2].
25
// This should not be confused with component IDs as obtained by [ComponentID]!
26
type RelationIndex struct {
27
        index  uint8
28
        target Entity
29
}
30

31
// Rel creates a new RelationIndex.
32
func Rel(index int, target Entity) RelationIndex {
119✔
33
        return RelationIndex{
119✔
34
                index:  uint8(index),
119✔
35
                target: target,
119✔
36
        }
119✔
37
}
119✔
38

39
type relations []RelationIndex
40

41
func (r relations) toRelations(reg *componentRegistry, ids []ID, out []relationID) []relationID {
2,179✔
42
        out = out[:0]
2,179✔
43
        for _, rel := range r {
2,298✔
44
                id := ids[rel.index]
119✔
45
                if !reg.IsRelation[id.id] {
119✔
46
                        panic(fmt.Sprintf("component at index %d is not a relation component", rel.index))
×
47
                }
48
                out = append(out, relationID{
119✔
49
                        component: id,
119✔
50
                        target:    rel.target,
119✔
51
                })
119✔
52
        }
53
        return out
2,179✔
54
}
55

56
type relationEntities []Entity
57

58
func (r relationEntities) toRelation(id ID, out []relationID) []relationID {
494,093✔
59
        out = out[:0]
494,093✔
60
        for _, rel := range r {
494,366✔
61
                out = append(out, relationID{
273✔
62
                        component: id,
273✔
63
                        target:    rel,
273✔
64
                })
273✔
65
        }
273✔
66
        return out
494,093✔
67
}
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