aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRudy Bousset <rbousset@z2r4p3.le-101.fr>2020-02-05 17:26:10 +0100
committerRudy Bousset <rbousset@z2r4p3.le-101.fr>2020-02-05 17:26:10 +0100
commit08dce587032f08c5bfbc2790bdb2d668ca1990c1 (patch)
treea927bf674dfa6d1d3efd03ef06dfacb115ae238f
parentmap fix (diff)
download42-cub3d-08dce587032f08c5bfbc2790bdb2d668ca1990c1.tar.gz
42-cub3d-08dce587032f08c5bfbc2790bdb2d668ca1990c1.tar.bz2
42-cub3d-08dce587032f08c5bfbc2790bdb2d668ca1990c1.tar.xz
42-cub3d-08dce587032f08c5bfbc2790bdb2d668ca1990c1.tar.zst
42-cub3d-08dce587032f08c5bfbc2790bdb2d668ca1990c1.zip
int16_tamer
Diffstat (limited to '')
-rw-r--r--inc/cub3d.h10
-rw-r--r--map/map_one.cub2
-rw-r--r--src/ft_check_missing.c5
-rw-r--r--src/ft_get_colors.c12
-rw-r--r--src/ft_get_res.c4
-rw-r--r--src/ft_get_screen_size.c15
-rw-r--r--src/ft_init_lists.c41
-rw-r--r--src/ft_parse_map.c1
-rw-r--r--src/ft_print_list.c4
-rw-r--r--src/ft_rgb_to_hex.c18
-rw-r--r--src/ft_select_get.c10
-rw-r--r--src/main.c1
12 files changed, 76 insertions, 47 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h
index f017973..7ea11d6 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -58,9 +58,9 @@ typedef struct s_img
typedef struct s_rgb
{
- uint8_t r;
- uint8_t g;
- uint8_t b;
+ int16_t r;
+ int16_t g;
+ int16_t b;
} t_rgb;
/*
@@ -85,8 +85,6 @@ typedef struct s_cub
char *ea_tex_path;
char *we_tex_path;
char *sprite_path;
- int f_color;
- int c_color;
char *mapl;
char **map;
size_t map_w;
@@ -130,6 +128,6 @@ int ft_map_error(t_cub *clist);
int ft_init_winlx(t_cub *clist);
void ft_drawmap(t_cub *clist);
void ft_print_list(t_cub *clist);
-int ft_rgb_to_hex(t_rgb rgb);
+uint32_t ft_rgb_to_hex(t_rgb rgb);
# endif
diff --git a/map/map_one.cub b/map/map_one.cub
index ad496ae..2a4c17a 100644
--- a/map/map_one.cub
+++ b/map/map_one.cub
@@ -7,7 +7,7 @@ WE ./path_to_the_west_texture
S ./path_to_the_sprite_texture
-F 100,123,213
+F 255,255,213
C 225,30,0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
diff --git a/src/ft_check_missing.c b/src/ft_check_missing.c
index 50fabbb..00bfbe9 100644
--- a/src/ft_check_missing.c
+++ b/src/ft_check_missing.c
@@ -27,6 +27,7 @@ int
int
ft_check_missing(t_cub *clist)
{
+ ft_printf("[%d], [%d], [%d]\n", clist->f_rgb.r, clist->f_rgb.g, clist->f_rgb.b);
if (!clist->no_tex_path[0])
return (ft_missing_error("north side texture", clist));
else if (!clist->so_tex_path[0])
@@ -39,9 +40,9 @@ int
return (ft_missing_error("sprite texture", clist));
else if (clist->wlist->x_size == 0 || clist->wlist->y_size == 0)
return (ft_missing_error("resolution", clist));
- else if (clist->f_color < 0)
+ else if (clist->f_rgb.r == -1 || clist->f_rgb.g == -1 || clist->f_rgb.b == -1)
return (ft_missing_error("floor color", clist));
- else if (clist->c_color < 0)
+ else if (clist->c_rgb.r == -1 || clist->c_rgb.g == -1 || clist->c_rgb.b == -1)
return (ft_missing_error("ceiling color", clist));
else if (clist->plist->pos_x == 0 || clist->plist->pos_y == 0)
return (ft_missing_error("player spawn", clist));
diff --git a/src/ft_get_colors.c b/src/ft_get_colors.c
index 249ff5a..52461ea 100644
--- a/src/ft_get_colors.c
+++ b/src/ft_get_colors.c
@@ -45,12 +45,6 @@ int8_t
ft_free_words(num);
return (-1);
}
- clist->f_color = ft_atoi(num[0]);
- clist->f_color *= 1000;
- clist->f_color += ft_atoi(num[1]);
- clist->f_color *= 1000;
- clist->f_color += ft_atoi(num[2]);
-
clist->f_rgb.r = ft_atoi(num[0]);
clist->f_rgb.g = ft_atoi(num[1]);
clist->f_rgb.b = ft_atoi(num[2]);
@@ -75,12 +69,6 @@ int8_t
ft_free_words(num);
return (-1);
}
- clist->c_color = ft_atoi(num[0]);
- clist->c_color *= 1000;
- clist->c_color += ft_atoi(num[1]);
- clist->c_color *= 1000;
- clist->c_color += ft_atoi(num[2]);
-
clist->c_rgb.r = ft_atoi(num[0]);
clist->c_rgb.g = ft_atoi(num[1]);
clist->c_rgb.b = ft_atoi(num[2]);
diff --git a/src/ft_get_res.c b/src/ft_get_res.c
index 649ab23..5e3dc06 100644
--- a/src/ft_get_res.c
+++ b/src/ft_get_res.c
@@ -30,7 +30,9 @@ static int8_t
int8_t
ft_get_res(char **words, t_cub *clist)
{
- t_win *wlist = clist->wlist;
+ t_win *wlist;
+
+ wlist = clist->wlist;
if (!(*words + 0) || !(*(words + 1)) ||
!(*(words + 2)) || (*(words + 3)))
return (-1);
diff --git a/src/ft_get_screen_size.c b/src/ft_get_screen_size.c
index cd9b162..a580a77 100644
--- a/src/ft_get_screen_size.c
+++ b/src/ft_get_screen_size.c
@@ -1,8 +1,21 @@
+/* ************************************************************************** */
+/* LE - / */
+/* / */
+/* ft_get_screen_size.c .:: .:/ . .:: */
+/* +:+:+ +: +: +:+:+ */
+/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
+/* #+# #+ #+ #+# */
+/* Created: 2020/02/05 16:06:58 by rbousset #+# ## ## #+# */
+/* Updated: 2020/02/05 16:06:59 by rbousset ### #+. /#+ ###.fr */
+/* / */
+/* / */
+/* ************************************************************************** */
+
#include <libft.h>
#include <cub3d.h>
int8_t
-ft_get_screen_size(t_win *wlist)
+ ft_get_screen_size(t_win *wlist)
{
char **words;
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index 291ef7b..ec46713 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -18,6 +18,30 @@
#include <stdlib.h>
#include <limits.h>
+static t_rgb
+ ft_init_rgb(void)
+{
+ t_rgb rgb;
+
+ rgb.r = -1;
+ rgb.g = -1;
+ rgb.b = -1;
+ return (rgb);
+}
+
+static t_player
+ *ft_init_player(void)
+{
+ t_player *plist;
+
+ if (!(plist = (t_player*)malloc(sizeof(t_player))))
+ return (NULL);
+ plist->pos_x = 0;
+ plist->pos_y = 0;
+ plist->view_side = 0;
+ return (plist);
+}
+
t_win
*ft_init_win(void)
{
@@ -36,19 +60,6 @@ t_win
return (wlist);
}
-static t_player
- *ft_init_player(void)
-{
- t_player *plist;
-
- if (!(plist = (t_player*)malloc(sizeof(t_player))))
- return (NULL);
- plist->pos_x = 0;
- plist->pos_y = 0;
- plist->view_side = 0;
- return (plist);
-}
-
t_cub
*ft_init_cub(void)
{
@@ -67,12 +78,12 @@ t_cub
!(clist->plist = ft_init_player()))
return (NULL);
clist->map[1] = 0;
- clist->f_color = -1;
- clist->c_color = -1;
clist->map_w = 0;
clist->map_h = 0;
clist->line_chk = 0;
clist->map_start = 0;
clist->isspawn = 0;
+ clist->f_rgb = ft_init_rgb();
+ clist->c_rgb = ft_init_rgb();
return (clist);
}
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index 58df20a..64b590b 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -122,6 +122,5 @@ void
if ((clist->scale = ((uint16_t)clist->wlist->x_size /
(uint16_t)clist->map_w) - 1) < 1)
clist->scale = 1;
- ft_print_list(clist);
close(fd);
}
diff --git a/src/ft_print_list.c b/src/ft_print_list.c
index 4e9e8d7..6c2b702 100644
--- a/src/ft_print_list.c
+++ b/src/ft_print_list.c
@@ -26,8 +26,8 @@ void
ft_printf("West ------- [%s]\n", clist->we_tex_path);
ft_printf("East ------- [%s]\n", clist->ea_tex_path);
ft_printf("Sprite ----- [%s]\n", clist->sprite_path);
- ft_printf("F color ---- [%d]\n", clist->f_color);
- ft_printf("C color ---- [%d]\n", clist->c_color);
+ ft_printf("F color ---- [%d]\n", ft_rgb_to_hex(clist->f_rgb));
+ ft_printf("C color ---- [%d]\n", ft_rgb_to_hex(clist->c_rgb));
i = 0;
ft_printf("Map\n----\n");
while (clist->map[i])
diff --git a/src/ft_rgb_to_hex.c b/src/ft_rgb_to_hex.c
index 525296d..4a7ad8e 100644
--- a/src/ft_rgb_to_hex.c
+++ b/src/ft_rgb_to_hex.c
@@ -1,9 +1,23 @@
+/* ************************************************************************** */
+/* LE - / */
+/* / */
+/* ft_rgb_to_hex.c .:: .:/ . .:: */
+/* +:+:+ +: +: +:+:+ */
+/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
+/* #+# #+ #+ #+# */
+/* Created: 2020/02/05 16:07:13 by rbousset #+# ## ## #+# */
+/* Updated: 2020/02/05 16:07:14 by rbousset ### #+. /#+ ###.fr */
+/* / */
+/* / */
+/* ************************************************************************** */
+
#include <cub3d.h>
+#include <stdint.h>
-int
+uint32_t
ft_rgb_to_hex(t_rgb rgb)
{
- int res;
+ uint32_t res;
res = 0;
res += ((rgb.r << 16) + (rgb.g << 8) + rgb.b);
diff --git a/src/ft_select_get.c b/src/ft_select_get.c
index 188a6de..53a37d4 100644
--- a/src/ft_select_get.c
+++ b/src/ft_select_get.c
@@ -33,10 +33,12 @@ ft_check_exists(const int8_t ret, t_cub *clist)
return (-1);
else if (ret == 5 && (clist->sprite_path[0]))
return (-1);
- else if (ret == 6 && (clist->f_color != -1))
- return (-1);
- else if (ret == 7 && (clist->c_color != -1))
- return (-1);
+ /* else if (ret == 6 && ((clist->f_rgb.r != -1) || (clist->f_rgb.g != -1) */
+ /* || (clist->f_rgb.b != -1))) */
+ /* return (-1); */
+ /* else if (ret == 7 && ((clist->c_rgb.r != -1) || (clist->c_rgb.g != -1) */
+ /* || (clist->c_rgb.b != -1))) */
+ /* return (-1); */
return (ret);
}
diff --git a/src/main.c b/src/main.c
index b9f4514..5de43e5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -31,6 +31,7 @@ int
ft_memdel((void**)&clist);
return (1);
}
+ ft_print_list(clist);
ft_parse_map("map/map_one.cub", clist);
if (ft_init_winlx(clist) < 0)
return (ft_exit(3, clist));