modify logging to simplify i18n
[voxelands-alt.git] / inc / common.h
blob2482dba056d0f9c02a55e1e7baeee616d035de2d
1 #ifndef _COMMON_H_
2 #define _COMMON_H_
4 #ifndef LINUX
5 #ifdef __linux__
6 #define LINUX
7 #endif
8 #endif
10 #ifdef LINUX
12 #ifdef _POSIX_C_SOURCE
13 #undef _POSIX_C_SOURCE
14 #endif
15 #define _POSIX_C_SOURCE 200112L
17 #ifdef _XOPEN_SOURCE
18 #undef _XOPEN_SOURCE
19 #endif
20 #define _XOPEN_SOURCE 700
22 #ifdef _DEFAULT_SOURCE
23 #undef _DEFAULT_SOURCE
24 #endif
25 #define _DEFAULT_SOURCE
26 #endif
28 #include <stdlib.h>
29 #include <stdint.h>
31 #ifndef _HAVE_ARRAY_TYPE
32 #define _HAVE_ARRAY_TYPE
33 typedef struct array_s {
34 uint32_t type;
35 uint32_t length;
36 uint32_t size;
37 void *data;
38 } array_t;
39 #endif
41 #ifndef _HAVE_FILE_TYPE
42 #define _HAVE_FILE_TYPE
43 typedef struct file_s {
44 struct file_s *prev;
45 struct file_s *next;
46 char* path;
47 char* name;
48 unsigned char* data;
49 int size;
50 int len;
51 int pos;
52 int modified;
53 } file_t;
54 #endif
56 #ifndef _HAVE_COLOUR_TYPE
57 #define _HAVE_COLOUR_TYPE
58 typedef struct colour_s {
59 uint8_t r;
60 uint8_t g;
61 uint8_t b;
62 uint8_t a;
63 } colour_t;
64 #endif
66 #ifndef _HAVE_V3_TYPE
67 #define _HAVE_V3_TYPE
68 typedef struct v3_s {
69 float x;
70 float y;
71 float z;
72 } __attribute__((packed)) v3_t;
73 #endif
75 #ifndef _HAVE_V2_TYPE
76 #define _HAVE_V2_TYPE
77 typedef struct v2_s {
78 float x;
79 float y;
80 } __attribute__((packed)) v2_t;
81 #endif
83 #ifndef _HAVE_AABOX_TYPE
84 #define _HAVE_AABOX_TYPE
85 typedef struct aabox_s {
86 v3_t min;
87 v3_t max;
88 } aabox_t;
89 #endif
91 #ifndef _HAVE_RECT_TYPE
92 #define _HAVE_RECT_TYPE
93 typedef struct rect_s {
94 int x;
95 int y;
96 int w;
97 int h;
98 } rect_t;
99 #endif
101 #ifndef _HAVE_RECTF_TYPE
102 #define _HAVE_RECTF_TYPE
103 typedef struct rectf_s {
104 float x;
105 float y;
106 float w;
107 float h;
108 } rectf_t;
109 #endif
111 #ifndef _HAVE_POS_TYPE
112 #define _HAVE_POS_TYPE
113 typedef struct pos_s {
114 int16_t x;
115 int16_t y;
116 int16_t z;
117 } __attribute__((packed)) pos_t;
118 #endif
120 #ifndef _HAVE_QUATERNION_TYPE
121 #define _HAVE_QUATERNION_TYPE
122 typedef struct quaternion_s {
123 float w;
124 float x;
125 float y;
126 float z;
127 } __attribute__((packed)) quaternion_t;
128 #endif
130 #ifndef _HAVE_MATRIX_TYPE
131 #define _HAVE_MATRIX_TYPE
132 typedef struct matrix_s {
133 float data[16];
134 } matrix_t;
135 #endif
137 #define CN_ERROR 0x01
138 #define CN_WARN 0x02
139 #define CN_ACTION 0x03
140 #define CN_CHAT 0x04
141 #define CN_INFO 0x05
142 #define CN_DEBUG 0x06
144 #define VLSTATE_EXIT 0x00
145 #define VLSTATE_GET 0x01
146 #define VLSTATE_MENU 0x02
147 #define VLSTATE_PAUSE 0x03
148 #define VLSTATE_PLAY 0x04
150 /* defined in math.c */
151 int math_next_pow2(int a);
152 int math_rand_range(int low, int high);
153 float math_rand_rangef(float low, float high);
154 float math_radians_to_degrees(float rads);
155 float math_degrees_to_radians(float degrees);
157 /* defined in math_quaternion.c */
158 quaternion_t *quat_create_quat(float x, float y, float z, float w);
159 quaternion_t *quat_create_euler(float x, float y, float z);
160 quaternion_t *quat_create_axis(v3_t *v, float angle);
161 void quat_init_quat(quaternion_t *q, float x, float y, float z, float w);
162 void quat_init_euler(quaternion_t *q, float x, float y, float z);
163 void quat_init_axis(quaternion_t *q, v3_t *v, float angle);
164 void quat_normalise(quaternion_t *q);
165 void quat_get_axis(quaternion_t *q, v3_t *v, float *angle);
166 void quat_multiply_vector(quaternion_t *q, quaternion_t *rq, v3_t *v);
167 void quat_multiply(quaternion_t *q1, quaternion_t *q2, quaternion_t *rq);
168 void quat_print(quaternion_t *q);
169 void quat_computew(quaternion_t *q);
170 void quat_rotate(quaternion_t *q, v3_t *in, v3_t *out);
172 /* defined in math_vector.c */
173 void vect_create(v3_t *start, v3_t *end, v3_t *v);
174 float vect_length(v3_t *v);
175 void vect_normalise(v3_t *v);
176 float vect_scalarproduct(v3_t *v1, v3_t *v2);
177 void vect_crossproduct(v3_t *v1, v3_t *v2, v3_t *v3);
178 void vect_dotproduct(v3_t *v1, v3_t *v2, v3_t *v3);
179 void vect_subtract(v3_t *v1, v3_t *v2, v3_t *v3);
180 float vect_diameter(v3_t *v);
181 float math_dotproduct(v3_t *v1, v3_t *v2);
182 float math_distance(v3_t *v1, v3_t *v2);
184 /* defined in math_matrix.c */
185 void matrix_init(matrix_t *m);
186 matrix_t *matrix_create(void);
187 void matrix_multiply(matrix_t *m, matrix_t *mul);
188 void matrix_translate(matrix_t *m, float x, float y, float z);
189 void matrix_translate_v(matrix_t *m, v3_t *v);
190 void matrix_scale(matrix_t *m, float x, float y, float z);
191 void matrix_scale_v(matrix_t *m, v3_t *v);
192 void matrix_rotate(matrix_t *m, float rads, float x, float y, float z);
193 void matrix_rotate_v(matrix_t *m, float rads, v3_t *v);
194 void matrix_rotate_x(matrix_t *m, float rads);
195 void matrix_rotate_y(matrix_t *m, float rads);
196 void matrix_rotate_z(matrix_t *m, float rads);
197 void matrix_rotate_deg(matrix_t *m, float degrees, float x, float y, float z);
198 void matrix_rotate_deg_v(matrix_t *m, float degrees, v3_t *v);
199 void matrix_rotate_deg_x(matrix_t *m, float degrees);
200 void matrix_rotate_deg_y(matrix_t *m, float degrees);
201 void matrix_rotate_deg_z(matrix_t *m, float degrees);
202 void matrix_rotate_quat(matrix_t *m, quaternion_t *q);
204 /* defined in string.c */
205 char* trim(char* str);
206 char* strdup(const char* str);
207 int strappend(char* dest, int size, char* str);
208 int parse_bool(char* str);
210 /* defined in config.c */
211 char* config_get(char* name);
212 int config_get_int(char* name);
213 float config_get_float(char* name);
214 int config_get_bool(char* name);
215 void config_set(char* name, char* value);
216 int config_set_command(array_t *args);
217 void config_set_int(char* name, int value);
218 void config_set_float(char* name, float value);
219 void config_set_default(char* name, char* value, int (*setter)(char* v));
220 void config_set_default_int(char* name, int value, int (*setter)(char* v));
221 void config_set_default_float(char* name, float value, int (*setter)(char* v));
222 void config_load(char* file);
223 int config_load_command(array_t *args);
224 int config_ignore_command(array_t *args);
225 void config_init(int argc, char** argv);
226 void config_save(void);
228 /* defined in config_default.c */
229 void config_default_init(void);
231 /* defined in log.c */
232 int log_minlevel_setter(char* v);
233 int log_maxlevel_setter(char* v);
234 int log_sminlevel_setter(char* v);
235 int log_smaxlevel_setter(char* v);
236 int log_cminlevel_setter(char* v);
237 int log_cmaxlevel_setter(char* v);
238 int log_file_setter(char* v);
239 void vlprintf(uint8_t type, char* fmt,...);
241 /* defined in utf8.c */
242 int utf8_seqlen(char* str);
243 uint32_t utf8_nextchar(char* str, int *i);
244 uint32_t utf8_toutf32(char* src, int size);
245 int utf8_fromutf32(char *dest, int sz, uint32_t ch);
246 uint32_t utf16_toutf32(uint16_t *str);
247 int utf8_offset(char* str, int i);
248 int utf8_charindex(char* str, int o);
249 int utf8_strlen(char* str);
250 void utf8_inc(char* str, int *i);
251 void utf8_dec(char* str, int *i);
252 char* utf8_strchr(char* str, uint32_t ch, int *charn);
253 char* utf8_memchr(char* str, uint32_t ch, size_t sz, int *charn);
255 /* defined in sys_console.c */
256 void sys_console_print(char* str, int newline);
257 void sys_console_printf(char* fmt, ...);
258 void sys_console_init(void);
259 void sys_console_exit(void);
261 /* defined in intl.c */
262 char* gettext(const char *s);
263 char* ngettext(const char* s1, const char* s2, int n);
264 void intl_init(void);
266 /* defined in time.c */
267 void time_init(void);
268 uint32_t time_ticks(void);
269 void delay(uint32_t ms);
270 float time_dtime(uint32_t last);
271 uint32_t interval_delay(uint32_t last, uint32_t hz);
272 uint32_t calc_fps(uint32_t prev, uint32_t current);
274 /* defined in command.c */
275 int command_init(void);
276 int command_add(char* name, int (*func)(array_t *args));
277 int command_apply(char* name, char* value);
278 int command_exec(char* str);
279 int command_execf(char* str, ...);
280 void command_save(file_t *f);
282 /* defined in main.c */
283 int client_state(int s);
285 #endif