Fix: no longer launch window in case of parse error, catch error on multiple player in map
This commit is contained in:
parent
b26a84b9bb
commit
4d2b8cb60b
7 changed files with 70 additions and 21 deletions
1
Makefile
1
Makefile
|
|
@ -43,6 +43,7 @@ LDFLAGS += $(MLXFLAGS)
|
|||
|
||||
SRC =\
|
||||
ft_addons/ft_inrange.c \
|
||||
ft_addons/ft_strchrs.c \
|
||||
mlx_layer/mlx_init.c \
|
||||
mlx_layer/looks.c \
|
||||
mlx_layer/mooves.c \
|
||||
|
|
|
|||
24
ft_addons/ft_strchrs.c
Normal file
24
ft_addons/ft_strchrs.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchrs.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/20 15:56:28 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/12/20 15:58:47 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
void *ft_strchrs(const char *str, const char *chrs)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
if (ft_strchr(chrs, *str))
|
||||
return ((void *)str);
|
||||
str++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/28 13:53:54 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/12/20 14:47:00 by bgoulard ### ########.fr */
|
||||
/* Updated: 2024/12/20 15:42:21 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -138,6 +138,7 @@ typedef enum e_error
|
|||
ERROR_PARSE_NO_BG_COLOR,
|
||||
ERROR_PARSE_ALREADY_SET,
|
||||
ERROR_PARSE_META_IN_MAP,
|
||||
ERROR_PARSE_MULTIPLE_PLAYER,
|
||||
ERROR_CLI,
|
||||
ERROR_MLX,
|
||||
ERROR_TEXTURE_FORMAT,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/16 06:09:01 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/12/16 15:34:31 by bgoulard ### ########.fr */
|
||||
/* Updated: 2024/12/20 15:57:10 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -30,4 +30,6 @@ bool ft_inrange_ex(int value, int min, int max);
|
|||
/// @return true if the value is in the range, false otherwise
|
||||
bool ft_inrange(int value, int min, int max);
|
||||
|
||||
void *ft_strchrs(const char *str, const char *chrs);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/01 17:47:15 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/12/20 14:46:40 by bgoulard ### ########.fr */
|
||||
/* Updated: 2024/12/20 15:59:04 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,22 +15,13 @@
|
|||
#include "cub3d_parsing.h"
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_addons.h"
|
||||
#include "ft_vector.h"
|
||||
#include "ft_math.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void *ft_strchrs(const char *str, const char *chrs)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
if (ft_strchr(chrs, *str))
|
||||
return ((void *)str);
|
||||
str++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int str_to_tile(const char *str, t_tile *tile, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
|
|
@ -74,15 +65,44 @@ t_vector *load_vector(t_map *map)
|
|||
return (str_map);
|
||||
}
|
||||
|
||||
#define EPMP ERROR_PARSE_MULTIPLE_PLAYER
|
||||
|
||||
static bool multiple_player_same_line(const char *str)
|
||||
{
|
||||
const bool p_symbol[8] = {\
|
||||
!ft_strchr(str, 'S'), !ft_strchr(str, 'E'), !ft_strchr(str, 'W'), \
|
||||
!ft_strchr(str, 'N'), !(ft_strrchr(str, 'N') - ft_strchr(str, 'N')), \
|
||||
!(ft_strrchr(str, 'E') - ft_strchr(str, 'E')), \
|
||||
!(ft_strrchr(str, 'W') - ft_strchr(str, 'W')), \
|
||||
!(ft_strrchr(str, 'S') - ft_strchr(str, 'S')), };
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
while (i < 4)
|
||||
{
|
||||
j = 0;
|
||||
while (j < 4)
|
||||
if (p_symbol[j++] == true && p_symbol[i] == true)
|
||||
return (true);
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while (i < 4)
|
||||
if (p_symbol[i++ + 4])
|
||||
return (true);
|
||||
return (false);
|
||||
}
|
||||
|
||||
int set_player(t_info *info, int i, t_vector *str_map)
|
||||
{
|
||||
t_dpoint pos;
|
||||
char *str;
|
||||
|
||||
ft_bzero(&pos, sizeof(t_dpoint));
|
||||
if (info->player.pos.x != 0 || info->player.pos.y != 0 || i == 0)
|
||||
return (ft_vec_destroy(&str_map), info->last_error = ERROR_PARSE, \
|
||||
EXIT_FAILURE);
|
||||
if (info->player.pos.x != 0 || info->player.pos.y != 0 || i == 0 || \
|
||||
multiple_player_same_line(ft_vec_at(str_map, i)))
|
||||
return (ft_vec_destroy(&str_map), sv_errno(info, EPMP), EXIT_FAILURE);
|
||||
str = ft_strchrs(ft_vec_at(str_map, i), "SNWE");
|
||||
pos.y = i + .5;
|
||||
pos.x = str - (char *)ft_vec_at(str_map, i) + .5;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/31 11:09:00 by rparodi #+# #+# */
|
||||
/* Updated: 2024/12/20 14:43:52 by bgoulard ### ########.fr */
|
||||
/* Updated: 2024/12/20 15:52:43 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -41,6 +41,7 @@ const char **get_error_message(void)
|
|||
err_msg[ERROR_TEXTURE_MISSING] = "texture missing";
|
||||
err_msg[ERROR_PARSE_NO_BG_COLOR] = "no background color provided";
|
||||
err_msg[ERROR_PARSE_META_IN_MAP] = "meta data in map (should be above)";
|
||||
err_msg[ERROR_PARSE_MULTIPLE_PLAYER] = "multiple player in map";
|
||||
return (err_msg);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/30 16:30:03 by rparodi #+# #+# */
|
||||
/* Updated: 2024/12/17 17:17:12 by bgoulard ### ########.fr */
|
||||
/* Updated: 2024/12/20 15:54:59 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -41,12 +41,12 @@ void run_cub3d(t_info *info)
|
|||
if (!info->mlx_ptr)
|
||||
return (sv_errno(info, ERROR_MLX), (void)0);
|
||||
parse_map(info);
|
||||
if (info->last_error != NO_ERROR)
|
||||
return ;
|
||||
if (init_mlx_env(info) != NO_ERROR)
|
||||
return (c3_perror(info));
|
||||
if (info->cli_ctx.debug)
|
||||
ft_putstr_fd("no debug mod on production run", STDERR_FILENO);
|
||||
if (info->last_error != NO_ERROR)
|
||||
return ;
|
||||
if (info->cli_ctx.no_graphics == true)
|
||||
return ;
|
||||
info->camera.screen_buff = mlx_new_image(info->mlx_ptr, info->screen_size.x,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue