[nexuiz-commits] r6525 - trunk/data/qcsrc/server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Fri Apr 17 15:00:49 EDT 2009


Author: div0
Date: 2009-04-17 15:00:47 -0400 (Fri, 17 Apr 2009)
New Revision: 6525

Added:
   trunk/data/qcsrc/server/g_models.qc
Modified:
   trunk/data/qcsrc/server/g_triggers.qc
   trunk/data/qcsrc/server/progs.src
   trunk/data/qcsrc/server/t_items.qc
Log:
refactored model entity code to make it more readable


Added: trunk/data/qcsrc/server/g_models.qc
===================================================================
--- trunk/data/qcsrc/server/g_models.qc	                        (rev 0)
+++ trunk/data/qcsrc/server/g_models.qc	2009-04-17 19:00:47 UTC (rev 6525)
@@ -0,0 +1,147 @@
+.float modelscale;
+
+void g_model_setcolormaptoactivator (void)
+{
+	if(teams_matter)
+	{
+		if(activator.team)
+			self.colormap = (activator.team - 1) * 0x11;
+		else
+			self.colormap = 0x00;
+	}
+	else
+		self.colormap = floor(random() * 256);
+	self.colormap |= 1024; // RENDER_COLORMAPPED
+}
+
+void g_clientmodel_setcolormaptoactivator (void)
+{
+	g_model_setcolormaptoactivator();
+	self.SendFlags |= 1;
+}
+
+void g_model_dropbyspawnflags()
+{
+	if(self.spawnflags & 3 == 1) // ALIGN_ORIGIN
+	{
+		traceline(self.origin, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
+		setorigin(self, trace_endpos);
+	}
+	else if(self.spawnflags & 3 == 2) // ALIGN_BOTTOM
+	{
+		tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
+		setorigin(self, trace_endpos);
+	}
+	else if(self.spawnflags & 3 == 3) // ALIGN_ORIGIN | ALIGN_BOTTOM
+	{
+		traceline(self.origin, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
+		setorigin(self, trace_endpos - '0 0 1' * self.mins_z);
+	}
+}
+
+void g_clientmodel_dropbyspawnflags()
+{
+	vector o0;
+	o0 = self.origin;
+	g_model_dropbyspawnflags();
+	if(self.origin != o0)
+		self.SendFlags |= 2;
+}
+
+float g_clientmodel_genericsendentity (entity to, float sf)
+{
+	sf = sf & 0x0F;
+	if(self.angles != '0 0 0')
+		sf |= 0x10;
+	if(self.solid && (self.mins != '0 0 0' || self.maxs != '0 0 0'))
+		sf |= 0x20;
+	if(self.colormap != 0)
+		sf |= 0x40;
+	
+	WriteByte(MSG_ENTITY, ENT_CLIENT_WALL);
+	WriteByte(MSG_ENTITY, sf);
+
+	if(sf & 1)
+	{
+		if(sf & 0x40)
+			WriteShort(MSG_ENTITY, self.colormap);
+	}
+
+	if(sf & 2)
+	{
+		WriteCoord(MSG_ENTITY, self.origin_x);
+		WriteCoord(MSG_ENTITY, self.origin_y);
+		WriteCoord(MSG_ENTITY, self.origin_z);
+	}
+
+	if(sf & 4)
+	{
+		if(sf & 0x10)
+		{
+			WriteAngle(MSG_ENTITY, self.angles_x);
+			WriteAngle(MSG_ENTITY, self.angles_y);
+			WriteAngle(MSG_ENTITY, self.angles_z);
+		}
+	}
+
+	if(sf & 8)
+	{
+		WriteShort(MSG_ENTITY, self.modelindex);
+		WriteByte(MSG_ENTITY, self.solid);
+		WriteByte(MSG_ENTITY, floor(self.scale * 16));
+		if(sf & 0x20)
+		{
+			WriteCoord(MSG_ENTITY, self.mins_x);
+			WriteCoord(MSG_ENTITY, self.mins_y);
+			WriteCoord(MSG_ENTITY, self.mins_z);
+			WriteCoord(MSG_ENTITY, self.maxs_x);
+			WriteCoord(MSG_ENTITY, self.maxs_y);
+			WriteCoord(MSG_ENTITY, self.maxs_z);
+		}
+		WriteString(MSG_ENTITY, self.bgmscript);
+		if(self.bgmscript != "")
+		{
+			WriteByte(MSG_ENTITY, floor(self.bgmscriptattack * 64));
+			WriteByte(MSG_ENTITY, floor(self.bgmscriptdecay * 64));
+			WriteByte(MSG_ENTITY, floor(self.bgmscriptsustain * 255));
+			WriteByte(MSG_ENTITY, floor(self.bgmscriptrelease * 64));
+			WriteCoord(MSG_ENTITY, self.movedir_x);
+			WriteCoord(MSG_ENTITY, self.movedir_y);
+			WriteCoord(MSG_ENTITY, self.movedir_z);
+			WriteByte(MSG_ENTITY, floor(self.lip * 255));
+		}
+	}
+
+	return TRUE;
+}
+
+
+#define G_MODEL_INIT(sol) \
+	SetBrushEntityModel(); \
+	if(!self.scale) self.scale = self.modelscale; \
+	self.use = g_model_setcolormaptoactivator; \
+	InitializeEntity(self, g_model_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
+	if(!self.solid) self.solid = (sol); else if(self.solid < 0) self.solid = SOLID_NOT;
+
+#define G_CLIENTMODEL_INIT(sol) \
+	SetBrushEntityModelNoLOD(); \
+	if(!self.scale) self.scale = self.modelscale; \
+	self.use = g_clientmodel_setcolormaptoactivator; \
+	InitializeEntity(self, g_clientmodel_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
+	if(!self.solid) self.solid = (sol); else if(self.solid < 0) self.solid = SOLID_NOT; \
+	if(!self.bgmscriptsustain) self.bgmscriptsustain = 1; else if(self.bgmscriptsustain < 0) self.bgmscriptsustain = 0; \
+	Net_LinkEntity(self, TRUE, 0, g_clientmodel_genericsendentity);
+
+// non-solid model entities:
+void spawnfunc_misc_gamemodel()         { G_MODEL_INIT      (SOLID_NOT) } // model entity
+void spawnfunc_misc_clientmodel()       { G_CLIENTMODEL_INIT(SOLID_NOT) } // model entity
+void spawnfunc_misc_models()            { G_MODEL_INIT      (SOLID_NOT) } // DEPRECATED old compat entity with confusing name, do not use
+
+// non-solid brush entities:
+void spawnfunc_func_illusionary()       { G_MODEL_INIT      (SOLID_NOT) } // Q1 name (WARNING: MISPREDICTED)
+void spawnfunc_func_clientillusionary() { G_CLIENTMODEL_INIT(SOLID_NOT) } // brush entity
+void spawnfunc_func_static()            { G_MODEL_INIT      (SOLID_NOT) } // DEPRECATED old alias name from some other game
+
+// solid brush entities
+void spawnfunc_func_wall()              { G_MODEL_INIT      (SOLID_BSP) } // Q1 name
+void spawnfunc_func_clientwall()        { G_CLIENTMODEL_INIT(SOLID_BSP) } // brush entity (WARNING: MISPREDICTED)

Modified: trunk/data/qcsrc/server/g_triggers.qc
===================================================================
--- trunk/data/qcsrc/server/g_triggers.qc	2009-04-17 18:42:26 UTC (rev 6524)
+++ trunk/data/qcsrc/server/g_triggers.qc	2009-04-17 19:00:47 UTC (rev 6525)
@@ -711,141 +711,6 @@
 	self.nextthink = time;
 }
 
-float func_clientwall_send (entity to, float sf)
-{
-	sf = sf & 0x0F;
-	if(self.angles != '0 0 0')
-		sf |= 0x10;
-	if(self.solid && (self.mins != '0 0 0' || self.maxs != '0 0 0'))
-		sf |= 0x20;
-	if(self.colormap != 0)
-		sf |= 0x40;
-	
-	WriteByte(MSG_ENTITY, ENT_CLIENT_WALL);
-	WriteByte(MSG_ENTITY, sf);
-
-	if(sf & 1)
-	{
-		if(sf & 0x40)
-			WriteShort(MSG_ENTITY, self.colormap);
-	}
-
-	if(sf & 2)
-	{
-		WriteCoord(MSG_ENTITY, self.origin_x);
-		WriteCoord(MSG_ENTITY, self.origin_y);
-		WriteCoord(MSG_ENTITY, self.origin_z);
-	}
-
-	if(sf & 4)
-	{
-		if(sf & 0x10)
-		{
-			WriteAngle(MSG_ENTITY, self.angles_x);
-			WriteAngle(MSG_ENTITY, self.angles_y);
-			WriteAngle(MSG_ENTITY, self.angles_z);
-		}
-	}
-
-	if(sf & 8)
-	{
-		WriteShort(MSG_ENTITY, self.modelindex);
-		WriteByte(MSG_ENTITY, self.solid);
-		WriteByte(MSG_ENTITY, floor(self.scale * 16));
-		if(sf & 0x20)
-		{
-			WriteCoord(MSG_ENTITY, self.mins_x);
-			WriteCoord(MSG_ENTITY, self.mins_y);
-			WriteCoord(MSG_ENTITY, self.mins_z);
-			WriteCoord(MSG_ENTITY, self.maxs_x);
-			WriteCoord(MSG_ENTITY, self.maxs_y);
-			WriteCoord(MSG_ENTITY, self.maxs_z);
-		}
-		WriteString(MSG_ENTITY, self.bgmscript);
-		if(self.bgmscript != "")
-		{
-			WriteByte(MSG_ENTITY, floor(self.bgmscriptattack * 64));
-			WriteByte(MSG_ENTITY, floor(self.bgmscriptdecay * 64));
-			WriteByte(MSG_ENTITY, floor(self.bgmscriptsustain * 255));
-			WriteByte(MSG_ENTITY, floor(self.bgmscriptrelease * 64));
-			WriteCoord(MSG_ENTITY, self.movedir_x);
-			WriteCoord(MSG_ENTITY, self.movedir_y);
-			WriteCoord(MSG_ENTITY, self.movedir_z);
-			WriteByte(MSG_ENTITY, floor(self.lip * 255));
-		}
-	}
-
-	return TRUE;
-}
-
-void func_clientwall_use (void)
-{
-	if(teams_matter)
-	{
-		if(activator.team)
-			self.colormap = (activator.team - 1) * 0x11;
-		else
-			self.colormap = 0x00;
-	}
-	else
-		self.colormap = floor(random() * 256);
-	self.colormap |= 1024; // RENDER_COLORMAPPED
-	self.SendFlags |= 1;
-}
-
-void gamemodel_drop();
-void clientmodel_drop()
-{
-	vector o0;
-	o0 = self.origin;
-	gamemodel_drop();
-	if(self.origin != o0)
-		self.SendFlags |= 2;
-}
-
-void spawnfunc_misc_clientmodel()
-{
-	SetBrushEntityModelNoLOD(); // LOD can't be done the CEFC way
-	self.use = func_clientwall_use;
-
-	if(!self.bgmscriptsustain)
-		self.bgmscriptsustain = 1;
-	else if(self.bgmscriptsustain < 0)
-		self.bgmscriptsustain = 0;
-
-	InitializeEntity(self, clientmodel_drop, INITPRIO_DROPTOFLOOR);
-
-	Net_LinkEntity(self, TRUE, 0, func_clientwall_send);
-}
-
-void spawnfunc_func_clientillusionary()
-{
-	SetBrushEntityModelNoLOD(); // LOD can't be done the CEFC way
-	self.use = func_clientwall_use;
-
-	if(!self.bgmscriptsustain)
-		self.bgmscriptsustain = 1;
-	else if(self.bgmscriptsustain < 0)
-		self.bgmscriptsustain = 0;
-
-	Net_LinkEntity(self, TRUE, 0, func_clientwall_send);
-}
-
-void spawnfunc_func_clientwall()
-{
-	SetBrushEntityModelNoLOD(); // LOD can't be done the CEFC way
-	if(!self.solid)
-		self.solid = SOLID_BSP;
-	self.use = func_clientwall_use;
-
-	if(!self.bgmscriptsustain)
-		self.bgmscriptsustain = 1;
-	else if(self.bgmscriptsustain < 0)
-		self.bgmscriptsustain = 0;
-
-	Net_LinkEntity(self, TRUE, 0, func_clientwall_send);
-}
-
 void spawnfunc_func_sparks()
 {
 	// self.cnt is the amount of sparks that one burst will spawn

Modified: trunk/data/qcsrc/server/progs.src
===================================================================
--- trunk/data/qcsrc/server/progs.src	2009-04-17 18:42:26 UTC (rev 6524)
+++ trunk/data/qcsrc/server/progs.src	2009-04-17 19:00:47 UTC (rev 6525)
@@ -83,6 +83,7 @@
 sv_stats.qc
 
 g_triggers.qc
+g_models.qc
 
 cl_weaponsystem.qc
 w_common.qc

Modified: trunk/data/qcsrc/server/t_items.qc
===================================================================
--- trunk/data/qcsrc/server/t_items.qc	2009-04-17 18:42:26 UTC (rev 6524)
+++ trunk/data/qcsrc/server/t_items.qc	2009-04-17 19:00:47 UTC (rev 6525)
@@ -989,76 +989,6 @@
 // compatibility:
 void spawnfunc_item_quad (void) {self.classname = "item_strength";spawnfunc_item_strength();}
 
-void spawnfunc_misc_models (void)
-{
-	// exists as alias name for 2.4.2 compat
-	SetBrushEntityModel();
-}
-
-void spawnfunc_func_static (void)
-{
-	// exists as alias name for having it with brushes
-	SetBrushEntityModel();
-}
-
-void func_wall_use (void)
-{
-	if(teams_matter)
-	{
-		if(activator.team)
-			self.colormap = (activator.team - 1) * 0x11;
-		else
-			self.colormap = 0x00;
-	}
-	else
-		self.colormap = floor(random() * 256);
-	self.colormap |= 1024; // RENDER_COLORMAPPED
-}
-
-void spawnfunc_func_wall (void)
-{
-	SetBrushEntityModel();
-	if(!self.solid)
-		self.solid = SOLID_BSP;
-	self.use = func_wall_use;
-}
-
-void spawnfunc_func_illusionary (void)
-{
-	SetBrushEntityModel();
-	self.use = func_wall_use;
-}
-
-void gamemodel_drop()
-{
-	if(self.spawnflags & 3 == 1) // ALIGN_ORIGIN
-	{
-		traceline(self.origin, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
-		setorigin(self, trace_endpos);
-	}
-	else if(self.spawnflags & 3 == 2) // ALIGN_BOTTOM
-	{
-		tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
-		setorigin(self, trace_endpos);
-	}
-	else if(self.spawnflags & 3 == 3) // ALIGN_ORIGIN | ALIGN_BOTTOM
-	{
-		traceline(self.origin, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
-		setorigin(self, trace_endpos - '0 0 1' * self.mins_z);
-	}
-}
-
-.float modelscale;
-void spawnfunc_misc_gamemodel (void)
-{
-	if(!self.scale)
-		self.scale = self.modelscale;
-	SetBrushEntityModel();
-	self.use = func_wall_use;
-
-	InitializeEntity(self, gamemodel_drop, INITPRIO_DROPTOFLOOR);
-}
-
 float target_item_func_set(float a, float b)
 {
 	if(b == 0)



More information about the nexuiz-commits mailing list