Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skunert #2

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SRCS = main.c ./srcs/map_check/file_type.c

OBJS = $(SRCS:.c=.o)

all: MLX42 $(NAME)
all: $(NAME)

$(NAME): $(OBJS)
@cd libft && make
Expand Down
28 changes: 20 additions & 8 deletions includes/cub3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
/* ::: :::::::: */
/* cub3d.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: njantsch <njantsch@student.42.fr> +#+ +:+ +#+ */
/* By: skunert <skunert@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/01 19:19:00 by skunert #+# #+# */
/* Updated: 2023/10/03 16:07:42 by njantsch ### ########.fr */
/* Updated: 2023/10/03 21:23:46 by skunert ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef CUB3D_H
# define CUB3D_H

#include "./libft/libs.h"
#include "./MLX42/include/MLX42/MLX42.h"
#include <stdio.h>
#include <math.h>
#include <fcntl.h>
# include "./libft/libs.h"
// #include "./MLX42/include/MLX42/MLX42.h"
# include <stdio.h>
# include <math.h>
# include <fcntl.h>
# include <stdbool.h>

typedef struct map
{
Expand All @@ -29,6 +30,17 @@ typedef struct map
char *texture_path_we;
} t_map;

int ft_check_file_type(char *str);
//parsing
int ft_check_file_type(char *str);
char **get_map(int map_fd);

//utils
t_map strct_init(char *file_path);

//parsing_utils.c
bool is_whitespace(char c);
int ft_matrixlen(char **matrix);
bool is_component(char c);
bool is_valid_border(char c);

#endif
1 change: 1 addition & 0 deletions maps/map.cub
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ NO ./path_to_the_north_texture
SO ./path_to_the_south_texture
WE ./path_to_the_west_texture
EA ./path_to_the_east_texture

F 220,100,0
C 225,30,0

Expand Down
4 changes: 2 additions & 2 deletions srcs/map_check/file_type.c → srcs/parsing/file_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* file_type.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: njantsch <njantsch@student.42.fr> +#+ +:+ +#+ */
/* By: skunert <skunert@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/02 13:23:13 by skunert #+# #+# */
/* Updated: 2023/10/03 15:16:21 by njantsch ### ########.fr */
/* Updated: 2023/10/03 18:07:59 by skunert ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
111 changes: 108 additions & 3 deletions srcs/parsing/map_parser.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,119 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parser.c :+: :+: :+: */
/* map_parser.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: njantsch <njantsch@student.42.fr> +#+ +:+ +#+ */
/* By: skunert <skunert@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 15:18:20 by njantsch #+# #+# */
/* Updated: 2023/10/03 15:19:01 by njantsch ### ########.fr */
/* Updated: 2023/10/03 21:26:58 by skunert ### ########.fr */
/* */
/* ************************************************************************** */

#include "../../includes/cub3d.h"

bool check_side_line(char **map, int index)
{
int i;

i = 0;
while(map[index][i])
{
if (!is_whitespace(map[index][i]))
if (map[index][i] != '1')
return (false);
i++;
}
return (true);
}

bool check_middle_lines(char **map)
{
int i;
int j;

i = 0;
j = 0;
while(map[i])
{
j = 0;
while (is_whitespace(map[i][j]))
j++;
if (map[i][j] != '1')
return (false);
if (map[i][ft_strlen(map[i]) - 1] != '1')
return (false);
i++;
}
return (true);
}

bool check_whitespace_border(char **map)
{
int i;
int j;

i = 0;
while (map[i])
{
j = 0;
while (map[i][j])
{
if (is_whitespace(map[i][j]))
{
if (!check_valid_border(map[i - 1][j]))
return (false);
if (!check_valid_border(map[i + 1][j]))
return (false);
if (!check_valid_border(map[i][j - 1]))
return (false);
if (!check_valid_border(map[i][j + 1]))
return (false);
}
j++;
}
i++;
}
return (true);
}

bool check_map(char **map)
{
if (check_side_line(map, 0) == false)
return (false);
if (check_side_line(map, ft_matrixlen(map) - 1) == false)
return (false);
if (check_middle_lines(map) == false)
return (false);
if (check_whitespace_border(map) == false)
return (false);
return (true);
}

char **get_map(int map_fd)
{
char *line;
char *buff;
char **map;

buff = ft_strdup("");
line = get_next_line(map_fd);
while (!ft_strncmp(buff, "\n", 1) && ft_strlen(buff) == 1)
{
free(line);
line = get_next_line(map_fd);
}
while (buff != NULL)
{
buff = ft_strjoin_free(buff, line);
if (buff == NULL
|| (!ft_strncmp(buff, "\n", 1) && ft_strlen(buff) == 1))
return (free(line), NULL);
free(line);
line = get_next_line(map_fd);
}
map = ft_split(buff, "\n");
if (map == NULL)
return (free(buff), NULL);
return (free(buff), map);
}
8 changes: 4 additions & 4 deletions srcs/utils/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: njantsch <njantsch@student.42.fr> +#+ +:+ +#+ */
/* By: skunert <skunert@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 15:24:52 by njantsch #+# #+# */
/* Updated: 2023/10/03 16:15:20 by njantsch ### ########.fr */
/* Updated: 2023/10/03 16:24:54 by skunert ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -18,8 +18,8 @@ t_map strct_init(char *file_path)

init.map_fd = open(file_path, O_RDONLY);
if (!init.map_fd)
return ()
return (init);
init.map = get_map(file_path);
init.texture_path_no = get_texture_path("NO")
init.texture_path_no = get_texture_path("NO");
return (init);
}
45 changes: 45 additions & 0 deletions srcs/utils/parsing_utils.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsing_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: skunert <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 18:27:36 by skunert #+# #+# */
/* Updated: 2023/10/03 21:23:41 by skunert ### ########.fr */
/* */
/* ************************************************************************** */

#include "../../includes/cub3d.h"

bool is_whitespace(char c)
{
if ((c >= 9 && c <= 13) || c == 32)
return (true);
return (false);
}

int ft_matrixlen(char **matrix)
{
int i;

i = 0;
while (matrix[i])
i++;
return (i);
}

bool is_component(char c)
{
if (c == '0' || c == '1')
return (true);
return (false);
}

bool is_valid_border(char c)
{
if (!is_whitespace(c))
if (c != '1')
return (false);
return (true);
}