ref: caa94b6b82aecb7a20e4e6de2cc2f2f9332436f9
parent: e1f34fe50840b05c37b58a6bdb1a9233219e4b5a
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Oct 12 12:06:54 EDT 2023
put MSG_ReadCoord and MSG_ReadAngle into protocol_t
--- a/cl_input.c
+++ b/cl_input.c
@@ -330,7 +330,7 @@
MSG_WriteFloat (&buf, cl.mtime[0]); // so server can get ping times
for (i=0 ; i<3 ; i++)
- MSG_WriteAngle (&buf, cl.viewangles[i]);
+ sv.protocol->MSG_WriteAngle (&buf, cl.viewangles[i]);
MSG_WriteShort (&buf, cmd->forwardmove);
MSG_WriteShort (&buf, cmd->sidemove);
--- a/cl_parse.c
+++ b/cl_parse.c
@@ -89,7 +89,6 @@
int volume;
int field_mask;
float attenuation;
- int i;
field_mask = MSG_ReadByte();
@@ -111,10 +110,9 @@
if (ent > MAX_EDICTS)
Host_Error ("CL_ParseStartSoundPacket: ent = %d", ent);
-
- for (i=0 ; i<3 ; i++)
- pos[i] = MSG_ReadCoord ();
-
+
+ MSG_ReadVec(pos);
+
startsfx (ent, channel, cl.sound_precache[sound_num], pos, volume/255.0, attenuation);
}
@@ -404,29 +402,29 @@
VectorCopy (ent->msg_angles[0], ent->msg_angles[1]);
if (bits & U_ORIGIN1)
- ent->msg_origins[0][0] = MSG_ReadCoord ();
+ ent->msg_origins[0][0] = sv.protocol->MSG_ReadCoord ();
else
ent->msg_origins[0][0] = ent->baseline.origin[0];
if (bits & U_ANGLE1)
- ent->msg_angles[0][0] = MSG_ReadAngle();
+ ent->msg_angles[0][0] = sv.protocol->MSG_ReadAngle();
else
ent->msg_angles[0][0] = ent->baseline.angles[0];
if (bits & U_ORIGIN2)
- ent->msg_origins[0][1] = MSG_ReadCoord ();
+ ent->msg_origins[0][1] = sv.protocol->MSG_ReadCoord ();
else
ent->msg_origins[0][1] = ent->baseline.origin[1];
if (bits & U_ANGLE2)
- ent->msg_angles[0][1] = MSG_ReadAngle();
+ ent->msg_angles[0][1] = sv.protocol->MSG_ReadAngle();
else
ent->msg_angles[0][1] = ent->baseline.angles[1];
if (bits & U_ORIGIN3)
- ent->msg_origins[0][2] = MSG_ReadCoord ();
+ ent->msg_origins[0][2] = sv.protocol->MSG_ReadCoord ();
else
ent->msg_origins[0][2] = ent->baseline.origin[2];
if (bits & U_ANGLE3)
- ent->msg_angles[0][2] = MSG_ReadAngle();
+ ent->msg_angles[0][2] = sv.protocol->MSG_ReadAngle();
else
ent->msg_angles[0][2] = ent->baseline.angles[2];
@@ -458,8 +456,8 @@
ent->baseline.skin = MSG_ReadByte();
for (i=0 ; i<3 ; i++)
{
- ent->baseline.origin[i] = MSG_ReadCoord ();
- ent->baseline.angles[i] = MSG_ReadAngle ();
+ ent->baseline.origin[i] = sv.protocol->MSG_ReadCoord ();
+ ent->baseline.angles[i] = sv.protocol->MSG_ReadAngle ();
}
}
@@ -659,10 +657,8 @@
{
vec3_t org;
int sound_num, vol, atten;
- int i;
-
- for (i=0 ; i<3 ; i++)
- org[i] = MSG_ReadCoord ();
+
+ MSG_ReadVec(org);
sound_num = MSG_ReadByte ();
vol = MSG_ReadByte ();
atten = MSG_ReadByte ();
@@ -773,7 +769,7 @@
case svc_setangle:
for (i=0 ; i<3 ; i++)
- cl.viewangles[i] = MSG_ReadAngle ();
+ cl.viewangles[i] = sv.protocol->MSG_ReadAngle ();
break;
case svc_setview:
--- a/cl_tent.c
+++ b/cl_tent.c
@@ -45,15 +45,10 @@
int i;
ent = MSG_ReadShort ();
-
- start[0] = MSG_ReadCoord ();
- start[1] = MSG_ReadCoord ();
- start[2] = MSG_ReadCoord ();
-
- end[0] = MSG_ReadCoord ();
- end[1] = MSG_ReadCoord ();
- end[2] = MSG_ReadCoord ();
+ MSG_ReadVec(start);
+ MSG_ReadVec(end);
+
// override any beam with the same entity
for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
if (b->entity == ent)
@@ -99,25 +94,19 @@
switch (type)
{
case TE_WIZSPIKE: // spike hitting wall
- pos[0] = MSG_ReadCoord ();
- pos[1] = MSG_ReadCoord ();
- pos[2] = MSG_ReadCoord ();
+ MSG_ReadVec(pos);
R_RunParticleEffect (pos, vec3_origin, 20, 30);
startsfx (-1, 0, cl_sfx_wizhit, pos, 1, 1);
break;
case TE_KNIGHTSPIKE: // spike hitting wall
- pos[0] = MSG_ReadCoord ();
- pos[1] = MSG_ReadCoord ();
- pos[2] = MSG_ReadCoord ();
+ MSG_ReadVec(pos);
R_RunParticleEffect (pos, vec3_origin, 226, 20);
startsfx (-1, 0, cl_sfx_knighthit, pos, 1, 1);
break;
case TE_SPIKE: // spike hitting wall
- pos[0] = MSG_ReadCoord ();
- pos[1] = MSG_ReadCoord ();
- pos[2] = MSG_ReadCoord ();
+ MSG_ReadVec(pos);
R_RunParticleEffect (pos, vec3_origin, 0, 10);
if ( rand() % 5 )
startsfx (-1, 0, cl_Sfxink1, pos, 1, 1);
@@ -133,9 +122,7 @@
}
break;
case TE_SUPERSPIKE: // super spike hitting wall
- pos[0] = MSG_ReadCoord ();
- pos[1] = MSG_ReadCoord ();
- pos[2] = MSG_ReadCoord ();
+ MSG_ReadVec(pos);
R_RunParticleEffect (pos, vec3_origin, 0, 20);
if ( rand() % 5 )
@@ -153,16 +140,12 @@
break;
case TE_GUNSHOT: // bullet hitting wall
- pos[0] = MSG_ReadCoord ();
- pos[1] = MSG_ReadCoord ();
- pos[2] = MSG_ReadCoord ();
+ MSG_ReadVec(pos);
R_RunParticleEffect (pos, vec3_origin, 0, 20);
break;
case TE_EXPLOSION: // rocket explosion
- pos[0] = MSG_ReadCoord ();
- pos[1] = MSG_ReadCoord ();
- pos[2] = MSG_ReadCoord ();
+ MSG_ReadVec(pos);
R_ParticleExplosion (pos);
dl = CL_AllocDlight (0);
VectorCopy (pos, dl->origin);
@@ -173,9 +156,7 @@
break;
case TE_TAREXPLOSION: // tarbaby explosion
- pos[0] = MSG_ReadCoord ();
- pos[1] = MSG_ReadCoord ();
- pos[2] = MSG_ReadCoord ();
+ MSG_ReadVec(pos);
R_BlobExplosion (pos);
startsfx (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
@@ -200,23 +181,17 @@
// PGM 01/21/97
case TE_LAVASPLASH:
- pos[0] = MSG_ReadCoord ();
- pos[1] = MSG_ReadCoord ();
- pos[2] = MSG_ReadCoord ();
+ MSG_ReadVec(pos);
R_LavaSplash (pos);
break;
case TE_TELEPORT:
- pos[0] = MSG_ReadCoord ();
- pos[1] = MSG_ReadCoord ();
- pos[2] = MSG_ReadCoord ();
+ MSG_ReadVec(pos);
R_TeleportSplash (pos);
break;
case TE_EXPLOSION2: // color mapped explosion
- pos[0] = MSG_ReadCoord ();
- pos[1] = MSG_ReadCoord ();
- pos[2] = MSG_ReadCoord ();
+ MSG_ReadVec(pos);
colorStart = MSG_ReadByte ();
colorLength = MSG_ReadByte ();
R_ParticleExplosion2 (pos, colorStart, colorLength);
--- a/common.c
+++ b/common.c
@@ -173,7 +173,7 @@
MSG_WriteByte (sb, ((int)f*256/360) & 255);
}
-void MSG_WriteAngleShort (sizebuf_t *sb, float f)
+void MSG_WriteAngleInt16 (sizebuf_t *sb, float f)
{
MSG_WriteShort (sb, Qrint(f*65536.0/360.0));
}
@@ -303,15 +303,23 @@
float MSG_ReadCoord (void)
{
- return MSG_ReadShort() * (1.0/8);
+ return MSG_ReadShort() * 1.0 / 8.0;
}
+float MSG_ReadCoordInt32 (void)
+{
+ return MSG_ReadLong() * 1.0 / 16.0;
+}
+
float MSG_ReadAngle (void)
{
- return MSG_ReadChar() * (360.0/256);
+ return MSG_ReadChar() * 360.0 / 256.0;
}
-
+float MSG_ReadAngleInt16 (void)
+{
+ return MSG_ReadShort() * 360.0 / 65536.0;
+}
//===========================================================================
--- a/common.h
+++ b/common.h
@@ -70,7 +70,7 @@
void MSG_WriteCoord (sizebuf_t *sb, float f);
void MSG_WriteCoordInt32 (sizebuf_t *sb, float f);
void MSG_WriteAngle (sizebuf_t *sb, float f);
-void MSG_WriteAngleShort (sizebuf_t *sb, float f);
+void MSG_WriteAngleInt16 (sizebuf_t *sb, float f);
extern int msg_readcount;
extern qboolean msg_badread; // set if a read goes beyond end of message
@@ -84,7 +84,15 @@
char *MSG_ReadString (void);
float MSG_ReadCoord (void);
+float MSG_ReadCoordInt32 (void);
float MSG_ReadAngle (void);
+float MSG_ReadAngleInt16 (void);
+
+#define MSG_ReadVec(d) do{ \
+ (d)[0] = sv.protocol->MSG_ReadCoord(); \
+ (d)[1] = sv.protocol->MSG_ReadCoord(); \
+ (d)[2] = sv.protocol->MSG_ReadCoord(); \
+}while(0)
//============================================================================
--- a/host_cmd.c
+++ b/host_cmd.c
@@ -781,8 +781,8 @@
ent = EDICT_NUM( 1 + (host_client - svs.clients) );
MSG_WriteByte (&host_client->message, svc_setangle);
for (i=0 ; i < 2 ; i++)
- MSG_WriteAngle (&host_client->message, ent->v.angles[i] );
- MSG_WriteAngle (&host_client->message, 0 );
+ sv.protocol->MSG_WriteAngle (&host_client->message, ent->v.angles[i] );
+ sv.protocol->MSG_WriteAngle (&host_client->message, 0 );
SV_WriteClientdataToMessage (sv_player, &host_client->message);
--- a/pr_cmds.c
+++ b/pr_cmds.c
@@ -513,7 +513,7 @@
MSG_WriteByte (&sv.signon,svc_spawnstaticsound);
for (i=0 ; i<3 ; i++)
- MSG_WriteCoord(&sv.signon, pos[i]);
+ sv.protocol->MSG_WriteCoord(&sv.signon, pos[i]);
MSG_WriteByte (&sv.signon, soundnum);
@@ -1410,12 +1410,12 @@
void PF_WriteAngle (void)
{
- MSG_WriteAngle (WriteDest(), G_FLOAT(OFS_PARM1));
+ sv.protocol->MSG_WriteAngle (WriteDest(), G_FLOAT(OFS_PARM1));
}
void PF_WriteCoord (void)
{
- MSG_WriteCoord (WriteDest(), G_FLOAT(OFS_PARM1));
+ sv.protocol->MSG_WriteCoord (WriteDest(), G_FLOAT(OFS_PARM1));
}
void PF_WriteString (void)
@@ -1449,8 +1449,8 @@
MSG_WriteByte (&sv.signon, ent->v.skin);
for (i=0 ; i<3 ; i++)
{
- MSG_WriteCoord(&sv.signon, ent->v.origin[i]);
- MSG_WriteAngle(&sv.signon, ent->v.angles[i]);
+ sv.protocol->MSG_WriteCoord(&sv.signon, ent->v.origin[i]);
+ sv.protocol->MSG_WriteAngle(&sv.signon, ent->v.angles[i]);
}
// throw the entity away now
--- a/r_part.c
+++ b/r_part.c
@@ -120,8 +120,7 @@
vec3_t org, dir;
int i, count, msgcount, color;
- for (i=0 ; i<3 ; i++)
- org[i] = MSG_ReadCoord ();
+ MSG_ReadVec(org);
for (i=0 ; i<3 ; i++)
dir[i] = MSG_ReadChar () * (1.0/16);
msgcount = MSG_ReadByte ();
--- a/server.h
+++ b/server.h
@@ -22,6 +22,8 @@
char *name;
void (*MSG_WriteCoord)(sizebuf_t *sb, float f);
void (*MSG_WriteAngle)(sizebuf_t *sb, float f);
+ float (*MSG_ReadCoord)(void);
+ float (*MSG_ReadAngle)(void);
}protocol_t;
typedef struct
--- a/sv_main.c
+++ b/sv_main.c
@@ -13,12 +13,16 @@
.name = "Quake",
.MSG_WriteCoord = MSG_WriteCoord,
.MSG_WriteAngle = MSG_WriteAngle,
+ .MSG_ReadCoord = MSG_ReadCoord,
+ .MSG_ReadAngle = MSG_ReadAngle,
},
[PROTO_RMQ] = {
.id = PROTO_RMQ,
.name = "RMQ",
.MSG_WriteCoord = MSG_WriteCoordInt32,
- .MSG_WriteAngle = MSG_WriteAngleShort,
+ .MSG_WriteAngle = MSG_WriteAngleInt16,
+ .MSG_ReadCoord = MSG_ReadCoordInt32,
+ .MSG_ReadAngle = MSG_ReadAngleInt16,
},
};
@@ -107,9 +111,9 @@
if (sv.datagram.cursize > MAX_DATAGRAM-16)
return;
MSG_WriteByte (&sv.datagram, svc_particle);
- MSG_WriteCoord (&sv.datagram, org[0]);
- MSG_WriteCoord (&sv.datagram, org[1]);
- MSG_WriteCoord (&sv.datagram, org[2]);
+ sv.protocol->MSG_WriteCoord (&sv.datagram, org[0]);
+ sv.protocol->MSG_WriteCoord (&sv.datagram, org[1]);
+ sv.protocol->MSG_WriteCoord (&sv.datagram, org[2]);
for (i=0 ; i<3 ; i++)
{
v = dir[i]*16;
@@ -193,7 +197,7 @@
MSG_WriteShort (&sv.datagram, channel);
MSG_WriteByte (&sv.datagram, sound_num);
for (i=0 ; i<3 ; i++)
- MSG_WriteCoord (&sv.datagram, entity->v.origin[i]+0.5*(entity->v.mins[i]+entity->v.maxs[i]));
+ sv.protocol->MSG_WriteCoord (&sv.datagram, entity->v.origin[i]+0.5*(entity->v.mins[i]+entity->v.maxs[i]));
}
/*
@@ -555,17 +559,17 @@
if (bits & U_EFFECTS)
MSG_WriteByte (msg, ent->v.effects);
if (bits & U_ORIGIN1)
- MSG_WriteCoord (msg, ent->v.origin[0]);
+ sv.protocol->MSG_WriteCoord (msg, ent->v.origin[0]);
if (bits & U_ANGLE1)
- MSG_WriteAngle(msg, ent->v.angles[0]);
+ sv.protocol->MSG_WriteAngle(msg, ent->v.angles[0]);
if (bits & U_ORIGIN2)
- MSG_WriteCoord (msg, ent->v.origin[1]);
+ sv.protocol->MSG_WriteCoord (msg, ent->v.origin[1]);
if (bits & U_ANGLE2)
- MSG_WriteAngle(msg, ent->v.angles[1]);
+ sv.protocol->MSG_WriteAngle(msg, ent->v.angles[1]);
if (bits & U_ORIGIN3)
- MSG_WriteCoord (msg, ent->v.origin[2]);
+ sv.protocol->MSG_WriteCoord (msg, ent->v.origin[2]);
if (bits & U_ANGLE3)
- MSG_WriteAngle(msg, ent->v.angles[2]);
+ sv.protocol->MSG_WriteAngle(msg, ent->v.angles[2]);
}
}
@@ -612,7 +616,7 @@
MSG_WriteByte (msg, ent->v.dmg_save);
MSG_WriteByte (msg, ent->v.dmg_take);
for (i=0 ; i<3 ; i++)
- MSG_WriteCoord (msg, other->v.origin[i] + 0.5*(other->v.mins[i] + other->v.maxs[i]));
+ sv.protocol->MSG_WriteCoord (msg, other->v.origin[i] + 0.5*(other->v.mins[i] + other->v.maxs[i]));
ent->v.dmg_take = 0;
ent->v.dmg_save = 0;
@@ -628,7 +632,7 @@
{
MSG_WriteByte (msg, svc_setangle);
for (i=0 ; i < 3 ; i++)
- MSG_WriteAngle (msg, ent->v.angles[i] );
+ sv.protocol->MSG_WriteAngle (msg, ent->v.angles[i] );
ent->v.fixangle = 0;
}
@@ -984,8 +988,8 @@
MSG_WriteByte (&sv.signon, svent->baseline.skin);
for (i=0 ; i<3 ; i++)
{
- MSG_WriteCoord(&sv.signon, svent->baseline.origin[i]);
- MSG_WriteAngle(&sv.signon, svent->baseline.angles[i]);
+ sv.protocol->MSG_WriteCoord(&sv.signon, svent->baseline.origin[i]);
+ sv.protocol->MSG_WriteAngle(&sv.signon, svent->baseline.angles[i]);
}
}
}
--- a/sv_user.c
+++ b/sv_user.c
@@ -431,7 +431,7 @@
// read current angles
for (i=0 ; i<3 ; i++)
- angle[i] = MSG_ReadAngle ();
+ angle[i] = sv.protocol->MSG_ReadAngle ();
VectorCopy (angle, host_client->edict->v.v_angle);
--- a/view.c
+++ b/view.c
@@ -292,7 +292,6 @@
{
int armor, blood;
vec3_t from;
- int i;
vec3_t forward, right, up;
entity_t *ent;
float side;
@@ -300,8 +299,7 @@
armor = MSG_ReadByte ();
blood = MSG_ReadByte ();
- for (i=0 ; i<3 ; i++)
- from[i] = MSG_ReadCoord ();
+ MSG_ReadVec(from);
count = blood*0.5 + armor*0.5;
if (count < 10)