diff --git a/includes/cub3d_struct.h b/includes/cub3d_struct.h index 333d8b3..fb1f140 100644 --- a/includes/cub3d_struct.h +++ b/includes/cub3d_struct.h @@ -6,7 +6,7 @@ /* By: bgoulard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/08 23:55:29 by bgoulard #+# #+# */ -/* Updated: 2024/11/09 01:50:35 by bgoulard ### ########.fr */ +/* Updated: 2024/11/10 05:37:11 by bgoulard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ # define CUB3D_STRUCT_H # include +# include "mlx_structs.h" # define FILE_EXTENSION ".cub" # define FILE_EXTENSION_LEN 4 @@ -110,8 +111,8 @@ typedef struct s_info { t_error last_error; - void *mlx_ptr; - void *win_ptr; + t_xvar *mlx_ptr; + t_win_list *win_ptr; t_map map; t_player player; t_cli cli_ctx; diff --git a/includes/fixed_mlx.h b/includes/mlx_functions.h similarity index 61% rename from includes/fixed_mlx.h rename to includes/mlx_functions.h index ab1f570..8d06083 100644 --- a/includes/fixed_mlx.h +++ b/includes/mlx_functions.h @@ -1,112 +1,19 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* fixed_mlx.h :+: :+: :+: */ +/* mlx_functions.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: bgoulard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/08 21:54:56 by bgoulard #+# #+# */ -/* Updated: 2024/11/09 00:16:25 by bgoulard ### ########.fr */ +/* Updated: 2024/11/10 05:35:44 by bgoulard ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FIXED_MLX_H # define FIXED_MLX_H -# include -# include -# include -# include -# include -# include -# include -# include -# include -/* #include */ - - -# define MLX_TYPE_SHM_PIXMAP 3 -# define MLX_TYPE_SHM 2 -# define MLX_TYPE_XIMAGE 1 - -# define MLX_MAX_EVENT LASTEvent - -# define ENV_DISPLAY "DISPLAY" -# define LOCALHOST "localhost" -# define ERR_NO_TRUECOLOR "MinilibX Error : No TrueColor Visual available.\n" -# define WARN_SHM_ATTACH "MinilibX Warning : X server can't attach shared memory.\n" - -typedef struct s_xpm_col -{ - int name; - int col; -} t_xpm_col; - - -struct s_col_name -{ - char *name; - int color; -}; - -typedef struct s_event_list -{ - int mask; - int (*hook)(); - void *param; -} t_event_list; - - -typedef struct s_win_list -{ - Window window; - GC gc; - struct s_win_list *next; - int (*mouse_hook)(); - int (*key_hook)(); - int (*expose_hook)(); - void *mouse_param; - void *key_param; - void *expose_param; - t_event_list hooks[MLX_MAX_EVENT]; -} t_win_list; - - -typedef struct s_img -{ - XImage *image; - Pixmap pix; - GC gc; - int size_line; - int bpp; - int width; - int height; - int type; - int format; - char *data; - XShmSegmentInfo shm; -} t_img; - -typedef struct s_xvar -{ - Display *display; - Window root; - int screen; - int depth; - Visual *visual; - Colormap cmap; - int private_cmap; - t_win_list *win_list; - int (*loop_hook)(); - void *loop_param; - int use_xshm; - int pshm_format; - int do_flush; - int decrgb[6]; - Atom wm_delete_window; - Atom wm_protocols; - int end_loop; -} t_xvar; +# include "mlx_structs.h" t_xvar *mlx_init(void); t_win_list *mlx_new_window(t_xvar *mlx_ptr, int size_x, int size_y, char *title); diff --git a/includes/mlx_structs.h b/includes/mlx_structs.h new file mode 100644 index 0000000..954de86 --- /dev/null +++ b/includes/mlx_structs.h @@ -0,0 +1,103 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* mlx_structs.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: bgoulard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/10 05:33:08 by bgoulard #+# #+# */ +/* Updated: 2024/11/10 05:38:28 by bgoulard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MLX_STRUCT_H +# define MLX_STRUCT_H + +# include +# include +# include + +# define MLX_TYPE_SHM_PIXMAP 3 +# define MLX_TYPE_SHM 2 +# define MLX_TYPE_XIMAGE 1 + +# define MLX_MAX_EVENT LASTEvent + +# define ENV_DISPLAY "DISPLAY" +# define LOCALHOST "localhost" +# define ERR_NO_TRUECOLOR "MinilibX Error : No TrueColor Visual available.\n" +# define WARN_SHM_ATTACH "MinilibX Warning : X server can't attach shared memory.\n" + +typedef struct s_xpm_col +{ + int name; + int col; +} t_xpm_col; + + +struct s_col_name +{ + char *name; + int color; +}; + +typedef struct s_event_list +{ + int mask; + int (*hook)(); + void *param; +} t_event_list; + +/// @brief window pointer from mlx +typedef struct s_win_list +{ + Window window; + GC gc; + struct s_win_list *next; + int (*mouse_hook)(); + int (*key_hook)(); + int (*expose_hook)(); + void *mouse_param; + void *key_param; + void *expose_param; + t_event_list hooks[MLX_MAX_EVENT]; +} t_win_list; + +typedef struct s_img +{ + XImage *image; + Pixmap pix; + GC gc; + int size_line; + int bpp; + int width; + int height; + int type; + int format; + char *data; + XShmSegmentInfo shm; +} t_img; + +/// @brief mlx pointer +typedef struct s_xvar +{ + Display *display; + Window root; + int screen; + int depth; + Visual *visual; + Colormap cmap; + int private_cmap; + t_win_list *win_list; + int (*loop_hook)(); + void *loop_param; + int use_xshm; + int pshm_format; + int do_flush; + int decrgb[6]; + Atom wm_delete_window; + Atom wm_protocols; + int end_loop; +} t_xvar; + +#endif /* MLX_STRUCT_H */ diff --git a/sources/main.c b/sources/main.c index 0016627..e757390 100644 --- a/sources/main.c +++ b/sources/main.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/30 16:30:03 by rparodi #+# #+# */ -/* Updated: 2024/11/09 01:45:20 by bgoulard ### ########.fr */ +/* Updated: 2024/11/10 05:48:09 by bgoulard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,12 +20,19 @@ void dump_info(t_info *info) { + const char *bool_str[2] = { "True", "False"}; + printf("t_info:\n"); printf("\tcli_ctx:\n"); printf("\t\tfile: %s\n", info->cli_ctx.file); - printf("\t\tdebug: %s\n", info->cli_ctx.debug ? "true" : "false"); - printf("\t\tsave: %s\n", info->cli_ctx.save ? "true" : "false"); - printf("\t\thelp: %s\n", info->cli_ctx.help ? "true" : "false"); + printf("\t\tdebug: %s\n", bool_str[info->cli_ctx.debug]); + printf("\t\tsave: %s\n", bool_str[info->cli_ctx.save]); + printf("\t\thelp: %s\n", bool_str[info->cli_ctx.help]); + printf("\tmap:\n"); + printf("\t\tpath:%s\n", info->map.path); + printf("\t\tfd:%d\n", info->map.fd); + printf("\t\tsize:\t(x:%d, y:%d)\n", info->map.size.x, info->map.size.y); + printf("\t\tplayer_pos:\t(x:%lf, y:%lf)\n", info->map.player_pos.x, info->map.player_pos.y); } void check_err(t_info *info) @@ -44,6 +51,11 @@ void check_err(t_info *info) void run_cub3d(t_info *info) { // code here + // - parse map + // - validity check + // - mlx inits + // - game loop + // - mlx cleanup (void)info; } @@ -62,13 +74,11 @@ int main_cub3d(char *file_arg, t_info *info) return (cleanup_info(info), EXIT_SUCCESS); } - int main(int argc, char *argv[]) { t_info info; int parsed_args; - (void)argc; parsed_args = c3_options(&info, argc, argv); if (parsed_args == -1) return (EXIT_FAILURE);