r2866 - in trunk/data/qcsrc: common menu-div0test menu-div0test/item server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Tue Oct 30 03:54:52 EDT 2007


Author: div0
Date: 2007-10-30 03:54:42 -0400 (Tue, 30 Oct 2007)
New Revision: 2866

Modified:
   trunk/data/qcsrc/common/util.qc
   trunk/data/qcsrc/common/util.qh
   trunk/data/qcsrc/menu-div0test/gamecommand.qc
   trunk/data/qcsrc/menu-div0test/item.c
   trunk/data/qcsrc/menu-div0test/item/checkbox.c
   trunk/data/qcsrc/menu-div0test/item/container.c
   trunk/data/qcsrc/menu-div0test/item/dialog.c
   trunk/data/qcsrc/menu-div0test/item/image.c
   trunk/data/qcsrc/menu-div0test/item/label.c
   trunk/data/qcsrc/menu-div0test/item/slider.c
   trunk/data/qcsrc/server/g_world.qc
Log:
added utility for depth-first search; added debug command "menu_cmd dumptree" to dump the state of the menu as a tree (see http://pastebin.com/m2a24265c)


Modified: trunk/data/qcsrc/common/util.qc
===================================================================
--- trunk/data/qcsrc/common/util.qc	2007-10-30 03:35:15 UTC (rev 2865)
+++ trunk/data/qcsrc/common/util.qc	2007-10-30 07:54:42 UTC (rev 2866)
@@ -101,3 +101,34 @@
 	// vlen of the remaining vector
 	return vlen(p);
 }
+
+void depthfirst(entity start, .entity up, .entity downleft, .entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass)
+{
+	entity e;
+	e = start;
+	funcPre(pass, e);
+	while(e.downleft)
+	{
+		e = e.downleft;
+		funcPre(pass, e);
+	}
+	funcPost(pass, e);
+	while(e != start)
+	{
+		if(e.right)
+		{
+			e = e.right;
+			funcPre(pass, e);
+			while(e.downleft)
+			{
+				e = e.downleft;
+				funcPre(pass, e);
+			}
+		}
+		else
+			e = e.up;
+		funcPost(pass, e);
+	}
+}
+
+

Modified: trunk/data/qcsrc/common/util.qh
===================================================================
--- trunk/data/qcsrc/common/util.qh	2007-10-30 03:35:15 UTC (rev 2865)
+++ trunk/data/qcsrc/common/util.qh	2007-10-30 07:54:42 UTC (rev 2866)
@@ -20,3 +20,7 @@
 float GameCommand_Generic(string cmd);
 // returns TRUE if handled, FALSE otherwise
 // uses tokenize on its argument!
+
+// iterative depth-first search, with fields that go "up", "down left" and "right" in a tree
+// for each element, funcPre is called first, then funcPre and funcPost for all its children, and funcPost last
+void depthfirst(entity start, .entity up, .entity downleft, .entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass);

Modified: trunk/data/qcsrc/menu-div0test/gamecommand.qc
===================================================================
--- trunk/data/qcsrc/menu-div0test/gamecommand.qc	2007-10-30 03:35:15 UTC (rev 2865)
+++ trunk/data/qcsrc/menu-div0test/gamecommand.qc	2007-10-30 07:54:42 UTC (rev 2866)
@@ -4,6 +4,33 @@
 	localcmd("alias qc_cmd \"menu_cmd $*\"\n");
 }
 
+string _dumptree_space;
+void _dumptree_open(entity pass, entity me)
+{
+	string s;
+	s = me.toString(me);
+	if(s == "")
+		s = me.classname;
+	else
+		s = strcat(me.classname, ": ", s);
+	print(_dumptree_space, etos(me), " (", s, ")");
+	if(me.firstChild)
+	{
+		print(" {\n");
+		_dumptree_space = strcat(_dumptree_space, "  ");
+	}
+	else
+		print("\n");
+}
+void _dumptree_close(entity pass, entity me)
+{
+	if(me.firstChild)
+	{
+		_dumptree_space = substring(_dumptree_space, 0, strlen(_dumptree_space) - 2);
+		print(_dumptree_space, "}\n");
+	}
+}
+
 void GameCommand(string theCommand)
 {
 	float argc;
@@ -34,5 +61,12 @@
 		return;
 	}
 
+	if(argv(0) == "dumptree")
+	{
+		_dumptree_space = "";
+		depthfirst(main, parent, firstChild, nextSibling, _dumptree_open, _dumptree_close, NULL);
+		return;
+	}
+
 	print("Invalid theCommand. For a list of supported theCommands, try menu_cmd help.\n");
 }

Modified: trunk/data/qcsrc/menu-div0test/item/checkbox.c
===================================================================
--- trunk/data/qcsrc/menu-div0test/item/checkbox.c	2007-10-30 03:35:15 UTC (rev 2865)
+++ trunk/data/qcsrc/menu-div0test/item/checkbox.c	2007-10-30 07:54:42 UTC (rev 2866)
@@ -4,6 +4,7 @@
 	METHOD(CheckBox, configureCheckBox, void(entity, string, float, string))
 	METHOD(CheckBox, resizeNotify, void(entity, vector, vector, vector, vector))
 	METHOD(CheckBox, draw, void(entity))
+	METHOD(CheckBox, toString, string(entity))
 	ATTRIB(CheckBox, checked, float, 0)
 	ATTRIB(CheckBox, onClick, void(entity, entity), CheckBox_Click)
 	ATTRIB(CheckBox, srcMulti, float, 0)
@@ -15,6 +16,10 @@
 {
 	me.checked = !me.checked;
 }
+string toStringCheckBox(entity me)
+{
+	return strcat(toStringLabel(me), ", ", me.checked ? "checked" : "unchecked");
+}
 void configureCheckBoxCheckBox(entity me, string txt, float sz, string gfx)
 {
 	me.configureButton(me, txt, sz, gfx);

Modified: trunk/data/qcsrc/menu-div0test/item/container.c
===================================================================
--- trunk/data/qcsrc/menu-div0test/item/container.c	2007-10-30 03:35:15 UTC (rev 2865)
+++ trunk/data/qcsrc/menu-div0test/item/container.c	2007-10-30 07:54:42 UTC (rev 2866)
@@ -22,14 +22,14 @@
 	ATTRIB(Container, lastChild, entity, NULL)
 	ATTRIB(Container, focusedChild, entity, NULL)
 ENDCLASS(Container)
+.entity nextSibling;
+.entity prevSibling;
 #endif
 
 #ifdef IMPLEMENTATION
 .vector Container_origin;
 .vector Container_size;
 .float Container_alpha;
-.entity nextSibling;
-.entity prevSibling;
 
 void openContainer(entity me)
 {

Modified: trunk/data/qcsrc/menu-div0test/item/dialog.c
===================================================================
--- trunk/data/qcsrc/menu-div0test/item/dialog.c	2007-10-30 03:35:15 UTC (rev 2865)
+++ trunk/data/qcsrc/menu-div0test/item/dialog.c	2007-10-30 07:54:42 UTC (rev 2866)
@@ -131,7 +131,7 @@
 	if(me.closable)
 	{
 		closebutton = me.closeButton = spawnButton();
-		closebutton.configureButton(closebutton, "", 12, me.closeButtonImage);
+		closebutton.configureButton(closebutton, "Close", 0, me.closeButtonImage);
 		closebutton.onClick = Dialog_Close; closebutton.onClickEntity = me;
 		closebutton.srcMulti = 0;
 		me.addItem(me, closebutton, '0 0 0', '1 1 0', 1); // put it as LAST

Modified: trunk/data/qcsrc/menu-div0test/item/image.c
===================================================================
--- trunk/data/qcsrc/menu-div0test/item/image.c	2007-10-30 03:35:15 UTC (rev 2865)
+++ trunk/data/qcsrc/menu-div0test/item/image.c	2007-10-30 07:54:42 UTC (rev 2866)
@@ -2,11 +2,16 @@
 CLASS(Image) EXTENDS(Item)
 	METHOD(Image, configureImage, void(entity, string))
 	METHOD(Image, draw, void(entity))
+	METHOD(Image, toString, string(entity))
 	ATTRIB(Image, src, string, "")
 ENDCLASS(Image)
 #endif
 
 #ifdef IMPLEMENTATION
+string toStringImage(entity me)
+{
+	return me.src;
+}
 void configureImageImage(entity me, string path)
 {
 	me.src = path;

Modified: trunk/data/qcsrc/menu-div0test/item/label.c
===================================================================
--- trunk/data/qcsrc/menu-div0test/item/label.c	2007-10-30 03:35:15 UTC (rev 2865)
+++ trunk/data/qcsrc/menu-div0test/item/label.c	2007-10-30 07:54:42 UTC (rev 2866)
@@ -4,6 +4,7 @@
 	METHOD(Label, draw, void(entity))
 	METHOD(Label, resizeNotify, void(entity, vector, vector, vector, vector))
 	METHOD(Label, setText, void(entity, string))
+	METHOD(Label, toString, string(entity))
 	ATTRIB(Label, text, string, "Big Red Button")
 	ATTRIB(Label, fontSize, float, 8)
 	ATTRIB(Label, align, float, 0.5)
@@ -16,6 +17,10 @@
 #endif
 
 #ifdef IMPLEMENTATION
+string toStringLabel(entity me)
+{
+	return me.text;
+}
 void setTextLabel(entity me, string txt)
 {
 	me.text = txt;
@@ -37,7 +42,7 @@
 }
 void drawLabel(entity me)
 {
-	if(me.text)
+	if(me.text && me.fontSize)
 		draw_Text(me.realOrigin, me.text, me.realFontSize, '1 1 1', me.alpha);
 }
 #endif

Modified: trunk/data/qcsrc/menu-div0test/item/slider.c
===================================================================
--- trunk/data/qcsrc/menu-div0test/item/slider.c	2007-10-30 03:35:15 UTC (rev 2865)
+++ trunk/data/qcsrc/menu-div0test/item/slider.c	2007-10-30 07:54:42 UTC (rev 2866)
@@ -9,6 +9,7 @@
 	METHOD(Slider, mouseDrag, float(entity, vector))
 	METHOD(Slider, mouseRelease, float(entity, vector))
 	METHOD(Slider, valueToText, string(entity, float))
+	METHOD(Slider, toString, string(entity))
 	ATTRIB(Slider, src, string, "")
 	ATTRIB(Slider, focusable, float, 1)
 	ATTRIB(Slider, value, float, 0)
@@ -26,6 +27,10 @@
 #endif
 
 #ifdef IMPLEMENTATION
+string toStringSlider(entity me)
+{
+	return strcat(ftos(me.value), " (", me.valueToText(me, me.value), ")");
+}
 void resizeNotifySlider(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
 {
 	resizeNotifyLabel(me, relOrigin, relSize, absOrigin, absSize);
@@ -128,14 +133,17 @@
 void drawSlider(entity me)
 {
 	float controlLeft;
-	controlLeft = (me.value - me.valueMin) / (me.valueMax - me.valueMin) * (1 - me.valueSpace - me.controlWidth);
 	draw_ButtonPicture('0 0 0', strcat(me.src, "_s"), eX * (1 - me.valueSpace) + eY, '1 1 1', 1);
-	if(me.pressed)
-		draw_Picture(eX * controlLeft, strcat(me.src, "_c"), eX * me.controlWidth + eY, '1 1 1', 1);
-	else if(me.focused)
-		draw_Picture(eX * controlLeft, strcat(me.src, "_f"), eX * me.controlWidth + eY, '1 1 1', 1);
-	else
-		draw_Picture(eX * controlLeft, strcat(me.src, "_n"), eX * me.controlWidth + eY, '1 1 1', 1);
+	if(me.value >= me.valueMin && me.value <= me.valueMax)
+	{
+		controlLeft = (me.value - me.valueMin) / (me.valueMax - me.valueMin) * (1 - me.valueSpace - me.controlWidth);
+		if(me.pressed)
+			draw_Picture(eX * controlLeft, strcat(me.src, "_c"), eX * me.controlWidth + eY, '1 1 1', 1);
+		else if(me.focused)
+			draw_Picture(eX * controlLeft, strcat(me.src, "_f"), eX * me.controlWidth + eY, '1 1 1', 1);
+		else
+			draw_Picture(eX * controlLeft, strcat(me.src, "_n"), eX * me.controlWidth + eY, '1 1 1', 1);
+	}
 	me.setText(me, me.valueToText(me, me.value));
 	drawLabel(me);
 	me.text = ""; // TEMPSTRING!

Modified: trunk/data/qcsrc/menu-div0test/item.c
===================================================================
--- trunk/data/qcsrc/menu-div0test/item.c	2007-10-30 03:35:15 UTC (rev 2865)
+++ trunk/data/qcsrc/menu-div0test/item.c	2007-10-30 07:54:42 UTC (rev 2866)
@@ -12,6 +12,7 @@
 	METHOD(Item, resizeNotify, void(entity, vector, vector, vector, vector))
 	METHOD(Item, relinquishFocus, void(entity))
 	METHOD(Item, open, void(entity))
+	METHOD(Item, toString, string(entity))
 	ATTRIB(Item, focused, float, 0)
 	ATTRIB(Item, focusable, float, 0)
 	ATTRIB(Item, parent, entity, NULL)
@@ -75,4 +76,9 @@
 void focusLeaveItem(entity me)
 {
 }
+
+string toStringItem(entity me)
+{
+	return "";
+}
 #endif

Modified: trunk/data/qcsrc/server/g_world.qc
===================================================================
--- trunk/data/qcsrc/server/g_world.qc	2007-10-30 03:35:15 UTC (rev 2865)
+++ trunk/data/qcsrc/server/g_world.qc	2007-10-30 07:54:42 UTC (rev 2866)
@@ -53,6 +53,104 @@
 	world.frags = 0;
 }
 
+float BoxSurfaceArea(vector d)
+{
+	return 2 * (d_x * d_y + d_y * d_z + d_z * d_x);
+}
+
+vector BoxPand(vector d, vector n)
+{
+	return max(d_x, n_x) * '1 0 0' + max(d_y, n_y) * '0 1 0' + max(d_z, n_z) * '0 0 1';
+}
+
+void bsp()
+{
+	float globhandle;
+	float i, n;
+	float area;
+	globhandle = search_begin("maps/*.bsp", TRUE, FALSE);
+	n = search_getsize(globhandle);
+	for(i = 0; i < n; ++i)
+	{
+		string fn;
+		string s;
+		float fh;
+		fn = search_getfilename(globhandle, i);
+		print("Processing ", fn);
+		fh = fopen(fn, FILE_READ);
+
+		string e_classname;
+		vector e_origin;
+		float spawns;
+		float spawns1;
+		float spawns2;
+		spawns = spawns1 = spawns2 = 0;
+		vector spawnmins, spawnmaxs;
+		vector spawnmins1, spawnmaxs1;
+		vector spawnmins2, spawnmaxs2;
+		while((s = fgets(fh)))
+		{
+			if(s == "}")
+			{
+				// entity ends
+				if(e_classname == "info_player_start" || e_classname == "info_player_deathmatch")
+				{
+					if(spawns)
+					{
+						spawnmins = -1 * BoxPand(-1 * spawnmins, -1 * e_origin);
+						spawnmaxs =      BoxPand(     spawnmaxs,      e_origin);
+					}
+					else
+						spawnmins = spawnmaxs = e_origin;
+					++spawns;
+				}
+				else if(e_classname == "info_player_team1")
+				{
+					if(spawns)
+					{
+						spawnmins = -1 * BoxPand(-1 * spawnmins, -1 * e_origin);
+						spawnmaxs =      BoxPand(     spawnmaxs,      e_origin);
+						spawnmins1 = -1 * BoxPand(-1 * spawnmins1, -1 * e_origin);
+						spawnmaxs1 =      BoxPand(     spawnmaxs1,      e_origin);
+					}
+					else
+						spawnmins = spawnmaxs = e_origin;
+					++spawns;
+					++spawns1;
+				}
+				else if(e_classname == "info_player_team2")
+				{
+					if(spawns)
+					{
+						spawnmins = -1 * BoxPand(-1 * spawnmins, -1 * e_origin);
+						spawnmaxs =      BoxPand(     spawnmaxs,      e_origin);
+						spawnmins2 = -1 * BoxPand(-1 * spawnmins2, -1 * e_origin);
+						spawnmaxs2 =      BoxPand(     spawnmaxs2,      e_origin);
+					}
+					else
+						spawnmins = spawnmaxs = e_origin;
+					++spawns;
+					++spawns2;
+				}
+				e_classname = "";
+				e_origin = '0 0 0';
+			}
+			else if(substring(s, 0, 13) == "\"classname\" \"")
+				e_classname = substring(s, 13, strlen(s) - 14);
+			else if(substring(s, 0, 10) == "\"origin\" \"")
+				e_origin = stov(substring(s, 10, strlen(s) - 11));
+		}
+		fclose(fh);
+		print(" -- found ", ftos(spawns), " spawns [");
+		print(vtos(spawnmins), " - ", vtos(spawnmaxs), "\n");
+
+		area = BoxSurfaceArea(spawnmaxs - spawnmins);
+		print("Spawn box surface area: ", ftos(area), "\n");
+		print("^4plot: ", ftos(area), " ", ftos(spawns), "\n");
+	}
+	search_end(globhandle);
+}
+
 void GotoFirstMap()
 {
 	if(cvar("_sv_init"))
@@ -101,6 +199,7 @@
 		precache_model ("models/runematch/rune.mdl");
 	}
 
+	bsp();
 	// Precache all player models if desired
 	if (cvar("sv_precacheplayermodels"))
 	{




More information about the nexuiz-commits mailing list