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 // (client and server) clears the database to contain no frames (thus delta compression compresses against nothing)
17 void EntityFrame_ClearDatabase(entityframe_database_t *d)
19 memset(d, 0, sizeof(*d));
22 // (client and server) clears frame, to prepare for adding entities
23 void EntityFrame_Clear(entity_frame_t *f, vec3_t eye, int framenum)
26 f->framenum = framenum;
31 VectorCopy(eye, f->eye);
34 // (server and client) removes frames older than 'frame' from database
35 void EntityFrame_AckFrame(entityframe_database_t *d, int frame)
38 d->ackframenum = frame;
39 for (i = 0;i < d->numframes && d->frames[i].framenum < frame;i++);
40 // ignore outdated frame acks (out of order packets)
44 // if some queue is left, slide it down to beginning of array
46 memmove(&d->frames[0], &d->frames[i], sizeof(d->frames[0]) * d->numframes);
49 // (server and client) reads a frame from the database
50 void EntityFrame_FetchFrame(entityframe_database_t *d, int framenum, entity_frame_t *f)
53 EntityFrame_Clear(f, NULL, -1);
54 for (i = 0;i < d->numframes && d->frames[i].framenum < framenum;i++);
55 if (i < d->numframes && framenum == d->frames[i].framenum)
57 f->framenum = framenum;
58 f->numentities = d->frames[i].endentity - d->frames[i].firstentity;
59 n = MAX_ENTITY_DATABASE - (d->frames[i].firstentity % MAX_ENTITY_DATABASE);
60 if (n > f->numentities)
62 memcpy(f->entitydata, d->entitydata + d->frames[i].firstentity % MAX_ENTITY_DATABASE, sizeof(*f->entitydata) * n);
63 if (f->numentities > n)
64 memcpy(f->entitydata + n, d->entitydata, sizeof(*f->entitydata) * (f->numentities - n));
65 VectorCopy(d->eye, f->eye);