MCPcopy Create free account
hub / github.com/ZDoom/Raze / PackUserCmd

Function PackUserCmd

source/core/d_protocol.cpp:180–235  ·  view source on GitHub ↗

Returns the number of bytes written

Source from the content-addressed store, hash-verified

178
179// Returns the number of bytes written
180int PackUserCmd (const InputPacket *ucmd, const InputPacket *basis, uint8_t **stream)
181{
182 uint8_t flags = 0;
183 uint8_t *temp = *stream;
184 uint8_t *start = *stream;
185 InputPacket blank;
186
187 if (basis == NULL)
188 {
189 memset (&blank, 0, sizeof(blank));
190 basis = ␣
191 }
192
193 WriteByte (0, stream); // Make room for the packing bits
194
195 if (ucmd->actions != basis->actions)
196 {
197 flags |= UCMDF_BUTTONS;
198 WriteLong(ucmd->actions, stream);
199 }
200 if (ucmd->ang.Pitch != basis->ang.Pitch)
201 {
202 flags |= UCMDF_PITCH;
203 WriteFloat ((float)ucmd->ang.Pitch.Degrees(), stream);
204 }
205 if (ucmd->ang.Yaw != basis->ang.Yaw)
206 {
207 flags |= UCMDF_YAW;
208 WriteFloat ((float)ucmd->ang.Yaw.Degrees(), stream);
209 }
210 if (ucmd->vel.X != basis->vel.X)
211 {
212 flags |= UCMDF_FORWARDMOVE;
213 WriteFloat ((float)ucmd->vel.X, stream);
214 }
215 if (ucmd->vel.Y != basis->vel.Y)
216 {
217 flags |= UCMDF_SIDEMOVE;
218 WriteFloat ((float)ucmd->vel.Y, stream);
219 }
220 if (ucmd->vel.Z != basis->vel.Z)
221 {
222 flags |= UCMDF_UPMOVE;
223 WriteFloat ((float)ucmd->vel.Z, stream);
224 }
225 if (ucmd->ang.Roll != basis->ang.Roll)
226 {
227 flags |= UCMDF_ROLL;
228 WriteFloat ((float)ucmd->ang.Roll.Degrees(), stream);
229 }
230
231 // Write the packing bits
232 WriteByte (flags, &temp);
233
234 return int(*stream - start);
235}
236
237FSerializer &Serialize(FSerializer &arc, const char *key, ticcmd_t &cmd, ticcmd_t *def)

Callers 1

WriteUserCmdMessageFunction · 0.85

Calls 4

WriteByteFunction · 0.85
WriteLongFunction · 0.85
WriteFloatFunction · 0.85
DegreesMethod · 0.80

Tested by

no test coverage detected