diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-09 02:11:22 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-09 02:11:31 +0100 |
commit | 40108b83398240f50c6045bfb2bf114bded43c72 (patch) | |
tree | 61e0e483e31e17724b2dd7e1a70088659e5be1bd /src | |
parent | Boy (diff) | |
download | 42-cub3d-40108b83398240f50c6045bfb2bf114bded43c72.tar.gz 42-cub3d-40108b83398240f50c6045bfb2bf114bded43c72.tar.bz2 42-cub3d-40108b83398240f50c6045bfb2bf114bded43c72.tar.xz 42-cub3d-40108b83398240f50c6045bfb2bf114bded43c72.tar.zst 42-cub3d-40108b83398240f50c6045bfb2bf114bded43c72.zip |
Reparse, may not compile
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_exit.c | 2 | ||||
-rw-r--r-- | src/ft_floor_cast.c | 51 | ||||
-rw-r--r-- | src/ft_get_colors.c | 2 | ||||
-rw-r--r-- | src/ft_get_tex_extra.c | 70 | ||||
-rw-r--r-- | src/ft_init_map.c | 4 | ||||
-rw-r--r-- | src/ft_tex_init.c | 10 | ||||
-rw-r--r-- | src/ft_warp_level.c | 2 |
7 files changed, 118 insertions, 23 deletions
diff --git a/src/ft_exit.c b/src/ft_exit.c index be4d46e..659d0ec 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -29,6 +29,8 @@ static void ft_memdel((void**)&clist->mlist.we_tex_path); ft_memdel((void**)&clist->mlist.sprite_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.music_path); ft_memdel((void**)&clist->mlist.music_cmd); diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c index 1b22a71..de53666 100644 --- a/src/ft_floor_cast.c +++ b/src/ft_floor_cast.c @@ -13,13 +13,13 @@ #include <cub3d.h> #include <stdint.h> -/* static void */ -/* ft_draw_plain_horizontal(t_rgb rgb, t_cub *cl, int32_t y, int32_t x) */ -/* { */ -/* *(int*)(cl->img.ptr + */ -/* (x * 4 + (y * cl->img.sizeline))) */ -/* = ft_darken(rgb, cl); */ -/* } */ +static void + ft_draw_plain_horizontal(t_rgb rgb, t_cub *cl, int32_t y, int32_t x) +{ + *(int*)(cl->img.ptr + + (x * 4 + (y * cl->img.sizeline))) + = ft_darken(rgb, cl); +} static void ft_draw_extra_tex(uint8_t tid, uint16_t y, uint16_t x, t_cub *cl) @@ -45,24 +45,37 @@ static void } 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); + cl->tlist[tid].tex_x = (int32_t)(cl->tlist[tid].img_h + * (rl->y_floor - rl->y_cell)) % (cl->tlist[tid].img_h); +} + +static void ft_floor_cast_loop(uint16_t y, uint16_t x, t_ray *rl, t_cub *cl) { rl->x_cell = (int32_t)(rl->x_floor); rl->y_cell = (int32_t)(rl->y_floor); - cl->tlist[6].tex_y = (int32_t)(cl->tlist[6].img_w - * (rl->x_floor - rl->x_cell)) % (cl->tlist[6].img_w); - cl->tlist[6].tex_x = (int32_t)(cl->tlist[6].img_h - * (rl->y_floor - rl->y_cell)) % (cl->tlist[6].img_h); - cl->tlist[7].tex_y = (int32_t)(cl->tlist[7].img_w - * (rl->x_floor - rl->x_cell)) % (cl->tlist[7].img_w); - cl->tlist[7].tex_x = (int32_t)(cl->tlist[7].img_h - * (rl->y_floor - rl->y_cell)) % (cl->tlist[7].img_h); + if (cl->mlist.isftex) + { + ft_set_tex_xy(6, rl, cl); + } + if (cl->mlist.isctex) + { + ft_set_tex_xy(7, rl, cl); + } rl->x_floor += cl->mlist.x_floor_step; rl->y_floor += cl->mlist.y_floor_step; - ft_draw_extra_tex(6, y, x, cl); - ft_draw_extra_tex(7, cl->wlist.y_size - y - 1, x, cl); - /* ft_draw_plain_horizontal(cl->f_rgb, cl, y, x); */ - /* ft_draw_plain_horizontal(cl->c_rgb, cl, cl->wlist.y_size - y - 1, x); */ + if (cl->mlist.isftex) + ft_draw_extra_tex(6, y, x, cl); + else + ft_draw_plain_horizontal(cl->f_rgb, cl, y, x); + if (cl->mlist.isctex) + ft_draw_extra_tex(7, cl->wlist.y_size - y - 1, x, cl); + else + ft_draw_plain_horizontal(cl->c_rgb, cl, cl->wlist.y_size - y - 1, x); } void diff --git a/src/ft_get_colors.c b/src/ft_get_colors.c index 69eb8f8..47b8265 100644 --- a/src/ft_get_colors.c +++ b/src/ft_get_colors.c @@ -74,6 +74,8 @@ int8_t ft_sprintf(clist->errmsg, FT_ERR_ARGS); return (-1); } + if (!ft_check_ext(words[1], ".xpm")) + return (ft_get_f_tex(words, clist)) if (!(num = ft_split(words[1], ','))) { ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE); diff --git a/src/ft_get_tex_extra.c b/src/ft_get_tex_extra.c new file mode 100644 index 0000000..acb7495 --- /dev/null +++ b/src/ft_get_tex_extra.c @@ -0,0 +1,70 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_get_tex_extra.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> + +int8_t + ft_get_f_tex(char **words, t_cub *clist) +{ + if (!(*words) || !(*(words + 1)) || (*(words + 2))) + { + ft_sprintf(clist->errmsg, "%s", FT_ERR_ARGS); + return (-1); + } + if (ft_check_ext(*(words + 1), ".xpm") < 0) + { + ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM); + return (-1); + } + 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); + return (-1); + } + if (ft_check_not_found(clist->mlist.fl_tex_path) < 0) + { + ft_sprintf(clist->errmsg, FT_ERR_RD_NL_TEX); + return (-1); + } + clist->isftex = 1; + return (0); +} + +int8_t + ft_get_c_tex(char **words, t_cub *clist) +{ + if (!(*words) || !(*(words + 1)) || (*(words + 2))) + { + ft_sprintf(clist->errmsg, "%s", FT_ERR_ARGS); + return (-1); + } + if (ft_check_ext(*(words + 1), ".xpm") < 0) + { + ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM); + return (-1); + } + 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); + return (-1); + } + if (ft_check_not_found(clist->mlist.ce_tex_path) < 0) + { + ft_sprintf(clist->errmsg, FT_ERR_RD_NL_TEX); + return (-1); + } + clist->isctex = 1; + return (0); +} diff --git a/src/ft_init_map.c b/src/ft_init_map.c index 1c12189..457f241 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -25,6 +25,8 @@ static int8_t !(mlist->we_tex_path = (char*)ft_calloc(1, sizeof(char))) || !(mlist->sprite_path = (char*)ft_calloc(1, sizeof(char))) || !(mlist->nl_tex_path = (char*)ft_calloc(1, sizeof(char))) || + !(mlist->fl_tex_path = (char*)ft_calloc(1, sizeof(char))) || + !(mlist->ce_tex_path = (char*)ft_calloc(1, sizeof(char))) || !(mlist->nlevel_path = (char*)ft_calloc(1, sizeof(char))) || !(mlist->music_path = (char*)ft_calloc(1, sizeof(char))) || !(mlist->music_cmd = (char*)ft_calloc(1, sizeof(char))) || @@ -52,6 +54,8 @@ int8_t mlist->line_chk = 0; mlist->map_start = 0; mlist->isspawn = 0; + mlist->iftex = 0; + mlist->ictex = 0; mlist->isnlvl = 0; mlist->ismusic = 0; mlist->scale = 0; diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index 599e902..1fce584 100644 --- a/src/ft_tex_init.c +++ b/src/ft_tex_init.c @@ -37,7 +37,7 @@ static void ft_get_floor_tex(t_cub *cl) { cl->tlist[6].img = mlx_xpm_file_to_image(cl->wlist.wlx, - cl->mlist.no_tex_path, &cl->tlist[6].img_w, &cl->tlist[6].img_h); + cl->mlist.fl_tex_path, &cl->tlist[6].img_w, &cl->tlist[6].img_h); cl->tlist[6].ptr = mlx_get_data_addr(cl->tlist[6].img, &cl->tlist[6].bpp, &cl->tlist[6].sizeline, &cl->tlist[6].endian); } @@ -46,7 +46,7 @@ static void ft_get_ceil_tex(t_cub *cl) { cl->tlist[7].img = mlx_xpm_file_to_image(cl->wlist.wlx, - cl->mlist.no_tex_path, &cl->tlist[7].img_w, &cl->tlist[7].img_h); + cl->mlist.ce_tex_path, &cl->tlist[7].img_w, &cl->tlist[7].img_h); cl->tlist[7].ptr = mlx_get_data_addr(cl->tlist[7].img, &cl->tlist[7].bpp, &cl->tlist[7].sizeline, &cl->tlist[7].endian); } @@ -76,7 +76,9 @@ void &cl->tlist[4].bpp, &cl->tlist[4].sizeline, &cl->tlist[4].endian); if (cl->mlist.isnlvl) ft_get_nlvl_img(cl); - ft_get_floor_tex(cl); - ft_get_ceil_tex(cl); + if (cl->mlist.isftex) + ft_get_floor_tex(cl); + if (cl->mlist.isctex) + ft_get_ceil_tex(cl); cl->walltexgood = 1; } diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index 09fbc7c..de2103d 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -30,6 +30,8 @@ static void ft_memdel((void**)&ml->we_tex_path); ft_memdel((void**)&ml->sprite_path); ft_memdel((void**)&ml->nl_tex_path); + ft_memdel((void**)&ml->fl_tex_path); + ft_memdel((void**)&ml->ce_tex_path); ft_memdel((void**)&ml->nlevel_path); ft_memdel((void**)&ml->music_path); ft_memdel((void**)&ml->music_cmd); |