-void ClearStateToDefault(entity_state_t *s)
-{
- *s = defaultstate;
- /*
- memset(s, 0, sizeof(*s));
- s->alpha = 255;
- s->scale = 16;
- s->glowcolor = 254;
- */
-}
-
-void EntityState_Write(entity_state_t *ent, sizebuf_t *msg, entity_state_t *delta)
-{
- int bits;
- vec3_t org, deltaorg;
- if (ent->active)
- {
- // if not active last frame, delta from defaults
- if (!delta->active)
- delta = &defaultstate;
- bits = 0;
- VectorCopy(ent->origin, org);
- VectorCopy(delta->origin, deltaorg);
- if (ent->flags & RENDER_LOWPRECISION)
- {
- if (org[0] > 0)
- org[0] = (int) (org[0] + 0.5f);
- else
- org[0] = (int) (org[0] - 0.5f);
- if (org[1] > 0)
- org[1] = (int) (org[1] + 0.5f);
- else
- org[1] = (int) (org[1] - 0.5f);
- if (org[2] > 0)
- org[2] = (int) (org[2] + 0.5f);
- else
- org[2] = (int) (org[2] - 0.5f);
- }
- if (delta->flags & RENDER_LOWPRECISION)
- {
- if (deltaorg[0] > 0)
- deltaorg[0] = (int) (deltaorg[0] + 0.5f);
- else
- deltaorg[0] = (int) (deltaorg[0] - 0.5f);
- if (deltaorg[1] > 0)
- deltaorg[1] = (int) (deltaorg[1] + 0.5f);
- else
- deltaorg[1] = (int) (deltaorg[1] - 0.5f);
- if (deltaorg[2] > 0)
- deltaorg[2] = (int) (deltaorg[2] + 0.5f);
- else
- deltaorg[2] = (int) (deltaorg[2] - 0.5f);
- }
- if (fabs(org[0] - deltaorg[0]) > 0.01f)
- bits |= E_ORIGIN1;
- if (fabs(org[1] - deltaorg[1]) > 0.01f)
- bits |= E_ORIGIN2;
- if (fabs(org[2] - deltaorg[2]) > 0.01f)
- bits |= E_ORIGIN3;
- if ((qbyte) (ent->angles[0] * (256.0f / 360.0f)) != (qbyte) (delta->angles[0] * (256.0f / 360.0f)))
- bits |= E_ANGLE1;
- if ((qbyte) (ent->angles[1] * (256.0f / 360.0f)) != (qbyte) (delta->angles[1] * (256.0f / 360.0f)))
- bits |= E_ANGLE2;
- if ((qbyte) (ent->angles[2] * (256.0f / 360.0f)) != (qbyte) (delta->angles[2] * (256.0f / 360.0f)))
- bits |= E_ANGLE3;
- if ((ent->modelindex ^ delta->modelindex) & 0x00FF)
- bits |= E_MODEL1;
- if ((ent->modelindex ^ delta->modelindex) & 0xFF00)
- bits |= E_MODEL2;
- if ((ent->frame ^ delta->frame) & 0x00FF)
- bits |= E_FRAME1;
- if ((ent->frame ^ delta->frame) & 0xFF00)
- bits |= E_FRAME2;
- if ((ent->effects ^ delta->effects) & 0x00FF)
- bits |= E_EFFECTS1;
- if ((ent->effects ^ delta->effects) & 0xFF00)
- bits |= E_EFFECTS2;
- if (ent->colormap != delta->colormap)
- bits |= E_COLORMAP;
- if (ent->skin != delta->skin)
- bits |= E_SKIN;
- if (ent->alpha != delta->alpha)
- bits |= E_ALPHA;
- if (ent->scale != delta->scale)
- bits |= E_SCALE;
- if (ent->glowsize != delta->glowsize)
- bits |= E_GLOWSIZE;
- if (ent->glowcolor != delta->glowcolor)
- bits |= E_GLOWCOLOR;
- if (ent->flags != delta->flags)
- bits |= E_FLAGS;
- if (ent->tagindex != delta->tagindex || ent->tagentity != delta->tagentity)
- bits |= E_TAGATTACHMENT;
- if (ent->light[0] != delta->light[0] || ent->light[1] != delta->light[1] || ent->light[2] != delta->light[2] || ent->light[3] != delta->light[3])
- bits |= E_LIGHT;
- if (ent->lightstyle != delta->lightstyle)
- bits |= E_LIGHTSTYLE;
- if (ent->lightpflags != delta->lightpflags)
- bits |= E_LIGHTPFLAGS;
-
- if (bits) // don't send anything if it hasn't changed
- {
- if (bits & 0xFF000000)
- bits |= E_EXTEND3;
- if (bits & 0x00FF0000)
- bits |= E_EXTEND2;
- if (bits & 0x0000FF00)
- bits |= E_EXTEND1;
-
- MSG_WriteShort(msg, ent->number);
- MSG_WriteByte(msg, bits & 0xFF);
- if (bits & E_EXTEND1)
- {
- MSG_WriteByte(msg, (bits >> 8) & 0xFF);
- if (bits & E_EXTEND2)
- {
- MSG_WriteByte(msg, (bits >> 16) & 0xFF);
- if (bits & E_EXTEND3)
- MSG_WriteByte(msg, (bits >> 24) & 0xFF);
- }
- }
- // LordHavoc: have to write flags first, as they can modify protocol
- if (bits & E_FLAGS)
- MSG_WriteByte(msg, ent->flags);
- if (ent->flags & RENDER_LOWPRECISION)
- {
- if (bits & E_ORIGIN1)
- MSG_WriteShort(msg, org[0]);
- if (bits & E_ORIGIN2)
- MSG_WriteShort(msg, org[1]);
- if (bits & E_ORIGIN3)
- MSG_WriteShort(msg, org[2]);
- if (bits & E_ANGLE1)
- MSG_WriteAngle(msg, ent->angles[0]);
- if (bits & E_ANGLE2)
- MSG_WriteAngle(msg, ent->angles[1]);
- if (bits & E_ANGLE3)
- MSG_WriteAngle(msg, ent->angles[2]);
- }
- else
- {
- if (bits & E_ORIGIN1)
- MSG_WriteFloat(msg, org[0]);
- if (bits & E_ORIGIN2)
- MSG_WriteFloat(msg, org[1]);
- if (bits & E_ORIGIN3)
- MSG_WriteFloat(msg, org[2]);
- if (bits & E_ANGLE1)
- MSG_WritePreciseAngle(msg, ent->angles[0]);
- if (bits & E_ANGLE2)
- MSG_WritePreciseAngle(msg, ent->angles[1]);
- if (bits & E_ANGLE3)
- MSG_WritePreciseAngle(msg, ent->angles[2]);
- }
- if (bits & E_MODEL1)
- MSG_WriteByte(msg, ent->modelindex & 0xFF);
- if (bits & E_MODEL2)
- MSG_WriteByte(msg, (ent->modelindex >> 8) & 0xFF);
- if (bits & E_FRAME1)
- MSG_WriteByte(msg, ent->frame & 0xFF);
- if (bits & E_FRAME2)
- MSG_WriteByte(msg, (ent->frame >> 8) & 0xFF);
- if (bits & E_EFFECTS1)
- MSG_WriteByte(msg, ent->effects & 0xFF);
- if (bits & E_EFFECTS2)
- MSG_WriteByte(msg, (ent->effects >> 8) & 0xFF);
- if (bits & E_COLORMAP)
- MSG_WriteByte(msg, ent->colormap);
- if (bits & E_SKIN)
- MSG_WriteByte(msg, ent->skin);
- if (bits & E_ALPHA)
- MSG_WriteByte(msg, ent->alpha);
- if (bits & E_SCALE)
- MSG_WriteByte(msg, ent->scale);
- if (bits & E_GLOWSIZE)
- MSG_WriteByte(msg, ent->glowsize);
- if (bits & E_GLOWCOLOR)
- MSG_WriteByte(msg, ent->glowcolor);
- if (bits & E_TAGATTACHMENT)
- {
- MSG_WriteShort(msg, ent->tagentity);
- MSG_WriteByte(msg, ent->tagindex);
- }
- if (bits & E_LIGHT)
- {
- MSG_WriteShort(msg, ent->light[0]);
- MSG_WriteShort(msg, ent->light[1]);
- MSG_WriteShort(msg, ent->light[2]);
- MSG_WriteShort(msg, ent->light[3]);
- }
- if (bits & E_LIGHTSTYLE)
- MSG_WriteByte(msg, ent->lightstyle);
- if (bits & E_LIGHTPFLAGS)
- MSG_WriteByte(msg, ent->lightpflags);
- }
- }
- else if (delta->active)
- MSG_WriteShort(msg, ent->number | 0x8000);
-}
-
-void EntityState_ReadUpdate(entity_state_t *e, int number)
-{
- int bits;
- cl_entities_active[number] = true;
- e->active = true;
- e->time = cl.mtime[0];
- e->number = number;
-
- bits = MSG_ReadByte();
- if (bits & E_EXTEND1)
- {
- bits |= MSG_ReadByte() << 8;
- if (bits & E_EXTEND2)
- {
- bits |= MSG_ReadByte() << 16;
- if (bits & E_EXTEND3)
- bits |= MSG_ReadByte() << 24;
- }
- }
-
- if (cl.protocol == PROTOCOL_DARKPLACES2)
- {
- if (bits & E_ORIGIN1)
- e->origin[0] = (signed short) MSG_ReadShort();
- if (bits & E_ORIGIN2)
- e->origin[1] = (signed short) MSG_ReadShort();
- if (bits & E_ORIGIN3)
- e->origin[2] = (signed short) MSG_ReadShort();
- }
- else
- {
- if (bits & E_FLAGS)
- e->flags = MSG_ReadByte();
- if (e->flags & RENDER_LOWPRECISION || cl.protocol == PROTOCOL_DARKPLACES2)
- {
- if (bits & E_ORIGIN1)
- e->origin[0] = (signed short) MSG_ReadShort();
- if (bits & E_ORIGIN2)
- e->origin[1] = (signed short) MSG_ReadShort();
- if (bits & E_ORIGIN3)
- e->origin[2] = (signed short) MSG_ReadShort();
- }
- else
- {
- if (bits & E_ORIGIN1)
- e->origin[0] = MSG_ReadFloat();
- if (bits & E_ORIGIN2)
- e->origin[1] = MSG_ReadFloat();
- if (bits & E_ORIGIN3)
- e->origin[2] = MSG_ReadFloat();
- }
- }
- if (cl.protocol == PROTOCOL_DARKPLACES5 && !(e->flags & RENDER_LOWPRECISION))
- {
- if (bits & E_ANGLE1)
- e->angles[0] = MSG_ReadPreciseAngle();
- if (bits & E_ANGLE2)
- e->angles[1] = MSG_ReadPreciseAngle();
- if (bits & E_ANGLE3)
- e->angles[2] = MSG_ReadPreciseAngle();
- }
- else
- {
- if (bits & E_ANGLE1)
- e->angles[0] = MSG_ReadAngle();
- if (bits & E_ANGLE2)
- e->angles[1] = MSG_ReadAngle();
- if (bits & E_ANGLE3)
- e->angles[2] = MSG_ReadAngle();
- }
- if (bits & E_MODEL1)
- e->modelindex = (e->modelindex & 0xFF00) | (unsigned int) MSG_ReadByte();
- if (bits & E_MODEL2)
- e->modelindex = (e->modelindex & 0x00FF) | ((unsigned int) MSG_ReadByte() << 8);
- if (bits & E_FRAME1)
- e->frame = (e->frame & 0xFF00) | (unsigned int) MSG_ReadByte();
- if (bits & E_FRAME2)
- e->frame = (e->frame & 0x00FF) | ((unsigned int) MSG_ReadByte() << 8);
- if (bits & E_EFFECTS1)
- e->effects = (e->effects & 0xFF00) | (unsigned int) MSG_ReadByte();
- if (bits & E_EFFECTS2)
- e->effects = (e->effects & 0x00FF) | ((unsigned int) MSG_ReadByte() << 8);
- if (bits & E_COLORMAP)
- e->colormap = MSG_ReadByte();
- if (bits & E_SKIN)
- e->skin = MSG_ReadByte();
- if (bits & E_ALPHA)
- e->alpha = MSG_ReadByte();
- if (bits & E_SCALE)
- e->scale = MSG_ReadByte();
- if (bits & E_GLOWSIZE)
- e->glowsize = MSG_ReadByte();
- if (bits & E_GLOWCOLOR)
- e->glowcolor = MSG_ReadByte();
- if (cl.protocol == PROTOCOL_DARKPLACES2)
- if (bits & E_FLAGS)
- e->flags = MSG_ReadByte();
- if (bits & E_TAGATTACHMENT)
- {
- e->tagentity = MSG_ReadShort();
- e->tagindex = MSG_ReadByte();
- }
- if (bits & E_LIGHT)
- {
- e->light[0] = MSG_ReadShort();
- e->light[1] = MSG_ReadShort();
- e->light[2] = MSG_ReadShort();
- e->light[3] = MSG_ReadShort();
- }
- if (bits & E_LIGHTSTYLE)
- e->lightstyle = MSG_ReadByte();
- if (bits & E_LIGHTPFLAGS)
- e->lightpflags = MSG_ReadByte();
-
- if (developer_networkentities.integer >= 2)
- {
- Con_Printf("ReadUpdate e%i", number);
-
- if (bits & E_ORIGIN1)
- Con_Printf(" E_ORIGIN1 %f", e->origin[0]);
- if (bits & E_ORIGIN2)
- Con_Printf(" E_ORIGIN2 %f", e->origin[1]);
- if (bits & E_ORIGIN3)
- Con_Printf(" E_ORIGIN3 %f", e->origin[2]);
- if (bits & E_ANGLE1)
- Con_Printf(" E_ANGLE1 %f", e->angles[0]);
- if (bits & E_ANGLE2)
- Con_Printf(" E_ANGLE2 %f", e->angles[1]);
- if (bits & E_ANGLE3)
- Con_Printf(" E_ANGLE3 %f", e->angles[2]);
- if (bits & (E_MODEL1 | E_MODEL2))
- Con_Printf(" E_MODEL %i", e->modelindex);
-
- if (bits & (E_FRAME1 | E_FRAME2))
- Con_Printf(" E_FRAME %i", e->frame);
- if (bits & (E_EFFECTS1 | E_EFFECTS2))
- Con_Printf(" E_EFFECTS %i", e->effects);
- if (bits & E_ALPHA)
- Con_Printf(" E_ALPHA %f", e->alpha / 255.0f);
- if (bits & E_SCALE)
- Con_Printf(" E_SCALE %f", e->scale / 16.0f);
- if (bits & E_COLORMAP)
- Con_Printf(" E_COLORMAP %i", e->colormap);
- if (bits & E_SKIN)
- Con_Printf(" E_SKIN %i", e->skin);
-
- if (bits & E_GLOWSIZE)
- Con_Printf(" E_GLOWSIZE %i", e->glowsize * 4);
- if (bits & E_GLOWCOLOR)
- Con_Printf(" E_GLOWCOLOR %i", e->glowcolor);
-
- if (bits & E_LIGHT)
- Con_Printf(" E_LIGHT %i:%i:%i:%i", e->light[0], e->light[1], e->light[2], e->light[3]);
- if (bits & E_LIGHTPFLAGS)
- Con_Printf(" E_LIGHTPFLAGS %i", e->lightpflags);
-
- if (bits & E_TAGATTACHMENT)
- Con_Printf(" E_TAGATTACHMENT e%i:%i", e->tagentity, e->tagindex);
- if (bits & E_LIGHTSTYLE)
- Con_Printf(" E_LIGHTSTYLE %i", e->lightstyle);
- Con_Printf("\n");
- }
-}
-
-// (server) clears the database to contain no frames (thus delta compression compresses against nothing)
-void EntityFrame_ClearDatabase(entity_database_t *d)
-{
- memset(d, 0, sizeof(*d));
-}