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

mlange-42 / ark / 13661217767

04 Mar 2025 07:16PM CUT coverage: 99.28%. Remained the same
13661217767

push

github

web-flow
User guide chapter on component operations (#125)

5788 of 5830 relevant lines covered (99.28%)

33857.51 hits per line

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

100.0
/ecs/exchange_gen.go
1
package ecs
2

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

5
import "unsafe"
6

7
// Exchange1 allows to exchange components of entities.
8
// It adds the given components. Use [Exchange1.Removes]
9
// to set components to be removed.
10
type Exchange1[A any] struct {
11
        world     *World
12
        ids       []ID
13
        remove    []ID
14
        relations []RelationID
15
}
16

17
// NewExchange1 creates an [Exchange1].
18
func NewExchange1[A any](world *World) *Exchange1[A] {
7✔
19
        ids := []ID{
7✔
20
                ComponentID[A](world),
7✔
21
        }
7✔
22
        return &Exchange1[A]{
7✔
23
                world: world,
7✔
24
                ids:   ids,
7✔
25
        }
7✔
26
}
7✔
27

28
// Removes sets the components that this [Exchange1] removes.
29
// Can be called multiple times in chains, or once with multiple arguments.
30
func (ex *Exchange1[A]) Removes(components ...Comp) *Exchange1[A] {
7✔
31
        for _, c := range components {
17✔
32
                ex.remove = append(ex.remove, ex.world.componentID(c.tp))
10✔
33
        }
10✔
34
        return ex
7✔
35
}
36

37
// Add the mapped components to the given entity.
38
func (ex *Exchange1[A]) Add(entity Entity, a *A, rel ...Relation) {
1✔
39
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
40
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
41
                unsafe.Pointer(a),
1✔
42
        }, ex.relations)
1✔
43
}
1✔
44

45
// Remove the components previously specified with [Exchange1.Removes] from the given entity.
46
func (ex *Exchange1[A]) Remove(entity Entity) {
1✔
47
        ex.world.exchange(entity, nil, ex.remove, nil, nil)
1✔
48
}
1✔
49

50
// Exchange performs the exchange on the given entity, adding the provided components
51
// and removing those previously specified with [Exchange1.Removes].
52
func (ex *Exchange1[A]) Exchange(entity Entity, a *A, rel ...Relation) {
1✔
53
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
54
        ex.world.exchange(entity, ex.ids, ex.remove, []unsafe.Pointer{
1✔
55
                unsafe.Pointer(a),
1✔
56
        }, ex.relations)
1✔
57
}
1✔
58

59
// AddBatch adds the mapped components to all entities matching the given batch filter.
60
func (ex *Exchange1[A]) AddBatch(batch *Batch, a *A, rel ...Relation) {
1✔
61
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
62
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
1✔
63
                unsafe.Pointer(a),
1✔
64
        }, ex.relations, nil)
1✔
65
}
1✔
66

67
// AddBatchFn adds the mapped components to all entities matching the given batch filter,
68
// running the given function on each. The function can be nil.
69
func (ex *Exchange1[A]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A), rel ...Relation) {
1✔
70
        ex.exchangeBatchFn(batch, fn, false, rel...)
1✔
71
}
1✔
72

73
// RemoveBatch removes the components previously specified with [Exchange1.Removes]
74
// from all entities matching the given batch filter,
75
// running the given function on each. The function can be nil.
76
func (ex *Exchange1[A]) RemoveBatch(batch *Batch, fn func(entity Entity)) {
2✔
77
        var process func(tableID tableID, start, len int)
2✔
78
        if fn != nil {
3✔
79
                process = func(tableID tableID, start, len int) {
3✔
80
                        table := &ex.world.storage.tables[tableID]
2✔
81

2✔
82
                        lock := ex.world.lock()
2✔
83
                        for i := range len {
26✔
84
                                index := uintptr(start + i)
24✔
85
                                fn(table.GetEntity(index))
24✔
86
                        }
24✔
87
                        ex.world.unlock(lock)
2✔
88
                }
89
        }
90
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
2✔
91
}
92

93
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
94
func (ex *Exchange1[A]) ExchangeBatch(batch *Batch, a *A, rel ...Relation) {
1✔
95
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
96
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
1✔
97
                unsafe.Pointer(a),
1✔
98
        }, ex.relations, nil)
1✔
99
}
1✔
100

101
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
102
// running the given function on each. The function can be nil.
103
func (ex *Exchange1[A]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A), rel ...Relation) {
1✔
104
        ex.exchangeBatchFn(batch, fn, true, rel...)
1✔
105
}
1✔
106

107
func (ex *Exchange1[A]) exchangeBatchFn(batch *Batch, fn func(entity Entity, a *A), remove bool, rel ...Relation) {
2✔
108
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
2✔
109

2✔
110
        var process func(tableID tableID, start, len int)
2✔
111
        if fn != nil {
4✔
112
                process = func(tableID tableID, start, len int) {
6✔
113
                        table := &ex.world.storage.tables[tableID]
4✔
114
                        columnA := table.GetColumn(ex.ids[0])
4✔
115

4✔
116
                        lock := ex.world.lock()
4✔
117
                        for i := range len {
52✔
118
                                index := uintptr(start + i)
48✔
119
                                fn(
48✔
120
                                        table.GetEntity(index),
48✔
121
                                        (*A)(columnA.Get(index)),
48✔
122
                                )
48✔
123
                        }
48✔
124
                        ex.world.unlock(lock)
4✔
125
                }
126
        }
127
        if remove {
3✔
128
                ex.world.exchangeBatch(batch, ex.ids, ex.remove, nil, ex.relations, process)
1✔
129
        } else {
2✔
130
                ex.world.exchangeBatch(batch, ex.ids, nil, nil, ex.relations, process)
1✔
131
        }
1✔
132
}
133

134
// Exchange2 allows to exchange components of entities.
135
// It adds the given components. Use [Exchange2.Removes]
136
// to set components to be removed.
137
type Exchange2[A any, B any] struct {
138
        world     *World
139
        ids       []ID
140
        remove    []ID
141
        relations []RelationID
142
}
143

144
// NewExchange2 creates an [Exchange2].
145
func NewExchange2[A any, B any](world *World) *Exchange2[A, B] {
7✔
146
        ids := []ID{
7✔
147
                ComponentID[A](world),
7✔
148
                ComponentID[B](world),
7✔
149
        }
7✔
150
        return &Exchange2[A, B]{
7✔
151
                world: world,
7✔
152
                ids:   ids,
7✔
153
        }
7✔
154
}
7✔
155

156
// Removes sets the components that this [Exchange2] removes.
157
// Can be called multiple times in chains, or once with multiple arguments.
158
func (ex *Exchange2[A, B]) Removes(components ...Comp) *Exchange2[A, B] {
7✔
159
        for _, c := range components {
17✔
160
                ex.remove = append(ex.remove, ex.world.componentID(c.tp))
10✔
161
        }
10✔
162
        return ex
7✔
163
}
164

165
// Add the mapped components to the given entity.
166
func (ex *Exchange2[A, B]) Add(entity Entity, a *A, b *B, rel ...Relation) {
1✔
167
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
168
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
169
                unsafe.Pointer(a),
1✔
170
                unsafe.Pointer(b),
1✔
171
        }, ex.relations)
1✔
172
}
1✔
173

174
// Remove the components previously specified with [Exchange2.Removes] from the given entity.
175
func (ex *Exchange2[A, B]) Remove(entity Entity) {
1✔
176
        ex.world.exchange(entity, nil, ex.remove, nil, nil)
1✔
177
}
1✔
178

179
// Exchange performs the exchange on the given entity, adding the provided components
180
// and removing those previously specified with [Exchange2.Removes].
181
func (ex *Exchange2[A, B]) Exchange(entity Entity, a *A, b *B, rel ...Relation) {
1✔
182
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
183
        ex.world.exchange(entity, ex.ids, ex.remove, []unsafe.Pointer{
1✔
184
                unsafe.Pointer(a),
1✔
185
                unsafe.Pointer(b),
1✔
186
        }, ex.relations)
1✔
187
}
1✔
188

189
// AddBatch adds the mapped components to all entities matching the given batch filter.
190
func (ex *Exchange2[A, B]) AddBatch(batch *Batch, a *A, b *B, rel ...Relation) {
1✔
191
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
192
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
1✔
193
                unsafe.Pointer(a),
1✔
194
                unsafe.Pointer(b),
1✔
195
        }, ex.relations, nil)
1✔
196
}
1✔
197

198
// AddBatchFn adds the mapped components to all entities matching the given batch filter,
199
// running the given function on each. The function can be nil.
200
func (ex *Exchange2[A, B]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B), rel ...Relation) {
1✔
201
        ex.exchangeBatchFn(batch, fn, false, rel...)
1✔
202
}
1✔
203

204
// RemoveBatch removes the components previously specified with [Exchange2.Removes]
205
// from all entities matching the given batch filter,
206
// running the given function on each. The function can be nil.
207
func (ex *Exchange2[A, B]) RemoveBatch(batch *Batch, fn func(entity Entity)) {
2✔
208
        var process func(tableID tableID, start, len int)
2✔
209
        if fn != nil {
3✔
210
                process = func(tableID tableID, start, len int) {
3✔
211
                        table := &ex.world.storage.tables[tableID]
2✔
212

2✔
213
                        lock := ex.world.lock()
2✔
214
                        for i := range len {
26✔
215
                                index := uintptr(start + i)
24✔
216
                                fn(table.GetEntity(index))
24✔
217
                        }
24✔
218
                        ex.world.unlock(lock)
2✔
219
                }
220
        }
221
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
2✔
222
}
223

224
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
225
func (ex *Exchange2[A, B]) ExchangeBatch(batch *Batch, a *A, b *B, rel ...Relation) {
1✔
226
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
227
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
1✔
228
                unsafe.Pointer(a),
1✔
229
                unsafe.Pointer(b),
1✔
230
        }, ex.relations, nil)
1✔
231
}
1✔
232

233
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
234
// running the given function on each. The function can be nil.
235
func (ex *Exchange2[A, B]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B), rel ...Relation) {
1✔
236
        ex.exchangeBatchFn(batch, fn, true, rel...)
1✔
237
}
1✔
238

239
func (ex *Exchange2[A, B]) exchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B), remove bool, rel ...Relation) {
2✔
240
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
2✔
241

2✔
242
        var process func(tableID tableID, start, len int)
2✔
243
        if fn != nil {
4✔
244
                process = func(tableID tableID, start, len int) {
6✔
245
                        table := &ex.world.storage.tables[tableID]
4✔
246
                        columnA := table.GetColumn(ex.ids[0])
4✔
247
                        columnB := table.GetColumn(ex.ids[1])
4✔
248

4✔
249
                        lock := ex.world.lock()
4✔
250
                        for i := range len {
52✔
251
                                index := uintptr(start + i)
48✔
252
                                fn(
48✔
253
                                        table.GetEntity(index),
48✔
254
                                        (*A)(columnA.Get(index)),
48✔
255
                                        (*B)(columnB.Get(index)),
48✔
256
                                )
48✔
257
                        }
48✔
258
                        ex.world.unlock(lock)
4✔
259
                }
260
        }
261
        if remove {
3✔
262
                ex.world.exchangeBatch(batch, ex.ids, ex.remove, nil, ex.relations, process)
1✔
263
        } else {
2✔
264
                ex.world.exchangeBatch(batch, ex.ids, nil, nil, ex.relations, process)
1✔
265
        }
1✔
266
}
267

268
// Exchange3 allows to exchange components of entities.
269
// It adds the given components. Use [Exchange3.Removes]
270
// to set components to be removed.
271
type Exchange3[A any, B any, C any] struct {
272
        world     *World
273
        ids       []ID
274
        remove    []ID
275
        relations []RelationID
276
}
277

278
// NewExchange3 creates an [Exchange3].
279
func NewExchange3[A any, B any, C any](world *World) *Exchange3[A, B, C] {
7✔
280
        ids := []ID{
7✔
281
                ComponentID[A](world),
7✔
282
                ComponentID[B](world),
7✔
283
                ComponentID[C](world),
7✔
284
        }
7✔
285
        return &Exchange3[A, B, C]{
7✔
286
                world: world,
7✔
287
                ids:   ids,
7✔
288
        }
7✔
289
}
7✔
290

291
// Removes sets the components that this [Exchange3] removes.
292
// Can be called multiple times in chains, or once with multiple arguments.
293
func (ex *Exchange3[A, B, C]) Removes(components ...Comp) *Exchange3[A, B, C] {
7✔
294
        for _, c := range components {
17✔
295
                ex.remove = append(ex.remove, ex.world.componentID(c.tp))
10✔
296
        }
10✔
297
        return ex
7✔
298
}
299

300
// Add the mapped components to the given entity.
301
func (ex *Exchange3[A, B, C]) Add(entity Entity, a *A, b *B, c *C, rel ...Relation) {
1✔
302
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
303
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
304
                unsafe.Pointer(a),
1✔
305
                unsafe.Pointer(b),
1✔
306
                unsafe.Pointer(c),
1✔
307
        }, ex.relations)
1✔
308
}
1✔
309

310
// Remove the components previously specified with [Exchange3.Removes] from the given entity.
311
func (ex *Exchange3[A, B, C]) Remove(entity Entity) {
1✔
312
        ex.world.exchange(entity, nil, ex.remove, nil, nil)
1✔
313
}
1✔
314

315
// Exchange performs the exchange on the given entity, adding the provided components
316
// and removing those previously specified with [Exchange3.Removes].
317
func (ex *Exchange3[A, B, C]) Exchange(entity Entity, a *A, b *B, c *C, rel ...Relation) {
1✔
318
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
319
        ex.world.exchange(entity, ex.ids, ex.remove, []unsafe.Pointer{
1✔
320
                unsafe.Pointer(a),
1✔
321
                unsafe.Pointer(b),
1✔
322
                unsafe.Pointer(c),
1✔
323
        }, ex.relations)
1✔
324
}
1✔
325

326
// AddBatch adds the mapped components to all entities matching the given batch filter.
327
func (ex *Exchange3[A, B, C]) AddBatch(batch *Batch, a *A, b *B, c *C, rel ...Relation) {
1✔
328
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
329
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
1✔
330
                unsafe.Pointer(a),
1✔
331
                unsafe.Pointer(b),
1✔
332
                unsafe.Pointer(c),
1✔
333
        }, ex.relations, nil)
1✔
334
}
1✔
335

336
// AddBatchFn adds the mapped components to all entities matching the given batch filter,
337
// running the given function on each. The function can be nil.
338
func (ex *Exchange3[A, B, C]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C), rel ...Relation) {
1✔
339
        ex.exchangeBatchFn(batch, fn, false, rel...)
1✔
340
}
1✔
341

342
// RemoveBatch removes the components previously specified with [Exchange3.Removes]
343
// from all entities matching the given batch filter,
344
// running the given function on each. The function can be nil.
345
func (ex *Exchange3[A, B, C]) RemoveBatch(batch *Batch, fn func(entity Entity)) {
2✔
346
        var process func(tableID tableID, start, len int)
2✔
347
        if fn != nil {
3✔
348
                process = func(tableID tableID, start, len int) {
3✔
349
                        table := &ex.world.storage.tables[tableID]
2✔
350

2✔
351
                        lock := ex.world.lock()
2✔
352
                        for i := range len {
26✔
353
                                index := uintptr(start + i)
24✔
354
                                fn(table.GetEntity(index))
24✔
355
                        }
24✔
356
                        ex.world.unlock(lock)
2✔
357
                }
358
        }
359
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
2✔
360
}
361

362
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
363
func (ex *Exchange3[A, B, C]) ExchangeBatch(batch *Batch, a *A, b *B, c *C, rel ...Relation) {
1✔
364
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
365
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
1✔
366
                unsafe.Pointer(a),
1✔
367
                unsafe.Pointer(b),
1✔
368
                unsafe.Pointer(c),
1✔
369
        }, ex.relations, nil)
1✔
370
}
1✔
371

372
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
373
// running the given function on each. The function can be nil.
374
func (ex *Exchange3[A, B, C]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C), rel ...Relation) {
1✔
375
        ex.exchangeBatchFn(batch, fn, true, rel...)
1✔
376
}
1✔
377

378
func (ex *Exchange3[A, B, C]) exchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C), remove bool, rel ...Relation) {
2✔
379
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
2✔
380

2✔
381
        var process func(tableID tableID, start, len int)
2✔
382
        if fn != nil {
4✔
383
                process = func(tableID tableID, start, len int) {
6✔
384
                        table := &ex.world.storage.tables[tableID]
4✔
385
                        columnA := table.GetColumn(ex.ids[0])
4✔
386
                        columnB := table.GetColumn(ex.ids[1])
4✔
387
                        columnC := table.GetColumn(ex.ids[2])
4✔
388

4✔
389
                        lock := ex.world.lock()
4✔
390
                        for i := range len {
52✔
391
                                index := uintptr(start + i)
48✔
392
                                fn(
48✔
393
                                        table.GetEntity(index),
48✔
394
                                        (*A)(columnA.Get(index)),
48✔
395
                                        (*B)(columnB.Get(index)),
48✔
396
                                        (*C)(columnC.Get(index)),
48✔
397
                                )
48✔
398
                        }
48✔
399
                        ex.world.unlock(lock)
4✔
400
                }
401
        }
402
        if remove {
3✔
403
                ex.world.exchangeBatch(batch, ex.ids, ex.remove, nil, ex.relations, process)
1✔
404
        } else {
2✔
405
                ex.world.exchangeBatch(batch, ex.ids, nil, nil, ex.relations, process)
1✔
406
        }
1✔
407
}
408

409
// Exchange4 allows to exchange components of entities.
410
// It adds the given components. Use [Exchange4.Removes]
411
// to set components to be removed.
412
type Exchange4[A any, B any, C any, D any] struct {
413
        world     *World
414
        ids       []ID
415
        remove    []ID
416
        relations []RelationID
417
}
418

419
// NewExchange4 creates an [Exchange4].
420
func NewExchange4[A any, B any, C any, D any](world *World) *Exchange4[A, B, C, D] {
7✔
421
        ids := []ID{
7✔
422
                ComponentID[A](world),
7✔
423
                ComponentID[B](world),
7✔
424
                ComponentID[C](world),
7✔
425
                ComponentID[D](world),
7✔
426
        }
7✔
427
        return &Exchange4[A, B, C, D]{
7✔
428
                world: world,
7✔
429
                ids:   ids,
7✔
430
        }
7✔
431
}
7✔
432

433
// Removes sets the components that this [Exchange4] removes.
434
// Can be called multiple times in chains, or once with multiple arguments.
435
func (ex *Exchange4[A, B, C, D]) Removes(components ...Comp) *Exchange4[A, B, C, D] {
7✔
436
        for _, c := range components {
17✔
437
                ex.remove = append(ex.remove, ex.world.componentID(c.tp))
10✔
438
        }
10✔
439
        return ex
7✔
440
}
441

442
// Add the mapped components to the given entity.
443
func (ex *Exchange4[A, B, C, D]) Add(entity Entity, a *A, b *B, c *C, d *D, rel ...Relation) {
1✔
444
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
445
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
446
                unsafe.Pointer(a),
1✔
447
                unsafe.Pointer(b),
1✔
448
                unsafe.Pointer(c),
1✔
449
                unsafe.Pointer(d),
1✔
450
        }, ex.relations)
1✔
451
}
1✔
452

453
// Remove the components previously specified with [Exchange4.Removes] from the given entity.
454
func (ex *Exchange4[A, B, C, D]) Remove(entity Entity) {
1✔
455
        ex.world.exchange(entity, nil, ex.remove, nil, nil)
1✔
456
}
1✔
457

458
// Exchange performs the exchange on the given entity, adding the provided components
459
// and removing those previously specified with [Exchange4.Removes].
460
func (ex *Exchange4[A, B, C, D]) Exchange(entity Entity, a *A, b *B, c *C, d *D, rel ...Relation) {
1✔
461
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
462
        ex.world.exchange(entity, ex.ids, ex.remove, []unsafe.Pointer{
1✔
463
                unsafe.Pointer(a),
1✔
464
                unsafe.Pointer(b),
1✔
465
                unsafe.Pointer(c),
1✔
466
                unsafe.Pointer(d),
1✔
467
        }, ex.relations)
1✔
468
}
1✔
469

470
// AddBatch adds the mapped components to all entities matching the given batch filter.
471
func (ex *Exchange4[A, B, C, D]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, rel ...Relation) {
1✔
472
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
473
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
1✔
474
                unsafe.Pointer(a),
1✔
475
                unsafe.Pointer(b),
1✔
476
                unsafe.Pointer(c),
1✔
477
                unsafe.Pointer(d),
1✔
478
        }, ex.relations, nil)
1✔
479
}
1✔
480

481
// AddBatchFn adds the mapped components to all entities matching the given batch filter,
482
// running the given function on each. The function can be nil.
483
func (ex *Exchange4[A, B, C, D]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D), rel ...Relation) {
1✔
484
        ex.exchangeBatchFn(batch, fn, false, rel...)
1✔
485
}
1✔
486

487
// RemoveBatch removes the components previously specified with [Exchange4.Removes]
488
// from all entities matching the given batch filter,
489
// running the given function on each. The function can be nil.
490
func (ex *Exchange4[A, B, C, D]) RemoveBatch(batch *Batch, fn func(entity Entity)) {
2✔
491
        var process func(tableID tableID, start, len int)
2✔
492
        if fn != nil {
3✔
493
                process = func(tableID tableID, start, len int) {
3✔
494
                        table := &ex.world.storage.tables[tableID]
2✔
495

2✔
496
                        lock := ex.world.lock()
2✔
497
                        for i := range len {
26✔
498
                                index := uintptr(start + i)
24✔
499
                                fn(table.GetEntity(index))
24✔
500
                        }
24✔
501
                        ex.world.unlock(lock)
2✔
502
                }
503
        }
504
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
2✔
505
}
506

507
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
508
func (ex *Exchange4[A, B, C, D]) ExchangeBatch(batch *Batch, a *A, b *B, c *C, d *D, rel ...Relation) {
1✔
509
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
510
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
1✔
511
                unsafe.Pointer(a),
1✔
512
                unsafe.Pointer(b),
1✔
513
                unsafe.Pointer(c),
1✔
514
                unsafe.Pointer(d),
1✔
515
        }, ex.relations, nil)
1✔
516
}
1✔
517

518
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
519
// running the given function on each. The function can be nil.
520
func (ex *Exchange4[A, B, C, D]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D), rel ...Relation) {
1✔
521
        ex.exchangeBatchFn(batch, fn, true, rel...)
1✔
522
}
1✔
523

524
func (ex *Exchange4[A, B, C, D]) exchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D), remove bool, rel ...Relation) {
2✔
525
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
2✔
526

2✔
527
        var process func(tableID tableID, start, len int)
2✔
528
        if fn != nil {
4✔
529
                process = func(tableID tableID, start, len int) {
6✔
530
                        table := &ex.world.storage.tables[tableID]
4✔
531
                        columnA := table.GetColumn(ex.ids[0])
4✔
532
                        columnB := table.GetColumn(ex.ids[1])
4✔
533
                        columnC := table.GetColumn(ex.ids[2])
4✔
534
                        columnD := table.GetColumn(ex.ids[3])
4✔
535

4✔
536
                        lock := ex.world.lock()
4✔
537
                        for i := range len {
52✔
538
                                index := uintptr(start + i)
48✔
539
                                fn(
48✔
540
                                        table.GetEntity(index),
48✔
541
                                        (*A)(columnA.Get(index)),
48✔
542
                                        (*B)(columnB.Get(index)),
48✔
543
                                        (*C)(columnC.Get(index)),
48✔
544
                                        (*D)(columnD.Get(index)),
48✔
545
                                )
48✔
546
                        }
48✔
547
                        ex.world.unlock(lock)
4✔
548
                }
549
        }
550
        if remove {
3✔
551
                ex.world.exchangeBatch(batch, ex.ids, ex.remove, nil, ex.relations, process)
1✔
552
        } else {
2✔
553
                ex.world.exchangeBatch(batch, ex.ids, nil, nil, ex.relations, process)
1✔
554
        }
1✔
555
}
556

557
// Exchange5 allows to exchange components of entities.
558
// It adds the given components. Use [Exchange5.Removes]
559
// to set components to be removed.
560
type Exchange5[A any, B any, C any, D any, E any] struct {
561
        world     *World
562
        ids       []ID
563
        remove    []ID
564
        relations []RelationID
565
}
566

567
// NewExchange5 creates an [Exchange5].
568
func NewExchange5[A any, B any, C any, D any, E any](world *World) *Exchange5[A, B, C, D, E] {
7✔
569
        ids := []ID{
7✔
570
                ComponentID[A](world),
7✔
571
                ComponentID[B](world),
7✔
572
                ComponentID[C](world),
7✔
573
                ComponentID[D](world),
7✔
574
                ComponentID[E](world),
7✔
575
        }
7✔
576
        return &Exchange5[A, B, C, D, E]{
7✔
577
                world: world,
7✔
578
                ids:   ids,
7✔
579
        }
7✔
580
}
7✔
581

582
// Removes sets the components that this [Exchange5] removes.
583
// Can be called multiple times in chains, or once with multiple arguments.
584
func (ex *Exchange5[A, B, C, D, E]) Removes(components ...Comp) *Exchange5[A, B, C, D, E] {
7✔
585
        for _, c := range components {
17✔
586
                ex.remove = append(ex.remove, ex.world.componentID(c.tp))
10✔
587
        }
10✔
588
        return ex
7✔
589
}
590

591
// Add the mapped components to the given entity.
592
func (ex *Exchange5[A, B, C, D, E]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, rel ...Relation) {
1✔
593
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
594
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
595
                unsafe.Pointer(a),
1✔
596
                unsafe.Pointer(b),
1✔
597
                unsafe.Pointer(c),
1✔
598
                unsafe.Pointer(d),
1✔
599
                unsafe.Pointer(e),
1✔
600
        }, ex.relations)
1✔
601
}
1✔
602

603
// Remove the components previously specified with [Exchange5.Removes] from the given entity.
604
func (ex *Exchange5[A, B, C, D, E]) Remove(entity Entity) {
1✔
605
        ex.world.exchange(entity, nil, ex.remove, nil, nil)
1✔
606
}
1✔
607

608
// Exchange performs the exchange on the given entity, adding the provided components
609
// and removing those previously specified with [Exchange5.Removes].
610
func (ex *Exchange5[A, B, C, D, E]) Exchange(entity Entity, a *A, b *B, c *C, d *D, e *E, rel ...Relation) {
1✔
611
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
612
        ex.world.exchange(entity, ex.ids, ex.remove, []unsafe.Pointer{
1✔
613
                unsafe.Pointer(a),
1✔
614
                unsafe.Pointer(b),
1✔
615
                unsafe.Pointer(c),
1✔
616
                unsafe.Pointer(d),
1✔
617
                unsafe.Pointer(e),
1✔
618
        }, ex.relations)
1✔
619
}
1✔
620

621
// AddBatch adds the mapped components to all entities matching the given batch filter.
622
func (ex *Exchange5[A, B, C, D, E]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, rel ...Relation) {
1✔
623
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
624
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
1✔
625
                unsafe.Pointer(a),
1✔
626
                unsafe.Pointer(b),
1✔
627
                unsafe.Pointer(c),
1✔
628
                unsafe.Pointer(d),
1✔
629
                unsafe.Pointer(e),
1✔
630
        }, ex.relations, nil)
1✔
631
}
1✔
632

633
// AddBatchFn adds the mapped components to all entities matching the given batch filter,
634
// running the given function on each. The function can be nil.
635
func (ex *Exchange5[A, B, C, D, E]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E), rel ...Relation) {
1✔
636
        ex.exchangeBatchFn(batch, fn, false, rel...)
1✔
637
}
1✔
638

639
// RemoveBatch removes the components previously specified with [Exchange5.Removes]
640
// from all entities matching the given batch filter,
641
// running the given function on each. The function can be nil.
642
func (ex *Exchange5[A, B, C, D, E]) RemoveBatch(batch *Batch, fn func(entity Entity)) {
2✔
643
        var process func(tableID tableID, start, len int)
2✔
644
        if fn != nil {
3✔
645
                process = func(tableID tableID, start, len int) {
3✔
646
                        table := &ex.world.storage.tables[tableID]
2✔
647

2✔
648
                        lock := ex.world.lock()
2✔
649
                        for i := range len {
26✔
650
                                index := uintptr(start + i)
24✔
651
                                fn(table.GetEntity(index))
24✔
652
                        }
24✔
653
                        ex.world.unlock(lock)
2✔
654
                }
655
        }
656
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
2✔
657
}
658

659
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
660
func (ex *Exchange5[A, B, C, D, E]) ExchangeBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, rel ...Relation) {
1✔
661
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
662
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
1✔
663
                unsafe.Pointer(a),
1✔
664
                unsafe.Pointer(b),
1✔
665
                unsafe.Pointer(c),
1✔
666
                unsafe.Pointer(d),
1✔
667
                unsafe.Pointer(e),
1✔
668
        }, ex.relations, nil)
1✔
669
}
1✔
670

671
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
672
// running the given function on each. The function can be nil.
673
func (ex *Exchange5[A, B, C, D, E]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E), rel ...Relation) {
1✔
674
        ex.exchangeBatchFn(batch, fn, true, rel...)
1✔
675
}
1✔
676

677
func (ex *Exchange5[A, B, C, D, E]) exchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E), remove bool, rel ...Relation) {
2✔
678
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
2✔
679

2✔
680
        var process func(tableID tableID, start, len int)
2✔
681
        if fn != nil {
4✔
682
                process = func(tableID tableID, start, len int) {
6✔
683
                        table := &ex.world.storage.tables[tableID]
4✔
684
                        columnA := table.GetColumn(ex.ids[0])
4✔
685
                        columnB := table.GetColumn(ex.ids[1])
4✔
686
                        columnC := table.GetColumn(ex.ids[2])
4✔
687
                        columnD := table.GetColumn(ex.ids[3])
4✔
688
                        columnE := table.GetColumn(ex.ids[4])
4✔
689

4✔
690
                        lock := ex.world.lock()
4✔
691
                        for i := range len {
52✔
692
                                index := uintptr(start + i)
48✔
693
                                fn(
48✔
694
                                        table.GetEntity(index),
48✔
695
                                        (*A)(columnA.Get(index)),
48✔
696
                                        (*B)(columnB.Get(index)),
48✔
697
                                        (*C)(columnC.Get(index)),
48✔
698
                                        (*D)(columnD.Get(index)),
48✔
699
                                        (*E)(columnE.Get(index)),
48✔
700
                                )
48✔
701
                        }
48✔
702
                        ex.world.unlock(lock)
4✔
703
                }
704
        }
705
        if remove {
3✔
706
                ex.world.exchangeBatch(batch, ex.ids, ex.remove, nil, ex.relations, process)
1✔
707
        } else {
2✔
708
                ex.world.exchangeBatch(batch, ex.ids, nil, nil, ex.relations, process)
1✔
709
        }
1✔
710
}
711

712
// Exchange6 allows to exchange components of entities.
713
// It adds the given components. Use [Exchange6.Removes]
714
// to set components to be removed.
715
type Exchange6[A any, B any, C any, D any, E any, F any] struct {
716
        world     *World
717
        ids       []ID
718
        remove    []ID
719
        relations []RelationID
720
}
721

722
// NewExchange6 creates an [Exchange6].
723
func NewExchange6[A any, B any, C any, D any, E any, F any](world *World) *Exchange6[A, B, C, D, E, F] {
7✔
724
        ids := []ID{
7✔
725
                ComponentID[A](world),
7✔
726
                ComponentID[B](world),
7✔
727
                ComponentID[C](world),
7✔
728
                ComponentID[D](world),
7✔
729
                ComponentID[E](world),
7✔
730
                ComponentID[F](world),
7✔
731
        }
7✔
732
        return &Exchange6[A, B, C, D, E, F]{
7✔
733
                world: world,
7✔
734
                ids:   ids,
7✔
735
        }
7✔
736
}
7✔
737

738
// Removes sets the components that this [Exchange6] removes.
739
// Can be called multiple times in chains, or once with multiple arguments.
740
func (ex *Exchange6[A, B, C, D, E, F]) Removes(components ...Comp) *Exchange6[A, B, C, D, E, F] {
7✔
741
        for _, c := range components {
17✔
742
                ex.remove = append(ex.remove, ex.world.componentID(c.tp))
10✔
743
        }
10✔
744
        return ex
7✔
745
}
746

747
// Add the mapped components to the given entity.
748
func (ex *Exchange6[A, B, C, D, E, F]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, rel ...Relation) {
1✔
749
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
750
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
751
                unsafe.Pointer(a),
1✔
752
                unsafe.Pointer(b),
1✔
753
                unsafe.Pointer(c),
1✔
754
                unsafe.Pointer(d),
1✔
755
                unsafe.Pointer(e),
1✔
756
                unsafe.Pointer(f),
1✔
757
        }, ex.relations)
1✔
758
}
1✔
759

760
// Remove the components previously specified with [Exchange6.Removes] from the given entity.
761
func (ex *Exchange6[A, B, C, D, E, F]) Remove(entity Entity) {
1✔
762
        ex.world.exchange(entity, nil, ex.remove, nil, nil)
1✔
763
}
1✔
764

765
// Exchange performs the exchange on the given entity, adding the provided components
766
// and removing those previously specified with [Exchange6.Removes].
767
func (ex *Exchange6[A, B, C, D, E, F]) Exchange(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, rel ...Relation) {
1✔
768
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
769
        ex.world.exchange(entity, ex.ids, ex.remove, []unsafe.Pointer{
1✔
770
                unsafe.Pointer(a),
1✔
771
                unsafe.Pointer(b),
1✔
772
                unsafe.Pointer(c),
1✔
773
                unsafe.Pointer(d),
1✔
774
                unsafe.Pointer(e),
1✔
775
                unsafe.Pointer(f),
1✔
776
        }, ex.relations)
1✔
777
}
1✔
778

779
// AddBatch adds the mapped components to all entities matching the given batch filter.
780
func (ex *Exchange6[A, B, C, D, E, F]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, f *F, rel ...Relation) {
1✔
781
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
782
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
1✔
783
                unsafe.Pointer(a),
1✔
784
                unsafe.Pointer(b),
1✔
785
                unsafe.Pointer(c),
1✔
786
                unsafe.Pointer(d),
1✔
787
                unsafe.Pointer(e),
1✔
788
                unsafe.Pointer(f),
1✔
789
        }, ex.relations, nil)
1✔
790
}
1✔
791

792
// AddBatchFn adds the mapped components to all entities matching the given batch filter,
793
// running the given function on each. The function can be nil.
794
func (ex *Exchange6[A, B, C, D, E, F]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F), rel ...Relation) {
1✔
795
        ex.exchangeBatchFn(batch, fn, false, rel...)
1✔
796
}
1✔
797

798
// RemoveBatch removes the components previously specified with [Exchange6.Removes]
799
// from all entities matching the given batch filter,
800
// running the given function on each. The function can be nil.
801
func (ex *Exchange6[A, B, C, D, E, F]) RemoveBatch(batch *Batch, fn func(entity Entity)) {
2✔
802
        var process func(tableID tableID, start, len int)
2✔
803
        if fn != nil {
3✔
804
                process = func(tableID tableID, start, len int) {
3✔
805
                        table := &ex.world.storage.tables[tableID]
2✔
806

2✔
807
                        lock := ex.world.lock()
2✔
808
                        for i := range len {
26✔
809
                                index := uintptr(start + i)
24✔
810
                                fn(table.GetEntity(index))
24✔
811
                        }
24✔
812
                        ex.world.unlock(lock)
2✔
813
                }
814
        }
815
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
2✔
816
}
817

818
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
819
func (ex *Exchange6[A, B, C, D, E, F]) ExchangeBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, f *F, rel ...Relation) {
1✔
820
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
821
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
1✔
822
                unsafe.Pointer(a),
1✔
823
                unsafe.Pointer(b),
1✔
824
                unsafe.Pointer(c),
1✔
825
                unsafe.Pointer(d),
1✔
826
                unsafe.Pointer(e),
1✔
827
                unsafe.Pointer(f),
1✔
828
        }, ex.relations, nil)
1✔
829
}
1✔
830

831
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
832
// running the given function on each. The function can be nil.
833
func (ex *Exchange6[A, B, C, D, E, F]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F), rel ...Relation) {
1✔
834
        ex.exchangeBatchFn(batch, fn, true, rel...)
1✔
835
}
1✔
836

837
func (ex *Exchange6[A, B, C, D, E, F]) exchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F), remove bool, rel ...Relation) {
2✔
838
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
2✔
839

2✔
840
        var process func(tableID tableID, start, len int)
2✔
841
        if fn != nil {
4✔
842
                process = func(tableID tableID, start, len int) {
6✔
843
                        table := &ex.world.storage.tables[tableID]
4✔
844
                        columnA := table.GetColumn(ex.ids[0])
4✔
845
                        columnB := table.GetColumn(ex.ids[1])
4✔
846
                        columnC := table.GetColumn(ex.ids[2])
4✔
847
                        columnD := table.GetColumn(ex.ids[3])
4✔
848
                        columnE := table.GetColumn(ex.ids[4])
4✔
849
                        columnF := table.GetColumn(ex.ids[5])
4✔
850

4✔
851
                        lock := ex.world.lock()
4✔
852
                        for i := range len {
52✔
853
                                index := uintptr(start + i)
48✔
854
                                fn(
48✔
855
                                        table.GetEntity(index),
48✔
856
                                        (*A)(columnA.Get(index)),
48✔
857
                                        (*B)(columnB.Get(index)),
48✔
858
                                        (*C)(columnC.Get(index)),
48✔
859
                                        (*D)(columnD.Get(index)),
48✔
860
                                        (*E)(columnE.Get(index)),
48✔
861
                                        (*F)(columnF.Get(index)),
48✔
862
                                )
48✔
863
                        }
48✔
864
                        ex.world.unlock(lock)
4✔
865
                }
866
        }
867
        if remove {
3✔
868
                ex.world.exchangeBatch(batch, ex.ids, ex.remove, nil, ex.relations, process)
1✔
869
        } else {
2✔
870
                ex.world.exchangeBatch(batch, ex.ids, nil, nil, ex.relations, process)
1✔
871
        }
1✔
872
}
873

874
// Exchange7 allows to exchange components of entities.
875
// It adds the given components. Use [Exchange7.Removes]
876
// to set components to be removed.
877
type Exchange7[A any, B any, C any, D any, E any, F any, G any] struct {
878
        world     *World
879
        ids       []ID
880
        remove    []ID
881
        relations []RelationID
882
}
883

884
// NewExchange7 creates an [Exchange7].
885
func NewExchange7[A any, B any, C any, D any, E any, F any, G any](world *World) *Exchange7[A, B, C, D, E, F, G] {
7✔
886
        ids := []ID{
7✔
887
                ComponentID[A](world),
7✔
888
                ComponentID[B](world),
7✔
889
                ComponentID[C](world),
7✔
890
                ComponentID[D](world),
7✔
891
                ComponentID[E](world),
7✔
892
                ComponentID[F](world),
7✔
893
                ComponentID[G](world),
7✔
894
        }
7✔
895
        return &Exchange7[A, B, C, D, E, F, G]{
7✔
896
                world: world,
7✔
897
                ids:   ids,
7✔
898
        }
7✔
899
}
7✔
900

901
// Removes sets the components that this [Exchange7] removes.
902
// Can be called multiple times in chains, or once with multiple arguments.
903
func (ex *Exchange7[A, B, C, D, E, F, G]) Removes(components ...Comp) *Exchange7[A, B, C, D, E, F, G] {
7✔
904
        for _, c := range components {
17✔
905
                ex.remove = append(ex.remove, ex.world.componentID(c.tp))
10✔
906
        }
10✔
907
        return ex
7✔
908
}
909

910
// Add the mapped components to the given entity.
911
func (ex *Exchange7[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 ...Relation) {
1✔
912
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
913
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
914
                unsafe.Pointer(a),
1✔
915
                unsafe.Pointer(b),
1✔
916
                unsafe.Pointer(c),
1✔
917
                unsafe.Pointer(d),
1✔
918
                unsafe.Pointer(e),
1✔
919
                unsafe.Pointer(f),
1✔
920
                unsafe.Pointer(g),
1✔
921
        }, ex.relations)
1✔
922
}
1✔
923

924
// Remove the components previously specified with [Exchange7.Removes] from the given entity.
925
func (ex *Exchange7[A, B, C, D, E, F, G]) Remove(entity Entity) {
1✔
926
        ex.world.exchange(entity, nil, ex.remove, nil, nil)
1✔
927
}
1✔
928

929
// Exchange performs the exchange on the given entity, adding the provided components
930
// and removing those previously specified with [Exchange7.Removes].
931
func (ex *Exchange7[A, B, C, D, E, F, G]) Exchange(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, rel ...Relation) {
1✔
932
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
933
        ex.world.exchange(entity, ex.ids, ex.remove, []unsafe.Pointer{
1✔
934
                unsafe.Pointer(a),
1✔
935
                unsafe.Pointer(b),
1✔
936
                unsafe.Pointer(c),
1✔
937
                unsafe.Pointer(d),
1✔
938
                unsafe.Pointer(e),
1✔
939
                unsafe.Pointer(f),
1✔
940
                unsafe.Pointer(g),
1✔
941
        }, ex.relations)
1✔
942
}
1✔
943

944
// AddBatch adds the mapped components to all entities matching the given batch filter.
945
func (ex *Exchange7[A, B, C, D, E, F, G]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, f *F, g *G, rel ...Relation) {
1✔
946
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
947
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
1✔
948
                unsafe.Pointer(a),
1✔
949
                unsafe.Pointer(b),
1✔
950
                unsafe.Pointer(c),
1✔
951
                unsafe.Pointer(d),
1✔
952
                unsafe.Pointer(e),
1✔
953
                unsafe.Pointer(f),
1✔
954
                unsafe.Pointer(g),
1✔
955
        }, ex.relations, nil)
1✔
956
}
1✔
957

958
// AddBatchFn adds the mapped components to all entities matching the given batch filter,
959
// running the given function on each. The function can be nil.
960
func (ex *Exchange7[A, B, C, D, E, F, G]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G), rel ...Relation) {
1✔
961
        ex.exchangeBatchFn(batch, fn, false, rel...)
1✔
962
}
1✔
963

964
// RemoveBatch removes the components previously specified with [Exchange7.Removes]
965
// from all entities matching the given batch filter,
966
// running the given function on each. The function can be nil.
967
func (ex *Exchange7[A, B, C, D, E, F, G]) RemoveBatch(batch *Batch, fn func(entity Entity)) {
2✔
968
        var process func(tableID tableID, start, len int)
2✔
969
        if fn != nil {
3✔
970
                process = func(tableID tableID, start, len int) {
3✔
971
                        table := &ex.world.storage.tables[tableID]
2✔
972

2✔
973
                        lock := ex.world.lock()
2✔
974
                        for i := range len {
26✔
975
                                index := uintptr(start + i)
24✔
976
                                fn(table.GetEntity(index))
24✔
977
                        }
24✔
978
                        ex.world.unlock(lock)
2✔
979
                }
980
        }
981
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
2✔
982
}
983

984
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
985
func (ex *Exchange7[A, B, C, D, E, F, G]) ExchangeBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, f *F, g *G, rel ...Relation) {
1✔
986
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
987
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
1✔
988
                unsafe.Pointer(a),
1✔
989
                unsafe.Pointer(b),
1✔
990
                unsafe.Pointer(c),
1✔
991
                unsafe.Pointer(d),
1✔
992
                unsafe.Pointer(e),
1✔
993
                unsafe.Pointer(f),
1✔
994
                unsafe.Pointer(g),
1✔
995
        }, ex.relations, nil)
1✔
996
}
1✔
997

998
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
999
// running the given function on each. The function can be nil.
1000
func (ex *Exchange7[A, B, C, D, E, F, G]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G), rel ...Relation) {
1✔
1001
        ex.exchangeBatchFn(batch, fn, true, rel...)
1✔
1002
}
1✔
1003

1004
func (ex *Exchange7[A, B, C, D, E, F, G]) exchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G), remove bool, rel ...Relation) {
2✔
1005
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
2✔
1006

2✔
1007
        var process func(tableID tableID, start, len int)
2✔
1008
        if fn != nil {
4✔
1009
                process = func(tableID tableID, start, len int) {
6✔
1010
                        table := &ex.world.storage.tables[tableID]
4✔
1011
                        columnA := table.GetColumn(ex.ids[0])
4✔
1012
                        columnB := table.GetColumn(ex.ids[1])
4✔
1013
                        columnC := table.GetColumn(ex.ids[2])
4✔
1014
                        columnD := table.GetColumn(ex.ids[3])
4✔
1015
                        columnE := table.GetColumn(ex.ids[4])
4✔
1016
                        columnF := table.GetColumn(ex.ids[5])
4✔
1017
                        columnG := table.GetColumn(ex.ids[6])
4✔
1018

4✔
1019
                        lock := ex.world.lock()
4✔
1020
                        for i := range len {
52✔
1021
                                index := uintptr(start + i)
48✔
1022
                                fn(
48✔
1023
                                        table.GetEntity(index),
48✔
1024
                                        (*A)(columnA.Get(index)),
48✔
1025
                                        (*B)(columnB.Get(index)),
48✔
1026
                                        (*C)(columnC.Get(index)),
48✔
1027
                                        (*D)(columnD.Get(index)),
48✔
1028
                                        (*E)(columnE.Get(index)),
48✔
1029
                                        (*F)(columnF.Get(index)),
48✔
1030
                                        (*G)(columnG.Get(index)),
48✔
1031
                                )
48✔
1032
                        }
48✔
1033
                        ex.world.unlock(lock)
4✔
1034
                }
1035
        }
1036
        if remove {
3✔
1037
                ex.world.exchangeBatch(batch, ex.ids, ex.remove, nil, ex.relations, process)
1✔
1038
        } else {
2✔
1039
                ex.world.exchangeBatch(batch, ex.ids, nil, nil, ex.relations, process)
1✔
1040
        }
1✔
1041
}
1042

1043
// Exchange8 allows to exchange components of entities.
1044
// It adds the given components. Use [Exchange8.Removes]
1045
// to set components to be removed.
1046
type Exchange8[A any, B any, C any, D any, E any, F any, G any, H any] struct {
1047
        world     *World
1048
        ids       []ID
1049
        remove    []ID
1050
        relations []RelationID
1051
}
1052

1053
// NewExchange8 creates an [Exchange8].
1054
func NewExchange8[A any, B any, C any, D any, E any, F any, G any, H any](world *World) *Exchange8[A, B, C, D, E, F, G, H] {
7✔
1055
        ids := []ID{
7✔
1056
                ComponentID[A](world),
7✔
1057
                ComponentID[B](world),
7✔
1058
                ComponentID[C](world),
7✔
1059
                ComponentID[D](world),
7✔
1060
                ComponentID[E](world),
7✔
1061
                ComponentID[F](world),
7✔
1062
                ComponentID[G](world),
7✔
1063
                ComponentID[H](world),
7✔
1064
        }
7✔
1065
        return &Exchange8[A, B, C, D, E, F, G, H]{
7✔
1066
                world: world,
7✔
1067
                ids:   ids,
7✔
1068
        }
7✔
1069
}
7✔
1070

1071
// Removes sets the components that this [Exchange8] removes.
1072
// Can be called multiple times in chains, or once with multiple arguments.
1073
func (ex *Exchange8[A, B, C, D, E, F, G, H]) Removes(components ...Comp) *Exchange8[A, B, C, D, E, F, G, H] {
7✔
1074
        for _, c := range components {
17✔
1075
                ex.remove = append(ex.remove, ex.world.componentID(c.tp))
10✔
1076
        }
10✔
1077
        return ex
7✔
1078
}
1079

1080
// Add the mapped components to the given entity.
1081
func (ex *Exchange8[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 ...Relation) {
1✔
1082
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
1083
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
1084
                unsafe.Pointer(a),
1✔
1085
                unsafe.Pointer(b),
1✔
1086
                unsafe.Pointer(c),
1✔
1087
                unsafe.Pointer(d),
1✔
1088
                unsafe.Pointer(e),
1✔
1089
                unsafe.Pointer(f),
1✔
1090
                unsafe.Pointer(g),
1✔
1091
                unsafe.Pointer(h),
1✔
1092
        }, ex.relations)
1✔
1093
}
1✔
1094

1095
// Remove the components previously specified with [Exchange8.Removes] from the given entity.
1096
func (ex *Exchange8[A, B, C, D, E, F, G, H]) Remove(entity Entity) {
1✔
1097
        ex.world.exchange(entity, nil, ex.remove, nil, nil)
1✔
1098
}
1✔
1099

1100
// Exchange performs the exchange on the given entity, adding the provided components
1101
// and removing those previously specified with [Exchange8.Removes].
1102
func (ex *Exchange8[A, B, C, D, E, F, G, H]) Exchange(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, rel ...Relation) {
1✔
1103
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
1104
        ex.world.exchange(entity, ex.ids, ex.remove, []unsafe.Pointer{
1✔
1105
                unsafe.Pointer(a),
1✔
1106
                unsafe.Pointer(b),
1✔
1107
                unsafe.Pointer(c),
1✔
1108
                unsafe.Pointer(d),
1✔
1109
                unsafe.Pointer(e),
1✔
1110
                unsafe.Pointer(f),
1✔
1111
                unsafe.Pointer(g),
1✔
1112
                unsafe.Pointer(h),
1✔
1113
        }, ex.relations)
1✔
1114
}
1✔
1115

1116
// AddBatch adds the mapped components to all entities matching the given batch filter.
1117
func (ex *Exchange8[A, B, C, D, E, F, G, H]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, rel ...Relation) {
1✔
1118
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
1119
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
1✔
1120
                unsafe.Pointer(a),
1✔
1121
                unsafe.Pointer(b),
1✔
1122
                unsafe.Pointer(c),
1✔
1123
                unsafe.Pointer(d),
1✔
1124
                unsafe.Pointer(e),
1✔
1125
                unsafe.Pointer(f),
1✔
1126
                unsafe.Pointer(g),
1✔
1127
                unsafe.Pointer(h),
1✔
1128
        }, ex.relations, nil)
1✔
1129
}
1✔
1130

1131
// AddBatchFn adds the mapped components to all entities matching the given batch filter,
1132
// running the given function on each. The function can be nil.
1133
func (ex *Exchange8[A, B, C, D, E, F, G, H]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H), rel ...Relation) {
1✔
1134
        ex.exchangeBatchFn(batch, fn, false, rel...)
1✔
1135
}
1✔
1136

1137
// RemoveBatch removes the components previously specified with [Exchange8.Removes]
1138
// from all entities matching the given batch filter,
1139
// running the given function on each. The function can be nil.
1140
func (ex *Exchange8[A, B, C, D, E, F, G, H]) RemoveBatch(batch *Batch, fn func(entity Entity)) {
2✔
1141
        var process func(tableID tableID, start, len int)
2✔
1142
        if fn != nil {
3✔
1143
                process = func(tableID tableID, start, len int) {
3✔
1144
                        table := &ex.world.storage.tables[tableID]
2✔
1145

2✔
1146
                        lock := ex.world.lock()
2✔
1147
                        for i := range len {
26✔
1148
                                index := uintptr(start + i)
24✔
1149
                                fn(table.GetEntity(index))
24✔
1150
                        }
24✔
1151
                        ex.world.unlock(lock)
2✔
1152
                }
1153
        }
1154
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
2✔
1155
}
1156

1157
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
1158
func (ex *Exchange8[A, B, C, D, E, F, G, H]) ExchangeBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H, rel ...Relation) {
1✔
1159
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
1✔
1160
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
1✔
1161
                unsafe.Pointer(a),
1✔
1162
                unsafe.Pointer(b),
1✔
1163
                unsafe.Pointer(c),
1✔
1164
                unsafe.Pointer(d),
1✔
1165
                unsafe.Pointer(e),
1✔
1166
                unsafe.Pointer(f),
1✔
1167
                unsafe.Pointer(g),
1✔
1168
                unsafe.Pointer(h),
1✔
1169
        }, ex.relations, nil)
1✔
1170
}
1✔
1171

1172
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
1173
// running the given function on each. The function can be nil.
1174
func (ex *Exchange8[A, B, C, D, E, F, G, H]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H), rel ...Relation) {
1✔
1175
        ex.exchangeBatchFn(batch, fn, true, rel...)
1✔
1176
}
1✔
1177

1178
func (ex *Exchange8[A, B, C, D, E, F, G, H]) exchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G, h *H), remove bool, rel ...Relation) {
2✔
1179
        ex.relations = relations(rel).toRelations(ex.world, ex.ids, nil, ex.relations)
2✔
1180

2✔
1181
        var process func(tableID tableID, start, len int)
2✔
1182
        if fn != nil {
4✔
1183
                process = func(tableID tableID, start, len int) {
6✔
1184
                        table := &ex.world.storage.tables[tableID]
4✔
1185
                        columnA := table.GetColumn(ex.ids[0])
4✔
1186
                        columnB := table.GetColumn(ex.ids[1])
4✔
1187
                        columnC := table.GetColumn(ex.ids[2])
4✔
1188
                        columnD := table.GetColumn(ex.ids[3])
4✔
1189
                        columnE := table.GetColumn(ex.ids[4])
4✔
1190
                        columnF := table.GetColumn(ex.ids[5])
4✔
1191
                        columnG := table.GetColumn(ex.ids[6])
4✔
1192
                        columnH := table.GetColumn(ex.ids[7])
4✔
1193

4✔
1194
                        lock := ex.world.lock()
4✔
1195
                        for i := range len {
52✔
1196
                                index := uintptr(start + i)
48✔
1197
                                fn(
48✔
1198
                                        table.GetEntity(index),
48✔
1199
                                        (*A)(columnA.Get(index)),
48✔
1200
                                        (*B)(columnB.Get(index)),
48✔
1201
                                        (*C)(columnC.Get(index)),
48✔
1202
                                        (*D)(columnD.Get(index)),
48✔
1203
                                        (*E)(columnE.Get(index)),
48✔
1204
                                        (*F)(columnF.Get(index)),
48✔
1205
                                        (*G)(columnG.Get(index)),
48✔
1206
                                        (*H)(columnH.Get(index)),
48✔
1207
                                )
48✔
1208
                        }
48✔
1209
                        ex.world.unlock(lock)
4✔
1210
                }
1211
        }
1212
        if remove {
3✔
1213
                ex.world.exchangeBatch(batch, ex.ids, ex.remove, nil, ex.relations, process)
1✔
1214
        } else {
2✔
1215
                ex.world.exchangeBatch(batch, ex.ids, nil, nil, ex.relations, process)
1✔
1216
        }
1✔
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