4 qbool EntityFrameQuake_WriteFrame(sizebuf_t *msg, int maxsize, int numstates, const entity_state_t **states)
6 prvm_prog_t *prog = SVVM_prog;
7 const entity_state_t *s;
8 entity_state_t baseline;
11 unsigned char data[128];
12 qbool success = false;
15 memset(&buf, 0, sizeof(buf));
17 buf.maxsize = sizeof(data);
19 for (i = 0;i < numstates;i++)
22 if(PRVM_serveredictfunction((&prog->edicts[s->number]), SendEntity))
32 if (s->flags & RENDER_STEP)
34 if (s->flags & RENDER_VIEWMODEL)
36 if (s->flags & RENDER_GLOWTRAIL)
38 if (s->flags & RENDER_EXTERIORMODEL)
39 bits |= U_EXTERIORMODEL;
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])
45 if (baseline.origin[1] != s->origin[1])
47 if (baseline.origin[2] != s->origin[2])
49 if (baseline.angles[0] != s->angles[0])
51 if (baseline.angles[1] != s->angles[1])
53 if (baseline.angles[2] != s->angles[2])
55 if (baseline.colormap != s->colormap)
57 if (baseline.skin != s->skin)
59 if (baseline.frame != s->frame)
62 if (s->frame & 0xFF00)
65 if (baseline.effects != s->effects)
68 if (s->effects & 0xFF00)
71 if (baseline.modelindex != s->modelindex)
74 if ((s->modelindex & 0xFF00) && sv.protocol != PROTOCOL_NEHAHRABJP && sv.protocol != PROTOCOL_NEHAHRABJP2 && sv.protocol != PROTOCOL_NEHAHRABJP3)
77 if (baseline.alpha != s->alpha)
79 if (baseline.scale != s->scale)
81 if (baseline.glowsize != s->glowsize)
83 if (baseline.glowcolor != s->glowcolor)
85 if (!VectorCompare(baseline.colormod, s->colormod))
88 // if extensions are disabled, clear the relevant update flags
89 if (sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_NEHAHRAMOVIE)
91 if (sv.protocol == PROTOCOL_NEHAHRAMOVIE)
92 if (s->alpha != 255 || s->effects & EF_FULLBRIGHT)
105 ENTITYSIZEPROFILING_START(msg, states[i]->number, bits);
107 MSG_WriteByte (&buf, bits);
108 if (bits & U_MOREBITS) MSG_WriteByte(&buf, bits>>8);
109 if (sv.protocol != PROTOCOL_NEHAHRAMOVIE)
111 if (bits & U_EXTEND1) MSG_WriteByte(&buf, bits>>16);
112 if (bits & U_EXTEND2) MSG_WriteByte(&buf, bits>>24);
114 if (bits & U_LONGENTITY) MSG_WriteShort(&buf, s->number);
115 else MSG_WriteByte(&buf, s->number);
119 if (sv.protocol == PROTOCOL_NEHAHRABJP || sv.protocol == PROTOCOL_NEHAHRABJP2 || sv.protocol == PROTOCOL_NEHAHRABJP3)
120 MSG_WriteShort(&buf, s->modelindex);
122 MSG_WriteByte(&buf, s->modelindex);
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);
143 // the nasty protocol
144 if ((bits & U_EXTEND1) && sv.protocol == PROTOCOL_NEHAHRAMOVIE)
146 if (s->effects & EF_FULLBRIGHT)
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
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
159 // if the commit is full, we're done this frame
160 if (msg->cursize + buf.cursize > maxsize)
162 // next frame we will continue where we left off
165 // write the message to the packet
166 SZ_Write(msg, buf.data, buf.cursize);
168 ENTITYSIZEPROFILING_END(msg, s->number, bits);