]> git.xonotic.org Git - xonotic/darkplaces.git/blob - com_ents.c
build: minor adjustments
[xonotic/darkplaces.git] / com_ents.c
1 #include "quakedef.h"
2 #include "protocol.h"
3
4 // (client and server) allocates a new empty database
5 entityframe_database_t *EntityFrame_AllocDatabase(mempool_t *mempool)
6 {
7         return (entityframe_database_t *)Mem_Alloc(mempool, sizeof(entityframe_database_t));
8 }
9
10 // (client and server) frees the database
11 void EntityFrame_FreeDatabase(entityframe_database_t *d)
12 {
13         Mem_Free(d);
14 }
15
16 // (server and client) removes frames older than 'frame' from database
17 void EntityFrame_AckFrame(entityframe_database_t *d, int frame)
18 {
19         int i;
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)
23         if (i == 0)
24                 return;
25         d->numframes -= i;
26         // if some queue is left, slide it down to beginning of array
27         if (d->numframes)
28                 memmove(&d->frames[0], &d->frames[i], sizeof(d->frames[0]) * d->numframes);
29 }
30
31 // (server and client) reads a frame from the database
32 void EntityFrame_FetchFrame(entityframe_database_t *d, int framenum, entity_frame_t *f)
33 {
34         int i, n;
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)
38         {
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)
43                         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);
48         }
49 }