aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--inc/cub3d.h148
-rw-r--r--inc/cub3d_structs.h20
-rw-r--r--src/ft_draw_scene.c5
-rw-r--r--src/ft_init_bmp.c46
-rw-r--r--src/ft_save_to_bmp.c9
5 files changed, 115 insertions, 113 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 2fefabe..8643c5c 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -22,110 +22,112 @@
** ====== STRUCTS ======
*/
-void ft_init_funptr(t_cub *clist);
-int8_t ft_init_cub3d(t_cub *clist);
-int ft_init_winlx(t_cub *clist);
-int ft_init_winptr(t_cub *clist);
-t_ray ft_init_s_ray(void);
-t_rgb ft_init_rgb(void);
-int8_t ft_init_map(t_map *mlist);
-void ft_init_bmp(t_bmp_file *bmp_file);
+void ft_init_funptr(t_cub *clist);
+int8_t ft_init_cub3d(t_cub *clist);
+int ft_init_winlx(t_cub *clist);
+int ft_init_winptr(t_cub *clist);
+t_ray ft_init_s_ray(void);
+t_rgb ft_init_rgb(void);
+int8_t ft_init_map(t_map *mlist);
+t_bmp_file ft_init_bmp(void);
+t_bmp_info ft_init_bmp_info(void);
+t_bmp_colors ft_init_bmp_colors(void)
/*
** ====== HOOKS ======
*/
-void ft_hooks_and_loops(t_win *wl, t_cub *cl);
-int ft_key_event(int keycode, t_cub *clist);
-int ft_key_release(int keycode, t_cub *clist);
-int ft_w_key(t_cub *clist);
-int ft_a_key(t_cub *clist);
-int ft_s_key(t_cub *clist);
-int ft_d_key(t_cub *clist);
-int ft_f1_key(t_cub *clist);
-int ft_left_key(t_cub *clist);
-int ft_right_key(t_cub *clist);
-int ft_click_close(int keycode, t_cub *clist);
-int ft_key_loop(t_cub *cl);
-int32_t ft_convert_keycode(const int32_t tmp_code);
+void ft_hooks_and_loops(t_win *wl, t_cub *cl);
+int ft_key_event(int keycode, t_cub *clist);
+int ft_key_release(int keycode, t_cub *clist);
+int ft_w_key(t_cub *clist);
+int ft_a_key(t_cub *clist);
+int ft_s_key(t_cub *clist);
+int ft_d_key(t_cub *clist);
+int ft_f1_key(t_cub *clist);
+int ft_left_key(t_cub *clist);
+int ft_right_key(t_cub *clist);
+int ft_click_close(int keycode, t_cub *clist);
+int ft_key_loop(t_cub *cl);
+int32_t ft_convert_keycode(const int32_t tmp_code);
/*
** ====== TEXTURES ======
*/
-void ft_wall_tex_init(t_cub *clist);
-void ft_choose_tex(t_cub *clist);
-void ft_calc_tex(t_cub *clist);
+void ft_wall_tex_init(t_cub *clist);
+void ft_choose_tex(t_cub *clist);
+void ft_calc_tex(t_cub *clist);
/*
** ====== DRAW ======
*/
-void ft_draw_square(int a, int b, int rgb, t_cub *clist);
-void ft_draw_map(char **map, t_cub *clist);
-void ft_draw_texture(t_cub *cl, int x, int y, int tex_y);
-void ft_draw_hud(t_cub *clist);
-void ft_draw_scene(t_cub *clist);
-void ft_draw_scene_bmp(t_cub *clist);
-void ft_draw_sprite(t_cub *cl, int i);
-void ft_draw_circle(float a, float b,
+void ft_draw_square(int a, int b, int rgb, t_cub *clist);
+void ft_draw_map(char **map, t_cub *clist);
+void ft_draw_texture(t_cub *cl, int x, int y, int tex_y);
+void ft_draw_hud(t_cub *clist);
+void ft_draw_scene(t_cub *clist);
+void ft_draw_scene_bmp(t_cub *clist);
+void ft_draw_sprite(t_cub *cl, int i);
+void ft_draw_circle(float a, float b,
int32_t color, t_cub *cl);
-int8_t ft_draw_verline(t_cub *cl, int32_t x,
+int8_t ft_draw_verline(t_cub *cl, int32_t x,
int32_t y1, int32_t y2);
/*
** ====== PARSING ======
*/
-void ft_parse_map(const char *map_path, t_cub *clist);
-void ft_get_player_spawn(t_player *plist, t_cub *clist);
-void ft_get_nlvl_pos(t_map *ml);
-int8_t ft_select_get(char **words, t_cub *clist);
-int8_t ft_get_screen_size(t_win *wlist);
-int8_t ft_get_res(char **words, t_cub *clist);
-int8_t ft_get_tex_no(char **words, t_cub *clist);
-int8_t ft_get_tex_so(char **words, t_cub *clist);
-int8_t ft_get_tex_ea(char **words, t_cub *clist);
-int8_t ft_get_tex_we(char **words, t_cub *clist);
-int8_t ft_get_sprite(char **words, t_cub *clist);
-int8_t ft_get_f_color(char **words, t_cub *clist);
-int8_t ft_get_c_color(char **words, t_cub *clist);
-int8_t ft_get_path_nl(char **words, t_cub *clist);
-int8_t ft_get_tex_nl(char **words, t_cub *clist);
-int8_t ft_get_music(char **words, t_cub *clist);
-size_t ft_get_map_h(char **map);
-size_t ft_get_map_w(char **map);
-int8_t ft_check_map_line(char *line, uint8_t l, t_cub *clist);
-int8_t ft_check_ext(const char *filep, const char *ext);
-int8_t ft_check_not_found(const char *path);
-int ft_get_map_first_line(char *line, t_cub *clist);
-int ft_get_map_core(int fd, t_cub *clist);
-void ft_check_map_surrounds(t_map *ml, t_cub *cl);
-int ft_check_missing(t_cub *clist);
-int ft_missing_error(const char *err, t_cub *clist);
-int ft_map_error(const char *errmsg, t_cub *clist);
-size_t ft_get_line_len(char *line);
+void ft_parse_map(const char *map_path, t_cub *clist);
+void ft_get_player_spawn(t_player *plist, t_cub *clist);
+void ft_get_nlvl_pos(t_map *ml);
+int8_t ft_select_get(char **words, t_cub *clist);
+int8_t ft_get_screen_size(t_win *wlist);
+int8_t ft_get_res(char **words, t_cub *clist);
+int8_t ft_get_tex_no(char **words, t_cub *clist);
+int8_t ft_get_tex_so(char **words, t_cub *clist);
+int8_t ft_get_tex_ea(char **words, t_cub *clist);
+int8_t ft_get_tex_we(char **words, t_cub *clist);
+int8_t ft_get_sprite(char **words, t_cub *clist);
+int8_t ft_get_f_color(char **words, t_cub *clist);
+int8_t ft_get_c_color(char **words, t_cub *clist);
+int8_t ft_get_path_nl(char **words, t_cub *clist);
+int8_t ft_get_tex_nl(char **words, t_cub *clist);
+int8_t ft_get_music(char **words, t_cub *clist);
+size_t ft_get_map_h(char **map);
+size_t ft_get_map_w(char **map);
+int8_t ft_check_map_line(char *line, uint8_t l, t_cub *clist);
+int8_t ft_check_ext(const char *filep, const char *ext);
+int8_t ft_check_not_found(const char *path);
+int ft_get_map_first_line(char *line, t_cub *clist);
+int ft_get_map_core(int fd, t_cub *clist);
+void ft_check_map_surrounds(t_map *ml, t_cub *cl);
+int ft_check_missing(t_cub *clist);
+int ft_missing_error(const char *err, t_cub *clist);
+int ft_map_error(const char *errmsg, t_cub *clist);
+size_t ft_get_line_len(char *line);
/*
** ====== ARGS ======
*/
-uint8_t ft_check_map_arg(int argc, const char *argv[]);
-uint8_t ft_use_args(int argc, const char *argv[], t_cub *clist);
+uint8_t ft_check_map_arg(int argc, const char *argv[]);
+uint8_t ft_use_args(int argc, const char *argv[], t_cub *clist);
/*
** ====== OTHER ======
*/
-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);
-int8_t ft_save_to_bmp(t_bmp_file *bmp_file, void *img, t_cub *cl);
-int ft_error(uint8_t retval, 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);
-uint32_t ft_rgb_to_hex(t_rgb rgb);
+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);
+int8_t ft_save_to_bmp(t_bmp_file *bmp_file, void *img, t_cub *cl);
+int ft_error(uint8_t retval, 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);
+uint32_t ft_rgb_to_hex(t_rgb rgb);
# endif
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index af39fdd..1eb6f08 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -30,6 +30,15 @@ typedef struct s_win
# pragma pack(push, 1)
+typedef struct s_bmp_file
+{
+ uint16_t file_type;
+ uint32_t file_size;
+ uint16_t reserv_one;
+ uint16_t reserv_two;
+ uint32_t offset_data;
+} t_bmp_file;
+
typedef struct s_bmp_info
{
uint32_t size;
@@ -55,17 +64,6 @@ typedef struct s_bmp_colors
uint32_t unused[16];
} t_bmp_colors;
-typedef struct s_bmp_file
-{
- uint16_t file_type;
- uint32_t file_size;
- uint16_t reserv_one;
- uint16_t reserv_two;
- uint32_t offset_data;
- struct s_bmp_info bmp_info;
- struct s_bmp_colors bmp_colors;
-} t_bmp_file;
-
# pragma pack(pop)
typedef struct s_img
diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c
index 846c2fb..cbe002f 100644
--- a/src/ft_draw_scene.c
+++ b/src/ft_draw_scene.c
@@ -33,15 +33,12 @@ void
void
ft_draw_scene_bmp(t_cub *clist)
{
- t_bmp_file bmp_file;
-
clist->img.img = mlx_new_image(clist->wlist.wlx,
clist->wlist.x_size, clist->wlist.y_size);
clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp,
&clist->img.sizeline, &clist->img.endian);
ft_castray(clist);
- ft_init_bmp(&bmp_file);
- if (ft_save_to_bmp(&bmp_file, clist->img.img, clist) < 0)
+ if (ft_save_to_bmp(clist->img.img, clist) < 0)
ft_error(FT_RET_BMP_ERR, FT_ERR_WR_BMP, clist);
mlx_destroy_image(clist->wlist.wlx, clist->img.img);
}
diff --git a/src/ft_init_bmp.c b/src/ft_init_bmp.c
index b123e52..e3fab01 100644
--- a/src/ft_init_bmp.c
+++ b/src/ft_init_bmp.c
@@ -14,8 +14,8 @@
#include <cub3d.h>
#include <stdint.h>
-static void
- ft_init_bmp_colors(t_bmp_colors *bmp_colors)
+t_bmp_colors
+ ft_init_bmp_colors(void)
{
bmp_colors->red_mask = 0x00ff0000;
bmp_colors->green_mask = 0x0000ff00;
@@ -25,30 +25,28 @@ static void
ft_bzero(bmp_colors, 16);
}
-static void
- ft_init_bmp_info(t_bmp_info *bmp_info)
+t_bmp_info
+ ft_init_bmp_info(void)
{
- bmp_info->size = 0;
- bmp_info->width = 0;
- bmp_info->height = 0;
- bmp_info->planes = 1;
- bmp_info->bit_count = 0;
- bmp_info->compression = 0;
- bmp_info->size_image = 0;
- bmp_info->x_pixels_per_meter = 0;
- bmp_info->y_pixels_per_meter = 0;
- bmp_info->colors_used = 0;
- bmp_info->colors_important = 0;
+ bmp_info.size = 0;
+ bmp_info.width = 0;
+ bmp_info.height = 0;
+ bmp_info.planes = 1;
+ bmp_info.bit_count = 0;
+ bmp_info.compression = 0;
+ bmp_info.size_image = 0;
+ bmp_info.x_pixels_per_meter = 0;
+ bmp_info.y_pixels_per_meter = 0;
+ bmp_info.colors_used = 0;
+ bmp_info.colors_important = 0;
}
-void
- ft_init_bmp(t_bmp_file *bmp_file)
+t_bmp_file
+ ft_init_bmp(void)
{
- bmp_file->file_type = 0x4d42;
- bmp_file->file_size = 0;
- bmp_file->reserv_one = 0;
- bmp_file->reserv_two = 0;
- bmp_file->offset_data = 0;
- ft_init_bmp_info(&bmp_file->bmp_info);
- ft_init_bmp_colors(&bmp_file->bmp_colors);
+ bmp_file.file_type = 0x4d42;
+ bmp_file.file_size = 0;
+ bmp_file.reserv_one = 0;
+ bmp_file.reserv_two = 0;
+ bmp_file.offset_data = 0;
}
diff --git a/src/ft_save_to_bmp.c b/src/ft_save_to_bmp.c
index 4bfaace..cb3fa9b 100644
--- a/src/ft_save_to_bmp.c
+++ b/src/ft_save_to_bmp.c
@@ -31,8 +31,15 @@ static int8_t
}
int8_t
- ft_save_to_bmp(t_bmp_file *bmp_file, void *img, t_cub *cl)
+ ft_save_to_bmp(void *img, t_cub *cl)
{
+ t_bmp_file bmp_file;
+ t_bmp_info bmp_info;
+ t_bmp_colors bmp_colors;
+
+ bmp_file = ft_init_bmp();
+ bmp_info = ft_init_bmp_info();
+ bmp_colors = ft_init_bmp_colors();
if (ft_convert_image_to_bmp(bmp_file, img, cl) < 0)
return (-1);
return (0);