add verification texture file

This commit is contained in:
kinou-p 2022-06-15 14:24:45 +02:00
parent efed7db4a9
commit cda81e1fd9
9 changed files with 79 additions and 90 deletions

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/09 19:58:04 by apommier #+# #+# */
/* Updated: 2022/01/17 11:28:39 by apommier ### ########.fr */
/* Updated: 2022/06/15 13:14:54 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,7 +20,7 @@ void ft_lstclear(t_list **lst, void (*del)(void*))
while (*lst)
{
chr = (*lst)->next;
del((*lst)->nbr);
del((*lst)->content);
free(*lst);
*lst = chr;
}

View File

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/09 19:54:40 by apommier #+# #+# */
/* Updated: 2020/12/12 09:10:11 by apommier ### ########.fr */
/* Updated: 2022/06/15 13:15:15 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,6 +16,6 @@ void ft_lstdelone(t_list *lst, void (*del)(void*))
{
if (!lst)
return ;
del(lst->nbr);
del(lst->content);
free(lst);
}

View File

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/09 20:14:47 by apommier #+# #+# */
/* Updated: 2020/12/11 17:47:39 by apommier ### ########.fr */
/* Updated: 2022/06/15 13:15:24 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,7 +16,7 @@ void ft_lstiter(t_list *lst, void (*f)(void *))
{
while (lst)
{
f(lst->nbr);
f(lst->content);
lst = lst->next;
}
}

View File

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/11 00:10:12 by apommier #+# #+# */
/* Updated: 2020/12/13 22:37:30 by apommier ### ########.fr */
/* Updated: 2022/06/15 13:15:33 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,7 +20,7 @@ t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
begin = 0;
while (lst)
{
new = ft_lstnew(f(lst->nbr));
new = ft_lstnew(f(lst->content));
if (!new)
{
ft_lstclear(&begin, *del);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/09 01:06:20 by apommier #+# #+# */
/* Updated: 2022/01/17 11:29:09 by apommier ### ########.fr */
/* Updated: 2022/06/15 13:15:45 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,8 +19,7 @@ t_list *ft_lstnew(void *content)
new = (t_list *)malloc(sizeof(t_list));
if (!new)
return (0);
new->swap = 0;
new->nbr = content;
new->content = content;
new->next = 0;
return (new);
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/11 03:21:27 by apommier #+# #+# */
/* Updated: 2022/05/06 19:29:58 by apommier ### ########.fr */
/* Updated: 2022/06/15 13:14:31 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,8 +19,7 @@
typedef struct t_slist
{
void *nbr;
int index;
void *content;
int swap;
struct t_slist *next;
} t_list;

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/06 16:10:11 by apommier #+# #+# */
/* Updated: 2022/06/15 00:34:01 by apommier ### ########.fr */
/* Updated: 2022/06/15 14:23:32 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -40,6 +40,25 @@ void put_texture_in_struct(char type, unsigned char *texture, t_data *img)
}
}
int verify_texture()
{
}
int is_nbr(char *str)
{
int i;
i = 0;
while (str[i])
{
if (!ft_isdigit(str[i]))
return (0);
i++;
}
return (1);
}
unsigned char *get_texture(char type, char *path, t_data *img)//change in list
{
int fd;
@ -47,19 +66,20 @@ unsigned char *get_texture(char type, char *path, t_data *img)//change in list
int count;
char *swap = 0;
if (!path)
{
//printf("no path\n");
path = ft_strjoin("./sprite/brick_wall.ppm", 0);
}
(void)type;
count = 0;
if (!path)
return(0);
fd = open(path, O_DIRECTORY);
if (fd >= 0)
{
close(fd);
ft_exit("Error\nTexture path is a directory\n");
}
fd = open(path, O_RDONLY);
if (fd == -1)
{
printf("path= %s\n", path);
ft_exit("Error\nBad texture file prout");
}
quit_game(img);
img->to_be_free.fd_one = fd;
while (swap || !count)
{
if (swap)
@ -68,26 +88,44 @@ unsigned char *get_texture(char type, char *path, t_data *img)//change in list
swap = get_next_line(fd);
}
close(fd);
img->to_be_free.fd_one = -1;
printf("count= %d\n", count);
if (count != 12291)
ft_exit("Error\n Bad texture file\n");
ret = ft_calloc(sizeof(char), count);
fd = open(path, O_RDONLY);
if (!ret)
return (0);
quit_game(img);
fd = open(path, O_RDONLY);
if (fd == -1)
ft_exit("Error\nBad texture file");
img->to_be_free.fd_one = fd;
count = 0;
while (swap || !count)
{
if (swap)
free(swap);
swap = get_next_line(fd);
//printf("str = -%s-\n", swap);
if (!count)
{
free(swap);
swap = get_next_line(fd);
}
if (swap)
swap[ft_strlen(swap) - 1] = 0;
if ((swap && is_nbr(swap) && ft_strlen(swap) <= 3 && ft_atoi(swap) <= 255 && ft_atoi(swap) >= 0) || !count)
ret[count] = (unsigned char)ft_atoi(swap);
else if (swap)
{
//printf("isnbr= %d swap= %s ft_atoi(swap)= ---%ld--- strlen= %ld\n",is_nbr(swap) ,swap , ft_atoi(swap), ft_strlen(swap) );
free(ret);
ft_exit("Error\nBad texture file\n");
}
count++;
}
close(fd);
img->to_be_free.fd_one = -1;
put_texture_in_struct(type, ret, img);
return (ret);
}
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/11 01:00:17 by apommier #+# #+# */
/* Updated: 2022/06/15 01:04:34 by apommier ### ########.fr */
/* Updated: 2022/06/15 12:40:19 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -115,7 +115,7 @@ void check_value(char **tab)
}
}
void set_color_utils(char **tab, color *img)
void set_color_utils(char **tab, color *rgb)
{
if (ft_strlen(tab[0]) > 3 || !(ft_atoi(tab[0]) >= 0 && ft_atoi(tab[0]) <= 255))
ft_exit("Error\nBad syntax in map file (RGB)\n");
@ -124,9 +124,10 @@ void set_color_utils(char **tab, color *img)
if (ft_strlen(tab[0]) > 3 || !(ft_atoi(tab[2]) >= 0 && ft_atoi(tab[2]) <= 255))
ft_exit("Error\nBad syntax in map file (RGB)\n");
check_value(tab);
img->r = (unsigned char)ft_atoi(tab[0]);
img->g = (unsigned char)ft_atoi(tab[1]);
img->b = (unsigned char)ft_atoi(tab[2]);
rgb->r = (unsigned char)ft_atoi(tab[0]);
rgb->g = (unsigned char)ft_atoi(tab[1]);
rgb->b = (unsigned char)ft_atoi(tab[2]);
rgb->set = 1;
//printf("---%d\n", img->g);
}
@ -137,15 +138,15 @@ void set_color(char *str, t_data *img)
int index;
char **tab;
printf("str=%s \n", str);
//printf("str=%s \n", str);
c = next_space(str, 0);
index = next_space_index(str + 1, 0);
tab = ft_split(str + index + 1, ',');
if (!tab)
quit_game(img);
if (double_size(tab) != 3)
ft_exit("Error\nBad syntax in map file (RGB) 1\n");
print_double_fd(tab, 1);
//if (double_size(tab) != 3)
// ft_exit("Error\nBad syntax in map file (RGB) 1\n");
//print_double_fd(tab, 1);
if (c == 'F')
set_color_utils(tab, &img->map.floor);
if (c == 'C')

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/13 23:37:02 by apommier #+# #+# */
/* Updated: 2022/06/15 00:54:36 by apommier ### ########.fr */
/* Updated: 2022/06/15 12:33:07 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -55,9 +55,6 @@ double reset_angle(double angle)
void ft_error(char *error_msg)
{
/*int i;
i = 0;*/
ft_putendl_fd(error_msg, 2);
exit(1);
}
@ -107,43 +104,11 @@ int update_pos(t_data *img)
return (0);
}
int create_trgb(unsigned char t, unsigned char r, unsigned char g, unsigned char b)
{
return (*(int *)(unsigned char [4]){b, g, r, t});
}
void set_back(t_data *img)
{
/*for(int y = 0; y < 512; ++y)
for(int x = 0; x < 960; ++x)
{
int pixel = (y * img->size_line) + (x * 4);
int x;
if (endian == 1) // Most significant (Alpha) byte first
{
buffer[pixel + 0] = (color >> 24);
buffer[pixel + 1] = (color >> 16) & 0xFF;
buffer[pixel + 2] = (color >> 8) & 0xFF;
buffer[pixel + 3] = (color) & 0xFF;
}
//else if (endian == 0) // Least significant (Blue) byte first
//{
img->buffer[pixel + 0] = (color) & 0xFF;
img->buffer[pixel + 1] = (color >> 8) & 0xFF;
img->buffer[pixel + 2] = (color >> 16) & 0xFF;
img->buffer[pixel + 3] = (color >> 24);
//}
}*/
int x = 0;
//int tmp;
//tmp = (int *)img->buffer;
// img->map.floor.r = 128;
// img->map.floor.g = 128;
// img->map.floor.b = 128;
// img->map.sky.r = 0;
// img->map.sky.g = 191;
// img->map.sky.b = 255;
x = 0;
while (x < 512 * 960 * 4)
{
if (x > 512 * 960 * 2)
@ -155,14 +120,6 @@ void set_back(t_data *img)
img->buffer[x + 2] =img->map.floor.r;
img->buffer[x + 3] = 0;
}
//tmp = create_trgb(128, 128, 128, 0);
else
{
img->buffer[x + 0] = 128;
img->buffer[x + 1] = 128;
img->buffer[x + 2] = 128;
img->buffer[x + 3] = 0;
}
}
else
{
@ -170,11 +127,6 @@ void set_back(t_data *img)
img->buffer[x + 1] = img->map.sky.g;
img->buffer[x + 2] =img->map.sky.r;
img->buffer[x + 3] = 0;
//tmp = create_trgb(255, 191, 0, 0);
/*img->buffer[x + 0] = 255;
img->buffer[x + 1] = 191;
img->buffer[x + 2] = 0;
img->buffer[x + 3] = 0;*/
}
x += 4;
}