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

mlange-42 / arche / 4903779843

06 May 2023 09:50PM CUT coverage: 100.0%. Remained the same
4903779843

push

github

GitHub
Optimize archetype iteration (#272)

38 of 38 new or added lines in 3 files covered. (100.0%)

3719 of 3719 relevant lines covered (100.0%)

85808.07 hits per line

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

100.0
/ecs/batch.go
1
package ecs
2

3
// Batch is a helper to perform batched operations on the world.
4
//
5
// Create using [World.Batch].
6
type Batch struct {
7
        world *World
8
}
9

10
// Add adds components to many entities, matching a filter.
11
//
12
// If the callback argument is given, it is called with a [Query] over the affected entities,
13
// one Query for each affected archetype.
14
//
15
// Panics:
16
//   - when called with components that can't be added because they are already present.
17
//   - when called on a locked world. Do not use during [Query] iteration!
18
//
19
// See also [World.Add].
20
func (b *Batch) Add(filter Filter, callback func(Query), comps ...ID) {
1✔
21
        b.world.exchangeBatch(filter, comps, nil, callback)
1✔
22
}
1✔
23

24
// Remove removes components from many entities, matching a filter.
25
//
26
// If the callback argument is given, it is called with a [Query] over the affected entities,
27
// one Query for each affected archetype.
28
//
29
// Panics:
30
//   - when called with components that can't be removed because they are not present.
31
//   - when called on a locked world. Do not use during [Query] iteration!
32
//
33
// See also [World.Remove].
34
func (b *Batch) Remove(filter Filter, callback func(Query), comps ...ID) {
2✔
35
        b.world.exchangeBatch(filter, nil, comps, callback)
2✔
36
}
2✔
37

38
// SetRelation sets the [Relation] target for many entities, matching a filter.
39
//
40
// If the callback argument is given, it is called with a [Query] over the affected entities,
41
// one Query for each affected archetype.
42
//
43
// Panics:
44
//   - when called for a missing component.
45
//   - when called for a component that is not a relation.
46
//   - when called on a locked world. Do not use during [Query] iteration!
47
//
48
// See also [Relations.Set] and [Relations.SetBatch].
49
func (b *Batch) SetRelation(filter Filter, comp ID, target Entity, callback func(Query)) {
6✔
50
        b.world.setRelationBatch(filter, comp, target, callback)
6✔
51
}
6✔
52

53
// Exchange exchanges components for many entities, matching a filter.
54
//
55
// If the callback argument is given, it is called with a [Query] over the affected entities,
56
// one Query for each affected archetype.
57
//
58
// Panics:
59
//   - when called with components that can't be added or removed because they are already present/not present, respectively.
60
//   - when called on a locked world. Do not use during [Query] iteration!
61
//
62
// See also [World.Exchange].
63
func (b *Batch) Exchange(filter Filter, add []ID, rem []ID, callback func(Query)) {
5✔
64
        b.world.exchangeBatch(filter, add, rem, callback)
5✔
65
}
5✔
66

67
// RemoveEntities removes and recycles all entities matching a filter.
68
//
69
// Returns the number of removed entities.
70
//
71
// Panics when called on a locked world.
72
// Do not use during [Query] iteration!
73
//
74
// See also [World.RemoveEntity]
75
func (b *Batch) RemoveEntities(filter Filter) int {
25,011✔
76
        return b.world.removeEntities(filter)
25,011✔
77
}
25,011✔
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