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

mlange-42 / ark / 13729021549

07 Mar 2025 08:47PM CUT coverage: 99.423%. Remained the same
13729021549

push

github

web-flow
Add ark-pixel to tools (#154)

6378 of 6415 relevant lines covered (99.42%)

28138.14 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
var entityIndexSize = sizeOf(typeOf[entityIndex]())
10

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

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

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

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

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

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

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

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

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

1✔
63
        return nil
1✔
64
}
65

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