diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-03 14:47:33 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-03 14:47:33 +0100 |
commit | 8866ef5699150d0549096efa94fc311ff7a48dc7 (patch) | |
tree | 4a03267f7e7f9b399a9ad0536b50ba6a90407e47 | |
parent | Music is pretty bav (diff) | |
download | 42-cub3d-8866ef5699150d0549096efa94fc311ff7a48dc7.tar.gz 42-cub3d-8866ef5699150d0549096efa94fc311ff7a48dc7.tar.bz2 42-cub3d-8866ef5699150d0549096efa94fc311ff7a48dc7.tar.xz 42-cub3d-8866ef5699150d0549096efa94fc311ff7a48dc7.tar.zst 42-cub3d-8866ef5699150d0549096efa94fc311ff7a48dc7.zip |
Changing stuff
44 files changed, 713 insertions, 719 deletions
@@ -20,56 +20,56 @@ INCS += cub3d_defines.h INCS += cub3d_structs.h #--------------------------------------------------------------------------------------------------# SRCS_NAME = main.c -SRCS_NAME += ft_init_lists.c -SRCS_NAME += ft_hooks_and_loops.c -SRCS_NAME += ft_key_events.c -SRCS_NAME += ft_click_close.c -SRCS_NAME += ft_exit.c -SRCS_NAME += ft_parse_map.c -SRCS_NAME += ft_select_get.c -SRCS_NAME += ft_get_screen_size.c -SRCS_NAME += ft_get_res.c -SRCS_NAME += ft_get_tex.c -SRCS_NAME += ft_get_sprite.c -SRCS_NAME += ft_get_colors.c -SRCS_NAME += ft_get_map.c -SRCS_NAME += ft_get_tex_nl.c -SRCS_NAME += ft_get_path_nl.c -SRCS_NAME += ft_get_nlvl_pos.c -SRCS_NAME += ft_get_player_spawn.c -SRCS_NAME += ft_get_music.c -SRCS_NAME += ft_set_minimap_scale.c -SRCS_NAME += ft_check_missing.c -SRCS_NAME += ft_check_not_found.c -SRCS_NAME += ft_check_map_line.c -SRCS_NAME += ft_free_words.c -SRCS_NAME += ft_map_error.c -SRCS_NAME += ft_init_winlx.c -SRCS_NAME += ft_draw_square.c -SRCS_NAME += ft_draw_circle.c -SRCS_NAME += ft_draw_map.c -SRCS_NAME += ft_draw_scene.c -SRCS_NAME += ft_basic_keys.c -SRCS_NAME += ft_extra_keys.c -SRCS_NAME += ft_draw_verline.c -SRCS_NAME += ft_rgb_to_hex.c -SRCS_NAME += ft_raycasting.c -SRCS_NAME += ft_init_s_ray.c -SRCS_NAME += ft_init_map.c -SRCS_NAME += ft_tex_init.c -SRCS_NAME += ft_detect.c -SRCS_NAME += ft_check_ext.c -SRCS_NAME += ft_draw_textures.c -SRCS_NAME += ft_key_release.c -SRCS_NAME += ft_convert_keycode.c -SRCS_NAME += ft_key_loop.c -SRCS_NAME += ft_draw_hud.c -SRCS_NAME += ft_music.c -SRCS_NAME += ft_draw_sprite.c -SRCS_NAME += ft_warp_level.c -SRCS_NAME += ft_save_to_bmp.c -SRCS_NAME += ft_treat_args.c -SRCS_NAME += ft_init_funptr.c +# SRCS_NAME += ft_init_lists.c +# SRCS_NAME += ft_hooks_and_loops.c +# SRCS_NAME += ft_key_events.c +# SRCS_NAME += ft_click_close.c +# SRCS_NAME += ft_exit.c +# SRCS_NAME += ft_parse_map.c +# SRCS_NAME += ft_select_get.c +# SRCS_NAME += ft_get_screen_size.c +# SRCS_NAME += ft_get_res.c +# SRCS_NAME += ft_get_tex.c +# SRCS_NAME += ft_get_sprite.c +# SRCS_NAME += ft_get_colors.c +# SRCS_NAME += ft_get_map.c +# SRCS_NAME += ft_get_tex_nl.c +# SRCS_NAME += ft_get_path_nl.c +# SRCS_NAME += ft_get_nlvl_pos.c +# SRCS_NAME += ft_get_player_spawn.c +# SRCS_NAME += ft_get_music.c +# SRCS_NAME += ft_set_minimap_scale.c +# SRCS_NAME += ft_check_missing.c +# SRCS_NAME += ft_check_not_found.c +# SRCS_NAME += ft_check_map_line.c +# SRCS_NAME += ft_free_words.c +# SRCS_NAME += ft_map_error.c +# SRCS_NAME += ft_init_winlx.c +# SRCS_NAME += ft_draw_square.c +# SRCS_NAME += ft_draw_circle.c +# SRCS_NAME += ft_draw_map.c +# SRCS_NAME += ft_draw_scene.c +# SRCS_NAME += ft_basic_keys.c +# SRCS_NAME += ft_extra_keys.c +# SRCS_NAME += ft_draw_verline.c +# SRCS_NAME += ft_rgb_to_hex.c +# SRCS_NAME += ft_raycasting.c +# SRCS_NAME += ft_init_s_ray.c +# SRCS_NAME += ft_init_map.c +# SRCS_NAME += ft_tex_init.c +# SRCS_NAME += ft_detect.c +# SRCS_NAME += ft_check_ext.c +# SRCS_NAME += ft_draw_textures.c +# SRCS_NAME += ft_key_release.c +# SRCS_NAME += ft_convert_keycode.c +# SRCS_NAME += ft_key_loop.c +# SRCS_NAME += ft_draw_hud.c +# SRCS_NAME += ft_music.c +# SRCS_NAME += ft_draw_sprite.c +# SRCS_NAME += ft_warp_level.c +# SRCS_NAME += ft_save_to_bmp.c +# SRCS_NAME += ft_treat_args.c +# SRCS_NAME += ft_init_funptr.c #--------------------------------------------------------------------------------------------------# SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME}) #--------------------------------------------------------------------------------------------------# diff --git a/src/ft_basic_keys.c b/src/ft_basic_keys.c index ff74262..1bc9821 100644 --- a/src/ft_basic_keys.c +++ b/src/ft_basic_keys.c @@ -19,9 +19,9 @@ int t_player *pl; const float move_speed = FT_MOVE_SPEED; - pl = clist->plist; - pl->pos_y += move_speed * pl->dir_x; - pl->pos_x += move_speed * pl->dir_y; + pl = clist.plist; + pl.pos_y += move_speed * pl.dir_x; + pl.pos_x += move_speed * pl.dir_y; return (0); } @@ -31,9 +31,9 @@ int t_player *pl; const float move_speed = FT_STRAFE_SPEED; - pl = clist->plist; - pl->pos_y += move_speed * -pl->dir_y; - pl->pos_x += move_speed * pl->dir_x; + pl = clist.plist; + pl.pos_y += move_speed * -pl.dir_y; + pl.pos_x += move_speed * pl.dir_x; return (0); } @@ -43,9 +43,9 @@ int t_player *pl; const float move_speed = FT_MOVE_SPEED; - pl = clist->plist; - pl->pos_y += move_speed * -pl->dir_x; - pl->pos_x += move_speed * -pl->dir_y; + pl = clist.plist; + pl.pos_y += move_speed * -pl.dir_x; + pl.pos_x += move_speed * -pl.dir_y; return (0); } @@ -55,8 +55,8 @@ int t_player *pl; const float move_speed = FT_STRAFE_SPEED; - pl = clist->plist; - pl->pos_y += move_speed * pl->dir_y; - pl->pos_x += move_speed * -pl->dir_x; + pl = clist.plist; + pl.pos_y += move_speed * pl.dir_y; + pl.pos_x += move_speed * -pl.dir_x; return (0); } diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c index 184e489..4368a18 100644 --- a/src/ft_check_map_line.c +++ b/src/ft_check_map_line.c @@ -20,21 +20,21 @@ static int8_t { if (!ft_ischarset("012NSEWL ", line[i])) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_ILL_MAP); + ft_sprintf(clist.errmsg, "%s", FT_ERR_ILL_MAP); return (-1); } if (ft_ischarset("NSEW", line[i])) - clist->mlist->isspawn += 1; - if (clist->mlist->isspawn > 1) + clist.mlist.isspawn += 1; + if (clist.mlist.isspawn > 1) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_MULT_SPAWN); + ft_sprintf(clist.errmsg, "%s", FT_ERR_MULT_SPAWN); return (-1); } if (line[i] == 'L') - clist->mlist->isnlvl += 1; - if (clist->mlist->isnlvl > 1) + clist.mlist.isnlvl += 1; + if (clist.mlist.isnlvl > 1) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_MULT_NLVL); + ft_sprintf(clist.errmsg, "%s", FT_ERR_MULT_NLVL); return (-1); } return (0); @@ -45,7 +45,7 @@ static int8_t { if (!ft_ischarset("1 ", line[i])) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_ILL_MAP); + ft_sprintf(clist.errmsg, "%s", FT_ERR_ILL_MAP); return (-1); } return (0); @@ -73,7 +73,7 @@ static int8_t { if (line[0] != '1' || line[i - 1] != '1') { - ft_sprintf(clist->errmsg, "%s", FT_ERR_ILL_ENTRY); + ft_sprintf(clist.errmsg, "%s", FT_ERR_ILL_ENTRY); return (-1); } return (0); @@ -100,9 +100,9 @@ int8_t } if (ft_check_side_walls(line, i, clist) < 0) return (-1); - if (ft_get_line_len(line) != clist->mlist->map_w) + if (ft_get_line_len(line) != clist.mlist.map_w) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_MAP_LEN); + ft_sprintf(clist.errmsg, "%s", FT_ERR_MAP_LEN); return (-1); } return (0); diff --git a/src/ft_check_missing.c b/src/ft_check_missing.c index 4828250..caaca9e 100644 --- a/src/ft_check_missing.c +++ b/src/ft_check_missing.c @@ -26,29 +26,29 @@ int int ft_check_missing(t_cub *clist) { - if (!clist->mlist->no_tex_path[0]) + if (!clist.mlist.no_tex_path[0]) return (ft_missing_error(FT_ERR_MISS_NORTH, clist)); - else if (!clist->mlist->so_tex_path[0]) + else if (!clist.mlist.so_tex_path[0]) return (ft_missing_error(FT_ERR_MISS_SOUTH, clist)); - else if (!clist->mlist->ea_tex_path[0]) + else if (!clist.mlist.ea_tex_path[0]) return (ft_missing_error(FT_ERR_MISS_EAST, clist)); - else if (!clist->mlist->we_tex_path[0]) + else if (!clist.mlist.we_tex_path[0]) return (ft_missing_error(FT_ERR_MISS_WEST, clist)); - else if (!clist->mlist->sprite_path[0]) + else if (!clist.mlist.sprite_path[0]) return (ft_missing_error(FT_ERR_MISS_SPRITE, clist)); - else if (clist->wlist->x_size == 0 || clist->wlist->y_size == 0) + else if (clist.wlist.x_size == 0 || clist.wlist.y_size == 0) return (ft_missing_error(FT_ERR_MISS_RESOLUTION, clist)); - else if (clist->f_rgb.r == -1 || clist->f_rgb.g == -1 - || clist->f_rgb.b == -1) + else if (clist.f_rgb.r == -1 || clist.f_rgb.g == -1 + || clist.f_rgb.b == -1) return (ft_missing_error(FT_ERR_MISS_FLOOR_C, clist)); - else if (clist->c_rgb.r == -1 || clist->c_rgb.g == -1 - || clist->c_rgb.b == -1) + else if (clist.c_rgb.r == -1 || clist.c_rgb.g == -1 + || clist.c_rgb.b == -1) return (ft_missing_error(FT_ERR_MISS_CEIL_C, clist)); - else if (clist->plist->pos_x == 0 || clist->plist->pos_y == 0) + else if (clist.plist.pos_x == 0 || clist.plist.pos_y == 0) return (ft_missing_error(FT_ERR_MISS_PLAYER_SPAWN, clist)); - else if (clist->mlist->isnlvl && !clist->mlist->nl_tex_path[0]) + else if (clist.mlist.isnlvl && !clist.mlist.nl_tex_path[0]) return (ft_missing_error(FT_ERR_MISS_NLVL, clist)); - else if (clist->mlist->isnlvl && !clist->mlist->nlevel_path[0]) + else if (clist.mlist.isnlvl && !clist.mlist.nlevel_path[0]) return (ft_missing_error(FT_ERR_MISS_NLVL_PATH, clist)); return (0); } diff --git a/src/ft_detect.c b/src/ft_detect.c index a8b5a6c..864b2b2 100644 --- a/src/ft_detect.c +++ b/src/ft_detect.c @@ -17,40 +17,40 @@ static void ft_detection_init_y(t_cub *cl) { - cl->rlist.y_delta_dist = sqrt(1 + (cl->rlist.x_ray_dir * - cl->rlist.x_ray_dir) / (cl->rlist.y_ray_dir * - cl->rlist.y_ray_dir)); - if (cl->rlist.y_ray_dir < 0) + cl.rlist.y_delta_dist = sqrt(1 + (cl.rlist.x_ray_dir * + cl.rlist.x_ray_dir) / (cl.rlist.y_ray_dir * + cl.rlist.y_ray_dir)); + if (cl.rlist.y_ray_dir < 0) { - cl->mlist->y_step = -1; - cl->rlist.y_side_dist = (cl->rlist.y_ray_pos - - cl->rlist.sqy) * cl->rlist.y_delta_dist; + cl.mlist.y_step = -1; + cl.rlist.y_side_dist = (cl.rlist.y_ray_pos - + cl.rlist.sqy) * cl.rlist.y_delta_dist; } else { - cl->mlist->y_step = 1; - cl->rlist.y_side_dist = (cl->rlist.sqy + 1.0 - - cl->rlist.y_ray_pos) * cl->rlist.y_delta_dist; + cl.mlist.y_step = 1; + cl.rlist.y_side_dist = (cl.rlist.sqy + 1.0 - + cl.rlist.y_ray_pos) * cl.rlist.y_delta_dist; } } static void ft_detection_init_x(t_cub *cl) { - cl->rlist.x_delta_dist = sqrt(1 + (cl->rlist.y_ray_dir * - cl->rlist.y_ray_dir) / (cl->rlist.x_ray_dir * - cl->rlist.x_ray_dir)); - if (cl->rlist.x_ray_dir < 0) + cl.rlist.x_delta_dist = sqrt(1 + (cl.rlist.y_ray_dir * + cl.rlist.y_ray_dir) / (cl.rlist.x_ray_dir * + cl.rlist.x_ray_dir)); + if (cl.rlist.x_ray_dir < 0) { - cl->mlist->x_step = -1; - cl->rlist.x_side_dist = (cl->rlist.x_ray_pos - - cl->rlist.sqx) * cl->rlist.x_delta_dist; + cl.mlist.x_step = -1; + cl.rlist.x_side_dist = (cl.rlist.x_ray_pos - + cl.rlist.sqx) * cl.rlist.x_delta_dist; } else { - cl->mlist->x_step = 1; - cl->rlist.x_side_dist = (cl->rlist.sqx + 1.0 - - cl->rlist.x_ray_pos) * cl->rlist.x_delta_dist; + cl.mlist.x_step = 1; + cl.rlist.x_side_dist = (cl.rlist.sqx + 1.0 - + cl.rlist.x_ray_pos) * cl.rlist.x_delta_dist; } } @@ -59,23 +59,23 @@ void { ft_detection_init_x(cl); ft_detection_init_y(cl); - cl->rlist.hit = 0; - while (cl->rlist.hit == 0) + cl.rlist.hit = 0; + while (cl.rlist.hit == 0) { - if (cl->rlist.x_side_dist < cl->rlist.y_side_dist) + if (cl.rlist.x_side_dist < cl.rlist.y_side_dist) { - cl->rlist.x_side_dist += cl->rlist.x_delta_dist; - cl->rlist.sqx += cl->mlist->x_step; - cl->rlist.side = 0; + cl.rlist.x_side_dist += cl.rlist.x_delta_dist; + cl.rlist.sqx += cl.mlist.x_step; + cl.rlist.side = 0; } else { - cl->rlist.y_side_dist += cl->rlist.y_delta_dist; - cl->rlist.sqy += cl->mlist->y_step; - cl->rlist.side = 1; + cl.rlist.y_side_dist += cl.rlist.y_delta_dist; + cl.rlist.sqy += cl.mlist.y_step; + cl.rlist.side = 1; } - if (cl->mlist->map[cl->rlist.sqx][cl->rlist.sqy] == '1' || - cl->mlist->map[cl->rlist.sqx][cl->rlist.sqy] == 'L') - cl->rlist.hit = 1; + if (cl.mlist.map[cl.rlist.sqx][cl.rlist.sqy] == '1' || + cl.mlist.map[cl.rlist.sqx][cl.rlist.sqy] == 'L') + cl.rlist.hit = 1; } } diff --git a/src/ft_draw_circle.c b/src/ft_draw_circle.c index 570543a..eba6869 100644 --- a/src/ft_draw_circle.c +++ b/src/ft_draw_circle.c @@ -25,7 +25,7 @@ void float y1; i = 0; - scale = cl->mlist->scale / 2.5; + scale = cl.mlist.scale / 2.5; while (scale > 0) { while (i < 360) @@ -33,8 +33,8 @@ void angle = i; x1 = scale * cos(angle * 3.14159265358979323846 / 180); y1 = scale * sin(angle * 3.14159265358979323846 / 180); - *(int*)(cl->img.ptr + ((int)a + (int)x1) * 4 + - (((int)b + (int)y1) * cl->img.sizeline)) = color; + *(int*)(cl.img.ptr + ((int)a + (int)x1) * 4 + + (((int)b + (int)y1) * cl.img.sizeline)) = color; i += 0.1; } i = 0; diff --git a/src/ft_draw_hud.c b/src/ft_draw_hud.c index 9cb5b1c..b54e9e5 100644 --- a/src/ft_draw_hud.c +++ b/src/ft_draw_hud.c @@ -17,19 +17,19 @@ static void ft_draw_hud_back(t_win *wl, t_cub *cl) { - const uint16_t scl = cl->mlist->scale; + const uint16_t scl = cl.mlist.scale; uint32_t x; uint32_t y; int32_t col; col = 0x00404040; x = 0; - y = wl->y_size - ((cl->mlist->map_h * scl)); - while (x < wl->x_size) + y = wl.y_size - ((cl.mlist.map_h * scl)); + while (x < wl.x_size) { - while (y < wl->y_size) + while (y < wl.y_size) { - *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = col; + *(int*)(cl.img.ptr + (x * 4 + (y * cl.img.sizeline))) = col; if (!(y % 3)) { if (col < 0x00909090) @@ -38,7 +38,7 @@ static void y++; } col = 0x00404040; - y = wl->y_size - ((cl->mlist->map_h * scl)); + y = wl.y_size - ((cl.mlist.map_h * scl)); x++; } } @@ -46,19 +46,19 @@ static void static void ft_draw_hud_back_top_l(size_t map_h, size_t map_w, t_win *wl, t_cub *cl) { - const uint16_t scl = cl->mlist->scale; + const uint16_t scl = cl.mlist.scale; uint32_t x; uint32_t y; int32_t col; col = 0x00373737; x = 0; - y = wl->y_size - (map_h * scl) - 20; + y = wl.y_size - (map_h * scl) - 20; while (x < (map_w * scl) + 20) { - while (y < wl->y_size - (map_h * scl)) + while (y < wl.y_size - (map_h * scl)) { - *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = col; + *(int*)(cl.img.ptr + (x * 4 + (y * cl.img.sizeline))) = col; if (!(y % 3)) { if (col < 0x00aaaaaa) @@ -67,7 +67,7 @@ static void y++; } col = 0x00353535; - y = wl->y_size - (map_h * scl) - 20; + y = wl.y_size - (map_h * scl) - 20; x++; } } @@ -75,19 +75,19 @@ static void static void ft_draw_hud_back_top_r(size_t map_h, size_t map_w, t_win *wl, t_cub *cl) { - const uint16_t scl = cl->mlist->scale; + const uint16_t scl = cl.mlist.scale; uint32_t x; uint32_t y; int32_t col; col = 0x00373737; - x = wl->x_size - (map_w * scl) + 20; - y = wl->y_size - (map_h * scl) - 20; - while (x < wl->x_size) + x = wl.x_size - (map_w * scl) + 20; + y = wl.y_size - (map_h * scl) - 20; + while (x < wl.x_size) { - while (y < wl->y_size - (map_h * scl)) + while (y < wl.y_size - (map_h * scl)) { - *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = col; + *(int*)(cl.img.ptr + (x * 4 + (y * cl.img.sizeline))) = col; if (!(y % 2)) { if (col < 0x00aaaaaa) @@ -96,7 +96,7 @@ static void y++; } col = 0x00353535; - y = wl->y_size - (map_h * scl) - 20; + y = wl.y_size - (map_h * scl) - 20; x++; } } @@ -104,10 +104,10 @@ static void void ft_draw_hud(t_cub *clist) { - ft_draw_hud_back(clist->wlist, clist); - ft_draw_hud_back_top_l(clist->mlist->map_h, - clist->mlist->map_w, clist->wlist, clist); - ft_draw_hud_back_top_r(clist->mlist->map_h, - clist->mlist->map_w, clist->wlist, clist); - ft_draw_map(clist->mlist->map, clist); + ft_draw_hud_back(clist.wlist, clist); + ft_draw_hud_back_top_l(clist.mlist.map_h, + clist.mlist.map_w, clist.wlist, clist); + ft_draw_hud_back_top_r(clist.mlist.map_h, + clist.mlist.map_w, clist.wlist, clist); + ft_draw_map(clist.mlist.map, clist); } diff --git a/src/ft_draw_map.c b/src/ft_draw_map.c index a334fc1..42f324b 100644 --- a/src/ft_draw_map.c +++ b/src/ft_draw_map.c @@ -16,17 +16,17 @@ static uint16_t ft_y_offset(t_cub *clist) { - return (clist->wlist->y_size - - (clist->mlist->map_h * clist->mlist->scale) - + clist->mlist->scale - 1); + return (clist.wlist.y_size + - (clist.mlist.map_h * clist.mlist.scale) + + clist.mlist.scale - 1); } static void ft_draw_player(t_player *plist, t_cub *clist) { - const uint16_t scale = clist->mlist->scale; - const float x = plist->pos_x; - const float y = plist->pos_y; + const uint16_t scale = clist.mlist.scale; + const float x = plist.pos_x; + const float y = plist.pos_y; ft_draw_circle( (scale / 2) + (x * (scale)), @@ -38,7 +38,7 @@ static void void ft_draw_map(char **map, t_cub *clist) { - const uint8_t scale = clist->mlist->scale; + const uint8_t scale = clist.mlist.scale; size_t x; size_t y; @@ -62,5 +62,5 @@ void x = 0; y++; } - ft_draw_player(clist->plist, clist); + ft_draw_player(clist.plist, clist); } diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c index a356cab..9c14612 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -18,26 +18,26 @@ void ft_draw_scene(t_cub *clist) { - clist->img.img = mlx_new_image(clist->wlist->wlx, - clist->wlist->x_size, clist->wlist->y_size); - clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp, - &clist->img.sizeline, &clist->img.endian); + clist.img.img = mlx_new_image(clist.wlist.wlx, + clist.wlist.x_size, clist.wlist.y_size); + clist.img.ptr = mlx_get_data_addr(clist.img.img, &clist.img.bpp, + &clist.img.sizeline, &clist.img.endian); ft_castray(clist); - if (clist->ishud) + if (clist.ishud) ft_draw_hud(clist); - mlx_put_image_to_window(clist->wlist->wlx, - clist->wlist->winptr, clist->img.img, 0, 0); - mlx_destroy_image(clist->wlist->wlx, clist->img.img); + mlx_put_image_to_window(clist.wlist.wlx, + clist.wlist.winptr, clist.img.img, 0, 0); + mlx_destroy_image(clist.wlist.wlx, clist.img.img); } void ft_draw_scene_bmp(t_cub *clist) { - clist->img.img = mlx_new_image(clist->wlist->wlx, - clist->wlist->x_size, clist->wlist->y_size); - clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp, - &clist->img.sizeline, &clist->img.endian); + clist.img.img = mlx_new_image(clist.wlist.wlx, + clist.wlist.x_size, clist.wlist.y_size); + clist.img.ptr = mlx_get_data_addr(clist.img.img, &clist.img.bpp, + &clist.img.sizeline, &clist.img.endian); ft_castray(clist); - mlx_destroy_image(clist->wlist->wlx, clist->img.img); + mlx_destroy_image(clist.wlist.wlx, clist.img.img); ft_save_to_bmp(); } diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 9cd7dae..4570905 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -20,17 +20,17 @@ void ft_draw_verline_sprite(t_cub *cl, int x, int y, int tex_y) { - if (cl->tlist[4].tex_x) - cl->img.ptr[x * 4 + (cl->img.sizeline * y)] = - (char)cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 * - cl->tlist[4].img_h * tex_y]; - cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] = - (char)cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 * - cl->tlist[4].img_h * tex_y + 1]; - cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] = - (char)cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 * - cl->tlist[4].img_h * tex_y + 2]; - cl->img.ptr[x * 4 + cl->wlist->x_size * y + 3] = (char)0; + if (cl.tlist[4].tex_x) + cl.img.ptr[x * 4 + (cl.img.sizeline * y)] = + (char)cl.tlist[4].ptr[cl.tlist[4].tex_x * 4 + 4 * + cl.tlist[4].img_h * tex_y]; + cl.img.ptr[x * 4 + (cl.img.sizeline * y) + 1] = + (char)cl.tlist[4].ptr[cl.tlist[4].tex_x * 4 + 4 * + cl.tlist[4].img_h * tex_y + 1]; + cl.img.ptr[x * 4 + (cl.img.sizeline * y) + 2] = + (char)cl.tlist[4].ptr[cl.tlist[4].tex_x * 4 + 4 * + cl.tlist[4].img_h * tex_y + 2]; + cl.img.ptr[x * 4 + cl.wlist.x_size * y + 3] = (char)0; } void @@ -40,12 +40,12 @@ void int d; int tex_y; - hor_it = cl->sp_list.s_start_y; - while (hor_it < cl->sp_list.s_end_y) + hor_it = cl.sp_list.s_start_y; + while (hor_it < cl.sp_list.s_end_y) { - d = hor_it * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; + d = hor_it * 256 - cl.wlist.y_size * 128 + cl.rlist.line_h * 128; d = (d <= 0) ? (-d) : (d); - tex_y = ((d * cl->tlist[4].img_h) / cl->rlist.line_h) / 256; + tex_y = ((d * cl.tlist[4].img_h) / cl.rlist.line_h) / 256; (tex_y < 0) ? (tex_y = 0) : 0; ft_draw_verline_sprite(cl, x, hor_it, tex_y); hor_it++; diff --git a/src/ft_draw_square.c b/src/ft_draw_square.c index 355969e..793bb8c 100644 --- a/src/ft_draw_square.c +++ b/src/ft_draw_square.c @@ -17,7 +17,7 @@ void ft_draw_square(int a, int b, int rgb, t_cub *clist) { - const uint16_t scale = clist->mlist->scale; + const uint16_t scale = clist.mlist.scale; int x; int y; @@ -27,7 +27,7 @@ void { while (y >= b - scale) { - *(int*)(clist->img.ptr + (x * 4 + (y * clist->img.sizeline))) = rgb; + *(int*)(clist.img.ptr + (x * 4 + (y * clist.img.sizeline))) = rgb; y--; } y = b; diff --git a/src/ft_draw_textures.c b/src/ft_draw_textures.c index 39d6278..73dda23 100644 --- a/src/ft_draw_textures.c +++ b/src/ft_draw_textures.c @@ -24,34 +24,34 @@ void ft_draw_texture(t_cub *cl, int x, int y, int tex_y) { - cl->img.ptr[x * 4 + (cl->img.sizeline * y)] = - (char)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * - cl->tlist[cl->w_side].img_h * tex_y]; - cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] = - (char)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * - cl->tlist[cl->w_side].img_h * tex_y + 1]; - cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] = - (char)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]; - cl->img.ptr[x * 4 + cl->wlist->x_size * y + 3] = (char)0; + cl.img.ptr[x * 4 + (cl.img.sizeline * y)] = + (char)cl.tlist[cl.w_side].ptr[cl.tlist[cl.w_side].tex_x * 4 + 4 * + cl.tlist[cl.w_side].img_h * tex_y]; + cl.img.ptr[x * 4 + (cl.img.sizeline * y) + 1] = + (char)cl.tlist[cl.w_side].ptr[cl.tlist[cl.w_side].tex_x * 4 + 4 * + cl.tlist[cl.w_side].img_h * tex_y + 1]; + cl.img.ptr[x * 4 + (cl.img.sizeline * y) + 2] = + (char)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]; + cl.img.ptr[x * 4 + cl.wlist.x_size * y + 3] = (char)0; } void ft_choose_tex(t_cub *clist) { - if (clist->rlist.sqy == clist->mlist->nlx - && clist->rlist.sqx == clist->mlist->nly) + if (clist.rlist.sqy == clist.mlist.nlx + && clist.rlist.sqx == clist.mlist.nly) { - clist->w_side = 5; + clist.w_side = 5; } else { - if (clist->rlist.side == 0 && clist->rlist.x_ray_dir < 0) - clist->w_side = 1; - else if (clist->rlist.side == 0 && clist->rlist.x_ray_dir > 0) - clist->w_side = 0; - else if (clist->rlist.side == 1 && clist->rlist.y_ray_dir > 0) - clist->w_side = 3; + if (clist.rlist.side == 0 && clist.rlist.x_ray_dir < 0) + clist.w_side = 1; + else if (clist.rlist.side == 0 && clist.rlist.x_ray_dir > 0) + clist.w_side = 0; + else if (clist.rlist.side == 1 && clist.rlist.y_ray_dir > 0) + clist.w_side = 3; else - clist->w_side = 2; + clist.w_side = 2; } } diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c index b0f9880..7b74d4a 100644 --- a/src/ft_draw_verline.c +++ b/src/ft_draw_verline.c @@ -15,10 +15,10 @@ static void ft_draw_floor(t_cub *cl, int32_t y, int32_t x) { - while ((uint32_t)y < cl->wlist->y_size) + while ((uint32_t)y < cl.wlist.y_size) { - *(int*)(cl->img.ptr + - (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(cl->f_rgb); + *(int*)(cl.img.ptr + + (x * 4 + (y * cl.img.sizeline))) = ft_rgb_to_hex(cl.f_rgb); y++; } } @@ -31,8 +31,8 @@ static void i = 0; while (i <= y) { - *(int*)(cl->img.ptr + - (x * 4 + (i * cl->img.sizeline))) = ft_rgb_to_hex(cl->c_rgb); + *(int*)(cl.img.ptr + + (x * 4 + (i * cl.img.sizeline))) = ft_rgb_to_hex(cl.c_rgb); i++; } } @@ -49,21 +49,21 @@ static void ** i = 0; ** while (i < y) ** { -** d = i * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; +** d = i * 256 - cl.wlist.y_size * 128 + cl.rlist.line_h * 128; ** d = (d <= 0) ? (-d) : (d); ** ft_printf("%d\n", d); -** tex_y = ((d * cl->tlist[1].img_h) / cl->rlist.line_h) / 256; +** tex_y = ((d * cl.tlist[1].img_h) / cl.rlist.line_h) / 256; ** (tex_y <= 0) ? (tex_y = 1) : 0; -** cl->img.ptr[x * 4 + (cl->img.sizeline * i)] = -** (int8_t)cl->tlist[1].ptr[cl->tlist[1].tex_x * 4 + 4 * -** cl->tlist[1].img_h * tex_y]; -** cl->img.ptr[x * 4 + (cl->img.sizeline * i) + 1] = -** (int8_t)cl->tlist[1].ptr[cl->tlist[1].tex_x * 4 + 4 * -** cl->tlist[1].img_h * tex_y + 1]; -** cl->img.ptr[x * 4 + (cl->img.sizeline * i) + 2] = -** (int8_t)cl->tlist[1].ptr[cl->tlist[1].tex_x * 4 + 4 * -** cl->tlist[1].img_h * tex_y + 2]; -** cl->img.ptr[x * 4 + cl->wlist->x_size * i + 3] = (char)0; +** cl.img.ptr[x * 4 + (cl.img.sizeline * i)] = +** (int8_t)cl.tlist[1].ptr[cl.tlist[1].tex_x * 4 + 4 * +** cl.tlist[1].img_h * tex_y]; +** cl.img.ptr[x * 4 + (cl.img.sizeline * i) + 1] = +** (int8_t)cl.tlist[1].ptr[cl.tlist[1].tex_x * 4 + 4 * +** cl.tlist[1].img_h * tex_y + 1]; +** cl.img.ptr[x * 4 + (cl.img.sizeline * i) + 2] = +** (int8_t)cl.tlist[1].ptr[cl.tlist[1].tex_x * 4 + 4 * +** cl.tlist[1].img_h * tex_y + 2]; +** cl.img.ptr[x * 4 + cl.wlist.x_size * i + 3] = (char)0; ** i++; ** } ** } @@ -78,12 +78,12 @@ int8_t (y < 0) ? (y = 0) : 0; (y2 < 0) ? (y2 = 0) : 0; ft_draw_ceil(cl, y, x); - (cl->rlist.line_h <= 0) ? (cl->rlist.line_h = 1) : 0; + (cl.rlist.line_h <= 0) ? (cl.rlist.line_h = 1) : 0; while (y < y2) { - d = y * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; + d = y * 256 - cl.wlist.y_size * 128 + cl.rlist.line_h * 128; d = (d <= 0) ? (-d) : (d); - tex_y = ((d * cl->tlist[cl->w_side].img_h) / cl->rlist.line_h) / 256; + tex_y = ((d * cl.tlist[cl.w_side].img_h) / cl.rlist.line_h) / 256; (tex_y <= 0) ? (tex_y = 1) : 0; ft_draw_texture(cl, x, y, tex_y); y++; diff --git a/src/ft_exit.c b/src/ft_exit.c index c022627..6622eb1 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -21,52 +21,52 @@ static void ft_free_lists(t_cub *clist) { - 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->sprite_path); - ft_memdel((void**)&clist->mlist->nl_tex_path); - ft_memdel((void**)&clist->mlist->nlevel_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_memdel((void**)&clist->mlist); - ft_memdel((void**)&clist->plist); - if (!clist->wlist->inited) - ft_memdel((void**)&clist->wlist->winptr); - ft_memdel((void**)&clist->wlist); + 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.sprite_path); + ft_memdel((void**)&clist.mlist.nl_tex_path); + ft_memdel((void**)&clist.mlist.nlevel_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_memdel((void**)&clist.mlist); + ft_memdel((void**)&clist.plist); + if (!clist.wlist.inited) + ft_memdel((void**)&clist.wlist.winptr); + ft_memdel((void**)&clist.wlist); ft_memdel((void**)&clist); } int ft_exit(uint8_t exit_code, t_cub *clist) { - if (clist->walltexgood) + if (clist.walltexgood) { - if (clist->tlist[0].img) - mlx_destroy_image(clist->wlist->wlx, clist->tlist[0].img); - if (clist->tlist[1].img) - mlx_destroy_image(clist->wlist->wlx, clist->tlist[1].img); - if (clist->tlist[2].img) - mlx_destroy_image(clist->wlist->wlx, clist->tlist[2].img); - if (clist->tlist[3].img) - mlx_destroy_image(clist->wlist->wlx, clist->tlist[3].img); - if (clist->tlist[4].img) - mlx_destroy_image(clist->wlist->wlx, clist->tlist[4].img); - if (clist->mlist->isnlvl && clist->tlist[5].img) - mlx_destroy_image(clist->wlist->wlx, clist->tlist[5].img); + if (clist.tlist[0].img) + mlx_destroy_image(clist.wlist.wlx, clist.tlist[0].img); + if (clist.tlist[1].img) + mlx_destroy_image(clist.wlist.wlx, clist.tlist[1].img); + if (clist.tlist[2].img) + mlx_destroy_image(clist.wlist.wlx, clist.tlist[2].img); + if (clist.tlist[3].img) + mlx_destroy_image(clist.wlist.wlx, clist.tlist[3].img); + if (clist.tlist[4].img) + mlx_destroy_image(clist.wlist.wlx, clist.tlist[4].img); + if (clist.mlist.isnlvl && clist.tlist[5].img) + mlx_destroy_image(clist.wlist.wlx, clist.tlist[5].img); } - if (clist->wlist->inited) + if (clist.wlist.inited) { - mlx_destroy_window(clist->wlist->wlx, clist->wlist->winptr); - clist->wlist->winptr = NULL; + mlx_destroy_window(clist.wlist.wlx, clist.wlist.winptr); + clist.wlist.winptr = NULL; } - if (clist->isoldmus && clist->wlist->inited) + if (clist.isoldmus && clist.wlist.inited) { - pthread_cancel(clist->tid); - pthread_join(clist->tid, NULL); + pthread_cancel(clist.tid); + pthread_join(clist.tid, NULL); } ft_free_lists(clist); ft_printf("Exiting program\n"); diff --git a/src/ft_extra_keys.c b/src/ft_extra_keys.c index 507f808..f02d298 100644 --- a/src/ft_extra_keys.c +++ b/src/ft_extra_keys.c @@ -22,13 +22,13 @@ int float sav_plane_x; const float rot_speed = FT_ROT_SPEED; - pl = clist->plist; - sav_dir_x = pl->dir_x; - pl->dir_x = pl->dir_x * cos(rot_speed) - pl->dir_y * sin(rot_speed); - pl->dir_y = sav_dir_x * sin(rot_speed) + pl->dir_y * cos(rot_speed); - sav_plane_x = pl->plane_x; - pl->plane_x = pl->plane_x * cos(rot_speed) - pl->plane_y * sin(rot_speed); - pl->plane_y = sav_plane_x * sin(rot_speed) + pl->plane_y * cos(rot_speed); + pl = clist.plist; + sav_dir_x = pl.dir_x; + pl.dir_x = pl.dir_x * cos(rot_speed) - pl.dir_y * sin(rot_speed); + pl.dir_y = sav_dir_x * sin(rot_speed) + pl.dir_y * cos(rot_speed); + sav_plane_x = pl.plane_x; + pl.plane_x = pl.plane_x * cos(rot_speed) - pl.plane_y * sin(rot_speed); + pl.plane_y = sav_plane_x * sin(rot_speed) + pl.plane_y * cos(rot_speed); return (0); } @@ -40,27 +40,27 @@ int float sav_plane_x; const float rot_speed = FT_ROT_SPEED; - pl = clist->plist; - sav_dir_x = pl->dir_x; - pl->dir_x = pl->dir_x * cos(-rot_speed) - pl->dir_y * sin(-rot_speed); - pl->dir_y = sav_dir_x * sin(-rot_speed) + pl->dir_y * cos(-rot_speed); - sav_plane_x = pl->plane_x; - pl->plane_x = pl->plane_x * cos(-rot_speed) - pl->plane_y * sin(-rot_speed); - pl->plane_y = sav_plane_x * sin(-rot_speed) + pl->plane_y * cos(-rot_speed); + pl = clist.plist; + sav_dir_x = pl.dir_x; + pl.dir_x = pl.dir_x * cos(-rot_speed) - pl.dir_y * sin(-rot_speed); + pl.dir_y = sav_dir_x * sin(-rot_speed) + pl.dir_y * cos(-rot_speed); + sav_plane_x = pl.plane_x; + pl.plane_x = pl.plane_x * cos(-rot_speed) - pl.plane_y * sin(-rot_speed); + pl.plane_y = sav_plane_x * sin(-rot_speed) + pl.plane_y * cos(-rot_speed); return (0); } int ft_f1_key(t_cub *clist) { - if (clist->ishud == 0) + if (clist.ishud == 0) { - clist->ishud = 1; + clist.ishud = 1; ft_draw_scene(clist); } - else if (clist->ishud == 1) + else if (clist.ishud == 1) { - clist->ishud = 0; + clist.ishud = 0; ft_draw_scene(clist); } return (0); diff --git a/src/ft_get_colors.c b/src/ft_get_colors.c index 69eb8f8..417608b 100644 --- a/src/ft_get_colors.c +++ b/src/ft_get_colors.c @@ -30,7 +30,7 @@ static int8_t if (i != ft_strlen(num[j])) { ft_free_words(num); - ft_sprintf(clist->errmsg, FT_ERR_COLOR_ALPHA); + ft_sprintf(clist.errmsg, FT_ERR_COLOR_ALPHA); return (-1); } i = 0; @@ -45,7 +45,7 @@ static int8_t if (ft_atoi(num[0]) > 255 || ft_atoi(num[1]) > 255 || ft_atoi(num[2]) > 255) { - ft_sprintf(clist->errmsg, FT_ERR_COLOR_MAX); + ft_sprintf(clist.errmsg, FT_ERR_COLOR_MAX); ft_free_words(num); return (-1); } @@ -57,7 +57,7 @@ static int8_t { if (!num[0] || !num[1] || !num[2] || num[3]) { - ft_sprintf(clist->errmsg, FT_ERR_COLOR_ARGS); + ft_sprintf(clist.errmsg, FT_ERR_COLOR_ARGS); ft_free_words(num); return (-1); } @@ -71,12 +71,12 @@ int8_t if (!(*words) || !words[1] || words[2]) { - ft_sprintf(clist->errmsg, FT_ERR_ARGS); + ft_sprintf(clist.errmsg, FT_ERR_ARGS); return (-1); } if (!(num = ft_split(words[1], ','))) { - ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE); + ft_sprintf(clist.errmsg, FT_ERR_ALLOCATE); return (-1); } if (ft_check_nums_amount(num, clist) < 0) @@ -85,9 +85,9 @@ int8_t return (-1); if (ft_check_max_int(num, clist) < 0) return (-1); - clist->f_rgb.r = ft_atoi(num[0]); - clist->f_rgb.g = ft_atoi(num[1]); - clist->f_rgb.b = ft_atoi(num[2]); + clist.f_rgb.r = ft_atoi(num[0]); + clist.f_rgb.g = ft_atoi(num[1]); + clist.f_rgb.b = ft_atoi(num[2]); ft_free_words(num); return (0); } @@ -99,12 +99,12 @@ int8_t if (!(*words) || !words[1] || words[2]) { - ft_sprintf(clist->errmsg, FT_ERR_ARGS); + ft_sprintf(clist.errmsg, FT_ERR_ARGS); return (-1); } if (!(num = ft_split(words[1], ','))) { - ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE); + ft_sprintf(clist.errmsg, FT_ERR_ALLOCATE); return (-1); } if (ft_check_nums_amount(num, clist) < 0) @@ -113,9 +113,9 @@ int8_t return (-1); if (ft_check_max_int(num, clist) < 0) return (-1); - clist->c_rgb.r = ft_atoi(num[0]); - clist->c_rgb.g = ft_atoi(num[1]); - clist->c_rgb.b = ft_atoi(num[2]); + clist.c_rgb.r = ft_atoi(num[0]); + clist.c_rgb.g = ft_atoi(num[1]); + clist.c_rgb.b = ft_atoi(num[2]); ft_free_words(num); return (0); } diff --git a/src/ft_get_map.c b/src/ft_get_map.c index f609c50..6a73e54 100644 --- a/src/ft_get_map.c +++ b/src/ft_get_map.c @@ -50,35 +50,35 @@ static void static int8_t ft_cat_mapl(char *line, size_t i, t_cub *clist) { - if (!(clist->mlist->mapl = (char *)ft_nrealloc(clist->mlist->mapl, - ((clist->mlist->map_w + 1) * i) * sizeof(char), - ((clist->mlist->map_w + 1) * (i + 1)) * sizeof(char)))) + if (!(clist.mlist.mapl = (char *)ft_nrealloc(clist.mlist.mapl, + ((clist.mlist.map_w + 1) * i) * sizeof(char), + ((clist.mlist.map_w + 1) * (i + 1)) * sizeof(char)))) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE); + ft_sprintf(clist.errmsg, "%s", FT_ERR_ALLOCATE); return (-1); } - ft_linecpy(line, clist->mlist->mapl, (clist->mlist->map_w + 1) * i); + ft_linecpy(line, clist.mlist.mapl, (clist.mlist.map_w + 1) * i); return (0); } int ft_get_map_first_line(char *line, t_cub *clist) { - clist->mlist->map_start = clist->mlist->line_chk; + clist.mlist.map_start = clist.mlist.line_chk; if (!line[0]) { ft_memdel((void**)&line); - ft_sprintf(clist->errmsg, "%s", FT_ERR_READ); + ft_sprintf(clist.errmsg, "%s", FT_ERR_READ); return (-1); } - clist->mlist->map_w = ft_get_line_len(line); + clist.mlist.map_w = ft_get_line_len(line); if (ft_check_map_line(line, 1, clist) < 0) { ft_memdel((void**)&line); - ft_sprintf(clist->errmsg, "%s", FT_ERR_READ); + ft_sprintf(clist.errmsg, "%s", FT_ERR_READ); return (-1); } - ft_memdel((void**)&clist->mlist->mapl); + ft_memdel((void**)&clist.mlist.mapl); if (ft_cat_mapl(line, 0, clist) < 0) { ft_memdel((void**)&line); @@ -99,7 +99,7 @@ int ret = 1; while ((ret = get_next_line(fd, &line)) > 0) { - clist->mlist->line_chk += 1; + clist.mlist.line_chk += 1; if (!line[0] || ft_check_map_line(line, 0, clist) < 0 || ft_cat_mapl(line, i, clist) < 0) { @@ -110,10 +110,10 @@ int i++; } ft_memdel((void**)&line); - clist->mlist->mapl[((clist->mlist->map_w + 1) * i) - 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); - ft_memdel((void**)&clist->mlist->mapl); + clist.mlist.mapl[((clist.mlist.map_w + 1) * i) - 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); + ft_memdel((void**)&clist.mlist.mapl); return (0); } diff --git a/src/ft_get_music.c b/src/ft_get_music.c index df65a7f..3d40ddf 100644 --- a/src/ft_get_music.c +++ b/src/ft_get_music.c @@ -20,18 +20,18 @@ static void { uint8_t len; - len = ft_strlen(mlist->music_path); + len = ft_strlen(mlist.music_path); if (FT_OS == 2) len += 22; else len += 18; - ft_memdel((void**)&mlist->music_cmd); - if (!(mlist->music_cmd = (char *)malloc((len + 1) * sizeof(char)))) + ft_memdel((void**)&mlist.music_cmd); + if (!(mlist.music_cmd = (char *)malloc((len + 1) * sizeof(char)))) return ; if (FT_OS == 2) { - ft_sprintf(mlist->music_cmd, "aplay -f cd -t wav -q %s", - mlist->music_path); + ft_sprintf(mlist.music_cmd, "aplay -f cd -t wav -q %s", + mlist.music_path); } else {} } @@ -41,26 +41,26 @@ int8_t { if (!(*words) || !(*(words + 1)) || (*(words + 2))) { - ft_sprintf(clist->errmsg, FT_ERR_ARGS); + ft_sprintf(clist.errmsg, FT_ERR_ARGS); return (-1); } if (ft_check_ext(*(words + 1), ".wav") < 0) { - ft_sprintf(clist->errmsg, FT_ERR_NOT_A_WAV); + ft_sprintf(clist.errmsg, FT_ERR_NOT_A_WAV); return (-1); } - ft_memdel((void**)&clist->mlist->music_path); - if (!(clist->mlist->music_path = ft_strdup(*(words + 1)))) + ft_memdel((void**)&clist.mlist.music_path); + if (!(clist.mlist.music_path = ft_strdup(*(words + 1)))) { - ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE); + ft_sprintf(clist.errmsg, FT_ERR_ALLOCATE); return (-1); } - if (ft_check_not_found(clist->mlist->music_path) < 0) + if (ft_check_not_found(clist.mlist.music_path) < 0) { - ft_sprintf(clist->errmsg, FT_ERR_RD_MUSIC); + ft_sprintf(clist.errmsg, FT_ERR_RD_MUSIC); return (-1); } - clist->mlist->ismusic = 1; - ft_set_music_cmd(clist->mlist); + clist.mlist.ismusic = 1; + ft_set_music_cmd(clist.mlist); return (0); } diff --git a/src/ft_get_nlvl_pos.c b/src/ft_get_nlvl_pos.c index db726e1..d0bf3e7 100644 --- a/src/ft_get_nlvl_pos.c +++ b/src/ft_get_nlvl_pos.c @@ -20,14 +20,14 @@ void x = 1; y = 1; - while (ml->map[y]) + while (ml.map[y]) { - while (ml->map[y][x]) + while (ml.map[y][x]) { - if (ml->map[y][x] == 'L') + if (ml.map[y][x] == 'L') { - ml->nlx = x; - ml->nly = y; + ml.nlx = x; + ml.nly = y; return ; } x++; diff --git a/src/ft_get_path_nl.c b/src/ft_get_path_nl.c index b14595f..c702129 100644 --- a/src/ft_get_path_nl.c +++ b/src/ft_get_path_nl.c @@ -19,23 +19,23 @@ int8_t { if (!(*words) || !(*(words + 1)) || (*(words + 2))) { - ft_sprintf(clist->errmsg, FT_ERR_ARGS); + ft_sprintf(clist.errmsg, FT_ERR_ARGS); return (-1); } if (ft_check_ext(*(words + 1), ".cub") < 0) { - ft_sprintf(clist->errmsg, FT_ERR_NOT_A_CUB); + ft_sprintf(clist.errmsg, FT_ERR_NOT_A_CUB); return (-1); } - ft_memdel((void**)&clist->mlist->nlevel_path); - if (!(clist->mlist->nlevel_path = ft_strdup(*(words + 1)))) + ft_memdel((void**)&clist.mlist.nlevel_path); + if (!(clist.mlist.nlevel_path = ft_strdup(*(words + 1)))) { - ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE); + ft_sprintf(clist.errmsg, FT_ERR_ALLOCATE); return (-1); } - if (ft_check_not_found(clist->mlist->nlevel_path) < 0) + if (ft_check_not_found(clist.mlist.nlevel_path) < 0) { - ft_sprintf(clist->errmsg, FT_ERR_RD_NL_MAP); + ft_sprintf(clist.errmsg, FT_ERR_RD_NL_MAP); return (-1); } return (0); diff --git a/src/ft_get_player_spawn.c b/src/ft_get_player_spawn.c index 617ec22..a4e94ea 100644 --- a/src/ft_get_player_spawn.c +++ b/src/ft_get_player_spawn.c @@ -21,21 +21,21 @@ static void float sav_dir_x; float sav_plane_x; - sav_dir_x = pl->dir_x; - pl->dir_x = -pl->dir_y; - pl->dir_y = sav_dir_x; - sav_plane_x = pl->plane_x; - pl->plane_x = -pl->plane_y; - pl->plane_y = sav_plane_x; + sav_dir_x = pl.dir_x; + pl.dir_x = -pl.dir_y; + pl.dir_y = sav_dir_x; + sav_plane_x = pl.plane_x; + pl.plane_x = -pl.plane_y; + pl.plane_y = sav_plane_x; } static void ft_get_s_dir(t_player *pl) { - pl->dir_x = -pl->dir_x; - pl->dir_y = -pl->dir_y; - pl->plane_x = -pl->plane_x; - pl->plane_y = -pl->plane_y; + pl.dir_x = -pl.dir_x; + pl.dir_y = -pl.dir_y; + pl.plane_x = -pl.plane_x; + pl.plane_y = -pl.plane_y; } static void @@ -44,12 +44,12 @@ static void float sav_dir_x; float sav_plane_x; - sav_dir_x = pl->dir_x; - pl->dir_x = pl->dir_y; - pl->dir_y = -sav_dir_x; - sav_plane_x = pl->plane_x; - pl->plane_x = pl->plane_y; - pl->plane_y = -sav_plane_x; + sav_dir_x = pl.dir_x; + pl.dir_x = pl.dir_y; + pl.dir_y = -sav_dir_x; + sav_plane_x = pl.plane_x; + pl.plane_x = pl.plane_y; + pl.plane_y = -sav_plane_x; } static void @@ -71,17 +71,17 @@ void x = 1; y = 1; - while (clist->mlist->map[y]) + while (clist.mlist.map[y]) { - while (clist->mlist->map[y][x]) + while (clist.mlist.map[y][x]) { - if (ft_ischarset("NSEW", clist->mlist->map[y][x])) + if (ft_ischarset("NSEW", clist.mlist.map[y][x])) { - plist->pos_x = x + 0.5; - plist->pos_y = y + 0.5; - plist->start_x = plist->pos_x; - plist->start_y = plist->pos_y; - ft_get_start_side(clist->mlist->map[y][x], clist->plist); + plist.pos_x = x + 0.5; + plist.pos_y = y + 0.5; + plist.start_x = plist.pos_x; + plist.start_y = plist.pos_y; + ft_get_start_side(clist.mlist.map[y][x], clist.plist); return ; } x++; diff --git a/src/ft_get_res.c b/src/ft_get_res.c index aa1bec4..8b86cea 100644 --- a/src/ft_get_res.c +++ b/src/ft_get_res.c @@ -24,7 +24,7 @@ static int8_t i++; if (i != ft_strlen(word)) { - ft_sprintf(clist->errmsg, FT_ERR_RES_ALPHA); + ft_sprintf(clist.errmsg, FT_ERR_RES_ALPHA); return (-1); } return (0); @@ -33,10 +33,10 @@ static int8_t static void ft_securize_scr(t_win *wl) { - while (wl->x_size % 10) - wl->x_size -= 1; - while (wl->y_size % 10) - wl->y_size -= 1; + while (wl.x_size % 10) + wl.x_size -= 1; + while (wl.y_size % 10) + wl.y_size -= 1; } static int8_t @@ -45,7 +45,7 @@ static int8_t if (!(*words + 0) || !(*(words + 1)) || !(*(words + 2)) || (*(words + 3))) { - ft_sprintf(clist->errmsg, FT_ERR_ARGS); + ft_sprintf(clist.errmsg, FT_ERR_ARGS); return (-1); } return (0); @@ -56,20 +56,20 @@ int8_t { t_win *wlist; - wlist = clist->wlist; - if (clist->currlvl > 0) + wlist = clist.wlist; + if (clist.currlvl > 0) return (0); if (ft_check_res_args(words, clist) < 0) return (-1); if ((ft_checkdigit(words[1], clist) < 0) || (ft_checkdigit(words[2], clist) < 0)) return (-1); - wlist->x_size = ft_atoi(words[1]); - wlist->y_size = ft_atoi(words[2]); - if (wlist->x_size <= 10 - || wlist->y_size <= 10) + wlist.x_size = ft_atoi(words[1]); + wlist.y_size = ft_atoi(words[2]); + if (wlist.x_size <= 10 + || wlist.y_size <= 10) { - ft_sprintf(clist->errmsg, FT_ERR_RES_SMALL); + ft_sprintf(clist.errmsg, FT_ERR_RES_SMALL); return (-1); } if (ft_get_screen_size(wlist) < 0) diff --git a/src/ft_get_screen_size.c b/src/ft_get_screen_size.c index 2b437c3..5bfd04e 100644 --- a/src/ft_get_screen_size.c +++ b/src/ft_get_screen_size.c @@ -22,11 +22,11 @@ int8_t return (-1); if (!(*words + 0) || !(*(words + 1)) || (*(words + 2))) return (-1); - wlist->x_max_size = ft_atoi(words[0]); - wlist->y_max_size = ft_atoi(words[1]); - if (wlist->x_size > wlist->x_max_size) - wlist->x_size = wlist->x_max_size; - if (wlist->y_size > wlist->y_max_size) - wlist->y_size = wlist->y_max_size; + wlist.x_max_size = ft_atoi(words[0]); + wlist.y_max_size = ft_atoi(words[1]); + if (wlist.x_size > wlist.x_max_size) + wlist.x_size = wlist.x_max_size; + if (wlist.y_size > wlist.y_max_size) + wlist.y_size = wlist.y_max_size; return (ft_free_words(words)); } diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index c9546fb..27a55d6 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -22,14 +22,14 @@ void x = 1; y = 1; - while (clist->mlist->map[y]) + while (clist.mlist.map[y]) { - while (clist->mlist->map[y][x]) + while (clist.mlist.map[y][x]) { - if (ft_ischarset("2", clist->mlist->map[y][x])) + if (ft_ischarset("2", clist.mlist.map[y][x])) { - clist->sp_list.s_pos_x = x + 0.5; - clist->sp_list.s_pos_y = y + 0.5; + clist.sp_list.s_pos_x = x + 0.5; + clist.sp_list.s_pos_y = y + 0.5; return ; } x++; @@ -44,23 +44,23 @@ int8_t { if (!(*words) || !words[1] || words[2]) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_ARGS); + 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); + ft_sprintf(clist.errmsg, "%s", FT_ERR_NOT_A_XPM); return (-1); } - ft_memdel((void**)&clist->mlist->sprite_path); - if (!(clist->mlist->sprite_path = ft_strdup(*(words + 1)))) + ft_memdel((void**)&clist.mlist.sprite_path); + if (!(clist.mlist.sprite_path = ft_strdup(*(words + 1)))) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE); + ft_sprintf(clist.errmsg, "%s", FT_ERR_ALLOCATE); return (-1); } - if (ft_check_not_found(clist->mlist->sprite_path) < 0) + if (ft_check_not_found(clist.mlist.sprite_path) < 0) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_RD_SP); + ft_sprintf(clist.errmsg, "%s", FT_ERR_RD_SP); return (-1); } return (0); diff --git a/src/ft_get_tex.c b/src/ft_get_tex.c index 2611fef..655e9ad 100644 --- a/src/ft_get_tex.c +++ b/src/ft_get_tex.c @@ -19,23 +19,23 @@ int8_t { if (!(*words) || !(*(words + 1)) || (*(words + 2))) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_ARGS); + 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); + ft_sprintf(clist.errmsg, "%s", FT_ERR_NOT_A_XPM); return (-1); } - ft_memdel((void**)&clist->mlist->no_tex_path); - if (!(clist->mlist->no_tex_path = ft_strdup(*(words + 1)))) + 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); + ft_sprintf(clist.errmsg, "%s", FT_ERR_ALLOCATE); return (-1); } - if (ft_check_not_found(clist->mlist->no_tex_path) < 0) + if (ft_check_not_found(clist.mlist.no_tex_path) < 0) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_RD_NO); + ft_sprintf(clist.errmsg, "%s", FT_ERR_RD_NO); return (-1); } return (0); @@ -46,23 +46,23 @@ int8_t { if (!(*words) || !(*(words + 1)) || (*(words + 2))) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_ARGS); + 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); + ft_sprintf(clist.errmsg, "%s", FT_ERR_NOT_A_XPM); return (-1); } - ft_memdel((void**)&clist->mlist->so_tex_path); - if (!(clist->mlist->so_tex_path = ft_strdup(*(words + 1)))) + 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); + ft_sprintf(clist.errmsg, "%s", FT_ERR_ALLOCATE); return (-1); } - if (ft_check_not_found(clist->mlist->so_tex_path) < 0) + if (ft_check_not_found(clist.mlist.so_tex_path) < 0) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_RD_SO); + ft_sprintf(clist.errmsg, "%s", FT_ERR_RD_SO); return (-1); } return (0); @@ -73,23 +73,23 @@ int8_t { if (!(*words) || !(*(words + 1)) || (*(words + 2))) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_ARGS); + 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); + ft_sprintf(clist.errmsg, "%s", FT_ERR_NOT_A_XPM); return (-1); } - ft_memdel((void**)&clist->mlist->ea_tex_path); - if (!(clist->mlist->ea_tex_path = ft_strdup(*(words + 1)))) + 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); + ft_sprintf(clist.errmsg, "%s", FT_ERR_ALLOCATE); return (-1); } - if (ft_check_not_found(clist->mlist->ea_tex_path) < 0) + if (ft_check_not_found(clist.mlist.ea_tex_path) < 0) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_RD_EA); + ft_sprintf(clist.errmsg, "%s", FT_ERR_RD_EA); return (-1); } return (0); @@ -100,23 +100,23 @@ int8_t { if (!(*words) || !(*(words + 1)) || (*(words + 2))) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_ARGS); + 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); + ft_sprintf(clist.errmsg, "%s", FT_ERR_NOT_A_XPM); return (-1); } - ft_memdel((void**)&clist->mlist->we_tex_path); - if (!(clist->mlist->we_tex_path = ft_strdup(*(words + 1)))) + 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); + ft_sprintf(clist.errmsg, "%s", FT_ERR_ALLOCATE); return (-1); } - if (ft_check_not_found(clist->mlist->we_tex_path) < 0) + if (ft_check_not_found(clist.mlist.we_tex_path) < 0) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_RD_WE); + ft_sprintf(clist.errmsg, "%s", FT_ERR_RD_WE); return (-1); } return (0); diff --git a/src/ft_get_tex_nl.c b/src/ft_get_tex_nl.c index 00155de..10dba91 100644 --- a/src/ft_get_tex_nl.c +++ b/src/ft_get_tex_nl.c @@ -19,23 +19,23 @@ int8_t { if (!(*words) || !(*(words + 1)) || (*(words + 2))) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_ARGS); + 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); + ft_sprintf(clist.errmsg, "%s", FT_ERR_NOT_A_XPM); return (-1); } - ft_memdel((void**)&clist->mlist->nl_tex_path); - if (!(clist->mlist->nl_tex_path = ft_strdup(*(words + 1)))) + 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); + ft_sprintf(clist.errmsg, "%s", FT_ERR_ALLOCATE); return (-1); } - if (ft_check_not_found(clist->mlist->nl_tex_path) < 0) + if (ft_check_not_found(clist.mlist.nl_tex_path) < 0) { - ft_sprintf(clist->errmsg, FT_ERR_RD_NL_TEX); + ft_sprintf(clist.errmsg, FT_ERR_RD_NL_TEX); return (-1); } return (0); diff --git a/src/ft_hooks_and_loops.c b/src/ft_hooks_and_loops.c index b8bdd36..7a31d8a 100644 --- a/src/ft_hooks_and_loops.c +++ b/src/ft_hooks_and_loops.c @@ -17,9 +17,9 @@ void 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); - mlx_loop_hook(wl->wlx, ft_key_loop, cl); - mlx_hook(wl->winptr, 17, 0L, ft_click_close, cl); - mlx_loop(wl->wlx); + mlx_hook(wl.winptr, 2, (1L << 0), ft_key_event, cl); + mlx_hook(wl.winptr, 3, (1L << 1), ft_key_release, cl); + mlx_loop_hook(wl.wlx, ft_key_loop, cl); + mlx_hook(wl.winptr, 17, 0L, ft_click_close, cl); + mlx_loop(wl.wlx); } diff --git a/src/ft_init_funptr.c b/src/ft_init_funptr.c index 1988cb0..d9ebf1f 100644 --- a/src/ft_init_funptr.c +++ b/src/ft_init_funptr.c @@ -15,21 +15,21 @@ void ft_init_funptr(t_cub *clist) { - clist->key_ptr[0] = ft_w_key; - clist->key_ptr[1] = ft_a_key; - clist->key_ptr[2] = ft_s_key; - clist->key_ptr[3] = ft_d_key; - clist->key_ptr[4] = ft_left_key; - clist->key_ptr[5] = ft_right_key; - clist->get_ptr[0] = ft_get_res; - clist->get_ptr[1] = ft_get_tex_no; - clist->get_ptr[2] = ft_get_tex_so; - clist->get_ptr[3] = ft_get_tex_ea; - clist->get_ptr[4] = ft_get_tex_we; - clist->get_ptr[5] = ft_get_sprite; - clist->get_ptr[6] = ft_get_f_color; - clist->get_ptr[7] = ft_get_c_color; - clist->get_ptr[8] = ft_get_path_nl; - clist->get_ptr[9] = ft_get_tex_nl; - clist->get_ptr[10] = ft_get_music; + clist.key_ptr[0] = ft_w_key; + clist.key_ptr[1] = ft_a_key; + clist.key_ptr[2] = ft_s_key; + clist.key_ptr[3] = ft_d_key; + clist.key_ptr[4] = ft_left_key; + clist.key_ptr[5] = ft_right_key; + clist.get_ptr[0] = ft_get_res; + clist.get_ptr[1] = ft_get_tex_no; + clist.get_ptr[2] = ft_get_tex_so; + clist.get_ptr[3] = ft_get_tex_ea; + clist.get_ptr[4] = ft_get_tex_we; + clist.get_ptr[5] = ft_get_sprite; + clist.get_ptr[6] = ft_get_f_color; + clist.get_ptr[7] = ft_get_c_color; + clist.get_ptr[8] = ft_get_path_nl; + clist.get_ptr[9] = ft_get_tex_nl; + clist.get_ptr[10] = ft_get_music; } diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index eec8d5d..2b2593c 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -36,15 +36,15 @@ static t_player if (!(plist = (t_player*)malloc(sizeof(t_player)))) return (NULL); - plist->pos_x = 0; - plist->pos_y = 0; - plist->start_x = 0; - plist->start_y = 0; - plist->cam_x = 0; - plist->dir_x = -1; - plist->dir_y = 0; - plist->plane_x = 0; - plist->plane_y = 0.75; + plist.pos_x = 0; + plist.pos_y = 0; + plist.start_x = 0; + plist.start_y = 0; + plist.cam_x = 0; + plist.dir_x = -1; + plist.dir_y = 0; + plist.plane_x = 0; + plist.plane_y = 0.75; return (plist); } @@ -55,58 +55,52 @@ static t_win if (!(wlist = (t_win*)malloc(sizeof(t_win)))) return (NULL); - if (!(wlist->winptr = malloc(1))) + if (!(wlist.winptr = malloc(1))) return (NULL); - wlist->inited = 0; - wlist->x_size = 0; - wlist->y_size = 0; - wlist->x_max_size = 0; - wlist->y_max_size = 0; + wlist.inited = 0; + wlist.x_size = 0; + wlist.y_size = 0; + wlist.x_max_size = 0; + wlist.y_max_size = 0; return (wlist); } static t_cub - *ft_init_cub(void) + ft_init_cub(void) { - t_cub *clist; + t_cub clist; uint8_t i; - if (!(clist = (t_cub*)malloc(sizeof(t_cub)))) + if (!(clist.plist = ft_init_player()) || + !(clist.mlist = ft_init_map())) return (NULL); - if (!(clist->plist = ft_init_player()) || - !(clist->mlist = ft_init_map())) - return (NULL); - ft_bzero(clist->errmsg, 40); + ft_bzero(clist.errmsg, 40); i = -1; while (++i < 5) - clist->key_input[i] = -1; - clist->ishud = 0; - clist->isoldmus = 0; - clist->f_rgb = ft_init_rgb(); - clist->c_rgb = ft_init_rgb(); - clist->rlist = ft_init_s_ray(); - clist->currlvl = 0; - clist->walltexgood = 0; + clist.key_input[i] = -1; + clist.ishud = 0; + clist.isoldmus = 0; + clist.f_rgb = ft_init_rgb(); + clist.c_rgb = ft_init_rgb(); + clist.rlist = ft_init_s_ray(); + clist.currlvl = 0; + clist.walltexgood = 0; ft_init_funptr(clist); return (clist); } -int8_t - ft_init_cub3d(t_cub **clist) +t_cub + ft_init_cub3d(void) { - t_cub *cl; + t_cub cl; if (!(cl = ft_init_cub())) + return (NULL); + if (!(cl.wlist = ft_init_win())) { + ft_memdel((void**)&cl.wlist); ft_memdel((void**)&cl); - return (-1); - } - if (!(cl->wlist = ft_init_win())) - { - ft_memdel((void**)&cl->wlist); - ft_memdel((void**)&cl); - return (-1); + return (NULL); } - *clist = cl; - return (0); + return (cl); } diff --git a/src/ft_init_map.c b/src/ft_init_map.c index c611ba2..4e8650b 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -18,18 +18,18 @@ static int8_t ft_init_map_callocs(t_map *mlist) { - if (!(mlist->no_tex_path = (char*)ft_calloc(1, sizeof(char))) || - !(mlist->so_tex_path = (char*)ft_calloc(1, sizeof(char))) || - !(mlist->ea_tex_path = (char*)ft_calloc(1, sizeof(char))) || - !(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->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))) || - !(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)))) + if (!(mlist.no_tex_path = (char*)ft_calloc(1, sizeof(char))) || + !(mlist.so_tex_path = (char*)ft_calloc(1, sizeof(char))) || + !(mlist.ea_tex_path = (char*)ft_calloc(1, sizeof(char))) || + !(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.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))) || + !(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)))) return (-1); return (0); } @@ -43,18 +43,18 @@ t_map return (NULL); if (ft_init_map_callocs(mlist) < 0) return (NULL); - mlist->map[1] = 0; - mlist->map_w = 0; - mlist->map_h = 0; - mlist->x_step = 0; - mlist->y_step = 0; - mlist->line_chk = 0; - mlist->map_start = 0; - mlist->isspawn = 0; - mlist->isnlvl = 0; - mlist->ismusic = 0; - mlist->scale = 0; - mlist->nlx = 0; - mlist->nly = 0; + mlist.map[1] = 0; + mlist.map_w = 0; + mlist.map_h = 0; + mlist.x_step = 0; + mlist.y_step = 0; + mlist.line_chk = 0; + mlist.map_start = 0; + mlist.isspawn = 0; + mlist.isnlvl = 0; + mlist.ismusic = 0; + mlist.scale = 0; + mlist.nlx = 0; + mlist.nly = 0; return (mlist); } diff --git a/src/ft_init_winlx.c b/src/ft_init_winlx.c index 87398e4..a65e419 100644 --- a/src/ft_init_winlx.c +++ b/src/ft_init_winlx.c @@ -18,7 +18,7 @@ int ft_init_winlx(t_cub *clist) { - if (!(clist->wlist->wlx = mlx_init())) + if (!(clist.wlist.wlx = mlx_init())) return (-1); return (0); } @@ -26,10 +26,10 @@ int int ft_init_winptr(t_cub *clist) { - 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"))) + 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); - clist->wlist->inited = 1; + clist.wlist.inited = 1; return (0); } diff --git a/src/ft_key_events.c b/src/ft_key_events.c index 317715d..36b4279 100644 --- a/src/ft_key_events.c +++ b/src/ft_key_events.c @@ -21,9 +21,9 @@ static void uint8_t i; i = 0; - while (i < 5 && clist->key_input[i] != keycode && clist->key_input[i] != -1) + while (i < 5 && clist.key_input[i] != keycode && clist.key_input[i] != -1) i++; - clist->key_input[i] = keycode; + clist.key_input[i] = keycode; } int diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index a7eaccf..0c759db 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -19,13 +19,13 @@ static uint64_t ft_find_x(int32_t key, const t_player *pl) { if (key == 0) - return (pl->pos_x + (pl->dir_y * FT_COLL_MULT)); + return (pl.pos_x + (pl.dir_y * FT_COLL_MULT)); else if (key == 1) - return (pl->pos_x + (pl->dir_x * (FT_COLL_MULT / 2))); + return (pl.pos_x + (pl.dir_x * (FT_COLL_MULT / 2))); else if (key == 2) - return (pl->pos_x - (pl->dir_y * FT_COLL_MULT)); + return (pl.pos_x - (pl.dir_y * FT_COLL_MULT)); else if (key == 3) - return (pl->pos_x - (pl->dir_x * (FT_COLL_MULT / 2))); + return (pl.pos_x - (pl.dir_x * (FT_COLL_MULT / 2))); return (1); } @@ -33,13 +33,13 @@ static uint64_t ft_find_y(int32_t key, const t_player *pl) { if (key == 0) - return (pl->pos_y + (pl->dir_x * FT_COLL_MULT)); + return (pl.pos_y + (pl.dir_x * FT_COLL_MULT)); else if (key == 1) - return (pl->pos_y - (pl->dir_y * (FT_COLL_MULT / 2))); + return (pl.pos_y - (pl.dir_y * (FT_COLL_MULT / 2))); else if (key == 2) - return (pl->pos_y - (pl->dir_x * FT_COLL_MULT)); + return (pl.pos_y - (pl.dir_x * FT_COLL_MULT)); else if (key == 3) - return (pl->pos_y + (pl->dir_y * (FT_COLL_MULT / 2))); + return (pl.pos_y + (pl.dir_y * (FT_COLL_MULT / 2))); return (1); } @@ -50,13 +50,13 @@ static void uint64_t y; t_player *pl; - pl = cl->plist; + pl = cl.plist; x = ft_find_x(key, pl); y = ft_find_y(key, pl); - if (cl->mlist->map[y][x] == '1' || cl->mlist->map[y][x] == '2') + if (cl.mlist.map[y][x] == '1' || cl.mlist.map[y][x] == '2') { - pl->pos_y = old_y; - pl->pos_x = old_x; + pl.pos_y = old_y; + pl.pos_x = old_x; } } @@ -64,22 +64,22 @@ int ft_key_loop(t_cub *cl) { uint8_t i; - const float old_y = cl->plist->pos_y; - const float old_x = cl->plist->pos_x; + const float old_y = cl.plist.pos_y; + const float old_x = cl.plist.pos_x; i = 0; - while (i < 5 && cl->key_input[i] != -1 && cl->key_input[i] <= 5) + 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) + cl.key_ptr[cl.key_input[i]](cl); + ft_collision(old_y, old_x, cl.key_input[i], cl); + if (cl.mlist.isnlvl) { if (ft_warp_level(cl) < 0) return (ft_exit(FT_RET_FAILED_STRUCTS, cl)); } i++; } - if (cl->key_input[0] != -1) + if (cl.key_input[0] != -1) ft_draw_scene(cl); return (0); } diff --git a/src/ft_key_release.c b/src/ft_key_release.c index 58eb2bc..c4cf257 100644 --- a/src/ft_key_release.c +++ b/src/ft_key_release.c @@ -22,10 +22,10 @@ static void i = 0; while (i < 3) { - if (cl->key_input[i] == -1 && cl->key_input[i + 1] != -1) + if (cl.key_input[i] == -1 && cl.key_input[i + 1] != -1) { - cl->key_input[i] = cl->key_input[i + 1]; - cl->key_input[i + 1] = -1; + cl.key_input[i] = cl.key_input[i + 1]; + cl.key_input[i + 1] = -1; } i++; } @@ -39,8 +39,8 @@ static void i = 0; while (i < 5) { - if (clist->key_input[i] == keycode) - clist->key_input[i] = -1; + if (clist.key_input[i] == keycode) + clist.key_input[i] = -1; i++; } ft_decale(clist); diff --git a/src/ft_map_error.c b/src/ft_map_error.c index a36507a..9e34649 100644 --- a/src/ft_map_error.c +++ b/src/ft_map_error.c @@ -20,7 +20,7 @@ int ft_dprintf(STDERR_FILENO, "Error\n"); ft_dprintf(STDERR_FILENO, "\033[1;31mMap error: line %lu: %s\033[0m\n", - clist->mlist->line_chk, + clist.mlist.line_chk, errmsg); return (ft_exit(4, clist)); } diff --git a/src/ft_music.c b/src/ft_music.c index d110256..9a86c98 100644 --- a/src/ft_music.c +++ b/src/ft_music.c @@ -22,7 +22,7 @@ void t_cub *cl; cl = (t_cub *)vargp; - cl->isoldmus = 1; - system(cl->mlist->music_cmd); + cl.isoldmus = 1; + system(cl.mlist.music_cmd); return (NULL); } diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index 48201fd..9b34087 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -25,13 +25,13 @@ static void size_t j; i = 0; - ml = clist->mlist; - while (ml->map[i]) + ml = clist.mlist; + while (ml.map[i]) i++; j = 0; - while (ml->map[i - 1][j]) + while (ml.map[i - 1][j]) { - if (ml->map[i - 1][j] != '1' && ml->map[i - 1][j] != '\0') + if (ml.map[i - 1][j] != '1' && ml.map[i - 1][j] != '\0') ft_map_error(FT_ERR_MAP_L_L, clist); j++; } @@ -51,7 +51,7 @@ static int8_t char **words; int ret; - clist->mlist->line_chk += 1; + clist.mlist.line_chk += 1; if ((ret = get_next_line(fd, &line)) < 0) return (ft_map_error(FT_ERR_READ, clist)); if (ret == 0) @@ -93,14 +93,14 @@ void while (ret != 12 && ret >= 0) ret = ft_parse_it(fd, clist); (ret == -2) ? (ft_map_error(FT_ERR_ALR_SET, clist)) : 0; - (ret == -1) ? (ft_map_error(clist->errmsg, clist)) : 0; + (ret == -1) ? (ft_map_error(clist.errmsg, clist)) : 0; if (ft_get_map_core(fd, clist) < 0) - ft_map_error(clist->errmsg, clist); + ft_map_error(clist.errmsg, clist); ft_check_map_last_line(clist); - ft_get_player_spawn(clist->plist, clist); - ft_get_nlvl_pos(clist->mlist); + ft_get_player_spawn(clist.plist, clist); + ft_get_nlvl_pos(clist.mlist); ft_check_missing(clist); ft_set_minimap_scale(clist); - clist->currlvl += 1; + clist.currlvl += 1; close(fd); } diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index cd34014..c27e596 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -19,61 +19,61 @@ /* static void */ /* ft_calc_sprite_norme(t_cub *cl) */ /* { */ -/* if (cl->sp_list.s_start_y < 0) */ -/* cl->sp_list.s_start_y = 0; */ -/* cl->sp_list.s_end_y = cl->sp_list.s_h / 2 + cl->wlist->y_size / 2; */ -/* if (cl->sp_list.s_end_y > (int)cl->wlist->y_size) */ -/* cl->sp_list.s_end_y = cl->wlist->y_size - 1; */ -/* cl->sp_list.s_w = abs((int)(cl->wlist->x_size */ -/* * cl->sp_list.sprite_transform_y)); /\*sprite width*\/ */ -/* cl->sp_list.s_start_x = -cl->sp_list.s_w / 2 + cl->sp_list.s_screen_x; */ -/* if (cl->sp_list.s_start_x < 0) */ -/* cl->sp_list.s_start_y = 0; */ -/* cl->sp_list.s_end_x = cl->sp_list.s_w / 2 + cl->wlist->x_size; */ -/* if (cl->sp_list.s_end_x < (int)cl->wlist->x_size) */ -/* cl->sp_list.s_end_x = cl->wlist->x_size - 1; */ +/* if (cl.sp_list.s_start_y < 0) */ +/* cl.sp_list.s_start_y = 0; */ +/* cl.sp_list.s_end_y = cl.sp_list.s_h / 2 + cl.wlist.y_size / 2; */ +/* if (cl.sp_list.s_end_y > (int)cl.wlist.y_size) */ +/* cl.sp_list.s_end_y = cl.wlist.y_size - 1; */ +/* cl.sp_list.s_w = abs((int)(cl.wlist.x_size */ +/* * cl.sp_list.sprite_transform_y)); /\*sprite width*\/ */ +/* cl.sp_list.s_start_x = -cl.sp_list.s_w / 2 + cl.sp_list.s_screen_x; */ +/* if (cl.sp_list.s_start_x < 0) */ +/* cl.sp_list.s_start_y = 0; */ +/* cl.sp_list.s_end_x = cl.sp_list.s_w / 2 + cl.wlist.x_size; */ +/* if (cl.sp_list.s_end_x < (int)cl.wlist.x_size) */ +/* cl.sp_list.s_end_x = cl.wlist.x_size - 1; */ /* } */ /* static void */ /* ft_calc_sprite(t_cub *cl) */ /* { */ -/* cl->sp_list.s_x = cl->sp_list.s_pos_x - cl->plist->pos_x; */ -/* cl->sp_list.s_y = cl->sp_list.s_pos_y - cl->plist->pos_y; */ -/* cl->sp_list.inv_c_m = 1.0 / (cl->plist->plane_x * cl->plist->dir_x */ -/* - cl->plist->dir_y * cl->plist->plane_y); */ -/* cl->sp_list.sprite_transform_x = cl->sp_list.inv_c_m */ -/* * (cl->plist->dir_y * cl->sp_list.s_x */ -/* - cl->plist->dir_x * cl->sp_list.s_y); */ -/* cl->sp_list.sprite_transform_y = cl->sp_list.inv_c_m */ -/* * (cl->plist->plane_y * cl->sp_list.s_x */ -/* - cl->plist->plane_x * cl->sp_list.s_y); */ -/* cl->sp_list.s_screen_x = (int)((cl->wlist->y_size / 2) */ -/* * (1 + cl->sp_list.sprite_transform_x */ -/* / cl->sp_list.sprite_transform_y)); */ -/* cl->sp_list.s_h = */ -/* abs((int)(cl->wlist->y_size * cl->sp_list.sprite_transform_y)); */ -/* cl->sp_list.s_start_y = -cl->sp_list.s_h / 2 + cl->wlist->y_size / 2; */ +/* cl.sp_list.s_x = cl.sp_list.s_pos_x - cl.plist.pos_x; */ +/* cl.sp_list.s_y = cl.sp_list.s_pos_y - cl.plist.pos_y; */ +/* cl.sp_list.inv_c_m = 1.0 / (cl.plist.plane_x * cl.plist.dir_x */ +/* - cl.plist.dir_y * cl.plist.plane_y); */ +/* cl.sp_list.sprite_transform_x = cl.sp_list.inv_c_m */ +/* * (cl.plist.dir_y * cl.sp_list.s_x */ +/* - cl.plist.dir_x * cl.sp_list.s_y); */ +/* cl.sp_list.sprite_transform_y = cl.sp_list.inv_c_m */ +/* * (cl.plist.plane_y * cl.sp_list.s_x */ +/* - cl.plist.plane_x * cl.sp_list.s_y); */ +/* cl.sp_list.s_screen_x = (int)((cl.wlist.y_size / 2) */ +/* * (1 + cl.sp_list.sprite_transform_x */ +/* / cl.sp_list.sprite_transform_y)); */ +/* cl.sp_list.s_h = */ +/* abs((int)(cl.wlist.y_size * cl.sp_list.sprite_transform_y)); */ +/* cl.sp_list.s_start_y = -cl.sp_list.s_h / 2 + cl.wlist.y_size / 2; */ /* ft_calc_sprite_norme(cl); */ /* } */ void ft_calc_tex(t_cub *clist) { - if (clist->rlist.side == 0) - clist->rlist.wall_hit_x = (clist->plist->pos_x) + - clist->rlist.wall_dist * clist->rlist.y_ray_dir; + if (clist.rlist.side == 0) + clist.rlist.wall_hit_x = (clist.plist.pos_x) + + clist.rlist.wall_dist * clist.rlist.y_ray_dir; else - clist->rlist.wall_hit_x = (clist->plist->pos_y) + - clist->rlist.wall_dist * clist->rlist.x_ray_dir; - clist->rlist.wall_hit_x -= floor(clist->rlist.wall_hit_x); - clist->tlist[clist->w_side].tex_x = (int)(clist->rlist.wall_hit_x * - (double)clist->tlist[clist->w_side].img_w); - if (clist->rlist.side == 0 && clist->rlist.x_ray_dir > 0) - clist->tlist[clist->w_side].tex_x = clist->tlist[clist->w_side].img_w - - clist->tlist[clist->w_side].tex_x - 1; - else if (clist->rlist.side == 1 && clist->rlist.y_ray_dir < 0) - clist->tlist[clist->w_side].tex_x = clist->tlist[clist->w_side].img_w - - clist->tlist[clist->w_side].tex_x - 1; + clist.rlist.wall_hit_x = (clist.plist.pos_y) + + clist.rlist.wall_dist * clist.rlist.x_ray_dir; + clist.rlist.wall_hit_x -= floor(clist.rlist.wall_hit_x); + clist.tlist[clist.w_side].tex_x = (int)(clist.rlist.wall_hit_x * + (double)clist.tlist[clist.w_side].img_w); + if (clist.rlist.side == 0 && clist.rlist.x_ray_dir > 0) + clist.tlist[clist.w_side].tex_x = clist.tlist[clist.w_side].img_w + - clist.tlist[clist.w_side].tex_x - 1; + else if (clist.rlist.side == 1 && clist.rlist.y_ray_dir < 0) + clist.tlist[clist.w_side].tex_x = clist.tlist[clist.w_side].img_w + - clist.tlist[clist.w_side].tex_x - 1; } static void @@ -82,26 +82,26 @@ static void t_win *wl; t_player *pl; - wl = cl->wlist; - pl = cl->plist; - pl->cam_x = 2 * i / (float)(wl->x_size) - 1; - cl->rlist.x_ray_pos = pl->pos_y; - cl->rlist.y_ray_pos = pl->pos_x; - cl->rlist.x_ray_dir = pl->dir_x + pl->plane_x * - pl->cam_x; - cl->rlist.y_ray_dir = pl->dir_y + pl->plane_y * - pl->cam_x; - cl->rlist.sqx = (int16_t)cl->rlist.x_ray_pos; - cl->rlist.sqy = (int16_t)cl->rlist.y_ray_pos; + wl = cl.wlist; + pl = cl.plist; + pl.cam_x = 2 * i / (float)(wl.x_size) - 1; + cl.rlist.x_ray_pos = pl.pos_y; + cl.rlist.y_ray_pos = pl.pos_x; + cl.rlist.x_ray_dir = pl.dir_x + pl.plane_x * + pl.cam_x; + cl.rlist.y_ray_dir = pl.dir_y + pl.plane_y * + pl.cam_x; + cl.rlist.sqx = (int16_t)cl.rlist.x_ray_pos; + cl.rlist.sqy = (int16_t)cl.rlist.y_ray_pos; ft_detect(cl); - if (cl->rlist.side == 0) + if (cl.rlist.side == 0) { - cl->rlist.wall_dist = (cl->rlist.sqx - cl->rlist.x_ray_pos + - (1 - cl->mlist->x_step) / 2) / cl->rlist.x_ray_dir; + cl.rlist.wall_dist = (cl.rlist.sqx - cl.rlist.x_ray_pos + + (1 - cl.mlist.x_step) / 2) / cl.rlist.x_ray_dir; } else - cl->rlist.wall_dist = (cl->rlist.sqy - cl->rlist.y_ray_pos + - (1 - cl->mlist->y_step) / 2) / cl->rlist.y_ray_dir; + cl.rlist.wall_dist = (cl.rlist.sqy - cl.rlist.y_ray_pos + + (1 - cl.mlist.y_step) / 2) / cl.rlist.y_ray_dir; } void @@ -111,22 +111,22 @@ void t_win *wl; i = 0; - wl = cl->wlist; - while (i < wl->x_size) + wl = cl.wlist; + while (i < wl.x_size) { ft_initray(cl, i); - cl->rlist.line_h = (int16_t)(wl->y_size / cl->rlist.wall_dist); - cl->rlist.wall_t = -cl->rlist.line_h / 2 + wl->y_size / 2; - if (cl->rlist.wall_t < 0) - cl->rlist.wall_t = 0; - cl->rlist.wall_b = cl->rlist.line_h / 2 + wl->y_size / 2; - if (cl->rlist.wall_b >= (float)wl->y_size) - cl->rlist.wall_b = wl->y_size - 1; + cl.rlist.line_h = (int16_t)(wl.y_size / cl.rlist.wall_dist); + cl.rlist.wall_t = -cl.rlist.line_h / 2 + wl.y_size / 2; + if (cl.rlist.wall_t < 0) + cl.rlist.wall_t = 0; + cl.rlist.wall_b = cl.rlist.line_h / 2 + wl.y_size / 2; + if (cl.rlist.wall_b >= (float)wl.y_size) + cl.rlist.wall_b = wl.y_size - 1; ft_choose_tex(cl); ft_calc_tex(cl); /* ft_calc_sprite(cl); */ /* ft_draw_sprite(cl , i); */ - ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b); + ft_draw_verline(cl, i, cl.rlist.wall_t, cl.rlist.wall_b); i++; } } diff --git a/src/ft_select_get.c b/src/ft_select_get.c index ed569ff..3355870 100644 --- a/src/ft_select_get.c +++ b/src/ft_select_get.c @@ -20,24 +20,24 @@ static int8_t { if (ret == 12) return (12); - if (ret == 0 && clist->currlvl == 0 && - (clist->wlist->x_size != 0 || clist->wlist->y_size != 0)) + if (ret == 0 && clist.currlvl == 0 && + (clist.wlist.x_size != 0 || clist.wlist.y_size != 0)) return (-1); - else if (ret == 1 && (clist->mlist->no_tex_path[0])) + else if (ret == 1 && (clist.mlist.no_tex_path[0])) return (-1); - else if (ret == 2 && (clist->mlist->so_tex_path[0])) + else if (ret == 2 && (clist.mlist.so_tex_path[0])) return (-1); - else if (ret == 3 && (clist->mlist->ea_tex_path[0])) + else if (ret == 3 && (clist.mlist.ea_tex_path[0])) return (-1); - else if (ret == 4 && (clist->mlist->we_tex_path[0])) + else if (ret == 4 && (clist.mlist.we_tex_path[0])) return (-1); - else if (ret == 5 && (clist->mlist->sprite_path[0])) + else if (ret == 5 && (clist.mlist.sprite_path[0])) return (-1); - else if (ret == 6 && ((clist->f_rgb.r != -1) || (clist->f_rgb.g != -1) - || (clist->f_rgb.b != -1))) + else if (ret == 6 && ((clist.f_rgb.r != -1) || (clist.f_rgb.g != -1) + || (clist.f_rgb.b != -1))) return (-1); - else if (ret == 7 && ((clist->c_rgb.r != -1) || (clist->c_rgb.g != -1) - || (clist->c_rgb.b != -1))) + else if (ret == 7 && ((clist.c_rgb.r != -1) || (clist.c_rgb.g != -1) + || (clist.c_rgb.b != -1))) return (-1); return (ret); } @@ -47,11 +47,11 @@ static int8_t { if (ret == 12) return (12); - if (ret == 8 && (clist->mlist->nlevel_path[0])) + if (ret == 8 && (clist.mlist.nlevel_path[0])) return (-1); - if (ret == 9 && (clist->mlist->nl_tex_path[0])) + if (ret == 9 && (clist.mlist.nl_tex_path[0])) return (-1); - if (ret == 10 && (clist->mlist->music_path[0])) + if (ret == 10 && (clist.mlist.music_path[0])) return (-1); return (ret); } @@ -94,7 +94,7 @@ int8_t ft_free_words(words); return (12); } - if (id < 0 || clist->get_ptr[id](words, clist) < 0) + if (id < 0 || clist.get_ptr[id](words, clist) < 0) { ft_free_words(words); return ((id < 0) ? (-2) : (-1)); diff --git a/src/ft_set_minimap_scale.c b/src/ft_set_minimap_scale.c index dc4bd12..9fa5a85 100644 --- a/src/ft_set_minimap_scale.c +++ b/src/ft_set_minimap_scale.c @@ -17,10 +17,10 @@ void { t_map *ml; - ml = clist->mlist; - ((ml->scale = (clist->wlist->x_size / (uint16_t)ml->map_w) - 1) < 1) - ? (ml->scale = 1) : 0; - (clist->wlist->y_size < (ml->map_h * ml->scale)) ? (ml->scale = - (clist->wlist->y_size / (uint16_t)ml->map_h) - 1) : 0; - (ml->scale >= 10) ? (ml->scale /= 4) : 0; + ml = clist.mlist; + ((ml.scale = (clist.wlist.x_size / (uint16_t)ml.map_w) - 1) < 1) + ? (ml.scale = 1) : 0; + (clist.wlist.y_size < (ml.map_h * ml.scale)) ? (ml.scale = + (clist.wlist.y_size / (uint16_t)ml.map_h) - 1) : 0; + (ml.scale >= 10) ? (ml.scale /= 4) : 0; } diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index 6e12a56..0dafd05 100644 --- a/src/ft_tex_init.c +++ b/src/ft_tex_init.c @@ -27,36 +27,36 @@ static void ft_get_nlvl_img(t_cub *cl) { - cl->tlist[5].img = mlx_xpm_file_to_image(cl->wlist->wlx, - cl->mlist->nl_tex_path, &cl->tlist[5].img_w, &cl->tlist[5].img_h); - cl->tlist[5].ptr = mlx_get_data_addr(cl->tlist[5].img, - &cl->tlist[5].bpp, &cl->tlist[5].sizeline, &cl->tlist[5].endian); + cl.tlist[5].img = mlx_xpm_file_to_image(cl.wlist.wlx, + cl.mlist.nl_tex_path, &cl.tlist[5].img_w, &cl.tlist[5].img_h); + cl.tlist[5].ptr = mlx_get_data_addr(cl.tlist[5].img, + &cl.tlist[5].bpp, &cl.tlist[5].sizeline, &cl.tlist[5].endian); } void ft_wall_tex_init(t_cub *cl) { - cl->tlist[0].img = mlx_xpm_file_to_image(cl->wlist->wlx, - cl->mlist->no_tex_path, &cl->tlist[0].img_w, &cl->tlist[0].img_h); - cl->tlist[0].ptr = mlx_get_data_addr(cl->tlist[0].img, - &cl->tlist[0].bpp, &cl->tlist[0].sizeline, &cl->tlist[0].endian); - cl->tlist[1].img = mlx_xpm_file_to_image(cl->wlist->wlx, - cl->mlist->so_tex_path, &cl->tlist[1].img_w, &cl->tlist[1].img_h); - cl->tlist[1].ptr = mlx_get_data_addr(cl->tlist[1].img, - &cl->tlist[1].bpp, &cl->tlist[1].sizeline, &cl->tlist[1].endian); - cl->tlist[2].img = mlx_xpm_file_to_image(cl->wlist->wlx, - cl->mlist->ea_tex_path, &cl->tlist[2].img_w, &cl->tlist[2].img_h); - cl->tlist[2].ptr = mlx_get_data_addr(cl->tlist[2].img, - &cl->tlist[2].bpp, &cl->tlist[2].sizeline, &cl->tlist[2].endian); - cl->tlist[3].img = mlx_xpm_file_to_image(cl->wlist->wlx, - cl->mlist->we_tex_path, &cl->tlist[3].img_w, &cl->tlist[3].img_h); - cl->tlist[3].ptr = mlx_get_data_addr(cl->tlist[3].img, - &cl->tlist[3].bpp, &cl->tlist[3].sizeline, &cl->tlist[3].endian); - cl->tlist[4].img = mlx_xpm_file_to_image(cl->wlist->wlx, - cl->mlist->sprite_path, &cl->tlist[4].img_w, &cl->tlist[4].img_h); - cl->tlist[4].ptr = mlx_get_data_addr(cl->tlist[4].img, - &cl->tlist[4].bpp, &cl->tlist[4].sizeline, &cl->tlist[4].endian); - if (cl->mlist->isnlvl) + cl.tlist[0].img = mlx_xpm_file_to_image(cl.wlist.wlx, + cl.mlist.no_tex_path, &cl.tlist[0].img_w, &cl.tlist[0].img_h); + cl.tlist[0].ptr = mlx_get_data_addr(cl.tlist[0].img, + &cl.tlist[0].bpp, &cl.tlist[0].sizeline, &cl.tlist[0].endian); + cl.tlist[1].img = mlx_xpm_file_to_image(cl.wlist.wlx, + cl.mlist.so_tex_path, &cl.tlist[1].img_w, &cl.tlist[1].img_h); + cl.tlist[1].ptr = mlx_get_data_addr(cl.tlist[1].img, + &cl.tlist[1].bpp, &cl.tlist[1].sizeline, &cl.tlist[1].endian); + cl.tlist[2].img = mlx_xpm_file_to_image(cl.wlist.wlx, + cl.mlist.ea_tex_path, &cl.tlist[2].img_w, &cl.tlist[2].img_h); + cl.tlist[2].ptr = mlx_get_data_addr(cl.tlist[2].img, + &cl.tlist[2].bpp, &cl.tlist[2].sizeline, &cl.tlist[2].endian); + cl.tlist[3].img = mlx_xpm_file_to_image(cl.wlist.wlx, + cl.mlist.we_tex_path, &cl.tlist[3].img_w, &cl.tlist[3].img_h); + cl.tlist[3].ptr = mlx_get_data_addr(cl.tlist[3].img, + &cl.tlist[3].bpp, &cl.tlist[3].sizeline, &cl.tlist[3].endian); + cl.tlist[4].img = mlx_xpm_file_to_image(cl.wlist.wlx, + cl.mlist.sprite_path, &cl.tlist[4].img_w, &cl.tlist[4].img_h); + cl.tlist[4].ptr = mlx_get_data_addr(cl.tlist[4].img, + &cl.tlist[4].bpp, &cl.tlist[4].sizeline, &cl.tlist[4].endian); + if (cl.mlist.isnlvl) ft_get_nlvl_img(cl); - cl->walltexgood = 1; + cl.walltexgood = 1; } diff --git a/src/ft_treat_args.c b/src/ft_treat_args.c index 6f8ef87..f850fc6 100644 --- a/src/ft_treat_args.c +++ b/src/ft_treat_args.c @@ -37,9 +37,9 @@ uint8_t if (ft_init_winptr(clist) < 0) return (ft_exit(FT_RET_FAILED_MLX, clist)); ft_draw_scene(clist); - if (clist->mlist->ismusic) - pthread_create(&clist->tid, NULL, ft_music_thread, clist); - ft_hooks_and_loops(clist->wlist, clist); + if (clist.mlist.ismusic) + pthread_create(&clist.tid, NULL, ft_music_thread, clist); + ft_hooks_and_loops(clist.wlist, clist); } else if (argc == 3 && !ft_strncmp("--save", argv[2], 7)) { diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index de87187..a50ff65 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -21,17 +21,17 @@ static void ft_del_map(t_map *ml) { - ft_memdel((void**)&ml->no_tex_path); - ft_memdel((void**)&ml->so_tex_path); - ft_memdel((void**)&ml->ea_tex_path); - ft_memdel((void**)&ml->we_tex_path); - ft_memdel((void**)&ml->sprite_path); - ft_memdel((void**)&ml->nl_tex_path); - ft_memdel((void**)&ml->nlevel_path); - ft_memdel((void**)&ml->music_path); - ft_memdel((void**)&ml->music_cmd); - ft_memdel((void**)&ml->mapl); - ft_free_words(ml->map); + ft_memdel((void**)&ml.no_tex_path); + ft_memdel((void**)&ml.so_tex_path); + ft_memdel((void**)&ml.ea_tex_path); + ft_memdel((void**)&ml.we_tex_path); + ft_memdel((void**)&ml.sprite_path); + ft_memdel((void**)&ml.nl_tex_path); + ft_memdel((void**)&ml.nlevel_path); + ft_memdel((void**)&ml.music_path); + ft_memdel((void**)&ml.music_cmd); + ft_memdel((void**)&ml.mapl); + ft_free_words(ml.map); ft_memdel((void**)&ml); } @@ -40,23 +40,23 @@ static void { uint8_t i; - cl->plist->pos_x = 0; - cl->plist->pos_y = 0; - cl->plist->start_x = 0; - cl->plist->start_y = 0; - cl->plist->cam_x = 0; - cl->plist->dir_x = -1; - cl->plist->dir_y = 0; - cl->plist->plane_x = 0; - cl->plist->plane_y = 0.66666666; - cl->f_rgb = ft_init_rgb(); - cl->c_rgb = ft_init_rgb(); - cl->rlist = ft_init_s_ray(); + cl.plist.pos_x = 0; + cl.plist.pos_y = 0; + cl.plist.start_x = 0; + cl.plist.start_y = 0; + cl.plist.cam_x = 0; + cl.plist.dir_x = -1; + cl.plist.dir_y = 0; + cl.plist.plane_x = 0; + cl.plist.plane_y = 0.66666666; + cl.f_rgb = ft_init_rgb(); + cl.c_rgb = ft_init_rgb(); + cl.rlist = ft_init_s_ray(); i = 0; while (i <= 5) { - mlx_destroy_image(cl->wlist->wlx, cl->tlist[i].img); - cl->tlist[i].img = NULL; + mlx_destroy_image(cl.wlist.wlx, cl.tlist[i].img); + cl.tlist[i].img = NULL; i++; } } @@ -64,21 +64,21 @@ static void static void ft_treat_music(uint8_t isoldmus, char *tmp_mup, t_cub *cl) { - if (isoldmus && !cl->mlist->ismusic) + if (isoldmus && !cl.mlist.ismusic) { - pthread_cancel(cl->tid); - pthread_join(cl->tid, NULL); - cl->isoldmus = 0; + pthread_cancel(cl.tid); + pthread_join(cl.tid, NULL); + cl.isoldmus = 0; } - else if (isoldmus && cl->mlist->ismusic - && ft_strncmp(tmp_mup, cl->mlist->music_path, ft_strlen(tmp_mup) + 1)) + else if (isoldmus && cl.mlist.ismusic + && ft_strncmp(tmp_mup, cl.mlist.music_path, ft_strlen(tmp_mup) + 1)) { - pthread_cancel(cl->tid); - pthread_join(cl->tid, NULL); - pthread_create(&cl->tid, NULL, ft_music_thread, cl); + pthread_cancel(cl.tid); + pthread_join(cl.tid, NULL); + pthread_create(&cl.tid, NULL, ft_music_thread, cl); } - else if (isoldmus && cl->mlist->ismusic - && !ft_strncmp(tmp_mup, cl->mlist->music_path, ft_strlen(tmp_mup) + 1)) + else if (isoldmus && cl.mlist.ismusic + && !ft_strncmp(tmp_mup, cl.mlist.music_path, ft_strlen(tmp_mup) + 1)) return ; } @@ -89,19 +89,19 @@ int8_t char *tmp_mup; uint8_t isoldmus; - if ((uint32_t)cl->plist->pos_x == cl->mlist->nlx && - (uint32_t)cl->plist->pos_y == cl->mlist->nly) + if ((uint32_t)cl.plist.pos_x == cl.mlist.nlx && + (uint32_t)cl.plist.pos_y == cl.mlist.nly) { if (!(next_path = (char *)malloc((ft_strlen( - cl->mlist->nlevel_path) + 1) * sizeof(char)))) + cl.mlist.nlevel_path) + 1) * sizeof(char)))) return (-1); - ft_sprintf(next_path, "%s", cl->mlist->nlevel_path); - isoldmus = cl->mlist->ismusic; + ft_sprintf(next_path, "%s", cl.mlist.nlevel_path); + isoldmus = cl.mlist.ismusic; if (isoldmus) - tmp_mup = ft_strdup(cl->mlist->music_path); + tmp_mup = ft_strdup(cl.mlist.music_path); ft_del_some(cl); - ft_del_map(cl->mlist); - if (!(cl->mlist = ft_init_map())) + ft_del_map(cl.mlist); + if (!(cl.mlist = ft_init_map())) return (-1); ft_parse_map(next_path, cl); ft_treat_music(isoldmus, tmp_mup, cl); @@ -17,11 +17,11 @@ int main(int argc, const char *argv[]) { - t_cub *clist; + t_cub clist; if (ft_check_map_arg(argc, argv) == FT_RET_BAD_ARGV) return (FT_RET_BAD_ARGV); - if (ft_init_cub3d(&clist) < 0) + if (!(clist = ft_init_cub3d())) return (FT_RET_FAILED_STRUCTS); ft_parse_map(argv[1], clist); if (ft_init_winlx(clist) < 0) |