add verification texture file
This commit is contained in:
parent
efed7db4a9
commit
cda81e1fd9
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2020/12/09 19:58:04 by apommier #+# #+# */
|
/* 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)
|
while (*lst)
|
||||||
{
|
{
|
||||||
chr = (*lst)->next;
|
chr = (*lst)->next;
|
||||||
del((*lst)->nbr);
|
del((*lst)->content);
|
||||||
free(*lst);
|
free(*lst);
|
||||||
*lst = chr;
|
*lst = chr;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,10 +3,10 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* ft_lstdelone.c :+: :+: :+: */
|
/* ft_lstdelone.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2020/12/09 19:54:40 by apommier #+# #+# */
|
/* 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)
|
if (!lst)
|
||||||
return ;
|
return ;
|
||||||
del(lst->nbr);
|
del(lst->content);
|
||||||
free(lst);
|
free(lst);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,10 +3,10 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* ft_lstiter.c :+: :+: :+: */
|
/* ft_lstiter.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2020/12/09 20:14:47 by apommier #+# #+# */
|
/* 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)
|
while (lst)
|
||||||
{
|
{
|
||||||
f(lst->nbr);
|
f(lst->content);
|
||||||
lst = lst->next;
|
lst = lst->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,10 +3,10 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* ft_lstmap.c :+: :+: :+: */
|
/* ft_lstmap.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2020/12/11 00:10:12 by apommier #+# #+# */
|
/* 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;
|
begin = 0;
|
||||||
while (lst)
|
while (lst)
|
||||||
{
|
{
|
||||||
new = ft_lstnew(f(lst->nbr));
|
new = ft_lstnew(f(lst->content));
|
||||||
if (!new)
|
if (!new)
|
||||||
{
|
{
|
||||||
ft_lstclear(&begin, *del);
|
ft_lstclear(&begin, *del);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2020/12/09 01:06:20 by apommier #+# #+# */
|
/* 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));
|
new = (t_list *)malloc(sizeof(t_list));
|
||||||
if (!new)
|
if (!new)
|
||||||
return (0);
|
return (0);
|
||||||
new->swap = 0;
|
new->content = content;
|
||||||
new->nbr = content;
|
|
||||||
new->next = 0;
|
new->next = 0;
|
||||||
return (new);
|
return (new);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2020/12/11 03:21:27 by apommier #+# #+# */
|
/* 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
|
typedef struct t_slist
|
||||||
{
|
{
|
||||||
void *nbr;
|
void *content;
|
||||||
int index;
|
|
||||||
int swap;
|
int swap;
|
||||||
struct t_slist *next;
|
struct t_slist *next;
|
||||||
} t_list;
|
} t_list;
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/05/06 16:10:11 by apommier #+# #+# */
|
/* 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
|
unsigned char *get_texture(char type, char *path, t_data *img)//change in list
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
@ -47,19 +66,20 @@ unsigned char *get_texture(char type, char *path, t_data *img)//change in list
|
|||||||
int count;
|
int count;
|
||||||
char *swap = 0;
|
char *swap = 0;
|
||||||
|
|
||||||
if (!path)
|
|
||||||
{
|
|
||||||
//printf("no path\n");
|
|
||||||
path = ft_strjoin("./sprite/brick_wall.ppm", 0);
|
|
||||||
}
|
|
||||||
(void)type;
|
(void)type;
|
||||||
count = 0;
|
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);
|
fd = open(path, O_RDONLY);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
quit_game(img);
|
||||||
printf("path= %s\n", path);
|
img->to_be_free.fd_one = fd;
|
||||||
ft_exit("Error\nBad texture file prout");
|
|
||||||
}
|
|
||||||
while (swap || !count)
|
while (swap || !count)
|
||||||
{
|
{
|
||||||
if (swap)
|
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);
|
swap = get_next_line(fd);
|
||||||
}
|
}
|
||||||
close(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);
|
ret = ft_calloc(sizeof(char), count);
|
||||||
fd = open(path, O_RDONLY);
|
|
||||||
if (!ret)
|
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;
|
count = 0;
|
||||||
while (swap || !count)
|
while (swap || !count)
|
||||||
{
|
{
|
||||||
if (swap)
|
if (swap)
|
||||||
free(swap);
|
free(swap);
|
||||||
swap = get_next_line(fd);
|
swap = get_next_line(fd);
|
||||||
|
//printf("str = -%s-\n", swap);
|
||||||
if (!count)
|
if (!count)
|
||||||
{
|
{
|
||||||
free(swap);
|
free(swap);
|
||||||
swap = get_next_line(fd);
|
swap = get_next_line(fd);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (swap)
|
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);
|
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++;
|
count++;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
img->to_be_free.fd_one = -1;
|
||||||
put_texture_in_struct(type, ret, img);
|
put_texture_in_struct(type, ret, img);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/06/11 01:00:17 by apommier #+# #+# */
|
/* 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))
|
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");
|
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))
|
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");
|
ft_exit("Error\nBad syntax in map file (RGB)\n");
|
||||||
check_value(tab);
|
check_value(tab);
|
||||||
img->r = (unsigned char)ft_atoi(tab[0]);
|
rgb->r = (unsigned char)ft_atoi(tab[0]);
|
||||||
img->g = (unsigned char)ft_atoi(tab[1]);
|
rgb->g = (unsigned char)ft_atoi(tab[1]);
|
||||||
img->b = (unsigned char)ft_atoi(tab[2]);
|
rgb->b = (unsigned char)ft_atoi(tab[2]);
|
||||||
|
rgb->set = 1;
|
||||||
//printf("---%d\n", img->g);
|
//printf("---%d\n", img->g);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -137,15 +138,15 @@ void set_color(char *str, t_data *img)
|
|||||||
int index;
|
int index;
|
||||||
char **tab;
|
char **tab;
|
||||||
|
|
||||||
printf("str=%s \n", str);
|
//printf("str=%s \n", str);
|
||||||
c = next_space(str, 0);
|
c = next_space(str, 0);
|
||||||
index = next_space_index(str + 1, 0);
|
index = next_space_index(str + 1, 0);
|
||||||
tab = ft_split(str + index + 1, ',');
|
tab = ft_split(str + index + 1, ',');
|
||||||
if (!tab)
|
if (!tab)
|
||||||
quit_game(img);
|
quit_game(img);
|
||||||
if (double_size(tab) != 3)
|
//if (double_size(tab) != 3)
|
||||||
ft_exit("Error\nBad syntax in map file (RGB) 1\n");
|
// ft_exit("Error\nBad syntax in map file (RGB) 1\n");
|
||||||
print_double_fd(tab, 1);
|
//print_double_fd(tab, 1);
|
||||||
if (c == 'F')
|
if (c == 'F')
|
||||||
set_color_utils(tab, &img->map.floor);
|
set_color_utils(tab, &img->map.floor);
|
||||||
if (c == 'C')
|
if (c == 'C')
|
||||||
|
|||||||
54
srcs/utils.c
54
srcs/utils.c
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/02/13 23:37:02 by apommier #+# #+# */
|
/* 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)
|
void ft_error(char *error_msg)
|
||||||
{
|
{
|
||||||
/*int i;
|
|
||||||
|
|
||||||
i = 0;*/
|
|
||||||
ft_putendl_fd(error_msg, 2);
|
ft_putendl_fd(error_msg, 2);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -107,43 +104,11 @@ int update_pos(t_data *img)
|
|||||||
return (0);
|
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)
|
void set_back(t_data *img)
|
||||||
{
|
{
|
||||||
/*for(int y = 0; y < 512; ++y)
|
int x;
|
||||||
for(int x = 0; x < 960; ++x)
|
|
||||||
{
|
|
||||||
int pixel = (y * img->size_line) + (x * 4);
|
|
||||||
|
|
||||||
if (endian == 1) // Most significant (Alpha) byte first
|
x = 0;
|
||||||
{
|
|
||||||
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;
|
|
||||||
while (x < 512 * 960 * 4)
|
while (x < 512 * 960 * 4)
|
||||||
{
|
{
|
||||||
if (x > 512 * 960 * 2)
|
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 + 2] =img->map.floor.r;
|
||||||
img->buffer[x + 3] = 0;
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -170,11 +127,6 @@ void set_back(t_data *img)
|
|||||||
img->buffer[x + 1] = img->map.sky.g;
|
img->buffer[x + 1] = img->map.sky.g;
|
||||||
img->buffer[x + 2] =img->map.sky.r;
|
img->buffer[x + 2] =img->map.sky.r;
|
||||||
img->buffer[x + 3] = 0;
|
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;
|
x += 4;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user