DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
com_ents.c
Go to the documentation of this file.
1#include "quakedef.h"
2#include "protocol.h"
3
4// (client and server) allocates a new empty database
9
10// (client and server) frees the database
15
16// (client and server) clears the database to contain no frames (thus delta compression compresses against nothing)
18{
19 memset(d, 0, sizeof(*d));
20}
21
22// (client and server) clears frame, to prepare for adding entities
23void EntityFrame_Clear(entity_frame_t *f, vec3_t eye, int framenum)
24{
25 f->time = 0;
26 f->framenum = framenum;
27 f->numentities = 0;
28 if (eye == NULL)
29 VectorClear(f->eye);
30 else
31 VectorCopy(eye, f->eye);
32}
33
34// (server and client) removes frames older than 'frame' from database
36{
37 int i;
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)
41 if (i == 0)
42 return;
43 d->numframes -= i;
44 // if some queue is left, slide it down to beginning of array
45 if (d->numframes)
46 memmove(&d->frames[0], &d->frames[i], sizeof(d->frames[0]) * d->numframes);
47}
48
49// (server and client) reads a frame from the database
51{
52 int i, n;
54 for (i = 0;i < d->numframes && d->frames[i].framenum < framenum;i++);
55 if (i < d->numframes && framenum == d->frames[i].framenum)
56 {
57 f->framenum = framenum;
58 f->numentities = d->frames[i].endentity - d->frames[i].firstentity;
60 if (n > f->numentities)
61 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);
66 }
67}
void EntityFrame_Clear(entity_frame_t *f, vec3_t eye, int framenum)
Definition com_ents.c:23
void EntityFrame_FetchFrame(entityframe_database_t *d, int framenum, entity_frame_t *f)
Definition com_ents.c:50
entityframe_database_t * EntityFrame_AllocDatabase(mempool_t *mempool)
Definition com_ents.c:5
void EntityFrame_AckFrame(entityframe_database_t *d, int frame)
Definition com_ents.c:35
void EntityFrame_ClearDatabase(entityframe_database_t *d)
Definition com_ents.c:17
void EntityFrame_FreeDatabase(entityframe_database_t *d)
Definition com_ents.c:11
float frame
#define n(x, y)
#define VectorClear(a)
Definition mathlib.h:97
#define VectorCopy(in, out)
Definition mathlib.h:101
#define MAX_ENTITY_DATABASE
Definition protocol.h:554
int i
#define NULL
Definition qtypes.h:12
vec_t vec3_t[3]
Definition qtypes.h:71
float f
entity_frameinfo_t frames[MAX_ENTITY_HISTORY]
Definition protocol.h:596
entity_state_t entitydata[MAX_ENTITY_DATABASE]
Definition protocol.h:598
#define Mem_Free(mem)
Definition zone.h:96
#define Mem_Alloc(pool, size)
Definition zone.h:92