• 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

94.59
/ecs/table.go
1
package ecs
2

3
import (
4
        "fmt"
5
        "math"
6
        "unsafe"
7
)
8

9
type tableID uint32
10

11
// maxTableID is used as table ID for unused entities.
12
const maxTableID = math.MaxUint32
13

14
type table struct {
15
        id          tableID
16
        archetype   archetypeID
17
        components  []int16
18
        entities    column
19
        ids         []ID
20
        columns     []column
21
        isRelation  []bool
22
        relations   []Entity
23
        relationIDs []relationID
24

25
        zeroValue   []byte
26
        zeroPointer unsafe.Pointer
27
}
28

29
func newTable(id tableID, archetype archetypeID, capacity uint32, reg *componentRegistry,
30
        ids []ID, componentsMap []int16, isRelation []bool, targets []Entity, relationIDs []relationID) table {
249✔
31

249✔
32
        entities := newColumn(entityType, capacity)
249✔
33
        columns := make([]column, len(ids))
249✔
34

249✔
35
        var maxSize uintptr = entitySize
249✔
36
        for i, id := range ids {
824✔
37
                columns[i] = newColumn(reg.Types[id.id], capacity)
575✔
38
                if columns[i].itemSize > maxSize {
723✔
39
                        maxSize = columns[i].itemSize
148✔
40
                }
148✔
41
        }
42
        var zeroValue []byte
249✔
43
        var zeroPointer unsafe.Pointer
249✔
44
        if maxSize > 0 {
498✔
45
                zeroValue = make([]byte, maxSize)
249✔
46
                zeroPointer = unsafe.Pointer(&zeroValue[0])
249✔
47
        }
249✔
48

49
        return table{
249✔
50
                id:          id,
249✔
51
                archetype:   archetype,
249✔
52
                components:  componentsMap,
249✔
53
                entities:    entities,
249✔
54
                ids:         ids,
249✔
55
                columns:     columns,
249✔
56
                isRelation:  isRelation,
249✔
57
                relations:   targets,
249✔
58
                zeroValue:   zeroValue,
249✔
59
                zeroPointer: zeroPointer,
249✔
60
                relationIDs: relationIDs,
249✔
61
        }
249✔
62
}
63

64
func (t *table) recycle(targets []Entity, relationIDs []relationID) {
1✔
65
        t.relations = targets
1✔
66
        t.relationIDs = relationIDs
1✔
67
}
1✔
68

69
func (t *table) Add(entity Entity) uint32 {
495,779✔
70
        _, idx := t.entities.Add(unsafe.Pointer(&entity))
495,779✔
71

495,779✔
72
        for i := range t.columns {
996,083✔
73
                t.columns[i].Alloc(1)
500,304✔
74
        }
500,304✔
75
        return idx
495,779✔
76
}
77

78
func (t *table) Get(component ID, index uintptr) unsafe.Pointer {
1,811✔
79
        return t.columns[t.components[component.id]].Get(index)
1,811✔
80
}
1,811✔
81

82
func (t *table) Has(component ID) bool {
6✔
83
        return t.components[component.id] >= 0
6✔
84
}
6✔
85

86
func (t *table) GetEntity(index uintptr) Entity {
2,463,190✔
87
        return *(*Entity)(t.entities.Get(index))
2,463,190✔
88
}
2,463,190✔
89

90
func (t *table) GetRelation(component ID) Entity {
103✔
91
        return t.relations[t.components[component.id]]
103✔
92
}
103✔
93

94
func (t *table) GetColumn(component ID) *column {
575✔
95
        return &t.columns[t.components[component.id]]
575✔
96
}
575✔
97

98
func (t *table) GetEntities(component ID) *column {
×
99
        return &t.entities
×
100
}
×
101

102
func (t *table) Set(component ID, index uint32, comp unsafe.Pointer) {
501,163✔
103
        t.columns[t.components[component.id]].Set(index, comp)
501,163✔
104
}
501,163✔
105

106
func (t *table) SetEntity(index uint32, entity Entity) {
384✔
107
        t.entities.Set(index, unsafe.Pointer(&entity))
384✔
108
}
384✔
109

110
// Alloc allocates memory for the given number of entities.
111
func (t *table) Alloc(n uint32) {
16✔
112
        t.entities.Alloc(n)
16✔
113
        for i := range t.columns {
88✔
114
                t.columns[i].Alloc(n)
72✔
115
        }
72✔
116
}
117

118
func (t *table) Remove(index uint32) bool {
494,178✔
119
        swapped := t.entities.Remove(index, nil)
494,178✔
120
        for i := range t.columns {
990,355✔
121
                t.columns[i].Remove(index, t.zeroPointer)
496,177✔
122
        }
496,177✔
123
        return swapped
494,178✔
124
}
125

126
func (t *table) Reset() {
1✔
127
        t.entities.Reset(nil)
1✔
128
        for c := range t.columns {
3✔
129
                t.columns[c].Reset(t.zeroPointer)
2✔
130
        }
2✔
131
}
132

133
func (t *table) AddAll(other *table) {
1✔
134
        t.entities.AddAll(&other.entities)
1✔
135
        for c := range t.columns {
3✔
136
                t.columns[c].AddAll(&other.columns[c])
2✔
137
        }
2✔
138
}
139

140
func (t *table) MatchesExact(relations []relationID) bool {
363✔
141
        if len(relations) != len(t.relationIDs) {
363✔
142
                panic("relation targets must be fully specified")
×
143
        }
144
        for _, rel := range relations {
784✔
145
                index := t.components[rel.component.id]
421✔
146
                if !t.isRelation[index] {
421✔
147
                        panic(fmt.Sprintf("component %d is not a relation component", rel.component.id))
×
148
                }
149
                //if rel.target == wildcard {
150
                //        panic("relation targets must be fully specified, no wildcard allowed")
151
                //}
152
                if rel.target != t.relations[index] {
442✔
153
                        return false
21✔
154
                }
21✔
155
        }
156
        return true
342✔
157
}
158

159
func (t *table) Matches(relations []relationID) bool {
36✔
160
        if len(relations) == 0 {
67✔
161
                return true
31✔
162
        }
31✔
163
        for _, rel := range relations {
12✔
164
                if rel.target == wildcard {
7✔
165
                        continue
×
166
                }
167
                if rel.target != t.relations[t.components[rel.component.id]] {
8✔
168
                        return false
1✔
169
                }
1✔
170
        }
171
        return true
4✔
172
}
173

174
func (t *table) Len() int {
1,145✔
175
        return t.entities.Len()
1,145✔
176
}
1,145✔
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