-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcub3d.h
291 lines (249 loc) · 6.6 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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sanan <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/11 13:49:40 by sanan #+# #+# */
/* Updated: 2023/10/24 13:36:58 by sanan ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CUB3D_H
# define CUB3D_H
# include <unistd.h>
# include <stdlib.h>
# include <stdio.h>
# include <fcntl.h>
# include <math.h>
# include <mlx.h>
# define OPEN_ERROR -1
# define READ_ELEMENTS 1
# define READ_MAP 1
# define FILLED 1
# define UNFILLED 0
# define NO_MORE_TO_READ NULL
# define MOVE_SPEED 0.035
# define ROTATE_SPEED 0.035
# ifndef SCREEN_WIDTH
# define SCREEN_WIDTH 640
# endif
# ifndef SCREEN_HEIGHT
# define SCREEN_HEIGHT 480
# endif
# ifndef GAME_NAME
# define GAME_NAME "cub3D"
# endif
# ifndef TEXTURE_WIDTH
# define TEXTURE_WIDTH 242
# endif
# ifndef TEXTURE_HEIGHT
# define TEXTURE_HEIGHT 242
# endif
# define RED_X_BUTTON 17
enum e_errno{
ERR_ELEM_INVALID,
ERR_ELEM_LACK,
ERR_MAP_FILE,
ERR_MAP_INVALID,
ERR_MAP_INVALID_PLAYER,
ERR_ARG,
ERR_WALL_INVALID,
};
enum e_key
{
KEY_W = 13,
KEY_A = 0,
KEY_S = 1,
KEY_D = 2,
KEY_LEFT = 123,
KEY_RIGHT = 124,
KEY_ESC = 53,
};
enum e_key_indexes
{
W = 0,
A,
S,
D,
LEFT,
RIGHT,
ESC,
};
typedef struct s_map
{
char *line;
struct s_map *prev;
struct s_map *next;
} t_map;
enum e_direction
{
NORTH = 0,
SOUTH,
EAST,
WEST,
MAP_NORTH = 2,
MAP_SOUTH = 3,
MAP_EAST = 4,
MAP_WEST = 5,
};
enum e_key_events
{
PRESS = 2,
RELEASE = 3,
EXIT = 17,
};
enum e_key_masks
{
MASK_PRESS = 1L<<0,
MASK_RELEASE = 1L<<1,
MASK_EXIT = 1L<<2,
};
typedef struct s_info
{
int fd;
char *north_path;
char *south_path;
char *west_path;
char *east_path;
int f_rgb[3];
int c_rgb[3];
struct s_map *map;
int map_width;
int map_height;
} t_info;
typedef struct s_vector
{
double x;
double y;
} t_vec;
typedef struct s_img
{
void *img;
void *data;
int bits_per_pixel;
int line_length;
int endian;
} t_img;
typedef struct s_game
{
void *mlx;
void *win;
void *img;
char *img_data;
int bits_per_pixel;
int img_line_size;
int endian;
char *texture[4];
t_img texture_imgs[4];
int **map;
int map_row;
int map_col;
int ceiling;
int floor;
int keys[7];
t_vec pos;
t_vec coord;
t_vec dir;
t_vec old_dir;
t_vec ray_dir;
t_vec plane;
double camera_x;
t_vec side_dist;
t_vec delta_dist;
double perp_wall_dist;
t_vec step;
int color;
int side;
int line_height;
int draw_start;
int draw_end;
int wall_texture_x;
int wall_texture_y;
double wall_x;
double step_texture;
double texture_pos;
int draw_buffer[SCREEN_HEIGHT][SCREEN_WIDTH];
} t_game;
/* ./cub3d_utils.c */
int is_extension_valid(char *filename);
int elements_filled(int elements_cnt[]);
void check_comma(char *str);
void check_file_order(char *line);
int get_last(t_map *map);
char *ft_linedup(char *s1);
char **ft_split(char const *s, char c);
int ft_strncmp(const char *s1, const char *s2, unsigned int n);
int ft_atoi(const char *str);
int ft_strcmp(char *s1, char *s2);
/* ./cub3d_utils2.c */
int rgb_to_hex(int red, int green, int blue);
int is_nsew(char c);
void check_path_valid(char *str);
void check_cases(t_map *tmp, char c, int i);
/* ./parsing/check_island_utils.c */
void check_island1(char **board, t_map *tmp, int *x, int *y);
void check_island2(char **board, int last);
/* ./parsing/elements_init.c */
void elements_cnt_init(int elements_cnt[]);
void check_path(t_info *info, char *line, int elements_cnt[]);
void check_f_rgb(t_info *info, char *line, int elements_cnt[]);
void check_c_rgb(t_info *info, char *line, int elements_cnt[]);
void elements_init(t_info *info);
/* ./parsing/check_wall.c */
void check_side(t_map *map, int i, int j, int last);
void check_closed(t_map *map, int i, int j, int last);
void recursion(char **board, int x, int y, int last);
void check_island(t_map *map, int i, int last);
void check_wall(t_map *map);
/* ./parsing/info_init.c */
void check_char(t_map *map, int player_cnt);
void info_init(t_info *info, char *filename);
/* ./parsing/map_init.c */
int check_validity(char *line);
void check_empty_line(t_map *map);
void map_start(t_info *info);
void map_init(t_info *info);
/* ./parsing/game_init.c */
void free_info_map(t_info *info);
void copy_map(t_info *info, t_game *game);
void copy_texture(t_info *info, t_game *game);
void init_map(t_info *info, t_game *game);
void put_path_if_valid(char **path_ptr, char *line, int cnt);
/* ./get_next_line/get_next_line_utils.c */
size_t ft_strlen(const char *s);
char *ft_strchr(const char *s, int c);
char *ft_strjoin(char *s1, char *s2);
char *ft_strdup(char *s1);
/* ./get_next_line/get_next_line.c */
char *get_next_line(int fd);
/* ./error/exit_error.c */
char *get_msg_by_errno(int errno);
void exit_error(int errno);
int exit_game(void);
void set_ray_direction(t_game *game);
void set_player_direction(t_game *game, int direction);
void set_map_position(t_game *game);
void set_delta_distance(t_game *game);
void set_side_distance(t_game *game);
void dda(t_game *game);
void init_game_mlx(t_game *game);
void init_game_textures(t_game *game);
void init_game_ray_condition(t_game *game);
void set_img_file_and_data(t_game *game, int direction);
int key_press(int key_code, t_game *game);
int key_release(int key_code, t_game *game);
void put_pixel(t_game *game, int x, int y, int color);
unsigned int get_color(t_game *game, int direction);
void hook_key_events(t_game *game);
int run_game(t_game *game);
void put_pixel(t_game *game, int x, int y, int color);
void draw_vertical(t_game *game, int x);
void raycast(t_game *game);
int read_keys_and_move(t_game *game);
void set_draw_range(t_game *game);
void calculate_texture(t_game *game);
void set_draw_buffer(t_game *game, int x);
void put_buffer_to_image(t_game *game);
unsigned int get_color(t_game *game, int direction);
#endif