From a883e185c758252c5d354dcd8162361c726aaa92 Mon Sep 17 00:00:00 2001 From: nicolas-arnaud Date: Tue, 22 Nov 2022 05:35:55 +0100 Subject: [PATCH] littles change --- includes/cub3d.h | 13 ++++++++++--- maps/tests/massive.cub | 1 + maps/tests/massive2.cub | 12 ++++++------ src/parsing/getline.c | 14 ++++++++++---- src/parsing/map.c | 10 +++++++--- src/parsing/parsing.c | 6 +++--- src/render/minimap.c | 32 +++++++++----------------------- src/render/render.c | 8 +++----- 8 files changed, 49 insertions(+), 47 deletions(-) diff --git a/includes/cub3d.h b/includes/cub3d.h index 7c84e15..0f8d278 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 23:17:41 by narnaud ### ########.fr */ +/* Updated: 2022/11/22 05:24:50 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,7 +70,6 @@ typedef struct s_img int pixel_bits; int line_bytes; int endian; - } t_img; typedef struct s_env @@ -96,13 +95,21 @@ typedef struct s_env t_dvec cam_plan; } t_env; +typedef struct s_minimap +{ + t_vec min; + t_vec max; + t_vec delt; +} t_mmap; + // Render +t_mmap measure(t_env *env); void check_side(t_rc *rc); void init_ray(t_env *env, t_rc *rc); int ray_hit(t_env *env, t_rc *rc); void draw_rectangle(t_env *env, t_rect rect, int borders); t_rect get_mm_cell(char type, t_vec pos, t_vec delta); -void render_minimap(t_env *env); +void render_minimap(t_env *env, t_mmap mm); void render_view(t_env *env); void render(t_env *env); diff --git a/maps/tests/massive.cub b/maps/tests/massive.cub index 47dc56b..f27d3c6 100644 --- a/maps/tests/massive.cub +++ b/maps/tests/massive.cub @@ -911,3 +911,4 @@ C 219, 213, 213 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 + diff --git a/maps/tests/massive2.cub b/maps/tests/massive2.cub index 90e8865..c845a44 100644 --- a/maps/tests/massive2.cub +++ b/maps/tests/massive2.cub @@ -1,15 +1,15 @@ NO ./textures/redbrick.xpm -EA ./textures/colorstone.xpm -SO ./textures/redbrick.xpm -WE ./textures/redbrick.xpm +EA ./textures/brownbrick.xpm +SO ./textures/greenbrick.xpm +WE ./textures/bluebrick.xpm DO ./textures/wood.xpm -F 147, 159, 153 -C 219, 213, 213 +F 0, 159, 0 +C 0,0, 213 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 -100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 +100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 100S00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 diff --git a/src/parsing/getline.c b/src/parsing/getline.c index 9eb352d..209bdd1 100644 --- a/src/parsing/getline.c +++ b/src/parsing/getline.c @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/21 21:23:40 by narnaud #+# #+# */ -/* Updated: 2022/08/23 16:34:20 by narnaud ### ########.fr */ +/* Updated: 2022/11/22 05:00:06 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,17 +19,23 @@ char *save_buffer(char *buffer, int *i) char *part2; char *ret; - part1 = ft_calloc(512, sizeof(char)); + part1 = malloc(4097 * sizeof(char)); j = 0; - while (j < 512) + while (j < 4096) { part1[j++] = buffer[*i]; if (buffer[*i] == '\0' || buffer[(*i)++] == '\n') + { + part1[j] = 0; return (part1); + } } + part1[4097] = 0; part2 = save_buffer(buffer, i); ret = ft_strjoin(part1, part2); - return (free(part1), free(part2), ret); + free(part1); + free(part2); + return (ret); } char *get_next_line(const int fd) diff --git a/src/parsing/map.c b/src/parsing/map.c index 270320f..7f0e25c 100644 --- a/src/parsing/map.c +++ b/src/parsing/map.c @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/08/23 09:30:50 by narnaud #+# #+# */ -/* Updated: 2022/11/21 19:05:12 by narnaud ### ########.fr */ +/* Updated: 2022/11/22 05:33:45 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,8 +57,12 @@ int find_player(t_env *env) int is_in_open_room(t_env *env, int x, int y) { - static char *checked; + static char *checked; + static int recurs; + recurs++; + if (recurs > 1000000 - 2 * (env->wide * env->deep)) + return (1); if (x < 0 || x >= env->wide || y < 0 || y >= env->deep) return (1); if (!checked) @@ -69,8 +73,8 @@ int is_in_open_room(t_env *env, int x, int y) if (env->map[y][x] == '1') return (0); else if (is_in_open_room(env, x + 1, y) - || is_in_open_room(env, x - 1, y) || is_in_open_room(env, x, y + 1) + || is_in_open_room(env, x - 1, y) || is_in_open_room(env, x, y - 1)) return (1); else diff --git a/src/parsing/parsing.c b/src/parsing/parsing.c index 7cbe06f..7346b56 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:43:41 by narnaud ### ########.fr */ +/* Updated: 2022/11/22 05:34:10 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -96,9 +96,9 @@ t_slist *read_map_line(t_env *env, char *line) int is_valid_map(t_env *env) { if (!find_player(env)) - printf("Error: There is no player on the map.\n"); + printf("Error\nYou probably somewhere but not on the map.\n"); else if (is_in_open_room(env, env->player_pos.x, env->player_pos.y)) - printf("Error: You are using an open map.\n"); + printf("Error\n The game can't handle infinite maps..\n"); else return (1); return (0); diff --git a/src/render/minimap.c b/src/render/minimap.c index 5838580..7515082 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 23:33:25 by narnaud ### ########.fr */ +/* Updated: 2022/11/22 03:04:16 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,29 +14,17 @@ t_rect get_mm_cell(char type, t_vec pos, t_vec delta) { - int color; - - if (type == '0') - color = 0x009F00; - else if (type == '1') - color = 0x00009F; + if (type == '1') + return ((t_rect){vec_mult(pos, delta), delta, 0x00009F}); else if (type == '2') - color = 0x9F709F; + return ((t_rect){vec_mult(pos, delta), delta, 0x9F709F}); else - color = 0x000000; - return ((t_rect){vec_mult(pos, delta), delta, color}); + return ((t_rect){vec_mult(pos, delta), delta, 0x009F00}); } -typedef struct s_minimap -{ - t_vec min; - t_vec max; - t_vec delt; -} t_minimap; - -t_minimap measure(t_env *env) +t_mmap measure(t_env *env) { - t_minimap ret; + t_mmap ret; ret.delt = (t_vec){4, 4}; ret.min = (t_vec){ft_max(env->player_pos.x - 25, 0), @@ -47,12 +35,10 @@ t_minimap measure(t_env *env) return (ret); } -void render_minimap(t_env *env) +void render_minimap(t_env *env, t_mmap mm) { t_vec pos; - t_minimap mm; - mm = measure(env); pos.y = 0; while (pos.y + mm.min.y < mm.max.y && env->map[pos.y + mm.min.y]) { @@ -67,7 +53,7 @@ void render_minimap(t_env *env) } pos.y++; } - draw_rectangle(env, (t_rect){\ + draw_rectangle(env, (t_rect){ (t_vec){(env->player_pos.x - mm.min.x) * mm.delt.x - 1, (env->player_pos.y - mm.min.y) * mm.delt.y - 1}, (t_vec){mm.delt.x / 2, mm.delt.y / 2}, 0xFF0000}, 0); diff --git a/src/render/render.c b/src/render/render.c index 5cc8636..6c8c19f 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 23:17:22 by narnaud ### ########.fr */ +/* Updated: 2022/11/22 00:06:15 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,7 +39,7 @@ void draw_wall(t_env *env, t_rc *rc, int wallHeight, int *wall_lim) { tex.y = (int)y_out & (tex_height - 1); y_out += step; - env->buffer[env->line_bytes * wall_lim[0] + rc->x] \ + env->buffer[env->line_bytes * wall_lim[0] + rc->x] = env->tex[rc->tex].buffer[tex_height * tex.y + tex.x]; wall_lim[0]++; } @@ -91,8 +91,6 @@ void render(t_env *env) ft_bzero(env->buffer, WIN_Y_SZ * WIN_X_SZ * sizeof(int)); render_view(env); if (env->minimap) - { - render_minimap(env); - } + render_minimap(env, measure(env)); mlx_put_image_to_window(env->mlx, env->win, env->img, 0, 0); }