================== SV_WriteSnapshotToClient ================== */
| 127 | ================== |
| 128 | */ |
| 129 | static void SV_WriteSnapshotToClient( client_t *client, msg_t *msg ) { |
| 130 | clientSnapshot_t *frame, *oldframe; |
| 131 | int lastframe; |
| 132 | int snapFlags; |
| 133 | |
| 134 | // this is the snapshot we are creating |
| 135 | frame = &client->frames[ client->netchan.outgoingSequence & PACKET_MASK ]; |
| 136 | |
| 137 | // try to use a previous frame as the source for delta compressing the snapshot |
| 138 | if ( client->deltaMessage <= 0 || client->state != CS_ACTIVE ) { |
| 139 | // client is asking for a retransmit |
| 140 | oldframe = NULL; |
| 141 | lastframe = 0; |
| 142 | } else if ( client->netchan.outgoingSequence - client->deltaMessage |
| 143 | >= (PACKET_BACKUP - 3) ) { |
| 144 | // client hasn't gotten a good message through in a long time |
| 145 | Com_DPrintf ("%s: Delta request from out of date packet.\n", client->name); |
| 146 | oldframe = NULL; |
| 147 | lastframe = 0; |
| 148 | } else { |
| 149 | // we have a valid snapshot to delta from |
| 150 | oldframe = &client->frames[ client->deltaMessage & PACKET_MASK ]; |
| 151 | lastframe = client->netchan.outgoingSequence - client->deltaMessage; |
| 152 | |
| 153 | // the snapshot's entities may still have rolled off the buffer, though |
| 154 | if ( oldframe->first_entity <= svs.nextSnapshotEntities - svs.numSnapshotEntities ) { |
| 155 | Com_DPrintf ("%s: Delta request from out of date entities.\n", client->name); |
| 156 | oldframe = NULL; |
| 157 | lastframe = 0; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | MSG_WriteByte (msg, svc_snapshot); |
| 162 | |
| 163 | // let the client know which reliable clientCommands we have received |
| 164 | MSG_WriteLong( msg, client->lastClientCommand ); |
| 165 | |
| 166 | // send over the current server time so the client can drift |
| 167 | // its view of time to try to match |
| 168 | MSG_WriteLong (msg, sv.time); |
| 169 | |
| 170 | // we must write a message number, because recorded demos won't have |
| 171 | // the same network message sequences |
| 172 | MSG_WriteLong (msg, client->netchan.outgoingSequence ); |
| 173 | MSG_WriteByte (msg, lastframe); // what we are delta'ing from |
| 174 | MSG_WriteLong (msg, client->cmdNum); // we have executed up to here |
| 175 | |
| 176 | snapFlags = client->droppedCommands << 1; |
| 177 | client->droppedCommands = qfalse; |
| 178 | |
| 179 | MSG_WriteByte (msg, snapFlags); |
| 180 | |
| 181 | // send over the areabits |
| 182 | MSG_WriteByte (msg, frame->areabytes); |
| 183 | MSG_WriteData (msg, frame->areabits, frame->areabytes); |
| 184 | |
| 185 | // delta encode the playerstate |
| 186 | if ( oldframe ) { |
no test coverage detected