Browse Source

save map description without spaces

master
narnaud 3 years ago
parent
commit
54f8a17e01
  1. 2
      Makefile
  2. 4
      includes/cub3d.h
  3. 52
      sources/main.c

2
Makefile

@ -14,7 +14,7 @@ endif
ifeq ($(UNAME_S), Darwin)
LFLAGS = -lmlx -framework OpenGL -framework AppKit -L. -lft
endif
CFLAGS = -Werror -Wall -Wextra -O3 -ffast-math -funsafe-math-optimizations
CFLAGS = -Werror -Wall -Wextra -g -O3 -ffast-math -funsafe-math-optimizations
$(LIBFT):
#@git clone

4
includes/cub3d.h

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/21 19:24:12 by narnaud #+# #+# */
/* Updated: 2022/05/23 13:05:28 by narnaud ### ########.fr */
/* Updated: 2022/05/23 14:44:49 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -52,6 +52,8 @@ typedef struct s_env
char *wallTexture[4];
int floorColor;
int ceilColor;
t_slist *raw_map;
int deep;
t_map *map;
} t_env;

52
sources/main.c

@ -6,17 +6,42 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/21 19:22:50 by narnaud #+# #+# */
/* Updated: 2022/05/23 13:35:12 by narnaud ### ########.fr */
/* Updated: 2022/05/23 14:50:48 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/cub3d.h"
/*
void get_map_datas(t_env *env, char **elem);
void get_map_datas(t_env *env, char *line)
{
return ;
t_slist *lst_e;
char *map_y;
int i;
i = 0;
lst_e = malloc(sizeof(*lst_e));
lst_e->next = NULL;
map_y = malloc(ft_strlen(line) * sizeof(char));
while (*line)
{
if (!ft_isspace(*line))
{
map_y[i] = *line;
i++;
}
line++;
}
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);
}
}
*/
int rgb_to_int(char *rgb)
{
int ret;
@ -54,8 +79,8 @@ void register_data(t_env *env, char *line)
env->floorColor = rgb_to_int(elem[1]);
else if (!ft_strncmp(elem[0],"C", 2))
env->ceilColor = rgb_to_int(elem[1]);
//else if (env->step > 6)
// get_map_datas(env, elem);
else if (env->step > 5)
get_map_datas(env, line);
else
env->step--;
env->step++;
@ -67,8 +92,11 @@ t_env *parse_envFile(char *filename)
int fd;
char *line;
t_env *ret;
int y;
t_slist *raw_map;
ret = malloc(sizeof(t_env));
ret->deep = 0;
fd = open(filename, O_RDONLY);
line = get_next_line(fd);
while (line)
@ -78,7 +106,7 @@ t_env *parse_envFile(char *filename)
free(line);
line = get_next_line(fd);
}
if (ret->step < 6)
if (ret->step < 7)
return (NULL);
printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
printf("%s\n", ret->wallTexture[0]);
@ -87,6 +115,14 @@ t_env *parse_envFile(char *filename)
printf("%s\n", ret->wallTexture[3]);
printf("%d\n", ret->floorColor);
printf("%d\n", ret->ceilColor);
y = 0;
raw_map = ret->raw_map;
while (y < ret->deep)
{
printf("%s\n", (char *)raw_map->content);
y++;
raw_map = raw_map->next;
}
return (ret);
}

Loading…
Cancel
Save