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

mlange-42 / ark / 13617072942

02 Mar 2025 04:02PM CUT coverage: 97.422% (-0.002%) from 97.424%
13617072942

Pull #100

github

web-flow
Merge d87f29472 into 8f54a3a49
Pull Request #100: Simplify component/resource registration functions

2 of 2 new or added lines in 1 file covered. (100.0%)

3893 of 3996 relevant lines covered (97.42%)

93522.98 hits per line

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

96.88
/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
// RelationID specifies an entity relation target by component [ID].
17
//
18
// It is used in Ark's unsafe, ID-based API.
19
type RelationID struct {
20
        component ID
21
        target    Entity
22
}
23

24
// RelID creates a new [RelationID].
25
func RelID(id ID, target Entity) RelationID {
82✔
26
        return RelationID{
82✔
27
                component: id,
82✔
28
                target:    target,
82✔
29
        }
82✔
30
}
82✔
31

32
// RelationIndex specifies an entity relation target by component index.
33
//
34
// Note that the index refers to the position of the component in the generics
35
// of e.g. a [Map2] or [Filter2].
36
// This should not be confused with component [ID] as obtained by [ComponentID]!
37
type RelationIndex struct {
38
        index  uint8
39
        target Entity
40
}
41

42
// Rel creates a new [RelationIndex].
43
func Rel(index int, target Entity) RelationIndex {
784✔
44
        return RelationIndex{
784✔
45
                index:  uint8(index),
784✔
46
                target: target,
784✔
47
        }
784✔
48
}
784✔
49

50
type relations []RelationIndex
51

52
func (r relations) toRelations(reg *componentRegistry, ids []ID, out []RelationID) []RelationID {
4,406✔
53
        out = out[:0]
4,406✔
54
        for _, rel := range r {
5,172✔
55
                id := ids[rel.index]
766✔
56
                if !reg.IsRelation[id.id] {
766✔
57
                        panic(fmt.Sprintf("component at index %d is not a relation component", rel.index))
×
58
                }
59
                out = append(out, RelationID{
766✔
60
                        component: id,
766✔
61
                        target:    rel.target,
766✔
62
                })
766✔
63
        }
64
        return out
4,406✔
65
}
66

67
type relationEntities []Entity
68

69
func (r relationEntities) toRelation(id ID, out []RelationID) []RelationID {
1,002,868✔
70
        out = out[:0]
1,002,868✔
71
        for _, rel := range r {
1,002,934✔
72
                out = append(out, RelationID{
66✔
73
                        component: id,
66✔
74
                        target:    rel,
66✔
75
                })
66✔
76
        }
66✔
77
        return out
1,002,868✔
78
}
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