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

mlange-42 / ark / 13653133357

04 Mar 2025 11:55AM CUT coverage: 99.261%. Remained the same
13653133357

Pull #107

github

web-flow
Merge f1d78c67a into 7f8aee9a7
Pull Request #107: User guide content

5772 of 5815 relevant lines covered (99.26%)

34307.67 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
func (ex *Exchange1[A]) Removes(components ...Comp) *Exchange1[A] {
7✔
30
        ids := make([]ID, len(components))
7✔
31
        for i, c := range components {
17✔
32
                ids[i] = ex.world.componentID(c.tp)
10✔
33
        }
10✔
34
        ex.remove = ids
7✔
35
        return ex
7✔
36
}
37

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

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

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

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

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

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

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

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

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

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

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

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

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

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

157
// Removes sets the components that this [Exchange2] removes.
158
func (ex *Exchange2[A, B]) Removes(components ...Comp) *Exchange2[A, B] {
7✔
159
        ids := make([]ID, len(components))
7✔
160
        for i, c := range components {
17✔
161
                ids[i] = ex.world.componentID(c.tp)
10✔
162
        }
10✔
163
        ex.remove = ids
7✔
164
        return ex
7✔
165
}
166

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

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

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

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

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

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

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

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

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

241
func (ex *Exchange2[A, B]) exchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B), remove bool, rel ...RelationIndex) {
2✔
242
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
2✔
243

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

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

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

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

293
// Removes sets the components that this [Exchange3] removes.
294
func (ex *Exchange3[A, B, C]) Removes(components ...Comp) *Exchange3[A, B, C] {
7✔
295
        ids := make([]ID, len(components))
7✔
296
        for i, c := range components {
17✔
297
                ids[i] = ex.world.componentID(c.tp)
10✔
298
        }
10✔
299
        ex.remove = ids
7✔
300
        return ex
7✔
301
}
302

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

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

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

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

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

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

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

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

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

381
func (ex *Exchange3[A, B, C]) exchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C), remove bool, rel ...RelationIndex) {
2✔
382
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
2✔
383

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

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

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

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

436
// Removes sets the components that this [Exchange4] removes.
437
func (ex *Exchange4[A, B, C, D]) Removes(components ...Comp) *Exchange4[A, B, C, D] {
7✔
438
        ids := make([]ID, len(components))
7✔
439
        for i, c := range components {
17✔
440
                ids[i] = ex.world.componentID(c.tp)
10✔
441
        }
10✔
442
        ex.remove = ids
7✔
443
        return ex
7✔
444
}
445

446
// Add the mapped components to the given entity.
447
func (ex *Exchange4[A, B, C, D]) Add(entity Entity, a *A, b *B, c *C, d *D, rel ...RelationIndex) {
1✔
448
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
1✔
449
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
450
                unsafe.Pointer(a),
1✔
451
                unsafe.Pointer(b),
1✔
452
                unsafe.Pointer(c),
1✔
453
                unsafe.Pointer(d),
1✔
454
        }, ex.relations)
1✔
455
}
1✔
456

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

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

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

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

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

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

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

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

528
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 ...RelationIndex) {
2✔
529
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
2✔
530

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

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

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

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

586
// Removes sets the components that this [Exchange5] removes.
587
func (ex *Exchange5[A, B, C, D, E]) Removes(components ...Comp) *Exchange5[A, B, C, D, E] {
7✔
588
        ids := make([]ID, len(components))
7✔
589
        for i, c := range components {
17✔
590
                ids[i] = ex.world.componentID(c.tp)
10✔
591
        }
10✔
592
        ex.remove = ids
7✔
593
        return ex
7✔
594
}
595

596
// Add the mapped components to the given entity.
597
func (ex *Exchange5[A, B, C, D, E]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, rel ...RelationIndex) {
1✔
598
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
1✔
599
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
600
                unsafe.Pointer(a),
1✔
601
                unsafe.Pointer(b),
1✔
602
                unsafe.Pointer(c),
1✔
603
                unsafe.Pointer(d),
1✔
604
                unsafe.Pointer(e),
1✔
605
        }, ex.relations)
1✔
606
}
1✔
607

608
// Remove the components previously specified with [Exchange5.Removes] from the given entity.
609
func (ex *Exchange5[A, B, C, D, E]) Remove(entity Entity) {
1✔
610
        ex.world.exchange(entity, nil, ex.remove, nil, nil)
1✔
611
}
1✔
612

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

626
// AddBatch adds the mapped components to all entities matching the given batch filter.
627
func (ex *Exchange5[A, B, C, D, E]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, rel ...RelationIndex) {
1✔
628
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
1✔
629
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
1✔
630
                unsafe.Pointer(a),
1✔
631
                unsafe.Pointer(b),
1✔
632
                unsafe.Pointer(c),
1✔
633
                unsafe.Pointer(d),
1✔
634
                unsafe.Pointer(e),
1✔
635
        }, ex.relations, nil)
1✔
636
}
1✔
637

638
// AddBatchFn adds the mapped components to all entities matching the given batch filter,
639
// running the given function on each. The function can be nil.
640
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 ...RelationIndex) {
1✔
641
        ex.exchangeBatchFn(batch, fn, false, rel...)
1✔
642
}
1✔
643

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

2✔
653
                        lock := ex.world.lock()
2✔
654
                        for i := range len {
26✔
655
                                index := uintptr(start + i)
24✔
656
                                fn(table.GetEntity(index))
24✔
657
                        }
24✔
658
                        ex.world.unlock(lock)
2✔
659
                }
660
        }
661
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
2✔
662
}
663

664
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
665
func (ex *Exchange5[A, B, C, D, E]) ExchangeBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, rel ...RelationIndex) {
1✔
666
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
1✔
667
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
1✔
668
                unsafe.Pointer(a),
1✔
669
                unsafe.Pointer(b),
1✔
670
                unsafe.Pointer(c),
1✔
671
                unsafe.Pointer(d),
1✔
672
                unsafe.Pointer(e),
1✔
673
        }, ex.relations, nil)
1✔
674
}
1✔
675

676
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
677
// running the given function on each. The function can be nil.
678
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 ...RelationIndex) {
1✔
679
        ex.exchangeBatchFn(batch, fn, true, rel...)
1✔
680
}
1✔
681

682
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 ...RelationIndex) {
2✔
683
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
2✔
684

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

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

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

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

743
// Removes sets the components that this [Exchange6] removes.
744
func (ex *Exchange6[A, B, C, D, E, F]) Removes(components ...Comp) *Exchange6[A, B, C, D, E, F] {
7✔
745
        ids := make([]ID, len(components))
7✔
746
        for i, c := range components {
17✔
747
                ids[i] = ex.world.componentID(c.tp)
10✔
748
        }
10✔
749
        ex.remove = ids
7✔
750
        return ex
7✔
751
}
752

753
// Add the mapped components to the given entity.
754
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 ...RelationIndex) {
1✔
755
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
1✔
756
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
757
                unsafe.Pointer(a),
1✔
758
                unsafe.Pointer(b),
1✔
759
                unsafe.Pointer(c),
1✔
760
                unsafe.Pointer(d),
1✔
761
                unsafe.Pointer(e),
1✔
762
                unsafe.Pointer(f),
1✔
763
        }, ex.relations)
1✔
764
}
1✔
765

766
// Remove the components previously specified with [Exchange6.Removes] from the given entity.
767
func (ex *Exchange6[A, B, C, D, E, F]) Remove(entity Entity) {
1✔
768
        ex.world.exchange(entity, nil, ex.remove, nil, nil)
1✔
769
}
1✔
770

771
// Exchange performs the exchange on the given entity, adding the provided components
772
// and removing those previously specified with [Exchange6.Removes].
773
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 ...RelationIndex) {
1✔
774
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
1✔
775
        ex.world.exchange(entity, ex.ids, ex.remove, []unsafe.Pointer{
1✔
776
                unsafe.Pointer(a),
1✔
777
                unsafe.Pointer(b),
1✔
778
                unsafe.Pointer(c),
1✔
779
                unsafe.Pointer(d),
1✔
780
                unsafe.Pointer(e),
1✔
781
                unsafe.Pointer(f),
1✔
782
        }, ex.relations)
1✔
783
}
1✔
784

785
// AddBatch adds the mapped components to all entities matching the given batch filter.
786
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 ...RelationIndex) {
1✔
787
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
1✔
788
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
1✔
789
                unsafe.Pointer(a),
1✔
790
                unsafe.Pointer(b),
1✔
791
                unsafe.Pointer(c),
1✔
792
                unsafe.Pointer(d),
1✔
793
                unsafe.Pointer(e),
1✔
794
                unsafe.Pointer(f),
1✔
795
        }, ex.relations, nil)
1✔
796
}
1✔
797

798
// AddBatchFn adds the mapped components to all entities matching the given batch filter,
799
// running the given function on each. The function can be nil.
800
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 ...RelationIndex) {
1✔
801
        ex.exchangeBatchFn(batch, fn, false, rel...)
1✔
802
}
1✔
803

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

2✔
813
                        lock := ex.world.lock()
2✔
814
                        for i := range len {
26✔
815
                                index := uintptr(start + i)
24✔
816
                                fn(table.GetEntity(index))
24✔
817
                        }
24✔
818
                        ex.world.unlock(lock)
2✔
819
                }
820
        }
821
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
2✔
822
}
823

824
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
825
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 ...RelationIndex) {
1✔
826
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
1✔
827
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
1✔
828
                unsafe.Pointer(a),
1✔
829
                unsafe.Pointer(b),
1✔
830
                unsafe.Pointer(c),
1✔
831
                unsafe.Pointer(d),
1✔
832
                unsafe.Pointer(e),
1✔
833
                unsafe.Pointer(f),
1✔
834
        }, ex.relations, nil)
1✔
835
}
1✔
836

837
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
838
// running the given function on each. The function can be nil.
839
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 ...RelationIndex) {
1✔
840
        ex.exchangeBatchFn(batch, fn, true, rel...)
1✔
841
}
1✔
842

843
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 ...RelationIndex) {
2✔
844
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
2✔
845

2✔
846
        var process func(tableID tableID, start, len int)
2✔
847
        if fn != nil {
4✔
848
                process = func(tableID tableID, start, len int) {
6✔
849
                        table := &ex.world.storage.tables[tableID]
4✔
850
                        columnA := table.GetColumn(ex.ids[0])
4✔
851
                        columnB := table.GetColumn(ex.ids[1])
4✔
852
                        columnC := table.GetColumn(ex.ids[2])
4✔
853
                        columnD := table.GetColumn(ex.ids[3])
4✔
854
                        columnE := table.GetColumn(ex.ids[4])
4✔
855
                        columnF := table.GetColumn(ex.ids[5])
4✔
856

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

880
// Exchange7 allows to exchange components of entities.
881
// It adds the given components. Use [Exchange7.Removes]
882
// to set components to be removed.
883
type Exchange7[A any, B any, C any, D any, E any, F any, G any] struct {
884
        world     *World
885
        ids       []ID
886
        remove    []ID
887
        relations []RelationID
888
}
889

890
// NewExchange7 creates an [Exchange7].
891
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✔
892
        ids := []ID{
7✔
893
                ComponentID[A](world),
7✔
894
                ComponentID[B](world),
7✔
895
                ComponentID[C](world),
7✔
896
                ComponentID[D](world),
7✔
897
                ComponentID[E](world),
7✔
898
                ComponentID[F](world),
7✔
899
                ComponentID[G](world),
7✔
900
        }
7✔
901
        return &Exchange7[A, B, C, D, E, F, G]{
7✔
902
                world: world,
7✔
903
                ids:   ids,
7✔
904
        }
7✔
905
}
7✔
906

907
// Removes sets the components that this [Exchange7] removes.
908
func (ex *Exchange7[A, B, C, D, E, F, G]) Removes(components ...Comp) *Exchange7[A, B, C, D, E, F, G] {
7✔
909
        ids := make([]ID, len(components))
7✔
910
        for i, c := range components {
17✔
911
                ids[i] = ex.world.componentID(c.tp)
10✔
912
        }
10✔
913
        ex.remove = ids
7✔
914
        return ex
7✔
915
}
916

917
// Add the mapped components to the given entity.
918
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 ...RelationIndex) {
1✔
919
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
1✔
920
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
921
                unsafe.Pointer(a),
1✔
922
                unsafe.Pointer(b),
1✔
923
                unsafe.Pointer(c),
1✔
924
                unsafe.Pointer(d),
1✔
925
                unsafe.Pointer(e),
1✔
926
                unsafe.Pointer(f),
1✔
927
                unsafe.Pointer(g),
1✔
928
        }, ex.relations)
1✔
929
}
1✔
930

931
// Remove the components previously specified with [Exchange7.Removes] from the given entity.
932
func (ex *Exchange7[A, B, C, D, E, F, G]) Remove(entity Entity) {
1✔
933
        ex.world.exchange(entity, nil, ex.remove, nil, nil)
1✔
934
}
1✔
935

936
// Exchange performs the exchange on the given entity, adding the provided components
937
// and removing those previously specified with [Exchange7.Removes].
938
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 ...RelationIndex) {
1✔
939
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
1✔
940
        ex.world.exchange(entity, ex.ids, ex.remove, []unsafe.Pointer{
1✔
941
                unsafe.Pointer(a),
1✔
942
                unsafe.Pointer(b),
1✔
943
                unsafe.Pointer(c),
1✔
944
                unsafe.Pointer(d),
1✔
945
                unsafe.Pointer(e),
1✔
946
                unsafe.Pointer(f),
1✔
947
                unsafe.Pointer(g),
1✔
948
        }, ex.relations)
1✔
949
}
1✔
950

951
// AddBatch adds the mapped components to all entities matching the given batch filter.
952
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 ...RelationIndex) {
1✔
953
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
1✔
954
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
1✔
955
                unsafe.Pointer(a),
1✔
956
                unsafe.Pointer(b),
1✔
957
                unsafe.Pointer(c),
1✔
958
                unsafe.Pointer(d),
1✔
959
                unsafe.Pointer(e),
1✔
960
                unsafe.Pointer(f),
1✔
961
                unsafe.Pointer(g),
1✔
962
        }, ex.relations, nil)
1✔
963
}
1✔
964

965
// AddBatchFn adds the mapped components to 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]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D, e *E, f *F, g *G), rel ...RelationIndex) {
1✔
968
        ex.exchangeBatchFn(batch, fn, false, rel...)
1✔
969
}
1✔
970

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

2✔
980
                        lock := ex.world.lock()
2✔
981
                        for i := range len {
26✔
982
                                index := uintptr(start + i)
24✔
983
                                fn(table.GetEntity(index))
24✔
984
                        }
24✔
985
                        ex.world.unlock(lock)
2✔
986
                }
987
        }
988
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
2✔
989
}
990

991
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
992
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 ...RelationIndex) {
1✔
993
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
1✔
994
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
1✔
995
                unsafe.Pointer(a),
1✔
996
                unsafe.Pointer(b),
1✔
997
                unsafe.Pointer(c),
1✔
998
                unsafe.Pointer(d),
1✔
999
                unsafe.Pointer(e),
1✔
1000
                unsafe.Pointer(f),
1✔
1001
                unsafe.Pointer(g),
1✔
1002
        }, ex.relations, nil)
1✔
1003
}
1✔
1004

1005
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
1006
// running the given function on each. The function can be nil.
1007
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 ...RelationIndex) {
1✔
1008
        ex.exchangeBatchFn(batch, fn, true, rel...)
1✔
1009
}
1✔
1010

1011
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 ...RelationIndex) {
2✔
1012
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
2✔
1013

2✔
1014
        var process func(tableID tableID, start, len int)
2✔
1015
        if fn != nil {
4✔
1016
                process = func(tableID tableID, start, len int) {
6✔
1017
                        table := &ex.world.storage.tables[tableID]
4✔
1018
                        columnA := table.GetColumn(ex.ids[0])
4✔
1019
                        columnB := table.GetColumn(ex.ids[1])
4✔
1020
                        columnC := table.GetColumn(ex.ids[2])
4✔
1021
                        columnD := table.GetColumn(ex.ids[3])
4✔
1022
                        columnE := table.GetColumn(ex.ids[4])
4✔
1023
                        columnF := table.GetColumn(ex.ids[5])
4✔
1024
                        columnG := table.GetColumn(ex.ids[6])
4✔
1025

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

1050
// Exchange8 allows to exchange components of entities.
1051
// It adds the given components. Use [Exchange8.Removes]
1052
// to set components to be removed.
1053
type Exchange8[A any, B any, C any, D any, E any, F any, G any, H any] struct {
1054
        world     *World
1055
        ids       []ID
1056
        remove    []ID
1057
        relations []RelationID
1058
}
1059

1060
// NewExchange8 creates an [Exchange8].
1061
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✔
1062
        ids := []ID{
7✔
1063
                ComponentID[A](world),
7✔
1064
                ComponentID[B](world),
7✔
1065
                ComponentID[C](world),
7✔
1066
                ComponentID[D](world),
7✔
1067
                ComponentID[E](world),
7✔
1068
                ComponentID[F](world),
7✔
1069
                ComponentID[G](world),
7✔
1070
                ComponentID[H](world),
7✔
1071
        }
7✔
1072
        return &Exchange8[A, B, C, D, E, F, G, H]{
7✔
1073
                world: world,
7✔
1074
                ids:   ids,
7✔
1075
        }
7✔
1076
}
7✔
1077

1078
// Removes sets the components that this [Exchange8] removes.
1079
func (ex *Exchange8[A, B, C, D, E, F, G, H]) Removes(components ...Comp) *Exchange8[A, B, C, D, E, F, G, H] {
7✔
1080
        ids := make([]ID, len(components))
7✔
1081
        for i, c := range components {
17✔
1082
                ids[i] = ex.world.componentID(c.tp)
10✔
1083
        }
10✔
1084
        ex.remove = ids
7✔
1085
        return ex
7✔
1086
}
1087

1088
// Add the mapped components to the given entity.
1089
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 ...RelationIndex) {
1✔
1090
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
1✔
1091
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
1092
                unsafe.Pointer(a),
1✔
1093
                unsafe.Pointer(b),
1✔
1094
                unsafe.Pointer(c),
1✔
1095
                unsafe.Pointer(d),
1✔
1096
                unsafe.Pointer(e),
1✔
1097
                unsafe.Pointer(f),
1✔
1098
                unsafe.Pointer(g),
1✔
1099
                unsafe.Pointer(h),
1✔
1100
        }, ex.relations)
1✔
1101
}
1✔
1102

1103
// Remove the components previously specified with [Exchange8.Removes] from the given entity.
1104
func (ex *Exchange8[A, B, C, D, E, F, G, H]) Remove(entity Entity) {
1✔
1105
        ex.world.exchange(entity, nil, ex.remove, nil, nil)
1✔
1106
}
1✔
1107

1108
// Exchange performs the exchange on the given entity, adding the provided components
1109
// and removing those previously specified with [Exchange8.Removes].
1110
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 ...RelationIndex) {
1✔
1111
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
1✔
1112
        ex.world.exchange(entity, ex.ids, ex.remove, []unsafe.Pointer{
1✔
1113
                unsafe.Pointer(a),
1✔
1114
                unsafe.Pointer(b),
1✔
1115
                unsafe.Pointer(c),
1✔
1116
                unsafe.Pointer(d),
1✔
1117
                unsafe.Pointer(e),
1✔
1118
                unsafe.Pointer(f),
1✔
1119
                unsafe.Pointer(g),
1✔
1120
                unsafe.Pointer(h),
1✔
1121
        }, ex.relations)
1✔
1122
}
1✔
1123

1124
// AddBatch adds the mapped components to all entities matching the given batch filter.
1125
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 ...RelationIndex) {
1✔
1126
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
1✔
1127
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
1✔
1128
                unsafe.Pointer(a),
1✔
1129
                unsafe.Pointer(b),
1✔
1130
                unsafe.Pointer(c),
1✔
1131
                unsafe.Pointer(d),
1✔
1132
                unsafe.Pointer(e),
1✔
1133
                unsafe.Pointer(f),
1✔
1134
                unsafe.Pointer(g),
1✔
1135
                unsafe.Pointer(h),
1✔
1136
        }, ex.relations, nil)
1✔
1137
}
1✔
1138

1139
// AddBatchFn adds the mapped components to all entities matching the given batch filter,
1140
// running the given function on each. The function can be nil.
1141
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 ...RelationIndex) {
1✔
1142
        ex.exchangeBatchFn(batch, fn, false, rel...)
1✔
1143
}
1✔
1144

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

2✔
1154
                        lock := ex.world.lock()
2✔
1155
                        for i := range len {
26✔
1156
                                index := uintptr(start + i)
24✔
1157
                                fn(table.GetEntity(index))
24✔
1158
                        }
24✔
1159
                        ex.world.unlock(lock)
2✔
1160
                }
1161
        }
1162
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
2✔
1163
}
1164

1165
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
1166
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 ...RelationIndex) {
1✔
1167
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
1✔
1168
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
1✔
1169
                unsafe.Pointer(a),
1✔
1170
                unsafe.Pointer(b),
1✔
1171
                unsafe.Pointer(c),
1✔
1172
                unsafe.Pointer(d),
1✔
1173
                unsafe.Pointer(e),
1✔
1174
                unsafe.Pointer(f),
1✔
1175
                unsafe.Pointer(g),
1✔
1176
                unsafe.Pointer(h),
1✔
1177
        }, ex.relations, nil)
1✔
1178
}
1✔
1179

1180
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
1181
// running the given function on each. The function can be nil.
1182
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 ...RelationIndex) {
1✔
1183
        ex.exchangeBatchFn(batch, fn, true, rel...)
1✔
1184
}
1✔
1185

1186
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 ...RelationIndex) {
2✔
1187
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, nil, ex.relations)
2✔
1188

2✔
1189
        var process func(tableID tableID, start, len int)
2✔
1190
        if fn != nil {
4✔
1191
                process = func(tableID tableID, start, len int) {
6✔
1192
                        table := &ex.world.storage.tables[tableID]
4✔
1193
                        columnA := table.GetColumn(ex.ids[0])
4✔
1194
                        columnB := table.GetColumn(ex.ids[1])
4✔
1195
                        columnC := table.GetColumn(ex.ids[2])
4✔
1196
                        columnD := table.GetColumn(ex.ids[3])
4✔
1197
                        columnE := table.GetColumn(ex.ids[4])
4✔
1198
                        columnF := table.GetColumn(ex.ids[5])
4✔
1199
                        columnG := table.GetColumn(ex.ids[6])
4✔
1200
                        columnH := table.GetColumn(ex.ids[7])
4✔
1201

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