mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
sdf
This commit is contained in:
parent
02079dfa87
commit
0627a90bc4
5 changed files with 91 additions and 17 deletions
|
|
@ -22,6 +22,7 @@ typedef struct s_mapdata
|
|||
char *EA_texture;
|
||||
int f_color;
|
||||
int c_color;
|
||||
int mapheight;
|
||||
char **map;
|
||||
char **mapflood;
|
||||
bool isvalid;
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ EA ./path_to_the_east_texture
|
|||
F 220,100,0
|
||||
C 225,30,0
|
||||
|
||||
1111111111111111111111111
|
||||
1000000000110000000000001
|
||||
1011000001110000000000001
|
||||
1001000000000000000000001
|
||||
1111111111111111111111111
|
||||
1000000000110000000000001
|
||||
1011000001110000000000001
|
||||
1001000000000000000000001
|
||||
111111111011000001110000000000001
|
||||
100000000011000001110111111111111
|
||||
10000000001100000111011111D111111
|
||||
11110111111111011100000010001
|
||||
11110111111111011101010010001
|
||||
11000000110101011100000010001
|
||||
|
|
|
|||
|
|
@ -6,12 +6,13 @@
|
|||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */
|
||||
/* Updated: 2025/06/16 17:03:00 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/06/17 16:33:43 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/maputils.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "../../includes/libft.h"
|
||||
|
||||
|
|
@ -110,11 +111,10 @@ bool add_textures(int fd, t_mapdata *map)
|
|||
line = get_next_line(fd);
|
||||
}
|
||||
free(line);
|
||||
print_mapdata(map);
|
||||
return (true);
|
||||
}
|
||||
|
||||
bool check_filename(char *file)
|
||||
bool check_filename(t_mapdata *map, char *file)
|
||||
{
|
||||
int filename_size;
|
||||
int i;
|
||||
|
|
@ -133,17 +133,76 @@ bool check_filename(char *file)
|
|||
}
|
||||
if (ft_strncmp(end, ".cub", 5))
|
||||
return (false);
|
||||
else
|
||||
map->filename = ft_strdup(file);
|
||||
return (true);
|
||||
}
|
||||
|
||||
void free_tab(char **tab)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (tab[i])
|
||||
{
|
||||
free(tab[i]);
|
||||
i++;
|
||||
}
|
||||
free(tab);
|
||||
}
|
||||
|
||||
void get_map_height(t_mapdata *map)
|
||||
{
|
||||
int fd;
|
||||
char **splitted;
|
||||
char *line;
|
||||
int i;
|
||||
int count;
|
||||
|
||||
fd = open(map->filename, O_RDONLY);
|
||||
line = get_next_line(fd);
|
||||
splitted = ft_split(line, ' ');
|
||||
i = 0;
|
||||
count = 0;
|
||||
while (splitted[i] && splitted[i][0] != '1')
|
||||
{
|
||||
free_tab(splitted);
|
||||
free(line);
|
||||
line = get_next_line(fd);
|
||||
i++;
|
||||
splitted = ft_split(line, ' ');
|
||||
}
|
||||
free_tab(splitted);
|
||||
while (line)
|
||||
{
|
||||
free(line);
|
||||
count++;
|
||||
line = get_next_line(fd);
|
||||
}
|
||||
map->mapheight = count + 1;
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void populate_maps(t_mapdata *map, int fd)
|
||||
{
|
||||
char *line;
|
||||
int i;
|
||||
|
||||
get_map_height(map);
|
||||
ft_printf("%d\n", map->mapheight);
|
||||
map->map = malloc(sizeof(char *) * map->mapheight);
|
||||
if (!map->map)
|
||||
return ;
|
||||
map->mapflood = malloc(sizeof(char *) * map->mapheight);
|
||||
if (!map->mapflood)
|
||||
return ;
|
||||
line = get_next_line(fd);
|
||||
ft_printf("%s", line);
|
||||
i = 0;
|
||||
while (line)
|
||||
{
|
||||
map->map[i] = ft_strdup(line);
|
||||
map->mapflood[i] = ft_strdup(line);
|
||||
i++;
|
||||
free(line);
|
||||
line = get_next_line(fd);
|
||||
}
|
||||
|
|
@ -152,17 +211,28 @@ void populate_maps(t_mapdata *map, int fd)
|
|||
|
||||
bool check_walls(int fd, t_mapdata *map)
|
||||
{
|
||||
bool last_first;
|
||||
|
||||
populate_maps(map, fd);
|
||||
(void)fd;
|
||||
ft_printf("%d\n", map->mapheight);
|
||||
return (true);
|
||||
}
|
||||
|
||||
void print_map(char **map)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (map && map[i])
|
||||
{
|
||||
ft_printf("%s", map[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
bool check_cubfile(char *file, t_mapdata *map)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (!check_filename(file))
|
||||
if (!check_filename(map, file))
|
||||
return (ft_strlcpy(map->error, "File is not a .cub file", 25), false);
|
||||
fd = open(file, O_RDONLY);
|
||||
if (fd < 0)
|
||||
|
|
@ -172,9 +242,12 @@ bool check_cubfile(char *file, t_mapdata *map)
|
|||
"Map started before all the textures", 37), false);
|
||||
if (map->error[0])
|
||||
return (close(fd), false);
|
||||
if (!check_walls(fd, map))
|
||||
return (close(fd), ft_strlcpy(map->error,
|
||||
"Map is malformed (invalid chars or missing walls)", 51), false);
|
||||
close(fd);
|
||||
fd = open(file, O_RDONLY);
|
||||
populate_maps(map, fd);
|
||||
//if (!check_walls(fd, map))
|
||||
// return (close(fd), ft_strlcpy(map->error,
|
||||
// "Map is malformed (invalid chars or missing walls)", 51), false);
|
||||
print_map(map->map);
|
||||
return (true);
|
||||
}
|
||||
|
|
|
|||
BIN
vgcore.11143
Normal file
BIN
vgcore.11143
Normal file
Binary file not shown.
BIN
vgcore.83143
Normal file
BIN
vgcore.83143
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue