// An hwsvc_packetentities has just been parsed, deal with the // rest of the data stream. static void CLHW_ParsePacketEntities( QMsg& message, bool delta ) { int oldpacket, newpacket; hwpacket_entities_t* oldp, * newp, dummy; int oldindex, newindex; int word, newnum, oldnum; qboolean full; byte from; newpacket = clc.netchan.incomingSequence & UPDATE_MASK_HW; newp = &cl.hw_frames[ newpacket ].packet_entities; cl.hw_frames[ newpacket ].invalid = false; if ( delta ) { from = message.ReadByte(); oldpacket = cl.hw_frames[ newpacket ].delta_sequence; if ( ( from & UPDATE_MASK_HW ) != ( oldpacket & UPDATE_MASK_HW ) ) { common->DPrintf( "WARNING: from mismatch\n" ); } } else { oldpacket = -1; } full = false; if ( oldpacket != -1 ) { if ( clc.netchan.outgoingSequence - oldpacket >= UPDATE_BACKUP_HW - 1 ) { // we can't use this, it is too old FlushEntityPacket( message ); return; } cl.qh_validsequence = clc.netchan.incomingSequence; oldp = &cl.hw_frames[ oldpacket & UPDATE_MASK_HW ].packet_entities; } else { // this is a full update that we can start delta compressing from now oldp = &dummy; dummy.num_entities = 0; cl.qh_validsequence = clc.netchan.incomingSequence; full = true; } oldindex = 0; newindex = 0; newp->num_entities = 0; while ( 1 ) { word = ( unsigned short )message.ReadShort(); if ( message.badread ) {// something didn't parse right... common->Error( "msg_badread in packetentities\n" ); return; } if ( !word ) { while ( oldindex < oldp->num_entities ) { // copy all the rest of the entities from the old packet if ( newindex >= HWMAX_PACKET_ENTITIES ) { common->Error( "CLHW_ParsePacketEntities: newindex == HWMAX_PACKET_ENTITIES" ); } newp->entities[ newindex ] = oldp->entities[ oldindex ]; newindex++; oldindex++; } break; } newnum = word & 511; oldnum = oldindex >= oldp->num_entities ? 9999 : oldp->entities[ oldindex ].number; while ( newnum > oldnum ) { if ( full ) { common->Printf( "WARNING: oldcopy on full update" ); FlushEntityPacket( message ); return; } // copy one of the old entities over to the new packet unchanged if ( newindex >= HWMAX_PACKET_ENTITIES ) { common->Error( "CLHW_ParsePacketEntities: newindex == HWMAX_PACKET_ENTITIES" ); } newp->entities[ newindex ] = oldp->entities[ oldindex ]; newindex++; oldindex++; oldnum = oldindex >= oldp->num_entities ? 9999 : oldp->entities[ oldindex ].number; } if ( newnum < oldnum ) { // new from baseline if ( word & HWU_REMOVE ) { if ( full ) { cl.qh_validsequence = 0; common->Printf( "WARNING: HWU_REMOVE on full update\n" ); FlushEntityPacket( message ); return; } continue; } if ( newindex >= HWMAX_PACKET_ENTITIES ) { common->Error( "CLHW_ParsePacketEntities: newindex == HWMAX_PACKET_ENTITIES" ); } CLHW_ParseDelta( message, &clh2_baselines[ newnum ], &newp->entities[ newindex ], word ); newindex++; continue; } if ( newnum == oldnum ) { // delta from previous if ( full ) { cl.qh_validsequence = 0; common->Printf( "WARNING: delta on full update" ); } if ( word & HWU_REMOVE ) { oldindex++; continue; } CLHW_ParseDelta( message, &oldp->entities[ oldindex ], &newp->entities[ newindex ], word ); newindex++; oldindex++; } } newp->num_entities = newindex; }
/* ================== CL_ParsePacketEntities An svc_packetentities has just been parsed, deal with the rest of the data stream. ================== */ void CL_ParsePacketEntities (qboolean delta) { int oldpacket, newpacket; packet_entities_t *oldp, *newp, dummy; int oldindex, newindex; int word, newnum, oldnum; qboolean full; byte from; newpacket = cls.netchan.incoming_sequence&UPDATE_MASK; newp = &cl.frames[newpacket].packet_entities; cl.frames[newpacket].invalid = false; if (delta) { from = MSG_ReadByte (); oldpacket = cl.frames[newpacket].delta_sequence; if ( (from&UPDATE_MASK) != (oldpacket&UPDATE_MASK) ) Con_DPrintf ("WARNING: from mismatch\n"); } else oldpacket = -1; full = false; if (oldpacket != -1) { if (cls.netchan.outgoing_sequence - oldpacket >= UPDATE_BACKUP-1) { // we can't use this, it is too old FlushEntityPacket (); return; } cl.validsequence = cls.netchan.incoming_sequence; oldp = &cl.frames[oldpacket&UPDATE_MASK].packet_entities; } else { // this is a full update that we can start delta compressing from now oldp = &dummy; dummy.num_entities = 0; cl.validsequence = cls.netchan.incoming_sequence; full = true; } oldindex = 0; newindex = 0; newp->num_entities = 0; while (1) { word = (unsigned short)MSG_ReadShort (); if (msg_badread) { // something didn't parse right... Host_EndGame ("msg_badread in packetentities"); return; } if (!word) { while (oldindex < oldp->num_entities) { // copy all the rest of the entities from the old packet //Con_Printf ("copy %i\n", oldp->entities[oldindex].number); if (newindex >= MAX_PACKET_ENTITIES) Host_EndGame ("CL_ParsePacketEntities: newindex == MAX_PACKET_ENTITIES ... 1"); newp->entities[newindex] = oldp->entities[oldindex]; newindex++; oldindex++; } break; } newnum = word&511; oldnum = oldindex >= oldp->num_entities ? 9999 : oldp->entities[oldindex].number; while (newnum > oldnum) { if (full) { Con_Printf ("WARNING: oldcopy on full update"); FlushEntityPacket (); return; } //Con_Printf ("copy %i\n", oldnum); // copy one of the old entities over to the new packet unchanged if (newindex >= MAX_PACKET_ENTITIES) Host_EndGame ("CL_ParsePacketEntities: newindex == MAX_PACKET_ENTITIES ... 2"); newp->entities[newindex] = oldp->entities[oldindex]; newindex++; oldindex++; oldnum = oldindex >= oldp->num_entities ? 9999 : oldp->entities[oldindex].number; } if (newnum < oldnum) { // new from baseline //Con_Printf ("baseline %i\n", newnum); if (word & U_REMOVE) { if (full) { cl.validsequence = 0; Con_Printf ("WARNING: U_REMOVE on full update\n"); FlushEntityPacket (); return; } continue; } if (newindex >= MAX_PACKET_ENTITIES) Host_EndGame ("CL_ParsePacketEntities: newindex == MAX_PACKET_ENTITIES ... 3"); CL_ParseDelta (&cl_baselines[newnum], &newp->entities[newindex], word); newindex++; continue; } if (newnum == oldnum) { // delta from previous if (full) { cl.validsequence = 0; Con_Printf ("WARNING: delta on full update"); } if (word & U_REMOVE) { oldindex++; continue; } //Con_Printf ("delta %i\n",newnum); CL_ParseDelta (&oldp->entities[oldindex], &newp->entities[newindex], word); newindex++; oldindex++; } } newp->num_entities = newindex; }