diff --git a/Makefile b/Makefile index 0463881..a90e203 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: fgras-ca +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/01/14 16:54:48 by fgras-ca #+# #+# # -# Updated: 2024/01/23 19:56:56 by fgras-ca ### ########.fr # +# Updated: 2024/01/29 20:12:12 by fgras-ca ### ########.fr # # # # **************************************************************************** # @@ -24,7 +24,6 @@ WHITE = \033[0;97m ORANGE = \033[38;5;214m NAME = cub3d -LIBFT = libft.a SRC = main.c \ ./utils/ft_utils_gnl.c \ @@ -32,7 +31,6 @@ SRC = main.c \ ./utils/ft_utils_convert.c \ ./utils/ft_utils_str_1.c \ ./parsing/ft_map_check.c \ - ./parsing/ft_read_map.c \ ./parsing/ft_map_dimensions.c \ ./parsing/ft_parsing.c \ ./move/ft_collision.c \ @@ -43,6 +41,7 @@ SRC = main.c \ ./draw/ft_2d_view.c \ ./draw/ft_textures.c \ ./draw/ft_3d_view.c \ + ./draw/ft_3d_view_utils.c \ ./draw/ft_horizontal_ray.c \ ./draw/ft_vertical_ray.c \ ./draw/ft_pixel.c \ @@ -56,10 +55,9 @@ SRC = main.c \ ./parsing/ft_find_map_start.c \ ./parsing/ft_textures_and_colors.c \ ./parsing/ft_find_player_position.c \ - -SRC_DIR_LIBFT = libft/ - -SRC_LIBFT = $(addprefix $(SRC_DIR_LIBFT), $(LIBFT)) + ./parsing/ft_find_player_utils.c \ + ./parsing/ft_map_check_utils.c \ + ./parsing/ft_text_and_col_utils.c \ OBJ = $(SRC:.c=.o) diff --git a/cub3d.h b/cub3d.h index b308b4a..574e70f 100644 --- a/cub3d.h +++ b/cub3d.h @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/14 16:56:52 by fgras-ca #+# #+# */ -/* Updated: 2024/01/28 22:03:37 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 20:09:43 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,29 +24,30 @@ # include "include/mlx.h" # ifndef BUFFER_SIZE -# define BUFFER_SIZE 100000 +# define BUFFER_SIZE 100000 # endif # define PI 3.14159265359 -# define P2 PI/2 -# define P3 3*PI/2 +# define P2 1.57079632679 +# define P3 4.71238898038 # define COLBUF 1 # define NUMRAY 1280 # define FOVIEW 60 # define DISRAY 1000000 # define DOF 120 -# define WIDTH 1780 +# define WIDTH 1680 # define HEIGHT 720 -# define BOV 500 +# define BOV 400 # define MAX_LINE_LENGTH 100000 +# define DX_LENGTH 8 -typedef enum { +typedef enum s_WallDirection { NORTH, SOUTH, WEST, EAST, - NONE // Utilisé lorsqu'aucun mur n'est touché -} WallDirection; + NONE +} t_WallDirection; typedef struct s_img { @@ -108,15 +109,15 @@ typedef struct s_struture_windows typedef struct s_texture { - char *north; - char *south; - char *west; - char *east; + char *north; + char *south; + char *west; + char *east; char *door; char *door_open; - unsigned int floor_color; - unsigned int ceil_color; -} t_texture; + unsigned int floor_color; + unsigned int ceil_color; +} t_texture; typedef struct s_struture_map { @@ -126,9 +127,9 @@ typedef struct s_struture_map int i; int j; int temp; - int mapX; - int mapY; - int mapS; + int map_x; + int map_y; + int map_s; float player_x; float player_y; char player_direction; @@ -136,10 +137,14 @@ typedef struct s_struture_map } t_structure_map; typedef struct s_sprite { - void *frames[3]; // Tableau pour stocker les frames du sprite - int width, height; // Dimensions du sprite - int current_frame; // Index de la frame actuelle -} t_sprite; + void *frames[3]; + int width; + int height; + int current_frame; + float world_x; + float world_y; + float distance; +} t_sprite; typedef struct s_structure_main { @@ -166,7 +171,7 @@ typedef struct s_res_params { int original_y; int pixel_pos_rescaled; int pixel_pos_original; -} t_res_params; +} t_res_params; typedef struct s_rescale_params { void *original_img; @@ -177,30 +182,29 @@ typedef struct s_rescale_params { int px; int py; t_res_params *res; -} t_rescale_params; +} t_rescale_params; typedef struct s_position_params { int *future_px; int *future_py; int pdx; int pdy; - int collisionBuffer; + int collision_buffer; int px; int py; double pa; char direction; -} t_position_params; - +} t_position_params; typedef struct s_map_params { t_structure_map *map_info; const char *buffer; int length; - int *maxWidth; + int *max_width; int *height; - int *currentWidth; - int *isNewLine; -} t_map_params; + int *current_width; + int *is_new_line; +} t_map_params; typedef struct s_square_params { t_structure_main *w; @@ -209,15 +213,15 @@ typedef struct s_square_params { int xo; int yo; int color; -} t_square_params; +} t_square_params; typedef struct s_sky_ground_params { t_structure_main *w; - int startHeight; - int endHeight; + int start_height; + int end_height; int color; - int backgroundOffsetX; -} t_sky_ground_params; + int background_off_setx; +} t_sky_ground_params; typedef struct s_line_params { t_structure_main *w; @@ -226,7 +230,7 @@ typedef struct s_line_params { int x1; int y1; int color; -} t_line_params; +} t_line_params; typedef struct s_line_deltas { int dx; @@ -235,53 +239,51 @@ typedef struct s_line_deltas { int sy; int err; t_line_params *params; -} t_line_deltas; - - +} t_line_deltas; typedef struct s_texture_params { t_structure_main *w; - int startX; - int endX; - float lineOff; - float lineH; - WallDirection wallDir; + int start_x; + int end_x; + float line_off; + float line_h; + t_WallDirection wall_dir; float rx; float ry; - float disT; -} t_texture_params; + float dis_t; +} t_texture_params; typedef struct s_ray_params { t_structure_main *w; t_square_params sq; t_texture_params texture; int r; - int tileSize; + int tile_size; float rx; float ry; - float disT; - WallDirection wallDir; - int numRays; + float dis_t; + t_WallDirection wall_dir; + int num_rays; int color; - int start3DHeight; - int max3DHeight; - float lineH; - float lineOff; - int backgroundOffsetX; + int start3d_height; + int max3d_height; + float line_h; + float line_off; + int background_off_setx; int raywidth; -} t_ray_params; +} t_ray_params; typedef struct s_ray_calc_params { t_structure_main *w; float ra; - float *disRay; + float *dis_ray; float *rx; float *ry; - WallDirection *wallDir; + t_WallDirection *wall_dir; float xo; float yo; int dof; -} t_ray_calc_params; +} t_ray_calc_params; typedef struct s_texture_data { @@ -295,71 +297,109 @@ typedef struct s_init_params { t_structure_main *w; int tilesize; int numrays; - float FOV; - float DR; -} t_init_params; + float fo_v; + float d_r; +} t_init_params; typedef struct s_ray_properties { - float disH; - float disV; - WallDirection hwalldir; - WallDirection vwalldir; + float dis_h; + float dis_v; + t_WallDirection hwalldir; + t_WallDirection vwalldir; float hx; float hy; float vx; float vy; -} t_ray_properties; +} t_ray_properties; -typedef struct { +typedef struct s_base_params { int tilesize; int numrays; - float FOV; - float DR; + float fo_v; + float d_r; float ra; -} t_base_params; +} t_base_params; -typedef struct { - float disH; - float disV; - float disT; +typedef struct s_ray_state { + float dis_h; + float dis_v; + float dis_t; float hx; float hy; float vx; float vy; - WallDirection hwalldir; - WallDirection vwalldir; -} t_ray_state; + t_WallDirection hwalldir; + t_WallDirection vwalldir; +} t_ray_state; -typedef struct { +typedef struct s_ray_calc { t_structure_main *w; int r; int color; -} t_ray_calc; +} t_ray_calc; -typedef struct { +typedef struct s_drawrays2d_params { t_base_params base_params; t_ray_state ray_state; t_ray_calc ray_calc; t_ray_params rayparams; t_ray_calc_params hrayparams; t_ray_calc_params vrayparams; -} t_drawrays2d_params; +} t_drawrays2d_params; -typedef struct { - int jkl; - int yui; -} t_state; +typedef struct s_state { + int jkl; + int yui; +} t_state; -typedef struct { - t_structure_main *w; - t_state state; -} t_global_struct; +typedef struct s_global_struct { + t_structure_main *w; + t_state state; +} t_global_struct; + +typedef struct s_draw_params +{ + int texturewidth; + int textureheight; + int texturex; + int textureY; + int a; + int b; + int c; + double step; + int x; + int i; +} t_draw_params; + +typedef struct s_collision_params +{ + int dx[DX_LENGTH]; + int dy[DX_LENGTH]; +} t_collision_params; + +typedef struct s_player_info +{ + bool *found_player; + t_structure_map *map; + int line_number; + int column_number; +} t_player_info; + +typedef struct s_point +{ + int x; + int y; +} t_point; + +typedef struct s_map_check +{ + char *map; + int maxWidth; + int height; +} t_map_check; -//ft_utils_split.c 5 / 5 char **ft_split(char const *s, char c); -//ft_utils_gnl.c 4 / 5 char *get_next_line(int fd); -/*ft_key.c 3/5*/ int *kill_prog(t_structure_main *w); void move(int key, t_structure_main *w); int deal_key(int key, t_structure_main *w); @@ -371,13 +411,12 @@ int ft_strncmp(const char *s1, const char *s2, size_t n); int ft_strcmp(const char *s1, const char *s2); void *ft_memcpy(void *dest, const void *src, size_t n); void *ft_memset(void *s, int c, size_t n); -/*collision*/ -int can_move_to(t_structure_main *w, double future_x, double future_y); +int can_move_to(t_structure_main *w, double future_x, double future_y); char *ft_itoa(int nb); void draw_black_ground(t_ray_params *params, t_texture_params tparams); -/*parsing*/ -int is_map_closed(char* map, int width, int height); -bool parse_map(const char *map_content, int length, t_structure_map *map_info); +int is_map_closed(char *map, int width, int height); +bool parse_map(const char *map_content, + int length, t_structure_map *map_info); int check_borders(char *map, int maxWidth, int height); int check_interior(char *map, int maxWidth, int height); void exit_error(t_structure_main *w); @@ -386,24 +425,25 @@ void process_character(t_map_params *params, int *i); void get_map_dimensions(t_map_params *params); void fill_map_space(t_structure_map *map_info, int maxWidth, int height); void copy_map_data(t_map_params *params); -bool load_cub_file(const char *filename, t_texture *textures, t_structure_map *map_info); +bool load_cub_file(const char *filename, + t_texture *textures, t_structure_map *map_info); bool parse_texture_line(const char *line, t_texture *textures); bool handle_map(int fd, char **map_buffer, int *map_length); bool parse_color_line(const char *line, unsigned int *color); +bool parse_number_from_str(const char **str, int *number); bool is_valid_texture(const char *line); bool handle_textures(int fd, t_texture *textures); -bool find_player_position_and_direction(const char *map_content, int length, t_structure_map *map_info); +bool find_player(const char *map_content, + int length, t_structure_map *map); void calculate_map(t_structure_map *map_info); -/*textures*/ void load_wall_textures(t_structure_main *w); void draw_texture(t_texture_params *tex_params); -int get_texture_color(t_structure_main *w, WallDirection wallDir, int textureX, int textureY); -void draw_yolo(t_ray_params *rparams, t_texture_params *tparams, int deca); -/*3D view*/ +int get_texture_color(t_structure_main *w, + t_WallDirection wallDir, int textureX, int textureY); +void draw_yolo(t_ray_params *rparams, t_texture_params *tparams, int deca); void drawray(t_ray_params *ray_params); void draw_background(t_structure_main *w); float correctFisheye(float distance, float ra, float playerAngle); -//2D map void rescale_image(t_rescale_params *params, t_structure_main *w); void draw_square(t_structure_main *w, int x, int y, int color); void draw_map(t_structure_main *w); @@ -411,20 +451,27 @@ void put_pixel_img(t_structure_main *w, int x, int y, int color); void draw_square_raw(t_square_params *params); void draw_line(t_line_params *params); void drawrays2d(t_structure_main *w); -//Ray void calculateverticalray(t_ray_calc_params *params); void handle_ra_vertical(t_ray_calc_params *params, float nTan, int tileSize); void calculatehorizontalray(t_ray_calc_params *params); -void handle_ra_not_equal_pi(t_ray_calc_params *params, float atan, int tilesize); +void handle_ra_not_equal_pi(t_ray_calc_params *params, + float atan, int tilesize); float dist(float ax, float ay, float bx, float by); -//window void init_windows(t_structure_main *w); void init_player(t_structure_main *w); void init_mlx_and_window(t_structure_main *w); void sleep_mouse(t_global_struct *global_struct); -//sprite -void load_sprite_frames(t_sprite *sprite, void *mlx_ptr); -void update_sprite_frame(t_sprite *sprite); -void draw_sprite(t_sprite *sprite, void *mlx_ptr, void *win_ptr, int win_width, int win_height); +void init_line_params(t_line_params *lineparams, t_ray_params *rayParams); +void init_texture_params(t_texture_params *textureparams, + t_ray_params *rayParams); +void initialize_variables(int *i, int *line_number, + int *column_number, bool *found_player); +bool check_for_player(char current_char, bool *found_player); +void update_player_info(t_structure_map *map_info, + int line_number, int column_number, char player_direction); +void update_position(char current_char, int *line_number, int *column_number); +bool check_for_multiple_players(bool found_player); +int check_boundaries(t_point p, t_map_check *map_check); +int is_space_surrounded_by_walls(t_map_check *map_check, t_point p); #endif diff --git a/draw/ft_2d_view.c b/draw/ft_2d_view.c index 58f825b..dc37893 100644 --- a/draw/ft_2d_view.c +++ b/draw/ft_2d_view.c @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/12 17:49:42 by fgras-ca #+# #+# */ -/* Updated: 2024/01/23 17:43:56 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 16:20:39 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,39 +26,39 @@ float correctfisheye(float distance, float ra, float playerAngle) void init_base_params(t_base_params *params, t_structure_main *w) { - params->tilesize = w->s_map.mapS; + params->tilesize = w->s_map.map_s; params->numrays = NUMRAY; - params->FOV = FOVIEW * (PI / 180); - params->DR = params->FOV / params->numrays; - params->ra = w->s_player.pa - (params->FOV / 2); + params->fo_v = FOVIEW * (PI / 180); + params->d_r = params->fo_v / params->numrays; + params->ra = w->s_player.pa - (params->fo_v / 2); draw_background(w); } void calculate_ray(t_base_params *base, t_ray_state *state, t_ray_calc *calc, t_ray_params *rayparams) { - if (state->disH < state->disV) + if (state->dis_h < state->dis_v) { - rayparams->disT = state->disH; + rayparams->dis_t = state->dis_h; calc->color = 0xFF0000; - rayparams->wallDir = state->hwalldir; + rayparams->wall_dir = state->hwalldir; rayparams->rx = state->hx; rayparams->ry = state->hy; } else { - rayparams->disT = state->disV; + rayparams->dis_t = state->dis_v; calc->color = 0x00FF00; - rayparams->wallDir = state->vwalldir; + rayparams->wall_dir = state->vwalldir; rayparams->rx = state->vx; rayparams->ry = state->vy; } - rayparams->disT = correctfisheye(rayparams->disT, + rayparams->dis_t = correctfisheye(rayparams->dis_t, base->ra, calc->w->s_player.pa); rayparams->w = calc->w; - rayparams->tileSize = base->tilesize; + rayparams->tile_size = base->tilesize; rayparams->r = calc->r; - rayparams->numRays = base->numrays; + rayparams->num_rays = base->numrays; rayparams->color = calc->color; } @@ -73,16 +73,16 @@ void drawrays2d(t_structure_main *w) { params.base_params.ra = fmod(params.base_params.ra + 2 * PI, 2 * PI); params.hrayparams = (t_ray_calc_params){w, params.base_params.ra, - ¶ms.ray_state.disH, ¶ms.ray_state.hx, + ¶ms.ray_state.dis_h, ¶ms.ray_state.hx, ¶ms.ray_state.hy, ¶ms.ray_state.hwalldir}; params.vrayparams = (t_ray_calc_params){w, params.base_params.ra, - ¶ms.ray_state.disV, ¶ms.ray_state.vx, + ¶ms.ray_state.dis_v, ¶ms.ray_state.vx, ¶ms.ray_state.vy, ¶ms.ray_state.vwalldir}; calculatehorizontalray(¶ms.hrayparams); calculateverticalray(¶ms.vrayparams); calculate_ray(¶ms.base_params, ¶ms.ray_state, ¶ms.ray_calc, ¶ms.rayparams); drawray(¶ms.rayparams); - params.base_params.ra += params.base_params.DR; + params.base_params.ra += params.base_params.d_r; } } diff --git a/draw/ft_3d_view.c b/draw/ft_3d_view.c index 108b878..3256678 100644 --- a/draw/ft_3d_view.c +++ b/draw/ft_3d_view.c @@ -6,32 +6,50 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/12 17:35:53 by fgras-ca #+# #+# */ -/* Updated: 2024/01/26 17:25:05 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 17:05:58 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #include "../cub3d.h" -void init_line_params(t_line_params *lineparams, t_ray_params *rayParams) +static void calculate_line_height(t_ray_params *rayparams) { - lineparams->w = rayParams->w; - lineparams->x0 = (int)rayParams->w->s_player.px; - lineparams->y0 = (int)rayParams->w->s_player.py; - lineparams->x1 = (int)rayParams->rx; - lineparams->y1 = (int)rayParams->ry; - lineparams->color = rayParams->color; + rayparams->line_h = (rayparams->tile_size * rayparams->max3d_height) + / rayparams->dis_t; + if (rayparams->line_h > rayparams->max3d_height) + { + rayparams->line_h = rayparams->max3d_height; + } + rayparams->line_off = ((rayparams->max3d_height - rayparams->line_h) / 2); } -void init_texture_params(t_texture_params *textureparams, - t_ray_params *rayParams) +static void calculate_deca(t_ray_params *rayparams, float *olineh, int *deca) { - textureparams->w = rayParams->w; - textureparams->lineOff = rayParams->lineOff; - textureparams->lineH = rayParams->lineH; - textureparams->wallDir = rayParams->wallDir; - textureparams->rx = rayParams->rx + rayParams->backgroundOffsetX; - textureparams->ry = rayParams->ry; - textureparams->disT = rayParams->disT; + *olineh = (rayparams->w->s_map.map_s * rayparams->w->s_win.height) + / rayparams->dis_t; + if (*olineh > rayparams->w->s_win.height) + { + *deca = *olineh - rayparams->w->s_win.height; + } + else + { + *deca = 0; + } +} + +static void set_rayparams(t_ray_params *rayparams) +{ + rayparams->start3d_height = 0; + rayparams->max3d_height = rayparams->w->s_win.height + + rayparams->start3d_height; +} + +static void set_texture_params(t_ray_params *rayparams, + t_texture_params *textureparams) +{ + textureparams->start_x = rayparams->r * rayparams->raywidth + + rayparams->background_off_setx; + textureparams->end_x = textureparams->start_x + rayparams->raywidth; } void drawray(t_ray_params *rayparams) @@ -40,96 +58,23 @@ void drawray(t_ray_params *rayparams) t_texture_params textureparams; float olineh; int deca; - int color; - rayparams->start3DHeight = 0; - rayparams->max3DHeight = rayparams->w->s_win.height - + rayparams->start3DHeight; - rayparams->lineH = (rayparams->tileSize * rayparams->max3DHeight) - / rayparams->disT; - if (rayparams->lineH > rayparams->max3DHeight) - { - rayparams->lineH = rayparams->max3DHeight; - } - rayparams->lineOff = ((rayparams->max3DHeight - rayparams->lineH) / 2); - olineh = (rayparams->w->s_map.mapS * rayparams->w->s_win.height) / rayparams->disT; - rayparams->backgroundOffsetX = BOV; - rayparams->raywidth = rayparams->w->s_win.width / rayparams->numRays; - textureparams.startX = rayparams->r * rayparams->raywidth - + rayparams->backgroundOffsetX; - textureparams.endX = textureparams.startX + rayparams->raywidth; + set_rayparams(rayparams); + calculate_line_height(rayparams); + rayparams->raywidth = rayparams->w->s_win.width / rayparams->num_rays; + rayparams->background_off_setx = BOV; + calculate_deca(rayparams, &olineh, &deca); + set_texture_params(rayparams, &textureparams); init_texture_params(&textureparams, rayparams); init_line_params(&lineparams, rayparams); draw_line(&lineparams); - if (olineh > rayparams->w->s_win.height) - deca = olineh - rayparams->w->s_win.height; - else - deca = 0; draw_black_ground(rayparams, textureparams); if (deca != 0) + { draw_yolo(rayparams, &textureparams, deca); + } else + { draw_texture(&textureparams); -} - -void draw_yolo(t_ray_params *rparams, t_texture_params *tparams, int deca) -{ - int texturewidth; - int textureheight; - int i; - int y; - int x; - float perspectivefactor; - int texturex; - int color; - - texturewidth = tparams->w->s_img.texture_width; - textureheight = tparams->w->s_img.texture_height; - i = 0; - for (y = rparams->lineOff; y < rparams->lineOff + rparams->lineH; y++) { - // La variable perspectiveFactor permet de mapper la texture en tenant compte de la perspective - perspectivefactor = (float)(y - rparams->lineOff) / rparams->lineH; - int textureY = perspectivefactor * (textureheight ); - if (textureY >= textureheight) { - textureY = textureheight - 1; - } - - //for (int x = startX; x < endX; x++) { - x = tparams->startX; - switch (tparams->wallDir) { - case NORTH: - case SOUTH: - // Assurez-vous que rx est normalisé correctement pour le mappage de texture - texturex = (int)(tparams->rx * texturewidth / tparams->w->s_map.mapS) % texturewidth; - break; - case WEST: - case EAST: - // Assurez-vous que ry est normalisé correctement pour le mappage de texture - texturex = (int)(tparams->ry * texturewidth / tparams->w->s_map.mapS) % texturewidth; - break; - } - if (texturex >= texturewidth) { - texturex = texturewidth - 1; - } - //printf("%f %f\n",lineOff, lineOff/lineH); - - - color = get_texture_color(tparams->w, tparams->wallDir, texturex, y); - - - // BLOCK OK MEH - // float ww = ((720+merde)/lineH); - // //printf("%d %d %d\n", t ,td, merde); - // put_pixel_img(w, x, (int)(iii*ww)-merde/2, color); - // iii++; - - int a = tparams->lineOff - deca / 2; - int b = tparams->lineH + (deca /2); - int c = tparams->lineH; - double step = (b - a)/(double)(c - 1); - //printf("%d %d %d\n", t ,td, merde); - put_pixel_img(tparams->w, x, (int)(a + i * step), color); - i++; - //} } } diff --git a/draw/ft_3d_view_utils.c b/draw/ft_3d_view_utils.c new file mode 100644 index 0000000..0b7a378 --- /dev/null +++ b/draw/ft_3d_view_utils.c @@ -0,0 +1,93 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_3d_view_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: fgras-ca +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/01/29 17:00:21 by fgras-ca #+# #+# */ +/* Updated: 2024/01/29 17:05:55 by fgras-ca ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../cub3d.h" + +static void set_texture_coords(t_texture_params *tparams, + t_draw_params *dparams) +{ + if (tparams->wall_dir == NORTH || tparams->wall_dir == SOUTH) + { + dparams->texturex = (int)(tparams->rx * dparams->texturewidth + / tparams->w->s_map.map_s) % dparams->texturewidth; + } + else if (tparams->wall_dir == WEST || tparams->wall_dir == EAST) + { + dparams->texturex = (int)(tparams->ry * dparams->texturewidth + / tparams->w->s_map.map_s) % dparams->texturewidth; + } + if (dparams->texturex >= dparams->texturewidth) + { + dparams->texturex = dparams->texturewidth - 1; + } +} + +static void draw_texture_line(t_ray_params *rparams, + t_texture_params *tparams, t_draw_params *dparams, int deca) +{ + int y; + int color; + float perspectivefactor; + + y = rparams->line_off; + dparams->i = 0; + dparams->x = tparams->start_x; + while (y < rparams->line_off + rparams->line_h) + { + perspectivefactor = (float)(y - rparams->line_off) / rparams->line_h; + dparams->textureY = perspectivefactor * dparams->textureheight; + if (dparams->textureY >= dparams->textureheight) + dparams->textureY = dparams->textureheight - 1; + set_texture_coords(tparams, dparams); + color = get_texture_color(tparams->w, + tparams->wall_dir, dparams->texturex, y); + dparams->a = tparams->line_off - deca / 2; + dparams->b = tparams->line_h + (deca / 2); + dparams->c = tparams->line_h; + dparams->step = (dparams->b - dparams->a) / (double)(dparams->c - 1); + put_pixel_img(tparams->w, dparams->x, + (int)(dparams->a + dparams->i * dparams->step), color); + dparams->i++; + y++; + } +} + +void draw_yolo(t_ray_params *rparams, t_texture_params *tparams, int deca) +{ + t_draw_params dparams; + + dparams.texturewidth = tparams->w->s_img.texture_width; + dparams.textureheight = tparams->w->s_img.texture_height; + draw_texture_line(rparams, tparams, &dparams, deca); +} + +void init_line_params(t_line_params *lineparams, t_ray_params *rayParams) +{ + lineparams->w = rayParams->w; + lineparams->x0 = (int)rayParams->w->s_player.px; + lineparams->y0 = (int)rayParams->w->s_player.py; + lineparams->x1 = (int)rayParams->rx; + lineparams->y1 = (int)rayParams->ry; + lineparams->color = rayParams->color; +} + +void init_texture_params(t_texture_params *textureparams, + t_ray_params *rayParams) +{ + textureparams->w = rayParams->w; + textureparams->line_off = rayParams->line_off; + textureparams->line_h = rayParams->line_h; + textureparams->wall_dir = rayParams->wall_dir; + textureparams->rx = rayParams->rx + rayParams->background_off_setx; + textureparams->ry = rayParams->ry; + textureparams->dis_t = rayParams->dis_t; +} diff --git a/draw/ft_background.c b/draw/ft_background.c index 4a4ff1f..945bf43 100644 --- a/draw/ft_background.c +++ b/draw/ft_background.c @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/11 23:19:39 by fgras-ca #+# #+# */ -/* Updated: 2024/01/26 17:40:14 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 17:08:15 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,10 +17,10 @@ void draw_sky_ground(t_sky_ground_params *params) t_square_params square_params; square_params.w = params->w; - square_params.x = params->backgroundOffsetX; - square_params.y = params->startHeight; - square_params.xo = params->w->s_win.width + params->backgroundOffsetX; - square_params.yo = params->endHeight; + square_params.x = params->background_off_setx; + square_params.y = params->start_height; + square_params.xo = params->w->s_win.width + params->background_off_setx; + square_params.yo = params->end_height; square_params.color = params->color; draw_square_raw(&square_params); } @@ -33,16 +33,16 @@ void draw_background(t_structure_main *w) backgroundoffsetx = BOV; sky_params.w = w; - sky_params.startHeight = 0; - sky_params.endHeight = w->s_win.height / 2; + sky_params.start_height = 0; + sky_params.end_height = w->s_win.height / 2; sky_params.color = w->t->ceil_color; - sky_params.backgroundOffsetX = backgroundoffsetx; + sky_params.background_off_setx = backgroundoffsetx; draw_sky_ground(&sky_params); ground_params.w = w; - ground_params.startHeight = w->s_win.height / 2; - ground_params.endHeight = w->s_win.height; + ground_params.start_height = w->s_win.height / 2; + ground_params.end_height = w->s_win.height; ground_params.color = w->t->floor_color; - ground_params.backgroundOffsetX = backgroundoffsetx; + ground_params.background_off_setx = backgroundoffsetx; draw_sky_ground(&ground_params); } @@ -51,10 +51,10 @@ void draw_black_ground(t_ray_params *params, t_texture_params tparams) t_square_params square_params; square_params.w = params->w; - square_params.x = tparams.startX; - square_params.y = params->lineOff; + square_params.x = tparams.start_x; + square_params.y = params->line_off; square_params.xo = square_params.x + 1; - square_params.yo = params->lineOff + params->lineH ; + square_params.yo = params->line_off + params->line_h ; square_params.color = 0x000000; draw_square_raw(&square_params); -} \ No newline at end of file +} diff --git a/draw/ft_draw.c b/draw/ft_draw.c index bc2fb1c..e64f5b7 100644 --- a/draw/ft_draw.c +++ b/draw/ft_draw.c @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/11 22:38:28 by fgras-ca #+# #+# */ -/* Updated: 2024/01/14 17:54:44 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 15:47:48 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,9 +20,9 @@ void draw_square(t_structure_main *w, int x, int y, int color) int i; int j; - xo = x * w->s_map.mapS; - yo = y * w->s_map.mapS; - size = w->s_map.mapS; + xo = x * w->s_map.map_s; + yo = y * w->s_map.map_s; + size = w->s_map.map_s; i = 0; while (i < size) { diff --git a/draw/ft_horizontal_ray.c b/draw/ft_horizontal_ray.c index 5170326..5ca2f13 100644 --- a/draw/ft_horizontal_ray.c +++ b/draw/ft_horizontal_ray.c @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/12 19:53:47 by fgras-ca #+# #+# */ -/* Updated: 2024/01/25 20:37:32 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 17:12:54 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,38 +25,37 @@ void inithorizontalray(t_ray_calc_params *params) int tilesize; atan = -1 / tan(params->ra); - tilesize = params->w->s_map.mapS; + tilesize = params->w->s_map.map_s; if (params->ra != PI) handle_ra_not_equal_pi(params, atan, tilesize); else handle_ra_equal_pi(params); } -void update_ray_params(t_ray_calc_params *params, int mx, int my) { - int mp = my * params->w->s_map.mapX + mx; +void update_ray_params(t_ray_calc_params *params, int mx, int my) +{ + int mp; + char map_pos; - if (mp >= 0 && mp < params->w->s_map.mapX * params->w->s_map.mapY) { - char map_pos = params->w->s_map.map[mp]; - - if (map_pos == '1' || map_pos == '2') { - params->dof = DOF; - *params->disRay = dist(params->w->s_player.px, params->w->s_player.py, - *params->rx, *params->ry); - - if (params->ra > PI) - *params->wallDir = NORTH; - else - *params->wallDir = SOUTH; - - // Définir le type de mur actuel - if (map_pos == '2') { - params->w->current_wall_type = map_pos; - } else { - // Assurez-vous de réinitialiser pour les murs normaux - params->w->current_wall_type = '1'; - } - } - } + mp = my * params->w->s_map.map_x + mx; + if (mp >= 0 && mp < params->w->s_map.map_x * params->w->s_map.map_y) + { + map_pos = params->w->s_map.map[mp]; + if (map_pos == '1' || map_pos == '2') + { + params->dof = DOF; + *params->dis_ray = dist(params->w->s_player.px, + params->w->s_player.py, *params->rx, *params->ry); + if (params->ra > PI) + *params->wall_dir = NORTH; + else + *params->wall_dir = SOUTH; + if (map_pos == '2') + params->w->current_wall_type = map_pos; + else + params->w->current_wall_type = '1'; + } + } } void processhorizontalray(t_ray_calc_params *params) @@ -65,8 +64,8 @@ void processhorizontalray(t_ray_calc_params *params) int my; int tilesize; - tilesize = params->w->s_map.mapS; - *params->disRay = DISRAY; + tilesize = params->w->s_map.map_s; + *params->dis_ray = DISRAY; while (params->dof < DOF) { mx = (int)(*params->rx) / tilesize; diff --git a/draw/ft_load_textures.c b/draw/ft_load_textures.c index d0365ce..6d979fc 100644 --- a/draw/ft_load_textures.c +++ b/draw/ft_load_textures.c @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/14 20:30:59 by fgras-ca #+# #+# */ -/* Updated: 2024/01/25 20:34:50 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 17:13:50 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,7 +37,6 @@ void load_wall_textures(t_structure_main *w) load_texture(w, w->t->west, (void **)&w->s_img.west_texture); load_texture(w, w->t->east, (void **)&w->s_img.east_texture); load_texture(w, "textures/door_close.xpm", (void **)&w->s_img.door_texture); - //load_texture(w, "textures/open_door.xpm", (void **)&w->s_img.open_door_texture); } void exit_error(t_structure_main *w) diff --git a/draw/ft_textures.c b/draw/ft_textures.c index c346c6e..3b0dc3d 100644 --- a/draw/ft_textures.c +++ b/draw/ft_textures.c @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/12 17:39:11 by fgras-ca #+# #+# */ -/* Updated: 2024/01/25 20:34:32 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 17:17:21 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,19 +20,19 @@ void draw_texture_line(t_texture_params *params, float y, int textureY) int color; texturewidth = params->w->s_img.texture_width; - x = params->startX; - while (x < params->endX) + x = params->start_x; + while (x < params->end_x) { - if (params->wallDir == NORTH || params->wallDir == SOUTH) + if (params->wall_dir == NORTH || params->wall_dir == SOUTH) texturex = (int)(params->rx * texturewidth - / params->w->s_map.mapS) % texturewidth; + / params->w->s_map.map_s) % texturewidth; else texturex = (int)(params->ry * texturewidth - / params->w->s_map.mapS) % texturewidth; + / params->w->s_map.map_s) % texturewidth; if (texturex >= texturewidth) texturex = texturewidth - 1; color = get_texture_color(params->w, - params->wallDir, texturex, textureY); + params->wall_dir, texturex, textureY); put_pixel_img(params->w, x, y, color); x++; } @@ -46,10 +46,10 @@ void draw_texture(t_texture_params *params) int texturey; textureheight = params->w->s_img.texture_height; - y = params->lineOff; - while (y < params->lineOff + params->lineH) + y = params->line_off; + while (y < params->line_off + params->line_h) { - perspectivefactor = (y - params->lineOff) / params->lineH; + perspectivefactor = (y - params->line_off) / params->line_h; texturey = perspectivefactor * textureheight; if (texturey >= textureheight) texturey = textureheight - 1; @@ -58,14 +58,15 @@ void draw_texture(t_texture_params *params) } } -void *get_selected_texture(t_structure_main *w, WallDirection wallDir) +void *get_selected_texture(t_structure_main *w, t_WallDirection wallDir) { - void *texture = NULL; - if (w->current_wall_type == '2') { - return w->s_img.door_texture; // Texture pour porte fermée - } /*else if (w->current_wall_type == '3') { - return w->s_img.open_door_texture; // Texture pour porte ouverte - }*/ + void *texture; + + texture = NULL; + if (w->current_wall_type == '2') + { + return (w->s_img.door_texture); + } else if (wallDir == NORTH) return (w->s_img.north_texture); else if (wallDir == SOUTH) @@ -76,12 +77,12 @@ void *get_selected_texture(t_structure_main *w, WallDirection wallDir) return (w->s_img.east_texture); else { - fprintf(stderr, "Invalid wall direction.\n"); + printf("Invalid wall direction.\n"); exit_error(w); return (NULL); } - if (texture == NULL) - fprintf(stderr, "get_selected_texture: selected texture is NULL\n"); + if (texture == NULL) + printf("get_selected_texture: selected texture is NULL\n"); else printf("get_selected_texture: selected texture = %p\n", texture); } @@ -95,7 +96,7 @@ t_texture_data get_texture_data(void *texture) return (texture_data); } -int get_texture_color(t_structure_main *w, WallDirection wallDir, +int get_texture_color(t_structure_main *w, t_WallDirection wallDir, int textureX, int textureY) { void *selected_texture; @@ -108,7 +109,6 @@ int get_texture_color(t_structure_main *w, WallDirection wallDir, fprintf(stderr, "No texture selected for color retrieval\n"); return (0); } - texture_data = get_texture_data(selected_texture); pixel_pos = (textureX + textureY * w->s_img.texture_width) * (texture_data.bpp / 8); diff --git a/draw/ft_vertical_ray.c b/draw/ft_vertical_ray.c index 2033889..dfada0b 100644 --- a/draw/ft_vertical_ray.c +++ b/draw/ft_vertical_ray.c @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/12 20:03:21 by fgras-ca #+# #+# */ -/* Updated: 2024/01/25 20:37:08 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 17:22:00 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,35 +18,35 @@ void initverticalray(t_ray_calc_params *params) int tilesize; ntan = -tan(params->ra); - tilesize = params->w->s_map.mapS; + tilesize = params->w->s_map.map_s; handle_ra_vertical(params, ntan, tilesize); } -void update_vertical_ray_params(t_ray_calc_params *params, int mx, int my) { - int mp = my * params->w->s_map.mapX + mx; +void update_vertical_ray_params(t_ray_calc_params *params, int mx, int my) +{ + int mp; + char map_pos; - if (mp >= 0 && mp < params->w->s_map.mapX * params->w->s_map.mapY) { - char map_pos = params->w->s_map.map[mp]; - - if (map_pos == '1' || map_pos == '2') { - params->dof = DOF; - *params->disRay = dist(params->w->s_player.px, params->w->s_player.py, - *params->rx, *params->ry); - - if (params->ra > P2 && params->ra < P3) - *params->wallDir = WEST; - else - *params->wallDir = EAST; - - // Définir le type de mur actuel - if (map_pos == '2') { - params->w->current_wall_type = map_pos; - } else { - // Assurez-vous de réinitialiser pour les murs normaux - params->w->current_wall_type = '1'; - } - } - } + mp = my * params->w->s_map.map_x + mx; + if (mp >= 0 && mp < params->w->s_map.map_x * params->w->s_map.map_y) + { + map_pos = params->w->s_map.map[mp]; + if (map_pos == '1' || map_pos == '2') + { + params->dof = DOF; + *params->dis_ray = dist(params->w->s_player.px, + params->w->s_player.py, + *params->rx, *params->ry); + if (params->ra > P2 && params->ra < P3) + *params->wall_dir = WEST; + else + *params->wall_dir = EAST; + if (map_pos == '2') + params->w->current_wall_type = map_pos; + else + params->w->current_wall_type = '1'; + } + } } void processverticalray(t_ray_calc_params *params) @@ -55,8 +55,8 @@ void processverticalray(t_ray_calc_params *params) int my; int tilesize; - tilesize = params->w->s_map.mapS; - *params->disRay = DISRAY; + tilesize = params->w->s_map.map_s; + *params->dis_ray = DISRAY; while (params->dof < DOF) { mx = (int)(*params->rx) / tilesize; diff --git a/include/mlx.h b/include/mlx.h index b323412..fc751cd 100644 --- a/include/mlx.h +++ b/include/mlx.h @@ -1,139 +1,53 @@ -/* -** mlx.h for MinilibX in -** -** Made by Charlie Root -** Login -** -** Started on Mon Jul 31 16:37:50 2000 Charlie Root -** Last update Tue May 15 16:23:28 2007 Olivier Crouzet -*/ - -/* -** MinilibX - Please report bugs -*/ - - -/* -** FR msg - FR msg - FR msg -** -** La MinilibX utilise 2 librairies supplementaires qu'il -** est necessaire de rajouter a la compilation : -** -lmlx -lXext -lX11 -** -** La MinilibX permet le chargement des images de type Xpm. -** Notez que cette implementation est incomplete. -** Merci de communiquer tout probleme de chargement d'image -** de ce type. -*/ - +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* mlx.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: fgras-ca +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/01/29 17:22:58 by fgras-ca #+# #+# */ +/* Updated: 2024/01/29 17:28:02 by fgras-ca ### ########.fr */ +/* */ +/* ************************************************************************** */ #ifndef MLX_H - -#define MLX_H - +# define MLX_H void *mlx_init(); -/* -** needed before everything else. -** return (void *)0 if failed -*/ - - -/* -** Basic actions -*/ - void *mlx_new_window(void *mlx_ptr, int size_x, int size_y, char *title); -/* -** return void *0 if failed -*/ -int mlx_clear_window(void *mlx_ptr, void *win_ptr); -int mlx_pixel_put(void *mlx_ptr, void *win_ptr, int x, int y, int color); -/* -** origin for x & y is top left corner of the window -** y down is positive -** color is 0x00RRGGBB -*/ - - -/* -** Image stuff -*/ - +int mlx_clear_window(void *mlx_ptr, void *win_ptr); +int mlx_pixel_put(void *mlx_ptr, void *win_ptr, int x, int y, int color); void *mlx_new_image(void *mlx_ptr,int width,int height); -/* -** return void *0 if failed -** obsolete : image2 data is stored using bit planes -** void *mlx_new_image2(void *mlx_ptr,int width,int height); -*/ char *mlx_get_data_addr(void *img_ptr, int *bits_per_pixel, - int *size_line, int *endian); -/* -** endian : 0 = sever X is little endian, 1 = big endian -** for mlx_new_image2, 2nd arg of mlx_get_data_addr is number_of_planes -*/ -int mlx_put_image_to_window(void *mlx_ptr, void *win_ptr, void *img_ptr, + int *size_line, int *endian); +int mlx_put_image_to_window(void *mlx_ptr, void *win_ptr, void *img_ptr, int x, int y); -int mlx_get_color_value(void *mlx_ptr, int color); - - -/* -** dealing with Events -*/ - -int mlx_mouse_hook (void *win_ptr, int (*funct_ptr)(), void *param); -int mlx_key_hook (void *win_ptr, int (*funct_ptr)(), void *param); -int mlx_expose_hook (void *win_ptr, int (*funct_ptr)(), void *param); - -int mlx_loop_hook (void *mlx_ptr, int (*funct_ptr)(), void *param); -int mlx_loop (void *mlx_ptr); -int mlx_loop_end (void *mlx_ptr); - -/* -** hook funct are called as follow : -** -** expose_hook(void *param); -** key_hook(int keycode, void *param); -** mouse_hook(int button, int x,int y, void *param); -** loop_hook(void *param); -** -*/ - - -/* -** Usually asked... -*/ - -int mlx_string_put(void *mlx_ptr, void *win_ptr, int x, int y, int color, - char *string); +int mlx_get_color_value(void *mlx_ptr, int color); +int mlx_mouse_hook (void *win_ptr, int (*funct_ptr)(), void *param); +int mlx_key_hook (void *win_ptr, int (*funct_ptr)(), void *param); +int mlx_expose_hook (void *win_ptr, int (*funct_ptr)(), void *param); +int mlx_loop_hook (void *mlx_ptr, int (*funct_ptr)(), void *param); +int mlx_loop (void *mlx_ptr); +int mlx_loop_end (void *mlx_ptr); +int mlx_string_put(void *mlx_ptr, void *win_ptr, int x, int y, int color, + char *string); void mlx_set_font(void *mlx_ptr, void *win_ptr, char *name); void *mlx_xpm_to_image(void *mlx_ptr, char **xpm_data, - int *width, int *height); + int *width, int *height); void *mlx_xpm_file_to_image(void *mlx_ptr, char *filename, - int *width, int *height); -int mlx_destroy_window(void *mlx_ptr, void *win_ptr); + int *width, int *height); +int mlx_destroy_window(void *mlx_ptr, void *win_ptr); +int mlx_destroy_image(void *mlx_ptr, void *img_ptr); +int mlx_destroy_display(void *mlx_ptr); +int mlx_hook(void *win_ptr, int x_event, int x_mask, + int (*funct)(), void *param); +int mlx_do_key_autorepeatoff(void *mlx_ptr); +int mlx_do_key_autorepeaton(void *mlx_ptr); +int mlx_do_sync(void *mlx_ptr); +int mlx_mouse_get_pos(void *mlx_ptr, void *win_ptr, int *x, int *y); +int mlx_mouse_move(void *mlx_ptr, void *win_ptr, int x, int y); +int mlx_mouse_hide(void *mlx_ptr, void *win_ptr); +int mlx_mouse_show(void *mlx_ptr, void *win_ptr); +int mlx_get_screen_size(void *mlx_ptr, int *sizex, int *sizey); -int mlx_destroy_image(void *mlx_ptr, void *img_ptr); - -int mlx_destroy_display(void *mlx_ptr); - -/* -** generic hook system for all events, and minilibX functions that -** can be hooked. Some macro and defines from X11/X.h are needed here. -*/ - -int mlx_hook(void *win_ptr, int x_event, int x_mask, - int (*funct)(), void *param); - -int mlx_do_key_autorepeatoff(void *mlx_ptr); -int mlx_do_key_autorepeaton(void *mlx_ptr); -int mlx_do_sync(void *mlx_ptr); - -int mlx_mouse_get_pos(void *mlx_ptr, void *win_ptr, int *x, int *y); -int mlx_mouse_move(void *mlx_ptr, void *win_ptr, int x, int y); -int mlx_mouse_hide(void *mlx_ptr, void *win_ptr); -int mlx_mouse_show(void *mlx_ptr, void *win_ptr); - -int mlx_get_screen_size(void *mlx_ptr, int *sizex, int *sizey); - -#endif /* MLX_H */ +#endif diff --git a/libft/Makefile b/libft/Makefile deleted file mode 100644 index 9e89f17..0000000 --- a/libft/Makefile +++ /dev/null @@ -1,102 +0,0 @@ -# **************************************************************************** # -# # -# ::: :::::::: # -# Makefile :+: :+: :+: # -# +:+ +:+ +:+ # -# By: fgras-ca +#+ +:+ +#+ # -# +#+#+#+#+#+ +#+ # -# Created: 2023/02/06 12:19:21 by fgras-ca #+# #+# # -# Updated: 2024/01/15 22:06:15 by fgras-ca ### ########.fr # -# # -# **************************************************************************** # - -RST = \033[0m -GRAY = \033[0;90m -RED = \033[0;91m -GREEN = \033[0;92m -YELLOW = \033[0;93m -BLUE = \033[0;94m -MAGENTA = \033[0;95m -CYAN = \033[0;96m -WHITE = \033[0;97m -ORANGE = \033[38;5;214m - -NAME = libft.a - -SOURCES = ft_atoi.c \ - ft_isalpha.c \ - ft_memchr.c \ - ft_memset.c \ - ft_strlcat.c \ - ft_strnstr.c \ - ft_toupper.c \ - ft_bzero.c \ - ft_isascii.c \ - ft_memcmp.c \ - ft_strchr.c \ - ft_strlcpy.c \ - ft_strrchr.c \ - ft_calloc.c \ - ft_isdigit.c \ - ft_memcpy.c \ - ft_substr.c \ - ft_isalnum.c \ - ft_isprint.c \ - ft_memmove.c \ - ft_strncmp.c \ - ft_tolower.c\ - ft_strtrim.c \ - ft_putchar_fd.c \ - ft_putstr_fd.c \ - ft_putendl_fd.c \ - ft_putnbr_fd.c \ - ft_strmapi.c \ - ft_striteri.c \ - ft_itoa.c \ - ft_strcmp.c \ - ft_strstr.c \ - ft_reallocarray.c \ - ft_strcat.c \ - ft_strcpy.c \ - ft_realloc.c \ - ft_strncpy.c \ - ft_strtol.c \ - ft_strtok.c \ - -SRCBONUS = ft_lstnew.c \ - ft_lstadd_front.c \ - ft_lstsize.c \ - ft_lstlast.c \ - ft_lstadd_back.c \ - ft_lstdelone.c \ - ft_lstclear.c \ - ft_lstiter.c \ - ft_lstiter.c \ - ft_lstmap.c \ - - -OBJECTS = $(SOURCES:.c=.o) - -BONUS_OBJ = $(SRCBONUS:.c=.o) - -CC = gcc - -RM = rm -f - -CFLAGS = -Wall -Werror -Wextra - -all: $(NAME) - -$(NAME): $(OBJECTS) - @echo $(CC) (CFLAGS) $(OBJECTS) -o $(NAME) - -bonus: $(OBJECTS) $(BONUS_OBJ) - $(CC) (CFLAGS) $(OBJECTS) $(BONUS_OBJ) -o $(NAME) - -clean: - @echo $(RM) $(OBJECTS) $(BONUS_OBJ) - -fclean: clean - @echo $(RM) $(NAME) $(BONUS_OBJ) - -re: fclean all diff --git a/libft/ft_atoi.c b/libft/ft_atoi.c deleted file mode 100644 index 5756d38..0000000 --- a/libft/ft_atoi.c +++ /dev/null @@ -1,38 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_atoi.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/11 16:16:54 by fgras-ca #+# #+# */ -/* Updated: 2023/02/21 09:57:55 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_atoi(const char *nptr) -{ - int i; - int sign; - int res; - - i = 0; - sign = 1; - res = 0; - while (nptr[i] == 32 || (nptr[i] >= 9 && nptr[i] <= 13)) - i++; - if (nptr[i] == '-' || nptr[i] == '+') - { - if (nptr[i] == '-') - sign = - (1); - i++; - } - while (nptr[i] >= 48 && nptr[i] <= 57) - { - res = res * 10 + nptr[i] - 48; - i++; - } - return (res * sign); -} diff --git a/libft/ft_atoi.o b/libft/ft_atoi.o deleted file mode 100644 index 129e2ec..0000000 Binary files a/libft/ft_atoi.o and /dev/null differ diff --git a/libft/ft_bzero.c b/libft/ft_bzero.c deleted file mode 100644 index d032508..0000000 --- a/libft/ft_bzero.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_bzero.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/04 11:37:30 by fgras-ca #+# #+# */ -/* Updated: 2023/02/20 16:07:19 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_bzero(void *ptr, size_t len) -{ - size_t i; - - i = 0; - while (i < len) - { - *(char *)(ptr + i) = 0; - i++; - } -} diff --git a/libft/ft_bzero.o b/libft/ft_bzero.o deleted file mode 100644 index ffe7599..0000000 Binary files a/libft/ft_bzero.o and /dev/null differ diff --git a/libft/ft_calloc.c b/libft/ft_calloc.c deleted file mode 100644 index 8858bcf..0000000 --- a/libft/ft_calloc.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_calloc.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/11 17:47:38 by fgras-ca #+# #+# */ -/* Updated: 2023/02/21 10:45:58 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_calloc(size_t nmemb, size_t size) -{ - void *ptr; - - if (!nmemb || !size) - return (malloc(0)); - if ((nmemb * size) / size != nmemb) - return (NULL); - ptr = malloc(size * nmemb); - if (!ptr) - return (0); - ft_bzero(ptr, size * nmemb); - return (ptr); -} diff --git a/libft/ft_calloc.o b/libft/ft_calloc.o deleted file mode 100644 index f21092e..0000000 Binary files a/libft/ft_calloc.o and /dev/null differ diff --git a/libft/ft_isalnum.c b/libft/ft_isalnum.c deleted file mode 100644 index 1f065f3..0000000 --- a/libft/ft_isalnum.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isalnum.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/01 16:21:11 by fgras-ca #+# #+# */ -/* Updated: 2023/02/01 16:24:23 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_isalnum(int c) -{ - if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57)) - return (1); - else - return (0); -} diff --git a/libft/ft_isalnum.o b/libft/ft_isalnum.o deleted file mode 100644 index 6f270a0..0000000 Binary files a/libft/ft_isalnum.o and /dev/null differ diff --git a/libft/ft_isalpha.c b/libft/ft_isalpha.c deleted file mode 100644 index 3ff8fc5..0000000 --- a/libft/ft_isalpha.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isalpha.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/01 13:36:34 by fgras-ca #+# #+# */ -/* Updated: 2023/02/01 13:58:21 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_isalpha(int c) -{ - if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122)) - return (1); - else - return (0); -} diff --git a/libft/ft_isalpha.o b/libft/ft_isalpha.o deleted file mode 100644 index cdd8acd..0000000 Binary files a/libft/ft_isalpha.o and /dev/null differ diff --git a/libft/ft_isascii.c b/libft/ft_isascii.c deleted file mode 100644 index 508aa16..0000000 --- a/libft/ft_isascii.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isascii.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/01 16:40:31 by fgras-ca #+# #+# */ -/* Updated: 2023/11/14 17:07:04 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_isascii(int c) -{ - if (c >= 0 && c <= 127) - return (1); - return (0); -} diff --git a/libft/ft_isascii.o b/libft/ft_isascii.o deleted file mode 100644 index 0c87c23..0000000 Binary files a/libft/ft_isascii.o and /dev/null differ diff --git a/libft/ft_isdigit.c b/libft/ft_isdigit.c deleted file mode 100644 index 30eff04..0000000 --- a/libft/ft_isdigit.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isdigit.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/01 14:46:59 by fgras-ca #+# #+# */ -/* Updated: 2023/02/01 15:55:00 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_isdigit(int c) -{ - if (c >= 48 && c <= 57) - return (1); - else - return (0); -} diff --git a/libft/ft_isdigit.o b/libft/ft_isdigit.o deleted file mode 100644 index 8aa6b69..0000000 Binary files a/libft/ft_isdigit.o and /dev/null differ diff --git a/libft/ft_isprint.c b/libft/ft_isprint.c deleted file mode 100644 index 2f6097d..0000000 --- a/libft/ft_isprint.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isprint.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/03 12:43:03 by fgras-ca #+# #+# */ -/* Updated: 2023/02/03 13:25:31 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_isprint(int c) -{ - if (c >= 32 && c <= 126) - return (1); - return (0); -} diff --git a/libft/ft_isprint.o b/libft/ft_isprint.o deleted file mode 100644 index e3a203c..0000000 Binary files a/libft/ft_isprint.o and /dev/null differ diff --git a/libft/ft_itoa.c b/libft/ft_itoa.c deleted file mode 100644 index b8f8a48..0000000 --- a/libft/ft_itoa.c +++ /dev/null @@ -1,56 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_itoa.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/17 15:53:35 by fgras-ca #+# #+# */ -/* Updated: 2023/02/21 10:21:07 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -static size_t ft_len_nb(int nb) -{ - int len; - - len = 0; - if (nb <= 0) - len++; - while (nb) - { - len++; - nb = nb / 10; - } - return (len); -} - -char *ft_itoa(int n) -{ - int len; - char *str; - long nb; - - len = ft_len_nb(n); - nb = n; - str = malloc(sizeof(char) * len +1); - if (!str) - return (0); - if (nb < 0) - { - str[0] = '-'; - nb = -nb; - } - if (nb == 0) - str[0] = '0'; - str[len--] = '\0'; - while (nb) - { - str[len] = nb % 10 + '0'; - len--; - nb = nb / 10; - } - return (str); -} diff --git a/libft/ft_itoa.o b/libft/ft_itoa.o deleted file mode 100644 index ad0d02e..0000000 Binary files a/libft/ft_itoa.o and /dev/null differ diff --git a/libft/ft_lstadd_back.c b/libft/ft_lstadd_back.c deleted file mode 100644 index 3615437..0000000 --- a/libft/ft_lstadd_back.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstadd_back.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/23 18:08:00 by fgras-ca #+# #+# */ -/* Updated: 2023/02/23 18:15:14 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_lstadd_back(t_list **lst, t_list *new) -{ - t_list *temp; - - if (new && lst) - { - if (*lst) - { - temp = ft_lstlast(*lst); - temp->next = new; - } - else - *lst = new; - } -} diff --git a/libft/ft_lstadd_front.c b/libft/ft_lstadd_front.c deleted file mode 100644 index 01305fe..0000000 --- a/libft/ft_lstadd_front.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstadd_front.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/22 18:06:54 by fgras-ca #+# #+# */ -/* Updated: 2023/11/14 17:06:52 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_lstadd_front(t_list **lst, t_list *new) -{ - if (new) - { - new->next = *lst; - *lst = new; - } -} diff --git a/libft/ft_lstclear.c b/libft/ft_lstclear.c deleted file mode 100644 index 2367922..0000000 --- a/libft/ft_lstclear.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstclear.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/23 18:19:42 by fgras-ca #+# #+# */ -/* Updated: 2023/02/23 18:22:17 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_lstclear(t_list **lst, void (*del)(void*)) -{ - t_list *temp; - - while (*lst && lst) - { - temp = (*lst)->next; - ft_lstdelone(*lst, (*del)); - *lst = temp; - } -} diff --git a/libft/ft_lstdelone.c b/libft/ft_lstdelone.c deleted file mode 100644 index 07b9774..0000000 --- a/libft/ft_lstdelone.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstdelone.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/23 18:17:06 by fgras-ca #+# #+# */ -/* Updated: 2023/02/23 18:33:01 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_lstdelone(t_list *lst, void (*del)(void*)) -{ - if (!lst || !del) - return ; - del(lst->content); - free(lst); -} diff --git a/libft/ft_lstiter.c b/libft/ft_lstiter.c deleted file mode 100644 index efed585..0000000 --- a/libft/ft_lstiter.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstiter.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/23 18:22:52 by fgras-ca #+# #+# */ -/* Updated: 2023/02/23 18:24:51 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_lstiter(t_list *lst, void (*f)(void *)) -{ - if (!lst || !f) - return ; - while (lst) - { - f(lst->content); - lst = lst->next; - } -} diff --git a/libft/ft_lstlast.c b/libft/ft_lstlast.c deleted file mode 100644 index e6279bb..0000000 --- a/libft/ft_lstlast.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstlast.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/23 17:48:29 by fgras-ca #+# #+# */ -/* Updated: 2023/02/23 18:02:44 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -t_list *ft_lstlast(t_list *lst) -{ - while (lst) - { - if (lst->next == NULL) - return (lst); - lst = lst->next; - } - return (lst); -} diff --git a/libft/ft_lstmap.c b/libft/ft_lstmap.c deleted file mode 100644 index eea1576..0000000 --- a/libft/ft_lstmap.c +++ /dev/null @@ -1,35 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstmap.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/23 18:25:24 by fgras-ca #+# #+# */ -/* Updated: 2023/02/23 18:29:44 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) -{ - t_list *tmp; - t_list *res; - - if (!lst || !f) - return (NULL); - res = 0; - while (lst) - { - tmp = ft_lstnew((*f)(lst->content)); - if (!tmp) - { - ft_lstclear(&res, del); - return (NULL); - } - ft_lstadd_back(&res, tmp); - lst = lst->next; - } - return (res); -} diff --git a/libft/ft_lstnew.c b/libft/ft_lstnew.c deleted file mode 100644 index 0ceaea4..0000000 --- a/libft/ft_lstnew.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstnew.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/22 17:09:25 by fgras-ca #+# #+# */ -/* Updated: 2023/11/14 17:06:38 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -t_list *ft_lstnew(void *content) -{ - t_list *new; - - new = malloc(sizeof(t_list)); - if (!new) - return (0); - new->content = content; - new->next = 0; - return (new); -} diff --git a/libft/ft_lstsize.c b/libft/ft_lstsize.c deleted file mode 100644 index 8c95558..0000000 --- a/libft/ft_lstsize.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstsize.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/23 17:17:36 by fgras-ca #+# #+# */ -/* Updated: 2023/11/14 17:06:24 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_lstsize(t_list *lst) -{ - int i; - t_list *tmp; - - tmp = lst; - i = 0; - while (tmp) - { - tmp = tmp->next; - i++; - } - return (i); -} diff --git a/libft/ft_memchr.c b/libft/ft_memchr.c deleted file mode 100644 index 34c95f7..0000000 --- a/libft/ft_memchr.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memchr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/10 13:42:10 by fgras-ca #+# #+# */ -/* Updated: 2023/02/14 13:03:28 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_memchr(const void *s, int c, size_t n) -{ - size_t i; - - i = 0; - while (i < n) - { - if (((unsigned char *)s)[i] == (unsigned char)c) - return ((void *)(s + i)); - i++; - } - return (0); -} diff --git a/libft/ft_memchr.o b/libft/ft_memchr.o deleted file mode 100644 index fa3b76a..0000000 Binary files a/libft/ft_memchr.o and /dev/null differ diff --git a/libft/ft_memcmp.c b/libft/ft_memcmp.c deleted file mode 100644 index ba77f19..0000000 --- a/libft/ft_memcmp.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memcmp.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/10 14:45:56 by fgras-ca #+# #+# */ -/* Updated: 2023/11/14 17:18:05 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_memcmp(const void *s1, const void *s2, size_t n) -{ - size_t i; - - i = 0; - while (i < n) - { - if (((unsigned char *)s1)[i] != ((unsigned char *)s2)[i]) - return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]); - i++; - } - return (0); -} diff --git a/libft/ft_memcmp.o b/libft/ft_memcmp.o deleted file mode 100644 index a051b0e..0000000 Binary files a/libft/ft_memcmp.o and /dev/null differ diff --git a/libft/ft_memcpy.c b/libft/ft_memcpy.c deleted file mode 100644 index 5473b65..0000000 --- a/libft/ft_memcpy.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memcpy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/04 14:43:15 by fgras-ca #+# #+# */ -/* Updated: 2023/02/20 16:13:43 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_memcpy(void *dest, const void *src, size_t n) -{ - char *destmov; - char *srcmov; - size_t i; - - destmov = (char *)dest; - srcmov = (char *)src; - if (!dest && !src) - return (0); - i = 0; - while (i < n) - { - destmov[i] = srcmov[i]; - i++; - } - return (dest); -} diff --git a/libft/ft_memcpy.o b/libft/ft_memcpy.o deleted file mode 100644 index f6a7acf..0000000 Binary files a/libft/ft_memcpy.o and /dev/null differ diff --git a/libft/ft_memmove.c b/libft/ft_memmove.c deleted file mode 100644 index c6d9588..0000000 --- a/libft/ft_memmove.c +++ /dev/null @@ -1,42 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memmove.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/07 11:11:49 by fgras-ca #+# #+# */ -/* Updated: 2023/02/07 16:04:25 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_memmove(void *dest, const void *src, size_t n) -{ - char *destmov; - char *srcmov; - size_t i; - - if (!dest && !src) - return (0); - destmov = (char *)dest; - srcmov = (char *)src; - i = 0; - if (destmov > srcmov) - { - while (n--) - { - destmov[n] = srcmov[n]; - } - } - else - { - while (n--) - { - destmov[i] = srcmov[i]; - i++; - } - } - return (destmov); -} diff --git a/libft/ft_memmove.o b/libft/ft_memmove.o deleted file mode 100644 index c839f63..0000000 Binary files a/libft/ft_memmove.o and /dev/null differ diff --git a/libft/ft_memset.c b/libft/ft_memset.c deleted file mode 100644 index 2ad7299..0000000 --- a/libft/ft_memset.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memset.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/03 15:49:51 by fgras-ca #+# #+# */ -/* Updated: 2023/11/14 17:07:29 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_memset(void *s, int c, size_t n) -{ - size_t i; - - i = 0; - while (i < n) - { - *(unsigned char *)(s + i) = (unsigned char)c; - i++; - } - return (s); -} diff --git a/libft/ft_memset.o b/libft/ft_memset.o deleted file mode 100644 index 1d349d4..0000000 Binary files a/libft/ft_memset.o and /dev/null differ diff --git a/libft/ft_putchar_fd.c b/libft/ft_putchar_fd.c deleted file mode 100644 index b8a82d7..0000000 --- a/libft/ft_putchar_fd.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putchar_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/15 11:23:07 by fgras-ca #+# #+# */ -/* Updated: 2023/02/15 11:30:37 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putchar_fd(char c, int fd) -{ - write(fd, &c, 1); -} diff --git a/libft/ft_putchar_fd.o b/libft/ft_putchar_fd.o deleted file mode 100644 index 83d697d..0000000 Binary files a/libft/ft_putchar_fd.o and /dev/null differ diff --git a/libft/ft_putendl_fd.c b/libft/ft_putendl_fd.c deleted file mode 100644 index 9f65fcc..0000000 --- a/libft/ft_putendl_fd.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putendl_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/15 13:33:49 by fgras-ca #+# #+# */ -/* Updated: 2023/02/21 10:19:05 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putendl_fd(char *s, int fd) -{ - int i; - - i = 0; - if (!s) - return ; - while (s[i]) - { - write(fd, &s[i], 1); - i++; - } - write(fd, "\n", 1); -} diff --git a/libft/ft_putendl_fd.o b/libft/ft_putendl_fd.o deleted file mode 100644 index 9a22a40..0000000 Binary files a/libft/ft_putendl_fd.o and /dev/null differ diff --git a/libft/ft_putnbr_fd.c b/libft/ft_putnbr_fd.c deleted file mode 100644 index d71d21d..0000000 --- a/libft/ft_putnbr_fd.c +++ /dev/null @@ -1,36 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putnbr_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/15 13:53:25 by fgras-ca #+# #+# */ -/* Updated: 2023/02/15 14:00:06 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putnbr_fd(int n, int fd) -{ - if (n == -2147483648) - { - write(fd, "-2147483648", 11); - } - else if (n >= 0 && n < 10) - { - n += 48; - ft_putchar_fd(n, fd); - } - else if (n < 0) - { - ft_putchar_fd('-', fd); - ft_putnbr_fd((n * (-1)), fd); - } - else - { - ft_putnbr_fd(n / 10, fd); - ft_putnbr_fd(n % 10, fd); - } -} diff --git a/libft/ft_putnbr_fd.o b/libft/ft_putnbr_fd.o deleted file mode 100644 index ba22b06..0000000 Binary files a/libft/ft_putnbr_fd.o and /dev/null differ diff --git a/libft/ft_putstr_fd.c b/libft/ft_putstr_fd.c deleted file mode 100644 index e266011..0000000 --- a/libft/ft_putstr_fd.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putstr_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/15 12:29:14 by fgras-ca #+# #+# */ -/* Updated: 2023/02/15 19:02:37 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putstr_fd(char *s, int fd) -{ - int i; - - i = 0; - if (!s || !fd) - return ; - while (s[i]) - { - write(fd, &s[i], 1); - i++; - } -} diff --git a/libft/ft_putstr_fd.o b/libft/ft_putstr_fd.o deleted file mode 100644 index 1d149a0..0000000 Binary files a/libft/ft_putstr_fd.o and /dev/null differ diff --git a/libft/ft_realloc.c b/libft/ft_realloc.c deleted file mode 100644 index 9fccdf1..0000000 --- a/libft/ft_realloc.c +++ /dev/null @@ -1,35 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_realloc.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/15 16:31:35 by fgras-ca #+# #+# */ -/* Updated: 2023/12/10 13:59:12 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_realloc(void *ptr, size_t newsize, size_t oldsize) -{ - char *newptr; - - if (ptr == NULL) - { - return (malloc(newsize)); - } - if (newsize <= oldsize) - { - return (ptr); - } - newptr = malloc(newsize); - if (newptr == NULL) - { - return (NULL); - } - ft_memcpy(newptr, ptr, oldsize); - free(ptr); - return (newptr); -} diff --git a/libft/ft_realloc.o b/libft/ft_realloc.o deleted file mode 100644 index d09ef80..0000000 Binary files a/libft/ft_realloc.o and /dev/null differ diff --git a/libft/ft_reallocarray.c b/libft/ft_reallocarray.c deleted file mode 100644 index cc89e9a..0000000 --- a/libft/ft_reallocarray.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_reallocarray.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/15 15:52:29 by fgras-ca #+# #+# */ -/* Updated: 2023/12/07 11:46:15 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -static size_t get_mul_no_overflow(void) -{ - return ((size_t)1 << (sizeof(size_t) * 4)); -} - -void *ft_reallocarray(void *optr, size_t nmemb, size_t size, size_t oldsize) -{ - size_t mul_no_overflow; - - mul_no_overflow = get_mul_no_overflow(); - if ((nmemb >= mul_no_overflow || size >= mul_no_overflow) - && nmemb > 0 && SIZE_MAX / nmemb < size) - { - errno = ENOMEM; - return (NULL); - } - return (ft_realloc(optr, nmemb * size, oldsize)); -} diff --git a/libft/ft_reallocarray.o b/libft/ft_reallocarray.o deleted file mode 100644 index a0b7cfd..0000000 Binary files a/libft/ft_reallocarray.o and /dev/null differ diff --git a/libft/ft_strcat.c b/libft/ft_strcat.c deleted file mode 100644 index 6916a5e..0000000 --- a/libft/ft_strcat.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strcat.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/21 19:20:36 by fgras-ca #+# #+# */ -/* Updated: 2023/11/21 19:28:29 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strcat(char *dest, const char *src) -{ - char *save; - - save = dest; - while (*dest) - { - dest++; - } - while (*src) - { - *dest = *src; - dest++; - src++; - } - *dest = '\0'; - return (save); -} diff --git a/libft/ft_strcat.o b/libft/ft_strcat.o deleted file mode 100644 index 0d90e86..0000000 Binary files a/libft/ft_strcat.o and /dev/null differ diff --git a/libft/ft_strchr.c b/libft/ft_strchr.c deleted file mode 100644 index 482fac2..0000000 --- a/libft/ft_strchr.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strchr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/09 14:27:10 by fgras-ca #+# #+# */ -/* Updated: 2023/02/21 10:54:39 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strchr(const char *s, int c) - -{ - int i; - char *str; - - str = (char *)s; - i = 0; - while (str[i]) - { - if (str[i] == (char)c) - return (&str[i]); - i++; - } - if (str[i] == (char)c) - return (&str[i]); - return (0); -} diff --git a/libft/ft_strchr.o b/libft/ft_strchr.o deleted file mode 100644 index 45d8928..0000000 Binary files a/libft/ft_strchr.o and /dev/null differ diff --git a/libft/ft_strcmp.c b/libft/ft_strcmp.c deleted file mode 100644 index d8f2c11..0000000 --- a/libft/ft_strcmp.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strcmp.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/14 16:57:42 by fgras-ca #+# #+# */ -/* Updated: 2023/11/14 17:10:27 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_strcmp(const char *s1, const char *s2) -{ - while (*s1 && (*s1 == *s2)) - { - s1++; - s2++; - } - return (*(const unsigned char *)s1 - *(const unsigned char *)s2); -} diff --git a/libft/ft_strcmp.o b/libft/ft_strcmp.o deleted file mode 100644 index 10e7d06..0000000 Binary files a/libft/ft_strcmp.o and /dev/null differ diff --git a/libft/ft_strcpy.c b/libft/ft_strcpy.c deleted file mode 100644 index a738a2f..0000000 --- a/libft/ft_strcpy.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strcpy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/21 19:23:08 by fgras-ca #+# #+# */ -/* Updated: 2023/11/21 19:26:36 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strcpy(char *dest, const char *src) -{ - char *save; - - save = dest; - while (*src) - { - *dest = *src; - dest++; - src++; - } - *dest = '\0'; - return (save); -} diff --git a/libft/ft_strcpy.o b/libft/ft_strcpy.o deleted file mode 100644 index 3e56cf7..0000000 Binary files a/libft/ft_strcpy.o and /dev/null differ diff --git a/libft/ft_striteri.c b/libft/ft_striteri.c deleted file mode 100644 index 36d249c..0000000 --- a/libft/ft_striteri.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_striteri.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/16 14:25:00 by fgras-ca #+# #+# */ -/* Updated: 2023/11/14 17:08:02 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -void ft_striteri(char *s, void (*f)(unsigned int, char*)) -{ - unsigned int i; - - if (!s) - return ; - i = 0; - while (s[i]) - { - f(i, &s[i]); - i++; - } -} diff --git a/libft/ft_striteri.o b/libft/ft_striteri.o deleted file mode 100644 index 3230bb5..0000000 Binary files a/libft/ft_striteri.o and /dev/null differ diff --git a/libft/ft_strlcat.c b/libft/ft_strlcat.c deleted file mode 100644 index 4521530..0000000 --- a/libft/ft_strlcat.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strlcat.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/08 14:10:58 by fgras-ca #+# #+# */ -/* Updated: 2023/11/14 17:09:41 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -size_t ft_strlcat(char *dst, const char *src, size_t size) -{ - size_t i; - size_t dst_len; - - i = 0; - if (!dst && !size) - return (0); - dst_len = ft_strlen(dst); - if (size <= dst_len) - return (size + ft_strlen(src)); - while (src[i] && i < size - dst_len -1) - { - dst[dst_len + i] = src[i]; - i++; - } - dst[dst_len + i] = 0; - return (dst_len + ft_strlen(src)); -} diff --git a/libft/ft_strlcat.o b/libft/ft_strlcat.o deleted file mode 100644 index 28bde98..0000000 Binary files a/libft/ft_strlcat.o and /dev/null differ diff --git a/libft/ft_strlcpy.c b/libft/ft_strlcpy.c deleted file mode 100644 index 55734e0..0000000 --- a/libft/ft_strlcpy.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strlcpy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/08 13:24:31 by fgras-ca #+# #+# */ -/* Updated: 2023/02/08 13:33:32 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -size_t ft_strlcpy(char *dst, const char *src, size_t size) -{ - size_t i; - - i = 0; - if (size > 0) - { - while (src[i] && i < (size - 1)) - { - dst[i] = src[i]; - i++; - } - dst[i] = 0; - } - while (src[i]) - i++; - return (i); -} diff --git a/libft/ft_strlcpy.o b/libft/ft_strlcpy.o deleted file mode 100644 index 0578b32..0000000 Binary files a/libft/ft_strlcpy.o and /dev/null differ diff --git a/libft/ft_strmapi.c b/libft/ft_strmapi.c deleted file mode 100644 index 0178510..0000000 --- a/libft/ft_strmapi.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strmapi.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/16 13:38:52 by fgras-ca #+# #+# */ -/* Updated: 2023/11/14 17:04:43 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strmapi(const char *s, char (*f)(unsigned int, char)) -{ - char *result; - unsigned int i; - - if (!s) - return (0); - result = malloc(sizeof(char) * (ft_strlen(s) + 1)); - if (!result) - return (0); - i = 0; - while (s[i]) - { - result[i] = f(i, s[i]); - i++; - } - result[i] = 0; - return (result); -} diff --git a/libft/ft_strmapi.o b/libft/ft_strmapi.o deleted file mode 100644 index b420f23..0000000 Binary files a/libft/ft_strmapi.o and /dev/null differ diff --git a/libft/ft_strncmp.c b/libft/ft_strncmp.c deleted file mode 100644 index d5d1d88..0000000 --- a/libft/ft_strncmp.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strncmp.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/09 17:12:38 by fgras-ca #+# #+# */ -/* Updated: 2023/02/14 13:26:15 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_strncmp(const char *s1, const char *s2, size_t n) -{ - size_t i; - - i = 0; - if (n == 0) - { - return (0); - } - while (s1[i] == s2[i] && (s1[i] != '\0' || s2[i] != '\0') && i < (n - 1)) - { - i++; - } - return ((unsigned char)s1[i] - (unsigned char)s2[i]); -} diff --git a/libft/ft_strncmp.o b/libft/ft_strncmp.o deleted file mode 100644 index 658a0ca..0000000 Binary files a/libft/ft_strncmp.o and /dev/null differ diff --git a/libft/ft_strncpy.c b/libft/ft_strncpy.c deleted file mode 100644 index 613eaa0..0000000 --- a/libft/ft_strncpy.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strncpy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/27 20:03:19 by fgras-ca #+# #+# */ -/* Updated: 2023/12/07 11:56:51 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strncpy(char *dest, char *src, unsigned int n) -{ - unsigned int i; - - i = 0; - while (src[i] != '\0' && i < n) - { - dest[i] = src[i]; - ++i; - } - while (i < n) - { - dest[i] = '\0'; - i++; - } - return (dest); -} diff --git a/libft/ft_strncpy.o b/libft/ft_strncpy.o deleted file mode 100644 index fe9533a..0000000 Binary files a/libft/ft_strncpy.o and /dev/null differ diff --git a/libft/ft_strnstr.c b/libft/ft_strnstr.c deleted file mode 100644 index d15e922..0000000 --- a/libft/ft_strnstr.c +++ /dev/null @@ -1,41 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strnstr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/11 14:31:40 by fgras-ca #+# #+# */ -/* Updated: 2023/02/21 10:08:36 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strnstr(const char *haystack, const char *needle, size_t len) -{ - size_t i; - size_t j; - - i = 0; - if (needle == haystack) - return ((char *)haystack); - if (!len && !haystack) - return (0); - while (haystack[i] != '\0') - { - j = 0; - while (haystack[i + j] == needle[j] && (i + j) < len) - { - if (haystack[i + j] == '\0' && needle[j] == '\0') - { - return ((char *)&haystack[j]); - } - j++; - } - if (needle[j] == '\0') - return ((char *)(haystack + i)); - i++; - } - return (NULL); -} diff --git a/libft/ft_strnstr.o b/libft/ft_strnstr.o deleted file mode 100644 index 65c6191..0000000 Binary files a/libft/ft_strnstr.o and /dev/null differ diff --git a/libft/ft_strrchr.c b/libft/ft_strrchr.c deleted file mode 100644 index 4c09b3a..0000000 --- a/libft/ft_strrchr.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strrchr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/09 16:10:11 by fgras-ca #+# #+# */ -/* Updated: 2023/02/14 15:36:23 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strrchr(const char *s, int c) -{ - int i; - - i = 0; - while (s[i]) - i++; - while (i >= 0) - { - if (s[i] == (char)c) - return ((char *)(s + i)); - i--; - } - return (0); -} diff --git a/libft/ft_strrchr.o b/libft/ft_strrchr.o deleted file mode 100644 index ca0a633..0000000 Binary files a/libft/ft_strrchr.o and /dev/null differ diff --git a/libft/ft_strstr.c b/libft/ft_strstr.c deleted file mode 100644 index 59afb4c..0000000 --- a/libft/ft_strstr.c +++ /dev/null @@ -1,42 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strstr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/14 20:54:44 by fgras-ca #+# #+# */ -/* Updated: 2023/11/14 21:08:57 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strstr(const char *haystack, const char *needle) -{ - const char *p; - const char *beginning; - const char *n; - - p = haystack; - if (*needle == '\0') - return ((char *)haystack); - while (*p != '\0') - { - if (*p == *needle) - { - beginning = p; - n = needle; - while (*p == *n && *n != '\0' && *p != '\0') - { - p++; - n++; - } - if (*n == '\0') - return ((char *)beginning); - p = beginning; - } - p++; - } - return (NULL); -} diff --git a/libft/ft_strstr.o b/libft/ft_strstr.o deleted file mode 100644 index ffe71d1..0000000 Binary files a/libft/ft_strstr.o and /dev/null differ diff --git a/libft/ft_strtok.c b/libft/ft_strtok.c deleted file mode 100644 index ba4583f..0000000 --- a/libft/ft_strtok.c +++ /dev/null @@ -1,83 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strtok.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/14 17:14:45 by fgras-ca #+# #+# */ -/* Updated: 2023/12/07 11:41:34 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -static char *init_str_and_lasts(char **lasts, char *str) -{ - if (str == NULL) - { - str = *lasts; - if (str == NULL) - return (NULL); - } - else - { - *lasts = str; - } - return (str); -} - -static char *find_token_start(char **lasts, const char *delim) -{ - int ch; - - ch = **lasts; - while (ch != '\0' && ft_strchr(delim, ch) != NULL) - { - (*lasts)++; - ch = **lasts; - } - if (**lasts == '\0') - { - *lasts = NULL; - return (NULL); - } - return (*lasts); -} - -static char *find_token_end(char **lasts, const char *delim) -{ - int ch; - char *str; - - str = *lasts; - ch = **lasts; - while (ch != '\0' && ft_strchr(delim, ch) == NULL) - { - (*lasts)++; - ch = **lasts; - } - if (**lasts != '\0') - { - **lasts = '\0'; - (*lasts)++; - } - else - { - *lasts = NULL; - } - return (str); -} - -char *ft_strtok(char *str, const char *delim) -{ - static char *lasts; - - str = init_str_and_lasts(&lasts, str); - if (str == NULL) - return (NULL); - str = find_token_start(&lasts, delim); - if (str == NULL) - return (NULL); - return (find_token_end(&lasts, delim)); -} diff --git a/libft/ft_strtok.o b/libft/ft_strtok.o deleted file mode 100644 index 9dc26af..0000000 Binary files a/libft/ft_strtok.o and /dev/null differ diff --git a/libft/ft_strtol.c b/libft/ft_strtol.c deleted file mode 100644 index 374a1ca..0000000 --- a/libft/ft_strtol.c +++ /dev/null @@ -1,115 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strtol.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/01 14:00:32 by fgras-ca #+# #+# */ -/* Updated: 2023/12/07 11:56:12 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -static int skip_whitespaces_and_sign(const char *str, int *sign) -{ - int i; - - i = 0; - while (str[i] == ' ' || (str[i] >= '\t' && str[i] <= '\r')) - i++; - if (str[i] == '+' || str[i] == '-') - { - if (str[i] == '-') - *sign = -1; - i++; - } - return (i); -} - -static int determine_base(const char *str, int *base, int index) -{ - if ((*base == 0 || *base == 16) && str[index] == '0' - && (str[index + 1] == 'x' || str[index + 1] == 'X')) - { - *base = 16; - index += 2; - } - else if (*base == 0) - { - if (str[index] == '0') - *base = 8; - else - *base = 10; - } - return (index); -} - -static int check_base(const char *str, int *base, int *sign) -{ - int i; - - *sign = 1; - i = skip_whitespaces_and_sign(str, sign); - i = determine_base(str, base, i); - return (i); -} - -static long convert_strtol(const char *str, int base, int sign) -{ - long result; - int digit; - - result = 0; - while (*str) - { - digit = 0; - if (*str >= '0' && *str <= '9') - digit = *str - '0'; - else if (*str >= 'A' && *str <= 'Z') - digit = *str - 'A' + 10; - else if (*str >= 'a' && *str <= 'z') - digit = *str - 'a' + 10; - else - break ; - if (digit >= base) - break ; - if (sign > 0 && result > (LONG_MAX - digit) / base) - return (errno = ERANGE, LONG_MAX); - if (sign < 0 && result < (LONG_MIN + digit) / base) - return (errno = ERANGE, LONG_MIN); - result = result * base + digit; - str++; - } - return (result * sign); -} - -long ft_strtol(const char *str, char **endptr, int base) -{ - int sign; - int i; - long result; - - if (base < 0 || base == 1 || base > 36) - { - if (endptr) - *endptr = (char *)str; - return (0); - } - i = check_base(str, &base, &sign); - result = convert_strtol(str + i, base, sign); - if (endptr) - *endptr = (char *)(str + i); - while (*str) - { - if ((*str >= '0' && *str <= '9' && *str - '0' < base) - || (*str >= 'A' && *str <= 'Z' && *str - 'A' + 10 < base) - || (*str >= 'a' && *str <= 'z' && *str - 'a' + 10 < base)) - *endptr = (char *)(str + 1); - else - break ; - str++; - } - return (result); -} diff --git a/libft/ft_strtol.o b/libft/ft_strtol.o deleted file mode 100644 index 2d52685..0000000 Binary files a/libft/ft_strtol.o and /dev/null differ diff --git a/libft/ft_strtrim.c b/libft/ft_strtrim.c deleted file mode 100644 index a162893..0000000 --- a/libft/ft_strtrim.c +++ /dev/null @@ -1,52 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strtrim.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/14 16:30:26 by fgras-ca #+# #+# */ -/* Updated: 2023/03/13 14:12:41 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -static int char_in_set(char c, char const *set) -{ - size_t i; - - i = 0; - while (set[i]) - { - if (set[i] == c) - return (1); - i++; - } - return (0); -} - -char *ft_strtrim(char const *s1, char const *set) -{ - char *str; - size_t i; - size_t start; - size_t end; - - if (!s1) - return (0); - start = 0; - while (s1[start] && char_in_set(s1[start], set)) - start++; - end = ft_strlen(s1); - while (end > start && char_in_set(s1[end - 1], set)) - end--; - str = (char *)malloc(sizeof(*s1) * (end - start + 1)); - if (!str) - return (0); - i = 0; - while (start < end) - str[i++] = s1[start++]; - str[i] = 0; - return (str); -} diff --git a/libft/ft_strtrim.o b/libft/ft_strtrim.o deleted file mode 100644 index 76c9893..0000000 Binary files a/libft/ft_strtrim.o and /dev/null differ diff --git a/libft/ft_substr.c b/libft/ft_substr.c deleted file mode 100644 index 11b1e8c..0000000 --- a/libft/ft_substr.c +++ /dev/null @@ -1,37 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_substr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/13 15:40:49 by fgras-ca #+# #+# */ -/* Updated: 2023/11/14 17:07:20 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_substr(char const *s, unsigned int start, size_t len) -{ - char *new_s; - size_t i; - size_t j; - - new_s = (char *)malloc(sizeof(char) * (len + 1)); - if (!s || !new_s) - return (NULL); - i = 0; - j = 0; - while (s[i]) - { - if (i >= start && j < len) - { - new_s[j] = s[i]; - j++; - } - i++; - } - new_s[j] = '\0'; - return (new_s); -} diff --git a/libft/ft_substr.o b/libft/ft_substr.o deleted file mode 100644 index 44b71b5..0000000 Binary files a/libft/ft_substr.o and /dev/null differ diff --git a/libft/ft_tolower.c b/libft/ft_tolower.c deleted file mode 100644 index b7378bb..0000000 --- a/libft/ft_tolower.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_tolower.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/09 14:09:59 by fgras-ca #+# #+# */ -/* Updated: 2023/02/14 13:36:02 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_tolower(int c) -{ - if (c >= 65 && c <= 90) - c += 32; - return (c); -} diff --git a/libft/ft_tolower.o b/libft/ft_tolower.o deleted file mode 100644 index cb388e5..0000000 Binary files a/libft/ft_tolower.o and /dev/null differ diff --git a/libft/ft_toupper.c b/libft/ft_toupper.c deleted file mode 100644 index 102da50..0000000 --- a/libft/ft_toupper.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_toupper.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/08 16:02:00 by fgras-ca #+# #+# */ -/* Updated: 2023/02/14 13:36:40 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_toupper(int c) -{ - if (c >= 97 && c <= 122) - c -= 32; - return (c); -} diff --git a/libft/ft_toupper.o b/libft/ft_toupper.o deleted file mode 100644 index 5afb2bc..0000000 Binary files a/libft/ft_toupper.o and /dev/null differ diff --git a/libft/libft.a b/libft/libft.a deleted file mode 100644 index 207f3a4..0000000 Binary files a/libft/libft.a and /dev/null differ diff --git a/libft/libft.h b/libft/libft.h deleted file mode 100644 index 5edbeb1..0000000 --- a/libft/libft.h +++ /dev/null @@ -1,82 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* libft.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/12 10:46:53 by fgras-ca #+# #+# */ -/* Updated: 2024/01/15 21:07:07 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef LIBFT_H -# define LIBFT_H - -# include -# include -# include -# include -# include -# include -# include -# include -# include "../cub3d.h" - -typedef struct s_list -{ - void *content; - struct s_list *next; -} t_list; - -int ft_isalpha(int c); -int ft_isdigit(int c); -int ft_isalnum(int c); -int ft_isascii(int c); -int ft_isprint(int c); -int ft_toupper(int c); -int ft_tolower(int c); -int ft_strcmp(const char *s1, const char *s2); -int ft_strncmp(const char *s1, const char *s2, size_t n); -int ft_strcmp(const char *s1, const char *s2); -int ft_memcmp(const void *s1, const void *s2, size_t n); -int ft_atoi(const char *nptr); -int ft_lstsize(t_list *lst); -void *ft_memset(void *s, int c, size_t n); -void ft_bzero(void *ptr, size_t len); -void *ft_memcpy(void *dest, const void *src, size_t n); -void *ft_memmove(void *dest, const void *src, size_t n); -void *ft_memchr(const void *s, int c, size_t n); -void *ft_calloc(size_t nmemb, size_t size); -void ft_putchar_fd(char c, int fd); -void ft_putstr_fd(char *s, int fd); -void ft_putendl_fd(char *s, int fd); -void ft_putnbr_fd(int n, int fd); -void ft_striteri(char *s, void (*f)(unsigned int, char*)); -void ft_lstadd_front(t_list **lst, t_list *new); -void ft_lstadd_back(t_list **lst, t_list *new); -void ft_lstdelone(t_list *lst, void (*del)(void *)); -void ft_lstclear(t_list **lst, void (*del)(void *)); -void ft_lstiter(t_list *lst, void (*f)(void *)); -size_t ft_strlcpy(char *dst, const char *src, size_t size); -size_t ft_strlcat(char *dst, const char *src, size_t size); -char *ft_strrchr(const char *s, int c); -char *ft_strtok(char *str, const char *delim); -char *ft_strnstr(const char *haystack, const char *needle, size_t len); -char *ft_strdup(const char *s); -char *ft_strstr(const char *haystack, const char *needle); -char *ft_substr(char const *s, unsigned int start, size_t len); -char *ft_strtrim(char const *s1, char const *set); -char *ft_strmapi(const char *s, char (*f)(unsigned int, char)); -char *ft_strncpy(char *dest, char *src, unsigned int n); -void *ft_reallocarray(void *optr, size_t nmemb, size_t size, size_t oldsize); -void *ft_realloc(void *ptr, size_t newsize, size_t oldsize); -char *ft_itoa(int n); -char *ft_strcat(char *dest, const char *src); -char *ft_strcpy(char *dest, const char *src); -t_list *ft_lstnew(void *content); -t_list *ft_lstlast(t_list *lst); -t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)); -long ft_strtol(const char *str, char **endptr, int base); - -#endif diff --git a/main.c b/main.c index 076576f..ab59b75 100644 --- a/main.c +++ b/main.c @@ -6,13 +6,14 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/15 18:45:52 by fgras-ca #+# #+# */ -/* Updated: 2024/01/28 22:39:18 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 15:11:41 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #include "cub3d.h" -int setup_and_load_map(int argc, char **argv, t_structure_main *w, t_texture *textures) +int setup_and_load_map(int argc, char **argv, + t_structure_main *w, t_texture *textures) { if (argc > 2) { @@ -32,7 +33,7 @@ int setup_and_load_map(int argc, char **argv, t_structure_main *w, t_texture *te return (1); } -void init_structure_main(t_structure_main *w) +void init_structure_main(t_structure_main *w) { if (w == NULL) { diff --git a/map.cub b/map.cub index e5c694d..d74c3d2 100644 --- a/map.cub +++ b/map.cub @@ -7,7 +7,7 @@ C 165, 176, 196 11111111 11111111111 11111111 11111111111 11111111111111111111111111111111111 111111000001110000000001110000001 10000000001 10000000000000000000000000000000001111111111111111111111111111 -1111100000000000000000000000200000001 10000000001 10000000000000000000000000000000000002000000000000000000000001 +1111100000000000000000000000000000001 10000000001 10000000000000000000000000000000000002000000000000000000000001 1000000000000000000000011111111111111 10000000001 10000000000000000000000000000000000002000000000000000000000001111 100000000000000000000001 10000000001 10000000000000000000000000000000001111111100000000000000000000001 100000000000000000000001111111111111111111000000000111110000000000000000000000000000000001 100000000000000000000001 diff --git a/move/ft_collision.c b/move/ft_collision.c index 0d1e6f9..9b600c3 100644 --- a/move/ft_collision.c +++ b/move/ft_collision.c @@ -6,29 +6,54 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/11 14:09:52 by fgras-ca #+# #+# */ -/* Updated: 2024/01/25 20:43:43 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 17:43:10 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #include "../cub3d.h" -int can_move_to(t_structure_main *w, double future_x, double future_y) { - int map_x, map_y; +static int check_collision(t_structure_main *w, double future_x, + double future_y, t_collision_params *coll_params) +{ + int i; + int map_x; + int map_y; + char map_position; - // Vérification manuelle de chaque position autour de la future position - int dx[] = {0, 0, -COLBUF, COLBUF, -COLBUF, COLBUF, -COLBUF, COLBUF}; - int dy[] = {-COLBUF, COLBUF, 0, 0, -COLBUF, -COLBUF, COLBUF, COLBUF}; - - for (int i = 0; i < 8; i++) { - map_x = (int)((future_x + dx[i]) / w->s_map.mapS); - map_y = (int)((future_y + dy[i]) / w->s_map.mapS); - char map_position = w->s_map.map[map_y * w->s_map.mapX + map_x]; - if (map_position != '0' && map_position != '3') { - printf("Collision détectée à x = %d, y = %d\n", map_x, map_y); - return 0; // Collision détectée, ne peut pas se déplacer - } - } - - printf("Pas de collision, peut se déplacer\n"); - return 1; // Pas de collision, peut se déplacer + i = 0; + while (i < DX_LENGTH) + { + map_x = (int)((future_x + coll_params->dx[i]) / w->s_map.map_s); + map_y = (int)((future_y + coll_params->dy[i]) / w->s_map.map_s); + map_position = w->s_map.map[map_y * w->s_map.map_x + map_x]; + if (map_position != '0' && map_position != '3') + return (0); + i++; + } + return (1); +} + +int can_move_to(t_structure_main *w, double future_x, double future_y) +{ + t_collision_params coll_params; + + coll_params.dx[0] = 0; + coll_params.dx[1] = 0; + coll_params.dx[2] = -COLBUF; + coll_params.dx[3] = COLBUF; + coll_params.dx[4] = -COLBUF; + coll_params.dx[5] = COLBUF; + coll_params.dx[6] = -COLBUF; + coll_params.dx[7] = COLBUF; + coll_params.dy[0] = -COLBUF; + coll_params.dy[1] = COLBUF; + coll_params.dy[2] = 0; + coll_params.dy[3] = 0; + coll_params.dy[4] = -COLBUF; + coll_params.dy[5] = -COLBUF; + coll_params.dy[6] = COLBUF; + coll_params.dy[7] = COLBUF; + if (check_collision(w, future_x, future_y, &coll_params) == 0) + return (0); + return (1); } diff --git a/move/ft_key.c b/move/ft_key.c index 0314654..569edce 100644 --- a/move/ft_key.c +++ b/move/ft_key.c @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/11 14:17:56 by fgras-ca #+# #+# */ -/* Updated: 2024/01/25 18:45:14 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 17:53:45 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,7 +41,7 @@ void adjust_player_angle(t_structure_main *w, int key) if (key != 65361 && key != 65363) return ; - angle_adjustment = 4 * (PI/180); + angle_adjustment = 4 * (PI / 180); if (key == 65361) { w->s_player.pa -= angle_adjustment; @@ -67,27 +67,28 @@ void handle_movement_keys(int key, t_structure_main *w) int deal_key(int key, t_structure_main *w) { if (key == 65307) - { kill_prog(w); - } else if (key == 65361 || key == 65363) - { adjust_player_angle(w, key); - } else if (key == 65362 || key == 65364 || key == 114 || key == 102) { } - else if (key == 101) //e door + else if (key == 101) { - printf("Touche 101\n"); - if (w->s_map.map[(int)((w->s_player.py + sin(w->s_player.pa) * 7)/w->s_map.mapS) * w->s_map.mapX + (int)((w->s_player.px + cos(w->s_player.pa) * 7)/w->s_map.mapS)] == '2') - w->s_map.map[(int)((w->s_player.py + sin(w->s_player.pa) * 7)/w->s_map.mapS) * w->s_map.mapX + (int)((w->s_player.px + cos(w->s_player.pa) * 7)/w->s_map.mapS)] = '3'; - else if (w->s_map.map[(int)((w->s_player.py + sin(w->s_player.pa) * 7)/w->s_map.mapS) * w->s_map.mapX + (int)((w->s_player.px + cos(w->s_player.pa) * 7)/w->s_map.mapS)] == '3') - w->s_map.map[(int)((w->s_player.py + sin(w->s_player.pa) * 7)/w->s_map.mapS) * w->s_map.mapX + (int)((w->s_player.px + cos(w->s_player.pa) * 7)/w->s_map.mapS)] = '2'; + if (w->s_map.map[(int)((w->s_player.py + sin(w->s_player.pa) * 7) + / w->s_map.map_s) *w->s_map.map_x + (int)((w->s_player.px + + cos(w->s_player.pa) * 7) / w->s_map.map_s)] == '2') + w->s_map.map[(int)((w->s_player.py + sin(w->s_player.pa) * 7) + / w->s_map.map_s) *w->s_map.map_x + (int)((w->s_player.px + + cos(w->s_player.pa) * 7) / w->s_map.map_s)] = '3'; + else if (w->s_map.map[(int)((w->s_player.py + sin(w->s_player.pa) * 7) + / w->s_map.map_s) *w->s_map.map_x + (int)((w->s_player.px + + cos(w->s_player.pa) * 7) / w->s_map.map_s)] == '3') + w->s_map.map[(int)((w->s_player.py + sin(w->s_player.pa) * 7) + / w->s_map.map_s) *w->s_map.map_x + (int)((w->s_player.px + + cos(w->s_player.pa) * 7) / w->s_map.map_s)] = '2'; } else - { handle_movement_keys(key, w); - } return (key); } diff --git a/move/ft_move.c b/move/ft_move.c index 1fa45b1..1fb81d7 100644 --- a/move/ft_move.c +++ b/move/ft_move.c @@ -6,70 +6,82 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/11 14:08:25 by fgras-ca #+# #+# */ -/* Updated: 2024/01/25 18:33:49 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 17:59:17 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #include "../cub3d.h" -void move_forward(t_structure_main *w, int key) { - double future_px; - double future_py; +void move_forward(t_structure_main *w, int key) +{ + double future_px; + double future_py; - if (key == 119) { // Touche 'w' pour avancer - future_px = w->s_player.px + cos(w->s_player.pa) * w->s_map.mapS; - future_py = w->s_player.py + sin(w->s_player.pa) * w->s_map.mapS; - - if (can_move_to(w, future_px, future_py)) { - w->s_player.px = future_px; - w->s_player.py = future_py; - } - } + if (key == 119) + { + future_px = w->s_player.px + cos(w->s_player.pa) * w->s_map.map_s; + future_py = w->s_player.py + sin(w->s_player.pa) * w->s_map.map_s; + if (can_move_to(w, future_px, future_py)) + { + w->s_player.px = future_px; + w->s_player.py = future_py; + } + } } -void move_backward(t_structure_main *w, int key) { - double future_px; - double future_py; +void move_backward(t_structure_main *w, int key) +{ + double future_px; + double future_py; - if (key == 115) { // Touche 's' pour reculer - future_px = w->s_player.px - cos(w->s_player.pa) * w->s_map.mapS; - future_py = w->s_player.py - sin(w->s_player.pa) * w->s_map.mapS; - - if (can_move_to(w, future_px, future_py)) { - w->s_player.px = future_px; - w->s_player.py = future_py; - } - } + if (key == 115) + { + future_px = w->s_player.px - cos(w->s_player.pa) * w->s_map.map_s; + future_py = w->s_player.py - sin(w->s_player.pa) * w->s_map.map_s; + if (can_move_to(w, future_px, future_py)) + { + w->s_player.px = future_px; + w->s_player.py = future_py; + } + } } -void move_right(t_structure_main *w, int key) { - double future_px; - double future_py; +void move_right(t_structure_main *w, int key) +{ + double future_px; + double future_py; - if (key == 100) { // Touche 'd' pour aller à droite - future_px = w->s_player.px + cos(w->s_player.pa + (PI/2)) * w->s_map.mapS; - future_py = w->s_player.py + sin(w->s_player.pa + (PI/2)) * w->s_map.mapS; - - if (can_move_to(w, future_px, future_py)) { - w->s_player.px = future_px; - w->s_player.py = future_py; - } - } + if (key == 100) + { + future_px = w->s_player.px + cos(w->s_player.pa + + (PI / 2)) * w->s_map.map_s; + future_py = w->s_player.py + sin(w->s_player.pa + + (PI / 2)) * w->s_map.map_s; + if (can_move_to(w, future_px, future_py)) + { + w->s_player.px = future_px; + w->s_player.py = future_py; + } + } } -void move_left(t_structure_main *w, int key) { - double future_px; - double future_py; +void move_left(t_structure_main *w, int key) +{ + double future_px; + double future_py; - if (key == 97) { // Touche 'a' pour aller à gauche - future_px = w->s_player.px + cos(w->s_player.pa - (PI/2)) * w->s_map.mapS; - future_py = w->s_player.py + sin(w->s_player.pa - (PI/2)) * w->s_map.mapS; - - if (can_move_to(w, future_px, future_py)) { - w->s_player.px = future_px; - w->s_player.py = future_py; - } - } + if (key == 97) + { + future_px = w->s_player.px + cos(w->s_player.pa + - (PI / 2)) * w->s_map.map_s; + future_py = w->s_player.py + sin(w->s_player.pa + - (PI / 2)) * w->s_map.map_s; + if (can_move_to(w, future_px, future_py)) + { + w->s_player.px = future_px; + w->s_player.py = future_py; + } + } } void move(int key, t_structure_main *w) diff --git a/parsing/ft_find_map_start.c b/parsing/ft_find_map_start.c index 7e9219c..bd0f568 100644 --- a/parsing/ft_find_map_start.c +++ b/parsing/ft_find_map_start.c @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/15 20:04:23 by fgras-ca #+# #+# */ -/* Updated: 2024/01/28 22:48:56 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 18:02:53 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,7 +43,8 @@ bool handle_colors(int fd, t_texture *textures) { line[i] = '\0'; printf("Ligne lue pour les couleurs: '%s'\n", line); - if ((line[0] == 'F' || line[0] == 'C') && process_color_line(line, textures)) + if ((line[0] == 'F' || line[0] == 'C') + && process_color_line(line, textures)) color_count++; i = 0; } @@ -94,10 +95,7 @@ bool load_cub_file(const char *filename, return (cleanup_and_close(fd, map_buffer, false)); } if (map_buffer) - { - //printf("Map buffer loaded:\n%s\n", map_buffer); result = parse_map(map_buffer, map_length, map_info); - } else { printf("No map data found in file.\n"); diff --git a/parsing/ft_find_player_position.c b/parsing/ft_find_player_position.c index d3e99d4..9316a34 100644 --- a/parsing/ft_find_player_position.c +++ b/parsing/ft_find_player_position.c @@ -6,97 +6,60 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/23 19:54:51 by fgras-ca #+# #+# */ -/* Updated: 2024/01/23 20:22:20 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 18:58:31 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #include "../cub3d.h" -static void initialize_variables(int *i, int *line_number, int *column_number, bool *found_player) +bool is_player_char(char c) { - *i = 0; - *line_number = 0; - *column_number = 0; - *found_player = false; + return (c == 'N' || c == 'S' || c == 'E' || c == 'W'); } -static bool check_for_player(char current_char, bool *found_player) +static bool process_player_char(char current_char, t_player_info *player_info) { - if (current_char == 'N' || current_char == 'S' || current_char == 'E' || current_char == 'W') + if (is_player_char(current_char)) { - if (*found_player) + if (check_for_multiple_players(*(player_info->found_player))) + { + *(player_info->found_player) = true; + update_player_info(player_info->map, player_info->line_number, + player_info->column_number, current_char); + } + else { printf("Multiple player start positions found. Invalid map.\n"); - return false; + return (false); } - *found_player = true; } - return true; + return (true); } -static void update_player_info(t_structure_map *map_info, int line_number, int column_number, char player_direction) +bool find_player(const char *map_content, int length, t_structure_map *map) { - map_info->player_x = column_number * map_info->mapS + map_info->mapS / 2; - map_info->player_y = line_number * map_info->mapS + map_info->mapS / 2; - map_info->player_direction = player_direction; - printf("Player found: x = %f, y = %f, direction = %c\n", map_info->player_x, map_info->player_y, map_info->player_direction); -} + int i; + bool found_player; + t_player_info player_info; - -static void update_position(char current_char, int *line_number, int *column_number) -{ - if (current_char == '\n') + i = 0; + initialize_variables(&i, &player_info.line_number, + &player_info.column_number, &found_player); + player_info.map = map; + player_info.found_player = &found_player; + while (i < length) { - (*line_number)++; - *column_number = 0; - } - else - { - (*column_number)++; + if (!found_player) + { + if (!process_player_char(map_content[i], &player_info)) + return (false); + } + calculate_map(map); + update_position(map_content[i], + &player_info.line_number, &player_info.column_number); + i++; } + if (!found_player) + return (false); + return (true); } - -static bool check_for_multiple_players(bool found_player) -{ - if (found_player) - { - printf("Multiple player start positions found. Invalid map.\n"); - return false; - } - return true; -} - -bool find_player_position_and_direction(const char *map_content, int length, t_structure_map *map_info) -{ - int i; - int line_number; - int column_number; - bool found_player; - - initialize_variables(&i, &line_number, &column_number, &found_player); - while (i < length) - { - char current_char = map_content[i]; - if (!found_player && (current_char == 'N' || current_char == 'S' || current_char == 'E' || current_char == 'W')) - { - if (check_for_multiple_players(found_player)) - { - found_player = true; - update_player_info(map_info, line_number, column_number, current_char); - } - else - { - return false; - } - } - calculate_map(map_info); - update_position(current_char, &line_number, &column_number); - i++; - } - if (!found_player) - { - printf("Player start position not found. Invalid map.\n"); - return false; - } - return true; -} \ No newline at end of file diff --git a/parsing/ft_find_player_utils.c b/parsing/ft_find_player_utils.c new file mode 100644 index 0000000..53a703c --- /dev/null +++ b/parsing/ft_find_player_utils.c @@ -0,0 +1,71 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_find_player_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: fgras-ca +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/01/29 18:57:38 by fgras-ca #+# #+# */ +/* Updated: 2024/01/29 18:58:26 by fgras-ca ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../cub3d.h" + +void initialize_variables(int *i, int *line_number, + int *column_number, bool *found_player) +{ + *i = 0; + *line_number = 0; + *column_number = 0; + *found_player = false; +} + +bool check_for_player(char current_char, bool *found_player) +{ + if (current_char == 'N' || current_char == 'S' + || current_char == 'E' || current_char == 'W') + { + if (*found_player) + { + printf("Multiple player start positions found. Invalid map.\n"); + return (false); + } + *found_player = true; + } + return (true); +} + +void update_player_info(t_structure_map *map_info, + int line_number, int column_number, char player_direction) +{ + map_info->player_x = column_number * map_info->map_s + map_info->map_s / 2; + map_info->player_y = line_number * map_info->map_s + map_info->map_s / 2; + map_info->player_direction = player_direction; + printf("Player found: x = %f, y = %f, direction = %c\n", map_info->player_x, + map_info->player_y, map_info->player_direction); +} + +void update_position(char current_char, + int *line_number, int *column_number) +{ + if (current_char == '\n') + { + (*line_number)++; + *column_number = 0; + } + else + { + (*column_number)++; + } +} + +bool check_for_multiple_players(bool found_player) +{ + if (found_player) + { + printf("Multiple player start positions found. Invalid map.\n"); + return (false); + } + return (true); +} diff --git a/parsing/ft_map_check.c b/parsing/ft_map_check.c index fa472c0..d4b428d 100644 --- a/parsing/ft_map_check.c +++ b/parsing/ft_map_check.c @@ -6,251 +6,105 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/11 14:49:45 by fgras-ca #+# #+# */ -/* Updated: 2024/01/28 22:20:51 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 19:46:50 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #include "../cub3d.h" -int is_space_surrounded_by_walls(char *map, int maxWidth, int height, int x, int y) { - // Vérifie si les cellules adjacentes à un espace sont toutes des murs ('1') - return (x > 0 && map[y * maxWidth + (x - 1)] == '1') && - (x < maxWidth - 1 && map[y * maxWidth + (x + 1)] == '1') && - (y > 0 && map[(y - 1) * maxWidth + x] == '1') && - (y < height - 1 && map[(y + 1) * maxWidth + x] == '1'); -} - -int flood_fill_and_check(char *map, char *visitedMap, int maxWidth, int height, int x, int y, char replacement) { - if (x < 0 || x >= maxWidth || y < 0 || y >= height) { - return 0; // Ouverture détectée - } - - if (visitedMap[y * maxWidth + x] == 1 || map[y * maxWidth + x] == '1') { - return 1; // Mur ou déjà visité - } - - if (map[y * maxWidth + x] == ' ' && !is_space_surrounded_by_walls(map, maxWidth, height, x, y)) { - return 0; // Espace non entouré correctement par des murs, ouverture intérieure détectée - } - - visitedMap[y * maxWidth + x] = 1; // Marquer la cellule comme visitée - map[y * maxWidth + x] = replacement; // Marquer la cellule dans la carte principale - - // Appliquer récursivement à toutes les directions - return flood_fill_and_check(map, visitedMap, maxWidth, height, x + 1, y, replacement) && - flood_fill_and_check(map, visitedMap, maxWidth, height, x - 1, y, replacement) && - flood_fill_and_check(map, visitedMap, maxWidth, height, x, y + 1, replacement) && - flood_fill_and_check(map, visitedMap, maxWidth, height, x, y - 1, replacement); -} - -int is_surrounded_by_walls(char *map, int maxWidth, int height, int x, int y) { - // Vérifier les limites - if (x <= 0 || x >= maxWidth - 1 || y <= 0 || y >= height - 1) return 1; - - // Vérifier les cellules adjacentes - if (map[(y - 1) * maxWidth + x] == '1' && map[(y + 1) * maxWidth + x] == '1' && - map[y * maxWidth + (x - 1)] == '1' && map[y * maxWidth + (x + 1)] == '1') { - return 1; - } - - return 0; -} - -int is_map_closed(char *map, int maxWidth, int height) { - - char *copy_map = malloc(maxWidth * height); - if (copy_map) - { - ft_memcpy(copy_map, map, maxWidth * height); - } - char *visitedMap = calloc(maxWidth * height, sizeof(char)); - if (!visitedMap) { - printf("Erreur d'allocation mémoire pour visitedMap.\n"); - return 0; - } - - int startX = -1, startY = -1; - printf("Début de la vérification de fermeture de la carte.\n"); - - /* Affichage de la carte avant flood_fill - printf("Carte avant flood_fill:\n"); - for (int y = 0; y < height; y++) { - for (int x = 0; x < maxWidth; x++) { - printf("%c", map[y * maxWidth + x]); - } - printf("\n"); - }*/ - - // Trouver un point de départ valide - for (int y = 0; y < height && startX == -1; y++) { - for (int x = 0; x < maxWidth && startX == -1; x++) { - if ((map[y * maxWidth + x] == '0' || map[y * maxWidth + x] == '2') && !is_surrounded_by_walls(map, maxWidth, height, x, y)) { - startX = x; - startY = y; - printf("Point de départ trouvé pour flood_fill à (%d, %d)\n", startX, startY); - break; - } - } - } - - if (startX == -1) { - printf("Aucun point de départ valide trouvé.\n"); - free(visitedMap); - return 1; // Si aucun point de départ n'est trouvé, la carte est considérée comme fermée - } - - int is_closed = flood_fill_and_check(copy_map, visitedMap, maxWidth, height, startX, startY, '3'); - - - /*printf("Carte après flood_fill:\n"); - for (int y = 0; y < height; y++) { - for (int x = 0; x < maxWidth; x++) { - printf("%c", visitedMap[y * maxWidth + x] ? '3' : map[y * maxWidth + x]); - } - printf("\n"); - }*/ - - - free(visitedMap); - free(copy_map); - return is_closed; -} - -/*int is_map_closed(char *map, int maxWidth, int height) +static int flood_fill_and_check(t_map_check *map_check, + char *visitedMap, t_point p, char replacement) { - if (!check_borders(map, maxWidth, height)) + if (p.x < 0 || p.x >= map_check->maxWidth + || p.y < 0 || p.y >= map_check->height) return (0); - if (!check_interior(map, maxWidth, height)) - return (0); - return (1); -} - -int check_line_border(char *line, int lineLength, int y) -{ - if (lineLength == 0) + if (visitedMap[p.y * map_check->maxWidth + p.x] == 1 + || map_check->map[p.y * map_check->maxWidth + p.x] == '1') return (1); - if (line[0] != '1') + if (map_check->map[p.y * map_check->maxWidth + p.x] == ' ' + && !is_space_surrounded_by_walls(map_check, p)) return (0); - if (line[lineLength - 1] != '1') - return (0); - return (1); + visitedMap[p.y * map_check->maxWidth + p.x] = 1; + map_check->map[p.y * map_check->maxWidth + p.x] = replacement; + return (flood_fill_and_check(map_check, visitedMap, + (t_point){p.x + 1, p.y}, replacement) + && flood_fill_and_check(map_check, visitedMap, + (t_point){p.x - 1, p.y}, replacement) + && flood_fill_and_check(map_check, visitedMap, + (t_point){p.x, p.y + 1}, replacement) + && flood_fill_and_check(map_check, visitedMap, + (t_point){p.x, p.y - 1}, replacement)); } -int check_vertical_borders(char *map, int maxWidth, int height) -{ - int x, y, first_wall_found, last_wall_found; - - for (x = 0; x < maxWidth; x++) - { - first_wall_found = 0; - last_wall_found = height - 1; - - // Trouver le premier '1' dans la colonne - for (y = 0; y < height; y++) - { - if (map[y * maxWidth + x] == '1') - { - first_wall_found = 1; - break; - } - } - - // Trouver le dernier '1' dans la colonne - for (y = height - 1; y >= 0; y--) - { - if (map[y * maxWidth + x] == '1') - { - last_wall_found = y; - break; - } - } - - // Si aucun mur trouvé, la colonne est incorrecte - if (!first_wall_found || last_wall_found == height - 1) - { - printf("Border issue detected in column %d\\n", x); - return 0; - } - - // Vérifier que la colonne est correctement fermée - for (y = first_wall_found; y <= last_wall_found; y++) - { - if (map[y * maxWidth + x] != '1' && map[y * maxWidth + x] != ' ') - { - printf("Border issue detected in column %d at position %d\\n", x, y); - return 0; - } - } - } - - return 1; -} - -int check_horizontal_borders(char *map, int maxWidth, int height) -{ - int x, y; - - for (y = 0; y < height; y += height - 1) // Vérifier seulement la première et la dernière ligne - { - int first_wall_found = 0; - int last_wall_found = 0; - - // Trouver le premier '1' dans la ligne - for (x = 0; x < maxWidth; x++) - { - if (map[y * maxWidth + x] == '1') - { - first_wall_found = 1; - break; - } - } - - // Trouver le dernier '1' dans la ligne - for (x = maxWidth - 1; x >= 0; x--) - { - if (map[y * maxWidth + x] == '1') - { - last_wall_found = 1; - break; - } - } - - // Si aucun mur '1' n'est trouvé au début ou à la fin de la ligne - if (!first_wall_found || !last_wall_found) - { - printf("Border issue detected in line %d\\n", y); - return 0; - } - } - - return 1; -} - -int check_borders(char *map, int maxWidth, int height) +static int find_start_point(t_map_check *map_check, t_point *startPoint) { int y; - int linelength; int x; y = 0; - while (y < height) + while (y < map_check->height) { - linelength = 0; x = 0; - while (x < maxWidth && map[y * maxWidth + x] != ' ') + while (x < map_check->maxWidth) { - linelength++; + if ((map_check->map[y * map_check->maxWidth + x] == '0' + || map_check->map[y * map_check->maxWidth + x] == '2') + && !is_space_surrounded_by_walls(map_check, (t_point){x, y})) + { + startPoint->x = x; + startPoint->y = y; + return (1); + } x++; } - if (!check_line_border(&map[y * maxWidth], linelength, y)) - { - return (0); - } y++; } - if (!check_horizontal_borders(map, maxWidth, height)) + return (0); +} + +static int initialize_maps(char **copy_map, char **visited_map, + int maxWidth, int height) +{ + *copy_map = malloc(maxWidth * height); + *visited_map = calloc(maxWidth * height, sizeof(char)); + if (!(*copy_map) || !(*visited_map)) { + free(*copy_map); + free(*visited_map); + printf("Erreur d'allocation mémoire.\n"); return (0); } - return (check_vertical_borders(map, maxWidth, height)); -}*/ + return (1); +} + +static void cleanup_and_print_error(char *visited_map, char *copy_map) +{ + free(visited_map); + free(copy_map); + printf("Aucun point de départ valide trouvé.\n"); +} + +int is_map_closed(char *map, int maxWidth, int height) +{ + char *copy_map; + char *visited_map; + t_map_check map_check; + t_point start_point; + int is_closed; + + map_check.maxWidth = maxWidth; + map_check.height = height; + if (!initialize_maps(©_map, &visited_map, maxWidth, height)) + return (0); + ft_memcpy(copy_map, map, maxWidth * height); + map_check.map = copy_map; + if (!find_start_point(&map_check, &start_point)) + { + cleanup_and_print_error(visited_map, copy_map); + return (1); + } + is_closed = flood_fill_and_check(&map_check, visited_map, start_point, '3'); + free(visited_map); + free(copy_map); + return (is_closed); +} diff --git a/parsing/ft_map_check_utils.c b/parsing/ft_map_check_utils.c new file mode 100644 index 0000000..20e34ad --- /dev/null +++ b/parsing/ft_map_check_utils.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_map_check_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: fgras-ca +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/01/29 19:44:27 by fgras-ca #+# #+# */ +/* Updated: 2024/01/29 19:48:01 by fgras-ca ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../cub3d.h" + +int check_boundaries(t_point p, t_map_check *map_check) +{ + return (p.x > 0 && p.x < map_check->maxWidth - 1 + && p.y > 0 && p.y < map_check->height - 1); +} + +int is_space_surrounded_by_walls(t_map_check *map_check, t_point p) +{ + if (!check_boundaries(p, map_check)) + return (0); + return (map_check->map[p.y * map_check->maxWidth + (p.x - 1)] == '1' + && map_check->map[p.y * map_check->maxWidth + (p.x + 1)] == '1' + && map_check->map[(p.y - 1) * map_check->maxWidth + p.x] == '1' + && map_check->map[(p.y + 1) * map_check->maxWidth + p.x] == '1'); +} diff --git a/parsing/ft_map_dimensions.c b/parsing/ft_map_dimensions.c index 651617b..b6386b5 100644 --- a/parsing/ft_map_dimensions.c +++ b/parsing/ft_map_dimensions.c @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/11 22:17:19 by fgras-ca #+# #+# */ -/* Updated: 2024/01/15 22:37:27 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 16:05:03 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,12 +15,12 @@ void update_max_dimensions(t_map_params *params) { (*(params->height))++; - if (*(params->currentWidth) > *(params->maxWidth)) + if (*(params->current_width) > *(params->max_width)) { - *(params->maxWidth) = *(params->currentWidth); + *(params->max_width) = *(params->current_width); } - *(params->currentWidth) = 0; - *(params->isNewLine) = 1; + *(params->current_width) = 0; + *(params->is_new_line) = 1; } void process_character(t_map_params *params, int *i) @@ -31,8 +31,8 @@ void process_character(t_map_params *params, int *i) } else if (params->buffer[*i] != '\r') { - (*(params->currentWidth))++; - *(params->isNewLine) = 0; + (*(params->current_width))++; + *(params->is_new_line) = 0; } (*i)++; } @@ -46,16 +46,16 @@ void get_map_dimensions(t_map_params *params) i = 0; currentwidth = 0; isnewline = 1; - *(params->maxWidth) = 0; + *(params->max_width) = 0; *(params->height) = 0; - params->currentWidth = ¤twidth; - params->isNewLine = &isnewline; + params->current_width = ¤twidth; + params->is_new_line = &isnewline; while (i < params->length) process_character(params, &i); - if (!*(params->isNewLine)) + if (!*(params->is_new_line)) update_max_dimensions(params); printf("Map dimensions: maxWidth=%d, height=%d\n", - *(params->maxWidth), *(params->height)); + *(params->max_width), *(params->height)); } void fill_map_space(t_structure_map *map_info, int maxWidth, int height) @@ -88,9 +88,9 @@ void copy_map_data(t_map_params *params) y++; x = 0; } - else if (params->buffer[i] != '\r' && x < *params->maxWidth) + else if (params->buffer[i] != '\r' && x < *params->max_width) { - params->map_info->map[y * *params->maxWidth + x] + params->map_info->map[y * *params->max_width + x] = params->buffer[i]; x++; } diff --git a/parsing/ft_parsing.c b/parsing/ft_parsing.c index b2c6cc4..ea62588 100644 --- a/parsing/ft_parsing.c +++ b/parsing/ft_parsing.c @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/11 14:43:46 by fgras-ca #+# #+# */ -/* Updated: 2024/01/28 17:31:00 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 19:51:28 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,8 @@ bool init_map_info(t_structure_map *map_info, int maxWidth, int height) { - map_info->mapX = maxWidth; - map_info->mapY = height; + map_info->map_x = maxWidth; + map_info->map_y = height; map_info->s_win.width = WIDTH; map_info->s_win.height = HEIGHT; map_info->map = malloc(maxWidth * height); @@ -31,7 +31,8 @@ bool init_map_info(t_structure_map *map_info, int maxWidth, int height) bool copy_map_data_and_check(t_map_params *params) { copy_map_data(params); - if (!is_map_closed(params->map_info->map, *params->maxWidth, *params->height)) + if (!is_map_closed(params->map_info->map, + *params->max_width, *params->height)) { printf("Map is not closed!\n"); free(params->map_info->map); @@ -45,23 +46,24 @@ void calculate_map(t_structure_map *map_info) float maps_x; float maps_y; - maps_x = (float)map_info->s_win.width / (map_info->mapX * 4); - maps_y = (float)map_info->s_win.height / (map_info->mapY * 2); + maps_x = (float)map_info->s_win.width / (map_info->map_x * 4); + maps_y = (float)map_info->s_win.height / (map_info->map_y * 2); if (maps_x < maps_y) { - map_info->mapS = (int)maps_x; + map_info->map_s = (int)maps_x; } else { - map_info->mapS = (int)maps_y; + map_info->map_s = (int)maps_y; } - if (map_info->mapS == 0) + if (map_info->map_s == 0) { - map_info->mapS = 1; + map_info->map_s = 1; } } -bool parse_map(const char *map_content, int length, t_structure_map *map_info) +bool parse_map(const char *map_content, int length, + t_structure_map *map_info) { t_map_params map_params; int max_width; @@ -72,7 +74,7 @@ bool parse_map(const char *map_content, int length, t_structure_map *map_info) map_params.map_info = map_info; map_params.buffer = map_content; map_params.length = length; - map_params.maxWidth = &max_width; + map_params.max_width = &max_width; map_params.height = &height; get_map_dimensions(&map_params); if (max_width <= 0 || height <= 0) @@ -82,7 +84,7 @@ bool parse_map(const char *map_content, int length, t_structure_map *map_info) } if (!init_map_info(map_info, max_width, height)) return (false); - if (!find_player_position_and_direction(map_content, length, map_info)) + if (!find_player(map_content, length, map_info)) return (false); return (copy_map_data_and_check(&map_params)); } diff --git a/parsing/ft_read_map.c b/parsing/ft_read_map.c deleted file mode 100644 index b079a2c..0000000 --- a/parsing/ft_read_map.c +++ /dev/null @@ -1,97 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_read_map.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/01/11 19:28:43 by fgras-ca #+# #+# */ -/* Updated: 2024/01/28 22:36:40 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "../cub3d.h" - -/*static int check_line(char *map, int maxWidth, int height, int y) -{ - int x; - char c; - - for (x = 0; x < maxWidth; x++) - { - c = map[y * maxWidth + x]; - if (c == ' ' && ((x > 0 && map[y * maxWidth + (x - 1)] != '1') || - (x < maxWidth - 1 && map[y * maxWidth + (x + 1)] != '1') || - (y > 0 && map[(y - 1) * maxWidth + x] != '1') || - (y < height - 1 && map[(y + 1) * maxWidth + x] != '1'))) - return (0); - } - return (1); -} - - -static int check_row(char *map, int maxWidth, int height, int y) -{ - return check_line(map, maxWidth, height, y); -} - -int check_interior(char *map, int maxWidth, int height) -{ - int y; - - for (y = 0; y < height; y++) - { - if (!check_row(map, maxWidth, height, y)) - return (0); - } - return (1); -}*/ - -void load_sprite_frames(t_sprite *sprite, void *mlx_ptr) { - sprite->frames[0] = mlx_xpm_file_to_image(mlx_ptr, "sprite/pnj/pnj01.xpm", &sprite->width, &sprite->height); - if (sprite->frames[0] == NULL) { - printf("Erreur de chargement de sprite/pnj/pnj01.xpm\n"); - } else { - printf("Sprite pnj01.xpm chargé avec succès. Dimensions: %d x %d\n", sprite->width, sprite->height); - } - sprite->frames[1] = mlx_xpm_file_to_image(mlx_ptr, "sprite/pnj/pnj02.xpm", &sprite->width, &sprite->height); - if (sprite->frames[1] == NULL) { - printf("Erreur de chargement de sprite/pnj/pnj01.xpm\n"); - } else { - printf("Sprite pnj02.xpm chargé avec succès. Dimensions: %d x %d\n", sprite->width, sprite->height); - } - sprite->frames[2] = mlx_xpm_file_to_image(mlx_ptr, "sprite/pnj/pnj03.xpm", &sprite->width, &sprite->height); - if (sprite->frames[2] == NULL) { - printf("Erreur de chargement de sprite/pnj/pnj01.xpm\n"); - } else { - printf("Sprite pnj03.xpm chargé avec succès. Dimensions: %d x %d\n", sprite->width, sprite->height); - } -} - -void update_sprite_frame(t_sprite *sprite) { - static int counter = 0; - counter = (counter + 1) % 60; - if (counter == 0) { - sprite->current_frame = (sprite->current_frame + 1) % 3; - printf("Frame du sprite mise à jour : %d\n", sprite->current_frame); - } -} - -void draw_sprite(t_sprite *sprite, void *mlx_ptr, void *win_ptr, int win_width, int win_height) { - if (sprite->frames[sprite->current_frame] != NULL) { - float posX = 170; - float posY = 30; - - // Logs pour débogage - printf("Dessin du sprite (frame %d)...\n", sprite->current_frame); - printf("Dimensions du sprite : largeur = %d, hauteur = %d\n", sprite->width, sprite->height); - printf("Coordonnées de dessin du sprite : X = %f, Y = %f\n", posX, posY); - - // Dessiner le sprite - mlx_put_image_to_window(mlx_ptr, win_ptr, sprite->frames[sprite->current_frame], posX, posY); - printf("Sprite dessiné aux coordonnées: %f, %f\n", posX, posY); - } else { - // Log en cas d'erreur - printf("Erreur lors du dessin du sprite (frame %d)\n", sprite->current_frame); - } -} diff --git a/parsing/ft_text_and_col_utils.c b/parsing/ft_text_and_col_utils.c new file mode 100644 index 0000000..031ec9f --- /dev/null +++ b/parsing/ft_text_and_col_utils.c @@ -0,0 +1,91 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_text_and_col_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: fgras-ca +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/01/29 20:07:44 by fgras-ca #+# #+# */ +/* Updated: 2024/01/29 20:17:23 by fgras-ca ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../cub3d.h" + +bool parse_texture_line(const char *line, t_texture *textures) +{ + char direction[3]; + char path[MAX_LINE_LENGTH]; + int i; + int j; + + i = 0; + j = 0; + while (line[i] != ' ' && line[i] != '\0' && i < 2) + direction[i++] = line[i]; + direction[i] = '\0'; + while (line[i] == ' ' && line[i] != '\0') + i++; + while (line[i] != ' ' && line[i] != '\0' && j < MAX_LINE_LENGTH - 1) + path[j++] = line[i++]; + path[j] = '\0'; + if (ft_strcmp(direction, "NO") == 0) + textures->north = ft_strdup(path); + else if (ft_strcmp(direction, "SO") == 0) + textures->south = ft_strdup(path); + else if (ft_strcmp(direction, "WE") == 0) + textures->west = ft_strdup(path); + else if (ft_strcmp(direction, "EA") == 0) + textures->east = ft_strdup(path); + return (true); +} + +bool parse_number_from_str(const char **str, int *number) +{ + *number = 0; + while (**str >= '0' && **str <= '9') + { + *number = *number * 10 + (**str - '0'); + (*str)++; + } + if (**str != ',' && **str != ' ' && **str != '\0') + { + return (false); + } + return (true); +} + +bool parse_color_line(const char *line, unsigned int *color) +{ + int r; + int g; + int b; + const char *ptr; + + r = 0; + g = 0; + b = 0; + ptr = line; + while (*ptr == ' ') + ptr++; + if (!parse_number_from_str(&ptr, &r) || *ptr++ != ',') + return (false); + while (*ptr == ' ') + ptr++; + if (!parse_number_from_str(&ptr, &g) || *ptr++ != ',') + return (false); + while (*ptr == ' ') + ptr++; + if (!parse_number_from_str(&ptr, &b)) + return (false); + *color = (r << 16) | (g << 8) | b; + return (true); +} + +bool is_valid_texture(const char *line) +{ + return (ft_strncmp(line, "NO ", 3) == 0 + || ft_strncmp(line, "SO ", 3) == 0 + || ft_strncmp(line, "WE ", 3) == 0 + || ft_strncmp(line, "EA ", 3) == 0); +} diff --git a/parsing/ft_textures_and_colors.c b/parsing/ft_textures_and_colors.c index fc57d97..3ad8a07 100644 --- a/parsing/ft_textures_and_colors.c +++ b/parsing/ft_textures_and_colors.c @@ -6,128 +6,53 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/16 16:19:13 by fgras-ca #+# #+# */ -/* Updated: 2024/01/28 18:06:00 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 20:17:57 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #include "../cub3d.h" -bool parse_texture_line(const char *line, t_texture *textures) +bool handle_map(int fd, char **map_buffer, int *map_length) { - char direction[3]; - char path[MAX_LINE_LENGTH]; - int i; - int j; + char *line; + size_t len; + ssize_t read; + bool start_copying; + FILE *stream; - i = 0; - j = 0; - while (line[i] != ' ' && line[i] != '\0' && i < 2) - direction[i++] = line[i]; - direction[i] = '\0'; - while (line[i] == ' ' && line[i] != '\0') - i++; - while (line[i] != ' ' && line[i] != '\0' && j < MAX_LINE_LENGTH - 1) - path[j++] = line[i++]; - path[j] = '\0'; - if (ft_strcmp(direction, "NO") == 0) - textures->north = ft_strdup(path); - else if (ft_strcmp(direction, "SO") == 0) - textures->south = ft_strdup(path); - else if (ft_strcmp(direction, "WE") == 0) - textures->west = ft_strdup(path); - else if (ft_strcmp(direction, "EA") == 0) - textures->east = ft_strdup(path); - return (true); -} - -bool handle_map(int fd, char **map_buffer, int *map_length) { - FILE *stream = fdopen(fd, "r"); - if (!stream) { - perror("Error converting file descriptor to FILE *"); - return false; - } - - char *line = NULL; - size_t len = 0; - ssize_t read; - bool start_copying = false; - - *map_length = 0; - *map_buffer = NULL; - - while ((read = getline(&line, &len, stream)) != -1) { - // Vérifier si la ligne contient '1' ou '0' - if (!start_copying && (ft_strchr(line, '1') || ft_strchr(line, '0'))) { - start_copying = true; - } - - // Commencer la copie si on a trouvé une ligne contenant '1' ou '0' - if (start_copying) { - *map_buffer = realloc(*map_buffer, *map_length + read + 1); - if (!*map_buffer) { - perror("Error reallocating memory for map buffer"); - free(line); - fclose(stream); - return (false); - } - ft_memcpy(*map_buffer + *map_length, line, read); - *map_length += read; - (*map_buffer)[*map_length] = '\0'; - } - } - - free(line); - fclose(stream); - return (*map_buffer != NULL); -} - - - -bool parse_number_from_str(const char **str, int *number) -{ - *number = 0; - while (**str >= '0' && **str <= '9') - { - *number = *number * 10 + (**str - '0'); - (*str)++; - } - if (**str != ',' && **str != ' ' && **str != '\0') + stream = fdopen(fd, "r"); + line = NULL; + len = 0; + start_copying = false; + *map_length = 0; + *map_buffer = NULL; + if (!stream) { + perror("Error converting file descriptor to FILE *"); return (false); } - return (true); -} - -bool parse_color_line(const char *line, unsigned int *color) -{ - int r; - int g; - int b; - const char *ptr; - - r = 0; - g = 0; - b = 0; - ptr = line; - while (*ptr == ' ') ptr++; - if (!parse_number_from_str(&ptr, &r) || *ptr++ != ',') - return (false); - while (*ptr == ' ') ptr++; - if (!parse_number_from_str(&ptr, &g) || *ptr++ != ',') - return (false); - while (*ptr == ' ') ptr++; - if (!parse_number_from_str(&ptr, &b)) - return (false); - *color = (r << 16) | (g << 8) | b; - return (true); -} - -bool is_valid_texture(const char *line) -{ - return (ft_strncmp(line, "NO ", 3) == 0 - || ft_strncmp(line, "SO ", 3) == 0 - || ft_strncmp(line, "WE ", 3) == 0 - || ft_strncmp(line, "EA ", 3) == 0); + while ((read = getline(&line, &len, stream)) != -1) + { + if (!start_copying && (ft_strchr(line, '1') || ft_strchr(line, '0'))) + start_copying = true; + if (start_copying) + { + *map_buffer = realloc(*map_buffer, *map_length + read + 1); + if (!*map_buffer) + { + perror("Error reallocating memory for map buffer"); + free(line); + fclose(stream); + return (false); + } + ft_memcpy(*map_buffer + *map_length, line, read); + *map_length += read; + (*map_buffer)[*map_length] = '\0'; + } + } + free(line); + fclose(stream); + return (*map_buffer != NULL); } bool handle_textures(int fd, t_texture *textures) diff --git a/window/ft_map.c b/window/ft_map.c index 3a6eb57..ec95e99 100644 --- a/window/ft_map.c +++ b/window/ft_map.c @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/14 20:19:01 by fgras-ca #+# #+# */ -/* Updated: 2024/01/25 18:36:59 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 15:47:34 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ void draw_map_line(t_structure_main *w, int y, int lineLength) x = 0; while (x < lineLength) { - index = y * w->s_map.mapX + x; + index = y * w->s_map.map_x + x; if (w->s_map.map[index] == '1') color = 0xFFFFFF; else if (w->s_map.map[index] == '0') @@ -48,12 +48,12 @@ void draw_map(t_structure_main *w) printf("Erreur: La carte n'a pas été chargée correctement.\n"); return ; } - while (y < w->s_map.mapY) + while (y < w->s_map.map_y) { linelength = 0; - while (linelength < w->s_map.mapX - && w->s_map.map[y * w->s_map.mapX + linelength] - != '\n' && w->s_map.map[y * w->s_map.mapX + linelength] != '\0') + while (linelength < w->s_map.map_x + && w->s_map.map[y * w->s_map.map_x + linelength] + != '\n' && w->s_map.map[y * w->s_map.map_x + linelength] != '\0') { linelength++; } diff --git a/window/ft_player.c b/window/ft_player.c index 9288b9d..0f25f05 100644 --- a/window/ft_player.c +++ b/window/ft_player.c @@ -6,29 +6,34 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/14 20:09:23 by fgras-ca #+# #+# */ -/* Updated: 2024/01/23 18:38:11 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 20:21:37 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #include "../cub3d.h" -void init_player(t_structure_main *w) { - w->s_player.px = w->s_map.player_x; - w->s_player.py = w->s_map.player_y; - - // Remplacer le switch par des if - if (w->s_map.player_direction == 'N') { - w->s_player.pa = M_PI; - } else if (w->s_map.player_direction == 'S') { - w->s_player.pa = 0; - } else if (w->s_map.player_direction == 'E') { - w->s_player.pa = M_PI / 2; - } else if (w->s_map.player_direction == 'W') { - w->s_player.pa = 3 * M_PI / 2; - } - - w->s_player.pdx = cos(w->s_player.pa) * 5; - w->s_player.pdy = sin(w->s_player.pa) * 5; +void init_player(t_structure_main *w) +{ + w->s_player.px = w->s_map.player_x; + w->s_player.py = w->s_map.player_y; + if (w->s_map.player_direction == 'N') + { + w->s_player.pa = M_PI; + } + else if (w->s_map.player_direction == 'S') + { + w->s_player.pa = 0; + } + else if (w->s_map.player_direction == 'E') + { + w->s_player.pa = M_PI / 2; + } + else if (w->s_map.player_direction == 'W') + { + w->s_player.pa = 3 * M_PI / 2; + } + w->s_player.pdx = cos(w->s_player.pa) * 5; + w->s_player.pdy = sin(w->s_player.pa) * 5; } void init_mlx_and_window(t_structure_main *w) diff --git a/window/ft_refresh_window.c b/window/ft_refresh_window.c index 6654247..95986bd 100644 --- a/window/ft_refresh_window.c +++ b/window/ft_refresh_window.c @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/15 19:50:24 by fgras-ca #+# #+# */ -/* Updated: 2024/01/28 22:04:52 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 20:23:13 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,10 +19,10 @@ void rescale_sprite(t_structure_main *w, t_state *state) params.original_img = w->s_img.roomadslam[state->jkl]; params.original_width = 112; params.original_height = 112; - params.new_width = w->s_map.mapS; - params.new_height = w->s_map.mapS; - params.px = w->s_player.px - w->s_map.mapS / 2; - params.py = w->s_player.py - w->s_map.mapS / 2; + params.new_width = w->s_map.map_s; + params.new_height = w->s_map.map_s; + params.px = w->s_player.px - w->s_map.map_s / 2; + params.py = w->s_player.py - w->s_map.map_s / 2; rescale_image(¶ms, w); } @@ -35,8 +35,6 @@ void refresh_window(t_structure_main *w, t_state *state) &(w->s_img.bpp), &(w->s_img.line_len), &(w->s_img.endian)); draw_map(w); drawrays2d(w); - update_sprite_frame(&w->sprite); - draw_sprite(&w->sprite, w->s_win.mlx, w->s_win.win, w->s_win.width, w->s_win.height); mlx_put_image_to_window(w->s_win.mlx, w->s_win.win, w->s_img.buffer, 0, 0); rescale_sprite(w, state); } @@ -48,11 +46,11 @@ void handle_mouse_movement(t_structure_main *w) mlx_mouse_get_pos(w->s_win.mlx, w->s_win.win, &x, &y); if ((x > 0 && x < w->s_win.width) && (y > 0 && y < w->s_win.height)) - { - if (x < w->s_win.width/2-40) - deal_key(65361,w); - else if (x > w->s_win.width/2+40) - deal_key(65363,w); + { + if (x < w->s_win.width / 2 - 40) + deal_key(65361, w); + else if (x > w->s_win.width / 2 + 40) + deal_key(65363, w); } } diff --git a/window/ft_window.c b/window/ft_window.c index c71b422..cad008c 100644 --- a/window/ft_window.c +++ b/window/ft_window.c @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/14 19:15:53 by fgras-ca #+# #+# */ -/* Updated: 2024/01/28 21:57:21 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/29 15:47:48 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -76,12 +76,12 @@ void calculate_map_scale(t_structure_main *w) int maps_x; int maps_y; - maps_x = w->s_win.width / (w->s_map.mapX * 4); - maps_y = w->s_win.height / (w->s_map.mapY * 2); + maps_x = w->s_win.width / (w->s_map.map_x * 4); + maps_y = w->s_win.height / (w->s_map.map_y * 2); if (maps_x < maps_y) - w->s_map.mapS = maps_x; + w->s_map.map_s = maps_x; else - w->s_map.mapS = maps_y; + w->s_map.map_s = maps_y; } void init_windows(t_structure_main *w) @@ -93,7 +93,6 @@ void init_windows(t_structure_main *w) load_textures(w, &temp); init_buffer(w); load_wall_textures(w); - load_sprite_frames(&w->sprite, w->s_win.mlx); printf("Window Dimensions: Width = %d, Height = %d\n", w->s_win.width, w->s_win.height); printf("Texture Dimensions: Width = %d, Height = %d\n",