aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile17
-rw-r--r--inc/cub3d.h1
-rw-r--r--inc/cub3d_structs.h2
-rw-r--r--libft/Makefile11
-rw-r--r--map/map_one.cub2
-rw-r--r--src/ft_del_extra_sprites.c4
-rw-r--r--src/ft_draw_scene.c2
-rw-r--r--src/ft_exit.c61
-rw-r--r--src/ft_floor_cast.c30
-rw-r--r--src/ft_free_words.c8
-rw-r--r--src/ft_get_map.c18
-rw-r--r--src/ft_get_music.c4
-rw-r--r--src/ft_get_path_nl.c2
-rw-r--r--src/ft_get_skybox.c2
-rw-r--r--src/ft_get_sprite.c2
-rw-r--r--src/ft_get_sprite_spawns.c5
-rw-r--r--src/ft_get_tex.c8
-rw-r--r--src/ft_get_tex_extra.c4
-rw-r--r--src/ft_get_tex_nl.c2
-rw-r--r--src/ft_get_traps.c2
-rw-r--r--src/ft_init_lists.c4
-rw-r--r--src/ft_init_map.c4
-rw-r--r--src/ft_init_sprites.c34
-rw-r--r--src/ft_init_winlx.c2
-rw-r--r--src/ft_key_loop.c3
-rw-r--r--src/ft_parse_map.c8
-rw-r--r--src/ft_raycasting.c6
-rw-r--r--src/ft_save_to_bmp.c10
-rw-r--r--src/ft_warp_level.c48
-rw-r--r--src/main.c17
30 files changed, 199 insertions, 124 deletions
diff --git a/Makefile b/Makefile
index 6805531..fa28732 100644
--- a/Makefile
+++ b/Makefile
@@ -99,6 +99,7 @@ SRCS_NAME += ft_sfx_pain.c
SRCS_NAME += ft_sfx_trap.c
SRCS_NAME += ft_death_screen.c
SRCS_NAME += ft_death_hooks.c
+SRCS_NAME += ft_init_sprites.c
#--------------------------------------------------------------------------------------------------#
SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME})
#--------------------------------------------------------------------------------------------------#
@@ -121,7 +122,11 @@ endif
#==================================================================================================#
#------------------------------------------ Compiler ----------------------------------------------#
#==================================================================================================#
-DEBUG = -glldb
+ifeq (${OS}, Darwin)
+ DBG = -glldb
+else
+ DBG = -ggdb
+endif
FSANITIZE = -fsanitize=address
#--------------------------------------------------------------------------------------------------#
ifeq (${OS}, Darwin)
@@ -136,8 +141,12 @@ CFLAGS += -Wextra
CFLAGS += -Werror
CFLAGS += -pedantic
#--------------------------------------------------------------------------------------------------#
+ifdef DEBUG
+ CFLAGS += ${DBG}
+endif
+#--------------------------------------------------------------------------------------------------#
ifdef ASAN
- CFLAGS += ${DEBUG}
+ CFLAGS += ${DBG}
CFLAGS += ${FSANITIZE}
endif
#--------------------------------------------------------------------------------------------------#
@@ -201,8 +210,10 @@ endif
#--------------------------------------------------------------------------------------------------#
re: fclean all
#--------------------------------------------------------------------------------------------------#
+bonus: all
+#--------------------------------------------------------------------------------------------------#
run: all
@./${NAME} "map/map_one.cub"
#--------------------------------------------------------------------------------------------------#
-.PHONY: all clean clean fclean re run default
+.PHONY: all clean clean fclean re bonus run default
#============================================== EOF ===============================================#
diff --git a/inc/cub3d.h b/inc/cub3d.h
index aafe288..5371305 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -35,6 +35,7 @@ t_bmp_file ft_init_bmp(void);
t_bmp_info ft_init_bmp_info(void);
t_rgb ft_hex_to_og_rgb(uint32_t color);
int8_t ft_init_sfx(t_sfx *sfx);
+int8_t ft_init_sprites(t_sprite ***sprites);
/*
** ====== HOOKS ======
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index 2d1d00d..92d928d 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -250,7 +250,7 @@ typedef struct s_cub
struct s_rgb f_rgb;
struct s_rgb c_rgb;
struct s_img tlist[16];
- struct s_sprite sprites[8][4096];
+ struct s_sprite **sprites;
struct s_sprite traps[512];
struct s_sfx sfx;
} t_cub;
diff --git a/libft/Makefile b/libft/Makefile
index 502c38a..3073304 100644
--- a/libft/Makefile
+++ b/libft/Makefile
@@ -118,7 +118,11 @@ OS = $(shell uname)
#==============================================================================#
#-------------------------------- Compiler ------------------------------------#
#==============================================================================#
-DEBUG = -glldb
+ifeq (${OS}, Darwin)
+ DBG = -glldb
+else
+ DBG = -ggdb
+endif
FSANITIZE = -fsanitize=address
#------------------------------------------------------------------------------#
ifeq (${OS}, Darwin)
@@ -132,9 +136,12 @@ CFLAGS += -Wall
CFLAGS += -Wextra
CFLAGS += -Werror
CFLAGS += -pedantic
+ifdef DEBUG
+ CFLAGS += ${DBG}
+endif
#------------------------------------------------------------------------------#
ifdef ASAN
- CFLAGS += ${DEBUG}
+ CFLAGS += ${DBG}
CFLAGS += ${FSANITIZE}
endif
#------------------------------------------------------------------------------#
diff --git a/map/map_one.cub b/map/map_one.cub
index f3dc29b..3dad2cc 100644
--- a/map/map_one.cub
+++ b/map/map_one.cub
@@ -19,7 +19,7 @@ T ./media/img/spikes.xpm
SH 2
111111111111111111
140000000000300001
-1000E0T00000000001
+1000E0000000000001
100100000000300001
101100000111000001
111111111111110011
diff --git a/src/ft_del_extra_sprites.c b/src/ft_del_extra_sprites.c
index 91d09a2..21df608 100644
--- a/src/ft_del_extra_sprites.c
+++ b/src/ft_del_extra_sprites.c
@@ -24,8 +24,8 @@ void
i = 1;
while ((i + 2) <= cl->mlist.topsp)
{
- if (cl->tlist[i + 9].img)
- mlx_destroy_image(cl->wlist.wlx, cl->tlist[i + 9].img);
+ if (cl->tlist[i + 7].img)
+ mlx_destroy_image(cl->wlist.wlx, cl->tlist[i + 7].img);
i++;
}
}
diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c
index a9ea6c5..c7b07a1 100644
--- a/src/ft_draw_scene.c
+++ b/src/ft_draw_scene.c
@@ -35,7 +35,7 @@ static int8_t
(uint32_t)x, y,
0x002288da,
str);
- ft_memdel((void**)&str);
+ ft_memdel((void*)&str);
return (0);
}
diff --git a/src/ft_exit.c b/src/ft_exit.c
index c3b5ebf..61f925e 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -19,33 +19,48 @@
#include <pthread.h>
static void
+ ft_free_some_extras(t_cub *clist)
+{
+ uint8_t i;
+
+ i = 0;
+ while (i < 8)
+ {
+ ft_memdel((void*)&clist->sprites[i]);
+ i++;
+ }
+ ft_memdel((void*)&clist->sprites);
+ ft_memdel((void*)&clist);
+}
+
+static void
ft_free_lists(t_cub *clist)
{
- ft_memdel((void**)&clist->mlist.filename);
- ft_memdel((void**)&clist->mlist.no_tex_path);
- ft_memdel((void**)&clist->mlist.so_tex_path);
- ft_memdel((void**)&clist->mlist.ea_tex_path);
- ft_memdel((void**)&clist->mlist.we_tex_path);
- ft_memdel((void**)&clist->mlist.nl_tex_path);
- ft_memdel((void**)&clist->mlist.fl_tex_path);
- ft_memdel((void**)&clist->mlist.ce_tex_path);
- ft_memdel((void**)&clist->mlist.nlevel_path);
- ft_memdel((void**)&clist->mlist.skybox_path);
- ft_memdel((void**)&clist->mlist.traps_path);
- ft_memdel((void**)&clist->mlist.music_path);
- ft_memdel((void**)&clist->mlist.music_cmd);
- ft_memdel((void**)&clist->mlist.mapl);
+ ft_memdel((void*)&clist->mlist.filename);
+ ft_memdel((void*)&clist->mlist.no_tex_path);
+ ft_memdel((void*)&clist->mlist.so_tex_path);
+ ft_memdel((void*)&clist->mlist.ea_tex_path);
+ ft_memdel((void*)&clist->mlist.we_tex_path);
+ ft_memdel((void*)&clist->mlist.nl_tex_path);
+ ft_memdel((void*)&clist->mlist.fl_tex_path);
+ ft_memdel((void*)&clist->mlist.ce_tex_path);
+ ft_memdel((void*)&clist->mlist.nlevel_path);
+ ft_memdel((void*)&clist->mlist.skybox_path);
+ ft_memdel((void*)&clist->mlist.traps_path);
+ ft_memdel((void*)&clist->mlist.music_path);
+ ft_memdel((void*)&clist->mlist.music_cmd);
+ ft_memdel((void*)&clist->mlist.mapl);
ft_free_words(clist->mlist.map);
- ft_memdel((void**)&clist->sfx.death);
- ft_memdel((void**)&clist->sfx.footstep_one);
- ft_memdel((void**)&clist->sfx.footstep_two);
- ft_memdel((void**)&clist->sfx.new_lvl);
- ft_memdel((void**)&clist->sfx.pain_one);
- ft_memdel((void**)&clist->sfx.pain_two);
- ft_memdel((void**)&clist->sfx.trap);
+ ft_memdel((void*)&clist->sfx.death);
+ ft_memdel((void*)&clist->sfx.footstep_one);
+ ft_memdel((void*)&clist->sfx.footstep_two);
+ ft_memdel((void*)&clist->sfx.new_lvl);
+ ft_memdel((void*)&clist->sfx.pain_one);
+ ft_memdel((void*)&clist->sfx.pain_two);
+ ft_memdel((void*)&clist->sfx.trap);
ft_free_sprites(clist->mlist.sprite_path);
if (!clist->wlist.inited)
- ft_memdel((void**)&clist->wlist.winptr);
+ ft_memdel((void*)&clist->wlist.winptr);
}
static void
@@ -107,10 +122,10 @@ int
if (FT_OS == 1)
mlx_destroy_image(clist->wlist.wlx, clist->img.img);
mlx_destroy_window(clist->wlist.wlx, clist->wlist.winptr);
- clist->wlist.winptr = NULL;
}
ft_cancel_threads(clist);
ft_free_lists(clist);
+ ft_free_some_extras(clist);
ft_printf("Exiting program\n");
exit(exit_code);
return (0);
diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c
index 2eda9d8..92dcb07 100644
--- a/src/ft_floor_cast.c
+++ b/src/ft_floor_cast.c
@@ -25,23 +25,21 @@ static void
{
float dist;
float calc;
+ t_rgb rgb;
- if ((dist = cl->rlist.row_dist) <= 0)
- dist = 0.0001;
+ dist = (cl->rlist.row_dist > 0) ? (cl->rlist.row_dist) : (0.0001);
calc = (dist * 0.1 * cl->mlist.darklvl);
calc = (calc >= 255) ? (255) : (calc);
calc = (calc < 1) ? (1) : (calc);
calc = (cl->mlist.darklvl > 0) ? (calc) : (1);
- cl->img.ptr[x * 4 + (cl->img.sizeline * y)] =
- (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 *
- cl->tlist[tid].img_h * cl->tlist[tid].tex_y] / calc;
- cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] =
- (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 *
- cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 1] / calc;
- cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] =
- (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 *
+ rgb.r = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 *
cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 2] / calc;
- cl->img.ptr[x * 4 + cl->wlist.x_size * y + 3] = (char)0;
+ rgb.g = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 *
+ cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 1] / calc;
+ rgb.b = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 *
+ cl->tlist[tid].img_h * cl->tlist[tid].tex_y] / calc;
+ *(int*)(cl->img.ptr +
+ (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(rgb);
}
static void
@@ -88,12 +86,12 @@ void
uint16_t y;
rl = &cl->rlist;
- y = (cl->wlist.y_size / 2) + 1;
- while (++y < cl->wlist.y_size)
+ y = (cl->wlist.y_size / 2);
+ while (y < cl->wlist.y_size)
{
ft_floor_cast_inits(y, rl, cl);
- x = -1;
- while (++x < cl->wlist.x_size)
+ x = 0;
+ while (x < cl->wlist.x_size)
{
if (cl->rlist.wall_bz[x] <= y)
{
@@ -101,6 +99,8 @@ void
}
rl->x_floor += cl->mlist.x_floor_step;
rl->y_floor += cl->mlist.y_floor_step;
+ x++;
}
+ y++;
}
}
diff --git a/src/ft_free_words.c b/src/ft_free_words.c
index a90b959..3ca01c8 100644
--- a/src/ft_free_words.c
+++ b/src/ft_free_words.c
@@ -20,10 +20,10 @@ uint8_t
i = 0;
while (i < 9)
{
- ft_memdel((void**)&sprites[i]);
+ ft_memdel((void*)&sprites[i]);
i++;
}
- ft_memdel((void**)&sprites);
+ ft_memdel((void*)&sprites);
return (0);
}
@@ -35,9 +35,9 @@ uint8_t
i = 0;
while (words[i])
{
- ft_memdel((void**)&words[i]);
+ ft_memdel((void*)&words[i]);
i++;
}
- ft_memdel((void**)&words);
+ ft_memdel((void*)&words);
return (0);
}
diff --git a/src/ft_get_map.c b/src/ft_get_map.c
index 08c9734..8602ce3 100644
--- a/src/ft_get_map.c
+++ b/src/ft_get_map.c
@@ -58,22 +58,22 @@ int
clist->mlist.map_start = clist->mlist.line_chk;
if (!line[0])
{
- ft_memdel((void**)&line);
+ ft_memdel((void*)&line);
ft_sprintf(clist->errmsg, FT_ERR_READ);
return (-1);
}
if (ft_check_map_line(line, 1, clist) < 0)
{
- ft_memdel((void**)&line);
+ ft_memdel((void*)&line);
return (-1);
}
- ft_memdel((void**)&clist->mlist.mapl);
+ ft_memdel((void*)&clist->mlist.mapl);
if (ft_cat_mapl(line, clist) < 0)
{
- ft_memdel((void**)&line);
+ ft_memdel((void*)&line);
return (-1);
}
- ft_memdel((void**)&line);
+ ft_memdel((void*)&line);
return (1);
}
@@ -92,17 +92,17 @@ int
{
if (!line[0])
ft_sprintf(clist->errmsg, FT_ERR_MAP_EMPL);
- ft_memdel((void**)&line);
+ ft_memdel((void*)&line);
return (-1);
}
- ft_memdel((void**)&line);
+ ft_memdel((void*)&line);
}
- ft_memdel((void**)&line);
+ ft_memdel((void*)&line);
clist->mlist.mapl[clist->mlist.mapl_len - 1] = '\0';
ft_free_words(clist->mlist.map);
clist->mlist.map = ft_split(clist->mlist.mapl, '\n');
clist->mlist.map_h = ft_get_map_h(clist->mlist.map);
clist->mlist.map_w = ft_get_map_w(clist->mlist.map);
- ft_memdel((void**)&clist->mlist.mapl);
+ ft_memdel((void*)&clist->mlist.mapl);
return (0);
}
diff --git a/src/ft_get_music.c b/src/ft_get_music.c
index 7e6c6be..cf105a3 100644
--- a/src/ft_get_music.c
+++ b/src/ft_get_music.c
@@ -22,7 +22,7 @@ static int8_t
len = ft_strlen(mlist->music_path);
len += ft_strlen(FT_SND_CMD) - 2;
- ft_memdel((void**)&mlist->music_cmd);
+ ft_memdel((void*)&mlist->music_cmd);
if (!(mlist->music_cmd = (char *)malloc((len + 1) * sizeof(char))))
return (-1);
ft_sprintf(mlist->music_cmd, FT_SND_CMD,
@@ -43,7 +43,7 @@ int8_t
ft_sprintf(clist->errmsg, FT_ERR_NOT_A_WAV);
return (-1);
}
- ft_memdel((void**)&clist->mlist.music_path);
+ ft_memdel((void*)&clist->mlist.music_path);
if (!(clist->mlist.music_path = ft_strdup(*(words + 1))))
{
ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE);
diff --git a/src/ft_get_path_nl.c b/src/ft_get_path_nl.c
index 68de5c6..38f5b36 100644
--- a/src/ft_get_path_nl.c
+++ b/src/ft_get_path_nl.c
@@ -27,7 +27,7 @@ int8_t
ft_sprintf(clist->errmsg, FT_ERR_NOT_A_CUB);
return (-1);
}
- ft_memdel((void**)&clist->mlist.nlevel_path);
+ ft_memdel((void*)&clist->mlist.nlevel_path);
if (!(clist->mlist.nlevel_path = ft_strdup(*(words + 1))))
{
ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE);
diff --git a/src/ft_get_skybox.c b/src/ft_get_skybox.c
index d2f1f02..1e55b85 100644
--- a/src/ft_get_skybox.c
+++ b/src/ft_get_skybox.c
@@ -27,7 +27,7 @@ int8_t
ft_sprintf(clist->errmsg, FT_ERR_NOT_A_XPM);
return (-1);
}
- ft_memdel((void**)&clist->mlist.skybox_path);
+ ft_memdel((void*)&clist->mlist.skybox_path);
if (!(clist->mlist.skybox_path = ft_strdup(*(words + 1))))
{
ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE);
diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c
index ed44d9b..5a5ecd0 100644
--- a/src/ft_get_sprite.c
+++ b/src/ft_get_sprite.c
@@ -53,7 +53,7 @@ static int8_t
static int8_t
ft_get_sprite_norme(int8_t id, char **words, t_cub *clist)
{
- ft_memdel((void**)&clist->mlist.sprite_path[id]);
+ ft_memdel((void*)&clist->mlist.sprite_path[id]);
if (!(clist->mlist.sprite_path[id] = ft_strdup(*(words + 1))))
{
ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE);
diff --git a/src/ft_get_sprite_spawns.c b/src/ft_get_sprite_spawns.c
index 3a44f56..da883b2 100644
--- a/src/ft_get_sprite_spawns.c
+++ b/src/ft_get_sprite_spawns.c
@@ -19,7 +19,7 @@ void
ft_get_next_sprite(t_cub *clist, int s_n, char c, size_t x)
{
size_t y;
- uint8_t i;
+ int16_t i;
y = 0;
i = 0;
@@ -37,7 +37,8 @@ void
}
x = 0;
}
- if (clist->sprites[s_n][i - 1].s_pos_x != 0)
+ if (clist->sprites[s_n][(i - 1 < 0) ? (0) : (i - 1)].s_pos_x != 0
+ && s_n + 1 < 7)
{
ft_get_next_sprite(clist, s_n + 1, c + 1, 0);
}
diff --git a/src/ft_get_tex.c b/src/ft_get_tex.c
index f8a817c..21096eb 100644
--- a/src/ft_get_tex.c
+++ b/src/ft_get_tex.c
@@ -27,7 +27,7 @@ int8_t
ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM);
return (-1);
}
- ft_memdel((void**)&clist->mlist.no_tex_path);
+ ft_memdel((void*)&clist->mlist.no_tex_path);
if (!(clist->mlist.no_tex_path = ft_strdup(*(words + 1))))
{
ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);
@@ -54,7 +54,7 @@ int8_t
ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM);
return (-1);
}
- ft_memdel((void**)&clist->mlist.so_tex_path);
+ ft_memdel((void*)&clist->mlist.so_tex_path);
if (!(clist->mlist.so_tex_path = ft_strdup(*(words + 1))))
{
ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);
@@ -81,7 +81,7 @@ int8_t
ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM);
return (-1);
}
- ft_memdel((void**)&clist->mlist.ea_tex_path);
+ ft_memdel((void*)&clist->mlist.ea_tex_path);
if (!(clist->mlist.ea_tex_path = ft_strdup(*(words + 1))))
{
ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);
@@ -108,7 +108,7 @@ int8_t
ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM);
return (-1);
}
- ft_memdel((void**)&clist->mlist.we_tex_path);
+ ft_memdel((void*)&clist->mlist.we_tex_path);
if (!(clist->mlist.we_tex_path = ft_strdup(*(words + 1))))
{
ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);
diff --git a/src/ft_get_tex_extra.c b/src/ft_get_tex_extra.c
index 25f9c23..77f053b 100644
--- a/src/ft_get_tex_extra.c
+++ b/src/ft_get_tex_extra.c
@@ -26,7 +26,7 @@ int8_t
ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM);
return (-1);
}
- ft_memdel((void**)&clist->mlist.fl_tex_path);
+ ft_memdel((void*)&clist->mlist.fl_tex_path);
if (!(clist->mlist.fl_tex_path = ft_strdup(*(words + 1))))
{
ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);
@@ -54,7 +54,7 @@ int8_t
ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM);
return (-1);
}
- ft_memdel((void**)&clist->mlist.ce_tex_path);
+ ft_memdel((void*)&clist->mlist.ce_tex_path);
if (!(clist->mlist.ce_tex_path = ft_strdup(*(words + 1))))
{
ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);
diff --git a/src/ft_get_tex_nl.c b/src/ft_get_tex_nl.c
index bb071f7..0931df1 100644
--- a/src/ft_get_tex_nl.c
+++ b/src/ft_get_tex_nl.c
@@ -27,7 +27,7 @@ int8_t
ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM);
return (-1);
}
- ft_memdel((void**)&clist->mlist.nl_tex_path);
+ ft_memdel((void*)&clist->mlist.nl_tex_path);
if (!(clist->mlist.nl_tex_path = ft_strdup(*(words + 1))))
{
ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);
diff --git a/src/ft_get_traps.c b/src/ft_get_traps.c
index 0235bb5..b7d12e1 100644
--- a/src/ft_get_traps.c
+++ b/src/ft_get_traps.c
@@ -55,7 +55,7 @@ int8_t
ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM);
return (-1);
}
- ft_memdel((void**)&clist->mlist.traps_path);
+ ft_memdel((void*)&clist->mlist.traps_path);
if (!(clist->mlist.traps_path = ft_strdup(*(words + 1))))
{
ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index 5726a5b..692f3ce 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -11,7 +11,6 @@
/* ************************************************************************** */
#include <libft.h>
-#include <mlx.h>
#include <cub3d.h>
#include <stddef.h>
#include <stdlib.h>
@@ -72,6 +71,7 @@ static int8_t
i = -1;
while (++i < 5)
cl->key_input[i] = -1;
+ cl->mtid = 0;
cl->ishud = 0;
cl->isoldmus = 0;
cl->doicast = 1;
@@ -84,6 +84,8 @@ static int8_t
cl->walltexgood = 0;
ft_init_funptr(cl);
ft_init_ref(cl);
+ if (ft_init_sprites(&cl->sprites) < 0)
+ return (-1);
return (0);
}
diff --git a/src/ft_init_map.c b/src/ft_init_map.c
index cf5bebe..8b97906 100644
--- a/src/ft_init_map.c
+++ b/src/ft_init_map.c
@@ -40,7 +40,7 @@ static int8_t
}
static int8_t
- ft_calloc_sprites(t_map *mlist)
+ ft_calloc_sprites_path(t_map *mlist)
{
uint8_t i;
@@ -73,7 +73,7 @@ int8_t
if (ft_init_map_callocs(mlist) < 0)
return (-1);
mlist->map[1] = 0;
- if (ft_calloc_sprites(mlist) < 0)
+ if (ft_calloc_sprites_path(mlist) < 0)
return (-1);
mlist->map_w = 0;
mlist->map_h = 0;
diff --git a/src/ft_init_sprites.c b/src/ft_init_sprites.c
new file mode 100644
index 0000000..4fc9aed
--- /dev/null
+++ b/src/ft_init_sprites.c
@@ -0,0 +1,34 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_init_lists.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:28:53 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:28:53 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+int8_t
+ ft_init_sprites(t_sprite ***sprites)
+{
+ uint8_t i;
+
+ if (!(*sprites = (t_sprite**)ft_calloc(8, sizeof(t_sprite*))))
+ return (-1);
+ i = 0;
+ while (i < 8)
+ {
+ if (!(*((*sprites) + i) = (t_sprite*)ft_calloc(4096, sizeof(t_sprite))))
+ return (-1);
+ i++;
+ }
+ return (0);
+}
diff --git a/src/ft_init_winlx.c b/src/ft_init_winlx.c
index dee4009..59d0b58 100644
--- a/src/ft_init_winlx.c
+++ b/src/ft_init_winlx.c
@@ -26,7 +26,7 @@ int
int
ft_init_winptr(t_cub *clist)
{
- ft_memdel((void**)&clist->wlist.winptr);
+ ft_memdel((void*)&clist->wlist.winptr);
if (!(clist->wlist.winptr = mlx_new_window(clist->wlist.wlx,
clist->wlist.x_size, clist->wlist.y_size, "Cub3D")))
return (-1);
diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c
index df97380..74ff775 100644
--- a/src/ft_key_loop.c
+++ b/src/ft_key_loop.c
@@ -99,7 +99,6 @@ int
}
i++;
}
- /* if (cl->key_input[0] != -1) */
- ft_draw_scene(cl);
+ ft_draw_scene(cl);
return (0);
}
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index f1df73d..79c00d2 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -42,7 +42,7 @@ static void
static int8_t
ft_error_here(const char *errmsg, char *line, t_cub *clist)
{
- ft_memdel((void**)&line);
+ ft_memdel((void*)&line);
return (ft_map_error(errmsg, clist));
}
@@ -60,7 +60,7 @@ static int8_t
return (ft_error_here(FT_ERR_UNFINISHED, line, clist));
if (!line[0])
{
- ft_memdel((void**)&line);
+ ft_memdel((void*)&line);
return (ft_parse_it(fd, clist));
}
if (ft_ischarset("1 ", line[0]))
@@ -70,14 +70,14 @@ static int8_t
return (ft_error_here(FT_ERR_ILL_ENTRY, line, clist));
if ((ret = ft_select_get(words, clist)) == FT_PARSE_END_RET)
return ((ft_get_map_first_line(line, clist) < 0) ? (-1) : (25));
- ft_memdel((void**)&line);
+ ft_memdel((void*)&line);
return (ret);
}
void
ft_save_name(const char *map_path, t_cub *clist)
{
- ft_memdel((void**)&clist->mlist.filename);
+ ft_memdel((void*)&clist->mlist.filename);
if (!(clist->mlist.filename =
(char*)malloc((ft_strlen(map_path) + 1) * sizeof(char))))
ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist);
diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c
index a0720ea..aa050c5 100644
--- a/src/ft_raycasting.c
+++ b/src/ft_raycasting.c
@@ -78,7 +78,6 @@ static void
cl->rlist.wall_b = cl->rlist.line_h / 2 + wl->y_size / 2;
if (cl->rlist.wall_b >= (int16_t)wl->y_size)
cl->rlist.wall_b = wl->y_size - 1;
- cl->rlist.wall_bz[i] = cl->rlist.wall_b;
}
void
@@ -101,12 +100,13 @@ void
ft_choose_tex(cl);
ft_calc_tex(cl);
ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b);
+ cl->rlist.wall_bz[i] = cl->rlist.wall_b;
cl->rlist.wall_dist_tab[i] = cl->rlist.wall_dist;
i++;
}
ft_floor_cast(cl);
ft_calc_sprite(cl);
ft_calc_trap(cl);
- ft_memdel((void**)&cl->rlist.wall_dist_tab);
- ft_memdel((void**)&cl->rlist.wall_bz);
+ ft_memdel((void*)&cl->rlist.wall_dist_tab);
+ ft_memdel((void*)&cl->rlist.wall_bz);
}
diff --git a/src/ft_save_to_bmp.c b/src/ft_save_to_bmp.c
index ae3a2b6..1737226 100644
--- a/src/ft_save_to_bmp.c
+++ b/src/ft_save_to_bmp.c
@@ -111,16 +111,16 @@ int8_t
return (-1);
if (!(bmp = ft_convert_image_to_bmp(cl->img, cl)))
{
- ft_memdel((void**)&fname);
+ ft_memdel((void*)&fname);
return (-1);
}
if (ft_write_bmp(fname, cl->wlist.y_size, cl->wlist.x_size, bmp) < 0)
{
- ft_memdel((void**)&bmp);
- ft_memdel((void**)&fname);
+ ft_memdel((void*)&bmp);
+ ft_memdel((void*)&fname);
return (-1);
}
- ft_memdel((void**)&bmp);
- ft_memdel((void**)&fname);
+ ft_memdel((void*)&bmp);
+ ft_memdel((void*)&fname);
return (0);
}
diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c
index dd4ed1b..fadbb2a 100644
--- a/src/ft_warp_level.c
+++ b/src/ft_warp_level.c
@@ -23,20 +23,20 @@
static void
ft_del_map(t_map *ml)
{
- ft_memdel((void**)&ml->filename);
- ft_memdel((void**)&ml->no_tex_path);
- ft_memdel((void**)&ml->so_tex_path);
- ft_memdel((void**)&ml->ea_tex_path);
- ft_memdel((void**)&ml->we_tex_path);
- ft_memdel((void**)&ml->nl_tex_path);
- ft_memdel((void**)&ml->fl_tex_path);
- ft_memdel((void**)&ml->ce_tex_path);
- ft_memdel((void**)&ml->nlevel_path);
- ft_memdel((void**)&ml->skybox_path);
- ft_memdel((void**)&ml->traps_path);
- ft_memdel((void**)&ml->music_path);
- ft_memdel((void**)&ml->music_cmd);
- ft_memdel((void**)&ml->mapl);
+ ft_memdel((void*)&ml->filename);
+ ft_memdel((void*)&ml->no_tex_path);
+ ft_memdel((void*)&ml->so_tex_path);
+ ft_memdel((void*)&ml->ea_tex_path);
+ ft_memdel((void*)&ml->we_tex_path);
+ ft_memdel((void*)&ml->nl_tex_path);
+ ft_memdel((void*)&ml->fl_tex_path);
+ ft_memdel((void*)&ml->ce_tex_path);
+ ft_memdel((void*)&ml->nlevel_path);
+ ft_memdel((void*)&ml->skybox_path);
+ ft_memdel((void*)&ml->traps_path);
+ ft_memdel((void*)&ml->music_path);
+ ft_memdel((void*)&ml->music_cmd);
+ ft_memdel((void*)&ml->mapl);
ft_free_sprites(ml->sprite_path);
ft_free_words(ml->map);
}
@@ -44,19 +44,15 @@ static void
static void
ft_del_some(t_cub *cl)
{
- uint8_t i;
+ int8_t i;
cl->plist = ft_init_player();
cl->f_rgb = ft_init_rgb();
cl->c_rgb = ft_init_rgb();
cl->rlist = ft_init_s_ray();
- i = 0;
- while (i < 5)
- {
+ i = -1;
+ while (++i < 5)
mlx_destroy_image(cl->wlist.wlx, cl->tlist[i].img);
- cl->tlist[i].ptr = NULL;
- i++;
- }
if (cl->mlist.isnlvl && cl->tlist[5].img)
mlx_destroy_image(cl->wlist.wlx, cl->tlist[5].img);
if (cl->mlist.isftex && cl->tlist[6].img)
@@ -66,6 +62,10 @@ static void
if (cl->mlist.istraps && cl->tlist[15].img)
mlx_destroy_image(cl->wlist.wlx, cl->tlist[15].img);
ft_del_extra_sprites(cl);
+ i = -1;
+ while (++i < 8)
+ ft_memdel((void*)&cl->sprites[i]);
+ ft_memdel((void*)&cl->sprites);
}
static void
@@ -103,13 +103,15 @@ int8_t
tmp_mup = ft_strdup(cl->mlist.music_path);
ft_del_some(cl);
ft_del_map(&cl->mlist);
+ if (ft_init_sprites(&cl->sprites) < 0)
+ return (-1);
if (ft_init_map(&cl->mlist) < 0)
return (-1);
ft_parse_map(next_path, cl);
ft_treat_music(isoldmus, tmp_mup, cl);
if (isoldmus)
- ft_memdel((void**)&tmp_mup);
+ ft_memdel((void*)&tmp_mup);
ft_wall_tex_init(cl);
- ft_memdel((void**)&next_path);
+ ft_memdel((void*)&next_path);
return (0);
}
diff --git a/src/main.c b/src/main.c
index 43b482a..a1c9a8c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -13,20 +13,23 @@
#include <libft.h>
#include <mlx.h>
#include <cub3d.h>
+#include <stdlib.h>
int
main(int argc, const char *argv[], char *const envp[])
{
- t_cub clist;
+ t_cub *clist;
if (ft_check_map_arg(argc, argv) == FT_RET_BAD_ARGV)
return (FT_RET_BAD_ARGV);
- if (ft_init_cub3d(&clist) < 0)
+ if (!(clist = (t_cub*)malloc(sizeof(t_cub))))
+ return (FT_RET_ALLOC_ERR);
+ if (ft_init_cub3d(clist) < 0)
return (FT_RET_FAILED_STRUCTS);
- ft_parse_map(argv[1], &clist);
- if (ft_init_winlx(&clist) < 0)
- return (ft_exit(FT_RET_FAILED_MLX, &clist));
- ft_wall_tex_init(&clist);
- ft_use_args(argc, argv, envp, &clist);
+ ft_parse_map(argv[1], clist);
+ if (ft_init_winlx(clist) < 0)
+ return (ft_exit(FT_RET_FAILED_MLX, clist));
+ ft_wall_tex_init(clist);
+ ft_use_args(argc, argv, envp, clist);
return (FT_RET_FINE);
}