From fb6d429478e2a8983b52ffee7bb7b20b7bb11211 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 21 Mar 2020 19:57:18 +0100 Subject: Starting to valgrind --- Makefile | 1 + inc/cub3d.h | 1 + inc/cub3d_structs.h | 2 +- src/ft_init_lists.c | 6 ++++-- src/ft_init_sprites.c | 2 +- src/ft_init_weaps.c | 34 ++++++++++++++++++++++++++++++++++ 6 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 src/ft_init_weaps.c diff --git a/Makefile b/Makefile index 60c2e2d..c11281d 100644 --- a/Makefile +++ b/Makefile @@ -114,6 +114,7 @@ SRCS_NAME += ft_draw_weapons.c SRCS_NAME += ft_draw_weapons_extra.c SRCS_NAME += ft_draw_handweap.c SRCS_NAME += ft_switch_weapons.c +SRCS_NAME += ft_init_weaps.c #--------------------------------------------------------------------------------------------------# SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME}) #--------------------------------------------------------------------------------------------------# diff --git a/inc/cub3d.h b/inc/cub3d.h index 2c25857..5f36a2e 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -36,6 +36,7 @@ t_bmp_info ft_init_bmp_info(void); t_rgb ft_hex_to_og_rgb(uint32_t color); int8_t ft_init_sfx(t_cub *cl); int8_t ft_init_sprites(t_sprite ***sprites); +int8_t ft_init_weaps(t_sprite ***weaps); /* ** ====== HOOKS ====== diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 259cf05..85031bb 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -259,7 +259,7 @@ typedef struct s_cub struct s_sprite **sprites; struct s_sprite traps[512]; struct s_sprite heals[64]; - struct s_sprite weaps[2][1]; + struct s_sprite **weaps; struct s_sfx sfx[10]; } t_cub; diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index 7bf716b..29771a5 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -96,8 +96,6 @@ 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); } @@ -108,6 +106,10 @@ int8_t return (-1); if (ft_init_win(&clist->wlist) < 0) return (-1); + if (ft_init_sprites(&clist->sprites) < 0) + return (-1); + if (ft_init_weaps(&clist->weaps) < 0) + return (-1); ft_sprintf(clist->fps_count, "fps: 60"); clist->isdead = 0; clist->moves = 0; diff --git a/src/ft_init_sprites.c b/src/ft_init_sprites.c index 4fc9aed..2099089 100644 --- a/src/ft_init_sprites.c +++ b/src/ft_init_sprites.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_init_lists.c :+: :+: :+: */ +/* ft_init_sprites.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ diff --git a/src/ft_init_weaps.c b/src/ft_init_weaps.c new file mode 100644 index 0000000..242b62d --- /dev/null +++ b/src/ft_init_weaps.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_init_weaps.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:28:53 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:28:53 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include +#include + +int8_t + ft_init_weaps(t_sprite ***weaps) +{ + uint8_t i; + + if (!(*weaps = (t_sprite**)ft_calloc(2, sizeof(t_sprite*)))) + return (-1); + i = 0; + while (i < 2) + { + if (!(*((*weaps) + i) = (t_sprite*)ft_calloc(1, sizeof(t_sprite)))) + return (-1); + i++; + } + return (0); +} -- cgit v1.2.3