Cub3D
Loading...
Searching...
No Matches
parse_map.c
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* parse_map.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: hnagasak <hnagasak@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/09/12 10:31:30 by kamitsui #+# #+# */
9/* Updated: 2024/12/20 17:59:28 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "cub3d.h"
14
15static void put_error_map_size_over(int cols, int rows)
16{
17 ft_eprintf("%s%s: ", ERR_PROMPT, EMSG_MAP_TOO_LARGE);
18 ft_eprintf("%d x %d", cols, rows);
19 ft_eprintf(" (within %d x %d)\n", MAX_COLS, MAX_ROWS);
20}
21
22int check_range_map(const char *line, t_parse *parse)
23{
24 size_t rows;
25 size_t cols;
26 size_t len;
27 bool is_over_size;
28
29 is_over_size = false;
30 rows = 0;
31 cols = 0;
32 while (line != NULL && ft_strchr(line, '\n') != NULL)
33 {
34 len = ft_strchr(line, '\n') - line;
35 if (cols < len)
36 cols = len;
37 rows++;
38 if (cols > MAX_COLS || rows > MAX_ROWS)
39 is_over_size = true;
40 line = find_next_line(line);
41 }
42 if (is_over_size == true)
43 {
44 put_error_map_size_over((int)cols, (int)rows);
45 return (EXIT_FAILURE);
46 }
47 (void)parse;
48 return (EXIT_SUCCESS);
49}
50
51int parse_map(const char *line, t_parse *parse)
52{
53 static t_parse_map func[5] = {
54 check_last_map, check_range_map, get_map_data,
55 get_player_info, check_enclosed_by_walls};
56 int i;
57 int status;
58
59 i = 0;
60 while (i < 5)
61 {
62 status = func[i](line, parse);
63 if (status != EXIT_SUCCESS)
64 return (EXIT_FAILURE);
65 i++;
66 }
67 parse->flag |= BIT_MAP;
68 return (EXIT_SUCCESS);
69}
70 //status = func[i](line, parse);
71 //if (status != EXIT_SUCCESS)
72 //{
73 // debug_parse_map_fail(parse->game->debug.fd, i);
74 // return (EXIT_FAILURE);
75 //}