-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
v0.lisp
82 lines (65 loc) · 2.33 KB
/
v0.lisp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
(in-package #:org.shirakumo.fraf.kandria)
(defclass v0 (version) ())
(define-decoder (vec2 v0) (data _p)
(destructuring-bind (x y) data
(vec2 x y)))
(define-encoder (vec2 v0) (_b _p)
(list (vx vec2)
(vy vec2)))
(define-decoder (vec3 v0) (data _p)
(destructuring-bind (x y z) data
(vec3 x y z)))
(define-encoder (vec3 v0) (_b _p)
(list (vx vec3)
(vy vec3)
(vz vec3)))
(define-decoder (vec4 v0) (data _p)
(destructuring-bind (x y z w) data
(vec4 x y z w)))
(define-encoder (vec4 v0) (_b _p)
(list (vx vec4)
(vy vec4)
(vz vec4)
(vw vec4)))
(define-decoder (colored:rgb v0) (data _p)
(destructuring-bind (x y z &optional (a 1.0)) data
(colored:color x y z a)))
(define-encoder (colored:rgb v0) (_b _p)
(list (colored:r colored:rgb)
(colored:g colored:rgb)
(colored:b colored:rgb)))
(define-decoder (asset v0) (data _p)
(destructuring-bind (pool name) data
(asset pool name)))
(define-encoder (asset v0) (_b _p)
(list (name (pool asset))
(name asset)))
(define-decoder (resource v0) (data _p)
(destructuring-bind (pool name &optional (id T)) data
(// pool name id)))
(define-encoder (resource v0) (_b _p)
(list (name (pool (generator resource)))
(name (generator resource))
(name resource)))
(define-decoder (random-state:squirrel v0) (data _p)
(destructuring-bind (seed index) data
(let ((gen (random-state:make-generator 'random-state:squirrel seed)))
(setf (random-state:index gen) index)
gen)))
(define-encoder (random-state:squirrel v0) (_b _p)
(list (random-state:seed random-state:squirrel)
(random-state:index random-state:squirrel)))
(defmethod decode-payload (_b (bindings (eql 'bindings)) _p (v0 v0))
(loop for binding in _b
for (var type val) = (enlist binding T)
collect (cons var
(if (eql type T)
val
(decode-payload val (type-prototype type) _p v0)))))
(defmethod encode-payload ((bindings (eql 'bindings)) _b _p (v0 v0))
(loop for (var . val) in _b
collect (list* var
(etypecase val
((or string symbol number) (list t val))
(standard-object
(list (type-of val) (encode-payload val _b _p v0)))))))