From: bones_was_here Date: Tue, 22 Nov 2022 03:50:09 +0000 (+1000) Subject: Implement cl_gunoffset: adjusts position of first person weapon viewmodel X-Git-Tag: xonotic-v0.8.6~235^2~10 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f61c16f86598c7ee086d81c106d14457bc665942;p=xonotic%2Fxonotic-data.pk3dir.git Implement cl_gunoffset: adjusts position of first person weapon viewmodel Fixes first person viewmodel casings being drawn on spectating clients with r_drawviewmodel 0 set. Fixes casing bitflag(s) being sent to clients other than the intended one(s). Includes casing-related refactoring. --- diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index fce90d7bf..c61a86e2d 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -313,6 +313,7 @@ void viewmodel_draw(entity this) { this.name_last = name; CL_WeaponEntity_SetModel(this, name, swap); + this.origin += autocvar_cl_gunoffset; this.viewmodel_origin = this.origin; this.viewmodel_angles = this.angles; } diff --git a/qcsrc/client/view.qh b/qcsrc/client/view.qh index 45959383b..cd33ebfb6 100644 --- a/qcsrc/client/view.qh +++ b/qcsrc/client/view.qh @@ -92,6 +92,7 @@ vector autocvar_cl_eventchase_viewoffset = '0 0 20'; string autocvar__togglezoom; int autocvar_cl_nade_timer; bool autocvar_r_drawviewmodel; +vector autocvar_cl_gunoffset; void calc_followmodel_ofs(entity view); diff --git a/qcsrc/common/effects/qc/casings.qc b/qcsrc/common/effects/qc/casings.qc index c0c7f5ac9..08864459d 100644 --- a/qcsrc/common/effects/qc/casings.qc +++ b/qcsrc/common/effects/qc/casings.qc @@ -22,10 +22,18 @@ void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float ran FOREACH_CLIENT(true, { if (!(CS_CVAR(it).cvar_cl_casings)) continue; - if (it == casingowner && !(CS_CVAR(it).cvar_r_drawviewmodel)) - continue; - msg_entity = it; + casingtype &= 0x3F; // reset any bitflags that were set for the previous client + + if (it == casingowner || (IS_SPEC(it) && it.enemy == casingowner)) + { + if (!(CS_CVAR(it).cvar_r_drawviewmodel)) + continue; + + casingtype |= 0x40; // client will apply autocvar_cl_gunoffset in first person + } + + msg_entity = it; // sound_allowed checks this if (!sound_allowed(MSG_ONE, it)) casingtype |= 0x80; // silent @@ -133,27 +141,29 @@ void Casing_Damage(entity this, float thisdmg, int hittype, vector org, vector t NET_HANDLE(casings, bool isNew) { - int _state = ReadByte(); - vector org = ReadVector(); - vector vel = decompressShortVector(ReadShort()); - vector ang; - ang_x = ReadByte() * 360 / 256; - ang_y = ReadByte() * 360 / 256; - ang_z = ReadByte() * 360 / 256; + Casing casing = ListNewChildRubble(CasingsNGibs, new(casing)); + + casing.state = ReadByte(); + casing.origin = ReadVector(); + casing.velocity = decompressShortVector(ReadShort()); + casing.angles_x = ReadByte() * 360 / 256; + casing.angles_y = ReadByte() * 360 / 256; + casing.angles_z = ReadByte() * 360 / 256; + return = true; - Casing casing = ListNewChildRubble(CasingsNGibs, new(casing)); - casing.silent = (_state & 0x80); - casing.state = (_state & 0x7F); - casing.origin = org; + casing.silent = casing.state & 0x80; + if (casing.state & 0x40 && !autocvar_chase_active) + casing.origin += autocvar_cl_gunoffset.x * v_forward + - autocvar_cl_gunoffset.y * v_right + + autocvar_cl_gunoffset.z * v_up; + casing.state &= 0x3F; // the 2 most significant bits are reserved for the silent and casingowner bitflags + setorigin(casing, casing.origin); - casing.velocity = vel; - casing.angles = ang; casing.drawmask = MASK_NORMAL; - casing.draw = Casing_Draw; if (isNew) IL_PUSH(g_drawables, casing); - casing.velocity = casing.velocity + 2 * prandomvec(); + casing.velocity += 2 * prandomvec(); casing.avelocity = '0 250 0' + 100 * prandomvec(); set_movetype(casing, MOVETYPE_BOUNCE); casing.bouncefactor = 0.25; diff --git a/xonotic-client.cfg b/xonotic-client.cfg index d427b0f5a..f85a05fa0 100644 --- a/xonotic-client.cfg +++ b/xonotic-client.cfg @@ -307,6 +307,7 @@ r_shadow_realtime_world_importlightentitiesfrommap 0 // Whether build process us cl_decals_fadetime 5 cl_decals_time 1 seta cl_gunalign 3 "Gun alignment; 1 = center, 3 = right, 4 = left; requires reconnect" +seta cl_gunoffset "0 0 0" "Adjust the weapon viewmodel position, applies only to your own first person view and is relative to cl_gunalign" seta cl_nogibs 0 "reduce number of violence effects, or remove them totally" seta cl_particlegibs 0 "simpler gibs" seta cl_gibs_damageforcescale 3.5 "force to push around gibs"