]> git.lizzy.rs Git - dragonblocks_alpha.git/blob - src/types.h
Add mountain generation
[dragonblocks_alpha.git] / src / types.h
1 #ifndef _TYPES_H_
2 #define _TYPES_H_
3
4 #include <stdint.h>
5 #include <stdbool.h>
6 #include <stddef.h>
7
8 bool read_full(int fd, char *buffer, size_t size);
9
10 #define DEFRW(type) \
11         bool read_ ## type(int fd, type *ptr); \
12         bool write_ ## type(int fd, type val);
13
14 #define DEFBOX(type) \
15         typedef struct {v ## type min; v ## type max;} aabb ## type;
16
17 #define DEFVEC(type) \
18         typedef struct {type x, y;} v2 ## type; \
19         DEFRW(v2 ## type) \
20         DEFBOX(2 ## type) \
21         typedef struct {type x, y, z;} v3 ## type; \
22         DEFRW(v3 ## type) \
23         DEFBOX(3 ## type)
24
25 #define DEFTYP(from, to) \
26         typedef from to; \
27         DEFRW(to) \
28         DEFVEC(to)
29
30 #define DEFTYPES(bits) \
31         DEFTYP(int ## bits ## _t, s ## bits) \
32         DEFTYP(uint ## bits ## _t, u ## bits)
33
34 DEFTYPES(8)
35 DEFTYPES(16)
36 DEFTYPES(32)
37 DEFTYPES(64)
38
39 typedef float f32;
40 typedef double f64;
41
42 DEFTYP(float, f32)
43 DEFTYP(double, f64)
44
45 typedef v2f32 v2f;
46 typedef v3f32 v3f;
47
48 typedef aabb2f32 aabb2f;
49 typedef aabb3f32 aabb3f;
50
51 #undef DEFRW
52 #undef DEFBOX
53 #undef DEFVEC
54 #undef DEFTYP
55 #undef DEFTYPES
56
57 #endif