• 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/entity.go
1
package ecs
2

3
import "reflect"
4

5
// Reflection type of an [Entity].
6
var entityType = reflect.TypeOf(Entity{})
7

8
// Size of an [Entity] in memory, in bytes.
9
var entitySize uint32 = uint32(entityType.Size())
10

11
// Size of an [entityIndex] in memory.
12
var entityIndexSize uint32 = uint32(reflect.TypeOf(entityIndex{}).Size())
13

14
// Entity identifier.
15
// Holds an entity ID and it's generation for recycling.
16
//
17
// Entities are only created via the [World], using [World.NewEntity] or [World.NewEntityWith].
18
// Batch creation of entities is possible via [Builder].
19
//
20
// ⚠️ Important:
21
// Entities are intended to be stored and passed around via copy, not via pointers!
22
// The zero value should be used to indicate "nil", and can be checked with [Entity.IsZero].
23
type Entity struct {
24
        id  eid    // Entity ID
25
        gen uint16 // Entity generation
26
}
27

28
// newEntity creates a new Entity.
29
func newEntity(id eid) Entity {
262,856✔
30
        return Entity{id, 0}
262,856✔
31
}
262,856✔
32

33
// newEntityGen creates a new Entity with a given generation.
34
func newEntityGen(id eid, gen uint16) Entity {
16✔
35
        return Entity{id, gen}
16✔
36
}
16✔
37

38
// IsZero returns whether this entity is the reserved zero entity.
39
func (e Entity) IsZero() bool {
87,970✔
40
        return e.id == 0
87,970✔
41
}
87,970✔
42

43
// entityIndex indicates where an entity is currently stored.
44
type entityIndex struct {
45
        arch  *archetype // Entity's current archetype
46
        index uint32     // Entity's current index in the archetype
47
}
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