Cub3D
Loading...
Searching...
No Matches
type_cub3d.h
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* type_cub3d.h :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/09/03 16:30:31 by kamitsui #+# #+# */
9/* Updated: 2024/12/14 18:48:10 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#ifndef TYPE_CUB3D_H
14# define TYPE_CUB3D_H
15
16/******************** draw_line *********************************/
17
18typedef struct s_clr
19{
20 int start_r;
21 int start_g;
22 int start_b;
23 int end_r;
24 int end_g;
25 int end_b;
26} t_clr;
27
28typedef struct s_plot {
29 int px;
30 int py;
31 int pc;
32 int dx;
33 int dy;
34 int sx;
35 int sy;
36 int err;
37 int err2;
38} t_plot;
39
40typedef struct s_line {
41 int x_start;
42 int y_start;
43 int color_start;
44 int x_end;
45 int y_end;
46 int color_end;
47} t_line;
48
49/******************** common *********************************/
50
51typedef struct s_game t_game;
55typedef struct s_debug {
56 int fd;
57 t_game *game;
58} t_debug;
59
60/*
61 * @brief cordinate of point (int x, int y)
62 *
63 * @note :
64 * map screen
65 */
66typedef struct s_point {
67 int x;
68 int y;
69} t_point;
70
74typedef struct s_vector {
75 double x;
76 double y;
77} t_vector;
78
82typedef struct s_img {
83 void *img;
84 char *addr;
85 int bpp;
86 int line_length;
87 int endian;
88 t_debug debug;
89} t_img;
90
94typedef struct s_texture {
95 t_img img_tex;
96 int width;
97 int height;
98 t_debug debug;
99} t_texture;
100// texture[0] ... texture[NORTH]
101// texture[1] ... texture[WEST]
102// texture[2] ... texture[EAST]
103// texture[3] ... texture[SOUTH]
104
105/******************** parse *********************************/
106
107typedef enum e_type_wall {
108 ENUM_NORTH,
109 ENUM_WEST,
110 ENUM_EAST,
111 ENUM_SOUTH
112} t_type_wall;
113
114typedef enum e_enum_fc {
115 ENUM_F,
116 ENUM_C
117} t_type_fc;
118
119typedef enum e_enum_rgb {
120 ENUM_R,
121 ENUM_G,
122 ENUM_B
123} t_type_rgb;
124
125typedef struct s_result {
126 int value;
127 const char *err_msg;
128} t_result;
129
130typedef struct s_info {
131 const char **key;
132 const int *bit;
133} t_info;
134
135typedef struct s_parse {
136 int flag;
137 t_info fc_info;
138 t_info tex_info;
139 t_point player_grid;
140 t_game *game;
141} t_parse;
142
143typedef enum e_enum_elem {
144 ENUM_TEX,
145 ENUM_FC,
146 ENUM_MAP,
147 ENUM_ELEMENT_ERR
148} t_type_elem;
149
150typedef struct s_map_size {
151 size_t rows;
152 size_t cols;
153} t_map_size;
154
155typedef struct s_stack {
156 t_point *data;
157 int top;
158 int capacity;
159} t_stack;
160
161typedef enum e_bool {
162 ENUM_ERROR = -1,
163 ENUM_FALSE = 0,
164 ENUM_TRUE = 1
165} t_bool;
166
167/******************** raycasting *********************************/
168
169/*
170 * @brief raycasting
171 */
172typedef struct s_ray_cast {
173 double camera_plane_x;
174 t_vector ray_dir;
175 t_point grid;
176 t_point step_dir;
177 t_vector next_distance;
178 t_vector delta_distance;
179} t_ray_cast;
180
181typedef struct s_dda {
182 int type_of_grid_line;
183 double perp_wall_dist;
184 int tex_x;
185 t_texture texture;
186} t_dda;
187
191typedef struct s_wall_slice {
192 int line_height;
193 int draw_start;
194 int draw_end;
195 int color;
197
198typedef enum e_enum_key {
199 ENUM_ESC,
200 ENUM_W,
201 ENUM_S,
202 ENUM_A,
203 ENUM_D,
204 ENUM_LEFT,
205 ENUM_RIGHT,
206 ENUM_OTHER
207} t_enum_key;
208
212//typedef struct s_keys {
213// int move_forward;
214// int move_backward;
215// int strafe_left;
216// int strafe_right;
217// int rotate_left;
218// int rotate_right;
219//} t_keys;
220
221/******************** main stracture *********************************/
222
223/*
224 * @brief ray vector
225 */
226typedef struct s_player {
227 t_vector view_point;
228 t_vector ray_dir;
229 t_vector camera_forcal_plane;
230 double move_speed;
231 double rotate_speed;
232} t_player;
233
237typedef struct s_map {
238 int width;
239 int height;
240 char **data;
241 t_debug debug;
242} t_map;
243
247typedef struct s_frame {
248 t_ray_cast ray_cast;
249 t_dda dda;
250 t_wall_slice wall_slice;
251 t_player *player;
252 int flag;
253 t_map *map;
254 t_texture *texture;
255 int *ceiling_color;
256 int *floor_color;
257 t_img *img_3d;
258 t_debug debug;
259} t_frame;
260
264typedef struct s_game {
265 void *mlx;
266 void *win;
267 t_img img_3d;
268 t_img img_2d;
269 t_map map;
270 int floor_color;
271 int ceiling_color;
272 t_player player;
273 t_texture texture[4];
274 t_frame frame;
275 t_debug debug;
276} t_game;
277
278#endif
debug info
Definition type_cub3d.h:55
single still image for render_frame
Definition type_cub3d.h:247
main game
Definition type_cub3d.h:264
3D or 2D or Texture image
Definition type_cub3d.h:82
game map
Definition type_cub3d.h:237
keyboard event flag
Definition type_cub3d.h:226
texture
Definition type_cub3d.h:94
vector
Definition type_cub3d.h:74
wall slice
Definition type_cub3d.h:191