Returns the number of bytes read
| 136 | |
| 137 | // Returns the number of bytes read |
| 138 | int 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 |
| 180 | int PackUserCmd (const InputPacket *ucmd, const InputPacket *basis, uint8_t **stream) |
no test coverage detected