diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-29 17:34:48 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-29 17:34:48 +0200 |
commit | 69ca60b6f989dedc94c2e25ab9927b26d63cbdf8 (patch) | |
tree | 28fb01bf9380925e60c19caaf967cb28685ca3bd | |
parent | The greatest (diff) | |
download | 42-cub3d-69ca60b6f989dedc94c2e25ab9927b26d63cbdf8.tar.gz 42-cub3d-69ca60b6f989dedc94c2e25ab9927b26d63cbdf8.tar.bz2 42-cub3d-69ca60b6f989dedc94c2e25ab9927b26d63cbdf8.tar.xz 42-cub3d-69ca60b6f989dedc94c2e25ab9927b26d63cbdf8.tar.zst 42-cub3d-69ca60b6f989dedc94c2e25ab9927b26d63cbdf8.zip |
Norm
-rw-r--r-- | Makefile | 10 | ||||
-rw-r--r-- | inc/cub3d.h | 4 | ||||
-rw-r--r-- | map/map_five.cub | 2 | ||||
-rw-r--r-- | map/map_one.cub | 9 | ||||
-rw-r--r-- | src/ft_big_t.c | 108 | ||||
-rw-r--r-- | src/ft_draw_heals.c | 106 | ||||
-rw-r--r-- | src/ft_draw_heals_extra.c | 40 | ||||
-rw-r--r-- | src/ft_draw_sprite.c | 42 | ||||
-rw-r--r-- | src/ft_draw_sprite_extra.c | 4 | ||||
-rw-r--r-- | src/ft_draw_traps.c | 104 | ||||
-rw-r--r-- | src/ft_draw_traps_extra.c | 40 | ||||
-rw-r--r-- | src/ft_draw_weapons.c | 111 | ||||
-rw-r--r-- | src/ft_draw_weapons_extra.c | 42 | ||||
-rw-r--r-- | src/ft_get_heal_spawn.c | 45 | ||||
-rw-r--r-- | src/ft_get_weapon_spawn.c | 59 | ||||
-rw-r--r-- | src/ft_init_weaps.c | 34 | ||||
-rw-r--r-- | src/ft_raycasting.c | 3 | ||||
-rw-r--r-- | src/ft_sort_s_t.c | 110 |
18 files changed, 135 insertions, 738 deletions
@@ -85,8 +85,6 @@ SRCS_NAME += ft_init_bmp.c SRCS_NAME += ft_floor_cast.c SRCS_NAME += ft_floor_cast_inits.c SRCS_NAME += ft_suffer_animation.c -# SRCS_NAME += ft_draw_traps.c -# SRCS_NAME += ft_draw_traps_extra.c SRCS_NAME += ft_draw_life_bar.c SRCS_NAME += ft_init_sfx.c SRCS_NAME += ft_sfx_death.c @@ -103,17 +101,10 @@ SRCS_NAME += ft_death_screen.c SRCS_NAME += ft_death_hooks.c SRCS_NAME += ft_init_sprites.c SRCS_NAME += ft_get_fps_count.c -# SRCS_NAME += ft_get_heal_spawn.c -# SRCS_NAME += ft_draw_heals.c -# SRCS_NAME += ft_draw_heals_extra.c SRCS_NAME += ft_find_item.c SRCS_NAME += ft_tex_weap_init.c -# SRCS_NAME += ft_get_weapon_spawn.c -# SRCS_NAME += ft_draw_weapons.c -# SRCS_NAME += ft_draw_weapons_extra.c SRCS_NAME += ft_draw_handweap.c SRCS_NAME += ft_switch_weapons.c -# SRCS_NAME += ft_init_weaps.c SRCS_NAME += ft_check_missing_defines.c SRCS_NAME += ft_check_missing_sfx.c SRCS_NAME += ft_del_tex.c @@ -135,6 +126,7 @@ SRCS_NAME += ft_wall_threads.c SRCS_NAME += ft_floor_threads.c SRCS_NAME += ft_castray_loop.c SRCS_NAME += ft_sort_s_t.c +SRCS_NAME += ft_big_t.c #--------------------------------------------------------------------------------------------------# SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME}) #--------------------------------------------------------------------------------------------------# diff --git a/inc/cub3d.h b/inc/cub3d.h index 82808f4..aa81b4c 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -87,7 +87,9 @@ void ft_draw_circle(float a, float b, int32_t color, t_cub *cl); void ft_draw_verline(t_cub *cl, int32_t x, int32_t y, int32_t y2); void ft_sprite_h_w(t_cub *cl, t_sprite *sprite); -float **ft_alloc_dist_tab(void); +void ft_alloc_big_t(t_cub *cl); +void ft_fill_big_t(float **dist_tab, t_cub *cl); +void ft_sort_big_t(t_cub *cl); void ft_sort_sprites(t_cub *cl, int16_t i, int16_t j); void ft_sort_s_t(t_cub *cl, float **dist_tab); void ft_calc_sprite(t_cub *cl); diff --git a/map/map_five.cub b/map/map_five.cub index b92f4e3..2a11f0c 100644 --- a/map/map_five.cub +++ b/map/map_five.cub @@ -23,7 +23,7 @@ SH 4 11110111111111011100000010001 11110111111111010001010000001 11000000110101010000000000001 -10002000000000000000000000001 +10000000000000000000000000001 10000000000000000001010000001 11000001110101011111011110N01 11110111 1110101 101111 10001 diff --git a/map/map_one.cub b/map/map_one.cub index 3d45184..43b9268 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -15,6 +15,7 @@ S5 ./media/img/sprites/linus.xpm S6 ./media/img/sprites/linus.xpm S7 ./media/img/sprites/linus.xpm S8 ./media/img/sprites/pylon.xpm +S9 ./media/img/sprites/wood_chest.xpm T ./media/img/sprites/spikes.xpm @@ -22,7 +23,7 @@ SH 2 1111111111111111111 1000000000000000001 - 1000000080000000001 + 1000900080000000001 1000000000000000001 111111111111000000000005000001 10000000000000000T0T0T00000001 @@ -31,9 +32,9 @@ SH 2 1001000000T0000000000000000001 10110+0+0111000001110000000111 111111111111110011 100000001 -1000001 100001 111111111 -1001001 100001 -1011001 100001 +1000001 190001 111111111 +1001001 190001 +1911001 190001 111101111111110111 10000000110101011 10000000000000001 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_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_sprite.c b/src/ft_draw_sprite.c index 41daec4..e41484e 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -16,25 +16,23 @@ #include <stdlib.h> #include <math.h> -/* static void */ -/* ft_sort_sprites_norme(float *dist_tab, int16_t *i, uint16_t j, t_cub *cl) */ -/* { */ -/* uint32_t tmp; */ -/* uint32_t it; */ +static float + **ft_alloc_dist_tab(void) +{ + uint16_t i; + float **dist_tab; -/* 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.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 = (float **)ft_calloc((FT_TOTAL_SPRT + 1), sizeof(float*)))) + return (NULL); + i = 0; + while (i < FT_TOTAL_SPRT + 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) @@ -56,18 +54,10 @@ void (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; */ } it = -1; } } - /* jt = -1; */ - /* while (++jt < FT_TOTAL_SPRT) */ - /* { */ - /* it = -1; */ - /* while (++it < cl->mlist.sprite_nbr[jt] - 1) */ - /* ft_sort_sprites_norme(dist_tab[jt], &it, jt, cl); */ - /* } */ ft_sort_s_t(cl, dist_tab); } diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index ba2dac5..c201566 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -59,9 +59,7 @@ void ft_sort_sprites(cl, -1, -1); while (++j < cl->big_t_val) { - sprite = - cl->sprites[(int8_t)cl->big_t[j][2]] - [(int16_t)cl->big_t[j][3]]; + 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); 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_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_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_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_raycasting.c b/src/ft_raycasting.c index 3bfd038..67c3f4e 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -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_sort_s_t.c b/src/ft_sort_s_t.c index 433fd07..18007dd 100644 --- a/src/ft_sort_s_t.c +++ b/src/ft_sort_s_t.c @@ -15,116 +15,6 @@ #include <stdlib.h> #include <stdint.h> -float - **ft_alloc_dist_tab(void) -{ - uint16_t i; - float **dist_tab; - - if (!(dist_tab = (float **)ft_calloc((FT_TOTAL_SPRT + 1), sizeof(float*)))) - return (NULL); - i = 0; - while (i < FT_TOTAL_SPRT + 1) - { - if (!(dist_tab[i] = (float *)ft_calloc(4096, sizeof(float)))) - return (NULL); - i++; - } - return (dist_tab); -} - -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); -} - -static 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++; - } -} - -static 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++; - } - } -} - -static 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++; - } -} - static void ft_init_st(int32_t *st_o) { |