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

mlange-42 / arche / 7577914431

19 Jan 2024 12:52AM CUT coverage: 100.0%. Remained the same
7577914431

push

github

web-flow
Make the Arche logo a link to the GitHub repository (#343)

6036 of 6036 relevant lines covered (100.0%)

53013.84 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
// Panics:
13
//   - when called with components that can't be added because they are already present.
14
//   - when called on a locked world. Do not use during [Query] iteration!
15
//
16
// See also [Batch.AddQ] and [World.Add].
17
func (b *Batch) Add(filter Filter, comps ...ID) {
3✔
18
        b.world.exchangeBatch(filter, comps, nil, ID{}, false, Entity{})
3✔
19
}
3✔
20

21
// AddQ adds components to many entities, matching a filter.
22
// It returns a query over the affected entities.
23
//
24
// Panics:
25
//   - when called with components that can't be added because they are already present.
26
//   - when called on a locked world. Do not use during [Query] iteration!
27
//
28
// See also [Batch.Add] and [World.Add].
29
func (b *Batch) AddQ(filter Filter, comps ...ID) Query {
2✔
30
        return b.world.exchangeBatchQuery(filter, comps, nil, ID{}, false, Entity{})
2✔
31
}
2✔
32

33
// Remove removes components from many entities, matching a filter.
34
//
35
// Panics:
36
//   - when called with components that can't be removed because they are not present.
37
//   - when called on a locked world. Do not use during [Query] iteration!
38
//
39
// See also [Batch.RemoveQ] and [World.Remove].
40
func (b *Batch) Remove(filter Filter, comps ...ID) {
3✔
41
        b.world.exchangeBatch(filter, nil, comps, ID{}, false, Entity{})
3✔
42
}
3✔
43

44
// RemoveQ removes components from many entities, matching a filter.
45
// It returns a query over the affected entities.
46
//
47
// Panics:
48
//   - when called with components that can't be removed because they are not present.
49
//   - when called on a locked world. Do not use during [Query] iteration!
50
//
51
// See also [Batch.Remove] and [World.Remove].
52
func (b *Batch) RemoveQ(filter Filter, comps ...ID) Query {
2✔
53
        return b.world.exchangeBatchQuery(filter, nil, comps, ID{}, false, Entity{})
2✔
54
}
2✔
55

56
// SetRelation sets the [Relation] target for many entities, matching a filter.
57
//
58
// Entities that match the filter but already have the desired target entity are not processed,
59
// and no events are emitted for them.
60
//
61
// Panics:
62
//   - when called for a missing component.
63
//   - when called for a component that is not a relation.
64
//   - when called on a locked world. Do not use during [Query] iteration!
65
//
66
// See also [Relations.Set] and [Relations.SetBatch].
67
func (b *Batch) SetRelation(filter Filter, comp ID, target Entity) {
3✔
68
        b.world.setRelationBatch(filter, comp, target)
3✔
69
}
3✔
70

71
// SetRelationQ sets the [Relation] target for many entities, matching a filter.
72
// It returns a query over the affected entities.
73
//
74
// Entities that match the filter but already have the desired target entity are not processed,
75
// not included in the query, and no events are emitted for them.
76
//
77
// Panics:
78
//   - when called for a missing component.
79
//   - when called for a component that is not a relation.
80
//   - when called on a locked world. Do not use during [Query] iteration!
81
//
82
// See also [Relations.Set] and [Relations.SetBatch].
83
func (b *Batch) SetRelationQ(filter Filter, comp ID, target Entity) Query {
4✔
84
        return b.world.setRelationBatchQuery(filter, comp, target)
4✔
85
}
4✔
86

87
// Exchange exchanges components for many entities, matching a filter.
88
//
89
// When a [Relation] component is removed and another one is added,
90
// the target entity of the relation is reset to zero.
91
//
92
// Panics:
93
//   - when called with components that can't be added or removed because they are already present/not present, respectively.
94
//   - when called on a locked world. Do not use during [Query] iteration!
95
//
96
// See also [Batch.ExchangeQ] and [World.Exchange].
97
// For batch-exchange with a relation target, see [Relations.ExchangeBatch].
98
func (b *Batch) Exchange(filter Filter, add []ID, rem []ID) {
6✔
99
        b.world.exchangeBatch(filter, add, rem, ID{}, false, Entity{})
6✔
100
}
6✔
101

102
// ExchangeQ exchanges components for many entities, matching a filter.
103
// It returns a query over the affected entities.
104
//
105
// When a [Relation] component is removed and another one is added,
106
// the target entity of the relation is reset to zero.
107
//
108
// Panics:
109
//   - when called with components that can't be added or removed because they are already present/not present, respectively.
110
//   - when called on a locked world. Do not use during [Query] iteration!
111
//
112
// See also [Batch.Exchange] and [World.Exchange].
113
// For batch-exchange with a relation target, see [Relations.ExchangeBatchQ].
114
func (b *Batch) ExchangeQ(filter Filter, add []ID, rem []ID) Query {
3✔
115
        return b.world.exchangeBatchQuery(filter, add, rem, ID{}, false, Entity{})
3✔
116
}
3✔
117

118
// RemoveEntities removes and recycles all entities matching a filter.
119
//
120
// Returns the number of removed entities.
121
//
122
// Panics when called on a locked world.
123
// Do not use during [Query] iteration!
124
//
125
// See also [World.RemoveEntity]
126
func (b *Batch) RemoveEntities(filter Filter) int {
25,014✔
127
        return b.world.removeEntities(filter)
25,014✔
128
}
25,014✔
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