r5668 - trunk/data/qcsrc/client

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Mon Jan 26 14:00:14 EST 2009


Author: div0
Date: 2009-01-26 14:00:12 -0500 (Mon, 26 Jan 2009)
New Revision: 5668

Added:
   trunk/data/qcsrc/client/prandom.qc
   trunk/data/qcsrc/client/prandom.qh
Modified:
   trunk/data/qcsrc/client/casings.qc
   trunk/data/qcsrc/client/damage.qc
   trunk/data/qcsrc/client/gibs.qc
   trunk/data/qcsrc/client/progs.src
Log:
prandom() - an attempt to make random decisions predictable (not sure if it actually works)

The goal is to make gibs and casings behave the very same way when playing back a demo.


Modified: trunk/data/qcsrc/client/casings.qc
===================================================================
--- trunk/data/qcsrc/client/casings.qc	2009-01-26 06:56:54 UTC (rev 5667)
+++ trunk/data/qcsrc/client/casings.qc	2009-01-26 19:00:12 UTC (rev 5668)
@@ -35,7 +35,7 @@
 				string s;
 				float f;
 
-				f = floor(random() * 3) + 1;
+				f = floor(prandom() * 3) + 1;
 				switch(self.state)
 				{
 					case 1:

Modified: trunk/data/qcsrc/client/damage.qc
===================================================================
--- trunk/data/qcsrc/client/damage.qc	2009-01-26 06:56:54 UTC (rev 5667)
+++ trunk/data/qcsrc/client/damage.qc	2009-01-26 19:00:12 UTC (rev 5668)
@@ -67,7 +67,7 @@
 		secondary = hittype & HITTYPE_SECONDARY;
 		bounce = hittype & HITTYPE_BOUNCE;
 		headshot = hittype & HITTYPE_HEADSHOT;
-		r = random();
+		r = prandom();
 
 		traceline(org - normalize(force) * 16, org + normalize(force) * 16, MOVE_NOMONSTERS, world);
 		if(trace_fraction < 1)

Modified: trunk/data/qcsrc/client/gibs.qc
===================================================================
--- trunk/data/qcsrc/client/gibs.qc	2009-01-26 06:56:54 UTC (rev 5667)
+++ trunk/data/qcsrc/client/gibs.qc	2009-01-26 19:00:12 UTC (rev 5668)
@@ -14,7 +14,7 @@
 		return;
 	}
 	
-	sound(self, CHAN_PAIN, strcat("misc/gib_splat0", ftos(floor(random() * 4 + 1)), ".wav"), VOL_BASE, ATTN_NORM);
+	sound(self, CHAN_PAIN, strcat("misc/gib_splat0", ftos(floor(prandom() * 4 + 1)), ".wav"), VOL_BASE, ATTN_NORM);
 	pointparticles(particleeffectnum("blood"), self.origin + '0 0 1', '0 0 30', 10);
 
 	remove(self);
@@ -69,7 +69,7 @@
 	gib.move_time = time;
 	gib.damageforcescale = 3.5;
 
-	gib.nextthink = time + 12 + random () * 4;
+	gib.nextthink = time + 12 + prandom () * 4;
 }
 
 void Ent_GibSplash()
@@ -107,37 +107,37 @@
 		case 0x01:
 			sound (self, CHAN_PAIN, "misc/gib.wav", VOL_BASE, ATTN_NORM);
 
-			if(random() < amount)
+			if(prandom() < amount)
 				TossGib("models/gibs/eye.md3", org, vel + randomvec() * 150, 0);
 			te_bloodshower(org + mi, org + ma, 1200, 1000 * amount);
-			if(random() < amount)
+			if(prandom() < amount)
 				TossGib("models/gibs/bloodyskull.md3", org, vel + randomvec() * 100, 0);
 
 			for(c = 0; c < amount; ++c)
 			{
 				randomvalue = amount - c;
 					
-				if(random() < randomvalue)
-					TossGib ("models/gibs/arm.md3", org, vel + randomvec() * (random() * 120 + 90),0);
-				if(random() < randomvalue)
-					TossGib ("models/gibs/arm.md3", org, vel + randomvec() * (random() * 120 + 90),0);
-				if(random() < randomvalue)
-					TossGib ("models/gibs/chest.md3", org + '0 0 -12', vel + randomvec() * (random() * 120 + 80),0);
-				if(random() < randomvalue)
-					TossGib ("models/gibs/smallchest.md3", org, vel + randomvec() * (random() * 120 + 80),0);
-				if(random() < randomvalue)
-					TossGib ("models/gibs/leg1.md3", org + '0 0 -5', vel + randomvec() * (random() * 120 + 85),0);
-				if(random() < randomvalue)
-					TossGib ("models/gibs/leg2.md3", org + '0 0 -9', vel + randomvec() * (random() * 120 + 85),0);
+				if(prandom() < randomvalue)
+					TossGib ("models/gibs/arm.md3", org, vel + randomvec() * (prandom() * 120 + 90),0);
+				if(prandom() < randomvalue)
+					TossGib ("models/gibs/arm.md3", org, vel + randomvec() * (prandom() * 120 + 90),0);
+				if(prandom() < randomvalue)
+					TossGib ("models/gibs/chest.md3", org + '0 0 -12', vel + randomvec() * (prandom() * 120 + 80),0);
+				if(prandom() < randomvalue)
+					TossGib ("models/gibs/smallchest.md3", org, vel + randomvec() * (prandom() * 120 + 80),0);
+				if(prandom() < randomvalue)
+					TossGib ("models/gibs/leg1.md3", org + '0 0 -5', vel + randomvec() * (prandom() * 120 + 85),0);
+				if(prandom() < randomvalue)
+					TossGib ("models/gibs/leg2.md3", org + '0 0 -9', vel + randomvec() * (prandom() * 120 + 85),0);
 
 				// these splat on impact
-				if(random() < randomvalue)
+				if(prandom() < randomvalue)
 					TossGib ("models/gibs/chunk.mdl", org, vel + randomvec() * 450,1);
-				if(random() < randomvalue)
+				if(prandom() < randomvalue)
 					TossGib ("models/gibs/chunk.mdl", org, vel + randomvec() * 450,1);
-				if(random() < randomvalue)
+				if(prandom() < randomvalue)
 					TossGib ("models/gibs/chunk.mdl", org, vel + randomvec() * 450,1);
-				if(random() < randomvalue)
+				if(prandom() < randomvalue)
 					TossGib ("models/gibs/chunk.mdl", org, vel + randomvec() * 450,1);
 			}
 			break;
@@ -145,7 +145,7 @@
 			pointparticles(particleeffectnum("blood"), org, vel, amount * 16);
 			break;
 		case 0x03:
-			if(random() < amount)
+			if(prandom() < amount)
 				TossGib ("models/gibs/chunk.mdl", org, vel, 1);
 			break;
 		case 0x81:

Added: trunk/data/qcsrc/client/prandom.qc
===================================================================
--- trunk/data/qcsrc/client/prandom.qc	                        (rev 0)
+++ trunk/data/qcsrc/client/prandom.qc	2009-01-26 19:00:12 UTC (rev 5668)
@@ -0,0 +1,15 @@
+// prandom - PREDICTABLE random number generator
+
+float prandom_time, prandom_seed;
+float prandom()
+{
+	float c;
+
+	// reinitialize every frame to make it act similar every frame
+	if(time != prandom_time)
+		prandom_seed = prandom_time = time;
+	
+	c = crc16(FALSE, strcat(ftos(prandom_seed), ftos(prandom_seed + 3.1415926535)));
+	prandom_seed = c;
+	return c / 65536; // in [0..1[
+}

Added: trunk/data/qcsrc/client/prandom.qh
===================================================================
--- trunk/data/qcsrc/client/prandom.qh	                        (rev 0)
+++ trunk/data/qcsrc/client/prandom.qh	2009-01-26 19:00:12 UTC (rev 5668)
@@ -0,0 +1,2 @@
+// prandom - PREDICTABLE random number generator
+float prandom();

Modified: trunk/data/qcsrc/client/progs.src
===================================================================
--- trunk/data/qcsrc/client/progs.src	2009-01-26 06:56:54 UTC (rev 5667)
+++ trunk/data/qcsrc/client/progs.src	2009-01-26 19:00:12 UTC (rev 5668)
@@ -14,6 +14,7 @@
 teamradar.qh
 waypointsprites.qh
 movetypes.qh
+prandom.qh
 
 main.qh
 
@@ -40,6 +41,7 @@
 teamradar.qc
 waypointsprites.qc
 movetypes.qc
+prandom.qc
 
 ../common/util.qc
 ../common/gamecommand.qc




More information about the nexuiz-commits mailing list