]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/util.qc
Merge branch 'master' into terencehill/newpanelhud
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / util.qc
index 9875529d3fe68c92084d6595e306dfe65f91ae06..1efc0e3738a06a4d9e5c33cd5681571c0d1b0444 100644 (file)
@@ -226,43 +226,8 @@ float median(float a, float b, float c)
 // works for up to 10 decimals!
 string ftos_decimals(float number, float decimals)
 {
-       string result;
-       string tmp;
-       float len;
-
-       // if negative, cut off the sign first
-       if(number < 0)
-               return strcat("-", ftos_decimals(-number, decimals));
-       // it now is always positive!
-
-       // 3.516 -> 352
-       number = floor(number * pow(10, decimals) + 0.5);
-
-       // 352 -> "352"
-       result = ftos(number);
-       len = strlen(result);
-       // does it have a decimal point (should not happen)? If there is one, it is always at len-7)
-               // if ftos had messed it up, which should never happen: "34278.000000"
-       if(len >= 7)
-               if(substring(result, len - 7, 1) == ".")
-               {
-                       dprint("ftos(integer) has comma? Can't be. Affected result: ", result, "\n");
-                       result = substring(result, 0, len - 7);
-                       len -= 7;
-               }
-               // "34278"
-       if(decimals == 0)
-               return result; // don't insert a point for zero decimals
-       // is it too short? If yes, insert leading zeroes
-       if(len <= decimals)
-       {
-               result = strcat(substring("0000000000", 0, decimals - len + 1), result);
-               len = decimals + 1;
-       }
-       // and now... INSERT THE POINT!
-       tmp = substring(result, len - decimals, decimals);
-       result = strcat(substring(result, 0, len - decimals), ".", tmp);
-       return result;
+       // we have sprintf...
+       return sprintf("%.*f", decimals, number);
 }
 
 float time;
@@ -1948,3 +1913,25 @@ float get_model_parameters(string m, float sk)
 
        return 1;
 }
+
+vector vec2(vector v)
+{
+       v_z = 0;
+       return v;
+}
+
+#ifndef MENUQC
+vector NearestPointOnBox(entity box, vector org)
+{
+       vector m1, m2, nearest;
+
+       m1 = box.mins + box.origin;
+       m2 = box.maxs + box.origin;
+
+       nearest_x = bound(m1_x, org_x, m2_x);
+       nearest_y = bound(m1_y, org_y, m2_y);
+       nearest_z = bound(m1_z, org_z, m2_z);
+
+       return nearest;
+}
+#endif