aboutsummaryrefslogtreecommitdiff
path: root/src/config.h
blob: 40a095c2f2eeff135d6363d70a2d53d87c3249b6 (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
#pragma once

typedef char i8;
typedef unsigned char u8;

typedef short i16;
typedef unsigned short u16;

typedef int i32;
typedef long long i64;

typedef unsigned int u32;
typedef unsigned long long u64;

typedef float f32;
typedef double f64;

/*
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)

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