X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=qdefs.h;h=5d0655f77f6e0b519bab330b08678166e20e639f;hp=ce1d38209ec21d28190f294d6353c9cd6094db7a;hb=19f27381a167c3713ff0417fd96651bb0469d2a6;hpb=e9ef9da90a206204b283dacd15c35bd3fd1fe5c9 diff --git a/qdefs.h b/qdefs.h index ce1d3820..5d0655f7 100644 --- a/qdefs.h +++ b/qdefs.h @@ -1,6 +1,10 @@ #ifndef QDEFS_H #define QDEFS_H +#if defined (__GNUC__) || defined (__clang__) || defined (__TINYC__) +#define DP_GCC_COMPATIBLE +#endif + #if (__GNUC__ > 2) || defined (__clang__) || (__TINYC__) #define DP_FUNC_PRINTF(n) __attribute__ ((format (printf, n, n+1))) #define DP_FUNC_PURE __attribute__ ((pure)) @@ -11,6 +15,12 @@ #define DP_FUNC_NORETURN #endif +#ifdef DP_GCC_COMPATIBLE +#define Q_typeof(var) typeof(var) +#elif defined (MSVC) +#define Q_typeof(var) decltype(var) +#endif + #define MAX_NUM_ARGVS 50 #ifdef DP_SMALLMEMORY @@ -90,7 +100,7 @@ #define CMDBUFSIZE 655360 ///< maximum script size that can be loaded by the exec command (8192 in Quake) #define MAX_ARGS 80 ///< maximum number of parameters to a console command or alias -#define NET_MAXMESSAGE 131072 ///< max reliable packet size (sent as multiple fragments of MAX_PACKETFRAGMENT) +#define NET_MAXMESSAGE 65536 ///< max reliable packet size (sent as multiple fragments of MAX_PACKETFRAGMENT) #define MAX_PACKETFRAGMENT 1024 ///< max length of packet fragment #define MAX_EDICTS 32768 ///< max number of objects in game world at once (32768 protocol limit) #define MAX_MODELS 8192 ///< max number of models loaded at once (including during level transitions) @@ -169,4 +179,51 @@ #define NET_MINRATE 1000 ///< limits "rate" and "sv_maxrate" cvars +// In Quake, any char in 0..32 counts as whitespace +//#define ISWHITESPACE(ch) ((unsigned char) ch <= (unsigned char) ' ') +#define ISWHITESPACE(ch) (!(ch) || (ch) == ' ' || (ch) == '\t' || (ch) == '\r' || (ch) == '\n') +#define ISCOMMENT(ch, pos) ch[pos] == '/' && ch[pos + 1] == '/' && (pos == 0 || ISWHITESPACE(ch[pos - 1])) +// This also includes extended characters, and ALL control chars +#define ISWHITESPACEORCONTROL(ch) ((signed char) (ch) <= (signed char) ' ') + +#ifdef PRVM_64 +#define FLOAT_IS_TRUE_FOR_INT(x) ((x) & 0x7FFFFFFFFFFFFFFF) // also match "negative zero" doubles of value 0x8000000000000000 +#define FLOAT_LOSSLESS_FORMAT "%.17g" +#define VECTOR_LOSSLESS_FORMAT "%.17g %.17g %.17g" +#else +#define FLOAT_IS_TRUE_FOR_INT(x) ((x) & 0x7FFFFFFF) // also match "negative zero" floats of value 0x80000000 +#define FLOAT_LOSSLESS_FORMAT "%.9g" +#define VECTOR_LOSSLESS_FORMAT "%.9g %.9g %.9g" +#endif + +// originally this was _MSC_VER +// but here we want to test the system libc, which on win32 is borked, and NOT the compiler +#ifdef WIN32 +#define INT_LOSSLESS_FORMAT_SIZE "I64" +#define INT_LOSSLESS_FORMAT_CONVERT_S(x) ((__int64)(x)) +#define INT_LOSSLESS_FORMAT_CONVERT_U(x) ((unsigned __int64)(x)) +#else +#define INT_LOSSLESS_FORMAT_SIZE "j" +#define INT_LOSSLESS_FORMAT_CONVERT_S(x) ((intmax_t)(x)) +#define INT_LOSSLESS_FORMAT_CONVERT_U(x) ((uintmax_t)(x)) +#endif + +// simple safe library to handle integer overflows when doing buffer size calculations +// Usage: +// - calculate data size using INTOVERFLOW_??? macros +// - compare: calculated-size <= INTOVERFLOW_NORMALIZE(buffersize) +// Functionality: +// - all overflows (values > INTOVERFLOW_MAX) and errors are mapped to INTOVERFLOW_MAX +// - if any input of an operation is INTOVERFLOW_MAX, INTOVERFLOW_MAX will be returned +// - otherwise, regular arithmetics apply + +#define INTOVERFLOW_MAX 2147483647 + +#define INTOVERFLOW_ADD(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (a) < INTOVERFLOW_MAX - (b)) ? ((a) + (b)) : INTOVERFLOW_MAX) +#define INTOVERFLOW_SUB(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (b) <= (a)) ? ((a) - (b)) : INTOVERFLOW_MAX) +#define INTOVERFLOW_MUL(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (a) < INTOVERFLOW_MAX / (b)) ? ((a) * (b)) : INTOVERFLOW_MAX) +#define INTOVERFLOW_DIV(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (b) > 0) ? ((a) / (b)) : INTOVERFLOW_MAX) + +#define INTOVERFLOW_NORMALIZE(a) (((a) < INTOVERFLOW_MAX) ? (a) : (INTOVERFLOW_MAX - 1)) + #endif