#ifndef CORE_H_SENTRY #define CORE_H_SENTRY /* ---- Types ---------------------------------------------------------- */ #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif typedef unsigned char U8; typedef unsigned short U16; typedef unsigned int U32; typedef unsigned long long U64; typedef signed char S8; typedef short S16; typedef int S32; typedef long long S64; typedef S8 B8; typedef S16 B16; typedef S32 B32; typedef S64 B64; typedef float F32; typedef double F64; /* ---- Units ---------------------------------------------------------- */ #define KB(n) (((U64)(n)) << 10) #define MB(n) (((U64)(n)) << 20) #define GB(n) (((U64)(n)) << 30) #define TB(n) (((U64)(n)) << 40) /* ---- Clamps, Min/Max ------------------------------------------------ */ #define MIN(A,B) (((A) < (B)) ? (A) : (B)) #define MAX(A,B) (((A) > (B)) ? (A) : (B)) #define CLAMP_TOP(A, X) Min(A, X) #define CLAMP_BOT(X, B) Max(X, B) #define CLAMP(A, X, B) (((X) < (A)) ? (A) : ((X) > (B)) ? (B) : (X)) /* ---- Asserts -------------------------------------------------------- */ #define Trap() __builtin_trap() #define AssertAlways(x) do { if(!(x)) { Trap(); } } while(0) #if BUILD_DEBUG #define Assert(x) AssertAlways(x) #else #define Assert(x) (void)(x) #endif /* ---- Helper Macros -------------------------------------------------- */ #define STRINGIFY_(S) #S #define STRINGIFY(S) STRINGIFY_(S) #define GLUE_(A, B) A##B #define GLUE(A, B) GLUE_(A,B) #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) #define SWAP(T, a, b) do { T t__ = a; a = b; b = t__; } while(0) /* ---- Constants ------------------------------------------------------ */ #define PI 3.14159265358979323846 #define MAX_U64 (U64)0xffffffffffffffff #define MAX_U32 (U32)0xffffffff #define MAX_U16 (U16)0xffff #define MAX_U8 (U8)0xff #define MAX_S64 (S64)0x7fffffffffffffff #define MAX_S32 (S32)0x7fffffff #define MAX_S16 (S16)0x7fff #define MAX_S8 (S8)0x7f #define MIN_S64 (S64)0x8000000000000000 #define MIN_S32 (S32)0x80000000 #define MIN_S16 (S16)0x8000 #define MIN_S8 (S8)0x80 #endif