#ifndef BASE_CORE_H #define BASE_CORE_H /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //~ #include #include // TODO(anton): Move to context cracking #if defined(_MSC_VER) #define COMPILER_MSVC 1 #endif //////////////////////////////// //~ Asserts #if COMPILER_MSVC # define Trap() __debugbreak() #elif COMPILER_CLANG || COMPILER_GCC # define Trap() __builtin_trap() #else # error Unknown trap intrinsic for this compiler. #endif #if COMPILER_MSVC # define AlignOf(T) __alignof(T) #else # error Need MSVC for now! #endif #define AssertAlways(x) do{if(!(x)) {Trap();}}while(0) #if BUILD_DEBUG # define Assert(x) AssertAlways(x) #else # define Assert(x) (void)(x) #endif #define InvalidPath Assert(!"Invalid Path!") #define NotImplemented Assert(!"Not Implemented!") #define NoOp ((void)0) #define StaticAssert(C, ID) global U8 Glue(ID, __LINE__)[(C)?1:-1] /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //~ typedef uint8_t U8; typedef uint16_t U16; typedef uint32_t U32; typedef uint64_t U64; typedef int8_t S8; typedef int16_t S16; typedef int32_t S32; typedef int64_t S64; typedef S8 B8; typedef S16 B16; typedef S32 B32; typedef S64 B64; typedef float F32; typedef double F64; typedef void VoidProc(void); typedef union U128 U128; union U128 { U8 u8[16]; U16 u16[8]; U32 u32[4]; U64 u64[2]; }; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //~ #define global static #define internal static #define local_persist static /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //~ #define Min(A,B) (((A)<(B))?(A):(B)) #define Max(A,B) (((A)>(B))?(A):(B)) #define ClampTop(A,X) Min(A,X) #define ClampBot(X,B) Max(X,B) #define Clamp(A,X,B) (((X)<(A))?(A):((X)>(B))?(B):(X)) #define MemoryCopy(dst, src, size) memmove((dst), (src), (size)) #define MemorySet(dst, byte, size) memset((dst), (byte), (size)) #define MemoryCopyStruct(d,s) MemoryCopy((d),(s),sizeof(*(d))) #define MemoryCopyArray(d,s) MemoryCopy((d),(s),sizeof(d)) #define MemoryZero(s,z) memset((s),0,(z)) #define MemoryZeroStruct(s) MemoryZero((s),sizeof(*(s))) #define MemoryZeroArray(a) MemoryZero((a),sizeof(a)) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //~ #define KB(n) (((U64)(n)) << 10) #define MB(n) (((U64)(n)) << 20) #define GB(n) (((U64)(n)) << 30) #define TB(n) (((U64)(n)) << 40) #define Thousand(n) ((n)*1000) #define Million(n) ((n)*1000000) #define Billion(n) ((n)*1000000000) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //~ Helper macros #define ArrayCount(a) (sizeof(a) / sizeof((a)[0])) #define AlignPow2(x,b) (((x) + (b) - 1)&(~((b) - 1))) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //~ #define LOG OS_W32_log_debug #endif /* BASE_CORE_H */