/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_warp_level.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/28 20:54:28 by rbousset #+# #+# */ /* Updated: 2020/02/28 20:54:29 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include #include #include #include #include #include #include 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->sprite_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_words(ml->map); ft_free_words(ml->mcmd_words); } static void ft_del_some(t_cub *cl) { uint8_t i; cl->plist.pos_x = 0; cl->plist.pos_y = 0; cl->plist.pos_z = 0; cl->plist.start_x = 0; cl->plist.start_y = 0; cl->plist.cam_x = 0; cl->plist.dir_x = -1; cl->plist.dir_y = 0; cl->plist.plane_x = 0; cl->plist.plane_y = 0.66; cl->f_rgb = ft_init_rgb(); cl->c_rgb = ft_init_rgb(); cl->rlist = ft_init_s_ray(); i = -1; while (++i <= 5) { mlx_destroy_image(cl->wlist.wlx, cl->tlist[i].img); cl->tlist[i].img = NULL; } if (cl->mlist.isftex && cl->tlist[6].img) mlx_destroy_image(cl->wlist.wlx, cl->tlist[6].img); if (cl->mlist.isctex && cl->tlist[7].img) mlx_destroy_image(cl->wlist.wlx, cl->tlist[7].img); } static void ft_treat_music(uint8_t isoldmus, char *tmp_mup, t_cub *cl) { if (isoldmus && !cl->mlist.ismusic) { kill(cl->mpid, SIGTERM); wait(&cl->mpid); cl->isoldmus = 0; } else if (isoldmus && cl->mlist.ismusic && ft_strncmp(tmp_mup, cl->mlist.music_path, ft_strlen(tmp_mup) + 1)) { kill(cl->mpid, SIGTERM); wait(&cl->mpid); ft_enable_music(cl); } else if (isoldmus && cl->mlist.ismusic && !ft_strncmp(tmp_mup, cl->mlist.music_path, ft_strlen(tmp_mup) + 1)) return ; } int8_t ft_warp_level(t_cub *cl) { char *next_path; char *tmp_mup; uint8_t isoldmus; 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)))) return (-1); ft_sprintf(next_path, "%s", cl->mlist.nlevel_path); if ((isoldmus = cl->mlist.ismusic)) tmp_mup = ft_strdup(cl->mlist.music_path); ft_del_some(cl); ft_del_map(&cl->mlist); 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_wall_tex_init(cl); ft_memdel((void**)&next_path); } return (0); }