]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/util.qc
Declare more ints as ints
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / util.qc
index 671c8d5a593e23f9c552a700172cc57b9cf7139c..e5eadc4525bf77e1f7d201abbfdb303dcfd749ef 100644 (file)
@@ -259,7 +259,7 @@ float fexists(string f)
 }
 
 // Databases (hash tables)
-#define DB_BUCKETS 8192
+const float DB_BUCKETS = 8192;
 void db_save(float db, string pFilename)
 {
        float fh, i, n;
@@ -346,14 +346,14 @@ void db_close(float db)
 string db_get(float db, string pKey)
 {
        float h;
-       h = mod(crc16(FALSE, pKey), DB_BUCKETS);
+       h = crc16(FALSE, pKey) % DB_BUCKETS;
        return uri_unescape(infoget(bufstr_get(db, h), pKey));
 }
 
 void db_put(float db, string pKey, string pValue)
 {
        float h;
-       h = mod(crc16(FALSE, pKey), DB_BUCKETS);
+       h = crc16(FALSE, pKey) % DB_BUCKETS;
        bufstr_set(db, h, infoadd(bufstr_get(db, h), pKey, uri_escape(pValue)));
 }
 
@@ -446,7 +446,7 @@ string mmssss(float hundredths)
        return strcat(ftos(minutes), ":", substring(s, 1, 2), ".", substring(s, 3, 2));
 }
 
-string ScoreString(float pFlags, float pValue)
+string ScoreString(int pFlags, float pValue)
 {
        string valstr;
        float l;
@@ -505,7 +505,7 @@ float lengthLogTable[128];
 
 float invertLengthLog(float x)
 {
-       float l, r, m, lerr, rerr;
+       int l, r, m;
 
        if(x >= lengthLogTable[127])
                return 127;
@@ -525,22 +525,21 @@ float invertLengthLog(float x)
        }
 
        // now: r is >=, l is <
-       lerr = (x - lengthLogTable[l]);
-       rerr = (lengthLogTable[r] - x);
+       float lerr = (x - lengthLogTable[l]);
+       float rerr = (lengthLogTable[r] - x);
        if(lerr < rerr)
                return l;
        return r;
 }
 
-vector decompressShortVector(float data)
+vector decompressShortVector(int data)
 {
        vector out;
-       float p, y, len;
        if(data == 0)
                return '0 0 0';
-       p   = (data & 0xF000) / 0x1000;
-       y   = (data & 0x0F80) / 0x80;
-       len = (data & 0x007F);
+       float p = (data & 0xF000) / 0x1000;
+       float y = (data & 0x0F80) / 0x80;
+       int len = (data & 0x007F);
 
        //print("\ndecompress: p ", ftos(p)); print("y ", ftos(y)); print("len ", ftos(len), "\n");
 
@@ -601,9 +600,9 @@ float compressShortVector(vector vec)
 
 void compressShortVector_init()
 {
-       float l, f, i;
-       l = 1;
-       f = pow(2, 1/8);
+       float l = 1;
+       float f = pow(2, 1/8);
+       int i;
        for(i = 0; i < 128; ++i)
        {
                lengthLogTable[i] = l;
@@ -1313,17 +1312,17 @@ float textLengthUpToLength(string theText, float maxWidth, textLengthUpToLength_
 
 string find_last_color_code(string s)
 {
-       float start, len, i, carets;
-       start = strstrofs(s, "^", 0);
+       int start = strstrofs(s, "^", 0);
        if (start == -1) // no caret found
                return "";
-       len = strlen(s)-1;
+       int len = strlen(s)-1;
+       int i;
        for(i = len; i >= start; --i)
        {
                if(substring(s, i, 1) != "^")
                        continue;
 
-               carets = 1;
+               int carets = 1;
                while (i-carets >= start && substring(s, i-carets, 1) == "^")
                        ++carets;
 
@@ -1742,7 +1741,7 @@ float compressShotOrigin(vector v)
        }
        return x * 0x10000 + y * 0x100 + z;
 }
-vector decompressShotOrigin(float f)
+vector decompressShotOrigin(int f)
 {
        vector v;
        v_x = ((f & 0xFF0000) / 0x10000) / 2;
@@ -2258,13 +2257,13 @@ string CTX(string s)
 // x-encoding (encoding as zero length invisible string)
 const string XENCODE_2  = "xX";
 const string XENCODE_22 = "0123456789abcdefABCDEF";
-string xencode(float f)
+string xencode(int f)
 {
        float a, b, c, d;
-       d = mod(f, 22); f = floor(f / 22);
-       c = mod(f, 22); f = floor(f / 22);
-       b = mod(f, 22); f = floor(f / 22);
-       a = mod(f,  2); // f = floor(f /  2);
+       d = f % 22; f = floor(f / 22);
+       c = f % 22; f = floor(f / 22);
+       b = f % 22; f = floor(f / 22);
+       a = f %  2; // f = floor(f /  2);
        return strcat(
                "^",
                substring(XENCODE_2,  a, 1),
@@ -2289,7 +2288,7 @@ float xdecode(string s)
        return ((a * 22 + b) * 22 + c) * 22 + d;
 }
 
-float lowestbit(float f)
+float lowestbit(int f)
 {
        f &= ~(f * 2);
        f &= ~(f * 4);
@@ -2373,7 +2372,7 @@ void m_shutdown()
        cvar_settemp_restore(); // this must be done LAST, but in any case
 }
 
-#define APPROXPASTTIME_ACCURACY_REQUIREMENT 0.05
+const float APPROXPASTTIME_ACCURACY_REQUIREMENT = 0.05;
 #define APPROXPASTTIME_MAX (16384 * APPROXPASTTIME_ACCURACY_REQUIREMENT)
 #define APPROXPASTTIME_RANGE (64 * APPROXPASTTIME_ACCURACY_REQUIREMENT)
 // this will use the value:
@@ -2801,7 +2800,7 @@ float Mod_Q1BSP_SuperContentsFromNativeContents(float nativecontents)
        return 0;
 }
 
-float Mod_Q1BSP_NativeContentsFromSuperContents(float supercontents)
+float Mod_Q1BSP_NativeContentsFromSuperContents(int supercontents)
 {
        if(supercontents & (DPCONTENTS_SOLID | DPCONTENTS_BODY))
                return CONTENT_SOLID;