From 8ee1c5f85aa797fb35a4a35fab6fe3db4d369e07 Mon Sep 17 00:00:00 2001 From: "B.Goulard" <84p71573@gmail.com> Date: Sat, 9 Nov 2024 01:53:22 +0100 Subject: [PATCH] First shot on structures, First shot on option option: Added options for help, debug, save, file using bgoulard lib structures: Moved cub3d.h structures to cub3d_struct.h Added color, dpoint, ipoint, tile, cli, error Modified t_map, t_player to use previously mentioned struct : ipoint, dpoint, tyle --- Makefile | 15 ++-- includes/cub3d.h | 52 +++----------- includes/cub3d_options.h | 22 ++++++ includes/cub3d_struct.h | 120 +++++++++++++++++++++++++++++++ includes/fixed_mlx.h | 152 +++++++++++++++++++++++++++++++++++++++ includes/message_error.h | 7 +- libft/Makefile | 4 +- parsing/arguments.c | 21 +++--- sources/cleanups.c | 38 ++++++++++ sources/error.c | 48 +++++++++---- sources/main.c | 64 +++++++++++++++-- sources/options.c | 40 +++++++++++ sources/options_impl.c | 52 ++++++++++++++ sources/rgb_to_color.c | 24 +++++++ 14 files changed, 580 insertions(+), 79 deletions(-) create mode 100644 includes/cub3d_options.h create mode 100644 includes/cub3d_struct.h create mode 100644 includes/fixed_mlx.h create mode 100644 sources/cleanups.c create mode 100644 sources/options.c create mode 100644 sources/options_impl.c create mode 100644 sources/rgb_to_color.c diff --git a/Makefile b/Makefile index 712156b..a4a25f9 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# # -# Updated: 2024/11/08 19:36:49 by rparodi ### ########.fr # +# Updated: 2024/11/09 01:52:06 by bgoulard ### ########.fr # # # # **************************************************************************** # @@ -26,7 +26,7 @@ CFLAGS += -g3 -MMD # CFLAGS += -fsanitize=address # CFLAGS += -fsanitize=thread -INCLUDES = -I ./includes/ -I ./includes/include/ -I ./minilibx-linux +INCLUDES = -I ./includes -I ./includes/include -I ./minilibx-linux # Paths LIBFT_DIR = ./libft @@ -41,9 +41,14 @@ MLXFLAGS = -L$(MLX_DIR) -lmlx -L/opt/X11/lib -lX11 -lXext -lXrender -lXrandr -lX # Add MLXFLAGS to the linker flags LDFLAGS += $(MLXFLAGS) -SRC = sources/main.c \ - sources/error.c \ - parsing/arguments.c +SRC =\ + parsing/arguments.c \ + sources/cleanups.c \ + sources/error.c \ + sources/main.c \ + sources/options.c \ + sources/options_impl.c \ + sources/rgb_to_color.c # Objects OBJDIRNAME = ./build diff --git a/includes/cub3d.h b/includes/cub3d.h index 6011025..ae0b004 100644 --- a/includes/cub3d.h +++ b/includes/cub3d.h @@ -6,59 +6,25 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/30 16:30:26 by rparodi #+# #+# */ -/* Updated: 2024/11/08 11:40:44 by rparodi ### ########.fr */ +/* Updated: 2024/11/09 01:19:41 by bgoulard ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef CUB3D_H # define CUB3D_H -# include -# include -# include -# include -# include -# include -# include - -# include "libft.h" -# include "../minilibx-linux/mlx.h" -# include "message_error.h" - +#include "cub3d_struct.h" # ifndef BONUS # define BONUS 0 # endif -typedef struct s_map -{ - int fd; - char *path; - char *oneline; - char **content; - double spawn_x; - double spawn_y; -} t_map; +# include -typedef struct s_player -{ - double pos_x; - double pos_y; - double dir_x; - double dir_y; - double view_x; - double view_y; -} t_player; - -typedef struct s_info -{ - void *mlx_ptr; - void *win_ptr; - t_map *map; - t_player player; -} t_info; - -void print_error(char *msg); -bool ft_parse_args(int argc, char *argv[]); +void cleanup_info(t_info *info); +int c3_options(t_info *info, int argc, char *argv[]); +void c3_perror(t_info *info); +void print_error(const char *msg); +void parse_args(char *arg, t_info *inf); int main(int argc, char *argv[]); -#endif +#endif /* CUB3D_H */ diff --git a/includes/cub3d_options.h b/includes/cub3d_options.h new file mode 100644 index 0000000..9df387f --- /dev/null +++ b/includes/cub3d_options.h @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cub3d_options.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: bgoulard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/09 01:15:15 by bgoulard #+# #+# */ +/* Updated: 2024/11/09 01:33:17 by bgoulard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef CUB3D_OPTIONS_H +# define CUB3D_OPTIONS_H + +void c3_set_file(void *usr_control_struct, const char *arg); +void c3_set_debug(void *usr_control_struct); +void c3_set_save(void *usr_control_struct); +void c3_print_help(void *usr_control_struct); + + +# endif /* CUB3D_OPTIONS_H */ diff --git a/includes/cub3d_struct.h b/includes/cub3d_struct.h new file mode 100644 index 0000000..333d8b3 --- /dev/null +++ b/includes/cub3d_struct.h @@ -0,0 +1,120 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cub3d_struct.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: bgoulard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/08 23:55:29 by bgoulard #+# #+# */ +/* Updated: 2024/11/09 01:50:35 by bgoulard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef CUB3D_STRUCT_H +# define CUB3D_STRUCT_H + +# include + +# define FILE_EXTENSION ".cub" +# define FILE_EXTENSION_LEN 4 + +// -- graphic utils + +typedef struct s_color +{ + union + { + unsigned int color; + struct + { + unsigned char b; + unsigned char g; + unsigned char r; + unsigned char a; + }; + }; +} t_color; + +typedef struct s_point +{ + int x; + int y; +} t_ipoint; + +typedef struct s_dpoint +{ + double x; + double y; +} t_dpoint; + +// -- map utils + +typedef enum e_tile +{ + EMPTY, + WALL +} t_tile; + +typedef struct s_map +{ + int fd; + char *path; + + t_dpoint player_pos; + t_ipoint size; + t_tile *map; + char **raw; +} t_map; + +// -- player utils + +typedef struct s_player +{ + t_dpoint pos; + t_dpoint dir; + t_dpoint view; +} t_player; + +// -- cli utils + +typedef struct s_cli { + int debug; + char *file; + bool save; + bool help; +} t_cli; + +// -- error utils + +typedef enum e_error +{ + NO_ERROR = 0, + UNKNOWN_ERROR, + + OPEN_FILE_ERROR, + READ_FILE_ERROR, + EXTENSION_FILE_ERROR, + NAME_FILE_ERROR, + MISSING_FILE_ERROR, + + MALLOC_ERROR, + + PARSE_ERROR, + CLI_ERROR, + MLX_ERROR +} t_error; + +// -- main struct + +typedef struct s_info +{ + t_error last_error; + + void *mlx_ptr; + void *win_ptr; + t_map map; + t_player player; + t_cli cli_ctx; +} t_info; + +#endif /* CUB3D_STRUCT_H */ diff --git a/includes/fixed_mlx.h b/includes/fixed_mlx.h new file mode 100644 index 0000000..ab1f570 --- /dev/null +++ b/includes/fixed_mlx.h @@ -0,0 +1,152 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* fixed_mlx.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: bgoulard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/08 21:54:56 by bgoulard #+# #+# */ +/* Updated: 2024/11/09 00:16:25 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; + +t_xvar *mlx_init(void); +t_win_list *mlx_new_window(t_xvar *mlx_ptr, int size_x, int size_y, char *title); + +int mlx_clear_window(t_xvar *mlx_ptr, t_win_list *win_ptr); +int mlx_pixel_put(t_xvar *mlx_ptr, t_win_list *win_ptr, int x, int y, int color); + +t_img *mlx_new_image(t_xvar *mlx_ptr,int width,int height); +char *mlx_get_data_addr(t_img *img_ptr, int *bits_per_pixel, int *size_line, int *endian); +int mlx_put_image_to_window(t_xvar *mlx_ptr, t_win_list *win_ptr, t_img *img_ptr, int x, int y); +int mlx_get_color_value(t_xvar *mlx_ptr, int color); + +int mlx_mouse_hook (t_win_list *win_ptr, int (*funct_ptr)(), void *param); +int mlx_key_hook (t_win_list *win_ptr, int (*funct_ptr)(), void *param); +int mlx_expose_hook (t_win_list *win_ptr, int (*funct_ptr)(), void *param); + +int mlx_loop_hook (t_xvar *mlx_ptr, int (*funct_ptr)(), void *param); +int mlx_loop (t_xvar *mlx_ptr); +int mlx_loop_end (t_xvar *mlx_ptr); + +int mlx_string_put(t_xvar *mlx_ptr, t_win_list *win_ptr, int x, int y, int color, char *string); +void mlx_set_font(t_xvar *mlx_ptr, t_win_list *win_ptr, char *name); +t_img *mlx_xpm_to_image(t_xvar *mlx_ptr, char **xpm_data, int *width, int *height); +t_img *mlx_xpm_file_to_image(t_xvar *mlx_ptr, char *filename, int *width, int *height); +int mlx_destroy_window(t_xvar *mlx_ptr, t_win_list *win_ptr); + +int mlx_destroy_image(t_xvar *mlx_ptr, t_img *img_ptr); + +int mlx_destroy_display(t_xvar *mlx_ptr); +int mlx_hook(t_win_list *win_ptr, int x_event, int x_mask, int (*funct)(), void *param); + +int mlx_do_key_autorepeatoff(t_xvar *mlx_ptr); +int mlx_do_key_autorepeaton(t_xvar *mlx_ptr); +int mlx_do_sync(t_xvar *mlx_ptr); + +int mlx_mouse_get_pos(t_xvar *mlx_ptr, t_win_list *win_ptr, int *x, int *y); +int mlx_mouse_move(t_xvar *mlx_ptr, t_win_list *win_ptr, int x, int y); +int mlx_mouse_hide(t_xvar *mlx_ptr, t_win_list *win_ptr); +int mlx_mouse_show(t_xvar *mlx_ptr, t_win_list *win_ptr); + +int mlx_get_screen_size(t_xvar *mlx_ptr, int *sizex, int *sizey); + +#endif /* FIXED_MLX_H */ diff --git a/includes/message_error.h b/includes/message_error.h index b6d778d..bd41e2e 100644 --- a/includes/message_error.h +++ b/includes/message_error.h @@ -6,15 +6,16 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/30 16:43:20 by rparodi #+# #+# */ -/* Updated: 2024/10/31 11:23:20 by rparodi ### ########.fr */ +/* Updated: 2024/11/09 00:42:02 by bgoulard ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef MESSAGE_ERROR_H # define MESSAGE_ERROR_H -# define ERR_ARGS_COUNT "You have to give only the map on arguments !\n" -# define INV_NAME_MAP "The name of the map have to finish by `.cub` !\n" +# define E_STR_AC "You have to give map as an argument !\n" +# define E_STR_EXT_MAP "The name of the map have to finish by `.cub` !\n" +# define E_STR_NAME_MAP "The name of the map is invalid !\n" # define RED "\x1b[31m" # define BOLD_RED "\033[1;31m" diff --git a/libft/Makefile b/libft/Makefile index 5432fca..11ff5d2 100644 --- a/libft/Makefile +++ b/libft/Makefile @@ -6,7 +6,7 @@ # By: bgoulard +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/12/05 09:04:05 by bgoulard #+# #+# # -# Updated: 2024/10/31 23:53:29 by bgoulard ### ########.fr # +# Updated: 2024/11/09 00:08:07 by bgoulard ### ########.fr # # # # **************************************************************************** # @@ -19,7 +19,7 @@ BOLD = "\\e[1m" # Commands CC = clang -NAME = ft_personal +NAME = ft OUTDIR = ../build TEST_NAME = tests_run diff --git a/parsing/arguments.c b/parsing/arguments.c index 6a444fb..43fc103 100644 --- a/parsing/arguments.c +++ b/parsing/arguments.c @@ -6,11 +6,13 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/30 16:41:32 by rparodi #+# #+# */ -/* Updated: 2024/10/31 16:54:21 by rparodi ### ########.fr */ +/* Updated: 2024/11/09 01:21:24 by bgoulard ### ########.fr */ /* */ /* ************************************************************************** */ #include "cub3d.h" +#include "cub3d_struct.h" +#include "ft_string.h" /** * @brief checking if the args given to the executable is valid @@ -19,12 +21,15 @@ * @param argv the arguments value * @return false if an error / true if no error */ -bool ft_parse_args(int argc, char *argv[]) +void parse_args(char *arg, t_info *inf) { - if (argc != 2) - return (print_error(ERR_ARGS_COUNT), false); - if (ft_strlen(argv[1]) < 4 || \ - ft_strcmp((argv[1] + (strlen(argv[1]) - 4)), ".cub") != 0) - return (print_error(INV_NAME_MAP), false); - return (true); + if (arg == NULL && inf->cli_ctx.file == NULL) + return (inf->last_error = MISSING_FILE_ERROR, (void)0); + if (arg && ft_strlen(arg) < 5) + return (inf->last_error = NAME_FILE_ERROR, (void)0); + if (arg && ft_strend_with(arg, FILE_EXTENSION) == false) + return (inf->last_error = EXTENSION_FILE_ERROR, (void)0); + if (arg && inf->cli_ctx.file == NULL) + inf->cli_ctx.file = ft_strdup(arg); + inf->last_error = NO_ERROR; } diff --git a/sources/cleanups.c b/sources/cleanups.c new file mode 100644 index 0000000..0250a92 --- /dev/null +++ b/sources/cleanups.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cleanups.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: bgoulard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/09 01:11:01 by bgoulard #+# #+# */ +/* Updated: 2024/11/09 01:11:45 by bgoulard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "cub3d_struct.h" + +#include + +static void cleanup_cli(t_cli *cli_ctx) +{ + if (cli_ctx->file) + free(cli_ctx->file); +} + +static void cleanup_map(t_map *map) +{ + (void)map; +} + +static void cleanup_mlx(t_info *info) +{ + (void)info; +} + +void cleanup_info(t_info *info) +{ + cleanup_cli(&info->cli_ctx); + cleanup_map(&info->map); + cleanup_mlx(info); +} diff --git a/sources/error.c b/sources/error.c index 3fedfa0..c16ce32 100644 --- a/sources/error.c +++ b/sources/error.c @@ -6,25 +6,45 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 11:09:00 by rparodi #+# #+# */ -/* Updated: 2024/10/31 12:01:18 by rparodi ### ########.fr */ +/* Updated: 2024/11/09 01:43:06 by bgoulard ### ########.fr */ /* */ /* ************************************************************************** */ +#include "ft_string.h" + #include "cub3d.h" +#include "message_error.h" -#include +#include -/** - * @brief Print the message error with red color ! - * - * @param msg The detailled message - */ -void print_error(char *msg) +const char *g_error_message[] = { + "no error", + "unknown error", + + "could not open file", + "could not read file", + "bad file extension", + "invalid file name", + "missing file", + "malloc error", + "parse error", + "cli error", + "mlx error", +}; + +void c3_perror(t_info *info) { - write(2, BOLD_RED, strlen(BOLD_RED)); - write(2, "Error:\n", strlen("Error:\n")); - write(2, RESET, strlen(RESET)); - write(2, RED, strlen(RED)); - write(2, msg, strlen(msg)); - write(2, RESET, strlen(RESET)); + if (info->last_error == NO_ERROR) + return ; + print_error(g_error_message[info->last_error]); +} + +void print_error(const char *msg) +{ + ft_putstr_fd(BOLD_RED, STDERR_FILENO); + ft_putstr_fd("Error:\n", STDERR_FILENO); + ft_putstr_fd(RESET, STDERR_FILENO); + ft_putstr_fd(RED, STDERR_FILENO); + ft_putstr_fd(msg, STDERR_FILENO); + ft_putstr_fd(RESET, STDERR_FILENO); } diff --git a/sources/main.c b/sources/main.c index 1dcc519..0016627 100644 --- a/sources/main.c +++ b/sources/main.c @@ -6,15 +6,71 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/30 16:30:03 by rparodi #+# #+# */ -/* Updated: 2024/11/08 11:48:44 by rparodi ### ########.fr */ +/* Updated: 2024/11/09 01:45:20 by bgoulard ### ########.fr */ /* */ /* ************************************************************************** */ #include "cub3d.h" +#include "cub3d_struct.h" +#include "ft_string.h" + +#include +#include +#include + +void dump_info(t_info *info) +{ + 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"); +} + +void check_err(t_info *info) +{ + if (info->cli_ctx.file == NULL) + return (info->last_error = MISSING_FILE_ERROR, (void)0); + else if (ft_strlen(info->cli_ctx.file) < 5) + return (info->last_error = NAME_FILE_ERROR, (void)0); + else if (ft_strend_with(info->cli_ctx.file, FILE_EXTENSION) == false) + return (info->last_error = EXTENSION_FILE_ERROR, (void)0); + info->map.fd = open(info->cli_ctx.file, O_RDONLY); + if (info->map.fd == -1) + return (info->last_error = OPEN_FILE_ERROR, (void)0); +} + +void run_cub3d(t_info *info) +{ + // code here + (void)info; +} + +int main_cub3d(char *file_arg, t_info *info) +{ + if (info->cli_ctx.help) + return (cleanup_info(info), EXIT_SUCCESS); + if (file_arg && info->cli_ctx.file == NULL) + info->cli_ctx.file = ft_strdup(file_arg); + check_err(info); + if (info->last_error != NO_ERROR) + return (c3_perror(info), cleanup_info(info), EXIT_FAILURE); + if (info->cli_ctx.debug) + (dump_info(info), printf("file_arg: %s\n", file_arg)); + run_cub3d(info); + return (cleanup_info(info), EXIT_SUCCESS); +} + int main(int argc, char *argv[]) { - if (!ft_parse_args(argc, argv)) - return (1); - return (0); + t_info info; + int parsed_args; + + (void)argc; + parsed_args = c3_options(&info, argc, argv); + if (parsed_args == -1) + return (EXIT_FAILURE); + return (main_cub3d(argv[parsed_args], &info)); } diff --git a/sources/options.c b/sources/options.c new file mode 100644 index 0000000..ca4808c --- /dev/null +++ b/sources/options.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* options.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: bgoulard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/09 01:14:09 by bgoulard #+# #+# */ +/* Updated: 2024/11/09 01:37:41 by bgoulard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "cub3d_struct.h" +#include "cub3d_options.h" + +#include "ft_args.h" +#include "ft_args_types.h" +#include "ft_string.h" + +int c3_options(t_info *info, int argc, char *argv[]) +{ + int parsed_args; + const t_opt opts[] = { + {"file", 'f', c3_set_file, OPT_ARG | OPT_EQSIGN | OPT_OTHER}, + {"debug", 'd', c3_set_debug, 0}, + {"save", 's', c3_set_save, 0}, + {"help", 'h', c3_print_help, 0}, + // add more options here put the implementation in options_impl.c + // if you want custom option see ft_args_types.h for more info + // code example in it. + {NULL, 0, NULL, 0} + }; + + (void)argc; + ft_bzero(info, sizeof(t_info)); + ft_setup_prog((const char * const *)argv); + ft_set_opt_list(opts); + parsed_args = ft_parse_args((const char **)argv, &(info->cli_ctx)); + return (parsed_args); +} diff --git a/sources/options_impl.c b/sources/options_impl.c new file mode 100644 index 0000000..a01c3ef --- /dev/null +++ b/sources/options_impl.c @@ -0,0 +1,52 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* options_impl.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: bgoulard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/09 01:12:16 by bgoulard #+# #+# */ +/* Updated: 2024/11/09 01:36:19 by bgoulard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "cub3d_struct.h" +#include "ft_string.h" + +void c3_set_file(void *usr_control_struct, const char *arg) +{ + t_cli *cli_ctx; + + cli_ctx = (t_cli *)usr_control_struct; + cli_ctx->file = ft_strdup(arg); +} + +void c3_set_debug(void *usr_control_struct) +{ + t_cli *cli_ctx; + + cli_ctx = (t_cli *)usr_control_struct; + cli_ctx->debug = true; +} + +void c3_set_save(void *usr_control_struct) +{ + t_cli *cli_ctx; + + cli_ctx = (t_cli *)usr_control_struct; + cli_ctx->save = true; +} + +void c3_print_help(void *usr_control_struct) +{ + t_cli *cli_ctx; + + cli_ctx = (t_cli *)usr_control_struct; + cli_ctx->help = true; + ft_putstr_fd("Usage: cub3d [options] \n", STDOUT_FILENO); + ft_putstr_fd("Options:\n", STDOUT_FILENO); + ft_putstr_fd("\t-f, --file : specify the file to load\n", STDOUT_FILENO); + ft_putstr_fd("\t-d, --debug : enable debug mode\n", STDOUT_FILENO); + ft_putstr_fd("\t-s, --save : save the state of the 'game' when closing\n", STDOUT_FILENO); + ft_putstr_fd("\t-h, --help : print this help\n", STDOUT_FILENO); +} diff --git a/sources/rgb_to_color.c b/sources/rgb_to_color.c new file mode 100644 index 0000000..6d44bac --- /dev/null +++ b/sources/rgb_to_color.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rgb_to_color.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: bgoulard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/08 21:49:55 by bgoulard #+# #+# */ +/* Updated: 2024/11/09 00:14:28 by bgoulard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "cub3d_struct.h" + +t_color rgb_to_color(int r, int g, int b) +{ + t_color color; + + color.r = r; + color.g = g; + color.b = b; + color.a = 0; + return (color); +}