From d6da3a5362f8b13d20bacd5010249f9a56429ec5 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 31 Dec 2024 01:23:37 +0200 Subject: [PATCH] protocol: extend entity_xstate_t.origin to floats --- README.md | 1 + src/client/cl_parse.c | 10 ++++---- src/client/cl_screen.c | 4 +-- src/client/cl_view.c | 2 +- src/common/header/common.h | 10 +++++--- src/common/movemsg.c | 52 +++++++++++++++++++++++++++++--------- src/game/header/game.h | 4 +-- src/server/sv_game.c | 4 +-- src/server/sv_send.c | 13 +++++----- 9 files changed, 65 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index f213a656..876fd5a1 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,7 @@ Goals, fully finished goals could be checked in [here](CHANGELOG): * [ ] Support textures/*/*_glow.png load from ReRelease, * [ ] Support tactile/*/*.bnvib/.wav feedback load from ReRelease, * [ ] Fix physics with incorrect floor height in psx/base0.bsp, +* [ ] Make pmove_state_t.origin 29.3 (PS_M_ORIGIN), * [ ] Fix statusbar for DoD `roarke`, * [ ] Group `it_pic` images in vulkan render, * [ ] Rearange surfaces in vulkan render before render, diff --git a/src/client/cl_parse.c b/src/client/cl_parse.c index c0790f58..04d0c317 100644 --- a/src/client/cl_parse.c +++ b/src/client/cl_parse.c @@ -295,17 +295,17 @@ CL_ParseDelta(const entity_xstate_t *from, entity_xstate_t *to, int number, int if (bits & U_ORIGIN1) { - to->origin[0] = MSG_ReadCoord(&net_message); + to->origin[0] = MSG_ReadCoord(&net_message, cls.serverProtocol); } if (bits & U_ORIGIN2) { - to->origin[1] = MSG_ReadCoord(&net_message); + to->origin[1] = MSG_ReadCoord(&net_message, cls.serverProtocol); } if (bits & U_ORIGIN3) { - to->origin[2] = MSG_ReadCoord(&net_message); + to->origin[2] = MSG_ReadCoord(&net_message, cls.serverProtocol); } if (bits & U_ANGLE1) @@ -325,7 +325,7 @@ CL_ParseDelta(const entity_xstate_t *from, entity_xstate_t *to, int number, int if (bits & U_OLDORIGIN) { - MSG_ReadPos(&net_message, to->old_origin); + MSG_ReadPosExt(&net_message, to->old_origin, cls.serverProtocol); } if (bits & U_SOUND) @@ -1361,7 +1361,7 @@ CL_ParseStartSoundPacket(void) if (flags & SND_POS) { /* positioned in space */ - MSG_ReadPos(&net_message, pos_v); + MSG_ReadPosExt(&net_message, pos_v, cls.serverProtocol); pos = pos_v; } diff --git a/src/client/cl_screen.c b/src/client/cl_screen.c index a2260448..45aeca1a 100644 --- a/src/client/cl_screen.c +++ b/src/client/cl_screen.c @@ -1177,9 +1177,9 @@ SCR_ExecuteLayoutString(char *s) clientinfo_t *ci; token = COM_Parse(&s); - x = viddef.width / 2 - scale * 160 + scale*(int)strtol(token, (char **)NULL, 10); + x = viddef.width / 2 - scale * 160 + scale * (int)strtol(token, (char **)NULL, 10); token = COM_Parse(&s); - y = viddef.height / 2 - scale * 120 + scale*(int)strtol(token, (char **)NULL, 10); + y = viddef.height / 2 - scale * 120 + scale * (int)strtol(token, (char **)NULL, 10); SCR_AddDirtyPoint(x, y); SCR_AddDirtyPoint(x + scale * 159, y + scale * 31); diff --git a/src/client/cl_view.c b/src/client/cl_view.c index 94c2dbc2..ad1e7a52 100644 --- a/src/client/cl_view.c +++ b/src/client/cl_view.c @@ -525,7 +525,7 @@ V_Render3dCrosshair(void) if(crosshair_3d->value || crosshair_3d_glow->value){ - VectorMA(cl.refdef.vieworg,8192,cl.v_forward,end); + VectorMA(cl.refdef.vieworg, 8192, cl.v_forward,end); crosshair_trace = CL_PMTrace(cl.refdef.vieworg, vec3_origin, vec3_origin, end); if(crosshair_3d_glow->value){ diff --git a/src/common/header/common.h b/src/common/header/common.h index 74508c5c..4026d85d 100644 --- a/src/common/header/common.h +++ b/src/common/header/common.h @@ -112,8 +112,9 @@ void MSG_WriteShort(sizebuf_t *sb, int c); void MSG_WriteLong(sizebuf_t *sb, int c); void MSG_WriteFloat(sizebuf_t *sb, float f); void MSG_WriteString(sizebuf_t *sb, const char *s); -void MSG_WriteCoord(sizebuf_t *sb, float f); -void MSG_WritePos(sizebuf_t *sb, vec3_t pos); +void MSG_WriteCoord(sizebuf_t *sb, float f, int protocol); +void MSG_WritePosExt(sizebuf_t *sb, const vec3_t pos, int protocol); +void MSG_WritePos(sizebuf_t *sb, const vec3_t pos); void MSG_WriteAngle(sizebuf_t *sb, float f); void MSG_WriteAngle16(sizebuf_t *sb, float f); void MSG_WriteDeltaUsercmd(sizebuf_t *sb, struct usercmd_s *from, @@ -121,7 +122,7 @@ void MSG_WriteDeltaUsercmd(sizebuf_t *sb, struct usercmd_s *from, void MSG_WriteDeltaEntity(const struct entity_xstate_s *from, const struct entity_xstate_s *to, sizebuf_t *msg, qboolean force, qboolean newentity, int protocol); -void MSG_WriteDir(sizebuf_t *sb, vec3_t vector); +void MSG_WriteDir(sizebuf_t *sb, const vec3_t vector); void MSG_BeginReading(sizebuf_t *sb); @@ -133,7 +134,8 @@ float MSG_ReadFloat(sizebuf_t *sb); char *MSG_ReadString(sizebuf_t *sb); char *MSG_ReadStringLine(sizebuf_t *sb); -float MSG_ReadCoord(sizebuf_t *sb); +float MSG_ReadCoord(sizebuf_t *sb, int protocol); +void MSG_ReadPosExt(sizebuf_t *sb, vec3_t pos, int protocol); void MSG_ReadPos(sizebuf_t *sb, vec3_t pos); float MSG_ReadAngle(sizebuf_t *sb); float MSG_ReadAngle16(sizebuf_t *sb); diff --git a/src/common/movemsg.c b/src/common/movemsg.c index 935b410c..fc3e2cd0 100644 --- a/src/common/movemsg.c +++ b/src/common/movemsg.c @@ -261,13 +261,28 @@ MSG_WriteString(sizebuf_t *sb, const char *s) } void -MSG_WriteCoord(sizebuf_t *sb, float f) +MSG_WriteCoord(sizebuf_t *sb, float f, int protocol) { - MSG_WriteShort(sb, (int)(f * 8)); + if (IS_QII97_PROTOCOL(protocol)) + { + MSG_WriteShort(sb, (int)(f * 8)); + } + else + { + MSG_WriteFloat(sb, f); + } } void -MSG_WritePos(sizebuf_t *sb, vec3_t pos) +MSG_WritePosExt(sizebuf_t *sb, const vec3_t pos, int protocol) +{ + MSG_WriteCoord(sb, pos[0], protocol); + MSG_WriteCoord(sb, pos[1], protocol); + MSG_WriteCoord(sb, pos[2], protocol); +} + +void +MSG_WritePos(sizebuf_t *sb, const vec3_t pos) { MSG_WriteShort(sb, (int)(pos[0] * 8)); MSG_WriteShort(sb, (int)(pos[1] * 8)); @@ -381,7 +396,7 @@ MSG_WriteDeltaUsercmd(sizebuf_t *buf, usercmd_t *from, usercmd_t *cmd) } void -MSG_WriteDir(sizebuf_t *sb, vec3_t dir) +MSG_WriteDir(sizebuf_t *sb, const vec3_t dir) { int i, best; float d, bestd; @@ -811,17 +826,17 @@ MSG_WriteDeltaEntity(const entity_xstate_t *from, if (bits & U_ORIGIN1) { - MSG_WriteCoord(msg, to->origin[0]); + MSG_WriteCoord(msg, to->origin[0], protocol); } if (bits & U_ORIGIN2) { - MSG_WriteCoord(msg, to->origin[1]); + MSG_WriteCoord(msg, to->origin[1], protocol); } if (bits & U_ORIGIN3) { - MSG_WriteCoord(msg, to->origin[2]); + MSG_WriteCoord(msg, to->origin[2], protocol); } if (bits & U_ANGLE1) @@ -841,9 +856,7 @@ MSG_WriteDeltaEntity(const entity_xstate_t *from, if (bits & U_OLDORIGIN) { - MSG_WriteCoord(msg, to->old_origin[0]); - MSG_WriteCoord(msg, to->old_origin[1]); - MSG_WriteCoord(msg, to->old_origin[2]); + MSG_WritePosExt(msg, to->old_origin, protocol); } if (bits & U_SOUND) @@ -1037,9 +1050,24 @@ MSG_ReadStringLine(sizebuf_t *msg_read) } float -MSG_ReadCoord(sizebuf_t *msg_read) +MSG_ReadCoord(sizebuf_t *msg_read, int protocol) { - return MSG_ReadShort(msg_read) * (0.125f); + if (IS_QII97_PROTOCOL(protocol)) + { + return MSG_ReadShort(msg_read) * (0.125f); + } + else + { + return MSG_ReadFloat(msg_read); + } +} + +void +MSG_ReadPosExt(sizebuf_t *msg_read, vec3_t pos, int protocol) +{ + pos[0] = MSG_ReadCoord(msg_read, protocol); + pos[1] = MSG_ReadCoord(msg_read, protocol); + pos[2] = MSG_ReadCoord(msg_read, protocol); } void diff --git a/src/game/header/game.h b/src/game/header/game.h index 82f18662..aa8a4c4b 100644 --- a/src/game/header/game.h +++ b/src/game/header/game.h @@ -179,8 +179,8 @@ typedef struct void (*WriteLong)(int c); void (*WriteFloat)(float f); void (*WriteString)(const char *s); - void (*WritePosition)(vec3_t pos); /* some fractional bits */ - void (*WriteDir)(vec3_t pos); /* single byte encoded, very coarse */ + void (*WritePosition)(const vec3_t pos); /* some fractional bits */ + void (*WriteDir)(const vec3_t pos); /* single byte encoded, very coarse */ void (*WriteAngle)(float f); /* managed memory allocation */ diff --git a/src/server/sv_game.c b/src/server/sv_game.c index 1c791dfc..8975320c 100644 --- a/src/server/sv_game.c +++ b/src/server/sv_game.c @@ -276,13 +276,13 @@ PF_WriteString(const char *s) } static void -PF_WritePos(vec3_t pos) +PF_WritePos(const vec3_t pos) { MSG_WritePos(&sv.multicast, pos); } static void -PF_WriteDir(vec3_t dir) +PF_WriteDir(const vec3_t dir) { MSG_WriteDir(&sv.multicast, dir); } diff --git a/src/server/sv_send.c b/src/server/sv_send.c index acd68bd9..2fcfd289 100644 --- a/src/server/sv_send.c +++ b/src/server/sv_send.c @@ -283,12 +283,11 @@ void SV_StartSound(vec3_t origin, edict_t *entity, int channel, int soundindex, float volume, float attenuation, float timeofs) { - int sendchan; - int flags; - int i; - int ent; - vec3_t origin_v; + int sendchan, flags, i, ent, protocol; qboolean use_phs; + vec3_t origin_v; + + protocol = sv_client ? sv_client->protocol : PROTOCOL_VERSION; if ((volume < 0) || (volume > 1.0)) { @@ -370,7 +369,7 @@ SV_StartSound(vec3_t origin, edict_t *entity, int channel, int soundindex, MSG_WriteByte(&sv.multicast, svc_sound); MSG_WriteByte(&sv.multicast, flags); - if (sv_client && IS_QII97_PROTOCOL(sv_client->protocol)) + if (IS_QII97_PROTOCOL(protocol)) { MSG_WriteByte(&sv.multicast, soundindex); } @@ -401,7 +400,7 @@ SV_StartSound(vec3_t origin, edict_t *entity, int channel, int soundindex, if (flags & SND_POS) { - MSG_WritePos(&sv.multicast, origin); + MSG_WritePosExt(&sv.multicast, origin, protocol); } /* if the sound doesn't attenuate,send it to everyone