cub3d/src/utils/inits.c

39 lines
1.8 KiB
C
Raw Normal View History

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* inits.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/31 13:26:53 by tchampio #+# #+# */
/* Updated: 2025/07/31 13:28:03 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#include "../cub3d_data.h"
#include "../../libft/includes/libft.h"
#include "../../mlx/mlx.h"
#include "../map/map_checker.h"
#include "frees.h"
void init_cub3d_data(t_cub3d_data *data, char **argv)
{
ft_bzero(data, sizeof(*data));
data->map = ft_calloc(sizeof(t_mapdata), 1);
if (!check_cubfile(argv[1], data->map))
return (ft_printf("Error: Wrong map file. Reason: %s\n",
data->map->error), free_map(data->map), exit(1));
data->mlx = mlx_init();
if (data->mlx == NULL)
return (ft_printf("Error: Failed to initalize mlx\n"),
free_map(data->map), exit(1));
data->mlx_win = mlx_new_window(data->mlx, WIDTH, HEIGHT, "Cub3d");
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,
&data->img_data->bits_per_pixel, &data->img_data->line_length,
&data->img_data->endian);
init_player(&data->player, data->map);
}