4 // (client and server) allocates a new empty database
5 entityframe_database_t *EntityFrame_AllocDatabase(mempool_t *mempool)
7 return (entityframe_database_t *)Mem_Alloc(mempool, sizeof(entityframe_database_t));
10 // (client and server) frees the database
11 void EntityFrame_FreeDatabase(entityframe_database_t *d)
16 // (server and client) removes frames older than 'frame' from database
17 void EntityFrame_AckFrame(entityframe_database_t *d, int frame)
20 d->ackframenum = frame;
21 for (i = 0;i < d->numframes && d->frames[i].framenum < frame;i++);
22 // ignore outdated frame acks (out of order packets)
26 // if some queue is left, slide it down to beginning of array
28 memmove(&d->frames[0], &d->frames[i], sizeof(d->frames[0]) * d->numframes);
31 // (server and client) reads a frame from the database
32 void EntityFrame_FetchFrame(entityframe_database_t *d, int framenum, entity_frame_t *f)
35 EntityFrame_Clear(f, NULL, -1);
36 for (i = 0;i < d->numframes && d->frames[i].framenum < framenum;i++);
37 if (i < d->numframes && framenum == d->frames[i].framenum)
39 f->framenum = framenum;
40 f->numentities = d->frames[i].endentity - d->frames[i].firstentity;
41 n = MAX_ENTITY_DATABASE - (d->frames[i].firstentity % MAX_ENTITY_DATABASE);
42 if (n > f->numentities)
44 memcpy(f->entitydata, d->entitydata + d->frames[i].firstentity % MAX_ENTITY_DATABASE, sizeof(*f->entitydata) * n);
45 if (f->numentities > n)
46 memcpy(f->entitydata + n, d->entitydata, sizeof(*f->entitydata) * (f->numentities - n));
47 VectorCopy(d->eye, f->eye);