aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ft_check_empty_line.c6
-rw-r--r--src/ft_drawsquare.c4
-rw-r--r--src/ft_exit.c26
-rw-r--r--src/ft_get_colors.c38
-rw-r--r--src/ft_get_map.c74
-rw-r--r--src/ft_get_res.c18
-rw-r--r--src/ft_get_sprite_tex.c10
-rw-r--r--src/ft_get_tex.c50
-rw-r--r--src/ft_init_lists.c1
-rw-r--r--src/ft_init_winlx.c18
-rw-r--r--src/ft_key_events.c2
-rw-r--r--src/ft_map_error.c4
-rw-r--r--src/ft_parse_map.c29
-rw-r--r--src/ft_print_list.c25
-rw-r--r--src/main.c24
15 files changed, 174 insertions, 155 deletions
diff --git a/src/ft_check_empty_line.c b/src/ft_check_empty_line.c
index 5515c90..5f98f7d 100644
--- a/src/ft_check_empty_line.c
+++ b/src/ft_check_empty_line.c
@@ -2,19 +2,19 @@
#include <cub3d.h>
void
-ft_check_empty_line(int fd, unsigned int linum, t_win *wlist)
+ft_check_empty_line(int fd, unsigned int linum, t_cub *clist)
{
char *line;
if (get_next_line(fd, &line) <= 0)
{
ft_memdel(line);
- ft_map_error(linum, wlist);
+ ft_map_error(linum, clist);
}
if (*line)
{
ft_memdel(line);
- ft_map_error(linum, wlist);
+ ft_map_error(linum, clist);
}
ft_memdel(line);
}
diff --git a/src/ft_drawsquare.c b/src/ft_drawsquare.c
index 1f1334b..3bf891b 100644
--- a/src/ft_drawsquare.c
+++ b/src/ft_drawsquare.c
@@ -2,7 +2,7 @@
#include <cub3d.h>
void
-ft_drawsquare(int a, int b, int rgb, t_win *wlist)
+ft_drawsquare(int a, int b, int rgb, t_cub *clist)
{
int x;
int y;
@@ -13,7 +13,7 @@ ft_drawsquare(int a, int b, int rgb, t_win *wlist)
{
while (y > b - 40)
{
- mlx_pixel_put(wlist->wlx, wlist->winptr, x, y, rgb);
+ mlx_pixel_put(clist->wlist->wlx, clist->wlist->winptr, x, y, rgb);
y--;
}
y = b;
diff --git a/src/ft_exit.c b/src/ft_exit.c
index 14f1f2a..925bbd5 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -4,27 +4,27 @@
#include <inttypes.h>
static void
-ft_free_lists(t_win *wlist)
+ft_free_lists(t_cub *clist)
{
- ft_memdel(wlist->clist->no_tex_path);
- ft_memdel(wlist->clist->so_tex_path);
- ft_memdel(wlist->clist->ea_tex_path);
- ft_memdel(wlist->clist->we_tex_path);
- ft_memdel(wlist->clist->sprite_path);
- ft_free_words(wlist->clist->map, NULL);
- ft_memdel(wlist->clist);
- ft_memdel(wlist->winptr);
- ft_memdel(wlist->wlx);
- ft_memdel(wlist);
+ ft_memdel(clist->no_tex_path);
+ ft_memdel(clist->so_tex_path);
+ ft_memdel(clist->ea_tex_path);
+ ft_memdel(clist->we_tex_path);
+ ft_memdel(clist->sprite_path);
+ ft_free_words(clist->map, NULL);
+ ft_memdel(clist->wlist->winptr);
+ ft_memdel(clist->wlist->wlx);
+ ft_memdel(clist->wlist);
+ ft_memdel(clist);
}
int
-ft_exit(uint8_t exit_code, t_win *wlist)
+ft_exit(uint8_t exit_code, t_cub *clist)
{
ft_printf("Exiting program\n");
if (exit_code < 0 || exit_code > 0)
ft_printf("Exit code: %hhu\n", exit_code);
- ft_free_lists(wlist);
+ ft_free_lists(clist);
exit(exit_code);
return (0);
}
diff --git a/src/ft_get_colors.c b/src/ft_get_colors.c
index 2e09fc6..750ebed 100644
--- a/src/ft_get_colors.c
+++ b/src/ft_get_colors.c
@@ -16,7 +16,7 @@ ft_check_digits(const char *word)
}
static int
-ft_get_f_color(char *line, char **words, t_win *wlist)
+ft_get_f_color(char *line, char **words, t_cub *clist)
{
char **num;
@@ -32,18 +32,18 @@ ft_get_f_color(char *line, char **words, t_win *wlist)
ft_free_words(num, NULL);
return (-1);
}
- wlist->clist->f_color = ft_atoi(num[0]);
- wlist->clist->f_color *= 1000;
- wlist->clist->f_color += ft_atoi(num[1]);
- wlist->clist->f_color *= 1000;
- wlist->clist->f_color += ft_atoi(num[2]);
+ 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]);
ft_free_words(num, NULL);
ft_free_words(words, line);
return (0);
}
static int
-ft_get_c_color(char *line, char **words, t_win *wlist)
+ft_get_c_color(char *line, char **words, t_cub *clist)
{
char **num;
@@ -59,18 +59,18 @@ ft_get_c_color(char *line, char **words, t_win *wlist)
ft_free_words(num, NULL);
return (-1);
}
- wlist->clist->c_color = ft_atoi(num[0]);
- wlist->clist->c_color *= 1000;
- wlist->clist->c_color += ft_atoi(num[1]);
- wlist->clist->c_color *= 1000;
- wlist->clist->c_color += ft_atoi(num[2]);
+ 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]);
ft_free_words(num, NULL);
ft_free_words(words, line);
return (0);
}
int
-ft_get_colors(int fd, t_win *wlist)
+ft_get_colors(int fd, t_cub *clist)
{
char *line;
char **words;
@@ -78,22 +78,22 @@ ft_get_colors(int fd, t_win *wlist)
if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' ')))
{
ft_memdel(line);
- return (ft_map_error(8, wlist));
+ return (ft_map_error(8, clist));
}
- if (ft_get_f_color(line, words, wlist) < 0)
+ if (ft_get_f_color(line, words, clist) < 0)
{
ft_free_words(words, line);
- return (ft_map_error(8, wlist));
+ 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, wlist));
+ return (ft_map_error(9, clist));
}
- if (ft_get_c_color(line, words, wlist) < 0)
+ if (ft_get_c_color(line, words, clist) < 0)
{
ft_free_words(words, line);
- return (ft_map_error(9, wlist));
+ return (ft_map_error(9, clist));
}
return (0);
}
diff --git a/src/ft_get_map.c b/src/ft_get_map.c
index a8a6fe0..e41ffd6 100644
--- a/src/ft_get_map.c
+++ b/src/ft_get_map.c
@@ -3,31 +3,26 @@
#include <stddef.h>
#include <stdlib.h>
-/* static char */
-/* **ft_split_lines(char *line, int count) */
-/* { */
-/* } */
-
static int
-ft_linecpy(char *line, char *mapL, size_t start)
+ft_linecpy(char *line, char *mapl, size_t start)
{
size_t i;
size_t j;
i = 0;
j = start;
- while (i < ft_strlen(line))
+ while (i < ft_strlen(line) && line[i])
{
- mapL[j] = line[i];
+ mapl[j] = line[i];
i += 2;
j++;
}
- mapL[j + 1] = '\n';
+ mapl[j] = '\n';
return (0);
}
static int
-ft_check_err(char *line, size_t size, t_win *wlist)
+ft_check_err(char *line, size_t size)
{
size_t i;
@@ -37,45 +32,60 @@ ft_check_err(char *line, size_t size, t_win *wlist)
while (i < ft_strlen(line) && line[i])
{
if (line[i] != ' ')
- return (ft_map_error(11, wlist));
+ return (-1);
i += 2;
}
return (0);
}
+
+static char
+*ft_get_first_line(char *line, t_cub *clist)
+{
+ size_t len;
+ char *mapl;
+
+ len = ft_strlen(line);
+ if (len < 2 || ft_check_err(line, len) < 0)
+ return (NULL);
+ if (!(mapl = (char*)malloc(((len / 2) + 2) * sizeof(char))))
+ return (NULL);
+ ft_linecpy(line, mapl, 0);
+ ft_memdel(line);
+ clist->map_width = len;
+ return (mapl);
+}
+
int
-ft_get_map(int fd, t_win *wlist)
+ft_get_map(int fd, t_cub *clist)
{
size_t i;
size_t len;
+ int ret;
char *line;
- char *mapL;
+ char *mapl;
- ft_free_words(wlist->clist->map, NULL);
- /* if (!(wlist->clist->map = (char**)malloc(40 * sizeof(char*)))) */
- /* return (-1); */
- if (get_next_line(fd, &line) > 0)
+ if (get_next_line(fd, &line) <= 0 ||
+ !(mapl = ft_get_first_line(line, clist)))
{
- len = ft_strlen(line);
- ft_check_err(line, len, wlist);
- if (!(mapL = (char*)malloc((len + 1) * sizeof(char))))
- return (-1);
- ft_linecpy(line, mapL, 0);
ft_memdel(line);
- }
- else
return (-1);
+ }
i = 1;
- while (get_next_line(fd, &line) > 0)
+ ret = 1;
+ len = clist->map_width;
+ while (ret > 0)
{
- ft_check_err(line, len, wlist);
- mapL = (char*)ft_nrealloc(mapL, ((len + 1) * i) * sizeof(char), (((len + 1) * i) + ft_strlen(line) + 1) * sizeof(char));
- ft_linecpy(line, mapL, (len + 1) * i);
+ ret = get_next_line(fd, &line);
+ ft_check_err(line, len);
+ mapl = (char*)ft_nrealloc(mapl, (((len / 2) + 2) * i) * sizeof(char),
+ ((((len / 2) + 2) * i) + (ft_strlen(line) / 2) + 2) * sizeof(char));
+ ft_linecpy(line, mapl, ((len / 2) + 2) * i);
ft_memdel(line);
i++;
}
- mapL[(i * (len + 1)) - 1] = '\0';
- ft_printf("mapL [%s]\n", mapL);
- wlist->clist->map = ft_split(mapL, '\n');
- ft_memdel(mapL);
+ mapl[(i * ((len / 2) + 2)) - 1] = '\0';
+ ft_free_words(clist->map, NULL);
+ clist->map = ft_split(mapl, '\n');
+ ft_memdel(mapl);
return (0);
}
diff --git a/src/ft_get_res.c b/src/ft_get_res.c
index 337d3d7..66eb1df 100644
--- a/src/ft_get_res.c
+++ b/src/ft_get_res.c
@@ -2,7 +2,7 @@
#include <cub3d.h>
static void
-ft_checkdigit(const char *word, t_win *wlist)
+ft_checkdigit(const char *word, t_cub *clist)
{
size_t i;
@@ -10,11 +10,11 @@ ft_checkdigit(const char *word, t_win *wlist)
while (ft_isdigit(word[i]))
i++;
if (i != ft_strlen(word))
- ft_map_error(1, wlist);
+ ft_map_error(1, clist);
}
int
-ft_get_res(int fd, t_win *wlist)
+ft_get_res(int fd, t_cub *clist)
{
char *line;
char **words;
@@ -22,18 +22,18 @@ ft_get_res(int fd, t_win *wlist)
if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' ')))
{
ft_memdel(line);
- return (ft_map_error(1, wlist));
+ return (ft_map_error(1, clist));
}
if (!(*words) || ft_strcmp(*words, "R") || !(*(words + 1))
|| !(*(words + 2)) || (*(words + 3)))
{
ft_free_words(words, line);
- return (ft_map_error(1, wlist));
+ return (ft_map_error(1, clist));
}
- ft_checkdigit(words[1], wlist);
- ft_checkdigit(words[2], wlist);
- wlist->x_size = ft_atoi(words[1]);
- wlist->y_size = ft_atoi(words[2]);
+ ft_checkdigit(words[1], clist);
+ ft_checkdigit(words[2], clist);
+ clist->wlist->x_size = ft_atoi(words[1]);
+ clist->wlist->y_size = ft_atoi(words[2]);
ft_free_words(words, line);
return (0);
}
diff --git a/src/ft_get_sprite_tex.c b/src/ft_get_sprite_tex.c
index 308ff84..4db469a 100644
--- a/src/ft_get_sprite_tex.c
+++ b/src/ft_get_sprite_tex.c
@@ -3,7 +3,7 @@
#include <stdlib.h>
int
-ft_get_sprite_tex(int fd, t_win *wlist)
+ft_get_sprite_tex(int fd, t_cub *clist)
{
char *line;
char **words;
@@ -11,15 +11,15 @@ ft_get_sprite_tex(int fd, t_win *wlist)
if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' ')))
{
ft_memdel(line);
- return (ft_map_error(7, wlist));
+ return (ft_map_error(7, clist));
}
if (!(*words) || ft_strcmp(*words, "S") || !words[1] || words[2])
{
ft_free_words(words, line);
- return (ft_map_error(7, wlist));
+ return (ft_map_error(7, clist));
}
- ft_memdel(wlist->clist->sprite_path);
- if (!(wlist->clist->sprite_path = ft_strdup(*(words + 1))))
+ ft_memdel(clist->sprite_path);
+ if (!(clist->sprite_path = ft_strdup(*(words + 1))))
{
ft_free_words(words, line);
return (-1);
diff --git a/src/ft_get_tex.c b/src/ft_get_tex.c
index 4c80c89..1a936bd 100644
--- a/src/ft_get_tex.c
+++ b/src/ft_get_tex.c
@@ -3,7 +3,7 @@
#include <stdlib.h>
static int
-ft_get_tex_no(int fd, t_win *wlist)
+ft_get_tex_no(int fd, t_cub *clist)
{
char *line;
char **words;
@@ -11,16 +11,16 @@ ft_get_tex_no(int fd, t_win *wlist)
if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' ')))
{
ft_memdel(line);
- return (ft_map_error(2, wlist));
+ return (ft_map_error(2, clist));
}
if (!(*words) || ft_strcmp(*words, "NO")
|| !(*(words + 1)) || (*(words + 2)))
{
ft_free_words(words, line);
- return (ft_map_error(2, wlist));
+ return (ft_map_error(2, clist));
}
- ft_memdel(wlist->clist->no_tex_path);
- if (!(wlist->clist->no_tex_path = ft_strdup(*(words + 1))))
+ ft_memdel(clist->no_tex_path);
+ if (!(clist->no_tex_path = ft_strdup(*(words + 1))))
{
ft_free_words(words, line);
return (-1);
@@ -30,7 +30,7 @@ ft_get_tex_no(int fd, t_win *wlist)
}
static int
-ft_get_tex_so(int fd, t_win *wlist)
+ft_get_tex_so(int fd, t_cub *clist)
{
char *line;
char **words;
@@ -38,16 +38,16 @@ ft_get_tex_so(int fd, t_win *wlist)
if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' ')))
{
ft_memdel(line);
- return (ft_map_error(3, wlist));
+ return (ft_map_error(3, clist));
}
if (!(*words) || ft_strcmp(*words, "SO")
|| !(*(words + 1)) || (*(words + 2)))
{
ft_free_words(words, line);
- return (ft_map_error(3, wlist));
+ return (ft_map_error(3, clist));
}
- ft_memdel(wlist->clist->so_tex_path);
- if (!(wlist->clist->so_tex_path = ft_strdup(*(words + 1))))
+ ft_memdel(clist->so_tex_path);
+ if (!(clist->so_tex_path = ft_strdup(*(words + 1))))
{
ft_free_words(words, line);
return (-1);
@@ -57,7 +57,7 @@ ft_get_tex_so(int fd, t_win *wlist)
}
static int
-ft_get_tex_we(int fd, t_win *wlist)
+ft_get_tex_we(int fd, t_cub *clist)
{
char *line;
char **words;
@@ -65,16 +65,16 @@ ft_get_tex_we(int fd, t_win *wlist)
if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' ')))
{
ft_memdel(line);
- return (ft_map_error(4, wlist));
+ return (ft_map_error(4, clist));
}
if (!(*words) || ft_strcmp(*words, "WE")
|| !(*(words + 1)) || (*(words + 2)))
{
ft_free_words(words, line);
- return (ft_map_error(4, wlist));
+ return (ft_map_error(4, clist));
}
- ft_memdel(wlist->clist->we_tex_path);
- if (!(wlist->clist->we_tex_path = ft_strdup(*(words + 1))))
+ ft_memdel(clist->we_tex_path);
+ if (!(clist->we_tex_path = ft_strdup(*(words + 1))))
{
ft_free_words(words, line);
return (-1);
@@ -84,7 +84,7 @@ ft_get_tex_we(int fd, t_win *wlist)
}
static int
-ft_get_tex_ea(int fd, t_win *wlist)
+ft_get_tex_ea(int fd, t_cub *clist)
{
char *line;
char **words;
@@ -92,16 +92,16 @@ ft_get_tex_ea(int fd, t_win *wlist)
if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' ')))
{
ft_memdel(line);
- return (ft_map_error(5, wlist));
+ return (ft_map_error(5, clist));
}
if (!(*words) || ft_strcmp(*words, "EA")
|| !(*(words + 1)) || (*(words + 2)))
{
ft_free_words(words, line);
- return (ft_map_error(5, wlist));
+ return (ft_map_error(5, clist));
}
- ft_memdel(wlist->clist->ea_tex_path);
- if (!(wlist->clist->ea_tex_path = ft_strdup(*(words + 1))))
+ ft_memdel(clist->ea_tex_path);
+ if (!(clist->ea_tex_path = ft_strdup(*(words + 1))))
{
ft_free_words(words, line);
return (-1);
@@ -111,12 +111,12 @@ ft_get_tex_ea(int fd, t_win *wlist)
}
int
-ft_get_tex(int fd, t_win *wlist)
+ft_get_tex(int fd, t_cub *clist)
{
- if (ft_get_tex_no(fd, wlist) < 0 ||
- ft_get_tex_so(fd, wlist) < 0 ||
- ft_get_tex_we(fd, wlist) < 0 ||
- ft_get_tex_ea(fd, wlist) < 0)
+ if (ft_get_tex_no(fd, clist) < 0 ||
+ ft_get_tex_so(fd, clist) < 0 ||
+ ft_get_tex_we(fd, clist) < 0 ||
+ ft_get_tex_ea(fd, clist) < 0)
return (-1);
return (0);
}
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index b395840..3554e5e 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -37,5 +37,6 @@ t_cub
if (!(clist->map[0] = (char*)ft_calloc(1, sizeof(char))))
return (NULL);
clist->map[1] = 0;
+ clist->map_width = 0;
return (clist);
}
diff --git a/src/ft_init_winlx.c b/src/ft_init_winlx.c
index a4b7208..931e19b 100644
--- a/src/ft_init_winlx.c
+++ b/src/ft_init_winlx.c
@@ -4,17 +4,19 @@
#include <stdlib.h>
int
-ft_init_winlx(t_win *wlist)
+ft_init_winlx(t_cub *clist)
{
- ft_memdel(wlist->wlx);
- if (!(wlist->wlx = mlx_init()))
+ ft_memdel(clist->wlist->wlx);
+ if (!(clist->wlist->wlx = mlx_init()))
return (-1);
- ft_memdel(wlist->winptr);
- if (!(wlist->winptr = (void*)malloc(wlist->x_size * wlist->y_size)))
+ ft_memdel(clist->wlist->winptr);
+ if (!(clist->wlist->winptr = malloc(clist->wlist->x_size
+ * clist->wlist->y_size)))
return (-1);
- if (!(wlist->winptr = mlx_new_window(wlist->wlx, wlist->x_size,\
- wlist->y_size, "Cub3D")))
+ if (!(clist->wlist->winptr = mlx_new_window(clist->wlist->wlx,
+ clist->wlist->x_size, clist->wlist->y_size, "Cub3D")))
return (-1);
- ft_printf("Created window of size %dx%d\n", wlist->x_size, wlist->y_size);
+ ft_printf("Created window of size %dx%d\n",
+ clist->wlist->x_size, clist->wlist->y_size);
return (0);
}
diff --git a/src/ft_key_events.c b/src/ft_key_events.c
index 8c8167a..7b3cdf2 100644
--- a/src/ft_key_events.c
+++ b/src/ft_key_events.c
@@ -46,6 +46,6 @@ ft_key_event(int keycode, void *param)
(keycode == FT_D_KEY) ? (keycode = 3) : 0;
(keycode <= 3) ? ((*fun_ptr[keycode])()) : 0;
if (keycode == FT_ESC_KEY)
- ft_exit(0, ((t_win*)param));
+ ft_exit(0, ((t_cub*)param));
return (0);
}
diff --git a/src/ft_map_error.c b/src/ft_map_error.c
index 2e8a9ff..df7a2fc 100644
--- a/src/ft_map_error.c
+++ b/src/ft_map_error.c
@@ -3,9 +3,9 @@
#include <unistd.h>
int
-ft_map_error(unsigned int linum, t_win *wlist)
+ft_map_error(unsigned int linum, t_cub *clist)
{
ft_dprintf(STDERR_FILENO, "Error\n");
ft_dprintf(STDERR_FILENO, "\033[1;31mMap error: line %d\033[0m\n", linum);
- return (ft_exit(1, wlist));
+ return (ft_exit(1, clist));
}
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index 70b81d4..1f31ca1 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -5,7 +5,7 @@
#include <unistd.h>
static void
-ft_check_cub(const char *map_path, t_win *wlist)
+ft_check_cub(const char *map_path, t_cub *clist)
{
char **words;
size_t i;
@@ -15,7 +15,7 @@ ft_check_cub(const char *map_path, t_win *wlist)
ft_dprintf(STDERR_FILENO, "Error\n");
ft_dprintf(STDERR_FILENO, "\033[31;1mMap is not a .cub\033[0m\n");
ft_free_words(words, NULL);
- ft_exit(2, wlist);
+ ft_exit(2, clist);
}
i = 0;
while (words[i])
@@ -25,7 +25,7 @@ ft_check_cub(const char *map_path, t_win *wlist)
ft_dprintf(STDERR_FILENO, "Error\n");
ft_dprintf(STDERR_FILENO, "\033[31;1mMap is not a .cub\033[0m\n");
ft_free_words(words, NULL);
- ft_exit(2, wlist);
+ ft_exit(2, clist);
}
ft_free_words(words, NULL);
}
@@ -35,26 +35,27 @@ ft_check_cub(const char *map_path, t_win *wlist)
*/
void
-ft_parse_map(const char *map_path, t_win *wlist)
+ft_parse_map(const char *map_path, t_cub *clist)
{
int fd;
- ft_check_cub(map_path, wlist);
+ ft_check_cub(map_path, clist);
fd = open(map_path, O_RDONLY);
if (fd < 0)
{
ft_dprintf(STDERR_FILENO, "Error\n");
ft_dprintf(STDERR_FILENO, "\033[31;1mNo map\033[0m\n");
- ft_exit(2, wlist);
+ ft_exit(2, clist);
}
- ft_get_res(fd, wlist);
- if (ft_get_tex(fd, wlist) < 0)
+ ft_get_res(fd, clist);
+ if (ft_get_tex(fd, clist) < 0)
return ;
- ft_check_empty_line(fd, 6, wlist);
- if (ft_get_sprite_tex(fd, wlist) < 0)
+ ft_check_empty_line(fd, 6, clist);
+ if (ft_get_sprite_tex(fd, clist) < 0)
return ;
- ft_get_colors(fd, wlist);
- ft_print_list(wlist);
- ft_check_empty_line(fd, 10, wlist);
- ft_get_map(fd, wlist);
+ ft_get_colors(fd, clist);
+ ft_check_empty_line(fd, 10, clist);
+ if (ft_get_map(fd, clist) < 0)
+ ft_map_error(11, clist);
+ ft_print_list(clist);
}
diff --git a/src/ft_print_list.c b/src/ft_print_list.c
index f038740..e48b2a2 100644
--- a/src/ft_print_list.c
+++ b/src/ft_print_list.c
@@ -2,23 +2,24 @@
#include <cub3d.h>
void
-ft_print_list(t_win *wlist)
+ft_print_list(t_cub *clist)
{
size_t i;
- ft_printf("x size [%d]\n", wlist->x_size);
- ft_printf("y size [%d]\n", wlist->y_size);
- ft_printf("North - [%s]\n", wlist->clist->no_tex_path);
- ft_printf("South - [%s]\n", wlist->clist->so_tex_path);
- ft_printf("West -- [%s]\n", wlist->clist->we_tex_path);
- ft_printf("East -- [%s]\n", wlist->clist->ea_tex_path);
- ft_printf("Sprite [%s]\n", wlist->clist->sprite_path);
- ft_printf("F color [%d]\n", wlist->clist->f_color);
- ft_printf("C color [%d]\n", wlist->clist->c_color);
+ ft_printf("x size [%d]\n", clist->wlist->x_size);
+ ft_printf("y size [%d]\n", clist->wlist->y_size);
+ ft_printf("North - [%s]\n", clist->no_tex_path);
+ ft_printf("South - [%s]\n", clist->so_tex_path);
+ 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);
i = 0;
- while (wlist->clist->map[i])
+ ft_printf("Map\n----\n");
+ while (clist->map[i])
{
- ft_printf("Map Line %zu [%s]\n", i + 1, wlist->clist->map[i]);
+ ft_printf("%2zu [%s]\n", i + 1, clist->map[i]);
i++;
}
}
diff --git a/src/main.c b/src/main.c
index d80866b..bca23ce 100644
--- a/src/main.c
+++ b/src/main.c
@@ -5,20 +5,24 @@
int
main(void)
{
- t_win *wlist;
+ t_cub *clist;
- if (!(wlist = ft_init_win()))
+ if (!(clist = ft_init_cub()))
+ {
+ ft_memdel(clist);
return (1);
- if (!(wlist->clist = ft_init_cub()))
+ }
+ if (!(clist->wlist = ft_init_win()))
{
- ft_memdel(wlist);
+ ft_memdel(clist->wlist);
+ ft_memdel(clist);
return (1);
}
- ft_parse_map("map/map_one.cub", wlist);
- if (ft_init_winlx(wlist) < 0)
- return (ft_exit(3, wlist));
- mlx_key_hook(wlist->winptr, ft_key_event, wlist);
- ft_drawsquare(80, 80, wlist->clist->f_color, wlist);
- mlx_loop(wlist->wlx);
+ ft_parse_map("map/map_one.cub", clist);
+ if (ft_init_winlx(clist) < 0)
+ return (ft_exit(3, clist));
+ mlx_key_hook(clist->wlist->winptr, ft_key_event, clist);
+ ft_drawsquare(80, 80, clist->f_color, clist);
+ mlx_loop(clist->wlist->wlx);
return (0);
}