From 5fd000a882130eb461bd29c7ad63e5b55780d23d Mon Sep 17 00:00:00 2001 From: TimePath Date: Fri, 30 Oct 2015 08:42:25 +1100 Subject: [PATCH] lib: inline a few functions --- qcsrc/common/util.qh | 4 ---- qcsrc/lib/accumulate.qh | 9 ++++++--- qcsrc/lib/bool.qh | 6 +++--- qcsrc/lib/math.qh | 13 ++----------- qcsrc/lib/string.qh | 12 ++++-------- qcsrc/server/g_subs.qh | 9 --------- 6 files changed, 15 insertions(+), 38 deletions(-) diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index 8bedccf0a..5c48e42a8 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -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; diff --git a/qcsrc/lib/accumulate.qh b/qcsrc/lib/accumulate.qh index a2f6714ec..e3d17b9f2 100644 --- a/qcsrc/lib/accumulate.qh +++ b/qcsrc/lib/accumulate.qh @@ -50,8 +50,11 @@ #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 diff --git a/qcsrc/lib/bool.qh b/qcsrc/lib/bool.qh index 34e8bfc66..5510c171c 100644 --- a/qcsrc/lib/bool.qh +++ b/qcsrc/lib/bool.qh @@ -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 diff --git a/qcsrc/lib/math.qh b/qcsrc/lib/math.qh index 7459a060f..24d004166 100644 --- a/qcsrc/lib/math.qh +++ b/qcsrc/lib/math.qh @@ -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)) /* diff --git a/qcsrc/lib/string.qh b/qcsrc/lib/string.qh index ca82ecce4..2bf9ac1f7 100644 --- a/qcsrc/lib/string.qh +++ b/qcsrc/lib/string.qh @@ -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) { diff --git a/qcsrc/server/g_subs.qh b/qcsrc/server/g_subs.qh index c9d1264c0..149324f6d 100644 --- a/qcsrc/server/g_subs.qh +++ b/qcsrc/server/g_subs.qh @@ -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 -- 2.39.2