+void EntityFrameCSQC_LostFrame(client_t *client, int framenum)
+{
+ // marks a frame as lost
+ int i, j, n;
+ qboolean valid;
+ int ringfirst, ringlast;
+ static int recoversendflags[MAX_EDICTS];
+ csqcentityframedb_t *d;
+
+ n = client->csqcnumedicts;
+
+ // is our frame out of history?
+ ringfirst = client->csqcentityframehistory_next; // oldest entry
+ ringlast = (ringfirst + NUM_CSQCENTITYDB_FRAMES - 1) % NUM_CSQCENTITYDB_FRAMES; // most recently added entry
+
+ valid = false;
+
+ for(j = 0; j < NUM_CSQCENTITYDB_FRAMES; ++j)
+ {
+ d = &client->csqcentityframehistory[(ringfirst + j) % NUM_CSQCENTITYDB_FRAMES];
+ if(d->framenum < 0)
+ continue;
+ if(d->framenum == framenum)
+ break;
+ else if(d->framenum < framenum)
+ valid = true;
+ }
+ if(j == NUM_CSQCENTITYDB_FRAMES)
+ {
+ if(valid) // got beaten, i.e. there is a frame < framenum
+ {
+ // a non-csqc frame got lost... great
+ return;
+ }
+ else
+ {
+ // a too old frame got lost... sorry, cannot handle this
+ Con_DPrintf("CSQC entity DB: lost a frame too early to do any handling (resending ALL)...\n");
+ Con_DPrintf("Lost frame = %d\n", framenum);
+ Con_DPrintf("Entity DB = %d to %d\n", client->csqcentityframehistory[ringfirst].framenum, client->csqcentityframehistory[ringlast].framenum);
+ EntityFrameCSQC_LostAllFrames(client);
+ }
+ return;
+ }
+
+ // so j is the frame that got lost
+ // ringlast is the frame that we have to go to
+ ringfirst = (ringfirst + j) % NUM_CSQCENTITYDB_FRAMES;
+ if(ringlast < ringfirst)
+ ringlast += NUM_CSQCENTITYDB_FRAMES;
+
+ memset(recoversendflags, 0, sizeof(recoversendflags));
+
+ for(j = ringfirst; j <= ringlast; ++j)
+ {
+ d = &client->csqcentityframehistory[j % NUM_CSQCENTITYDB_FRAMES];
+ if(d->framenum < 0)
+ {
+ // deleted frame
+ }
+ else if(d->framenum < framenum)
+ {
+ // a frame in the past... should never happen
+ Con_Printf("CSQC entity DB encountered a frame from the past when recovering from PL...?\n");
+ }
+ else if(d->framenum == framenum)
+ {
+ // handling the actually lost frame now
+ for(i = 0; i < d->num; ++i)
+ {
+ int sf = d->sendflags[i];
+ int ent = d->entno[i];
+ if(sf < 0) // remove
+ recoversendflags[ent] |= -1; // all bits, including sign
+ else if(sf > 0)
+ recoversendflags[ent] |= sf;
+ }
+ }
+ else
+ {
+ // handling the frames that followed it now
+ for(i = 0; i < d->num; ++i)
+ {
+ int sf = d->sendflags[i];
+ int ent = d->entno[i];
+ if(sf < 0) // remove
+ {
+ recoversendflags[ent] = 0; // no need to update, we got a more recent remove (and will fix it THEN)
+ break; // no flags left to remove...
+ }
+ else if(sf > 0)
+ recoversendflags[ent] &= ~sf; // no need to update these bits, we already got them later
+ }
+ }
+ }