diff options
Diffstat (limited to 'src')
49 files changed, 806 insertions, 282 deletions
diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c index b9fd636..50464a9 100644 --- a/src/ft_check_map_line.c +++ b/src/ft_check_map_line.c @@ -37,8 +37,8 @@ static int8_t ft_sprintf(clist->errmsg, FT_ERR_MULT_NLVL); return (-1); } - if (line[i] == 'T') - clist->mlist.istraps = 1; + clist->mlist.istraps = (line[i] == 'T') ? (1) : (clist->mlist.istraps); + clist->mlist.isheals = (line[i] == '+') ? (1) : (clist->mlist.isheals); ft_get_topsp(line[i], clist); return (0); } diff --git a/src/ft_check_missing.c b/src/ft_check_missing.c index a17bdea..6bf41ab 100644 --- a/src/ft_check_missing.c +++ b/src/ft_check_missing.c @@ -14,15 +14,6 @@ #include <cub3d.h> #include <unistd.h> -int - ft_missing_error(const char *err, t_cub *clist) -{ - ft_dprintf(STDERR_FILENO, "Error\n"); - ft_dprintf(STDERR_FILENO, - "\033[1;31m%s %s\033[0m\n", FT_ERR_MISS_ELEMENT, err); - return (ft_exit(FT_ERR_MISSING, clist)); -} - static int ft_check_missing_sfx(t_cub *clist) { @@ -60,6 +51,21 @@ static int } static int + ft_check_missing_tex_defines(t_cub *clist) +{ + if (ft_check_not_found(FT_DEATH_SCREEN_PATH) < 0 || + ft_check_ext(FT_DEATH_SCREEN_PATH, ".xpm") < 0) + return (ft_missing_error(FT_ERR_MISS_DEATH_SCREEN, clist)); + if (ft_check_not_found(FT_HUD_BACK_PATH) < 0 || + ft_check_ext(FT_HUD_BACK_PATH, ".xpm") < 0) + return (ft_missing_error(FT_ERR_MISS_HUD_BACK, clist)); + if (ft_check_not_found(FT_HEAL_PACK_PATH) < 0 || + ft_check_ext(FT_HEAL_PACK_PATH, ".xpm") < 0) + return (ft_missing_error(FT_ERR_MISS_HEAL_PACK, clist)); + return (ft_check_missing_sprites(clist)); +} + +static int ft_check_missing_norme(t_cub *clist) { if (!clist->mlist.isftex) @@ -82,10 +88,7 @@ static int return (ft_missing_error(FT_ERR_MISS_NLVL_PATH, clist)); if (clist->mlist.istraps && !clist->mlist.traps_path[0]) return (ft_missing_error(FT_ERR_MISS_TRAP, clist)); - if (ft_check_not_found(FT_DEATH_SCREEN_PATH) < 0 || - ft_check_ext(FT_DEATH_SCREEN_PATH, ".xpm") < 0) - return (ft_missing_error(FT_ERR_MISS_DEATH_SCREEN, clist)); - return (ft_check_missing_sprites(clist)); + return (ft_check_missing_tex_defines(clist)); } int diff --git a/src/ft_death_screen.c b/src/ft_death_screen.c index cc299d1..55a61cb 100644 --- a/src/ft_death_screen.c +++ b/src/ft_death_screen.c @@ -25,10 +25,10 @@ static void while (y < (int32_t)cl->wlist.y_size) { x = 0; + cl->death_screen.tex_y = ((y * y_ratio) >> 16); while (x < (int32_t)cl->wlist.x_size) { cl->death_screen.tex_x = ((x * x_ratio) >> 16); - cl->death_screen.tex_y = ((y * y_ratio) >> 16); cl->img.ptr[x * 4 + (cl->img.sizeline * y)] = (uint8_t)cl->death_screen.ptr[cl->death_screen.tex_x * 4 + 4 * cl->death_screen.img_w * cl->death_screen.tex_y]; @@ -38,7 +38,6 @@ static void cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] = (uint8_t)cl->death_screen.ptr[cl->death_screen.tex_x * 4 + 4 * cl->death_screen.img_w * cl->death_screen.tex_y + 2]; - cl->img.ptr[x * 4 + cl->wlist.x_size * y + 3] = (char)0; x++; } y++; diff --git a/src/ft_draw_heals.c b/src/ft_draw_heals.c new file mode 100644 index 0000000..bc1e1b2 --- /dev/null +++ b/src/ft_draw_heals.c @@ -0,0 +1,109 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_draw_heals.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ +/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdint.h> +#include <stdlib.h> +#include <math.h> + +static void + ft_sort_heals_norme(float *dist_tab, int32_t it, t_cub *cl) +{ + uint32_t tmp; + + tmp = 0; + if (dist_tab[it] > dist_tab[it + 1]) + { + tmp = dist_tab[it]; + dist_tab[it] = dist_tab[it + 1]; + dist_tab[it + 1] = tmp; + tmp = cl->mlist.heals_order[it]; + cl->mlist.heals_order[it] = cl->mlist.heals_order[it + 1]; + cl->mlist.heals_order[it + 1] = tmp; + it = 0; + } +} + +void + ft_sort_heals(t_cub *cl) +{ + float dist_tab[4096]; + int32_t it; + + it = 0; + while (it < cl->mlist.heals_nbr) + { + dist_tab[it] = ((cl->plist.pos_x - cl->heals[it].s_pos_x) * + (cl->plist.pos_x - cl->heals[it].s_pos_x) + + (cl->plist.pos_y - cl->heals[it].s_pos_y) * + (cl->plist.pos_y - cl->heals[it].s_pos_y)); + cl->mlist.heals_order[it] = it; + it++; + } + it = 0; + while (it < cl->mlist.heals_nbr) + { + ft_sort_heals_norme(dist_tab, it, cl); + } +} + +static void + ft_put_heal(t_sprite *sprite, t_cub *cl) +{ + float dist; + float calc; + + if ((dist = cl->rlist.wall_dist_tab[sprite->x]) <= 0) + dist = 0.0001; + calc = (dist * 0.1 * cl->mlist.darklvl); + calc = (calc >= 255) ? (255) : (calc); + calc = (calc < 1) ? (1) : (calc); + cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline)] = + (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[17].img_h * sprite->tex_y] / calc; + cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 1] = + (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[17].img_h * sprite->tex_y + 1] / calc; + cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] = + (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[17].img_h * sprite->tex_y + 2] / calc; +} + +void + ft_draw_heals(t_cub *cl, t_sprite *sprite) +{ + int32_t d; + + sprite->x = sprite->drawstartx; + while (sprite->x < sprite->drawendx) + { + sprite->tex_x = (int32_t)((sprite->x - (-sprite->spritewidth / 2 + + sprite->spritescreenx)) + * cl->tlist[17].img_w / sprite->spritewidth); + sprite->y = sprite->drawstarty; + while (sprite->y < sprite->drawendy) + { + d = sprite->y * 256 - cl->wlist.y_size * 128 + + sprite->spriteheight * 128; + sprite->tex_y = ((d * cl->tlist[17].img_h / 2) / + sprite->spriteheight) / 128; + if (sprite->transformy > 0 + && cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[17].img_h * sprite->tex_y] + && cl->rlist.wall_dist_tab[sprite->x] > sprite->transformy) + ft_put_heal(sprite, cl); + sprite->y++; + } + sprite->x++; + } +} diff --git a/src/ft_draw_heals_extra.c b/src/ft_draw_heals_extra.c new file mode 100644 index 0000000..62c64b0 --- /dev/null +++ b/src/ft_draw_heals_extra.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_draw_heals_extra.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ +/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdint.h> +#include <stdlib.h> +#include <math.h> + +void + ft_calc_heal(t_cub *cl) +{ + t_sprite sprite; + int32_t i; + + i = 0; + while (i < cl->mlist.heals_nbr) + { + sprite = cl->heals[i]; + sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5); + sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5); + sprite.invdet = 1.0 / (cl->plist.plane_x * cl->plist.dir_y + - cl->plist.dir_x * cl->plist.plane_y); + sprite.transformx = sprite.invdet * (cl->plist.dir_y * sprite.spritex + - cl->plist.dir_x * sprite.spritey); + sprite.transformy = sprite.invdet * (-cl->plist.plane_y * sprite.spritex + + cl->plist.plane_x * sprite.spritey); + sprite.spritescreenx = (int)(cl->wlist.x_size / 2) * + (1 + sprite.transformx / sprite.transformy); + ft_sprite_h_w(cl, &sprite); + ft_draw_heals(cl, &sprite); + i++; + } +} diff --git a/src/ft_draw_hud.c b/src/ft_draw_hud.c index eb329c6..121e85e 100644 --- a/src/ft_draw_hud.c +++ b/src/ft_draw_hud.c @@ -14,31 +14,44 @@ #include <stdint.h> static void - ft_draw_life_back(t_win *wl, t_cub *cl) + ft_put_image_back_to_ptr(uint16_t y, uint16_t x, t_cub *cl) { - const uint16_t scl = cl->mlist.scale; - uint32_t x; - uint32_t y; - int32_t col; + const uint32_t col = 0x00d2d4d6; - col = 0x00353535; - x = (cl->mlist.map_w * scl) + 20; - y = wl->y_size - (cl->mlist.map_h * scl) - 20; - while (x < ((cl->mlist.map_w * scl) + 20) + (3 * scl)) + *(cl->img.ptr + x * 4 + (cl->img.sizeline * y)) = + (uint8_t)*(cl->tlist[16].ptr + cl->tlist[16].tex_x * 4 + 4 * + cl->tlist[16].img_w * cl->tlist[16].tex_y) & col; + *(cl->img.ptr + x * 4 + (cl->img.sizeline * y) + 1) = + (uint8_t)*(cl->tlist[16].ptr + cl->tlist[16].tex_x * 4 + 4 * + cl->tlist[16].img_w * cl->tlist[16].tex_y + 1) & col; + *(cl->img.ptr + x * 4 + (cl->img.sizeline * y) + 2) = + (uint8_t)*(cl->tlist[16].ptr + cl->tlist[16].tex_x * 4 + 4 * + cl->tlist[16].img_w * cl->tlist[16].tex_y + 2) & col; +} + +static void + ft_draw_minimap_back_image(uint16_t h, uint16_t w, t_cub *cl) +{ + int32_t x_ratio; + int32_t y_ratio; + int16_t x; + int16_t y; + + x_ratio = (int)((cl->tlist[16].img_w << 16) / w) + 1; + y_ratio = (int)((cl->tlist[16].img_h << 16) / h) + 1; + y = cl->wlist.y_size - (cl->mlist.map_h * cl->mlist.scale) - 20; + while (y < (int32_t)cl->wlist.y_size) { - while (y < wl->y_size) + x = 0; + cl->tlist[16].tex_y = (y * y_ratio) >> 16; + while (x < (uint16_t)((cl->mlist.map_w + * cl->mlist.scale) + 20 + (3 * cl->mlist.scale))) { - *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = col; - if (!(y % 3)) - { - if (col < 0x00aaaaaa) - col += 0x00010101; - } - y++; + cl->tlist[16].tex_x = (x * x_ratio) >> 16; + ft_put_image_back_to_ptr(y, x, cl); + x++; } - col = 0x00353535; - y = wl->y_size - (cl->mlist.map_h * scl) - 20; - x++; + y++; } } @@ -46,29 +59,18 @@ static void ft_draw_minimap_back(size_t map_h, size_t map_w, t_win *wl, t_cub *cl) { const uint16_t scl = cl->mlist.scale; - uint32_t x; - uint32_t y; - int32_t col; + uint16_t x; + uint16_t y; - col = 0x00353535; x = 0; y = wl->y_size - (map_h * scl) - 20; - while (x < (map_w * scl) + 20) + while (x < (map_w * scl) + 20 + (3 * scl)) { while (y < wl->y_size) - { - *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = col; - if (!(y % 3)) - { - if (col < 0x00aaaaaa) - col += 0x00010101; - } y++; - } - col = 0x00353535; - y = wl->y_size - (map_h * scl) - 20; x++; } + ft_draw_minimap_back_image(y, x, cl); } static void @@ -107,7 +109,6 @@ int8_t ft_draw_minimap_back(clist->mlist.map_h, clist->mlist.map_w, &clist->wlist, clist); ft_draw_map(clist->mlist.map, clist); - ft_draw_life_back(&clist->wlist, clist); ft_draw_life_bar(&clist->wlist, clist); if (clist->mlist.isnlvl) { diff --git a/src/ft_draw_map.c b/src/ft_draw_map.c index 5d37566..286f69d 100644 --- a/src/ft_draw_map.c +++ b/src/ft_draw_map.c @@ -31,7 +31,7 @@ static void ft_draw_circle( (scale / 2) + (x * (scale)), - ft_y_offset(clist) - (scale) + (y * (scale)), + ft_y_offset(clist) - (scale + 9) + (y * (scale)), 0x009843fa, clist); } @@ -52,7 +52,7 @@ void if (ft_ischarset("1", map[y][x])) ft_draw_square(scale + 9 + (x * (scale)), ft_y_offset(clist) - 9 + (y * (scale)), 0x00ca5422, clist); - else if (map[y][x] == '2') + else if (ft_ischarset(FT_CHRST_SPRITES, map[y][x])) ft_draw_square(scale + 9 + (x * (scale)), ft_y_offset(clist) - 9 + (y * (scale)), 0x0033ccff, clist); else if (ft_ischarset(FT_CHRST_MAP_NON_WALL, map[y][x])) diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c index 1edef2a..86009f6 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -13,8 +13,19 @@ #include <libft.h> #include <cub3d.h> #include <mlx.h> +#include <stdlib.h> #include <stdint.h> +static void + ft_put_fps(t_cub *clist) +{ + mlx_string_put(clist->wlist.wlx, + clist->wlist.winptr, + 10, 20, + 0x00eeeeee, + clist->fps_count); +} + static int8_t ft_put_stage(t_cub *clist) { @@ -34,7 +45,7 @@ static int8_t (uint32_t)x, y, 0x002288da, str); - ft_memdel((void**)&str); + ft_memdel((void*)&str); return (0); } @@ -60,9 +71,12 @@ void clist->wlist.winptr, clist->img.img, 0, 0); if (FT_OS == 2) mlx_destroy_image(clist->wlist.wlx, clist->img.img); - if (clist->ishud && clist->mlist.isnlvl) - if (ft_put_stage(clist) < 0) + if (clist->ishud) + { + ft_put_fps(clist); + if (clist->mlist.isnlvl && ft_put_stage(clist) < 0) ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist); + } } void diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index cb9a573..5fc28d3 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -85,7 +85,6 @@ static void cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 2] / calc; - cl->img.ptr[sprite->x * 4 + cl->wlist.x_size * sprite->y + 3] = (char)0; } void diff --git a/src/ft_draw_textures.c b/src/ft_draw_textures.c index 5fc3bdd..dcd36e7 100644 --- a/src/ft_draw_textures.c +++ b/src/ft_draw_textures.c @@ -41,7 +41,6 @@ void ft_draw_texture(t_cub *cl, int x, int y, int tex_y) cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] = (uint8_t)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * cl->tlist[cl->w_side].img_h * tex_y + 2] / calc; - cl->img.ptr[x * 4 + cl->wlist.x_size * y + 3] = (char)0; } void ft_choose_tex(t_cub *clist) diff --git a/src/ft_draw_traps.c b/src/ft_draw_traps.c index f1acc20..71e8fe8 100644 --- a/src/ft_draw_traps.c +++ b/src/ft_draw_traps.c @@ -77,7 +77,6 @@ static void cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] = (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 * cl->tlist[15].img_h * sprite->tex_y + 2] / calc; - cl->img.ptr[sprite->x * 4 + cl->wlist.x_size * sprite->y + 3] = (char)0; } void diff --git a/src/ft_error.c b/src/ft_error.c index 87be01e..0f2bc97 100644 --- a/src/ft_error.c +++ b/src/ft_error.c @@ -34,3 +34,12 @@ int errmsg); return (ft_exit(FT_RET_MAP_ERR, clist)); } + +int + ft_missing_error(const char *err, t_cub *clist) +{ + ft_dprintf(STDERR_FILENO, "Error\n"); + ft_dprintf(STDERR_FILENO, + "\033[1;31m%s %s\033[0m\n", FT_ERR_MISS_ELEMENT, err); + return (ft_exit(FT_ERR_MISSING, clist)); +} diff --git a/src/ft_exit.c b/src/ft_exit.c index 80fd734..390f234 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -15,39 +15,52 @@ #include <mlx.h> #include <stddef.h> #include <stdlib.h> -#include <signal.h> -#include <sys/types.h> -#include <sys/wait.h> #include <stdint.h> +#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_free_words(clist->mlist.mcmd_words); - ft_free_words(clist->sfx.death); - ft_free_words(clist->sfx.pain_one); - ft_free_words(clist->sfx.pain_two); - ft_free_words(clist->sfx.new_lvl); - ft_free_words(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); + ft_memdel((void*)&clist->wlist.winptr); } static void @@ -71,29 +84,36 @@ static void mlx_destroy_image(clist->wlist.wlx, clist->tlist[7].img); if (clist->mlist.istraps && clist->tlist[15].img) mlx_destroy_image(clist->wlist.wlx, clist->tlist[15].img); + if (clist->tlist[16].img) + mlx_destroy_image(clist->wlist.wlx, clist->tlist[16].img); + if (clist->mlist.isheals && clist->tlist[17].img) + mlx_destroy_image(clist->wlist.wlx, clist->tlist[17].img); ft_del_extra_sprites(clist); } static void - ft_kill_forks(t_cub *clist) + ft_cancel_threads(t_cub *clist) { - pid_t tmp; - - if (!(tmp = waitpid(clist->mpid, NULL, WNOHANG))) - kill(clist->mpid, SIGTERM); - wait(&clist->mpid); - if (!(tmp = waitpid(clist->sfx.death_pid, NULL, WNOHANG))) - kill(clist->sfx.death_pid, SIGTERM); - wait(&clist->sfx.death_pid); - if (!(tmp = waitpid(clist->sfx.new_lvl_pid, NULL, WNOHANG))) - kill(clist->sfx.new_lvl_pid, SIGTERM); - wait(&clist->sfx.new_lvl_pid); - if (!(tmp = waitpid(clist->sfx.pain_pid, NULL, WNOHANG))) - kill(clist->sfx.pain_pid, SIGTERM); - wait(&clist->sfx.pain_pid); - if (!(tmp = waitpid(clist->sfx.trap_pid, NULL, WNOHANG))) - kill(clist->sfx.trap_pid, SIGTERM); - wait(&clist->sfx.trap_pid); + if (clist->isoldmus && clist->wlist.inited) + { + pthread_cancel(clist->mtid); + pthread_join(clist->mtid, NULL); + } + pthread_mutex_unlock(&clist->sfx.death_mutex); + pthread_cancel(clist->sfx.death_tid); + pthread_join(clist->sfx.death_tid, NULL); + pthread_mutex_unlock(&clist->sfx.footstep_mutex); + pthread_cancel(clist->sfx.footstep_tid); + pthread_join(clist->sfx.footstep_tid, NULL); + pthread_mutex_unlock(&clist->sfx.new_lvl_mutex); + pthread_cancel(clist->sfx.new_lvl_tid); + pthread_join(clist->sfx.new_lvl_tid, NULL); + pthread_mutex_unlock(&clist->sfx.pain_mutex); + pthread_cancel(clist->sfx.pain_tid); + pthread_join(clist->sfx.pain_tid, NULL); + pthread_mutex_unlock(&clist->sfx.trap_mutex); + pthread_cancel(clist->sfx.trap_tid); + pthread_join(clist->sfx.trap_tid, NULL); } int @@ -106,10 +126,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_kill_forks(clist); + 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_find_item.c b/src/ft_find_item.c new file mode 100644 index 0000000..d00b62d --- /dev/null +++ b/src/ft_find_item.c @@ -0,0 +1,53 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_find_item.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/17 20:06:26 by rbousset #+# #+# */ +/* Updated: 2020/02/17 20:06:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdint.h> + +static uint16_t + ft_fetch_heals_id(uint64_t pos_y, uint64_t pos_x, t_cub *cl) +{ + uint16_t id; + + id = 0; + while (id <= 64) + { + if (cl->heals[id].s_pos_y == pos_y && cl->heals[id].s_pos_x == pos_x) + return (id); + id++; + } + return (0); +} + +void + ft_find_item(t_player *pl, t_map *ml, t_cub *cl) +{ + uint16_t id; + + if (ft_ischarset(FT_CHRST_ITEM, + ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x])) + { + if (ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x] == '+' + && pl->life < 100) + { + pl->life += FT_HEAL_PACK_AMOUNT; + pl->life = (pl->life > 100) ? (100) : (pl->life); + ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x] = '0'; + id = ft_fetch_heals_id((uint64_t)pl->pos_y, + (uint64_t)pl->pos_x, cl); + cl->heals[id].s_pos_x = 0; + cl->heals[id].s_pos_y = 0; + /* TODO: ft_sfx_heal(3) */ + } + } +} diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c index 92dcb07..160a2c1 100644 --- a/src/ft_floor_cast.c +++ b/src/ft_floor_cast.c @@ -25,30 +25,30 @@ static void { float dist; float calc; - t_rgb rgb; 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); - 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; - 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); + *(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_w * 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_w * 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 * + cl->tlist[tid].img_w * cl->tlist[tid].tex_y + 2) / calc; } static void ft_set_tex_xy(uint8_t tid, t_ray *rl, t_cub *cl) { cl->tlist[tid].tex_y = (int32_t)(cl->tlist[tid].img_w - * (rl->x_floor - rl->x_cell)) % (cl->tlist[tid].img_w); + * (rl->x_floor - rl->x_cell)); cl->tlist[tid].tex_x = (int32_t)(cl->tlist[tid].img_h - * (rl->y_floor - rl->y_cell)) % (cl->tlist[tid].img_h); + * (rl->y_floor - rl->y_cell)); cl->tlist[tid].tex_x = (cl->tlist[tid].tex_x > 0) ? (cl->tlist[tid].tex_x) : (-cl->tlist[tid].tex_x); cl->tlist[tid].tex_y = (cl->tlist[tid].tex_y > 0) 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_fps_count.c b/src/ft_get_fps_count.c new file mode 100644 index 0000000..16306c1 --- /dev/null +++ b/src/ft_get_fps_count.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_key_loop.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/17 20:06:26 by rbousset #+# #+# */ +/* Updated: 2020/02/17 20:06:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stddef.h> +#include <stdint.h> +#include <time.h> + +static float + ft_clock_to_ms(clock_t ticks) +{ + return ((ticks / (float)CLOCKS_PER_SEC) * 1000.0); +} + +#include <stdio.h> + +void + ft_get_fps_count(clock_t dt, t_cub *cl) +{ + static clock_t curr_time = 0; + + curr_time += dt; + if (dt > 0 && ft_clock_to_ms(curr_time) > 1000.0) + { + ft_sprintf(cl->fps_count, "fps: %ld", (uint32_t)CLOCKS_PER_SEC / dt); + curr_time -= CLOCKS_PER_SEC; + } +} diff --git a/src/ft_get_heal_spawn.c b/src/ft_get_heal_spawn.c new file mode 100644 index 0000000..142709b --- /dev/null +++ b/src/ft_get_heal_spawn.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_get_traps.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/28 18:24:52 by rbousset #+# #+# */ +/* Updated: 2020/02/28 18:24:56 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdint.h> + +void + ft_get_heal_spawn(t_cub *clist) +{ + size_t x; + size_t y; + uint8_t i; + + x = 1; + y = 1; + i = 0; + while (clist->mlist.map[y]) + { + while (clist->mlist.map[y][x]) + { + if (clist->mlist.map[y][x] == '+') + { + clist->mlist.heals_nbr++; + if (clist->mlist.heals_nbr > 64) + ft_map_error(FT_ERR_TOO_MUCH_HEALS, clist); + clist->heals[i].s_pos_x = x; + clist->heals[i].s_pos_y = y; + i++; + } + x++; + } + x = 1; + y++; + } +} 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 7a8d36f..cf105a3 100644 --- a/src/ft_get_music.c +++ b/src/ft_get_music.c @@ -22,14 +22,11 @@ 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, mlist->music_path); - ft_free_words(mlist->mcmd_words); - if (!(mlist->mcmd_words = ft_split(mlist->music_cmd, ' '))) - return (-1); return (0); } @@ -46,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_player_spawn.c b/src/ft_get_player_spawn.c index ef2edd9..1ba6437 100644 --- a/src/ft_get_player_spawn.c +++ b/src/ft_get_player_spawn.c @@ -84,6 +84,7 @@ void ft_get_start_side(clist->mlist.map[y][x], plist); ft_get_sprite_spawn(clist); ft_get_trap_spawn(clist); + ft_get_heal_spawn(clist); return ; } x++; 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 e0b37b5..d7b6677 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..fef3179 100644 --- a/src/ft_get_traps.c +++ b/src/ft_get_traps.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_get_tex_nl.c :+: :+: :+: */ +/* ft_get_traps.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -19,7 +19,7 @@ void { size_t x; size_t y; - uint8_t i; + uint16_t i; x = 1; y = 1; @@ -31,6 +31,8 @@ void if (clist->mlist.map[y][x] == 'T') { clist->mlist.traps_nbr++; + if (clist->mlist.traps_nbr > 512) + ft_map_error(FT_ERR_TOO_MUCH_TRAPS, clist); clist->traps[i].s_pos_x = x; clist->traps[i].s_pos_y = y; i++; @@ -55,7 +57,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_hooks_and_loops.c b/src/ft_hooks_and_loops.c index b8bdd36..9293496 100644 --- a/src/ft_hooks_and_loops.c +++ b/src/ft_hooks_and_loops.c @@ -15,7 +15,7 @@ #include <mlx.h> void - ft_hooks_and_loops(t_win *wl, t_cub *cl) +ft_hooks_and_loops(t_win *wl, t_cub *cl) { mlx_hook(wl->winptr, 2, (1L << 0), ft_key_event, cl); mlx_hook(wl->winptr, 3, (1L << 1), ft_key_release, cl); diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index 3e4dc96..99ebd65 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,7 +71,7 @@ static int8_t i = -1; while (++i < 5) cl->key_input[i] = -1; - cl->mpid = 0; + cl->mtid = 0; cl->ishud = 0; cl->isoldmus = 0; cl->doicast = 1; @@ -85,22 +84,18 @@ 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); } int8_t ft_init_cub3d(t_cub *clist) { - uint8_t i; if (ft_init_cub(clist) < 0) return (-1); if (ft_init_win(&clist->wlist) < 0) return (-1); - i = 0; - while (i < 9) - { - ft_bzero(clist->sprites[i], 4096); - i++; - } + ft_sprintf(clist->fps_count, "fps: 60"); return (0); } diff --git a/src/ft_init_map.c b/src/ft_init_map.c index 4ee8def..37fc858 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -34,15 +34,13 @@ static int8_t !(mlist->music_cmd = (char*)ft_calloc(1, sizeof(char))) || !(mlist->mapl = (char*)ft_calloc(1, sizeof(char))) || !(mlist->map = (char**)ft_calloc(2, sizeof(char*))) || - !(mlist->map[0] = (char*)ft_calloc(1, sizeof(char))) || - !(mlist->mcmd_words = (char**)ft_calloc(2, sizeof(char*))) || - !(mlist->mcmd_words[0] = (char*)ft_calloc(1, sizeof(char)))) + !(mlist->map[0] = (char*)ft_calloc(1, sizeof(char)))) return (-1); return (0); } static int8_t - ft_calloc_sprites(t_map *mlist) + ft_calloc_sprites_path(t_map *mlist) { uint8_t i; @@ -76,8 +74,7 @@ int8_t if (ft_init_map_callocs(mlist) < 0) return (-1); mlist->map[1] = 0; - mlist->mcmd_words[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; @@ -93,7 +90,9 @@ int8_t mlist->ismusic = 0; mlist->isskybox = 0; mlist->istraps = 0; + mlist->isheals = 0; mlist->traps_nbr = 0; + mlist->heals_nbr = 0; mlist->darklvl = 0; return (ft_init_map_norme(mlist)); } diff --git a/src/ft_init_sfx.c b/src/ft_init_sfx.c index 9049250..35ab57d 100644 --- a/src/ft_init_sfx.c +++ b/src/ft_init_sfx.c @@ -17,39 +17,41 @@ #include <stdlib.h> #include <stdint.h> #include <unistd.h> +#include <pthread.h> static int8_t - ft_split_sfx(char ***target, const char *path) + ft_init_sfx_cmd(char **target, const char *path) { uint8_t len; - char *tmp; len = ft_strlen(path); len += ft_strlen(FT_SND_CMD) - 2; - if (!(tmp = (char *)malloc((len + 1) * sizeof(char)))) + if (!(*target = (char *)malloc((len + 1) * sizeof(char)))) return (-1); - ft_sprintf(tmp, FT_SND_CMD, path); - if (!(*target = ft_split(tmp, ' '))) - { - ft_memdel((void**)&tmp); - return (-1); - } - ft_memdel((void**)&tmp); + ft_sprintf(*target, FT_SND_CMD, path); return (0); } int8_t ft_init_sfx(t_sfx *sfx) { - sfx->death_pid = 0; - sfx->new_lvl_pid = 0; - sfx->pain_pid = 0; - sfx->trap_pid = 0; - if (ft_split_sfx(&sfx->death, FT_SFX_DEATH_PATH) < 0 || - ft_split_sfx(&sfx->new_lvl, FT_SFX_N_LVL_PATH) < 0 || - ft_split_sfx(&sfx->pain_one, FT_SFX_SCR_ONE_PATH) < 0 || - ft_split_sfx(&sfx->pain_two, FT_SFX_SCR_TWO_PATH) < 0 || - ft_split_sfx(&sfx->trap, FT_SFX_TRAP_PATH) < 0) + if (ft_init_sfx_cmd(&sfx->death, FT_SFX_DEATH_PATH) < 0 || + ft_init_sfx_cmd(&sfx->footstep_one, FT_SFX_FS_ONE_PATH) < 0 || + ft_init_sfx_cmd(&sfx->footstep_two, FT_SFX_FS_TWO_PATH) < 0 || + ft_init_sfx_cmd(&sfx->new_lvl, FT_SFX_N_LVL_PATH) < 0 || + ft_init_sfx_cmd(&sfx->pain_one, FT_SFX_SCR_ONE_PATH) < 0 || + ft_init_sfx_cmd(&sfx->pain_two, FT_SFX_SCR_TWO_PATH) < 0 || + ft_init_sfx_cmd(&sfx->trap, FT_SFX_TRAP_PATH) < 0) return (-1); + pthread_mutex_init(&sfx->death_mutex, NULL); + pthread_mutex_init(&sfx->footstep_mutex, NULL); + pthread_mutex_init(&sfx->new_lvl_mutex, NULL); + pthread_mutex_init(&sfx->pain_mutex, NULL); + pthread_mutex_init(&sfx->trap_mutex, NULL); + pthread_create(&sfx->death_tid, NULL, ft_sfx_death_thread, sfx); + pthread_create(&sfx->footstep_tid, NULL, ft_sfx_footstep_thread, sfx); + pthread_create(&sfx->new_lvl_tid, NULL, ft_sfx_new_lvl_thread, sfx); + pthread_create(&sfx->pain_tid, NULL, ft_sfx_pain_thread, sfx); + pthread_create(&sfx->trap_tid, NULL, ft_sfx_trap_thread, sfx); return (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 c16655e..e0177e2 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -13,8 +13,9 @@ #include <libft.h> #include <cub3d.h> #include <mlx.h> -#include <stdint.h> #include <stddef.h> +#include <stdint.h> +#include <time.h> static uint64_t ft_find_x(int32_t key, const t_player *pl) @@ -77,25 +78,32 @@ int uint8_t i; const float old_y = cl->plist.pos_y; const float old_x = cl->plist.pos_x; + clock_t begin_frame; + begin_frame = clock(); i = 0; while (i < 5 && cl->key_input[i] != -1 && cl->key_input[i] <= 5) { cl->key_ptr[cl->key_input[i]](cl); - ft_collision(old_y, old_x, cl->key_input[i], cl); - if (cl->mlist.isnlvl) + if (cl->key_input[i] >= 0 && cl->key_input[i] <= 3) { - if ((uint32_t)cl->plist.pos_x == cl->mlist.nlx && - (uint32_t)cl->plist.pos_y == cl->mlist.nly) + ft_sfx_footstep(cl); + ft_collision(old_y, old_x, cl->key_input[i], cl); + ft_find_item(&cl->plist, &cl->mlist, cl); + if (cl->mlist.isnlvl) { - ft_sfx_new_level(cl); - return ((ft_warp_level(cl->mlist.nlevel_path, cl) < 0) ? - (ft_exit(FT_RET_FAILED_STRUCTS, cl)) : (0)); + if ((uint32_t)cl->plist.pos_x == cl->mlist.nlx && + (uint32_t)cl->plist.pos_y == cl->mlist.nly) + { + ft_sfx_new_level(cl); + return ((ft_warp_level(cl->mlist.nlevel_path, cl) < 0) ? + (ft_exit(FT_RET_FAILED_STRUCTS, cl)) : (0)); + } } } i++; } - if (cl->key_input[0] != -1) - ft_draw_scene(cl); + ft_draw_scene(cl); + ft_get_fps_count(clock() - begin_frame, cl); return (0); } diff --git a/src/ft_music.c b/src/ft_music.c index 234f86e..7a2d800 100644 --- a/src/ft_music.c +++ b/src/ft_music.c @@ -11,21 +11,29 @@ /* ************************************************************************** */ #include <cub3d.h> -#include <unistd.h> +#include <stddef.h> +#include <stdlib.h> +#include <pthread.h> -void - ft_music_fork(char **mcmd_words, char *const envp[]) +static void + *ft_music_thread(void *vargp) { - execve(*(mcmd_words + 0), mcmd_words, envp); + t_cub *cl; + + if (FT_OS == 1) + pthread_setcancelstate(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + else + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + cl = (t_cub *)vargp; + while (1) + if (system(cl->mlist.music_cmd) != 0) + pthread_exit(NULL); + return(NULL); } void ft_enable_music(t_cub *cl) { cl->isoldmus = 1; - cl->mpid = fork(); - if (cl->mpid == 0) - { - ft_music_fork(cl->mlist.mcmd_words, cl->envp); - } + pthread_create(&cl->mtid, NULL, ft_music_thread, cl); } 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 743dc36..2d7df79 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -106,7 +106,8 @@ void } ft_floor_cast(cl); ft_calc_sprite(cl); + ft_calc_heal(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_sfx_death.c b/src/ft_sfx_death.c index 2566358..32ad6fe 100644 --- a/src/ft_sfx_death.c +++ b/src/ft_sfx_death.c @@ -11,14 +11,31 @@ /* ************************************************************************** */ #include <cub3d.h> -#include <unistd.h> +#include <stdlib.h> +#include <pthread.h> void - ft_sfx_death(t_cub *cl) + *ft_sfx_death_thread(void *vargp) { - cl->sfx.death_pid = fork(); - if (cl->sfx.death_pid == 0) + t_sfx *sfx; + + if (FT_OS == 1) + pthread_setcancelstate(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + else + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + sfx = (t_sfx *)vargp; + pthread_mutex_lock(&sfx->death_mutex); + while (1) { - execve(*(cl->sfx.death + 0), cl->sfx.death, cl->envp); + pthread_mutex_lock(&sfx->death_mutex); + if (system(sfx->death)) + pthread_exit(NULL); } + return (NULL); +} + +void + ft_sfx_death(t_cub *cl) +{ + pthread_mutex_unlock(&cl->sfx.death_mutex); } diff --git a/src/ft_sfx_footstep.c b/src/ft_sfx_footstep.c new file mode 100644 index 0000000..c0c9ffe --- /dev/null +++ b/src/ft_sfx_footstep.c @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sfx_footstep.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 17:17:54 by rbousset #+# #+# */ +/* Updated: 2020/02/24 17:17:56 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <cub3d.h> +#include <stdlib.h> +#include <pthread.h> + +void + *ft_sfx_footstep_thread(void *vargp) +{ + t_sfx *sfx; + static uint8_t ref = 0; + + if (FT_OS == 1) + pthread_setcancelstate(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + else + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + sfx = (t_sfx *)vargp; + pthread_mutex_lock(&sfx->footstep_mutex); + while (1) + { + ref = (ref > 201) ? (0) : (ref + 1); + pthread_mutex_lock(&sfx->footstep_mutex); + if (ref % 2) + { + if (system(sfx->footstep_one)) + pthread_exit(NULL); + } + else if (system(sfx->footstep_two)) + pthread_exit(NULL); + } + return (NULL); +} + +void + ft_sfx_footstep(t_cub *cl) +{ + pthread_mutex_unlock(&cl->sfx.footstep_mutex); +} diff --git a/src/ft_sfx_new_level.c b/src/ft_sfx_new_level.c index 05e9059..2cde15c 100644 --- a/src/ft_sfx_new_level.c +++ b/src/ft_sfx_new_level.c @@ -11,14 +11,31 @@ /* ************************************************************************** */ #include <cub3d.h> -#include <unistd.h> +#include <stdlib.h> +#include <pthread.h> void - ft_sfx_new_level(t_cub *cl) + *ft_sfx_new_lvl_thread(void *vargp) { - cl->sfx.new_lvl_pid = fork(); - if (cl->sfx.new_lvl_pid == 0) + t_sfx *sfx; + + if (FT_OS == 1) + pthread_setcancelstate(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + else + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + sfx = (t_sfx *)vargp; + pthread_mutex_lock(&sfx->new_lvl_mutex); + while (1) { - execve(*(cl->sfx.new_lvl + 0), cl->sfx.new_lvl, cl->envp); + pthread_mutex_lock(&sfx->new_lvl_mutex); + if (system(sfx->new_lvl)) + pthread_exit(NULL); } + return (NULL); +} + +void + ft_sfx_new_level(t_cub *cl) +{ + pthread_mutex_unlock(&cl->sfx.new_lvl_mutex); } diff --git a/src/ft_sfx_pain.c b/src/ft_sfx_pain.c new file mode 100644 index 0000000..68340c5 --- /dev/null +++ b/src/ft_sfx_pain.c @@ -0,0 +1,52 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sfx_trap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 17:17:54 by rbousset #+# #+# */ +/* Updated: 2020/02/24 17:17:56 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <cub3d.h> +#include <stdlib.h> +#include <pthread.h> + +void + *ft_sfx_pain_thread(void *vargp) +{ + t_sfx *sfx; + static uint8_t ref = 0; + + if (FT_OS == 1) + pthread_setcancelstate(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + else + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + sfx = (t_sfx *)vargp; + pthread_mutex_lock(&sfx->pain_mutex); + while (1) + { + pthread_mutex_lock(&sfx->pain_mutex); + ref = (ref > 201) ? (0) : (ref + 1); + if (ref % 3) + { + if (system(sfx->pain_one)) + pthread_exit(NULL); + } + else if (system(sfx->pain_two)) + pthread_exit(NULL); + } + return (NULL); +} + +void + ft_sfx_pain(t_cub *cl) +{ + static uint8_t ref = 0; + + ref = (ref > 201) ? (0) : (ref + 1); + if (ref % 2) + pthread_mutex_unlock(&cl->sfx.pain_mutex); +} diff --git a/src/ft_sfx_trap.c b/src/ft_sfx_trap.c index 1499ecf..a395450 100644 --- a/src/ft_sfx_trap.c +++ b/src/ft_sfx_trap.c @@ -10,40 +10,32 @@ /* */ /* ************************************************************************** */ -#include <libft.h> #include <cub3d.h> -#include <unistd.h> -#include <stdint.h> +#include <stdlib.h> +#include <pthread.h> -static void - ft_sfx_pain(t_cub *cl) +void + *ft_sfx_trap_thread(void *vargp) { - static uint8_t ref = 0; + t_sfx *sfx; - ref += 1; - if (ref > 201) - ref = 0; - if (ref % 2) + if (FT_OS == 1) + pthread_setcancelstate(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + else + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + sfx = (t_sfx *)vargp; + pthread_mutex_lock(&sfx->trap_mutex); + while (1) { - cl->sfx.pain_pid = fork(); - if (cl->sfx.pain_pid == 0) - { - if (ref % 3) - execve(*(cl->sfx.pain_one + 0), cl->sfx.pain_one, cl->envp); - else - execve(*(cl->sfx.pain_two + 0), cl->sfx.pain_two, cl->envp); - } + pthread_mutex_lock(&sfx->trap_mutex); + if (system(sfx->trap)) + pthread_exit(NULL); } + return (NULL); } void ft_sfx_trap(t_cub *cl) { - cl->sfx.trap_pid = fork(); - if (cl->sfx.trap_pid == 0) - execve(*(cl->sfx.trap + 0), cl->sfx.trap, cl->envp); - else - { - ft_sfx_pain(cl); - } + pthread_mutex_unlock(&cl->sfx.trap_mutex); } diff --git a/src/ft_suffer_animation.c b/src/ft_suffer_animation.c index d08fa54..a0a21a5 100644 --- a/src/ft_suffer_animation.c +++ b/src/ft_suffer_animation.c @@ -14,7 +14,6 @@ #include <cub3d.h> #include <mlx.h> #include <stdint.h> -#include <unistd.h> void ft_linux_suffer_animation(t_cub *cl) @@ -44,7 +43,10 @@ void ft_death_screen(cl); } else + { ft_sfx_trap(cl); + ft_sfx_pain(cl); + } } void diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index 298fbfc..6486e87 100644 --- a/src/ft_tex_init.c +++ b/src/ft_tex_init.c @@ -35,6 +35,8 @@ ** 13 : sprite 8 ** 14 : sprite 9 ** 15 : trap +** 16 : HUD back +** 17 : heal pack */ static void @@ -72,11 +74,13 @@ static void cl->tlist[7].ptr = mlx_get_data_addr(cl->tlist[7].img, &cl->tlist[7].bpp, &cl->tlist[7].sizeline, &cl->tlist[7].endian); } + cl->tlist[16].img = mlx_xpm_file_to_image(cl->wlist.wlx, + FT_HUD_BACK_PATH, &cl->tlist[16].img_w, &cl->tlist[16].img_h); + cl->tlist[16].ptr = mlx_get_data_addr(cl->tlist[16].img, + &cl->tlist[16].bpp, &cl->tlist[16].sizeline, &cl->tlist[16].endian); cl->walltexgood = 1; if (cl->mlist.sprite_var > 1) - { ft_next_sprite_init(cl); - } } static void @@ -103,6 +107,13 @@ static void cl->tlist[15].ptr = mlx_get_data_addr(cl->tlist[15].img, &cl->tlist[15].bpp, &cl->tlist[15].sizeline, &cl->tlist[15].endian); } + if (cl->mlist.isheals) + { + cl->tlist[17].img = mlx_xpm_file_to_image(cl->wlist.wlx, + FT_HEAL_PACK_PATH, &cl->tlist[17].img_w, &cl->tlist[17].img_h); + cl->tlist[17].ptr = mlx_get_data_addr(cl->tlist[17].img, + &cl->tlist[17].bpp, &cl->tlist[17].sizeline, &cl->tlist[17].endian); + } ft_wall_tex_init_norme_bis(cl); } diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index 56d4d67..a2b6006 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -23,41 +23,36 @@ 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); - ft_free_words(ml->mcmd_words); } 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,7 +61,15 @@ static void mlx_destroy_image(cl->wlist.wlx, cl->tlist[7].img); if (cl->mlist.istraps && cl->tlist[15].img) mlx_destroy_image(cl->wlist.wlx, cl->tlist[15].img); + if (cl->tlist[16].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[16].img); + if (cl->mlist.isheals && cl->tlist[17].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[17].img); ft_del_extra_sprites(cl); + i = -1; + while (++i < 8) + ft_memdel((void*)&cl->sprites[i]); + ft_memdel((void*)&cl->sprites); } static void @@ -74,15 +77,15 @@ static void { if (isoldmus && !cl->mlist.ismusic) { - kill(cl->mpid, SIGTERM); - wait(&cl->mpid); + pthread_cancel(cl->mtid); + pthread_join(cl->mtid, NULL); 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); + pthread_cancel(cl->mtid); + pthread_join(cl->mtid, NULL); ft_enable_music(cl); } else if (isoldmus && cl->mlist.ismusic @@ -104,13 +107,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); } @@ -13,6 +13,7 @@ #include <libft.h> #include <mlx.h> #include <cub3d.h> +#include <stdlib.h> int main(int argc, const char *argv[], char *const envp[]) |