4 entity_state_t defaultstate =
6 0,//double time; // time this state was built
7 {0,0,0},//vec3_t origin;
8 {0,0,0},//vec3_t angles;
9 0,//int number; // entity number this state is for
10 0,//unsigned short active; // true if a valid state
11 0,//unsigned short modelindex;
12 0,//unsigned short frame;
13 0,//unsigned short effects;
14 0,//unsigned short tagentity;
15 0,//unsigned short specialvisibilityradius;
16 0,//unsigned short viewmodelforclient;
17 0,//unsigned short exteriormodelforclient;
18 0,//unsigned short nodrawtoclient;
19 0,//unsigned short drawonlytoclient;
25 254,//qbyte glowcolor;
30 void ClearStateToDefault(entity_state_t *s)
34 memset(s, 0, sizeof(*s));
41 void EntityState_Write(entity_state_t *ent, sizebuf_t *msg, entity_state_t *delta)
47 // if not active last frame, delta from defaults
49 delta = &defaultstate;
51 VectorCopy(ent->origin, org);
52 VectorCopy(delta->origin, deltaorg);
53 if (ent->flags & RENDER_LOWPRECISION)
56 org[0] = (int) (org[0] + 0.5f);
58 org[0] = (int) (org[0] - 0.5f);
60 org[1] = (int) (org[1] + 0.5f);
62 org[1] = (int) (org[1] - 0.5f);
64 org[2] = (int) (org[2] + 0.5f);
66 org[2] = (int) (org[2] - 0.5f);
68 if (delta->flags & RENDER_LOWPRECISION)
71 deltaorg[0] = (int) (deltaorg[0] + 0.5f);
73 deltaorg[0] = (int) (deltaorg[0] - 0.5f);
75 deltaorg[1] = (int) (deltaorg[1] + 0.5f);
77 deltaorg[1] = (int) (deltaorg[1] - 0.5f);
79 deltaorg[2] = (int) (deltaorg[2] + 0.5f);
81 deltaorg[2] = (int) (deltaorg[2] - 0.5f);
83 if (fabs(org[0] - deltaorg[0]) > 0.01f)
85 if (fabs(org[1] - deltaorg[1]) > 0.01f)
87 if (fabs(org[2] - deltaorg[2]) > 0.01f)
89 if ((qbyte) (ent->angles[0] * (256.0f / 360.0f)) != (qbyte) (delta->angles[0] * (256.0f / 360.0f)))
91 if ((qbyte) (ent->angles[1] * (256.0f / 360.0f)) != (qbyte) (delta->angles[1] * (256.0f / 360.0f)))
93 if ((qbyte) (ent->angles[2] * (256.0f / 360.0f)) != (qbyte) (delta->angles[2] * (256.0f / 360.0f)))
95 if ((ent->modelindex ^ delta->modelindex) & 0x00FF)
97 if ((ent->modelindex ^ delta->modelindex) & 0xFF00)
99 if ((ent->frame ^ delta->frame) & 0x00FF)
101 if ((ent->frame ^ delta->frame) & 0xFF00)
103 if ((ent->effects ^ delta->effects) & 0x00FF)
105 if ((ent->effects ^ delta->effects) & 0xFF00)
107 if (ent->colormap != delta->colormap)
109 if (ent->skin != delta->skin)
111 if (ent->alpha != delta->alpha)
113 if (ent->scale != delta->scale)
115 if (ent->glowsize != delta->glowsize)
117 if (ent->glowcolor != delta->glowcolor)
119 if (ent->flags != delta->flags)
121 if (ent->tagindex != delta->tagindex || ent->tagentity != delta->tagentity)
122 bits |= E_TAGATTACHMENT;
124 if (bits) // don't send anything if it hasn't changed
126 if (bits & 0xFF000000)
128 if (bits & 0x00FF0000)
130 if (bits & 0x0000FF00)
133 MSG_WriteShort(msg, ent->number);
134 MSG_WriteByte(msg, bits & 0xFF);
135 if (bits & E_EXTEND1)
137 MSG_WriteByte(msg, (bits >> 8) & 0xFF);
138 if (bits & E_EXTEND2)
140 MSG_WriteByte(msg, (bits >> 16) & 0xFF);
141 if (bits & E_EXTEND3)
142 MSG_WriteByte(msg, (bits >> 24) & 0xFF);
145 // LordHavoc: have to write flags first, as they can modify protocol
147 MSG_WriteByte(msg, ent->flags);
148 if (ent->flags & RENDER_LOWPRECISION)
150 if (bits & E_ORIGIN1)
151 MSG_WriteShort(msg, org[0]);
152 if (bits & E_ORIGIN2)
153 MSG_WriteShort(msg, org[1]);
154 if (bits & E_ORIGIN3)
155 MSG_WriteShort(msg, org[2]);
159 if (bits & E_ORIGIN1)
160 MSG_WriteFloat(msg, org[0]);
161 if (bits & E_ORIGIN2)
162 MSG_WriteFloat(msg, org[1]);
163 if (bits & E_ORIGIN3)
164 MSG_WriteFloat(msg, org[2]);
167 MSG_WriteAngle(msg, ent->angles[0]);
169 MSG_WriteAngle(msg, ent->angles[1]);
171 MSG_WriteAngle(msg, ent->angles[2]);
173 MSG_WriteByte(msg, ent->modelindex & 0xFF);
175 MSG_WriteByte(msg, (ent->modelindex >> 8) & 0xFF);
177 MSG_WriteByte(msg, ent->frame & 0xFF);
179 MSG_WriteByte(msg, (ent->frame >> 8) & 0xFF);
180 if (bits & E_EFFECTS1)
181 MSG_WriteByte(msg, ent->effects & 0xFF);
182 if (bits & E_EFFECTS2)
183 MSG_WriteByte(msg, (ent->effects >> 8) & 0xFF);
184 if (bits & E_COLORMAP)
185 MSG_WriteByte(msg, ent->colormap);
187 MSG_WriteByte(msg, ent->skin);
189 MSG_WriteByte(msg, ent->alpha);
191 MSG_WriteByte(msg, ent->scale);
192 if (bits & E_GLOWSIZE)
193 MSG_WriteByte(msg, ent->glowsize);
194 if (bits & E_GLOWCOLOR)
195 MSG_WriteByte(msg, ent->glowcolor);
196 if (bits & E_TAGATTACHMENT)
198 MSG_WriteShort(msg, ent->tagentity);
199 MSG_WriteByte(msg, ent->tagindex);
203 else if (delta->active)
204 MSG_WriteShort(msg, ent->number | 0x8000);
207 void EntityState_ReadUpdate(entity_state_t *e, int number)
210 cl_entities_active[number] = true;
212 e->time = cl.mtime[0];
215 bits = MSG_ReadByte();
216 if (bits & E_EXTEND1)
218 bits |= MSG_ReadByte() << 8;
219 if (bits & E_EXTEND2)
221 bits |= MSG_ReadByte() << 16;
222 if (bits & E_EXTEND3)
223 bits |= MSG_ReadByte() << 24;
227 if (cl.protocol == PROTOCOL_DARKPLACES2)
229 if (bits & E_ORIGIN1)
230 e->origin[0] = (signed short) MSG_ReadShort();
231 if (bits & E_ORIGIN2)
232 e->origin[1] = (signed short) MSG_ReadShort();
233 if (bits & E_ORIGIN3)
234 e->origin[2] = (signed short) MSG_ReadShort();
239 e->flags = MSG_ReadByte();
240 if (e->flags & RENDER_LOWPRECISION || cl.protocol == PROTOCOL_DARKPLACES2)
242 if (bits & E_ORIGIN1)
243 e->origin[0] = (signed short) MSG_ReadShort();
244 if (bits & E_ORIGIN2)
245 e->origin[1] = (signed short) MSG_ReadShort();
246 if (bits & E_ORIGIN3)
247 e->origin[2] = (signed short) MSG_ReadShort();
251 if (bits & E_ORIGIN1)
252 e->origin[0] = MSG_ReadFloat();
253 if (bits & E_ORIGIN2)
254 e->origin[1] = MSG_ReadFloat();
255 if (bits & E_ORIGIN3)
256 e->origin[2] = MSG_ReadFloat();
260 e->angles[0] = MSG_ReadAngle();
262 e->angles[1] = MSG_ReadAngle();
264 e->angles[2] = MSG_ReadAngle();
266 e->modelindex = (e->modelindex & 0xFF00) | (unsigned int) MSG_ReadByte();
268 e->modelindex = (e->modelindex & 0x00FF) | ((unsigned int) MSG_ReadByte() << 8);
270 e->frame = (e->frame & 0xFF00) | (unsigned int) MSG_ReadByte();
272 e->frame = (e->frame & 0x00FF) | ((unsigned int) MSG_ReadByte() << 8);
273 if (bits & E_EFFECTS1)
274 e->effects = (e->effects & 0xFF00) | (unsigned int) MSG_ReadByte();
275 if (bits & E_EFFECTS2)
276 e->effects = (e->effects & 0x00FF) | ((unsigned int) MSG_ReadByte() << 8);
277 if (bits & E_COLORMAP)
278 e->colormap = MSG_ReadByte();
280 e->skin = MSG_ReadByte();
282 e->alpha = MSG_ReadByte();
284 e->scale = MSG_ReadByte();
285 if (bits & E_GLOWSIZE)
286 e->glowsize = MSG_ReadByte();
287 if (bits & E_GLOWCOLOR)
288 e->glowcolor = MSG_ReadByte();
289 if (cl.protocol == PROTOCOL_DARKPLACES2)
291 e->flags = MSG_ReadByte();
292 if (bits & E_TAGATTACHMENT)
294 e->tagentity = MSG_ReadShort();
295 e->tagindex = MSG_ReadByte();
298 if (developer_networkentities.integer >= 2)
300 Con_Printf("ReadUpdate e%i", number);
302 if (bits & E_ORIGIN1)
303 Con_Printf(" E_ORIGIN1 %f", e->origin[0]);
304 if (bits & E_ORIGIN2)
305 Con_Printf(" E_ORIGIN2 %f", e->origin[1]);
306 if (bits & E_ORIGIN3)
307 Con_Printf(" E_ORIGIN3 %f", e->origin[2]);
309 Con_Printf(" E_ANGLE1 %f", e->angles[0]);
311 Con_Printf(" E_ANGLE2 %f", e->angles[1]);
313 Con_Printf(" E_ANGLE3 %f", e->angles[2]);
314 if (bits & (E_MODEL1 | E_MODEL2))
315 Con_Printf(" E_MODEL %i", e->modelindex);
317 if (bits & (E_FRAME1 | E_FRAME2))
318 Con_Printf(" E_FRAME %i", e->frame);
319 if (bits & (E_EFFECTS1 | E_EFFECTS2))
320 Con_Printf(" E_EFFECTS %i", e->effects);
322 Con_Printf(" E_ALPHA %f", e->alpha / 255.0f);
324 Con_Printf(" E_SCALE %f", e->scale / 16.0f);
325 if (bits & E_COLORMAP)
326 Con_Printf(" E_COLORMAP %i", e->colormap);
328 Con_Printf(" E_SKIN %i", e->skin);
330 if (bits & E_GLOWSIZE)
331 Con_Printf(" E_GLOWSIZE %i", e->glowsize * 8);
332 if (bits & E_GLOWCOLOR)
333 Con_Printf(" E_GLOWCOLOR %i", e->glowcolor);
335 if (bits & E_TAGATTACHMENT)
336 Con_Printf(" E_TAGATTACHMENT e%i:%i", e->tagentity, e->tagindex);
341 // (server) clears the database to contain no frames (thus delta compression compresses against nothing)
342 void EntityFrame_ClearDatabase(entity_database_t *d)
344 memset(d, 0, sizeof(*d));
347 // (server and client) removes frames older than 'frame' from database
348 void EntityFrame_AckFrame(entity_database_t *d, int frame)
351 if (d->ackframe < frame)
353 for (i = 0;i < d->numframes && d->frames[i].framenum < frame;i++);
354 // ignore outdated frame acks (out of order packets)
358 // if some queue is left, slide it down to beginning of array
360 memmove(&d->frames[0], &d->frames[i], sizeof(d->frames[0]) * d->numframes);
363 // (server) clears frame, to prepare for adding entities
364 void EntityFrame_Clear(entity_frame_t *f, vec3_t eye, int framenum)
367 f->framenum = framenum;
375 VectorCopy(eye, f->eye);
379 // (server) adds an entity to frame
380 void EntityFrame_AddEntity(entity_frame_t *f, entity_state_t *s)
382 if (f->numentities < MAX_ENTITY_DATABASE)
384 f->entitydata[f->numentities] = *s;
385 f->entitydata[f->numentities++].active = true;
389 // (server and client) reads a frame from the database
390 void EntityFrame_FetchFrame(entity_database_t *d, int framenum, entity_frame_t *f)
393 EntityFrame_Clear(f, NULL, -1);
394 for (i = 0;i < d->numframes && d->frames[i].framenum < framenum;i++);
395 if (i < d->numframes && framenum == d->frames[i].framenum)
397 f->framenum = framenum;
398 f->numentities = d->frames[i].endentity - d->frames[i].firstentity;
399 n = MAX_ENTITY_DATABASE - (d->frames[i].firstentity % MAX_ENTITY_DATABASE);
400 if (n > f->numentities)
402 memcpy(f->entitydata, d->entitydata + d->frames[i].firstentity % MAX_ENTITY_DATABASE, sizeof(*f->entitydata) * n);
403 if (f->numentities > n)
404 memcpy(f->entitydata + n, d->entitydata, sizeof(*f->entitydata) * (f->numentities - n));
405 VectorCopy(d->eye, f->eye);
409 // (server and client) adds a entity_frame to the database, for future reference
410 void EntityFrame_AddFrame(entity_database_t *d, entity_frame_t *f)
413 entity_frameinfo_t *info;
415 VectorCopy(f->eye, d->eye);
417 // figure out how many entity slots are used already
420 n = d->frames[d->numframes - 1].endentity - d->frames[0].firstentity;
421 if (n + f->numentities > MAX_ENTITY_DATABASE || d->numframes >= MAX_ENTITY_HISTORY)
423 // ran out of room, dump database
424 EntityFrame_ClearDatabase(d);
428 info = &d->frames[d->numframes];
429 info->framenum = f->framenum;
431 // make sure we check the newly added frame as well, but we haven't incremented numframes yet
432 for (n = 0;n <= d->numframes;n++)
434 if (e >= d->frames[n].framenum)
436 if (e == f->framenum)
437 Con_Printf("EntityFrame_AddFrame: tried to add out of sequence frame to database\n");
439 Con_Printf("EntityFrame_AddFrame: out of sequence frames in database\n");
442 e = d->frames[n].framenum;
444 // if database still has frames after that...
446 info->firstentity = d->frames[d->numframes - 1].endentity;
448 info->firstentity = 0;
449 info->endentity = info->firstentity + f->numentities;
452 n = info->firstentity % MAX_ENTITY_DATABASE;
453 e = MAX_ENTITY_DATABASE - n;
454 if (e > f->numentities)
456 memcpy(d->entitydata + n, f->entitydata, sizeof(entity_state_t) * e);
457 if (f->numentities > e)
458 memcpy(d->entitydata, f->entitydata + e, sizeof(entity_state_t) * (f->numentities - e));
461 // (server) writes a frame to network stream
462 static entity_frame_t deltaframe; // FIXME?
463 void EntityFrame_Write(entity_database_t *d, entity_frame_t *f, sizebuf_t *msg)
466 entity_frame_t *o = &deltaframe;
467 entity_state_t *ent, *delta;
469 EntityFrame_AddFrame(d, f);
471 EntityFrame_FetchFrame(d, d->ackframe > 0 ? d->ackframe : -1, o);
472 MSG_WriteByte (msg, svc_entities);
473 MSG_WriteLong (msg, o->framenum);
474 MSG_WriteLong (msg, f->framenum);
475 MSG_WriteFloat (msg, f->eye[0]);
476 MSG_WriteFloat (msg, f->eye[1]);
477 MSG_WriteFloat (msg, f->eye[2]);
480 for (i = 0;i < f->numentities;i++)
482 ent = f->entitydata + i;
483 number = ent->number;
484 for (;onum < o->numentities && o->entitydata[onum].number < number;onum++)
486 // write remove message
487 MSG_WriteShort(msg, o->entitydata[onum].number | 0x8000);
489 if (onum < o->numentities && (o->entitydata[onum].number == number))
491 // delta from previous frame
492 delta = o->entitydata + onum;
493 // advance to next entity in delta frame
498 // delta from defaults
499 delta = &defaultstate;
501 EntityState_Write(ent, msg, delta);
503 for (;onum < o->numentities;onum++)
505 // write remove message
506 MSG_WriteShort(msg, o->entitydata[onum].number | 0x8000);
508 MSG_WriteShort(msg, 0xFFFF);
511 // (client) reads a frame from network stream
512 static entity_frame_t framedata; // FIXME?
513 void EntityFrame_Read(entity_database_t *d)
516 entity_frame_t *f = &framedata, *delta = &deltaframe;
517 entity_state_t *e, *old, *oldend;
519 EntityFrame_Clear(f, NULL, -1);
521 // read the frame header info
522 f->time = cl.mtime[0];
523 number = MSG_ReadLong();
524 f->framenum = MSG_ReadLong();
525 f->eye[0] = MSG_ReadFloat();
526 f->eye[1] = MSG_ReadFloat();
527 f->eye[2] = MSG_ReadFloat();
528 EntityFrame_AckFrame(d, number);
529 EntityFrame_FetchFrame(d, number, delta);
530 old = delta->entitydata;
531 oldend = old + delta->numentities;
532 // read entities until we hit the magic 0xFFFF end tag
533 while ((number = (unsigned short) MSG_ReadShort()) != 0xFFFF)
536 Host_Error("EntityFrame_Read: read error\n");
537 removed = number & 0x8000;
539 if (number >= MAX_EDICTS)
540 Host_Error("EntityFrame_Read: number (%i) >= MAX_EDICTS (%i)\n", number, MAX_EDICTS);
542 // seek to entity, while copying any skipped entities (assume unchanged)
543 while (old < oldend && old->number < number)
545 if (f->numentities >= MAX_ENTITY_DATABASE)
546 Host_Error("EntityFrame_Read: entity list too big\n");
547 f->entitydata[f->numentities] = *old++;
548 f->entitydata[f->numentities++].time = cl.mtime[0];
552 if (old < oldend && old->number == number)
555 Con_Printf("EntityFrame_Read: REMOVE on unused entity %i\n", number);
559 if (f->numentities >= MAX_ENTITY_DATABASE)
560 Host_Error("EntityFrame_Read: entity list too big\n");
563 e = f->entitydata + f->numentities++;
565 if (old < oldend && old->number == number)
567 // delta from old entity
572 // delta from defaults
576 EntityState_ReadUpdate(e, number);
581 if (f->numentities >= MAX_ENTITY_DATABASE)
582 Host_Error("EntityFrame_Read: entity list too big\n");
583 f->entitydata[f->numentities] = *old++;
584 f->entitydata[f->numentities++].time = cl.mtime[0];
586 EntityFrame_AddFrame(d, f);
590 // (client) returns the frame number of the most recent frame recieved
591 int EntityFrame_MostRecentlyRecievedFrameNum(entity_database_t *d)
594 return d->frames[d->numframes - 1].framenum;
604 entity_state_t *EntityFrame4_GetReferenceEntity(entity_database4_t *d, int number)
606 if (d->maxreferenceentities <= number)
608 int oldmax = d->maxreferenceentities;
609 entity_state_t *oldentity = d->referenceentity;
610 d->maxreferenceentities = (number + 15) & ~7;
611 d->referenceentity = Mem_Alloc(d->mempool, d->maxreferenceentities * sizeof(*d->referenceentity));
614 memcpy(d->referenceentity, oldentity, oldmax * sizeof(*d->referenceentity));
617 // clear the newly created entities
618 for (;oldmax < d->maxreferenceentities;oldmax++)
620 d->referenceentity[oldmax] = defaultstate;
621 d->referenceentity[oldmax].number = oldmax;
624 return d->referenceentity + number;
627 void EntityFrame4_AddCommitEntity(entity_database4_t *d, entity_state_t *s)
629 // resize commit's entity list if full
630 if (d->currentcommit->maxentities <= d->currentcommit->numentities)
632 entity_state_t *oldentity = d->currentcommit->entity;
633 d->currentcommit->maxentities += 8;
634 d->currentcommit->entity = Mem_Alloc(d->mempool, d->currentcommit->maxentities * sizeof(*d->currentcommit->entity));
637 memcpy(d->currentcommit->entity, oldentity, d->currentcommit->numentities * sizeof(*d->currentcommit->entity));
641 d->currentcommit->entity[d->currentcommit->numentities++] = *s;
644 entity_database4_t *EntityFrame4_AllocDatabase(mempool_t *pool)
646 entity_database4_t *d;
647 d = Mem_Alloc(pool, sizeof(*d));
649 EntityFrame4_ResetDatabase(d);
654 void EntityFrame4_FreeDatabase(entity_database4_t *d)
657 for (i = 0;i < MAX_ENTITY_HISTORY;i++)
658 if (d->commit[i].entity)
659 Mem_Free(d->commit[i].entity);
660 if (d->referenceentity)
661 Mem_Free(d->referenceentity);
665 void EntityFrame4_ResetDatabase(entity_database4_t *d)
668 d->referenceframenum = -1;
669 for (i = 0;i < MAX_ENTITY_HISTORY;i++)
670 d->commit[i].numentities = 0;
671 for (i = 0;i < d->maxreferenceentities;i++)
672 d->referenceentity[i] = defaultstate;
675 int EntityFrame4_AckFrame(entity_database4_t *d, int framenum)
677 int i, j, found = false;
678 entity_database4_commit_t *commit;
679 if (d->referenceframenum == framenum)
683 EntityFrame4_ResetDatabase(d);
686 for (i = 0, commit = d->commit;i < MAX_ENTITY_HISTORY;i++, commit++)
688 if (commit->numentities && commit->framenum <= framenum)
690 if (commit->framenum == framenum)
693 d->referenceframenum = framenum;
694 if (developer_networkentities.integer >= 3)
696 for (j = 0;j < commit->numentities;j++)
698 entity_state_t *s = EntityFrame4_GetReferenceEntity(d, commit->entity[j].number);
699 if (commit->entity[j].active != s->active)
701 if (commit->entity[j].active)
702 Con_Printf("commit entity %i has become active (modelindex %i)\n", commit->entity[j].number, commit->entity[j].modelindex);
704 Con_Printf("commit entity %i has become inactive (modelindex %i)\n", commit->entity[j].number, commit->entity[j].modelindex);
706 *s = commit->entity[j];
710 for (j = 0;j < commit->numentities;j++)
711 *EntityFrame4_GetReferenceEntity(d, commit->entity[j].number) = commit->entity[j];
713 commit->numentities = 0;
719 int EntityFrame4_SV_WriteFrame_Entity(entity_database4_t *d, sizebuf_t *msg, int maxbytes, entity_state_t *s)
724 // prepare the buffer
725 memset(&buf, 0, sizeof(buf));
727 buf.maxsize = sizeof(data);
729 e = EntityFrame4_GetReferenceEntity(d, s->number);
730 // send an update (may update or remove the entity)
731 EntityState_Write(s, &buf, e);
732 // if the message is empty, skip out now
735 // if the commit is full, we're done
736 if (msg->cursize + buf.cursize + 2 >= min(msg->maxsize, maxbytes))
738 // add the entity to the commit
739 EntityFrame4_AddCommitEntity(d, s);
740 // write the message to the packet
741 SZ_Write(msg, buf.data, buf.cursize);
746 extern void CL_MoveLerpEntityStates(entity_t *ent);
747 void EntityFrame4_CL_ReadFrame(entity_database4_t *d)
749 int i, n, cnumber, referenceframenum, framenum, enumber, done, stopnumber, skip = false;
750 // read the number of the frame this refers to
751 referenceframenum = MSG_ReadLong();
752 // read the number of this frame
753 framenum = MSG_ReadLong();
754 // read the start number
755 enumber = MSG_ReadShort();
756 if (developer_networkentities.integer >= 1)
758 Con_Printf("recv svc_entities ref:%i num:%i (database: ref:%i commits:", referenceframenum, framenum, d->referenceframenum);
759 for (i = 0;i < MAX_ENTITY_HISTORY;i++)
760 if (d->commit[i].numentities)
761 Con_Printf(" %i", d->commit[i].framenum);
764 if (!EntityFrame4_AckFrame(d, referenceframenum))
766 Con_Printf("EntityFrame4_CL_ReadFrame: reference frame invalid (VERY BAD ERROR), this update will be skipped\n");
769 EntityFrame4_ResetDatabase(d);
771 d->currentcommit = NULL;
772 for (i = 0;i < MAX_ENTITY_HISTORY;i++)
774 if (!d->commit[i].numentities)
776 d->currentcommit = d->commit + i;
777 d->currentcommit->framenum = d->ackframenum = framenum;
778 d->currentcommit->numentities = 0;
781 if (d->currentcommit == NULL)
783 Con_Printf("EntityFrame4_CL_ReadFrame: error while decoding frame %i: database full, reading but not storing this update\n", framenum);
787 while (!done && !msg_badread)
789 // read the number of the modified entity
790 // (gaps will be copied unmodified)
791 n = (unsigned short)MSG_ReadShort();
794 // no more entities in this update, but we still need to copy the
795 // rest of the reference entities (final gap)
797 // read end of range number, then process normally
798 n = (unsigned short)MSG_ReadShort();
800 // high bit means it's a remove message
801 cnumber = n & 0x7FFF;
802 // add one (the changed one) if not done
803 stopnumber = cnumber + !done;
804 // process entities in range from the last one to the changed one
805 for (;enumber < stopnumber;enumber++)
809 if (enumber == cnumber && (n & 0x8000) == 0)
811 entity_state_t tempstate;
812 EntityState_ReadUpdate(&tempstate, enumber);
816 // slide the current into the previous slot
817 cl_entities[enumber].state_previous = cl_entities[enumber].state_current;
818 // copy a new current from reference database
819 cl_entities[enumber].state_current = *EntityFrame4_GetReferenceEntity(d, enumber);
820 // if this is the one to modify, read more data...
821 if (enumber == cnumber)
826 if (developer_networkentities.integer >= 2)
827 Con_Printf("entity %i: remove\n", enumber);
828 cl_entities[enumber].state_current = defaultstate;
833 if (developer_networkentities.integer >= 2)
834 Con_Printf("entity %i: update\n", enumber);
835 EntityState_ReadUpdate(&cl_entities[enumber].state_current, enumber);
838 else if (developer_networkentities.integer >= 4)
839 Con_Printf("entity %i: copy\n", enumber);
840 // fix the number (it gets wiped occasionally by copying from defaultstate)
841 cl_entities[enumber].state_current.number = enumber;
842 // check if we need to update the lerp stuff
843 if (cl_entities[enumber].state_current.active)
845 CL_MoveLerpEntityStates(&cl_entities[enumber]);
846 cl_entities_active[enumber] = true;
848 // add this to the commit entry whether it is modified or not
849 if (d->currentcommit)
850 EntityFrame4_AddCommitEntity(d, &cl_entities[enumber].state_current);
851 // print extra messages if desired
852 if (developer_networkentities.integer >= 2 && cl_entities[enumber].state_current.active != cl_entities[enumber].state_previous.active)
854 if (cl_entities[enumber].state_current.active)
855 Con_Printf("entity #%i has become active\n", enumber);
856 else if (cl_entities[enumber].state_previous.active)
857 Con_Printf("entity #%i has become inactive\n", enumber);
861 d->currentcommit = NULL;