From c342eba620564b9011f9f3d1740da83060effe4e Mon Sep 17 00:00:00 2001 From: Saint Wish <6036821+SaintWish@users.noreply.github.com> Date: Sat, 21 Feb 2026 21:00:43 -0600 Subject: [PATCH 1/4] easy way to test noclip --- src/game/server/client.cpp | 79 ++++---------------------------------- 1 file changed, 8 insertions(+), 71 deletions(-) diff --git a/src/game/server/client.cpp b/src/game/server/client.cpp index de8bde22..c7e3bcbb 100644 --- a/src/game/server/client.cpp +++ b/src/game/server/client.cpp @@ -934,6 +934,14 @@ void ClientCommand2(edict_t *pEntity) } pPlayer->m_hEnemy = NULL; } + else if (FStrEq(pcmd, "pnoclip")) + { + pPlayer->pev->movetype = MOVETYPE_NOCLIP; + pPlayer->pev->solid = SOLID_NOT; + SetBits(pPlayer->m_afPhysicsFlags, PFLAG_OBSERVER); + SetBits(pPlayer->pev->flags, FL_NOTARGET); + //pPlayer->SetSpeed( 300 ); + } else if (FStrEq(pcmd, "storage")) { if (CMD_ARGC() < 2) @@ -1338,77 +1346,6 @@ void ClientCommand2(edict_t *pEntity) pPlayer->m_ClientCurrentHand = -1; }*/ } - //Thothie JUL2011_02 - Dynamic Client Command - else if (FStrEq(pcmd, "ce")) - { - //clcmd - called by client-side script command clcmd - /*IScripted *pScripted = NULL; - if (!strcmp(CMD_ARGV(1), "GM")) - { - ALERT(at_console, "DEBUG: ce - requested GM as target\n"); - CBaseEntity *pGameMasterEnt = UTIL_FindEntityByString(NULL, "netname", msstring("-") + "game_master"); - if (pGameMasterEnt) - { - pScripted = pGameMasterEnt->GetScripted(); - } - else - { - ALERT(at_console, "ERROR: ce - Failed to find game master!\n"); - } - } - else - { - if (!strcmp(CMD_ARGV(1), "player")) - { - pScripted = pPlayer->GetScripted(); - } - } - - if (pScripted) - { - static msstringlist Params; - Params.clearitems(); - int i = 0; - for (i = 0; i < CMD_ARGC(); i++) - { - if (i > 2) - { - Params.add(CMD_ARGV(i)); - } - } - Params.add(CMD_ARGV(i + 1)); - pScripted->CallScriptEvent(CMD_ARGV(2), &Params); - }*/ - - /* - CBaseEntity *pEntity = StringToEnt( CMD_ARGV(1) ); - if( pEntity ) - { - pScripted = pEntity->GetScripted(); - if ( pScripted ) - { - static msstringlist Params; - Params.clearitems( ); - for (int i = 0; i < CMD_ARGC(); i++) - { - if ( i > 2 ) - { - Params.add( CMD_ARGV(i) ); - } - } - pScripted->CallScriptEvent( CMD_ARGV(2), &Params ); - } - else - { - MSErrorConsoleText( "clcmd - entity ", msstring(CMD_ARGV(1)) + " found, but not scripted." ); - } - } - else - { - MSErrorConsoleText( "clcmd - entity ", msstring(CMD_ARGV(1)) + " not found." ); - } - */ - } else if (FStrEq(pcmd, "inv") && CMD_ARGV(1) && bCanUseInventory) //MAY2008 - no pulling invenotry when you cant attack { if (pPlayer->pev->weaponanim > 0) From 2abec835ac149aae27d2d364418450e125f2bf51 Mon Sep 17 00:00:00 2001 From: Saint Wish <6036821+SaintWish@users.noreply.github.com> Date: Sun, 22 Feb 2026 00:35:52 -0600 Subject: [PATCH 2/4] refactor vector math stuff for some reason. --- src/common/mathlib.h | 149 +++++++-------- .../client/angelscript/ASClientBindings.cpp | 1 + src/game/client/cl_util.h | 31 +-- src/game/client/entity.cpp | 1 + src/game/client/ev_common.cpp | 1 + src/game/client/ev_hldm.cpp | 25 ++- src/game/client/hud_spectator.cpp | 20 +- src/game/client/in_camera.cpp | 3 +- src/game/client/input.cpp | 2 +- src/game/client/ms/clglobal.cpp | 3 +- src/game/client/ms/health.cpp | 3 +- src/game/client/ms/hudid.cpp | 3 +- src/game/client/render/clrender.cpp | 2 +- src/game/client/render/clrendermirror.cpp | 8 +- src/game/client/render/studio_util.cpp | 113 ----------- src/game/client/render/studio_util.h | 10 +- .../client/render/studiomodelrenderer.cpp | 3 +- .../client/ui/ms/vgui_choosecharacter.cpp | 4 +- src/game/client/util.cpp | 92 +-------- src/game/client/view.cpp | 18 +- src/game/shared/movement/pm_math.cpp | 180 ++++++++---------- src/game/shared/movement/pm_shared.cpp | 155 ++------------- src/game/shared/ms/global.cpp | 13 +- src/game/shared/ms/msdebug.h | 2 +- src/game/shared/ms/script.cpp | 4 +- src/game/shared/ms/scriptcmds.cpp | 2 +- src/game/shared/ms/sharedutil.cpp | 2 +- src/game/shared/voice_status.cpp | 1 + src/game/shared/weapons/giattack.cpp | 2 +- 29 files changed, 227 insertions(+), 626 deletions(-) diff --git a/src/common/mathlib.h b/src/common/mathlib.h index 99bacb44..583acdf1 100644 --- a/src/common/mathlib.h +++ b/src/common/mathlib.h @@ -14,38 +14,34 @@ ****/ // mathlib.h -#ifdef __cplusplus -extern "C" -{ -#endif - typedef float vec_t; - typedef vec_t vec3_t[3]; - typedef vec_t vec4_t[4]; // x,y,z,w - typedef vec_t vec5_t[5]; +#pragma once + +#include +#include "hl/vector.h" + +typedef float vec_t; +typedef vec_t vec4_t[4]; // x,y,z,w +typedef vec_t vec5_t[5]; - typedef short vec_s_t; - typedef vec_s_t vec3s_t[3]; - typedef vec_s_t vec4s_t[4]; // x,y,z,w - typedef vec_s_t vec5s_t[5]; +typedef short vec_s_t; +typedef vec_s_t vec3s_t[3]; +typedef vec_s_t vec4s_t[4]; // x,y,z,w +typedef vec_s_t vec5s_t[5]; - typedef int fixed4_t; - typedef int fixed8_t; - typedef int fixed16_t; +typedef int fixed4_t; +typedef int fixed8_t; +typedef int fixed16_t; #ifndef M_PI #define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h #endif - struct mplane_s; +struct mplane_s; - extern vec3_t vec3_origin; - extern int nanmask; +extern Vector vec3_origin; +extern int nanmask; -#define IS_NAN(x) (((*(int *)&x) & nanmask) == nanmask) - -#ifndef VECTOR_H -#define DotProduct(x, y) ((x)[0] * (y)[0] + (x)[1] * (y)[1] + (x)[2] * (y)[2]) -#endif +#define IS_NAN(x) (((*(int*)&x) & nanmask) == nanmask) #define VectorSubtract(a, b, c) \ { \ @@ -65,43 +61,63 @@ extern "C" (b)[1] = (a)[1]; \ (b)[2] = (a)[2]; \ } -#define VectorClear(a) \ - { \ - (a)[0] = 0.0; \ - (a)[1] = 0.0; \ - (a)[2] = 0.0; \ - } +inline void VectorClear(float* a) +{ + a[0] = 0.0; + a[1] = 0.0; + a[2] = 0.0; +} + +void VectorMA(const float* veca, float scale, const float* vecb, float* vecc); - void VectorMA(const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc); +bool VectorCompare(const float* v1, const float* v2); +float Length(const float* v); +void CrossProduct(const float* v1, const float* v2, float* cross); +float VectorNormalize(float* v); // returns vector length +void VectorInverse(float* v); +void VectorScale(const float* in, float scale, float* out); +int Q_log2(int val); - vec_t _DotProduct(vec3_t v1, vec3_t v2); - void _VectorSubtract(vec3_t veca, vec3_t vecb, vec3_t out); - void _VectorAdd(vec3_t veca, vec3_t vecb, vec3_t out); - void _VectorCopy(vec3_t in, vec3_t out); +void R_ConcatRotations(float in1[3][3], float in2[3][3], float out[3][3]); +void R_ConcatTransforms(float in1[3][4], float in2[3][4], float out[3][4]); - int VectorCompare(const vec3_t v1, const vec3_t v2); - float Length(const vec3_t v); - void CrossProduct(const vec3_t v1, const vec3_t v2, vec3_t cross); - float VectorNormalize(vec3_t v); // returns vector length - void VectorInverse(vec3_t v); - void VectorScale(const vec3_t in, vec_t scale, vec3_t out); - int Q_log2(int val); +void FloorDivMod(double numer, double denom, int* quotient, int* rem); +fixed16_t Invert24To16(fixed16_t val); +int GreatestCommonDivisor(int i1, int i2); - void R_ConcatRotations(float in1[3][3], float in2[3][3], float out[3][3]); - void R_ConcatTransforms(float in1[3][4], float in2[3][4], float out[3][4]); +void AngleVectors(const Vector& angles, Vector* forward, Vector* right, Vector* up); +void AngleVectorsTranspose(const Vector& angles, Vector* forward, Vector* right, Vector* up); +#define AngleIVectors AngleVectorsTranspose - // Here are some "manual" INLINE routines for doing floating point to integer conversions - extern short new_cw, old_cw; +void AngleMatrix(const float* angles, float (*matrix)[4]); +void AngleIMatrix(const Vector& angles, float (*matrix)[4]); +void VectorTransform(const float* in1, float in2[3][4], float* out); - typedef union DLONG - { - int i[2]; - double d; - float f; - } DLONG; +void NormalizeAngles(float* angles); +void InterpolateAngles(float* start, float* end, float* output, float frac); +float AngleBetweenVectors(const float* v1, const float* v2); + +void VectorMatrix(const Vector& forward, Vector& right, Vector& up); +void VectorAngles(const float* forward, float* angles); + +int InvertMatrix(const float* m, float* out); + +int BoxOnPlaneSide(const Vector& emins, const Vector& emaxs, struct mplane_s* plane); +float anglemod(float a); - extern DLONG dlong; +// Here are some "manual" INLINE routines for doing floating point to integer conversions +extern short new_cw, old_cw; +typedef union DLONG +{ + int i[2]; + double d; + float f; +} DLONG; + +extern DLONG dlong; + +// wtf is even going on here?? #ifdef _WIN32 void __inline set_fpu_cw(void) { @@ -134,35 +150,6 @@ extern "C" #define set_fpu_cw() /* */ #define quick_ftol(f) ftol(f) #define restore_fpu_cw() /* */ -#endif - - void FloorDivMod(double numer, double denom, int *quotient, - int *rem); - fixed16_t Invert24To16(fixed16_t val); - int GreatestCommonDivisor(int i1, int i2); - - void AngleVectors(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up); - void AngleVectorsTranspose(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up); -#define AngleIVectors AngleVectorsTranspose - - void AngleMatrix(const vec3_t angles, float (*matrix)[4]); - void AngleIMatrix(const vec3_t angles, float (*matrix)[4]); - void VectorTransform(const vec3_t in1, float in2[3][4], vec3_t out); - - void NormalizeAngles(vec3_t angles); - void InterpolateAngles(vec3_t start, vec3_t end, vec3_t output, float frac); - float AngleBetweenVectors(const vec3_t v1, const vec3_t v2); - - void VectorMatrix(vec3_t forward, vec3_t right, vec3_t up); - void VectorAngles(const vec3_t forward, vec3_t angles); - - int InvertMatrix(const float *m, float *out); - - int BoxOnPlaneSide(vec3_t emins, vec3_t emaxs, struct mplane_s *plane); - float anglemod(float a); - -#ifdef __cplusplus -} #endif #define BOX_ON_PLANE_SIDE(emins, emaxs, p) \ diff --git a/src/game/client/angelscript/ASClientBindings.cpp b/src/game/client/angelscript/ASClientBindings.cpp index 5146f452..ec54d71c 100644 --- a/src/game/client/angelscript/ASClientBindings.cpp +++ b/src/game/client/angelscript/ASClientBindings.cpp @@ -29,6 +29,7 @@ // Master Sword includes #include "mslogger.h" #include "sharedutil.h" +#include // External client globals extern cl_enginefunc_t gEngfuncs; diff --git a/src/game/client/cl_util.h b/src/game/client/cl_util.h index 5ba194aa..e3bfefce 100644 --- a/src/game/client/cl_util.h +++ b/src/game/client/cl_util.h @@ -102,7 +102,7 @@ inline struct cvar_s *CVAR_CREATE(const char *cv, const char *val, const int fla #define ServerCmd (*gEngfuncs.pfnServerCmd) #define ClientCmd (*gEngfuncs.pfnClientCmd) #define SetCrosshair (*gEngfuncs.pfnSetCrosshair) -#define AngleVectors (*gEngfuncs.pfnAngleVectors) +//#define AngleVectors (*gEngfuncs.pfnAngleVectors) // Gets the height & width of a sprite, at the specified frame inline int SPR_Height(HLSPRITE x, int f) { return gEngfuncs.pfnSPR_Height(x, f); } @@ -155,35 +155,6 @@ inline void PlayHUDSound(const char *Sound, float vol) { PlaySound((char *)Sound void ScaleColors(int &r, int &g, int &b, int a); #define DotProduct(x, y) ((x)[0] * (y)[0] + (x)[1] * (y)[1] + (x)[2] * (y)[2]) -#define VectorSubtract(a, b, c) \ - { \ - (c)[0] = (a)[0] - (b)[0]; \ - (c)[1] = (a)[1] - (b)[1]; \ - (c)[2] = (a)[2] - (b)[2]; \ - } -#define VectorAdd(a, b, c) \ - { \ - (c)[0] = (a)[0] + (b)[0]; \ - (c)[1] = (a)[1] + (b)[1]; \ - (c)[2] = (a)[2] + (b)[2]; \ - } -#define VectorCopy(a, b) \ - { \ - (b)[0] = (a)[0]; \ - (b)[1] = (a)[1]; \ - (b)[2] = (a)[2]; \ - } -inline void VectorClear(float *a) -{ - a[0] = 0.0; - a[1] = 0.0; - a[2] = 0.0; -} -float Length(const float *v); -void VectorMA(const float *veca, float scale, const float *vecb, float *vecc); -void VectorScale(const float *in, float scale, float *out); -float VectorNormalize(float *v); -void VectorInverse(float *v); // ugh, some bits of the client code expect a float[3] while others expect a Vector, and there's a macro that pretends they're the same // handle the extern with the correct types in the places where it's required diff --git a/src/game/client/entity.cpp b/src/game/client/entity.cpp index c99b82ed..60b5a9ad 100644 --- a/src/game/client/entity.cpp +++ b/src/game/client/entity.cpp @@ -27,6 +27,7 @@ #include "ms/hudscript.h" #include "ms/clglobal.h" #include "script.h" +#include #undef DLLEXPORT //Master Sword #define DLLEXPORT EXPORT diff --git a/src/game/client/ev_common.cpp b/src/game/client/ev_common.cpp index 58af3bd9..63418887 100644 --- a/src/game/client/ev_common.cpp +++ b/src/game/client/ev_common.cpp @@ -23,6 +23,7 @@ #include "eventscripts.h" #include "event_api.h" +#include "mathlib.h" /* ================= diff --git a/src/game/client/ev_hldm.cpp b/src/game/client/ev_hldm.cpp index a4d40fb6..9ba4734d 100644 --- a/src/game/client/ev_hldm.cpp +++ b/src/game/client/ev_hldm.cpp @@ -30,11 +30,10 @@ #include "event_api.h" #include "event_args.h" #include "in_defs.h" +#include "mathlib.h" #include -extern "C" float* vec3_origin; - static int tracerCount[32]; void V_PunchAxis(int axis, float punch); @@ -474,7 +473,7 @@ void EV_FireGlock1(event_args_t *args) VectorCopy(args->velocity, velocity); empty = args->bparam1; - AngleVectors(angles, forward, right, up); + AngleVectors(angles, &forward, &right, &up); shell = gEngfuncs.pEventAPI->EV_FindModelIndex("models/shell.mdl"); // brass shell @@ -528,7 +527,7 @@ void EV_FireGlock2(event_args_t *args) VectorCopy(args->angles, angles); VectorCopy(args->velocity, velocity); - AngleVectors(angles, forward, right, up); + AngleVectors(angles, &forward, &right, &up); shell = gEngfuncs.pEventAPI->EV_FindModelIndex("models/shell.mdl"); // brass shell @@ -583,7 +582,7 @@ void EV_FireShotGunDouble(event_args_t *args) VectorCopy(args->angles, angles); VectorCopy(args->velocity, velocity); - AngleVectors(angles, forward, right, up); + AngleVectors(angles, &forward, &right, &up); shell = gEngfuncs.pEventAPI->EV_FindModelIndex("models/shotgunshell.mdl"); // brass shell @@ -649,7 +648,7 @@ void EV_FireShotGunSingle(event_args_t *args) VectorCopy(args->angles, angles); VectorCopy(args->velocity, velocity); - AngleVectors(angles, forward, right, up); + AngleVectors(angles, &forward, &right, &up); shell = gEngfuncs.pEventAPI->EV_FindModelIndex("models/shotgunshell.mdl"); // brass shell @@ -710,7 +709,7 @@ void EV_FireMP5(event_args_t *args) VectorCopy(args->angles, angles); VectorCopy(args->velocity, velocity); - AngleVectors(angles, forward, right, up); + AngleVectors(angles, &forward, &right, &up); shell = gEngfuncs.pEventAPI->EV_FindModelIndex("models/shell.mdl"); // brass shell @@ -769,7 +768,7 @@ void EV_FirePython(event_args_t *args) VectorCopy(args->angles, angles); VectorCopy(args->velocity, velocity); - AngleVectors(angles, forward, right, up); + AngleVectors(angles, &forward, &right, &up); if (EV_IsLocal(idx)) { @@ -866,7 +865,7 @@ void EV_FireGauss(event_args_t *args) m_iBeam = gEngfuncs.pEventAPI->EV_FindModelIndex("sprites/smoke.spr"); m_iBalls = m_iGlow = gEngfuncs.pEventAPI->EV_FindModelIndex("sprites/hotglow.spr"); - AngleVectors(angles, forward, right, up); + AngleVectors(angles, &forward, &right, &up); VectorMA(vecSrc, 8192, forward, vecDest); @@ -968,7 +967,7 @@ void EV_FireGauss(event_args_t *args) VectorMA(tr.endpos, 8.0, forward, vecSrc); VectorMA(vecSrc, 8192.0, forward, vecDest); - gEngfuncs.pEfxAPI->R_TempSprite(tr.endpos, vec3_origin, 0.2, m_iGlow, kRenderGlow, kRenderFxNoDissipation, flDamage * n / 255.0, flDamage * n * 0.5 * 0.1, FTENT_FADEOUT); + gEngfuncs.pEfxAPI->R_TempSprite(tr.endpos, Vector(0,0,0), 0.2, m_iGlow, kRenderGlow, kRenderFxNoDissipation, flDamage * n / 255.0, flDamage * n * 0.5 * 0.1, FTENT_FADEOUT); { vec3_t fwd; @@ -990,7 +989,7 @@ void EV_FireGauss(event_args_t *args) // tunnel EV_HLDM_DecalGunshot(&tr, BULLET_MONSTER_12MM); - gEngfuncs.pEfxAPI->R_TempSprite(tr.endpos, vec3_origin, 1.0, m_iGlow, kRenderGlow, kRenderFxNoDissipation, flDamage / 255.0, 6.0, FTENT_FADEOUT); + gEngfuncs.pEfxAPI->R_TempSprite(tr.endpos, Vector(0,0,0), 1.0, m_iGlow, kRenderGlow, kRenderFxNoDissipation, flDamage / 255.0, 6.0, FTENT_FADEOUT); // limit it to one hole punch if (fHasPunched) @@ -1047,7 +1046,7 @@ void EV_FireGauss(event_args_t *args) EV_HLDM_DecalGunshot(&beam_tr, BULLET_MONSTER_12MM); - gEngfuncs.pEfxAPI->R_TempSprite(beam_tr.endpos, vec3_origin, 0.1, m_iGlow, kRenderGlow, kRenderFxNoDissipation, flDamage / 255.0, 6.0, FTENT_FADEOUT); + gEngfuncs.pEfxAPI->R_TempSprite(beam_tr.endpos, Vector(0,0,0), 0.1, m_iGlow, kRenderGlow, kRenderFxNoDissipation, flDamage / 255.0, 6.0, FTENT_FADEOUT); // balls { @@ -1073,7 +1072,7 @@ void EV_FireGauss(event_args_t *args) { // slug doesn't punch through ever with primary // fire, so leave a little glowy bit and make some balls - gEngfuncs.pEfxAPI->R_TempSprite(tr.endpos, vec3_origin, 0.2, m_iGlow, kRenderGlow, kRenderFxNoDissipation, 200.0 / 255.0, 0.3, FTENT_FADEOUT); + gEngfuncs.pEfxAPI->R_TempSprite(tr.endpos, Vector(0,0,0), 0.2, m_iGlow, kRenderGlow, kRenderFxNoDissipation, 200.0 / 255.0, 0.3, FTENT_FADEOUT); { vec3_t fwd; diff --git a/src/game/client/hud_spectator.cpp b/src/game/client/hud_spectator.cpp index 822d9335..b19b9661 100644 --- a/src/game/client/hud_spectator.cpp +++ b/src/game/client/hud_spectator.cpp @@ -30,8 +30,7 @@ #include "vgui_scorepanel.h" #include "vgui_menudefsshared.h" #include "filesystem_shared.h" - -extern "C" float* vec3_origin; +#include #pragma warning(disable : 4244) @@ -43,7 +42,7 @@ extern void V_GetInEyePos(int entity, float *origin, float *angles); extern void V_ResetChaseCam(); extern void V_GetChasePos(int target, float *cl_angles, float *origin, float *angles); extern void VectorAngles(const float *forward, float *angles); -extern "C" void NormalizeAngles(float *angles); +extern void NormalizeAngles(float *angles); extern float *GetClientColor(int clientIndex); extern vec3_t v_origin; // last view origin @@ -74,7 +73,7 @@ void SpectatorSpray(void) if (!gEngfuncs.IsSpectateOnly()) return; - AngleVectors(v_angles, forward, NULL, NULL); + AngleVectors(v_angles, &forward, NULL, NULL); VectorScale(forward, 128, forward); VectorAdd(forward, v_origin, forward); pmtrace_t *trace = gEngfuncs.PM_TraceLine(v_origin, forward, PM_TRACELINE_PHYSENTSONLY, 2, -1); @@ -349,11 +348,8 @@ void CHudSpectator::SetSpectatorStartPosition() else { // jump to 0,0,0 if no better position was found - if (vec3_origin != NULL) - { - VectorCopy(vec3_origin, m_cameraOrigin); - VectorCopy(vec3_origin, m_cameraAngles); - } + VectorCopy(Vector(0,0,0), m_cameraOrigin); + VectorCopy(Vector(0,0,0), m_cameraAngles); } VectorCopy(m_cameraOrigin, vJumpOrigin); @@ -414,7 +410,7 @@ int CHudSpectator::Draw(float flTime) if ((m_moveDelta != 0.0f) && (g_iUser1 != OBS_ROAMING)) { vec3_t right; - AngleVectors(v_angles, NULL, right, NULL); + AngleVectors(v_angles, NULL, &right, NULL); VectorNormalize(right); VectorScale(right, m_moveDelta, right); @@ -1212,7 +1208,7 @@ void CHudSpectator::DrawOverviewEntities() // see R_DrawSpriteModel // draws players sprite - AngleVectors(ent->angles, right, up, NULL); + AngleVectors(ent->angles, &right, &up, NULL); VectorCopy(ent->origin, origin); @@ -1343,7 +1339,7 @@ void CHudSpectator::DrawOverviewEntities() gEngfuncs.pTriAPI->Color4f(r, g, b, 1.0); - AngleVectors(angles, forward, NULL, NULL); + AngleVectors(angles, &forward, NULL, NULL); VectorScale(forward, 512.0f, forward); offset[0] = 0.0f; diff --git a/src/game/client/in_camera.cpp b/src/game/client/in_camera.cpp index 315f9571..9ee1df09 100644 --- a/src/game/client/in_camera.cpp +++ b/src/game/client/in_camera.cpp @@ -11,12 +11,13 @@ #include "const.h" #include "camera.h" #include "in_defs.h" +#include //#define LATER void V_GetChaseOrigin(float *angles, float *origin, float distance, float *returnvec); extern float v_lastDistance; -extern "C" void NormalizeAngles(float *angles); //Master Sword +extern void NormalizeAngles(float *angles); //Master Sword bool Cam_SwitchingTo1StPerson = false; float CL_KeyState(kbutton_t *key); diff --git a/src/game/client/input.cpp b/src/game/client/input.cpp index 1d817829..5229a540 100644 --- a/src/game/client/input.cpp +++ b/src/game/client/input.cpp @@ -37,6 +37,7 @@ extern "C" #include "clientlibrary.h" #include "scriptmgr.h" #include "ms/clglobal.h" +#include extern "C" { @@ -52,7 +53,6 @@ extern cl_enginefunc_t gEngfuncs; extern CClientLibrary gClient; // Defined in pm_math.c -extern "C" float anglemod(float a); void IN_Init(void); void IN_Move(float frametime, usercmd_t *cmd); diff --git a/src/game/client/ms/clglobal.cpp b/src/game/client/ms/clglobal.cpp index 430ad4b5..bdf8f3a8 100644 --- a/src/game/client/ms/clglobal.cpp +++ b/src/game/client/ms/clglobal.cpp @@ -11,6 +11,7 @@ #include "hudscript.h" #include "ms/vgui_hud.h" #include "mslogger.h" +#include //#include "SteamClientHelper.h" //#include "richpresence.h" @@ -291,7 +292,7 @@ char* UTIL_VarArgs(const char *format, ...) Vector UTIL_VecToAngles(const Vector &vec) { float rgflVecOut[3]; - AngleVectors(vec, rgflVecOut, NULL, NULL); + VEC_TO_ANGLES(vec, rgflVecOut); return Vector(rgflVecOut); } diff --git a/src/game/client/ms/health.cpp b/src/game/client/ms/health.cpp index ce12c134..aad8e4c0 100644 --- a/src/game/client/ms/health.cpp +++ b/src/game/client/ms/health.cpp @@ -33,6 +33,7 @@ #include "health.h" #include "hudmisc.h" #include "menu.h" +#include MS_DECLARE_MESSAGE(m_Health, HP) MS_DECLARE_MESSAGE(m_Health, MP) @@ -313,7 +314,7 @@ void CHudHealth::CalcDamageDirection(vec3_t vecFrom) float flDistToTarget = vecFrom.Length(); vecFrom = vecFrom.Normalize(); - AngleVectors(vecAngles, forward, right, up); + AngleVectors(vecAngles, &forward, &right, &up); front = DotProduct(vecFrom, right); side = DotProduct(vecFrom, forward); diff --git a/src/game/client/ms/hudid.cpp b/src/game/client/ms/hudid.cpp index dd8c642e..47dc589a 100644 --- a/src/game/client/ms/hudid.cpp +++ b/src/game/client/ms/hudid.cpp @@ -30,6 +30,7 @@ extern void HUD_PrepEntity(CBaseEntity *pEntity, CBasePlayer *pWeaponOwner); #include "hudid.h" #include "ms/vgui_hud.h" +#include MS_DECLARE_MESSAGE(m_HUDId, EntInfo); @@ -167,7 +168,7 @@ entinfo_t *CHudID::GetEntInFrontOfMe(float Range) Vector vViewAngle; gEngfuncs.GetViewAngles(vViewAngle); cl_entity_s *clplayer = gEngfuncs.GetLocalPlayer(); - AngleVectors(vViewAngle, vForward, NULL, NULL); + AngleVectors(vViewAngle, &vForward, NULL, NULL); Vector vecSrc = clplayer->origin, vecEnd, viewOfs; gEngfuncs.pEventAPI->EV_LocalPlayerViewheight(viewOfs); diff --git a/src/game/client/render/clrender.cpp b/src/game/client/render/clrender.cpp index b858d4c0..fa2e0162 100644 --- a/src/game/client/render/clrender.cpp +++ b/src/game/client/render/clrender.cpp @@ -81,7 +81,7 @@ CParticle::CParticle() void CParticle::SetAngles(Vector Angles) { - EngineFunc::MakeVectors(Angles, m_DirForward, m_DirRight, m_DirUp); + EngineFunc::MakeVectors(Angles, &m_DirForward, &m_DirRight, &m_DirUp); } void CParticle::BillBoard() diff --git a/src/game/client/render/clrendermirror.cpp b/src/game/client/render/clrendermirror.cpp index ab041e72..02aa8397 100644 --- a/src/game/client/render/clrendermirror.cpp +++ b/src/game/client/render/clrendermirror.cpp @@ -90,7 +90,7 @@ class CFrustum { Vector Forward; Vector NewAng = ViewMgr.Angles + Vector(0, RightPlaneYaw, 0); - EngineFunc::MakeVectors(NewAng, Forward); + EngineFunc::MakeVectors(NewAng, &Forward); plane.m_Normal = Forward; plane.m_Dist = DotProduct(ViewMgr.Origin, plane.m_Normal); break; @@ -99,7 +99,7 @@ class CFrustum { Vector Forward; Vector NewAng = ViewMgr.Angles + Vector(0, -RightPlaneYaw, 0); - EngineFunc::MakeVectors(NewAng, Forward); + EngineFunc::MakeVectors(NewAng, &Forward); plane.m_Normal = Forward; plane.m_Dist = DotProduct(ViewMgr.Origin, plane.m_Normal); break; @@ -108,7 +108,7 @@ class CFrustum { Vector Forward; Vector NewAng = ViewMgr.Angles + Vector(-UpPlanePitch, 0, 0); - EngineFunc::MakeVectors(NewAng, Forward); + EngineFunc::MakeVectors(NewAng, &Forward); plane.m_Normal = Forward; plane.m_Dist = DotProduct(ViewMgr.Origin, plane.m_Normal); break; @@ -117,7 +117,7 @@ class CFrustum { Vector Forward; Vector NewAng = ViewMgr.Angles + Vector(UpPlanePitch, 0, 0); - EngineFunc::MakeVectors(NewAng, Forward); + EngineFunc::MakeVectors(NewAng, &Forward); plane.m_Normal = Forward; plane.m_Dist = DotProduct(ViewMgr.Origin, plane.m_Normal); break; diff --git a/src/game/client/render/studio_util.cpp b/src/game/client/render/studio_util.cpp index 5ed514a6..78bfded6 100644 --- a/src/game/client/render/studio_util.cpp +++ b/src/game/client/render/studio_util.cpp @@ -12,119 +12,6 @@ #include "com_model.h" #include "studio_util.h" -/* -==================== -AngleMatrix - -==================== -*/ -void AngleMatrix (const float *angles, float (*matrix)[4] ) -{ - float angle; - float sr, sp, sy, cr, cp, cy; - - angle = angles[YAW] * (M_PI*2 / 360); - sy = sin(angle); - cy = cos(angle); - angle = angles[PITCH] * (M_PI*2 / 360); - sp = sin(angle); - cp = cos(angle); - angle = angles[ROLL] * (M_PI*2 / 360); - sr = sin(angle); - cr = cos(angle); - - // matrix = (YAW * PITCH) * ROLL - matrix[0][0] = cp*cy; - matrix[1][0] = cp*sy; - matrix[2][0] = -sp; - matrix[0][1] = sr*sp*cy+cr*-sy; - matrix[1][1] = sr*sp*sy+cr*cy; - matrix[2][1] = sr*cp; - matrix[0][2] = (cr*sp*cy+-sr*-sy); - matrix[1][2] = (cr*sp*sy+-sr*cy); - matrix[2][2] = cr*cp; - matrix[0][3] = 0.0; - matrix[1][3] = 0.0; - matrix[2][3] = 0.0; -} - -/* -==================== -VectorCompare - -==================== -*/ -int VectorCompare (const float *v1, const float *v2) -{ - int i; - - for (i=0 ; i<3 ; i++) - if (v1[i] != v2[i]) - return 0; - - return 1; -} - -/* -==================== -CrossProduct - -==================== -*/ -void CrossProduct (const float *v1, const float *v2, float *cross) -{ - cross[0] = v1[1]*v2[2] - v1[2]*v2[1]; - cross[1] = v1[2]*v2[0] - v1[0]*v2[2]; - cross[2] = v1[0]*v2[1] - v1[1]*v2[0]; -} - -/* -==================== -VectorTransform - -==================== -*/ -void VectorTransform (const float *in1, float in2[3][4], float *out) -{ - out[0] = DotProduct(in1, in2[0]) + in2[0][3]; - out[1] = DotProduct(in1, in2[1]) + in2[1][3]; - out[2] = DotProduct(in1, in2[2]) + in2[2][3]; -} - -/* -================ -ConcatTransforms - -================ -*/ -void ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4]) -{ - out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] + - in1[0][2] * in2[2][0]; - out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] + - in1[0][2] * in2[2][1]; - out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] + - in1[0][2] * in2[2][2]; - out[0][3] = in1[0][0] * in2[0][3] + in1[0][1] * in2[1][3] + - in1[0][2] * in2[2][3] + in1[0][3]; - out[1][0] = in1[1][0] * in2[0][0] + in1[1][1] * in2[1][0] + - in1[1][2] * in2[2][0]; - out[1][1] = in1[1][0] * in2[0][1] + in1[1][1] * in2[1][1] + - in1[1][2] * in2[2][1]; - out[1][2] = in1[1][0] * in2[0][2] + in1[1][1] * in2[1][2] + - in1[1][2] * in2[2][2]; - out[1][3] = in1[1][0] * in2[0][3] + in1[1][1] * in2[1][3] + - in1[1][2] * in2[2][3] + in1[1][3]; - out[2][0] = in1[2][0] * in2[0][0] + in1[2][1] * in2[1][0] + - in1[2][2] * in2[2][0]; - out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] + - in1[2][2] * in2[2][1]; - out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] + - in1[2][2] * in2[2][2]; - out[2][3] = in1[2][0] * in2[0][3] + in1[2][1] * in2[1][3] + - in1[2][2] * in2[2][3] + in1[2][3]; -} - // angles index are not the same as ROLL, PITCH, YAW /* diff --git a/src/game/client/render/studio_util.h b/src/game/client/render/studio_util.h index f6efb25c..7a2aa47b 100644 --- a/src/game/client/render/studio_util.h +++ b/src/game/client/render/studio_util.h @@ -5,11 +5,7 @@ // $NoKeywords: $ //============================================================================= -#if !defined(STUDIO_UTIL_H) -#define STUDIO_UTIL_H -#if defined(WIN32) #pragma once -#endif #ifndef M_PI #define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h @@ -28,13 +24,11 @@ #define FDotProduct(a, b) (fabs((a[0]) * (b[0])) + fabs((a[1]) * (b[1])) + fabs((a[2]) * (b[2]))) void AngleMatrix(const float *angles, float (*matrix)[4]); -int VectorCompare(const float *v1, const float *v2); +bool VectorCompare (const float *v1, const float *v2); void CrossProduct(const float *v1, const float *v2, float *cross); void VectorTransform(const float *in1, float in2[3][4], float *out); void ConcatTransforms(float in1[3][4], float in2[3][4], float out[3][4]); void MatrixCopy(float in[3][4], float out[3][4]); void QuaternionMatrix(vec4_t quaternion, float (*matrix)[4]); void QuaternionSlerp(vec4_t p, vec4_t q, float t, vec4_t qt); -void AngleQuaternion(float *angles, vec4_t quaternion); - -#endif // STUDIO_UTIL_H \ No newline at end of file +void AngleQuaternion(float *angles, vec4_t quaternion); \ No newline at end of file diff --git a/src/game/client/render/studiomodelrenderer.cpp b/src/game/client/render/studiomodelrenderer.cpp index 2c3243e7..ffe7a40d 100644 --- a/src/game/client/render/studiomodelrenderer.cpp +++ b/src/game/client/render/studiomodelrenderer.cpp @@ -35,6 +35,7 @@ #include "ms/clglobal.h" #include "ms/hudscript.h" #include // Header File For The OpenGL32 Library +#include extern "C" int nanmask; #define IS_NAN(x) (((*(int *)&x) & nanmask) == nanmask) @@ -1482,7 +1483,7 @@ int CStudioModelRenderer::StudioDrawModel(int flags) m_pPlayerInfo = IEngineStudio.PlayerInfo(ZeroBasedPlayerIdx); Vector PrevOrigin = m_pPlayerInfo->prevgaitorigin; Vector vForward; - EngineFunc::MakeVectors(m_pCurrentEntity->angles, vForward, NULL, NULL); + EngineFunc::MakeVectors(m_pCurrentEntity->angles, &vForward, NULL, NULL); //Set the "last origin" to behind me to the walk code thinks I'm walking forward. //This needs to be scaled from the original velocity, incase I'm drawing a fake player of a different size diff --git a/src/game/client/ui/ms/vgui_choosecharacter.cpp b/src/game/client/ui/ms/vgui_choosecharacter.cpp index 38ef352d..f74e2e31 100644 --- a/src/game/client/ui/ms/vgui_choosecharacter.cpp +++ b/src/game/client/ui/ms/vgui_choosecharacter.cpp @@ -1204,7 +1204,7 @@ void CRenderChar::Render( ) return; Vector vForward, vRight, vUp; - EngineFunc::MakeVectors( ViewMgr.Angles, vForward, vRight, vUp ); + EngineFunc::MakeVectors( ViewMgr.Angles, &vForward, &vRight, &vUp ); m_Ent.origin = ViewMgr.Origin + vForward * 5.0f + vUp * 0.4; if( m_Stage == STG_CHOOSECHAR ) @@ -1413,7 +1413,7 @@ void CRenderSpawnbox::Init( ) void CRenderSpawnbox::Render( ) { Vector vForward, vRight, vUp; - EngineFunc::MakeVectors( ViewMgr.Angles, vForward, vRight, vUp ); + EngineFunc::MakeVectors( ViewMgr.Angles, &vForward, &vRight, &vUp ); m_Ent.origin = ViewMgr.Origin; m_Ent.angles = Vector( ViewMgr.Angles.x, ViewMgr.Angles.y + 180, 0 ); m_Ent.curstate.angles = m_Ent.angles; diff --git a/src/game/client/util.cpp b/src/game/client/util.cpp index 5e55329f..71af8638 100644 --- a/src/game/client/util.cpp +++ b/src/game/client/util.cpp @@ -18,101 +18,13 @@ // implementation of class-less helper functions // -#include "stdio.h" -#include "stdlib.h" -#include "math.h" +#include +#include #include "hud.h" #include "cl_util.h" #include -#ifndef M_PI -#define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h -#endif - -double sqrt(double x); - -float Length(const float *v) -{ - int i; - float length; - - length = 0; - for (i = 0; i < 3; i++) - length += v[i] * v[i]; - length = sqrt(length); // FIXME - - return length; -} - -void VectorAngles(const float *forward, float *angles) -{ - float tmp, yaw, pitch; - - if (forward[1] == 0 && forward[0] == 0) - { - yaw = 0; - if (forward[2] > 0) - pitch = 90; - else - pitch = 270; - } - else - { - yaw = (atan2(forward[1], forward[0]) * 180 / M_PI); - if (yaw < 0) - yaw += 360; - - tmp = sqrt(forward[0] * forward[0] + forward[1] * forward[1]); - pitch = (atan2(forward[2], tmp) * 180 / M_PI); - if (pitch < 0) - pitch += 360; - } - - angles[0] = pitch; - angles[1] = yaw; - angles[2] = 0; -} - -float VectorNormalize(float *v) -{ - float length, ilength; - - length = v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; - length = sqrt(length); // FIXME - - if (length) - { - ilength = 1 / length; - v[0] *= ilength; - v[1] *= ilength; - v[2] *= ilength; - } - - return length; -} - -void VectorInverse(float *v) -{ - v[0] = -v[0]; - v[1] = -v[1]; - v[2] = -v[2]; -} - -void VectorScale(const float *in, float scale, float *out) -{ - out[0] = in[0] * scale; - out[1] = in[1] * scale; - out[2] = in[2] * scale; -} - -void VectorMA(const float *veca, float scale, const float *vecb, float *vecc) -{ - vecc[0] = veca[0] + scale * vecb[0]; - vecc[1] = veca[1] + scale * vecb[1]; - vecc[2] = veca[2] + scale * vecb[2]; -} - HLSPRITE LoadSprite(const char *pszName) { int i; diff --git a/src/game/client/view.cpp b/src/game/client/view.cpp index ccdcb746..2864abcb 100644 --- a/src/game/client/view.cpp +++ b/src/game/client/view.cpp @@ -32,6 +32,7 @@ #include "player/player.h" #include "render/clrender.h" #include "ms/clglobal.h" +#include //Master Sword - viewmode testing static bool MSTestView = false; @@ -68,9 +69,6 @@ extern "C" void PM_ParticleLine(float *start, float *end, int pcolor, float life, float vert); int PM_GetVisEntInfo(int ent); int PM_GetPhysEntInfo(int ent); - void InterpolateAngles(float *start, float *end, float *output, float frac); - void NormalizeAngles(float *angles); - float AngleBetweenVectors(const float *v1, const float *v2); float vJumpOrigin[3]; float vJumpAngles[3]; @@ -255,7 +253,7 @@ float V_CalcRoll(vec3_t angles, vec3_t velocity, float rollangle, float rollspee float value; vec3_t forward, right, up; - AngleVectors(angles, forward, right, up); + AngleVectors(angles, &forward, &right, &up); side = DotProduct(velocity, right); sign = side < 0 ? -1 : 1; @@ -632,7 +630,7 @@ void V_CalcNormalRefdef(struct ref_params_s *pparams) // offsets VectorCopy(pparams->cl_viewangles, angles); - AngleVectors(angles, pparams->forward, pparams->right, pparams->up); + AngleVectors(angles, &pparams->forward, &pparams->right, &pparams->up); // don't allow cheats in multiplayer if (pparams->maxclients <= 1) @@ -655,7 +653,7 @@ void V_CalcNormalRefdef(struct ref_params_s *pparams) VectorCopy(ofs, camAngles); camAngles[ROLL] = 0; - AngleVectors(camAngles, camForward, camRight, camUp); + AngleVectors(camAngles, &camForward, &camRight, &camUp); for (i = 0; i < 3; i++) { @@ -959,7 +957,7 @@ void V_GetChaseOrigin(float *angles, float *origin, float distance, float *retur cl_entity_t *ent = NULL; // Trace back from the target using the player's view angles - AngleVectors(angles, forward, NULL, NULL); + AngleVectors(angles, &forward, NULL, NULL); VectorScale(forward, -1, forward); @@ -1385,7 +1383,7 @@ void V_GetMapFreePosition(float *cl_angles, float *origin, float *angles) zScaledTarget[1] = gHUD.m_Spectator.m_mapOrigin[1]; zScaledTarget[2] = gHUD.m_Spectator.m_mapOrigin[2] * ((90.0f - angles[0]) / 90.0f); - AngleVectors(angles, forward, NULL, NULL); + AngleVectors(angles, &forward, NULL, NULL); VectorNormalize(forward); @@ -1428,7 +1426,7 @@ void V_GetMapChasePosition(int target, float *cl_angles, float *origin, float *a origin[2] *= ((90.0f - angles[0]) / 90.0f); angles[2] = 0.0f; // don't roll angle (if chased player is dead) - AngleVectors(angles, forward, NULL, NULL); + AngleVectors(angles, &forward, NULL, NULL); VectorNormalize(forward); @@ -1719,7 +1717,7 @@ void DLLEXPORT V_CalcRefdef(struct ref_params_s *pparams) //Must recalculate this, for the extra stuff that gets rendered later. //This new calculation takes view lowers/view rotations from falling into account - EngineFunc::MakeVectors(pparams->viewangles, pparams->forward, pparams->right, pparams->up); + EngineFunc::MakeVectors(pparams->viewangles, &pparams->forward, &pparams->right, &pparams->up); screenfade_t sf; gEngfuncs.pfnGetScreenFade(&sf); diff --git a/src/game/shared/movement/pm_math.cpp b/src/game/shared/movement/pm_math.cpp index a24ba82d..d4e6bcf4 100644 --- a/src/game/shared/movement/pm_math.cpp +++ b/src/game/shared/movement/pm_math.cpp @@ -14,9 +14,9 @@ ****/ // pm_math.c -- math primitives +#include "Platform.h" #include "mathlib.h" #include "const.h" -#include // up / down #define PITCH 0 @@ -27,16 +27,15 @@ #pragma warning(disable : 4244) -vec3_t vec3_origin = {0, 0, 0}; int nanmask = 255 << 23; float anglemod(float a) { - a = (360.0 / 65536) * ((int)(a * (65536 / 360.0)) & 65535); + a = static_cast(360.0f / 65536) * (static_cast(a * static_cast(65536 / 360.0f)) & 65535); return a; } -void AngleVectors(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up) +void AngleVectors(const Vector& angles, Vector* forward, Vector* right, Vector* up) { float angle; float sr, sp, sy, cr, cp, cy; @@ -53,25 +52,25 @@ void AngleVectors(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up) if (forward) { - forward[0] = cp * cy; - forward[1] = cp * sy; - forward[2] = -sp; + forward->x = cp * cy; + forward->y = cp * sy; + forward->z = -sp; } if (right) { - right[0] = (-1 * sr * sp * cy + -1 * cr * -sy); - right[1] = (-1 * sr * sp * sy + -1 * cr * cy); - right[2] = -1 * sr * cp; + right->x = (-1 * sr * sp * cy + -1 * cr * -sy); + right->y = (-1 * sr * sp * sy + -1 * cr * cy); + right->z = -1 * sr * cp; } if (up) { - up[0] = (cr * sp * cy + -sr * -sy); - up[1] = (cr * sp * sy + -sr * cy); - up[2] = cr * cp; + up->x = (cr * sp * cy + -sr * -sy); + up->y = (cr * sp * sy + -sr * cy); + up->z = cr * cp; } } -void AngleVectorsTranspose(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up) +void AngleVectorsTranspose(const Vector& angles, Vector* forward, Vector* right, Vector* up) { float angle; float sr, sp, sy, cr, cp, cy; @@ -88,25 +87,25 @@ void AngleVectorsTranspose(const vec3_t angles, vec3_t forward, vec3_t right, ve if (forward) { - forward[0] = cp * cy; - forward[1] = (sr * sp * cy + cr * -sy); - forward[2] = (cr * sp * cy + -sr * -sy); + forward->x = cp * cy; + forward->y = (sr * sp * cy + cr * -sy); + forward->z = (cr * sp * cy + -sr * -sy); } if (right) { - right[0] = cp * sy; - right[1] = (sr * sp * sy + cr * cy); - right[2] = (cr * sp * sy + -sr * cy); + right->x = cp * sy; + right->y = (sr * sp * sy + cr * cy); + right->z = (cr * sp * sy + -sr * cy); } if (up) { - up[0] = -sp; - up[1] = sr * cp; - up[2] = cr * cp; + up->x = -sp; + up->y = sr * cp; + up->z = cr * cp; } } -void AngleMatrix(const vec3_t angles, float (*matrix)[4]) +void AngleMatrix(const float* angles, float (*matrix)[4]) { float angle; float sr, sp, sy, cr, cp, cy; @@ -136,7 +135,7 @@ void AngleMatrix(const vec3_t angles, float (*matrix)[4]) matrix[2][3] = 0.0; } -void AngleIMatrix(const vec3_t angles, float matrix[3][4]) +void AngleIMatrix(const Vector& angles, float matrix[3][4]) { float angle; float sr, sp, sy, cr, cp, cy; @@ -166,7 +165,7 @@ void AngleIMatrix(const vec3_t angles, float matrix[3][4]) matrix[2][3] = 0.0; } -void NormalizeAngles(float *angles) +void NormalizeAngles(float* angles) { int i; // Normalize angles @@ -192,7 +191,7 @@ FIXME: Use Quaternions to avoid discontinuities Frac is 0.0 to 1.0 ( i.e., should probably be clamped, but doesn't have to be ) =================== */ -void InterpolateAngles(float *start, float *end, float *output, float frac) +void InterpolateAngles(float* start, float* end, float* output, float frac) { int i; float ang1, ang2; @@ -222,19 +221,20 @@ void InterpolateAngles(float *start, float *end, float *output, float frac) NormalizeAngles(output); } + /* =================== AngleBetweenVectors =================== */ -float AngleBetweenVectors(const vec3_t v1, const vec3_t v2) +float AngleBetweenVectors(const Vector& v1, const Vector& v2) { float angle; float l1 = Length(v1); float l2 = Length(v2); - if (!l1 || !l2) + if (0 == l1 || 0 == l2) return 0.0f; angle = acos(DotProduct(v1, v2)) / (l1 * l2); @@ -243,67 +243,39 @@ float AngleBetweenVectors(const vec3_t v1, const vec3_t v2) return angle; } -void VectorTransform(const vec3_t in1, float in2[3][4], vec3_t out) +void VectorTransform(const float* in1, float in2[3][4], float* out) { - out[0] = DotProduct(in1, in2[0]) + in2[0][3]; - out[1] = DotProduct(in1, in2[1]) + in2[1][3]; - out[2] = DotProduct(in1, in2[2]) + in2[2][3]; + out[0] = DotProduct(*reinterpret_cast(in1), *reinterpret_cast(in2[0])) + in2[0][3]; + out[1] = DotProduct(*reinterpret_cast(in1), *reinterpret_cast(in2[1])) + in2[1][3]; + out[2] = DotProduct(*reinterpret_cast(in1), *reinterpret_cast(in2[2])) + in2[2][3]; } -int VectorCompare(const vec3_t v1, const vec3_t v2) +bool VectorCompare(const float* v1, const float* v2) { int i; for (i = 0; i < 3; i++) if (v1[i] != v2[i]) - return 0; + return false; - return 1; + return true; } -void VectorMA(const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc) +void VectorMA(const float* veca, float scale, const float* vecb, float* vecc) { vecc[0] = veca[0] + scale * vecb[0]; vecc[1] = veca[1] + scale * vecb[1]; vecc[2] = veca[2] + scale * vecb[2]; } -vec_t _DotProduct(vec3_t v1, vec3_t v2) -{ - return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]; -} - -void _VectorSubtract(vec3_t veca, vec3_t vecb, vec3_t out) -{ - out[0] = veca[0] - vecb[0]; - out[1] = veca[1] - vecb[1]; - out[2] = veca[2] - vecb[2]; -} - -void _VectorAdd(vec3_t veca, vec3_t vecb, vec3_t out) -{ - out[0] = veca[0] + vecb[0]; - out[1] = veca[1] + vecb[1]; - out[2] = veca[2] + vecb[2]; -} - -void _VectorCopy(vec3_t in, vec3_t out) -{ - out[0] = in[0]; - out[1] = in[1]; - out[2] = in[2]; -} - -void CrossProduct(const vec3_t v1, const vec3_t v2, vec3_t cross) +void CrossProduct(const float* v1, const float* v2, float* cross) { cross[0] = v1[1] * v2[2] - v1[2] * v2[1]; cross[1] = v1[2] * v2[0] - v1[0] * v2[2]; cross[2] = v1[0] * v2[1] - v1[1] * v2[0]; } -double sqrt(double x); - -float Length(const vec3_t v) +float Length(const float* v) { int i; float length = 0.0f; @@ -315,21 +287,21 @@ float Length(const vec3_t v) return length; } -float Distance(const vec3_t v1, const vec3_t v2) +float Distance(const float* v1, const float* v2) { - vec3_t d; + Vector d; VectorSubtract(v2, v1, d); return Length(d); } -float VectorNormalize(vec3_t v) +float VectorNormalize(float* v) { float length, ilength; length = v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; length = sqrt(length); // FIXME - if (length) + if (0 != length) { ilength = 1 / length; v[0] *= ilength; @@ -340,14 +312,14 @@ float VectorNormalize(vec3_t v) return length; } -void VectorInverse(vec3_t v) +void VectorInverse(float* v) { v[0] = -v[0]; v[1] = -v[1]; v[2] = -v[2]; } -void VectorScale(const vec3_t in, vec_t scale, vec3_t out) +void VectorScale(const float* in, float scale, float* out) { out[0] = in[0] * scale; out[1] = in[1] * scale; @@ -362,9 +334,9 @@ int Q_log2(int val) return answer; } -void VectorMatrix(vec3_t forward, vec3_t right, vec3_t up) +void VectorMatrix(const Vector& forward, Vector& right, Vector& up) { - vec3_t tmp; + Vector tmp; if (forward[0] == 0 && forward[1] == 0) { @@ -386,9 +358,9 @@ void VectorMatrix(vec3_t forward, vec3_t right, vec3_t up) VectorNormalize(up); } -void VectorAngles(const vec3_t forward, vec3_t angles) +void VectorAngles(const float* forward, float* angles) { - float tmp, yaw, pitch; + double tmp, yaw, pitch; if (forward[1] == 0 && forward[0] == 0) { @@ -421,30 +393,30 @@ ConcatTransforms ================ */ -// void ConcatTransforms(float in1[3][4], float in2[3][4], float out[3][4]) -// { -// out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] + -// in1[0][2] * in2[2][0]; -// out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] + -// in1[0][2] * in2[2][1]; -// out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] + -// in1[0][2] * in2[2][2]; -// out[0][3] = in1[0][0] * in2[0][3] + in1[0][1] * in2[1][3] + -// in1[0][2] * in2[2][3] + in1[0][3]; -// out[1][0] = in1[1][0] * in2[0][0] + in1[1][1] * in2[1][0] + -// in1[1][2] * in2[2][0]; -// out[1][1] = in1[1][0] * in2[0][1] + in1[1][1] * in2[1][1] + -// in1[1][2] * in2[2][1]; -// out[1][2] = in1[1][0] * in2[0][2] + in1[1][1] * in2[1][2] + -// in1[1][2] * in2[2][2]; -// out[1][3] = in1[1][0] * in2[0][3] + in1[1][1] * in2[1][3] + -// in1[1][2] * in2[2][3] + in1[1][3]; -// out[2][0] = in1[2][0] * in2[0][0] + in1[2][1] * in2[1][0] + -// in1[2][2] * in2[2][0]; -// out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] + -// in1[2][2] * in2[2][1]; -// out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] + -// in1[2][2] * in2[2][2]; -// out[2][3] = in1[2][0] * in2[0][3] + in1[2][1] * in2[1][3] + -// in1[2][2] * in2[2][3] + in1[2][3]; -// } \ No newline at end of file +void ConcatTransforms(float in1[3][4], float in2[3][4], float out[3][4]) +{ + out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] + + in1[0][2] * in2[2][0]; + out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] + + in1[0][2] * in2[2][1]; + out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] + + in1[0][2] * in2[2][2]; + out[0][3] = in1[0][0] * in2[0][3] + in1[0][1] * in2[1][3] + + in1[0][2] * in2[2][3] + in1[0][3]; + out[1][0] = in1[1][0] * in2[0][0] + in1[1][1] * in2[1][0] + + in1[1][2] * in2[2][0]; + out[1][1] = in1[1][0] * in2[0][1] + in1[1][1] * in2[1][1] + + in1[1][2] * in2[2][1]; + out[1][2] = in1[1][0] * in2[0][2] + in1[1][1] * in2[1][2] + + in1[1][2] * in2[2][2]; + out[1][3] = in1[1][0] * in2[0][3] + in1[1][1] * in2[1][3] + + in1[1][2] * in2[2][3] + in1[1][3]; + out[2][0] = in1[2][0] * in2[0][0] + in1[2][1] * in2[1][0] + + in1[2][2] * in2[2][0]; + out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] + + in1[2][2] * in2[2][1]; + out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] + + in1[2][2] * in2[2][2]; + out[2][3] = in1[2][0] * in2[0][3] + in1[2][1] * in2[1][3] + + in1[2][2] * in2[2][3] + in1[2][3]; +} diff --git a/src/game/shared/movement/pm_shared.cpp b/src/game/shared/movement/pm_shared.cpp index bcfa81ab..e7ab8c07 100644 --- a/src/game/shared/movement/pm_shared.cpp +++ b/src/game/shared/movement/pm_shared.cpp @@ -24,7 +24,6 @@ #include // isspace #include #include -//#include "mathlib.h" #include "const.h" #include "usercmd.h" #include "pm_defs.h" @@ -33,15 +32,7 @@ #include "pm_debug.h" #include "player/player.h" #include "filesystem_shared.h" - -extern "C" vec3_t vec3_origin; - -//Dogg -- Ripped from mathlib.h -extern "C" -{ - extern int nanmask; -#define IS_NAN(x) (((*(int *)&x) & nanmask) == nanmask) -}; +#include "mathlib.h" //----------------------------- //Master Sword ----- @@ -58,41 +49,6 @@ extern "C" extern float vJumpOrigin[3]; extern float vJumpAngles[3]; } -#else - -#define DotProduct(x, y) ((x)[0] * (y)[0] + (x)[1] * (y)[1] + (x)[2] * (y)[2]) -#define VectorSubtract(a, b, c) \ - { \ - (c)[0] = (a)[0] - (b)[0]; \ - (c)[1] = (a)[1] - (b)[1]; \ - (c)[2] = (a)[2] - (b)[2]; \ - } -#define VectorAdd(a, b, c) \ - { \ - (c)[0] = (a)[0] + (b)[0]; \ - (c)[1] = (a)[1] + (b)[1]; \ - (c)[2] = (a)[2] + (b)[2]; \ - } -#define VectorCopy(a, b) \ - { \ - (b)[0] = (a)[0]; \ - (b)[1] = (a)[1]; \ - (b)[2] = (a)[2]; \ - } -inline void VectorClear(float *a) -{ - a[0] = 0.0; - a[1] = 0.0; - a[2] = 0.0; -} -float Length(const float *v); -void VectorMA(const float *veca, float scale, const float *vecb, float *vecc); -void VectorScale(const float *in, float scale, float *out); -float VectorNormalize(float *v); -void VectorInverse(float *v); - -extern "C" vec3_t vec3_origin; -extern "C" void AngleVectors(const float *angles, float *forward, float *right, float *up); #endif IScripted *PMScript = NULL; @@ -189,12 +145,6 @@ typedef struct hull_s // double to float warning #pragma warning(disable : 4244) -// up / down -#define PITCH 0 -// left / right -#define YAW 1 -// fall over -#define ROLL 2 #define MAX_CLIENTS 32 @@ -207,6 +157,15 @@ typedef struct hull_s #define CONTENTS_TRANSLUCENT -15 +// up / down +#define PITCH 0 +// left / right +#define YAW 1 +// fall over +#define ROLL 2 + +Vector vec3_origin(0,0,0); + static vec3_t rgv3tStuckTable[54]; static int rgStuckLast[MAX_CLIENTS][2]; @@ -2310,7 +2269,7 @@ void PM_LadderMove(physent_t *pLadder) float forward = 0, right = 0; vec3_t vpn, v_right; - AngleVectors(pmove->angles, vpn, v_right, NULL); + AngleVectors(pmove->angles, &vpn, &v_right, NULL); if (pmove->cmd.buttons & IN_BACK) forward -= MAX_CLIMB_SPEED; if (pmove->cmd.buttons & IN_FORWARD) @@ -2991,7 +2950,7 @@ float PM_CalcRoll(vec3_t angles, vec3_t velocity, float rollangle, float rollspe float value; vec3_t forward, right, up; - AngleVectors(angles, forward, right, up); + AngleVectors(angles, &forward, &right, &up); side = DotProduct(velocity, right); @@ -3167,7 +3126,7 @@ void PM_PlayerMove(qboolean server) PM_ReduceTimers(); // Convert view angles to vectors - AngleVectors(pmove->angles, pmove->forward, pmove->right, pmove->up); + AngleVectors(pmove->angles, &pmove->forward, &pmove->right, &pmove->up); // PM_ShowClipBox(); @@ -3626,90 +3585,4 @@ const char* PM_GetValue(msstringlist &Params) RETURN_ANGLE("velocity", pmove->velocity) RETURN_NOTHING; -} - -#ifdef VALVE_DLL -// c++ version of the utils, ripped from the client's util.h -double sqrt(double x); - -float Length(const float *v) -{ - int i; - float length; - - length = 0; - for (i = 0; i < 3; i++) - length += v[i] * v[i]; - length = sqrt(length); // FIXME - - return length; -} - -void VectorAngles(const float *forward, float *angles) -{ - float tmp, yaw, pitch; - - if (forward[1] == 0 && forward[0] == 0) - { - yaw = 0; - if (forward[2] > 0) - pitch = 90; - else - pitch = 270; - } - else - { - yaw = (atan2(forward[1], forward[0]) * 180 / M_PI); - if (yaw < 0) - yaw += 360; - - tmp = sqrt(forward[0] * forward[0] + forward[1] * forward[1]); - pitch = (atan2(forward[2], tmp) * 180 / M_PI); - if (pitch < 0) - pitch += 360; - } - - angles[0] = pitch; - angles[1] = yaw; - angles[2] = 0; -} - -float VectorNormalize(float *v) -{ - float length, ilength; - - length = v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; - length = sqrt(length); // FIXME - - if (length) - { - ilength = 1 / length; - v[0] *= ilength; - v[1] *= ilength; - v[2] *= ilength; - } - - return length; -} - -void VectorInverse(float *v) -{ - v[0] = -v[0]; - v[1] = -v[1]; - v[2] = -v[2]; -} - -void VectorScale(const float *in, float scale, float *out) -{ - out[0] = in[0] * scale; - out[1] = in[1] * scale; - out[2] = in[2] * scale; -} - -void VectorMA(const float *veca, float scale, const float *vecb, float *vecc) -{ - vecc[0] = veca[0] + scale * vecb[0]; - vecc[1] = veca[1] + scale * vecb[1]; - vecc[2] = veca[2] + scale * vecb[2]; -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/game/shared/ms/global.cpp b/src/game/shared/ms/global.cpp index bcf7ae30..988e3812 100644 --- a/src/game/shared/ms/global.cpp +++ b/src/game/shared/ms/global.cpp @@ -23,6 +23,7 @@ #ifndef _WIN32 #include #endif +#include //#define EXTENSIVE_LOGGING //Causes EXTENSIVE logging of every dbg operation @@ -553,13 +554,15 @@ int EngineFunc::AllocString(const char* String) return ALLOC_STRING(String); } -void EngineFunc::MakeVectors(const Vector &vecAngles, float *p_vForward, float *p_vRight, float *p_vUp) +void EngineFunc::MakeVectors(const Vector &vecAngles, Vector *p_vForward, Vector *p_vRight, Vector *p_vUp) { -#ifdef VALVE_DLL - g_engfuncs.pfnAngleVectors(vecAngles, p_vForward, p_vRight, p_vUp); -#else + // not sure if this will have any undesired side effects. +//#ifdef VALVE_DLL +// g_engfuncs.pfnAngleVectors(vecAngles, p_vForward, p_vRight, p_vUp); +//#else +// AngleVectors(vecAngles, p_vForward, p_vRight, p_vUp); +//#endif AngleVectors(vecAngles, p_vForward, p_vRight, p_vUp); -#endif } float EngineFunc::CVAR_GetFloat(const char* Cvar) diff --git a/src/game/shared/ms/msdebug.h b/src/game/shared/ms/msdebug.h index 002b6399..50e2d038 100644 --- a/src/game/shared/ms/msdebug.h +++ b/src/game/shared/ms/msdebug.h @@ -41,7 +41,7 @@ class EngineFunc static void CVAR_SetFloat(const char* Cvar, float Value); static void CVAR_SetString(const char* Cvar, const char* Value); #ifdef VECTOR_H - static void MakeVectors(const Vector &vecAngles, float *p_vForward, float *p_vRight = NULL, float *p_vUp = NULL); + static void MakeVectors(const Vector &vecAngles, Vector *p_vForward, Vector *p_vRight = NULL, Vector *p_vUp = NULL); #endif #ifdef CVARDEF_H #ifndef VALVE_DLL diff --git a/src/game/shared/ms/script.cpp b/src/game/shared/ms/script.cpp index 68f69270..0ee2f575 100644 --- a/src/game/shared/ms/script.cpp +++ b/src/game/shared/ms/script.cpp @@ -747,7 +747,7 @@ msstring CScript::ScriptGetter_Cone(msstring& FullName, msstring& ParserName, ms float ConeFOV = cosf(atof(Params[3]) / 2.0f); Vector vForward; - EngineFunc::MakeVectors(ConeAngles, vForward, NULL, NULL); + EngineFunc::MakeVectors(ConeAngles, &vForward, NULL, NULL); Vector vec2LOS = PointOrigin - ConeOrigin; @@ -3620,7 +3620,7 @@ msstring CScript::ScriptGetter_RelVel(msstring& FullName, msstring& ParserName, } Vector vForward, vRight, vUp; - EngineFunc::MakeVectors(Angle, vForward, vRight, vUp); + EngineFunc::MakeVectors(Angle, &vForward, &vRight, &vUp); Vector Final = vRight * RelVel.x + vForward * RelVel.y + vUp * RelVel.z; diff --git a/src/game/shared/ms/scriptcmds.cpp b/src/game/shared/ms/scriptcmds.cpp index a0fd6c94..36f05776 100644 --- a/src/game/shared/ms/scriptcmds.cpp +++ b/src/game/shared/ms/scriptcmds.cpp @@ -1035,7 +1035,7 @@ const char* CBaseEntity::GetProp(CBaseEntity *pTarget, msstring &FullParams, mss else if (Prop == "forwardspeed") { Vector vForward; - EngineFunc::MakeVectors(pTarget->pev->v_angle, vForward, NULL, NULL); + EngineFunc::MakeVectors(pTarget->pev->v_angle, &vForward, NULL, NULL); RETURN_FLOAT(DotProduct(pTarget->pev->velocity, vForward)); } else if (Prop == "absmin") //Thothie DEC2014_12 diff --git a/src/game/shared/ms/sharedutil.cpp b/src/game/shared/ms/sharedutil.cpp index bdec66a5..1576b1f0 100644 --- a/src/game/shared/ms/sharedutil.cpp +++ b/src/game/shared/ms/sharedutil.cpp @@ -89,7 +89,7 @@ Vector GetRelativePos(Vector &Ang, Vector &Dir) { Vector vForward, vRight, vUp, vPosition; - EngineFunc::MakeVectors(Ang, vForward, vRight, vUp); //Use the mutal client/server friendly version of this + EngineFunc::MakeVectors(Ang, &vForward, &vRight, &vUp); //Use the mutal client/server friendly version of this vPosition = vRight * Dir.x; vPosition += vForward * Dir.y; diff --git a/src/game/shared/voice_status.cpp b/src/game/shared/voice_status.cpp index 9593bfe9..897385b9 100644 --- a/src/game/shared/voice_status.cpp +++ b/src/game/shared/voice_status.cpp @@ -23,6 +23,7 @@ #include "vgui_helpers.h" #include "VGUI_MouseCode.h" #include "filesystem_shared.h" +#include "mathlib.h" using namespace vgui; diff --git a/src/game/shared/weapons/giattack.cpp b/src/game/shared/weapons/giattack.cpp index e8bc8a9c..1d696320 100644 --- a/src/game/shared/weapons/giattack.cpp +++ b/src/game/shared/weapons/giattack.cpp @@ -1045,7 +1045,7 @@ void CGenericItem::ChargeThrowProj() Vector vStartPos = GetRelativePos(vAngle, vOffsets); vStartPos += vOrigin; - EngineFunc::MakeVectors(vAngle, vForward, NULL, NULL); + EngineFunc::MakeVectors(vAngle, &vForward, NULL, NULL); float flRange = CurrentAttack->flRange * flTimeHeldAdjusted; Vector vTemp = vForward * flRange; pProjectile->TossProjectile(this, vStartPos, vTemp); From 32c97e397f38e9be55b0dbcbc5f493a90df09518 Mon Sep 17 00:00:00 2001 From: Saint Wish <6036821+SaintWish@users.noreply.github.com> Date: Sun, 22 Feb 2026 01:24:43 -0600 Subject: [PATCH 3/4] refactor PM_Stuck stuff --- src/game/client/view.cpp | 12 +-- src/game/shared/movement/pm_shared.cpp | 132 ++++++++++++++++--------- src/game/shared/movement/pm_shared.h | 4 +- 3 files changed, 94 insertions(+), 54 deletions(-) diff --git a/src/game/client/view.cpp b/src/game/client/view.cpp index 2864abcb..6aee0ffd 100644 --- a/src/game/client/view.cpp +++ b/src/game/client/view.cpp @@ -55,9 +55,9 @@ extern "C" int iIsSpectator; } -#ifndef M_PI -#define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h -#endif +int PM_GetVisEntInfo(int ent); +void PM_ParticleLine(float *start, float *end, int pcolor, float life, float vert); +int PM_GetPhysEntInfo(int ent); extern "C" { @@ -65,11 +65,7 @@ extern "C" void CL_CameraOffset(float *ofs); void DLLEXPORT V_CalcRefdef(struct ref_params_s *pparams); - - void PM_ParticleLine(float *start, float *end, int pcolor, float life, float vert); - int PM_GetVisEntInfo(int ent); - int PM_GetPhysEntInfo(int ent); - + float vJumpOrigin[3]; float vJumpAngles[3]; } diff --git a/src/game/shared/movement/pm_shared.cpp b/src/game/shared/movement/pm_shared.cpp index e7ab8c07..c49c32f0 100644 --- a/src/game/shared/movement/pm_shared.cpp +++ b/src/game/shared/movement/pm_shared.cpp @@ -1807,7 +1807,39 @@ allow for the cut precision of the net coordinates */ #define PM_CHECKSTUCK_MINTIME 0.05 // Don't check again too quickly. -int PM_CheckStuck(void) +bool PM_TryToUnstuck(Vector base) +{ + float x, y, z; + float xystep = 8.0; + float zstep = 18.0; + float xyminmax = xystep; + float zminmax = 4 * zstep; + Vector test; + + for (z = 0; z <= zminmax; z += zstep) + { + for (x = -xyminmax; x <= xyminmax; x += xystep) + { + for (y = -xyminmax; y <= xyminmax; y += xystep) + { + test = base; + test[0] += x; + test[1] += y; + test[2] += z; + + if (pmove->PM_TestPlayerPosition(test, NULL) == -1) + { + VectorCopy(test, pmove->origin); + return false; + } + } + } + } + + return true; +} + +bool PM_CheckStuck(void) { vec3_t base; vec3_t offset; @@ -1825,7 +1857,7 @@ int PM_CheckStuck(void) if (hitent == -1) { PM_ResetStuckOffsets(pmove->player_index, pmove->server); - return 0; + return false; } VectorCopy(pmove->origin, base); @@ -1851,28 +1883,28 @@ int PM_CheckStuck(void) PM_ResetStuckOffsets(pmove->player_index, pmove->server); VectorCopy(test, pmove->origin); - return 0; + return false; } nReps++; } while (nReps < 54); } } - // Only an issue on the client. - - if (pmove->server) - idx = 0; - else - idx = 1; - - fTime = pmove->Sys_FloatTime(); - // Too soon? - if (rgStuckCheckTime[pmove->player_index][idx] >= - (fTime - PM_CHECKSTUCK_MINTIME)) + // Always check if we've just changed levels. + if (!(pmove->server != 0 && g_CheckForPlayerStuck)) { - return 1; + // TODO: not really necessary to have separate arrays for client and server since the code is separate anyway. + const int idx = 0 != pmove->server ? 0 : 1; + + const float fTime = pmove->Sys_FloatTime(); + // Too soon? + if (rgStuckCheckTime[pmove->player_index][idx] >= + (fTime - PM_CHECKSTUCK_MINTIME)) + { + return true; + } + rgStuckCheckTime[pmove->player_index][idx] = fTime; } - rgStuckCheckTime[pmove->player_index][idx] = fTime; pmove->PM_StuckTouch(hitent, &traceresult); @@ -1888,43 +1920,38 @@ int PM_CheckStuck(void) if (i >= 27) VectorCopy(test, pmove->origin); - return 0; + return false; } - // If player is flailing while stuck in another player ( should never happen ), then see - // if we can't "unstick" them forceably. - if (pmove->cmd.buttons & (IN_JUMP | IN_DUCK | IN_ATTACK) && (pmove->physents[hitent].player != 0)) + // Try to unstuck the player after a level change. + // This only works in singleplayer. In multiplayer there it's too unreliable to try, so only the first player gets unstuck. + if (pmove->server != 0 && g_CheckForPlayerStuck) { - float x, y, z; - float xystep = 8.0; - float zstep = 18.0; - float xyminmax = xystep; - float zminmax = 4 * zstep; + g_CheckForPlayerStuck = false; - for (z = 0; z <= zminmax; z += zstep) + // Are we stuck inside the world? + if (hitent == 0) { - for (x = -xyminmax; x <= xyminmax; x += xystep) + if (!PM_TryToUnstuck(base)) { - for (y = -xyminmax; y <= xyminmax; y += xystep) - { - VectorCopy(base, test); - test[0] += x; - test[1] += y; - test[2] += z; - - if (pmove->PM_TestPlayerPosition(test, NULL) == -1) - { - VectorCopy(test, pmove->origin); - return 0; - } - } + return false; } } } + // If player is flailing while stuck in another player ( should never happen ), then see + // if we can't "unstick" them forceably. + if ((pmove->cmd.buttons & (IN_JUMP | IN_DUCK | IN_ATTACK)) != 0 && (pmove->physents[hitent].player != 0)) + { + if (!PM_TryToUnstuck(base)) + { + return false; + } + } + //VectorCopy (base, pmove->origin); - return 1; + return true; } /* @@ -3143,7 +3170,13 @@ void PM_PlayerMove(qboolean server) { if (PM_CheckStuck()) { - return; // Can't move, we're stuck + // Let the user try to duck to get unstuck + PM_Duck(); + + if (PM_CheckStuck()) + { + return; // Can't move, we're stuck + } } } @@ -3476,7 +3509,7 @@ invoked by each side as appropriate. There should be no distinction, internally and client. This will ensure that prediction behaves appropriately. */ -void PM_Move(struct playermove_s *ppmove, int server) +void PM_Move(struct playermove_s *ppmove, qboolean server) { assert(pm_shared_initialized); @@ -3491,7 +3524,7 @@ void PM_Move(struct playermove_s *ppmove, int server) PMScript = HUDScript; #endif - PM_PlayerMove((server != 0) ? true : false); + PM_PlayerMove(server); if (pmove->onground != -1) { @@ -3511,7 +3544,16 @@ void PM_Move(struct playermove_s *ppmove, int server) PMScript = NULL; } -extern "C" int PM_GetPhysEntInfo(int ent) +int PM_GetVisEntInfo(int ent) +{ + if (ent >= 0 && ent <= pmove->numvisent) + { + return pmove->visents[ent].info; + } + return -1; +} + +int PM_GetPhysEntInfo(int ent) { if (ent >= 0 && ent <= pmove->numphysent) { diff --git a/src/game/shared/movement/pm_shared.h b/src/game/shared/movement/pm_shared.h index 43cfbef4..4f184f89 100644 --- a/src/game/shared/movement/pm_shared.h +++ b/src/game/shared/movement/pm_shared.h @@ -21,7 +21,7 @@ #pragma once void PM_Init(struct playermove_s *ppmove); -void PM_Move(struct playermove_s *ppmove, int server); +void PM_Move(struct playermove_s *ppmove, qboolean server); char PM_FindTextureType(char *name); /** @@ -40,4 +40,6 @@ char* memfgets(const byte* pMemFile, std::size_t fileSize, std::size_t& filePos, #define OBS_MAP_FREE 5 #define OBS_MAP_CHASE 6 +inline bool g_CheckForPlayerStuck = false; + #endif From a143d367ac8eed72b5e27aab5ca64efb02f52dcc Mon Sep 17 00:00:00 2001 From: Saint Wish <6036821+SaintWish@users.noreply.github.com> Date: Mon, 23 Feb 2026 02:54:07 -0600 Subject: [PATCH 4/4] fix some redefinition for vectors --- src/game/client/hud_spectator.cpp | 2 -- src/game/client/render/studiomodelrenderer.cpp | 4 ---- src/game/shared/movement/pm_shared.cpp | 2 -- 3 files changed, 8 deletions(-) diff --git a/src/game/client/hud_spectator.cpp b/src/game/client/hud_spectator.cpp index b19b9661..fe79639f 100644 --- a/src/game/client/hud_spectator.cpp +++ b/src/game/client/hud_spectator.cpp @@ -41,8 +41,6 @@ extern "C" float vJumpAngles[3]; extern void V_GetInEyePos(int entity, float *origin, float *angles); extern void V_ResetChaseCam(); extern void V_GetChasePos(int target, float *cl_angles, float *origin, float *angles); -extern void VectorAngles(const float *forward, float *angles); -extern void NormalizeAngles(float *angles); extern float *GetClientColor(int clientIndex); extern vec3_t v_origin; // last view origin diff --git a/src/game/client/render/studiomodelrenderer.cpp b/src/game/client/render/studiomodelrenderer.cpp index ffe7a40d..917f33ed 100644 --- a/src/game/client/render/studiomodelrenderer.cpp +++ b/src/game/client/render/studiomodelrenderer.cpp @@ -37,16 +37,12 @@ #include // Header File For The OpenGL32 Library #include -extern "C" int nanmask; -#define IS_NAN(x) (((*(int *)&x) & nanmask) == nanmask) - // Global engine <-> studio model rendering code interface engine_studio_api_t IEngineStudio; modelinfo_t CModelMgr::m_ModelInfo[4096]; void Print(const char* szFmt, ...); -void VectorAngles(const float* forward, float* angles); int ViewModel_ExclusiveViewHand = -1; void ViewModel_InactiveModelVisible(bool fVisible, const cl_entity_s* ActiveEntity) diff --git a/src/game/shared/movement/pm_shared.cpp b/src/game/shared/movement/pm_shared.cpp index c49c32f0..bf6086cc 100644 --- a/src/game/shared/movement/pm_shared.cpp +++ b/src/game/shared/movement/pm_shared.cpp @@ -1845,8 +1845,6 @@ bool PM_CheckStuck(void) vec3_t offset; vec3_t test; int hitent; - int idx; - float fTime; int i; pmtrace_t traceresult;