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

mlange-42 / ark / 13604663297

01 Mar 2025 12:16PM CUT coverage: 94.752% (-2.3%) from 97.025%
13604663297

Pull #83

github

web-flow
Merge ca5080db9 into 3013a616a
Pull Request #83: Add functionality required for (de)-serialization

19 of 112 new or added lines in 4 files covered. (16.96%)

3737 of 3944 relevant lines covered (94.75%)

47657.17 hits per line

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

54.84
/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
// IsZero returns whether this entity is the reserved zero entity.
23
func (e Entity) IsZero() bool {
46✔
24
        return e.id == 0
46✔
25
}
46✔
26

27
// isWildcard returns whether this entity is the reserved wildcard entity.
28
func (e Entity) isWildcard() bool {
1✔
29
        return e.id == 1
1✔
30
}
1✔
31

32
// MarshalJSON returns a JSON representation of the entity, for serialization purposes.
33
//
34
// The JSON representation of an entity is a two-element array of entity ID and generation.
NEW
35
func (e Entity) MarshalJSON() ([]byte, error) {
×
NEW
36
        arr := [2]uint32{uint32(e.id), e.gen}
×
NEW
37
        jsonValue, _ := json.Marshal(arr) // Ignore the error, as we can be sure this works.
×
NEW
38
        return jsonValue, nil
×
NEW
39
}
×
40

41
// UnmarshalJSON into an entity.
42
//
43
// For serialization purposes only. Do not use this to create entities!
NEW
44
func (e *Entity) UnmarshalJSON(data []byte) error {
×
NEW
45
        arr := [2]uint32{}
×
NEW
46
        if err := json.Unmarshal(data, &arr); err != nil {
×
NEW
47
                return err
×
NEW
48
        }
×
NEW
49
        e.id = entityID(arr[0])
×
NEW
50
        e.gen = arr[1]
×
NEW
51

×
NEW
52
        return nil
×
53
}
54

55
func (e Entity) toRelation(id ID, out []RelationID) []RelationID {
34✔
56
        out = out[:0]
34✔
57
        out = append(out, RelationID{
34✔
58
                component: id,
34✔
59
                target:    Entity(e),
34✔
60
        })
34✔
61
        return out
34✔
62
}
34✔
63

64
type entityIndex struct {
65
        table tableID
66
        row   uint32
67
}
68

69
type entities []entityIndex
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