--- deliantra/server/include/util.h 2009/10/15 21:09:32 1.91 +++ deliantra/server/include/util.h 2009/11/08 16:13:45 1.94 @@ -23,32 +23,12 @@ #ifndef UTIL_H__ #define UTIL_H__ +#include + #define DEBUG_POISON 0x00 // poison memory before freeing it if != 0 #define DEBUG_SALLOC 0 // add a debug wrapper around all sallocs #define PREFER_MALLOC 0 // use malloc and not the slice allocator -#if __GNUC__ >= 3 -# define is_constant(c) __builtin_constant_p (c) -# define expect(expr,value) __builtin_expect ((expr),(value)) -# define prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality) -# define noinline __attribute__((__noinline__)) -#else -# define is_constant(c) 0 -# define expect(expr,value) (expr) -# define prefetch(addr,rw,locality) -# define noinline -#endif - -#if __GNUC__ < 4 || (__GNUC__ == 4 || __GNUC_MINOR__ < 4) -# define decltype(x) typeof(x) -#endif - -// put into ifs if you are very sure that the expression -// is mostly true or mosty false. note that these return -// booleans, not the expression. -#define expect_false(expr) expect ((expr) ? 1 : 0, 0) -#define expect_true(expr) expect ((expr) ? 1 : 0, 1) - #include #include @@ -208,7 +188,7 @@ return b - d; } -// this is much faster than crossfires original algorithm +// this is much faster than crossfire's original algorithm // on modern cpus inline int isqrt (int n) @@ -216,6 +196,20 @@ return (int)sqrtf ((float)n); } +// this is kind of like the ^^ operator, if it would exist, without sequence point. +// more handy than it looks like, due to the implicit !! done on its arguments +inline bool +logical_xor (bool a, bool b) +{ + return a != b; +} + +inline bool +logical_implies (bool a, bool b) +{ + return a <= b; +} + // this is only twice as fast as naive sqrtf (dx*dy+dy*dy) #if 0 // and has a max. error of 6 in the range -100..+100. @@ -710,7 +704,7 @@ // like v?sprintf, but returns a "static" buffer char *vformat (const char *format, va_list ap); -char *format (const char *format, ...); +char *format (const char *format, ...) attribute ((format (printf, 1, 2))); // safety-check player input which will become object->msg bool msg_is_safe (const char *msg);