diff options
Diffstat (limited to '')
34 files changed, 376 insertions, 749 deletions
diff --git a/src/ft_big_t.c b/src/ft_big_t.c new file mode 100644 index 0000000..e01bed7 --- /dev/null +++ b/src/ft_big_t.c @@ -0,0 +1,108 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sort_s_t.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 <cub3d.h> +#include <stdlib.h> +#include <stdint.h> + +static int8_t + ft_set_current_sprite(t_cub *cl, int8_t j) +{ + const int8_t st_o = cl->mlist.st_o[j]; + + if (st_o == 0) + return (4); + else if (st_o >= 1 && st_o <= 7) + return (st_o + 7); + else if (st_o == 8) + return (15); + else if (st_o == 9) + return (17); + else if (st_o >= 10) + return (st_o + 8); + return (0); +} + +void + ft_alloc_big_t(t_cub *cl) +{ + int32_t i; + + if (!(cl->big_t = (float**)malloc((cl->big_t_val) * sizeof(float*)))) + { + ft_alloc_error(cl); + } + i = 0; + while (i < cl->big_t_val) + { + if (!(cl->big_t[i] = (float*)malloc(4 * sizeof(float)))) + { + ft_alloc_error(cl); + } + i++; + } +} + +void + ft_fill_big_t(float **dist_tab, t_cub *cl) +{ + int32_t i; + int32_t j; + int32_t k; + + i = 0; + j = 0; + k = 0; + while (i < cl->big_t_val) + { + if (dist_tab[j][k]) + { + cl->big_t[i][0] = dist_tab[j][k]; + cl->big_t[i][1] = (float)ft_set_current_sprite(cl, j); + cl->big_t[i][2] = (float)j; + cl->big_t[i][3] = (float)k; + k++; + i++; + } + else + { + k = 0; + j++; + } + } +} + +void + ft_sort_big_t(t_cub *cl) +{ + int32_t i; + int8_t j; + float tmp[4]; + + i = 0; + while (i < cl->big_t_val - 1) + { + if (cl->big_t[i][0] < cl->big_t[i + 1][0]) + { + j = -1; + while (++j < 4) + { + tmp[j] = cl->big_t[i][j]; + cl->big_t[i][j] = cl->big_t[i + 1][j]; + cl->big_t[i + 1][j] = tmp[j]; + } + i = -1; + } + i++; + } +} + diff --git a/src/ft_death_hooks.c b/src/ft_death_hooks.c index 1f0cb6c..c6705b0 100644 --- a/src/ft_death_hooks.c +++ b/src/ft_death_hooks.c @@ -26,7 +26,7 @@ static int if (keycode == FT_RET_KEY) { if (ft_warp_level(clist->mlist.filename, clist) < 0) - return (ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist)); + return (ft_alloc_error(clist)); ft_draw_scene(clist); ft_hooks_and_loops(&clist->wlist, clist); return (0); diff --git a/src/ft_del_sprites_lists.c b/src/ft_del_sprites_lists.c index bb382e6..6a1a662 100644 --- a/src/ft_del_sprites_lists.c +++ b/src/ft_del_sprites_lists.c @@ -17,20 +17,13 @@ void ft_del_sprites_lists(t_cub *clist) { - uint8_t i; + int8_t i; i = 0; - while (i < 8) + while (i < FT_TOTAL_SPRT) { ft_memdel((void*)&clist->sprites[i]); i++; } ft_memdel((void*)&clist->sprites); - i = 0; - while (i < 3) - { - ft_memdel((void*)&clist->weaps[i]); - i++; - } - ft_memdel((void*)&clist->weaps); } diff --git a/src/ft_del_tex.c b/src/ft_del_tex.c index 70f23fa..fc0cf99 100644 --- a/src/ft_del_tex.c +++ b/src/ft_del_tex.c @@ -86,7 +86,7 @@ static void void ft_del_tex(t_cub *cl) { - if (cl->wlist.inited) + if (cl->walltexgood == 1) { if (cl->tlist[0].img) mlx_destroy_image(cl->wlist.wlx, cl->tlist[0].img); diff --git a/src/ft_draw_heals.c b/src/ft_draw_heals.c deleted file mode 100644 index 0ef9590..0000000 --- a/src/ft_draw_heals.c +++ /dev/null @@ -1,106 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* 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; - t_rgb rgb; - - if ((dist = sqrtf(powf(cl->plist.pos_x - sprite->s_pos_x, 2) - + powf(cl->plist.pos_y - sprite->s_pos_y, 2))) <= 0) - dist = 0.0001; - rgb.r = (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[17].img_h * sprite->tex_y + 2]; - rgb.g = (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[17].img_h * sprite->tex_y + 1]; - rgb.b = (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[17].img_h * sprite->tex_y]; - *(int*)(cl->img.ptr + ((uint16_t)sprite->x * 4 + - (sprite->y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl); -} - -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 deleted file mode 100644 index 1e5a775..0000000 --- a/src/ft_draw_heals_extra.c +++ /dev/null @@ -1,40 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* 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 <cub3d.h> -#include <stdint.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_scene.c b/src/ft_draw_scene.c index a76f403..4c7879b 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -73,7 +73,7 @@ void { ft_put_fps(clist); if (clist->mlist.isnlvl && ft_put_stage(clist) < 0) - ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist); + ft_alloc_error(clist); } } diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 5c0fe41..e41484e 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -16,51 +16,47 @@ #include <stdlib.h> #include <math.h> -static void - ft_sort_sprites_norme(float *dist_tab, int16_t *i, uint16_t j, t_cub *cl) +static float + **ft_alloc_dist_tab(void) { - uint32_t tmp; - uint32_t it; + uint16_t i; + float **dist_tab; - it = *i; - tmp = 0; - if (dist_tab[it] < dist_tab[it + 1]) + if (!(dist_tab = (float **)ft_calloc((FT_TOTAL_SPRT + 1), sizeof(float*)))) + return (NULL); + i = 0; + while (i < FT_TOTAL_SPRT + 1) { - tmp = dist_tab[it]; - dist_tab[it] = dist_tab[it + 1]; - dist_tab[it + 1] = tmp; - tmp = cl->mlist.sprite_order[j][it]; - cl->mlist.sprite_order[j][it] = cl->mlist.sprite_order[j][it + 1]; - cl->mlist.sprite_order[j][it + 1] = tmp; - *i = -1; + if (!(dist_tab[i] = (float *)ft_calloc(4096, sizeof(float)))) + return (NULL); + i++; } + return (dist_tab); } void ft_sort_sprites(t_cub *cl, int16_t it, int16_t jt) { - float dist_tab[8][4096]; + float **dist_tab; - while (++jt < cl->mlist.sprite_var) + if (!(dist_tab = ft_alloc_dist_tab())) + ft_alloc_error(cl); + while (++jt < FT_TOTAL_SPRT) { - while (++it < cl->mlist.sprite_nbr[jt]) + if (cl->mlist.sprite_nbr[jt] == 0) + dist_tab[jt][0] = 0; + else { - dist_tab[jt][it] = - ((cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) * - (cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) + - (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y) * - (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y)); - cl->mlist.sprite_order[jt][it] = it; + while (++it < cl->mlist.sprite_nbr[jt]) + { + dist_tab[jt][it] = + ((cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) * + (cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) + + (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y) * + (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y)); + } + it = -1; } - it = -1; - } - it = -1; - jt = -1; - while (++jt < cl->mlist.sprite_var) - { - while (++it < cl->mlist.sprite_nbr[jt] - 1) - ft_sort_sprites_norme(dist_tab[jt], &it, jt, cl); - it = -1; } ft_sort_s_t(cl, dist_tab); } @@ -75,11 +71,11 @@ static void + powf(cl->plist.pos_y - sprite->s_pos_y, 2))) <= 0) dist = 0.0001; rgb.r = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x - * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 2]; + * 4 + 4 * cl->tlist[sprite->current_sprite].img_w * sprite->tex_y + 2]; rgb.g = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x - * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 1]; + * 4 + 4 * cl->tlist[sprite->current_sprite].img_w * sprite->tex_y + 1]; rgb.b = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x - * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y]; + * 4 + 4 * cl->tlist[sprite->current_sprite].img_w * sprite->tex_y]; *(int*)(cl->img.ptr + ((uint16_t)sprite->x * 4 + (sprite->y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl); } @@ -104,7 +100,7 @@ void sprite->spriteheight) / 128; if (sprite->transformy > 0 && cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[sprite->current_sprite].img_h * sprite->tex_y] + cl->tlist[sprite->current_sprite].img_w * sprite->tex_y] && cl->rlist.wall_dist_tab[sprite->x] > sprite->transformy) ft_put_sprite(sprite, cl); sprite->y++; diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index 0830d2c..c201566 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -51,26 +51,21 @@ void ft_calc_sprite(t_cub *cl) { t_sprite sprite; - int32_t i; - int32_t j; + int16_t i; + int8_t j; i = -1; j = -1; ft_sort_sprites(cl, -1, -1); - while (++j < cl->mlist.sprite_var) + while (++j < cl->big_t_val) { - while (++i < cl->mlist.sprite_nbr[j]) - { - sprite = cl->sprites[cl->mlist.st_o[j]][cl->mlist.sprite_order[cl->mlist - .st_o[j]][i]]; - sprite.current_sprite = (cl->mlist.st_o[j] == 0) ? - 4 : cl->mlist.st_o[j] + 7; - sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5); - sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5); - ft_init_sprite(cl, &sprite); - ft_sprite_h_w(cl, &sprite); - ft_draw_sprite(cl, &sprite); - } + sprite = cl->sprites[(int8_t)cl->big_t[j][2]][(int32_t)cl->big_t[j][3]]; + sprite.current_sprite = (int8_t)cl->big_t[j][1]; + sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5); + sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5); + ft_init_sprite(cl, &sprite); + ft_sprite_h_w(cl, &sprite); + ft_draw_sprite(cl, &sprite); i = -1; } } diff --git a/src/ft_draw_traps.c b/src/ft_draw_traps.c deleted file mode 100644 index ed53dc0..0000000 --- a/src/ft_draw_traps.c +++ /dev/null @@ -1,104 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_draw_traps.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 <cub3d.h> -#include <stdint.h> -#include <math.h> - -static void - ft_sort_traps_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.traps_order[it]; - cl->mlist.traps_order[it] = cl->mlist.traps_order[it + 1]; - cl->mlist.traps_order[it + 1] = tmp; - it = 0; - } -} - -void - ft_sort_traps(t_cub *cl) -{ - float dist_tab[4096]; - int32_t it; - - it = 0; - while (it < cl->mlist.traps_nbr) - { - dist_tab[it] = ((cl->plist.pos_x - cl->traps[it].s_pos_x) * - (cl->plist.pos_x - cl->traps[it].s_pos_x) + - (cl->plist.pos_y - cl->traps[it].s_pos_y) * - (cl->plist.pos_y - cl->traps[it].s_pos_y)); - cl->mlist.traps_order[it] = it; - it++; - } - it = 0; - while (it < cl->mlist.traps_nbr) - { - ft_sort_traps_norme(dist_tab, it, cl); - } -} - -static void - ft_put_trap(t_sprite *sprite, t_cub *cl) -{ - float dist; - t_rgb rgb; - - if ((dist = sqrtf(powf(cl->plist.pos_x - sprite->s_pos_x, 2) - + powf(cl->plist.pos_y - sprite->s_pos_y, 2))) <= 0) - dist = 0.0001; - rgb.r = (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[15].img_h * sprite->tex_y + 2]; - rgb.g = (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[15].img_h * sprite->tex_y + 1]; - rgb.b = (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[15].img_h * sprite->tex_y]; - *(int*)(cl->img.ptr + ((uint16_t)sprite->x * 4 + - (sprite->y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl); -} - -void - ft_draw_traps(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[15].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[15].img_h / 2) / - sprite->spriteheight) / 128; - if (sprite->transformy > 0 - && cl->tlist[15].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[15].img_h * sprite->tex_y] - && cl->rlist.wall_dist_tab[sprite->x] > sprite->transformy) - ft_put_trap(sprite, cl); - sprite->y++; - } - sprite->x++; - } -} diff --git a/src/ft_draw_traps_extra.c b/src/ft_draw_traps_extra.c deleted file mode 100644 index cbeffe1..0000000 --- a/src/ft_draw_traps_extra.c +++ /dev/null @@ -1,40 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_draw_traps_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 <cub3d.h> -#include <stdint.h> - -void - ft_calc_trap(t_cub *cl) -{ - t_sprite sprite; - int32_t i; - - i = 0; - while (i < cl->mlist.traps_nbr) - { - sprite = cl->traps[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_traps(cl, &sprite); - i++; - } -} diff --git a/src/ft_draw_weapons.c b/src/ft_draw_weapons.c deleted file mode 100644 index c527987..0000000 --- a/src/ft_draw_weapons.c +++ /dev/null @@ -1,111 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_draw_weapons.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 <cub3d.h> -#include <stdint.h> -#include <math.h> - -static void - ft_sort_weapons_norme(float *dist_tab, int16_t *i, uint16_t j, t_cub *cl) -{ - uint32_t tmp; - uint32_t it; - - it = *i; - 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.weaps_order[j][it]; - cl->mlist.weaps_order[j][it] = cl->mlist.weaps_order[j][it + 1]; - cl->mlist.weaps_order[j][it + 1] = tmp; - *i = -1; - } -} - -void - ft_sort_weapons(t_cub *cl, int16_t it, int16_t jt) -{ - float dist_tab[2][1]; - - while (++jt <= cl->mlist.weapon_var) - { - while (++it <= cl->mlist.weaps_nbr[jt]) - { - dist_tab[jt][it] = - ((cl->plist.pos_x - cl->weaps[jt][it].s_pos_x) * - (cl->plist.pos_x - cl->weaps[jt][it].s_pos_x) + - (cl->plist.pos_y - cl->weaps[jt][it].s_pos_y) * - (cl->plist.pos_y - cl->weaps[jt][it].s_pos_y)); - cl->mlist.weaps_order[jt][it] = it; - } - it = -1; - } - it = -1; - jt = -1; - while (++jt < cl->mlist.weapon_var) - { - while (++it < cl->mlist.weaps_nbr[jt] - 1) - ft_sort_weapons_norme(dist_tab[jt], &it, jt, cl); - it = -1; - } -} - -static void - ft_put_weapon(t_sprite *sprite, t_cub *cl) -{ - float dist; - t_rgb rgb; - - if ((dist = sqrtf(powf(cl->plist.pos_x - sprite->s_pos_x, 2) - + powf(cl->plist.pos_y - sprite->s_pos_y, 2))) <= 0) - dist = 0.0001; - rgb.r = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x - * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 2]; - rgb.g = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x - * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 1]; - rgb.b = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x - * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y]; - *(int*)(cl->img.ptr + ((uint16_t)sprite->x * 4 + - (sprite->y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl); -} - -void - ft_draw_weapon(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[sprite->current_sprite].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[sprite->current_sprite].img_h / 2) / - sprite->spriteheight) / 128; - if (sprite->transformy > 0 && - cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[sprite->current_sprite].img_h * sprite->tex_y] - && cl->rlist.wall_dist_tab[sprite->x] > sprite->transformy) - ft_put_weapon(sprite, cl); - sprite->y++; - } - sprite->x++; - } -} diff --git a/src/ft_draw_weapons_extra.c b/src/ft_draw_weapons_extra.c deleted file mode 100644 index ed3ed53..0000000 --- a/src/ft_draw_weapons_extra.c +++ /dev/null @@ -1,42 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_draw_weapons_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 <cub3d.h> -#include <stdint.h> - -static void - ft_calc_weapon(uint8_t id, t_cub *cl) -{ - t_sprite sprite; - - sprite = cl->weaps[id][0]; - 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_weapon(cl, &sprite); -} - -void - ft_calc_weaps(t_cub *cl) -{ - ft_calc_weapon(0, cl); - ft_calc_weapon(1, cl); - ft_calc_weapon(2, cl); -} diff --git a/src/ft_error.c b/src/ft_error.c index 0f2bc97..a643b5c 100644 --- a/src/ft_error.c +++ b/src/ft_error.c @@ -36,10 +36,19 @@ int } int + ft_alloc_error(t_cub *clist) +{ + ft_dprintf(STDERR_FILENO, "Error\n"); + ft_dprintf(STDERR_FILENO, + "\033[1;31m%s\033[0m\n", FT_ERR_ALLOCATE); + return (ft_exit(FT_RET_ALLOC_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); + "\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 ed1191c..79b3068 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -21,6 +21,15 @@ static void ft_del_last_remains(t_cub *clist) { + uint16_t i; + + i = 0; + while (i < clist->big_t_val) + { + ft_memdel((void*)&clist->big_t[i]); + i++; + } + ft_memdel((void*)&clist->big_t); if (!clist->wlist.inited) { ft_memdel((void*)&clist->wlist.winptr); diff --git a/src/ft_extra_keys.c b/src/ft_extra_keys.c index f8a6db8..1a71402 100644 --- a/src/ft_extra_keys.c +++ b/src/ft_extra_keys.c @@ -12,7 +12,6 @@ #include <cub3d.h> #include <stdint.h> -#include <stdio.h> #include <math.h> #include <time.h> #include <libft.h> diff --git a/src/ft_find_item.c b/src/ft_find_item.c index 59b4a4f..394e060 100644 --- a/src/ft_find_item.c +++ b/src/ft_find_item.c @@ -22,7 +22,24 @@ static uint16_t id = 0; while (id <= 64) { - if (cl->heals[id].s_pos_y == pos_y && cl->heals[id].s_pos_x == pos_x) + if (cl->sprites[9][id].s_pos_y == pos_y && + cl->sprites[9][id].s_pos_x == pos_x) + return (id); + id++; + } + return (0); +} + +static uint16_t + ft_fetch_weaps_id(int8_t weap_id, uint64_t pos_y, uint64_t pos_x, t_cub *cl) +{ + uint16_t id; + + id = 0; + while (id <= 64) + { + if (cl->sprites[10 + weap_id][id].s_pos_y == pos_y && + cl->sprites[10 + weap_id][id].s_pos_x == pos_x) return (id); id++; } @@ -46,6 +63,7 @@ static void ft_weapon_check(const char map_char, t_player *pl, t_cub *cl) { uint8_t weap_id; + uint8_t that_id; if (ft_ischarset(FT_CHRST_WEAPONS, map_char)) { @@ -55,19 +73,16 @@ static void else if (map_char == '#') weap_id = 2; cl->mlist.map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x] = '0'; - cl->weaps[weap_id][0].s_pos_x = 0; - cl->weaps[weap_id][0].s_pos_y = 0; + that_id = ft_fetch_weaps_id(weap_id, (uint64_t)pl->pos_y, + (uint64_t)pl->pos_x, cl); + cl->sprites[10 + weap_id][that_id].s_pos_x = 0; + cl->sprites[10 + weap_id][that_id].s_pos_y = 0; pl->has_weapon[weap_id] = 1; pl->handles_weapon = (weap_id == 0) ? (0) : (pl->handles_weapon); pl->handles_weapon = (weap_id == 1) ? (2) : (pl->handles_weapon); pl->handles_weapon = (weap_id == 2) ? (4) : (pl->handles_weapon); ft_set_ammo(weap_id, pl); - if (weap_id == 0) - cl->sfx[6].sfx_play(cl->sfx); - else if (weap_id == 1) - cl->sfx[8].sfx_play(cl->sfx); - else if (weap_id == 2) - cl->sfx[10].sfx_play(cl->sfx); + cl->sfx[6 + (weap_id * 2)].sfx_play(cl->sfx); } } @@ -86,8 +101,8 @@ void 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; + cl->sprites[9][id].s_pos_x = 0; + cl->sprites[9][id].s_pos_y = 0; cl->sfx[5].sfx_play(cl->sfx); } ft_weapon_check(map_char, pl, cl); diff --git a/src/ft_get_heal_spawn.c b/src/ft_get_heal_spawn.c deleted file mode 100644 index 142709b..0000000 --- a/src/ft_get_heal_spawn.c +++ /dev/null @@ -1,45 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* 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 4cb4941..d2f0a31 100644 --- a/src/ft_get_map.c +++ b/src/ft_get_map.c @@ -17,7 +17,7 @@ #include <stdint.h> static void - ft_linecpy(char *line, char *mapl, size_t start) + ft_linecpy(char *line, char *mapl, size_t start, t_cub *cl) { size_t i; size_t j; @@ -29,6 +29,9 @@ static void while (i < slen && line[i]) { mapl[j] = line[i]; + if (mapl[j] - 48 > 2 && mapl[j] - 48 < 10 + && mapl[j] - 48 > cl->mlist.topsp) + ft_error(FT_RET_MAP_ERR, FT_ERR_UNDEF_SPRITE, cl); i++; j++; } @@ -47,7 +50,7 @@ static int8_t return (-1); } ft_linecpy(line, clist->mlist.mapl, - clist->mlist.mapl_len); + clist->mlist.mapl_len, clist); clist->mlist.mapl_len += ft_strlen(line) + 1; return (0); } diff --git a/src/ft_get_spawns.c b/src/ft_get_spawns.c index 6422785..0caedf3 100644 --- a/src/ft_get_spawns.c +++ b/src/ft_get_spawns.c @@ -19,8 +19,8 @@ void { ft_get_player_spawn(&cl->plist, cl); ft_get_sprite_spawn(cl); - ft_get_trap_spawn(cl); - ft_get_heal_spawn(cl); - if (cl->isdead == 0) - ft_get_weapon_spawn(cl); + /* ft_get_trap_spawn(cl); */ + /* ft_get_heal_spawn(cl); */ + /* if (cl->isdead == 0) */ + /* ft_get_weapon_spawn(cl); */ } diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index 05b13b2..64a8284 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -46,6 +46,8 @@ static int8_t return (-1); i++; } + if (i + 2 > clist->mlist.topsp) + clist->mlist.topsp = i + 2; return (0); } diff --git a/src/ft_get_sprite_spawns.c b/src/ft_get_sprite_spawns.c index f4d7e1e..9329c51 100644 --- a/src/ft_get_sprite_spawns.c +++ b/src/ft_get_sprite_spawns.c @@ -14,7 +14,58 @@ #include <cub3d.h> #include <stdint.h> -void +/* +** cl->sprite[] index summary +** -------------------------- +** 0: sprite 2 - tlist[4] - 4096 +** 1: sprite 3 - tlist[8] - 4096 +** 2: sprite 4 - tlist[9] - 4096 +** 3: sprite 5 - tlist[10] - 4096 +** 4: sprite 6 - tlist[11] - 4096 +** 5: sprite 7 - tlist[12] - 4096 +** 6: sprite 8 - tlist[13] - 4096 +** 7: sprite 9 - tlist[14] - 4096 +** 8: trap - tlist[15] - 512 +** 9: heal - tlist[17] - 64 +** 10: weapon one - tlist[18] - 4 +** 11: weapon two - tlist[19] - 4 +** 12: weapon three - tlist[20] - 4 +*/ + +static void + ft_check_amount(t_cub *cl, int s_n) +{ + if (s_n < 8 && cl->mlist.sprite_nbr[s_n] > 4096) + ft_map_error(FT_ERR_TOO_MUCH_SPRT, cl); + else if (s_n == 8 && cl->mlist.sprite_nbr[s_n] > 512) + ft_map_error(FT_ERR_TOO_MUCH_TRAPS, cl); + else if (s_n == 9 && cl->mlist.sprite_nbr[s_n] > 64) + ft_map_error(FT_ERR_TOO_MUCH_HEALS, cl); + else if (s_n == 10 && cl->mlist.sprite_nbr[s_n] > 4) + ft_map_error(FT_ERR_TOO_MUCH_W_ONE, cl); + else if (s_n == 11 && cl->mlist.sprite_nbr[s_n] > 4) + ft_map_error(FT_ERR_TOO_MUCH_W_TWO, cl); + else if (s_n == 12 && cl->mlist.sprite_nbr[s_n] > 4) + ft_map_error(FT_ERR_TOO_MUCH_W_THREE, cl); +} + +static int8_t + ft_other_next_sprite(t_cub *cl, int s_n) +{ + if (s_n + 1 == 8) + return (ft_get_next_sprite(cl, 8, 'T', 0)); + if (s_n + 1 == 9) + return (ft_get_next_sprite(cl, 9, '+', 0)); + if (s_n + 1 == 10) + return (ft_get_next_sprite(cl, 10, '!', 0)); + if (s_n + 1 == 11) + return (ft_get_next_sprite(cl, 11, '@', 0)); + if (s_n + 1 == 12) + return (ft_get_next_sprite(cl, 12, '#', 0)); + return (0); +} + +int8_t ft_get_next_sprite(t_cub *clist, int s_n, char c, size_t x) { size_t y; @@ -30,6 +81,7 @@ void if (clist->mlist.map[y][x] == c) { clist->mlist.sprite_nbr[s_n]++; + clist->sprites[s_n][i].exists = 1; clist->sprites[s_n][i].s_pos_x = x; clist->sprites[s_n][i].s_pos_y = y; i++; @@ -37,11 +89,11 @@ void } 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); - } + ft_check_amount(clist, s_n); + if (/* clist->sprites[s_n][(i - 1 < 0) ? (0) : (i - 1)].s_pos_x != 0 + && */ s_n + 1 <= 7) + return (ft_get_next_sprite(clist, s_n + 1, c + 1, 0)); + return (ft_other_next_sprite(clist, s_n)); } void @@ -62,6 +114,7 @@ void if (ft_ischarset("2", clist->mlist.map[y][x])) { clist->mlist.sprite_nbr[0]++; + clist->sprites[0][i].exists = 1; clist->sprites[0][i].s_pos_x = x; clist->sprites[0][i].s_pos_y = y; i++; diff --git a/src/ft_get_traps.c b/src/ft_get_traps.c index fef3179..db0699c 100644 --- a/src/ft_get_traps.c +++ b/src/ft_get_traps.c @@ -14,35 +14,35 @@ #include <cub3d.h> #include <stdint.h> -void - ft_get_trap_spawn(t_cub *clist) -{ - size_t x; - size_t y; - uint16_t i; +/* void */ +/* ft_get_trap_spawn(t_cub *clist) */ +/* { */ +/* size_t x; */ +/* size_t y; */ +/* uint16_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] == '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++; - } - x++; - } - x = 1; - y++; - } -} +/* x = 1; */ +/* y = 1; */ +/* i = 0; */ +/* while (clist->mlist.map[y]) */ +/* { */ +/* while (clist->mlist.map[y][x]) */ +/* { */ +/* 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++; */ +/* } */ +/* x++; */ +/* } */ +/* x = 1; */ +/* y++; */ +/* } */ +/* } */ int8_t ft_get_traps(char **words, t_cub *clist) diff --git a/src/ft_get_weapon_spawn.c b/src/ft_get_weapon_spawn.c deleted file mode 100644 index 1ed4c7d..0000000 --- a/src/ft_get_weapon_spawn.c +++ /dev/null @@ -1,59 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_get_weapon_spawn.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/02/28 20:54:28 by rbousset #+# #+# */ -/* Updated: 2020/02/28 20:54:29 by rbousset ### ########lyon.fr */ -/* */ -/* ************************************************************************** */ - -#include <libft.h> -#include <cub3d.h> -#include <stdint.h> - -static void - ft_get_weapon_id_spawn(uint8_t id, size_t y, size_t x, t_cub *clist) -{ - clist->mlist.weaps_nbr[id]++; - if (clist->mlist.weaps_nbr[id] > 1) - { - if (id == 0) - ft_map_error(FT_ERR_TOO_MUCH_W_ONE, clist); - else if (id == 1) - ft_map_error(FT_ERR_TOO_MUCH_W_TWO, clist); - else - ft_map_error(FT_ERR_TOO_MUCH_W_THREE, clist); - } - clist->weaps[id][0].s_pos_x = x; - clist->weaps[id][0].s_pos_y = y; - clist->weaps[id][0].current_sprite = 18 + id; - clist->mlist.weapon_var++; -} - -void - ft_get_weapon_spawn(t_cub *clist) -{ - size_t x; - size_t y; - - x = 1; - y = 1; - while (clist->mlist.map[y]) - { - while (clist->mlist.map[y][x]) - { - if (clist->mlist.map[y][x] == '!') - ft_get_weapon_id_spawn(0, y, x, clist); - else if (clist->mlist.map[y][x] == '@') - ft_get_weapon_id_spawn(1, y, x, clist); - else if (clist->mlist.map[y][x] == '#') - ft_get_weapon_id_spawn(2, y, x, clist); - x++; - } - x = 1; - y++; - } -} diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index 942b9a4..2105a64 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -115,8 +115,11 @@ int8_t return (-1); if (ft_init_sprites(&clist->sprites) < 0) return (-1); - if (ft_init_weaps(&clist->weaps) < 0) + if (!(clist->big_t = (float**)ft_calloc(2, sizeof(float*))) || + !(clist->big_t[0] = (float*)ft_calloc(1, sizeof(float))) || + !(clist->big_t[1] = (float*)ft_calloc(1, sizeof(float)))) return (-1); + clist->big_t_val = 2; ft_sprintf(clist->fps_count, "fps: 60"); clist->isdead = 0; clist->moves = 0; diff --git a/src/ft_init_map.c b/src/ft_init_map.c index e0c232c..4d3cc08 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -56,22 +56,19 @@ static int8_t int8_t ft_init_map_norme(t_map *mlist) { + int8_t i; + mlist->darklvl = 0; mlist->scale = 0; mlist->nlx = 0; mlist->nly = 0; mlist->sprite_var = 0; - mlist->weapon_var = 0; mlist->topsp = 0; - ft_bzero(mlist->sprite_nbr, 4096); - ft_bzero(mlist->sprite_order, 4096); - ft_bzero(mlist->st_o, 4096); - ft_bzero(mlist->traps_order, 512); - ft_bzero(mlist->heals_order, 64); - mlist->weaps_nbr[0] = 0; - mlist->weaps_nbr[1] = 0; - mlist->weaps_nbr[2] = 0; - ft_bzero(mlist->weaps_order, 1); + ft_bzero(mlist->sprite_nbr, FT_TOTAL_SPRT * sizeof(int16_t)); + i = -1; + while (++i < FT_TOTAL_SPRT) + ft_bzero(mlist->sprite_order[i], 4096); + ft_bzero(mlist->st_o, FT_TOTAL_SPRT + 1); return (0); } @@ -97,7 +94,5 @@ int8_t mlist->ismusic = 0; mlist->istraps = 0; mlist->isheals = 0; - mlist->traps_nbr = 0; - mlist->heals_nbr = 0; return (ft_init_map_norme(mlist)); } diff --git a/src/ft_init_sprites.c b/src/ft_init_sprites.c index 2099089..ee9506f 100644 --- a/src/ft_init_sprites.c +++ b/src/ft_init_sprites.c @@ -16,19 +16,46 @@ #include <stdlib.h> #include <stdint.h> +/* +** cl->sprite[] index summary +** -------------------------- +** 0: sprite 2 - tlist[4] - 4096 +** 1: sprite 3 - tlist[8] - 4096 +** 2: sprite 4 - tlist[9] - 4096 +** 3: sprite 5 - tlist[10] - 4096 +** 4: sprite 6 - tlist[11] - 4096 +** 5: sprite 7 - tlist[12] - 4096 +** 6: sprite 8 - tlist[13] - 4096 +** 7: sprite 9 - tlist[14] - 4096 +** 8: trap - tlist[15] - 512 +** 9: heal - tlist[17] - 64 +** 10: weapon one - tlist[18] - 4 +** 11: weapon two - tlist[19] - 4 +** 12: weapon three - tlist[20] - 4 +*/ + int8_t ft_init_sprites(t_sprite ***sprites) { - uint8_t i; + int8_t i; - if (!(*sprites = (t_sprite**)ft_calloc(8, sizeof(t_sprite*)))) + if (!(*sprites = (t_sprite**)ft_calloc(FT_TOTAL_SPRT, sizeof(t_sprite*)))) return (-1); - i = 0; - while (i < 8) + i = -1; + while (++i < 8) { if (!(*((*sprites) + i) = (t_sprite*)ft_calloc(4096, sizeof(t_sprite)))) return (-1); - i++; + } + if (!(*((*sprites) + 8) = (t_sprite*)ft_calloc(512, sizeof(t_sprite)))) + return (-1); + if (!(*((*sprites) + 9) = (t_sprite*)ft_calloc(64, sizeof(t_sprite)))) + return (-1); + i = 9; + while (++i < 13) + { + if (!(*((*sprites) + i) = (t_sprite*)ft_calloc(4, sizeof(t_sprite)))) + return (-1); } return (0); } diff --git a/src/ft_init_weaps.c b/src/ft_init_weaps.c deleted file mode 100644 index f3f7452..0000000 --- a/src/ft_init_weaps.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_init_weaps.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_weaps(t_sprite ***weaps) -{ - uint8_t i; - - if (!(*weaps = (t_sprite**)ft_calloc(3, sizeof(t_sprite*)))) - return (-1); - i = 0; - while (i < 3) - { - if (!(*((*weaps) + i) = (t_sprite*)ft_calloc(1, sizeof(t_sprite)))) - return (-1); - i++; - } - return (0); -} diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index 46fe022..3141171 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -80,7 +80,7 @@ static void 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); + ft_alloc_error(clist); ft_sprintf(clist->mlist.filename, "%s", map_path); } diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 8a79154..67c3f4e 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -32,18 +32,18 @@ static void !(rl->fc_tex_x_tab = (int32_t***)malloc(2 * sizeof(int32_t**))) || !(rl->fc_tex_y_tab = (int32_t***)malloc(2 * sizeof(int32_t**))) || !(rl->row_dist_tab = (float*)malloc(y_s * sizeof(float)))) - ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl); + ft_alloc_error(cl); x = -1; while (++x < 2) { if (!(rl->fc_tex_x_tab[x] = (int**)malloc(y_s * sizeof(int*))) || !(rl->fc_tex_y_tab[x] = (int**)malloc(y_s * sizeof(int*)))) - ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl); + ft_alloc_error(cl); y = -1; while (++y < y_s) if (!(rl->fc_tex_x_tab[x][y] = (int*)malloc(x_s * sizeof(int))) || !(rl->fc_tex_y_tab[x][y] = (int*)malloc(x_s * sizeof(int)))) - ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl); + ft_alloc_error(cl); } } @@ -107,9 +107,6 @@ void pthread_join(tid[0], 0x0); pthread_join(tid[1], 0x0); ft_calc_sprite(cl); - ft_calc_heal(cl); - ft_calc_trap(cl); - ft_calc_weaps(cl); if (cl->plist.handles_weapon > -1) ft_draw_handweap(cl); ft_del_tabs(cl); diff --git a/src/ft_select_get.c b/src/ft_select_get.c index d311528..0edc4f2 100644 --- a/src/ft_select_get.c +++ b/src/ft_select_get.c @@ -33,11 +33,12 @@ static int8_t return (-1); else if (ret == 5 && (clist->mlist.sprite_path[0][0])) return (-1); - else if (ret == 6 && ((clist->f_rgb.r != -1) || (clist->f_rgb.g != -1) - || (clist->f_rgb.b != -1))) + if (ret == 6 && (((clist->f_rgb.r != -1) || (clist->f_rgb.g != -1) + || (clist->f_rgb.b != -1)) || clist->mlist.fl_tex_path[0])) return (-1); - else if ((ret == 7 || ret == 12) && ((clist->c_rgb.r != -1) || - (clist->c_rgb.g != -1) || (clist->c_rgb.b != -1))) + if ((ret == 7 || ret == 12) && (((clist->c_rgb.r != -1) || + (clist->c_rgb.g != -1) || (clist->c_rgb.b != -1)) || + clist->mlist.ce_tex_path[0])) return (-1); return (ret); } diff --git a/src/ft_sort_s_t.c b/src/ft_sort_s_t.c index 24ed358..18007dd 100644 --- a/src/ft_sort_s_t.c +++ b/src/ft_sort_s_t.c @@ -12,36 +12,41 @@ #include <libft.h> #include <cub3d.h> +#include <stdlib.h> #include <stdint.h> static void - ft_init_st(uint16_t sprite_var, int32_t st_o[8]) + ft_init_st(int32_t *st_o) { - int8_t i; + int8_t i; - i = -1; - while (++i < sprite_var) + i = 0; + while (i < FT_TOTAL_SPRT) + { st_o[i] = i; + i++; + } } void - ft_sort_s_t(t_cub *cl, float dist_tab[8][4096]) + ft_sort_s_t(t_cub *cl, float **dist_tab) { - int16_t i; - int32_t tmp; - float tmp_i[4096]; + int32_t i; + ft_init_st(cl->mlist.st_o); + i = -1; + while (++i < cl->big_t_val) + ft_memdel((void*)&cl->big_t[i]); + ft_memdel((void*)&cl->big_t); + i = -1; + cl->big_t_val = 0; + while (++i < FT_TOTAL_SPRT) + cl->big_t_val += cl->mlist.sprite_nbr[i]; + ft_alloc_big_t(cl); + ft_fill_big_t(dist_tab, cl); + ft_sort_big_t(cl); i = -1; - ft_init_st(cl->mlist.sprite_var, cl->mlist.st_o); - while (++i < cl->mlist.sprite_var) - if (dist_tab[i][0] < dist_tab[i + 1][0]) - { - tmp = cl->mlist.st_o[i]; - cl->mlist.st_o[i] = cl->mlist.st_o[i + 1]; - cl->mlist.st_o[i + 1] = tmp; - ft_memcpy(tmp_i, dist_tab[i], 4096); - ft_memcpy(dist_tab[i], dist_tab[i + 1], 4096); - ft_memcpy(dist_tab[i + 1], tmp_i, 4096); - i = -1; - } + while (++i < FT_TOTAL_SPRT + 1) + ft_memdel((void*)&dist_tab[i]); + ft_memdel((void*)&dist_tab); } diff --git a/src/ft_tex_sprites_extra_init.c b/src/ft_tex_sprites_extra_init.c index 9ff7612..84684be 100644 --- a/src/ft_tex_sprites_extra_init.c +++ b/src/ft_tex_sprites_extra_init.c @@ -31,5 +31,4 @@ void &cl->tlist[i + 7].endian); i++; } - cl->mlist.topsp = i + 1; } diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index 5055445..f9fac3e 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -60,8 +60,6 @@ static int8_t ft_del_sprites_lists(cl); if (ft_init_sprites(&cl->sprites) < 0) return (-1); - if (ft_init_weaps(&cl->weaps) < 0) - return (-1); if (ft_init_map(&cl->mlist) < 0) return (-1); i = 0; @@ -101,6 +99,7 @@ int8_t char *tmp_mup; uint8_t isoldmus; + cl->walltexgood = 0; if (!(next_path = (char *)malloc((ft_strlen(path) + 1) * sizeof(char)))) return (-1); ft_sprintf(next_path, "%s", path); |