From 3e64b2c1f955ef4ad6187e0a699c72826878258e Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 24 Mar 2024 20:48:57 +0000 Subject: [PATCH 1/2] VectorLength reduces complexity. --- src/common/shared/shared.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/common/shared/shared.c b/src/common/shared/shared.c index 34aa155e..54fb139c 100644 --- a/src/common/shared/shared.c +++ b/src/common/shared/shared.c @@ -577,19 +577,9 @@ double sqrt(double x); vec_t VectorLength(vec3_t v) { - int i; - float length; - - length = 0; - - for (i = 0; i < 3; i++) - { - length += v[i] * v[i]; - } - - length = (float)sqrt(length); - - return length; + return sqrtf((v[0] * v[0]) + + (v[1] * v[1]) + + (v[2] * v[2])); } void From c134d0127da1e27cd0b91d664bb02bf094afb5a2 Mon Sep 17 00:00:00 2001 From: BjossiAlfreds Date: Sun, 31 Mar 2024 10:45:31 +0000 Subject: [PATCH 2/2] Added cvar cl_laseralpha and documentation in cvarlist --- doc/040_cvarlist.md | 5 +++++ src/client/cl_entities.c | 11 ++++++++++- src/client/cl_main.c | 2 ++ src/client/cl_tempentities.c | 12 +++++++++++- src/client/header/client.h | 1 + 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/doc/040_cvarlist.md b/doc/040_cvarlist.md index 64427688..54e77c2c 100644 --- a/doc/040_cvarlist.md +++ b/doc/040_cvarlist.md @@ -120,6 +120,11 @@ Set `0` by default. * **cl_kickangles**: If set to `0` angle kicks (weapon recoil, damage hits and the like) are ignored. Cheat-protected. Defaults to `1`. +* **cl_laseralpha**: Controls how see-through laserbeams are. + The value ranges from 0.0 to 1.0, from completely invisible to + completely opaque. So higher value means better visibility. + Defaults to `0.3`. + * **cl_limitsparksounds**: If set to `1` the number of sound generated when shooting into power screen and power shields is limited to 16. This works around global volume drops in some OpenAL implementations diff --git a/src/client/cl_entities.c b/src/client/cl_entities.c index f26d00ab..af967f74 100644 --- a/src/client/cl_entities.c +++ b/src/client/cl_entities.c @@ -139,8 +139,17 @@ CL_AddPacketEntities(frame_t *frame) /* tweak the color of beams */ if (renderfx & RF_BEAM) { + ent.alpha = cl_laseralpha->value; + if (ent.alpha < 0.0f) + { + ent.alpha = 0.0f; + } + else if (ent.alpha > 1.0f) + { + ent.alpha = 1.0f; + } + /* the four beam colors are encoded in 32 bits of skinnum (hack) */ - ent.alpha = 0.30f; ent.skinnum = (s1->skinnum >> ((randk() % 4) * 8)) & 0xff; ent.model = NULL; } diff --git a/src/client/cl_main.c b/src/client/cl_main.c index 4fe1f3f7..1d5b1132 100644 --- a/src/client/cl_main.c +++ b/src/client/cl_main.c @@ -50,6 +50,7 @@ cvar_t *cl_add_lights; cvar_t *cl_add_entities; cvar_t *cl_add_blend; cvar_t *cl_kickangles; +cvar_t *cl_laseralpha; cvar_t *cl_shownet; cvar_t *cl_showmiss; @@ -515,6 +516,7 @@ CL_InitLocal(void) cl_predict = Cvar_Get("cl_predict", "1", 0); cl_showfps = Cvar_Get("cl_showfps", "0", CVAR_ARCHIVE); cl_showspeed = Cvar_Get("cl_showspeed", "0", CVAR_ARCHIVE); + cl_laseralpha = Cvar_Get("cl_laseralpha", "0.3", 0); cl_upspeed = Cvar_Get("cl_upspeed", "200", 0); cl_forwardspeed = Cvar_Get("cl_forwardspeed", "200", 0); diff --git a/src/client/cl_tempentities.c b/src/client/cl_tempentities.c index b9ef4b35..e5ef4bbd 100644 --- a/src/client/cl_tempentities.c +++ b/src/client/cl_tempentities.c @@ -492,10 +492,20 @@ CL_ParseLaser(int colors) { if (l->endtime < cl.time) { + float alpha = cl_laseralpha->value; + if (alpha < 0.0f) + { + alpha = 0.0f; + } + else if (alpha > 1.0f) + { + alpha = 1.0f; + } + l->ent.flags = RF_TRANSLUCENT | RF_BEAM; VectorCopy(start, l->ent.origin); VectorCopy(end, l->ent.oldorigin); - l->ent.alpha = 0.30f; + l->ent.alpha = alpha; l->ent.skinnum = (colors >> ((randk() % 4) * 8)) & 0xff; l->ent.model = NULL; l->ent.frame = 4; diff --git a/src/client/header/client.h b/src/client/header/client.h index 9f57d3d5..0cdef885 100644 --- a/src/client/header/client.h +++ b/src/client/header/client.h @@ -316,6 +316,7 @@ extern cvar_t *vid_renderer; extern cvar_t *cl_kickangles; extern cvar_t *cl_r1q2_lightstyle; extern cvar_t *cl_limitsparksounds; +extern cvar_t *cl_laseralpha; typedef struct {