DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
com_ents4.c
Go to the documentation of this file.
1#include "quakedef.h"
2#include "protocol.h"
3
12
14{
15 int i;
16 for (i = 0;i < MAX_ENTITY_HISTORY;i++)
17 if (d->commit[i].entity)
19 if (d->referenceentity)
21 Mem_Free(d);
22}
23
25{
26 int i;
27 d->referenceframenum = -1;
28 for (i = 0;i < MAX_ENTITY_HISTORY;i++)
29 d->commit[i].numentities = 0;
30 for (i = 0;i < d->maxreferenceentities;i++)
32}
33
35{
36 if (d->maxreferenceentities <= number)
37 {
38 int oldmax = d->maxreferenceentities;
39 entity_state_t *oldentity = d->referenceentity;
40 d->maxreferenceentities = (number + 15) & ~7;
42 if (oldentity)
43 {
44 memcpy(d->referenceentity, oldentity, oldmax * sizeof(*d->referenceentity));
45 Mem_Free(oldentity);
46 }
47 // clear the newly created entities
48 for (;oldmax < d->maxreferenceentities;oldmax++)
49 {
50 d->referenceentity[oldmax] = defaultstate;
51 d->referenceentity[oldmax].number = oldmax;
52 }
53 }
54 return d->referenceentity + number;
55}
56
58{
59 // resize commit's entity list if full
61 {
62 entity_state_t *oldentity = d->currentcommit->entity;
65 if (oldentity)
66 {
67 memcpy(d->currentcommit->entity, oldentity, d->currentcommit->numentities * sizeof(*d->currentcommit->entity));
68 Mem_Free(oldentity);
69 }
70 }
72}
73
74int EntityFrame4_AckFrame(entityframe4_database_t *d, int framenum, int servermode)
75{
76 int i, j, found;
78 if (framenum == -1)
79 {
80 // reset reference, but leave commits alone
81 d->referenceframenum = -1;
82 for (i = 0;i < d->maxreferenceentities;i++)
84 // if this is the server, remove commits
85 for (i = 0, commit = d->commit;i < MAX_ENTITY_HISTORY;i++, commit++)
86 commit->numentities = 0;
87 found = true;
88 }
89 else if (d->referenceframenum == framenum)
90 found = true;
91 else
92 {
93 found = false;
94 for (i = 0, commit = d->commit;i < MAX_ENTITY_HISTORY;i++, commit++)
95 {
96 if (commit->numentities && commit->framenum <= framenum)
97 {
98 if (commit->framenum == framenum)
99 {
100 found = true;
101 d->referenceframenum = framenum;
103 {
104 for (j = 0;j < commit->numentities;j++)
105 {
107 if (commit->entity[j].active != s->active)
108 {
109 if (commit->entity[j].active == ACTIVE_NETWORK)
110 Con_Printf("commit entity %i has become active (modelindex %i)\n", commit->entity[j].number, commit->entity[j].modelindex);
111 else
112 Con_Printf("commit entity %i has become inactive (modelindex %i)\n", commit->entity[j].number, commit->entity[j].modelindex);
113 }
114 *s = commit->entity[j];
115 }
116 }
117 else
118 for (j = 0;j < commit->numentities;j++)
119 *EntityFrame4_GetReferenceEntity(d, commit->entity[j].number) = commit->entity[j];
120 }
121 commit->numentities = 0;
122 }
123 }
124 }
126 {
127 Con_Printf("ack ref:%i database updated to: ref:%i commits:", framenum, d->referenceframenum);
128 for (i = 0;i < MAX_ENTITY_HISTORY;i++)
129 if (d->commit[i].numentities)
130 Con_Printf(" %i", d->commit[i].framenum);
131 Con_Print("\n");
132 }
133 return found;
134}
cvar_t developer_networkentities
Definition cl_parse.c:173
void EntityFrame4_FreeDatabase(entityframe4_database_t *d)
Definition com_ents4.c:13
int EntityFrame4_AckFrame(entityframe4_database_t *d, int framenum, int servermode)
Definition com_ents4.c:74
entityframe4_database_t * EntityFrame4_AllocDatabase(mempool_t *pool)
Definition com_ents4.c:4
void EntityFrame4_ResetDatabase(entityframe4_database_t *d)
Definition com_ents4.c:24
entity_state_t * EntityFrame4_GetReferenceEntity(entityframe4_database_t *d, int number)
Definition com_ents4.c:34
void EntityFrame4_AddCommitEntity(entityframe4_database_t *d, const entity_state_t *s)
Definition com_ents4.c:57
void Con_Print(const char *msg)
Prints to all appropriate console targets, and adds timestamps.
Definition console.c:1504
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
Definition console.c:1514
entity_state_t defaultstate
Definition protocol.c:4
#define MAX_ENTITY_HISTORY
Definition protocol.h:553
@ ACTIVE_NETWORK
Definition protocol.h:433
int i
int integer
Definition cvar.h:73
entity_state_t * entity
Definition protocol.h:697
unsigned short modelindex
Definition protocol.h:449
unsigned char active
Definition protocol.h:459
unsigned short number
Definition protocol.h:448
entity_database4_commit_t commit[MAX_ENTITY_HISTORY]
Definition protocol.h:713
entity_state_t * referenceentity
Definition protocol.h:710
entity_database4_commit_t * currentcommit
Definition protocol.h:715
struct mempool_s * mempool
Definition protocol.h:704
#define Mem_Free(mem)
Definition zone.h:96
#define Mem_Alloc(pool, size)
Definition zone.h:92