diff --git a/README b/README index cf1452f..b0130e2 100644 --- a/README +++ b/README @@ -16,13 +16,6 @@ M - boite magique faire un systeme de "cheats" soit par un menu de debug soit par une ligne de commande intégrée dans le jeu ---[ Attention pour Valgrind - -Valgrind doit avoir une taille de stack assez grande pour éviter les invalid -read ou write. C'est du a la matrice de pixel qui est immense et donc il -n'arrive pas à bien s'en occuper (il part du principe qu'on change de stack) -car sa stack "par défaut" est plus petite. - --[ Correspondances des angles / points cardinaux PI [ nord ] diff --git a/src/cub3d_data.h b/src/cub3d_data.h index 708943f..83c6678 100644 --- a/src/cub3d_data.h +++ b/src/cub3d_data.h @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:59:37 by kcolin #+# #+# */ -/* Updated: 2025/07/30 16:07:36 by tchampio ### ########.fr */ +/* Updated: 2025/07/31 13:23:32 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,7 @@ typedef struct s_cub3d_data t_mapdata *map; t_player player; t_keypresses keypresses; - int screen_matrix[HEIGHT][WIDTH]; + int *screen_matrix; } t_cub3d_data; #endif // CUB3D_DATA_H diff --git a/src/main.c b/src/main.c index 1cb332c..fb16572 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/07/31 11:28:04 by tchampio ### ########.fr */ +/* Updated: 2025/07/31 13:25:36 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,6 +64,7 @@ int main(int argc, char **argv) return (ft_printf("Error: Failed to initalize mlx\n"), free_map(data.map), 1); data.mlx_win = mlx_new_window(data.mlx, WIDTH, HEIGHT, "Cub3d"); + data.screen_matrix = ft_calloc(sizeof(int), WIDTH * HEIGHT); data.img_data = ft_calloc(sizeof(t_img_data), 1); data.img_data->img = mlx_new_image(data.mlx, WIDTH, HEIGHT); data.img_data->addr = mlx_get_data_addr(data.img_data->img, diff --git a/src/raycast/render.c b/src/raycast/render.c index a1a83c8..52b2221 100644 --- a/src/raycast/render.c +++ b/src/raycast/render.c @@ -3,16 +3,17 @@ /* ::: :::::::: */ /* render.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: freddy +#+ +:+ +#+ */ +/* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/07/30 12:50:10 by tchampio #+# #+# */ -/* Updated: 2025/07/31 11:24:59 by tchampio ### ########.fr */ +/* Created: 2025/07/31 13:17:39 by kcolin #+# #+# */ +/* Updated: 2025/07/31 13:38:07 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ #include "../cub3d_data.h" #include "../consts.h" #include "ray.h" +#include "../renderer/render.h" int get_cardinal(t_ray *ray) { @@ -76,7 +77,7 @@ void render_walls(t_cub3d_data *data, t_ray *ray, int x) pos += step; color = get_color(dir); (void)pos; - data->screen_matrix[ray->draw_start][x] = color; + matrix_set(data, x, ray->draw_start, color); ray->draw_start++; } } diff --git a/src/renderer/render.c b/src/renderer/render.c index 2b3b399..e73c6b1 100644 --- a/src/renderer/render.c +++ b/src/renderer/render.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* render.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: tchampio +#+ +:+ +#+ */ +/* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/07/30 14:53:39 by tchampio #+# #+# */ -/* Updated: 2025/07/30 16:39:51 by tchampio ### ########.fr */ +/* Created: 2025/07/31 13:18:17 by kcolin #+# #+# */ +/* Updated: 2025/07/31 13:38:49 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,20 +18,17 @@ void reset_matrix(t_cub3d_data *data) { - int x; - int y; + ft_bzero(data->screen_matrix, sizeof(int) * WIDTH * HEIGHT); +} - y = 0; - while (y < HEIGHT) - { - x = 0; - while (x < WIDTH) - { - data->screen_matrix[y][x] = 0; - x++; - } - y++; - } +int matrix_get(t_cub3d_data *data, int x, int y) +{ + return (data->screen_matrix[y + x * WIDTH]); +} + +void matrix_set(t_cub3d_data *data, int x, int y, int color) +{ + data->screen_matrix[y + x * WIDTH] = color; } void matrix_to_image(t_cub3d_data *data) @@ -45,9 +42,9 @@ void matrix_to_image(t_cub3d_data *data) x = 0; while (x < WIDTH) { - if (data->screen_matrix[y][x] > 0) + if (matrix_get(data, x, y) > 0) my_mlx_pixel_put(data->img_data, - x, y, data->screen_matrix[y][x]); + x, y, matrix_get(data, x, y)); x++; } y++; diff --git a/src/renderer/render.h b/src/renderer/render.h index 4471629..b9d8f48 100644 --- a/src/renderer/render.h +++ b/src/renderer/render.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* render.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: tchampio +#+ +:+ +#+ */ +/* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/07/30 14:52:12 by tchampio #+# #+# */ -/* Updated: 2025/07/30 16:20:57 by tchampio ### ########.fr */ +/* Created: 2025/07/31 13:36:36 by kcolin #+# #+# */ +/* Updated: 2025/07/31 13:36:43 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,5 +17,6 @@ void reset_matrix(t_cub3d_data *data); void matrix_to_image(t_cub3d_data *data); +void matrix_set(t_cub3d_data *data, int x, int y, int color); #endif // RENDER_H diff --git a/src/utils/frees.c b/src/utils/frees.c index abe3d0d..233884b 100644 --- a/src/utils/frees.c +++ b/src/utils/frees.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 13:59:27 by kcolin #+# #+# */ -/* Updated: 2025/07/23 12:18:08 by tchampio ### ########.fr */ +/* Updated: 2025/07/31 13:26:06 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -69,6 +69,7 @@ int destroy(t_cub3d_data *data) if (data->mlx) mlx_destroy_display(data->mlx); free(data->mlx); + free(data->screen_matrix); exit(0); return (0); }