+ sv_writeentitiestoclient_culled_pvs = 0;
+ sv_writeentitiestoclient_culled_trace = 0;
+ sv_writeentitiestoclient_visibleentities = 0;
+ sv_writeentitiestoclient_totalentities = 0;
+
+ Mod_CheckLoaded(sv.worldmodel);
+
+// find the client's PVS
+ // the real place being tested from
+ VectorAdd(clent->v->origin, clent->v->view_ofs, sv_writeentitiestoclient_testeye);
+ sv_writeentitiestoclient_pvsbytes = 0;
+ if (sv.worldmodel && sv.worldmodel->brush.FatPVS)
+ sv_writeentitiestoclient_pvsbytes = sv.worldmodel->brush.FatPVS(sv.worldmodel, sv_writeentitiestoclient_testeye, 8, sv_writeentitiestoclient_pvs, sizeof(sv_writeentitiestoclient_pvs));
+
+ sv_writeentitiestoclient_clentnum = EDICT_TO_PROG(clent); // LordHavoc: for comparison purposes
+
+ sententitiesmark++;
+
+ // the place being reported (to consider the fact the client still
+ // applies the view_ofs[2], so we have to only send the fractional part
+ // of view_ofs[2], undoing what the client will redo)
+ VectorCopy(sv_writeentitiestoclient_testeye, testorigin);
+ i = (int) clent->v->view_ofs[2] & 255;
+ if (i >= 128)
+ i -= 256;
+ testorigin[2] -= (float) i;
+
+ for (i = 0;i < numsendentities;i++)
+ SV_MarkWriteEntityStateToClient(sendentities + i);
+
+ d->currentcommit->numentities = 0;
+ d->currentcommit->framenum = ++d->latestframenumber;
+ MSG_WriteByte(msg, svc_entities);
+ MSG_WriteLong(msg, d->referenceframenum);
+ MSG_WriteLong(msg, d->currentcommit->framenum);
+ if (developer_networkentities.integer >= 1)
+ {
+ Con_Printf("send svc_entities num:%i ref:%i (database: ref:%i commits:", d->currentcommit->framenum, d->referenceframenum, d->referenceframenum);
+ for (i = 0;i < MAX_ENTITY_HISTORY;i++)
+ if (d->commit[i].numentities)
+ Con_Printf(" %i", d->commit[i].framenum);
+ Con_Print(")\n");
+ }
+ if (d->currententitynumber >= sv.max_edicts)
+ startnumber = 1;
+ else
+ startnumber = bound(1, d->currententitynumber, sv.max_edicts - 1);
+ MSG_WriteShort(msg, startnumber);
+ // reset currententitynumber so if the loop does not break it we will
+ // start at beginning next frame (if it does break, it will set it)
+ d->currententitynumber = 1;
+ for (i = 0, n = startnumber;n < sv.max_edicts;n++)
+ {
+ // find the old state to delta from
+ e = EntityFrame4_GetReferenceEntity(d, n);
+ // prepare the buffer
+ SZ_Clear(&buf);
+ // make the message
+ if (sententities[n] == sententitiesmark)