merge bgoulard branch on master

This commit is contained in:
Baptiste GOULARD 2024-11-28 13:56:45 +01:00
commit 2568aa69a6
14 changed files with 464 additions and 78 deletions

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/30 16:30:26 by rparodi #+# #+# */
/* Updated: 2024/11/26 13:37:20 by rparodi ### ########.fr */
/* Updated: 2024/11/28 13:54:39 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
@ -32,7 +32,7 @@ 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 print_error(const char *msg, int errno_state);
void parse_map(t_info *info);
void parse_args(char *arg, t_info *inf);

View file

@ -6,13 +6,14 @@
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/09 01:15:15 by bgoulard #+# #+# */
/* Updated: 2024/11/11 21:34:02 by rparodi ### ########.fr */
/* Updated: 2024/11/27 11:35:39 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CUB3D_OPTIONS_H
# define CUB3D_OPTIONS_H
void c3_set_parse_excl(void *usr_control_struct);
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);

53
includes/cub3d_parsing.h Normal file
View file

@ -0,0 +1,53 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d_parsing.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/11 14:41:07 by bgoulard #+# #+# */
/* Updated: 2024/11/18 11:32:00 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CUB3D_PARSING_H
# define CUB3D_PARSING_H
# include <stdbool.h>
# define C3D_PRS_PLS "SO"
# define C3D_PRS_PLW "WE"
# define C3D_PRS_PLN "NO"
# define C3D_PRS_PLE "EA"
# define C3D_PRS_WLL_TRAIL ' '
# define C3D_PRS_WLL '1'
# define C3D_PRS_EMP '0'
enum e_tile_m
{
EMPTY,
DOOR_OPEN,
DOOR_ANIM,
DOOR_CLOSE,
WALL_TRAIL,
WALL,
PLAYER_N,
PLAYER_S,
PLAYER_E,
PLAYER_W
};
typedef struct s_map_truth
{
enum e_tile_m tile;
char chr[2];
} t_map_truth;
typedef struct s_tile
{
enum e_tile_m tile;
bool visited;
} t_tile;
#endif /* CUB3D_PARSING_H */

View file

@ -5,8 +5,8 @@
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/08 23:55:29 by bgoulard #+# #+# */
/* Updated: 2024/11/26 13:35:13 by rparodi ### ########.fr */
/* Created: 2024/11/28 13:53:54 by bgoulard #+# #+# */
/* Updated: 2024/11/28 13:54:53 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,6 +18,8 @@
# define FILE_EXTENSION ".cub"
# define FILE_EXTENSION_LEN 4
# define BG_CLG 0
# define BG_FLR 1
#define FOV 65
#define TILE_SIZE 64
@ -38,6 +40,14 @@ typedef struct s_color
};
} t_color;
typedef struct s_texture
{
t_img *img;
int width;
int height;
char *path;
} t_texture;
typedef struct s_point
{
int x;
@ -54,8 +64,18 @@ typedef struct s_dpoint
typedef enum e_tile
{
EMPTY,
WALL
EMPTY = 0,
WALL = 1,
} t_tile_type;
typedef union u_tile
{
int raw_tile;
struct {
unsigned int tile_visited: 1; // parsing
unsigned int other: 27; // disponible
unsigned int tile_type: 4; // 16 tile types possible
};
} t_tile;
typedef struct s_map
@ -67,6 +87,7 @@ typedef struct s_map
t_tile *map;
char **fraw;
t_img *texture[4];
t_texture texture_[4];
t_color bg_colors[2];
} t_map;
@ -86,6 +107,7 @@ typedef struct s_cli
char *file;
bool save;
bool help;
bool no_graphics;
} t_cli;
// -- error utils
@ -103,6 +125,7 @@ typedef enum e_error
ERROR_PARSE,
ERROR_CLI,
ERROR_MLX,
ERROR_TEXTURE_FORMAT,
ERROR_IMPLEM,
} t_error;
@ -111,6 +134,8 @@ typedef enum e_error
typedef struct s_info
{
t_error last_error;
int errno_state;
t_xvar *mlx_ptr;
t_win_list *win_ptr;
t_map map;

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/30 16:43:20 by rparodi #+# #+# */
/* Updated: 2024/11/09 00:42:02 by bgoulard ### ########.fr */
/* Updated: 2024/11/27 11:57:28 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,5 +19,7 @@
# define RED "\x1b[31m"
# define BOLD_RED "\033[1;31m"
# define YELLOW "\x1b[33m"
# define BOLD_YELLOW "\033[1;33m"
# define RESET "\x1b[K\x1b[0m"
#endif

View file

@ -6,7 +6,7 @@
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/27 16:03:56 by bgoulard #+# #+# */
/* Updated: 2023/12/04 10:38:27 by bgoulard ### ########.fr */
/* Updated: 2024/11/18 16:38:56 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,5 +15,7 @@
// return elem n
void *ft_vec_at(t_vector *vec, size_t n)
{
if (n >= vec->count)
return (NULL);
return (vec->datas[n]);
}

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/11 19:53:42 by rparodi #+# #+# */
/* Updated: 2024/11/26 13:40:17 by rparodi ### ########.fr */
/* Updated: 2024/11/28 13:55:09 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,11 +20,11 @@
int c3_frame_update(void *inf_ptr);
/* move player w keys and call to redraw screen */
int c3_keyhook(int keycode, t_info *info)
{
if (keycode == XK_Escape || keycode == 65307)
return (mlx_loop_end(info->mlx_ptr), EXIT_SUCCESS);
/* move player w keys and call to redraw screen */
return (EXIT_SUCCESS);
}
@ -55,6 +55,6 @@ int init_mlx_env(t_info *info)
mlx_hook(info->win_ptr, KeyPress, KeyPressMask, c3_keyhook, info);
mlx_hook(info->win_ptr, DestroyNotify, StructureNotifyMask, c3_redcross, info);
mlx_loop_hook(info->mlx_ptr, (int (*)())shelves_launch, &info);
/*mlx_loop_hook(info->mlx_ptr, c3_frame_update, info);*/
mlx_loop_hook(info->mlx_ptr, c3_frame_update, info);
return (NO_ERROR);
}

View file

@ -6,52 +6,317 @@
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/12 08:31:06 by bgoulard #+# #+# */
/* Updated: 2024/11/12 11:29:13 by bgoulard ### ########.fr */
/* Updated: 2024/11/27 11:53:06 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
// proj
#include "cub3d.h"
#include "ft_string.h"
#include "ft_optional.h"
#include "cub3d_struct.h"
// mlx
#include "mlx_functions.h"
// libft - types
#include "ft_vector_types.h"
#include "ft_optional_types.h"
// libft
#include "ft_math.h"
#include "ft_string.h"
#include "ft_vector.h"
#include "ft_optional.h"
// sys std
#include <fcntl.h>
#include <stdio.h>
#include <sys/types.h>
// steps:
// 1. load_map into a buffer
// 2. store the map while deleting trailing newlines
void *load_map(void *data)
void *load_file(void *data)
{
t_info *info = (t_info *)data;
char *file = NULL;
t_info *info;
char *file;
file = NULL;
info = (t_info *)data;
file = ft_fd_to_buff(info->map.fd);
if (file == NULL)
return (info->errno_state = errno,
info->last_error = ERROR_READ_FILE, NULL);
info->map.fraw = ft_split(file, '\n');
if (info->map.fraw == NULL)
return (info->errno_state = errno,
info->last_error = ERROR_MALLOC, NULL);
ft_free((void **)&file);
return (info->last_error = ERROR_IMPLEM, NULL);
info->last_error = NO_ERROR;
return (info);
}
bool is_identifier(const char *str, const char **id_str)
{
size_t i;
i = 0;
while (id_str[i])
{
if (ft_strstart_with(str, id_str[i]))
return (true);
i++;
}
return (false);
}
bool load_texture(t_info *info, const char *str, const char **id_str)
{
size_t i;
t_texture texture;
i = 0;
while (i < 4)
{
if (ft_strstart_with(str, id_str[i]))
{
texture.path = ft_strtrim(str + ft_strlen(id_str[i]), " ");
if (texture.path == NULL)
return (info->errno_state = errno,
info->last_error = ERROR_MALLOC, false);
if (ft_strend_with(texture.path, ".xpm") == false)
return (info->last_error = ERROR_TEXTURE_FORMAT, false);
texture.img = mlx_xpm_file_to_image(info->mlx_ptr, texture.path, \
&texture.width, &texture.height);
if (texture.img == NULL)
return (info->errno_state = errno,
info->last_error = ERROR_MLX, false);
return (info->map.texture[i] = texture, true);
}
i++;
}
return (false);
}
bool color_from_str(const char *str, t_color *color)
{
int col[4];
char **split;
split = ft_split(str, ',');
if (split == NULL)
return (false);
col[0] = ft_atoi(split[0]);
col[1] = ft_atoi(split[1]);
col[2] = ft_atoi(split[2]);
if (split[3])
col[3] = ft_atoi(split[3]);
else
col[3] = 255;
if (col[0] < 0 || col[0] > 255 || col[1] < 0 || col[1] > 255 || \
col[2] < 0 || col[2] > 255 || col[3] < 0 || col[3] > 255)
return (false);
*color = (t_color){.r = col[0], .g = col[1], .b = col[2], .a = col[3]};
ft_free_2d((void **)split);
return (true);
}
bool load_bg(t_info *info, const char *line, const char **id_str)
{
t_color color;
size_t i;
i = 0;
ft_bzero(&color, sizeof(t_color));
while (id_str[i])
{
if (ft_strstart_with(line, id_str[i]) && \
(color_from_str(line + ft_strlen(id_str[i]), &color) == false ||
color.a < 255))
return (info->last_error = ERROR_PARSE, false);
if (ft_strstart_with(id_str[i], "F "))
info->map.bg_colors[BG_FLR] = color;
else
info->map.bg_colors[BG_CLG] = color;
i++;
}
if (color.color == 0)
return (info->last_error = ERROR_PARSE, false);
return (true);
}
void *load_textures(void *data)
{
const char *id_str[] = {"NO ", "SO ", "WE ", "EA ", NULL};
t_info *info;
size_t i;
i = 0;
info = (t_info *)data;
while (info->map.fraw[i])
{
if (is_identifier(info->map.fraw[i], id_str) && \
load_texture(info, info->map.fraw[i], id_str) == false)
return (NULL);
i++;
}
return (info);
}
void *load_bgs(void *data)
{
const char *id_str[] = {"F ", "C ", NULL};
t_info *info;
size_t i;
i = 0;
info = (t_info *)data;
while (info->map.fraw[i])
{
if (is_identifier(info->map.fraw[i], id_str) && \
load_bg(info, info->map.fraw[i], id_str) == false)
return (NULL);
i++;
}
return (info);
}
void *ft_strchrs(const char *str, const char *chrs)
{
while (*str)
{
if (ft_strchr(chrs, *str))
return ((void *)str);
str++;
}
return (NULL);
}
void str_to_tile(const char *str, t_tile *tile, size_t size)
{
size_t i;
i = 0;
while (str[i])
{
if (str[i] == '1' || i[str] == ' ')
tile[i].raw_tile = WALL;
else
tile[i].raw_tile = EMPTY;
i++;
}
while (i < size)
tile[i++].raw_tile = WALL;
}
t_vector *load_vector(t_map *map)
{
const char *id_str__all[] = {"NO ", "SO ", "WE ", "EA ", "F ", "C ", NULL};
t_vector *str_map;
size_t i;
str_map = ft_vec_new();
if (str_map == NULL)
return (NULL);
i = 0;
while (map->fraw[i] &&
is_identifier(map->fraw[i], id_str__all))
i++;
while (map->fraw[i + map->size.y])
{
map->size.x = ft_max(map->size.x, ft_strlen(map->fraw[i]));
ft_vec_add(&str_map, map->fraw[i + map->size.y++]);
}
return (str_map);
}
void *load_tiles(void *data)
{
t_info *info;
t_vector *str_map;
size_t i;
t_dpoint pos;
info = (t_info *)data;
str_map = load_vector(&info->map);
if (!str_map)
return (info->last_error = ERROR_MALLOC, NULL);
info->map.map = ft_calloc(sizeof(t_tile), \
(info->map.size.y * info->map.size.x));
if (!info->map.map)
return (ft_vec_destroy(&str_map), \
info->last_error = ERROR_MALLOC, NULL);
i = 0;
ft_bzero(&pos, sizeof(t_dpoint));
while (ft_vec_at(str_map, i))
{
str_to_tile(ft_vec_at(str_map, i), info->map.map + \
(i * info->map.size.x), info->map.size.x);
if (ft_strchrs(ft_vec_at(str_map, i), "SNWE"))
{
if (pos.x != 0 || pos.y != 0 || i == 0)
return (ft_vec_destroy(&str_map), \
info->last_error = ERROR_PARSE, NULL);
pos.x = i + .5;
pos.y = ft_strchrs(ft_vec_at(str_map, i), "SNWE") - ft_vec_at(str_map, i) + .5;
info->player.pos = pos;
}
i++;
}
return (ft_vec_destroy(&str_map), info);
}
t_tile *c3_get_cell(t_tile *map, t_ipoint dimensions, t_ipoint pos)
{
return (map + (pos.y * dimensions.x + pos.x));
}
bool flood_fill(t_tile *tiles, t_ipoint pos, t_ipoint maxs)
{
t_tile *current;
size_t i;
const t_ipoint to_check[] = {
(t_ipoint){pos.x + 1, pos.y},
(t_ipoint){pos.x - 1, pos.y},
(t_ipoint){pos.x, pos.y + 1},
(t_ipoint){pos.x, pos.y - 1},
(t_ipoint){pos.x + 1, pos.y + 1},
(t_ipoint){pos.x - 1, pos.y + 1},
(t_ipoint){pos.x + 1, pos.y - 1},
(t_ipoint){pos.x - 1, pos.y - 1},
};
if (pos.x < 0 || pos.y < 0 || pos.x >= maxs.x || pos.y >= maxs.y)
return (false);
current = c3_get_cell(tiles, maxs, pos);
if (current->tile_visited == true || current->tile_type == WALL)
return (true);
current->tile_visited = true;
i = 0;
while (i != (sizeof(to_check) / sizeof(to_check[0])))
if (flood_fill(tiles, to_check[i++], maxs) == false)
return (false);
return (true);
}
void *traverse_map(void *data)
{
t_info *info = (t_info *)data;
t_info *info;
t_ipoint pos_start;
info->last_error = ERROR_IMPLEM;
return (NULL);
info = (t_info *)data;
pos_start = (t_ipoint){.x = info->player.pos.x, .y = info->player.pos.y};
if (flood_fill(info->map.map, pos_start, info->map.size) == false)
return (info->last_error = ERROR_PARSE, NULL);
return (info);
}
void parse_map(t_info *info)
{
t_optional opt = {OPT_NONE, NULL};
t_optional opt;
const t_data_tr_i function_list[] = {
load_map,
load_file,
load_textures,
load_bgs,
load_tiles,
traverse_map,
NULL,
};
opt.val = info;
opt.pres = OPT_SOME;
opt = (t_optional){.val = info, .pres = OPT_SOME};
info->map.path = info->cli_ctx.file;
if (ft_optional_chain(&opt, function_list) == false)
return (c3_perror(info), (void)0);

View file

@ -6,7 +6,7 @@
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/12 06:02:54 by bgoulard #+# #+# */
/* Updated: 2024/11/12 06:21:09 by bgoulard ### ########.fr */
/* Updated: 2024/11/18 12:12:29 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
@ -36,6 +36,6 @@ int c3_frame_update(void *inf_ptr)
info = inf_ptr;
mlx_clear_window(info->mlx_ptr, info->win_ptr);
ft_putendl_fd("update called\n", STDOUT_FILENO);
// ft_putendl_fd("update called\n", STDOUT_FILENO);
return (EXIT_SUCCESS);
}

View file

@ -6,7 +6,7 @@
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/09 01:11:01 by bgoulard #+# #+# */
/* Updated: 2024/11/12 11:06:44 by bgoulard ### ########.fr */
/* Updated: 2024/11/18 17:14:06 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,15 +26,24 @@ static void cleanup_map(t_map *map)
(close(map->fd), map->fd = 0);
if (map->fraw)
(ft_free_2d((void **)map->fraw), map->fraw = NULL);
if (map->map)
ft_free((void **)&map->map);
}
static void cleanup_mlx(t_info *info)
{
if (info->mlx_ptr && info->win_ptr)
if (!info->mlx_ptr)
return ;
if (info->win_ptr)
mlx_destroy_window(info->mlx_ptr, info->win_ptr);
if (info->mlx_ptr)
for (int i = 0; i < 4; i++)
{
if (info->map.texture[i].img)
mlx_destroy_image(info->mlx_ptr, info->map.texture[i].img);
if (info->map.texture[i].path)
ft_free((void **)&info->map.texture[i].path);
}
mlx_destroy_display(info->mlx_ptr);
if (info->mlx_ptr)
ft_free((void **)&info->mlx_ptr);
}

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/31 11:09:00 by rparodi #+# #+# */
/* Updated: 2024/11/12 08:45:03 by bgoulard ### ########.fr */
/* Updated: 2024/11/27 12:00:34 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,7 +17,7 @@
#include <unistd.h>
const char *g_error_message[] = {
const char *const g_error_message[] = {
"no error",
"unknown error",
"could not open file",
@ -29,6 +29,7 @@ const char *g_error_message[] = {
"parse error",
"cli error",
"mlx error",
"texture format error",
"not implemented",
};
@ -36,10 +37,10 @@ void c3_perror(t_info *info)
{
if (info->last_error == NO_ERROR)
return ;
print_error(g_error_message[info->last_error]);
print_error(g_error_message[info->last_error], info->errno_state);
}
void print_error(const char *msg)
void print_error(const char *msg, int state)
{
ft_putstr_fd(BOLD_RED, STDERR_FILENO);
ft_putstr_fd("Error:\n", STDERR_FILENO);
@ -47,5 +48,13 @@ void print_error(const char *msg)
ft_putstr_fd(RED, STDERR_FILENO);
ft_putstr_fd(msg, STDERR_FILENO);
ft_putstr_fd(RESET, STDERR_FILENO);
if (state != 0)
{
ft_putstr_fd(YELLOW, STDERR_FILENO);
ft_putstr_fd(" due to:\n", STDERR_FILENO);
ft_putstr_fd(BOLD_YELLOW, STDERR_FILENO);
ft_putstr_fd(ft_strerror(state), STDERR_FILENO);
ft_putstr_fd(RESET, STDERR_FILENO);
}
ft_putstr_fd(".\n", STDERR_FILENO);
}

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/30 16:30:03 by rparodi #+# #+# */
/* Updated: 2024/11/18 14:31:35 by rparodi ### ########.fr */
/* Updated: 2024/11/28 13:55:42 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,6 +18,7 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
void blank(t_info *info);
@ -26,7 +27,9 @@ void blank(t_info *info);
void dump_info(t_info *info)
{
const char *bool_str[2] = {"True", "False"};
size_t i;
i = 0;
printf("t_info:\n");
printf("\tcli_ctx:\n");
printf("\t\tfile: %s\n", info->cli_ctx.file);
@ -37,9 +40,13 @@ void dump_info(t_info *info)
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);
for (size_t i = 0; info->map.fraw[i]; i++)
printf("\t\tplayer_pos:\t(x:%lf, y:%lf)\n", info->map.player_pos.x, \
info->map.player_pos.y);
while (info->map.fraw[i])
{
printf("\t\tmap.fraw[%zu]: %s\n", i, info->map.fraw[i]);
i++;
}
}
void check_err(t_info *info)
@ -52,25 +59,28 @@ void check_err(t_info *info)
return (info->last_error = ERROR_EXTENSION_FILE, (void)0);
info->map.fd = open(info->cli_ctx.file, O_RDONLY);
if (info->map.fd == -1)
return (info->last_error = ERROR_OPEN_FILE, (void)0);
return (info->errno_state = errno,
info->last_error = ERROR_OPEN_FILE, (void)0);
}
void run_cub3d(t_info *info)
{
blank(info);
if (init_mlx_env(info) != NO_ERROR)
return ;
parse_map(info);
if (info->cli_ctx.debug)
dump_info(info);
if (info->last_error != NO_ERROR)
return ;
if (info->cli_ctx.no_graphics)
printf("no graphics mode\n");
// todo: here
// - validity check
init_mlx_env(info);
printf("launching mlx\n");
mlx_loop(info->mlx_ptr);
// - game loop : already loops over the mlx_ptr
// -> get events if key pressed move player + run math to re-draw screen
// - mlx cleanup : already called in parent function deprecated to call here
// -> previous 'segfault' were due to someone calling cleaup instead of
// mlx_loop_end
}
/// @brief main function of the cub3d executable

View file

@ -6,7 +6,7 @@
/* 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 */
/* Updated: 2024/11/27 11:35:08 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
@ -25,6 +25,7 @@ int c3_options(t_info *info, int argc, char *argv[])
{"debug", 'd', c3_set_debug, 0},
{"save", 's', c3_set_save, 0},
{"help", 'h', c3_print_help, 0},
{"parse-only", 'p', c3_set_parse_excl, 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.

View file

@ -6,13 +6,21 @@
/* 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 */
/* Updated: 2024/11/27 11:35:14 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d_struct.h"
#include "ft_string.h"
void c3_set_parse_excl(void *usr_control_struct)
{
t_cli *cli_ctx;
cli_ctx = (t_cli *)usr_control_struct;
cli_ctx->no_graphics = true;
}
void c3_set_file(void *usr_control_struct, const char *arg)
{
t_cli *cli_ctx;
@ -40,13 +48,14 @@ void c3_set_save(void *usr_control_struct)
void c3_print_help(void *usr_control_struct)
{
t_cli *cli_ctx;
const char *help_str = \
"Usage: cub3d [options] <file>\nOptions:\n" \
"\t-f, --file <file> : specify the file to load\n" \
"\t-d, --debug : enable debug mode\n" \
"\t-s, --save : save the state of the 'game' when closing\n" \
"\t-h, --help : print this help\n";
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);
ft_putstr_fd(help_str, STDOUT_FILENO);
}