#ifndef CORE_H #define CORE_H /* ---- Switches ------------------------------------------------------- */ #ifndef BUILD_DEBUG #define BUILD_DEBUG 1 #endif #ifndef BUILD_INTERNAL #define BUILD_INTERNAL 1 #endif /* ---- Environment Detection ------------------------------------------ */ /* Architecture */ #ifndef ARCHITECTURE_X64 #define ARCHITECTURE_X64 1 #endif #ifndef ARCHITECTURE_X86 #define ARCHITECTURE_X86 0 #endif #ifndef ARCHITECTURE_ARM64 #define ARCHITECTURE_ARM64 0 #endif #ifndef ARCHITECTURE_ARM32 #define ARCHITECTURE_ARM32 0 #endif /* OS */ #ifndef OS_LINUX #define OS_LINUX 1 #endif #ifndef OS_WINDOWS #define OS_WINDOWS 0 #endif #ifndef OS_MACOS #define OS_MACOS 0 #endif /* Compiler */ #ifndef COMPILER_CLANG #define COMPILER_CLANG 1 #endif #ifndef COMPILER_MSVC #define COMPILER_MSVC 0 #endif #ifndef COMPILER_GCC #define COMPILER_GCC 0 #endif /* ---- Units ---------------------------------------------------------- */ #define KB(n) (((unsigned long long)(n)) << 10) #define MB(n) (((unsigned long long)(n)) << 20) #define GB(n) (((unsigned long long)(n)) << 30) #define TB(n) (((unsigned long long)(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 -------------------------------------------------------- */ #if COMPILER_CLANG || COMPILER_GCC #define TRAP() __builtin_trap() #elif COMPILER_MSVC #define TRAP() __debugbreak() #else #error Unknow debug break for the compiler . . . #endif #define ASSERT_ALWAYS(x) do { if(!(x)) { TRAP(); } } while(0) #if BUILD_DEBUG #define ASSERT(x) ASSERT_ALWAYS(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 MIN_U64 (U64)0x0 #define MIN_U32 (U32)0x0 #define MIN_U16 (U16)0x0 #define MIN_U8 (U8)0x0 #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