DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
sv_ents_nq.c File Reference
#include "quakedef.h"
#include "protocol.h"
+ Include dependency graph for sv_ents_nq.c:

Go to the source code of this file.

Functions

qbool EntityFrameQuake_WriteFrame (sizebuf_t *msg, int maxsize, int numstates, const entity_state_t **states)
 

Function Documentation

◆ EntityFrameQuake_WriteFrame()

qbool EntityFrameQuake_WriteFrame ( sizebuf_t * msg,
int maxsize,
int numstates,
const entity_state_t ** states )

Definition at line 4 of file sv_ents_nq.c.

5{
7 const entity_state_t *s;
8 entity_state_t baseline;
9 int i, bits;
11 unsigned char data[128];
12 qbool success = false;
13
14 // prepare the buffer
15 memset(&buf, 0, sizeof(buf));
16 buf.data = data;
17 buf.maxsize = sizeof(data);
18
19 for (i = 0;i < numstates;i++)
20 {
21 s = states[i];
22 if(PRVM_serveredictfunction((&prog->edicts[s->number]), SendEntity))
23 continue;
24
25 // prepare the buffer
26 SZ_Clear(&buf);
27
28// send an update
29 bits = 0;
30 if (s->number >= 256)
31 bits |= U_LONGENTITY;
32 if (s->flags & RENDER_STEP)
33 bits |= U_STEP;
34 if (s->flags & RENDER_VIEWMODEL)
35 bits |= U_VIEWMODEL;
36 if (s->flags & RENDER_GLOWTRAIL)
37 bits |= U_GLOWTRAIL;
39 bits |= U_EXTERIORMODEL;
40
41 // LadyHavoc: old stuff, but rewritten to have more exact tolerances
42 baseline = prog->edicts[s->number].priv.server->baseline;
43 if (baseline.origin[0] != s->origin[0])
44 bits |= U_ORIGIN1;
45 if (baseline.origin[1] != s->origin[1])
46 bits |= U_ORIGIN2;
47 if (baseline.origin[2] != s->origin[2])
48 bits |= U_ORIGIN3;
49 if (baseline.angles[0] != s->angles[0])
50 bits |= U_ANGLE1;
51 if (baseline.angles[1] != s->angles[1])
52 bits |= U_ANGLE2;
53 if (baseline.angles[2] != s->angles[2])
54 bits |= U_ANGLE3;
55 if (baseline.colormap != s->colormap)
56 bits |= U_COLORMAP;
57 if (baseline.skin != s->skin)
58 bits |= U_SKIN;
59 if (baseline.frame != s->frame)
60 {
61 bits |= U_FRAME;
62 if (s->frame & 0xFF00)
63 bits |= U_FRAME2;
64 }
65 if (baseline.effects != s->effects)
66 {
67 bits |= U_EFFECTS;
68 if (s->effects & 0xFF00)
69 bits |= U_EFFECTS2;
70 }
71 if (baseline.modelindex != s->modelindex)
72 {
73 bits |= U_MODEL;
75 bits |= U_MODEL2;
76 }
77 if (baseline.alpha != s->alpha)
78 bits |= U_ALPHA;
79 if (baseline.scale != s->scale)
80 bits |= U_SCALE;
81 if (baseline.glowsize != s->glowsize)
82 bits |= U_GLOWSIZE;
83 if (baseline.glowcolor != s->glowcolor)
84 bits |= U_GLOWCOLOR;
85 if (!VectorCompare(baseline.colormod, s->colormod))
86 bits |= U_COLORMOD;
87
88 // if extensions are disabled, clear the relevant update flags
90 bits &= 0x7FFF;
92 if (s->alpha != 255 || s->effects & EF_FULLBRIGHT)
93 bits |= U_EXTEND1;
94
95 // write the message
96 if (bits >= 16777216)
97 bits |= U_EXTEND2;
98 if (bits >= 65536)
99 bits |= U_EXTEND1;
100 if (bits >= 256)
101 bits |= U_MOREBITS;
102 bits |= U_SIGNAL;
103
104 {
105 ENTITYSIZEPROFILING_START(msg, states[i]->number, bits);
106
107 MSG_WriteByte (&buf, bits);
108 if (bits & U_MOREBITS) MSG_WriteByte(&buf, bits>>8);
110 {
111 if (bits & U_EXTEND1) MSG_WriteByte(&buf, bits>>16);
112 if (bits & U_EXTEND2) MSG_WriteByte(&buf, bits>>24);
113 }
114 if (bits & U_LONGENTITY) MSG_WriteShort(&buf, s->number);
115 else MSG_WriteByte(&buf, s->number);
116
117 if (bits & U_MODEL)
118 {
121 else
123 }
124 if (bits & U_FRAME) MSG_WriteByte(&buf, s->frame);
125 if (bits & U_COLORMAP) MSG_WriteByte(&buf, s->colormap);
126 if (bits & U_SKIN) MSG_WriteByte(&buf, s->skin);
127 if (bits & U_EFFECTS) MSG_WriteByte(&buf, s->effects);
128 if (bits & U_ORIGIN1) MSG_WriteCoord(&buf, s->origin[0], sv.protocol);
129 if (bits & U_ANGLE1) MSG_WriteAngle(&buf, s->angles[0], sv.protocol);
130 if (bits & U_ORIGIN2) MSG_WriteCoord(&buf, s->origin[1], sv.protocol);
131 if (bits & U_ANGLE2) MSG_WriteAngle(&buf, s->angles[1], sv.protocol);
132 if (bits & U_ORIGIN3) MSG_WriteCoord(&buf, s->origin[2], sv.protocol);
133 if (bits & U_ANGLE3) MSG_WriteAngle(&buf, s->angles[2], sv.protocol);
134 if (bits & U_ALPHA) MSG_WriteByte(&buf, s->alpha);
135 if (bits & U_SCALE) MSG_WriteByte(&buf, s->scale);
136 if (bits & U_EFFECTS2) MSG_WriteByte(&buf, s->effects >> 8);
137 if (bits & U_GLOWSIZE) MSG_WriteByte(&buf, s->glowsize);
138 if (bits & U_GLOWCOLOR) MSG_WriteByte(&buf, s->glowcolor);
139 if (bits & U_COLORMOD) {int c = ((int)bound(0, s->colormod[0] * (7.0f / 32.0f), 7) << 5) | ((int)bound(0, s->colormod[1] * (7.0f / 32.0f), 7) << 2) | ((int)bound(0, s->colormod[2] * (3.0f / 32.0f), 3) << 0);MSG_WriteByte(&buf, c);}
140 if (bits & U_FRAME2) MSG_WriteByte(&buf, s->frame >> 8);
141 if (bits & U_MODEL2) MSG_WriteByte(&buf, s->modelindex >> 8);
142
143 // the nasty protocol
144 if ((bits & U_EXTEND1) && sv.protocol == PROTOCOL_NEHAHRAMOVIE)
145 {
146 if (s->effects & EF_FULLBRIGHT)
147 {
148 MSG_WriteFloat(&buf, 2); // QSG protocol version
149 MSG_WriteFloat(&buf, s->alpha <= 0 ? 0 : (s->alpha >= 255 ? 1 : s->alpha * (1.0f / 255.0f))); // alpha
150 MSG_WriteFloat(&buf, 1); // fullbright
151 }
152 else
153 {
154 MSG_WriteFloat(&buf, 1); // QSG protocol version
155 MSG_WriteFloat(&buf, s->alpha <= 0 ? 0 : (s->alpha >= 255 ? 1 : s->alpha * (1.0f / 255.0f))); // alpha
156 }
157 }
158
159 // if the commit is full, we're done this frame
160 if (msg->cursize + buf.cursize > maxsize)
161 {
162 // next frame we will continue where we left off
163 break;
164 }
165 // write the message to the packet
166 SZ_Write(msg, buf.data, buf.cursize);
167 success = true;
168 ENTITYSIZEPROFILING_END(msg, s->number, bits);
169 }
170 }
171 return success;
172}
void MSG_WriteShort(sizebuf_t *sb, int c)
Definition com_msg.c:138
void MSG_WriteCoord(sizebuf_t *sb, float f, protocolversion_t protocol)
Definition com_msg.c:202
void MSG_WriteByte(sizebuf_t *sb, int c)
Definition com_msg.c:130
void MSG_WriteFloat(sizebuf_t *sb, float f)
Definition com_msg.c:158
void MSG_WriteAngle(sizebuf_t *sb, float f, protocolversion_t protocol)
Definition com_msg.c:237
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
@ PROTOCOL_NEHAHRABJP2
same as NEHAHRABJP but with 16bit soundindex
Definition common.h:147
@ PROTOCOL_NEHAHRABJP
same as QUAKEDP but with 16bit modelindex
Definition common.h:146
@ PROTOCOL_QUAKE
quake (aka netquake/normalquake/nq) protocol
Definition common.h:144
@ PROTOCOL_NEHAHRABJP3
same as NEHAHRABJP2 but with some changes
Definition common.h:148
@ PROTOCOL_NEHAHRAMOVIE
Nehahra movie protocol, a big nasty hack dating back to early days of the Quake Standards Group (but ...
Definition common.h:143
static int(ZEXPORT *qz_inflate)(z_stream *strm
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 VectorCompare(a, b)
Definition mathlib.h:113
#define PRVM_serveredictfunction(ed, fieldname)
Definition progsvm.h:176
#define SVVM_prog
Definition progsvm.h:766
#define RENDER_EXTERIORMODEL
Definition protocol.h:359
#define ENTITYSIZEPROFILING_START(msg, num, flags)
Definition protocol.h:39
#define EF_FULLBRIGHT
Definition protocol.h:77
#define U_ANGLE2
Definition protocol.h:115
#define U_COLORMOD
1 byte, 3 bit red, 3 bit green, 2 bit blue, this lets you tint an object artifically,...
Definition protocol.h:139
#define U_ANGLE3
Definition protocol.h:123
#define U_SIGNAL
Definition protocol.h:120
#define U_SCALE
1 byte, scale / 16 positive, not sent if 1.0
Definition protocol.h:135
#define U_EFFECTS2
1 byte, this is .effects & 0xFF00 (second byte)
Definition protocol.h:136
#define U_STEP
Definition protocol.h:117
#define U_EXTEND1
Definition protocol.h:131
#define U_GLOWCOLOR
1 byte, palette index, default is 254 (white), this IS used for darklight (allowing colored darklight...
Definition protocol.h:138
#define U_ORIGIN2
Definition protocol.h:113
#define U_ORIGIN1
Definition protocol.h:112
#define U_MODEL
Definition protocol.h:124
#define RENDER_VIEWMODEL
Definition protocol.h:358
#define U_ORIGIN3
Definition protocol.h:114
#define U_COLORMAP
Definition protocol.h:125
#define U_FRAME2
1 byte, this is .frame & 0xFF00 (second byte)
Definition protocol.h:144
#define RENDER_GLOWTRAIL
Definition protocol.h:357
#define U_EFFECTS
Definition protocol.h:127
#define ENTITYSIZEPROFILING_END(msg, num, flags)
Definition protocol.h:42
#define U_GLOWTRAIL
leaves a trail of particles (of color .glowcolor, or black if it is a negative glowsize)
Definition protocol.h:142
#define U_EXTEND2
another byte to follow
Definition protocol.h:140
#define U_VIEWMODEL
attachs the model to the view (origin and angles become relative to it), only shown to owner,...
Definition protocol.h:143
#define U_SKIN
Definition protocol.h:126
#define RENDER_STEP
Definition protocol.h:356
#define U_LONGENTITY
Definition protocol.h:128
#define U_FRAME
Definition protocol.h:118
#define U_ALPHA
1 byte, 0.0-1.0 maps to 0-255, not sent if exactly 1, and the entity is not sent if <=0 unless it has...
Definition protocol.h:134
#define U_MOREBITS
Definition protocol.h:111
#define U_MODEL2
1 byte, this is .modelindex & 0xFF00 (second byte)
Definition protocol.h:145
#define U_ANGLE1
Definition protocol.h:122
#define U_GLOWSIZE
1 byte, encoding is float/4.0, unsigned, not sent if 0
Definition protocol.h:137
#define U_EXTERIORMODEL
causes this model to not be drawn when using a first person view (third person will draw it,...
Definition protocol.h:146
int i
bool qbool
Definition qtypes.h:9
server_t sv
local server
Definition sv_main.c:223
unsigned char flags
Definition protocol.h:468
unsigned char skin
Definition protocol.h:463
unsigned char glowcolor
Definition protocol.h:467
unsigned char glowsize
Definition protocol.h:466
float origin[3]
Definition protocol.h:444
unsigned char colormap
Definition protocol.h:462
unsigned short modelindex
Definition protocol.h:449
unsigned char colormod[3]
Definition protocol.h:471
unsigned char alpha
Definition protocol.h:464
float angles[3]
Definition protocol.h:445
unsigned short frame
Definition protocol.h:450
unsigned short number
Definition protocol.h:448
unsigned char scale
Definition protocol.h:465
union prvm_edict_t::@29 priv
struct edict_engineprivate_s * server
FIXME: this server pointer really means world, not server (it is used by both server qc and client qc...
Definition progsvm.h:106
prvm_edict_t * edicts
Definition progsvm.h:680
protocolversion_t protocol
one of the PROTOCOL_ values
Definition server.h:74
int cursize
Definition common.h:54

References entity_state_t::alpha, entity_state_t::angles, bound, buf, entity_state_t::colormap, entity_state_t::colormod, sizebuf_t::cursize, data, prvm_prog_t::edicts, EF_FULLBRIGHT, entity_state_t::effects, ENTITYSIZEPROFILING_END, ENTITYSIZEPROFILING_START, entity_state_t::flags, entity_state_t::frame, entity_state_t::glowcolor, entity_state_t::glowsize, i, int(), entity_state_t::modelindex, MSG_WriteAngle(), MSG_WriteByte(), MSG_WriteCoord(), MSG_WriteFloat(), MSG_WriteShort(), entity_state_t::number, entity_state_t::origin, prvm_edict_t::priv, server_t::protocol, PROTOCOL_NEHAHRABJP, PROTOCOL_NEHAHRABJP2, PROTOCOL_NEHAHRABJP3, PROTOCOL_NEHAHRAMOVIE, PROTOCOL_QUAKE, PRVM_serveredictfunction, RENDER_EXTERIORMODEL, RENDER_GLOWTRAIL, RENDER_STEP, RENDER_VIEWMODEL, entity_state_t::scale, prvm_edict_t::server, entity_state_t::skin, sv, SVVM_prog, SZ_Clear(), SZ_Write(), U_ALPHA, U_ANGLE1, U_ANGLE2, U_ANGLE3, U_COLORMAP, U_COLORMOD, U_EFFECTS, U_EFFECTS2, U_EXTEND1, U_EXTEND2, U_EXTERIORMODEL, U_FRAME, U_FRAME2, U_GLOWCOLOR, U_GLOWSIZE, U_GLOWTRAIL, U_LONGENTITY, U_MODEL, U_MODEL2, U_MOREBITS, U_ORIGIN1, U_ORIGIN2, U_ORIGIN3, U_SCALE, U_SIGNAL, U_SKIN, U_STEP, U_VIEWMODEL, and VectorCompare.