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
This commit is contained in:
B.Goulard 2024-11-09 01:53:22 +01:00
parent be6038dcc8
commit 8ee1c5f85a
14 changed files with 580 additions and 79 deletions

View file

@ -6,7 +6,7 @@
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ # # By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/11/12 11:05:05 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=address
# CFLAGS += -fsanitize=thread # CFLAGS += -fsanitize=thread
INCLUDES = -I ./includes/ -I ./includes/include/ -I ./minilibx-linux INCLUDES = -I ./includes -I ./includes/include -I ./minilibx-linux
# Paths # Paths
LIBFT_DIR = ./libft 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 # Add MLXFLAGS to the linker flags
LDFLAGS += $(MLXFLAGS) LDFLAGS += $(MLXFLAGS)
SRC = sources/main.c \ SRC =\
sources/error.c \ parsing/arguments.c \
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 # Objects
OBJDIRNAME = ./build OBJDIRNAME = ./build

View file

@ -6,59 +6,25 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/30 16:30:26 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 #ifndef CUB3D_H
# define CUB3D_H # define CUB3D_H
# include <stdio.h> #include "cub3d_struct.h"
# include <math.h>
# include <fcntl.h>
# include <stdlib.h>
# include <sys/time.h>
# include <unistd.h>
# include <stdbool.h>
# include "libft.h"
# include "../minilibx-linux/mlx.h"
# include "message_error.h"
# ifndef BONUS # ifndef BONUS
# define BONUS 0 # define BONUS 0
# endif # endif
typedef struct s_map # include <stdbool.h>
{
int fd;
char *path;
char *oneline;
char **content;
double spawn_x;
double spawn_y;
} t_map;
typedef struct s_player void cleanup_info(t_info *info);
{ int c3_options(t_info *info, int argc, char *argv[]);
double pos_x; void c3_perror(t_info *info);
double pos_y; void print_error(const char *msg);
double dir_x; void parse_args(char *arg, t_info *inf);
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[]);
int main(int argc, char *argv[]); int main(int argc, char *argv[]);
#endif #endif /* CUB3D_H */

22
includes/cub3d_options.h Normal file
View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d_options.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */

120
includes/cub3d_struct.h Normal file
View file

@ -0,0 +1,120 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d_struct.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdbool.h>
# 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 */

152
includes/fixed_mlx.h Normal file
View file

@ -0,0 +1,152 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fixed_mlx.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <unistd.h>
# include <fcntl.h>
# include <sys/mman.h>
# include <X11/Xlib.h>
# include <X11/Xutil.h>
# include <sys/ipc.h>
# include <sys/shm.h>
# include <X11/extensions/XShm.h>
# include <X11/XKBlib.h>
/* #include <X11/xpm.h> */
# 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 */

View file

@ -6,15 +6,16 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/30 16:43:20 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 #ifndef MESSAGE_ERROR_H
# define MESSAGE_ERROR_H # define MESSAGE_ERROR_H
# define ERR_ARGS_COUNT "You have to give only the map on arguments !\n" # define E_STR_AC "You have to give map as an argument !\n"
# define INV_NAME_MAP "The name of the map have to finish by `.cub` !\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 RED "\x1b[31m"
# define BOLD_RED "\033[1;31m" # define BOLD_RED "\033[1;31m"

View file

@ -6,7 +6,7 @@
# By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ # # By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/12/05 09:04:05 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 # Commands
CC = clang CC = clang
NAME = ft_personal NAME = ft
OUTDIR = ../build OUTDIR = ../build
TEST_NAME = tests_run TEST_NAME = tests_run

View file

@ -6,11 +6,13 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/30 16:41:32 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.h"
#include "cub3d_struct.h"
#include "ft_string.h"
/** /**
* @brief checking if the args given to the executable is valid * @brief checking if the args given to the executable is valid
@ -19,12 +21,15 @@
* @param argv the arguments value * @param argv the arguments value
* @return false if an error / true if no error * @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) if (arg == NULL && inf->cli_ctx.file == NULL)
return (print_error(ERR_ARGS_COUNT), false); return (inf->last_error = MISSING_FILE_ERROR, (void)0);
if (ft_strlen(argv[1]) < 4 || \ if (arg && ft_strlen(arg) < 5)
ft_strcmp((argv[1] + (strlen(argv[1]) - 4)), ".cub") != 0) return (inf->last_error = NAME_FILE_ERROR, (void)0);
return (print_error(INV_NAME_MAP), false); if (arg && ft_strend_with(arg, FILE_EXTENSION) == false)
return (true); 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;
} }

38
sources/cleanups.c Normal file
View file

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cleanups.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/09 01:11:01 by bgoulard #+# #+# */
/* Updated: 2024/11/09 01:11:45 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d_struct.h"
#include <stdlib.h>
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);
}

View file

@ -6,25 +6,45 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/31 11:09:00 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 "cub3d.h"
#include "message_error.h"
#include <string.h> #include <unistd.h>
/** const char *g_error_message[] = {
* @brief Print the message error with red color ! "no error",
* "unknown error",
* @param msg The detailled message
*/ "could not open file",
void print_error(char *msg) "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)); if (info->last_error == NO_ERROR)
write(2, "Error:\n", strlen("Error:\n")); return ;
write(2, RESET, strlen(RESET)); print_error(g_error_message[info->last_error]);
write(2, RED, strlen(RED)); }
write(2, msg, strlen(msg));
write(2, RESET, strlen(RESET)); 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);
} }

View file

@ -6,15 +6,71 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/30 16:30:03 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.h"
#include "cub3d_struct.h"
#include "ft_string.h"
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
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[]) int main(int argc, char *argv[])
{ {
if (!ft_parse_args(argc, argv)) t_info info;
return (1); int parsed_args;
return (0);
(void)argc;
parsed_args = c3_options(&info, argc, argv);
if (parsed_args == -1)
return (EXIT_FAILURE);
return (main_cub3d(argv[parsed_args], &info));
} }

40
sources/options.c Normal file
View file

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* options.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

52
sources/options_impl.c Normal file
View file

@ -0,0 +1,52 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* options_impl.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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] <file>\n", STDOUT_FILENO);
ft_putstr_fd("Options:\n", STDOUT_FILENO);
ft_putstr_fd("\t-f, --file <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);
}

24
sources/rgb_to_color.c Normal file
View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rgb_to_color.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}