This repository has been archived by the owner on Sep 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rw_types.h
163 lines (136 loc) · 3.35 KB
/
rw_types.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
FILE: rw_type.h
VERSION: 0.1.0
DESCRIPTION: Define or redefines common types.
AUTHOR: Raymond Wan
USAGE: Just include this file
NOTE(ray): To quickly navigate through the file,
sections and/or subsections are available to jump to.
SECTIONS:
1. __CORE
2. __DEF
*/
#ifndef __RW_TYPES_H__
#define __RW_TYPES_H__
#include <stdint.h>
// Detect compiler type (for intrinsics)
#if !defined(RW_DISABLE_INTRINSICS)
#define RW_USE_INTRINSICS
#if defined(__GNUC__) || defined(__GNUG__) || defined(__clang__)
#include <x86intrin.h>
#elif defined(_WIN32)
#include <intrin.h>
#endif
#endif // #if !defined(RW_DISABLE_INTRINSICS)
///////////////////////////////////////////////////////////////////////////////
// __CORE
///////////////////////////////////////////////////////////////////////////////
#if defined(RWTYPES_STATIC_REDEF)
#if !defined(internal)
#define internal static
#endif
#define static internal
#define global static
#endif // #if defined(RWTYPES_STATIC_REDEF)
typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;
typedef float real32;
typedef double real64;
typedef intptr_t intptr;
typedef uintptr_t uintptr;
///////////////////////////////////////////////////////////////////////////////
// __DEF
///////////////////////////////////////////////////////////////////////////////
// NOTE(ray): I don't remember why I moved the math types into here.
// I should probably be able to move them back into rw_math.h
// Is there ever a case where I need the types and not the corresponding functions?
// NOTE(ray): Be able to only include "core" types
#if !defined(RWTYPES_CORE_ONLY)
typedef union Vec2 {
struct { float x, y; };
struct { float u, v; };
float e[2];
} Vec2;
typedef union Vec3 {
struct { float x, y, z; };
struct { float r, g, b; };
struct { float u, v, w; };
float e[3];
} Vec3;
typedef union Vec4 {
struct { float x, y, z, w; };
struct { float r, g, b, a; };
float e[4];
#if defined(RW_USE_INTRINSICS)
__m128 m;
#endif
} Vec4;
typedef Vec2 Point2;
typedef Vec3 Point3;
typedef Vec4 Point4;
typedef Vec3 Normal3;
typedef union Quaternion {
struct { float x, y, z, w; };
struct { float b, c, d, a; };
float e[4];
#if defined(RW_USE_INTRINSICS)
__m128 m;
#endif
} Quaternion;
typedef union Mat3 {
// NOTE(ray): row major
struct {
float e00, e01, e02;
float e10, e11, e12;
float e20, e21, e22;
};
float e[3][3];
} Mat3;
typedef union Mat4 {
struct {
float e00, e01, e02, e03;
float e10, e11, e12, e13;
float e20, e21, e22, e23;
float e30, e31, e32, e33;
};
float e[4][4];
#if defined(RW_USE_INTRINSICS)
__m128 row[4];
#endif
} Mat4;
typedef struct Transform {
Mat4 t;
Mat4 t_inv;
} Transform;
typedef union Rect2 {
struct {
Vec2 min_p;
Vec2 max_p;
};
struct {
float min_px, min_py;
float max_px, max_py;
};
// NOTE(ray): idx 0 is the min point, and idx 1 is the max point
Vec3 p[2];
} Rect2;
typedef union Rect3 {
struct {
Vec3 min_p;
Vec3 max_p;
};
struct {
float min_px, min_py, min_pz;
float max_px, max_py, max_pz;
};
// NOTE(ray): idx 0 is the min point, and idx 1 is the max point
Vec3 p[2];
} Rect3;
#endif // #if !defined(RWTYPES_CORE_ONLY)
#endif // #ifndef __RW_TYPES_H__