aboutsummaryrefslogtreecommitdiff
path: root/src/gunner/config.h
blob: dc098e56a49a5d7d3fc6c7da7d59be435cee4214 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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)