Skip to content

Commit b4d21dc

Browse files
committed
fix parsing and add second getrgba with transparency
1 parent 43834cb commit b4d21dc

File tree

9 files changed

+63
-34
lines changed

9 files changed

+63
-34
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.objs
22
*.o
33
cub3D
4+
cub4D
45
libft.a
56
Raycast
67
.vscode

bonus/includes/cub3d.h

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ void move_keyhook(void *param);
133133

134134
// UTILS
135135
int get_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
136+
int get_rgba_transparency(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
136137
void get_player_pos(t_data *data);
137138
void get_map_size(t_data *data);
138139
int get_correct_color(u_int8_t *pixel);

bonus/includes/macros.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: mvpee <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/06/06 13:08:32 by nechaara #+# #+# */
9-
/* Updated: 2024/07/01 14:46:43 by mvpee ### ########.fr */
9+
/* Updated: 2024/07/02 21:20:01 by mvpee ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -22,6 +22,9 @@
2222
# define INVALID_BORDER "Error\nBad Border\n"
2323
# define WRONG_PLAYER_COUNT "Error\nWrong player count\n"
2424
# define NUMBERS_OF_ARGUMENTS "Error\nNumber of argument(s)\n"
25+
# define FLOOR_COLOR "Error\nBad floor color\n"
26+
# define CEILING_COLOR "Error\nBad ceiling color\n"
27+
2528
// COLOR
2629
# define RED "\x1b[31m"
2730
# define GREEN "\x1b[32m"

bonus/srcs/init_and_unit/init_and_unit.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: mvpee <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/06/07 20:07:42 by nechaara #+# #+# */
9-
/* Updated: 2024/07/02 20:39:37 by mvpee ### ########.fr */
9+
/* Updated: 2024/07/02 21:29:20 by mvpee ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -30,19 +30,19 @@ void free_data(t_data *data)
3030
static void init_minimap_color(t_minimap *minimap)
3131
{
3232
minimap->white = get_rgba(255, 255, 255, 255);
33-
minimap->door = get_rgba(255, 255, 255, 75);
33+
minimap->door = get_rgba_transparency(255, 255, 255, 75);
3434
minimap->door = \
3535
get_correct_color((u_int8_t *)&(minimap->door));
36-
minimap->transparent_white = get_rgba(255, 255, 255, 50);
36+
minimap->transparent_white = get_rgba_transparency(255, 255, 255, 50);
3737
minimap->transparent_white = \
3838
get_correct_color((u_int8_t *)&(minimap->transparent_white));
39-
minimap->transparent = get_rgba(0, 0, 0, 0);
39+
minimap->transparent = get_rgba_transparency(0, 0, 0, 0);
4040
minimap->transparent = \
4141
get_correct_color((u_int8_t *)&(minimap->transparent));
4242
minimap->black = get_rgba(0, 0, 0, 255);
4343
minimap->black = \
4444
get_correct_color((u_int8_t *)&(minimap->black));
45-
minimap->transparent_black = get_rgba(0, 0, 0, 100);
45+
minimap->transparent_black = get_rgba_transparency(0, 0, 0, 100);
4646
minimap->transparent_black = \
4747
get_correct_color((u_int8_t *)&(minimap->transparent_black));
4848
}

bonus/srcs/parsing/check_file.c

+20-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: mvpee <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/04/25 11:08:42 by mvpee #+# #+# */
9-
/* Updated: 2024/07/02 20:39:41 by mvpee ### ########.fr */
9+
/* Updated: 2024/07/02 21:25:21 by mvpee ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -64,29 +64,33 @@ static void get_texture(t_data *data, t_img **image, char *line)
6464
ft_free(3, &str, &line, &temp);
6565
}
6666

67-
static void get_color(int *color, char *line)
67+
static bool get_color(int *color, char *line)
6868
{
6969
char **split;
7070
int i;
7171
int array[3];
7272

73-
ft_memset(array, 0, 3);
73+
ft_memset(array, -1, 3);
7474
i = -1;
7575
split = ft_split(line, ", ");
76+
if (!split)
77+
return (true);
7678
if (split)
7779
{
78-
while (++i < 3 && split[i])
80+
while (++i < 3 && split[i] && ft_strlen(split[i]) < 4)
7981
{
8082
array[i] = ft_atoi(split[i]);
81-
if (array[i] < 0)
82-
array[i] = 0;
83-
if (array[i] > 255)
84-
array[i] = 255;
83+
if (array[i] < 0 || array[i] > 255 || array[i] == -1)
84+
return (true);
8585
}
86+
if (i != 3)
87+
return (true);
8688
ft_free_matrix(1, &split);
8789
}
8890
ft_free(1, &line);
8991
*color = get_rgba(array[0], array[1], array[2], 255);
92+
*color = get_correct_color((u_int8_t *)color);
93+
return (false);
9094
}
9195

9296
bool check_file(t_data *data)
@@ -107,11 +111,15 @@ bool check_file(t_data *data)
107111
else if (!ft_strncmp(data->file[i], "DO ", 3))
108112
get_texture(data, &data->door_image, data->file[i]);
109113
else if (!ft_strncmp(data->file[i], "F ", 2))
110-
get_color(&data->floor_color, ft_substr(data->file[i], 2,
111-
ft_strlen(data->file[i]) - 3));
114+
{
115+
if (get_color(&data->floor_color, ft_substr(data->file[i], 2, ft_strlen(data->file[i]) - 3)))
116+
return (ft_printf_fd(2, RED FLOOR_COLOR RESET), true);
117+
}
112118
else if (!ft_strncmp(data->file[i], "C ", 2))
113-
get_color(&data->ceiling_color, ft_substr(data->file[i], 2,
114-
ft_strlen(data->file[i]) - 3));
119+
{
120+
if (get_color(&data->ceiling_color, ft_substr(data->file[i], 2, ft_strlen(data->file[i]) - 3)))
121+
return (ft_printf_fd(2, RED CEILING_COLOR RESET), true);
122+
}
115123
else if (ft_strlen(data->file[i]) > 1)
116124
data->map = ft_splitjoin(data->map, data->file[i]);
117125
}

bonus/srcs/utils/utils.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@
66
/* By: mvpee <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/06/06 13:36:30 by nechaara #+# #+# */
9-
/* Updated: 2024/07/02 20:40:19 by mvpee ### ########.fr */
9+
/* Updated: 2024/07/02 21:28:49 by mvpee ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include "../../includes/cub3d.h"
1414

1515
int get_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
16+
{
17+
return (r << 24 | g << 16 | b << 8 | a);
18+
}
19+
20+
int get_rgba_transparency(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
1621
{
1722
return (a << 24 | b << 16 | g << 8 | r);
1823
}

mandatory/includes/macros.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: mvpee <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/06/06 13:08:32 by nechaara #+# #+# */
9-
/* Updated: 2024/06/26 15:59:30 by mvpee ### ########.fr */
9+
/* Updated: 2024/07/02 20:59:18 by mvpee ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -22,6 +22,9 @@
2222
# define INVALID_BORDER "Error\nBad Border\n"
2323
# define WRONG_PLAYER_COUNT "Error\nWrong player count\n"
2424
# define NUMBERS_OF_ARGUMENTS "Error\nNumber of argument(s)\n"
25+
# define FLOOR_COLOR "Error\nBad floor color\n"
26+
# define CEILING_COLOR "Error\nBad ceiling color\n"
27+
2528
// COLOR
2629
# define RED "\x1b[31m"
2730
# define GREEN "\x1b[32m"

mandatory/srcs/parsing/check_file.c

+20-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: mvpee <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/04/25 11:08:42 by mvpee #+# #+# */
9-
/* Updated: 2024/07/02 20:43:40 by mvpee ### ########.fr */
9+
/* Updated: 2024/07/02 21:23:03 by mvpee ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -62,29 +62,33 @@ static void get_texture(t_data *data, t_img **image, char *line)
6262
ft_free(3, &str, &line, &temp);
6363
}
6464

65-
static void get_color(int *color, char *line)
65+
static bool get_color(int *color, char *line)
6666
{
6767
char **split;
6868
int i;
6969
int array[3];
7070

71-
ft_memset(array, 0, 3);
71+
ft_memset(array, -1, 3);
7272
i = -1;
7373
split = ft_split(line, ", ");
74+
if (!split)
75+
return (true);
7476
if (split)
7577
{
76-
while (++i < 3 && split[i])
78+
while (++i < 3 && split[i] && ft_strlen(split[i]) < 4)
7779
{
7880
array[i] = ft_atoi(split[i]);
79-
if (array[i] < 0)
80-
array[i] = 0;
81-
if (array[i] > 255)
82-
array[i] = 255;
81+
if (array[i] < 0 || array[i] > 255 || array[i] == -1)
82+
return (true);
8383
}
84+
if (i != 3)
85+
return (true);
8486
ft_free_matrix(1, &split);
8587
}
8688
ft_free(1, &line);
8789
*color = get_rgba(array[0], array[1], array[2], 255);
90+
*color = get_correct_color((u_int8_t *)color);
91+
return (false);
8892
}
8993

9094
bool check_file(t_data *data)
@@ -103,11 +107,15 @@ bool check_file(t_data *data)
103107
else if (!ft_strncmp(data->file[i], "EA ", 3))
104108
get_texture(data, &data->east_image, data->file[i]);
105109
else if (!ft_strncmp(data->file[i], "F ", 2))
106-
get_color(&data->floor_color, ft_substr(data->file[i], 2,
107-
ft_strlen(data->file[i]) - 3));
110+
{
111+
if (get_color(&data->floor_color, ft_substr(data->file[i], 2, ft_strlen(data->file[i]) - 3)))
112+
return (ft_printf_fd(2, RED FLOOR_COLOR RESET), true);
113+
}
108114
else if (!ft_strncmp(data->file[i], "C ", 2))
109-
get_color(&data->ceiling_color, ft_substr(data->file[i], 2,
110-
ft_strlen(data->file[i]) - 3));
115+
{
116+
if (get_color(&data->ceiling_color, ft_substr(data->file[i], 2, ft_strlen(data->file[i]) - 3)))
117+
return (ft_printf_fd(2, RED CEILING_COLOR RESET), true);
118+
}
111119
else if (ft_strlen(data->file[i]) > 1)
112120
data->map = ft_splitjoin(data->map, data->file[i]);
113121
}

mandatory/srcs/utils/utils.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
/* By: mvpee <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/06/06 13:36:30 by nechaara #+# #+# */
9-
/* Updated: 2024/07/02 20:43:54 by mvpee ### ########.fr */
9+
/* Updated: 2024/07/02 21:27:30 by mvpee ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include "../../includes/cub3d.h"
1414

1515
int get_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
1616
{
17-
return (a << 24 | b << 16 | g << 8 | r);
17+
return (r << 24 | g << 16 | b << 8 | a);
1818
}
1919

2020
void get_map_size(t_data *data)

0 commit comments

Comments
 (0)