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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/15 06:40:37 by cacharle #+# #+# */
/* Updated: 2020/01/11 10:24:44 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#ifndef CUB3D_H
# define CUB3D_H
# include <unistd.h>
# include <fcntl.h>
# include <stdlib.h>
# include <math.h>
# include "mlx.h"
# include "libft.h"
# define WINDOW_TITLE "cub3D"
# define MLXK_ESC 53
# define MLXK_W 13
# define MLXK_A 0
# define MLXK_S 1
# define MLXK_D 2
# define MLXK_LEFT 123
# define MLXK_RIGHT 124
# define MLX_LITTLE_ENDIAN 0
# define MLX_BIG_ENDIAN 1
# define TRUE 1
# define FALSE 0
# define SQUARE(x) ((x) * (x))
typedef int t_bool;
typedef struct
{
double x;
double y;
} t_vector;
typedef union
{
unsigned int hexcode;
struct
{
t_byte r;
t_byte g;
t_byte b;
t_byte alpha;
} rgb;
} t_color;
typedef enum
{
CELL_EMPTY = 1 << 1,
CELL_WALL = 1 << 2,
CELL_ITEM = 1 << 3,
CELL_LOOK_NORTH = 1 << 4,
CELL_LOOK_SOUTH = 1 << 5,
CELL_LOOK_WEST = 1 << 6,
CELL_LOOK_EAST = 1 << 7
} t_cell;
typedef t_cell** t_map;
enum
{
TEX_NORTH,
TEX_SOUTH,
TEX_WEST,
TEX_EAST,
TEX_SPRITE
};
# define TEXTURES_NUM (TEX_SPRITE - TEX_NORTH + 1)
typedef struct
{
int width;
int height;
void *id;
char *data;
int depth;
int size_line;
int endian;
} t_image;
typedef struct s_state
{
t_bool running;
void *mlx_ptr;
void *window_ptr;
int window_width;
int window_height;
t_vector pos;
t_vector dir;
t_vector plane;
t_map map;
int map_width;
int map_height;
t_color ceilling_color;
t_color floor_color;
t_image window;
char *textures_path[TEXTURES_NUM];
t_image textures[TEXTURES_NUM];
} t_state;
typedef t_bool (*t_option_parser_func)(t_state *state, char *line);
typedef struct s_option_parser
{
char *id;
t_option_parser_func func;
} t_option_parser;
typedef enum
{
SIDE_NORTH_SOUTH,
SIDE_WEST_EAST
} t_side;
/*
** parse/parse.c
*/
t_state *parse(char *filename);
char **get_file_lines(char *filename);
t_bool parse_line(t_state *state, char *line);
t_state *parse_map(t_state *state, char **lines);
t_cell *create_map_row(char *line);
/*
** parse/parse_resolution.c
*/
t_bool parse_resolution(t_state *state, char *line);
/*
** parse/parse_textures.c
*/
t_bool parse_north_texture(t_state *state, char *line);
t_bool parse_south_texture(t_state *state, char *line);
t_bool parse_west_texture(t_state *state, char *line);
t_bool parse_east_texture(t_state *state, char *line);
t_bool parse_sprite_texture(t_state *state, char *line);
/*
** parse/parse_color.c
*/
t_bool parse_floor_color(t_state *state, char *line);
t_bool parse_ceilling_color(t_state *state, char *line);
/*
** event.c
*/
int event_keydown(int key, void *param);
/*
** state.c
*/
t_state *state_new(t_state *state);
void state_init_player(t_state *state);
t_state *state_new_empty(void);
void *state_destroy(t_state *state);
void load_texture(void *mlx_ptr, t_image *image, char *path);
/*
** render.c
*/
int render_update(void *param);
void render_column(t_state *state, int x);
/*
** vector.c
*/
t_vector vector_add(t_vector a, t_vector b);
t_vector vector_scale(t_vector v, double scalar);
t_vector vector_rotate(t_vector v, double angle);
double vector_norm(t_vector v);
/*
** error.c
*/
void error_put_usage_exit(char *name);
/*
** helper.c
*/
t_bool helper_is_player_cell(t_cell cell);
void helper_free_splited(char **splited);
#endif
|