From: bones_was_here Date: Mon, 12 Jun 2023 18:38:36 +0000 (+1000) Subject: items: alpha calculation rework X-Git-Tag: xonotic-v0.8.6~7^2~12 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6484368763b19e29cb26aed6f1aaa9f175cd5550;p=xonotic%2Fxonotic-data.pk3dir.git items: alpha calculation rework - more efficient networking - clients can now customise the range of the fade effect (as well as disable it) - clients can no longer override server maxdist setting (was unfair) - replaces vehicle ghost items with a weapon_stay-based effect Fixes #2059 --- diff --git a/qcsrc/client/items/items.qc b/qcsrc/client/items/items.qc index f4abe9989..a10ac41e4 100644 --- a/qcsrc/client/items/items.qc +++ b/qcsrc/client/items/items.qc @@ -8,35 +8,10 @@ #include #include -bool autocvar_cl_ghost_items_vehicle = true; .vector item_glowmod; .bool item_simple; // probably not really needed, but better safe than sorry .float alpha; .bool pushable; -void Item_SetAlpha(entity this) -{ - bool veh_hud = (hud && autocvar_cl_ghost_items_vehicle); - - if(!veh_hud && (this.ItemStatus & ITS_AVAILABLE)) - { - this.alpha = 1; - this.colormod = '1 1 1'; - this.glowmod = this.item_glowmod; - } - else - { - this.alpha = autocvar_cl_ghost_items; - this.colormod = this.glowmod = autocvar_cl_ghost_items_color; - } - - if((!veh_hud) && (this.ItemStatus & ITS_STAYWEP)) - { - this.colormod = this.glowmod = autocvar_cl_weapon_stay_color; - this.alpha = autocvar_cl_weapon_stay_alpha; - } - - this.drawmask = ((this.alpha <= 0) ? 0 : MASK_NORMAL); -} void ItemDraw(entity this) { @@ -80,38 +55,51 @@ void ItemDraw(entity this) } } - Item_SetAlpha(this); -} - -void Item_PreDraw(entity this) -{ - if(warpzone_warpzones_exist) + // set alpha based on distance + this.alpha = 1; + this.drawmask = 0; + if(this.fade_end && !warpzone_warpzones_exist) { - setpredraw(this, func_null); // no need to keep running this - return; + vector org = getpropertyvec(VF_ORIGIN); + if(vdist(org - this.origin, >, this.fade_end)) + this.alpha = 0; // save on some processing + else if(autocvar_cl_items_fadedist > 0) + { + this.fade_start = max(500, this.fade_end - autocvar_cl_items_fadedist); + if(vdist(org - this.origin, >, this.fade_start)) + this.alpha = bound(0, (this.fade_end - vlen(org - this.origin - 0.5 * (this.mins + this.maxs))) / (this.fade_end - this.fade_start), 1); + } } - float alph; - vector org = getpropertyvec(VF_ORIGIN); - //if(!checkpvs(org, this)) // this makes sense as long as we don't support recursive warpzones - //alph = 0; // this shouldn't be needed, since items behind walls are culled anyway - if(this.fade_start) + + if(!this.alpha) + return; + + // modify alpha based on availability and vehicle hud + if(this.ItemStatus & ITS_AVAILABLE) { - if(vdist(org - this.origin, >, this.fade_end)) - alph = 0; // save on some processing - else if(vdist(org - this.origin, <, this.fade_start)) - alph = 1; // more processing saved + if(hud) // apparently this means we're in a vehicle lol + { + this.alpha *= autocvar_cl_items_vehicle_alpha; + this.colormod = this.glowmod = autocvar_cl_items_vehicle_color; + } + else if(this.ItemStatus & ITS_STAYWEP) + { + this.alpha *= autocvar_cl_weapon_stay_alpha; + this.colormod = this.glowmod = autocvar_cl_weapon_stay_color; + } else - alph = bound(0, (this.fade_end - vlen(org - this.origin - 0.5 * (this.mins + this.maxs))) / (this.fade_end - this.fade_start), 1); + { + this.colormod = '1 1 1'; + this.glowmod = this.item_glowmod; + } } else - alph = 1; - //printf("%v <-> %v\n", view_origin, this.origin + 0.5 * (this.mins + this.maxs)); - if(!hud && (this.ItemStatus & ITS_AVAILABLE)) - this.alpha = alph; - if(alph <= 0) - this.drawmask = 0; - //else - //this.drawmask = MASK_NORMAL; // reset by the setalpha function + { + this.alpha *= autocvar_cl_ghost_items; + this.colormod = this.glowmod = autocvar_cl_ghost_items_color; + } + + this.drawmask = this.alpha <= 0 ? 0 : MASK_NORMAL; } void ItemRemove(entity this) @@ -154,8 +142,6 @@ NET_HANDLE(ENT_CLIENT_ITEM, bool isnew) { this.ItemStatus = ReadByte(); - Item_SetAlpha(this); - if(this.ItemStatus & ITS_ALLOWFB) this.effects |= EF_FULLBRIGHT; else @@ -172,7 +158,6 @@ NET_HANDLE(ENT_CLIENT_ITEM, bool isnew) if(sf & ISF_MODEL) { - this.drawmask = MASK_NORMAL; set_movetype(this, MOVETYPE_TOSS); if (isnew) IL_PUSH(g_drawables, this); this.draw = ItemDraw; @@ -180,9 +165,6 @@ NET_HANDLE(ENT_CLIENT_ITEM, bool isnew) //this.flags |= FL_ITEM; this.fade_end = ReadShort(); - this.fade_start = ReadShort(); - if(!warpzone_warpzones_exist && this.fade_start && !autocvar_cl_items_nofade) - setpredraw(this, Item_PreDraw); strfree(this.mdl); diff --git a/qcsrc/client/items/items.qh b/qcsrc/client/items/items.qh index 78e109db4..aa8122697 100644 --- a/qcsrc/client/items/items.qh +++ b/qcsrc/client/items/items.qh @@ -4,7 +4,9 @@ const int AMMO_COUNT = 4; // amount of ammo types to show in the ammo panel .float onground_time; -bool autocvar_cl_items_nofade; +float autocvar_cl_items_fadedist = 500; +float autocvar_cl_items_vehicle_alpha = 0.75; +vector autocvar_cl_items_vehicle_color = '2 0.5 0.5'; float autocvar_cl_animate_items = 1; float autocvar_cl_ghost_items = 0.45; vector autocvar_cl_ghost_items_color = '-1 -1 -1'; diff --git a/qcsrc/server/items/items.qc b/qcsrc/server/items/items.qc index 5214d12ef..d9ddce275 100644 --- a/qcsrc/server/items/items.qc +++ b/qcsrc/server/items/items.qc @@ -59,7 +59,6 @@ bool ItemSend(entity this, entity to, int sf) if(sf & ISF_MODEL) { WriteShort(MSG_ENTITY, bound(0, this.fade_end, 32767)); - WriteShort(MSG_ENTITY, bound(0, this.fade_start, 32767)); if(this.mdl == "") LOG_TRACE("^1WARNING!^7 this.mdl is unset for item ", this.classname, "expect a crash just about now"); @@ -993,11 +992,9 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default int weaponid = def.instanceOfWeaponPickup ? def.m_weapon.m_id : 0; this.weapon = weaponid; + // bones_was_here TODO: implement sv_cullentities_dist and replace g_items_maxdist with it if(!this.fade_end) - { - this.fade_start = autocvar_g_items_mindist; this.fade_end = autocvar_g_items_maxdist; - } if(weaponid) STAT(WEAPONS, this) = WepSet_FromWeapon(REGISTRY_GET(Weapons, weaponid)); diff --git a/qcsrc/server/items/items.qh b/qcsrc/server/items/items.qh index 8af67c8de..bd26ce4b6 100644 --- a/qcsrc/server/items/items.qh +++ b/qcsrc/server/items/items.qh @@ -5,7 +5,6 @@ float autocvar_g_balance_superweapons_time; bool autocvar_g_fullbrightitems; -float autocvar_g_items_mindist; float autocvar_g_items_maxdist; float autocvar_g_items_dropped_lifetime; int autocvar_g_pickup_items; diff --git a/xonotic-client.cfg b/xonotic-client.cfg index 4a68913e2..5cce26783 100644 --- a/xonotic-client.cfg +++ b/xonotic-client.cfg @@ -905,11 +905,12 @@ exec hud_luma.cfg // enable menu syncing - must be after files that call menu_sync on startup - see alias menu_sync "" alias menu_sync "menu_cmd sync" -seta cl_items_nofade 0 +seta cl_items_fadedist 500 "distance, relative to the server's g_items_maxdist, at which far away items will start to fade out; 0 disables fading effect" +seta cl_items_vehicle_alpha 0.75 "Alpha of items seen from inside a vehicle" +seta cl_items_vehicle_color "2 0.5 0.5" "Colour of items seen from inside a vehicle" seta cl_animate_items 1 seta cl_ghost_items 0.45 "enable ghosted items (when between 0 and 1, overrides the alpha value)" seta cl_ghost_items_color "-1 -1 -1" "color of ghosted items (colormod format: 0 0 0 leaves the color unchanged, negative values allowed)" -seta cl_ghost_items_vehicle 1 "show ghosted items when inside a vehicle even when the item is available, to indicate that it can't be picked up" seta cl_simple_items 0 "enable simple items (if server allows)" set cl_simpleitems_postfix "_luma" "posfix to add fo model name when simple items are enabled" set cl_weapon_stay_color "2 0.5 0.5" "Color of picked up weapons when g_weapon_stay > 0 (colormod format: 0 0 0 leaves the color unchanged, negative values allowed)" diff --git a/xonotic-server.cfg b/xonotic-server.cfg index 4a374aa05..61db289a7 100644 --- a/xonotic-server.cfg +++ b/xonotic-server.cfg @@ -233,7 +233,6 @@ set g_maplist_sizes_count_maxplayers 1 "check the player limit when getting the set g_maplist_sizes_count_bots 1 "include the number of bots currently in the server when counting the number of players for size restrictions" set g_maplist_sizes_specparty 0 "this fraction of people are expected to only spectate, reduces player count used to select voting GUI maps" -set g_items_mindist 4000 "starting distance for the fading of items" set g_items_maxdist 4500 "maximum distance at which an item can be viewed, after which it will be invisible" set g_items_dropped_lifetime 20 "default lifetime for dropped items unless explicitly overriden (ie. flags)"