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

mlange-42 / ark / 13593874277

28 Feb 2025 06:06PM CUT coverage: 96.872% (+2.1%) from 94.795%
13593874277

Pull #79

github

web-flow
Merge 94da96c6d into 10315654e
Pull Request #79: Relation getters for queries and maps

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

8 existing lines in 1 file now uncovered.

3562 of 3677 relevant lines covered (96.87%)

50530.93 hits per line

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

94.55
/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
        relationIDs []relationID
22

23
        zeroValue   []byte
24
        zeroPointer unsafe.Pointer
25
}
26

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

265✔
30
        entities := newColumn(entityType, false, Entity{}, capacity)
265✔
31
        columns := make([]column, len(ids))
265✔
32

265✔
33
        var maxSize uintptr = entitySize
265✔
34
        for i, id := range ids {
852✔
35
                columns[i] = newColumn(reg.Types[id.id], isRelation[i], targets[i], capacity)
587✔
36
                if columns[i].itemSize > maxSize {
738✔
37
                        maxSize = columns[i].itemSize
151✔
38
                }
151✔
39
        }
40
        var zeroValue []byte
265✔
41
        var zeroPointer unsafe.Pointer
265✔
42
        if maxSize > 0 {
530✔
43
                zeroValue = make([]byte, maxSize)
265✔
44
                zeroPointer = unsafe.Pointer(&zeroValue[0])
265✔
45
        }
265✔
46

47
        return table{
265✔
48
                id:          id,
265✔
49
                archetype:   archetype,
265✔
50
                components:  componentsMap,
265✔
51
                entities:    entities,
265✔
52
                ids:         ids,
265✔
53
                columns:     columns,
265✔
54
                zeroValue:   zeroValue,
265✔
55
                zeroPointer: zeroPointer,
265✔
56
                relationIDs: relationIDs,
265✔
57
        }
265✔
58
}
59

60
func (t *table) recycle(targets []Entity, relationIDs []relationID) {
1✔
61
        t.relationIDs = relationIDs
1✔
62
        for i := range t.columns {
3✔
63
                t.columns[i].target = targets[i]
2✔
64
        }
2✔
65
}
66

67
func (t *table) Add(entity Entity) uint32 {
498,290✔
68
        _, idx := t.entities.Add(unsafe.Pointer(&entity))
498,290✔
69

498,290✔
70
        for i := range t.columns {
1,000,065✔
71
                t.columns[i].Alloc(1)
501,775✔
72
        }
501,775✔
73
        return idx
498,290✔
74
}
75

76
func (t *table) Get(component ID, index uintptr) unsafe.Pointer {
767✔
77
        return t.columns[t.components[component.id]].Get(index)
767✔
78
}
767✔
79

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

84
func (t *table) GetEntity(index uintptr) Entity {
2,500,514✔
85
        return *(*Entity)(t.entities.Get(index))
2,500,514✔
86
}
2,500,514✔
87

88
func (t *table) GetRelation(component ID) Entity {
127✔
89
        return t.columns[t.components[component.id]].target
127✔
90
}
127✔
91

92
func (t *table) GetColumn(component ID) *column {
587✔
93
        return &t.columns[t.components[component.id]]
587✔
94
}
587✔
95

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

100
func (t *table) Set(component ID, index uint32, comp unsafe.Pointer) {
502,634✔
101
        t.columns[t.components[component.id]].Set(index, comp)
502,634✔
102
}
502,634✔
103

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

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

116
func (t *table) Remove(index uint32) bool {
497,180✔
117
        swapped := t.entities.Remove(index, nil)
497,180✔
118
        for i := range t.columns {
995,827✔
119
                t.columns[i].Remove(index, t.zeroPointer)
498,647✔
120
        }
498,647✔
121
        return swapped
497,180✔
122
}
123

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

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

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

157
func (t *table) Matches(relations []relationID) bool {
36✔
158
        if len(relations) == 0 {
59✔
159
                return true
23✔
160
        }
23✔
161
        for _, rel := range relations {
28✔
162
                if rel.target == wildcard {
15✔
163
                        continue
×
164
                }
165
                if rel.target != t.columns[t.components[rel.component.id]].target {
16✔
166
                        return false
1✔
167
                }
1✔
168
        }
169
        return true
12✔
170
}
171

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