Cub3D
Loading...
Searching...
No Matches
parse_tex.c
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* parse_tex.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/11/15 00:43:41 by kamitsui #+# #+# */
9/* Updated: 2024/12/20 18:00:09 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "cub3d.h"
14
20static int get_texture_addr(t_texture *texture, t_type_wall type)
21{
22 t_img *img;
23
24 img = (t_img *)&texture[type].img_tex;
25 img->addr = (char *)mlx_get_data_addr(
26 img->img, &img->bpp, &img->line_length, &img->endian);
27 if (img->addr == NULL)
28 {
29 ft_eprintf("%s%s\n", ERR_PROMPT, EMSG_IMG_DATA_ADDR);
30 return (EXIT_FAILURE);
31 }
32 return (EXIT_SUCCESS);
33}
34 //debug_img_tex(texture[type].debug.fd, texture[type].img_tex, type,
35 // "after mlx_get_data_addr()");
36
42static t_type_wall get_type_of_wall(const char *line, const char *key[])
43{
44 t_type_wall type;
45
46 type = ENUM_NORTH;
47 while (type < ENUM_SOUTH)
48 {
49 if (is_key_line(line, key[type]) == true)
50 break ;
51 type++;
52 }
53 return (type);
54}
55
56int parse_tex(const char *line, t_parse *parse)
57{
58 void *mlx;
59 t_texture *texture;
60 t_type_wall type;
61 static const char *key[4] = {"NO ", "WE ", "EA ", "SO "};
62 static const int bit[4] = {BIT_NORTH, BIT_WEST, BIT_EAST, BIT_SOUTH};
63
64 mlx = parse->game->mlx;
65 texture = parse->game->texture;
66 type = get_type_of_wall(line, key);
67 if (check_duplicate_info(parse->flag, bit[type], line) != EXIT_SUCCESS)
68 return (EXIT_FAILURE);
69 if (create_texture_image(line, parse, type) != EXIT_SUCCESS)
70 return (EXIT_FAILURE);
71 if (get_texture_addr(texture, type) != EXIT_SUCCESS)
72 {
73 destroy_texture_image(mlx, texture, parse->flag);
74 return (EXIT_FAILURE);
75 }
76 parse->flag |= bit[type];
77 if (check_for_not_matching_bit(parse->flag,
78 BIT_NORTH | BIT_SOUTH | BIT_EAST | BIT_WEST) == 0x00)
79 parse->flag |= BIT_INIT_TEX;
80 return (EXIT_SUCCESS);
81}
3D or 2D or Texture image
Definition type_cub3d.h:82
texture
Definition type_cub3d.h:94