Cub3D
Loading...
Searching...
No Matches
parse_tex_utils.c
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* parse_tex_utils.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/11/15 00:51:06 by kamitsui #+# #+# */
9/* Updated: 2024/12/29 19:54:47 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "cub3d.h"
14
15static int get_texture_image(
16 void *mlx, const char *first_word, t_texture *texture)
17{
18 const char *next_word;
19 char *file;
20
21 next_word = find_next_word(first_word);
22 if (next_word == NULL)
23 {
24 put_error_msg(first_word, EMSG_XPM_FILE);
25 return (EXIT_FAILURE);
26 }
27 file = strdup_trimmed_line(next_word);
28 if (file == NULL)
29 return (EXIT_FAILURE);
30 texture->img_tex.img = (void *)mlx_xpm_file_to_image(
31 mlx, file, &texture->width, &texture->height);
32 if (texture->img_tex.img == NULL)
33 {
34 ft_eprintf("%s%s: %s\n", ERR_PROMPT, EMSG_MLX_XPM_TO_IMG, file);
35 free(file);
36 return (EXIT_FAILURE);
37 }
38 free(file);
39 return (EXIT_SUCCESS);
40}
41 //debug_texture(file, *texture, "get_texture_image()");
42
43// Probably Unnessesary
48static void clear_flag_of_texture(t_parse *parse)
49{
50 int clear_flag;
51
52 clear_flag = ~(BIT_NORTH | BIT_WEST | BIT_EAST | BIT_SOUTH);
53 parse->flag = parse->flag & clear_flag;
54}
55
56int create_texture_image(const char *line, t_parse *parse, t_type_wall type)
57{
58 void *mlx;
59 t_texture *texture;
60
61 mlx = parse->game->mlx;
62 texture = parse->game->texture;
63 if (get_texture_image(mlx, line, &texture[type]) != EXIT_SUCCESS)
64 {
65 destroy_texture_image(mlx, texture, parse->flag);
66 clear_flag_of_texture(parse);
67 return (EXIT_FAILURE);
68 }
69 return (EXIT_SUCCESS);
70}
71// debug code
72// debug_tex_info(parse->game->debug.fd, parse->tex_info);
texture
Definition type_cub3d.h:94