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

Function UnpackUserCmd

source/core/d_protocol.cpp:138–177  ·  view source on GitHub ↗

Returns the number of bytes read

Source from the content-addressed store, hash-verified

136
137// Returns the number of bytes read
138int UnpackUserCmd (InputPacket *ucmd, const InputPacket *basis, uint8_t **stream)
139{
140 uint8_t *start = *stream;
141 uint8_t flags;
142
143 if (basis != NULL)
144 {
145 if (basis != ucmd)
146 {
147 memcpy (ucmd, basis, sizeof(InputPacket));
148 }
149 }
150 else
151 {
152 memset (ucmd, 0, sizeof(InputPacket));
153 }
154
155 flags = ReadByte (stream);
156
157 if (flags)
158 {
159 // We can support up to 29 buttons, using from 0 to 4 bytes to store them.
160 if (flags & UCMDF_BUTTONS)
161 ucmd->actions = ESyncBits::FromInt(ReadLong(stream));
162 if (flags & UCMDF_PITCH)
163 ucmd->ang.Pitch = DAngle::fromDeg(ReadFloat(stream));
164 if (flags & UCMDF_YAW)
165 ucmd->ang.Yaw = DAngle::fromDeg(ReadFloat(stream));
166 if (flags & UCMDF_FORWARDMOVE)
167 ucmd->vel.X = ReadFloat(stream);
168 if (flags & UCMDF_SIDEMOVE)
169 ucmd->vel.Y = ReadFloat(stream);
170 if (flags & UCMDF_UPMOVE)
171 ucmd->vel.Z = ReadFloat(stream);
172 if (flags & UCMDF_ROLL)
173 ucmd->ang.Roll = DAngle::fromDeg(ReadFloat(stream));
174 }
175
176 return int(*stream - start);
177}
178
179// Returns the number of bytes written
180int PackUserCmd (const InputPacket *ucmd, const InputPacket *basis, uint8_t **stream)

Callers 1

ReadTicCmdFunction · 0.85

Calls 3

ReadLongFunction · 0.85
ReadFloatFunction · 0.85
ReadByteFunction · 0.70

Tested by

no test coverage detected