Last development push
This commit is contained in:
2
Makefile
2
Makefile
@@ -12,7 +12,7 @@ GNL := ./lib/gnl
|
|||||||
GNL_A := ./lib/gnl/get_next_line.a
|
GNL_A := ./lib/gnl/get_next_line.a
|
||||||
|
|
||||||
HEADERS := -I ./include -I $(LIBMLX)/include -I $(LIBFT) -I $(FTPRINTF) -I $(GNL)
|
HEADERS := -I ./include -I $(LIBMLX)/include -I $(LIBFT) -I $(FTPRINTF) -I $(GNL)
|
||||||
LIBS := $(LIBMLX)/build/libmlx42.a $(LIBFT_A) $(FT_PRINTF_A) $(GNL_A) -ldl -lglfw -pthread -lm
|
LIBS := $(LIBMLX)/build/libmlx42.a $(GNL_A) $(LIBFT_A) $(FT_PRINTF_A) -ldl -lglfw -pthread -lm
|
||||||
SRCS := $(shell find ./src -iname "*.c")
|
SRCS := $(shell find ./src -iname "*.c")
|
||||||
OBJS := ${SRCS:.c=.o}
|
OBJS := ${SRCS:.c=.o}
|
||||||
|
|
||||||
|
|||||||
22
assets/maps/map.cub
Normal file
22
assets/maps/map.cub
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
NO assets/textures/backRoom.png
|
||||||
|
SO assets/textures/backRoom.png
|
||||||
|
WE assets/textures/backRoom2.png
|
||||||
|
EA assets/textures/backRoom2.png
|
||||||
|
|
||||||
|
C 164,157,79
|
||||||
|
F 136,123,55
|
||||||
|
|
||||||
|
11111111111111111111111111111
|
||||||
|
10000000001100000000000000001
|
||||||
|
10110000011100000010000010001
|
||||||
|
10010000000000000000000010001
|
||||||
|
10110000011100000010000010001
|
||||||
|
10000000001100000111011110001
|
||||||
|
11110111111111011100000010001
|
||||||
|
11110111111111011101010010001
|
||||||
|
11000000110101011100000010001
|
||||||
|
10000000000000001100000010001
|
||||||
|
10000000000000001101010010001
|
||||||
|
11000000110101011111011110N01
|
||||||
|
11110111111101011111000000001
|
||||||
|
11111111111111111111111111111
|
||||||
BIN
assets/textures/backRoom.png
Normal file
BIN
assets/textures/backRoom.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 64 KiB |
BIN
assets/textures/backRoom2.png
Normal file
BIN
assets/textures/backRoom2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 366 KiB |
BIN
assets/textures/img_ea.png
Normal file
BIN
assets/textures/img_ea.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 673 KiB |
BIN
assets/textures/img_no.png
Normal file
BIN
assets/textures/img_no.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1002 KiB |
BIN
assets/textures/img_so.png
Normal file
BIN
assets/textures/img_so.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 920 KiB |
BIN
assets/textures/img_we.png
Normal file
BIN
assets/textures/img_we.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 861 KiB |
216
includes/cub3d.h
216
includes/cub3d.h
@@ -6,7 +6,7 @@
|
|||||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/11/25 19:47:02 by aortigos #+# #+# */
|
/* Created: 2025/11/25 19:47:02 by aortigos #+# #+# */
|
||||||
/* Updated: 2025/12/09 18:40:30 by aortigos ### ########.fr */
|
/* Updated: 2025/12/09 18:49:27 by aortigos ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -16,83 +16,201 @@
|
|||||||
|
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
|
# include <stdio.h>
|
||||||
# include <math.h>
|
# include <math.h>
|
||||||
|
# include <fcntl.h>
|
||||||
|
# include <signal.h>
|
||||||
# include "../lib/mlx/include/MLX42/MLX42.h"
|
# include "../lib/mlx/include/MLX42/MLX42.h"
|
||||||
# include "../lib/libft/libft.h"
|
# include "../lib/libft/libft.h"
|
||||||
# include "../lib/ft_printf/ft_printf.h"
|
# include "../lib/ft_printf/ft_printf.h"
|
||||||
# include "../lib/gnl/get_next_line.h"
|
# include "../lib/gnl/get_next_line.h"
|
||||||
|
|
||||||
# define S_W 800
|
/*═══════════════════════════ [ MACROS ] ═══════════════════════════════════*/
|
||||||
# define S_H 600
|
|
||||||
# define FOV 60
|
// MLX - GAME
|
||||||
# define PLAYER_SPEED 3
|
|
||||||
|
# define S_W 1900 // screen width
|
||||||
|
# define S_H 1000 // screen height
|
||||||
|
# define WALL_SIZE 30 // wall size
|
||||||
|
# define FOV 60 // field of view
|
||||||
|
# define ROTATION_SPEED 0.045 // rotation speed
|
||||||
|
# define PLAYER_SPEED 4 // player speed
|
||||||
|
|
||||||
|
// ERROR
|
||||||
|
|
||||||
|
# define ERR_INV_COP "Error: invalid argument\n"
|
||||||
|
# define ERR_INV_FILE "Error: invalid file\n"
|
||||||
|
# define ERR_EMPTY_FILE "Error: empty file\n"
|
||||||
|
|
||||||
|
# define ERR_MAP_INV "Error: invalid map element\n"
|
||||||
|
# define ERR_MAP_EMPTY "Error: empty ligne in the map\n"
|
||||||
|
# define ERR_MAP_DUP "Error: duplicate map element\n"
|
||||||
|
# define ERR_MAP_RGB "Error: invalid color map [RGB]\n"
|
||||||
|
|
||||||
|
/*══════════════════════════ [ STRUCTS ] ═══════════════════════════════════*/
|
||||||
|
|
||||||
|
typedef struct s_tex
|
||||||
|
{
|
||||||
|
mlx_texture_t *no;
|
||||||
|
mlx_texture_t *so;
|
||||||
|
mlx_texture_t *we;
|
||||||
|
mlx_texture_t *ea;
|
||||||
|
} t_tex;
|
||||||
|
|
||||||
|
typedef struct s_turelist
|
||||||
|
{
|
||||||
|
char *name;
|
||||||
|
char *value;
|
||||||
|
struct s_turelist *next;
|
||||||
|
} t_turelist;
|
||||||
|
|
||||||
|
typedef struct s_player
|
||||||
|
{
|
||||||
|
int plyr_x; // player x position in pixels
|
||||||
|
int plyr_y; // player y position in pixels
|
||||||
|
double angle; // player angle
|
||||||
|
float fov_rd; // field of view in radians
|
||||||
|
int rot; // rotation flag
|
||||||
|
int l_r; // left right flag
|
||||||
|
int u_d; // up down flag
|
||||||
|
} t_player;
|
||||||
|
|
||||||
|
typedef struct s_ray
|
||||||
|
{
|
||||||
|
int index;
|
||||||
|
double ray_ngl;
|
||||||
|
double horiz_x;
|
||||||
|
double horiz_y;
|
||||||
|
double vert_x;
|
||||||
|
double vert_y;
|
||||||
|
double distance;
|
||||||
|
int flag;
|
||||||
|
} t_ray;
|
||||||
|
|
||||||
|
typedef struct s_data
|
||||||
|
{
|
||||||
|
int p_x; // player x position in the map
|
||||||
|
int p_y; // player y position in the map
|
||||||
|
int w_map; // map width
|
||||||
|
int h_map; // map height
|
||||||
|
int fd;
|
||||||
|
char *line;
|
||||||
|
char *ture;
|
||||||
|
char **ture2d;
|
||||||
|
char *map;
|
||||||
|
char **map2d;
|
||||||
|
char **sq_map;
|
||||||
|
char **cc;
|
||||||
|
char **ff;
|
||||||
|
t_turelist *t_list;
|
||||||
|
} t_data;
|
||||||
|
|
||||||
|
typedef struct s_mlx
|
||||||
|
{
|
||||||
|
mlx_image_t *img; // the image
|
||||||
|
mlx_t *mlx_ptr; // the mlx pointer
|
||||||
|
t_ray *ray; // the ray structure
|
||||||
|
t_data *dt; // the data structure
|
||||||
|
t_player *ply; // the player structure
|
||||||
|
t_tex *tex;
|
||||||
|
t_turelist *l_ture;
|
||||||
|
} t_mlx;
|
||||||
|
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
|
|
||||||
// parsing.c
|
// parsing.c
|
||||||
int read_map(char *av, t_data *map, int *count);
|
int read_map(char *av, t_data *map, int *count);
|
||||||
void get_x_y_player(t_data *data);
|
void get_x_y_player(t_data *data);
|
||||||
int check_extension_map(char *file);
|
int check_extension_map(char *file);
|
||||||
int parsing(int ac, char **av, t_data *data);
|
int parsing(int ac, char **av, t_data *data);
|
||||||
|
|
||||||
// frees.c
|
// frees.c
|
||||||
void freetl(char *ture, char *line, int fd);
|
void freetl(char *ture, char *line, int fd);
|
||||||
void free_map(t_data *data);
|
void free_map(t_data *data);
|
||||||
void free_m(t_mlx *mlx);
|
void free_m(t_mlx *mlx);
|
||||||
void freelist(t_turelist **txture);
|
void freelist(t_turelist **txture);
|
||||||
|
|
||||||
// lst_textures.c
|
// lst_textures.c
|
||||||
int get_index(char *line, int i);
|
int get_index(char *line, int i);
|
||||||
t_turelist *new_texture(char *line);
|
t_turelist *new_texture(char *line);
|
||||||
void lst_back_ture(t_turelist **l_ture, t_turelist *new);
|
void lst_back_ture(t_turelist **l_ture, t_turelist *new);
|
||||||
int lst_ture(t_data *m, t_turelist **l_ture);
|
int lst_ture(t_data *m, t_turelist **l_ture);
|
||||||
|
|
||||||
// read_map.c
|
// read_map.c
|
||||||
int is_surrounded(char *line);
|
int is_surrounded(char *line);
|
||||||
int is_validmap(char *line, int *flag);
|
int is_validmap(char *line, int *flag);
|
||||||
char *getmap(t_data *map);
|
char *getmap(t_data *map);
|
||||||
int read_map_(t_data *map, int count);
|
int read_map_(t_data *map, int count);
|
||||||
void process_map(t_data *map, int *count);
|
void process_map(t_data *map, int *count);
|
||||||
|
|
||||||
// read_map_utils.c
|
// read_map_utils.c
|
||||||
int check_tures_space_tab(char **ture2d, int count);
|
int check_tures_space_tab(char **ture2d, int count);
|
||||||
int parse_rgb(char **ture2d);
|
int parse_rgb(char **ture2d);
|
||||||
int check_dup(t_data *m);
|
int check_dup(t_data *m);
|
||||||
int check_first_last_line(char **map);
|
int check_first_last_line(char **map);
|
||||||
int surrounded_by_one(char **map);
|
int surrounded_by_one(char **map);
|
||||||
|
|
||||||
// textures.c
|
// textures.c
|
||||||
int check_color_values(char **rgb);
|
int check_color_values(char **rgb);
|
||||||
void ft_process_rgb_color(t_turelist *tmp, t_data *m);
|
void ft_process_rgb_color(t_turelist *tmp, t_data *m);
|
||||||
int color_ture(t_data *m, t_turelist *l_ture);
|
int color_ture(t_data *m, t_turelist *l_ture);
|
||||||
int check_color_textures(char *line);
|
int check_color_textures(char *line);
|
||||||
int check_count_textures(t_data *m, int count);
|
int check_count_textures(t_data *m, int count);
|
||||||
|
|
||||||
// textures_utils.c
|
// textures_utils.c
|
||||||
int is_valid_texture(char *line);
|
int is_valid_texture(char *line);
|
||||||
int count_comma(char *rgb);
|
int count_comma(char *rgb);
|
||||||
int check_pos_cf(char *l);
|
int check_pos_cf(char *l);
|
||||||
int line_around_one(char *line);
|
int line_around_one(char *line);
|
||||||
char *getlastline(char **map);
|
char *getlastline(char **map);
|
||||||
|
|
||||||
//valid_map.c
|
//valid_map.c
|
||||||
int h_map(char **map);
|
int h_map(char **map);
|
||||||
int v_map(char **map);
|
int v_map(char **map);
|
||||||
char *fixline(char *line, int maxlen);
|
char *fixline(char *line, int maxlen);
|
||||||
int getsize_line(char **map);
|
int getsize_line(char **map);
|
||||||
int valid_map(t_data *m);
|
int valid_map(t_data *m);
|
||||||
|
|
||||||
// frees.c
|
// frees.c
|
||||||
void ft_delete_texture(t_texture *texture);
|
void ft_delete_texture(t_tex *texture);
|
||||||
void ft_exit(t_mlx *mlx);
|
void ft_exit(t_mlx *mlx);
|
||||||
|
|
||||||
// movement.c
|
// movement.c
|
||||||
void rotate_player(t_mlx *mlx, int i);
|
void rotate_player(t_mlx *mlx, int i);
|
||||||
void move_player(t_mlx *mlx, double move_x, double move_y);
|
void move_player(t_mlx *mlx, double move_x, double move_y);
|
||||||
void cub_hook(t_mlx *mlx, double move_x, double move_y);
|
void cub_hook(t_mlx *mlx, double move_x, double move_y);
|
||||||
void ft_reset_move(mlx_key_data_t keydata, t_mlx *mlx);
|
void ft_reset_move(mlx_key_data_t keydata, t_mlx *mlx);
|
||||||
void key_press(mlx_key_data_t keydata, void *ml);
|
void key_press(mlx_key_data_t keydata, void *ml);
|
||||||
|
|
||||||
|
// raycasting.c
|
||||||
|
int inter_check(float angle, float *inter, float *step, int is_horizon);
|
||||||
|
int wall_hit(float x, float y, t_mlx *mlx);
|
||||||
|
float get_h_inter(t_mlx *mlx, float angl);
|
||||||
|
float get_v_inter(t_mlx *mlx, float angl);
|
||||||
|
void cast_rays(t_mlx *mlx);
|
||||||
|
|
||||||
|
// render.c
|
||||||
|
void draw_floor_ceiling(t_mlx *mlx, int ray, int t_pix, int b_pix);
|
||||||
|
mlx_texture_t *get_texture(t_mlx *mlx, int flag);
|
||||||
|
double get_x_o(mlx_texture_t *texture, t_mlx *mlx);
|
||||||
|
void draw_wall(t_mlx *mlx, int t_pix, int b_pix, double wall_h);
|
||||||
|
void render_wall(t_mlx *mlx, int ray);
|
||||||
|
|
||||||
|
// render2.c
|
||||||
|
int get_rgba(int r, int g, int b, int a);
|
||||||
|
int reverse_bytes(int c);
|
||||||
|
void my_mlx_pixel_put(t_mlx *mlx, int x, int y, int color);
|
||||||
|
float nor_angle(float angle);
|
||||||
|
int unit_circle(float angle, char c);
|
||||||
|
|
||||||
|
// execution.c
|
||||||
|
void drow_map_pixel(void *mlxl);
|
||||||
|
int check_load_ture(t_turelist *list);
|
||||||
|
int load_texture(t_tex *tex, t_turelist *l_ture);
|
||||||
|
void get_angle(t_mlx *mlx);
|
||||||
|
int execution(t_data *dt);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* get_next_line.c :+: :+: :+: */
|
/* get_next_line.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: aortigos <aortigos@student.42malaga.com> +#+ +:+ +#+ */
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/15 18:37:44 by aortigos #+# #+# */
|
/* Created: 2024/03/15 18:37:44 by aortigos #+# #+# */
|
||||||
/* Updated: 2024/03/15 19:31:56 by aortigos ### ########.fr */
|
/* Updated: 2025/12/09 19:21:50 by aortigos ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -31,6 +31,8 @@ char *ft_read_to_left_str(int fd, char *left_str)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
buff[rd_bytes] = '\0';
|
buff[rd_bytes] = '\0';
|
||||||
|
if (!left_str)
|
||||||
|
left_str = ft_strdup(""); // o malloc(1) + '\0'
|
||||||
left_str = ft_strjoin(left_str, buff);
|
left_str = ft_strjoin(left_str, buff);
|
||||||
}
|
}
|
||||||
free(buff);
|
free(buff);
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* ft_strchr.c :+: :+: :+: */
|
/* ft_strchr.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: aortigos <aortigos@student.42malaga.com> +#+ +:+ +#+ */
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/09/21 17:16:15 by aortigos #+# #+# */
|
/* Created: 2023/09/21 17:16:15 by aortigos #+# #+# */
|
||||||
/* Updated: 2023/10/12 15:15:10 by aortigos ### ########.fr */
|
/* Updated: 2025/12/09 19:12:12 by aortigos ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -16,6 +16,8 @@ char *ft_strchr(const char *str, int c)
|
|||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
if (!str)
|
||||||
|
return (NULL);
|
||||||
i = 0;
|
i = 0;
|
||||||
while (str[i] != '\0')
|
while (str[i] != '\0')
|
||||||
{
|
{
|
||||||
|
|||||||
116
src/execution/execution.c
Normal file
116
src/execution/execution.c
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* execution.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/12/09 18:46:27 by aortigos #+# #+# */
|
||||||
|
/* Updated: 2025/12/09 19:56:57 by aortigos ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../../includes/cub3d.h"
|
||||||
|
|
||||||
|
void drow_map_pixel(void *mlxl)
|
||||||
|
{
|
||||||
|
t_mlx *mlx;
|
||||||
|
|
||||||
|
mlx = mlxl;
|
||||||
|
mlx_delete_image(mlx->mlx_ptr, mlx->img);
|
||||||
|
mlx->img = mlx_new_image(mlx->mlx_ptr, S_W, S_H);
|
||||||
|
cub_hook(mlx, 0, 0);
|
||||||
|
cast_rays(mlx);
|
||||||
|
mlx_image_to_window(mlx->mlx_ptr, mlx->img, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int check_load_ture(t_turelist *list)
|
||||||
|
{
|
||||||
|
t_turelist *tmp;
|
||||||
|
mlx_texture_t *texture;
|
||||||
|
|
||||||
|
tmp = list;
|
||||||
|
while (tmp)
|
||||||
|
{
|
||||||
|
if (tmp->name && (
|
||||||
|
!ft_strncmp(tmp->name, "NO", 2)
|
||||||
|
|| !ft_strncmp(tmp->name, "SO", 2)
|
||||||
|
|| !ft_strncmp(tmp->name, "WE", 2)
|
||||||
|
|| !ft_strncmp(tmp->name, "EA", 2)))
|
||||||
|
{
|
||||||
|
texture = mlx_load_png(tmp->value);
|
||||||
|
if (!texture)
|
||||||
|
return (0);
|
||||||
|
mlx_delete_texture(texture);
|
||||||
|
}
|
||||||
|
tmp = tmp->next;
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int load_texture(t_tex *tex, t_turelist *l_ture)
|
||||||
|
{
|
||||||
|
t_turelist *tmp;
|
||||||
|
|
||||||
|
if (!l_ture)
|
||||||
|
return (0);
|
||||||
|
tmp = l_ture;
|
||||||
|
if (!check_load_ture(l_ture))
|
||||||
|
return (0);
|
||||||
|
while (tmp)
|
||||||
|
{
|
||||||
|
if (!tmp->name || !tmp->value)
|
||||||
|
tmp = tmp->next;
|
||||||
|
if (!ft_strncmp(tmp->name, "NO", 2))
|
||||||
|
tex->no = mlx_load_png(tmp->value);
|
||||||
|
else if (!ft_strncmp(tmp->name, "SO", 2))
|
||||||
|
tex->so = mlx_load_png(tmp->value);
|
||||||
|
else if (!ft_strncmp(tmp->name, "WE", 2))
|
||||||
|
tex->we = mlx_load_png(tmp->value);
|
||||||
|
else if (!ft_strncmp(tmp->name, "EA", 2))
|
||||||
|
tex->ea = mlx_load_png(tmp->value);
|
||||||
|
tmp = tmp->next;
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void get_angle(t_mlx *mlx)
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
|
||||||
|
c = mlx->dt->sq_map[mlx->dt->p_y][mlx->dt->p_x];
|
||||||
|
if (c == 'N')
|
||||||
|
mlx->ply->angle = 3 * M_PI / 2;
|
||||||
|
if (c == 'S')
|
||||||
|
mlx->ply->angle = M_PI / 2;
|
||||||
|
if (c == 'E')
|
||||||
|
mlx->ply->angle = 0;
|
||||||
|
if (c == 'W')
|
||||||
|
mlx->ply->angle = M_PI;
|
||||||
|
mlx->ply->plyr_x = (mlx->dt->p_x * WALL_SIZE) + WALL_SIZE / 2;
|
||||||
|
mlx->ply->plyr_y = (mlx->dt->p_y * WALL_SIZE) + WALL_SIZE / 2;
|
||||||
|
mlx->ply->fov_rd = (FOV * M_PI / 180);
|
||||||
|
}
|
||||||
|
|
||||||
|
int execution(t_data *dt)
|
||||||
|
{
|
||||||
|
t_mlx mlx;
|
||||||
|
|
||||||
|
if (S_H > 1440 || S_W > 2560 || FOV >= 180 || FOV <= 0)
|
||||||
|
return (freelist(&dt->t_list), free_map(dt), 0);
|
||||||
|
mlx.ply = (t_player *)ft_calloc(sizeof(t_player), 1);
|
||||||
|
mlx.ray = (t_ray *)ft_calloc(sizeof(t_ray), 1);
|
||||||
|
mlx.tex = (t_tex *)ft_calloc(sizeof(t_tex), 1);
|
||||||
|
mlx.dt = dt;
|
||||||
|
mlx.mlx_ptr = mlx_init(S_W, S_H, "cub3D", false);
|
||||||
|
if (!mlx.mlx_ptr)
|
||||||
|
return (ft_exit(&mlx), 0);
|
||||||
|
if (!load_texture(mlx.tex, dt->t_list))
|
||||||
|
return (ft_exit(&mlx), 0);
|
||||||
|
get_angle(&mlx);
|
||||||
|
mlx_key_hook(mlx.mlx_ptr, &key_press, &mlx);
|
||||||
|
mlx_loop_hook(mlx.mlx_ptr, &drow_map_pixel, &mlx);
|
||||||
|
mlx_loop(mlx.mlx_ptr);
|
||||||
|
ft_exit(&mlx);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -6,22 +6,22 @@
|
|||||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/12/05 17:07:58 by aortigos #+# #+# */
|
/* Created: 2025/12/05 17:07:58 by aortigos #+# #+# */
|
||||||
/* Updated: 2025/12/05 17:10:05 by aortigos ### ########.fr */
|
/* Updated: 2025/12/09 19:55:15 by aortigos ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../../includes/cub3d.h"
|
#include "../../includes/cub3d.h"
|
||||||
|
|
||||||
void ft_delete_texture(t_texture *texture)
|
void ft_delete_texture(t_tex *tex)
|
||||||
{
|
{
|
||||||
if (texture->no)
|
if (tex->no)
|
||||||
mlx_delete_texture(texture->no);
|
mlx_delete_texture(tex->no);
|
||||||
if (texture->so)
|
if (tex->so)
|
||||||
mlx_delete_texture(texture->so);
|
mlx_delete_texture(tex->so);
|
||||||
if (texture->we)
|
if (tex->we)
|
||||||
mlx_delete_texture(texture->we);
|
mlx_delete_texture(tex->we);
|
||||||
if (texture->ea)
|
if (tex->ea)
|
||||||
mlx_delete_texture(texture->ea);
|
mlx_delete_texture(tex->ea);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_exit(t_mlx *mlx)
|
void ft_exit(t_mlx *mlx)
|
||||||
@@ -37,4 +37,4 @@ void ft_exit(t_mlx *mlx)
|
|||||||
mlx_terminate(mlx->mlx_ptr);
|
mlx_terminate(mlx->mlx_ptr);
|
||||||
ft_putstr_fd("END GAME\n", 1);
|
ft_putstr_fd("END GAME\n", 1);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
133
src/execution/raycasting.c
Normal file
133
src/execution/raycasting.c
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* raycasting.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/12/09 18:41:15 by aortigos #+# #+# */
|
||||||
|
/* Updated: 2025/12/09 18:41:30 by aortigos ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../../includes/cub3d.h"
|
||||||
|
|
||||||
|
int inter_check(float angle, float *inter, float *step, int is_horizon)
|
||||||
|
{
|
||||||
|
if (is_horizon)
|
||||||
|
{
|
||||||
|
if (angle > 0 && angle < M_PI)
|
||||||
|
{
|
||||||
|
*inter += WALL_SIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
*step *= -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!(angle > M_PI / 2 && angle < 3 * M_PI / 2))
|
||||||
|
{
|
||||||
|
*inter += WALL_SIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
*step *= -1;
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int wall_hit(float x, float y, t_mlx *mlx)
|
||||||
|
{
|
||||||
|
int x_m;
|
||||||
|
int y_m;
|
||||||
|
|
||||||
|
if (x < 0 || y < 0)
|
||||||
|
return (0);
|
||||||
|
x_m = floor(x / WALL_SIZE);
|
||||||
|
y_m = floor(y / WALL_SIZE);
|
||||||
|
if ((y_m >= mlx->dt->h_map || x_m >= mlx->dt->w_map))
|
||||||
|
return (0);
|
||||||
|
if (mlx->dt->map2d[y_m] && x_m <= (int)ft_strlen(mlx->dt->map2d[y_m]))
|
||||||
|
if (mlx->dt->map2d[y_m][x_m] == '1')
|
||||||
|
return (0);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
float get_h_inter(t_mlx *mlx, float angl)
|
||||||
|
{
|
||||||
|
float h_x;
|
||||||
|
float h_y;
|
||||||
|
float x_step;
|
||||||
|
float y_step;
|
||||||
|
int pixel;
|
||||||
|
|
||||||
|
y_step = WALL_SIZE;
|
||||||
|
x_step = WALL_SIZE / tan(angl);
|
||||||
|
h_y = floor(mlx->ply->plyr_y / WALL_SIZE) * WALL_SIZE;
|
||||||
|
pixel = inter_check(angl, &h_y, &y_step, 1);
|
||||||
|
h_x = mlx->ply->plyr_x + (h_y - mlx->ply->plyr_y) / tan(angl);
|
||||||
|
if ((unit_circle(angl, 'y') && x_step > 0) || (!unit_circle(angl, 'y')
|
||||||
|
&& x_step < 0))
|
||||||
|
x_step *= -1;
|
||||||
|
while (wall_hit(h_x, h_y - pixel, mlx))
|
||||||
|
{
|
||||||
|
h_x += x_step;
|
||||||
|
h_y += y_step;
|
||||||
|
}
|
||||||
|
mlx->ray->horiz_x = h_x;
|
||||||
|
mlx->ray->horiz_y = h_y;
|
||||||
|
return (sqrt(pow(h_x - mlx->ply->plyr_x, 2) + pow(h_y - mlx->ply->plyr_y,
|
||||||
|
2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
float get_v_inter(t_mlx *mlx, float angl)
|
||||||
|
{
|
||||||
|
float v_x;
|
||||||
|
float v_y;
|
||||||
|
float x_step;
|
||||||
|
float y_step;
|
||||||
|
int pixel;
|
||||||
|
|
||||||
|
x_step = WALL_SIZE;
|
||||||
|
y_step = WALL_SIZE * tan(angl);
|
||||||
|
v_x = floor(mlx->ply->plyr_x / WALL_SIZE) * WALL_SIZE;
|
||||||
|
pixel = inter_check(angl, &v_x, &x_step, 0);
|
||||||
|
v_y = mlx->ply->plyr_y + (v_x - mlx->ply->plyr_x) * tan(angl);
|
||||||
|
if ((unit_circle(angl, 'x') && y_step < 0) || (!unit_circle(angl, 'x')
|
||||||
|
&& y_step > 0))
|
||||||
|
y_step *= -1;
|
||||||
|
while (wall_hit(v_x - pixel, v_y, mlx))
|
||||||
|
{
|
||||||
|
v_x += x_step;
|
||||||
|
v_y += y_step;
|
||||||
|
}
|
||||||
|
mlx->ray->vert_x = v_x;
|
||||||
|
mlx->ray->vert_y = v_y;
|
||||||
|
return (sqrt(pow(v_x - mlx->ply->plyr_x, 2) + pow(v_y - mlx->ply->plyr_y,
|
||||||
|
2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void cast_rays(t_mlx *mlx)
|
||||||
|
{
|
||||||
|
double h_inter;
|
||||||
|
double v_inter;
|
||||||
|
int ray;
|
||||||
|
|
||||||
|
ray = 0;
|
||||||
|
mlx->ray->ray_ngl = mlx->ply->angle - (mlx->ply->fov_rd / 2);
|
||||||
|
while (ray < S_W)
|
||||||
|
{
|
||||||
|
mlx->ray->flag = 0;
|
||||||
|
h_inter = get_h_inter(mlx, nor_angle(mlx->ray->ray_ngl));
|
||||||
|
v_inter = get_v_inter(mlx, nor_angle(mlx->ray->ray_ngl));
|
||||||
|
if (v_inter <= h_inter)
|
||||||
|
mlx->ray->distance = v_inter;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mlx->ray->distance = h_inter;
|
||||||
|
mlx->ray->flag = 1;
|
||||||
|
}
|
||||||
|
render_wall(mlx, ray);
|
||||||
|
ray++;
|
||||||
|
mlx->ray->ray_ngl += (mlx->ply->fov_rd / S_W);
|
||||||
|
}
|
||||||
|
}
|
||||||
106
src/execution/render.c
Normal file
106
src/execution/render.c
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* render.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/12/09 18:42:30 by aortigos #+# #+# */
|
||||||
|
/* Updated: 2025/12/09 19:55:21 by aortigos ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../../includes/cub3d.h"
|
||||||
|
|
||||||
|
void draw_floor_ceiling(t_mlx *mlx, int ray, int t_pix, int b_pix)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int c;
|
||||||
|
|
||||||
|
i = b_pix;
|
||||||
|
c = get_rgba(ft_atoi(mlx->dt->ff[0]), ft_atoi(mlx->dt->ff[1]),
|
||||||
|
ft_atoi(mlx->dt->ff[2]), 255);
|
||||||
|
while (i < S_H)
|
||||||
|
my_mlx_pixel_put(mlx, ray, i++, c);
|
||||||
|
c = get_rgba(ft_atoi(mlx->dt->cc[0]), ft_atoi(mlx->dt->cc[1]),
|
||||||
|
ft_atoi(mlx->dt->cc[2]), 255);
|
||||||
|
i = 0;
|
||||||
|
while (i < t_pix)
|
||||||
|
my_mlx_pixel_put(mlx, ray, i++, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
mlx_texture_t *get_texture(t_mlx *mlx, int flag)
|
||||||
|
{
|
||||||
|
mlx->ray->ray_ngl = nor_angle(mlx->ray->ray_ngl);
|
||||||
|
if (flag == 0)
|
||||||
|
{
|
||||||
|
if (mlx->ray->ray_ngl > M_PI / 2 && mlx->ray->ray_ngl < 3 * (M_PI / 2))
|
||||||
|
return (mlx->tex->ea);
|
||||||
|
else
|
||||||
|
return (mlx->tex->we);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (mlx->ray->ray_ngl > 0 && mlx->ray->ray_ngl < M_PI)
|
||||||
|
return (mlx->tex->so);
|
||||||
|
else
|
||||||
|
return (mlx->tex->no);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double get_x_o(mlx_texture_t *texture, t_mlx *mlx)
|
||||||
|
{
|
||||||
|
double x_o;
|
||||||
|
|
||||||
|
if (mlx->ray->flag == 1)
|
||||||
|
x_o = (int)fmodf((mlx->ray->horiz_x * (texture->width / WALL_SIZE)),
|
||||||
|
texture->width);
|
||||||
|
else
|
||||||
|
x_o = (int)fmodf((mlx->ray->vert_y * (texture->width / WALL_SIZE)),
|
||||||
|
texture->width);
|
||||||
|
return (x_o);
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_wall(t_mlx *mlx, int t_pix, int b_pix, double wall_h)
|
||||||
|
{
|
||||||
|
double x_o;
|
||||||
|
double y_o;
|
||||||
|
mlx_texture_t *texture;
|
||||||
|
uint32_t *arr;
|
||||||
|
double factor;
|
||||||
|
|
||||||
|
texture = get_texture(mlx, mlx->ray->flag);
|
||||||
|
arr = (uint32_t *)texture->pixels;
|
||||||
|
factor = (double)texture->height / wall_h;
|
||||||
|
x_o = get_x_o(texture, mlx);
|
||||||
|
y_o = (t_pix - (S_H / 2) + (wall_h / 2)) * factor;
|
||||||
|
if (y_o < 0)
|
||||||
|
y_o = 0;
|
||||||
|
while (t_pix < b_pix)
|
||||||
|
{
|
||||||
|
my_mlx_pixel_put(mlx, mlx->ray->index, t_pix, reverse_bytes(arr[(int)y_o
|
||||||
|
* texture->width + (int)x_o]));
|
||||||
|
y_o += factor;
|
||||||
|
t_pix++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void render_wall(t_mlx *mlx, int ray)
|
||||||
|
{
|
||||||
|
double wall_h;
|
||||||
|
double b_pix;
|
||||||
|
double t_pix;
|
||||||
|
|
||||||
|
mlx->ray->distance *= cos(nor_angle(mlx->ray->ray_ngl - mlx->ply->angle));
|
||||||
|
wall_h = (WALL_SIZE / mlx->ray->distance) * ((S_W / 2)
|
||||||
|
/ tan(mlx->ply->fov_rd / 2));
|
||||||
|
b_pix = (S_H / 2) + (wall_h / 2);
|
||||||
|
t_pix = (S_H / 2) - (wall_h / 2);
|
||||||
|
if (b_pix > S_H)
|
||||||
|
b_pix = S_H;
|
||||||
|
if (t_pix < 0)
|
||||||
|
t_pix = 0;
|
||||||
|
mlx->ray->index = ray;
|
||||||
|
draw_wall(mlx, t_pix, b_pix, wall_h);
|
||||||
|
draw_floor_ceiling(mlx, ray, t_pix, b_pix);
|
||||||
|
}
|
||||||
67
src/execution/render2.c
Normal file
67
src/execution/render2.c
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* render2.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/12/09 18:44:12 by aortigos #+# #+# */
|
||||||
|
/* Updated: 2025/12/09 18:44:40 by aortigos ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../../includes/cub3d.h"
|
||||||
|
|
||||||
|
int get_rgba(int r, int g, int b, int a)
|
||||||
|
{
|
||||||
|
return (r << 24 | g << 16 | b << 8 | a << 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int reverse_bytes(int c)
|
||||||
|
{
|
||||||
|
unsigned int b;
|
||||||
|
|
||||||
|
b = 0;
|
||||||
|
b |= (c & 0xFF) << 24;
|
||||||
|
b |= (c & 0xFF00) << 8;
|
||||||
|
b |= (c & 0xFF0000) >> 8;
|
||||||
|
b |= (c & 0xFF000000) >> 24;
|
||||||
|
return (b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void my_mlx_pixel_put(t_mlx *mlx, int x, int y, int color)
|
||||||
|
{
|
||||||
|
if (x < 0)
|
||||||
|
return ;
|
||||||
|
else if (x >= S_W)
|
||||||
|
return ;
|
||||||
|
if (y < 0)
|
||||||
|
return ;
|
||||||
|
else if (y >= S_H)
|
||||||
|
return ;
|
||||||
|
mlx_put_pixel(mlx->img, x, y, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
float nor_angle(float angle)
|
||||||
|
{
|
||||||
|
if (angle < 0)
|
||||||
|
angle += (2 * M_PI);
|
||||||
|
if (angle > (2 * M_PI))
|
||||||
|
angle -= (2 * M_PI);
|
||||||
|
return (angle);
|
||||||
|
}
|
||||||
|
|
||||||
|
int unit_circle(float angle, char c)
|
||||||
|
{
|
||||||
|
if (c == 'x')
|
||||||
|
{
|
||||||
|
if (angle > 0 && angle < M_PI)
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
else if (c == 'y')
|
||||||
|
{
|
||||||
|
if (angle > (M_PI / 2) && angle < (3 * M_PI) / 2)
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/11/14 09:35:53 by aortigos #+# #+# */
|
/* Created: 2025/11/14 09:35:53 by aortigos #+# #+# */
|
||||||
/* Updated: 2025/11/16 20:29:38 by aortigos ### ########.fr */
|
/* Updated: 2025/12/09 19:45:29 by aortigos ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -31,4 +31,4 @@ int main(int argc, char **argv)
|
|||||||
return (1);
|
return (1);
|
||||||
execution(&data);
|
execution(&data);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,64 +1,64 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* frees.c :+: :+: :+: */
|
/* frees.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/11/28 20:03:22 by aortigos #+# #+# */
|
/* Created: 2025/11/28 20:03:22 by aortigos #+# #+# */
|
||||||
/* Updated: 2025/11/28 20:09:04 by aortigos ### ########.fr */
|
/* Updated: 2025/12/09 19:46:17 by aortigos ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../../includes/cub3d.h"
|
#include "../../includes/cub3d.h"
|
||||||
|
|
||||||
void freetl(char *ture, char *line, int fd)
|
void freetl(char *ture, char *line, int fd)
|
||||||
|
{
|
||||||
|
if (ture)
|
||||||
|
ft_memfree(ture);
|
||||||
|
if (line)
|
||||||
|
ft_memfree(line);
|
||||||
|
if (fd >= 0)
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_map(t_data *data)
|
||||||
|
{
|
||||||
|
free2d(data->sq_map);
|
||||||
|
free2d(data->map2d);
|
||||||
|
free2d(data->ture2d);
|
||||||
|
if (data->ff)
|
||||||
|
free2d(data->ff);
|
||||||
|
if (data->cc)
|
||||||
|
free2d(data->cc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_m(t_mlx *mlx)
|
||||||
|
{
|
||||||
|
if (mlx->dt->sq_map)
|
||||||
|
free2d(mlx->dt->sq_map);
|
||||||
|
if (mlx->dt->map2d)
|
||||||
|
free2d(mlx->dt->map2d);
|
||||||
|
if (mlx->dt->ture2d)
|
||||||
|
free2d(mlx->dt->ture2d);
|
||||||
|
if (mlx->dt->ff)
|
||||||
|
free2d(mlx->dt->ff);
|
||||||
|
if (mlx->dt->cc)
|
||||||
|
free2d(mlx->dt->cc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void freelist(t_turelist **txture)
|
||||||
|
{
|
||||||
|
t_turelist *tmp;
|
||||||
|
|
||||||
|
tmp = *txture;
|
||||||
|
while (tmp)
|
||||||
{
|
{
|
||||||
if (ture)
|
*txture = tmp->next;
|
||||||
ft_memfree(ture);
|
ft_memfree(tmp->name);
|
||||||
if (line)
|
ft_memfree(tmp->value);
|
||||||
ft_memfree(line);
|
ft_memfree(tmp);
|
||||||
if (fd >= 0)
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
void free_map(t_data *data)
|
|
||||||
{
|
|
||||||
free2d(data->sq_map);
|
|
||||||
free2d(data->map2d);
|
|
||||||
free2d(data->ture2d);
|
|
||||||
if (data->ff)
|
|
||||||
free2d(data->ff);
|
|
||||||
if (data->cc)
|
|
||||||
free2d(data->cc);
|
|
||||||
}
|
|
||||||
|
|
||||||
void free_m(t_mlx *mlx)
|
|
||||||
{
|
|
||||||
if (mlx->dt->sq_map)
|
|
||||||
free2d(mlx->dt->sq_map);
|
|
||||||
if(mlx->dt->map2d)
|
|
||||||
free2d(mlx->dt->map2d);
|
|
||||||
if (mlx->dt->ture2d)
|
|
||||||
free2d(mlx->dt->ture2d);
|
|
||||||
if (mlx->dt->ff)
|
|
||||||
free2d(mlx->dt->ff);
|
|
||||||
if (mlx->dt->cc)
|
|
||||||
free2d(mlx->dt->cc);
|
|
||||||
}
|
|
||||||
|
|
||||||
void freelist(t_turelist **txture)
|
|
||||||
{
|
|
||||||
t_turelist *tmp;
|
|
||||||
|
|
||||||
tmp = *txture;
|
tmp = *txture;
|
||||||
while (tmp)
|
|
||||||
{
|
|
||||||
*txture = tmp->next;
|
|
||||||
ft_memfree(tmp->name);
|
|
||||||
ft_memfree(tmp->value);
|
|
||||||
ft_memfree(tmp);
|
|
||||||
tmp = *txture;
|
|
||||||
}
|
|
||||||
ft_memfree(*txture);
|
|
||||||
}
|
}
|
||||||
|
ft_memfree(*txture);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* textures.c :+: :+: :+: */
|
/* lst_textures.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/12/01 08:48:55 by aortigos #+# #+# */
|
/* Created: 2025/12/01 08:48:55 by aortigos #+# #+# */
|
||||||
/* Updated: 2025/12/01 10:02:55 by aortigos ### ########.fr */
|
/* Updated: 2025/12/09 19:51:07 by aortigos ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -29,11 +29,11 @@ t_turelist *new_texture(char *line)
|
|||||||
while (ft_isspace(*line))
|
while (ft_isspace(*line))
|
||||||
line++;
|
line++;
|
||||||
if ((!ft_strncmp(line, "NO", 2) || !ft_strncmp(line, "sO", 2))
|
if ((!ft_strncmp(line, "NO", 2) || !ft_strncmp(line, "sO", 2))
|
||||||
|| !ft_strncmp(line, "WE", 2) || !ft_strncmp(line, "EA", 2))
|
|| !ft_strncmp(line, "WE", 2) || !ft_strncmp(line, "EA", 2))
|
||||||
{
|
{
|
||||||
list->name = ft_substr(line, 0, 2);
|
list->name = ft_substr(line, 0, 2);
|
||||||
list->value = ft_substr(line, get_index(line, 2), ft_strlen(line));
|
list->value = ft_substr(line, get_index(line, 2), ft_strlen(line));
|
||||||
}
|
}
|
||||||
else if ((!ft_strncmp(line, "F", 1) || !ft_strncmp(line, "C", 1)))
|
else if ((!ft_strncmp(line, "F", 1) || !ft_strncmp(line, "C", 1)))
|
||||||
{
|
{
|
||||||
list->name = ft_substr(line, 0, 1);
|
list->name = ft_substr(line, 0, 1);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/11/25 19:47:38 by aortigos #+# #+# */
|
/* Created: 2025/11/25 19:47:38 by aortigos #+# #+# */
|
||||||
/* Updated: 2025/11/28 20:01:02 by aortigos ### ########.fr */
|
/* Updated: 2025/12/09 19:47:13 by aortigos ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -14,22 +14,22 @@
|
|||||||
|
|
||||||
int read_map(char *av, t_data *map, int *count)
|
int read_map(char *av, t_data *map, int *count)
|
||||||
{
|
{
|
||||||
map->fd = open(av, O_RDONLY);
|
map->fd = open(av, O_RDONLY);
|
||||||
if (map->fd == -1)
|
if (map->fd == -1)
|
||||||
return (ft_putstr_fd(ERR_INV_FILE, 2), 0);
|
return (ft_putstr_fd(ERR_INV_FILE, 2), 0);
|
||||||
map->line = get_next_line(map->fd);
|
map->line = get_next_line(map->fd);
|
||||||
if (map->line == NULL)
|
if (map->line == NULL)
|
||||||
return (ft_putstr_fd(ERR_EMPTY_FILE, 2), 0);
|
return (ft_putstr_fd(ERR_EMPTY_FILE, 2), 0);
|
||||||
map->ture = ft_strdup("");
|
map->ture = ft_strdup("");
|
||||||
process_map(map, count);
|
process_map(map, count);
|
||||||
if (!check_count_textures(map, *count))
|
if (!check_count_textures(map, *count))
|
||||||
return (freetl(map->ture, map->line, map->fd), 0);
|
return (freetl(map->ture, map->line, map->fd), 0);
|
||||||
map->ture2d = ft_split(map->ture, '\n');
|
map->ture2d = ft_split(map->ture, '\n');
|
||||||
if (!map->ture2d)
|
if (!map->ture2d)
|
||||||
return (freetl(map->ture, map->line, map->fd), 0);
|
return (freetl(map->ture, map->line, map->fd), 0);
|
||||||
if (!read_map_(map, *count))
|
if (!read_map_(map, *count))
|
||||||
return (freetl(map->ture, map->line, map->fd), free2d(map->ture2d), 0);
|
return (freetl(map->ture, map->line, map->fd), free2d(map->ture2d), 0);
|
||||||
return (freetl(map->ture, map->line, map->fd), 1);
|
return (freetl(map->ture, map->line, map->fd), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_x_y_player(t_data *data)
|
void get_x_y_player(t_data *data)
|
||||||
@@ -82,4 +82,4 @@ int parsing(int ac, char **av, t_data *data)
|
|||||||
return (free_map(data), freelist(&data->t_list), 0);
|
return (free_map(data), freelist(&data->t_list), 0);
|
||||||
get_x_y_player(data);
|
get_x_y_player(data);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/12/04 09:28:05 by aortigos #+# #+# */
|
/* Created: 2025/12/04 09:28:05 by aortigos #+# #+# */
|
||||||
/* Updated: 2025/12/04 09:59:45 by aortigos ### ########.fr */
|
/* Updated: 2025/12/09 19:52:54 by aortigos ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -26,12 +26,13 @@ int is_validmap(char *line, int *flag)
|
|||||||
i = -1;
|
i = -1;
|
||||||
while (line[++i])
|
while (line[++i])
|
||||||
{
|
{
|
||||||
if ((line[i] != '1' && line[i] != 32 && line[i] != '0'
|
if ((line[i] != '1' && line[i] != '0'
|
||||||
&& line[i] != '\n') && !(line[i] != 'W' || line[i] != 'E'
|
&& line[i] != ' ' && line[i] != '\n'
|
||||||
|| line[i] != 'N' || line[i] != 'S'))
|
&& line[i] != 'W' && line[i] != 'E'
|
||||||
|
&& line[i] != 'N' && line[i] != 'S'))
|
||||||
return (0);
|
return (0);
|
||||||
else if (line[i] != 'W' || line[i] != 'E' || line[i] != 'N'
|
else if (line[i] == 'W' || line[i] == 'E' || line[i] == 'N'
|
||||||
|| line[i] != 'S')
|
|| line[i] == 'S')
|
||||||
(*flag)++;
|
(*flag)++;
|
||||||
}
|
}
|
||||||
return (1);
|
return (1);
|
||||||
@@ -45,8 +46,8 @@ char *getmap(t_data *map)
|
|||||||
while (map->line)
|
while (map->line)
|
||||||
{
|
{
|
||||||
if (map->line[0] == '\n')
|
if (map->line[0] == '\n')
|
||||||
return (ft_putstr_fd(ERR_MAP_EMPTY, 2), freetl(map->map, map->line,
|
return (ft_putstr_fd(ERR_MAP_EMPTY, 2),
|
||||||
-1), NULL);
|
freetl(map->map, map->line, -1), NULL);
|
||||||
tmp = ft_strjoin(map->map, map->line);
|
tmp = ft_strjoin(map->map, map->line);
|
||||||
ft_memfree(map->map);
|
ft_memfree(map->map);
|
||||||
ft_memfree(map->line);
|
ft_memfree(map->line);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/12/04 10:07:52 by aortigos #+# #+# */
|
/* Created: 2025/12/04 10:07:52 by aortigos #+# #+# */
|
||||||
/* Updated: 2025/12/04 10:32:30 by aortigos ### ########.fr */
|
/* Updated: 2025/12/09 19:51:28 by aortigos ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -67,8 +67,8 @@ int check_dup(t_data *m)
|
|||||||
int check_first_last_line(char **map)
|
int check_first_last_line(char **map)
|
||||||
{
|
{
|
||||||
if (!map[0])
|
if (!map[0])
|
||||||
return (ft_putstr_fd(ERR_MAP_INV, 2), 0);
|
return (ft_putstr_fd(ERR_MAP_INV, 2), 0);
|
||||||
if (!line_around_one(map[0]) || !line_around_one(map[ft_arraylen(map) - 1]))
|
if (!line_around_one(map[0]) || !line_around_one(map[ft_arraylen(map) - 1]))
|
||||||
return (ft_putstr_fd("one Y\n", 2), 0);
|
return (ft_putstr_fd("one Y\n", 2), 0);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
@@ -81,9 +81,9 @@ int surrounded_by_one(char **map)
|
|||||||
flag = 0;
|
flag = 0;
|
||||||
i = -1;
|
i = -1;
|
||||||
while (map[++i])
|
while (map[++i])
|
||||||
if (!is_surrounded(map[i]) || !is_validmap(map[i], &flag) || flag > 1)
|
if (!is_surrounded(map[i]) || !is_validmap(map[i], &flag) || flag > 1)
|
||||||
return (ft_putstr_fd("one X\n", 2), 0);
|
return (ft_putstr_fd("one X\n", 2), 0);
|
||||||
if (flag == 0)
|
if (flag == 0)
|
||||||
return (ft_putstr_fd("no position map\n", 2), 0);
|
return (ft_putstr_fd("no position map\n", 2), 0);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/12/05 15:42:28 by aortigos #+# #+# */
|
/* Created: 2025/12/05 15:42:28 by aortigos #+# #+# */
|
||||||
/* Updated: 2025/12/05 16:06:21 by aortigos ### ########.fr */
|
/* Updated: 2025/12/09 19:55:01 by aortigos ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -18,16 +18,16 @@ int check_color_values(char **rgb)
|
|||||||
|
|
||||||
i = -1;
|
i = -1;
|
||||||
while (rgb[++i])
|
while (rgb[++i])
|
||||||
if (ft_atoi(rgb[i]) > 255 || ft_atoi(rgb[i]) < 0)
|
if (ft_atoi(rgb[i]) > 255 || ft_atoi(rgb[i]) < 0)
|
||||||
return (free2d(rgb), 0);
|
return (free2d(rgb), 0);
|
||||||
return (free2d(rgb), 1);
|
return (free2d(rgb), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_process_rgb_color(t_turelist *tmp, t_data *m)
|
void ft_process_rgb_color(t_turelist *tmp, t_data *m)
|
||||||
{
|
{
|
||||||
if (!f_strncmp(tmp->name, "F", 2))
|
if (!ft_strncmp(tmp->name, "F", 2))
|
||||||
m->ff = ft_split(tmp->value, ',');
|
m->ff = ft_split(tmp->value, ',');
|
||||||
else if(!ft_strncmp(tmp->name, "C", 2))
|
else if (!ft_strncmp(tmp->name, "C", 2))
|
||||||
m->cc = ft_split(tmp->value, ',');
|
m->cc = ft_split(tmp->value, ',');
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
@@ -35,15 +35,18 @@ void ft_process_rgb_color(t_turelist *tmp, t_data *m)
|
|||||||
int color_ture(t_data *m, t_turelist *l_ture)
|
int color_ture(t_data *m, t_turelist *l_ture)
|
||||||
{
|
{
|
||||||
t_turelist *tmp;
|
t_turelist *tmp;
|
||||||
|
char **colors;
|
||||||
|
|
||||||
m->cc = NULL;
|
m->cc = NULL;
|
||||||
m->ff = NULL;
|
m->ff = NULL;
|
||||||
tmp = l_ture;
|
tmp = l_ture;
|
||||||
while (tmp)
|
while (tmp)
|
||||||
{
|
{
|
||||||
if (!ft_strncmp(tmp->name, "F", 1) || !ft_strncmp(tmp->name, "C", 1))
|
if (tmp->name && (!ft_strncmp(tmp->name, "F", 1)
|
||||||
|
|| !ft_strncmp(tmp->name, "C", 1)))
|
||||||
{
|
{
|
||||||
if (!check_color_values(ft_split(tmp->value, ',')))
|
colors = ft_split(tmp->value, ',');
|
||||||
|
if (!check_color_values(colors))
|
||||||
return (ft_putstr_fd(ERR_MAP_RGB, 2), 0);
|
return (ft_putstr_fd(ERR_MAP_RGB, 2), 0);
|
||||||
ft_process_rgb_color(tmp, m);
|
ft_process_rgb_color(tmp, m);
|
||||||
}
|
}
|
||||||
@@ -56,15 +59,15 @@ int check_color_textures(char *line)
|
|||||||
{
|
{
|
||||||
while (ft_isspace(*line))
|
while (ft_isspace(*line))
|
||||||
line++;
|
line++;
|
||||||
return ((!ft_strncmp(line, "EA", 2) || !ft_strncmp(line, "NO", 2)
|
return ((!ft_strncmp(line, "EA", 2) || !ft_strncmp(line, "NO", 2)
|
||||||
|| !ft_strncmp(line, "SO", 2) || !ft_strncmp(line, "WE", 2))
|
|| !ft_strncmp(line, "SO", 2) || !ft_strncmp(line, "WE", 2))
|
||||||
|| (!ft_strncmp(line, "F", 1) || !ft_strncmp(line, "C", 1)));
|
|| (!ft_strncmp(line, "F", 1) || !ft_strncmp(line, "C", 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_count_textures(t_data *m, int count)
|
int check_count_textures(t_data *m, int count)
|
||||||
{
|
{
|
||||||
(void)m;
|
(void)m;
|
||||||
if (count != 6)
|
if (count != 6)
|
||||||
return (ft_putstr_fd(ERR_MAP_INV, 2), 0);
|
return (ft_putstr_fd(ERR_MAP_INV, 2), 0);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,11 @@
|
|||||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/12/05 16:09:33 by aortigos #+# #+# */
|
/* Created: 2025/12/05 16:09:33 by aortigos #+# #+# */
|
||||||
/* Updated: 2025/12/05 16:29:28 by aortigos ### ########.fr */
|
/* Updated: 2025/12/09 19:50:46 by aortigos ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../../cub3d.h"
|
#include "../../includes/cub3d.h"
|
||||||
|
|
||||||
int is_valid_texture(char *line)
|
int is_valid_texture(char *line)
|
||||||
{
|
{
|
||||||
@@ -18,11 +18,11 @@ int is_valid_texture(char *line)
|
|||||||
line++;
|
line++;
|
||||||
if ((!ft_strncmp(line, "NO", 2) || !ft_strncmp(line, "SO", 2)
|
if ((!ft_strncmp(line, "NO", 2) || !ft_strncmp(line, "SO", 2)
|
||||||
|| !ft_strncmp(line, "WE", 2) || !ft_strncmp(line, "EA", 2))
|
|| !ft_strncmp(line, "WE", 2) || !ft_strncmp(line, "EA", 2))
|
||||||
&& ft_isspace(line[2]))
|
&& ft_isspace(line[2]))
|
||||||
return (1);
|
return (1);
|
||||||
else if ((!ft_strncmp(line, "F", 1) || !ft_strncmp(line, "C", 1))
|
else if ((!ft_strncmp(line, "F", 1) || !ft_strncmp(line, "C", 1))
|
||||||
&& ft_isspace(line[1]))
|
&& ft_isspace(line[1]))
|
||||||
return (1);
|
return (1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ int check_pos_cf(char *l)
|
|||||||
i = 0;
|
i = 0;
|
||||||
while (ft_isspace(*l) || *l == 'C' || *l == 'F')
|
while (ft_isspace(*l) || *l == 'C' || *l == 'F')
|
||||||
{
|
{
|
||||||
if (*l == 'C' || *l == 'F')
|
if (*l == 'C' || *l == 'F')
|
||||||
flag++;
|
flag++;
|
||||||
l++;
|
l++;
|
||||||
}
|
}
|
||||||
@@ -58,10 +58,10 @@ int check_pos_cf(char *l)
|
|||||||
return (0);
|
return (0);
|
||||||
while (l[i])
|
while (l[i])
|
||||||
{
|
{
|
||||||
if ((!ft_isdigit(l[i]) && l[i] != ',') || (l[i] == ',' && l[i+1]
|
if ((!ft_isdigit(l[i]) && l[i] != ',') || (l[i] == ',' && l[i + 1]
|
||||||
&& l[i + 1] == ','))
|
&& l[i + 1] == ','))
|
||||||
return (0);
|
return (0);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ int line_around_one(char *line)
|
|||||||
while (line[++i])
|
while (line[++i])
|
||||||
if (line[i] != '1' && line[i] != 32)
|
if (line[i] != '1' && line[i] != 32)
|
||||||
return (0);
|
return (0);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *getlastline(char **map)
|
char *getlastline(char **map)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/12/05 16:30:33 by aortigos #+# #+# */
|
/* Created: 2025/12/05 16:30:33 by aortigos #+# #+# */
|
||||||
/* Updated: 2025/12/05 16:53:44 by aortigos ### ########.fr */
|
/* Updated: 2025/12/09 19:49:06 by aortigos ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -23,8 +23,8 @@ int h_map(char **map)
|
|||||||
j = 0;
|
j = 0;
|
||||||
while (map[i][j])
|
while (map[i][j])
|
||||||
{
|
{
|
||||||
if (map[i][j] != '1' && map [i][j] != ' ')
|
if (map[i][j] != '1' || map [i][j] != ' ')
|
||||||
if (map[i][j - 1] == ' ' || map[i][j + 1] == ' ')
|
if (map[i][j - 1] == ' ' || map[i][j + 1] == ' ')
|
||||||
return (ft_putstr_fd(ERR_MAP_INV, 2), 0);
|
return (ft_putstr_fd(ERR_MAP_INV, 2), 0);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@ int v_map(char **map)
|
|||||||
while (map[i][j])
|
while (map[i][j])
|
||||||
{
|
{
|
||||||
if (map[i][j] != '1' && map[i][j] != ' ')
|
if (map[i][j] != '1' && map[i][j] != ' ')
|
||||||
if (map[i - 1][j] == ' ' || map[i + 1][j] == ' ')
|
if (map[i - 1][j] == ' ' || map[i + 1][j] == ' ')
|
||||||
return (ft_putstr_fd(ERR_MAP_INV, 2), 0);
|
return (ft_putstr_fd(ERR_MAP_INV, 2), 0);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ char *fixline(char *line, int maxlen)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
new = ft_calloc(sizeof(char), (maxlen + 1));
|
new = ft_calloc(sizeof(char), (maxlen + 1));
|
||||||
if (!new)
|
if (!new)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
while (line[i])
|
while (line[i])
|
||||||
@@ -68,7 +68,7 @@ char *fixline(char *line, int maxlen)
|
|||||||
new[i] = line[i];
|
new[i] = line[i];
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
while (i < maxlen)
|
while (i < maxlen)
|
||||||
{
|
{
|
||||||
new[i] = ' ';
|
new[i] = ' ';
|
||||||
i++;
|
i++;
|
||||||
@@ -76,8 +76,7 @@ char *fixline(char *line, int maxlen)
|
|||||||
return (new);
|
return (new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getsize_line(char **map)
|
||||||
int getsize_line(char **map)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int max;
|
int max;
|
||||||
@@ -95,21 +94,21 @@ int valid_map(t_data *m)
|
|||||||
int i;
|
int i;
|
||||||
int maxlen;
|
int maxlen;
|
||||||
|
|
||||||
maxlen = getsize_line(m->map2d);
|
maxlen = getsize_line(m->map2d);
|
||||||
m->sq_map = ft_calloc(sizeof(char *), (ft_arraylen(m->map2d) + 1));
|
m->sq_map = ft_calloc(sizeof(char *), (ft_arraylen(m->map2d) + 1));
|
||||||
if (!m->sq_map)
|
if (!m->sq_map)
|
||||||
return (0);
|
return (0);
|
||||||
i = -1;
|
i = -1;
|
||||||
while (m->map2d[++i])
|
while (m->map2d[++i])
|
||||||
{
|
{
|
||||||
if (maxlen == (int)ft_strlen(m->map2d[i]))
|
if (maxlen == (int)ft_strlen(m->map2d[i]))
|
||||||
m->sq_map[i] = ft_strdup(m->map2d[i]);
|
m->sq_map[i] = ft_strdup(m->map2d[i]);
|
||||||
else
|
else
|
||||||
m->sq_map[i] = fixline(m->map2d[i], maxlen);
|
m->sq_map[i] = fixline(m->map2d[i], maxlen);
|
||||||
}
|
}
|
||||||
m->h_map = ft_arraylen(m->sq_map);
|
m->h_map = ft_arraylen(m->sq_map);
|
||||||
m->w_map = ft_strlen(m->sq_map[0]);
|
m->w_map = ft_strlen(m->sq_map[0]);
|
||||||
if (!h_map(m->sq_map) || !v_map(m->sq_map))
|
if (!h_map(m->sq_map) || !v_map(m->sq_map))
|
||||||
return (free2d(m->sq_map), free2d(m->map2d), free2d(m->ture2d), 0);
|
return (free2d(m->sq_map), free2d(m->map2d), free2d(m->ture2d), 0);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user