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

mlange-42 / ark / 13526736655

25 Feb 2025 05:02PM CUT coverage: 94.787%. Remained the same
13526736655

push

github

web-flow
Add an example to the README (#74)

3400 of 3587 relevant lines covered (94.79%)

51722.1 hits per line

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

89.52
/ecs/maps_gen.go
1
package ecs
2

3
// Code generated by go generate; DO NOT EDIT.
4

5
import "unsafe"
6

7
// Map1 is a mapper to access 1 components of an entity.
8
type Map1[A any] struct {
9
        world     *World
10
        ids       []ID
11
        storageA  *componentStorage
12
        relations []relationID
13
}
14

15
// NewMap1 creates a new [Map1].
16
func NewMap1[A any](world *World) Map1[A] {
9✔
17
        ids := []ID{
9✔
18
                ComponentID[A](world),
9✔
19
        }
9✔
20
        return Map1[A]{
9✔
21
                world:    world,
9✔
22
                ids:      ids,
9✔
23
                storageA: &world.storage.components[ids[0].id],
9✔
24
        }
9✔
25
}
9✔
26

27
// NewEntity creates a new entity with the mapped components.
28
func (m *Map1[A]) NewEntity(a *A, rel ...RelationIndex) Entity {
96✔
29
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
96✔
30
        return m.world.newEntityWith(m.ids, []unsafe.Pointer{
96✔
31
                unsafe.Pointer(a),
96✔
32
        }, m.relations)
96✔
33
}
96✔
34

35
// NewBatch creates a batch of new entities with the mapped components.
36
func (m *Map1[A]) NewBatch(count int, a *A, rel ...RelationIndex) {
1✔
37
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
1✔
38
        m.world.newEntitiesWith(count, m.ids, []unsafe.Pointer{
1✔
39
                unsafe.Pointer(a),
1✔
40
        }, m.relations)
1✔
41
}
1✔
42

43
// NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each.
44
// The initializer function can be nil.
45
func (m *Map1[A]) NewBatchFn(count int, fn func(entity Entity, a *A), rel ...RelationIndex) {
1✔
46
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
1✔
47
        tableID, start := m.world.newEntities(count, m.ids, m.relations)
1✔
48
        if fn == nil {
1✔
49
                return
×
50
        }
×
51

52
        table := &m.world.storage.tables[tableID]
1✔
53
        columnA := m.storageA.columns[tableID]
1✔
54

1✔
55
        for i := range count {
25✔
56
                index := uintptr(start + i)
24✔
57
                fn(
24✔
58
                        table.GetEntity(index),
24✔
59
                        (*A)(columnA.Get(index)),
24✔
60
                )
24✔
61
        }
24✔
62
}
63

64
// Get returns the mapped components for the given entity.
65
func (m *Map1[A]) Get(entity Entity) *A {
24✔
66
        if !m.world.Alive(entity) {
24✔
67
                panic("can't get components of a dead entity")
×
68
        }
69
        return m.GetUnchecked(entity)
24✔
70
}
71

72
// GetUnchecked returns the mapped components for the given entity.
73
// It does not check whether the entity is alive.
74
// Can be used as an optimization when it is certain that the entity is alive.
75
func (m *Map1[A]) GetUnchecked(entity Entity) *A {
24✔
76
        index := m.world.storage.entities[entity.id]
24✔
77
        row := uintptr(index.row)
24✔
78
        checkMapHasComponent(m.storageA, index.table)
24✔
79

24✔
80
        return (*A)(m.storageA.columns[index.table].Get(row))
24✔
81
}
24✔
82

83
// HasAll return whether the given entity has all mapped components.
84
func (m *Map1[A]) HasAll(entity Entity) bool {
29✔
85
        if !m.world.Alive(entity) {
29✔
86
                panic("can't check components of a dead entity")
×
87
        }
88
        index := m.world.storage.entities[entity.id]
29✔
89
        return m.storageA.columns[index.table] != nil
29✔
90
}
91

92
// Add the mapped components to the given entity.
93
func (m *Map1[A]) Add(entity Entity, a *A, rel ...RelationIndex) {
13✔
94
        if !m.world.Alive(entity) {
13✔
95
                panic("can't add components to a dead entity")
×
96
        }
97
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
13✔
98
        m.world.exchange(entity, m.ids, nil, []unsafe.Pointer{
13✔
99
                unsafe.Pointer(a),
13✔
100
        }, m.relations)
13✔
101
}
102

103
// Remove the mapped components from the given entity.
104
func (m *Map1[A]) Remove(entity Entity) {
24✔
105
        if !m.world.Alive(entity) {
24✔
106
                panic("can't remove components from a dead entity")
×
107
        }
108
        m.world.exchange(entity, nil, m.ids, nil, nil)
24✔
109
}
110

111
// Remove the mapped components from the given entity.
112
func (m *Map1[A]) SetRelations(entity Entity, rel ...RelationIndex) {
×
113
        if !m.world.Alive(entity) {
×
114
                panic("can't remove components from a dead entity")
×
115
        }
116
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
117
        m.world.setRelations(entity, m.relations)
×
118
}
119

120
// Map2 is a mapper to access 2 components of an entity.
121
type Map2[A any, B any] struct {
122
        world     *World
123
        ids       []ID
124
        storageA  *componentStorage
125
        storageB  *componentStorage
126
        relations []relationID
127
}
128

129
// NewMap2 creates a new [Map2].
130
func NewMap2[A any, B any](world *World) Map2[A, B] {
35✔
131
        ids := []ID{
35✔
132
                ComponentID[A](world),
35✔
133
                ComponentID[B](world),
35✔
134
        }
35✔
135
        return Map2[A, B]{
35✔
136
                world:    world,
35✔
137
                ids:      ids,
35✔
138
                storageA: &world.storage.components[ids[0].id],
35✔
139
                storageB: &world.storage.components[ids[1].id],
35✔
140
        }
35✔
141
}
35✔
142

143
// NewEntity creates a new entity with the mapped components.
144
func (m *Map2[A, B]) NewEntity(a *A, b *B, rel ...RelationIndex) Entity {
254✔
145
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
254✔
146
        return m.world.newEntityWith(m.ids, []unsafe.Pointer{
254✔
147
                unsafe.Pointer(a),
254✔
148
                unsafe.Pointer(b),
254✔
149
        }, m.relations)
254✔
150
}
254✔
151

152
// NewBatch creates a batch of new entities with the mapped components.
153
func (m *Map2[A, B]) NewBatch(count int, a *A, b *B, rel ...RelationIndex) {
1✔
154
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
1✔
155
        m.world.newEntitiesWith(count, m.ids, []unsafe.Pointer{
1✔
156
                unsafe.Pointer(a),
1✔
157
                unsafe.Pointer(b),
1✔
158
        }, m.relations)
1✔
159
}
1✔
160

161
// NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each.
162
// The initializer function can be nil.
163
func (m *Map2[A, B]) NewBatchFn(count int, fn func(entity Entity, a *A, b *B), rel ...RelationIndex) {
1✔
164
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
1✔
165
        tableID, start := m.world.newEntities(count, m.ids, m.relations)
1✔
166
        if fn == nil {
1✔
167
                return
×
168
        }
×
169

170
        table := &m.world.storage.tables[tableID]
1✔
171
        columnA := m.storageA.columns[tableID]
1✔
172
        columnB := m.storageB.columns[tableID]
1✔
173

1✔
174
        for i := range count {
25✔
175
                index := uintptr(start + i)
24✔
176
                fn(
24✔
177
                        table.GetEntity(index),
24✔
178
                        (*A)(columnA.Get(index)),
24✔
179
                        (*B)(columnB.Get(index)),
24✔
180
                )
24✔
181
        }
24✔
182
}
183

184
// Get returns the mapped components for the given entity.
185
func (m *Map2[A, B]) Get(entity Entity) (*A, *B) {
24✔
186
        if !m.world.Alive(entity) {
24✔
187
                panic("can't get components of a dead entity")
×
188
        }
189
        return m.GetUnchecked(entity)
24✔
190
}
191

192
// GetUnchecked returns the mapped components for the given entity.
193
// It does not check whether the entity is alive.
194
// Can be used as an optimization when it is certain that the entity is alive.
195
func (m *Map2[A, B]) GetUnchecked(entity Entity) (*A, *B) {
24✔
196
        index := m.world.storage.entities[entity.id]
24✔
197
        row := uintptr(index.row)
24✔
198
        checkMapHasComponent(m.storageA, index.table)
24✔
199
        checkMapHasComponent(m.storageB, index.table)
24✔
200

24✔
201
        return (*A)(m.storageA.columns[index.table].Get(row)),
24✔
202
                (*B)(m.storageB.columns[index.table].Get(row))
24✔
203
}
24✔
204

205
// HasAll return whether the given entity has all mapped components.
206
func (m *Map2[A, B]) HasAll(entity Entity) bool {
53✔
207
        if !m.world.Alive(entity) {
53✔
208
                panic("can't check components of a dead entity")
×
209
        }
210
        index := m.world.storage.entities[entity.id]
53✔
211
        return m.storageA.columns[index.table] != nil &&
53✔
212
                m.storageB.columns[index.table] != nil
53✔
213
}
214

215
// Add the mapped components to the given entity.
216
func (m *Map2[A, B]) Add(entity Entity, a *A, b *B, rel ...RelationIndex) {
12✔
217
        if !m.world.Alive(entity) {
12✔
218
                panic("can't add components to a dead entity")
×
219
        }
220
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
12✔
221
        m.world.exchange(entity, m.ids, nil, []unsafe.Pointer{
12✔
222
                unsafe.Pointer(a),
12✔
223
                unsafe.Pointer(b),
12✔
224
        }, m.relations)
12✔
225
}
226

227
// Remove the mapped components from the given entity.
228
func (m *Map2[A, B]) Remove(entity Entity) {
24✔
229
        if !m.world.Alive(entity) {
24✔
230
                panic("can't remove components from a dead entity")
×
231
        }
232
        m.world.exchange(entity, nil, m.ids, nil, nil)
24✔
233
}
234

235
// Remove the mapped components from the given entity.
236
func (m *Map2[A, B]) SetRelations(entity Entity, rel ...RelationIndex) {
×
237
        if !m.world.Alive(entity) {
×
238
                panic("can't remove components from a dead entity")
×
239
        }
240
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
241
        m.world.setRelations(entity, m.relations)
×
242
}
243

244
// Map3 is a mapper to access 3 components of an entity.
245
type Map3[A any, B any, C any] struct {
246
        world     *World
247
        ids       []ID
248
        storageA  *componentStorage
249
        storageB  *componentStorage
250
        storageC  *componentStorage
251
        relations []relationID
252
}
253

254
// NewMap3 creates a new [Map3].
255
func NewMap3[A any, B any, C any](world *World) Map3[A, B, C] {
9✔
256
        ids := []ID{
9✔
257
                ComponentID[A](world),
9✔
258
                ComponentID[B](world),
9✔
259
                ComponentID[C](world),
9✔
260
        }
9✔
261
        return Map3[A, B, C]{
9✔
262
                world:    world,
9✔
263
                ids:      ids,
9✔
264
                storageA: &world.storage.components[ids[0].id],
9✔
265
                storageB: &world.storage.components[ids[1].id],
9✔
266
                storageC: &world.storage.components[ids[2].id],
9✔
267
        }
9✔
268
}
9✔
269

270
// NewEntity creates a new entity with the mapped components.
271
func (m *Map3[A, B, C]) NewEntity(a *A, b *B, c *C, rel ...RelationIndex) Entity {
136✔
272
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
136✔
273
        return m.world.newEntityWith(m.ids, []unsafe.Pointer{
136✔
274
                unsafe.Pointer(a),
136✔
275
                unsafe.Pointer(b),
136✔
276
                unsafe.Pointer(c),
136✔
277
        }, m.relations)
136✔
278
}
136✔
279

280
// NewBatch creates a batch of new entities with the mapped components.
281
func (m *Map3[A, B, C]) NewBatch(count int, a *A, b *B, c *C, rel ...RelationIndex) {
1✔
282
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
1✔
283
        m.world.newEntitiesWith(count, m.ids, []unsafe.Pointer{
1✔
284
                unsafe.Pointer(a),
1✔
285
                unsafe.Pointer(b),
1✔
286
                unsafe.Pointer(c),
1✔
287
        }, m.relations)
1✔
288
}
1✔
289

290
// NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each.
291
// The initializer function can be nil.
292
func (m *Map3[A, B, C]) NewBatchFn(count int, fn func(entity Entity, a *A, b *B, c *C), rel ...RelationIndex) {
1✔
293
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
1✔
294
        tableID, start := m.world.newEntities(count, m.ids, m.relations)
1✔
295
        if fn == nil {
1✔
296
                return
×
297
        }
×
298

299
        table := &m.world.storage.tables[tableID]
1✔
300
        columnA := m.storageA.columns[tableID]
1✔
301
        columnB := m.storageB.columns[tableID]
1✔
302
        columnC := m.storageC.columns[tableID]
1✔
303

1✔
304
        for i := range count {
25✔
305
                index := uintptr(start + i)
24✔
306
                fn(
24✔
307
                        table.GetEntity(index),
24✔
308
                        (*A)(columnA.Get(index)),
24✔
309
                        (*B)(columnB.Get(index)),
24✔
310
                        (*C)(columnC.Get(index)),
24✔
311
                )
24✔
312
        }
24✔
313
}
314

315
// Get returns the mapped components for the given entity.
316
func (m *Map3[A, B, C]) Get(entity Entity) (*A, *B, *C) {
24✔
317
        if !m.world.Alive(entity) {
24✔
318
                panic("can't get components of a dead entity")
×
319
        }
320
        return m.GetUnchecked(entity)
24✔
321
}
322

323
// GetUnchecked returns the mapped components for the given entity.
324
// It does not check whether the entity is alive.
325
// Can be used as an optimization when it is certain that the entity is alive.
326
func (m *Map3[A, B, C]) GetUnchecked(entity Entity) (*A, *B, *C) {
24✔
327
        index := m.world.storage.entities[entity.id]
24✔
328
        row := uintptr(index.row)
24✔
329
        checkMapHasComponent(m.storageA, index.table)
24✔
330
        checkMapHasComponent(m.storageB, index.table)
24✔
331
        checkMapHasComponent(m.storageC, index.table)
24✔
332

24✔
333
        return (*A)(m.storageA.columns[index.table].Get(row)),
24✔
334
                (*B)(m.storageB.columns[index.table].Get(row)),
24✔
335
                (*C)(m.storageC.columns[index.table].Get(row))
24✔
336
}
24✔
337

338
// HasAll return whether the given entity has all mapped components.
339
func (m *Map3[A, B, C]) HasAll(entity Entity) bool {
29✔
340
        if !m.world.Alive(entity) {
29✔
341
                panic("can't check components of a dead entity")
×
342
        }
343
        index := m.world.storage.entities[entity.id]
29✔
344
        return m.storageA.columns[index.table] != nil &&
29✔
345
                m.storageB.columns[index.table] != nil &&
29✔
346
                m.storageC.columns[index.table] != nil
29✔
347
}
348

349
// Add the mapped components to the given entity.
350
func (m *Map3[A, B, C]) Add(entity Entity, a *A, b *B, c *C, rel ...RelationIndex) {
12✔
351
        if !m.world.Alive(entity) {
12✔
352
                panic("can't add components to a dead entity")
×
353
        }
354
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
12✔
355
        m.world.exchange(entity, m.ids, nil, []unsafe.Pointer{
12✔
356
                unsafe.Pointer(a),
12✔
357
                unsafe.Pointer(b),
12✔
358
                unsafe.Pointer(c),
12✔
359
        }, m.relations)
12✔
360
}
361

362
// Remove the mapped components from the given entity.
363
func (m *Map3[A, B, C]) Remove(entity Entity) {
24✔
364
        if !m.world.Alive(entity) {
24✔
365
                panic("can't remove components from a dead entity")
×
366
        }
367
        m.world.exchange(entity, nil, m.ids, nil, nil)
24✔
368
}
369

370
// Remove the mapped components from the given entity.
371
func (m *Map3[A, B, C]) SetRelations(entity Entity, rel ...RelationIndex) {
×
372
        if !m.world.Alive(entity) {
×
373
                panic("can't remove components from a dead entity")
×
374
        }
375
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
376
        m.world.setRelations(entity, m.relations)
×
377
}
378

379
// Map4 is a mapper to access 4 components of an entity.
380
type Map4[A any, B any, C any, D any] struct {
381
        world     *World
382
        ids       []ID
383
        storageA  *componentStorage
384
        storageB  *componentStorage
385
        storageC  *componentStorage
386
        storageD  *componentStorage
387
        relations []relationID
388
}
389

390
// NewMap4 creates a new [Map4].
391
func NewMap4[A any, B any, C any, D any](world *World) Map4[A, B, C, D] {
8✔
392
        ids := []ID{
8✔
393
                ComponentID[A](world),
8✔
394
                ComponentID[B](world),
8✔
395
                ComponentID[C](world),
8✔
396
                ComponentID[D](world),
8✔
397
        }
8✔
398
        return Map4[A, B, C, D]{
8✔
399
                world:    world,
8✔
400
                ids:      ids,
8✔
401
                storageA: &world.storage.components[ids[0].id],
8✔
402
                storageB: &world.storage.components[ids[1].id],
8✔
403
                storageC: &world.storage.components[ids[2].id],
8✔
404
                storageD: &world.storage.components[ids[3].id],
8✔
405
        }
8✔
406
}
8✔
407

408
// NewEntity creates a new entity with the mapped components.
409
func (m *Map4[A, B, C, D]) NewEntity(a *A, b *B, c *C, d *D, rel ...RelationIndex) Entity {
96✔
410
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
96✔
411
        return m.world.newEntityWith(m.ids, []unsafe.Pointer{
96✔
412
                unsafe.Pointer(a),
96✔
413
                unsafe.Pointer(b),
96✔
414
                unsafe.Pointer(c),
96✔
415
                unsafe.Pointer(d),
96✔
416
        }, m.relations)
96✔
417
}
96✔
418

419
// NewBatch creates a batch of new entities with the mapped components.
420
func (m *Map4[A, B, C, D]) NewBatch(count int, a *A, b *B, c *C, d *D, rel ...RelationIndex) {
1✔
421
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
1✔
422
        m.world.newEntitiesWith(count, m.ids, []unsafe.Pointer{
1✔
423
                unsafe.Pointer(a),
1✔
424
                unsafe.Pointer(b),
1✔
425
                unsafe.Pointer(c),
1✔
426
                unsafe.Pointer(d),
1✔
427
        }, m.relations)
1✔
428
}
1✔
429

430
// NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each.
431
// The initializer function can be nil.
432
func (m *Map4[A, B, C, D]) NewBatchFn(count int, fn func(entity Entity, a *A, b *B, c *C, d *D), rel ...RelationIndex) {
1✔
433
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
1✔
434
        tableID, start := m.world.newEntities(count, m.ids, m.relations)
1✔
435
        if fn == nil {
1✔
436
                return
×
437
        }
×
438

439
        table := &m.world.storage.tables[tableID]
1✔
440
        columnA := m.storageA.columns[tableID]
1✔
441
        columnB := m.storageB.columns[tableID]
1✔
442
        columnC := m.storageC.columns[tableID]
1✔
443
        columnD := m.storageD.columns[tableID]
1✔
444

1✔
445
        for i := range count {
25✔
446
                index := uintptr(start + i)
24✔
447
                fn(
24✔
448
                        table.GetEntity(index),
24✔
449
                        (*A)(columnA.Get(index)),
24✔
450
                        (*B)(columnB.Get(index)),
24✔
451
                        (*C)(columnC.Get(index)),
24✔
452
                        (*D)(columnD.Get(index)),
24✔
453
                )
24✔
454
        }
24✔
455
}
456

457
// Get returns the mapped components for the given entity.
458
func (m *Map4[A, B, C, D]) Get(entity Entity) (*A, *B, *C, *D) {
24✔
459
        if !m.world.Alive(entity) {
24✔
460
                panic("can't get components of a dead entity")
×
461
        }
462
        return m.GetUnchecked(entity)
24✔
463
}
464

465
// GetUnchecked returns the mapped components for the given entity.
466
// It does not check whether the entity is alive.
467
// Can be used as an optimization when it is certain that the entity is alive.
468
func (m *Map4[A, B, C, D]) GetUnchecked(entity Entity) (*A, *B, *C, *D) {
24✔
469
        index := m.world.storage.entities[entity.id]
24✔
470
        row := uintptr(index.row)
24✔
471
        checkMapHasComponent(m.storageA, index.table)
24✔
472
        checkMapHasComponent(m.storageB, index.table)
24✔
473
        checkMapHasComponent(m.storageC, index.table)
24✔
474
        checkMapHasComponent(m.storageD, index.table)
24✔
475

24✔
476
        return (*A)(m.storageA.columns[index.table].Get(row)),
24✔
477
                (*B)(m.storageB.columns[index.table].Get(row)),
24✔
478
                (*C)(m.storageC.columns[index.table].Get(row)),
24✔
479
                (*D)(m.storageD.columns[index.table].Get(row))
24✔
480
}
24✔
481

482
// HasAll return whether the given entity has all mapped components.
483
func (m *Map4[A, B, C, D]) HasAll(entity Entity) bool {
29✔
484
        if !m.world.Alive(entity) {
29✔
485
                panic("can't check components of a dead entity")
×
486
        }
487
        index := m.world.storage.entities[entity.id]
29✔
488
        return m.storageA.columns[index.table] != nil &&
29✔
489
                m.storageB.columns[index.table] != nil &&
29✔
490
                m.storageC.columns[index.table] != nil &&
29✔
491
                m.storageD.columns[index.table] != nil
29✔
492
}
493

494
// Add the mapped components to the given entity.
495
func (m *Map4[A, B, C, D]) Add(entity Entity, a *A, b *B, c *C, d *D, rel ...RelationIndex) {
12✔
496
        if !m.world.Alive(entity) {
12✔
497
                panic("can't add components to a dead entity")
×
498
        }
499
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
12✔
500
        m.world.exchange(entity, m.ids, nil, []unsafe.Pointer{
12✔
501
                unsafe.Pointer(a),
12✔
502
                unsafe.Pointer(b),
12✔
503
                unsafe.Pointer(c),
12✔
504
                unsafe.Pointer(d),
12✔
505
        }, m.relations)
12✔
506
}
507

508
// Remove the mapped components from the given entity.
509
func (m *Map4[A, B, C, D]) Remove(entity Entity) {
24✔
510
        if !m.world.Alive(entity) {
24✔
511
                panic("can't remove components from a dead entity")
×
512
        }
513
        m.world.exchange(entity, nil, m.ids, nil, nil)
24✔
514
}
515

516
// Remove the mapped components from the given entity.
517
func (m *Map4[A, B, C, D]) SetRelations(entity Entity, rel ...RelationIndex) {
×
518
        if !m.world.Alive(entity) {
×
519
                panic("can't remove components from a dead entity")
×
520
        }
521
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
522
        m.world.setRelations(entity, m.relations)
×
523
}
524

525
// Map5 is a mapper to access 5 components of an entity.
526
type Map5[A any, B any, C any, D any, E any] struct {
527
        world     *World
528
        ids       []ID
529
        storageA  *componentStorage
530
        storageB  *componentStorage
531
        storageC  *componentStorage
532
        storageD  *componentStorage
533
        storageE  *componentStorage
534
        relations []relationID
535
}
536

537
// NewMap5 creates a new [Map5].
538
func NewMap5[A any, B any, C any, D any, E any](world *World) Map5[A, B, C, D, E] {
8✔
539
        ids := []ID{
8✔
540
                ComponentID[A](world),
8✔
541
                ComponentID[B](world),
8✔
542
                ComponentID[C](world),
8✔
543
                ComponentID[D](world),
8✔
544
                ComponentID[E](world),
8✔
545
        }
8✔
546
        return Map5[A, B, C, D, E]{
8✔
547
                world:    world,
8✔
548
                ids:      ids,
8✔
549
                storageA: &world.storage.components[ids[0].id],
8✔
550
                storageB: &world.storage.components[ids[1].id],
8✔
551
                storageC: &world.storage.components[ids[2].id],
8✔
552
                storageD: &world.storage.components[ids[3].id],
8✔
553
                storageE: &world.storage.components[ids[4].id],
8✔
554
        }
8✔
555
}
8✔
556

557
// NewEntity creates a new entity with the mapped components.
558
func (m *Map5[A, B, C, D, E]) NewEntity(a *A, b *B, c *C, d *D, e *E, rel ...RelationIndex) Entity {
96✔
559
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
96✔
560
        return m.world.newEntityWith(m.ids, []unsafe.Pointer{
96✔
561
                unsafe.Pointer(a),
96✔
562
                unsafe.Pointer(b),
96✔
563
                unsafe.Pointer(c),
96✔
564
                unsafe.Pointer(d),
96✔
565
                unsafe.Pointer(e),
96✔
566
        }, m.relations)
96✔
567
}
96✔
568

569
// NewBatch creates a batch of new entities with the mapped components.
570
func (m *Map5[A, B, C, D, E]) NewBatch(count int, a *A, b *B, c *C, d *D, e *E, rel ...RelationIndex) {
1✔
571
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
1✔
572
        m.world.newEntitiesWith(count, m.ids, []unsafe.Pointer{
1✔
573
                unsafe.Pointer(a),
1✔
574
                unsafe.Pointer(b),
1✔
575
                unsafe.Pointer(c),
1✔
576
                unsafe.Pointer(d),
1✔
577
                unsafe.Pointer(e),
1✔
578
        }, m.relations)
1✔
579
}
1✔
580

581
// NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each.
582
// The initializer function can be nil.
583
func (m *Map5[A, B, C, D, E]) NewBatchFn(count int, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E), rel ...RelationIndex) {
1✔
584
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
1✔
585
        tableID, start := m.world.newEntities(count, m.ids, m.relations)
1✔
586
        if fn == nil {
1✔
587
                return
×
588
        }
×
589

590
        table := &m.world.storage.tables[tableID]
1✔
591
        columnA := m.storageA.columns[tableID]
1✔
592
        columnB := m.storageB.columns[tableID]
1✔
593
        columnC := m.storageC.columns[tableID]
1✔
594
        columnD := m.storageD.columns[tableID]
1✔
595
        columnE := m.storageE.columns[tableID]
1✔
596

1✔
597
        for i := range count {
25✔
598
                index := uintptr(start + i)
24✔
599
                fn(
24✔
600
                        table.GetEntity(index),
24✔
601
                        (*A)(columnA.Get(index)),
24✔
602
                        (*B)(columnB.Get(index)),
24✔
603
                        (*C)(columnC.Get(index)),
24✔
604
                        (*D)(columnD.Get(index)),
24✔
605
                        (*E)(columnE.Get(index)),
24✔
606
                )
24✔
607
        }
24✔
608
}
609

610
// Get returns the mapped components for the given entity.
611
func (m *Map5[A, B, C, D, E]) Get(entity Entity) (*A, *B, *C, *D, *E) {
24✔
612
        if !m.world.Alive(entity) {
24✔
613
                panic("can't get components of a dead entity")
×
614
        }
615
        return m.GetUnchecked(entity)
24✔
616
}
617

618
// GetUnchecked returns the mapped components for the given entity.
619
// It does not check whether the entity is alive.
620
// Can be used as an optimization when it is certain that the entity is alive.
621
func (m *Map5[A, B, C, D, E]) GetUnchecked(entity Entity) (*A, *B, *C, *D, *E) {
24✔
622
        index := m.world.storage.entities[entity.id]
24✔
623
        row := uintptr(index.row)
24✔
624
        checkMapHasComponent(m.storageA, index.table)
24✔
625
        checkMapHasComponent(m.storageB, index.table)
24✔
626
        checkMapHasComponent(m.storageC, index.table)
24✔
627
        checkMapHasComponent(m.storageD, index.table)
24✔
628
        checkMapHasComponent(m.storageE, index.table)
24✔
629

24✔
630
        return (*A)(m.storageA.columns[index.table].Get(row)),
24✔
631
                (*B)(m.storageB.columns[index.table].Get(row)),
24✔
632
                (*C)(m.storageC.columns[index.table].Get(row)),
24✔
633
                (*D)(m.storageD.columns[index.table].Get(row)),
24✔
634
                (*E)(m.storageE.columns[index.table].Get(row))
24✔
635
}
24✔
636

637
// HasAll return whether the given entity has all mapped components.
638
func (m *Map5[A, B, C, D, E]) HasAll(entity Entity) bool {
29✔
639
        if !m.world.Alive(entity) {
29✔
640
                panic("can't check components of a dead entity")
×
641
        }
642
        index := m.world.storage.entities[entity.id]
29✔
643
        return m.storageA.columns[index.table] != nil &&
29✔
644
                m.storageB.columns[index.table] != nil &&
29✔
645
                m.storageC.columns[index.table] != nil &&
29✔
646
                m.storageD.columns[index.table] != nil &&
29✔
647
                m.storageE.columns[index.table] != nil
29✔
648
}
649

650
// Add the mapped components to the given entity.
651
func (m *Map5[A, B, C, D, E]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, rel ...RelationIndex) {
12✔
652
        if !m.world.Alive(entity) {
12✔
653
                panic("can't add components to a dead entity")
×
654
        }
655
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
12✔
656
        m.world.exchange(entity, m.ids, nil, []unsafe.Pointer{
12✔
657
                unsafe.Pointer(a),
12✔
658
                unsafe.Pointer(b),
12✔
659
                unsafe.Pointer(c),
12✔
660
                unsafe.Pointer(d),
12✔
661
                unsafe.Pointer(e),
12✔
662
        }, m.relations)
12✔
663
}
664

665
// Remove the mapped components from the given entity.
666
func (m *Map5[A, B, C, D, E]) Remove(entity Entity) {
24✔
667
        if !m.world.Alive(entity) {
24✔
668
                panic("can't remove components from a dead entity")
×
669
        }
670
        m.world.exchange(entity, nil, m.ids, nil, nil)
24✔
671
}
672

673
// Remove the mapped components from the given entity.
674
func (m *Map5[A, B, C, D, E]) SetRelations(entity Entity, rel ...RelationIndex) {
×
675
        if !m.world.Alive(entity) {
×
676
                panic("can't remove components from a dead entity")
×
677
        }
678
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
679
        m.world.setRelations(entity, m.relations)
×
680
}
681

682
// Map6 is a mapper to access 6 components of an entity.
683
type Map6[A any, B any, C any, D any, E any, F any] struct {
684
        world     *World
685
        ids       []ID
686
        storageA  *componentStorage
687
        storageB  *componentStorage
688
        storageC  *componentStorage
689
        storageD  *componentStorage
690
        storageE  *componentStorage
691
        storageF  *componentStorage
692
        relations []relationID
693
}
694

695
// NewMap6 creates a new [Map6].
696
func NewMap6[A any, B any, C any, D any, E any, F any](world *World) Map6[A, B, C, D, E, F] {
8✔
697
        ids := []ID{
8✔
698
                ComponentID[A](world),
8✔
699
                ComponentID[B](world),
8✔
700
                ComponentID[C](world),
8✔
701
                ComponentID[D](world),
8✔
702
                ComponentID[E](world),
8✔
703
                ComponentID[F](world),
8✔
704
        }
8✔
705
        return Map6[A, B, C, D, E, F]{
8✔
706
                world:    world,
8✔
707
                ids:      ids,
8✔
708
                storageA: &world.storage.components[ids[0].id],
8✔
709
                storageB: &world.storage.components[ids[1].id],
8✔
710
                storageC: &world.storage.components[ids[2].id],
8✔
711
                storageD: &world.storage.components[ids[3].id],
8✔
712
                storageE: &world.storage.components[ids[4].id],
8✔
713
                storageF: &world.storage.components[ids[5].id],
8✔
714
        }
8✔
715
}
8✔
716

717
// NewEntity creates a new entity with the mapped components.
718
func (m *Map6[A, B, C, D, E, F]) NewEntity(a *A, b *B, c *C, d *D, e *E, f *F, rel ...RelationIndex) Entity {
96✔
719
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
96✔
720
        return m.world.newEntityWith(m.ids, []unsafe.Pointer{
96✔
721
                unsafe.Pointer(a),
96✔
722
                unsafe.Pointer(b),
96✔
723
                unsafe.Pointer(c),
96✔
724
                unsafe.Pointer(d),
96✔
725
                unsafe.Pointer(e),
96✔
726
                unsafe.Pointer(f),
96✔
727
        }, m.relations)
96✔
728
}
96✔
729

730
// NewBatch creates a batch of new entities with the mapped components.
731
func (m *Map6[A, B, C, D, E, F]) NewBatch(count int, a *A, b *B, c *C, d *D, e *E, f *F, rel ...RelationIndex) {
1✔
732
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
1✔
733
        m.world.newEntitiesWith(count, m.ids, []unsafe.Pointer{
1✔
734
                unsafe.Pointer(a),
1✔
735
                unsafe.Pointer(b),
1✔
736
                unsafe.Pointer(c),
1✔
737
                unsafe.Pointer(d),
1✔
738
                unsafe.Pointer(e),
1✔
739
                unsafe.Pointer(f),
1✔
740
        }, m.relations)
1✔
741
}
1✔
742

743
// NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each.
744
// The initializer function can be nil.
745
func (m *Map6[A, B, C, D, E, F]) NewBatchFn(count int, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F), rel ...RelationIndex) {
1✔
746
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
1✔
747
        tableID, start := m.world.newEntities(count, m.ids, m.relations)
1✔
748
        if fn == nil {
1✔
749
                return
×
750
        }
×
751

752
        table := &m.world.storage.tables[tableID]
1✔
753
        columnA := m.storageA.columns[tableID]
1✔
754
        columnB := m.storageB.columns[tableID]
1✔
755
        columnC := m.storageC.columns[tableID]
1✔
756
        columnD := m.storageD.columns[tableID]
1✔
757
        columnE := m.storageE.columns[tableID]
1✔
758
        columnF := m.storageF.columns[tableID]
1✔
759

1✔
760
        for i := range count {
25✔
761
                index := uintptr(start + i)
24✔
762
                fn(
24✔
763
                        table.GetEntity(index),
24✔
764
                        (*A)(columnA.Get(index)),
24✔
765
                        (*B)(columnB.Get(index)),
24✔
766
                        (*C)(columnC.Get(index)),
24✔
767
                        (*D)(columnD.Get(index)),
24✔
768
                        (*E)(columnE.Get(index)),
24✔
769
                        (*F)(columnF.Get(index)),
24✔
770
                )
24✔
771
        }
24✔
772
}
773

774
// Get returns the mapped components for the given entity.
775
func (m *Map6[A, B, C, D, E, F]) Get(entity Entity) (*A, *B, *C, *D, *E, *F) {
24✔
776
        if !m.world.Alive(entity) {
24✔
777
                panic("can't get components of a dead entity")
×
778
        }
779
        return m.GetUnchecked(entity)
24✔
780
}
781

782
// GetUnchecked returns the mapped components for the given entity.
783
// It does not check whether the entity is alive.
784
// Can be used as an optimization when it is certain that the entity is alive.
785
func (m *Map6[A, B, C, D, E, F]) GetUnchecked(entity Entity) (*A, *B, *C, *D, *E, *F) {
24✔
786
        index := m.world.storage.entities[entity.id]
24✔
787
        row := uintptr(index.row)
24✔
788
        checkMapHasComponent(m.storageA, index.table)
24✔
789
        checkMapHasComponent(m.storageB, index.table)
24✔
790
        checkMapHasComponent(m.storageC, index.table)
24✔
791
        checkMapHasComponent(m.storageD, index.table)
24✔
792
        checkMapHasComponent(m.storageE, index.table)
24✔
793
        checkMapHasComponent(m.storageF, index.table)
24✔
794

24✔
795
        return (*A)(m.storageA.columns[index.table].Get(row)),
24✔
796
                (*B)(m.storageB.columns[index.table].Get(row)),
24✔
797
                (*C)(m.storageC.columns[index.table].Get(row)),
24✔
798
                (*D)(m.storageD.columns[index.table].Get(row)),
24✔
799
                (*E)(m.storageE.columns[index.table].Get(row)),
24✔
800
                (*F)(m.storageF.columns[index.table].Get(row))
24✔
801
}
24✔
802

803
// HasAll return whether the given entity has all mapped components.
804
func (m *Map6[A, B, C, D, E, F]) HasAll(entity Entity) bool {
29✔
805
        if !m.world.Alive(entity) {
29✔
806
                panic("can't check components of a dead entity")
×
807
        }
808
        index := m.world.storage.entities[entity.id]
29✔
809
        return m.storageA.columns[index.table] != nil &&
29✔
810
                m.storageB.columns[index.table] != nil &&
29✔
811
                m.storageC.columns[index.table] != nil &&
29✔
812
                m.storageD.columns[index.table] != nil &&
29✔
813
                m.storageE.columns[index.table] != nil &&
29✔
814
                m.storageF.columns[index.table] != nil
29✔
815
}
816

817
// Add the mapped components to the given entity.
818
func (m *Map6[A, B, C, D, E, F]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, rel ...RelationIndex) {
12✔
819
        if !m.world.Alive(entity) {
12✔
820
                panic("can't add components to a dead entity")
×
821
        }
822
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
12✔
823
        m.world.exchange(entity, m.ids, nil, []unsafe.Pointer{
12✔
824
                unsafe.Pointer(a),
12✔
825
                unsafe.Pointer(b),
12✔
826
                unsafe.Pointer(c),
12✔
827
                unsafe.Pointer(d),
12✔
828
                unsafe.Pointer(e),
12✔
829
                unsafe.Pointer(f),
12✔
830
        }, m.relations)
12✔
831
}
832

833
// Remove the mapped components from the given entity.
834
func (m *Map6[A, B, C, D, E, F]) Remove(entity Entity) {
24✔
835
        if !m.world.Alive(entity) {
24✔
836
                panic("can't remove components from a dead entity")
×
837
        }
838
        m.world.exchange(entity, nil, m.ids, nil, nil)
24✔
839
}
840

841
// Remove the mapped components from the given entity.
842
func (m *Map6[A, B, C, D, E, F]) SetRelations(entity Entity, rel ...RelationIndex) {
×
843
        if !m.world.Alive(entity) {
×
844
                panic("can't remove components from a dead entity")
×
845
        }
846
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
847
        m.world.setRelations(entity, m.relations)
×
848
}
849

850
// Map7 is a mapper to access 7 components of an entity.
851
type Map7[A any, B any, C any, D any, E any, F any, G any] struct {
852
        world     *World
853
        ids       []ID
854
        storageA  *componentStorage
855
        storageB  *componentStorage
856
        storageC  *componentStorage
857
        storageD  *componentStorage
858
        storageE  *componentStorage
859
        storageF  *componentStorage
860
        storageG  *componentStorage
861
        relations []relationID
862
}
863

864
// NewMap7 creates a new [Map7].
865
func NewMap7[A any, B any, C any, D any, E any, F any, G any](world *World) Map7[A, B, C, D, E, F, G] {
8✔
866
        ids := []ID{
8✔
867
                ComponentID[A](world),
8✔
868
                ComponentID[B](world),
8✔
869
                ComponentID[C](world),
8✔
870
                ComponentID[D](world),
8✔
871
                ComponentID[E](world),
8✔
872
                ComponentID[F](world),
8✔
873
                ComponentID[G](world),
8✔
874
        }
8✔
875
        return Map7[A, B, C, D, E, F, G]{
8✔
876
                world:    world,
8✔
877
                ids:      ids,
8✔
878
                storageA: &world.storage.components[ids[0].id],
8✔
879
                storageB: &world.storage.components[ids[1].id],
8✔
880
                storageC: &world.storage.components[ids[2].id],
8✔
881
                storageD: &world.storage.components[ids[3].id],
8✔
882
                storageE: &world.storage.components[ids[4].id],
8✔
883
                storageF: &world.storage.components[ids[5].id],
8✔
884
                storageG: &world.storage.components[ids[6].id],
8✔
885
        }
8✔
886
}
8✔
887

888
// NewEntity creates a new entity with the mapped components.
889
func (m *Map7[A, B, C, D, E, F, G]) NewEntity(a *A, b *B, c *C, d *D, e *E, f *F, g *G, rel ...RelationIndex) Entity {
96✔
890
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
96✔
891
        return m.world.newEntityWith(m.ids, []unsafe.Pointer{
96✔
892
                unsafe.Pointer(a),
96✔
893
                unsafe.Pointer(b),
96✔
894
                unsafe.Pointer(c),
96✔
895
                unsafe.Pointer(d),
96✔
896
                unsafe.Pointer(e),
96✔
897
                unsafe.Pointer(f),
96✔
898
                unsafe.Pointer(g),
96✔
899
        }, m.relations)
96✔
900
}
96✔
901

902
// NewBatch creates a batch of new entities with the mapped components.
903
func (m *Map7[A, B, C, D, E, F, G]) NewBatch(count int, a *A, b *B, c *C, d *D, e *E, f *F, g *G, rel ...RelationIndex) {
1✔
904
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
1✔
905
        m.world.newEntitiesWith(count, m.ids, []unsafe.Pointer{
1✔
906
                unsafe.Pointer(a),
1✔
907
                unsafe.Pointer(b),
1✔
908
                unsafe.Pointer(c),
1✔
909
                unsafe.Pointer(d),
1✔
910
                unsafe.Pointer(e),
1✔
911
                unsafe.Pointer(f),
1✔
912
                unsafe.Pointer(g),
1✔
913
        }, m.relations)
1✔
914
}
1✔
915

916
// NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each.
917
// The initializer function can be nil.
918
func (m *Map7[A, B, C, D, E, F, G]) NewBatchFn(count int, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G), rel ...RelationIndex) {
1✔
919
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
1✔
920
        tableID, start := m.world.newEntities(count, m.ids, m.relations)
1✔
921
        if fn == nil {
1✔
922
                return
×
923
        }
×
924

925
        table := &m.world.storage.tables[tableID]
1✔
926
        columnA := m.storageA.columns[tableID]
1✔
927
        columnB := m.storageB.columns[tableID]
1✔
928
        columnC := m.storageC.columns[tableID]
1✔
929
        columnD := m.storageD.columns[tableID]
1✔
930
        columnE := m.storageE.columns[tableID]
1✔
931
        columnF := m.storageF.columns[tableID]
1✔
932
        columnG := m.storageG.columns[tableID]
1✔
933

1✔
934
        for i := range count {
25✔
935
                index := uintptr(start + i)
24✔
936
                fn(
24✔
937
                        table.GetEntity(index),
24✔
938
                        (*A)(columnA.Get(index)),
24✔
939
                        (*B)(columnB.Get(index)),
24✔
940
                        (*C)(columnC.Get(index)),
24✔
941
                        (*D)(columnD.Get(index)),
24✔
942
                        (*E)(columnE.Get(index)),
24✔
943
                        (*F)(columnF.Get(index)),
24✔
944
                        (*G)(columnG.Get(index)),
24✔
945
                )
24✔
946
        }
24✔
947
}
948

949
// Get returns the mapped components for the given entity.
950
func (m *Map7[A, B, C, D, E, F, G]) Get(entity Entity) (*A, *B, *C, *D, *E, *F, *G) {
24✔
951
        if !m.world.Alive(entity) {
24✔
952
                panic("can't get components of a dead entity")
×
953
        }
954
        return m.GetUnchecked(entity)
24✔
955
}
956

957
// GetUnchecked returns the mapped components for the given entity.
958
// It does not check whether the entity is alive.
959
// Can be used as an optimization when it is certain that the entity is alive.
960
func (m *Map7[A, B, C, D, E, F, G]) GetUnchecked(entity Entity) (*A, *B, *C, *D, *E, *F, *G) {
24✔
961
        index := m.world.storage.entities[entity.id]
24✔
962
        row := uintptr(index.row)
24✔
963
        checkMapHasComponent(m.storageA, index.table)
24✔
964
        checkMapHasComponent(m.storageB, index.table)
24✔
965
        checkMapHasComponent(m.storageC, index.table)
24✔
966
        checkMapHasComponent(m.storageD, index.table)
24✔
967
        checkMapHasComponent(m.storageE, index.table)
24✔
968
        checkMapHasComponent(m.storageF, index.table)
24✔
969
        checkMapHasComponent(m.storageG, index.table)
24✔
970

24✔
971
        return (*A)(m.storageA.columns[index.table].Get(row)),
24✔
972
                (*B)(m.storageB.columns[index.table].Get(row)),
24✔
973
                (*C)(m.storageC.columns[index.table].Get(row)),
24✔
974
                (*D)(m.storageD.columns[index.table].Get(row)),
24✔
975
                (*E)(m.storageE.columns[index.table].Get(row)),
24✔
976
                (*F)(m.storageF.columns[index.table].Get(row)),
24✔
977
                (*G)(m.storageG.columns[index.table].Get(row))
24✔
978
}
24✔
979

980
// HasAll return whether the given entity has all mapped components.
981
func (m *Map7[A, B, C, D, E, F, G]) HasAll(entity Entity) bool {
29✔
982
        if !m.world.Alive(entity) {
29✔
983
                panic("can't check components of a dead entity")
×
984
        }
985
        index := m.world.storage.entities[entity.id]
29✔
986
        return m.storageA.columns[index.table] != nil &&
29✔
987
                m.storageB.columns[index.table] != nil &&
29✔
988
                m.storageC.columns[index.table] != nil &&
29✔
989
                m.storageD.columns[index.table] != nil &&
29✔
990
                m.storageE.columns[index.table] != nil &&
29✔
991
                m.storageF.columns[index.table] != nil &&
29✔
992
                m.storageG.columns[index.table] != nil
29✔
993
}
994

995
// Add the mapped components to the given entity.
996
func (m *Map7[A, B, C, D, E, F, G]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, rel ...RelationIndex) {
12✔
997
        if !m.world.Alive(entity) {
12✔
998
                panic("can't add components to a dead entity")
×
999
        }
1000
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
12✔
1001
        m.world.exchange(entity, m.ids, nil, []unsafe.Pointer{
12✔
1002
                unsafe.Pointer(a),
12✔
1003
                unsafe.Pointer(b),
12✔
1004
                unsafe.Pointer(c),
12✔
1005
                unsafe.Pointer(d),
12✔
1006
                unsafe.Pointer(e),
12✔
1007
                unsafe.Pointer(f),
12✔
1008
                unsafe.Pointer(g),
12✔
1009
        }, m.relations)
12✔
1010
}
1011

1012
// Remove the mapped components from the given entity.
1013
func (m *Map7[A, B, C, D, E, F, G]) Remove(entity Entity) {
24✔
1014
        if !m.world.Alive(entity) {
24✔
1015
                panic("can't remove components from a dead entity")
×
1016
        }
1017
        m.world.exchange(entity, nil, m.ids, nil, nil)
24✔
1018
}
1019

1020
// Remove the mapped components from the given entity.
1021
func (m *Map7[A, B, C, D, E, F, G]) SetRelations(entity Entity, rel ...RelationIndex) {
×
1022
        if !m.world.Alive(entity) {
×
1023
                panic("can't remove components from a dead entity")
×
1024
        }
1025
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
1026
        m.world.setRelations(entity, m.relations)
×
1027
}
1028

1029
// Map8 is a mapper to access 8 components of an entity.
1030
type Map8[A any, B any, C any, D any, E any, F any, G any, H any] struct {
1031
        world     *World
1032
        ids       []ID
1033
        storageA  *componentStorage
1034
        storageB  *componentStorage
1035
        storageC  *componentStorage
1036
        storageD  *componentStorage
1037
        storageE  *componentStorage
1038
        storageF  *componentStorage
1039
        storageG  *componentStorage
1040
        storageH  *componentStorage
1041
        relations []relationID
1042
}
1043

1044
// NewMap8 creates a new [Map8].
1045
func NewMap8[A any, B any, C any, D any, E any, F any, G any, H any](world *World) Map8[A, B, C, D, E, F, G, H] {
8✔
1046
        ids := []ID{
8✔
1047
                ComponentID[A](world),
8✔
1048
                ComponentID[B](world),
8✔
1049
                ComponentID[C](world),
8✔
1050
                ComponentID[D](world),
8✔
1051
                ComponentID[E](world),
8✔
1052
                ComponentID[F](world),
8✔
1053
                ComponentID[G](world),
8✔
1054
                ComponentID[H](world),
8✔
1055
        }
8✔
1056
        return Map8[A, B, C, D, E, F, G, H]{
8✔
1057
                world:    world,
8✔
1058
                ids:      ids,
8✔
1059
                storageA: &world.storage.components[ids[0].id],
8✔
1060
                storageB: &world.storage.components[ids[1].id],
8✔
1061
                storageC: &world.storage.components[ids[2].id],
8✔
1062
                storageD: &world.storage.components[ids[3].id],
8✔
1063
                storageE: &world.storage.components[ids[4].id],
8✔
1064
                storageF: &world.storage.components[ids[5].id],
8✔
1065
                storageG: &world.storage.components[ids[6].id],
8✔
1066
                storageH: &world.storage.components[ids[7].id],
8✔
1067
        }
8✔
1068
}
8✔
1069

1070
// NewEntity creates a new entity with the mapped components.
1071
func (m *Map8[A, B, C, D, E, F, G, H]) NewEntity(a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, rel ...RelationIndex) Entity {
96✔
1072
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
96✔
1073
        return m.world.newEntityWith(m.ids, []unsafe.Pointer{
96✔
1074
                unsafe.Pointer(a),
96✔
1075
                unsafe.Pointer(b),
96✔
1076
                unsafe.Pointer(c),
96✔
1077
                unsafe.Pointer(d),
96✔
1078
                unsafe.Pointer(e),
96✔
1079
                unsafe.Pointer(f),
96✔
1080
                unsafe.Pointer(g),
96✔
1081
                unsafe.Pointer(h),
96✔
1082
        }, m.relations)
96✔
1083
}
96✔
1084

1085
// NewBatch creates a batch of new entities with the mapped components.
1086
func (m *Map8[A, B, C, D, E, F, G, H]) NewBatch(count int, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, rel ...RelationIndex) {
1✔
1087
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
1✔
1088
        m.world.newEntitiesWith(count, m.ids, []unsafe.Pointer{
1✔
1089
                unsafe.Pointer(a),
1✔
1090
                unsafe.Pointer(b),
1✔
1091
                unsafe.Pointer(c),
1✔
1092
                unsafe.Pointer(d),
1✔
1093
                unsafe.Pointer(e),
1✔
1094
                unsafe.Pointer(f),
1✔
1095
                unsafe.Pointer(g),
1✔
1096
                unsafe.Pointer(h),
1✔
1097
        }, m.relations)
1✔
1098
}
1✔
1099

1100
// NewBatchFn creates a batch of new entities with the mapped components, running the given initializer function on each.
1101
// The initializer function can be nil.
1102
func (m *Map8[A, B, C, D, E, F, G, H]) NewBatchFn(count int, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H), rel ...RelationIndex) {
1✔
1103
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
1✔
1104
        tableID, start := m.world.newEntities(count, m.ids, m.relations)
1✔
1105
        if fn == nil {
1✔
1106
                return
×
1107
        }
×
1108

1109
        table := &m.world.storage.tables[tableID]
1✔
1110
        columnA := m.storageA.columns[tableID]
1✔
1111
        columnB := m.storageB.columns[tableID]
1✔
1112
        columnC := m.storageC.columns[tableID]
1✔
1113
        columnD := m.storageD.columns[tableID]
1✔
1114
        columnE := m.storageE.columns[tableID]
1✔
1115
        columnF := m.storageF.columns[tableID]
1✔
1116
        columnG := m.storageG.columns[tableID]
1✔
1117
        columnH := m.storageH.columns[tableID]
1✔
1118

1✔
1119
        for i := range count {
25✔
1120
                index := uintptr(start + i)
24✔
1121
                fn(
24✔
1122
                        table.GetEntity(index),
24✔
1123
                        (*A)(columnA.Get(index)),
24✔
1124
                        (*B)(columnB.Get(index)),
24✔
1125
                        (*C)(columnC.Get(index)),
24✔
1126
                        (*D)(columnD.Get(index)),
24✔
1127
                        (*E)(columnE.Get(index)),
24✔
1128
                        (*F)(columnF.Get(index)),
24✔
1129
                        (*G)(columnG.Get(index)),
24✔
1130
                        (*H)(columnH.Get(index)),
24✔
1131
                )
24✔
1132
        }
24✔
1133
}
1134

1135
// Get returns the mapped components for the given entity.
1136
func (m *Map8[A, B, C, D, E, F, G, H]) Get(entity Entity) (*A, *B, *C, *D, *E, *F, *G, *H) {
24✔
1137
        if !m.world.Alive(entity) {
24✔
1138
                panic("can't get components of a dead entity")
×
1139
        }
1140
        return m.GetUnchecked(entity)
24✔
1141
}
1142

1143
// GetUnchecked returns the mapped components for the given entity.
1144
// It does not check whether the entity is alive.
1145
// Can be used as an optimization when it is certain that the entity is alive.
1146
func (m *Map8[A, B, C, D, E, F, G, H]) GetUnchecked(entity Entity) (*A, *B, *C, *D, *E, *F, *G, *H) {
24✔
1147
        index := m.world.storage.entities[entity.id]
24✔
1148
        row := uintptr(index.row)
24✔
1149
        checkMapHasComponent(m.storageA, index.table)
24✔
1150
        checkMapHasComponent(m.storageB, index.table)
24✔
1151
        checkMapHasComponent(m.storageC, index.table)
24✔
1152
        checkMapHasComponent(m.storageD, index.table)
24✔
1153
        checkMapHasComponent(m.storageE, index.table)
24✔
1154
        checkMapHasComponent(m.storageF, index.table)
24✔
1155
        checkMapHasComponent(m.storageG, index.table)
24✔
1156
        checkMapHasComponent(m.storageH, index.table)
24✔
1157

24✔
1158
        return (*A)(m.storageA.columns[index.table].Get(row)),
24✔
1159
                (*B)(m.storageB.columns[index.table].Get(row)),
24✔
1160
                (*C)(m.storageC.columns[index.table].Get(row)),
24✔
1161
                (*D)(m.storageD.columns[index.table].Get(row)),
24✔
1162
                (*E)(m.storageE.columns[index.table].Get(row)),
24✔
1163
                (*F)(m.storageF.columns[index.table].Get(row)),
24✔
1164
                (*G)(m.storageG.columns[index.table].Get(row)),
24✔
1165
                (*H)(m.storageH.columns[index.table].Get(row))
24✔
1166
}
24✔
1167

1168
// HasAll return whether the given entity has all mapped components.
1169
func (m *Map8[A, B, C, D, E, F, G, H]) HasAll(entity Entity) bool {
29✔
1170
        if !m.world.Alive(entity) {
29✔
1171
                panic("can't check components of a dead entity")
×
1172
        }
1173
        index := m.world.storage.entities[entity.id]
29✔
1174
        return m.storageA.columns[index.table] != nil &&
29✔
1175
                m.storageB.columns[index.table] != nil &&
29✔
1176
                m.storageC.columns[index.table] != nil &&
29✔
1177
                m.storageD.columns[index.table] != nil &&
29✔
1178
                m.storageE.columns[index.table] != nil &&
29✔
1179
                m.storageF.columns[index.table] != nil &&
29✔
1180
                m.storageG.columns[index.table] != nil &&
29✔
1181
                m.storageH.columns[index.table] != nil
29✔
1182
}
1183

1184
// Add the mapped components to the given entity.
1185
func (m *Map8[A, B, C, D, E, F, G, H]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, rel ...RelationIndex) {
12✔
1186
        if !m.world.Alive(entity) {
12✔
1187
                panic("can't add components to a dead entity")
×
1188
        }
1189
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
12✔
1190
        m.world.exchange(entity, m.ids, nil, []unsafe.Pointer{
12✔
1191
                unsafe.Pointer(a),
12✔
1192
                unsafe.Pointer(b),
12✔
1193
                unsafe.Pointer(c),
12✔
1194
                unsafe.Pointer(d),
12✔
1195
                unsafe.Pointer(e),
12✔
1196
                unsafe.Pointer(f),
12✔
1197
                unsafe.Pointer(g),
12✔
1198
                unsafe.Pointer(h),
12✔
1199
        }, m.relations)
12✔
1200
}
1201

1202
// Remove the mapped components from the given entity.
1203
func (m *Map8[A, B, C, D, E, F, G, H]) Remove(entity Entity) {
24✔
1204
        if !m.world.Alive(entity) {
24✔
1205
                panic("can't remove components from a dead entity")
×
1206
        }
1207
        m.world.exchange(entity, nil, m.ids, nil, nil)
24✔
1208
}
1209

1210
// Remove the mapped components from the given entity.
1211
func (m *Map8[A, B, C, D, E, F, G, H]) SetRelations(entity Entity, rel ...RelationIndex) {
×
1212
        if !m.world.Alive(entity) {
×
1213
                panic("can't remove components from a dead entity")
×
1214
        }
1215
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
1216
        m.world.setRelations(entity, m.relations)
×
1217
}
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