diff options
Diffstat (limited to 'inc')
-rw-r--r-- | inc/cub3d.h | 189 | ||||
-rw-r--r-- | inc/cub3d_defines.h | 186 | ||||
-rw-r--r-- | inc/cub3d_structs.h | 269 |
3 files changed, 422 insertions, 222 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h index 310e00d..615112b 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -19,80 +19,129 @@ #include <stdint.h> /* -** ret vals: -** 1: no argv[1] -** 2: failed structs init -** 3: failed mlx init -** 4: map error -** 5: no map -** 6: read error +** ====== STRUCTS ====== */ -int8_t ft_init_cub3d(t_cub **clist); -t_map *ft_init_map(void); -void ft_wall_tex_init(t_cub *clist); -void ft_choose_tex(t_cub *clist); -void ft_hooks_and_loops(t_win *wl, t_cub *cl); -int ft_key_event(int keycode, t_cub *clist); -int ft_click_close(int keycode, t_cub *clist); -int ft_exit(uint8_t exit_code, t_cub *clist); -void ft_draw_square(int a, int b, int rgb, t_cub *clist); -void ft_parse_map(const char *map_path, t_cub *clist); -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); -int ft_get_map_first_line(char *line, t_cub *clist); -int ft_get_map_core(int fd, t_cub *clist); -void ft_get_player_spawn(t_player *plist, t_cub *clist); -void ft_set_minimap_scale(t_cub *clist); -int ft_check_missing(t_cub *clist); -int8_t ft_check_map_line(char *line, uint8_t l, t_cub *clist); -size_t ft_get_line_len(char *line); -int ft_missing_error(const char *err, t_cub *clist); -uint8_t ft_free_words(char **words); -int ft_map_error(const char *errmsg, t_cub *clist); -int ft_init_winlx(t_cub *clist); -void ft_draw_scene(t_cub *clist); -void ft_print_list(t_cub *clist); -uint32_t ft_rgb_to_hex(t_rgb rgb); -t_ray ft_init_s_ray(void); -void ft_detect(t_cub *cl); -int8_t ft_draw_verline(t_cub *cl, int32_t x, - int32_t y1, int32_t y2); -void ft_castray(t_cub *cl); -void ft_draw_map(char **map, 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_key_release(int keycode, t_cub *clist); -int8_t ft_check_ext(const char *filep, const char *ext); -int32_t ft_convert_keycode(const int32_t tmp_code); -int ft_key_loop(t_cub *cl); -void ft_draw_circle(float a, float b, - int32_t color, t_cub *cl); -void ft_draw_texture(t_cub *cl, int x, int y, int tex_y); -int8_t ft_check_not_found(const char *path); -void ft_calc_tex(t_cub *clist); -void ft_draw_hud(t_cub *clist); -void ft_draw_life_bar(size_t map_w, - const uint16_t scale, - const int8_t life, - t_cub *cl); -void ft_music(t_cub *cl); +void ft_init_funptr(t_cub *clist); +void ft_init_ref(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); + +/* +** ====== 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); + +/* +** ====== TEXTURES ====== +*/ + +void ft_wall_tex_init(t_cub *clist); +void ft_choose_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); +int8_t ft_draw_hud(t_cub *clist); +void ft_draw_scene(t_cub *clist); +void ft_draw_scene_bmp(t_cub *clist); +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, + int32_t y1, int32_t y2); void ft_calc_sprite(t_cub *cl); -void ft_calc_sprite_norme(t_cub *cl); void ft_draw_sprite(t_cub *cl, t_sprite *sprite); void ft_get_sprite_spawn(t_cub *cl); +/* +** ====== 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_f_tex(char **words, t_cub *clist); +int8_t ft_get_c_color(char **words, t_cub *clist); +int8_t ft_get_c_tex(char **words, t_cub *clist); +int8_t ft_get_darkness(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[], + char *const envp[], t_cub *clist); + +/* +** ====== RAYCAST ====== +*/ + +void ft_castray(t_cub *cl); +void ft_detect(t_cub *cl); +void ft_floor_cast(uint16_t y, t_cub *cl); + +/* +** ====== OTHER ====== +*/ + +void ft_set_minimap_scale(t_cub *clist); +void ft_enable_music(t_cub *cl); +void ft_music_fork(char **mcmd_words, char *const envp[]); +int8_t ft_save_to_bmp(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); +t_bmp_rgb ft_hex_to_rgb(uint32_t color); +uint32_t ft_darken(t_rgb rgb, t_cub *cl); + # endif diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h index e201228..b3dd986 100644 --- a/inc/cub3d_defines.h +++ b/inc/cub3d_defines.h @@ -14,44 +14,93 @@ # define CUB3D_DEFINES_H /* -** ====== KEYS ====== +** ====== RETURN VALUES ====== */ +enum +{ + FT_RET_FINE, + FT_RET_BAD_ARGV, + FT_RET_ALLOC_ERR, + FT_RET_FAILED_STRUCTS, + FT_RET_FAILED_MLX, + FT_RET_MAP_ERR, + FT_RET_NO_MAP, + FT_RET_READ_ERR, + FT_RET_BMP_ERR +} retvals; -# ifndef FT_W_KEY -# define FT_W_KEY 13 -# endif -# ifndef FT_A_KEY -# define FT_A_KEY 0 -# endif -# ifndef FT_S_KEY -# define FT_S_KEY 1 -# endif -# ifndef FT_D_KEY -# define FT_D_KEY 2 -# endif -# ifndef FT_L_ARR_KEY -# define FT_L_ARR_KEY 123 -# endif -# ifndef FT_R_ARR_KEY -# define FT_R_ARR_KEY 124 -# endif -# ifndef FT_ESC_KEY -# define FT_ESC_KEY 53 +/* +** ret vals: +** 1: no argv[1] +** 2: failed structs init +** 3: failed mlx init +** 4: map error +** 5: no map +** 6: read error +*/ + +/* +** ====== OS ====== +*/ + +/* +** 1: Darwin +** 2: Linux +*/ + +# ifndef FT_OS +# define FT_OS 1 # endif -# ifndef FT_F1_KEY -# define FT_F1_KEY 122 + +/* +** ====== KEYS ====== +*/ + +# if FT_OS == 1 +# define FT_W_KEY 13 +# define FT_A_KEY 0 +# define FT_S_KEY 1 +# define FT_D_KEY 2 +# define FT_L_ARR_KEY 123 +# define FT_R_ARR_KEY 124 +# define FT_F1_KEY 122 +# define FT_TAB_KEY 48 +# define FT_ESC_KEY 53 +# else +# define FT_W_KEY 119 +# define FT_A_KEY 97 +# define FT_S_KEY 115 +# define FT_D_KEY 100 +# define FT_L_ARR_KEY 65361 +# define FT_R_ARR_KEY 65363 +# define FT_TAB_KEY 65289 +# define FT_F1_KEY 65470 +# define FT_ESC_KEY 65307 # endif -# ifndef FT_TAB_KEY -# define FT_TAB_KEY 48 + +/* +** ====== MUSIC CMD ====== +*/ + +# if FT_OS == 1 +# define FT_MUS_CMD "/usr/bin/afplay --volume 0.2 %s" +# else +# define FT_MUS_CMD "/usr/bin/aplay -f cd -t wav -q %s" # endif /* ** ====== MOVE SPEED ====== */ -# define FT_MOVE_SPEED 0.1 -# define FT_STRAFE_SPEED 0.1 -# define FT_ROT_SPEED 0.09 +# define FT_MOVE_SPEED 0.2 +# define FT_STRAFE_SPEED 0.2 +# define FT_ROT_SPEED 0.2 + +/* +** ====== COLLISION ====== +*/ + +# define FT_COLL_MULT 0.225 /* ** ====== SCREEN ====== @@ -62,40 +111,61 @@ # endif /* -** ====== OTHERS ====== +** ====== CHARSET ====== */ -# ifndef FT_OS -# define FT_OS "Darwin" -# endif +# define FT_CHRST_VALID_PARSE "RNSEWFCLM" +# define FT_CHRST_MAP_ENTRY "012NSEWL " +# define FT_CHRST_SPAWN "NSEW" +# define FT_CHRST_MAP_NON_WALL "02NESWL" +# define FT_CHRST_COLLISION "12 " +# define FT_CHRST_DETECT "1L" + +/* +** ====== BMP ====== +*/ +# ifndef FT_BMP_SAVE_DIR +# define FT_BMP_SAVE_DIR "./" +# endif /* ** ====== MAP ERROR MSG ====== */ -# define FT_ERR_ALLOCATE "allocation error" -# define FT_ERR_READ "read error" -# define FT_ERR_NOT_A_CUB "given map is not a .cub" -# define FT_ERR_ARGS "too many or to few arguments" -# define FT_ERR_RES_SMALL "resolution is too small" -# define FT_ERR_RES_ALPHA "resolution should be digits only" -# define FT_ERR_NOT_A_XPM "given texture is not a .xpm" -# define FT_ERR_COLOR_ALPHA "colors should be digits only" -# define FT_ERR_COLOR_MAX "colors should be maximum 255" -# define FT_ERR_COLOR_ARGS "colors three numbers separated by commas" -# define FT_ERR_UNFINISHED "no map" -# define FT_ERR_MAP_LEN "map length inconsistency" -# define FT_ERR_ILL_ENTRY "illegal map entry" -# define FT_ERR_ALR_SET "duplicate entry" -# define FT_ERR_ILL_MAP "map contains illegal char" -# define FT_ERR_MULT_SPAWN "multiple spawn points" -# define FT_ERR_MAP_L_L "last line is invalid" -# define FT_ERR_RD_NO "could not find north side texture file" -# define FT_ERR_RD_SO "could not find south side texture file" -# define FT_ERR_RD_EA "could not find east side texture file" -# define FT_ERR_RD_WE "could not find west side texture file" -# define FT_ERR_RD_SP "could not find sprite texture file" +# define FT_ERR_ALLOCATE "Allocation error" +# define FT_ERR_READ "read error" +# define FT_ERR_ARGS "too many or to few arguments" +# define FT_ERR_RES_SMALL "resolution is too small, 50x50 minimum pls" +# define FT_ERR_RES_ALPHA "resolution should be digits only" +# define FT_ERR_SH_ALPHA "shadow amount should be digits only" +# define FT_ERR_SH_RANGE "shadow should be set between 0 - 20" +# define FT_ERR_NOT_A_CUB "given map is not a .cub" +# define FT_ERR_NOT_A_XPM "given texture is not a .xpm" +# define FT_ERR_NOT_A_WAV "given sound file is not a .wav" +# define FT_ERR_COLOR_ALPHA "colors should be digits only" +# define FT_ERR_COLOR_MAX "colors should be maximum 255" +# define FT_ERR_COLOR_ARGS "colors should be three numbers with commas" +# define FT_ERR_UNFINISHED "no map" +# define FT_ERR_MAP_LEN "map length inconsistency" +# define FT_ERR_ILL_ENTRY "illegal map entry" +# define FT_ERR_ALR_SET "duplicate entry" +# define FT_ERR_ILL_MAP "map contains illegal char" +# define FT_ERR_MULT_SPAWN "multiple spawn points" +# define FT_ERR_MULT_NLVL "multiple spawn new level access points" +# define FT_ERR_NO_MAP "No map" +# define FT_ERR_MAP_WALLS "bad space or map is not surrounded by walls" +# define FT_ERR_MAP_EMPL "empty line in map" +# define FT_ERR_MAP_L_L "last line is invalid" +# define FT_ERR_RD_NO "could not find north side texture file" +# define FT_ERR_RD_SO "could not find south side texture file" +# define FT_ERR_RD_EA "could not find east side texture file" +# define FT_ERR_RD_WE "could not find west side texture file" +# define FT_ERR_RD_SP "could not find sprite texture file" +# 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 ====== @@ -107,9 +177,17 @@ # define FT_ERR_MISS_EAST "east side texture" # define FT_ERR_MISS_WEST "west side texture" # define FT_ERR_MISS_SPRITE "sprite texture" +# define FT_ERR_MISS_NLVL_PATH "next level path" +# define FT_ERR_MISS_NLVL "next level texture" # define FT_ERR_MISS_RESOLUTION "resolution" # define FT_ERR_MISS_FLOOR_C "floor color" # define FT_ERR_MISS_CEIL_C "ceiling color" # define FT_ERR_MISS_PLAYER_SPAWN "player spawn" +/* +** ====== OTHER ====== +*/ + +# define FT_PARSE_END_RET 25 + # endif diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index cceafec..3c7ae28 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -14,40 +14,77 @@ # define CUB3D_STRUCTS_H #include <stddef.h> +#include <stdlib.h> #include <stdint.h> +#include <sys/types.h> -typedef struct s_win +typedef struct s_win { - void *wlx; - void *winptr; - uint8_t inited; - uint16_t x_max_size; - uint16_t y_max_size; - uint32_t x_size; - uint32_t y_size; -} t_win; - -typedef struct s_img + void *wlx; + void *winptr; + uint8_t inited; + uint16_t x_max_size; + uint16_t y_max_size; + uint32_t x_size; + uint32_t y_size; +} t_win; + +# pragma pack(push, 1) + +typedef struct s_bmp_file { - void *img; - char *ptr; - int bpp; - int sizeline; - int endian; - int img_w; - int img_h; - int tex_x; - int tex_y; -} t_img; - -typedef struct s_rgb + 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 { - int16_t r; - int16_t g; - int16_t b; -} t_rgb; + uint32_t size; + int32_t width; + int32_t height; + uint16_t planes; + uint16_t bit_count; + uint32_t compression; + uint32_t size_image; + int32_t x_pixels_per_meter; + int32_t y_pixels_per_meter; + uint32_t colors_used; + uint32_t colors_important; +} t_bmp_info; -typedef struct s_sprite +typedef struct s_bmp_rgb +{ + uint8_t r; + uint8_t g; + uint8_t b; +} t_bmp_rgb; + +# pragma pack(pop) + +typedef struct s_img +{ + void *img; + char *ptr; + int bpp; + int sizeline; + int endian; + int img_w; + int img_h; + int tex_x; + int tex_y; +} t_img; + +typedef struct s_rgb +{ + int16_t r; + int16_t g; + int16_t b; +} t_rgb; + +typedef struct s_sprite { int32_t spritescreenx; int32_t x; @@ -73,78 +110,114 @@ typedef struct s_sprite typedef struct s_player { - float pos_x; - float pos_y; - float start_x; - float start_y; - float dir_x; - float dir_y; - float cam_x; - float plane_x; - float plane_y; -} t_player; - -typedef struct s_ray + float pos_x; + float pos_y; + float pos_z; + float start_x; + float start_y; + float dir_x; + float dir_y; + float cam_x; + float plane_x; + float plane_y; +} t_player; + +typedef struct s_ray { - uint16_t line_h; - float wall_dist; - float *wall_dist_tab; - float x_ray_pos; - float y_ray_pos; - float x_ray_dir; - float y_ray_dir; - float x_side_dist; - float y_side_dist; - float x_delta_dist; - float y_delta_dist; - int16_t wall_t; - int16_t wall_b; - uint8_t side; - size_t sqx; - size_t sqy; - uint8_t hit; - double wall_hit_x; - double step_tex_v; -} t_ray; - -typedef struct s_map + uint16_t line_h; + float wall_dist; + float *wall_dist_tab; + float x_ray_pos; + float y_ray_pos; + float x_ray_dir; + float y_ray_dir; + float x_side_dist; + float y_side_dist; + float x_delta_dist; + float y_delta_dist; + int16_t wall_t; + int16_t wall_b; + uint8_t side; + size_t sqx; + size_t sqy; + uint8_t hit; + double wall_hit_x; + double step_tex_v; + float x_f_ray_dir; + float y_f_ray_dir; + float x_f_ray_dir_bis; + float y_f_ray_dir_bis; + uint16_t p; + float row_dist; + float x_floor; + float y_floor; + int32_t x_cell; + int32_t y_cell; +} t_ray; + +typedef struct s_map { - char *no_tex_path; - char *so_tex_path; - char *ea_tex_path; - char *we_tex_path; - char *sprite_path; - char *mapl; - char **map; - int32_t sprite_nbr; - int32_t sprite_order[12]; - int8_t x_step; - int8_t y_step; - size_t map_w; - size_t map_h; - size_t line_chk; - size_t map_start; - uint8_t isspawn; - uint8_t scale; - uint8_t isnlvl; -} t_map; - -typedef struct s_cub + char *filename; + char *no_tex_path; + char *so_tex_path; + char *ea_tex_path; + char *we_tex_path; + char *sprite_path; + char *nl_tex_path; + char *fl_tex_path; + char *ce_tex_path; + char *nlevel_path; + char *music_path; + char *music_cmd; + char *mapl; + char **map; + char **mcmd_words; + int8_t x_step; + int8_t y_step; + size_t map_w; + size_t map_h; + size_t mapl_len; + int32_t sprite_nbr; + int32_t sprite_order[12]; + size_t line_chk; + size_t map_start; + uint8_t isspawn; + uint8_t isnlvl; + uint8_t ismusic; + uint8_t isftex; + uint8_t isctex; + uint8_t darklvl; + uint8_t scale; + uint32_t nlx; + uint32_t nly; + float x_floor_step; + float y_floor_step; +} t_map; + +typedef struct s_cub { - uint8_t w_side; - uint8_t ishud; - char errmsg[40]; - int32_t key_input[5]; - int (*key_ptr[6])(struct s_cub*); - struct s_win *wlist; - struct s_player *plist; - struct s_map *mlist; - struct s_ray rlist; - struct s_img img; - struct s_rgb f_rgb; - struct s_rgb c_rgb; - struct s_img tlist[5]; - struct s_sprite sprites[12]; -} t_cub; + uint8_t w_side; + uint8_t ishud; + uint8_t walltexgood; + uint8_t isoldmus; + uint16_t currlvl; + uint16_t i; + char *const *envp; + char errmsg[64]; + int32_t key_input[5]; + pid_t mpid; + int (*key_ptr[6])(struct s_cub*); + int8_t (*get_ptr[12])(char**, struct s_cub*); + char ref[13][3]; + struct s_win wlist; + struct s_player plist; + struct s_map mlist; + struct s_ray rlist; + struct s_img img; + struct s_rgb f_rgb; + struct s_rgb c_rgb; + struct s_img tlist[8]; + struct s_sprite sprites[12]; +} t_cub; # endif |