-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcub3d.h
More file actions
224 lines (208 loc) · 5.63 KB
/
cub3d.h
File metadata and controls
224 lines (208 loc) · 5.63 KB
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
#ifndef CUB3D_H
# define CUB3D_H
# include <fcntl.h>
# include <unistd.h>
# include <limits.h>
# include <math.h>
# include <stdlib.h>
# include "MLX42/MLX42.h"
# define NO 11
# define SO 12
# define WE 13
# define EA 14
# define F 15
# define C 16
# define TILESIZE 64
# define PLAYER_RADIUS 9.14285714286
# define STRAFE_SPEED 4
# define FOV 60
# define W_HEIGHT 700
# define WIN_WIDTH 1000
# define BLACK 0x000000FF
# define WHITE 0xFFFFFFFF
# define RED 0xFF0000FF
# define CYAN 0x00FFFFFF
# define LIGHT_GREEN 0x008080FF
# define MINI_MAP_WH 200
typedef struct s_trash
{
void *to_free;
struct s_trash *next;
} t_trash;
typedef struct s_rgb
{
unsigned char red;
unsigned char green;
unsigned char blue;
} t_rgb;
typedef struct s_point
{
double x;
double y;
int hori_or_vert;
} t_point;
typedef struct s_player
{
long x;
long y;
double radius;
int turn_direction;
int walk_direction;
double rotation_angle;
int move_speed;
double rotation_speed;
int strafe_direction;
int spawn_direction;
bool up;
bool left;
bool down;
bool right;
} t_player;
typedef struct s_sprite
{
mlx_texture_t *textures[13];
mlx_image_t *img;
} t_sprite;
typedef struct s_cub
{
char *no;
char *we;
char *so;
char *ea;
char *color_floor;
char *color_ceiling;
t_rgb *ceiling;
t_rgb *floor;
char **map;
t_trash *garbage;
mlx_t *mlx_window;
mlx_image_t *mlx_img;
double window_height;
double window_width;
t_player *player;
double closest_inter_x;
double closest_inter_y;
double hor_closest_inter_x;
double hor_closest_inter_y;
mlx_texture_t *no_pic_data;
mlx_texture_t *so_pic_data;
mlx_texture_t *we_pic_data;
mlx_texture_t *ea_pic_data;
mlx_texture_t *door_pic_data;
t_sprite sprites;
int x_mouse;
int y_mouse;
int map_fd;
bool sprites_ready;
} t_cub;
typedef struct s_pinfo
{
int new_x;
int new_y;
int step;
double strafe_step;
int tmp_x;
int tmp_y;
int count;
double angle;
} t_pinfo;
typedef struct s_textinf
{
double x;
double y0;
double y1;
double wall_strip_height;
int pixels;
} t_tinfo;
typedef struct s_list
{
char *c;
struct s_list *next;
} t_list;
void ft_putstr_fd(char *s, int fd);
size_t ft_strcmp(char *s1, char *s2);
char *ft_substr(const char *s, unsigned int start, size_t len, t_cub *cub);
size_t ft_strlen(const char *s);
int parse_map_name(char *map_file, t_cub *cub);
char *ft_strdup(const char *s1, t_cub *cub);
char *ft_strjoin(char *s1, char *s2, t_cub *cub);
char *ft_strchr(const char *s, int c);
char *get_next_line(int fd, t_cub *cub);
void *ft_memcpy(void *dst, const void *src, size_t n);
int ft_iswspace(unsigned char c);
int ft_strncmp(const char *s1, const char *s2, size_t n);
size_t ft_strlcpy(char *dst, const char *src, size_t dstsize);
int element_type(char *line);
int fill_field(char *line, int type, t_cub *cub);
int empty_line(char *line);
int full_cub(t_cub *cub);
int ft_atoi(const char *str);
int ft_isdigit(int c);
int check_rgb(t_cub *cub);
void init_cub(t_cub *cub);
int fill_cub(t_cub *cub, int map_fd);
t_list *ft_lstnew(void *c, t_cub *cub);
void ft_lstadd_back(t_list **lst, t_list *new);
t_list *ft_lstlast(t_list *lst);
t_list *map_split(int map_fd, char *map_file, t_cub *cub);
int ft_lstsize(t_list *lst);
void gc_free(t_cub *data);
t_trash *gc_new(void *address, t_cub *data);
void gc_add(t_trash **head, t_trash *new);
void *gc_malloc(size_t size, t_cub *data);
void gc_free(t_cub *data);
void free_trash(t_trash *head);
void textures(t_cub *cube, double id, t_tinfo t_data,
mlx_texture_t *pic_data);
void player_update(t_cub *cub);
void my_keyhook(void *param);
int check_line(char *str);
int map_checker(t_list *map);
int map_check(t_cub *cub, char *map_file);
void put_map(t_cub *cub);
void put_frame(t_cub *cub);
double limit_angle(double angle);
double get_distance(double x1, double y1, double x2, double y2);
bool check_coordinates(double x, double y, t_cub *cub);
double closest_vertical_inter(t_cub *cub, double ray_angle, t_point *point);
double closest_horizontal_inter(t_cub *cub, double ray_angle, t_point *point);
void put_ceiling(t_cub *cub, int color);
void put_floor(t_cub *cub, int color);
void put_frame(t_cub *cub);
void ray_cast(t_cub *cub, double ray_angle,
double fov_in_rad, t_tinfo t_data);
void init_sprites(t_cub *cube);
void sprite(t_cub *cube, bool first, bool is_it_moving);
void doors(mlx_key_data_t key, void *param);
void replace_whitespace(char *line);
void transform_mtl(char *line, t_cub *cub, t_list **head);
void extend_line(t_list *node, size_t max, t_cub *cub);
int check_adjacent_x(t_list *head);
void replace_x_with_one(t_list *head);
t_list *map_to_list(int map_fd, t_cub *cub);
char **list_to_arr(t_list *head, t_cub *data);
void player_location(t_cub *cub);
int pre_check(char **string);
int rgb_range(int color);
t_rgb *rgb_new(unsigned char r,
unsigned char g, unsigned char b, t_cub *cub);
void mouse_hook(t_cub *cube);
void wasd_keyhook(t_cub *cub, int *is_moving);
void arrows_keyhook(t_cub *cub);
void initialize_step(double ray_angle, t_cub *cub,
double *step_x, double *step_y);
double process_intersections(t_cub *cub, double step_x,
double step_y, t_point *point);
void set_spawn_direction(t_cub *cub);
void change_map(t_cub *cub, char old, char new);
char **ft_split(char const *s, char c, t_cub *data);
int misplaced_space(char *input, t_cub *cub);
char *ft_strtrim(const char *s1, const char *set, t_cub *cub);
int is_all(char *string, int c);
t_list *process_map_lines(int map_fd, t_cub *cub, size_t *max);
void extend_all_lines(t_list *head, size_t max, t_cub *cub);
int validate_twos(t_list *head);
void terminate(void *cub);
void clear_textures(t_cub *cub);
int is_p(int c);
#endif