feat: use t_img_data to store textures insted of void ptr

This allows for easier writing of future functions, see next pr comming soon
This commit is contained in:
Khaïs COLIN 2025-08-05 13:08:47 +02:00
parent 121db8bd3c
commit c09ba88d90
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
3 changed files with 25 additions and 15 deletions

View file

@ -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/31 14:17:28 by kcolin ### ########.fr */ /* Updated: 2025/08/05 13:09:22 by kcolin ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,10 +23,10 @@ typedef struct s_cub3d_data
{ {
void *mlx; void *mlx;
void *mlx_win; void *mlx_win;
void *no_texture; t_img_data *no_texture;
void *so_texture; t_img_data *so_texture;
void *we_texture; t_img_data *we_texture;
void *ea_texture; t_img_data *ea_texture;
t_img_data *img_data; t_img_data *img_data;
t_mapdata *map; t_mapdata *map;
t_player player; t_player player;

View file

@ -67,13 +67,17 @@ int destroy(t_cub3d_data *data)
mlx_destroy_image(data->mlx, data->img_data->img); mlx_destroy_image(data->mlx, data->img_data->img);
free(data->img_data); free(data->img_data);
if (data->no_texture) if (data->no_texture)
mlx_destroy_image(data->mlx, data->no_texture); mlx_destroy_image(data->mlx, data->no_texture->img);
free(data->no_texture);
if (data->so_texture) if (data->so_texture)
mlx_destroy_image(data->mlx, data->so_texture); mlx_destroy_image(data->mlx, data->so_texture->img);
free(data->so_texture);
if (data->ea_texture) if (data->ea_texture)
mlx_destroy_image(data->mlx, data->ea_texture); mlx_destroy_image(data->mlx, data->ea_texture->img);
free(data->ea_texture);
if (data->we_texture) if (data->we_texture)
mlx_destroy_image(data->mlx, data->we_texture); mlx_destroy_image(data->mlx, data->we_texture->img);
free(data->we_texture);
if (data->mlx) if (data->mlx)
mlx_destroy_display(data->mlx); mlx_destroy_display(data->mlx);
free(data->mlx); free(data->mlx);

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/31 13:43:05 by kcolin #+# #+# */ /* Created: 2025/07/31 13:43:05 by kcolin #+# #+# */
/* Updated: 2025/07/31 14:27:12 by kcolin ### ########.fr */ /* Updated: 2025/08/05 13:19:40 by kcolin ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,11 +17,12 @@
#include "../map/map_checker.h" #include "../map/map_checker.h"
#include "frees.h" #include "frees.h"
void *load_single_texture(t_cub3d_data *data, char *path) t_img_data *load_single_texture(t_cub3d_data *data, char *path)
{ {
int width; int width;
int height; int height;
void *img; void *img;
t_img_data *img_data;
img = mlx_xpm_file_to_image(data->mlx, path, &width, &height); img = mlx_xpm_file_to_image(data->mlx, path, &width, &height);
if (img == NULL) if (img == NULL)
@ -35,7 +36,12 @@ void *load_single_texture(t_cub3d_data *data, char *path)
destroy(data); destroy(data);
} }
ft_printf("image: %p\n", img); ft_printf("image: %p\n", img);
return (img); img_data = ft_calloc(sizeof(t_img_data), 1);
img_data->img = img;
img_data->addr = mlx_get_data_addr(img_data->img,
&img_data->bits_per_pixel, &img_data->line_length,
&img_data->endian);
return (img_data);
} }
void load_textures(t_cub3d_data *data) void load_textures(t_cub3d_data *data)