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

mlange-42 / arche / 7515952855

14 Jan 2024 01:00AM CUT coverage: 100.0%. Remained the same
7515952855

push

github

web-flow
Reduce archetype size by storing layouts in a growing slice (#327)

Use a growing slice to hold archetype mem layouts, instead of a fixes-size array.

Reduces archetype size from 4 kB to 88 B, plus the heap-allocated slice. The slice starts with size 16 (i.e. 16 component types) and grows in steps of 16 up to 256.

# Commits

* reduce archetype size by storing components in a growing slice
* re-arrange test functions
* document undefined behavior for IDs out of range, update changelog
* move non-zero capacity calculation to a separate function
* check component registry limit vs. int, not uint8
* move arche-serde up in the tools list in README

4871 of 4871 relevant lines covered (100.0%)

65485.4 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
// Panics:
59
//   - when called for a missing component.
60
//   - when called for a component that is not a relation.
61
//   - when called on a locked world. Do not use during [Query] iteration!
62
//
63
// See also [Relations.Set] and [Relations.SetBatch].
64
func (b *Batch) SetRelation(filter Filter, comp ID, target Entity) {
3✔
65
        b.world.setRelationBatch(filter, comp, target)
3✔
66
}
3✔
67

68
// SetRelationQ sets the [Relation] target for many entities, matching a filter.
69
// It returns a query over the affected entities.
70
//
71
// Panics:
72
//   - when called for a missing component.
73
//   - when called for a component that is not a relation.
74
//   - when called on a locked world. Do not use during [Query] iteration!
75
//
76
// See also [Relations.Set] and [Relations.SetBatch].
77
func (b *Batch) SetRelationQ(filter Filter, comp ID, target Entity) Query {
4✔
78
        return b.world.setRelationBatchQuery(filter, comp, target)
4✔
79
}
4✔
80

81
// Exchange exchanges components for many entities, matching a filter.
82
//
83
// Panics:
84
//   - when called with components that can't be added or removed because they are already present/not present, respectively.
85
//   - when called on a locked world. Do not use during [Query] iteration!
86
//
87
// See also [Batch.ExchangeQ] and [World.Exchange].
88
func (b *Batch) Exchange(filter Filter, add []ID, rem []ID) {
4✔
89
        b.world.exchangeBatch(filter, add, rem)
4✔
90
}
4✔
91

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

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