/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
126.1.1 by Gustav Hartvigsson
* Using
1
#pragma once
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
2
30 by Gustav Hartvigsson
* Made the code compile using CMake.
3
#include <stdlib.h>
4
#include <stdint.h>
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
5
#include "defs.h"
6
7
/** @file
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
8
 * @defgroup Vectors Vectors
9
 * @addtogroup Vectors
10
 * @{
11
 * Vectors are multi value structures that can be used when doing some types of
12
 * maths.
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
13
 */
14
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
15
S_BEGIN_DECLS
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
16
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
17
/**
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
18
 * A Vector of three standard int values.
19
 *
20
 * A Vec3 is considerer a primitive type and as such has no ref/unref memory
21
 * management and no vec_free function. You will have to do that yourself.
22
 *
23
 * @sa vec3_new
24
 * @sa Vec3_16
25
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
26
typedef struct
27
Vec3 {
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
28
  sint a;
29
  sint b;
30
  sint c;
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
31
} Vec3;
32
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
33
/**
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
34
 * A Vector of three 16 bit int values.
35
 *
36
 * @sa vec3_16_new
37
 * @sa Vec3
38
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
39
typedef struct
40
Vec3_16 {
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
41
  sshort a;
42
  sshort b;
43
  sshort c;
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
44
} Vec3_16;
45
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
46
/**
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
47
 *
48
 * A Vec3_f is a vector of three 32bit precision floating point values.
49
 */
50
typedef struct
51
Vec3_f {
52
  sfloat a;
53
  sfloat b;
54
  sfloat c;
55
} Vec3_f;
56
83 by Gustav Hartvigsson
* vec.h:
57
#ifndef __MSC_VER
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
58
/**
59
 * Add Vectors together, resulting in a new vector.
60
 *
61
 * The type of vector that is returned depends on the types that were put in.
62
 *
63
 * Due to the reflective way of these operations, many may just be inverses of
64
 * others. IE: `vec3_add (Vec3 *, Vec3_16 *)` is the same as
65
 * `vec3_add (Vec3_16 *, Vec3 *)`.
66
 */
84 by Gustav Hartvigsson
WOOPS!
67
#define vec3_add(x, y) _Generic((x, y)\
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
68
                                 Vec3 *: _Generic((y)\
69
                                                 Vec3 *: vec3_add_vec3\
70
                                                 Vec3_16 *: vec3_add_vec3_16\
71
                                                 Vec3_f *: vec3_add_vec3_f\
72
                                                 )\
73
                                 Vec3_16 *: _Generic((y)\
74
                                                    Vec3 *: vec3_16_add_vec3\
75
                                                    Vec3_16 *: vec3_16_add_vec3_16\
76
                                                    Vec3_f *: vec3_16_add_vec3_f\
77
                                                    )\
78
                                 Vec3_f *: _Generic((y)\
79
                                                   Vec3 *: vec3_f_add_vec3\
80
                                                   Vec3_16 *: vec3_f_add_vec3_16\
81
                                                   Vec3_f *: vec3_f_add_vec3_f\
82
                                                   )\
83
                                 )(x,y)
83 by Gustav Hartvigsson
* vec.h:
84
#endif /* __MSC_VER */
85
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
86
87
#define vec_free(x) free (x)
88
89
90
91
/** @brief
92
 * allocates and initialises a Vec3 pointer.
93
 *
94
 * @sa Vec3
95
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
96
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
97
Vec3 *
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
98
vec3_new (sint a,
99
          sint b,
100
          sint c);
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
101
102
/**
103
 * Add Vector a to Vector
104
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
105
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
106
Vec3 *
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
107
vec3_add_vec3 (Vec3 * a,
108
               Vec3 * b);
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
109
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
110
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
111
Vec3 *
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
112
vec3_add_vec3_16 (Vec3 * a,
113
                  Vec3_16 * b);
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
114
115
116
/**
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
117
 * @brief
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
118
 * allocates and initialises a Vec3_16 pointer.
119
 * 
120
 * @sa Vec3_16
121
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
122
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
123
Vec3_16 *
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
124
vec3_16_new (sshort a,
125
             sshort b,
126
             sshort c);
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
127
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
128
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
129
Vec3_16 *
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
130
vec3_16_add_vec3_16 (Vec3_16 * a,
131
                     Vec3_16 * b);
132
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
133
S_EXPORTED
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
134
Vec3 *
135
vec3_16_add_vec3(Vec3_16 * a,
136
                 Vec3 * b);
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
137
138
139
/**
140
 * Allocates and initialises a Vec3_f pointer.
141
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
142
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
143
Vec3_f *
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
144
vec3_f_new (sfloat a,
145
            sfloat b,
146
            sfloat c);
147
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
148
S_EXPORTED
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
149
Vec3_f *
150
vec3_f_add_vec3_f (Vec3_f * a,
151
                   Vec3_f * b);
152
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
153
S_EXPORTED
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
154
Vec3_f *
155
vec3_f_add_vec3 (Vec3_f * a,
156
                 Vec3 * b);
157
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
158
S_EXPORTED
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
159
Vec3_f *
160
vec3_f_add_vec3_16 (Vec3_f * a,
161
                    Vec3_16 * b);
162
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
163
S_EXPORTED
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
164
Vec3_f *
165
vec3_add_vec3_f (Vec3 * a,
166
                 Vec3_f * b);
167
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
168
S_EXPORTED
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
169
Vec3_f *
170
vec3_16_add_vec3_f (Vec3_16 * a,
171
                    Vec3_f * b);
83 by Gustav Hartvigsson
* vec.h:
172
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
173
/** @} */
174
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
175
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
176
S_END_DECLS