| 67 | |
| 68 | |
| 69 | void* PlayerState::pack(void* buf, uint16_t& code, bool increment) { |
| 70 | if (increment) { |
| 71 | order++; |
| 72 | } |
| 73 | |
| 74 | buf = nboPackInt32(buf, int32_t(order)); |
| 75 | buf = nboPackInt16(buf, int16_t(status)); |
| 76 | |
| 77 | static BZDB_bool noSmallPackets(BZDBNAMES.NOSMALLPACKETS); |
| 78 | if (noSmallPackets || |
| 79 | (fabsf(pos.x) >= smallMaxDist) || |
| 80 | (fabsf(pos.y) >= smallMaxDist) || |
| 81 | (fabsf(pos.z) >= smallMaxDist) || |
| 82 | (fabsf(velocity.x) >= smallMaxVel) || |
| 83 | (fabsf(velocity.y) >= smallMaxVel) || |
| 84 | (fabsf(velocity.z) >= smallMaxVel) || |
| 85 | (fabsf(angVel) >= smallMaxAngVel)) { |
| 86 | |
| 87 | code = MsgPlayerUpdate; |
| 88 | |
| 89 | buf = nboPackFVec3(buf, pos); |
| 90 | buf = nboPackFVec3(buf, velocity); |
| 91 | buf = nboPackFloat(buf, azimuth); |
| 92 | buf = nboPackFloat(buf, angVel); |
| 93 | } |
| 94 | else { |
| 95 | |
| 96 | code = MsgPlayerUpdateSmall; |
| 97 | |
| 98 | int16_t posShort[3], velShort[3], aziShort, angVelShort; |
| 99 | |
| 100 | for (int i = 0; i < 3; i++) { |
| 101 | posShort[i] = (int16_t)((pos[i] * smallScale) / smallMaxDist); |
| 102 | velShort[i] = (int16_t)((velocity[i] * smallScale) / smallMaxVel); |
| 103 | } |
| 104 | |
| 105 | // put the angle between -M_PI and +M_PI |
| 106 | float angle = fmodf(azimuth, (float)M_PI * 2.0f); |
| 107 | if (angle > M_PI) { |
| 108 | angle -= (float)(M_PI * 2.0); |
| 109 | } |
| 110 | else if (angle < -M_PI) { |
| 111 | angle += (float)(M_PI * 2.0); |
| 112 | } |
| 113 | aziShort = (int16_t)((angle * smallScale) / M_PI); |
| 114 | angVelShort = (int16_t)((angVel * smallScale) / smallMaxAngVel); |
| 115 | |
| 116 | buf = nboPackInt16(buf, posShort[0]); |
| 117 | buf = nboPackInt16(buf, posShort[1]); |
| 118 | buf = nboPackInt16(buf, posShort[2]); |
| 119 | buf = nboPackInt16(buf, velShort[0]); |
| 120 | buf = nboPackInt16(buf, velShort[1]); |
| 121 | buf = nboPackInt16(buf, velShort[2]); |
| 122 | buf = nboPackInt16(buf, aziShort); |
| 123 | buf = nboPackInt16(buf, angVelShort); |
| 124 | } |
| 125 | |
| 126 | if ((status & JumpJets) != 0) { |
nothing calls this directly
no test coverage detected