Skip to content

Instantly share code, notes, and snippets.

@entdark
Created July 13, 2015 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save entdark/e069057377d58b7a2b0f to your computer and use it in GitHub Desktop.
Save entdark/e069057377d58b7a2b0f to your computer and use it in GitHub Desktop.
void demoCutParsePacketEntities(msg_t *msg, clSnapshot_t *oldSnap, clSnapshot_t *newSnap, clientActive_t *clCut) {
/* The beast that is entity parsing */
int newnum;
entityState_t *oldstate, *newstate;
int oldindex = 0;
int oldnum;
newSnap->parseEntitiesNum = clCut->parseEntitiesNum;
newSnap->numEntities = 0;
newnum = MSG_ReadBits(msg, GENTITYNUM_BITS);
while (1) {
// read the entity index number
if (oldSnap && oldindex < oldSnap->numEntities) {
oldstate = &clCut->parseEntities[(oldSnap->parseEntitiesNum + oldindex) & (MAX_PARSE_ENTITIES-1)];
oldnum = oldstate->number;
} else {
oldstate = 0;
oldnum = 99999;
}
newstate = &clCut->parseEntities[clCut->parseEntitiesNum];
if (!oldstate && (newnum == (MAX_GENTITIES-1))) {
break;
} else if (oldnum < newnum) {
*newstate = *oldstate;
oldindex++;
} else if (oldnum == newnum) {
oldindex++;
MSG_ReadDeltaEntity(msg, oldstate, newstate, newnum);
newnum = MSG_ReadBits(msg, GENTITYNUM_BITS);
} else if (oldnum > newnum) {
MSG_ReadDeltaEntity(msg, &clCut->entityBaselines[newnum], newstate, newnum);
newnum = MSG_ReadBits(msg, GENTITYNUM_BITS);
}
if (newstate->number == MAX_GENTITIES-1)
continue;
clCut->parseEntitiesNum++;
clCut->parseEntitiesNum &= (MAX_PARSE_ENTITIES-1);
newSnap->numEntities++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment