-
Notifications
You must be signed in to change notification settings - Fork 0
/
cub3d.h
249 lines (207 loc) · 5.58 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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adu-pavi <adu-pavi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/18 09:05:22 by AlainduPa #+# #+# */
/* Updated: 2021/04/19 18:44:03 by adu-pavi ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CUB3D_H
# define CUB3D_H
# include <math.h>
# include <stdio.h>
# include <fcntl.h>
# include <string.h>
# include "mlx/mlx.h"
# include "libft/libft.h"
# include "utils/keycode_linux.h"
# define MLX_SYNC_IMAGE_WRITABLE 1
# define MLX_SYNC_WIN_FLUSH_CMD 2
# define MLX_SYNC_WIN_CMD_COMPLETED 3
# define X_EVENT_EXIT 17
typedef struct s_img
{
void *img;
char *addr;
int bpp;
int line_length;
int width;
int height;
int endian;
} t_img;
typedef struct s_sprite
{
double posx;
double posy;
double distance;
t_img *tex;
struct s_sprite *next;
struct s_sprite *sorted;
} t_sprite;
typedef struct s_sprite_print
{
double spritex;
double spritey;
double invdet;
double transformx;
double transformy;
int spritescreenx;
int spritewidth;
int spriteheight;
int drawstarty;
int drawendy;
int drawstartx;
int drawendx;
int texx;
int texy;
int texwidth;
int texheight;
} t_sprite_print;
typedef struct s_data
{
void *mlx_ptr;
void *mlx_win;
} t_data;
typedef struct s_str
{
char *line;
struct s_str *next;
} t_str;
typedef struct s_pos
{
double x;
double y;
} t_pos;
typedef struct s_player
{
int position_initialised;
double posx;
double posy;
double dirx;
double diry;
double planex;
double planey;
double time;
double old_time;
double camerax;
double raydirx;
double raydiry;
int mapx;
int mapy;
double sidedistx;
double sidedisty;
double deltadistx;
double deltadisty;
double perpwalldist;
int stepx;
int stepy;
int hit;
int side;
int lineheight;
int drawstart;
int drawend;
int wallcolor;
t_img current_image;
int movex;
int movey;
int rot_left;
int rot_right;
double wallx;
int texnum;
int texx;
int texy;
double step;
double texpos;
} t_player;
typedef struct s_map
{
int window_height;
int window_width;
int window_max_height;
int window_max_width;
int color_floor;
int color_ceiling;
int te_no_color;
int te_so_color;
int te_we_color;
int te_ea_color;
int te_s_color;
t_img te_no;
t_img te_so;
t_img te_we;
t_img te_ea;
t_img te_s;
t_str *plan;
int plan_height;
int plan_width;
t_sprite *sprites;
} t_map;
typedef struct s_config
{
int screenshot;
char *prog_name;
char *conf_file;
int conf_check;
} t_config;
typedef struct s_game
{
t_map map_info;
t_player player;
t_data mlx;
t_config config;
t_sprite_print sprites_p;
} t_game;
void my_mlx_pixel_put(t_img *data, int x, int y, int color);
int parsing(t_game *game, int argc, char **argv);
int handle_resolution(char *line, t_map *map_info, t_game *game);
int handle_textures(char **line, t_map *map_info, t_data *data);
int load_texture(char *tex_link, t_img *img, t_data *mlx);
int parse_line(char *line, t_data *data, t_map *map_info, t_game *game);
int handle_colors(char **line, t_map *map_info);
int parse_map_line(t_game *game, t_map *map, char *line);
char ft_map(t_str *map, int width, int height);
void set_wall_color(t_game *game, int x);
int draw_floor_and_ceiling(t_img img_to_change, int x, int y_begin, int len,
t_map *map_info);
int drawvertlinefromcolor(t_img img_to_change, int x, int y_begin, int len,
int color);
int raycasting(t_game *game);
int key_press(int key_code, t_game *game);
int key_release(int key_code, t_game *game);
void perform_dda(t_game *game);
void update_pos_view(t_game *game);
void update_rotation(t_game *game);
void define_deltaDist(t_game *game);
void define_side_dist(t_game *game);
void search_wall(t_game *game);
void get_line_length(t_game *game);
int everything_was_set(t_map *map_info, t_game *game);
void init_player(t_player *player);
void init_map(t_map *map_info);
void init_config(t_config *config);
void set_init_pos(t_game *game, int x, int y, char c);
void check_user_position(t_game *game, char *str, int y);
int save_sprite(int x, int y, t_game *game);
void sprites_scanner(t_game *game, char *str, int y);
int parse_map_line(t_game *game, t_map *map, char *line);
void clear_player(t_game *game);
void clear_mlx(t_data *mlx);
void clear_map_info(t_game *game);
void clear_config(t_config *config);
void clear_all_variables(t_game *game);
int exit_error(t_game *game, char *message);
int exit_success(t_game *game);
int write_and_save_screen(t_game *game);
int load_color_from_tex(t_img *tex, int x, int y);
void texture_pixel_put(t_game *game, t_img *tex, int x, int y);
void sprite_pixel_put(t_game *game, t_img *tex,
t_sprite_print *sprit, int x, int y);
int sprite_bubble_sort(t_game *game);
double get_ss_distance(double posX, double posY, int posSX, int posSY);
int set_sprite_distance(t_game *game);
int main(int argc, char **argv);
void print_all_sprite(t_game *game);
#endif