-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcub.h
315 lines (285 loc) · 6.05 KB
/
cub.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zskeeter <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/04/26 20:31:39 by zskeeter #+# #+# */
/* Updated: 2021/04/29 01:36:49 by zskeeter ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CUB_H
# define CUB_H
# include "libft/libft.h"
# include "gnl/get_next_line.h"
# include "minilibx/mlx.h"
# include <stdio.h>
# include <math.h>
typedef enum {
KEY_A = 0,
KEY_S = 1,
KEY_D = 2,
KEY_W = 13,
KEY_AL = 123,
KEY_AR = 124,
KEY_AD = 125,
KEY_AT = 126,
KEY_SHIFT_L = 257,
KEY_SHIFT_R = 258,
KEY_ESC = 53
} t_buttons;
typedef struct s_keys
{
char a;
char d;
char s;
char w;
char arr_l;
char arr_r;
char arr_t;
char arr_d;
} t_keys;
/*
** Structures
*/
typedef struct s_colors
{
int defined;
int r;
int g;
int b;
} t_colors;
typedef struct s_res
{
int x;
int y;
int defined;
} t_res;
typedef struct s_pos
{
double x;
double y;
} t_pos;
typedef struct s_sprite
{
double y;
double x;
double dist;
} t_sprite;
typedef struct s_map
{
t_list *list;
t_colors c_colors;
t_colors f_colors;
t_res res;
t_pos pos;
int s_count;
char player;
char *we;
char *ea;
char *so;
char *no;
char *s;
t_sprite *sprites;
int is_scnsht;
size_t l_width;
t_list *backup;
} t_map;
typedef struct s_img
{
void *ptr;
char *addr;
int bpp;
int length;
int endian;
} t_img;
typedef struct s_dxy
{
double x;
double y;
} t_dxy;
typedef struct s_ixy
{
int x;
int y;
} t_ixy;
typedef struct s_speed
{
double forward;
double rot;
} t_speed;
typedef struct s_wall
{
int height;
int start;
int finish;
int color;
} t_wall;
typedef struct s_txtr
{
t_img img;
int h;
int w;
} t_txtr;
typedef struct s_all_txtrs
{
t_txtr so;
t_txtr no;
t_txtr ea;
t_txtr we;
t_txtr s;
} t_all_txtrs;
typedef struct s_txtr_rc
{
double s;
double p;
} t_txtr_rc;
typedef struct s_rc
{
char **arr;
t_map *data;
t_dxy player_pos;
t_dxy ray_dir;
t_dxy wens;
t_ixy ray_square;
t_dxy closest_line;
t_dxy next_line;
t_dxy plane;
t_ixy ray_step;
t_img img;
t_wall wall;
t_speed speed;
t_keys keys;
t_all_txtrs t;
t_txtr cur_side;
t_sprite *sprites;
double *zb;
double dist_to_wall;
double cam;
void *mlx;
void *win;
int was_hit;
int side;
int wens_defined;
} t_rc;
typedef struct s_txtr_data
{
double wall_x;
double tex_y;
double tex_x;
double step;
double tex_pos;
} t_txtr_data;
typedef struct s_s_rc
{
double sprite_x;
double sprite_y;
double inv_det;
double transform_y;
double transform_x;
int sprite_screen_x;
int sprite_height;
int draw_start_y;
int draw_end_y;
int sprite_width;
int draw_start_x;
int draw_end_x;
int mv_scr;
int d;
int tex_y;
int tex_x;
} t_s_rc;
typedef struct s_qs
{
int middle;
int i;
int j;
} t_qs;
/*
** Kinda general functions
*/
void error(char *err);
void init_str_and_map(char **str, t_map *map);
/*
** List validation functions
*/
void iterate_list(t_map *map);
int is_map_line(char *str);
int is_wside(char *str);
int is_xpm_file(char *str);
void fill_resolution(t_map *map, char *res_x, char *res_y);
void define_file(t_map *map, char *type, char *file);
void fill_s_c_f(t_map *map, char c, char *file);
int is_colors_set(char *str);
void store_colors(t_map *map, char type, char *str);
int is_param(char *str);
/*
** Map validation functions
*/
void convert_to_array(t_list *map_list, t_map *data);
void validate_map(char **arr, t_map *data);
/*
** Sprites
*/
void init_sprites(char **arr, t_map *data);
void recalc_sprites(t_rc *rc);
/*
** GUI functions
*/
void init_windows(char **arr, t_map *data);
void draw_sprites(t_rc *rc);
void put_pixel(t_img img, int x, int y, int color);
int make_trgb(int t, int r, int g, int b);
int drawer(t_rc *rc);
void handle_player_dir(t_rc *rc, t_map *data);
void handle_rc(t_rc *rc, t_map *data, int x);
void init_keys(t_rc *rc);
void init_rc(t_rc *rc, t_map *data);
void init_mlx(t_rc *rc);
int key_press(int code, t_rc *rc);
int key_unpress(int code, t_rc *rc);
int handle_loop(t_rc *rc);
int get_pixel(t_txtr txtr, t_txtr_data *data);
void put_pixel(t_img img, int x, int y, int color);
void rot_right(t_rc *rc);
void rot_left(t_rc *rc);
void step_forward(t_rc *rc);
void step_back(t_rc *rc);
void step_right(t_rc *rc);
void step_left(t_rc *rc);
void calc_wall(t_rc *rc, t_map *data);
void define_color(t_rc *rc);
void calcs_for_txtr(t_rc *rc, t_txtr_data *data);
void prepare_rc(t_rc *rc);
void run_dda(t_rc *rc, char **arr);
void define_side(t_rc *rc);
/*
** Screenshots
*/
void make_scrsht(t_rc *rc);
/*
** Additional utils
*/
int ft_isnumber(char *str);
size_t get_max(size_t a, size_t b);
double ft_abs_dbl(double num);
void quicksort(t_sprite *arr, int first, int last);
void print_sprites(t_map *data, t_dxy player_pos);
double get_decimal(double num);
double get_floor(double num);
double get_up(double num);
int make_trgb(int t, int r, int g, int b);
int finish(t_rc *rc);
void miss_zeros(char **res_x, char **res_y);
int get_min(int a, int b);
int count_commas(char *str);
size_t ft_strlen_without_spaces(char *str);
void init_lines(char **arr, size_t width);
void check_char(char c);
void clean_arr(char **arr);
void free_list(t_list *list);
void bubblesort(t_sprite *arr, int count);
void free_file_paths(t_map *data);
void check_txtr(void *ptr);
#endif