From fcb08f6447bae21945f40deed37e264b55ddc98f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Tue, 12 Aug 2025 12:21:56 +0200 Subject: [PATCH] fix: various rendering issues - Correct rendering on whole window if window is not square - Multiple crashes eliminated - Sprites no longer lag behind player movement/rotation --- src/consts.h | 4 ++-- src/draw/drawutils.c | 4 ++-- src/main.c | 6 ++---- src/renderer/render.c | 6 +++--- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/consts.h b/src/consts.h index 2e87250..a15c03e 100644 --- a/src/consts.h +++ b/src/consts.h @@ -6,15 +6,15 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:54:36 by kcolin #+# #+# */ -/* Updated: 2025/08/07 13:45:34 by kcolin ### ########.fr */ +/* Updated: 2025/08/12 14:32:47 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef CONSTS_H # define CONSTS_H -# define HEIGHT 800 # define WIDTH 800 +# define HEIGHT 600 # define SIZE 64 # define MAP_SIZE 10 diff --git a/src/draw/drawutils.c b/src/draw/drawutils.c index 145cdc1..7948d9d 100644 --- a/src/draw/drawutils.c +++ b/src/draw/drawutils.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:28:56 by kcolin #+# #+# */ -/* Updated: 2025/08/06 14:02:08 by tchampio ### ########.fr */ +/* Updated: 2025/08/12 14:30:49 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,7 @@ void my_mlx_pixel_put(t_img_data *data, int x, int y, int color) { char *dst; - if (x < 0 || y < 0 || x >= HEIGHT || y >= WIDTH) + if (x < 0 || y < 0 || x >= WIDTH || y >= HEIGHT) return ; dst = data->addr + (y * data->line_length + x * (data->bits_per_pixel / 8)); *(unsigned int *)dst = color; diff --git a/src/main.c b/src/main.c index 07ee598..7c57d95 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */ -/* Updated: 2025/08/11 11:03:22 by tchampio ### ########.fr */ +/* Updated: 2025/08/12 14:23:27 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,11 +39,9 @@ int game_loop(t_cub3d_data *data) char *fps_string; data->last_tick = get_milliseconds(); - mlx_destroy_image(data->mlx, data->img_data->img); - data->img_data->img = mlx_new_image(data->mlx, WIDTH, HEIGHT); reset_matrix(data); - raycaster(data, &ray); move_player(data); + raycaster(data, &ray); sprite_caster(data); matrix_to_image(data); draw_map(data->map, &data->player, data->img_data); diff --git a/src/renderer/render.c b/src/renderer/render.c index e73c6b1..37e4011 100644 --- a/src/renderer/render.c +++ b/src/renderer/render.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/31 13:18:17 by kcolin #+# #+# */ -/* Updated: 2025/07/31 13:38:49 by kcolin ### ########.fr */ +/* Updated: 2025/08/12 14:31:04 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,12 +23,12 @@ void reset_matrix(t_cub3d_data *data) int matrix_get(t_cub3d_data *data, int x, int y) { - return (data->screen_matrix[y + x * WIDTH]); + return (data->screen_matrix[y + x * HEIGHT]); } void matrix_set(t_cub3d_data *data, int x, int y, int color) { - data->screen_matrix[y + x * WIDTH] = color; + data->screen_matrix[y + x * HEIGHT] = color; } void matrix_to_image(t_cub3d_data *data)