From 8866ef5699150d0549096efa94fc311ff7a48dc7 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 3 Mar 2020 14:47:33 +0100 Subject: Changing stuff --- src/ft_init_lists.c | 78 +++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 42 deletions(-) (limited to 'src/ft_init_lists.c') diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index eec8d5d..2b2593c 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -36,15 +36,15 @@ static t_player if (!(plist = (t_player*)malloc(sizeof(t_player)))) return (NULL); - plist->pos_x = 0; - plist->pos_y = 0; - plist->start_x = 0; - plist->start_y = 0; - plist->cam_x = 0; - plist->dir_x = -1; - plist->dir_y = 0; - plist->plane_x = 0; - plist->plane_y = 0.75; + plist.pos_x = 0; + plist.pos_y = 0; + plist.start_x = 0; + plist.start_y = 0; + plist.cam_x = 0; + plist.dir_x = -1; + plist.dir_y = 0; + plist.plane_x = 0; + plist.plane_y = 0.75; return (plist); } @@ -55,58 +55,52 @@ static t_win if (!(wlist = (t_win*)malloc(sizeof(t_win)))) return (NULL); - if (!(wlist->winptr = malloc(1))) + if (!(wlist.winptr = malloc(1))) return (NULL); - wlist->inited = 0; - wlist->x_size = 0; - wlist->y_size = 0; - wlist->x_max_size = 0; - wlist->y_max_size = 0; + wlist.inited = 0; + wlist.x_size = 0; + wlist.y_size = 0; + wlist.x_max_size = 0; + wlist.y_max_size = 0; return (wlist); } static t_cub - *ft_init_cub(void) + ft_init_cub(void) { - t_cub *clist; + t_cub clist; uint8_t i; - if (!(clist = (t_cub*)malloc(sizeof(t_cub)))) + if (!(clist.plist = ft_init_player()) || + !(clist.mlist = ft_init_map())) return (NULL); - if (!(clist->plist = ft_init_player()) || - !(clist->mlist = ft_init_map())) - return (NULL); - ft_bzero(clist->errmsg, 40); + ft_bzero(clist.errmsg, 40); i = -1; while (++i < 5) - clist->key_input[i] = -1; - clist->ishud = 0; - clist->isoldmus = 0; - clist->f_rgb = ft_init_rgb(); - clist->c_rgb = ft_init_rgb(); - clist->rlist = ft_init_s_ray(); - clist->currlvl = 0; - clist->walltexgood = 0; + clist.key_input[i] = -1; + clist.ishud = 0; + clist.isoldmus = 0; + clist.f_rgb = ft_init_rgb(); + clist.c_rgb = ft_init_rgb(); + clist.rlist = ft_init_s_ray(); + clist.currlvl = 0; + clist.walltexgood = 0; ft_init_funptr(clist); return (clist); } -int8_t - ft_init_cub3d(t_cub **clist) +t_cub + ft_init_cub3d(void) { - t_cub *cl; + t_cub cl; if (!(cl = ft_init_cub())) + return (NULL); + if (!(cl.wlist = ft_init_win())) { + ft_memdel((void**)&cl.wlist); ft_memdel((void**)&cl); - return (-1); - } - if (!(cl->wlist = ft_init_win())) - { - ft_memdel((void**)&cl->wlist); - ft_memdel((void**)&cl); - return (-1); + return (NULL); } - *clist = cl; - return (0); + return (cl); } -- cgit v1.2.3 From ce43b1cd1caa539af687425f58a6999a20807878 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 3 Mar 2020 16:14:26 +0100 Subject: Going full stack is bav --- src/ft_init_lists.c | 92 ++++++++++++++++++++++++----------------------------- 1 file changed, 42 insertions(+), 50 deletions(-) (limited to 'src/ft_init_lists.c') diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index 2b2593c..1b91ed0 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -15,8 +15,7 @@ #include #include #include -#include -#include +#include t_rgb ft_init_rgb(void) @@ -30,12 +29,10 @@ t_rgb } static t_player - *ft_init_player(void) + ft_init_player(void) { - t_player *plist; + t_player plist; - if (!(plist = (t_player*)malloc(sizeof(t_player)))) - return (NULL); plist.pos_x = 0; plist.pos_y = 0; plist.start_x = 0; @@ -48,59 +45,54 @@ static t_player return (plist); } -static t_win - *ft_init_win(void) +static int8_t + ft_init_win(t_win *wl) { - t_win *wlist; - - if (!(wlist = (t_win*)malloc(sizeof(t_win)))) - return (NULL); - if (!(wlist.winptr = malloc(1))) - return (NULL); - wlist.inited = 0; - wlist.x_size = 0; - wlist.y_size = 0; - wlist.x_max_size = 0; - wlist.y_max_size = 0; - return (wlist); + if (!(wl->winptr = malloc(1))) + return (-1); + wl->inited = 0; + wl->x_size = 0; + wl->y_size = 0; + wl->x_max_size = 0; + wl->y_max_size = 0; + /* wlist = &wl; */ + return (0); } -static t_cub - ft_init_cub(void) +static int8_t + ft_init_cub(t_cub *cl) { - t_cub clist; - uint8_t i; + int8_t i; - if (!(clist.plist = ft_init_player()) || - !(clist.mlist = ft_init_map())) - return (NULL); - ft_bzero(clist.errmsg, 40); + if (ft_init_map(&cl->mlist) < 0) + return (-1); + cl->plist = ft_init_player(); + ft_bzero(cl->errmsg, 40); i = -1; while (++i < 5) - clist.key_input[i] = -1; - clist.ishud = 0; - clist.isoldmus = 0; - clist.f_rgb = ft_init_rgb(); - clist.c_rgb = ft_init_rgb(); - clist.rlist = ft_init_s_ray(); - clist.currlvl = 0; - clist.walltexgood = 0; - ft_init_funptr(clist); - return (clist); + cl->key_input[i] = -1; + cl->ishud = 0; + cl->isoldmus = 0; + cl->f_rgb = ft_init_rgb(); + cl->c_rgb = ft_init_rgb(); + cl->rlist = ft_init_s_ray(); + cl->currlvl = 0; + cl->walltexgood = 0; + ft_init_funptr(cl); + return (0); } -t_cub - ft_init_cub3d(void) +int8_t + ft_init_cub3d(t_cub *clist) { - t_cub cl; + /* t_cub *cl; */ - if (!(cl = ft_init_cub())) - return (NULL); - if (!(cl.wlist = ft_init_win())) - { - ft_memdel((void**)&cl.wlist); - ft_memdel((void**)&cl); - return (NULL); - } - return (cl); + /* if (!(cl = (t_cub*)malloc(sizeof(t_cub)))) */ + /* return (-1); */ + if (ft_init_cub(clist) < 0) + return (-1); + if (ft_init_win(&clist->wlist) < 0) + return (-1); + /* *clist = cl; */ + return (0); } -- cgit v1.2.3