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

mlange-42 / arche / 7558406615

17 Jan 2024 04:00PM CUT coverage: 100.0%. Remained the same
7558406615

push

github

web-flow
Fix component subscription logic (#337)

* use saparate masks for component addition and removal -- was not taken into account correctly
* fix component subscription logic -- some relation subscriptions could get lost
* tweak docs of listener implementations

# Commits

* tweak docs of listener implementations
* fix and tweak conditions in determining listener subscription
* use only triggered event type bits for component subscription check
* move check for event type subscription into utility function
* use separate added and removed masks in events and subscription logic
* check for trigger before calling subscription logic

5225 of 5225 relevant lines covered (100.0%)

61206.13 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) {
2✔
18
        b.world.exchangeBatch(filter, comps, nil)
2✔
19
}
2✔
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)
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)
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)
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
// Panics:
90
//   - when called with components that can't be added or removed because they are already present/not present, respectively.
91
//   - when called on a locked world. Do not use during [Query] iteration!
92
//
93
// See also [Batch.ExchangeQ] and [World.Exchange].
94
func (b *Batch) Exchange(filter Filter, add []ID, rem []ID) {
4✔
95
        b.world.exchangeBatch(filter, add, rem)
4✔
96
}
4✔
97

98
// ExchangeQ exchanges components for many entities, matching a filter.
99
// It returns a query over the affected entities.
100
//
101
// Panics:
102
//   - when called with components that can't be added or removed because they are already present/not present, respectively.
103
//   - when called on a locked world. Do not use during [Query] iteration!
104
//
105
// See also [Batch.Exchange] and [World.Exchange].
106
func (b *Batch) ExchangeQ(filter Filter, add []ID, rem []ID) Query {
3✔
107
        return b.world.exchangeBatchQuery(filter, add, rem)
3✔
108
}
3✔
109

110
// RemoveEntities removes and recycles all entities matching a filter.
111
//
112
// Returns the number of removed entities.
113
//
114
// Panics when called on a locked world.
115
// Do not use during [Query] iteration!
116
//
117
// See also [World.RemoveEntity]
118
func (b *Batch) RemoveEntities(filter Filter) int {
25,014✔
119
        return b.world.removeEntities(filter)
25,014✔
120
}
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