From: Mario Date: Thu, 2 Apr 2015 06:13:50 +0000 (+1100) Subject: Add an option to hide items further than a set distance away from the player (can... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=13c1991a74ee1392b3dc91cfce8571e8ca1810db;p=xonotic%2Fxonotic-data.pk3dir.git Add an option to hide items further than a set distance away from the player (can greatly improve performance on maps with a lot of items), disabled by default --- diff --git a/qcsrc/server/autocvars.qh b/qcsrc/server/autocvars.qh index f0be3e581..1c15fa41e 100644 --- a/qcsrc/server/autocvars.qh +++ b/qcsrc/server/autocvars.qh @@ -500,6 +500,8 @@ float autocvar_g_nix_with_powerups; float autocvar_g_nodepthtestitems; float autocvar_g_nodepthtestplayers; float autocvar_g_norecoil; +float autocvar_g_items_mindist; +float autocvar_g_items_maxdist; float autocvar_g_pickup_cells_max; float autocvar_g_pickup_plasma_max; float autocvar_g_pickup_fuel_max; diff --git a/qcsrc/server/t_items.qc b/qcsrc/server/t_items.qc index f995f721d..39c644251 100644 --- a/qcsrc/server/t_items.qc +++ b/qcsrc/server/t_items.qc @@ -79,6 +79,24 @@ void ItemDrawSimple() } } +void Item_PreDraw() +{ + vector org; + float alph; + org = getpropertyvec(VF_ORIGIN); + if(!checkpvs(org, self)) // this makes sense as long as we don't support recursive warpzones + alph = 0; + else if(self.fade_start) + alph = bound(0, (self.fade_end - vlen(org - self.origin - 0.5 * (self.mins + self.maxs))) / (self.fade_end - self.fade_start), 1); + else + alph = 1; + //printf("%v <-> %v\n", view_origin, self.origin + 0.5 * (self.mins + self.maxs)); + if(alph <= 0) + self.drawmask = 0; + else + self.drawmask = MASK_NORMAL; +} + void ItemRead(float _IsNew) { int sf = ReadByte(); @@ -153,6 +171,11 @@ void ItemRead(float _IsNew) //self.renderflags |= RF_DEPTHHACK; self.draw = ItemDraw; + self.fade_end = ReadShort(); + self.fade_start = ReadShort(); + if(self.fade_start) + self.predraw = Item_PreDraw; + if(self.mdl) strunzone(self.mdl); @@ -261,6 +284,8 @@ float ItemSend(entity to, float sf) if(sf & ISF_MODEL) { + WriteShort(MSG_ENTITY, self.fade_end); + WriteShort(MSG_ENTITY, self.fade_start); if(self.mdl == "") dprint("^1WARNING!^7 self.mdl is unset for item ", self.classname, "exspect a crash just aboute now\n"); @@ -961,6 +986,12 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, self.items = itemid; self.weapon = weaponid; + if(!self.fade_end) + { + self.fade_start = autocvar_g_items_mindist; + self.fade_end = autocvar_g_items_maxdist; + } + if(weaponid) self.weapons = WepSet_FromWeapon(weaponid); diff --git a/qcsrc/server/t_items.qh b/qcsrc/server/t_items.qh index 59239c7f5..5d3471a98 100644 --- a/qcsrc/server/t_items.qh +++ b/qcsrc/server/t_items.qh @@ -58,6 +58,9 @@ const int ISF_SIZE = 128; .int ItemStatus; +.float fade_start; +.float fade_end; + #ifdef CSQC float autocvar_cl_animate_items = 1;