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

mlange-42 / ark / 13618795509

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

Pull #101

github

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

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

374 existing lines in 1 file now uncovered.

4386 of 5176 relevant lines covered (84.74%)

36519.03 hits per line

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

33.07
/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] {
3✔
19
        ids := []ID{
3✔
20
                ComponentID[A](world),
3✔
21
        }
3✔
22
        return &Exchange1[A]{
3✔
23
                world: world,
3✔
24
                ids:   ids,
3✔
25
        }
3✔
26
}
3✔
27

28
// Removes sets the components that this [Exchange1] removes.
29
func (ex *Exchange1[A]) Removes(components ...Comp) *Exchange1[A] {
3✔
30
        ids := make([]ID, len(components))
3✔
31
        for i, c := range components {
9✔
32
                ids[i] = ex.world.componentID(c.tp)
6✔
33
        }
6✔
34
        ex.remove = ids
3✔
35
        return ex
3✔
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, 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, 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.
NEW
61
func (ex *Exchange1[A]) AddBatch(batch *Batch, a *A, rel ...RelationIndex) {
×
NEW
62
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
63
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
×
NEW
64
                unsafe.Pointer(a),
×
NEW
65
        }, ex.relations, nil)
×
NEW
66
}
×
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.
NEW
70
func (ex *Exchange1[A]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A), rel ...RelationIndex) {
×
NEW
71
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
72

×
NEW
73
        var process func(tableID tableID, start, len int)
×
NEW
74
        if fn != nil {
×
NEW
75
                process = func(tableID tableID, start, len int) {
×
NEW
76
                        table := &ex.world.storage.tables[tableID]
×
NEW
77
                        columnA := table.GetColumn(ex.ids[0])
×
NEW
78

×
NEW
79
                        lock := ex.world.lock()
×
NEW
80
                        for i := range len {
×
NEW
81
                                index := uintptr(start + i)
×
NEW
82
                                fn(
×
NEW
83
                                        table.GetEntity(index),
×
NEW
84
                                        (*A)(columnA.Get(index)),
×
NEW
85
                                )
×
NEW
86
                        }
×
NEW
87
                        ex.world.unlock(lock)
×
88
                }
89
        }
NEW
90
        ex.world.exchangeBatch(batch, ex.ids, nil, nil, ex.relations, process)
×
91
}
92

93
// RemoveBatch removes the components previously specified with [Exchange1.Removes]
94
// from all entities matching the given batch filter,
95
// running the given function on each. The function can be nil.
NEW
96
func (ex *Exchange1[A]) RemoveBatch(batch *Batch, fn func(entity Entity)) {
×
NEW
97
        var process func(tableID tableID, start, len int)
×
NEW
98
        if fn != nil {
×
NEW
99
                process = func(tableID tableID, start, len int) {
×
NEW
100
                        table := &ex.world.storage.tables[tableID]
×
NEW
101

×
NEW
102
                        lock := ex.world.lock()
×
NEW
103
                        for i := range len {
×
NEW
104
                                index := uintptr(start + i)
×
NEW
105
                                fn(table.GetEntity(index))
×
NEW
106
                        }
×
NEW
107
                        ex.world.unlock(lock)
×
108
                }
109
        }
NEW
110
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
×
111
}
112

113
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
NEW
114
func (ex *Exchange1[A]) ExchangeBatch(batch *Batch, a *A, rel ...RelationIndex) {
×
NEW
115
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
116
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
×
NEW
117
                unsafe.Pointer(a),
×
NEW
118
        }, ex.relations, nil)
×
NEW
119
}
×
120

121
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
122
// running the given function on each. The function can be nil.
NEW
123
func (ex *Exchange1[A]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A), rel ...RelationIndex) {
×
NEW
124
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
125

×
NEW
126
        var process func(tableID tableID, start, len int)
×
NEW
127
        if fn != nil {
×
NEW
128
                process = func(tableID tableID, start, len int) {
×
NEW
129
                        table := &ex.world.storage.tables[tableID]
×
NEW
130
                        columnA := table.GetColumn(ex.ids[0])
×
NEW
131

×
NEW
132
                        lock := ex.world.lock()
×
NEW
133
                        for i := range len {
×
NEW
134
                                index := uintptr(start + i)
×
NEW
UNCOV
135
                                fn(
×
NEW
UNCOV
136
                                        table.GetEntity(index),
×
NEW
UNCOV
137
                                        (*A)(columnA.Get(index)),
×
NEW
UNCOV
138
                                )
×
NEW
UNCOV
139
                        }
×
NEW
UNCOV
140
                        ex.world.unlock(lock)
×
141
                }
142
        }
NEW
UNCOV
143
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, nil, ex.relations, process)
×
144
}
145

146
// Exchange2 allows to exchange components of entities.
147
// It adds the given components. Use [Exchange2.Removes]
148
// to set components to be removed.
149
type Exchange2[A any, B any] struct {
150
        world     *World
151
        ids       []ID
152
        remove    []ID
153
        relations []RelationID
154
}
155

156
// NewExchange2 creates an [Exchange2].
157
func NewExchange2[A any, B any](world *World) *Exchange2[A, B] {
3✔
158
        ids := []ID{
3✔
159
                ComponentID[A](world),
3✔
160
                ComponentID[B](world),
3✔
161
        }
3✔
162
        return &Exchange2[A, B]{
3✔
163
                world: world,
3✔
164
                ids:   ids,
3✔
165
        }
3✔
166
}
3✔
167

168
// Removes sets the components that this [Exchange2] removes.
169
func (ex *Exchange2[A, B]) Removes(components ...Comp) *Exchange2[A, B] {
3✔
170
        ids := make([]ID, len(components))
3✔
171
        for i, c := range components {
9✔
172
                ids[i] = ex.world.componentID(c.tp)
6✔
173
        }
6✔
174
        ex.remove = ids
3✔
175
        return ex
3✔
176
}
177

178
// Add the mapped components to the given entity.
179
func (ex *Exchange2[A, B]) Add(entity Entity, a *A, b *B, rel ...RelationIndex) {
1✔
180
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
1✔
181
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
182
                unsafe.Pointer(a),
1✔
183
                unsafe.Pointer(b),
1✔
184
        }, ex.relations)
1✔
185
}
1✔
186

187
// Remove the components previously specified with [Exchange2.Removes] from the given entity.
188
func (ex *Exchange2[A, B]) Remove(entity Entity) {
1✔
189
        ex.world.exchange(entity, nil, ex.remove, nil, nil)
1✔
190
}
1✔
191

192
// Exchange performs the exchange on the given entity, adding the provided components
193
// and removing those previously specified with [Exchange2.Removes].
194
func (ex *Exchange2[A, B]) Exchange(entity Entity, a *A, b *B, rel ...RelationIndex) {
1✔
195
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
1✔
196
        ex.world.exchange(entity, ex.ids, ex.remove, []unsafe.Pointer{
1✔
197
                unsafe.Pointer(a),
1✔
198
                unsafe.Pointer(b),
1✔
199
        }, ex.relations)
1✔
200
}
1✔
201

202
// AddBatch adds the mapped components to all entities matching the given batch filter.
NEW
203
func (ex *Exchange2[A, B]) AddBatch(batch *Batch, a *A, b *B, rel ...RelationIndex) {
×
NEW
204
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
205
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
×
NEW
206
                unsafe.Pointer(a),
×
NEW
207
                unsafe.Pointer(b),
×
NEW
208
        }, ex.relations, nil)
×
NEW
209
}
×
210

211
// AddBatchFn adds the mapped components to all entities matching the given batch filter,
212
// running the given function on each. The function can be nil.
NEW
213
func (ex *Exchange2[A, B]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B), rel ...RelationIndex) {
×
NEW
214
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
215

×
NEW
216
        var process func(tableID tableID, start, len int)
×
NEW
217
        if fn != nil {
×
NEW
218
                process = func(tableID tableID, start, len int) {
×
NEW
219
                        table := &ex.world.storage.tables[tableID]
×
NEW
220
                        columnA := table.GetColumn(ex.ids[0])
×
NEW
221
                        columnB := table.GetColumn(ex.ids[1])
×
NEW
222

×
NEW
223
                        lock := ex.world.lock()
×
NEW
224
                        for i := range len {
×
NEW
225
                                index := uintptr(start + i)
×
NEW
226
                                fn(
×
NEW
227
                                        table.GetEntity(index),
×
NEW
228
                                        (*A)(columnA.Get(index)),
×
NEW
229
                                        (*B)(columnB.Get(index)),
×
NEW
230
                                )
×
NEW
231
                        }
×
NEW
232
                        ex.world.unlock(lock)
×
233
                }
234
        }
NEW
235
        ex.world.exchangeBatch(batch, ex.ids, nil, nil, ex.relations, process)
×
236
}
237

238
// RemoveBatch removes the components previously specified with [Exchange2.Removes]
239
// from all entities matching the given batch filter,
240
// running the given function on each. The function can be nil.
NEW
241
func (ex *Exchange2[A, B]) RemoveBatch(batch *Batch, fn func(entity Entity)) {
×
NEW
242
        var process func(tableID tableID, start, len int)
×
NEW
243
        if fn != nil {
×
NEW
244
                process = func(tableID tableID, start, len int) {
×
NEW
245
                        table := &ex.world.storage.tables[tableID]
×
NEW
246

×
NEW
247
                        lock := ex.world.lock()
×
NEW
248
                        for i := range len {
×
NEW
249
                                index := uintptr(start + i)
×
NEW
250
                                fn(table.GetEntity(index))
×
NEW
251
                        }
×
NEW
252
                        ex.world.unlock(lock)
×
253
                }
254
        }
NEW
255
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
×
256
}
257

258
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
NEW
259
func (ex *Exchange2[A, B]) ExchangeBatch(batch *Batch, a *A, b *B, rel ...RelationIndex) {
×
NEW
260
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
261
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
×
NEW
262
                unsafe.Pointer(a),
×
NEW
263
                unsafe.Pointer(b),
×
NEW
264
        }, ex.relations, nil)
×
NEW
265
}
×
266

267
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
268
// running the given function on each. The function can be nil.
NEW
269
func (ex *Exchange2[A, B]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B), rel ...RelationIndex) {
×
NEW
UNCOV
270
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
UNCOV
271

×
NEW
UNCOV
272
        var process func(tableID tableID, start, len int)
×
NEW
UNCOV
273
        if fn != nil {
×
NEW
UNCOV
274
                process = func(tableID tableID, start, len int) {
×
NEW
UNCOV
275
                        table := &ex.world.storage.tables[tableID]
×
NEW
UNCOV
276
                        columnA := table.GetColumn(ex.ids[0])
×
NEW
UNCOV
277
                        columnB := table.GetColumn(ex.ids[1])
×
NEW
UNCOV
278

×
NEW
UNCOV
279
                        lock := ex.world.lock()
×
NEW
UNCOV
280
                        for i := range len {
×
NEW
UNCOV
281
                                index := uintptr(start + i)
×
NEW
UNCOV
282
                                fn(
×
NEW
UNCOV
283
                                        table.GetEntity(index),
×
NEW
UNCOV
284
                                        (*A)(columnA.Get(index)),
×
NEW
UNCOV
285
                                        (*B)(columnB.Get(index)),
×
NEW
UNCOV
286
                                )
×
NEW
UNCOV
287
                        }
×
NEW
UNCOV
288
                        ex.world.unlock(lock)
×
289
                }
290
        }
NEW
UNCOV
291
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, nil, ex.relations, process)
×
292
}
293

294
// Exchange3 allows to exchange components of entities.
295
// It adds the given components. Use [Exchange3.Removes]
296
// to set components to be removed.
297
type Exchange3[A any, B any, C any] struct {
298
        world     *World
299
        ids       []ID
300
        remove    []ID
301
        relations []RelationID
302
}
303

304
// NewExchange3 creates an [Exchange3].
305
func NewExchange3[A any, B any, C any](world *World) *Exchange3[A, B, C] {
3✔
306
        ids := []ID{
3✔
307
                ComponentID[A](world),
3✔
308
                ComponentID[B](world),
3✔
309
                ComponentID[C](world),
3✔
310
        }
3✔
311
        return &Exchange3[A, B, C]{
3✔
312
                world: world,
3✔
313
                ids:   ids,
3✔
314
        }
3✔
315
}
3✔
316

317
// Removes sets the components that this [Exchange3] removes.
318
func (ex *Exchange3[A, B, C]) Removes(components ...Comp) *Exchange3[A, B, C] {
3✔
319
        ids := make([]ID, len(components))
3✔
320
        for i, c := range components {
9✔
321
                ids[i] = ex.world.componentID(c.tp)
6✔
322
        }
6✔
323
        ex.remove = ids
3✔
324
        return ex
3✔
325
}
326

327
// Add the mapped components to the given entity.
328
func (ex *Exchange3[A, B, C]) Add(entity Entity, a *A, b *B, c *C, rel ...RelationIndex) {
1✔
329
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
1✔
330
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
331
                unsafe.Pointer(a),
1✔
332
                unsafe.Pointer(b),
1✔
333
                unsafe.Pointer(c),
1✔
334
        }, ex.relations)
1✔
335
}
1✔
336

337
// Remove the components previously specified with [Exchange3.Removes] from the given entity.
338
func (ex *Exchange3[A, B, C]) Remove(entity Entity) {
1✔
339
        ex.world.exchange(entity, nil, ex.remove, nil, nil)
1✔
340
}
1✔
341

342
// Exchange performs the exchange on the given entity, adding the provided components
343
// and removing those previously specified with [Exchange3.Removes].
344
func (ex *Exchange3[A, B, C]) Exchange(entity Entity, a *A, b *B, c *C, rel ...RelationIndex) {
1✔
345
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
1✔
346
        ex.world.exchange(entity, ex.ids, ex.remove, []unsafe.Pointer{
1✔
347
                unsafe.Pointer(a),
1✔
348
                unsafe.Pointer(b),
1✔
349
                unsafe.Pointer(c),
1✔
350
        }, ex.relations)
1✔
351
}
1✔
352

353
// AddBatch adds the mapped components to all entities matching the given batch filter.
NEW
354
func (ex *Exchange3[A, B, C]) AddBatch(batch *Batch, a *A, b *B, c *C, rel ...RelationIndex) {
×
NEW
355
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
356
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
×
NEW
357
                unsafe.Pointer(a),
×
NEW
358
                unsafe.Pointer(b),
×
NEW
359
                unsafe.Pointer(c),
×
NEW
360
        }, ex.relations, nil)
×
NEW
361
}
×
362

363
// AddBatchFn adds the mapped components to all entities matching the given batch filter,
364
// running the given function on each. The function can be nil.
NEW
365
func (ex *Exchange3[A, B, C]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C), rel ...RelationIndex) {
×
NEW
366
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
367

×
NEW
368
        var process func(tableID tableID, start, len int)
×
NEW
369
        if fn != nil {
×
NEW
370
                process = func(tableID tableID, start, len int) {
×
NEW
371
                        table := &ex.world.storage.tables[tableID]
×
NEW
372
                        columnA := table.GetColumn(ex.ids[0])
×
NEW
373
                        columnB := table.GetColumn(ex.ids[1])
×
NEW
374
                        columnC := table.GetColumn(ex.ids[2])
×
NEW
375

×
NEW
376
                        lock := ex.world.lock()
×
NEW
377
                        for i := range len {
×
NEW
378
                                index := uintptr(start + i)
×
NEW
379
                                fn(
×
NEW
380
                                        table.GetEntity(index),
×
NEW
381
                                        (*A)(columnA.Get(index)),
×
NEW
382
                                        (*B)(columnB.Get(index)),
×
NEW
383
                                        (*C)(columnC.Get(index)),
×
NEW
384
                                )
×
NEW
385
                        }
×
NEW
386
                        ex.world.unlock(lock)
×
387
                }
388
        }
NEW
389
        ex.world.exchangeBatch(batch, ex.ids, nil, nil, ex.relations, process)
×
390
}
391

392
// RemoveBatch removes the components previously specified with [Exchange3.Removes]
393
// from all entities matching the given batch filter,
394
// running the given function on each. The function can be nil.
NEW
395
func (ex *Exchange3[A, B, C]) RemoveBatch(batch *Batch, fn func(entity Entity)) {
×
NEW
396
        var process func(tableID tableID, start, len int)
×
NEW
397
        if fn != nil {
×
NEW
398
                process = func(tableID tableID, start, len int) {
×
NEW
399
                        table := &ex.world.storage.tables[tableID]
×
NEW
400

×
NEW
401
                        lock := ex.world.lock()
×
NEW
402
                        for i := range len {
×
NEW
403
                                index := uintptr(start + i)
×
NEW
404
                                fn(table.GetEntity(index))
×
NEW
405
                        }
×
NEW
406
                        ex.world.unlock(lock)
×
407
                }
408
        }
NEW
409
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
×
410
}
411

412
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
NEW
UNCOV
413
func (ex *Exchange3[A, B, C]) ExchangeBatch(batch *Batch, a *A, b *B, c *C, rel ...RelationIndex) {
×
NEW
UNCOV
414
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
UNCOV
415
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
×
NEW
UNCOV
416
                unsafe.Pointer(a),
×
NEW
UNCOV
417
                unsafe.Pointer(b),
×
NEW
UNCOV
418
                unsafe.Pointer(c),
×
NEW
UNCOV
419
        }, ex.relations, nil)
×
NEW
UNCOV
420
}
×
421

422
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
423
// running the given function on each. The function can be nil.
NEW
UNCOV
424
func (ex *Exchange3[A, B, C]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C), rel ...RelationIndex) {
×
NEW
UNCOV
425
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
UNCOV
426

×
NEW
UNCOV
427
        var process func(tableID tableID, start, len int)
×
NEW
UNCOV
428
        if fn != nil {
×
NEW
UNCOV
429
                process = func(tableID tableID, start, len int) {
×
NEW
UNCOV
430
                        table := &ex.world.storage.tables[tableID]
×
NEW
UNCOV
431
                        columnA := table.GetColumn(ex.ids[0])
×
NEW
UNCOV
432
                        columnB := table.GetColumn(ex.ids[1])
×
NEW
UNCOV
433
                        columnC := table.GetColumn(ex.ids[2])
×
NEW
UNCOV
434

×
NEW
UNCOV
435
                        lock := ex.world.lock()
×
NEW
UNCOV
436
                        for i := range len {
×
NEW
UNCOV
437
                                index := uintptr(start + i)
×
NEW
UNCOV
438
                                fn(
×
NEW
UNCOV
439
                                        table.GetEntity(index),
×
NEW
UNCOV
440
                                        (*A)(columnA.Get(index)),
×
NEW
UNCOV
441
                                        (*B)(columnB.Get(index)),
×
NEW
UNCOV
442
                                        (*C)(columnC.Get(index)),
×
NEW
UNCOV
443
                                )
×
NEW
UNCOV
444
                        }
×
NEW
UNCOV
445
                        ex.world.unlock(lock)
×
446
                }
447
        }
NEW
UNCOV
448
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, nil, ex.relations, process)
×
449
}
450

451
// Exchange4 allows to exchange components of entities.
452
// It adds the given components. Use [Exchange4.Removes]
453
// to set components to be removed.
454
type Exchange4[A any, B any, C any, D any] struct {
455
        world     *World
456
        ids       []ID
457
        remove    []ID
458
        relations []RelationID
459
}
460

461
// NewExchange4 creates an [Exchange4].
462
func NewExchange4[A any, B any, C any, D any](world *World) *Exchange4[A, B, C, D] {
3✔
463
        ids := []ID{
3✔
464
                ComponentID[A](world),
3✔
465
                ComponentID[B](world),
3✔
466
                ComponentID[C](world),
3✔
467
                ComponentID[D](world),
3✔
468
        }
3✔
469
        return &Exchange4[A, B, C, D]{
3✔
470
                world: world,
3✔
471
                ids:   ids,
3✔
472
        }
3✔
473
}
3✔
474

475
// Removes sets the components that this [Exchange4] removes.
476
func (ex *Exchange4[A, B, C, D]) Removes(components ...Comp) *Exchange4[A, B, C, D] {
3✔
477
        ids := make([]ID, len(components))
3✔
478
        for i, c := range components {
9✔
479
                ids[i] = ex.world.componentID(c.tp)
6✔
480
        }
6✔
481
        ex.remove = ids
3✔
482
        return ex
3✔
483
}
484

485
// Add the mapped components to the given entity.
486
func (ex *Exchange4[A, B, C, D]) Add(entity Entity, a *A, b *B, c *C, d *D, rel ...RelationIndex) {
1✔
487
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
1✔
488
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
489
                unsafe.Pointer(a),
1✔
490
                unsafe.Pointer(b),
1✔
491
                unsafe.Pointer(c),
1✔
492
                unsafe.Pointer(d),
1✔
493
        }, ex.relations)
1✔
494
}
1✔
495

496
// Remove the components previously specified with [Exchange4.Removes] from the given entity.
497
func (ex *Exchange4[A, B, C, D]) Remove(entity Entity) {
1✔
498
        ex.world.exchange(entity, nil, ex.remove, nil, nil)
1✔
499
}
1✔
500

501
// Exchange performs the exchange on the given entity, adding the provided components
502
// and removing those previously specified with [Exchange4.Removes].
503
func (ex *Exchange4[A, B, C, D]) Exchange(entity Entity, a *A, b *B, c *C, d *D, rel ...RelationIndex) {
1✔
504
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
1✔
505
        ex.world.exchange(entity, ex.ids, ex.remove, []unsafe.Pointer{
1✔
506
                unsafe.Pointer(a),
1✔
507
                unsafe.Pointer(b),
1✔
508
                unsafe.Pointer(c),
1✔
509
                unsafe.Pointer(d),
1✔
510
        }, ex.relations)
1✔
511
}
1✔
512

513
// AddBatch adds the mapped components to all entities matching the given batch filter.
NEW
514
func (ex *Exchange4[A, B, C, D]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, rel ...RelationIndex) {
×
NEW
515
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
516
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
×
NEW
517
                unsafe.Pointer(a),
×
NEW
518
                unsafe.Pointer(b),
×
NEW
519
                unsafe.Pointer(c),
×
NEW
520
                unsafe.Pointer(d),
×
NEW
521
        }, ex.relations, nil)
×
NEW
522
}
×
523

524
// AddBatchFn adds the mapped components to all entities matching the given batch filter,
525
// running the given function on each. The function can be nil.
NEW
526
func (ex *Exchange4[A, B, C, D]) AddBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D), rel ...RelationIndex) {
×
NEW
527
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
528

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

×
NEW
538
                        lock := ex.world.lock()
×
NEW
539
                        for i := range len {
×
NEW
540
                                index := uintptr(start + i)
×
NEW
541
                                fn(
×
NEW
542
                                        table.GetEntity(index),
×
NEW
543
                                        (*A)(columnA.Get(index)),
×
NEW
544
                                        (*B)(columnB.Get(index)),
×
NEW
545
                                        (*C)(columnC.Get(index)),
×
NEW
546
                                        (*D)(columnD.Get(index)),
×
NEW
547
                                )
×
NEW
548
                        }
×
NEW
549
                        ex.world.unlock(lock)
×
550
                }
551
        }
NEW
552
        ex.world.exchangeBatch(batch, ex.ids, nil, nil, ex.relations, process)
×
553
}
554

555
// RemoveBatch removes the components previously specified with [Exchange4.Removes]
556
// from all entities matching the given batch filter,
557
// running the given function on each. The function can be nil.
NEW
558
func (ex *Exchange4[A, B, C, D]) RemoveBatch(batch *Batch, fn func(entity Entity)) {
×
NEW
559
        var process func(tableID tableID, start, len int)
×
NEW
560
        if fn != nil {
×
NEW
UNCOV
561
                process = func(tableID tableID, start, len int) {
×
NEW
UNCOV
562
                        table := &ex.world.storage.tables[tableID]
×
NEW
UNCOV
563

×
NEW
UNCOV
564
                        lock := ex.world.lock()
×
NEW
UNCOV
565
                        for i := range len {
×
NEW
UNCOV
566
                                index := uintptr(start + i)
×
NEW
UNCOV
567
                                fn(table.GetEntity(index))
×
NEW
UNCOV
568
                        }
×
NEW
UNCOV
569
                        ex.world.unlock(lock)
×
570
                }
571
        }
NEW
UNCOV
572
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
×
573
}
574

575
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
NEW
UNCOV
576
func (ex *Exchange4[A, B, C, D]) ExchangeBatch(batch *Batch, a *A, b *B, c *C, d *D, rel ...RelationIndex) {
×
NEW
UNCOV
577
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
UNCOV
578
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
×
NEW
UNCOV
579
                unsafe.Pointer(a),
×
NEW
UNCOV
580
                unsafe.Pointer(b),
×
NEW
UNCOV
581
                unsafe.Pointer(c),
×
NEW
UNCOV
582
                unsafe.Pointer(d),
×
NEW
UNCOV
583
        }, ex.relations, nil)
×
NEW
UNCOV
584
}
×
585

586
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
587
// running the given function on each. The function can be nil.
NEW
UNCOV
588
func (ex *Exchange4[A, B, C, D]) ExchangeBatchFn(batch *Batch, fn func(entity Entity, a *A, b *B, c *C, d *D), rel ...RelationIndex) {
×
NEW
UNCOV
589
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
UNCOV
590

×
NEW
UNCOV
591
        var process func(tableID tableID, start, len int)
×
NEW
UNCOV
592
        if fn != nil {
×
NEW
UNCOV
593
                process = func(tableID tableID, start, len int) {
×
NEW
UNCOV
594
                        table := &ex.world.storage.tables[tableID]
×
NEW
UNCOV
595
                        columnA := table.GetColumn(ex.ids[0])
×
NEW
UNCOV
596
                        columnB := table.GetColumn(ex.ids[1])
×
NEW
UNCOV
597
                        columnC := table.GetColumn(ex.ids[2])
×
NEW
UNCOV
598
                        columnD := table.GetColumn(ex.ids[3])
×
NEW
UNCOV
599

×
NEW
UNCOV
600
                        lock := ex.world.lock()
×
NEW
UNCOV
601
                        for i := range len {
×
NEW
UNCOV
602
                                index := uintptr(start + i)
×
NEW
UNCOV
603
                                fn(
×
NEW
UNCOV
604
                                        table.GetEntity(index),
×
NEW
UNCOV
605
                                        (*A)(columnA.Get(index)),
×
NEW
UNCOV
606
                                        (*B)(columnB.Get(index)),
×
NEW
UNCOV
607
                                        (*C)(columnC.Get(index)),
×
NEW
UNCOV
608
                                        (*D)(columnD.Get(index)),
×
NEW
UNCOV
609
                                )
×
NEW
UNCOV
610
                        }
×
NEW
UNCOV
611
                        ex.world.unlock(lock)
×
612
                }
613
        }
NEW
UNCOV
614
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, nil, ex.relations, process)
×
615
}
616

617
// Exchange5 allows to exchange components of entities.
618
// It adds the given components. Use [Exchange5.Removes]
619
// to set components to be removed.
620
type Exchange5[A any, B any, C any, D any, E any] struct {
621
        world     *World
622
        ids       []ID
623
        remove    []ID
624
        relations []RelationID
625
}
626

627
// NewExchange5 creates an [Exchange5].
628
func NewExchange5[A any, B any, C any, D any, E any](world *World) *Exchange5[A, B, C, D, E] {
3✔
629
        ids := []ID{
3✔
630
                ComponentID[A](world),
3✔
631
                ComponentID[B](world),
3✔
632
                ComponentID[C](world),
3✔
633
                ComponentID[D](world),
3✔
634
                ComponentID[E](world),
3✔
635
        }
3✔
636
        return &Exchange5[A, B, C, D, E]{
3✔
637
                world: world,
3✔
638
                ids:   ids,
3✔
639
        }
3✔
640
}
3✔
641

642
// Removes sets the components that this [Exchange5] removes.
643
func (ex *Exchange5[A, B, C, D, E]) Removes(components ...Comp) *Exchange5[A, B, C, D, E] {
3✔
644
        ids := make([]ID, len(components))
3✔
645
        for i, c := range components {
9✔
646
                ids[i] = ex.world.componentID(c.tp)
6✔
647
        }
6✔
648
        ex.remove = ids
3✔
649
        return ex
3✔
650
}
651

652
// Add the mapped components to the given entity.
653
func (ex *Exchange5[A, B, C, D, E]) Add(entity Entity, a *A, b *B, c *C, d *D, e *E, rel ...RelationIndex) {
1✔
654
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
1✔
655
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
656
                unsafe.Pointer(a),
1✔
657
                unsafe.Pointer(b),
1✔
658
                unsafe.Pointer(c),
1✔
659
                unsafe.Pointer(d),
1✔
660
                unsafe.Pointer(e),
1✔
661
        }, ex.relations)
1✔
662
}
1✔
663

664
// Remove the components previously specified with [Exchange5.Removes] from the given entity.
665
func (ex *Exchange5[A, B, C, D, E]) Remove(entity Entity) {
1✔
666
        ex.world.exchange(entity, nil, ex.remove, nil, nil)
1✔
667
}
1✔
668

669
// Exchange performs the exchange on the given entity, adding the provided components
670
// and removing those previously specified with [Exchange5.Removes].
671
func (ex *Exchange5[A, B, C, D, E]) Exchange(entity Entity, a *A, b *B, c *C, d *D, e *E, rel ...RelationIndex) {
1✔
672
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
1✔
673
        ex.world.exchange(entity, ex.ids, ex.remove, []unsafe.Pointer{
1✔
674
                unsafe.Pointer(a),
1✔
675
                unsafe.Pointer(b),
1✔
676
                unsafe.Pointer(c),
1✔
677
                unsafe.Pointer(d),
1✔
678
                unsafe.Pointer(e),
1✔
679
        }, ex.relations)
1✔
680
}
1✔
681

682
// AddBatch adds the mapped components to all entities matching the given batch filter.
NEW
683
func (ex *Exchange5[A, B, C, D, E]) AddBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, rel ...RelationIndex) {
×
NEW
684
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
685
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
×
NEW
686
                unsafe.Pointer(a),
×
NEW
687
                unsafe.Pointer(b),
×
NEW
688
                unsafe.Pointer(c),
×
NEW
689
                unsafe.Pointer(d),
×
NEW
690
                unsafe.Pointer(e),
×
NEW
691
        }, ex.relations, nil)
×
NEW
692
}
×
693

694
// AddBatchFn adds the mapped components to all entities matching the given batch filter,
695
// running the given function on each. The function can be nil.
NEW
696
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) {
×
NEW
697
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
698

×
NEW
699
        var process func(tableID tableID, start, len int)
×
NEW
700
        if fn != nil {
×
NEW
701
                process = func(tableID tableID, start, len int) {
×
NEW
702
                        table := &ex.world.storage.tables[tableID]
×
NEW
703
                        columnA := table.GetColumn(ex.ids[0])
×
NEW
704
                        columnB := table.GetColumn(ex.ids[1])
×
NEW
705
                        columnC := table.GetColumn(ex.ids[2])
×
NEW
706
                        columnD := table.GetColumn(ex.ids[3])
×
NEW
707
                        columnE := table.GetColumn(ex.ids[4])
×
NEW
708

×
NEW
709
                        lock := ex.world.lock()
×
NEW
710
                        for i := range len {
×
NEW
711
                                index := uintptr(start + i)
×
NEW
712
                                fn(
×
NEW
713
                                        table.GetEntity(index),
×
NEW
714
                                        (*A)(columnA.Get(index)),
×
NEW
715
                                        (*B)(columnB.Get(index)),
×
NEW
716
                                        (*C)(columnC.Get(index)),
×
NEW
UNCOV
717
                                        (*D)(columnD.Get(index)),
×
NEW
UNCOV
718
                                        (*E)(columnE.Get(index)),
×
NEW
UNCOV
719
                                )
×
NEW
UNCOV
720
                        }
×
NEW
UNCOV
721
                        ex.world.unlock(lock)
×
722
                }
723
        }
NEW
UNCOV
724
        ex.world.exchangeBatch(batch, ex.ids, nil, nil, ex.relations, process)
×
725
}
726

727
// RemoveBatch removes the components previously specified with [Exchange5.Removes]
728
// from all entities matching the given batch filter,
729
// running the given function on each. The function can be nil.
NEW
UNCOV
730
func (ex *Exchange5[A, B, C, D, E]) RemoveBatch(batch *Batch, fn func(entity Entity)) {
×
NEW
UNCOV
731
        var process func(tableID tableID, start, len int)
×
NEW
UNCOV
732
        if fn != nil {
×
NEW
UNCOV
733
                process = func(tableID tableID, start, len int) {
×
NEW
UNCOV
734
                        table := &ex.world.storage.tables[tableID]
×
NEW
UNCOV
735

×
NEW
UNCOV
736
                        lock := ex.world.lock()
×
NEW
UNCOV
737
                        for i := range len {
×
NEW
UNCOV
738
                                index := uintptr(start + i)
×
NEW
UNCOV
739
                                fn(table.GetEntity(index))
×
NEW
UNCOV
740
                        }
×
NEW
UNCOV
741
                        ex.world.unlock(lock)
×
742
                }
743
        }
NEW
UNCOV
744
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
×
745
}
746

747
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
NEW
UNCOV
748
func (ex *Exchange5[A, B, C, D, E]) ExchangeBatch(batch *Batch, a *A, b *B, c *C, d *D, e *E, rel ...RelationIndex) {
×
NEW
UNCOV
749
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
UNCOV
750
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
×
NEW
UNCOV
751
                unsafe.Pointer(a),
×
NEW
UNCOV
752
                unsafe.Pointer(b),
×
NEW
UNCOV
753
                unsafe.Pointer(c),
×
NEW
UNCOV
754
                unsafe.Pointer(d),
×
NEW
UNCOV
755
                unsafe.Pointer(e),
×
NEW
UNCOV
756
        }, ex.relations, nil)
×
NEW
UNCOV
757
}
×
758

759
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
760
// running the given function on each. The function can be nil.
NEW
UNCOV
761
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) {
×
NEW
UNCOV
762
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
UNCOV
763

×
NEW
UNCOV
764
        var process func(tableID tableID, start, len int)
×
NEW
UNCOV
765
        if fn != nil {
×
NEW
UNCOV
766
                process = func(tableID tableID, start, len int) {
×
NEW
UNCOV
767
                        table := &ex.world.storage.tables[tableID]
×
NEW
UNCOV
768
                        columnA := table.GetColumn(ex.ids[0])
×
NEW
UNCOV
769
                        columnB := table.GetColumn(ex.ids[1])
×
NEW
UNCOV
770
                        columnC := table.GetColumn(ex.ids[2])
×
NEW
UNCOV
771
                        columnD := table.GetColumn(ex.ids[3])
×
NEW
UNCOV
772
                        columnE := table.GetColumn(ex.ids[4])
×
NEW
UNCOV
773

×
NEW
UNCOV
774
                        lock := ex.world.lock()
×
NEW
UNCOV
775
                        for i := range len {
×
NEW
UNCOV
776
                                index := uintptr(start + i)
×
NEW
UNCOV
777
                                fn(
×
NEW
UNCOV
778
                                        table.GetEntity(index),
×
NEW
UNCOV
779
                                        (*A)(columnA.Get(index)),
×
NEW
UNCOV
780
                                        (*B)(columnB.Get(index)),
×
NEW
UNCOV
781
                                        (*C)(columnC.Get(index)),
×
NEW
UNCOV
782
                                        (*D)(columnD.Get(index)),
×
NEW
UNCOV
783
                                        (*E)(columnE.Get(index)),
×
NEW
UNCOV
784
                                )
×
NEW
785
                        }
×
NEW
786
                        ex.world.unlock(lock)
×
787
                }
788
        }
NEW
789
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, nil, ex.relations, process)
×
790
}
791

792
// Exchange6 allows to exchange components of entities.
793
// It adds the given components. Use [Exchange6.Removes]
794
// to set components to be removed.
795
type Exchange6[A any, B any, C any, D any, E any, F any] struct {
796
        world     *World
797
        ids       []ID
798
        remove    []ID
799
        relations []RelationID
800
}
801

802
// NewExchange6 creates an [Exchange6].
803
func NewExchange6[A any, B any, C any, D any, E any, F any](world *World) *Exchange6[A, B, C, D, E, F] {
3✔
804
        ids := []ID{
3✔
805
                ComponentID[A](world),
3✔
806
                ComponentID[B](world),
3✔
807
                ComponentID[C](world),
3✔
808
                ComponentID[D](world),
3✔
809
                ComponentID[E](world),
3✔
810
                ComponentID[F](world),
3✔
811
        }
3✔
812
        return &Exchange6[A, B, C, D, E, F]{
3✔
813
                world: world,
3✔
814
                ids:   ids,
3✔
815
        }
3✔
816
}
3✔
817

818
// Removes sets the components that this [Exchange6] removes.
819
func (ex *Exchange6[A, B, C, D, E, F]) Removes(components ...Comp) *Exchange6[A, B, C, D, E, F] {
3✔
820
        ids := make([]ID, len(components))
3✔
821
        for i, c := range components {
9✔
822
                ids[i] = ex.world.componentID(c.tp)
6✔
823
        }
6✔
824
        ex.remove = ids
3✔
825
        return ex
3✔
826
}
827

828
// Add the mapped components to the given entity.
829
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✔
830
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
1✔
831
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
832
                unsafe.Pointer(a),
1✔
833
                unsafe.Pointer(b),
1✔
834
                unsafe.Pointer(c),
1✔
835
                unsafe.Pointer(d),
1✔
836
                unsafe.Pointer(e),
1✔
837
                unsafe.Pointer(f),
1✔
838
        }, ex.relations)
1✔
839
}
1✔
840

841
// Remove the components previously specified with [Exchange6.Removes] from the given entity.
842
func (ex *Exchange6[A, B, C, D, E, F]) Remove(entity Entity) {
1✔
843
        ex.world.exchange(entity, nil, ex.remove, nil, nil)
1✔
844
}
1✔
845

846
// Exchange performs the exchange on the given entity, adding the provided components
847
// and removing those previously specified with [Exchange6.Removes].
848
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✔
849
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
1✔
850
        ex.world.exchange(entity, ex.ids, ex.remove, []unsafe.Pointer{
1✔
851
                unsafe.Pointer(a),
1✔
852
                unsafe.Pointer(b),
1✔
853
                unsafe.Pointer(c),
1✔
854
                unsafe.Pointer(d),
1✔
855
                unsafe.Pointer(e),
1✔
856
                unsafe.Pointer(f),
1✔
857
        }, ex.relations)
1✔
858
}
1✔
859

860
// AddBatch adds the mapped components to all entities matching the given batch filter.
NEW
861
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) {
×
NEW
862
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
863
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
×
NEW
864
                unsafe.Pointer(a),
×
NEW
865
                unsafe.Pointer(b),
×
NEW
866
                unsafe.Pointer(c),
×
NEW
867
                unsafe.Pointer(d),
×
NEW
868
                unsafe.Pointer(e),
×
NEW
869
                unsafe.Pointer(f),
×
NEW
870
        }, ex.relations, nil)
×
NEW
871
}
×
872

873
// AddBatchFn adds the mapped components to all entities matching the given batch filter,
874
// running the given function on each. The function can be nil.
NEW
875
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) {
×
NEW
876
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
877

×
NEW
878
        var process func(tableID tableID, start, len int)
×
NEW
879
        if fn != nil {
×
NEW
UNCOV
880
                process = func(tableID tableID, start, len int) {
×
NEW
UNCOV
881
                        table := &ex.world.storage.tables[tableID]
×
NEW
UNCOV
882
                        columnA := table.GetColumn(ex.ids[0])
×
NEW
UNCOV
883
                        columnB := table.GetColumn(ex.ids[1])
×
NEW
UNCOV
884
                        columnC := table.GetColumn(ex.ids[2])
×
NEW
UNCOV
885
                        columnD := table.GetColumn(ex.ids[3])
×
NEW
UNCOV
886
                        columnE := table.GetColumn(ex.ids[4])
×
NEW
UNCOV
887
                        columnF := table.GetColumn(ex.ids[5])
×
NEW
UNCOV
888

×
NEW
UNCOV
889
                        lock := ex.world.lock()
×
NEW
UNCOV
890
                        for i := range len {
×
NEW
UNCOV
891
                                index := uintptr(start + i)
×
NEW
UNCOV
892
                                fn(
×
NEW
UNCOV
893
                                        table.GetEntity(index),
×
NEW
UNCOV
894
                                        (*A)(columnA.Get(index)),
×
NEW
UNCOV
895
                                        (*B)(columnB.Get(index)),
×
NEW
UNCOV
896
                                        (*C)(columnC.Get(index)),
×
NEW
UNCOV
897
                                        (*D)(columnD.Get(index)),
×
NEW
UNCOV
898
                                        (*E)(columnE.Get(index)),
×
NEW
UNCOV
899
                                        (*F)(columnF.Get(index)),
×
NEW
UNCOV
900
                                )
×
NEW
UNCOV
901
                        }
×
NEW
UNCOV
902
                        ex.world.unlock(lock)
×
903
                }
904
        }
NEW
UNCOV
905
        ex.world.exchangeBatch(batch, ex.ids, nil, nil, ex.relations, process)
×
906
}
907

908
// RemoveBatch removes the components previously specified with [Exchange6.Removes]
909
// from all entities matching the given batch filter,
910
// running the given function on each. The function can be nil.
NEW
UNCOV
911
func (ex *Exchange6[A, B, C, D, E, F]) RemoveBatch(batch *Batch, fn func(entity Entity)) {
×
NEW
UNCOV
912
        var process func(tableID tableID, start, len int)
×
NEW
UNCOV
913
        if fn != nil {
×
NEW
UNCOV
914
                process = func(tableID tableID, start, len int) {
×
NEW
UNCOV
915
                        table := &ex.world.storage.tables[tableID]
×
NEW
UNCOV
916

×
NEW
UNCOV
917
                        lock := ex.world.lock()
×
NEW
UNCOV
918
                        for i := range len {
×
NEW
UNCOV
919
                                index := uintptr(start + i)
×
NEW
UNCOV
920
                                fn(table.GetEntity(index))
×
NEW
UNCOV
921
                        }
×
NEW
UNCOV
922
                        ex.world.unlock(lock)
×
923
                }
924
        }
NEW
UNCOV
925
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
×
926
}
927

928
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
NEW
UNCOV
929
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) {
×
NEW
UNCOV
930
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
UNCOV
931
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
×
NEW
UNCOV
932
                unsafe.Pointer(a),
×
NEW
UNCOV
933
                unsafe.Pointer(b),
×
NEW
UNCOV
934
                unsafe.Pointer(c),
×
NEW
UNCOV
935
                unsafe.Pointer(d),
×
NEW
UNCOV
936
                unsafe.Pointer(e),
×
NEW
UNCOV
937
                unsafe.Pointer(f),
×
NEW
UNCOV
938
        }, ex.relations, nil)
×
NEW
UNCOV
939
}
×
940

941
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
942
// running the given function on each. The function can be nil.
NEW
UNCOV
943
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) {
×
NEW
UNCOV
944
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
UNCOV
945

×
NEW
UNCOV
946
        var process func(tableID tableID, start, len int)
×
NEW
UNCOV
947
        if fn != nil {
×
NEW
UNCOV
948
                process = func(tableID tableID, start, len int) {
×
NEW
UNCOV
949
                        table := &ex.world.storage.tables[tableID]
×
NEW
UNCOV
950
                        columnA := table.GetColumn(ex.ids[0])
×
NEW
951
                        columnB := table.GetColumn(ex.ids[1])
×
NEW
952
                        columnC := table.GetColumn(ex.ids[2])
×
NEW
953
                        columnD := table.GetColumn(ex.ids[3])
×
NEW
954
                        columnE := table.GetColumn(ex.ids[4])
×
NEW
955
                        columnF := table.GetColumn(ex.ids[5])
×
NEW
956

×
NEW
957
                        lock := ex.world.lock()
×
NEW
958
                        for i := range len {
×
NEW
959
                                index := uintptr(start + i)
×
NEW
960
                                fn(
×
NEW
961
                                        table.GetEntity(index),
×
NEW
962
                                        (*A)(columnA.Get(index)),
×
NEW
963
                                        (*B)(columnB.Get(index)),
×
NEW
964
                                        (*C)(columnC.Get(index)),
×
NEW
965
                                        (*D)(columnD.Get(index)),
×
NEW
966
                                        (*E)(columnE.Get(index)),
×
NEW
967
                                        (*F)(columnF.Get(index)),
×
NEW
968
                                )
×
NEW
969
                        }
×
NEW
970
                        ex.world.unlock(lock)
×
971
                }
972
        }
NEW
973
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, nil, ex.relations, process)
×
974
}
975

976
// Exchange7 allows to exchange components of entities.
977
// It adds the given components. Use [Exchange7.Removes]
978
// to set components to be removed.
979
type Exchange7[A any, B any, C any, D any, E any, F any, G any] struct {
980
        world     *World
981
        ids       []ID
982
        remove    []ID
983
        relations []RelationID
984
}
985

986
// NewExchange7 creates an [Exchange7].
987
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] {
3✔
988
        ids := []ID{
3✔
989
                ComponentID[A](world),
3✔
990
                ComponentID[B](world),
3✔
991
                ComponentID[C](world),
3✔
992
                ComponentID[D](world),
3✔
993
                ComponentID[E](world),
3✔
994
                ComponentID[F](world),
3✔
995
                ComponentID[G](world),
3✔
996
        }
3✔
997
        return &Exchange7[A, B, C, D, E, F, G]{
3✔
998
                world: world,
3✔
999
                ids:   ids,
3✔
1000
        }
3✔
1001
}
3✔
1002

1003
// Removes sets the components that this [Exchange7] removes.
1004
func (ex *Exchange7[A, B, C, D, E, F, G]) Removes(components ...Comp) *Exchange7[A, B, C, D, E, F, G] {
3✔
1005
        ids := make([]ID, len(components))
3✔
1006
        for i, c := range components {
9✔
1007
                ids[i] = ex.world.componentID(c.tp)
6✔
1008
        }
6✔
1009
        ex.remove = ids
3✔
1010
        return ex
3✔
1011
}
1012

1013
// Add the mapped components to the given entity.
1014
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✔
1015
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
1✔
1016
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
1017
                unsafe.Pointer(a),
1✔
1018
                unsafe.Pointer(b),
1✔
1019
                unsafe.Pointer(c),
1✔
1020
                unsafe.Pointer(d),
1✔
1021
                unsafe.Pointer(e),
1✔
1022
                unsafe.Pointer(f),
1✔
1023
                unsafe.Pointer(g),
1✔
1024
        }, ex.relations)
1✔
1025
}
1✔
1026

1027
// Remove the components previously specified with [Exchange7.Removes] from the given entity.
1028
func (ex *Exchange7[A, B, C, D, E, F, G]) Remove(entity Entity) {
1✔
1029
        ex.world.exchange(entity, nil, ex.remove, nil, nil)
1✔
1030
}
1✔
1031

1032
// Exchange performs the exchange on the given entity, adding the provided components
1033
// and removing those previously specified with [Exchange7.Removes].
1034
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✔
1035
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
1✔
1036
        ex.world.exchange(entity, ex.ids, ex.remove, []unsafe.Pointer{
1✔
1037
                unsafe.Pointer(a),
1✔
1038
                unsafe.Pointer(b),
1✔
1039
                unsafe.Pointer(c),
1✔
1040
                unsafe.Pointer(d),
1✔
1041
                unsafe.Pointer(e),
1✔
1042
                unsafe.Pointer(f),
1✔
1043
                unsafe.Pointer(g),
1✔
1044
        }, ex.relations)
1✔
1045
}
1✔
1046

1047
// AddBatch adds the mapped components to all entities matching the given batch filter.
NEW
1048
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) {
×
NEW
1049
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
UNCOV
1050
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
×
NEW
UNCOV
1051
                unsafe.Pointer(a),
×
NEW
UNCOV
1052
                unsafe.Pointer(b),
×
NEW
UNCOV
1053
                unsafe.Pointer(c),
×
NEW
UNCOV
1054
                unsafe.Pointer(d),
×
NEW
UNCOV
1055
                unsafe.Pointer(e),
×
NEW
UNCOV
1056
                unsafe.Pointer(f),
×
NEW
UNCOV
1057
                unsafe.Pointer(g),
×
NEW
UNCOV
1058
        }, ex.relations, nil)
×
NEW
UNCOV
1059
}
×
1060

1061
// AddBatchFn adds the mapped components to all entities matching the given batch filter,
1062
// running the given function on each. The function can be nil.
NEW
UNCOV
1063
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) {
×
NEW
UNCOV
1064
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
UNCOV
1065

×
NEW
UNCOV
1066
        var process func(tableID tableID, start, len int)
×
NEW
UNCOV
1067
        if fn != nil {
×
NEW
UNCOV
1068
                process = func(tableID tableID, start, len int) {
×
NEW
UNCOV
1069
                        table := &ex.world.storage.tables[tableID]
×
NEW
UNCOV
1070
                        columnA := table.GetColumn(ex.ids[0])
×
NEW
UNCOV
1071
                        columnB := table.GetColumn(ex.ids[1])
×
NEW
UNCOV
1072
                        columnC := table.GetColumn(ex.ids[2])
×
NEW
UNCOV
1073
                        columnD := table.GetColumn(ex.ids[3])
×
NEW
UNCOV
1074
                        columnE := table.GetColumn(ex.ids[4])
×
NEW
UNCOV
1075
                        columnF := table.GetColumn(ex.ids[5])
×
NEW
UNCOV
1076
                        columnG := table.GetColumn(ex.ids[6])
×
NEW
UNCOV
1077

×
NEW
UNCOV
1078
                        lock := ex.world.lock()
×
NEW
UNCOV
1079
                        for i := range len {
×
NEW
UNCOV
1080
                                index := uintptr(start + i)
×
NEW
UNCOV
1081
                                fn(
×
NEW
UNCOV
1082
                                        table.GetEntity(index),
×
NEW
UNCOV
1083
                                        (*A)(columnA.Get(index)),
×
NEW
UNCOV
1084
                                        (*B)(columnB.Get(index)),
×
NEW
UNCOV
1085
                                        (*C)(columnC.Get(index)),
×
NEW
UNCOV
1086
                                        (*D)(columnD.Get(index)),
×
NEW
UNCOV
1087
                                        (*E)(columnE.Get(index)),
×
NEW
UNCOV
1088
                                        (*F)(columnF.Get(index)),
×
NEW
UNCOV
1089
                                        (*G)(columnG.Get(index)),
×
NEW
UNCOV
1090
                                )
×
NEW
UNCOV
1091
                        }
×
NEW
UNCOV
1092
                        ex.world.unlock(lock)
×
1093
                }
1094
        }
NEW
UNCOV
1095
        ex.world.exchangeBatch(batch, ex.ids, nil, nil, ex.relations, process)
×
1096
}
1097

1098
// RemoveBatch removes the components previously specified with [Exchange7.Removes]
1099
// from all entities matching the given batch filter,
1100
// running the given function on each. The function can be nil.
NEW
UNCOV
1101
func (ex *Exchange7[A, B, C, D, E, F, G]) RemoveBatch(batch *Batch, fn func(entity Entity)) {
×
NEW
UNCOV
1102
        var process func(tableID tableID, start, len int)
×
NEW
UNCOV
1103
        if fn != nil {
×
NEW
UNCOV
1104
                process = func(tableID tableID, start, len int) {
×
NEW
UNCOV
1105
                        table := &ex.world.storage.tables[tableID]
×
NEW
UNCOV
1106

×
NEW
UNCOV
1107
                        lock := ex.world.lock()
×
NEW
UNCOV
1108
                        for i := range len {
×
NEW
UNCOV
1109
                                index := uintptr(start + i)
×
NEW
UNCOV
1110
                                fn(table.GetEntity(index))
×
NEW
UNCOV
1111
                        }
×
NEW
UNCOV
1112
                        ex.world.unlock(lock)
×
1113
                }
1114
        }
NEW
UNCOV
1115
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
×
1116
}
1117

1118
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
NEW
UNCOV
1119
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) {
×
NEW
UNCOV
1120
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
UNCOV
1121
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
×
NEW
UNCOV
1122
                unsafe.Pointer(a),
×
NEW
1123
                unsafe.Pointer(b),
×
NEW
1124
                unsafe.Pointer(c),
×
NEW
1125
                unsafe.Pointer(d),
×
NEW
1126
                unsafe.Pointer(e),
×
NEW
1127
                unsafe.Pointer(f),
×
NEW
1128
                unsafe.Pointer(g),
×
NEW
1129
        }, ex.relations, nil)
×
NEW
1130
}
×
1131

1132
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
1133
// running the given function on each. The function can be nil.
NEW
1134
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) {
×
NEW
1135
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
1136

×
NEW
1137
        var process func(tableID tableID, start, len int)
×
NEW
1138
        if fn != nil {
×
NEW
1139
                process = func(tableID tableID, start, len int) {
×
NEW
1140
                        table := &ex.world.storage.tables[tableID]
×
NEW
1141
                        columnA := table.GetColumn(ex.ids[0])
×
NEW
1142
                        columnB := table.GetColumn(ex.ids[1])
×
NEW
1143
                        columnC := table.GetColumn(ex.ids[2])
×
NEW
1144
                        columnD := table.GetColumn(ex.ids[3])
×
NEW
1145
                        columnE := table.GetColumn(ex.ids[4])
×
NEW
1146
                        columnF := table.GetColumn(ex.ids[5])
×
NEW
1147
                        columnG := table.GetColumn(ex.ids[6])
×
NEW
1148

×
NEW
1149
                        lock := ex.world.lock()
×
NEW
1150
                        for i := range len {
×
NEW
1151
                                index := uintptr(start + i)
×
NEW
1152
                                fn(
×
NEW
1153
                                        table.GetEntity(index),
×
NEW
1154
                                        (*A)(columnA.Get(index)),
×
NEW
1155
                                        (*B)(columnB.Get(index)),
×
NEW
1156
                                        (*C)(columnC.Get(index)),
×
NEW
1157
                                        (*D)(columnD.Get(index)),
×
NEW
1158
                                        (*E)(columnE.Get(index)),
×
NEW
1159
                                        (*F)(columnF.Get(index)),
×
NEW
1160
                                        (*G)(columnG.Get(index)),
×
NEW
1161
                                )
×
NEW
1162
                        }
×
NEW
1163
                        ex.world.unlock(lock)
×
1164
                }
1165
        }
NEW
1166
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, nil, ex.relations, process)
×
1167
}
1168

1169
// Exchange8 allows to exchange components of entities.
1170
// It adds the given components. Use [Exchange8.Removes]
1171
// to set components to be removed.
1172
type Exchange8[A any, B any, C any, D any, E any, F any, G any, H any] struct {
1173
        world     *World
1174
        ids       []ID
1175
        remove    []ID
1176
        relations []RelationID
1177
}
1178

1179
// NewExchange8 creates an [Exchange8].
1180
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] {
3✔
1181
        ids := []ID{
3✔
1182
                ComponentID[A](world),
3✔
1183
                ComponentID[B](world),
3✔
1184
                ComponentID[C](world),
3✔
1185
                ComponentID[D](world),
3✔
1186
                ComponentID[E](world),
3✔
1187
                ComponentID[F](world),
3✔
1188
                ComponentID[G](world),
3✔
1189
                ComponentID[H](world),
3✔
1190
        }
3✔
1191
        return &Exchange8[A, B, C, D, E, F, G, H]{
3✔
1192
                world: world,
3✔
1193
                ids:   ids,
3✔
1194
        }
3✔
1195
}
3✔
1196

1197
// Removes sets the components that this [Exchange8] removes.
1198
func (ex *Exchange8[A, B, C, D, E, F, G, H]) Removes(components ...Comp) *Exchange8[A, B, C, D, E, F, G, H] {
3✔
1199
        ids := make([]ID, len(components))
3✔
1200
        for i, c := range components {
9✔
1201
                ids[i] = ex.world.componentID(c.tp)
6✔
1202
        }
6✔
1203
        ex.remove = ids
3✔
1204
        return ex
3✔
1205
}
1206

1207
// Add the mapped components to the given entity.
1208
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✔
1209
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
1✔
1210
        ex.world.exchange(entity, ex.ids, nil, []unsafe.Pointer{
1✔
1211
                unsafe.Pointer(a),
1✔
1212
                unsafe.Pointer(b),
1✔
1213
                unsafe.Pointer(c),
1✔
1214
                unsafe.Pointer(d),
1✔
1215
                unsafe.Pointer(e),
1✔
1216
                unsafe.Pointer(f),
1✔
1217
                unsafe.Pointer(g),
1✔
1218
                unsafe.Pointer(h),
1✔
1219
        }, ex.relations)
1✔
1220
}
1✔
1221

1222
// Remove the components previously specified with [Exchange8.Removes] from the given entity.
1223
func (ex *Exchange8[A, B, C, D, E, F, G, H]) Remove(entity Entity) {
1✔
1224
        ex.world.exchange(entity, nil, ex.remove, nil, nil)
1✔
1225
}
1✔
1226

1227
// Exchange performs the exchange on the given entity, adding the provided components
1228
// and removing those previously specified with [Exchange8.Removes].
1229
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✔
1230
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
1✔
1231
        ex.world.exchange(entity, ex.ids, ex.remove, []unsafe.Pointer{
1✔
1232
                unsafe.Pointer(a),
1✔
1233
                unsafe.Pointer(b),
1✔
1234
                unsafe.Pointer(c),
1✔
1235
                unsafe.Pointer(d),
1✔
1236
                unsafe.Pointer(e),
1✔
1237
                unsafe.Pointer(f),
1✔
1238
                unsafe.Pointer(g),
1✔
1239
                unsafe.Pointer(h),
1✔
1240
        }, ex.relations)
1✔
1241
}
1✔
1242

1243
// AddBatch adds the mapped components to all entities matching the given batch filter.
NEW
UNCOV
1244
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) {
×
NEW
UNCOV
1245
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
UNCOV
1246
        ex.world.exchangeBatch(batch, ex.ids, nil, []unsafe.Pointer{
×
NEW
UNCOV
1247
                unsafe.Pointer(a),
×
NEW
UNCOV
1248
                unsafe.Pointer(b),
×
NEW
UNCOV
1249
                unsafe.Pointer(c),
×
NEW
UNCOV
1250
                unsafe.Pointer(d),
×
NEW
UNCOV
1251
                unsafe.Pointer(e),
×
NEW
UNCOV
1252
                unsafe.Pointer(f),
×
NEW
UNCOV
1253
                unsafe.Pointer(g),
×
NEW
UNCOV
1254
                unsafe.Pointer(h),
×
NEW
UNCOV
1255
        }, ex.relations, nil)
×
NEW
UNCOV
1256
}
×
1257

1258
// AddBatchFn adds the mapped components to all entities matching the given batch filter,
1259
// running the given function on each. The function can be nil.
NEW
UNCOV
1260
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) {
×
NEW
UNCOV
1261
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
UNCOV
1262

×
NEW
UNCOV
1263
        var process func(tableID tableID, start, len int)
×
NEW
UNCOV
1264
        if fn != nil {
×
NEW
UNCOV
1265
                process = func(tableID tableID, start, len int) {
×
NEW
UNCOV
1266
                        table := &ex.world.storage.tables[tableID]
×
NEW
UNCOV
1267
                        columnA := table.GetColumn(ex.ids[0])
×
NEW
UNCOV
1268
                        columnB := table.GetColumn(ex.ids[1])
×
NEW
UNCOV
1269
                        columnC := table.GetColumn(ex.ids[2])
×
NEW
UNCOV
1270
                        columnD := table.GetColumn(ex.ids[3])
×
NEW
UNCOV
1271
                        columnE := table.GetColumn(ex.ids[4])
×
NEW
UNCOV
1272
                        columnF := table.GetColumn(ex.ids[5])
×
NEW
UNCOV
1273
                        columnG := table.GetColumn(ex.ids[6])
×
NEW
UNCOV
1274
                        columnH := table.GetColumn(ex.ids[7])
×
NEW
UNCOV
1275

×
NEW
UNCOV
1276
                        lock := ex.world.lock()
×
NEW
UNCOV
1277
                        for i := range len {
×
NEW
UNCOV
1278
                                index := uintptr(start + i)
×
NEW
UNCOV
1279
                                fn(
×
NEW
UNCOV
1280
                                        table.GetEntity(index),
×
NEW
UNCOV
1281
                                        (*A)(columnA.Get(index)),
×
NEW
UNCOV
1282
                                        (*B)(columnB.Get(index)),
×
NEW
UNCOV
1283
                                        (*C)(columnC.Get(index)),
×
NEW
UNCOV
1284
                                        (*D)(columnD.Get(index)),
×
NEW
UNCOV
1285
                                        (*E)(columnE.Get(index)),
×
NEW
UNCOV
1286
                                        (*F)(columnF.Get(index)),
×
NEW
UNCOV
1287
                                        (*G)(columnG.Get(index)),
×
NEW
UNCOV
1288
                                        (*H)(columnH.Get(index)),
×
NEW
UNCOV
1289
                                )
×
NEW
UNCOV
1290
                        }
×
NEW
UNCOV
1291
                        ex.world.unlock(lock)
×
1292
                }
1293
        }
NEW
UNCOV
1294
        ex.world.exchangeBatch(batch, ex.ids, nil, nil, ex.relations, process)
×
1295
}
1296

1297
// RemoveBatch removes the components previously specified with [Exchange8.Removes]
1298
// from all entities matching the given batch filter,
1299
// running the given function on each. The function can be nil.
NEW
UNCOV
1300
func (ex *Exchange8[A, B, C, D, E, F, G, H]) RemoveBatch(batch *Batch, fn func(entity Entity)) {
×
NEW
UNCOV
1301
        var process func(tableID tableID, start, len int)
×
NEW
UNCOV
1302
        if fn != nil {
×
NEW
UNCOV
1303
                process = func(tableID tableID, start, len int) {
×
NEW
UNCOV
1304
                        table := &ex.world.storage.tables[tableID]
×
NEW
UNCOV
1305

×
NEW
UNCOV
1306
                        lock := ex.world.lock()
×
NEW
UNCOV
1307
                        for i := range len {
×
NEW
UNCOV
1308
                                index := uintptr(start + i)
×
NEW
UNCOV
1309
                                fn(table.GetEntity(index))
×
NEW
UNCOV
1310
                        }
×
NEW
UNCOV
1311
                        ex.world.unlock(lock)
×
1312
                }
1313
        }
NEW
UNCOV
1314
        ex.world.exchangeBatch(batch, nil, ex.remove, nil, nil, process)
×
1315
}
1316

1317
// ExchangeBatch performs the exchange on all entities matching the given batch filter.
NEW
UNCOV
1318
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) {
×
NEW
UNCOV
1319
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
UNCOV
1320
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, []unsafe.Pointer{
×
NEW
UNCOV
1321
                unsafe.Pointer(a),
×
NEW
UNCOV
1322
                unsafe.Pointer(b),
×
NEW
UNCOV
1323
                unsafe.Pointer(c),
×
NEW
UNCOV
1324
                unsafe.Pointer(d),
×
NEW
UNCOV
1325
                unsafe.Pointer(e),
×
NEW
UNCOV
1326
                unsafe.Pointer(f),
×
NEW
UNCOV
1327
                unsafe.Pointer(g),
×
NEW
UNCOV
1328
                unsafe.Pointer(h),
×
NEW
UNCOV
1329
        }, ex.relations, nil)
×
NEW
UNCOV
1330
}
×
1331

1332
// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
1333
// running the given function on each. The function can be nil.
NEW
UNCOV
1334
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) {
×
NEW
UNCOV
1335
        ex.relations = relations(rel).toRelations(&ex.world.storage.registry, ex.ids, ex.relations)
×
NEW
UNCOV
1336

×
NEW
UNCOV
1337
        var process func(tableID tableID, start, len int)
×
NEW
UNCOV
1338
        if fn != nil {
×
NEW
UNCOV
1339
                process = func(tableID tableID, start, len int) {
×
NEW
UNCOV
1340
                        table := &ex.world.storage.tables[tableID]
×
NEW
UNCOV
1341
                        columnA := table.GetColumn(ex.ids[0])
×
NEW
UNCOV
1342
                        columnB := table.GetColumn(ex.ids[1])
×
NEW
UNCOV
1343
                        columnC := table.GetColumn(ex.ids[2])
×
NEW
UNCOV
1344
                        columnD := table.GetColumn(ex.ids[3])
×
NEW
UNCOV
1345
                        columnE := table.GetColumn(ex.ids[4])
×
NEW
UNCOV
1346
                        columnF := table.GetColumn(ex.ids[5])
×
NEW
UNCOV
1347
                        columnG := table.GetColumn(ex.ids[6])
×
NEW
UNCOV
1348
                        columnH := table.GetColumn(ex.ids[7])
×
NEW
UNCOV
1349

×
NEW
UNCOV
1350
                        lock := ex.world.lock()
×
NEW
UNCOV
1351
                        for i := range len {
×
NEW
UNCOV
1352
                                index := uintptr(start + i)
×
NEW
UNCOV
1353
                                fn(
×
NEW
UNCOV
1354
                                        table.GetEntity(index),
×
NEW
UNCOV
1355
                                        (*A)(columnA.Get(index)),
×
NEW
UNCOV
1356
                                        (*B)(columnB.Get(index)),
×
NEW
UNCOV
1357
                                        (*C)(columnC.Get(index)),
×
NEW
UNCOV
1358
                                        (*D)(columnD.Get(index)),
×
NEW
UNCOV
1359
                                        (*E)(columnE.Get(index)),
×
NEW
UNCOV
1360
                                        (*F)(columnF.Get(index)),
×
NEW
UNCOV
1361
                                        (*G)(columnG.Get(index)),
×
NEW
UNCOV
1362
                                        (*H)(columnH.Get(index)),
×
NEW
UNCOV
1363
                                )
×
NEW
UNCOV
1364
                        }
×
NEW
UNCOV
1365
                        ex.world.unlock(lock)
×
1366
                }
1367
        }
NEW
UNCOV
1368
        ex.world.exchangeBatch(batch, ex.ids, ex.remove, nil, ex.relations, process)
×
1369
}
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