DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
sv_ents4.c
Go to the documentation of this file.
1#include "quakedef.h"
2#include "protocol.h"
3
4qbool EntityFrame4_WriteFrame(sizebuf_t *msg, int maxsize, entityframe4_database_t *d, int numstates, const entity_state_t **states)
5{
7 const entity_state_t *e, *s;
8 entity_state_t inactiveentitystate;
9 int i, n, startnumber;
11 unsigned char data[128];
12
13 // if there isn't enough space to accomplish anything, skip it
14 if (msg->cursize + 24 > maxsize)
15 return false;
16
17 // prepare the buffer
18 memset(&buf, 0, sizeof(buf));
19 buf.data = data;
20 buf.maxsize = sizeof(data);
21
22 for (i = 0;i < MAX_ENTITY_HISTORY;i++)
23 if (!d->commit[i].numentities)
24 break;
25 // if commit buffer full, just don't bother writing an update this frame
26 if (i == MAX_ENTITY_HISTORY)
27 return false;
28 d->currentcommit = d->commit + i;
29
30 // this state's number gets played around with later
31 inactiveentitystate = defaultstate;
32
39 {
40 Con_Printf("send svc_entities num:%i ref:%i (database: ref:%i commits:", d->currentcommit->framenum, d->referenceframenum, d->referenceframenum);
41 for (i = 0;i < MAX_ENTITY_HISTORY;i++)
42 if (d->commit[i].numentities)
43 Con_Printf(" %i", d->commit[i].framenum);
44 Con_Print(")\n");
45 }
46 if (d->currententitynumber >= prog->max_edicts)
47 startnumber = 1;
48 else
49 startnumber = bound(1, d->currententitynumber, prog->max_edicts - 1);
50 MSG_WriteShort(msg, startnumber);
51 // reset currententitynumber so if the loop does not break it we will
52 // start at beginning next frame (if it does break, it will set it)
54 for (i = 0, n = startnumber;n < prog->max_edicts;n++)
55 {
56 if (PRVM_serveredictfunction((&prog->edicts[n]), SendEntity))
57 continue;
58 // find the old state to delta from
60 // prepare the buffer
61 SZ_Clear(&buf);
62 // entity exists, build an update (if empty there is no change)
63 // find the state in the list
64 for (;i < numstates && states[i]->number < n;i++);
65 // make the message
66 s = states[i];
67 if (s->number == n)
68 {
69 // build the update
71 }
72 else
73 {
74 inactiveentitystate.number = n;
75 s = &inactiveentitystate;
76 if (e->active == ACTIVE_NETWORK)
77 {
78 // entity used to exist but doesn't anymore, send remove
79 MSG_WriteShort(&buf, n | 0x8000);
80 }
81 }
82 // if the commit is full, we're done this frame
83 if (msg->cursize + buf.cursize > maxsize - 4)
84 {
85 // next frame we will continue where we left off
86 break;
87 }
88 // add the entity to the commit
90 // if the message is empty, skip out now
91 if (buf.cursize)
92 {
93 // write the message to the packet
94 SZ_Write(msg, buf.data, buf.cursize);
95 }
96 }
98
99 // remove world message (invalid, and thus a good terminator)
100 MSG_WriteShort(msg, 0x8000);
101 // write the number of the end entity
103 // just to be sure
104 d->currentcommit = NULL;
105
106 return true;
107}
cvar_t developer_networkentities
Definition cl_parse.c:173
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 MSG_WriteShort(sizebuf_t *sb, int c)
Definition com_msg.c:138
void MSG_WriteLong(sizebuf_t *sb, int c)
Definition com_msg.c:147
void MSG_WriteByte(sizebuf_t *sb, int c)
Definition com_msg.c:130
void SZ_Clear(sizebuf_t *buf)
Definition common.c:44
void SZ_Write(sizebuf_t *buf, const unsigned char *data, int length)
Definition common.c:72
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
#define n(x, y)
GLsizeiptr const GLvoid * data
Definition glquake.h:639
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition glquake.h:657
#define bound(min, num, max)
Definition mathlib.h:34
#define PRVM_serveredictfunction(ed, fieldname)
Definition progsvm.h:176
#define SVVM_prog
Definition progsvm.h:766
entity_state_t defaultstate
Definition protocol.c:4
#define MAX_ENTITY_HISTORY
Definition protocol.h:553
#define svc_entities
Definition protocol.h:277
void EntityState_WriteUpdate(const entity_state_t *ent, struct sizebuf_s *msg, const entity_state_t *delta)
@ ACTIVE_NETWORK
Definition protocol.h:433
int i
#define NULL
Definition qtypes.h:12
bool qbool
Definition qtypes.h:9
int integer
Definition cvar.h:73
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_database4_commit_t * currentcommit
Definition protocol.h:715
prvm_edict_t * edicts
Definition progsvm.h:680
int max_edicts
number of edicts for which space has been (should be) allocated
Definition progsvm.h:673
int cursize
Definition common.h:54
qbool EntityFrame4_WriteFrame(sizebuf_t *msg, int maxsize, entityframe4_database_t *d, int numstates, const entity_state_t **states)
Definition sv_ents4.c:4