From 945a946855cdf821d784e61af330c1d6042ddb94 Mon Sep 17 00:00:00 2001 From: tzork Date: Tue, 2 Jun 2009 07:47:13 +0000 Subject: [PATCH] cl_gibs_maxcount and cl_casings_maxcount performance enhancement / config options. limits the maximum number of items of that type known to a client at any one time. git-svn-id: svn://svn.icculus.org/nexuiz/trunk@6846 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/qcsrc/client/casings.qc | 30 +++++++++++++++++++----- data/qcsrc/client/gibs.qc | 45 +++++++++++++++++++++++++----------- data/qcsrc/client/progs.src | 2 ++ data/qcsrc/client/rubble.qc | 34 +++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 20 deletions(-) create mode 100644 data/qcsrc/client/rubble.qc diff --git a/data/qcsrc/client/casings.qc b/data/qcsrc/client/casings.qc index 6e6dd8a11..397520ed4 100644 --- a/data/qcsrc/client/casings.qc +++ b/data/qcsrc/client/casings.qc @@ -1,3 +1,12 @@ +float casecount; +entity caselist; + +void Casing_Delete() +{ + --casecount; + remove(self); +} + void Casing_Draw() { if(self.move_flags & FL_ONGROUND) @@ -8,12 +17,12 @@ void Casing_Draw() } Movetype_Physics(FALSE); - + self.renderflags = 0; self.alpha = bound(0, self.cnt - time, 1); if(self.alpha < ALPHA_MIN_VISIBLE) - remove(self); + Casing_Delete(); else R_AddEntity(self); } @@ -22,7 +31,7 @@ void Casing_Touch() { if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) { - remove(self); + Casing_Delete(); return; } @@ -65,8 +74,15 @@ void Casing_Damage(float thisdmg, float hittype, vector org, vector thisforce) void Ent_Casing() { entity casing; + + if not(caselist) + caselist = spawn(); + + casing = RubbleNew(caselist); + ++casecount; + if(casecount >= cvar_or("cl_casings_maxcount",100)) + RubbleDrop(caselist,Casing_Delete); - casing = spawn(); casing.state = ReadByte(); casing.origin_x = ReadCoord(); casing.origin_y = ReadCoord(); @@ -75,7 +91,7 @@ void Ent_Casing() casing.angles_x = ReadByte() * 360 / 256; casing.angles_y = ReadByte() * 360 / 256; casing.angles_z = ReadByte() * 360 / 256; - + if(cvar("cl_casings")) { casing.draw = Casing_Draw; casing.move_origin = casing.origin; @@ -101,7 +117,9 @@ void Ent_Casing() } setsize(casing, '0 0 -1', '0 0 -1'); - } else remove(self); + } + else + Casing_Delete(); } void Casings_Precache() diff --git a/data/qcsrc/client/gibs.qc b/data/qcsrc/client/gibs.qc index 4f776d019..b665edef4 100644 --- a/data/qcsrc/client/gibs.qc +++ b/data/qcsrc/client/gibs.qc @@ -1,3 +1,12 @@ +float gibcount; +entity giblist; + +void Gib_Delete() +{ + --gibcount; + remove(self); +} + string species_prefix(float specnum) { switch(specnum) @@ -23,7 +32,7 @@ void new_te_bloodshower (float ef, vector org, float explosionspeed, float howma void SUB_RemoveOnNoImpact() { if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) - remove(self); + Gib_Delete(); } void Gib_Touch() @@ -32,14 +41,14 @@ void Gib_Touch() if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) { - remove(self); + Gib_Delete(); return; } - + sound(self, CHAN_PAIN, strcat("misc/gib_splat0", ftos(floor(prandom() * 4 + 1)), ".wav"), VOL_BASE, ATTN_NORM); pointparticles(particleeffectnum(strcat(species_prefix(self.cnt), "blood")), self.origin + '0 0 1', '0 0 30', 10); - remove(self); + Gib_Delete(); } void Gib_Draw() @@ -50,7 +59,7 @@ void Gib_Draw() Movetype_Physics(FALSE); if(wasfreed(self)) return; - + if(self.touch == Gib_Touch) // don't do this for the "chunk" thingie... trailparticles(self, particleeffectnum(strcat(species_prefix(self.cnt), "TR_SLIGHTBLOOD")), oldorg, self.origin); else @@ -60,7 +69,7 @@ void Gib_Draw() self.alpha = bound(0, self.nextthink - time, 1); if(self.alpha < ALPHA_MIN_VISIBLE) - remove(self); + Gib_Delete(); else R_AddEntity(self); } @@ -69,9 +78,17 @@ void TossGib (string mdlname, vector org, vector vconst, vector vrand, float spe { entity gib; - // TODO remove some gibs according to cl_nogibs - - gib = spawn(); + if not(giblist) + giblist = spawn(); + + // TODO remove some gibs according to cl_nogibs + gib = RubbleNew(giblist); + ++gibcount; + if(gibcount >= cvar_or("cl_gibs_maxcount",100)) + RubbleDrop(giblist,Gib_Delete); + + //gib = spawn(); + gib.classname = "gib"; gib.move_movetype = MOVETYPE_BOUNCE; gib.gravity = 1; @@ -82,7 +99,7 @@ void TossGib (string mdlname, vector org, vector vconst, vector vrand, float spe gib.skin = specnum; setsize (gib, '-8 -8 -8', '8 8 8'); - + gib.draw = Gib_Draw; if(destroyontouch) gib.move_touch = Gib_Touch; @@ -115,16 +132,16 @@ void Ent_GibSplash() if(cvar("cl_gentle")) type |= 0x80; // set gentle bit - + gibfactor = 1 - cvar("cl_nogibs"); if(gibfactor <= 0) return; - + amount *= gibfactor; if(cvar("ekg")) amount *= 5; - + self.origin = org; // for the sounds specnum = (type & 0x78) / 8; // blood/gibmodel type: using four bits (0..15, bit indexes 3,4,5,6) @@ -145,7 +162,7 @@ void Ent_GibSplash() for(c = 0; c < amount; ++c) { randomvalue = amount - c; - + if(prandom() < randomvalue) TossGib ("models/gibs/arm.md3", org, vel, prandomvec() * (prandom() * 120 + 90), specnum,0); if(prandom() < randomvalue) diff --git a/data/qcsrc/client/progs.src b/data/qcsrc/client/progs.src index b104e5ce1..09492f590 100644 --- a/data/qcsrc/client/progs.src +++ b/data/qcsrc/client/progs.src @@ -28,6 +28,7 @@ ctf.qc sbar.qc mapvoting.qc +rubble.qc hook.qc particles.qc laser.qc @@ -38,6 +39,7 @@ casings.qc effects.qc wall.qc +vehicles/spiderbot.qc Main.qc View.qc interpolate.qc diff --git a/data/qcsrc/client/rubble.qc b/data/qcsrc/client/rubble.qc new file mode 100644 index 000000000..ff1805f19 --- /dev/null +++ b/data/qcsrc/client/rubble.qc @@ -0,0 +1,34 @@ +.float creationtime; + +void RubbleDrop(entity list, void() deleteproc) +{ + float t,tt; + entity rub,old_rub; + + rub = findchainentity(owner,list); + while(rub) + { + if(rub.creationtime > t) + { + old_rub = rub; + tt = t; + } + rub = rub.chain; + } + + rub = self; + self = old_rub; + deleteproc(); + self = rub; +} + +entity RubbleNew(entity list) +{ + entity rub; + + rub = spawn(); + rub.creationtime = time; + rub.owner = list; + + return rub; +} -- 2.39.2