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

mlange-42 / ark / 13683680318

05 Mar 2025 07:11PM CUT coverage: 99.318% (+0.002%) from 99.316%
13683680318

Pull #136

github

web-flow
Merge 0b4eff22d into c73c750d7
Pull Request #136: Add World.NewEntities

14 of 14 new or added lines in 1 file covered. (100.0%)

5824 of 5864 relevant lines covered (99.32%)

35696.89 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 "encoding/json"
4

5
type entityID uint32
6

7
var entityType = typeOf[Entity]()
8
var entitySize = sizeOf(entityType)
9

10
//var wildcard = Entity{1, 0}
11

12
// Entity identifier.
13
type Entity struct {
14
        id  entityID // Entity ID
15
        gen uint32   // Entity generation
16
}
17

18
func newEntity(id entityID) Entity {
8✔
19
        return Entity{id, 0}
8✔
20
}
8✔
21

22
// ID returns the entity's ID, primarily for debugging purposes.
23
func (e Entity) ID() uint32 {
101✔
24
        return uint32(e.id)
101✔
25
}
101✔
26

27
// Gen returns the entity's generation, primarily for debugging purposes.
28
func (e Entity) Gen() uint32 {
1✔
29
        return e.gen
1✔
30
}
1✔
31

32
// IsZero returns whether this entity is the reserved zero entity.
33
func (e Entity) IsZero() bool {
946✔
34
        return e.id == 0
946✔
35
}
946✔
36

37
// isWildcard returns whether this entity is the reserved wildcard entity.
38
func (e Entity) isWildcard() bool {
1✔
39
        return e.id == 1
1✔
40
}
1✔
41

42
// MarshalJSON returns a JSON representation of the entity, for serialization purposes.
43
//
44
// The JSON representation of an entity is a two-element array of entity ID and generation.
45
func (e Entity) MarshalJSON() ([]byte, error) {
1✔
46
        arr := [2]uint32{uint32(e.id), e.gen}
1✔
47
        jsonValue, _ := json.Marshal(arr) // Ignore the error, as we can be sure this works.
1✔
48
        return jsonValue, nil
1✔
49
}
1✔
50

51
// UnmarshalJSON into an entity.
52
//
53
// For serialization purposes only. Do not use this to create entities!
54
func (e *Entity) UnmarshalJSON(data []byte) error {
2✔
55
        arr := [2]uint32{}
2✔
56
        if err := json.Unmarshal(data, &arr); err != nil {
3✔
57
                return err
1✔
58
        }
1✔
59
        e.id = entityID(arr[0])
1✔
60
        e.gen = arr[1]
1✔
61

1✔
62
        return nil
1✔
63
}
64

65
// entityIndex denotes an entity's location by table and row index.
66
type entityIndex struct {
67
        table tableID
68
        row   uint32
69
}
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