[nexuiz-commits] r7612 - trunk/data/qcsrc/client

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Thu Sep 3 12:27:42 EDT 2009


Author: lordhavoc
Date: 2009-09-03 12:27:41 -0400 (Thu, 03 Sep 2009)
New Revision: 7612

Modified:
   trunk/data/qcsrc/client/casings.qc
   trunk/data/qcsrc/client/gibs.qc
   trunk/data/qcsrc/client/rubble.qc
Log:
rewrote rubble handling to fix more bugs


Modified: trunk/data/qcsrc/client/casings.qc
===================================================================
--- trunk/data/qcsrc/client/casings.qc	2009-09-03 16:05:02 UTC (rev 7611)
+++ trunk/data/qcsrc/client/casings.qc	2009-09-03 16:27:41 UTC (rev 7612)
@@ -1,10 +1,7 @@
-float  casecount;
-entity caselist;
 .float silent;
 
 void Casing_Delete()
 {
-    --casecount;
     remove(self);
 }
 
@@ -77,16 +74,7 @@
 {
 	entity casing;
 
-	if not(caselist)
-        caselist = spawn();
-
-	casing = RubbleNew(caselist);
-	++casecount;
-	if(casecount >= cvar_or("cl_casings_maxcount",100))
-        RubbleDrop(caselist,Casing_Delete);
-	if(wasfreed(casing))
-		return;
-
+	casing = RubbleNew("casing");
 	casing.state = ReadByte();
 	casing.silent = (casing.state & 0x80);
 	casing.state = (casing.state & 0x7F);
@@ -126,6 +114,8 @@
 	}
     else
         Casing_Delete();
+
+	RubbleLimit("casing", cvar_or("cl_casings_maxcount",100), Casing_Delete);
 }
 
 void Casings_Precache()

Modified: trunk/data/qcsrc/client/gibs.qc
===================================================================
--- trunk/data/qcsrc/client/gibs.qc	2009-09-03 16:05:02 UTC (rev 7611)
+++ trunk/data/qcsrc/client/gibs.qc	2009-09-03 16:27:41 UTC (rev 7612)
@@ -1,11 +1,8 @@
-float  gibcount;
-entity giblist;
 .float silent;
 
 void Gib_Delete()
 {
-    --gibcount;
-    remove(self);
+	remove(self);
 }
 
 string species_prefix(float specnum)
@@ -80,20 +77,8 @@
 {
 	entity gib;
 
-	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);
-	if(wasfreed(gib))
-		return;
-
-	//gib = spawn();
-
-	gib.classname = "gib";
+	gib = RubbleNew("gib");
 	gib.move_movetype = MOVETYPE_BOUNCE;
 	gib.gravity = 1;
 	gib.solid = SOLID_CORPSE;
@@ -118,6 +103,8 @@
 	gib.damageforcescale = cvar_or("cl_gibs_damageforcescale", 3.5);
 
 	gib.nextthink = time + cvar_or("cl_gibs_lifetime", 14) * (1 + prandom() * 0.15);
+
+	RubbleLimit("gib", cvar_or("cl_gibs_maxcount",100), Gib_Delete);
 }
 
 void Ent_GibSplash()

Modified: trunk/data/qcsrc/client/rubble.qc
===================================================================
--- trunk/data/qcsrc/client/rubble.qc	2009-09-03 16:05:02 UTC (rev 7611)
+++ trunk/data/qcsrc/client/rubble.qc	2009-09-03 16:27:41 UTC (rev 7612)
@@ -1,40 +1,59 @@
 .float creationtime;
 
-void RubbleDrop(entity list, void() deleteproc)
+// LordHavoc: rewrote this file, it was really bad code
+
+void RubbleLimit(string cname, float limit, void() deleteproc)
 {
-    float t;
-    entity rub,old_rub;
+	entity e;
+	entity oldest;
+	entity oldself;
+	float c;
+	float oldesttime;
 
-    rub = findchainentity(owner,list);
-    old_rub = rub;
-    t = rub.creationtime;
-    rub = rub.chain;
-    while(rub)
-    {
-        if(t > rub.creationtime)
-        {
-            t = rub.creationtime;
-            old_rub = rub;
-        }
-        rub = rub.chain;
-    }
+	oldself = self;
 
-    if (old_rub == world)
-        return;
+	// remove rubble of the same type if it's at the limit
+	// remove multiple rubble if the limit has been decreased
+	while(1)
+	{
+		e = findchain(classname,cname);
+		if (e == world)
+			break;
+		// walk the list and count the entities, find the oldest
+		// initialize our search with the first entity
+		c = 1;
+		oldest = e;
+		oldesttime = e.creationtime;
+		e = e.chain;
+		// compare to all other matching entities
+		while (e)
+		{
+			c = c + 1;
+			if (oldesttime > e.creationtime)
+			{
+				oldesttime = e.creationtime;
+				oldest = e;
+			}
+			e = e.chain;
+		}
 
-    rub = self;
-    self = old_rub;
-    deleteproc();
-    self = rub;
+		// stop if there are less than the limit already
+		if (c <= limit)
+			break;
+
+		// delete this oldest one and search again
+		self = oldest;
+		deleteproc();
+		self = oldself;
+	}
 }
 
-entity RubbleNew(entity list)
+entity RubbleNew(string cname)
 {
-    entity rub;
-
-    rub = spawn();
-    rub.creationtime = time;
-    rub.owner = list;
-
-    return rub;
+	entity e;
+	// spawn a new entity and return it
+	e = spawn();
+	e.classname = cname;
+	e.creationtime = time;
+	return e;
 }



More information about the nexuiz-commits mailing list