feat: added maps, added readfile to parsing
This commit is contained in:
parent
4db733648e
commit
e4d2dfda21
19 changed files with 282 additions and 41 deletions
9
.clangd
9
.clangd
|
|
@ -1,12 +1,11 @@
|
||||||
CompileFlags:
|
CompileFlags:
|
||||||
Add:
|
Add:
|
||||||
- "-Werror"
|
- "-Werror -Wextra -Wall"
|
||||||
- "-Wextra"
|
|
||||||
- "-Wall"
|
|
||||||
- "-g3"
|
|
||||||
- "-I/opt/X11/include"
|
- "-I/opt/X11/include"
|
||||||
- "-I/Users/raphael/Documents/42_cursus/circle4/Cub3D/includes"
|
- "-I/Users/raphael/Documents/42_cursus/circle4/Cub3D/includes"
|
||||||
- "-I/Users/raphael/Documents/42_cursus/circle4/Cub3D/includes/include"
|
- "-I/Users/raphael/Documents/42_cursus/circle4/Cub3D/includes/include"
|
||||||
# - "-I/Users/raphael/Documents/42_cursus/circle4/Cub3D/minilibx-linux"
|
|
||||||
- "-I/home/iron/Documents/code/42school/Cub3D/includes"
|
- "-I/home/iron/Documents/code/42school/Cub3D/includes"
|
||||||
- "-I/home/iron/Documents/code/42school/Cub3D/includes/include"
|
- "-I/home/iron/Documents/code/42school/Cub3D/includes/include"
|
||||||
|
- "-I/home/bgoulard/Documents/projects/shared/common/Cub3D/includes"
|
||||||
|
- "-I/home/bgoulard/Documents/projects/shared/common/Cub3D/includes/include"
|
||||||
|
- "-xc"
|
||||||
|
|
|
||||||
3
Makefile
3
Makefile
|
|
@ -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/12 06:12:02 by bgoulard ### ########.fr #
|
# Updated: 2024/11/12 09:17:25 by bgoulard ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -45,6 +45,7 @@ SRC =\
|
||||||
raycast/frame_update.c \
|
raycast/frame_update.c \
|
||||||
mlx_layer/mlx_init.c \
|
mlx_layer/mlx_init.c \
|
||||||
parsing/arguments.c \
|
parsing/arguments.c \
|
||||||
|
parsing/map.c \
|
||||||
sources/main.c \
|
sources/main.c \
|
||||||
sources/cleanups.c \
|
sources/cleanups.c \
|
||||||
sources/options.c \
|
sources/options.c \
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* 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/11 21:33:28 by rparodi ### ########.fr */
|
/* Updated: 2024/11/12 08:33:12 by bgoulard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -21,11 +21,16 @@
|
||||||
# include <stdbool.h>
|
# include <stdbool.h>
|
||||||
|
|
||||||
int init_mlx_env(t_info *info);
|
int init_mlx_env(t_info *info);
|
||||||
|
|
||||||
void cleanup_info(t_info *info);
|
void cleanup_info(t_info *info);
|
||||||
|
|
||||||
int c3_options(t_info *info, int argc, char *argv[]);
|
int c3_options(t_info *info, int argc, char *argv[]);
|
||||||
void c3_perror(t_info *info);
|
void c3_perror(t_info *info);
|
||||||
void print_error(const char *msg);
|
void print_error(const char *msg);
|
||||||
|
|
||||||
|
void parse_map(t_info *info);
|
||||||
void parse_args(char *arg, t_info *inf);
|
void parse_args(char *arg, t_info *inf);
|
||||||
|
|
||||||
int main(int argc, char *argv[]);
|
int main(int argc, char *argv[]);
|
||||||
|
|
||||||
#endif /* CUB3D_H */
|
#endif /* CUB3D_H */
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/11/08 23:55:29 by bgoulard #+# #+# */
|
/* Created: 2024/11/08 23:55:29 by bgoulard #+# #+# */
|
||||||
/* Updated: 2024/11/11 21:34:38 by rparodi ### ########.fr */
|
/* Updated: 2024/11/12 11:05:49 by bgoulard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -63,7 +63,9 @@ typedef struct s_map
|
||||||
t_dpoint player_pos;
|
t_dpoint player_pos;
|
||||||
t_ipoint size;
|
t_ipoint size;
|
||||||
t_tile *map;
|
t_tile *map;
|
||||||
char **raw;
|
char **fraw;
|
||||||
|
t_img texture[4];
|
||||||
|
t_color bg_colors[2];
|
||||||
} t_map;
|
} t_map;
|
||||||
|
|
||||||
// -- player utils
|
// -- player utils
|
||||||
|
|
@ -89,16 +91,17 @@ typedef struct s_cli
|
||||||
typedef enum e_error
|
typedef enum e_error
|
||||||
{
|
{
|
||||||
NO_ERROR = 0,
|
NO_ERROR = 0,
|
||||||
UNKNOWN_ERROR,
|
ERROR_UNKNOWN,
|
||||||
OPEN_FILE_ERROR,
|
ERROR_OPEN_FILE,
|
||||||
READ_FILE_ERROR,
|
ERROR_READ_FILE,
|
||||||
EXTENSION_FILE_ERROR,
|
ERROR_EXTENSION_FILE,
|
||||||
NAME_FILE_ERROR,
|
ERROR_NAME_FILE,
|
||||||
MISSING_FILE_ERROR,
|
ERROR_MISSING_FILE,
|
||||||
MALLOC_ERROR,
|
ERROR_MALLOC,
|
||||||
PARSE_ERROR,
|
ERROR_PARSE,
|
||||||
CLI_ERROR,
|
ERROR_CLI,
|
||||||
MLX_ERROR
|
ERROR_MLX,
|
||||||
|
ERROR_IMPLEM,
|
||||||
} t_error;
|
} t_error;
|
||||||
|
|
||||||
// -- main struct
|
// -- main struct
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/18 19:52:02 by bgoulard #+# #+# */
|
/* Created: 2024/05/18 19:52:02 by bgoulard #+# #+# */
|
||||||
/* Updated: 2024/06/13 16:46:24 by bgoulard ### ########.fr */
|
/* Updated: 2024/11/12 09:38:37 by bgoulard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -31,12 +31,12 @@ char *ft_fd_to_buff(int fd)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
buff[ret] = '\0';
|
buff[ret] = '\0';
|
||||||
file = ft_strdup(buff);
|
file = ft_strdup(buff);
|
||||||
while (ret == BUFFER_SIZE)
|
while (ret == BUFFER_SIZE && file)
|
||||||
{
|
{
|
||||||
ret = read(fd, buff, BUFFER_SIZE);
|
ret = read(fd, buff, BUFFER_SIZE);
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
return (ft_free((void **)&file), NULL);
|
return (ft_free((void **)&file), NULL);
|
||||||
buff[ret] = '\0';
|
buff[ret + 1 * (ret == 0)] = '\0';
|
||||||
prev = file;
|
prev = file;
|
||||||
file = ft_strjoin(file, buff);
|
file = ft_strjoin(file, buff);
|
||||||
ft_free((void **)&prev);
|
ft_free((void **)&prev);
|
||||||
|
|
|
||||||
23
maps/bad_format_color_c.cub
Normal file
23
maps/bad_format_color_c.cub
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
SO ./textures/png_ugly.png
|
||||||
|
NO ./textures/png_ugly.png
|
||||||
|
WE ./textures/png_pretty.png
|
||||||
|
EA ./textures/png_pretty.png
|
||||||
|
|
||||||
|
F 255,255,255
|
||||||
|
C 255,,255
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
111
|
||||||
|
1N1
|
||||||
|
111
|
||||||
23
maps/bad_format_color_f.cub
Normal file
23
maps/bad_format_color_f.cub
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
SO ./textures/png_ugly.png
|
||||||
|
NO ./textures/png_ugly.png
|
||||||
|
WE ./textures/png_pretty.png
|
||||||
|
EA ./textures/png_pretty.png
|
||||||
|
|
||||||
|
F 255,255,
|
||||||
|
C 255,255,255
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
111
|
||||||
|
1N1
|
||||||
|
111
|
||||||
24
maps/bad_format_map_char.cub
Normal file
24
maps/bad_format_map_char.cub
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
SO ./textures/png_ugly.png
|
||||||
|
NO ./textures/png_ugly.png
|
||||||
|
WE ./textures/png_pretty.png
|
||||||
|
EA ./textures/png_pretty.png
|
||||||
|
|
||||||
|
F 255,255,255
|
||||||
|
C 255,255,255
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
111
|
||||||
|
1N11111
|
||||||
|
1000xy1
|
||||||
|
1111111
|
||||||
23
maps/bad_format_map_open.cub
Normal file
23
maps/bad_format_map_open.cub
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
SO ./textures/png_ugly.png
|
||||||
|
NO ./textures/png_ugly.png
|
||||||
|
WE ./textures/png_pretty.png
|
||||||
|
EA ./textures/png_pretty.png
|
||||||
|
|
||||||
|
F 255,255,255
|
||||||
|
C 255,255,255
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
1111
|
||||||
|
00N1
|
||||||
|
1111
|
||||||
23
maps/bad_format_texture.cub
Normal file
23
maps/bad_format_texture.cub
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
SO ./textures/png_ugly.png
|
||||||
|
NO = ./textures/png_ugly.png
|
||||||
|
WE ./textures/png_pretty.png
|
||||||
|
EA ./textures/png_pretty.png
|
||||||
|
|
||||||
|
F 255,255,255
|
||||||
|
C 255,255,255
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
111
|
||||||
|
1N1
|
||||||
|
111
|
||||||
23
maps/bad_perm.cub
Normal file
23
maps/bad_perm.cub
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
SO ./textures/png_ugly.png
|
||||||
|
NO ./textures/png_ugly.png
|
||||||
|
WE ./textures/png_pretty.png
|
||||||
|
EA ./textures/png_pretty.png
|
||||||
|
|
||||||
|
F 255,255,255
|
||||||
|
C 255,255,255
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
111
|
||||||
|
1N1
|
||||||
|
111
|
||||||
23
maps/valid_01.cub
Normal file
23
maps/valid_01.cub
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
SO ./textures/png_ugly.png
|
||||||
|
NO ./textures/png_ugly.png
|
||||||
|
WE ./textures/png_pretty.png
|
||||||
|
EA ./textures/png_pretty.png
|
||||||
|
|
||||||
|
F 255,255,255
|
||||||
|
C 255,255,255
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
111
|
||||||
|
1N1
|
||||||
|
111
|
||||||
|
|
@ -48,10 +48,10 @@ int init_mlx_env(t_info *info)
|
||||||
{
|
{
|
||||||
info->mlx_ptr = mlx_init();
|
info->mlx_ptr = mlx_init();
|
||||||
if (!info->mlx_ptr)
|
if (!info->mlx_ptr)
|
||||||
return (MLX_ERROR);
|
return (ERROR_MLX);
|
||||||
info->win_ptr = c3_init_mlx_window(info);
|
info->win_ptr = c3_init_mlx_window(info);
|
||||||
if (!info->win_ptr)
|
if (!info->win_ptr)
|
||||||
return (MLX_ERROR);
|
return (ERROR_MLX);
|
||||||
mlx_hook(info->win_ptr, KeyPress, KeyPressMask, c3_keyhook, info);
|
mlx_hook(info->win_ptr, KeyPress, KeyPressMask, c3_keyhook, info);
|
||||||
mlx_hook(info->win_ptr, DestroyNotify, StructureNotifyMask, c3_redcross, info);
|
mlx_hook(info->win_ptr, DestroyNotify, StructureNotifyMask, c3_redcross, info);
|
||||||
mlx_loop_hook(info->mlx_ptr, c3_frame_update, info);
|
mlx_loop_hook(info->mlx_ptr, c3_frame_update, info);
|
||||||
|
|
|
||||||
|
|
@ -24,11 +24,11 @@
|
||||||
void parse_args(char *arg, t_info *inf)
|
void parse_args(char *arg, t_info *inf)
|
||||||
{
|
{
|
||||||
if (arg == NULL && inf->cli_ctx.file == NULL)
|
if (arg == NULL && inf->cli_ctx.file == NULL)
|
||||||
return (inf->last_error = MISSING_FILE_ERROR, (void)0);
|
return (inf->last_error = ERROR_MISSING_FILE, (void)0);
|
||||||
if (arg && ft_strlen(arg) < 5)
|
if (arg && ft_strlen(arg) < 5)
|
||||||
return (inf->last_error = NAME_FILE_ERROR, (void)0);
|
return (inf->last_error = ERROR_NAME_FILE, (void)0);
|
||||||
if (arg && ft_strend_with(arg, FILE_EXTENSION) == false)
|
if (arg && ft_strend_with(arg, FILE_EXTENSION) == false)
|
||||||
return (inf->last_error = EXTENSION_FILE_ERROR, (void)0);
|
return (inf->last_error = ERROR_EXTENSION_FILE, (void)0);
|
||||||
if (arg && inf->cli_ctx.file == NULL)
|
if (arg && inf->cli_ctx.file == NULL)
|
||||||
inf->cli_ctx.file = ft_strdup(arg);
|
inf->cli_ctx.file = ft_strdup(arg);
|
||||||
inf->last_error = NO_ERROR;
|
inf->last_error = NO_ERROR;
|
||||||
|
|
|
||||||
58
parsing/map.c
Normal file
58
parsing/map.c
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* map.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* 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 */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "cub3d.h"
|
||||||
|
|
||||||
|
#include "ft_string.h"
|
||||||
|
#include "ft_optional.h"
|
||||||
|
#include "ft_optional_types.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)
|
||||||
|
{
|
||||||
|
t_info *info = (t_info *)data;
|
||||||
|
char *file = NULL;
|
||||||
|
|
||||||
|
file = ft_fd_to_buff(info->map.fd);
|
||||||
|
info->map.fraw = ft_split(file, '\n');
|
||||||
|
|
||||||
|
ft_free((void **)&file);
|
||||||
|
return (info->last_error = ERROR_IMPLEM, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *traverse_map(void *data)
|
||||||
|
{
|
||||||
|
t_info *info = (t_info *)data;
|
||||||
|
|
||||||
|
info->last_error = ERROR_IMPLEM;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_map(t_info *info)
|
||||||
|
{
|
||||||
|
t_optional opt = {OPT_NONE, NULL};
|
||||||
|
const t_data_tr_i function_list[] = {
|
||||||
|
load_map,
|
||||||
|
traverse_map,
|
||||||
|
NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
opt.val = info;
|
||||||
|
opt.pres = OPT_SOME;
|
||||||
|
info->map.path = info->cli_ctx.file;
|
||||||
|
if (ft_optional_chain(&opt, function_list) == false)
|
||||||
|
return (c3_perror(info), (void)0);
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/11/09 01:11:01 by bgoulard #+# #+# */
|
/* Created: 2024/11/09 01:11:01 by bgoulard #+# #+# */
|
||||||
/* Updated: 2024/11/12 05:49:23 by bgoulard ### ########.fr */
|
/* Updated: 2024/11/12 11:06:44 by bgoulard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -24,12 +24,16 @@ static void cleanup_map(t_map *map)
|
||||||
{
|
{
|
||||||
if (map->fd)
|
if (map->fd)
|
||||||
(close(map->fd), map->fd = 0);
|
(close(map->fd), map->fd = 0);
|
||||||
|
if (map->fraw)
|
||||||
|
(ft_free_2d((void **)map->fraw), map->fraw = NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cleanup_mlx(t_info *info)
|
static void cleanup_mlx(t_info *info)
|
||||||
{
|
{
|
||||||
mlx_destroy_window(info->mlx_ptr, info->win_ptr);
|
if (info->mlx_ptr && info->win_ptr)
|
||||||
mlx_destroy_display(info->mlx_ptr);
|
mlx_destroy_window(info->mlx_ptr, info->win_ptr);
|
||||||
|
if (info->mlx_ptr)
|
||||||
|
mlx_destroy_display(info->mlx_ptr);
|
||||||
if (info->mlx_ptr)
|
if (info->mlx_ptr)
|
||||||
ft_free((void **)&info->mlx_ptr);
|
ft_free((void **)&info->mlx_ptr);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* 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/11/10 16:13:25 by rparodi ### ########.fr */
|
/* Updated: 2024/11/12 08:45:03 by bgoulard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,7 +20,6 @@
|
||||||
const char *g_error_message[] = {
|
const char *g_error_message[] = {
|
||||||
"no error",
|
"no error",
|
||||||
"unknown error",
|
"unknown error",
|
||||||
|
|
||||||
"could not open file",
|
"could not open file",
|
||||||
"could not read file",
|
"could not read file",
|
||||||
"bad file extension",
|
"bad file extension",
|
||||||
|
|
@ -30,6 +29,7 @@ const char *g_error_message[] = {
|
||||||
"parse error",
|
"parse error",
|
||||||
"cli error",
|
"cli error",
|
||||||
"mlx error",
|
"mlx error",
|
||||||
|
"not implemented",
|
||||||
};
|
};
|
||||||
|
|
||||||
void c3_perror(t_info *info)
|
void c3_perror(t_info *info)
|
||||||
|
|
@ -47,5 +47,5 @@ void print_error(const char *msg)
|
||||||
ft_putstr_fd(RED, STDERR_FILENO);
|
ft_putstr_fd(RED, STDERR_FILENO);
|
||||||
ft_putstr_fd(msg, STDERR_FILENO);
|
ft_putstr_fd(msg, STDERR_FILENO);
|
||||||
ft_putstr_fd(RESET, STDERR_FILENO);
|
ft_putstr_fd(RESET, STDERR_FILENO);
|
||||||
ft_putstr_fd("\n", STDERR_FILENO);
|
ft_putstr_fd(".\n", STDERR_FILENO);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* 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/12 06:20:46 by bgoulard ### ########.fr */
|
/* Updated: 2024/11/12 09:50:01 by bgoulard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -36,23 +36,30 @@ void dump_info(t_info *info)
|
||||||
printf("\t\tfd:%d\n", info->map.fd);
|
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\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);
|
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\tmap.fraw[%zu]: %s\n", i, info->map.fraw[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_err(t_info *info)
|
void check_err(t_info *info)
|
||||||
{
|
{
|
||||||
if (info->cli_ctx.file == NULL)
|
if (info->cli_ctx.file == NULL)
|
||||||
return (info->last_error = MISSING_FILE_ERROR, (void)0);
|
return (info->last_error = ERROR_MISSING_FILE, (void)0);
|
||||||
else if (ft_strlen(info->cli_ctx.file) < 5)
|
else if (ft_strlen(info->cli_ctx.file) < 5)
|
||||||
return (info->last_error = NAME_FILE_ERROR, (void)0);
|
return (info->last_error = ERROR_NAME_FILE, (void)0);
|
||||||
else if (ft_strend_with(info->cli_ctx.file, FILE_EXTENSION) == false)
|
else if (ft_strend_with(info->cli_ctx.file, FILE_EXTENSION) == false)
|
||||||
return (info->last_error = EXTENSION_FILE_ERROR, (void)0);
|
return (info->last_error = ERROR_EXTENSION_FILE, (void)0);
|
||||||
info->map.fd = open(info->cli_ctx.file, O_RDONLY);
|
info->map.fd = open(info->cli_ctx.file, O_RDONLY);
|
||||||
if (info->map.fd == -1)
|
if (info->map.fd == -1)
|
||||||
return (info->last_error = OPEN_FILE_ERROR, (void)0);
|
return (info->last_error = ERROR_OPEN_FILE, (void)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void run_cub3d(t_info *info)
|
void run_cub3d(t_info *info)
|
||||||
{
|
{
|
||||||
|
parse_map(info);
|
||||||
|
if (info->cli_ctx.debug)
|
||||||
|
dump_info(info);
|
||||||
|
if (info->last_error != NO_ERROR)
|
||||||
|
return ;
|
||||||
// todo: here
|
// todo: here
|
||||||
// - parse map
|
// - parse map
|
||||||
// - validity check
|
// - validity check
|
||||||
|
|
@ -65,6 +72,10 @@ void run_cub3d(t_info *info)
|
||||||
// mlx_loop_end
|
// mlx_loop_end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief main function of the cub3d executable
|
||||||
|
/// @param file_arg the file path to the .cub file
|
||||||
|
/// @param info the info structure
|
||||||
|
/// @return false (0) if no error, true (1) if an error
|
||||||
int main_cub3d(char *file_arg, t_info *info)
|
int main_cub3d(char *file_arg, t_info *info)
|
||||||
{
|
{
|
||||||
if (info->cli_ctx.help)
|
if (info->cli_ctx.help)
|
||||||
|
|
@ -74,10 +85,8 @@ int main_cub3d(char *file_arg, t_info *info)
|
||||||
check_err(info);
|
check_err(info);
|
||||||
if (info->last_error != NO_ERROR)
|
if (info->last_error != NO_ERROR)
|
||||||
return (c3_perror(info), cleanup_info(info), EXIT_FAILURE);
|
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);
|
run_cub3d(info);
|
||||||
return (cleanup_info(info), info->last_error);
|
return (cleanup_info(info), info->last_error != NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue