]> git.lizzy.rs Git - dragonstd.git/blob - number.h
Extract source from dragonblocks alpha
[dragonstd.git] / number.h
1 #ifndef _DRAGONTYPE_NUMBER_H_
2 #define _DRAGONTYPE_NUMBER_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         bool v2 ## type ## _equals(v2 ## type a, v2 ## type b); \
22         v2 ## type v2 ## type ## _add(v2 ## type a, v2 ## type b); \
23         typedef struct {type x, y, z;} v3 ## type; \
24         DEFRW(v3 ## type) \
25         DEFBOX(3 ## type) \
26         bool v3 ## type ## _equals(v3 ## type a, v3 ## type b); \
27         v3 ## type v3 ## type ## _add(v3 ## type a, v3 ## type b);
28
29 #define DEFTYP(from, to) \
30         typedef from to; \
31         DEFRW(to) \
32         DEFVEC(to)
33
34 #define DEFTYPES(bits) \
35         DEFTYP(int ## bits ## _t, s ## bits) \
36         DEFTYP(uint ## bits ## _t, u ## bits)
37
38 DEFTYPES(8)
39 DEFTYPES(16)
40 DEFTYPES(32)
41 DEFTYPES(64)
42
43 typedef float f32;
44 typedef double f64;
45
46 DEFTYP(float, f32)
47 DEFTYP(double, f64)
48
49 #undef DEFRW
50 #undef DEFBOX
51 #undef DEFVEC
52 #undef DEFTYP
53 #undef DEFTYPES
54
55 #endif