From 7192176e101b0af7185e7a7477a846c2845946f2 Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Wed, 12 Aug 2020 14:54:09 +0000 Subject: [PATCH] Make V_CalcRoll a common function. Add sv_rollangle and sv_rollspeed cvars. This allows V_Init to move to client code. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12897 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_ents_qw.c | 5 ++++- cl_main.c | 2 +- client.h | 1 - common.c | 27 +++++++++++++++++++++++++++ common.h | 2 ++ host.c | 1 - sv_main.c | 6 ++++++ sv_user.c | 4 +++- view.c | 32 +------------------------------- 9 files changed, 44 insertions(+), 36 deletions(-) diff --git a/cl_ents_qw.c b/cl_ents_qw.c index e21c7a21..2656dbc0 100644 --- a/cl_ents_qw.c +++ b/cl_ents_qw.c @@ -40,6 +40,9 @@ static void QW_TranslateEffects(entity_state_t *s, int qweffects) s->effects |= EF_DIMLIGHT; } +extern cvar_t cl_rollangle; +extern cvar_t cl_rollspeed; + void EntityStateQW_ReadPlayerUpdate(void) { int slot = MSG_ReadByte(&cl_message); @@ -130,7 +133,7 @@ void EntityStateQW_ReadPlayerUpdate(void) s->angles[0] = viewangles[0] * -0.0333; s->angles[1] = viewangles[1]; s->angles[2] = 0; - s->angles[2] = V_CalcRoll(s->angles, velocity)*4; + s->angles[2] = Com_CalcRoll(s->angles, velocity, cl_rollangle.value, cl_rollspeed.value)*4; // if this is an update on our player, update interpolation state if (enumber == cl.playerentity) diff --git a/cl_main.c b/cl_main.c index 517d3883..6ba4bd0c 100644 --- a/cl_main.c +++ b/cl_main.c @@ -2928,7 +2928,7 @@ void CL_Init (void) S_Init(); CDAudio_Init(); Key_Init(); - + V_Init(); cls.levelmempool = Mem_AllocPool("client (per-level memory)", 0, NULL); cls.permanentmempool = Mem_AllocPool("client (long term memory)", 0, NULL); diff --git a/client.h b/client.h index 159d3233..a9a1eb36 100644 --- a/client.h +++ b/client.h @@ -1645,7 +1645,6 @@ void V_StartPitchDrift_f(cmd_state_t *cmd); void V_StopPitchDrift (void); void V_Init (void); -float V_CalcRoll (const vec3_t angles, const vec3_t velocity); void V_UpdateBlends (void); void V_ParseDamage (void); diff --git a/common.c b/common.c index 9513239f..03b7087e 100644 --- a/common.c +++ b/common.c @@ -884,6 +884,33 @@ int COM_CheckParm (const char *parm) return 0; } +/* +=============== +Com_CalcRoll + +Used by view and sv_user +=============== +*/ +float Com_CalcRoll (const vec3_t angles, const vec3_t velocity, const vec_t angleval, const vec_t velocityval) +{ + vec3_t right; + float sign; + float side; + + AngleVectors (angles, NULL, right, NULL); + side = DotProduct (velocity, right); + sign = side < 0 ? -1 : 1; + side = fabs(side); + + if (side < velocityval) + side = side * angleval / velocityval; + else + side = angleval; + + return side*sign; + +} + //=========================================================================== /* diff --git a/common.h b/common.h index f05450f9..15ca90d0 100644 --- a/common.h +++ b/common.h @@ -382,5 +382,7 @@ size_t base64_encode(unsigned char *buf, size_t buflen, size_t outbuflen); #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) +float Com_CalcRoll (const vec3_t angles, const vec3_t velocity, const vec_t angleval, const vec_t velocityval); + #endif diff --git a/host.c b/host.c index c9a0ca3f..911b29bf 100644 --- a/host.c +++ b/host.c @@ -701,7 +701,6 @@ static void Host_Init (void) Mod_Init(); World_Init(); SV_Init(); - V_Init(); // some cvars needed by server player physics (cl_rollangle etc) Host_InitLocal(); Host_ServerOptions(); diff --git a/sv_main.c b/sv_main.c index a7a99dea..c2419941 100644 --- a/sv_main.c +++ b/sv_main.c @@ -161,6 +161,9 @@ cvar_t teamplay = {CVAR_SERVER | CVAR_NOTIFY, "teamplay","0", "teamplay mode, va cvar_t timelimit = {CVAR_SERVER | CVAR_NOTIFY, "timelimit","0", "ends level at this time (in minutes)"}; cvar_t sv_threaded = {CVAR_SERVER, "sv_threaded", "0", "enables a separate thread for server code, improving performance, especially when hosting a game while playing, EXPERIMENTAL, may be crashy"}; +cvar_t sv_rollspeed = {CVAR_CLIENT, "sv_rollspeed", "200", "how much strafing is necessary to tilt the view"}; +cvar_t sv_rollangle = {CVAR_CLIENT, "sv_rollangle", "2.0", "how much to tilt the view when strafing"}; + cvar_t saved1 = {CVAR_SERVER | CVAR_SAVE, "saved1", "0", "unused cvar in quake that is saved to config.cfg on exit, can be used by mods"}; cvar_t saved2 = {CVAR_SERVER | CVAR_SAVE, "saved2", "0", "unused cvar in quake that is saved to config.cfg on exit, can be used by mods"}; cvar_t saved3 = {CVAR_SERVER | CVAR_SAVE, "saved3", "0", "unused cvar in quake that is saved to config.cfg on exit, can be used by mods"}; @@ -583,6 +586,9 @@ void SV_Init (void) Cvar_RegisterVariable (&timelimit); Cvar_RegisterVariable (&sv_threaded); + Cvar_RegisterVariable (&sv_rollangle); + Cvar_RegisterVariable (&sv_rollspeed); + Cvar_RegisterVariable (&saved1); Cvar_RegisterVariable (&saved2); Cvar_RegisterVariable (&saved3); diff --git a/sv_user.c b/sv_user.c index d6cd9aa0..57fc14b7 100644 --- a/sv_user.c +++ b/sv_user.c @@ -25,6 +25,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static usercmd_t usercmd; extern cvar_t sv_autodemo_perclient; +extern cvar_t sv_rollangle; +extern cvar_t sv_rollspeed; /* ================== @@ -606,7 +608,7 @@ void SV_ClientThink (void) VectorAdd (PRVM_serveredictvector(host_client->edict, v_angle), PRVM_serveredictvector(host_client->edict, punchangle), v_angle); VectorCopy(PRVM_serveredictvector(host_client->edict, angles), angles); VectorCopy(PRVM_serveredictvector(host_client->edict, velocity), velocity); - PRVM_serveredictvector(host_client->edict, angles)[ROLL] = V_CalcRoll (angles, velocity)*4; + PRVM_serveredictvector(host_client->edict, angles)[ROLL] = Com_CalcRoll (angles, velocity, sv_rollangle.value, sv_rollspeed.value)*4; if (!PRVM_serveredictfloat(host_client->edict, fixangle)) { PRVM_serveredictvector(host_client->edict, angles)[PITCH] = -v_angle[PITCH]/3; diff --git a/view.c b/view.c index 315738c2..d7b1ac74 100644 --- a/view.c +++ b/view.c @@ -146,36 +146,6 @@ float v_dmg_time, v_dmg_roll, v_dmg_pitch; int cl_punchangle_applied; -/* -=============== -V_CalcRoll - -Used by view and sv_user -=============== -*/ -float V_CalcRoll (const vec3_t angles, const vec3_t velocity) -{ - vec3_t right; - float sign; - float side; - float value; - - AngleVectors (angles, NULL, right, NULL); - side = DotProduct (velocity, right); - sign = side < 0 ? -1 : 1; - side = fabs(side); - - value = cl_rollangle.value; - - if (side < cl_rollspeed.value) - side = side * value / cl_rollspeed.value; - else - side = value; - - return side*sign; - -} - void V_StartPitchDrift (void) { if (cl.laststop == cl.time) @@ -692,7 +662,7 @@ void V_CalcRefdefUsing (const matrix4x4_t *entrendermatrix, const vec3_t clviewa VectorAdd(viewangles, cl.punchangle, viewangles); cl_punchangle_applied = 1; } - viewangles[ROLL] += V_CalcRoll(clviewangles, clvelocity); + viewangles[ROLL] += Com_CalcRoll(clviewangles, clvelocity, cl_rollangle.value, cl_rollspeed.value); if (v_dmg_time > 0) { -- 2.39.2