r4567 - trunk/data/qcsrc/server
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Wed Oct 1 07:22:19 EDT 2008
Author: div0
Date: 2008-10-01 07:22:17 -0400 (Wed, 01 Oct 2008)
New Revision: 4567
Modified:
trunk/data/qcsrc/server/gamecommand.qc
Log:
roughmap command: made it run in "background" (still makes a server unplayable); this allows larger output images without hitting DP's loop counter
Modified: trunk/data/qcsrc/server/gamecommand.qc
===================================================================
--- trunk/data/qcsrc/server/gamecommand.qc 2008-10-01 07:41:23 UTC (rev 4566)
+++ trunk/data/qcsrc/server/gamecommand.qc 2008-10-01 11:22:17 UTC (rev 4567)
@@ -37,88 +37,149 @@
return floor(FullTraceFraction(a, mi, ma, b) / (world.maxs_z - world.mins_z) * 255);
}
#else
-float RoughMapAtPoint(float x, float y, float w, float h)
+float RoughMapAtPoint(float x, float y, float w, float h, float zmin, float zsize)
{
vector o, mi, ma;
float i, r;
vector dz;
mi = '0 0 0';
- dz = ((mi_max_z - mi_min_z) / 64) * '0 0 1';
+ dz = (zsize / 256) * '0 0 1';
ma = '1 0 0' * w + '0 1 0' * h + dz;
- o = '1 0 0' * x + '0 1 0' * y + '0 0 1' * mi_min_z;
+ o = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
r = 0;
- for(i = 0; i < 51; ++i)
+ for(i = 0; i < 255; ++i)
{
tracebox(o + dz * i, mi, ma, o + dz * i, MOVE_WORLDONLY, world);
if(trace_startsolid)
++r;
}
- return r * 5; // 0 .. 255
+ return r; // 0 .. 255
}
#endif
string doublehex = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF";
-void RoughMap()
+entity roughmapper;
+// rough map entity
+// cnt: current line
+// size: pixel width/height
+// maxs: cell width/height
+// frame: counter
+void RoughMap_Think()
{
- float w, h;
- float m, n;
- float x, y;
- float l;
- float f;
- float i;
+ float i, x, l;
string si;
- string fn;
- get_mi_min_max();
-
- m = 256;
- n = 256;
-
- w = (mi_picmax_x - mi_picmin_x) / m;
- h = (mi_picmax_y - mi_picmin_y) / n;
-
- print("Picture mins/maxs: ", ftos(w), " and ", ftos(h), " should match\n");
-
- fn = strcat("maps/", mi_shortname, "_mini.xpm");
- f = fopen(fn, FILE_WRITE);
- if(f < 0)
+ if(self.frame == 0)
{
- print("Error writing ", fn, "\n");
- return;
+ // initialize
+ get_mi_min_max();
+ self.size_x = 512;
+ self.size_y = 512;
+ self.mins = mi_min;
+ self.maxs_x = (mi_picmax_x - mi_picmin_x) / self.size_x;
+ self.maxs_y = (mi_picmax_y - mi_picmin_y) / self.size_y;
+ self.maxs_z = mi_max_z - mi_min_z;
+ print("Picture mins/maxs: ", ftos(self.maxs_x), " and ", ftos(self.maxs_y), " should match\n");
+ self.netname = strzone(strcat("maps/", mi_shortname, "_mini.xpm"));
+ if(!(self.count & 1))
+ {
+ self.cnt = fopen(self.netname, FILE_READ);
+ if(self.cnt >= 0)
+ {
+ print(self.netname, " already exists, aborting (you may want to specify --force)\n");
+ if(self.count & 2)
+ {
+ if(self.count & 1)
+ localcmd("defer 1 \"sv_cmd roughmap --force --loop\"\n");
+ else
+ localcmd("defer 1 \"sv_cmd roughmap --loop\"\n");
+ GotoNextMap();
+ }
+ remove(self);
+ return;
+ }
+ }
+ self.cnt = fopen(self.netname, FILE_WRITE);
+ if(self.cnt < 0)
+ {
+ print("Error writing ", self.netname, "\n");
+ remove(self);
+ roughmapper = world;
+ return;
+ }
+ print("Writing to ", self.netname, "...\n");
+ fputs(self.cnt, "/* XPM */\n");
+ fputs(self.cnt, "static char *RoughMap[] = {\n");
+ fputs(self.cnt, "/* columns rows colors chars-per-pixel */\n");
+ fputs(self.cnt, strcat("\"", ftos(self.size_x), " ", ftos(self.size_y), " 256 2\",\n"));
+ for(i = 0; i < 256; ++i)
+ {
+ si = substring(doublehex, i*2, 2);
+ fputs(self.cnt, strcat("\"", si, " c #", si, si, si, "\",\n"));
+ }
+ self.frame += 1;
+ self.nextthink = time;
}
- print("Writing to ", fn, "...\n");
- fputs(f, "/* XPM */\n");
- fputs(f, "static char *RoughMap[] = {\n");
- fputs(f, "/* columns rows colors chars-per-pixel */\n");
- fputs(f, strcat("\"", ftos(m), " ", ftos(n), " 256 2\",\n"));
- for(i = 0; i < 256; ++i)
+ else if(self.frame <= self.size_y)
{
- si = substring(doublehex, i*2, 2);
- fputs(f, strcat("\"", si, " c #", si, si, si, "\",\n"));
- }
- for(y = n-1; y >= 0; --y)
- {
- fputs(f, "\"");
- for(x = 0; x < m; ++x)
+ // write a pixel line
+ fputs(self.cnt, "\"");
+ for(x = 0; x < self.size_x; ++x)
{
- l = RoughMapAtPoint(mi_min_x + x * w, mi_min_y + y * h, w, h);
- fputs(f, substring(doublehex, 2 * l, 2));
+ l = RoughMapAtPoint(self.mins_x + x * self.maxs_x, self.mins_y + (self.size_y - self.frame) * self.maxs_y, self.maxs_x, self.maxs_y, self.mins_z, self.maxs_z);
+ fputs(self.cnt, substring(doublehex, 2 * l, 2));
}
- if(y == 0)
- fputs(f, "\"\n");
+ if(self.frame == self.size_y)
+ fputs(self.cnt, "\"\n");
else
{
- fputs(f, "\",\n");
- print(ftos(y), " lines left\n");
+ fputs(self.cnt, "\",\n");
+ print(ftos(self.size_y - self.frame), " lines left\n");
}
+ self.frame += 1;
+ self.nextthink = time;
}
- fputs(f, "};\n");
- fclose(f);
- print("Finished. Please edit data/", fn, " with an image editing application and place it in the TGA format in the same folder as the BSP file.\n");
+ else
+ {
+ // close the file
+ fputs(self.cnt, "};\n");
+ fclose(self.cnt);
+ print("Finished. Please edit data/", self.netname, " with an image editing application and place it in the TGA format in the same folder as the BSP file.\n");
+ if(self.count & 2)
+ {
+ if(self.count & 1)
+ localcmd("defer 1 \"sv_cmd roughmap --force --loop\"\n");
+ else
+ localcmd("defer 1 \"sv_cmd roughmap --loop\"\n");
+ GotoNextMap();
+ }
+ remove(self);
+ roughmapper = world;
+ }
}
+void RoughMap(float argc)
+{
+ if(roughmapper)
+ return;
+ float i;
+ roughmapper = spawn();
+ roughmapper.classname = "roughmapper";
+ roughmapper.think = RoughMap_Think;
+ roughmapper.nextthink = time;
+ roughmapper.count = 0;
+
+ for(i = 1; i < argc; ++i)
+ {
+ if(argv(i) == "--force")
+ roughmapper.count |= 1;
+ if(argv(i) == "--loop")
+ roughmapper.count |= 2;
+ }
+}
+
void EffectIndexDump()
{
float d;
@@ -403,7 +464,7 @@
}
if (argv(0) == "roughmap")
{
- RoughMap();
+ RoughMap(argc);
return;
}
if (argv(0) == "cvar_changes")
More information about the nexuiz-commits
mailing list