diff options
| author | Uneven Prankster <unevenprankster@protonmail.com> | 2023-10-15 21:28:29 -0300 |
|---|---|---|
| committer | Uneven Prankster <unevenprankster@protonmail.com> | 2023-10-15 21:28:29 -0300 |
| commit | 1c0cc775732201f4c4d3ee0d6772be786b3b4aa1 (patch) | |
| tree | f5d692d046868261275c7430a624c3ea9ed75d3d /src/gunner/config.h | |
| parent | a89f892640cf12f75c7ce18e6e88c70a8d3965ed (diff) | |
A lot has certainly happened!
Diffstat (limited to 'src/gunner/config.h')
| -rw-r--r-- | src/gunner/config.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/gunner/config.h b/src/gunner/config.h new file mode 100644 index 0000000..dc098e5 --- /dev/null +++ b/src/gunner/config.h @@ -0,0 +1,70 @@ +#pragma once + +#include <stddef.h> +#include <stdint.h> + +typedef int8_t i8; +typedef uint8_t u8; + +typedef int16_t i16; +typedef uint16_t u16; + +typedef int32_t i32; +typedef int64_t i64; + +typedef uint32_t u32; +typedef uint64_t u64; + +typedef float f32; +typedef double f64; + +typedef unsigned char byte; +typedef ptrdiff_t size; + +/* +You may be wondering "why fixed point values???", and that's simple +Floating Point was a mistake and has caused great suffering to countless. +Time-keeping is specially burdened. Nobody should ever keep track of time +with float values. Variable precision can and WILL throw off calculations +no matter how much of a NERD you are. + +What I did was to just leverage the support for floats in order to make most +things simply take them (that's what everyone expects) then convert them to +fixed point for precise operations. + +They can still be happily used for other things, specially inside shaders. +But don't @ me. +*/ + +// 24.8 format +typedef i32 fx32; +#define FIXED_POINT_BITS 8 +#define FIXED_POINT_ONE (1 << FIXED_POINT_BITS) +#define TO_FIXED(x) ((fx32)(x) << FIXED_POINT_BITS) +#define FROM_FIXED(x) ((x) >> FIXED_POINT_BITS) +#define FP_TO_FIXED(x) (fx32)((x) * FIXED_POINT_ONE) +#define FP_FROM_FIXED(x) (f32)((x) * (f32)(1 / FIXED_POINT_ONE)) + +typedef struct{ + fx32 x, y; +}vec2; + +typedef i8 b32; +#define false 0 +#define true 1 + +#ifdef DEBUG +# if __GNUC__ +# define assert(c) if (!(c)) __builtin_trap() +# elif _MSC_VER +# define assert(c) if (!(c)) __debugbreak() +# else +# define assert(c) if (!(c)) *(volatile int *)0 = 0 +# endif +#else +# define assert(c) +#endif + +#define sizeof(x) (size)sizeof(x) +#define countof(a) (sizeof(a) / sizeof(*(a))) +#define lengthof(s) (countof(s) - 1) |
