base_types.h (3480B)
1 #ifndef BASE_TYPES_H 2 #define BASE_TYPES_H 3 #include "base_compiler.h" 4 5 #if COMPILER_MSVC 6 typedef unsigned __int64 u64; 7 typedef signed __int64 i64; 8 typedef unsigned __int32 u32; 9 typedef signed __int32 i32; 10 typedef unsigned __int16 u16; 11 typedef signed __int16 i16; 12 typedef unsigned __int8 u8; 13 typedef signed __int8 i8; 14 #else 15 typedef __UINT64_TYPE__ u64; 16 typedef __INT64_TYPE__ i64; 17 typedef __UINT32_TYPE__ u32; 18 typedef __INT32_TYPE__ i32; 19 typedef __UINT16_TYPE__ u16; 20 typedef __INT16_TYPE__ i16; 21 typedef __UINT8_TYPE__ u8; 22 typedef __INT8_TYPE__ i8; 23 #endif 24 25 #define I8_MAX (0x0000007FL) 26 #define I32_MAX (0x7FFFFFFFL) 27 #define S32_MAX (0x7FFFFFFFL) 28 #define U8_MAX (0x000000FFUL) 29 #define U16_MAX (0x0000FFFFUL) 30 #define U32_MAX (0xFFFFFFFFUL) 31 #define U64_MAX (0xFFFFFFFFFFFFFFFFULL) 32 #define F32_EPSILON (1e-6f) 33 #ifndef PI 34 #define PI (3.14159265358979323846f) 35 #endif 36 37 typedef char c8; 38 typedef u8 b8; 39 typedef u16 b16; 40 typedef u32 b32; 41 typedef _Float16 f16; 42 typedef float f32; 43 typedef double f64; 44 typedef i64 iptr; 45 typedef u64 uptr; 46 47 typedef struct { u64 start, stop; } RangeU64; 48 49 typedef union { 50 struct { i32 x, y; }; 51 struct { i32 w, h; }; 52 i32 E[2]; 53 } iv2; 54 55 typedef union { 56 struct { i32 x, y, z; }; 57 struct { i32 w, h, d; }; 58 iv2 xy; 59 i32 E[3]; 60 } iv3; 61 62 typedef union { 63 struct { i32 x, y, z, w; }; 64 struct { iv3 xyz; i32 _w; }; 65 i32 E[4]; 66 } iv4; 67 68 typedef union { 69 struct { u32 x, y; }; 70 struct { u32 w, h; }; 71 u32 E[2]; 72 } uv2; 73 74 typedef union { 75 struct { u32 x, y, z; }; 76 struct { u32 w, h, d; }; 77 uv2 xy; 78 u32 E[3]; 79 } uv3; 80 81 typedef union { 82 struct { u32 x, y, z, w; }; 83 struct { uv3 xyz; u32 _w; }; 84 u32 E[4]; 85 } uv4; 86 87 typedef union { 88 struct { b32 x, y, z; }; 89 b32 E[3]; 90 } bv3; 91 92 typedef union { 93 struct { f32 x, y; }; 94 struct { f32 w, h; }; 95 f32 E[2]; 96 } v2; 97 #define V2_INFINITY (v2){{-inf32(), inf32()}} 98 99 typedef union { 100 struct { f32 x, y, z; }; 101 struct { f32 w, h, d; }; 102 struct { v2 xy; f32 _1; }; 103 struct { f32 _2; v2 yz; }; 104 f32 E[3]; 105 } v3; 106 107 typedef union { 108 struct { f32 x, y, z, w; }; 109 struct { f32 r, g, b, a; }; 110 struct { v3 xyz; f32 _1; }; 111 struct { f32 _2; v3 yzw; }; 112 struct { v2 xy, zw; }; 113 f32 E[4]; 114 } v4; 115 116 typedef union { 117 struct { v4 x, y, z, w; }; 118 v4 c[4]; 119 f32 E[16]; 120 } m4; 121 122 typedef enum { 123 ArenaFlag_NoChain = 1 << 0, 124 125 ArenaFlag_CreationMask = ArenaFlag_NoChain, 126 127 ArenaFlag_Sealed = 1 << 31, 128 } ArenaFlags; 129 130 typedef struct { 131 u64 reserve_size; 132 u64 commit_size; 133 ArenaFlags flags; 134 135 void *optional_backing_store; 136 137 char *name; 138 char *allocation_site_file; 139 i32 allocation_site_line; 140 } ArenaParameters; 141 142 typedef struct Arena Arena; 143 struct Arena { 144 u64 position; 145 u64 committed; 146 u64 reserved; 147 148 // NOTE(rnp): arena chain 149 u64 base_position; // position relative to first arena in chain 150 Arena *prev; 151 Arena *current; 152 153 u64 reserve_size; 154 u64 commit_size; 155 ArenaFlags flags; 156 157 char *name; 158 char *allocation_site_file; 159 i32 allocation_site_line; 160 }; 161 typedef struct { Arena *arena; u64 position; } Temp; 162 163 typedef struct { i64 length; u8 *data; } str8; 164 #define str8(s) (str8){.length = countof(s) - 1, .data = (u8 *)s} 165 #define str8_comp(s) {sizeof(s) - 1, (u8 *)s} 166 #define str8_struct(v) (str8){.length = sizeof(*v), .data = (u8 *)v} 167 168 typedef struct { i64 length; u16 *data; } str16; 169 170 #endif /* BASE_TYPES_H */