aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Makefile2
-rw-r--r--inc/cub3d.h3
-rw-r--r--map/map_one.cub1
-rw-r--r--src/ft_exit.c8
-rw-r--r--src/ft_get_colors.c43
-rw-r--r--src/ft_get_res.c5
-rw-r--r--src/ft_parse_map.c2
-rw-r--r--src/ft_select_get.c11
9 files changed, 25 insertions, 52 deletions
diff --git a/.gitignore b/.gitignore
index 819b7e0..5b425db 100644
--- a/.gitignore
+++ b/.gitignore
@@ -127,7 +127,7 @@ flycheck_*.el
.LSOverride
# Icon must end with two \r
-Icon
+Icon
# Thumbnails
._*
diff --git a/Makefile b/Makefile
index 1707b67..f167cda 100644
--- a/Makefile
+++ b/Makefile
@@ -26,7 +26,7 @@ SRCS_NAME += ft_select_get.c
SRCS_NAME += ft_get_res.c
SRCS_NAME += ft_get_tex.c
SRCS_NAME += ft_get_sprite.c
-# SRCS_NAME += ft_get_colors.c
+SRCS_NAME += ft_get_colors.c
# SRCS_NAME += ft_get_map.c
# SRCS_NAME += ft_check_empty_line.c
SRCS_NAME += ft_free_words.c
diff --git a/inc/cub3d.h b/inc/cub3d.h
index e0b2f79..b33d040 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -57,7 +57,8 @@ int ft_get_tex_so(char **words, t_cub *clist);
int ft_get_tex_ea(char **words, t_cub *clist);
int ft_get_tex_we(char **words, t_cub *clist);
int ft_get_sprite(char **words, t_cub *clist);
-int ft_get_colors(int fd, t_cub *clist);
+int ft_get_f_color(char **words, t_cub *clist);
+int ft_get_c_color(char **words, t_cub *clist);
int ft_get_map(int fd, t_cub *clist);
void ft_check_empty_line(int fd,
unsigned int linum,
diff --git a/map/map_one.cub b/map/map_one.cub
index 388dd3a..837c115 100644
--- a/map/map_one.cub
+++ b/map/map_one.cub
@@ -5,6 +5,7 @@ SO ./path_to_the_south_texture
EA ./path_to_the_east_texture
WE ./path_to_the_west_texture
S ./path_to_the_sprite_texture
+
F 220,100,0
C 225,30,0
diff --git a/src/ft_exit.c b/src/ft_exit.c
index a3ec72d..c445e37 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -1,6 +1,7 @@
#include <libft.h>
#include <cub3d.h>
#include <mlx.h>
+#include <stddef.h>
#include <stdlib.h>
#include <inttypes.h>
@@ -13,8 +14,8 @@ ft_free_lists(t_cub *clist)
ft_memdel(clist->we_tex_path);
ft_memdel(clist->sprite_path);
ft_free_words(clist->map);
- if (!clist->wlist->inited)
- ft_memdel(clist->wlist->winptr);
+ /* if (!clist->wlist->inited) */
+ ft_memdel(clist->wlist->winptr);
ft_memdel(clist->wlist->wlx);
ft_memdel(clist->wlist);
ft_memdel(clist);
@@ -24,7 +25,10 @@ int
ft_exit(uint8_t exit_code, t_cub *clist)
{
if (clist->wlist->inited)
+ {
mlx_destroy_window(clist->wlist->wlx, clist->wlist->winptr);
+ clist->wlist->winptr = NULL;
+ }
ft_printf("Exiting program\n");
if (exit_code < 0 || exit_code > 0)
ft_printf("Exit code: %hhu\n", exit_code);
diff --git a/src/ft_get_colors.c b/src/ft_get_colors.c
index 1b67447..226b427 100644
--- a/src/ft_get_colors.c
+++ b/src/ft_get_colors.c
@@ -16,11 +16,11 @@ ft_check_digits(const char *word)
}
int
-ft_get_f_color(char *line, char **words, t_cub *clist)
+ft_get_f_color(char **words, t_cub *clist)
{
char **num;
- if (!(*words) || ft_strcmp(*words, "F") || !words[1] || words[2])
+ if (!(*words) || !words[1] || words[2])
return (-1);
if (!(num = ft_split(words[1], ',')))
return (-1);
@@ -29,7 +29,7 @@ ft_get_f_color(char *line, char **words, t_cub *clist)
ft_check_digits(num[2]) || ft_atoi(num[0]) > 255 ||
ft_atoi(num[1]) > 255 || ft_atoi(num[2]) > 255)
{
- ft_free_words(num, NULL);
+ ft_free_words(num);
return (-1);
}
clist->f_color = ft_atoi(num[0]);
@@ -37,13 +37,11 @@ ft_get_f_color(char *line, char **words, t_cub *clist)
clist->f_color += ft_atoi(num[1]);
clist->f_color *= 1000;
clist->f_color += ft_atoi(num[2]);
- ft_free_words(num, NULL);
- ft_free_words(words, line);
return (0);
}
int
-ft_get_c_color(char *line, char **words, t_cub *clist)
+ft_get_c_color(char **words, t_cub *clist)
{
char **num;
@@ -56,7 +54,7 @@ ft_get_c_color(char *line, char **words, t_cub *clist)
ft_check_digits(num[2]) || ft_atoi(num[0]) > 255 ||
ft_atoi(num[1]) > 255 || ft_atoi(num[2]) > 255)
{
- ft_free_words(num, NULL);
+ ft_free_words(num);
return (-1);
}
clist->c_color = ft_atoi(num[0]);
@@ -64,36 +62,5 @@ ft_get_c_color(char *line, char **words, t_cub *clist)
clist->c_color += ft_atoi(num[1]);
clist->c_color *= 1000;
clist->c_color += ft_atoi(num[2]);
- ft_free_words(num, NULL);
- ft_free_words(words, line);
- return (0);
-}
-
-int
-ft_get_colors(int fd, t_cub *clist)
-{
- char *line;
- char **words;
-
- if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' ')))
- {
- ft_memdel(line);
- return (ft_map_error(8, clist));
- }
- if (ft_get_f_color(line, words, clist) < 0)
- {
- ft_free_words(words, line);
- return (ft_map_error(8, clist));
- }
- if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' ')))
- {
- ft_memdel(line);
- return (ft_map_error(9, clist));
- }
- if (ft_get_c_color(line, words, clist) < 0)
- {
- ft_free_words(words, line);
- return (ft_map_error(9, clist));
- }
return (0);
}
diff --git a/src/ft_get_res.c b/src/ft_get_res.c
index 850e82e..6fecb74 100644
--- a/src/ft_get_res.c
+++ b/src/ft_get_res.c
@@ -18,10 +18,7 @@ ft_get_res(char **words, t_cub *clist)
{
if (!(*words + 0) || !(*(words + 1))
|| !(*(words + 2)) || (*(words + 3)))
- {
- ft_free_words(words);
- return (ft_map_error(clist));
- }
+ return (-1);
ft_checkdigit(words[1], clist);
ft_checkdigit(words[2], clist);
clist->wlist->x_size = ft_atoi(words[1]);
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index 7704ff2..52c6316 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -91,7 +91,7 @@ ft_parse_map(const char *map_path, t_cub *clist)
ret = 1;
while (ret != 12)
ret = ft_parse_it(fd, clist);
- /* ft_get_map(void); */
+ ft_get_map(fd, clist);
/* if (ft_get_tex(fd, clist) < 0) */
/* return ; */
/* ft_check_empty_line(fd, 6, clist); */
diff --git a/src/ft_select_get.c b/src/ft_select_get.c
index eb68711..6c1900d 100644
--- a/src/ft_select_get.c
+++ b/src/ft_select_get.c
@@ -17,15 +17,17 @@ ft_get_id(char **words)
return (4);
if (!ft_strncmp(words[0], "S", 1))
return (5);
- /* if (!ft_strncmp(words[0], "F", 1)) */
- /* return (6); */
+ if (!ft_strncmp(words[0], "F", 1))
+ return (6);
+ if (!ft_strncmp(words[0], "C", 1))
+ return (7);
return (12);
}
uint8_t
ft_select_get(char **words, t_cub *clist)
{
- int (*fun_ptr[7])(char**, t_cub*);
+ int (*fun_ptr[8])(char**, t_cub*);
uint8_t id;
fun_ptr[0] = ft_get_res;
@@ -34,7 +36,8 @@ ft_select_get(char **words, t_cub *clist)
fun_ptr[3] = ft_get_tex_ea;
fun_ptr[4] = ft_get_tex_we;
fun_ptr[5] = ft_get_sprite;
- /* fun_ptr[6] = ft_get_f_color; */
+ fun_ptr[6] = ft_get_f_color;
+ fun_ptr[7] = ft_get_c_color;
if ((id = ft_get_id(words)) == 12)
{
ft_free_words(words);