From 14cd78c64d15dc040d555f5f92fd273f37f190bc Mon Sep 17 00:00:00 2001 From: havoc Date: Tue, 21 Sep 2004 09:34:06 +0000 Subject: [PATCH] made quakec stuffed quake1 protocol entities work alongside newer protocols, to attempt to fix the ending of Scourge of Armagon (still not working properly yet, camera is not taking the angles except in PROTOCOL_QUAKE mode) also fixed separator positioning in Com_HexDumpToConsole (used for packet dumps) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4534 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_parse.c | 18 +++++----------- common.c | 19 ++++++++++++++-- common.h | 2 ++ host_cmd.c | 15 +++---------- pr_cmds.c | 7 ++---- protocol.c | 62 +++++++++++++++++++++++++++++++++++------------------ prvm_cmds.c | 2 +- sv_main.c | 21 +++++++----------- 8 files changed, 79 insertions(+), 67 deletions(-) diff --git a/cl_parse.c b/cl_parse.c index e180f6f3..8eed400f 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -339,6 +339,7 @@ void CL_ParseServerInfo (void) return; } cl.protocol = i; + Con_DPrintf("Protocol %i\n", cl.protocol); // parse maxclients cl.maxclients = MSG_ReadByte (); @@ -574,7 +575,7 @@ void CL_ParseBaseline (entity_t *ent, int large) for (i = 0;i < 3;i++) { ent->state_baseline.origin[i] = MSG_ReadCoord(cl.protocol); - ent->state_baseline.angles[i] = MSG_ReadAngle8i(); + ent->state_baseline.angles[i] = MSG_ReadAngle(cl.protocol); } CL_ValidateState(&ent->state_baseline); ent->state_previous = ent->state_current = ent->state_baseline; @@ -1290,7 +1291,7 @@ int parsingerror = false; void CL_ParseServerMessage(void) { int cmd; - int i, entitiesupdated; + int i; qbyte cmdlog[32]; char *cmdlogname[32], *temp; int cmdindex, cmdcount = 0; @@ -1314,8 +1315,6 @@ void CL_ParseServerMessage(void) // //MSG_BeginReading (); - entitiesupdated = false; - parsingerror = true; while (1) @@ -1338,7 +1337,6 @@ void CL_ParseServerMessage(void) // if the high bit of the command byte is set, it is a fast update if (cmd & 128) { - entitiesupdated = true; // LordHavoc: fix for bizarre problem in MSVC that I do not understand (if I assign the string pointer directly it ends up storing a NULL pointer) temp = "entity"; cmdlogname[cmdindex] = temp; @@ -1444,12 +1442,7 @@ void CL_ParseServerMessage(void) case svc_setangle: for (i=0 ; i<3 ; i++) - { - if (cl.protocol == PROTOCOL_DARKPLACES5) - cl.viewangles[i] = MSG_ReadAngle16i (); - else - cl.viewangles[i] = MSG_ReadAngle8i (); - } + cl.viewangles[i] = MSG_ReadAngle (cl.protocol); break; case svc_setview: @@ -1668,8 +1661,7 @@ void CL_ParseServerMessage(void) } } - if (entitiesupdated) - EntityFrameQuake_ISeeDeadEntities(); + EntityFrameQuake_ISeeDeadEntities(); parsingerror = false; } diff --git a/common.c b/common.c index 6ec9282a..5c72b72f 100644 --- a/common.c +++ b/common.c @@ -252,6 +252,13 @@ void MSG_WriteAngle32f (sizebuf_t *sb, float f) MSG_WriteFloat (sb, f); } +void MSG_WriteAngle (sizebuf_t *sb, float f, int protocol) +{ + if (protocol == PROTOCOL_DARKPLACES5) + MSG_WriteAngle16i (sb, f); + else + MSG_WriteAngle8i (sb, f); +} // // reading functions @@ -403,7 +410,7 @@ float MSG_ReadAngle8i (void) float MSG_ReadAngle16i (void) { - return MSG_ReadShort () * (360.0/65536.0); + return (unsigned short)MSG_ReadShort () * (360.0/65536.0); } float MSG_ReadAngle32f (void) @@ -411,6 +418,14 @@ float MSG_ReadAngle32f (void) return MSG_ReadFloat (); } +float MSG_ReadAngle (int protocol) +{ + if (protocol == PROTOCOL_DARKPLACES5) + return MSG_ReadAngle16i (); + else + return MSG_ReadAngle8i (); +} + //=========================================================================== @@ -504,7 +519,7 @@ void Com_HexDumpToConsole(const qbyte *data, int size) *cur++ = ' '; *cur++ = ' '; } - if ((j & 3) == 0) + if ((j & 3) == 3) *cur++ = ' '; } // print text diff --git a/common.h b/common.h index b6272a80..f367ef66 100644 --- a/common.h +++ b/common.h @@ -123,6 +123,7 @@ void MSG_WriteCoord16i (sizebuf_t *sb, float f); void MSG_WriteCoord32f (sizebuf_t *sb, float f); void MSG_WriteCoord (sizebuf_t *sb, float f, int protocol); void MSG_WriteVector (sizebuf_t *sb, float *v, int protocol); +void MSG_WriteAngle (sizebuf_t *sb, float f, int protocol); extern int msg_readcount; extern qboolean msg_badread; // set if a read goes beyond end of message @@ -151,6 +152,7 @@ float MSG_ReadCoord16i (void); float MSG_ReadCoord32f (void); float MSG_ReadCoord (int protocol); void MSG_ReadVector (float *v, int protocol); +float MSG_ReadAngle (int protocol); //============================================================================ diff --git a/host_cmd.c b/host_cmd.c index bdae5cf8..0bb621fd 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -1216,18 +1216,9 @@ void Host_Spawn_f (void) // and it won't happen if the game was just loaded, so you wind up // with a permanent head tilt MSG_WriteByte (&host_client->message, svc_setangle); - if (sv.protocol == PROTOCOL_DARKPLACES5) - { - MSG_WriteAngle16i (&host_client->message, sv_player->v->angles[0]); - MSG_WriteAngle16i (&host_client->message, sv_player->v->angles[1]); - MSG_WriteAngle16i (&host_client->message, 0); - } - else - { - MSG_WriteAngle8i (&host_client->message, sv_player->v->angles[0]); - MSG_WriteAngle8i (&host_client->message, sv_player->v->angles[1]); - MSG_WriteAngle8i (&host_client->message, 0); - } + MSG_WriteAngle (&host_client->message, sv_player->v->angles[0], sv.protocol); + MSG_WriteAngle (&host_client->message, sv_player->v->angles[1], sv.protocol); + MSG_WriteAngle (&host_client->message, 0, sv.protocol); SV_WriteClientdataToMessage (sv_player, &host_client->message); diff --git a/pr_cmds.c b/pr_cmds.c index 930a88d5..8bdb8f0f 100644 --- a/pr_cmds.c +++ b/pr_cmds.c @@ -1874,10 +1874,7 @@ void PF_WriteLong (void) void PF_WriteAngle (void) { - if (sv.protocol == PROTOCOL_DARKPLACES5) - MSG_WriteAngle16i (WriteDest(), G_FLOAT(OFS_PARM1)); - else - MSG_WriteAngle8i (WriteDest(), G_FLOAT(OFS_PARM1)); + MSG_WriteAngle (WriteDest(), G_FLOAT(OFS_PARM1), sv.protocol); } void PF_WriteCoord (void) @@ -1931,7 +1928,7 @@ void PF_makestatic (void) for (i=0 ; i<3 ; i++) { MSG_WriteCoord(&sv.signon, ent->v->origin[i], sv.protocol); - MSG_WriteAngle8i(&sv.signon, ent->v->angles[i]); + MSG_WriteAngle(&sv.signon, ent->v->angles[i], sv.protocol); } // throw the entity away now diff --git a/protocol.c b/protocol.c index 0fe0cc0e..f897d219 100644 --- a/protocol.c +++ b/protocol.c @@ -35,7 +35,9 @@ entity_state_t defaultstate = {0,0,0,0}//unsigned char unused[4]; // ! }; -double entityframequake_mtime = 0; +// keep track of quake entities because they need to be killed if they get stale +int cl_lastquakeentity = 0; +qbyte cl_isquakeentity[MAX_EDICTS]; void EntityFrameQuake_ReadEntity(int bits) { @@ -43,8 +45,6 @@ void EntityFrameQuake_ReadEntity(int bits) entity_t *ent; entity_state_t s; - entityframequake_mtime = cl.mtime[0]; - if (bits & U_MOREBITS) bits |= (MSG_ReadByte()<<8); if ((bits & U_EXTEND1) && cl.protocol != PROTOCOL_NEHAHRAMOVIE) @@ -77,6 +77,9 @@ void EntityFrameQuake_ReadEntity(int bits) s.active = true; } + cl_isquakeentity[num] = true; + if (cl_lastquakeentity < num) + cl_lastquakeentity = num; s.number = num; s.time = cl.mtime[0]; s.flags = 0; @@ -85,12 +88,12 @@ void EntityFrameQuake_ReadEntity(int bits) if (bits & U_COLORMAP) s.colormap = MSG_ReadByte(); if (bits & U_SKIN) s.skin = MSG_ReadByte(); if (bits & U_EFFECTS) s.effects = (s.effects & 0xFF00) | MSG_ReadByte(); - if (bits & U_ORIGIN1) s.origin[0] = MSG_ReadCoord13i(); - if (bits & U_ANGLE1) s.angles[0] = MSG_ReadAngle8i(); - if (bits & U_ORIGIN2) s.origin[1] = MSG_ReadCoord13i(); - if (bits & U_ANGLE2) s.angles[1] = MSG_ReadAngle8i(); - if (bits & U_ORIGIN3) s.origin[2] = MSG_ReadCoord13i(); - if (bits & U_ANGLE3) s.angles[2] = MSG_ReadAngle8i(); + if (bits & U_ORIGIN1) s.origin[0] = MSG_ReadCoord(cl.protocol); + if (bits & U_ANGLE1) s.angles[0] = MSG_ReadAngle(cl.protocol); + if (bits & U_ORIGIN2) s.origin[1] = MSG_ReadCoord(cl.protocol); + if (bits & U_ANGLE2) s.angles[1] = MSG_ReadAngle(cl.protocol); + if (bits & U_ORIGIN3) s.origin[2] = MSG_ReadCoord(cl.protocol); + if (bits & U_ANGLE3) s.angles[2] = MSG_ReadAngle(cl.protocol); if (bits & U_STEP) s.flags |= RENDER_STEP; if (bits & U_ALPHA) s.alpha = MSG_ReadByte(); if (bits & U_SCALE) s.scale = MSG_ReadByte(); @@ -138,14 +141,31 @@ void EntityFrameQuake_ReadEntity(int bits) void EntityFrameQuake_ISeeDeadEntities(void) { - int i; - for (i = 0;i < cl_max_entities;i++) + int num, lastentity; + if (cl_lastquakeentity == 0) + return; + lastentity = cl_lastquakeentity; + cl_lastquakeentity = 0; + for (num = 0;num < lastentity;num++) { - if (cl_entities_active[i] && cl_entities[i].state_current.time != cl.mtime[0]) + if (cl_isquakeentity[num]) { - cl_entities_active[i] = false; - cl_entities[i].state_current = defaultstate; - cl_entities[i].state_current.number = i; + cl_isquakeentity[num] = false; + if (cl_entities_active[num]) + { + if (cl_entities[num].state_current.time == cl.mtime[0]) + { + cl_isquakeentity[num] = true; + cl_lastquakeentity = num; + } + else + { + cl_isquakeentity[num] = false; + cl_entities_active[num] = false; + cl_entities[num].state_current = defaultstate; + cl_entities[num].state_current.number = num; + } + } } } } @@ -251,12 +271,12 @@ void EntityFrameQuake_WriteFrame(sizebuf_t *msg, int numstates, const entity_sta if (bits & U_COLORMAP) MSG_WriteByte(&buf, s->colormap); if (bits & U_SKIN) MSG_WriteByte(&buf, s->skin); if (bits & U_EFFECTS) MSG_WriteByte(&buf, s->effects); - if (bits & U_ORIGIN1) MSG_WriteCoord13i(&buf, s->origin[0]); - if (bits & U_ANGLE1) MSG_WriteAngle8i(&buf, s->angles[0]); - if (bits & U_ORIGIN2) MSG_WriteCoord13i(&buf, s->origin[1]); - if (bits & U_ANGLE2) MSG_WriteAngle8i(&buf, s->angles[1]); - if (bits & U_ORIGIN3) MSG_WriteCoord13i(&buf, s->origin[2]); - if (bits & U_ANGLE3) MSG_WriteAngle8i(&buf, s->angles[2]); + if (bits & U_ORIGIN1) MSG_WriteCoord(&buf, s->origin[0], sv.protocol); + if (bits & U_ANGLE1) MSG_WriteAngle(&buf, s->angles[0], sv.protocol); + if (bits & U_ORIGIN2) MSG_WriteCoord(&buf, s->origin[1], sv.protocol); + if (bits & U_ANGLE2) MSG_WriteAngle(&buf, s->angles[1], sv.protocol); + if (bits & U_ORIGIN3) MSG_WriteCoord(&buf, s->origin[2], sv.protocol); + if (bits & U_ANGLE3) MSG_WriteAngle(&buf, s->angles[2], sv.protocol); if (bits & U_ALPHA) MSG_WriteByte(&buf, s->alpha); if (bits & U_SCALE) MSG_WriteByte(&buf, s->scale); if (bits & U_EFFECTS2) MSG_WriteByte(&buf, s->effects >> 8); diff --git a/prvm_cmds.c b/prvm_cmds.c index 79fee2a8..0a6acf87 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -1356,7 +1356,7 @@ void VM_WriteLong (void) void VM_WriteAngle (void) { - MSG_WriteAngle16i (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0)); + MSG_WriteAngle (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol); } void VM_WriteCoord (void) diff --git a/sv_main.c b/sv_main.c index 7aa15301..591884d8 100644 --- a/sv_main.c +++ b/sv_main.c @@ -730,12 +730,12 @@ void SV_WriteEntitiesToClient_QUAKE (client_t *client, edict_t *clent, sizebuf_t if (bits & U_COLORMAP) MSG_WriteByte(msg, ent->v->colormap); if (bits & U_SKIN) MSG_WriteByte(msg, ent->v->skin); if (bits & U_EFFECTS) MSG_WriteByte(msg, ent->v->effects); - if (bits & U_ORIGIN1) MSG_WriteCoord13i(msg, origin[0]); - if (bits & U_ANGLE1) MSG_WriteAngle8i(msg, angles[0]); - if (bits & U_ORIGIN2) MSG_WriteCoord13i(msg, origin[1]); - if (bits & U_ANGLE2) MSG_WriteAngle8i(msg, angles[1]); - if (bits & U_ORIGIN3) MSG_WriteCoord13i(msg, origin[2]); - if (bits & U_ANGLE3) MSG_WriteAngle8i(msg, angles[2]); + if (bits & U_ORIGIN1) MSG_WriteCoord(msg, origin[0], sv.protocol); + if (bits & U_ANGLE1) MSG_WriteAngle(msg, angles[0], sv.protocol); + if (bits & U_ORIGIN2) MSG_WriteCoord(msg, origin[1], sv.protocol); + if (bits & U_ANGLE2) MSG_WriteAngle(msg, angles[1], sv.protocol); + if (bits & U_ORIGIN3) MSG_WriteCoord(msg, origin[2], sv.protocol); + if (bits & U_ANGLE3) MSG_WriteAngle(msg, angles[2], sv.protocol); // LordHavoc: new stuff if (bits & U_ALPHA) MSG_WriteByte(msg, alpha); @@ -1320,12 +1320,7 @@ void SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg) { MSG_WriteByte (msg, svc_setangle); for (i=0 ; i < 3 ; i++) - { - if (sv.protocol == PROTOCOL_DARKPLACES5) - MSG_WriteAngle16i (msg, ent->v->angles[i] ); - else - MSG_WriteAngle8i (msg, ent->v->angles[i] ); - } + MSG_WriteAngle (msg, ent->v->angles[i], sv.protocol); ent->v->fixangle = 0; } @@ -1880,7 +1875,7 @@ void SV_CreateBaseline (void) for (i=0 ; i<3 ; i++) { MSG_WriteCoord(&sv.signon, svent->e->baseline.origin[i], sv.protocol); - MSG_WriteAngle8i(&sv.signon, svent->e->baseline.angles[i]); + MSG_WriteAngle(&sv.signon, svent->e->baseline.angles[i], sv.protocol); } } } -- 2.39.2