MCPcopy Create free account
hub / github.com/JACoders/OpenJK / SV_EmitPacketEntities

Function SV_EmitPacketEntities

code/server/sv_snapshot.cpp:58–120  ·  view source on GitHub ↗

============= SV_EmitPacketEntities Writes a delta update of an entityState_t list to the message. ============= */

Source from the content-addressed store, hash-verified

56=============
57*/
58static void SV_EmitPacketEntities( clientSnapshot_t *from, clientSnapshot_t *to, msg_t *msg ) {
59 entityState_t *oldent, *newent;
60 int oldindex, newindex;
61 int oldnum, newnum;
62 int from_num_entities;
63
64 // generate the delta update
65 if ( !from ) {
66 from_num_entities = 0;
67 } else {
68 from_num_entities = from->num_entities;
69 }
70
71 newent = NULL;
72 oldent = NULL;
73 newindex = 0;
74 oldindex = 0;
75 const int num2Send = to->num_entities >= svs.numSnapshotEntities ? svs.numSnapshotEntities : to->num_entities;
76
77 while ( newindex < num2Send || oldindex < from_num_entities ) {
78 if ( newindex >= num2Send ) {
79 newnum = 9999;
80 } else {
81 newent = &svs.snapshotEntities[(to->first_entity+newindex) % svs.numSnapshotEntities];
82 newnum = newent->number;
83 }
84
85 if ( oldindex >= from_num_entities ) {
86 oldnum = 9999;
87 } else {
88 oldent = &svs.snapshotEntities[(from->first_entity+oldindex) % svs.numSnapshotEntities];
89 oldnum = oldent->number;
90 }
91
92 if ( newnum == oldnum ) {
93 // delta update from old position
94 // because the force parm is qfalse, this will not result
95 // in any bytes being emited if the entity has not changed at all
96 MSG_WriteEntity(msg, newent, 0);
97 oldindex++;
98 newindex++;
99 continue;
100 }
101
102 if ( newnum < oldnum ) {
103 // this is a new entity, send it from the baseline
104 MSG_WriteEntity (msg, newent, 0);
105 newindex++;
106 continue;
107 }
108
109 if ( newnum > oldnum ) {
110 // the old entity isn't present in the new message
111 if(oldent) {
112 MSG_WriteEntity (msg, NULL, oldent->number);
113 }
114 oldindex++;
115 continue;

Callers 1

SV_WriteSnapshotToClientFunction · 0.70

Calls 2

MSG_WriteEntityFunction · 0.85
MSG_WriteBitsFunction · 0.50

Tested by

no test coverage detected