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

mlange-42 / arche / 7464066922

09 Jan 2024 04:37PM CUT coverage: 100.0%. Remained the same
7464066922

push

github

web-flow
Extend to a maximum of 256 component types (#313)

Rework `Mask` to hold an array of 4 x `uint64` to represent 256 bits. Everything else comes into place almost by itself.

Alternative to #312:

- `Filter.Match` takes a mask pointer as argument
- `Mask` is copied when using as a filter (is pointer receiver in #312)

Primarily avoids `All(ids...)` either returning a pointer, or requiring users to store the result (temporarily) to be able to get a pointer to it.

Performance remains unchanged, except that `MaskFilter` matches are about 3 times slower (i.e. filters with component inclusion and exclusion). Not sure why, as the mask functions used there are as fast as before.

## Commits

* Extend to a maximum of 256 component types
* fix IdMap for 265 possible IDs
* filters match against pointer to mask, to avoid copying
* minor optimization: check for zero mask at end of MaskFilter conditions
* make internal Mask representation private
* update changelog and readme

3835 of 3835 relevant lines covered (100.0%)

83072.29 hits per line

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

100.0
/ecs/archetypes.go
1
package ecs
2

3
// Interface for an iterator over archetypes.
4
type archetypes interface {
5
        Get(index int32) *archetype
6
        Len() int32
7
}
8

9
// Implementation of an archetype iterator for a single archetype.
10
// Implements [archetypes].
11
type singleArchetype struct {
12
        Archetype *archetype
13
}
14

15
// Get returns the value at the given index.
16
func (s singleArchetype) Get(index int32) *archetype {
100,662✔
17
        return s.Archetype
100,662✔
18
}
100,662✔
19

20
// Len returns the current number of items in the paged array.
21
func (s singleArchetype) Len() int32 {
100,062✔
22
        return 1
100,062✔
23
}
100,062✔
24

25
// Implementation of an archetype iterator for a single archetype and partial iteration.
26
// Implements [archetypes].
27
//
28
// Used for the [Query] returned by entity batch creation methods.
29
type batchArchetypes struct {
30
        Archetype    []*archetype
31
        StartIndex   []uint32
32
        EndIndex     []uint32
33
        OldArchetype []*archetype
34
        Added        []ID
35
        Removed      []ID
36
}
37

38
// Get returns the value at the given index.
39
func (s *batchArchetypes) Get(index int32) *archetype {
73✔
40
        return s.Archetype[index]
73✔
41
}
73✔
42

43
// Len returns the current number of items in the paged array.
44
func (s *batchArchetypes) Len() int32 {
134✔
45
        return int32(len(s.Archetype))
134✔
46
}
134✔
47

48
func (s *batchArchetypes) Add(arch, oldArch *archetype, start, end uint32) {
70✔
49
        s.Archetype = append(s.Archetype, arch)
70✔
50
        s.OldArchetype = append(s.OldArchetype, oldArch)
70✔
51
        s.StartIndex = append(s.StartIndex, start)
70✔
52
        s.EndIndex = append(s.EndIndex, end)
70✔
53
}
70✔
54

55
// Implementation of an archetype iterator for pointers.
56
// Implements [archetypes].
57
//
58
// Used for tracking filter archetypes in [Cache].
59
type pointers[T any] struct {
60
        pointers []*T
61
}
62

63
// Get returns the value at the given index.
64
func (a *pointers[T]) Get(index int32) *T {
9✔
65
        return a.pointers[index]
9✔
66
}
9✔
67

68
// Add an element.
69
func (a *pointers[T]) Add(elem *T) {
32✔
70
        a.pointers = append(a.pointers, elem)
32✔
71
}
32✔
72

73
// RemoveAt swap-removes an element at a given index.
74
//
75
// Returns whether it was a swap.
76
func (a *pointers[T]) RemoveAt(index int) bool {
9✔
77
        ln := len(a.pointers)
9✔
78
        if index == ln-1 {
13✔
79
                a.pointers[index] = nil
4✔
80
                a.pointers = a.pointers[:index]
4✔
81
                return false
4✔
82
        }
4✔
83
        a.pointers[index], a.pointers[ln-1] = a.pointers[ln-1], nil
5✔
84
        a.pointers = a.pointers[:ln-1]
5✔
85
        return true
5✔
86
}
87

88
// Len returns the current number of items in the paged array.
89
func (a *pointers[T]) Len() int32 {
20✔
90
        return int32(len(a.pointers))
20✔
91
}
20✔
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