-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jean Teissier
authored and
Jean Teissier
committed
Aug 16, 2024
1 parent
f5fc8f6
commit 7d76685
Showing
8 changed files
with
144 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
# By: jteissie <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2024/08/15 12:02:08 by tsuchen #+# #+# # | ||
# Updated: 2024/08/16 16:57:12 by jteissie ### ########.fr # | ||
# Updated: 2024/08/16 18:59:41 by jteissie ### ########.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
|
@@ -15,7 +15,8 @@ NAME = cub3d | |
SRCS_M = main.c | ||
|
||
SRCS_PS = parser.c \ | ||
build_map.c | ||
build_map.c \ | ||
parser_utils.c | ||
|
||
SRCS_MAP = map.c | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: jteissie <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/15 00:19:44 by tsuchen #+# #+# */ | ||
/* Updated: 2024/08/16 16:47:40 by jteissie ### ########.fr */ | ||
/* Updated: 2024/08/16 18:45:38 by jteissie ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -54,10 +54,10 @@ typedef enum e_bool | |
|
||
typedef enum e_p_dir | ||
{ | ||
NORTH, | ||
SOUTH, | ||
WEST, | ||
EAST, | ||
NORTH = 'N', | ||
SOUTH = 'S', | ||
WEST = 'W', | ||
EAST = 'E', | ||
} t_p_dir; | ||
typedef struct s_data | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,16 +6,16 @@ | |
/* By: jteissie <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/15 15:00:57 by jteissie #+# #+# */ | ||
/* Updated: 2024/08/16 16:46:40 by jteissie ### ########.fr */ | ||
/* Updated: 2024/08/16 18:58:41 by jteissie ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef PARSER_H | ||
# define PARSER_H | ||
# include "cub3d.h" | ||
|
||
typedef enum e_bool t_bool; | ||
typedef struct s_data t_data; | ||
typedef enum e_bool t_bool; | ||
typedef struct s_data t_data; | ||
|
||
typedef enum e_parse_status | ||
{ | ||
|
@@ -24,6 +24,10 @@ typedef enum e_parse_status | |
PANIC_ERR, | ||
} t_parse_status; | ||
|
||
int parse_map(t_data *data); | ||
|
||
int parse_map(t_data *data); | ||
char **build_map(t_data *data); | ||
t_bool is_invalid_char(char c); | ||
t_parse_status check_invalid_chars(char **map); | ||
void fill_whitespaces(char **map); | ||
t_parse_status find_start(uint32_t coordinates[], char **map); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,10 @@ | |
/* By: jteissie <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/05/25 14:11:27 by jteissie #+# #+# */ | ||
/* Updated: 2024/08/16 14:49:53 by jteissie ### ########.fr */ | ||
/* Updated: 2024/08/16 18:20:02 by jteissie ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
||
#ifndef GET_NEXT_LINE_BONUS_H | ||
# define GET_NEXT_LINE_BONUS_H | ||
# ifndef BUFFER_SIZE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,19 +6,20 @@ | |
/* By: jteissie <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/15 12:03:33 by tsuchen #+# #+# */ | ||
/* Updated: 2024/08/16 16:51:16 by jteissie ### ########.fr */ | ||
/* Updated: 2024/08/16 18:20:24 by jteissie ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "cub3d.h" | ||
|
||
//check for file extension (.cub); | ||
|
||
int main(int ac, char *av[]) | ||
{ | ||
t_data data; | ||
|
||
if (ac < 2 || ac > 2) | ||
return (EXIT_FAILURE); | ||
//check for file extension (.cub); | ||
ft_memset(&data, 0, sizeof(t_data)); | ||
data.map_path = av[1]; | ||
data.map_fd = open(av[1], O_RDONLY); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: jteissie <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/16 16:51:48 by jteissie #+# #+# */ | ||
/* Updated: 2024/08/16 16:55:45 by jteissie ### ########.fr */ | ||
/* Updated: 2024/08/16 18:31:34 by jteissie ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -48,7 +48,7 @@ static size_t get_map_size(char *path) | |
return (line_nb); | ||
} | ||
|
||
static char **read_map_file(size_t size, char *line, t_data *data) | ||
static char **read_map_file(size_t size, char *line, t_data *data) | ||
{ | ||
size_t index; | ||
char **map; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,113 +6,12 @@ | |
/* By: jteissie <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/15 12:12:00 by tsuchen #+# #+# */ | ||
/* Updated: 2024/08/16 16:58:07 by jteissie ### ########.fr */ | ||
/* Updated: 2024/08/16 18:49:30 by jteissie ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "cub3d.h" | ||
|
||
static t_parse_status find_start(uint32_t coordinates[], char **map) | ||
{ | ||
uint32_t x; | ||
uint32_t y; | ||
|
||
x = 0; | ||
y = 0; | ||
coordinates[0] = 0; | ||
coordinates[1] = 0; | ||
while (map[x]) | ||
{ | ||
while (map[x][y]) | ||
{ | ||
if (map[x][y] == 'N' || map[x][y] == 'S' || map[x][y] == 'W' || map[x][y] == 'E') //enums please | ||
{ | ||
if (coordinates[0] != 0 || coordinates[1] != 0) | ||
return (MAP_ERR); | ||
coordinates[0] = x; | ||
coordinates[1] = y; | ||
} | ||
y++; | ||
} | ||
y = 0; | ||
x++; | ||
} | ||
if (coordinates[0] == 0 && (map[0][0] == '0' || map[0][0] == '1')) | ||
return (MAP_ERR); | ||
return (MAP_OK); | ||
} | ||
|
||
t_bool is_invalid_char(char c) | ||
{ | ||
if (c == '1' || c == '0') | ||
return (FALSE); | ||
else if (c == ' ' || c == '\n') | ||
return (FALSE); | ||
else if (c == 'N' || c == 'S' || c == 'W' || c == 'E') | ||
return (FALSE); | ||
return (TRUE); | ||
} | ||
|
||
t_parse_status check_invalid_chars(char **map) | ||
{ | ||
uint32_t x; | ||
uint32_t y; | ||
|
||
x = 0; | ||
y = 0; | ||
while (map[x]) | ||
{ | ||
while (map[x][y]) | ||
{ | ||
if (is_invalid_char(map[x][y]) == TRUE) | ||
return (MAP_ERR); | ||
y++; | ||
} | ||
x++; | ||
y = 0; | ||
} | ||
return (MAP_OK); | ||
} | ||
|
||
void fill_whitespaces(char **map) | ||
{ | ||
uint32_t x; | ||
uint32_t y; | ||
|
||
x = 0; | ||
y = 0; | ||
while (map[x]) | ||
{ | ||
while (map[x][y]) | ||
{ | ||
if (map[x][y] == ' ') | ||
map[x][y] = '1'; | ||
y++; | ||
} | ||
y = 0; | ||
x++; | ||
} | ||
} | ||
|
||
// static void print_map(char **map) | ||
// { | ||
// int x; | ||
// int y; | ||
|
||
// x = 0; | ||
// y = 0; | ||
// while (map[x]) | ||
// { | ||
// while (map[x][y]) | ||
// { | ||
// ft_putchar_fd(map[x][y], STDOUT_FILENO); | ||
// y++; | ||
// } | ||
// y = 0; | ||
// x++; | ||
// } | ||
// } | ||
|
||
t_parse_status check_walls(char **map, uint32_t x, uint32_t y, size_t bound) | ||
{ | ||
if (map[x][y] == 'F') | ||
|
@@ -153,6 +52,8 @@ t_parse_status verify_map(char **map, t_data *data) | |
{ | ||
uint32_t start[2]; | ||
|
||
start[0] = 0; | ||
start[1] = 0; | ||
if (check_invalid_chars(map) == MAP_ERR) | ||
return (MAP_ERR); | ||
get_player_dir(data, start[0], start[1]); | ||
|
@@ -171,7 +72,7 @@ int parse_map(t_data *data) | |
return (PANIC); | ||
if (verify_map(data->map, data) == MAP_ERR) | ||
{ | ||
ft_putstr_fd("Error, implement custom messages here (parse_map)\n", STDERR_FILENO); | ||
ft_putstr_fd("Error\n", STDERR_FILENO); | ||
return (ft_free_all(data->map), PANIC); | ||
} | ||
return (SUCCESS); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* parser_utils.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: jteissie <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/16 18:12:37 by jteissie #+# #+# */ | ||
/* Updated: 2024/08/16 18:46:27 by jteissie ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "parser.h" | ||
|
||
t_bool is_invalid_char(char c) | ||
{ | ||
if (c == '1' || c == '0') | ||
return (FALSE); | ||
else if (c == ' ' || c == '\n') | ||
return (FALSE); | ||
else if (c == 'N' || c == 'S' || c == 'W' || c == 'E') | ||
return (FALSE); | ||
return (TRUE); | ||
} | ||
|
||
t_parse_status check_invalid_chars(char **map) | ||
{ | ||
uint32_t x; | ||
uint32_t y; | ||
|
||
x = 0; | ||
y = 0; | ||
while (map[x]) | ||
{ | ||
while (map[x][y]) | ||
{ | ||
if (is_invalid_char(map[x][y]) == TRUE) | ||
return (MAP_ERR); | ||
y++; | ||
} | ||
x++; | ||
y = 0; | ||
} | ||
return (MAP_OK); | ||
} | ||
|
||
void fill_whitespaces(char **map) | ||
{ | ||
uint32_t x; | ||
uint32_t y; | ||
|
||
x = 0; | ||
y = 0; | ||
while (map[x]) | ||
{ | ||
while (map[x][y]) | ||
{ | ||
if (map[x][y] == ' ') | ||
map[x][y] = '1'; | ||
y++; | ||
} | ||
y = 0; | ||
x++; | ||
} | ||
} | ||
|
||
static uint32_t is_cardinal_pos(char c) | ||
{ | ||
return (c == NORTH || c == SOUTH || c == WEST || c == EAST); | ||
} | ||
|
||
t_parse_status find_start(uint32_t coordinates[], char **map) | ||
{ | ||
uint32_t x; | ||
uint32_t y; | ||
|
||
x = 0; | ||
y = 0; | ||
while (map[x]) | ||
{ | ||
while (map[x][y]) | ||
{ | ||
if (is_cardinal_pos(map[x][y])) | ||
{ | ||
if (coordinates[0] != 0 || coordinates[1] != 0) | ||
return (MAP_ERR); | ||
coordinates[0] = x; | ||
coordinates[1] = y; | ||
} | ||
y++; | ||
} | ||
y = 0; | ||
x++; | ||
} | ||
if (coordinates[0] == 0 && (!is_cardinal_pos(map[0][0]))) | ||
return (MAP_ERR); | ||
return (MAP_OK); | ||
} | ||
|
||
// static void print_map(char **map) | ||
// { | ||
// int x; | ||
// int y; | ||
|
||
// x = 0; | ||
// y = 0; | ||
// while (map[x]) | ||
// { | ||
// while (map[x][y]) | ||
// { | ||
// ft_putchar_fd(map[x][y], STDOUT_FILENO); | ||
// y++; | ||
// } | ||
// y = 0; | ||
// x++; | ||
// } | ||
// } |