forked from Minetest-j45/mt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ao.go
201 lines (163 loc) · 3.22 KB
/
ao.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package mt
import (
"fmt"
"image/color"
"io"
)
type AOID uint16
type aoType uint8
const genericCAO aoType = 101
type AOInitData struct {
// Version.
//mt:const uint8(1)
// For players.
Name string
IsPlayer bool
ID AOID
Pos
Rot [3]float32
HP uint16
// See (de)serialize.fmt.
Msgs []AOMsg
}
type AOProps struct {
// Version.
//mt:const uint8(4)
MaxHP uint16 // Player only.
CollideWithNodes bool
Weight float32 // deprecated
ColBox, SelBox Box
Pointable bool
Visual string
VisualSize [3]float32
Textures []Texture
SpriteSheetSize [2]int16 // in sprites.
SpritePos [2]int16 // in sprite sheet.
Visible bool
MakeFootstepSnds bool
RotateSpeed float32 // in radians per second.
Mesh string
Colors []color.NRGBA
CollideWithAOs bool
StepHeight float32
FaceRotateDir bool
FaceRotateDirOff float32 // in degrees.
BackfaceCull bool
Nametag string
NametagColor color.NRGBA
FaceRotateSpeed float32 // in degrees per second.
Infotext string
Itemstring string
Glow int8
MaxBreath uint16 // Player only.
EyeHeight float32 // Player only.
ZoomFOV float32 // in degrees. Player only.
UseTextureAlpha bool
DmgTextureMod Texture // suffix
Shaded bool
ShowOnMinimap bool
NametagBG color.NRGBA
}
type AOPos struct {
Pos
Vel, Acc Vec
Rot [3]float32
Interpolate bool
End bool
UpdateInterval float32
}
type AOSprite struct {
Frame0 [2]int16
Frames uint16
FrameDuration float32
ViewAngleFrames bool
}
type AOAnim struct {
Frames [2]int32
Speed float32
Blend float32
NoLoop bool
}
type AOBonePos struct {
Pos Vec
Rot [3]float32
}
type AOAttach struct {
ParentID AOID
Bone string
Pos Vec
Rot [3]float32
ForceVisible bool
}
type AOPhysOverride struct {
Walk, Jump, Gravity float32
// Player only.
NoSneak, NoSneakGlitch, OldSneak bool
}
type AOCmdProps struct {
Props AOProps
}
type AOCmdPos struct {
Pos AOPos
}
type AOCmdTextureMod struct {
Mod Texture // suffix
}
type AOCmdSprite struct {
Sprite AOSprite
}
type AOCmdHP struct {
HP uint16
}
type AOCmdArmorGroups struct {
Armor []Group
}
type AOCmdAnim struct {
Anim AOAnim
}
type AOCmdBonePos struct {
Bone string
Pos AOBonePos
}
type AOCmdAttach struct {
Attach AOAttach
}
type AOCmdPhysOverride struct {
Phys AOPhysOverride
}
type AOCmdSpawnInfant struct {
ID AOID
// Type.
//mt:const genericCAO
}
type AOCmdAnimSpeed struct {
Speed float32
}
type AOMsg interface {
aoCmdNo() uint8
}
//go:generate ./cmdno.sh aocmds AOCmd ao uint8 AOMsg newAOMsg
func writeAOMsg(w io.Writer, msg AOMsg) error {
if _, err := w.Write([]byte{msg.aoCmdNo()}); err != nil {
return err
}
return serialize(w, msg)
}
func readAOMsg(r io.Reader) (AOMsg, error) {
buf := make([]byte, 1)
if _, err := io.ReadFull(r, buf); err != nil {
return nil, err
}
newCmd, ok := newAOMsg[buf[0]]
if !ok {
return nil, fmt.Errorf("unsupported ao msg: %d", buf[0])
}
msg := newCmd()
return msg, deserialize(r, msg)
}
type IDAOMsg struct {
ID AOID
//mt:lenhdr 16
Msg AOMsg
//mt:end
}