r4542 - in trunk/data: qcsrc/server scripts

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sun Sep 28 13:15:25 EDT 2008


Author: div0
Date: 2008-09-28 13:15:24 -0400 (Sun, 28 Sep 2008)
New Revision: 4542

Modified:
   trunk/data/qcsrc/server/g_subs.qc
   trunk/data/qcsrc/server/miscfunctions.qc
   trunk/data/qcsrc/server/sv_main.qc
   trunk/data/scripts/entities.def
Log:
LOD for misc_models and similar entities


Modified: trunk/data/qcsrc/server/g_subs.qc
===================================================================
--- trunk/data/qcsrc/server/g_subs.qc	2008-09-28 10:56:37 UTC (rev 4541)
+++ trunk/data/qcsrc/server/g_subs.qc	2008-09-28 17:15:24 UTC (rev 4542)
@@ -344,13 +344,99 @@
 	return a;
 }
 
-void SetBrushEntityModel()
+.string lodtarget1;
+.string lodtarget2;
+.string lodmodel1;
+.string lodmodel2;
+.float lodmodelindex0;
+.float lodmodelindex1;
+.float lodmodelindex2;
+.float loddistance1;
+.float loddistance2;
+
+float LOD_customize()
 {
-	if(self.model != "")
+	float d;
+
+	// TODO csqc network this so it only gets sent once
+	d = vlen(self.origin - other.origin);
+	if(d < self.loddistance1)
+		self.modelindex = self.lodmodelindex0;
+	else if(!self.lodmodelindex2 || d < self.loddistance2)
+		self.modelindex = self.lodmodelindex1;
+	else
+		self.modelindex = self.lodmodelindex2;
+
+	return TRUE;
+}
+
+void LOD_uncustomize()
+{
+	self.modelindex = self.lodmodelindex0;
+}
+
+void LODmodel_attach()
+{
+	entity e;
+
+	if(!self.loddistance1)
+		self.loddistance1 = 1000;
+	if(!self.loddistance2)
+		self.loddistance2 = 2000;
+	self.lodmodelindex0 = self.modelindex;
+
+	if(self.lodtarget1 != "")
 	{
-		precache_model(self.model);
-		setmodel(self, self.model); // no precision needed
+		e = find(world, targetname, self.lodtarget1);
+		if(e)
+		{
+			self.lodmodel1 = e.model;
+			remove(e);
+		}
 	}
+	if(self.lodtarget2 != "")
+	{
+		e = find(world, targetname, self.lodtarget2);
+		if(e)
+		{
+			self.lodmodel2 = e.model;
+			remove(e);
+		}
+	}
+
+	if(self.lodmodel1 != "")
+	{
+		vector mi, ma;
+		mi = self.mins;
+		ma = self.maxs;
+
+		precache_model(self.lodmodel1);
+		setmodel(self, self.lodmodel1);
+		self.lodmodelindex1 = self.modelindex;
+
+		if(self.lodmodel2 != "")
+		{
+			precache_model(self.lodmodel2);
+			setmodel(self, self.lodmodel2);
+			self.lodmodelindex2 = self.modelindex;
+		}
+
+		self.modelindex = self.lodmodelindex0;
+		setsize(self, mi, ma);
+	}
+
+	if(self.lodmodelindex1)
+		SetCustomizer(self, LOD_customize, LOD_uncustomize);
+}
+
+void SetBrushEntityModel()
+{
+ 	if(self.model != "")
+ 	{
+ 		precache_model(self.model);
+ 		setmodel(self, self.model); // no precision needed
+		InitializeEntity(self, LODmodel_attach, INITPRIO_FINDTARGET);
+ 	}
 	setorigin(self, self.origin);
 	setsize(self, self.mins, self.maxs);
 }

Modified: trunk/data/qcsrc/server/miscfunctions.qc
===================================================================
--- trunk/data/qcsrc/server/miscfunctions.qc	2008-09-28 10:56:37 UTC (rev 4541)
+++ trunk/data/qcsrc/server/miscfunctions.qc	2008-09-28 17:15:24 UTC (rev 4542)
@@ -1277,6 +1277,24 @@
 	initialize_entity_first = world;
 }
 
+.float uncustomizeentityforclient_set;
+.void(void) uncustomizeentityforclient;
+void(void) SUB_Nullpointer = #0;
+void UncustomizeEntitiesRun()
+{
+	entity oldself;
+	oldself = self;
+	for(self = world; (self = findfloat(self, uncustomizeentityforclient_set, 1)); )
+		self.uncustomizeentityforclient();
+	self = oldself;
+}
+void SetCustomizer(entity e, float(void) customizer, void(void) uncustomizer)
+{
+	e.customizeentityforclient = customizer;
+	e.uncustomizeentityforclient = uncustomizer;
+	e.uncustomizeentityforclient_set = (uncustomizer != SUB_Nullpointer);
+}
+
 .float nottargeted;
 #define IFTARGETED if(!self.nottargeted && self.targetname != "")
 

Modified: trunk/data/qcsrc/server/sv_main.qc
===================================================================
--- trunk/data/qcsrc/server/sv_main.qc	2008-09-28 10:56:37 UTC (rev 4541)
+++ trunk/data/qcsrc/server/sv_main.qc	2008-09-28 17:15:24 UTC (rev 4542)
@@ -139,6 +139,7 @@
 		return;
 
 	InitializeEntitiesRun();
+	UncustomizeEntitiesRun();
 
 	sv_maxairspeed = cvar("sv_maxairspeed");
 	sv_maxspeed = cvar ("sv_maxspeed");

Modified: trunk/data/scripts/entities.def
===================================================================
--- trunk/data/scripts/entities.def	2008-09-28 10:56:37 UTC (rev 4541)
+++ trunk/data/scripts/entities.def	2008-09-28 17:15:24 UTC (rev 4542)
@@ -564,6 +564,12 @@
 velocity: when movetype isn't 0, initial velocity vector
 angles: initial looking direction
 effects: sum of 1 = BRIGHTFIELD, 4 = BRIGHTLIGHT, 8 = DIMLIGHT, 32 = ADDITIVE, 64 = BLUE, 128 = RED, 512 = FULLBRIGHT, 1024 = FLAME, 2048 = STARDUST, 4096 = NOSHADOW, 8192 = NODEPTHTEST, 32768 = DOUBLESIDED, 8388608 = NOMODELFLAGS (ignores the following coming from a model file), 16777216 = ROCKET, 33554432 = GRENADE, 67108864 = GIB, 134217728 = ROTATE, 268435456 = TRACER, 536870912 = ZOMGIB, 1073741824 = TRACER2, -2147483648 = TRACER3
+loddistance1: distance after which to show the first LOD model replacement (default: 1000)
+loddistance2: distance after which to show the second LOD model replacement (default: 2000)
+lodmodel1: file name of the first LOD model replacement
+lodmodel2: file name of the second LOD model replacement
+lodtarget1: targetname of the first LOD model entity (can be used instead of lodmodel1 to use a brush model instead)
+lodtarget2: targetname of the second LOD model entity (can be used instead of lodmodel2 to use a brush model instead)
 -------- Q3MAP2 KEYS --------
 _frame: frame of model to include (set equal to frame if _castshadows is set)
 modelscale: scaling factor (set equal to scale if _castshadows is set)




More information about the nexuiz-commits mailing list