From 7f1091b721843a5b19e60a61f5bd09facdfb21bb Mon Sep 17 00:00:00 2001 From: "B.Goulard" <84p71573@gmail.com> Date: Tue, 17 Dec 2024 17:28:51 +0100 Subject: [PATCH] Fix: removed the t_img texture and left the t_texture instead. --- .c | 0 includes/cub3d.h | 3 ++- includes/cub3d_struct.h | 5 ++--- mlx_layer/mlx_init.c | 10 ++-------- parsing/load_textures.c | 17 ++++++----------- parsing/utils.c | 8 +++++++- raycast/get_texture.c | 10 +++++----- sources/cleanups.c | 15 ++++++--------- sources/main.c | 7 +++++-- 9 files changed, 35 insertions(+), 40 deletions(-) delete mode 100644 .c diff --git a/.c b/.c deleted file mode 100644 index e69de29..0000000 diff --git a/includes/cub3d.h b/includes/cub3d.h index a1bfd7a..05ccf9e 100644 --- a/includes/cub3d.h +++ b/includes/cub3d.h @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/30 16:30:26 by rparodi #+# #+# */ -/* Updated: 2024/12/16 15:35:29 by bgoulard ### ########.fr */ +/* Updated: 2024/12/17 17:18:05 by bgoulard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,6 +30,7 @@ t_texture *get_texture(int side, t_ipoint step, t_info *data); void draw_(int *ti, double *td, t_ipoint step, t_info *data); // utils +void sv_errno(t_info *inf, int err_code); void draw_floor(t_info *data); int render_frame(t_info *data); void my_mlx_pixel_put(t_info *data, int x, int y, int color); diff --git a/includes/cub3d_struct.h b/includes/cub3d_struct.h index 674695d..d97bcf3 100644 --- a/includes/cub3d_struct.h +++ b/includes/cub3d_struct.h @@ -6,7 +6,7 @@ /* By: bgoulard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/28 13:53:54 by bgoulard #+# #+# */ -/* Updated: 2024/12/17 16:52:53 by bgoulard ### ########.fr */ +/* Updated: 2024/12/17 17:21:45 by bgoulard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -93,8 +93,7 @@ typedef struct s_map t_ipoint size; t_tile *map; char **fraw; - t_img *texture[4]; - t_texture texture_[4]; + t_texture texture[4]; t_color bg_colors[2]; } t_map; diff --git a/mlx_layer/mlx_init.c b/mlx_layer/mlx_init.c index 5dcff99..b4bb2da 100644 --- a/mlx_layer/mlx_init.c +++ b/mlx_layer/mlx_init.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/11 19:53:42 by rparodi #+# #+# */ -/* Updated: 2024/12/16 15:36:35 by bgoulard ### ########.fr */ +/* Updated: 2024/12/17 17:18:34 by bgoulard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,6 @@ #include "ft_math.h" -#include #include #include @@ -51,14 +50,9 @@ t_win_list *c3_init_mlx_window(t_info *info) int init_mlx_env(t_info *info) { - info->mlx_ptr = mlx_init(); - if (!info->mlx_ptr) - return (info->last_error = ERROR_MLX, info->errno_state = errno, \ - ERROR_MLX); info->win_ptr = c3_init_mlx_window(info); if (!info->win_ptr) - return (info->last_error = ERROR_MLX, info->errno_state = errno, \ - ERROR_MLX); + return (sv_errno(info, ERROR_MLX), ERROR_MLX); mlx_hook(info->win_ptr, KeyPress, KeyPressMask, keypress_feature, info); mlx_hook(info->win_ptr, KeyRelease, KeyReleaseMask, keyrelease_feature, \ info); diff --git a/parsing/load_textures.c b/parsing/load_textures.c index 26703dc..1ee1f7a 100644 --- a/parsing/load_textures.c +++ b/parsing/load_textures.c @@ -6,10 +6,11 @@ /* By: bgoulard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/01 17:46:52 by bgoulard #+# #+# */ -/* Updated: 2024/12/17 16:58:30 by bgoulard ### ########.fr */ +/* Updated: 2024/12/17 17:22:21 by bgoulard ### ########.fr */ /* */ /* ************************************************************************** */ +#include "cub3d.h" #include "cub3d_struct.h" #include "cub3d_parsing.h" @@ -19,12 +20,6 @@ #include #include -static void sv_errno(t_info *inf, int err_code) -{ - inf->errno_state = errno; - inf->last_error = err_code; -} - bool load_texture(t_info *info, const char *str, const char **id_str) { size_t i; @@ -35,7 +30,7 @@ bool load_texture(t_info *info, const char *str, const char **id_str) { if (ft_strstart_with(str, id_str[i])) { - if (info->map.texture_[i].img != NULL) + if (info->map.texture[i].img != NULL) return (sv_errno(info, ERROR_PARSE_ALREADY_SET), false); texture.path = ft_strtrim(str + ft_strlen(id_str[i]), " \t"); if (texture.path == NULL) @@ -46,7 +41,7 @@ bool load_texture(t_info *info, const char *str, const char **id_str) &texture.width, &texture.height); if (texture.img == NULL) return (sv_errno(info, ERROR_MLX), false); - return (info->map.texture_[i] = texture, true); + return (info->map.texture[i] = texture, true); } i++; } @@ -70,9 +65,9 @@ void *load_textures(void *data) } i = 0; errno = 0; - while (i < sizeof(info->map.texture_) / sizeof(info->map.texture_[0])) + while (i < sizeof(info->map.texture) / sizeof(info->map.texture[0])) { - if (info->map.texture_[i].img == NULL || info->map.texture[i] == NULL) + if (info->map.texture[i].img == NULL) return (sv_errno(info, ERROR_TEXTURE_MISSING), NULL); i++; } diff --git a/parsing/utils.c b/parsing/utils.c index 6682c49..ea6c3e5 100644 --- a/parsing/utils.c +++ b/parsing/utils.c @@ -6,7 +6,7 @@ /* By: bgoulard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/01 17:43:17 by bgoulard #+# #+# */ -/* Updated: 2024/12/16 09:39:50 by bgoulard ### ########.fr */ +/* Updated: 2024/12/17 17:17:53 by bgoulard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,12 @@ #include #include +void sv_errno(t_info *inf, int err_code) +{ + inf->errno_state = errno; + inf->last_error = err_code; +} + t_tile *c3_get_cell(t_tile *map, t_ipoint dimensions, t_ipoint pos) { if (pos.x < 0 || pos.y < 0 || pos.x >= dimensions.x diff --git a/raycast/get_texture.c b/raycast/get_texture.c index d64f832..5b2a0dd 100644 --- a/raycast/get_texture.c +++ b/raycast/get_texture.c @@ -6,7 +6,7 @@ /* By: bgoulard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/16 14:46:04 by bgoulard #+# #+# */ -/* Updated: 2024/12/16 14:46:14 by bgoulard ### ########.fr */ +/* Updated: 2024/12/17 17:23:54 by bgoulard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,11 +15,11 @@ t_texture *get_texture(int side, t_ipoint step, t_info *data) { if (side == 0 && step.x > 0) - return (&data->map.texture_[0]); + return (&data->map.texture[0]); else if (side == 0 && step.x < 0) - return (&data->map.texture_[1]); + return (&data->map.texture[1]); else if (side == 1 && step.y > 0) - return (&data->map.texture_[2]); + return (&data->map.texture[2]); else - return (&data->map.texture_[3]); + return (&data->map.texture[3]); } diff --git a/sources/cleanups.c b/sources/cleanups.c index 05fac29..bb09c11 100644 --- a/sources/cleanups.c +++ b/sources/cleanups.c @@ -6,7 +6,7 @@ /* By: bgoulard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/09 01:11:01 by bgoulard #+# #+# */ -/* Updated: 2024/12/01 17:24:54 by bgoulard ### ########.fr */ +/* Updated: 2024/12/17 17:23:25 by bgoulard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,17 +39,14 @@ static void cleanup_mlx(t_info *info) return ; if (info->win_ptr) mlx_destroy_window(info->mlx_ptr, info->win_ptr); - while (i < sizeof(info->map.texture_) / sizeof(info->map.texture_[0])) + while (i < sizeof(info->map.texture) / sizeof(info->map.texture[0])) { - if (info->map.texture_[i].img) - mlx_destroy_image(info->mlx_ptr, info->map.texture_[i].img); - if (info->map.texture_[i++].path) - ft_free((void **)&info->map.texture_[i - 1].path); + if (info->map.texture[i].img) + mlx_destroy_image(info->mlx_ptr, info->map.texture[i].img); + if (info->map.texture[i++].path) + ft_free((void **)&info->map.texture[i - 1].path); } i = 0; - while (i < sizeof(info->map.texture) / sizeof(info->map.texture[0])) - if (info->map.texture[i++]) - mlx_destroy_image(info->mlx_ptr, info->map.texture[i - 1]); if (info->camera.screen_buff) mlx_destroy_image(info->mlx_ptr, info->camera.screen_buff); mlx_destroy_display(info->mlx_ptr); diff --git a/sources/main.c b/sources/main.c index c6388e0..fe1d716 100644 --- a/sources/main.c +++ b/sources/main.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/30 16:30:03 by rparodi #+# #+# */ -/* Updated: 2024/12/17 16:55:25 by bgoulard ### ########.fr */ +/* Updated: 2024/12/17 17:17:12 by bgoulard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,9 +37,12 @@ void check_err(t_info *info) void run_cub3d(t_info *info) { + info->mlx_ptr = mlx_init(); + if (!info->mlx_ptr) + return (sv_errno(info, ERROR_MLX), (void)0); + parse_map(info); if (init_mlx_env(info) != NO_ERROR) return (c3_perror(info)); - parse_map(info); if (info->cli_ctx.debug) ft_putstr_fd("no debug mod on production run", STDERR_FILENO); if (info->last_error != NO_ERROR)