]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
items: alpha calculation rework
authorbones_was_here <bones_was_here@xonotic.au>
Mon, 12 Jun 2023 18:38:36 +0000 (04:38 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Thu, 15 Jun 2023 20:36:23 +0000 (06:36 +1000)
- 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

qcsrc/client/items/items.qc
qcsrc/client/items/items.qh
qcsrc/server/items/items.qc
qcsrc/server/items/items.qh
xonotic-client.cfg
xonotic-server.cfg

index f4abe998999df6f273de160cb0ce37195ef8b388..a10ac41e490a93ce9c832845dee618797e1dc42f 100644 (file)
@@ -8,35 +8,10 @@
 #include <lib/csqcmodel/common.qh>
 #include <lib/warpzone/common.qh>
 
-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);
 
index 78e109db46d6368b076f399957a5aefbdf65ca37..aa8122697e060deb455cabcaa6a44aa7bfa443ae 100644 (file)
@@ -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';
index 5214d12ef6ff138f3f9c1acbc65ae83f33015b92..d9ddce2752ac3779ecb20a32ce230f842e0c3768 100644 (file)
@@ -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));
index 8af67c8deea9a203ff6b759abb19ed24b3921f32..bd26ce4b675e359e6df576d5befc5ce5acd4f9b5 100644 (file)
@@ -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;
index 4a68913e20b56a26ae77aeb01436b1d789008406..5cce2678371ab4eb31b8666751e5932902622743 100644 (file)
@@ -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)"
index 4a374aa05b2beb990950e4b23e3efc5f47d94a43..61db289a70c5b987786520152e24d768b0235bcc 100644 (file)
@@ -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)"