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

mlange-42 / arche / 12455637666

22 Dec 2024 03:48PM CUT coverage: 100.0%. Remained the same
12455637666

Pull #442

github

web-flow
Merge dcf4cea1c into 30c1f4bc4
Pull Request #442: Update CHANGELOG for release v0.14.0

6411 of 6411 relevant lines covered (100.0%)

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

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

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

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

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

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

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

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

122
// RemoveEntities removes and recycles all entities matching a filter.
123
// Returns the number of removed entities.
124
//
125
// Panics when called on a locked world.
126
// Do not use during [Query] iteration!
127
//
128
// Unlike with the other batch operations, it is not easily possible to provide a query version RemoveEntitiesQ.
129
// However, one can simply query with the same filter before calling RemoveEntities.
130
//
131
// See also [World.RemoveEntity]
132
func (b *Batch) RemoveEntities(filter Filter) int {
25,014✔
133
        return b.world.removeEntities(filter)
25,014✔
134
}
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