]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/command/radarmap.qc
take3: format 903 files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / command / radarmap.qc
index 6c31af72c853d54cdef08fd5d723940efe6baecf..5a42b8188254cd9b562c9e6cedeac7d259d33872 100644 (file)
@@ -27,15 +27,13 @@ float FullTraceFraction(vector a, vector mi, vector ma, vector b)
        float n, m;
        n = m = 0;
 
-       while (vdist(c - b, >, 1))
-       {
+       while (vdist(c - b, >, 1)) {
                ++m;
 
                tracebox(c, mi, ma, b, MOVE_WORLDONLY, NULL);
                ++n;
 
-               if (!trace_startsolid)
-               {
+               if (!trace_startsolid) {
                        black += vlen(trace_endpos - c);
                        c = trace_endpos;
                }
@@ -46,7 +44,7 @@ float FullTraceFraction(vector a, vector mi, vector ma, vector b)
                c = trace_endpos;
        }
 
-       if (n > 200) LOG_TRACE("HOLY SHIT! FullTraceFraction: ", ftos(n), " total traces, ", ftos(m), " iterations");
+       if (n > 200) { LOG_TRACE("HOLY SHIT! FullTraceFraction: ", ftos(n), " total traces, ", ftos(m), " iterations"); }
 
        return white / (black + white);
 }
@@ -75,14 +73,13 @@ float RadarMapAtPoint_LineBlock(float e, float f, float w, float h, float zmin,
        ma = '1 0 0' * w + '0 1 0' * h + dz;
        o = '1 0 0' * e + '0 1 0' * f + '0 0 1' * zmin;
 
-       if (e < world.absmin.x - w) return 0;
-       if (f < world.absmin.y - h) return 0;
-       if (e > world.absmax.x) return 0;
-       if (f > world.absmax.y) return 0;
+       if (e < world.absmin.x - w) { return 0; }
+       if (f < world.absmin.y - h) { return 0; }
+       if (e > world.absmax.x) { return 0; }
+       if (f > world.absmax.y) { return 0; }
 
        r = 0;
-       for (i = 0; i < q; ++i)
-       {
+       for (i = 0; i < q; ++i) {
                vector v1, v2;
                v1 = v2 = o + dz * i + mi;
                v1_x += random() * (ma.x - mi.x);
@@ -92,7 +89,7 @@ float RadarMapAtPoint_LineBlock(float e, float f, float w, float h, float zmin,
                v2_y += random() * (ma.y - mi.y);
                v2_z += random() * (ma.z - mi.z);
                traceline(v1, v2, MOVE_WORLDONLY, NULL);
-               if (trace_startsolid || trace_fraction < 1) ++r;
+               if (trace_startsolid || trace_fraction < 1) { ++r; }
        }
        return r / q;
 }
@@ -110,16 +107,15 @@ float RadarMapAtPoint_Block(float e, float f, float w, float h, float zmin, floa
        ma = '1 0 0' * w + '0 1 0' * h + dz;
        o = '1 0 0' * e + '0 1 0' * f + '0 0 1' * zmin;
 
-       if (e < world.absmin.x - w) return 0;
-       if (f < world.absmin.y - h) return 0;
-       if (e > world.absmax.x) return 0;
-       if (f > world.absmax.y) return 0;
+       if (e < world.absmin.x - w) { return 0; }
+       if (f < world.absmin.y - h) { return 0; }
+       if (e > world.absmax.x) { return 0; }
+       if (f > world.absmax.y) { return 0; }
 
        r = 0;
-       for (i = 0; i < q; ++i)
-       {
+       for (i = 0; i < q; ++i) {
                tracebox(o + dz * i, mi, ma, o + dz * i, MOVE_WORLDONLY, NULL);
-               if (trace_startsolid) ++r;
+               if (trace_startsolid) { ++r; }
        }
        return r / q;
 }
@@ -127,7 +123,7 @@ float RadarMapAtPoint_Sample(float e, float f, float w, float h, float zmin, flo
 {
        vector a, b, mi, ma;
 
-       q *= 4;  // choose q so it matches the regular algorithm in speed
+       q *= 4; // choose q so it matches the regular algorithm in speed
 
        q = 256 * q - 1;
        // 256q-1 is the ideal sample count to map equal amount of sample values to one pixel value
@@ -140,14 +136,13 @@ float RadarMapAtPoint_Sample(float e, float f, float w, float h, float zmin, flo
        float c, i;
        c = 0;
 
-       for (i = 0; i < q; ++i)
-       {
+       for (i = 0; i < q; ++i) {
                vector v;
                v.x = a.x + random() * b.x;
                v.y = a.y + random() * b.y;
                v.z = a.z + random() * b.z;
                traceline(v, v, MOVE_WORLDONLY, NULL);
-               if (trace_startsolid) ++c;
+               if (trace_startsolid) { ++c; }
        }
 
        return c / q;
@@ -158,16 +153,16 @@ void sharpen_set(int b, float v)
 }
 float sharpen_getpixel(int b, int c)
 {
-       if (b < 0) return 0;
-       if (b >= RADAR_WIDTH_MAX) return 0;
-       if (c < 0) return 0;
-       if (c > 2) return 0;
+       if (b < 0) { return 0; }
+       if (b >= RADAR_WIDTH_MAX) { return 0; }
+       if (c < 0) { return 0; }
+       if (c > 2) { return 0; }
        return sharpen_buffer[b + c * RADAR_WIDTH_MAX];
 }
 float sharpen_get(float b, float a)
 {
        float sum = sharpen_getpixel(b, 1);
-       if (a == 0) return sum;
+       if (a == 0) { return sum; }
        sum *= (8 + 1 / a);
        sum -= sharpen_getpixel(b - 1, 0);
        sum -= sharpen_getpixel(b - 1, 1);
@@ -181,8 +176,7 @@ float sharpen_get(float b, float a)
 }
 void sharpen_shift(int w)
 {
-       for (int i = 0; i < w; ++i)
-       {
+       for (int i = 0; i < w; ++i) {
                sharpen_buffer[i] = sharpen_buffer[i + RADAR_WIDTH_MAX];
                sharpen_buffer[i + RADAR_WIDTH_MAX] = sharpen_buffer[i + 2 * RADAR_WIDTH_MAX];
                sharpen_buffer[i + 2 * RADAR_WIDTH_MAX] = 0;
@@ -190,8 +184,7 @@ void sharpen_shift(int w)
 }
 void sharpen_init(int w)
 {
-       for (int i = 0; i < w; ++i)
-       {
+       for (int i = 0; i < w; ++i) {
                sharpen_buffer[i] = 0;
                sharpen_buffer[i + RADAR_WIDTH_MAX] = 0;
                sharpen_buffer[i + 2 * RADAR_WIDTH_MAX] = 0;
@@ -199,12 +192,9 @@ void sharpen_init(int w)
 }
 void RadarMap_Next()
 {
-       if (radarmapper.count & 4)
-       {
+       if (radarmapper.count & 4) {
                localcmd("quit\n");
-       }
-       else if (radarmapper.count & 2)
-       {
+       } else if (radarmapper.count & 2) {
                localcmd(strcat("defer 1 \"sv_cmd radarmap --flags ", ftos(radarmapper.count), strcat(" --res ", ftos(radarmapper.size.x), " ", ftos(radarmapper.size.y), " --sharpen ", ftos(radarmapper.ltime), " --qual ", ftos(radarmapper.size.z)), "\"\n"));
                GotoNextMap(0);
        }
@@ -222,8 +212,7 @@ void RadarMap_Think(entity this)
        float i, x, l;
        string si;
 
-       if (this.frame == 0)
-       {
+       if (this.frame == 0) {
                // initialize
                get_mi_min_max_texcoords(1);
                this.mins = mi_picmin;
@@ -232,17 +221,15 @@ void RadarMap_Think(entity this)
                this.maxs_z = mi_max.z - mi_min.z;
                LOG_INFO("Picture mins/maxs: ", ftos(this.maxs.x), " and ", ftos(this.maxs.y), " should match");
                this.netname = strzone(strcat("gfx/", mi_shortname, "_radar.xpm"));
-               if (!(this.count & 1))
-               {
+               if (!(this.count & 1)) {
                        this.cnt = fopen(this.netname, FILE_READ);
-                       if (this.cnt < 0) this.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.tga"), FILE_READ);
-                       if (this.cnt < 0) this.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.png"), FILE_READ);
-                       if (this.cnt < 0) this.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.jpg"), FILE_READ);
-                       if (this.cnt < 0) this.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.tga"), FILE_READ);
-                       if (this.cnt < 0) this.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.png"), FILE_READ);
-                       if (this.cnt < 0) this.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.jpg"), FILE_READ);
-                       if (this.cnt >= 0)
-                       {
+                       if (this.cnt < 0) { this.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.tga"), FILE_READ); }
+                       if (this.cnt < 0) { this.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.png"), FILE_READ); }
+                       if (this.cnt < 0) { this.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.jpg"), FILE_READ); }
+                       if (this.cnt < 0) { this.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.tga"), FILE_READ); }
+                       if (this.cnt < 0) { this.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.png"), FILE_READ); }
+                       if (this.cnt < 0) { this.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.jpg"), FILE_READ); }
+                       if (this.cnt >= 0) {
                                fclose(this.cnt);
 
                                LOG_INFO(this.netname, " already exists, aborting (you may want to specify --force)");
@@ -251,8 +238,7 @@ void RadarMap_Think(entity this)
                        }
                }
                this.cnt = fopen(this.netname, FILE_WRITE);
-               if (this.cnt < 0)
-               {
+               if (this.cnt < 0) {
                        LOG_INFO("Error writing ", this.netname);
                        delete(this);
                        radarmapper = NULL;
@@ -263,48 +249,40 @@ void RadarMap_Think(entity this)
                fputs(this.cnt, "static char *RadarMap[] = {\n");
                fputs(this.cnt, "/* columns rows colors chars-per-pixel */\n");
                fputs(this.cnt, strcat("\"", ftos(this.size.x), " ", ftos(this.size.y), " 256 2\",\n"));
-               for (i = 0; i < 256; ++i)
-               {
+               for (i = 0; i < 256; ++i) {
                        si = substring(doublehex, i * 2, 2);
                        fputs(this.cnt, strcat("\"", si, " c #", si, si, si, "\",\n"));
                }
                this.frame += 1;
                this.nextthink = time;
                sharpen_init(this.size.x);
-       }
-       else if (this.frame <= this.size.y)
-       {
+       } else if (this.frame <= this.size.y) {
                // fill the sharpen buffer with this line
                sharpen_shift(this.size.x);
                i = this.count & 24;
 
-               switch (i)
-               {
+               switch (i) {
                        case 0:
                        default:
-                               for (x = 0; x < this.size.x; ++x)
-                               {
+                               for (x = 0; x < this.size.x; ++x) {
                                        l = RadarMapAtPoint_Block(this.mins.x + x * this.maxs.x, this.mins.y + (this.size.y - this.frame) * this.maxs.y, this.maxs.x, this.maxs.y, this.mins.z, this.maxs.z, this.size.z);
                                        sharpen_set(x, l);
                                }
                                break;
                        case 8:
-                               for (x = 0; x < this.size.x; ++x)
-                               {
+                               for (x = 0; x < this.size.x; ++x) {
                                        l = RadarMapAtPoint_Trace(this.mins.x + x * this.maxs.x, this.mins.y + (this.size.y - this.frame) * this.maxs.y, this.maxs.x, this.maxs.y, this.mins.z, this.maxs.z, this.size.z);
                                        sharpen_set(x, l);
                                }
                                break;
                        case 16:
-                               for (x = 0; x < this.size.x; ++x)
-                               {
+                               for (x = 0; x < this.size.x; ++x) {
                                        l = RadarMapAtPoint_Sample(this.mins.x + x * this.maxs.x, this.mins.y + (this.size.y - this.frame) * this.maxs.y, this.maxs.x, this.maxs.y, this.mins.z, this.maxs.z, this.size.z);
                                        sharpen_set(x, l);
                                }
                                break;
                        case 24:
-                               for (x = 0; x < this.size.x; ++x)
-                               {
+                               for (x = 0; x < this.size.x; ++x) {
                                        l = RadarMapAtPoint_LineBlock(this.mins.x + x * this.maxs.x, this.mins.y + (this.size.y - this.frame) * this.maxs.y, this.maxs.x, this.maxs.y, this.mins.z, this.maxs.z, this.size.z);
                                        sharpen_set(x, l);
                                }
@@ -312,43 +290,33 @@ void RadarMap_Think(entity this)
                }
 
                // do we have enough lines?
-               if (this.frame >= 2)
-               {
+               if (this.frame >= 2) {
                        // write a pixel line
                        fputs(this.cnt, "\"");
-                       for (x = 0; x < this.size.x; ++x)
-                       {
+                       for (x = 0; x < this.size.x; ++x) {
                                l = sharpen_get(x, this.ltime);
                                fputs(this.cnt, substring(doublehex, 2 * floor(l * 256.0), 2));
                        }
-                       if (this.frame == this.size.y)
-                       {
+                       if (this.frame == this.size.y) {
                                fputs(this.cnt, "\"\n");
-                       }
-                       else
-                       {
+                       } else {
                                fputs(this.cnt, "\",\n");
                                LOG_INFO(ftos(this.size.y - this.frame), " lines left");
                        }
                }
 
                // is this the last line? then write back the missing line
-               if (this.frame == this.size.y)
-               {
+               if (this.frame == this.size.y) {
                        sharpen_shift(this.size.x);
                        // write a pixel line
                        fputs(this.cnt, "\"");
-                       for (x = 0; x < this.size.x; ++x)
-                       {
+                       for (x = 0; x < this.size.x; ++x) {
                                l = sharpen_get(x, this.ltime);
                                fputs(this.cnt, substring(doublehex, 2 * floor(l * 256.0), 2));
                        }
-                       if (this.frame == this.size.y)
-                       {
+                       if (this.frame == this.size.y) {
                                fputs(this.cnt, "\"\n");
-                       }
-                       else
-                       {
+                       } else {
                                fputs(this.cnt, "\",\n");
                                LOG_INFO(ftos(this.size.y - this.frame), " lines left");
                        }
@@ -356,9 +324,7 @@ void RadarMap_Think(entity this)
 
                this.frame += 1;
                this.nextthink = time;
-       }
-       else
-       {
+       } else {
                // close the file
                fputs(this.cnt, "};\n");
                fclose(this.cnt);
@@ -371,18 +337,15 @@ bool RadarMap_Make(float argc)
 {
        float i;
 
-       if (!radarmapper)
-       {
+       if (!radarmapper) {
                radarmapper = new(radarmapper);
                setthink(radarmapper, RadarMap_Think);
                radarmapper.nextthink = time;
-               radarmapper.count = 8;  // default to the --trace method, as it is faster now
+               radarmapper.count = 8; // default to the --trace method, as it is faster now
                radarmapper.ltime = 1;
                radarmapper.size = '512 512 1';
-               for (i = 1; i < argc; ++i)
-               {
-                       switch (argv(i))
-                       {
+               for (i = 1; i < argc; ++i) {
+                       switch (argv(i)) {
                                case "--force":
                                { radarmapper.count |= 1;
                                  break;
@@ -417,13 +380,13 @@ bool RadarMap_Make(float argc)
                                { ++i;
                                  radarmapper.count = stof(argv(i));
                                  break;
-                               }  // for the recursive call
+                               } // for the recursive call
                                case "--sharpen":
                                { ++i;
                                  radarmapper.ltime = stof(argv(i));
                                  break;
-                               }  // for the recursive call
-                               case "--res":  // minor alias
+                               } // for the recursive call
+                               case "--res": // minor alias
                                case "--resolution":
                                { ++i;
                                  radarmapper.size_x = stof(argv(i));
@@ -431,7 +394,7 @@ bool RadarMap_Make(float argc)
                                  radarmapper.size_y = stof(argv(i));
                                  break;
                                }
-                               case "--qual":  // minor alias
+                               case "--qual": // minor alias
                                case "--quality":
                                { ++i;
                                  radarmapper.size_z = stof(argv(i));
@@ -446,10 +409,9 @@ bool RadarMap_Make(float argc)
                        }
                }
 
-               if (radarmapper)  // after doing the arguments, see if we successfully went forward.
-               {
+               if (radarmapper) { // after doing the arguments, see if we successfully went forward.
                        LOG_INFO("Radarmap entity spawned.");
-                       return true;  // if so, don't print usage.
+                       return true;   // if so, don't print usage.
                }
        }