]> git.lizzy.rs Git - dragonblocks_alpha.git/blob - src/types.h
Add missing header file
[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 DEFVEC(type) \
15         typedef struct {type x, y;} v2 ## type; \
16         DEFRW(v2 ## type) \
17         typedef struct {type x, y, z;} v3 ## type; \
18         DEFRW(v3 ## type)
19
20 #define DEFTYP(from, to) \
21         typedef from to; \
22         DEFRW(to) \
23         DEFVEC(to)
24
25 #define DEFTYPES(bits) \
26         DEFTYP(int ## bits ## _t, s ## bits) \
27         DEFTYP(uint ## bits ## _t, u ## bits)
28
29 DEFTYPES(8)
30 DEFTYPES(16)
31 DEFTYPES(32)
32 DEFTYPES(64)
33
34 typedef float f32;
35 typedef double f64;
36
37 DEFTYP(float, f32)
38 DEFTYP(double, f64)
39
40 typedef v2f32 v2f;
41 typedef v3f32 v3f;
42
43 #undef DEFRW
44 #undef DEFVEC
45 #undef DEFTYP
46 #undef DEFTYPES
47
48 #endif