From 5db7c4f7d445373d92c41a7cc9aa667e223e5507 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 4 Mar 2020 15:21:10 +0100 Subject: tryna save --- Makefile | 2 +- inc/cub3d.h | 3 ++- inc/cub3d_defines.h | 6 ++++-- src/ft_draw_scene.c | 3 ++- src/ft_error.c | 36 ++++++++++++++++++++++++++++++++++++ src/ft_map_error.c | 26 -------------------------- src/ft_save_to_bmp.c | 23 +++++++++++++++++++++-- 7 files changed, 66 insertions(+), 33 deletions(-) create mode 100644 src/ft_error.c delete mode 100644 src/ft_map_error.c diff --git a/Makefile b/Makefile index a5e5f72..17c7809 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ SRCS_NAME += ft_check_not_found.c SRCS_NAME += ft_check_map_line.c SRCS_NAME += ft_check_map_surrounds.c SRCS_NAME += ft_free_words.c -SRCS_NAME += ft_map_error.c +SRCS_NAME += ft_error.c SRCS_NAME += ft_init_winlx.c SRCS_NAME += ft_draw_square.c SRCS_NAME += ft_draw_circle.c diff --git a/inc/cub3d.h b/inc/cub3d.h index e640a14..b1712c1 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -120,7 +120,8 @@ void ft_set_minimap_scale(t_cub *clist); void *ft_music_thread(void *vargp); void ft_detect(t_cub *cl); void ft_castray(t_cub *cl); -void ft_save_to_bmp(void); +int8_t ft_save_to_bmp(void *img, t_cub *cl); +int ft_error(const char *errmsg, t_cub *clist); uint8_t ft_free_words(char **words); int8_t ft_warp_level(t_cub *cl); int ft_exit(uint8_t exit_code, t_cub *clist); diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h index 66303ab..ed57f3e 100644 --- a/inc/cub3d_defines.h +++ b/inc/cub3d_defines.h @@ -22,9 +22,10 @@ enum FT_RET_BAD_ARGV, FT_RET_FAILED_STRUCTS, FT_RET_FAILED_MLX, - FT_RET_MAP_ERROR, + FT_RET_MAP_ERR, FT_RET_NO_MAP, - FT_RET_READ_ERROR + FT_RET_READ_ERR, + FT_RET_BMP_ERR } retvals; /* @@ -140,6 +141,7 @@ enum # define FT_ERR_RD_NL_TEX "could not find next level texture file" # define FT_ERR_RD_NL_MAP "could not find next level map file" # define FT_ERR_RD_MUSIC "could not find music file" +# define FT_ERR_WR_BMP "could not export to bmp" /* ** ====== MISSING ERROR MSG ====== diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c index 1e16ba5..78a56b4 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -38,6 +38,7 @@ void clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp, &clist->img.sizeline, &clist->img.endian); ft_castray(clist); - ft_save_to_bmp(); + if (ft_save_to_bmp(clist->img.img, clist) < 0) + ft_error(FT_ERR_WR_BMP, clist); mlx_destroy_image(clist->wlist.wlx, clist->img.img); } diff --git a/src/ft_error.c b/src/ft_error.c new file mode 100644 index 0000000..b793b96 --- /dev/null +++ b/src/ft_error.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_error.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:28:55 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:28:55 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include + +int + ft_error(const char *errmsg, t_cub *clist) +{ + ft_dprintf(STDERR_FILENO, "Error\n"); + ft_dprintf(STDERR_FILENO, + "\033[1;31m%s\033[0m\n", + errmsg); + return (ft_exit(FT_RET_BMP_ERR, clist)); +} + +int + ft_map_error(const char *errmsg, t_cub *clist) +{ + ft_dprintf(STDERR_FILENO, "Error\n"); + ft_dprintf(STDERR_FILENO, + "\033[1;31mMap error: line %lu: %s\033[0m\n", + clist->mlist.line_chk, + errmsg); + return (ft_exit(FT_RET_MAP_ERR, clist)); +} diff --git a/src/ft_map_error.c b/src/ft_map_error.c deleted file mode 100644 index b777415..0000000 --- a/src/ft_map_error.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_map_error.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rbousset +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/02/14 17:28:55 by rbousset #+# #+# */ -/* Updated: 2020/02/14 17:28:55 by rbousset ### ########lyon.fr */ -/* */ -/* ************************************************************************** */ - -#include -#include -#include - -int - ft_map_error(const char *errmsg, t_cub *clist) -{ - ft_dprintf(STDERR_FILENO, "Error\n"); - ft_dprintf(STDERR_FILENO, - "\033[1;31mMap error: line %lu: %s\033[0m\n", - clist->mlist.line_chk, - errmsg); - return (ft_exit(4, clist)); -} diff --git a/src/ft_save_to_bmp.c b/src/ft_save_to_bmp.c index a510d6b..1118384 100644 --- a/src/ft_save_to_bmp.c +++ b/src/ft_save_to_bmp.c @@ -12,8 +12,27 @@ #include #include +#include +#include -void - ft_save_to_bmp(void) +static int8_t + ft_convert_image_to_bmp(void *img, t_cub *cl) { + int32_t filelen; + uint8_t *bmp; + + (void)img; + filelen = 54 + 3 * cl->wlist.x_size * cl->wlist.y_size; + if (!(bmp = (uint8_t*)malloc((filelen - 54) * sizeof(uint8_t)))) + return (-1); + ft_memdel((void**)&bmp) + return (0); +} + +int8_t + ft_save_to_bmp(void *img, t_cub *cl) +{ + if (ft_convert_image_to_bmp(img, cl) < 0) + return (-1); + return (0); } -- cgit v1.2.3