Skip to content

Commit

Permalink
to push
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathis ROLY committed Apr 4, 2022
1 parent eab193f commit 3653f84
Show file tree
Hide file tree
Showing 197 changed files with 4,200 additions and 103 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SRC = main.c \
get_next_line.c get_next_line_u.c \
parse_map.c \
exit.c \
utils_str.c utils_free.c \
utils_str.c utils_free.c utils_str2.c \
check_cub.c check_cub2.c check_cub3.c \
check_handv.c \
count_island.c count_island_utils.c \
Expand All @@ -21,7 +21,7 @@ SRC_BONUS = main.c \
get_next_line.c get_next_line_u.c \
parse_map.c \
exit.c \
utils_str.c utils_free.c \
utils_str.c utils_free.c utils_str2.c \
check_cub.c check_cub2.c check_cub3.c \
check_handv.c \
count_island.c count_island_utils.c \
Expand Down Expand Up @@ -62,7 +62,7 @@ BONUS_MLX_DIR = $(addprefix cub3d_bonus/, $(MLX_DIR))
MAND_MLX = $(addprefix cub3d_mand/, $(MLX))
BONUS_MLX = $(addprefix cub3d_bonus/, $(MLX))

CFLAGS = -Wall -Wextra -Werror -g #-fsanitize=address
CFLAGS = -Wall -Wextra -Werror #-g -fsanitize=address

OBJ_DIR = cub3d_mand/obj
SRC_DIR = cub3d_mand/src
Expand Down
5 changes: 4 additions & 1 deletion cub3d_bonus/inc/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maroly <maroly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/15 18:48:21 by hkovac #+# #+# */
/* Updated: 2022/04/04 12:26:31 by maroly ### ########.fr */
/* Updated: 2022/04/04 13:59:56 by maroly ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -35,6 +35,9 @@ int ft_strncmp(const char *s1, const char *s2, int n);
int ft_atoi(const char *nptr);
int check_ext(char *file);
void fill_tab2d(t_gbl *gbl, int fd);
char *ft_strcat(char *s1, char *s2);
/*utils_str2.c*/
int check_rgb(char **tab);
/*check_cub.c*/
void all_param(t_gbl *gbl);
int check_char(char c);
Expand Down
73 changes: 29 additions & 44 deletions cub3d_bonus/src/check_cub.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maroly <maroly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/16 17:58:23 by hkovac #+# #+# */
/* Updated: 2022/04/02 21:23:01 by maroly ### ########.fr */
/* Updated: 2022/04/04 14:00:10 by maroly ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -40,32 +40,6 @@ void all_param2(t_gbl *gbl, int i)
}
}

char *ft_strcat(char *s1, char *s2)
{
int i;
int j;
char *new;

i = 0;
j = 0;
new = malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
while (s1[i])
{
new[j] = s1[i];
j++;
i++;
}
i = 0;
while (s2[i])
{
new[j] = s2[i];
i++;
j++;
}
new[j] = 0;
return (new);
}

void free_color(t_color *color)
{
free(color->r);
Expand All @@ -74,24 +48,8 @@ void free_color(t_color *color)
free(color->rg_hexa);
}

unsigned int rgb_hexa(char *str, t_gbl *gbl)
unsigned int rgb_hexa2(t_color color)
{
t_color color;

color.rgb = ft_split(str, ',', gbl);
color.r = ft_convert_base(color.rgb[0], "0123456789", "0123456789abcdef");
color.g = ft_convert_base(color.rgb[1], "0123456789", "0123456789abcdef");
color.b = ft_convert_base(color.rgb[2], "0123456789", "0123456789abcdef");
destroy_tab(color.rgb);
if (ft_atoi(color.r) > 255 || ft_atoi(color.r) < 0
|| ft_atoi(color.g) > 255
|| ft_atoi(color.g) < 0 || ft_atoi(color.b) > 255
|| ft_atoi(color.b) < 0)
{
write (2, "Error\nProbleme with rgb code for F or C\n",
ft_strlen("Error\nProbleme with rgb code for F or C\n"));
err_exit(gbl);
}
color.rg_hexa = ft_strcat(color.r, color.g);
color.rgb_hexa = ft_strcat(color.rg_hexa, color.b);
free_color(&color);
Expand All @@ -103,6 +61,33 @@ unsigned int rgb_hexa(char *str, t_gbl *gbl)
return (color.color);
}

unsigned int rgb_hexa(char *str, t_gbl *gbl)
{
t_color color;

color.rgb = ft_split(str, ',', gbl);
if (check_rgb(color.rgb) == 1)
{
write(2, "Error\nRGB code incorrect\n",
ft_strlen("Error\nRGB code incorrect\n"));
err_exit(gbl);
}
if (ft_atoi(color.rgb[0]) > 255 || ft_atoi(color.rgb[0]) < 0
|| ft_atoi(color.rgb[1]) > 255
|| ft_atoi(color.rgb[1]) < 0 || ft_atoi(color.rgb[2]) > 255
|| ft_atoi(color.rgb[2]) < 0)
{
write (2, "Error\nProbleme with rgb code for F or C\n",
ft_strlen("Error\nProbleme with rgb code for F or C\n"));
err_exit(gbl);
}
color.r = ft_convert_base(color.rgb[0], "0123456789", "0123456789abcdef");
color.g = ft_convert_base(color.rgb[1], "0123456789", "0123456789abcdef");
color.b = ft_convert_base(color.rgb[2], "0123456789", "0123456789abcdef");
destroy_tab(color.rgb);
return (rgb_hexa2(color));
}

void all_param(t_gbl *gbl)
{
int i;
Expand Down
8 changes: 6 additions & 2 deletions cub3d_bonus/src/check_handv.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maroly <maroly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/31 19:22:57 by maroly #+# #+# */
/* Updated: 2022/04/04 11:49:57 by maroly ### ########.fr */
/* Updated: 2022/04/04 13:28:21 by maroly ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -23,7 +23,11 @@ int check_map_horizontal2(t_gbl *gbl, int *i, int *j)
while (gbl->map[*i][*j] && gbl->map[*i][*j] != ' ')
{
if (check_char(gbl->map[*i][*j]) == 1)
return (1);
{
write(2, "Error\nUnknow character\n",
ft_strlen("Error\nUnknow character\n"));
err_exit(gbl);
}
(*j)++;
}
if (*i > 0 && gbl->map[*i][(*j) - 1] && gbl->map[*i][(*j) - 1] != '1')
Expand Down
4 changes: 2 additions & 2 deletions cub3d_bonus/src/open_texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maroly <maroly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/24 10:02:13 by hkovac #+# #+# */
/* Updated: 2022/04/02 15:03:58 by maroly ### ########.fr */
/* Updated: 2022/04/04 13:34:28 by maroly ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -28,7 +28,7 @@ void open_texture(t_gbl *gbl)
gbl->tex_string[i], &tex[i]->texwidth, &tex[i]->texheight);
if (!tex[i]->img)
{
write(1, "Error\nProblem when opening texture\n",
write(2, "Error\nProblem when opening texture\n",
ft_strlen("Error\nProblem when opening texture\n"));
err_exit(gbl);
}
Expand Down
28 changes: 27 additions & 1 deletion cub3d_bonus/src/utils_str.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maroly <maroly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/16 15:58:58 by hkovac #+# #+# */
/* Updated: 2022/03/31 19:03:20 by maroly ### ########.fr */
/* Updated: 2022/04/04 13:41:17 by maroly ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -78,3 +78,29 @@ int ft_atoi(const char *nptr)
}
return (result * sign);
}

char *ft_strcat(char *s1, char *s2)
{
int i;
int j;
char *new;

i = 0;
j = 0;
new = malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
while (s1[i])
{
new[j] = s1[i];
j++;
i++;
}
i = 0;
while (s2[i])
{
new[j] = s2[i];
i++;
j++;
}
new[j] = 0;
return (new);
}
32 changes: 32 additions & 0 deletions cub3d_bonus/src/utils_str2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_str2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maroly <maroly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/04 13:42:39 by maroly #+# #+# */
/* Updated: 2022/04/04 14:00:29 by maroly ### ########.fr */
/* */
/* ************************************************************************** */

#include "include.h"

int check_rgb(char **tab)
{
int i;
int j;

i = 0;
while (tab[i])
{
j = -1;
while (tab[i][++j])
if (!(tab[i][j] >= '0' && tab[i][j] <= '9'))
return (1);
i++;
}
if (i != 3)
return (1);
return (0);
}
5 changes: 4 additions & 1 deletion cub3d_mand/inc/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maroly <maroly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/15 18:48:21 by hkovac #+# #+# */
/* Updated: 2022/03/31 19:24:48 by maroly ### ########.fr */
/* Updated: 2022/04/04 14:01:07 by maroly ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -35,6 +35,9 @@ int ft_strncmp(const char *s1, const char *s2, int n);
int ft_atoi(const char *nptr);
int check_ext(char *file);
void fill_tab2d(t_gbl *gbl, int fd);
char *ft_strcat(char *s1, char *s2);
/*utils_str2.c*/
int check_rgb(char **tab);
/*check_cub.c*/
void all_param(t_gbl *gbl);
int check_char(char c);
Expand Down
22 changes: 22 additions & 0 deletions cub3d_mand/invalid_maps/invalid_RGB_000.cub
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
R 1080 720
NO ./textures/greystone.xpm
SO ./textures/redbrick.xpm
EA ./textures/wood.xpm
WE ./textures/wood.xpm
S ./textures/barrel.xpm
C 255,200,
F 122,122,122

11111111111111111
10000000000000001
10200000200000201
10000000000000001
10002000200020001
10000000000000001
10202020N02020201
10000000000000001
10002000200200001
10000000000000001
10200000200002001
10000000000000001
11111111111111111
22 changes: 22 additions & 0 deletions cub3d_mand/invalid_maps/invalid_RGB_001.cub
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
R 1080 720
NO ./textures/greystone.xpm
SO ./textures/redbrick.xpm
EA ./textures/wood.xpm
WE ./textures/wood.xpm
S ./textures/barrel.xpm
C 255,200,160
F

11111111111111111
10000000000000001
10200000200000201
10000000000000001
10002000200020001
10000000000000001
10202020N02020201
10000000000000001
10002000200200001
10000000000000001
10200000200002001
10000000000000001
11111111111111111
22 changes: 22 additions & 0 deletions cub3d_mand/invalid_maps/invalid_RGB_002.cub
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
R 1080 720
NO ./textures/greystone.xpm
SO ./textures/redbrick.xpm
EA ./textures/wood.xpm
WE ./textures/wood.xpm
S ./textures/barrel.xpm
C
F 122,122,122

11111111111111111
10000000000000001
10200000200000201
10000000000000001
10002000200020001
10000000000000001
10202020N02020201
10000000000000001
10002000200200001
10000000000000001
10200000200002001
10000000000000001
11111111111111111
22 changes: 22 additions & 0 deletions cub3d_mand/invalid_maps/invalid_RGB_003.cub
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
R 1080 720
NO ./textures/greystone.xpm
SO ./textures/redbrick.xpm
EA ./textures/wood.xpm
WE ./textures/wood.xpm
S ./textures/barrel.xpm
C 255,200,160


11111111111111111
10000000000000001
10200000200000201
10000000000000001
10002000200020001
10000000000000001
10202020N02020201
10000000000000001
10002000200200001
10000000000000001
10200000200002001
10000000000000001
11111111111111111
22 changes: 22 additions & 0 deletions cub3d_mand/invalid_maps/invalid_RGB_004.cub
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
R 1080 720
NO ./textures/greystone.xpm
SO ./textures/redbrick.xpm
EA ./textures/wood.xpm
WE ./textures/wood.xpm
S ./textures/barrel.xpm

F 122,122,122

11111111111111111
10000000000000001
10200000200000201
10000000000000001
10002000200020001
10000000000000001
10202020N02020201
10000000000000001
10002000200200001
10000000000000001
10200000200002001
10000000000000001
11111111111111111
Loading

0 comments on commit 3653f84

Please sign in to comment.