From 1860d36b25f1770650721607ffc646f1ef284d3a Mon Sep 17 00:00:00 2001 From: nicolas-arnaud Date: Mon, 21 Nov 2022 20:08:00 +0100 Subject: [PATCH] fixed ugly minimap --- includes/cub3d.h | 2 +- src/parsing/parsing.c | 14 ++++++-------- src/render/minimap.c | 6 ++---- src/render/render.c | 13 +++++++++++-- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/includes/cub3d.h b/includes/cub3d.h index 686ed3b..78b40ce 100644 --- a/includes/cub3d.h +++ b/includes/cub3d.h @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/21 19:24:12 by narnaud #+# #+# */ -/* Updated: 2022/11/21 18:55:22 by narnaud ### ########.fr */ +/* Updated: 2022/11/21 19:41:26 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/parsing/parsing.c b/src/parsing/parsing.c index b9e8751..7cbe06f 100644 --- a/src/parsing/parsing.c +++ b/src/parsing/parsing.c @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/23 17:20:29 by narnaud #+# #+# */ -/* Updated: 2022/11/21 19:00:21 by narnaud ### ########.fr */ +/* Updated: 2022/11/21 19:43:41 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -75,11 +75,9 @@ t_slist *read_map_line(t_env *env, char *line) ret = malloc(sizeof(t_slist)); i = 0; map_y = malloc((ft_strlen(line)) * sizeof(char)); - while (*line) + while (*line && *line != '\n') { - if (*line == '\n') - break ; - else if (!ft_isspace(*line)) + if (!ft_isspace(*line)) map_y[i] = *line; else map_y[i] = '0'; @@ -119,12 +117,12 @@ t_env *load_map(char *filename) line = get_next_line(fd); while (line) { - if (*line && *line != '\n' && progress > 6 && progress++) + if ((*line == '1' || *line == '\t' || *line == ' ') + && progress > 6 && progress++) ft_slst_add_back(&e_map, read_map_line(env, line)); else if (*line != '#') register_settings(&progress, env, line); - free(line); - line = get_next_line(fd); + line = (free(line), get_next_line(fd)); } if (progress < 7 && cleanup_datas(env)) return (printf("Error\nYour map isn't valid.\n"), NULL); diff --git a/src/render/minimap.c b/src/render/minimap.c index 018c6dd..1618f15 100644 --- a/src/render/minimap.c +++ b/src/render/minimap.c @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/08/23 08:14:08 by narnaud #+# #+# */ -/* Updated: 2022/11/21 19:01:36 by narnaud ### ########.fr */ +/* Updated: 2022/11/21 19:56:47 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,13 +27,11 @@ t_rect get_mm_cell(char type, t_vec pos, t_vec delta) return ((t_rect){vec_mult(pos, delta), delta, color}); } -void render_minimap(t_env *env, t_vec size) +void render_minimap(t_env *env, t_vec delt) { char **map; t_vec pos; - t_vec delt; - vec_set(&delt, size.x / env->wide, size.y / env->deep); pos.y = 0; map = env->map; while (map[pos.y]) diff --git a/src/render/render.c b/src/render/render.c index 2d4ff71..c98f54f 100644 --- a/src/render/render.c +++ b/src/render/render.c @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/31 09:33:02 by narnaud #+# #+# */ -/* Updated: 2022/11/21 19:04:16 by narnaud ### ########.fr */ +/* Updated: 2022/11/21 20:04:25 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -88,9 +88,18 @@ void render_view(t_env *env) void render(t_env *env) { + int delt; + ft_bzero(env->buffer, WIN_Y_SZ * WIN_X_SZ * sizeof(int)); render_view(env); if (env->minimap) - render_minimap(env, (t_vec){WIN_X_SZ / 3, WIN_Y_SZ / 3}); + { + delt = WIN_X_SZ / (env->wide * 2); + if (env->deep > WIN_Y_SZ / 2) + delt /= 2 * env->deep / WIN_Y_SZ; + if (env->wide > WIN_X_SZ / 2) + delt /= 2 * env->wide / WIN_X_SZ; + render_minimap(env, (t_vec){delt, delt}); + } mlx_put_image_to_window(env->mlx, env->win, env->img, 0, 0); }