]> git.lizzy.rs Git - mt.git/blob - ao.go
Add WaitGroup to SerializePkt
[mt.git] / ao.go
1 package mt
2
3 import (
4         "fmt"
5         "image/color"
6         "io"
7 )
8
9 type AOID uint16
10
11 type aoType uint8
12
13 const genericCAO aoType = 101
14
15 type AOInitData struct {
16         // Version.
17         //mt:const uint8(1)
18
19         // For players.
20         Name     string
21         IsPlayer bool
22
23         ID AOID
24
25         Pos
26         Rot [3]float32
27
28         HP uint16
29
30         // See (de)serialize.fmt.
31         Msgs []AOMsg
32 }
33
34 type AOProps struct {
35         // Version.
36         //mt:const uint8(4)
37
38         MaxHP            uint16 // Player only.
39         CollideWithNodes bool
40         Weight           float32 // deprecated
41         ColBox, SelBox   Box
42         Pointable        bool
43         Visual           string
44         VisualSize       [3]float32
45         Textures         []Texture
46         SpriteSheetSize  [2]int16 // in sprites.
47         SpritePos        [2]int16 // in sprite sheet.
48         Visible          bool
49         MakeFootstepSnds bool
50         RotateSpeed      float32 // in radians per second.
51         Mesh             string
52         Colors           []color.NRGBA
53         CollideWithAOs   bool
54         StepHeight       float32
55         FaceRotateDir    bool
56         FaceRotateDirOff float32 // in degrees.
57         BackfaceCull     bool
58         Nametag          string
59         NametagColor     color.NRGBA
60         FaceRotateSpeed  float32 // in degrees per second.
61         Infotext         string
62         Itemstring       string
63         Glow             int8
64         MaxBreath        uint16  // Player only.
65         EyeHeight        float32 // Player only.
66         ZoomFOV          float32 // in degrees. Player only.
67         UseTextureAlpha  bool
68         DmgTextureMod    Texture // suffix
69         Shaded           bool
70         ShowOnMinimap    bool
71         NametagBG        color.NRGBA
72 }
73
74 type AOPos struct {
75         Pos
76         Vel, Acc Vec
77         Rot      [3]float32
78
79         Interpolate    bool
80         End            bool
81         UpdateInterval float32
82 }
83
84 type AOSprite struct {
85         Frame0          [2]int16
86         Frames          uint16
87         FrameDuration   float32
88         ViewAngleFrames bool
89 }
90
91 type AOAnim struct {
92         Frames [2]int32
93         Speed  float32
94         Blend  float32
95         NoLoop bool
96 }
97
98 type AOBonePos struct {
99         Pos Vec
100         Rot [3]float32
101 }
102
103 type AOAttach struct {
104         ParentID     AOID
105         Bone         string
106         Pos          Vec
107         Rot          [3]float32
108         ForceVisible bool
109 }
110
111 type AOPhysOverride struct {
112         Walk, Jump, Gravity float32
113
114         // Player only.
115         NoSneak, NoSneakGlitch, OldSneak bool
116 }
117
118 type AOCmdProps struct {
119         Props AOProps
120 }
121
122 type AOCmdPos struct {
123         Pos AOPos
124 }
125
126 type AOCmdTextureMod struct {
127         Mod Texture // suffix
128 }
129
130 type AOCmdSprite struct {
131         Sprite AOSprite
132 }
133
134 type AOCmdHP struct {
135         HP uint16
136 }
137
138 type AOCmdArmorGroups struct {
139         Armor []Group
140 }
141
142 type AOCmdAnim struct {
143         Anim AOAnim
144 }
145
146 type AOCmdBonePos struct {
147         Bone string
148         Pos  AOBonePos
149 }
150
151 type AOCmdAttach struct {
152         Attach AOAttach
153 }
154
155 type AOCmdPhysOverride struct {
156         Phys AOPhysOverride
157 }
158
159 type AOCmdSpawnInfant struct {
160         ID AOID
161
162         // Type.
163         //mt:const genericCAO
164 }
165
166 type AOCmdAnimSpeed struct {
167         Speed float32
168 }
169
170 type AOMsg interface {
171         aoCmdNo() uint8
172 }
173
174 //go:generate ./cmdno.sh aocmds AOCmd ao uint8 AOMsg newAOMsg
175
176 func writeAOMsg(w io.Writer, msg AOMsg) error {
177         if _, err := w.Write([]byte{msg.aoCmdNo()}); err != nil {
178                 return err
179         }
180         return serialize(w, msg)
181 }
182
183 func readAOMsg(r io.Reader) (AOMsg, error) {
184         buf := make([]byte, 1)
185         if _, err := io.ReadFull(r, buf); err != nil {
186                 return nil, err
187         }
188         newCmd, ok := newAOMsg[buf[0]]
189         if !ok {
190                 return nil, fmt.Errorf("unsupported ao msg: %d", buf[0])
191         }
192         msg := newCmd()
193         return msg, deserialize(r, msg)
194 }
195
196 type IDAOMsg struct {
197         ID AOID
198         //mt:lenhdr 16
199         Msg AOMsg
200         //mt:end
201 }