diff --git a/README.md b/README.md index bdf9e2a..2387b8b 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,16 @@ CUBE3D ## Resources : - [Walls textures](https://opengameart.org/art-search-advanced?field_art_tags_tid=wall) - [Convert to xpm](https://convertio.co/) +- [Debug maps (Outdated?)](https://github.com/nsterk/cub3D/tree/main/maps) +- [Tester & maps](https://github.com/MichelleJiam/cub3D_tester) ## Program life cycle : - map parsing : - - [ ] read file, - - [ ] extract walls textures, - - [ ] extract sky and ceil colors - - [ ] import map into array, + - [o] read file, + - [o] extract walls textures, + - [o] extract sky and ceil colors + - [o] import map into chained list, + - [-] comvert list to 2D array. - [ ] save player pos, - [ ] handle errors, - initialize env diff --git a/maps/.DS_Store b/maps/.DS_Store new file mode 100644 index 0000000..6203e7a Binary files /dev/null and b/maps/.DS_Store differ diff --git a/maps/inv.cub b/maps/inv.cub deleted file mode 100644 index c68428f..0000000 --- a/maps/inv.cub +++ /dev/null @@ -1,11 +0,0 @@ -NO ./textures/brick.xpm -SO ./textures/blue.xpm -WE ./textures/wood.xpm -EA ./textures/grey.xpm - -F 100,0,100 -C 0,0,0 - -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 W 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 diff --git a/maps/inv2.cub b/maps/inv2.cub deleted file mode 100644 index efb15bb..0000000 --- a/maps/inv2.cub +++ /dev/null @@ -1,22 +0,0 @@ -NO ./textures/brick.xpm -SO ./textures/blue.xpm -WE ./textures/wood.xpm -EA ./textures/grey.xpm - -F 224,172,105 -C 205,249,255 - -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 1 1 0 0 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 -1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 W 0 1 0 0 0 0 1 -1 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 1 -1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 0 0 0 1 0 0 0 1 -1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 0 1 0 0 0 0 0 0 1 -1 1 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0 0 1 0 0 0 1 -1 1 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 1 1 0 1 1 1 1 0 0 0 1 -1 1 1 1 0 1 1 1 1 1 1 1 0 1 0 1 1 1 1 1 0 1 1 1 1 0 0 0 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 diff --git a/maps/map.cub b/maps/map.cub deleted file mode 100644 index e68fd73..0000000 --- a/maps/map.cub +++ /dev/null @@ -1,22 +0,0 @@ -NO ./textures/brick.xpm -SO ./textures/blue.xpm -WE ./textures/wood.xpm -EA ./textures/grey.xpm - -F 224,172,105 -C 205,249,255 - -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 -1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 W 0 0 1 0 0 0 1 -1 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 1 -1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 0 0 0 1 0 0 0 1 -1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 0 1 0 0 0 0 0 0 1 -1 1 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0 0 1 0 0 0 1 -1 1 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 1 1 0 1 1 1 1 0 0 0 1 -1 1 1 1 0 1 1 1 1 1 1 1 0 1 0 1 1 1 1 1 0 1 1 1 1 0 0 0 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 diff --git a/maps/scene.cub b/maps/scene.cub new file mode 100755 index 0000000..5269b0f --- /dev/null +++ b/maps/scene.cub @@ -0,0 +1,30 @@ +NO ./textures/wood.xpm +EA ./textures/colorstone.xpm +SO ./textures/wood.xpm +WE ./textures/wood.xpm + +F 147, 159, 153 +C 219, 213, 213 + + 1111 + 1001 + 1001 + 1001 +11111 11111 1001 +10001 1000111110011111111111 +10001 1000000000000000000001 +10001 1000000000000000000001 +10001 1000111101111111100001 +10001 10001 101 100001 +10001 10001 101111111100001 +10001111110001 100000000000001 +10000000000001 111110111100001 +10000000000001 10111100001 +10000E00000001 10000000001 +10000000002001 10000000001 +10111111111111 11111111111 +100000001 10000000001 +1111110011111111111110000000001 +1000000010001000000000000000011 +100000000000000000000000000001 +111111111111111111111111111111 \ No newline at end of file diff --git a/maps/simple.cub b/maps/simple.cub new file mode 100755 index 0000000..f2e65a2 --- /dev/null +++ b/maps/simple.cub @@ -0,0 +1,12 @@ +NO ./textures/redbrick.xpm +EA ./textures/colorstone.xpm +SO ./textures/redbrick.xpm +WE ./textures/redbrick.xpm + +F 147, 159, 153 +C 219, 213, 213 + +1111111 +100N001 +1000001 +1111111 \ No newline at end of file diff --git a/maps/sqr.cub b/maps/sqr.cub deleted file mode 100644 index cbd533a..0000000 --- a/maps/sqr.cub +++ /dev/null @@ -1,20 +0,0 @@ -NO ./textures/brick.xpm -SO ./textures/blue.xpm -WE ./textures/wood.xpm -EA ./textures/grey.xpm - -F 224,172,105 -C 205,249,255 - -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 N 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 diff --git a/sources/main.c b/sources/main.c index c884175..ac19092 100644 --- a/sources/main.c +++ b/sources/main.c @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/21 19:22:50 by narnaud #+# #+# */ -/* Updated: 2022/05/23 14:50:48 by narnaud ### ########.fr */ +/* Updated: 2022/05/23 16:54:20 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,42 +19,53 @@ void get_map_datas(t_env *env, char *line) int i; i = 0; - lst_e = malloc(sizeof(*lst_e)); - lst_e->next = NULL; - map_y = malloc(ft_strlen(line) * sizeof(char)); + map_y = malloc((ft_strlen(line)) * sizeof(char)); while (*line) { - if (!ft_isspace(*line)) - { + if (*line == '\n') + break ; + else if (!ft_isspace(*line)) map_y[i] = *line; - i++; - } + else + map_y[i] = '0'; line++; + i++; } map_y[i] = '\0'; env->deep++; - if (!env->raw_map) - env->raw_map = ft_slst_new(map_y); - else - { - lst_e->content = map_y; - ft_slst_add_back(&(env->raw_map), lst_e); - } + lst_e = malloc(sizeof(*lst_e)); + lst_e->next = NULL; + lst_e->content = map_y; + ft_slst_add_back(&(env->raw_map), lst_e); } -int rgb_to_int(char *rgb) +int rgb_to_int(char **rgb) { int ret; + int i; int c; char **colors; ret = 0; - colors = ft_split(rgb, ','); + rgb++; + colors = ft_split(*rgb, ','); c = 0; + i = 0; while (c < 3) { - ret |= ft_atoi(colors[c]) << (8 * (2 - c)); - c++; + if (colors[i]) + { + ret |= ft_atoi(colors[i]) << (8 * (2 - c)); + c++; + i++; + } + else + { + ft_free_split(colors); + rgb++; + i = 0; + colors = ft_split(*rgb, ','); + } } ft_free_split(colors); return (ret); @@ -64,23 +75,26 @@ void register_data(t_env *env, char *line) { char **elem; + if (*line && *line != '\n' && env->step > 5) + { + get_map_datas(env, line); + return ; + } elem = ft_split(line, ' '); if (!elem[0] || !elem[1]) return ; if (!ft_strncmp(elem[0],"NO", 3)) - env->wallTexture[0] = ft_strdup(elem[1]); + env->wallTexture[0] = ft_strtrim(elem[1], "\n"); else if (!ft_strncmp(elem[0],"SO", 3)) - env->wallTexture[1] = ft_strdup(elem[1]); + env->wallTexture[1] = ft_strtrim(elem[1], "\n"); else if (!ft_strncmp(elem[0],"WE", 3)) - env->wallTexture[2] = ft_strdup(elem[1]); + env->wallTexture[2] = ft_strtrim(elem[1], "\n"); else if (!ft_strncmp(elem[0],"EA", 3)) - env->wallTexture[3] = ft_strdup(elem[1]); + env->wallTexture[3] = ft_strtrim(elem[1], "\n"); else if (!ft_strncmp(elem[0],"F", 2)) - env->floorColor = rgb_to_int(elem[1]); + env->floorColor = rgb_to_int(elem); else if (!ft_strncmp(elem[0],"C", 2)) - env->ceilColor = rgb_to_int(elem[1]); - else if (env->step > 5) - get_map_datas(env, line); + env->ceilColor = rgb_to_int(elem); else env->step--; env->step++; @@ -101,14 +115,14 @@ t_env *parse_envFile(char *filename) line = get_next_line(fd); while (line) { - register_data(ret, line); printf("%s", line); + register_data(ret, line); free(line); line = get_next_line(fd); } - if (ret->step < 7) + if (ret->step < 6) return (NULL); - printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n"); + printf("\n*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n"); printf("%s\n", ret->wallTexture[0]); printf("%s\n", ret->wallTexture[1]); printf("%s\n", ret->wallTexture[2]); diff --git a/sources/utils/getline.c b/sources/utils/getline.c index d2957e6..c3f926e 100644 --- a/sources/utils/getline.c +++ b/sources/utils/getline.c @@ -20,10 +20,10 @@ char *save_buffer(char *buffer, int *i) part1 = ft_calloc(512, sizeof(char)); j = 0; - while (j < 512 && buffer[*i]) + while (j < 512) { part1[j++] = buffer[*i]; - if (buffer[(*i)++] == '\n') + if (buffer[*i] == '\0' || buffer[(*i)++] == '\n') return (part1); } part2 = save_buffer(buffer, i);