+ Con_Printf("client \"%s\" entities: %d total, %d visible, %d culled by: %d pvs %d trace\n", client->name, sv_writeentitiestoclient_totalentities, sv_writeentitiestoclient_visibleentities, sv_writeentitiestoclient_culled_pvs + sv_writeentitiestoclient_culled_trace, sv_writeentitiestoclient_culled_pvs, sv_writeentitiestoclient_culled_trace);
+}
+*/
+
+void SV_WriteEntitiesToClient(client_t *client, edict_t *clent, sizebuf_t *msg)
+{
+ int i, numsendstates;
+ entity_state_t *s;
+
+ // if there isn't enough space to accomplish anything, skip it
+ if (msg->cursize + 25 > msg->maxsize)
+ return;
+
+ sv_writeentitiestoclient_client = client;
+
+ 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++;
+
+ for (i = 0;i < numsendentities;i++)
+ SV_MarkWriteEntityStateToClient(sendentities + i);
+
+ numsendstates = 0;
+ for (i = 0;i < numsendentities;i++)
+ {
+ if (sententities[sendentities[i].number] == sententitiesmark)
+ {
+ s = &sendstates[numsendstates++];
+ *s = sendentities[i];
+ if (s->exteriormodelforclient && s->exteriormodelforclient == sv_writeentitiestoclient_clentnum)
+ s->flags |= RENDER_EXTERIORMODEL;
+ }
+ }
+
+ if (sv_cullentities_stats.integer)
+ Con_Printf("client \"%s\" entities: %d total, %d visible, %d culled by: %d pvs %d trace\n", client->name, sv_writeentitiestoclient_totalentities, sv_writeentitiestoclient_visibleentities, sv_writeentitiestoclient_culled_pvs + sv_writeentitiestoclient_culled_trace, sv_writeentitiestoclient_culled_pvs, sv_writeentitiestoclient_culled_trace);
+
+ if (client->entitydatabase5)
+ EntityFrame5_WriteFrame(msg, client->entitydatabase5, numsendstates, sendstates, client - svs.clients + 1);
+ else if (client->entitydatabase4)
+ EntityFrame4_WriteFrame(msg, client->entitydatabase4, numsendstates, sendstates);
+ else if (client->entitydatabase)
+ EntityFrame_WriteFrame(msg, client->entitydatabase, numsendstates, sendstates, client - svs.clients + 1);
+ else
+ EntityFrameQuake_WriteFrame(msg, numsendstates, sendstates);