aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ft_check_missing.c4
-rw-r--r--src/ft_exit.c17
-rw-r--r--src/ft_get_colors.c14
-rw-r--r--src/ft_get_path_nl.c4
-rw-r--r--src/ft_get_res.c24
-rw-r--r--src/ft_get_tex_nl.c2
-rw-r--r--src/ft_parse_map.c7
-rw-r--r--src/ft_select_get.c3
-rw-r--r--src/ft_warp_level.c18
9 files changed, 58 insertions, 35 deletions
diff --git a/src/ft_check_missing.c b/src/ft_check_missing.c
index 7353a0e..4828250 100644
--- a/src/ft_check_missing.c
+++ b/src/ft_check_missing.c
@@ -46,5 +46,9 @@ int
return (ft_missing_error(FT_ERR_MISS_CEIL_C, clist));
else if (clist->plist->pos_x == 0 || clist->plist->pos_y == 0)
return (ft_missing_error(FT_ERR_MISS_PLAYER_SPAWN, clist));
+ else if (clist->mlist->isnlvl && !clist->mlist->nl_tex_path[0])
+ return (ft_missing_error(FT_ERR_MISS_NLVL, clist));
+ else if (clist->mlist->isnlvl && !clist->mlist->nlevel_path[0])
+ return (ft_missing_error(FT_ERR_MISS_NLVL_PATH, clist));
return (0);
}
diff --git a/src/ft_exit.c b/src/ft_exit.c
index 6457191..4914803 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -43,12 +43,17 @@ int
{
if (clist->wlist->inited)
{
- mlx_destroy_image(clist->wlist->wlx, clist->tlist[0].img);
- mlx_destroy_image(clist->wlist->wlx, clist->tlist[1].img);
- mlx_destroy_image(clist->wlist->wlx, clist->tlist[2].img);
- mlx_destroy_image(clist->wlist->wlx, clist->tlist[3].img);
- mlx_destroy_image(clist->wlist->wlx, clist->tlist[4].img);
- if (clist->mlist->isnlvl)
+ if (clist->tlist[0].img)
+ mlx_destroy_image(clist->wlist->wlx, clist->tlist[0].img);
+ if (clist->tlist[1].img)
+ mlx_destroy_image(clist->wlist->wlx, clist->tlist[1].img);
+ if (clist->tlist[2].img)
+ mlx_destroy_image(clist->wlist->wlx, clist->tlist[2].img);
+ if (clist->tlist[3].img)
+ mlx_destroy_image(clist->wlist->wlx, clist->tlist[3].img);
+ if (clist->tlist[4].img)
+ mlx_destroy_image(clist->wlist->wlx, clist->tlist[4].img);
+ if (clist->mlist->isnlvl && clist->tlist[5].img)
mlx_destroy_image(clist->wlist->wlx, clist->tlist[5].img);
mlx_destroy_window(clist->wlist->wlx, clist->wlist->winptr);
}
diff --git a/src/ft_get_colors.c b/src/ft_get_colors.c
index 96be925..69eb8f8 100644
--- a/src/ft_get_colors.c
+++ b/src/ft_get_colors.c
@@ -30,7 +30,7 @@ static int8_t
if (i != ft_strlen(num[j]))
{
ft_free_words(num);
- ft_sprintf(clist->errmsg, "%s", FT_ERR_COLOR_ALPHA);
+ ft_sprintf(clist->errmsg, FT_ERR_COLOR_ALPHA);
return (-1);
}
i = 0;
@@ -45,7 +45,7 @@ static int8_t
if (ft_atoi(num[0]) > 255 || ft_atoi(num[1]) > 255
|| ft_atoi(num[2]) > 255)
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_COLOR_MAX);
+ ft_sprintf(clist->errmsg, FT_ERR_COLOR_MAX);
ft_free_words(num);
return (-1);
}
@@ -57,7 +57,7 @@ static int8_t
{
if (!num[0] || !num[1] || !num[2] || num[3])
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_COLOR_ARGS);
+ ft_sprintf(clist->errmsg, FT_ERR_COLOR_ARGS);
ft_free_words(num);
return (-1);
}
@@ -71,12 +71,12 @@ int8_t
if (!(*words) || !words[1] || words[2])
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_ARGS);
+ ft_sprintf(clist->errmsg, FT_ERR_ARGS);
return (-1);
}
if (!(num = ft_split(words[1], ',')))
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);
+ ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE);
return (-1);
}
if (ft_check_nums_amount(num, clist) < 0)
@@ -99,12 +99,12 @@ int8_t
if (!(*words) || !words[1] || words[2])
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_ARGS);
+ ft_sprintf(clist->errmsg, FT_ERR_ARGS);
return (-1);
}
if (!(num = ft_split(words[1], ',')))
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);
+ ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE);
return (-1);
}
if (ft_check_nums_amount(num, clist) < 0)
diff --git a/src/ft_get_path_nl.c b/src/ft_get_path_nl.c
index 7227f63..f826070 100644
--- a/src/ft_get_path_nl.c
+++ b/src/ft_get_path_nl.c
@@ -24,7 +24,7 @@ int8_t
}
if (ft_check_ext(*(words + 1), ".cub") < 0)
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM);
+ ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_CUB);
return (-1);
}
ft_memdel((void**)&clist->mlist->nlevel_path);
@@ -35,7 +35,7 @@ int8_t
}
if (ft_check_not_found(clist->mlist->nlevel_path) < 0)
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_RD_NO);
+ ft_sprintf(clist->errmsg, "%s", FT_ERR_RD_NL_MAP);
return (-1);
}
return (0);
diff --git a/src/ft_get_res.c b/src/ft_get_res.c
index 9bcf4ef..e7b38c9 100644
--- a/src/ft_get_res.c
+++ b/src/ft_get_res.c
@@ -24,7 +24,7 @@ static int8_t
i++;
if (i != ft_strlen(word))
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_RES_ALPHA);
+ ft_sprintf(clist->errmsg, FT_ERR_RES_ALPHA);
return (-1);
}
return (0);
@@ -39,18 +39,28 @@ static void
wl->y_size -= 1;
}
+static int8_t
+ft_check_res_args(char **words, t_cub *clist)
+{
+ if (!(*words + 0) || !(*(words + 1)) ||
+ !(*(words + 2)) || (*(words + 3)))
+ {
+ ft_sprintf(clist->errmsg, FT_ERR_ARGS);
+ return (-1);
+ }
+ return (0);
+}
+
int8_t
ft_get_res(char **words, t_cub *clist)
{
t_win *wlist;
wlist = clist->wlist;
- if (!(*words + 0) || !(*(words + 1)) ||
- !(*(words + 2)) || (*(words + 3)))
- {
- ft_sprintf(clist->errmsg, "%s", FT_ERR_ARGS);
+ if (clist->currlvl > 0)
+ return (0);
+ if (ft_check_res_args(words, clist) < 0)
return (-1);
- }
if ((ft_checkdigit(words[1], clist) < 0) ||
(ft_checkdigit(words[2], clist) < 0))
return (-1);
@@ -59,7 +69,7 @@ int8_t
if (wlist->x_size <= 10
|| wlist->y_size <= 10)
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_RES_SMALL);
+ ft_sprintf(clist->errmsg, FT_ERR_RES_SMALL);
return (-1);
}
if (ft_get_screen_size(wlist) < 0)
diff --git a/src/ft_get_tex_nl.c b/src/ft_get_tex_nl.c
index 77a309a..00155de 100644
--- a/src/ft_get_tex_nl.c
+++ b/src/ft_get_tex_nl.c
@@ -35,7 +35,7 @@ int8_t
}
if (ft_check_not_found(clist->mlist->nl_tex_path) < 0)
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_RD_NO);
+ ft_sprintf(clist->errmsg, FT_ERR_RD_NL_TEX);
return (-1);
}
return (0);
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index afb1d88..c2fb593 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -100,10 +100,7 @@ void
ft_get_player_spawn(clist->plist, clist);
ft_get_nlvl_pos(clist->mlist);
ft_check_missing(clist);
- if (clist->currlvl == 0)
- {
- ft_set_minimap_scale(clist);
- clist->currlvl += 1;
- }
+ ft_set_minimap_scale(clist);
+ clist->currlvl += 1;
close(fd);
}
diff --git a/src/ft_select_get.c b/src/ft_select_get.c
index 4ec1a45..c6251c2 100644
--- a/src/ft_select_get.c
+++ b/src/ft_select_get.c
@@ -20,7 +20,8 @@ static int8_t
{
if (ret == 12)
return (12);
- if (ret == 0 && (clist->wlist->x_size != 0 || clist->wlist->y_size != 0))
+ if (ret == 0 && clist->currlvl == 0 &&
+ (clist->wlist->x_size != 0 || clist->wlist->y_size != 0))
return (-1);
else if (ret == 1 && (clist->mlist->no_tex_path[0]))
return (-1);
diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c
index 4e2a258..cfacd81 100644
--- a/src/ft_warp_level.c
+++ b/src/ft_warp_level.c
@@ -13,6 +13,7 @@
#include <libft.h>
#include <cub3d.h>
#include <stdlib.h>
+#include <stddef.h>
#include <stdint.h>
#include <mlx.h>
@@ -36,10 +37,6 @@ static void
{
cl->plist->pos_x = 0;
cl->plist->pos_y = 0;
- cl->wlist->x_size = 0;
- cl->wlist->y_size = 0;
- cl->f_rgb = ft_init_rgb();
- cl->c_rgb = ft_init_rgb();
cl->plist->start_x = 0;
cl->plist->start_y = 0;
cl->plist->cam_x = 0;
@@ -47,12 +44,21 @@ static void
cl->plist->dir_y = 0;
cl->plist->plane_x = 0;
cl->plist->plane_y = 0.66666666;
+ cl->f_rgb = ft_init_rgb();
+ cl->c_rgb = ft_init_rgb();
+ cl->rlist = ft_init_s_ray();
mlx_destroy_image(cl->wlist->wlx, cl->tlist[0].img);
mlx_destroy_image(cl->wlist->wlx, cl->tlist[1].img);
mlx_destroy_image(cl->wlist->wlx, cl->tlist[2].img);
mlx_destroy_image(cl->wlist->wlx, cl->tlist[3].img);
mlx_destroy_image(cl->wlist->wlx, cl->tlist[4].img);
mlx_destroy_image(cl->wlist->wlx, cl->tlist[5].img);
+ cl->tlist[0].img = NULL;
+ cl->tlist[1].img = NULL;
+ cl->tlist[2].img = NULL;
+ cl->tlist[3].img = NULL;
+ cl->tlist[4].img = NULL;
+ cl->tlist[5].img = NULL;
}
int8_t
@@ -60,8 +66,8 @@ int8_t
{
char *next_path;
- if ((uint32_t)cl->plist->pos_x == cl->mlist->nlx
- && (uint32_t)cl->plist->pos_y == cl->mlist->nly)
+ if ((uint32_t)cl->plist->pos_x == cl->mlist->nlx &&
+ (uint32_t)cl->plist->pos_y == cl->mlist->nly)
{
if (!(next_path = (char *)malloc((ft_strlen(
cl->mlist->nlevel_path) + 1) * sizeof(char))))