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

mlange-42 / ark / 13618795509

02 Mar 2025 07:58PM CUT coverage: 84.737% (-12.6%) from 97.38%
13618795509

Pull #101

github

web-flow
Merge 7affb7efc into 2ca3e2911
Pull Request #101: Implement batch operations on `ExchangeX`

0 of 672 new or added lines in 1 file covered. (0.0%)

374 existing lines in 1 file now uncovered.

4386 of 5176 relevant lines covered (84.74%)

36519.03 hits per line

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

97.44
/ecs/archetype.go
1
package ecs
2

3
import "slices"
4

5
type archetypeID uint32
6

7
type archetype struct {
8
        id             archetypeID
9
        mask           Mask
10
        components     []ID
11
        componentsMap  []int16
12
        isRelation     []bool
13
        tables         []tableID
14
        freeTables     []tableID
15
        numRelations   uint8
16
        relationTables []map[entityID]*tableIDs
17
}
18

19
type tableIDs struct {
20
        tables []tableID
21
}
22

23
func newArchetype(id archetypeID, mask *Mask, components []ID, tables []tableID, reg *componentRegistry) archetype {
351✔
24
        componentsMap := make([]int16, MaskTotalBits)
351✔
25
        for i := range MaskTotalBits {
90,207✔
26
                componentsMap[i] = -1
89,856✔
27
        }
89,856✔
28
        for i, id := range components {
1,084✔
29
                componentsMap[id.id] = int16(i)
733✔
30
        }
733✔
31

32
        numRelations := uint8(0)
351✔
33
        isRelation := make([]bool, len(components))
351✔
34
        relationTables := make([]map[entityID]*tableIDs, len(components))
351✔
35
        for i, id := range components {
1,084✔
36
                if reg.IsRelation[id.id] {
764✔
37
                        isRelation[i] = true
31✔
38
                        relationTables[i] = map[entityID]*tableIDs{}
31✔
39
                        numRelations++
31✔
40
                }
31✔
41
        }
42
        return archetype{
351✔
43
                id:             id,
351✔
44
                mask:           *mask,
351✔
45
                components:     components,
351✔
46
                componentsMap:  componentsMap,
351✔
47
                isRelation:     isRelation,
351✔
48
                tables:         tables,
351✔
49
                numRelations:   numRelations,
351✔
50
                relationTables: relationTables,
351✔
51
        }
351✔
52
}
53

54
func (a *archetype) HasRelations() bool {
505,841✔
55
        return a.numRelations > 0
505,841✔
56
}
505,841✔
57

58
func (a *archetype) GetTable(storage *storage, relations []RelationID) (*table, bool) {
504,309✔
59
        if len(a.tables) == 0 {
504,522✔
60
                return nil, false
213✔
61
        }
213✔
62
        if !a.HasRelations() {
1,007,784✔
63
                return &storage.tables[a.tables[0]], true
503,688✔
64
        }
503,688✔
65

66
        index := a.componentsMap[relations[0].component.id]
408✔
67
        tables, ok := a.relationTables[index][relations[0].target.id]
408✔
68
        if !ok {
445✔
69
                return nil, false
37✔
70
        }
37✔
71
        for _, t := range tables.tables {
761✔
72
                table := &storage.tables[t]
390✔
73
                if table.MatchesExact(relations) {
759✔
74
                        return table, true
369✔
75
                }
369✔
76
        }
77
        return nil, false
2✔
78
}
79

80
func (a *archetype) GetTables(relations []RelationID) []tableID {
27✔
81
        if !a.HasRelations() {
27✔
82
                return a.tables
×
83
        }
×
84
        if len(relations) == 0 {
41✔
85
                return a.tables
14✔
86
        }
14✔
87
        index := a.componentsMap[relations[0].component.id]
13✔
88
        if tables, ok := a.relationTables[index][relations[0].target.id]; ok {
26✔
89
                return tables.tables
13✔
90
        }
13✔
91
        return nil
×
92
}
93

94
func (a *archetype) GetFreeTable() (tableID, bool) {
252✔
95
        if len(a.freeTables) == 0 {
503✔
96
                return 0, false
251✔
97
        }
251✔
98
        last := len(a.freeTables) - 1
1✔
99
        table := a.freeTables[last]
1✔
100

1✔
101
        a.freeTables = a.freeTables[:last]
1✔
102

1✔
103
        return table, true
1✔
104
}
105

106
func (a *archetype) FreeTable(table tableID) {
4✔
107
        index := slices.Index(a.tables, table)
4✔
108
        last := len(a.tables) - 1
4✔
109

4✔
110
        a.tables[index], a.tables[last] = a.tables[last], a.tables[index]
4✔
111
        a.tables = a.tables[:last]
4✔
112

4✔
113
        a.freeTables = append(a.freeTables, table)
4✔
114
}
4✔
115

116
func (a *archetype) AddTable(table *table) {
252✔
117
        a.tables = append(a.tables, table.id)
252✔
118
        if !a.HasRelations() {
437✔
119
                return
185✔
120
        }
185✔
121

122
        for i := range table.ids {
303✔
123
                column := &table.columns[i]
236✔
124
                if !column.isRelation {
397✔
125
                        continue
161✔
126
                }
127
                target := column.target
75✔
128
                relations := a.relationTables[i]
75✔
129

75✔
130
                if tables, ok := relations[target.id]; ok {
80✔
131
                        tables.tables = append(tables.tables, table.id)
5✔
132
                } else {
75✔
133
                        relations[target.id] = &tableIDs{tables: []tableID{table.id}}
70✔
134
                }
70✔
135
        }
136
}
137

138
func (a *archetype) RemoveTarget(entity Entity) {
2✔
139
        for i := range a.relationTables {
6✔
140
                if !a.isRelation[i] {
6✔
141
                        continue
2✔
142
                }
143
                delete(a.relationTables[i], entity.id)
2✔
144
        }
145
}
146

147
func (a *archetype) Reset(storage *storage) {
4✔
148
        if !a.HasRelations() {
7✔
149
                storage.tables[a.tables[0]].Reset()
3✔
150
                return
3✔
151
        }
3✔
152

153
        for _, tab := range a.tables {
3✔
154
                table := &storage.tables[tab]
2✔
155
                table.Reset()
2✔
156
        }
2✔
157

158
        for i := len(a.tables) - 1; i >= 0; i-- {
3✔
159
                a.FreeTable(a.tables[i])
2✔
160
        }
2✔
161

162
        for _, m := range a.relationTables {
3✔
163
                for key := range m {
4✔
164
                        delete(m, key)
2✔
165
                }
2✔
166
        }
167
}
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