-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserialization.go
66 lines (51 loc) · 1.36 KB
/
serialization.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package ecs
import (
"sync"
"github.com/BurntSushi/toml"
"github.com/google/uuid"
)
type Printer interface {
Printf(fmt string, args ...interface{})
}
var (
SerializerLogger Printer
)
type SerializedWorld struct {
Entities []SerializedEntity `toml:"entities"`
ComponentIndex ComponentIndex `toml:"component_index"`
Enabled bool `toml:"enabled"`
}
type DeserializedWorld struct {
Entities []DeserializedEntity `toml:"entities"`
ComponentIndex ComponentIndex `toml:"component_index"`
Enabled bool `toml:"enabled"`
}
type DeserializedEntity struct {
UUID uuid.UUID `toml:"uuid"`
Components []DeserializedComponentData `toml:"components"`
}
type SerializedEntity struct {
UUID uuid.UUID `toml:"uuid"`
Components []interface{} `toml:"components"`
}
type DeserializedComponentData struct {
CI int `toml:"ci"` // component index
Data toml.Primitive `toml:"data"`
}
type SerializedComponentData struct {
CI int `toml:"ci"` // component index
Data interface{} `toml:"data"`
}
type Encoder interface {
Encode(interface{}) error
}
var encoderMutex sync.Mutex
var encoderWorld *World
var decoderMutex sync.Mutex
var decoderWorld *World
func setEncoderWorld(w *World) {
encoderWorld = w
}
func setDecoderWorld(w *World) {
decoderWorld = w
}