From 1c0cc775732201f4c4d3ee0d6772be786b3b4aa1 Mon Sep 17 00:00:00 2001 From: Uneven Prankster Date: Sun, 15 Oct 2023 21:28:29 -0300 Subject: A lot has certainly happened! --- src/gunner/config.h | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/gunner/config.h (limited to 'src/gunner/config.h') 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 +#include + +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) -- cgit v1.2.3