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

mlange-42 / ark / 13665123960

04 Mar 2025 11:39PM CUT coverage: 99.297% (+0.02%) from 99.28%
13665123960

Pull #131

github

web-flow
Merge 2d561f24a into 06677b7f6
Pull Request #131: Check validity of relations when creating tables

8 of 9 new or added lines in 1 file covered. (88.89%)

5794 of 5835 relevant lines covered (99.3%)

35032.0 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
// IsZero returns whether this entity is the reserved zero entity.
23
func (e Entity) IsZero() bool {
138✔
24
        return e.id == 0
138✔
25
}
138✔
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.
35
func (e Entity) MarshalJSON() ([]byte, error) {
1✔
36
        arr := [2]uint32{uint32(e.id), e.gen}
1✔
37
        jsonValue, _ := json.Marshal(arr) // Ignore the error, as we can be sure this works.
1✔
38
        return jsonValue, nil
1✔
39
}
1✔
40

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

1✔
52
        return nil
1✔
53
}
54

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

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