fix empty line in map
This commit is contained in:
parent
1d4dcf811b
commit
5da1a4b1c9
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/02/13 16:30:59 by apommier #+# #+# */
|
||||
/* Updated: 2022/06/15 18:42:10 by apommier ### ########.fr */
|
||||
/* Updated: 2022/06/15 21:39:57 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -113,9 +113,14 @@ char *transform_map(char **double_map, t_data *img);
|
||||
int check_texture_color(char **tab, t_data *img);
|
||||
int check_map(char **av, t_data *img);
|
||||
void ft_exit(char *str, t_data *img);
|
||||
|
||||
void set_back(t_data *img);
|
||||
unsigned char *get_texture(char type, char *path, t_data *img);
|
||||
int get_color(char one, char two, char three);
|
||||
void set_pixel(t_data *img, int color, int x, int y);
|
||||
void get_file_size(char *path, t_data *img, int *count, int fd);
|
||||
void get_map_size(char *path, t_data *img, int *count, int fd);
|
||||
|
||||
double reset_angle(double angle);
|
||||
double deg_to_rad(double angle);
|
||||
void draw_ray(t_data *img);
|
||||
|
||||
@ -12,43 +12,6 @@
|
||||
|
||||
#include "../../includes/Cub3D.h"
|
||||
|
||||
int get_color(char R, char G, char B)
|
||||
{
|
||||
int color;
|
||||
|
||||
color = 0;
|
||||
color = color << 8;
|
||||
color += R;
|
||||
color = color << 8;
|
||||
color += G;
|
||||
color = color << 8;
|
||||
color += B;
|
||||
return (color);
|
||||
}
|
||||
|
||||
void set_pixel(t_data *img, int color, int x, int y)
|
||||
{
|
||||
int pixel;
|
||||
|
||||
if (y < 0 || y > 520 || x < 0 || x > 960)
|
||||
return ;
|
||||
pixel = (y * img->size_line) + (x * 4);
|
||||
if (img->endian == 1)
|
||||
{
|
||||
img->buffer[pixel + 0] = 0;
|
||||
img->buffer[pixel + 1] = (color >> 16) & 0xFF;
|
||||
img->buffer[pixel + 2] = (color >> 8) & 0xFF;
|
||||
img->buffer[pixel + 3] = (color) & 0xFF;
|
||||
}
|
||||
else if (img->endian == 0)
|
||||
{
|
||||
img->buffer[pixel + 0] = (color) & 0xFF;
|
||||
img->buffer[pixel + 1] = (color >> 8) & 0xFF;
|
||||
img->buffer[pixel + 2] = (color >> 16) & 0xFF;
|
||||
img->buffer[pixel + 3] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void draw_ray3d(t_data *img, t_ray ray)
|
||||
{
|
||||
double line_height;
|
||||
@ -61,14 +24,9 @@ void draw_ray3d(t_data *img, t_ray ray)
|
||||
double gap;
|
||||
double myy;
|
||||
|
||||
x = 0;
|
||||
y = 0;
|
||||
mx = 0;
|
||||
my = 0;
|
||||
line_height = 64 * 960 / ray.dist;
|
||||
line_offset = 256 - ((int)line_height) / 2;
|
||||
gap = 1;
|
||||
myy = 0;
|
||||
x = 0;
|
||||
y = 0;
|
||||
my = 0;
|
||||
myy = 0;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/06 16:10:11 by apommier #+# #+# */
|
||||
/* Updated: 2022/06/15 19:15:40 by apommier ### ########.fr */
|
||||
/* Updated: 2022/06/15 21:38:53 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -76,7 +76,7 @@ void get_file_size(char *path, t_data *img, int *count, int fd)
|
||||
close(fd);
|
||||
img->to_be_free.fd = -1;
|
||||
if (*count != 12291)
|
||||
ft_exit("Error\nBad texture file (too much line)\n", img);
|
||||
ft_exit("Error\nBad texture file (too much or not enough line)\n", img);
|
||||
}
|
||||
|
||||
void fill_ret(int count, t_data *img, unsigned char **ret, char *swap)
|
||||
|
||||
@ -6,46 +6,68 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/02/13 23:37:02 by apommier #+# #+# */
|
||||
/* Updated: 2022/06/15 19:15:23 by apommier ### ########.fr */
|
||||
/* Updated: 2022/06/15 21:39:46 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/Cub3D.h"
|
||||
|
||||
double deg_to_rad(double angle)
|
||||
int get_color(char R, char G, char B)
|
||||
{
|
||||
return (angle * 3.14159265358979323846 / 180.0);
|
||||
int color;
|
||||
|
||||
color = 0;
|
||||
color = color << 8;
|
||||
color += R;
|
||||
color = color << 8;
|
||||
color += G;
|
||||
color = color << 8;
|
||||
color += B;
|
||||
return (color);
|
||||
}
|
||||
|
||||
double reset_angle(double angle)
|
||||
void set_pixel(t_data *img, int color, int x, int y)
|
||||
{
|
||||
if (angle > 359)
|
||||
angle -= 360.0;
|
||||
if (angle < 0)
|
||||
angle += 360.0;
|
||||
return (angle);
|
||||
}
|
||||
int pixel;
|
||||
|
||||
void ft_error(char *error_msg)
|
||||
{
|
||||
ft_putendl_fd(error_msg, 2);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void ft_exit(char *str, t_data *img)
|
||||
{
|
||||
ft_putstr_fd(str, 2);
|
||||
quit_game(img);
|
||||
}
|
||||
|
||||
void check_dir(char *path, t_data *img)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open(path, O_DIRECTORY);
|
||||
if (fd >= 0)
|
||||
if (y < 0 || y > 520 || x < 0 || x > 960)
|
||||
return ;
|
||||
pixel = (y * img->size_line) + (x * 4);
|
||||
if (img->endian == 1)
|
||||
{
|
||||
close(fd);
|
||||
ft_exit("Error\nPath is a directory and not a file\n", img);
|
||||
img->buffer[pixel + 0] = 0;
|
||||
img->buffer[pixel + 1] = (color >> 16) & 0xFF;
|
||||
img->buffer[pixel + 2] = (color >> 8) & 0xFF;
|
||||
img->buffer[pixel + 3] = (color) & 0xFF;
|
||||
}
|
||||
else if (img->endian == 0)
|
||||
{
|
||||
img->buffer[pixel + 0] = (color) & 0xFF;
|
||||
img->buffer[pixel + 1] = (color >> 8) & 0xFF;
|
||||
img->buffer[pixel + 2] = (color >> 16) & 0xFF;
|
||||
img->buffer[pixel + 3] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void get_map_size(char *path, t_data *img, int *count, int fd)
|
||||
{
|
||||
char *swap;
|
||||
|
||||
swap = 0;
|
||||
if (!path)
|
||||
ft_exit("Error\nNo path for map\n", img);
|
||||
check_dir(path, img);
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd == -1)
|
||||
ft_exit("Error\nBad path for map\n", img);
|
||||
img->to_be_free.fd = fd;
|
||||
while (swap || !(*count))
|
||||
{
|
||||
if (swap)
|
||||
free(swap);
|
||||
(*count)++;
|
||||
swap = get_next_line(fd);
|
||||
}
|
||||
close(fd);
|
||||
img->to_be_free.fd = -1;
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/10 17:54:25 by sadjigui #+# #+# */
|
||||
/* Updated: 2022/06/15 18:52:15 by apommier ### ########.fr */
|
||||
/* Updated: 2022/06/15 22:03:10 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -214,6 +214,8 @@ void check_zero_one(char **split, t_data *img)
|
||||
i = 0;
|
||||
while (split[i])
|
||||
{
|
||||
if (!ft_strchr(split[i], '1'))
|
||||
ft_exit("Error\nInvalid line in map file\n", img);
|
||||
size_line(split[i], img);
|
||||
i++;
|
||||
}
|
||||
@ -271,58 +273,41 @@ int detect_map_line(char *line)
|
||||
return (1);
|
||||
}
|
||||
|
||||
char **fill_tab(char *swap, int count, char **ret, int fd)
|
||||
{
|
||||
while (swap || !count)
|
||||
{
|
||||
swap = get_next_line(fd);
|
||||
if (ft_strlen(swap) >= 1 && swap[ft_strlen(swap) - 1] == '\n')
|
||||
swap[ft_strlen(swap) - 1] = 0;
|
||||
ret[count] = swap;
|
||||
count++;
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
char **isafile(char **av, t_data *img)
|
||||
{
|
||||
|
||||
int fd;
|
||||
char *line;
|
||||
char *str;
|
||||
char *tmp;
|
||||
char **split;
|
||||
char **ret;
|
||||
int count;
|
||||
int pass;
|
||||
|
||||
check_dir(av[1], img);
|
||||
img->err = 0;
|
||||
fd = open(av[1], O_RDONLY);
|
||||
img->to_be_free.fd = fd;
|
||||
str = NULL;
|
||||
tmp = NULL;
|
||||
if (fd == - 1)
|
||||
ft_exit("Error\nFile doesn't exist\n", img);
|
||||
while ((line = get_next_line(fd)) != NULL)
|
||||
{
|
||||
if (line[0] != '\n' && img->err == 0)
|
||||
{
|
||||
if (detect_map_line(line))
|
||||
img->err = 1;
|
||||
if (line[0] == '\n' && img->err == 1)
|
||||
img->err = 2;
|
||||
}
|
||||
tmp = ft_strjoin(str, line);
|
||||
free(line);
|
||||
line = NULL;
|
||||
if (str != NULL)
|
||||
free(str);
|
||||
if (!tmp)
|
||||
count = 0;
|
||||
get_map_size(av[1], img, &count, 0);
|
||||
ret = ft_calloc(sizeof(char*), count);
|
||||
if (!ret)
|
||||
quit_game(img);
|
||||
str = tmp;
|
||||
}
|
||||
if (img->err == 2)
|
||||
{
|
||||
free(str);
|
||||
ft_exit("Error\nBad texture file\n", img);
|
||||
}
|
||||
split = ft_split(str, '\n');
|
||||
img->to_be_free.tab = split;
|
||||
free(str);
|
||||
free(line);
|
||||
img->to_be_free.tab = ret;
|
||||
fd = open(av[1], O_RDONLY);
|
||||
if (fd == -1)
|
||||
ft_exit("Error\nBad texture file", img);
|
||||
ret = fill_tab(0, 0, ret, fd);
|
||||
close(fd);
|
||||
img->to_be_free.fd = -1;
|
||||
int pass = 0;
|
||||
pass = check_texture_color(split, img);
|
||||
check_zero_one(split + pass, img);
|
||||
//leaks here -- normalement c bon
|
||||
transform_map(split + pass, img);
|
||||
free_double(split);
|
||||
pass = check_texture_color(ret, img);
|
||||
check_zero_one(ret + pass, img);
|
||||
transform_map(ret + pass, img);
|
||||
free_double(ret);
|
||||
img->to_be_free.tab = 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -6,8 +6,46 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/06/15 18:48:45 by apommier #+# #+# */
|
||||
/* Updated: 2022/06/15 18:48:47 by apommier ### ########.fr */
|
||||
/* Updated: 2022/06/15 19:23:03 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/Cub3D.h"
|
||||
|
||||
double deg_to_rad(double angle)
|
||||
{
|
||||
return (angle * 3.14159265358979323846 / 180.0);
|
||||
}
|
||||
|
||||
double reset_angle(double angle)
|
||||
{
|
||||
if (angle > 359)
|
||||
angle -= 360.0;
|
||||
if (angle < 0)
|
||||
angle += 360.0;
|
||||
return (angle);
|
||||
}
|
||||
|
||||
void ft_error(char *error_msg)
|
||||
{
|
||||
ft_putendl_fd(error_msg, 2);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void ft_exit(char *str, t_data *img)
|
||||
{
|
||||
ft_putstr_fd(str, 2);
|
||||
quit_game(img);
|
||||
}
|
||||
|
||||
void check_dir(char *path, t_data *img)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open(path, O_DIRECTORY);
|
||||
if (fd >= 0)
|
||||
{
|
||||
close(fd);
|
||||
ft_exit("Error\nPath is a directory and not a file\n", img);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user