mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
feat: allocate screen_matrix on the heap
This commit is contained in:
parent
8d0a6d841b
commit
e625e254f7
7 changed files with 30 additions and 36 deletions
7
README
7
README
|
|
@ -16,13 +16,6 @@ M - boite magique
|
||||||
faire un systeme de "cheats" soit par un menu de debug soit par une ligne de
|
faire un systeme de "cheats" soit par un menu de debug soit par une ligne de
|
||||||
commande intégrée dans le jeu
|
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
|
--[ Correspondances des angles / points cardinaux
|
||||||
|
|
||||||
PI [ nord ]
|
PI [ nord ]
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 14:59:37 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_mapdata *map;
|
||||||
t_player player;
|
t_player player;
|
||||||
t_keypresses keypresses;
|
t_keypresses keypresses;
|
||||||
int screen_matrix[HEIGHT][WIDTH];
|
int *screen_matrix;
|
||||||
} t_cub3d_data;
|
} t_cub3d_data;
|
||||||
|
|
||||||
#endif // CUB3D_DATA_H
|
#endif // CUB3D_DATA_H
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 14:14:30 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"),
|
return (ft_printf("Error: Failed to initalize mlx\n"),
|
||||||
free_map(data.map), 1);
|
free_map(data.map), 1);
|
||||||
data.mlx_win = mlx_new_window(data.mlx, WIDTH, HEIGHT, "Cub3d");
|
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 = ft_calloc(sizeof(t_img_data), 1);
|
||||||
data.img_data->img = mlx_new_image(data.mlx, WIDTH, HEIGHT);
|
data.img_data->img = mlx_new_image(data.mlx, WIDTH, HEIGHT);
|
||||||
data.img_data->addr = mlx_get_data_addr(data.img_data->img,
|
data.img_data->addr = mlx_get_data_addr(data.img_data->img,
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,17 @@
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* render.c :+: :+: :+: */
|
/* render.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: freddy <freddy@student.42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/30 12:50:10 by tchampio #+# #+# */
|
/* Created: 2025/07/31 13:17:39 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/07/31 11:24:59 by tchampio ### ########.fr */
|
/* Updated: 2025/07/31 13:38:07 by kcolin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../cub3d_data.h"
|
#include "../cub3d_data.h"
|
||||||
#include "../consts.h"
|
#include "../consts.h"
|
||||||
#include "ray.h"
|
#include "ray.h"
|
||||||
|
#include "../renderer/render.h"
|
||||||
|
|
||||||
int get_cardinal(t_ray *ray)
|
int get_cardinal(t_ray *ray)
|
||||||
{
|
{
|
||||||
|
|
@ -76,7 +77,7 @@ void render_walls(t_cub3d_data *data, t_ray *ray, int x)
|
||||||
pos += step;
|
pos += step;
|
||||||
color = get_color(dir);
|
color = get_color(dir);
|
||||||
(void)pos;
|
(void)pos;
|
||||||
data->screen_matrix[ray->draw_start][x] = color;
|
matrix_set(data, x, ray->draw_start, color);
|
||||||
ray->draw_start++;
|
ray->draw_start++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* render.c :+: :+: :+: */
|
/* render.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/30 14:53:39 by tchampio #+# #+# */
|
/* Created: 2025/07/31 13:18:17 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/07/30 16:39:51 by tchampio ### ########.fr */
|
/* Updated: 2025/07/31 13:38:49 by kcolin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,20 +18,17 @@
|
||||||
|
|
||||||
void reset_matrix(t_cub3d_data *data)
|
void reset_matrix(t_cub3d_data *data)
|
||||||
{
|
{
|
||||||
int x;
|
ft_bzero(data->screen_matrix, sizeof(int) * WIDTH * HEIGHT);
|
||||||
int y;
|
}
|
||||||
|
|
||||||
y = 0;
|
int matrix_get(t_cub3d_data *data, int x, int y)
|
||||||
while (y < HEIGHT)
|
{
|
||||||
{
|
return (data->screen_matrix[y + x * WIDTH]);
|
||||||
x = 0;
|
}
|
||||||
while (x < WIDTH)
|
|
||||||
{
|
void matrix_set(t_cub3d_data *data, int x, int y, int color)
|
||||||
data->screen_matrix[y][x] = 0;
|
{
|
||||||
x++;
|
data->screen_matrix[y + x * WIDTH] = color;
|
||||||
}
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void matrix_to_image(t_cub3d_data *data)
|
void matrix_to_image(t_cub3d_data *data)
|
||||||
|
|
@ -45,9 +42,9 @@ void matrix_to_image(t_cub3d_data *data)
|
||||||
x = 0;
|
x = 0;
|
||||||
while (x < WIDTH)
|
while (x < WIDTH)
|
||||||
{
|
{
|
||||||
if (data->screen_matrix[y][x] > 0)
|
if (matrix_get(data, x, y) > 0)
|
||||||
my_mlx_pixel_put(data->img_data,
|
my_mlx_pixel_put(data->img_data,
|
||||||
x, y, data->screen_matrix[y][x]);
|
x, y, matrix_get(data, x, y));
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
y++;
|
y++;
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* render.h :+: :+: :+: */
|
/* render.h :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/30 14:52:12 by tchampio #+# #+# */
|
/* Created: 2025/07/31 13:36:36 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/07/30 16:20:57 by tchampio ### ########.fr */
|
/* Updated: 2025/07/31 13:36:43 by kcolin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,5 +17,6 @@
|
||||||
|
|
||||||
void reset_matrix(t_cub3d_data *data);
|
void reset_matrix(t_cub3d_data *data);
|
||||||
void matrix_to_image(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
|
#endif // RENDER_H
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 13:59:27 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)
|
if (data->mlx)
|
||||||
mlx_destroy_display(data->mlx);
|
mlx_destroy_display(data->mlx);
|
||||||
free(data->mlx);
|
free(data->mlx);
|
||||||
|
free(data->screen_matrix);
|
||||||
exit(0);
|
exit(0);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue