]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
lib: inline a few functions
authorTimePath <andrew.hardaker1995@gmail.com>
Thu, 29 Oct 2015 21:42:25 +0000 (08:42 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Thu, 29 Oct 2015 21:42:25 +0000 (08:42 +1100)
qcsrc/common/util.qh
qcsrc/lib/accumulate.qh
qcsrc/lib/bool.qh
qcsrc/lib/math.qh
qcsrc/lib/string.qh
qcsrc/server/g_subs.qh

index 8bedccf0ae44b38d9935e48686c154de7a362479..5c48e42a8a62d1235bd6e4385fce4f19d1bb9e1f 100644 (file)
@@ -174,11 +174,7 @@ float float2range01(float f);
 
 float gsl_ran_gaussian(float sigma);
 
-string car(string s); // returns first word
-string cdr(string s); // returns all but first word
 float matchacl(string acl, string str); // matches str against ACL acl (with entries +foo*, +foo, +*foo, +*foo*, and same with - for forbidding)
-float startsWith(string haystack, string needle);
-float startsWithNocase(string haystack, string needle);
 
 string get_model_datafilename(string mod, float skn, string fil); // skin -1 will return wildcard, mod string_null will also put wildcard there
 string get_model_parameters_modelname;
index a2f6714ec7b42d43c00824f2614f46359c2bcd68..e3d17b9f26848ae9f473b1c844878729274fd784 100644 (file)
 #endif
 
 // used for simplifying ACCUMULATE_FUNCTIONs
-#define SET_FIRST_OR_LAST(input, first, count) if (!input) { input = (first + count); }
-#define SET_FIELD_COUNT(field, first, count) if (!field) { field = (first + count); ++count; }
-#define CHECK_MAX_COUNT(name, max, count, type) if (count > max) { error(strcat("Maximum ", type, " hit: ", #name, ": ", ftos(count), ".\n")); }
+#define SET_FIRST_OR_LAST(input, first, count) \
+       if (!input) { input = (first + count); }
+#define SET_FIELD_COUNT(field, first, count) \
+       if (!field) { field = (first + count); ++count; }
+#define CHECK_MAX_COUNT(name, max, count, type) \
+       if (count > max) { error(strcat("Maximum ", type, " hit: ", #name, ": ", ftos(count), ".\n")); }
 
 #endif
index 34e8bfc66999b66968cc4b08e8de1b283167dbea..5510c171cfcc357487f4cd92182e8b987f88d7ea 100644 (file)
@@ -11,6 +11,8 @@
 [[deprecated("use true")]][[alias("true")]] const bool TRUE;
 [[deprecated("use false")]][[alias("false")]] const bool FALSE;
 
+#define boolean(value) ((value) != 0)
+
 // get true/false value of a string with multiple different inputs
 float InterpretBoolean(string input)
 {
@@ -26,10 +28,8 @@ float InterpretBoolean(string input)
                case "off":
                        return false;
 
-               default: return stof(input);
+               default: return boolean(stof(input));
        }
 }
 
-#define boolean(value) ((value) != 0)
-
 #endif
index 7459a060f298413f5be3669a9cd386a6c8876f6e..24d004166cfd4bec600b102eb50a9198757e5e58 100644 (file)
@@ -20,17 +20,8 @@ float mean_evaluate(entity e, .float a, .float c, float mean)
 #define MEAN_EVALUATE(prefix) mean_evaluate(self, prefix##_accumulator, prefix##_count, prefix##_mean)
 #define MEAN_DECLARE(prefix, m) float prefix##_mean = m; .float prefix##_count, prefix##_accumulator
 
-/*
-==================
-crandom
-
-Returns a random number between -1.0 and 1.0
-==================
-*/
-float crandom()
-{
-       return 2 * (random() - 0.5);
-}
+/** Returns a random number between -1.0 and 1.0 */
+#define crandom() (2 * (random() - 0.5))
 
 
 /*
index ca82ecce43f21b69b94c2241338a23df02067159..2bf9ac1f7b5c8a5f6ddac99a14ce2a15134937e7 100644 (file)
@@ -65,10 +65,7 @@ string CCR(string input)
        return input;
 }
 
-bool startsWith(string haystack, string needle)
-{
-       return substring(haystack, 0, strlen(needle)) == needle;
-}
+#define startsWith(haystack, needle) (strstrofs(haystack, needle, 0) == 0)
 
 bool startsWithNocase(string haystack, string needle)
 {
@@ -84,6 +81,7 @@ string fstrunzone(string s)
        return sc;
 }
 
+/** returns first word */
 string car(string s)
 {
        int o = strstrofs(s, " ", 0);
@@ -91,6 +89,7 @@ string car(string s)
        return substring(s, 0, o);
 }
 
+/** returns all but first word */
 string cdr(string s)
 {
        int o = strstrofs(s, " ", 0);
@@ -171,10 +170,7 @@ string strwords(string s, int w)
        return substring(s, 0, endpos);
 }
 
-bool strhasword(string s, string w)
-{
-       return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
-}
+#define strhasword(s, w) (strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0)
 
 int u8_strsize(string s)
 {
index c9d1264c07721897a7b84b9665b8cb6d98749fcf..149324f6dd6ab2163ed03550f3863dc8027553f8 100644 (file)
@@ -135,15 +135,6 @@ Ripped from DPMod
 */
 vector findbetterlocation (vector org, float mindist);
 
-/*
-==================
-crandom
-
-Returns a random number between -1.0 and 1.0
-==================
-*/
-float crandom (void);
-
 /*
 ==================
 Angc used for animations