X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=protocol.c;h=0c2d844ead120c179ab1025026d8a5c7c70254ef;hb=24a125e70e38a140f8060938722bd47612aa2e9b;hp=a5e16ab285fd34c9b57e4f9f889a03716ce6d948;hpb=c4ee1bbcc6b2f917465f07269ad09942bbf40849;p=xonotic%2Fdarkplaces.git diff --git a/protocol.c b/protocol.c index a5e16ab2..0c2d844e 100644 --- a/protocol.c +++ b/protocol.c @@ -44,8 +44,18 @@ void EntityFrame_AckFrame(entity_database_t *d, int frame) // (server) clears frame, to prepare for adding entities void EntityFrame_Clear(entity_frame_t *f, vec3_t eye) { - memset(f, 0, sizeof(*f)); - VectorCopy(eye, f->eye); + //memset(f, 0, sizeof(*f)); + f->time = 0; + f->framenum = 0; + f->numentities = 0; + if (eye == NULL) + { + VectorClear(f->eye); + } + else + { + VectorCopy(eye, f->eye); + } } // (server) allocates an entity slot in frame, returns NULL if full @@ -64,7 +74,7 @@ entity_state_t *EntityFrame_NewEntity(entity_frame_t *f, int number) void EntityFrame_FetchFrame(entity_database_t *d, int framenum, entity_frame_t *f) { int i, n; - memset(f, 0, sizeof(*f)); + EntityFrame_Clear(f, NULL); for (i = 0;i < d->numframes && d->frames[i].framenum < framenum;i++); if (i < d->numframes && framenum == d->frames[i].framenum) { @@ -175,12 +185,24 @@ void EntityFrame_Write(entity_database_t *d, entity_frame_t *f, sizebuf_t *msg) delta = &baseline; } bits = 0; - if ((int) ent->origin[0] != (int) delta->origin[0]) - bits |= E_ORIGIN1; - if ((int) ent->origin[1] != (int) delta->origin[1]) - bits |= E_ORIGIN2; - if ((int) ent->origin[2] != (int) delta->origin[2]) - bits |= E_ORIGIN3; + if (ent->flags & RENDER_LOWPRECISION) + { + if ((int) ent->origin[0] != (int) delta->origin[0]) + bits |= E_ORIGIN1; + if ((int) ent->origin[1] != (int) delta->origin[1]) + bits |= E_ORIGIN2; + if ((int) ent->origin[2] != (int) delta->origin[2]) + bits |= E_ORIGIN3; + } + else + { + if (fabs(ent->origin[0] - delta->origin[0]) > 0.01f) + bits |= E_ORIGIN1; + if (fabs(ent->origin[1] - delta->origin[1]) > 0.01f) + bits |= E_ORIGIN2; + if (fabs(ent->origin[2] - delta->origin[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))) @@ -235,12 +257,27 @@ void EntityFrame_Write(entity_database_t *d, entity_frame_t *f, sizebuf_t *msg) MSG_WriteByte(msg, (bits >> 24) & 0xFF); } } - if (bits & E_ORIGIN1) - MSG_WriteShort(msg, ent->origin[0]); - if (bits & E_ORIGIN2) - MSG_WriteShort(msg, ent->origin[1]); - if (bits & E_ORIGIN3) - MSG_WriteShort(msg, ent->origin[2]); + // 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, ent->origin[0]); + if (bits & E_ORIGIN2) + MSG_WriteShort(msg, ent->origin[1]); + if (bits & E_ORIGIN3) + MSG_WriteShort(msg, ent->origin[2]); + } + else + { + if (bits & E_ORIGIN1) + MSG_WriteFloat(msg, ent->origin[0]); + if (bits & E_ORIGIN2) + MSG_WriteFloat(msg, ent->origin[1]); + if (bits & E_ORIGIN3) + MSG_WriteFloat(msg, ent->origin[2]); + } if (bits & E_ANGLE1) MSG_WriteAngle(msg, ent->angles[0]); if (bits & E_ANGLE2) @@ -248,17 +285,17 @@ void EntityFrame_Write(entity_database_t *d, entity_frame_t *f, sizebuf_t *msg) if (bits & E_ANGLE3) MSG_WriteAngle(msg, ent->angles[2]); if (bits & E_MODEL1) - MSG_WriteByte(msg, ent->modelindex & 0x00FF); + MSG_WriteByte(msg, ent->modelindex & 0xFF); if (bits & E_MODEL2) - MSG_WriteByte(msg, ent->modelindex & 0xFF00); + MSG_WriteByte(msg, (ent->modelindex >> 8) & 0xFF); if (bits & E_FRAME1) - MSG_WriteByte(msg, ent->frame & 0x00FF); + MSG_WriteByte(msg, ent->frame & 0xFF); if (bits & E_FRAME2) - MSG_WriteByte(msg, ent->frame & 0xFF00); + MSG_WriteByte(msg, (ent->frame >> 8) & 0xFF); if (bits & E_EFFECTS1) - MSG_WriteByte(msg, ent->effects & 0x00FF); + MSG_WriteByte(msg, ent->effects & 0xFF); if (bits & E_EFFECTS2) - MSG_WriteByte(msg, ent->effects & 0xFF00); + MSG_WriteByte(msg, (ent->effects >> 8) & 0xFF); if (bits & E_COLORMAP) MSG_WriteByte(msg, ent->colormap); if (bits & E_SKIN) @@ -271,8 +308,6 @@ void EntityFrame_Write(entity_database_t *d, entity_frame_t *f, sizebuf_t *msg) MSG_WriteByte(msg, ent->glowsize); if (bits & E_GLOWCOLOR) MSG_WriteByte(msg, ent->glowcolor); - if (bits & E_FLAGS) - MSG_WriteByte(msg, ent->flags); } } for (;onum < o->numentities;onum++) @@ -291,7 +326,9 @@ void EntityFrame_Read(entity_database_t *d) entity_state_t *e, baseline, *old, *oldend; ClearStateToDefault(&baseline); - memset(f, 0, sizeof(*f)); + + EntityFrame_Clear(f, NULL); + // read the frame header info f->time = cl.mtime[0]; number = MSG_ReadLong(); @@ -365,12 +402,38 @@ void EntityFrame_Read(entity_database_t *d) } } - 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(); + if (dpprotocol == DPPROTOCOL_VERSION2) + { + 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 || dpprotocol == DPPROTOCOL_VERSION2) + { + 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 (bits & E_ANGLE1) e->angles[0] = MSG_ReadAngle(); if (bits & E_ANGLE2) @@ -378,17 +441,17 @@ void EntityFrame_Read(entity_database_t *d) if (bits & E_ANGLE3) e->angles[2] = MSG_ReadAngle(); if (bits & E_MODEL1) - e->modelindex = (e->modelindex & 0xFF00) | MSG_ReadByte(); + e->modelindex = (e->modelindex & 0xFF00) | (unsigned int) MSG_ReadByte(); if (bits & E_MODEL2) - e->modelindex = (e->modelindex & 0x00FF) | (MSG_ReadByte() << 8); + e->modelindex = (e->modelindex & 0x00FF) | ((unsigned int) MSG_ReadByte() << 8); if (bits & E_FRAME1) - e->frame = (e->frame & 0xFF00) | MSG_ReadByte(); + e->frame = (e->frame & 0xFF00) | (unsigned int) MSG_ReadByte(); if (bits & E_FRAME2) - e->frame = (e->frame & 0x00FF) | (MSG_ReadByte() << 8); + e->frame = (e->frame & 0x00FF) | ((unsigned int) MSG_ReadByte() << 8); if (bits & E_EFFECTS1) - e->effects = (e->effects & 0xFF00) | MSG_ReadByte(); + e->effects = (e->effects & 0xFF00) | (unsigned int) MSG_ReadByte(); if (bits & E_EFFECTS2) - e->effects = (e->effects & 0x00FF) | (MSG_ReadByte() << 8); + e->effects = (e->effects & 0x00FF) | ((unsigned int) MSG_ReadByte() << 8); if (bits & E_COLORMAP) e->colormap = MSG_ReadByte(); if (bits & E_SKIN) @@ -401,8 +464,9 @@ void EntityFrame_Read(entity_database_t *d) e->glowsize = MSG_ReadByte(); if (bits & E_GLOWCOLOR) e->glowcolor = MSG_ReadByte(); - if (bits & E_FLAGS) - e->flags = MSG_ReadByte(); + if (dpprotocol == DPPROTOCOL_VERSION2) + if (bits & E_FLAGS) + e->flags = MSG_ReadByte(); } } while (old < oldend)