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

mlange-42 / ark / 13521963365

25 Feb 2025 01:07PM CUT coverage: 69.617%. First build
13521963365

Pull #67

github

web-flow
Merge fb3821f8a into 5e435fa80
Pull Request #67: Code-gen tests for queries

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

2470 of 3548 relevant lines covered (69.62%)

50922.97 hits per line

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

31.9
/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] {
3✔
17
        ids := []ID{
3✔
18
                ComponentID[A](world),
3✔
19
        }
3✔
20
        return Map1[A]{
3✔
21
                world:    world,
3✔
22
                ids:      ids,
3✔
23
                storageA: &world.storage.components[ids[0].id],
3✔
24
        }
3✔
25
}
3✔
26

27
// NewEntity creates a new entity with the mapped components.
28
func (m *Map1[A]) NewEntity(a *A, rel ...RelationIndex) Entity {
60✔
29
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
60✔
30
        return m.world.newEntityWith(m.ids, []unsafe.Pointer{
60✔
31
                unsafe.Pointer(a),
60✔
32
        }, m.relations)
60✔
33
}
60✔
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) {
×
37
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
38
        m.world.newEntitiesWith(count, m.ids, []unsafe.Pointer{
×
39
                unsafe.Pointer(a),
×
40
        }, m.relations)
×
41
}
×
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) {
×
46
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
47
        tableID, start := m.world.newEntities(count, m.ids, m.relations)
×
48
        if fn == nil {
×
49
                return
×
50
        }
×
51

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

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

64
// Get returns the mapped components for the given entity.
65
func (m *Map1[A]) Get(entity Entity) *A {
×
66
        if !m.world.Alive(entity) {
×
67
                panic("can't get components of a dead entity")
×
68
        }
69
        return m.GetUnchecked(entity)
×
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 {
×
76
        index := m.world.storage.entities[entity.id]
×
77
        row := uintptr(index.row)
×
78
        checkMapHasComponent(m.storageA, index.table)
×
79

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

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

92
// Add the mapped components to the given entity.
93
func (m *Map1[A]) Add(entity Entity, a *A, rel ...RelationIndex) {
1✔
94
        if !m.world.Alive(entity) {
1✔
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)
1✔
98
        m.world.exchange(entity, m.ids, nil, []unsafe.Pointer{
1✔
99
                unsafe.Pointer(a),
1✔
100
        }, m.relations)
1✔
101
}
102

103
// Remove the mapped components from the given entity.
104
func (m *Map1[A]) Remove(entity Entity) {
×
105
        if !m.world.Alive(entity) {
×
106
                panic("can't remove components from a dead entity")
×
107
        }
108
        m.world.exchange(entity, nil, m.ids, nil, nil)
×
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] {
9✔
131
        ids := []ID{
9✔
132
                ComponentID[A](world),
9✔
133
                ComponentID[B](world),
9✔
134
        }
9✔
135
        return Map2[A, B]{
9✔
136
                world:    world,
9✔
137
                ids:      ids,
9✔
138
                storageA: &world.storage.components[ids[0].id],
9✔
139
                storageB: &world.storage.components[ids[1].id],
9✔
140
        }
9✔
141
}
9✔
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 {
220✔
145
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
220✔
146
        return m.world.newEntityWith(m.ids, []unsafe.Pointer{
220✔
147
                unsafe.Pointer(a),
220✔
148
                unsafe.Pointer(b),
220✔
149
        }, m.relations)
220✔
150
}
220✔
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) {
13✔
186
        if !m.world.Alive(entity) {
13✔
187
                panic("can't get components of a dead entity")
×
188
        }
189
        return m.GetUnchecked(entity)
13✔
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) {
13✔
196
        index := m.world.storage.entities[entity.id]
13✔
197
        row := uintptr(index.row)
13✔
198
        checkMapHasComponent(m.storageA, index.table)
13✔
199
        checkMapHasComponent(m.storageB, index.table)
13✔
200

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

205
// HasAll return whether the given entity has all mapped components.
206
func (m *Map2[A, B]) HasAll(entity Entity) bool {
14✔
207
        if !m.world.Alive(entity) {
14✔
208
                panic("can't check components of a dead entity")
×
209
        }
210
        index := m.world.storage.entities[entity.id]
14✔
211
        return m.storageA.columns[index.table] != nil &&
14✔
212
                m.storageB.columns[index.table] != nil
14✔
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) {
12✔
229
        if !m.world.Alive(entity) {
12✔
230
                panic("can't remove components from a dead entity")
×
231
        }
232
        m.world.exchange(entity, nil, m.ids, nil, nil)
12✔
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] {
3✔
256
        ids := []ID{
3✔
257
                ComponentID[A](world),
3✔
258
                ComponentID[B](world),
3✔
259
                ComponentID[C](world),
3✔
260
        }
3✔
261
        return Map3[A, B, C]{
3✔
262
                world:    world,
3✔
263
                ids:      ids,
3✔
264
                storageA: &world.storage.components[ids[0].id],
3✔
265
                storageB: &world.storage.components[ids[1].id],
3✔
266
                storageC: &world.storage.components[ids[2].id],
3✔
267
        }
3✔
268
}
3✔
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 {
100✔
272
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
100✔
273
        return m.world.newEntityWith(m.ids, []unsafe.Pointer{
100✔
274
                unsafe.Pointer(a),
100✔
275
                unsafe.Pointer(b),
100✔
276
                unsafe.Pointer(c),
100✔
277
        }, m.relations)
100✔
278
}
100✔
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) {
×
282
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
283
        m.world.newEntitiesWith(count, m.ids, []unsafe.Pointer{
×
284
                unsafe.Pointer(a),
×
285
                unsafe.Pointer(b),
×
286
                unsafe.Pointer(c),
×
287
        }, m.relations)
×
288
}
×
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) {
×
293
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
294
        tableID, start := m.world.newEntities(count, m.ids, m.relations)
×
295
        if fn == nil {
×
296
                return
×
297
        }
×
298

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

×
304
        for i := range count {
×
305
                index := uintptr(start + i)
×
306
                fn(
×
307
                        table.GetEntity(index),
×
308
                        (*A)(columnA.Get(index)),
×
309
                        (*B)(columnB.Get(index)),
×
310
                        (*C)(columnC.Get(index)),
×
311
                )
×
312
        }
×
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) {
×
317
        if !m.world.Alive(entity) {
×
318
                panic("can't get components of a dead entity")
×
319
        }
320
        return m.GetUnchecked(entity)
×
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) {
×
327
        index := m.world.storage.entities[entity.id]
×
328
        row := uintptr(index.row)
×
329
        checkMapHasComponent(m.storageA, index.table)
×
330
        checkMapHasComponent(m.storageB, index.table)
×
331
        checkMapHasComponent(m.storageC, index.table)
×
332

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

338
// HasAll return whether the given entity has all mapped components.
339
func (m *Map3[A, B, C]) HasAll(entity Entity) bool {
×
340
        if !m.world.Alive(entity) {
×
341
                panic("can't check components of a dead entity")
×
342
        }
343
        index := m.world.storage.entities[entity.id]
×
344
        return m.storageA.columns[index.table] != nil &&
×
345
                m.storageB.columns[index.table] != nil &&
×
346
                m.storageC.columns[index.table] != nil
×
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) {
×
351
        if !m.world.Alive(entity) {
×
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)
×
355
        m.world.exchange(entity, m.ids, nil, []unsafe.Pointer{
×
356
                unsafe.Pointer(a),
×
357
                unsafe.Pointer(b),
×
358
                unsafe.Pointer(c),
×
359
        }, m.relations)
×
360
}
361

362
// Remove the mapped components from the given entity.
363
func (m *Map3[A, B, C]) Remove(entity Entity) {
×
364
        if !m.world.Alive(entity) {
×
365
                panic("can't remove components from a dead entity")
×
366
        }
367
        m.world.exchange(entity, nil, m.ids, nil, nil)
×
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] {
2✔
392
        ids := []ID{
2✔
393
                ComponentID[A](world),
2✔
394
                ComponentID[B](world),
2✔
395
                ComponentID[C](world),
2✔
396
                ComponentID[D](world),
2✔
397
        }
2✔
398
        return Map4[A, B, C, D]{
2✔
399
                world:    world,
2✔
400
                ids:      ids,
2✔
401
                storageA: &world.storage.components[ids[0].id],
2✔
402
                storageB: &world.storage.components[ids[1].id],
2✔
403
                storageC: &world.storage.components[ids[2].id],
2✔
404
                storageD: &world.storage.components[ids[3].id],
2✔
405
        }
2✔
406
}
2✔
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 {
60✔
410
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
60✔
411
        return m.world.newEntityWith(m.ids, []unsafe.Pointer{
60✔
412
                unsafe.Pointer(a),
60✔
413
                unsafe.Pointer(b),
60✔
414
                unsafe.Pointer(c),
60✔
415
                unsafe.Pointer(d),
60✔
416
        }, m.relations)
60✔
417
}
60✔
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) {
×
421
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
422
        m.world.newEntitiesWith(count, m.ids, []unsafe.Pointer{
×
423
                unsafe.Pointer(a),
×
424
                unsafe.Pointer(b),
×
425
                unsafe.Pointer(c),
×
426
                unsafe.Pointer(d),
×
427
        }, m.relations)
×
428
}
×
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) {
×
433
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
434
        tableID, start := m.world.newEntities(count, m.ids, m.relations)
×
435
        if fn == nil {
×
436
                return
×
437
        }
×
438

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

×
445
        for i := range count {
×
446
                index := uintptr(start + i)
×
447
                fn(
×
448
                        table.GetEntity(index),
×
449
                        (*A)(columnA.Get(index)),
×
450
                        (*B)(columnB.Get(index)),
×
451
                        (*C)(columnC.Get(index)),
×
452
                        (*D)(columnD.Get(index)),
×
453
                )
×
454
        }
×
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) {
×
459
        if !m.world.Alive(entity) {
×
460
                panic("can't get components of a dead entity")
×
461
        }
462
        return m.GetUnchecked(entity)
×
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) {
×
469
        index := m.world.storage.entities[entity.id]
×
470
        row := uintptr(index.row)
×
471
        checkMapHasComponent(m.storageA, index.table)
×
472
        checkMapHasComponent(m.storageB, index.table)
×
473
        checkMapHasComponent(m.storageC, index.table)
×
474
        checkMapHasComponent(m.storageD, index.table)
×
475

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

482
// HasAll return whether the given entity has all mapped components.
483
func (m *Map4[A, B, C, D]) HasAll(entity Entity) bool {
×
484
        if !m.world.Alive(entity) {
×
485
                panic("can't check components of a dead entity")
×
486
        }
487
        index := m.world.storage.entities[entity.id]
×
488
        return m.storageA.columns[index.table] != nil &&
×
489
                m.storageB.columns[index.table] != nil &&
×
490
                m.storageC.columns[index.table] != nil &&
×
491
                m.storageD.columns[index.table] != nil
×
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) {
×
496
        if !m.world.Alive(entity) {
×
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)
×
500
        m.world.exchange(entity, m.ids, nil, []unsafe.Pointer{
×
501
                unsafe.Pointer(a),
×
502
                unsafe.Pointer(b),
×
503
                unsafe.Pointer(c),
×
504
                unsafe.Pointer(d),
×
505
        }, m.relations)
×
506
}
507

508
// Remove the mapped components from the given entity.
509
func (m *Map4[A, B, C, D]) Remove(entity Entity) {
×
510
        if !m.world.Alive(entity) {
×
511
                panic("can't remove components from a dead entity")
×
512
        }
513
        m.world.exchange(entity, nil, m.ids, nil, nil)
×
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] {
2✔
539
        ids := []ID{
2✔
540
                ComponentID[A](world),
2✔
541
                ComponentID[B](world),
2✔
542
                ComponentID[C](world),
2✔
543
                ComponentID[D](world),
2✔
544
                ComponentID[E](world),
2✔
545
        }
2✔
546
        return Map5[A, B, C, D, E]{
2✔
547
                world:    world,
2✔
548
                ids:      ids,
2✔
549
                storageA: &world.storage.components[ids[0].id],
2✔
550
                storageB: &world.storage.components[ids[1].id],
2✔
551
                storageC: &world.storage.components[ids[2].id],
2✔
552
                storageD: &world.storage.components[ids[3].id],
2✔
553
                storageE: &world.storage.components[ids[4].id],
2✔
554
        }
2✔
555
}
2✔
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 {
60✔
559
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
60✔
560
        return m.world.newEntityWith(m.ids, []unsafe.Pointer{
60✔
561
                unsafe.Pointer(a),
60✔
562
                unsafe.Pointer(b),
60✔
563
                unsafe.Pointer(c),
60✔
564
                unsafe.Pointer(d),
60✔
565
                unsafe.Pointer(e),
60✔
566
        }, m.relations)
60✔
567
}
60✔
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) {
×
571
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
572
        m.world.newEntitiesWith(count, m.ids, []unsafe.Pointer{
×
573
                unsafe.Pointer(a),
×
574
                unsafe.Pointer(b),
×
575
                unsafe.Pointer(c),
×
576
                unsafe.Pointer(d),
×
577
                unsafe.Pointer(e),
×
578
        }, m.relations)
×
579
}
×
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) {
×
584
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
585
        tableID, start := m.world.newEntities(count, m.ids, m.relations)
×
586
        if fn == nil {
×
587
                return
×
588
        }
×
589

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

×
597
        for i := range count {
×
598
                index := uintptr(start + i)
×
599
                fn(
×
600
                        table.GetEntity(index),
×
601
                        (*A)(columnA.Get(index)),
×
602
                        (*B)(columnB.Get(index)),
×
603
                        (*C)(columnC.Get(index)),
×
604
                        (*D)(columnD.Get(index)),
×
605
                        (*E)(columnE.Get(index)),
×
606
                )
×
607
        }
×
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) {
×
612
        if !m.world.Alive(entity) {
×
613
                panic("can't get components of a dead entity")
×
614
        }
615
        return m.GetUnchecked(entity)
×
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) {
×
622
        index := m.world.storage.entities[entity.id]
×
623
        row := uintptr(index.row)
×
624
        checkMapHasComponent(m.storageA, index.table)
×
625
        checkMapHasComponent(m.storageB, index.table)
×
626
        checkMapHasComponent(m.storageC, index.table)
×
627
        checkMapHasComponent(m.storageD, index.table)
×
628
        checkMapHasComponent(m.storageE, index.table)
×
629

×
630
        return (*A)(m.storageA.columns[index.table].Get(row)),
×
631
                (*B)(m.storageB.columns[index.table].Get(row)),
×
632
                (*C)(m.storageC.columns[index.table].Get(row)),
×
633
                (*D)(m.storageD.columns[index.table].Get(row)),
×
634
                (*E)(m.storageE.columns[index.table].Get(row))
×
635
}
×
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 {
×
639
        if !m.world.Alive(entity) {
×
640
                panic("can't check components of a dead entity")
×
641
        }
642
        index := m.world.storage.entities[entity.id]
×
643
        return m.storageA.columns[index.table] != nil &&
×
644
                m.storageB.columns[index.table] != nil &&
×
645
                m.storageC.columns[index.table] != nil &&
×
646
                m.storageD.columns[index.table] != nil &&
×
647
                m.storageE.columns[index.table] != nil
×
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) {
×
652
        if !m.world.Alive(entity) {
×
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)
×
656
        m.world.exchange(entity, m.ids, nil, []unsafe.Pointer{
×
657
                unsafe.Pointer(a),
×
658
                unsafe.Pointer(b),
×
659
                unsafe.Pointer(c),
×
660
                unsafe.Pointer(d),
×
661
                unsafe.Pointer(e),
×
662
        }, m.relations)
×
663
}
664

665
// Remove the mapped components from the given entity.
666
func (m *Map5[A, B, C, D, E]) Remove(entity Entity) {
×
667
        if !m.world.Alive(entity) {
×
668
                panic("can't remove components from a dead entity")
×
669
        }
670
        m.world.exchange(entity, nil, m.ids, nil, nil)
×
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] {
2✔
697
        ids := []ID{
2✔
698
                ComponentID[A](world),
2✔
699
                ComponentID[B](world),
2✔
700
                ComponentID[C](world),
2✔
701
                ComponentID[D](world),
2✔
702
                ComponentID[E](world),
2✔
703
                ComponentID[F](world),
2✔
704
        }
2✔
705
        return Map6[A, B, C, D, E, F]{
2✔
706
                world:    world,
2✔
707
                ids:      ids,
2✔
708
                storageA: &world.storage.components[ids[0].id],
2✔
709
                storageB: &world.storage.components[ids[1].id],
2✔
710
                storageC: &world.storage.components[ids[2].id],
2✔
711
                storageD: &world.storage.components[ids[3].id],
2✔
712
                storageE: &world.storage.components[ids[4].id],
2✔
713
                storageF: &world.storage.components[ids[5].id],
2✔
714
        }
2✔
715
}
2✔
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 {
60✔
719
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
60✔
720
        return m.world.newEntityWith(m.ids, []unsafe.Pointer{
60✔
721
                unsafe.Pointer(a),
60✔
722
                unsafe.Pointer(b),
60✔
723
                unsafe.Pointer(c),
60✔
724
                unsafe.Pointer(d),
60✔
725
                unsafe.Pointer(e),
60✔
726
                unsafe.Pointer(f),
60✔
727
        }, m.relations)
60✔
728
}
60✔
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) {
×
732
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
733
        m.world.newEntitiesWith(count, m.ids, []unsafe.Pointer{
×
734
                unsafe.Pointer(a),
×
735
                unsafe.Pointer(b),
×
736
                unsafe.Pointer(c),
×
737
                unsafe.Pointer(d),
×
738
                unsafe.Pointer(e),
×
739
                unsafe.Pointer(f),
×
740
        }, m.relations)
×
741
}
×
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) {
×
746
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
747
        tableID, start := m.world.newEntities(count, m.ids, m.relations)
×
748
        if fn == nil {
×
749
                return
×
750
        }
×
751

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

×
760
        for i := range count {
×
761
                index := uintptr(start + i)
×
762
                fn(
×
763
                        table.GetEntity(index),
×
764
                        (*A)(columnA.Get(index)),
×
765
                        (*B)(columnB.Get(index)),
×
766
                        (*C)(columnC.Get(index)),
×
767
                        (*D)(columnD.Get(index)),
×
768
                        (*E)(columnE.Get(index)),
×
769
                        (*F)(columnF.Get(index)),
×
770
                )
×
771
        }
×
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) {
×
776
        if !m.world.Alive(entity) {
×
777
                panic("can't get components of a dead entity")
×
778
        }
779
        return m.GetUnchecked(entity)
×
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) {
×
786
        index := m.world.storage.entities[entity.id]
×
787
        row := uintptr(index.row)
×
788
        checkMapHasComponent(m.storageA, index.table)
×
789
        checkMapHasComponent(m.storageB, index.table)
×
790
        checkMapHasComponent(m.storageC, index.table)
×
791
        checkMapHasComponent(m.storageD, index.table)
×
792
        checkMapHasComponent(m.storageE, index.table)
×
793
        checkMapHasComponent(m.storageF, index.table)
×
794

×
795
        return (*A)(m.storageA.columns[index.table].Get(row)),
×
796
                (*B)(m.storageB.columns[index.table].Get(row)),
×
797
                (*C)(m.storageC.columns[index.table].Get(row)),
×
798
                (*D)(m.storageD.columns[index.table].Get(row)),
×
799
                (*E)(m.storageE.columns[index.table].Get(row)),
×
800
                (*F)(m.storageF.columns[index.table].Get(row))
×
801
}
×
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 {
×
805
        if !m.world.Alive(entity) {
×
806
                panic("can't check components of a dead entity")
×
807
        }
808
        index := m.world.storage.entities[entity.id]
×
809
        return m.storageA.columns[index.table] != nil &&
×
810
                m.storageB.columns[index.table] != nil &&
×
811
                m.storageC.columns[index.table] != nil &&
×
812
                m.storageD.columns[index.table] != nil &&
×
813
                m.storageE.columns[index.table] != nil &&
×
814
                m.storageF.columns[index.table] != nil
×
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) {
×
819
        if !m.world.Alive(entity) {
×
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)
×
823
        m.world.exchange(entity, m.ids, nil, []unsafe.Pointer{
×
824
                unsafe.Pointer(a),
×
825
                unsafe.Pointer(b),
×
826
                unsafe.Pointer(c),
×
827
                unsafe.Pointer(d),
×
828
                unsafe.Pointer(e),
×
829
                unsafe.Pointer(f),
×
830
        }, m.relations)
×
831
}
832

833
// Remove the mapped components from the given entity.
834
func (m *Map6[A, B, C, D, E, F]) Remove(entity Entity) {
×
835
        if !m.world.Alive(entity) {
×
836
                panic("can't remove components from a dead entity")
×
837
        }
838
        m.world.exchange(entity, nil, m.ids, nil, nil)
×
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] {
2✔
866
        ids := []ID{
2✔
867
                ComponentID[A](world),
2✔
868
                ComponentID[B](world),
2✔
869
                ComponentID[C](world),
2✔
870
                ComponentID[D](world),
2✔
871
                ComponentID[E](world),
2✔
872
                ComponentID[F](world),
2✔
873
                ComponentID[G](world),
2✔
874
        }
2✔
875
        return Map7[A, B, C, D, E, F, G]{
2✔
876
                world:    world,
2✔
877
                ids:      ids,
2✔
878
                storageA: &world.storage.components[ids[0].id],
2✔
879
                storageB: &world.storage.components[ids[1].id],
2✔
880
                storageC: &world.storage.components[ids[2].id],
2✔
881
                storageD: &world.storage.components[ids[3].id],
2✔
882
                storageE: &world.storage.components[ids[4].id],
2✔
883
                storageF: &world.storage.components[ids[5].id],
2✔
884
                storageG: &world.storage.components[ids[6].id],
2✔
885
        }
2✔
886
}
2✔
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 {
60✔
890
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
60✔
891
        return m.world.newEntityWith(m.ids, []unsafe.Pointer{
60✔
892
                unsafe.Pointer(a),
60✔
893
                unsafe.Pointer(b),
60✔
894
                unsafe.Pointer(c),
60✔
895
                unsafe.Pointer(d),
60✔
896
                unsafe.Pointer(e),
60✔
897
                unsafe.Pointer(f),
60✔
898
                unsafe.Pointer(g),
60✔
899
        }, m.relations)
60✔
900
}
60✔
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) {
×
904
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
905
        m.world.newEntitiesWith(count, m.ids, []unsafe.Pointer{
×
906
                unsafe.Pointer(a),
×
907
                unsafe.Pointer(b),
×
908
                unsafe.Pointer(c),
×
909
                unsafe.Pointer(d),
×
910
                unsafe.Pointer(e),
×
911
                unsafe.Pointer(f),
×
912
                unsafe.Pointer(g),
×
913
        }, m.relations)
×
914
}
×
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) {
×
919
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
920
        tableID, start := m.world.newEntities(count, m.ids, m.relations)
×
921
        if fn == nil {
×
922
                return
×
923
        }
×
924

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

×
934
        for i := range count {
×
935
                index := uintptr(start + i)
×
936
                fn(
×
937
                        table.GetEntity(index),
×
938
                        (*A)(columnA.Get(index)),
×
939
                        (*B)(columnB.Get(index)),
×
940
                        (*C)(columnC.Get(index)),
×
941
                        (*D)(columnD.Get(index)),
×
942
                        (*E)(columnE.Get(index)),
×
943
                        (*F)(columnF.Get(index)),
×
944
                        (*G)(columnG.Get(index)),
×
945
                )
×
946
        }
×
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) {
×
951
        if !m.world.Alive(entity) {
×
952
                panic("can't get components of a dead entity")
×
953
        }
954
        return m.GetUnchecked(entity)
×
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) {
×
961
        index := m.world.storage.entities[entity.id]
×
962
        row := uintptr(index.row)
×
963
        checkMapHasComponent(m.storageA, index.table)
×
964
        checkMapHasComponent(m.storageB, index.table)
×
965
        checkMapHasComponent(m.storageC, index.table)
×
966
        checkMapHasComponent(m.storageD, index.table)
×
967
        checkMapHasComponent(m.storageE, index.table)
×
968
        checkMapHasComponent(m.storageF, index.table)
×
969
        checkMapHasComponent(m.storageG, index.table)
×
970

×
971
        return (*A)(m.storageA.columns[index.table].Get(row)),
×
972
                (*B)(m.storageB.columns[index.table].Get(row)),
×
973
                (*C)(m.storageC.columns[index.table].Get(row)),
×
974
                (*D)(m.storageD.columns[index.table].Get(row)),
×
975
                (*E)(m.storageE.columns[index.table].Get(row)),
×
976
                (*F)(m.storageF.columns[index.table].Get(row)),
×
977
                (*G)(m.storageG.columns[index.table].Get(row))
×
978
}
×
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 {
×
982
        if !m.world.Alive(entity) {
×
983
                panic("can't check components of a dead entity")
×
984
        }
985
        index := m.world.storage.entities[entity.id]
×
986
        return m.storageA.columns[index.table] != nil &&
×
987
                m.storageB.columns[index.table] != nil &&
×
988
                m.storageC.columns[index.table] != nil &&
×
989
                m.storageD.columns[index.table] != nil &&
×
990
                m.storageE.columns[index.table] != nil &&
×
991
                m.storageF.columns[index.table] != nil &&
×
992
                m.storageG.columns[index.table] != nil
×
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) {
×
997
        if !m.world.Alive(entity) {
×
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)
×
1001
        m.world.exchange(entity, m.ids, nil, []unsafe.Pointer{
×
1002
                unsafe.Pointer(a),
×
1003
                unsafe.Pointer(b),
×
1004
                unsafe.Pointer(c),
×
1005
                unsafe.Pointer(d),
×
1006
                unsafe.Pointer(e),
×
1007
                unsafe.Pointer(f),
×
1008
                unsafe.Pointer(g),
×
1009
        }, m.relations)
×
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) {
×
1014
        if !m.world.Alive(entity) {
×
1015
                panic("can't remove components from a dead entity")
×
1016
        }
1017
        m.world.exchange(entity, nil, m.ids, nil, nil)
×
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] {
2✔
1046
        ids := []ID{
2✔
1047
                ComponentID[A](world),
2✔
1048
                ComponentID[B](world),
2✔
1049
                ComponentID[C](world),
2✔
1050
                ComponentID[D](world),
2✔
1051
                ComponentID[E](world),
2✔
1052
                ComponentID[F](world),
2✔
1053
                ComponentID[G](world),
2✔
1054
                ComponentID[H](world),
2✔
1055
        }
2✔
1056
        return Map8[A, B, C, D, E, F, G, H]{
2✔
1057
                world:    world,
2✔
1058
                ids:      ids,
2✔
1059
                storageA: &world.storage.components[ids[0].id],
2✔
1060
                storageB: &world.storage.components[ids[1].id],
2✔
1061
                storageC: &world.storage.components[ids[2].id],
2✔
1062
                storageD: &world.storage.components[ids[3].id],
2✔
1063
                storageE: &world.storage.components[ids[4].id],
2✔
1064
                storageF: &world.storage.components[ids[5].id],
2✔
1065
                storageG: &world.storage.components[ids[6].id],
2✔
1066
                storageH: &world.storage.components[ids[7].id],
2✔
1067
        }
2✔
1068
}
2✔
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 {
60✔
1072
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
60✔
1073
        return m.world.newEntityWith(m.ids, []unsafe.Pointer{
60✔
1074
                unsafe.Pointer(a),
60✔
1075
                unsafe.Pointer(b),
60✔
1076
                unsafe.Pointer(c),
60✔
1077
                unsafe.Pointer(d),
60✔
1078
                unsafe.Pointer(e),
60✔
1079
                unsafe.Pointer(f),
60✔
1080
                unsafe.Pointer(g),
60✔
1081
                unsafe.Pointer(h),
60✔
1082
        }, m.relations)
60✔
1083
}
60✔
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) {
×
1087
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
1088
        m.world.newEntitiesWith(count, m.ids, []unsafe.Pointer{
×
1089
                unsafe.Pointer(a),
×
1090
                unsafe.Pointer(b),
×
1091
                unsafe.Pointer(c),
×
1092
                unsafe.Pointer(d),
×
1093
                unsafe.Pointer(e),
×
1094
                unsafe.Pointer(f),
×
1095
                unsafe.Pointer(g),
×
1096
                unsafe.Pointer(h),
×
1097
        }, m.relations)
×
1098
}
×
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) {
×
1103
        m.relations = relations(rel).toRelations(&m.world.storage.registry, m.ids, m.relations)
×
1104
        tableID, start := m.world.newEntities(count, m.ids, m.relations)
×
1105
        if fn == nil {
×
1106
                return
×
1107
        }
×
1108

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

×
1119
        for i := range count {
×
1120
                index := uintptr(start + i)
×
1121
                fn(
×
1122
                        table.GetEntity(index),
×
1123
                        (*A)(columnA.Get(index)),
×
1124
                        (*B)(columnB.Get(index)),
×
1125
                        (*C)(columnC.Get(index)),
×
1126
                        (*D)(columnD.Get(index)),
×
1127
                        (*E)(columnE.Get(index)),
×
1128
                        (*F)(columnF.Get(index)),
×
1129
                        (*G)(columnG.Get(index)),
×
1130
                        (*H)(columnH.Get(index)),
×
1131
                )
×
1132
        }
×
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) {
×
1137
        if !m.world.Alive(entity) {
×
1138
                panic("can't get components of a dead entity")
×
1139
        }
1140
        return m.GetUnchecked(entity)
×
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) {
×
1147
        index := m.world.storage.entities[entity.id]
×
1148
        row := uintptr(index.row)
×
1149
        checkMapHasComponent(m.storageA, index.table)
×
1150
        checkMapHasComponent(m.storageB, index.table)
×
1151
        checkMapHasComponent(m.storageC, index.table)
×
1152
        checkMapHasComponent(m.storageD, index.table)
×
1153
        checkMapHasComponent(m.storageE, index.table)
×
1154
        checkMapHasComponent(m.storageF, index.table)
×
1155
        checkMapHasComponent(m.storageG, index.table)
×
1156
        checkMapHasComponent(m.storageH, index.table)
×
1157

×
1158
        return (*A)(m.storageA.columns[index.table].Get(row)),
×
1159
                (*B)(m.storageB.columns[index.table].Get(row)),
×
1160
                (*C)(m.storageC.columns[index.table].Get(row)),
×
1161
                (*D)(m.storageD.columns[index.table].Get(row)),
×
1162
                (*E)(m.storageE.columns[index.table].Get(row)),
×
1163
                (*F)(m.storageF.columns[index.table].Get(row)),
×
1164
                (*G)(m.storageG.columns[index.table].Get(row)),
×
1165
                (*H)(m.storageH.columns[index.table].Get(row))
×
1166
}
×
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 {
×
1170
        if !m.world.Alive(entity) {
×
1171
                panic("can't check components of a dead entity")
×
1172
        }
1173
        index := m.world.storage.entities[entity.id]
×
1174
        return m.storageA.columns[index.table] != nil &&
×
1175
                m.storageB.columns[index.table] != nil &&
×
1176
                m.storageC.columns[index.table] != nil &&
×
1177
                m.storageD.columns[index.table] != nil &&
×
1178
                m.storageE.columns[index.table] != nil &&
×
1179
                m.storageF.columns[index.table] != nil &&
×
1180
                m.storageG.columns[index.table] != nil &&
×
1181
                m.storageH.columns[index.table] != nil
×
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) {
×
1186
        if !m.world.Alive(entity) {
×
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)
×
1190
        m.world.exchange(entity, m.ids, nil, []unsafe.Pointer{
×
1191
                unsafe.Pointer(a),
×
1192
                unsafe.Pointer(b),
×
1193
                unsafe.Pointer(c),
×
1194
                unsafe.Pointer(d),
×
1195
                unsafe.Pointer(e),
×
1196
                unsafe.Pointer(f),
×
1197
                unsafe.Pointer(g),
×
1198
                unsafe.Pointer(h),
×
1199
        }, m.relations)
×
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) {
×
1204
        if !m.world.Alive(entity) {
×
1205
                panic("can't remove components from a dead entity")
×
1206
        }
1207
        m.world.exchange(entity, nil, m.ids, nil, nil)
×
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