-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcub3d.h
211 lines (198 loc) · 5.57 KB
/
cub3d.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3D.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lbrandy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/25 14:05:58 by lbrandy #+# #+# */
/* Updated: 2021/04/02 19:05:56 by lbrandy ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CUB3D_H
# define CUB3D_H
# include "./source/libft/libft.h"
# include <mlx.h>
# include <stdio.h>
# include <math.h>
# include <unistd.h>
typedef struct s_win
{
void *mlx;
void *win;
void *img;
char *addr;
int bpp;
int length;
int endian;
} t_win;
typedef struct s_draw
{
int line_h;
int start;
int end;
int color;
int tex_width;
int tex_height;
double wall_x;
double step;
int tex_x;
int tex_y;
double tex_pos;
double ms;
double rs;
} t_draw;
typedef struct s_raycast
{
double camera_x;
double raydir_x;
double raydir_y;
int map_x;
int map_y;
double sidedist_x;
double sidedist_y;
double deltadist_x;
double deltadist_y;
double walldist;
int step_x;
int step_y;
int hit;
int side;
} t_raycast;
typedef struct s_pos
{
int map_width;
int map_height;
double pos_x;
double pos_y;
double dir_x;
double dir_y;
double plane_x;
double plane_y;
} t_pos;
typedef struct s_textures
{
int x;
int y;
char *no_texture;
char *so_texture;
char *we_texture;
char *ea_texture;
char *s_texture;
int f;
int c;
} t_textures;
typedef struct s_sprite
{
double x;
double y;
double dist;
} t_sprite;
typedef struct s_datasprite
{
t_sprite *sprites;
int count_sprites;
double sprite_x;
double sprite_y;
double inv_det;
double transform_x;
double transform_y;
int sprite_screen_x;
int tex_height;
int tex_width;
int sprite_height;
int sprite_width;
int draw_start_x;
int draw_start_y;
int draw_end_x;
int draw_end_y;
int stripe;
int tex_x;
int tex_y;
int color;
double *z_buffer;
} t_datasprite;
typedef struct s_datatext
{
void *img;
char *addr;
int bpp;
int length;
int endian;
int height;
int width;
} t_datatext;
typedef struct s_all
{
t_datatext *no;
t_datatext *so;
t_datatext *we;
t_datatext *ea;
t_datatext *s;
t_win *win;
t_textures *textures;
t_pos *pos;
t_raycast *raycast;
t_draw *draw;
t_datasprite *data_sprite;
char **map;
char dir;
} t_all;
void my_mlx_pixel_put(t_all *all, int x, int y, int color);
int raycasting(t_all *all);
void draw_frame(t_all *all);
void reading_textures(t_all *all);
void draw_wall(t_all *all, t_draw *d, int *y, int x);
void init_mlx(t_win *w, t_all *all, int argc);
void draw_sprites(t_all *all);
void draw_sprite(t_datasprite *s, t_textures *res,
t_datatext *tex, t_all *all);
void init_sprite(t_all *all);
void quick_sort(t_sprite *sprite, int start, int end);
void array_of_sprites(t_all *all, int i);
int count_of_sprites(char **map);
int argv_check(int argc, char **argv);
t_all *pars_all(char *name_of_file);
void check_color(t_textures *tex, int type);
void skip(char **s, int flag);
void pars_colors(t_textures *tex, int type, char *s);
t_list *pars_struct(t_textures *t, t_list **list);
void pars_file(t_list **list, t_all *all);
void fill_map(t_list *list, t_all *all);
t_pos *pars_map(t_list *list, t_all *all);
char **copy_map(t_pos *p, t_all *all);
void free_new_map(t_pos *p, char **new_map);
void init_dir(t_pos *pos, char temp);
void init_pos(t_all *all, t_pos *pos);
void check_up_down(char **map, int i, int h);
void check_boundary(t_all *all, char **map, t_pos *pos);
int max_width_map(char **map);
void flood_fill(char **map, t_pos *p, int x, int y);
void flood(t_pos *pos, t_all *all);
void pars_res(char *res, t_textures *t, int len);
void skip_spaces(char **s);
void check_trash_str(char *s, t_textures *t);
int check_full_struct(t_textures *t);
void init_struct(t_textures *t);
void pars_textures(t_textures *text, int side, char *s);
void check_xpm(char *s);
void check_textures(t_textures *tex, int side);
void error_handler(char *str);
void ft_lstfree_cont(void *content);
int my_exit_from_game(void);
void screen_save(t_all *all, int argc);
int ft_press_but(int keycode, t_all *all);
int ft_release_but(int keycode, t_all *all);
int drawing(int keycode, t_all *all);
int len_number(char *s, int flag);
void ft_filling_map(t_list *list, t_all *all, int count);
void init_step(t_raycast *ray, t_pos *pos);
void init_raycast(t_raycast *raycast, int x, int w, t_pos *pos);
void calc_dda(t_raycast *ray, char **map, t_pos *p);
void init_draw(t_draw *draw, t_raycast *r, t_all *all, t_pos *p);
void init_sprite_dist(t_datasprite *data_sprite,
t_pos *pos, t_all *all);
void calculate_draw(t_datasprite *sprite, t_textures *res);
void calc_sprite(t_datasprite *sprite, int i,
t_pos *pos, t_textures *res);
#endif