From 9cd2f6e29e5164f9b172cd2fe0d10863085183fa Mon Sep 17 00:00:00 2001 From: mcolonna Date: Tue, 1 Oct 2024 14:08:22 +0200 Subject: [PATCH 01/80] add include/map.h --- include/map.h | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 include/map.h diff --git a/include/map.h b/include/map.h new file mode 100644 index 0000000..67e379e --- /dev/null +++ b/include/map.h @@ -0,0 +1,64 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* map.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */ +/* Updated: 2024/10/01 14:00:40 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MAP_H +# define MAP_H + +/// @brief The type of a case. +typedef enum e_map_wall +{ + /// @brief Empty case, for '0' and ' '. + EMPTY, + /// @brief A wall, for '1'. + WALL, +} t_map_wall; + +/// @brief An object of the map (player, enemies?) +typedef struct s_object +{ + /// @brief Function called when creating the object. + /// @param data Address of the s_object.data pointer. + void (*init)(void **data); + /// @brief Function called when destroying the object (to free everything). + /// @param data Address of the s_object.data pointer. + void (*destroy)(void **data); + /// @brief Function called each tick. + /// @param data Address of the s_object.data pointer. + void (*tick)(void **data); + /// @brief Pointer the object can use to save data. + void *data; +} t_object; + +/// @brief Represents a case of the map. +typedef struct s_map_case +{ + /// @brief Is the case empty or a wall? + t_map_wall wall; + /// @brief The object that appears on this case. If there is none, + /// every pointer of the struct will be NULL. + t_object object; +} t_map_case; + +/// @brief Represents a map. +typedef struct s_map +{ + /// @brief Width of the map. + int width; + /// @brief Height of the map. + int height; + /// @brief An 2D array of all the cases. + /// Syntax to get a case: cases[y][x] + /// x is left to right, y is top to bottom. + t_map_case **cases; +} t_map; + +#endif \ No newline at end of file From f04587cd62ec5d9d39fc8059489e92143467ac24 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Tue, 1 Oct 2024 16:22:42 +0200 Subject: [PATCH 02/80] add Makefile --- Makefile | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6f950dd --- /dev/null +++ b/Makefile @@ -0,0 +1,63 @@ +NAME = cub3D +CPP = gcc -Wall -Wextra -Werror $(FLAGS) +C_FILES = $(wildcard *.c) +O_FILES = $(patsubst %.c,%.o,$(C_FILES)) + +ECHO = echoo(){ \ + if [ -t 1 ]; then \ + echo "$$*"; \ + else \ + echo "$$*" | sed -E "s/\x1B[[][0-9;]+m//g"; \ + fi; \ +};echoo + +all : $(NAME) + +clean : + @$(ECHO) + @$(ECHO) "\e[30;47;1m $(NAME): clean... \e[0m" + -rm -f $(O_FILES) + +fclean : clean + @$(ECHO) + @$(ECHO) "\e[30;47;1m $(NAME): fclean... \e[0m" + -rm -f $(NAME) + +re : fclean all + +$(NAME) : $(O_FILES) + @$(ECHO) + @$(ECHO) "\e[30;47;1m $(NAME): linking... \e[0m" + $(CPP) $(FLAGS_2) -o $(NAME) $(O_FILES) + @$(ECHO) + @$(ECHO) "\t\t \e[0;92m\(^o^)/ \e[0;102;30;1m $(NAME) made! \e[0;92m \(^o^)/\e[0m" + @$(ECHO) + +%.o : %.cpp + @$(ECHO) + @$(ECHO) "\e[30;47;1m $(NAME): making '$@'... \e[0m" + $(CPP) $(FLAGS_1) -c $< -o $@ + +check_headers : + @ERROR=0; \ + echo $(wildcard **/*.h); \ + for HEADER in $(wildcard **/*.h); \ + do \ + echo "check header $$HEADER..."; \ + > __tmp_check_header.c echo "#include \"$$HEADER\""; \ + >> __tmp_check_header.c echo "#include \"$$HEADER\""; \ + >> __tmp_check_header.c echo "int main(void) {}"; \ + $(CPP) -o __tmp_check_header.out __tmp_check_header.c; \ + if [ $$? -ne 0 ]; \ + then \ + ERROR=1; \ + echo error \ + break; \ + fi; \ + echo "good :)"; \ + 2> /dev/null rm -- "__tmp_check_header.out" "__tmp_check_header.c"; \ + done; \ + 2> /dev/null rm __tmp_check_header.out __tmp_check_header.c; \ + if [ $$ERROR -eq 0 ]; then true; else false; fi; + +.PHONY : all clean fclean re check_headers \ No newline at end of file From 8eed6feb6b1a7a3a98c4123e29c183331365d2db Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Tue, 1 Oct 2024 18:58:49 +0200 Subject: [PATCH 03/80] f --- Makefile | 45 +++++++++++++++++++++++++++++++++++++++++++ algo.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ algo.h | 36 +++++++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 Makefile create mode 100644 algo.c create mode 100644 algo.h diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..72fd05f --- /dev/null +++ b/Makefile @@ -0,0 +1,45 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: grobledo +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/07/29 13:08:42 by greg #+# #+# # +# Updated: 2024/10/01 18:58:09 by grobledo ### ########.fr # +# # +# **************************************************************************** # + +NAME = cub3d + +SRC = + +OBJS = ${SRC:.c=.o} + +LIBFT = Libft + +MLX = Minilibx + +CC = gcc -g + +CFLAGS = -Wall -Werror -Wextra + +obj : ${OBJS} + +all: $(NAME) + +$(NAME): ${OBJS} + + make -C ${LIBFT} + make -C ${MLX} + gcc ${OBJS} Libft/libft.a Minilibx/libmlx.a -lX11 -lXext -o cub3d + +clean : + rm -f ${OBJS} + +fclean : clean + rm -f $(NAME) + make fclean -C ${LIBFT} + make clean -C ${MLX} + +re : fclean all diff --git a/algo.c b/algo.c new file mode 100644 index 0000000..bacfda7 --- /dev/null +++ b/algo.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* algo.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ +/* Updated: 2024/10/01 18:57:51 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "algo.h" + + +int algo(struct) +{ + double posX; + double posY; //position x et y du joueur sur la map + double dirX; + double dirY; // orientation du joeur sur la map + double planeX; + double planeY;// position de la cam + double currtime; // temps frame actuelle + double oldtime; // temps derniere frame + + posX = 2; + posY = 2; + dirX = -1; + dirY = 0; + planeX = 0; + planeY = 0.66; // FOV de 66 degres + currtime = 0; + oldtime = 0; + +} + +// int initalgo(struct) +// { +// posX = 2; +// posY = 2; +// dirX = -1; +// dirY = 0; +// planeX = 0; +// planeY = 0.66; // FOV de 66 degres +// currtime = 0; +// oldtime = 0; +// return (0); +// } + + + + +// https://github.com/iciamyplant/Cub3d-Linux + +// https://lodev.org/cgtutor/raycasting.html + +// https://www.youtube.com/watch?v=js7HW65MmNw&list=PL0H9-oZl_QOHM34HvD3DiGmwmj5X7GvTW diff --git a/algo.h b/algo.h new file mode 100644 index 0000000..9ed7355 --- /dev/null +++ b/algo.h @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* algo.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ +/* Updated: 2024/10/01 18:57:39 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef ALGO_H +#define ALGO_H + +#include +#include + +typedef struct s_player +{ + // pos player on map + double posX; + double posY; + // orientation player on map + double dirX; + double dirY; + // orientation cam on map + double planeX; + double planeY; + // current frame + double currtime; + // last frame + double oldtime; +} t_player; + +#endif From f7f92cbaa80626629496eeaa832ace979c9cca87 Mon Sep 17 00:00:00 2001 From: ReverseSky Date: Thu, 3 Oct 2024 17:54:28 +0200 Subject: [PATCH 04/80] first part algo --- Makefile | 6 +-- algo.c | 139 ++++++++++++++++++++++++++++++++++++++++++------------- algo.h | 25 ++++++++-- 3 files changed, 132 insertions(+), 38 deletions(-) diff --git a/Makefile b/Makefile index 72fd05f..8ba5229 100644 --- a/Makefile +++ b/Makefile @@ -3,16 +3,16 @@ # ::: :::::::: # # Makefile :+: :+: :+: # # +:+ +:+ +:+ # -# By: grobledo +#+ +:+ +#+ # +# By: greg +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/07/29 13:08:42 by greg #+# #+# # -# Updated: 2024/10/01 18:58:09 by grobledo ### ########.fr # +# Updated: 2024/10/03 17:00:43 by greg ### ########.fr # # # # **************************************************************************** # NAME = cub3d -SRC = +SRC = algo.c OBJS = ${SRC:.c=.o} diff --git a/algo.c b/algo.c index bacfda7..2dc1cbb 100644 --- a/algo.c +++ b/algo.c @@ -3,50 +3,127 @@ /* ::: :::::::: */ /* algo.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ +/* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/01 18:57:51 by grobledo ### ########.fr */ +/* Updated: 2024/10/03 17:42:13 by greg ### ########.fr */ /* */ /* ************************************************************************** */ #include "algo.h" -int algo(struct) +static int initalgo(t_ray *ray) { - double posX; - double posY; //position x et y du joueur sur la map - double dirX; - double dirY; // orientation du joeur sur la map - double planeX; - double planeY;// position de la cam - double currtime; // temps frame actuelle - double oldtime; // temps derniere frame + ray->posX = 2; + ray->posY = 2; + ray->dirX = -1; + ray->dirY = 0; + ray->planeX = 0; + ray->planeY = 0.66; // FOV de 66 degres + ray->currtime = 0; + ray->oldtime = 0; + return (0); +} - posX = 2; - posY = 2; - dirX = -1; - dirY = 0; - planeX = 0; - planeY = 0.66; // FOV de 66 degres - currtime = 0; - oldtime = 0; + +int algo() +{ + t_ray ray; + int x; + double width; + int height; + // quelle box sur la map on est + int mapX; + int mapY; + // wall hit and if yes in wich direction + int hit; + int side; + + initalgo(&ray); + // init image; + + + x = 0; + width = 640; + height = 480; + while (x < w) + { + // position et direction du rayon + ray.cameraX = 2 * x / width - 1; + ray.raydirX = ray.dirX + ray.planeX * ray.cameraX; + ray.raydirY = ray.dirY + ray.planeY * ray.cameraX; + + mapX = (int)ray.posX; + mapY = (int)ray.posY; + + ray.deltadistX = (ray.raydirX == 0) ? 1e30 : fabs(1 / ray.raydirX); + ray.deltadistY = (ray.raydirY == 0) ? 1e30 : fabs(1 / ray.raydirY); + + hit = 0; + + //calculate step and initial sideDist + if (ray.raydirX < 0) + { + ray.stepX = -1; + ray.sidedistX = (ray.posX - mapX) * ray.deltadistX; + } + else + { + ray.stepX = 1; + ray.sidedistX = (mapX + 1.0 - ray.posX) * ray.deltadistX; + } + if (ray.raydirY < 0) + { + ray.stepY = -1; + ray.sidedistY = (ray.posY - mapY) * ray.deltadistY; + } + else + { + ray.stepY = 1; + ray.sidedistY = (mapY + 1.0 - ray.posY) * ray.deltadistY; + } + while(hit == 0) + { + //jump to next map square, either in x-direction, or in y-direction + if(ray.sidedistX < ray.sidedistY) + { + ray.sidedistX += ray.deltadistX; + mapX += ray.stepX; + side = 0; + } + else + { + ray.sidedistY += ray.deltadistY; + mapY += ray.stepY; + side = 1; + } + //Check if ray has hit a wall + if(worldMap[mapX][mapY] == 1) + hit = 1; + } + if(side == 0) + ray.perpwalldist = (ray.sidedistX - ray.deltadistX); + else + ray.perpwalldist = (ray.sidedistY - ray.deltadistY); + //Calculate height of line to draw on screen + int lineHeight = (int)(height / ray.perpwalldist); + lineHeight = (int)(height / ray.perpwalldist); + + //calculate lowest and highest pixel to fill in current stripe + int drawStart; + drawStart = -lineHeight / 2 + height / 2; + if(drawStart < 0) + drawStart = 0; + int drawEnd; + if(drawEnd >= height) + drawEnd = height - 1; + + } + return (0); } -// int initalgo(struct) -// { -// posX = 2; -// posY = 2; -// dirX = -1; -// dirY = 0; -// planeX = 0; -// planeY = 0.66; // FOV de 66 degres -// currtime = 0; -// oldtime = 0; -// return (0); -// } diff --git a/algo.h b/algo.h index 9ed7355..8f89eeb 100644 --- a/algo.h +++ b/algo.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* algo.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ +/* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/01 18:57:39 by grobledo ### ########.fr */ +/* Updated: 2024/10/03 17:26:27 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ #include #include -typedef struct s_player +typedef struct s_ray { // pos player on map double posX; @@ -31,6 +31,23 @@ typedef struct s_player double currtime; // last frame double oldtime; -} t_player; + // camera pos + double cameraX; + // direction rayon + double raydirX; + double raydirY; + // longueur du rayon entre pos actuelle et pos du prochain cote d'une box + double sidedistX; + double sidedistY; + // longueur du rayon entre pos d'un cote d'une box jusqu'a pos du prochain cote d'une box + double deltadistX; + double deltadistY; + // calcul lenght of ray (shortest perpendicular distance between wall and camera plane) + double perpwalldist; + // step direction (can be -1 or +1) + int stepX; + int stepY; + //wall hit? +} t_ray; #endif From bdd7e86f3cb9be6c43ee1623cf1d1577e6fa3851 Mon Sep 17 00:00:00 2001 From: ReverseSky Date: Thu, 3 Oct 2024 19:00:43 +0200 Subject: [PATCH 05/80] manque even, mlx fonction et definition map --- algo.c | 181 ++++++++++++++++++++++++++++++++++++++------------------- algo.h | 11 ++-- 2 files changed, 125 insertions(+), 67 deletions(-) diff --git a/algo.c b/algo.c index 2dc1cbb..b67db6a 100644 --- a/algo.c +++ b/algo.c @@ -6,7 +6,7 @@ /* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/03 17:42:13 by greg ### ########.fr */ +/* Updated: 2024/10/03 18:59:06 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,8 @@ static int initalgo(t_ray *ray) ray->planeY = 0.66; // FOV de 66 degres ray->currtime = 0; ray->oldtime = 0; + ray->movespeed = 0.1; + ray->rotspeed = 0.1; return (0); } @@ -47,78 +49,135 @@ int algo() x = 0; width = 640; height = 480; - while (x < w) + while (x < width) { - // position et direction du rayon - ray.cameraX = 2 * x / width - 1; - ray.raydirX = ray.dirX + ray.planeX * ray.cameraX; - ray.raydirY = ray.dirY + ray.planeY * ray.cameraX; + // position et direction du rayon + ray.cameraX = 2 * x / width - 1; + ray.raydirX = ray.dirX + ray.planeX * ray.cameraX; + ray.raydirY = ray.dirY + ray.planeY * ray.cameraX; - mapX = (int)ray.posX; - mapY = (int)ray.posY; + mapX = (int)ray.posX; + mapY = (int)ray.posY; - ray.deltadistX = (ray.raydirX == 0) ? 1e30 : fabs(1 / ray.raydirX); - ray.deltadistY = (ray.raydirY == 0) ? 1e30 : fabs(1 / ray.raydirY); + ray.deltadistX = (ray.raydirX == 0) ? 1e30 : fabs(1 / ray.raydirX); + ray.deltadistY = (ray.raydirY == 0) ? 1e30 : fabs(1 / ray.raydirY); - hit = 0; + hit = 0; - //calculate step and initial sideDist - if (ray.raydirX < 0) - { - ray.stepX = -1; - ray.sidedistX = (ray.posX - mapX) * ray.deltadistX; - } - else - { - ray.stepX = 1; - ray.sidedistX = (mapX + 1.0 - ray.posX) * ray.deltadistX; - } - if (ray.raydirY < 0) - { - ray.stepY = -1; - ray.sidedistY = (ray.posY - mapY) * ray.deltadistY; - } - else - { - ray.stepY = 1; - ray.sidedistY = (mapY + 1.0 - ray.posY) * ray.deltadistY; - } - while(hit == 0) - { - //jump to next map square, either in x-direction, or in y-direction - if(ray.sidedistX < ray.sidedistY) + //calculate step and initial sideDist + if (ray.raydirX < 0) { - ray.sidedistX += ray.deltadistX; - mapX += ray.stepX; - side = 0; + ray.stepX = -1; + ray.sidedistX = (ray.posX - mapX) * ray.deltadistX; } else { - ray.sidedistY += ray.deltadistY; - mapY += ray.stepY; - side = 1; + ray.stepX = 1; + ray.sidedistX = (mapX + 1.0 - ray.posX) * ray.deltadistX; } - //Check if ray has hit a wall - if(worldMap[mapX][mapY] == 1) - hit = 1; - } - if(side == 0) - ray.perpwalldist = (ray.sidedistX - ray.deltadistX); - else - ray.perpwalldist = (ray.sidedistY - ray.deltadistY); - //Calculate height of line to draw on screen - int lineHeight = (int)(height / ray.perpwalldist); - lineHeight = (int)(height / ray.perpwalldist); + if (ray.raydirY < 0) + { + ray.stepY = -1; + ray.sidedistY = (ray.posY - mapY) * ray.deltadistY; + } + else + { + ray.stepY = 1; + ray.sidedistY = (mapY + 1.0 - ray.posY) * ray.deltadistY; + } + while(hit == 0) + { + //jump to next map square, either in x-direction, or in y-direction + if(ray.sidedistX < ray.sidedistY) + { + ray.sidedistX += ray.deltadistX; + mapX += ray.stepX; + side = 0; + } + else + { + ray.sidedistY += ray.deltadistY; + mapY += ray.stepY; + side = 1; + } + //Check if ray has hit a wall + if(worldMap[mapX][mapY] == 1) + hit = 1; + } + if(side == 0) + ray.perpwalldist = (ray.sidedistX - ray.deltadistX); + else + ray.perpwalldist = (ray.sidedistY - ray.deltadistY); + //Calculate height of line to draw on screen + int lineHeight = (int)(height / ray.perpwalldist); + lineHeight = (int)(height / ray.perpwalldist); - //calculate lowest and highest pixel to fill in current stripe - int drawStart; - drawStart = -lineHeight / 2 + height / 2; - if(drawStart < 0) - drawStart = 0; - int drawEnd; - if(drawEnd >= height) - drawEnd = height - 1; + //calculate lowest and highest pixel to fill in current stripe + int drawStart; + drawStart = -lineHeight / 2 + height / 2; + if(drawStart < 0) + drawStart = 0; + int drawEnd; + if(drawEnd >= height) + drawEnd = height - 1; + /*mlx fontction color + + give x and y sides different brightness + if (side == 1) {color = color / 2;} + + //draw the pixels of the stripe as a vertical line + verLine(x, drawStart, drawEnd, color); */ + + + //timing for input to dissociate speed from speed processor (same speed on all pc) + ray.oldtime = ray.currtime; + ray.currtime = getTicks(); + // put image to window + // destroy old image + + + // hook event + + readKeys(); + //move forward if no wall in front of you + if (keyDown(move_up)) + { + if(worldMap[(ray.posX + ray.dirX * ray.movespeed)][(int)(ray.posY)] == 0) + ray.posX += ray.dirX * ray.movespeed; + if(worldMap[(ray.posX)][((int)ray.posY + (int)ray.dirY * (int)ray.movespeed)] == 0) + ray.posY += ray.dirY * ray.movespeed; + } + //move backwards if no wall behind you + if (keyDown(moove_down)) + { + if(worldMap[(ray.posX - ray.dirX * ray.movespeed)][(int)(ray.posY)] == 0) + ray.posX -= ray.dirX * ray.movespeed; + if(worldMap[(ray.posX)][((int)ray.posY - (int)ray.dirY * (int)ray.movespeed)] == 0) + ray.posY -= ray.dirY * ray.movespeed; + } + //rotate to the right + if (keyDown(moove_right)) + { + //both camera direction and camera plane must be rotated + ray.oldDirX = ray.dirX; + ray.dirX = ray.dirX * cos(-ray.rotspeed) - ray.dirY * sin(-ray.rotspeed); + ray.dirY = ray.oldDirX * sin(-ray.rotspeed) + ray.dirY * cos(-ray.rotspeed); + ray.oldPlaneX = ray.planeX; + ray.planeX = ray.planeX * cos(-ray.rotspeed) - ray.planeY * sin(-ray.rotspeed); + ray.planeY = ray.oldPlaneX * sin(-ray.rotspeed) + ray.planeY * cos(-ray.rotspeed); + } + //rotate to the left + if (keyDown(moove_left)) + { + //both camera direction and camera plane must be rotated + ray.oldDirX = ray.dirX; + ray.dirX = ray.dirX * cos(ray.rotspeed) - ray.dirY * sin(ray.rotspeed); + ray.dirY = ray.oldDirX * sin(ray.rotspeed) + ray.dirY * cos(ray.rotspeed); + ray.oldPlaneX = ray.planeX; + ray.planeX = ray.planeX * cos(ray.rotspeed) - ray.planeY * sin(ray.rotspeed); + ray.planeY = ray.oldPlaneX * sin(ray.rotspeed) + ray.planeY * cos(ray.rotspeed); + } } return (0); diff --git a/algo.h b/algo.h index 8f89eeb..acb137f 100644 --- a/algo.h +++ b/algo.h @@ -6,7 +6,7 @@ /* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/03 17:26:27 by greg ### ########.fr */ +/* Updated: 2024/10/03 18:59:43 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,10 +27,6 @@ typedef struct s_ray // orientation cam on map double planeX; double planeY; - // current frame - double currtime; - // last frame - double oldtime; // camera pos double cameraX; // direction rayon @@ -47,7 +43,10 @@ typedef struct s_ray // step direction (can be -1 or +1) int stepX; int stepY; - //wall hit? + double movespeed; + double rotspeed; + double oldDirX; + double oldPlaneX; } t_ray; #endif From 5bad24dcee2c32bcb22ca76b5560903aeb54a6d0 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Fri, 4 Oct 2024 15:32:12 +0200 Subject: [PATCH 06/80] add map parsing and other things --- .gitignore | 1 + .vscode/c_cpp_properties.json | 17 +++++ .vscode/settings.json | 5 ++ Makefile | 14 ++-- dev/cub.vim | 21 ++++++ include/color.h | 30 +++++++++ include/map.h | 56 ++++++++++++++-- include/map_mapping.h | 31 +++++++++ include/read_all_text.h | 29 +++++++++ include/stream.h | 54 ++++++++++++++++ include/util.h | 24 +++++++ src/color.c | 18 ++++++ src/main.c | 34 ++++++++++ src/map.c | 55 ++++++++++++++++ src/map_mapping.c | 24 +++++++ src/map_utils.h | 80 +++++++++++++++++++++++ src/map_utils1.c | 116 ++++++++++++++++++++++++++++++++++ src/map_utils2.c | 105 ++++++++++++++++++++++++++++++ src/read_all_text.c | 94 +++++++++++++++++++++++++++ src/stream.c | 89 ++++++++++++++++++++++++++ src/util.c | 38 +++++++++++ testmaps/hdhd.cub | 19 ++++++ testmaps/idid.cub | 15 +++++ testmaps/jdjd.cub | 20 ++++++ 24 files changed, 974 insertions(+), 15 deletions(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/settings.json create mode 100644 dev/cub.vim create mode 100644 include/color.h create mode 100644 include/map_mapping.h create mode 100644 include/read_all_text.h create mode 100644 include/stream.h create mode 100644 include/util.h create mode 100644 src/color.c create mode 100644 src/main.c create mode 100644 src/map.c create mode 100644 src/map_mapping.c create mode 100644 src/map_utils.h create mode 100644 src/map_utils1.c create mode 100644 src/map_utils2.c create mode 100644 src/read_all_text.c create mode 100644 src/stream.c create mode 100644 src/util.c create mode 100644 testmaps/hdhd.cub create mode 100644 testmaps/idid.cub create mode 100644 testmaps/jdjd.cub diff --git a/.gitignore b/.gitignore index c6127b3..f36f0f7 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ *.i*86 *.x86_64 *.hex +/cub3D # Debug files *.dSYM/ diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..4f3a506 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,17 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "compilerPath": "/usr/bin/clang", + "cStandard": "c17", + "cppStandard": "c++14", + "intelliSenseMode": "linux-clang-x64", + "configurationProvider": "ms-vscode.makefile-tools" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6cb9523 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "util.h": "c" + } +} diff --git a/Makefile b/Makefile index 6f950dd..255c719 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ NAME = cub3D -CPP = gcc -Wall -Wextra -Werror $(FLAGS) -C_FILES = $(wildcard *.c) +CPP = gcc -Wall -Wextra -Werror -I include $(FLAGS) +C_FILES = $(wildcard **/*.c) O_FILES = $(patsubst %.c,%.o,$(C_FILES)) ECHO = echoo(){ \ @@ -33,14 +33,13 @@ $(NAME) : $(O_FILES) @$(ECHO) "\t\t \e[0;92m\(^o^)/ \e[0;102;30;1m $(NAME) made! \e[0;92m \(^o^)/\e[0m" @$(ECHO) -%.o : %.cpp +%.o : %.c @$(ECHO) @$(ECHO) "\e[30;47;1m $(NAME): making '$@'... \e[0m" $(CPP) $(FLAGS_1) -c $< -o $@ check_headers : @ERROR=0; \ - echo $(wildcard **/*.h); \ for HEADER in $(wildcard **/*.h); \ do \ echo "check header $$HEADER..."; \ @@ -51,13 +50,12 @@ check_headers : if [ $$? -ne 0 ]; \ then \ ERROR=1; \ - echo error \ - break; \ + echo " error \e[31m:(\e[0m"; \ fi; \ - echo "good :)"; \ + echo " good \e[32m:)\e[0m"; \ 2> /dev/null rm -- "__tmp_check_header.out" "__tmp_check_header.c"; \ done; \ 2> /dev/null rm __tmp_check_header.out __tmp_check_header.c; \ if [ $$ERROR -eq 0 ]; then true; else false; fi; -.PHONY : all clean fclean re check_headers \ No newline at end of file +.PHONY : all clean fclean re check_headers diff --git a/dev/cub.vim b/dev/cub.vim new file mode 100644 index 0000000..72ed989 --- /dev/null +++ b/dev/cub.vim @@ -0,0 +1,21 @@ +function! CubSyntax() +if expand('%:e') == 'cub' + +highlight cubParameter ctermfg=blue +syntax match cubParameter /^(NO|SO|WE|EA|F|C) .$/ + +highlight cubDefault ctermfg=white +syntax match cubDefault /./ + +highlight cub0 ctermfg=grey +syntax match cub0 /0/ + +highlight cub1 cterm=bold ctermfg=white +syntax match cub1 /1/ + +highlight cubP cterm=bold ctermfg=blue +syntax match cubP /[NSWE]/ + +endif +endfunction +autocmd BufReadPost * call CubSyntax() diff --git a/include/color.h b/include/color.h new file mode 100644 index 0000000..98c01fa --- /dev/null +++ b/include/color.h @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* color.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/01 16:25:50 by mcolonna #+# #+# */ +/* Updated: 2024/10/02 15:41:43 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef COLOR_H +# define COLOR_H + +# include + +// TODO Must the transparency be 0 or 255? +/// @brief Represents an TRGB color in 0xTTRRGGBB format. +typedef __u32 t_color; + +/// @brief Convert a color from each color value to a t_color. +/// +/// @param red Level of red from 0 to 255. +/// @param green Level of green from 0 to 255. +/// @param blue Level of blue from 0 to 255. +/// @return The result. +t_color color_from_rgb(int red, int green, int blue); + +#endif diff --git a/include/map.h b/include/map.h index 67e379e..2224a3c 100644 --- a/include/map.h +++ b/include/map.h @@ -6,13 +6,16 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */ -/* Updated: 2024/10/01 14:00:40 by mcolonna ### ########.fr */ +/* Updated: 2024/10/04 13:13:04 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef MAP_H # define MAP_H +# include +# include "color.h" + /// @brief The type of a case. typedef enum e_map_wall { @@ -26,14 +29,20 @@ typedef enum e_map_wall typedef struct s_object { /// @brief Function called when creating the object. + /// /// @param data Address of the s_object.data pointer. void (*init)(void **data); - /// @brief Function called when destroying the object (to free everything). + + /// @brief Function called when destroying the object (to avoid leaks). + /// /// @param data Address of the s_object.data pointer. void (*destroy)(void **data); + /// @brief Function called each tick. + /// /// @param data Address of the s_object.data pointer. void (*tick)(void **data); + /// @brief Pointer the object can use to save data. void *data; } t_object; @@ -43,6 +52,7 @@ typedef struct s_map_case { /// @brief Is the case empty or a wall? t_map_wall wall; + /// @brief The object that appears on this case. If there is none, /// every pointer of the struct will be NULL. t_object object; @@ -51,14 +61,46 @@ typedef struct s_map_case /// @brief Represents a map. typedef struct s_map { + /// @brief Color of the floor. + t_color color_floor; + + /// @brief Color of the ceiling. + t_color color_ceiling; + + /// @brief Path to the image file for the wall face north. + const char *texture_north; + + /// @brief Path to the image file for the wall face south. + const char *texture_south; + + /// @brief Path to the image file for the wall face west. + const char *texture_west; + + /// @brief Path to the image file for the wall face east. + const char *texture_east; + /// @brief Width of the map. - int width; + unsigned int width; + /// @brief Height of the map. - int height; + unsigned int height; + /// @brief An 2D array of all the cases. - /// Syntax to get a case: cases[y][x] + /// + /// Syntax to get a case: cases[y * width + x] /// x is left to right, y is top to bottom. - t_map_case **cases; + t_map_case *cases; } t_map; -#endif \ No newline at end of file +/// @brief Create a t_map from the content of a .cub file. +/// +/// @param dest Pointer to the t_map to set. +/// @param file .cub file to use to create the t_map. +/// It must be destroyed with mapDestroy to avoid leaks. +/// @return false if an error occured, otherwise true. +bool map_from_file(t_map *dest, const char *file); + +/// @brief Destroy the map to avoid leaks. +void map_destroy(t_map *map); + +#endif diff --git a/include/map_mapping.h b/include/map_mapping.h new file mode 100644 index 0000000..5a3b2c9 --- /dev/null +++ b/include/map_mapping.h @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* map_mapping.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/04 12:00:07 by mcolonna #+# #+# */ +/* Updated: 2024/10/04 15:24:14 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MAP_MAPPING_H +# define MAP_MAPPING_H + +# include "map.h" + +/// @brief Each element of g_map_mapping. A case and its associated char. +typedef struct s_map_mapping_element +{ + /// @brief char representing the case. + char name; + /// @brief associated case. + t_map_case value; +} t_map_mapping_element; + +/// @brief List of each char and its according case. +/// Ended by an element with the name '\0'. +extern const t_map_mapping_element g_map_mapping[]; + +#endif diff --git a/include/read_all_text.h b/include/read_all_text.h new file mode 100644 index 0000000..f86eec9 --- /dev/null +++ b/include/read_all_text.h @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* read_all_text.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/02 15:39:02 by mcolonna #+# #+# */ +/* Updated: 2024/10/02 17:04:33 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef READ_ALL_TEXT_H +# define READ_ALL_TEXT_H + +/// @brief Size of buffer used in read_all_text(). +# define BUFFER_SIZE 1000 + +/// @brief Read all the text of the given file. +/// +/// If the last line isn't ended by a '\\n', add one. +/// +/// If error, returns NULL and set errno accordingly. +/// +/// @param fd File descriptor of the file. +/// @return Alloc'd string of the file content. NULL if error. +char *read_all_text(int fd); + +#endif diff --git a/include/stream.h b/include/stream.h new file mode 100644 index 0000000..12232ac --- /dev/null +++ b/include/stream.h @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* stream.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/02 12:33:25 by mcolonna #+# #+# */ +/* Updated: 2024/10/02 16:14:23 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef STREAM_H +# define STREAM_H + +# include + +/// @brief Represents a string and an associated cursor. +typedef struct s_stream +{ + /// @brief Index of the cursor. + int i; + + /// @brief Pointer to the string. + const char *str; +} t_stream; + +/// @brief Read a specific string, error if it isn't the expected string. +/// +/// @param str Expected string. +/// @param stream Stream to use. +/// @param err Set to true if an error occured. +/// If already true, the function won't do anything. +void read_expected_string(const char *str, t_stream *stream, bool *err); + +/// @brief Read an unsigned int (which fits the pattern /[0-9]+/). +/// +/// @param dest Will be set to the value of the unsigned integer. +/// @param stream Stream to use. +/// @param err Set to true if an error occured. +/// If already true, the function won't do anything. +void read_unsigned(unsigned int *dest, t_stream *stream, bool *err); + +/// @brief Read a string until limit char or \0. +/// +/// @param c Limit char. +/// @param dest Will be set to an alloc'd pointer to the read string. +/// NULL if alloc error. +/// @param stream Stream to use. +/// @param err Set to true if an error occured. +/// If already true, the function won't do anything. +void read_until(char c, char **dest, t_stream *stream, bool *err); + +#endif diff --git a/include/util.h b/include/util.h new file mode 100644 index 0000000..bab8592 --- /dev/null +++ b/include/util.h @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* util.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/03 14:19:03 by mc #+# #+# */ +/* Updated: 2024/10/04 15:27:07 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef UTIL_H +# define UTIL_H + +/// @brief Get the length of a string. +int getlen(const char *str); + +/// @brief Write an error message on stderr. +/// +/// @param str... All the strings to write. The last parameter MUST BE NULL. +void write_err(const char *str, ...); + +#endif diff --git a/src/color.c b/src/color.c new file mode 100644 index 0000000..c0af271 --- /dev/null +++ b/src/color.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* color.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/01 17:04:56 by mcolonna #+# #+# */ +/* Updated: 2024/10/02 14:27:53 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "color.h" + +t_color color_from_rgb(int red, int green, int blue) +{ + return (red << 16 | green << 8 | blue); +} diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..115ee5a --- /dev/null +++ b/src/main.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/02 15:45:49 by mcolonna #+# #+# */ +/* Updated: 2024/10/04 15:10:50 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "map.h" +#include + +int main(int argc, char *argv[]) +{ + t_map map; + bool success; + + if (argc != 2) + { + printf(":(\n"); + return (1); + } + success = map_from_file(&map, argv[1]); + printf("--> Success: %i <--\n", success); + if (success) + printf("C 0x%08x\nF 0x%08x\nEA %s\nWE %s\nNO %s\nSO %s\n", + map.color_ceiling, map.color_floor, + map.texture_east, map.texture_west, + map.texture_north, map.texture_south); + map_destroy(&map); +} diff --git a/src/map.c b/src/map.c new file mode 100644 index 0000000..475b024 --- /dev/null +++ b/src/map.c @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* map.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/01 17:12:58 by mcolonna #+# #+# */ +/* Updated: 2024/10/04 15:25:32 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "map.h" +#include "map_utils.h" +#include "stream.h" +#include "read_all_text.h" +#include +#include +#include +#include +#include + +bool map_from_file(t_map *dest, const char *file) +{ + int fd; + t_stream stream; + bool err; + + fd = open(file, O_RDONLY); + if (fd < 0) + { + write_err("Can't open '", file, "': ", strerror(errno), "\n", + NULL); + return (false); + } + stream.str = read_all_text(fd); + if (!stream.str) + { + write_err("Can't read file.\n", NULL); + return (false); + } + stream.i = 0; + err = read_map(dest, &stream); + free((void *)stream.str); + return (err); +} + +void map_destroy(t_map *map) +{ + free((void *)map->texture_east); + free((void *)map->texture_west); + free((void *)map->texture_north); + free((void *)map->texture_south); + free(map->cases); +} diff --git a/src/map_mapping.c b/src/map_mapping.c new file mode 100644 index 0000000..e4b575f --- /dev/null +++ b/src/map_mapping.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* map_mapping.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/04 12:05:21 by mcolonna #+# #+# */ +/* Updated: 2024/10/04 15:23:28 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "map_mapping.h" +#include + +const t_map_mapping_element g_map_mapping[] = { +{' ', {EMPTY, {NULL, NULL, NULL, NULL}}}, +{'0', {EMPTY, {NULL, NULL, NULL, NULL}}}, +{'1', {WALL, {NULL, NULL, NULL, NULL}}}, +{'N', {EMPTY, {NULL, NULL, NULL, NULL}}}, // TODO add player object +{'S', {EMPTY, {NULL, NULL, NULL, NULL}}}, // -- +{'E', {EMPTY, {NULL, NULL, NULL, NULL}}}, // -- +{'W', {EMPTY, {NULL, NULL, NULL, NULL}}}, // -- +{'\0', {EMPTY, {NULL, NULL, NULL, NULL}}}}; diff --git a/src/map_utils.h b/src/map_utils.h new file mode 100644 index 0000000..6c0a693 --- /dev/null +++ b/src/map_utils.h @@ -0,0 +1,80 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* map_utils.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/03 15:05:13 by mc #+# #+# */ +/* Updated: 2024/10/04 15:30:03 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MAP_UTILS_H +# define MAP_UTILS_H + +# include "color.h" +# include "stream.h" +# include "map.h" +# include +# include + +/// @brief Read a parameter of the map which has a color as an argument. +/// Color format: [0-255],[0-255],[0-255] +/// @param name Name of the parameter. +/// @param dest Will be set to the value of the parameter. +/// Unchanged if error. +/// If success but *dest is not 0xFF000000, throws an error. +/// @param stream Stream to use. +/// Unchanged if error. +/// @param redefined Set to true if the parameter was already defined. +/// @return true if success or redefined, false if non-fatal error. +bool read_color_parameter(const char *name, t_color *dest, + t_stream *stream, bool *redefined); + +/// @brief Read a parameter of the map which has a string as an argument. +/// @param name Name of the parameter. +/// @param dest Will be set to an alloc'd pointer to the value of the parameter. +/// Unchanged if error. +/// If success but *dest is not null, throws an error. +/// @param stream Stream to use. +/// Unchanged if error. +/// @param redefined Set to true if the parameter was already defined. +/// @return true if success or redefined, false if non-fatal error. +bool read_string_parameter(const char *name, const char **dest, + t_stream *stream, bool *redefined); + +/// @brief Set the map to initial values. Every texture becomes NULL +/// and every color becomes 0xFF000000. +/// @param dest Map to reset. +void reset_map(t_map *dest); + +/// @brief Read a map-formatted string. +/// If an error occurs, write an error message on stderr. +/// @param dest Will be set to the map. +/// @param stream Stream to use. +/// @return true if success, false if error. +bool read_map(t_map *dest, t_stream *stream); + +/// @brief Get the case associated with the char. +/// +/// @param dest Will be set to the char. +/// @param name Name of the case. +/// @return true if success, false if error. +bool get_case(t_map_case *dest, char name); + +/// @brief Fill the pointer with 'size' null bytes. +/// +/// @param dest The pointer to set. +/// @param size The number of bytes. +void fill_zeros(void *dest, size_t size); + +/// @brief Read the map description part of the map. +/// Read until the end of the file. +/// +/// @param map The .width, .height and .cases members will be set. +/// @param stream Stream to use. +/// @return true if success, false if error. +bool read_map_description(t_map *map, t_stream *stream); + +#endif diff --git a/src/map_utils1.c b/src/map_utils1.c new file mode 100644 index 0000000..6377db0 --- /dev/null +++ b/src/map_utils1.c @@ -0,0 +1,116 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* map_utils1.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/03 15:02:09 by mc #+# #+# */ +/* Updated: 2024/10/04 15:28:06 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "map_utils.h" +#include "util.h" +#include "map_mapping.h" +#include + +bool read_color_parameter(const char *name, t_color *dest, + t_stream *stream, bool *redefined) +{ + unsigned int rgb[3]; + bool err; + t_stream old; + + old = *stream; + err = false; + read_expected_string(name, stream, &err); + read_expected_string(" ", stream, &err); + read_unsigned(&rgb[0], stream, &err); + read_expected_string(",", stream, &err); + read_unsigned(&rgb[1], stream, &err); + read_expected_string(",", stream, &err); + read_unsigned(&rgb[2], stream, &err); + read_expected_string("\n", stream, &err); + if (!err && *dest != 0xFF000000) + { + *redefined = true; + write_err("Parameter '", name, "' was defined several times\n", + NULL); + } + else if (!err) + *dest = color_from_rgb(rgb[0], rgb[1], rgb[2]); + else + *stream = old; + return (!err); +} + +bool read_string_parameter(const char *name, const char **dest, + t_stream *stream, bool *redefined) +{ + char *r; + bool err; + t_stream old; + + old = *stream; + err = false; + r = NULL; + read_expected_string(name, stream, &err); + read_expected_string(" ", stream, &err); + read_until('\n', &r, stream, &err); + read_expected_string("\n", stream, &err); + if (!err && *dest) + { + *redefined = true; + write_err("Parameter '", name, "' was defined several times\n", + NULL); + } + if (err || (!err && *dest)) + { + *stream = old; + free(r); + } + else + *dest = r; + return (!err); +} + +void reset_map(t_map *dest) +{ + dest->cases = NULL; + dest->color_ceiling = 0xFF000000; + dest->color_floor = 0xFF000000; + dest->texture_east = NULL; + dest->texture_west = NULL; + dest->texture_north = NULL; + dest->texture_south = NULL; +} + +bool read_map(t_map *dest, t_stream *stream) +{ + bool err; + bool rdf; + + reset_map(dest); + err = false; + rdf = false; + while (!rdf && !err && stream->str[stream->i]) + { + if (true + && (read_expected_string("\n", stream, &err), err) + && !read_string_parameter("NO", &dest->texture_north, stream, &rdf) + && !read_string_parameter("SO", &dest->texture_south, stream, &rdf) + && !read_string_parameter("WE", &dest->texture_west, stream, &rdf) + && !read_string_parameter("EA", &dest->texture_east, stream, &rdf) + && !read_color_parameter("F", &dest->color_floor, stream, &rdf) + && !read_color_parameter("C", &dest->color_ceiling, stream, &rdf)) + { + err = !read_map_description(dest, stream); + return (!err); + } + err = false; + } + if (!rdf && !dest->cases) + write_err("Map description missing\n", NULL); + return (!err && !rdf && dest->cases); +} diff --git a/src/map_utils2.c b/src/map_utils2.c new file mode 100644 index 0000000..7c762c2 --- /dev/null +++ b/src/map_utils2.c @@ -0,0 +1,105 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* map_utils2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/04 15:12:08 by mcolonna #+# #+# */ +/* Updated: 2024/10/04 15:25:52 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "map_utils.h" +#include "map_mapping.h" +#include "util.h" +#include + +/// @brief Read the map description to get the dimensions. +/// The map must be at least 1x1. +/// +/// @param map The .width and .height members will be set. +/// @param stream Stream to use. +/// @return true if success, false if error. +static bool get_map_dimensions(t_map *map, t_stream *stream) +{ + unsigned int x; + unsigned int y; + + map->width = 0; + map->height = 0; + y = 0; + while (stream->str[stream->i]) + { + x = 0; + while (stream->str[stream->i] && stream->str[stream->i] != '\n') + { + stream->i++; + x++; + } + if (x > map->width) + map->width = x; + if (stream->str[stream->i] == '\n') + stream->i++; + y++; + } + map->height = y; + return (map->width > 0 && map->height > 0); +} + +bool get_case(t_map_case *dest, char name) +{ + int i; + char tmp[2]; + + i = -1; + while (g_map_mapping[++i].name) + { + if (name == g_map_mapping[i].name) + { + *dest = g_map_mapping[i].value; + return (true); + } + } + tmp[0] = name; + tmp[1] = '\0'; + write_err("Character '", tmp, "' unexpected\n", NULL); + return (false); +} + +void fill_zeros(void *dest, size_t size) +{ + size_t i; + + i = -1; + while (++i < size) + ((char *)dest)[i] = '\0'; +} + +bool read_map_description(t_map *map, t_stream *stream) +{ + t_stream stream2; + unsigned int x; + unsigned int y; + + stream2 = *stream; + if (!get_map_dimensions(map, &stream2)) + return (false); + map->cases = malloc((map->width * map->height) * sizeof(t_map_case)); + y = -1; + fill_zeros(map->cases, (map->width * map->height) * sizeof(t_map_case)); + while (++y < map->height) + { + x = 0; + while (stream->str[stream->i] && stream->str[stream->i] != '\n') + { + if (!get_case(&map->cases[y * map->width + x], + stream->str[stream->i])) + return (false); + stream->i++; + x++; + } + stream->i++; + } + return (true); +} diff --git a/src/read_all_text.c b/src/read_all_text.c new file mode 100644 index 0000000..490efc3 --- /dev/null +++ b/src/read_all_text.c @@ -0,0 +1,94 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* read_all_text.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/02 16:18:35 by mcolonna #+# #+# */ +/* Updated: 2024/10/03 14:20:37 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "read_all_text.h" +#include "util.h" +#include +#include +#include + +/// @brief Concatenate *dest and src and put the result in *dest. +/// +/// *dest is alloc'd to contain the result value. +/// +/// the old *dest is freed only if the function succeds. +/// +/// src doesn't have to be nul-terminated, instead n is the size of src. +/// +/// @return true if success, false if error. +static bool strconcat(char **dest, char *src, int n) +{ + const int len_dest = getlen(*dest); + char *old_dest; + int i; + + old_dest = *dest; + *dest = malloc((len_dest + n + 1) * sizeof(char)); + if (!*dest) + return (false); + i = -1; + while (old_dest[++i]) + (*dest)[i] = old_dest[i]; + while (i < len_dest + n) + { + (*dest)[i] = src[i - len_dest]; + i++; + } + (*dest)[i] = '\0'; + free(old_dest); + return (true); +} + +/// @brief If the string isn't empty and isn't ended by a '\\n', add one and +/// return the result. +/// +/// str is either returned directly, or another freeable pointer is returned +/// and str is freed. +/// +/// @return Return the result or NULL if error. +static char *add_endline_if_necessary(char *str) +{ + char *endline; + + if (str[0] == '\0' || str[getlen(str) - 1] == '\n') + return (str); + endline = malloc(1 * sizeof(char)); + if (!endline) + return (free(str), NULL); + endline[0] = '\n'; + if (!strconcat(&str, endline, 1)) + return (free(str), NULL); + return (str); +} + +char *read_all_text(int fd) +{ + char buf[BUFFER_SIZE]; + int n; + char *r; + + r = malloc(sizeof(char)); + if (!r) + return (NULL); + r[0] = '\0'; + n = 1; + while (n) + { + n = read(fd, buf, BUFFER_SIZE); + if (n < 0 || (n && !strconcat(&r, buf, n))) + { + free(r); + return (NULL); + } + } + return (add_endline_if_necessary(r)); +} diff --git a/src/stream.c b/src/stream.c new file mode 100644 index 0000000..107c464 --- /dev/null +++ b/src/stream.c @@ -0,0 +1,89 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* stream.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/02 14:08:10 by mcolonna #+# #+# */ +/* Updated: 2024/10/02 17:31:34 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "stream.h" +#include + +void read_expected_string(const char *str, t_stream *stream, bool *err) +{ + int i; + + if (*err) + return ; + i = 0; + while (str[i]) + { + if (str[i] != stream->str[stream->i]) + { + *err = true; + return ; + } + i++; + stream->i++; + } + return ; +} + +/// @brief Check if a character is a digit. +/// @param c Character to check. +/// @return true if the character is a digit, false if not. +/// false if the character is '\0'. +static bool is_digit(char c) +{ + return (c >= '0' && c <= '9'); +} + +void read_unsigned(unsigned int *dest, t_stream *stream, bool *err) +{ + int r; + + if (*err) + return ; + if (!is_digit(stream->str[stream->i])) + { + *err = true; + return ; + } + r = 0; + while (is_digit(stream->str[stream->i])) + { + r = r * 10 + stream->str[stream->i] - '0'; + stream->i++; + } + *dest = r; +} + +void read_until(char c, char **dest, t_stream *stream, bool *err) +{ + int len; + int i; + + if (*err) + return ; + len = 0; + while (stream->str[stream->i + len] && stream->str[stream->i + len] != c) + len++; + *dest = malloc((len + 1) * sizeof(char)); + if (!*dest) + { + *err = true; + return ; + } + i = 0; + while (stream->str[stream->i] && stream->str[stream->i] != c) + { + (*dest)[i] = stream->str[stream->i]; + i++; + stream->i++; + } + (*dest)[i] = '\0'; +} diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..a18b2c5 --- /dev/null +++ b/src/util.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* util.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/03 14:19:38 by mc #+# #+# */ +/* Updated: 2024/10/04 15:26:32 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "util.h" +#include +#include + +int getlen(const char *str) +{ + int i; + + i = 0; + while (str[i]) + i++; + return (i); +} + +void write_err(const char *str, ...) +{ + va_list args; + + va_start(args, str); + write(2, "Error\n", 6); + while (str) + { + write(2, str, getlen(str)); + str = va_arg(args, const char *); + } +} diff --git a/testmaps/hdhd.cub b/testmaps/hdhd.cub new file mode 100644 index 0000000..df272c6 --- /dev/null +++ b/testmaps/hdhd.cub @@ -0,0 +1,19 @@ + + +F 255,127,0 + +EA eastimage + + + +NO theimageforthenorthwall +C 0,2,67 + +SO SOUTH!!!!!!1 +SO jde: + +WE weeeee + + + +SO south2 diff --git a/testmaps/idid.cub b/testmaps/idid.cub new file mode 100644 index 0000000..0eb3904 --- /dev/null +++ b/testmaps/idid.cub @@ -0,0 +1,15 @@ +F 255,127,0 + +EA eastimage + +NO theimageforthenorthwall +C 0,2,67 + +SO SOUTH!!!!!!1 + +WE weeeee + + + + + diff --git a/testmaps/jdjd.cub b/testmaps/jdjd.cub new file mode 100644 index 0000000..cf473b2 --- /dev/null +++ b/testmaps/jdjd.cub @@ -0,0 +1,20 @@ +F 255,127,0 + +EA eastimage + +NO theimageforthenorthwall +C 0,2,67 + +SO SOUTH!!!!!!1 + +WE weeeee + + + + + +1111111 +1000001 +10W0001 +1000001 +1111111 From 5fd959eeb88c9ea08eccdfe5404626b081bced8d Mon Sep 17 00:00:00 2001 From: ReverseSky Date: Wed, 9 Oct 2024 03:35:09 +0200 Subject: [PATCH 07/80] problemes affichage --- Libft/Makefile | 30 +++++++ Libft/ft_atoi.c | 34 ++++++++ Libft/ft_bzero.c | 26 ++++++ Libft/ft_calloc.c | 29 +++++++ Libft/ft_hexa.c | 64 +++++++++++++++ Libft/ft_isalnum.c | 19 +++++ Libft/ft_isalpha.c | 19 +++++ Libft/ft_isascii.c | 19 +++++ Libft/ft_isdigit.c | 19 +++++ Libft/ft_isprint.c | 19 +++++ Libft/ft_itoa.c | 62 +++++++++++++++ Libft/ft_lstadd_back.c | 30 +++++++ Libft/ft_lstadd_front.c | 18 +++++ Libft/ft_lstclear.c | 30 +++++++ Libft/ft_lstdelone.c | 22 ++++++ Libft/ft_lstiter.c | 27 +++++++ Libft/ft_lstlast.c | 21 +++++ Libft/ft_lstmap.c | 41 ++++++++++ Libft/ft_lstnew.c | 24 ++++++ Libft/ft_lstsize.c | 25 ++++++ Libft/ft_memchr.c | 26 ++++++ Libft/ft_memcmp.c | 26 ++++++ Libft/ft_memcpy.c | 28 +++++++ Libft/ft_memmove.c | 39 +++++++++ Libft/ft_memset.c | 26 ++++++ Libft/ft_printf.c | 63 +++++++++++++++ Libft/ft_put.c | 75 ++++++++++++++++++ Libft/ft_putchar_fd.c | 17 ++++ Libft/ft_putendl_fd.c | 27 +++++++ Libft/ft_putnbr_fd.c | 33 ++++++++ Libft/ft_putstr_fd.c | 26 ++++++ Libft/ft_split.c | 78 ++++++++++++++++++ Libft/ft_strchr.c | 28 +++++++ Libft/ft_strdup.c | 25 ++++++ Libft/ft_striteri.c | 26 ++++++ Libft/ft_strjoin.c | 41 ++++++++++ Libft/ft_strlcat.c | 37 +++++++++ Libft/ft_strlcpy.c | 28 +++++++ Libft/ft_strlen.c | 24 ++++++ Libft/ft_strmapi.c | 33 ++++++++ Libft/ft_strncmp.c | 26 ++++++ Libft/ft_strnstr.c | 38 +++++++++ Libft/ft_strrchr.c | 28 +++++++ Libft/ft_strtrim.c | 40 ++++++++++ Libft/ft_substr.c | 39 +++++++++ Libft/ft_tolower.c | 19 +++++ Libft/ft_toupper.c | 19 +++++ Libft/get_next_line.c | 110 ++++++++++++++++++++++++++ Libft/get_next_line_utils.c | 53 +++++++++++++ Libft/libft.h | 89 +++++++++++++++++++++ Makefile | 8 +- Minilibx | 1 + algo.c | 152 ++++++++++++++++++++++-------------- algo.h | 6 +- 54 files changed, 1849 insertions(+), 63 deletions(-) create mode 100644 Libft/Makefile create mode 100644 Libft/ft_atoi.c create mode 100644 Libft/ft_bzero.c create mode 100644 Libft/ft_calloc.c create mode 100644 Libft/ft_hexa.c create mode 100644 Libft/ft_isalnum.c create mode 100644 Libft/ft_isalpha.c create mode 100644 Libft/ft_isascii.c create mode 100644 Libft/ft_isdigit.c create mode 100644 Libft/ft_isprint.c create mode 100644 Libft/ft_itoa.c create mode 100644 Libft/ft_lstadd_back.c create mode 100644 Libft/ft_lstadd_front.c create mode 100644 Libft/ft_lstclear.c create mode 100644 Libft/ft_lstdelone.c create mode 100644 Libft/ft_lstiter.c create mode 100644 Libft/ft_lstlast.c create mode 100644 Libft/ft_lstmap.c create mode 100644 Libft/ft_lstnew.c create mode 100644 Libft/ft_lstsize.c create mode 100644 Libft/ft_memchr.c create mode 100644 Libft/ft_memcmp.c create mode 100644 Libft/ft_memcpy.c create mode 100644 Libft/ft_memmove.c create mode 100644 Libft/ft_memset.c create mode 100644 Libft/ft_printf.c create mode 100644 Libft/ft_put.c create mode 100644 Libft/ft_putchar_fd.c create mode 100644 Libft/ft_putendl_fd.c create mode 100644 Libft/ft_putnbr_fd.c create mode 100644 Libft/ft_putstr_fd.c create mode 100644 Libft/ft_split.c create mode 100644 Libft/ft_strchr.c create mode 100644 Libft/ft_strdup.c create mode 100644 Libft/ft_striteri.c create mode 100644 Libft/ft_strjoin.c create mode 100644 Libft/ft_strlcat.c create mode 100644 Libft/ft_strlcpy.c create mode 100644 Libft/ft_strlen.c create mode 100644 Libft/ft_strmapi.c create mode 100644 Libft/ft_strncmp.c create mode 100644 Libft/ft_strnstr.c create mode 100644 Libft/ft_strrchr.c create mode 100644 Libft/ft_strtrim.c create mode 100644 Libft/ft_substr.c create mode 100644 Libft/ft_tolower.c create mode 100644 Libft/ft_toupper.c create mode 100644 Libft/get_next_line.c create mode 100644 Libft/get_next_line_utils.c create mode 100644 Libft/libft.h create mode 160000 Minilibx diff --git a/Libft/Makefile b/Libft/Makefile new file mode 100644 index 0000000..fa0de42 --- /dev/null +++ b/Libft/Makefile @@ -0,0 +1,30 @@ +NAME = libft.a + +SRC = ft_atoi.c ft_bzero.c ft_calloc.c ft_isalnum.c ft_isalpha.c ft_isascii.c \ +ft_isdigit.c ft_isprint.c ft_memchr.c ft_memcmp.c ft_memcpy.c ft_memmove.c \ +ft_memset.c ft_strchr.c ft_strdup.c ft_strlcat.c ft_strlcpy.c ft_strlen.c \ +ft_strncmp.c ft_strrchr.c ft_tolower.c ft_toupper.c ft_strnstr.c ft_substr.c\ +ft_strjoin.c ft_strtrim.c ft_itoa.c ft_strmapi.c ft_striteri.c ft_putchar_fd.c\ +ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c ft_split.c 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_lstmap.c ft_hexa.c ft_printf.c\ +ft_put.c get_next_line.c get_next_line_utils.c + +OBJS = ${SRC:.c=.o} + +CC = gcc + +CFLAGS = -Wall -Werror -Wextra + +all: $(NAME) + +$(NAME): ${OBJS} + ar rc ${NAME} ${OBJS} + +clean : + rm -f ${OBJS} + +fclean : clean + rm -f $(NAME) + +re : fclean all diff --git a/Libft/ft_atoi.c b/Libft/ft_atoi.c new file mode 100644 index 0000000..8504ede --- /dev/null +++ b/Libft/ft_atoi.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/04 14:30:22 by grobledo #+# #+# */ +/* Updated: 2023/02/04 14:30:24 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_atoi(const char *str) +{ + int i; + int is_neg; + int number; + + i = 0; + is_neg = 1; + number = 0; + while ((str[i] >= 9 && str[i] <= 13) || str[i] == 32) + i++; + if (str[i] == '-' || str[i] == '+') + { + if (str[i] == '-') + is_neg *= -1; + i++; + } + while (str [i] >= '0' && str[i] <= '9') + number = (number * 10) + str[i++] - 48; + return (number * is_neg); +} diff --git a/Libft/ft_bzero.c b/Libft/ft_bzero.c new file mode 100644 index 0000000..b322d22 --- /dev/null +++ b/Libft/ft_bzero.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/08 14:32:10 by grobledo #+# #+# */ +/* Updated: 2023/02/08 14:32:22 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +void ft_bzero(void *s, size_t n) +{ + unsigned char *str; + size_t i; + + i = 0; + str = s; + while (i < n) + { + str[i] = 0; + i++; + } +} diff --git a/Libft/ft_calloc.c b/Libft/ft_calloc.c new file mode 100644 index 0000000..ca1c5d6 --- /dev/null +++ b/Libft/ft_calloc.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_calloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/08 19:35:13 by grobledo #+# #+# */ +/* Updated: 2023/02/08 19:35:23 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +void *ft_calloc(size_t count, size_t size) +{ + void *str; + size_t tmp; + + tmp = size * count; + if (size == 0 || count == 0) + return (malloc(0)); + if (tmp / count != size) + return (NULL); + str = malloc(size * count); + if (str == NULL) + return (NULL); + ft_bzero (str, size * count); + return (str); +} diff --git a/Libft/ft_hexa.c b/Libft/ft_hexa.c new file mode 100644 index 0000000..a439086 --- /dev/null +++ b/Libft/ft_hexa.c @@ -0,0 +1,64 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_hexa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/04 09:38:27 by grobledo #+# #+# */ +/* Updated: 2023/04/04 09:38:28 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_hexa(unsigned int args, char format, int count) +{ + char *base; + char *shiftbase; + + base = "0123456789abcdef"; + shiftbase = "0123456789ABCDEF"; + if (format == 'x') + { + if (args >= 16) + count = ft_hexa(args / 16, format, count); + count = ft_putcharf(base[args % 16], count); + return (count); + } + if (format == 'X') + { + if (args >= 16) + count = ft_hexa(args / 16, format, count); + count = ft_putcharf(shiftbase[args % 16], count); + return (count); + } + return (0); +} + +int ft_starthexa(unsigned int args, char format, int count) +{ + if (!args && (format == 'x' || format == 'X')) + return (ft_putcharf('0', count)); + count = ft_hexa(args, format, count); + return (count); +} + +int ft_startpointer(unsigned long long int args, char format, int count) +{ + if (!args) + return (ft_putstrf("(nil)", count)); + count = ft_putstrf("0x", count); + count = ft_pointer(args, format, count); + return (count); +} + +int ft_pointer(unsigned long long int args, char format, int count) +{ + char *base; + + base = "0123456789abcdef"; + if (args >= 16) + count = ft_pointer(args / 16, format, count); + count = ft_putcharf(base[args % 16], count); + return (count); +} diff --git a/Libft/ft_isalnum.c b/Libft/ft_isalnum.c new file mode 100644 index 0000000..f5a8ec6 --- /dev/null +++ b/Libft/ft_isalnum.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/02 18:17:39 by grobledo #+# #+# */ +/* Updated: 2023/02/02 18:17:41 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_isalnum(int c) +{ + if (ft_isalpha(c) || ft_isdigit(c)) + return (1); + return (0); +} diff --git a/Libft/ft_isalpha.c b/Libft/ft_isalpha.c new file mode 100644 index 0000000..351bf89 --- /dev/null +++ b/Libft/ft_isalpha.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/02 17:36:30 by grobledo #+# #+# */ +/* Updated: 2023/02/02 17:36:34 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_isalpha(int c) +{ + if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) + return (1); + return (0); +} diff --git a/Libft/ft_isascii.c b/Libft/ft_isascii.c new file mode 100644 index 0000000..f95ded8 --- /dev/null +++ b/Libft/ft_isascii.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/02 18:20:38 by grobledo #+# #+# */ +/* Updated: 2023/02/02 18:20:40 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_isascii(int c) +{ + if (c >= 0 && c <= 127) + return (1); + return (0); +} diff --git a/Libft/ft_isdigit.c b/Libft/ft_isdigit.c new file mode 100644 index 0000000..beb94d6 --- /dev/null +++ b/Libft/ft_isdigit.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/02 17:48:20 by grobledo #+# #+# */ +/* Updated: 2023/02/02 17:48:22 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_isdigit(int c) +{ + if (c >= '0' && c <= '9') + return (1); + return (0); +} diff --git a/Libft/ft_isprint.c b/Libft/ft_isprint.c new file mode 100644 index 0000000..acaa9b7 --- /dev/null +++ b/Libft/ft_isprint.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/02 18:27:24 by grobledo #+# #+# */ +/* Updated: 2023/02/02 18:27:25 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_isprint(int c) +{ + if (c >= 32 && c <= 126) + return (1); + return (0); +} diff --git a/Libft/ft_itoa.c b/Libft/ft_itoa.c new file mode 100644 index 0000000..3f1cdf6 --- /dev/null +++ b/Libft/ft_itoa.c @@ -0,0 +1,62 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/19 19:32:47 by grobledo #+# #+# */ +/* Updated: 2023/02/19 19:32:48 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int countsize(int nb) +{ + long int temp; + int size; + + size = 0; + temp = nb; + if (nb < 0) + { + temp = -nb; + size = size +1; + } + while (temp > 9) + { + temp = (temp / 10); + size++; + } + size++; + return (size); +} + +char *ft_itoa(int nb) +{ + long int temp; + char *res; + int size; + + if (nb == -2147483648) + return (ft_strdup("-2147483648")); + temp = nb; + size = countsize(nb); + res = ft_calloc(size + 1, sizeof (char)); + if (!res) + return (NULL); + if (nb < 0) + { + res[0] = '-'; + temp *= -1; + } + if (nb == 0) + res[0] = '0'; + while (temp > 0) + { + res[size - 1] = (temp % 10 + 48); + size--; + temp /= 10; + } + return (res); +} diff --git a/Libft/ft_lstadd_back.c b/Libft/ft_lstadd_back.c new file mode 100644 index 0000000..fd2389e --- /dev/null +++ b/Libft/ft_lstadd_back.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_back.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/23 11:38:44 by grobledo #+# #+# */ +/* Updated: 2023/02/23 11:38:46 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +void ft_lstadd_back(t_list **lst, t_list *new) +{ + t_list *temp; + + if (!new) + return ; + if (!*lst) + { + *lst = new; + return ; + } + else + { + temp = ft_lstlast(*lst); + temp->next = new; + } +} diff --git a/Libft/ft_lstadd_front.c b/Libft/ft_lstadd_front.c new file mode 100644 index 0000000..a24ae19 --- /dev/null +++ b/Libft/ft_lstadd_front.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_front.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/21 23:42:28 by grobledo #+# #+# */ +/* Updated: 2023/02/21 23:42:30 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +void ft_lstadd_front(t_list **lst, t_list *new) +{ + new->next = *lst; + *lst = new; +} diff --git a/Libft/ft_lstclear.c b/Libft/ft_lstclear.c new file mode 100644 index 0000000..3d8d38d --- /dev/null +++ b/Libft/ft_lstclear.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstclear.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/23 22:05:11 by grobledo #+# #+# */ +/* Updated: 2023/02/23 22:05:12 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +void ft_lstclear(t_list **lst, void (*del)(void*)) +{ + t_list *next; + t_list *current; + + if (lst == NULL || del == NULL || *lst == NULL) + return ; + current = *lst; + while (current != NULL) + { + next = current->next; + del(current->content); + free(current); + current = next; + } + *lst = NULL; +} diff --git a/Libft/ft_lstdelone.c b/Libft/ft_lstdelone.c new file mode 100644 index 0000000..da37e72 --- /dev/null +++ b/Libft/ft_lstdelone.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdelone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/23 20:15:05 by grobledo #+# #+# */ +/* Updated: 2023/02/23 20:15:06 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +void ft_lstdelone(t_list *lst, void (*del)(void*)) +{ + if (!lst) + return ; + if (!del) + return ; + del(lst->content); + free(lst); +} diff --git a/Libft/ft_lstiter.c b/Libft/ft_lstiter.c new file mode 100644 index 0000000..67041a2 --- /dev/null +++ b/Libft/ft_lstiter.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstiter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/23 22:42:44 by grobledo #+# #+# */ +/* Updated: 2023/02/23 22:42:45 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +void ft_lstiter(t_list *lst, void (*f)(void *)) +{ + t_list *node; + + node = lst; + if (lst == NULL || f == NULL) + return ; + node = lst; + while (node != NULL) + { + f(node->content); + node = node->next; + } +} diff --git a/Libft/ft_lstlast.c b/Libft/ft_lstlast.c new file mode 100644 index 0000000..9024c06 --- /dev/null +++ b/Libft/ft_lstlast.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstlast.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/23 10:27:02 by grobledo #+# #+# */ +/* Updated: 2023/02/23 10:27:07 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +t_list *ft_lstlast(t_list *lst) +{ + if (!lst) + return (NULL); + while (lst->next) + lst = lst->next; + return (lst); +} diff --git a/Libft/ft_lstmap.c b/Libft/ft_lstmap.c new file mode 100644 index 0000000..8329e15 --- /dev/null +++ b/Libft/ft_lstmap.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstmap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/24 11:59:12 by grobledo #+# #+# */ +/* Updated: 2023/02/24 11:59:13 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +t_list *ft_lstmap(t_list *lst, void *(f)(void *), void (*del)(void *)) +{ + t_list *new; + t_list *current; + + if (!lst || !f ||!del) + return (NULL); + new = ft_lstnew(NULL); + if (!new) + return (NULL); + current = new; + while (lst) + { + current->content = f(lst->content); + if (lst->next) + { + current->next = ft_lstnew(NULL); + if (!current) + { + ft_lstclear(&new, del); + return (NULL); + } + current = current ->next; + } + lst = lst->next; + } + return (new); +} diff --git a/Libft/ft_lstnew.c b/Libft/ft_lstnew.c new file mode 100644 index 0000000..1cf613c --- /dev/null +++ b/Libft/ft_lstnew.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/21 19:40:32 by grobledo #+# #+# */ +/* Updated: 2023/02/21 22:58:42 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +t_list *ft_lstnew(void *content) +{ + t_list *new; + + new = malloc(sizeof(t_list)); + if (new == 0) + return (NULL); + new->content = content; + new->next = NULL; + return (new); +} diff --git a/Libft/ft_lstsize.c b/Libft/ft_lstsize.c new file mode 100644 index 0000000..c489c1a --- /dev/null +++ b/Libft/ft_lstsize.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstsize.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/23 10:14:39 by grobledo #+# #+# */ +/* Updated: 2023/02/23 10:14:41 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_lstsize(t_list *lst) +{ + int i; + + i = 0; + while (lst) + { + lst = lst->next; + i++; + } + return (i); +} diff --git a/Libft/ft_memchr.c b/Libft/ft_memchr.c new file mode 100644 index 0000000..6a35922 --- /dev/null +++ b/Libft/ft_memchr.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/08 20:08:44 by grobledo #+# #+# */ +/* Updated: 2023/02/08 20:08:45 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +void *ft_memchr(const void *str, int c, size_t n) +{ + size_t i; + + i = 0; + while (i < n) + { + if ((((unsigned char *)str)[i]) == (unsigned char)c) + return ((void *)str + i); + i++; + } + return (NULL); +} diff --git a/Libft/ft_memcmp.c b/Libft/ft_memcmp.c new file mode 100644 index 0000000..112ccee --- /dev/null +++ b/Libft/ft_memcmp.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/08 20:15:03 by grobledo #+# #+# */ +/* Updated: 2023/02/08 20:15:05 by grobledo ### ########.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_memcpy.c b/Libft/ft_memcpy.c new file mode 100644 index 0000000..407ca30 --- /dev/null +++ b/Libft/ft_memcpy.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/08 15:04:22 by grobledo #+# #+# */ +/* Updated: 2023/02/08 15:04:24 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +void *ft_memcpy(void *dest, const void *src, size_t n) +{ + int i; + + if (!dest && !src) + return (NULL); + i = 0; + while (n != 0) + { + ((unsigned char *)dest)[i] = ((unsigned char *)src)[i]; + i++; + n--; + } + return ((void *)dest); +} diff --git a/Libft/ft_memmove.c b/Libft/ft_memmove.c new file mode 100644 index 0000000..c6e9153 --- /dev/null +++ b/Libft/ft_memmove.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/10 10:32:23 by grobledo #+# #+# */ +/* Updated: 2023/02/10 10:32:25 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +void *ft_memmove(void *dest, const void *src, size_t n) +{ + size_t i; + + if (!dest && !src) + return (NULL); + i = 0; + if (dest < src) + { + while (n--) + { + (((unsigned char *)dest)[i]) = (((unsigned char *)src)[i]); + i++; + } + } + else + { + i = i + n - 1; + while (n--) + { + (((unsigned char *)dest)[i]) = (((unsigned char *)src)[i]); + i--; + } + } + return ((void *)dest); +} diff --git a/Libft/ft_memset.c b/Libft/ft_memset.c new file mode 100644 index 0000000..ca28cfe --- /dev/null +++ b/Libft/ft_memset.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/02 18:40:30 by grobledo #+# #+# */ +/* Updated: 2023/02/02 18:40:33 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +void *ft_memset(void *str, int c, size_t n) +{ + int i; + + i = 0; + while (n != 0) + { + (((unsigned char *)str)[i]) = c; + i++; + n--; + } + return ((void *)str); +} diff --git a/Libft/ft_printf.c b/Libft/ft_printf.c new file mode 100644 index 0000000..f2c233c --- /dev/null +++ b/Libft/ft_printf.c @@ -0,0 +1,63 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/03/13 10:48:34 by grobledo #+# #+# */ +/* Updated: 2023/03/13 10:48:35 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_format(const char format, va_list args, int count) +{ + if (format == 'c') + count = ft_putcharf((char)va_arg(args, int), count); + else if (format == 's') + count = ft_putstrf(va_arg(args, char *), count); + else if (format == 'd') + count = ft_putnbrf(va_arg(args, int), count); + else if (format == 'i') + count = ft_putnbrf(va_arg(args, int), count); + else if (format == 'u') + count = ft_putnbrposf(va_arg(args, unsigned int), count); + else if (format == 'x') + count = ft_starthexa (va_arg(args, unsigned int), 'x', count); + else if (format == 'X') + count = ft_starthexa (va_arg(args, unsigned int), 'X', count); + else if (format == 'p') + count = ft_startpointer + (va_arg(args, unsigned long long int), 'p', count); + else if (format == '%') + count = ft_putcharf('%', count); + return (count); +} + +int ft_printf(const char *format, ...) +{ + va_list args; + int i; + int count; + + va_start(args, format); + i = 0; + count = 0; + while (format[i]) + { + if (format[i] != '%') + { + write(1, &format[i], 1); + count++; + } + else + { + i++; + count = ft_format(format[i], args, count); + } + i++; + } + va_end(args); + return (count); +} diff --git a/Libft/ft_put.c b/Libft/ft_put.c new file mode 100644 index 0000000..b29ff4d --- /dev/null +++ b/Libft/ft_put.c @@ -0,0 +1,75 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_put.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/13 10:26:43 by grobledo #+# #+# */ +/* Updated: 2023/04/13 10:26:45 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_putcharf(char c, int count) +{ + write(1, &c, 1); + count++; + return (count); +} + +int ft_putnbrf(int n, int count) +{ + if (n == -2147483648) + { + (write(1, "-2147483648", 11)); + count += 11; + return (count); + } + if (n < 0) + { + count = ft_putcharf('-', count); + n *= -1; + count = ft_putnbrf(n, count); + } + else if (n >= 10) + { + count = ft_putnbrf(n / 10, count); + count = ft_putnbrf(n % 10, count); + } + else + { + count = ft_putcharf(n + '0', count); + } + return (count); +} + +int ft_putnbrposf(unsigned int n, int count) +{ + if (n >= 10) + { + count = ft_putnbrposf(n / 10, count); + count = ft_putnbrposf(n % 10, count); + } + else + { + count = ft_putcharf(n + '0', count); + } + return (count); +} + +int ft_putstrf(char *s, int count) +{ + int i; + + if (!s) + return (ft_putstrf("(null)", count)); + i = 0; + while (s[i]) + { + write(1, &s[i], 1); + i++; + count++; + } + return (count); +} diff --git a/Libft/ft_putchar_fd.c b/Libft/ft_putchar_fd.c new file mode 100644 index 0000000..33fe262 --- /dev/null +++ b/Libft/ft_putchar_fd.c @@ -0,0 +1,17 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/20 23:21:04 by grobledo #+# #+# */ +/* Updated: 2023/02/20 23:21:05 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} diff --git a/Libft/ft_putendl_fd.c b/Libft/ft_putendl_fd.c new file mode 100644 index 0000000..bed0653 --- /dev/null +++ b/Libft/ft_putendl_fd.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/20 23:36:08 by grobledo #+# #+# */ +/* Updated: 2023/02/20 23:36:09 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +void ft_putendl_fd(char *s, int fd) +{ + int i; + + if (!s) + return ; + i = 0; + while (s[i]) + { + write(fd, &s[i], 1); + i++; + } + ft_putchar_fd('\n', fd); +} diff --git a/Libft/ft_putnbr_fd.c b/Libft/ft_putnbr_fd.c new file mode 100644 index 0000000..89e7851 --- /dev/null +++ b/Libft/ft_putnbr_fd.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/20 23:43:01 by grobledo #+# #+# */ +/* Updated: 2023/02/20 23:43:02 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +void ft_putnbr_fd(int n, int fd) +{ + if (n == -2147483648) + { + write(fd, "-2147483648", 11); + } + else if (n < 0) + { + ft_putchar_fd('-', fd); + n *= -1; + ft_putnbr_fd(n, fd); + } + else if (n >= 10) + { + ft_putnbr_fd(n / 10, fd); + ft_putnbr_fd(n % 10, fd); + } + else + ft_putchar_fd(n + '0', fd); +} diff --git a/Libft/ft_putstr_fd.c b/Libft/ft_putstr_fd.c new file mode 100644 index 0000000..7a53068 --- /dev/null +++ b/Libft/ft_putstr_fd.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/20 23:29:21 by grobledo #+# #+# */ +/* Updated: 2023/02/20 23:29:26 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +void ft_putstr_fd(char *s, int fd) +{ + int i; + + if (!s) + return ; + i = 0; + while (s[i]) + { + write(fd, &s[i], 1); + i++; + } +} diff --git a/Libft/ft_split.c b/Libft/ft_split.c new file mode 100644 index 0000000..f48337c --- /dev/null +++ b/Libft/ft_split.c @@ -0,0 +1,78 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/21 11:11:19 by grobledo #+# #+# */ +/* Updated: 2023/02/21 18:03:11 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_countword(const char *s, char c) +{ + int i; + int j; + + i = 0; + j = 0; + while (s[i]) + { + while (s[i] == c) + i++; + if (s[i] != '\0') + j++; + while (s[i] != c && s[i]) + i++; + } + return (j); +} + +char *ft_strdup_modif(const char *s, char c, size_t i) +{ + size_t k; + char *dest; + + k = 0; + while (s[i + k] && s[i + k] != c) + k++; + dest = ft_calloc(sizeof(char), (k + 1)); + k = 0; + if (dest == 0) + return (NULL); + while (s[i + k] && s[i + k] != c) + { + dest[k] = s[i + k]; + k++; + } + return (dest); +} + +char **ft_split(const char *s, char c) +{ + size_t i; + size_t j; + char **res; + + if (!s) + return (NULL); + res = ft_calloc(sizeof (char *), (ft_countword(s, c) + 1)); + if (!res) + return (NULL); + i = 0; + j = 0; + while (s[i]) + { + while (s[i] == c) + i++; + if (s[i] == '\0') + break ; + res[j] = ft_strdup_modif(s, c, i); + j++; + while (s[i] != c && s[i]) + i++; + } + return (res); +} diff --git a/Libft/ft_strchr.c b/Libft/ft_strchr.c new file mode 100644 index 0000000..8bb7eee --- /dev/null +++ b/Libft/ft_strchr.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/04 12:59:29 by grobledo #+# #+# */ +/* Updated: 2023/02/04 12:59:31 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +char *ft_strchr(const char *str, int tofind) +{ + int i; + + i = 0; + while (str[i]) + { + if ((unsigned char)str[i] == (unsigned char)tofind) + return ((char *)&str[i]); + i++; + } + if (tofind == '\0') + return ((char *)&str[i]); + return (0); +} diff --git a/Libft/ft_strdup.c b/Libft/ft_strdup.c new file mode 100644 index 0000000..b743a62 --- /dev/null +++ b/Libft/ft_strdup.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/08 20:55:55 by grobledo #+# #+# */ +/* Updated: 2023/02/13 21:30:44 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +char *ft_strdup(const char *src) +{ + size_t size; + char *dest; + + size = ft_strlen(src); + dest = (char *)malloc(size + 1); + if (dest == 0) + return (NULL); + ft_strlcpy(dest, src, size + 1); + return (dest); +} diff --git a/Libft/ft_striteri.c b/Libft/ft_striteri.c new file mode 100644 index 0000000..934c9d8 --- /dev/null +++ b/Libft/ft_striteri.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/20 22:29:06 by grobledo #+# #+# */ +/* Updated: 2023/02/20 22:29:07 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +void ft_striteri(char *s, void (*f)(unsigned int, char*)) +{ + size_t i; + + if (!s || !(*f)) + return ; + i = 0; + while (i < ft_strlen(s)) + { + (*f)(i, &s[i]); + i++; + } +} diff --git a/Libft/ft_strjoin.c b/Libft/ft_strjoin.c new file mode 100644 index 0000000..735da25 --- /dev/null +++ b/Libft/ft_strjoin.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/14 16:41:00 by grobledo #+# #+# */ +/* Updated: 2023/02/14 16:41:02 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +char *ft_strjoin(char const *s1, char const *s2) +{ + size_t i; + size_t j; + char *dest; + + if (!s1 || !s2) + return (NULL); + dest = ft_calloc ((ft_strlen(s1) + ft_strlen(s2) + 1), sizeof (char)); + if (dest == 0) + return (NULL); + i = 0; + j = 0; + while (s1[i] || s2[j]) + { + while (i < ft_strlen(s1)) + { + dest[i] = s1[i]; + i++; + } + while (j < ft_strlen(s2)) + { + dest[i + j] = s2[j]; + j++; + } + } + return (dest); +} diff --git a/Libft/ft_strlcat.c b/Libft/ft_strlcat.c new file mode 100644 index 0000000..89ae6b0 --- /dev/null +++ b/Libft/ft_strlcat.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/02 19:33:00 by grobledo #+# #+# */ +/* Updated: 2023/02/02 19:33:01 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_strlcat(char *dest, const char *src, size_t size) +{ + unsigned int i; + unsigned int j; + unsigned int dlen; + unsigned int slen; + + if ((dest == NULL || src == NULL) && size == 0) + return (0); + i = 0; + j = ft_strlen(dest); + dlen = j; + slen = ft_strlen(src); + if (size <= dlen) + return (slen + size); + while (src[i] != '\0' && i < size - dlen - 1) + { + dest[j] = src[i]; + i++; + j++; + } + dest[j] = '\0'; + return (dlen + slen); +} diff --git a/Libft/ft_strlcpy.c b/Libft/ft_strlcpy.c new file mode 100644 index 0000000..5201ec0 --- /dev/null +++ b/Libft/ft_strlcpy.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/02 19:33:21 by grobledo #+# #+# */ +/* Updated: 2023/02/02 19:33:24 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_strlcpy(char *dest, const char *src, size_t size) +{ + unsigned int i; + + i = 0; + if (size == 0) + return (ft_strlen(src)); + while (src[i] && i < size - 1) + { + dest[i] = src[i]; + i++; + } + dest[i] = '\0'; + return (ft_strlen(src)); +} diff --git a/Libft/ft_strlen.c b/Libft/ft_strlen.c new file mode 100644 index 0000000..45c7ee9 --- /dev/null +++ b/Libft/ft_strlen.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/02 18:31:38 by grobledo #+# #+# */ +/* Updated: 2023/02/02 18:31:39 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +size_t ft_strlen(const char *str) +{ + size_t i; + + i = 0; + while (str[i]) + { + i++; + } + return (i); +} diff --git a/Libft/ft_strmapi.c b/Libft/ft_strmapi.c new file mode 100644 index 0000000..6ce2ee1 --- /dev/null +++ b/Libft/ft_strmapi.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/20 21:51:01 by grobledo #+# #+# */ +/* Updated: 2023/02/20 21:51:02 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) +{ + size_t i; + size_t dlen; + char *dest; + + if (!s || !(*f)) + return (NULL); + i = 0; + dlen = ft_strlen(s); + dest = ft_calloc(dlen + 1, sizeof (char)); + if (!dest) + return (NULL); + while (i < ft_strlen(s)) + { + dest[i] = (*f)(i, s[i]); + i++; + } + return (dest); +} diff --git a/Libft/ft_strncmp.c b/Libft/ft_strncmp.c new file mode 100644 index 0000000..8a35309 --- /dev/null +++ b/Libft/ft_strncmp.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/04 14:33:04 by grobledo #+# #+# */ +/* Updated: 2023/02/04 14:33:06 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_strncmp(const char *s1, const char *s2, size_t size) +{ + size_t i; + + i = 0; + while ((s1[i] || s2[i]) && (i < size)) + { + if (s1[i] != s2[i]) + return (((unsigned char)(s1[i]) - ((unsigned char)s2[i]))); + i++; + } + return (0); +} diff --git a/Libft/ft_strnstr.c b/Libft/ft_strnstr.c new file mode 100644 index 0000000..1a8660a --- /dev/null +++ b/Libft/ft_strnstr.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/13 22:07:12 by grobledo #+# #+# */ +/* Updated: 2023/02/13 22:07:14 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +char *ft_strnstr(const char *big, const char *little, size_t len) +{ + size_t i; + size_t j; + + if ((big == NULL || little == NULL) && !len) + return (0); + i = 0; + j = 0; + if (little[i] == '\0') + return ((char *)big); + while (big[i] && i < len) + { + if (big[i] == little[j]) + { + while (big[i + j] == little[j] && (i + j) < len && little[j]) + j++; + if (little[j] == '\0') + return ((char *)&big[i]); + j = 0; + } + i++; + } + return (NULL); +} diff --git a/Libft/ft_strrchr.c b/Libft/ft_strrchr.c new file mode 100644 index 0000000..c1fb9e4 --- /dev/null +++ b/Libft/ft_strrchr.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/04 14:00:32 by grobledo #+# #+# */ +/* Updated: 2023/02/13 21:32:54 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +char *ft_strrchr(const char *str, int tofind) +{ + int i; + + i = 0; + while (str[i]) + i++; + while (i >= 0) + { + if ((unsigned char)str[i] == (unsigned char)tofind) + return ((char *)&str[i]); + i--; + } + return (0); +} diff --git a/Libft/ft_strtrim.c b/Libft/ft_strtrim.c new file mode 100644 index 0000000..02a14e6 --- /dev/null +++ b/Libft/ft_strtrim.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/18 18:34:05 by grobledo #+# #+# */ +/* Updated: 2023/02/18 18:34:08 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +char *ft_strtrim(const char *s1, const char *set) +{ + size_t i; + size_t j; + size_t k; + size_t dlen; + char *dest; + + if (!s1) + return (NULL); + i = 0; + j = ft_strlen(s1); + k = -1; + while (ft_strchr(set, s1[i]) != 0 && s1[i]) + i++; + if (!s1[i]) + return (ft_strdup("")); + while (ft_strchr(set, s1[j]) != 0 && j > 0) + j--; + dlen = (j - i); + dest = ft_calloc ((dlen + 2), sizeof (char)); + if (dest == 0) + return (NULL); + while (++k <= dlen) + dest[k] = s1[i + k]; + return (dest); +} diff --git a/Libft/ft_substr.c b/Libft/ft_substr.c new file mode 100644 index 0000000..22c55ea --- /dev/null +++ b/Libft/ft_substr.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/14 14:52:48 by grobledo #+# #+# */ +/* Updated: 2023/02/14 14:52:51 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +char *ft_substr(const char *s, unsigned int start, size_t len) +{ + size_t i; + size_t j; + char *dest; + + if (!s) + return (NULL); + i = start; + j = 0; + if (start >= ft_strlen(s)) + return (ft_calloc(1, 1)); + if (ft_strlen(s + start) < len) + dest = (char *)ft_calloc((ft_strlen(s + start) + 1), sizeof(char)); + else + dest = (char *)ft_calloc((len + 1), sizeof(char)); + if (dest == 0) + return (NULL); + while (j < len && s[i]) + { + dest[j] = s[i]; + i++; + j++; + } + return (dest); +} diff --git a/Libft/ft_tolower.c b/Libft/ft_tolower.c new file mode 100644 index 0000000..7eae236 --- /dev/null +++ b/Libft/ft_tolower.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/02 20:49:29 by grobledo #+# #+# */ +/* Updated: 2023/02/02 20:49:30 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_tolower(int c) +{ + if (c >= 65 && c <= 90) + c += 32; + return (c); +} diff --git a/Libft/ft_toupper.c b/Libft/ft_toupper.c new file mode 100644 index 0000000..2f7e5f2 --- /dev/null +++ b/Libft/ft_toupper.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/02 20:19:23 by grobledo #+# #+# */ +/* Updated: 2023/02/02 20:19:25 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_toupper(int c) +{ + if (c >= 97 && c <= 122) + c -= 32; + return (c); +} diff --git a/Libft/get_next_line.c b/Libft/get_next_line.c new file mode 100644 index 0000000..da04a89 --- /dev/null +++ b/Libft/get_next_line.c @@ -0,0 +1,110 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/05 20:41:22 by grobledo #+# #+# */ +/* Updated: 2023/05/05 20:41:25 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +char *ft_join( char *buffer, char *buff_read) +{ + char *temp; + + temp = ft_strjoing(buffer, buff_read); + free (buffer); + return (temp); +} + +char *ft_nextline(char *buffer) +{ + int i; + int j; + char *nextline; + + i = 0; + while (buffer[i] && buffer[i] != '\n') + i++; + if (buffer[i] == '\n') + i++; + if (!buffer[i]) + { + free (buffer); + return (NULL); + } + j = 0; + nextline = ft_calloc(ft_strleng(buffer) - i + 1, sizeof(char)); + while (buffer[i]) + { + nextline[j++] = buffer[i++]; + } + free (buffer); + return (nextline); +} + +char *ft_line(char *buffer) +{ + char *line; + int i; + + i = 0; + if (!buffer) + return (NULL); + while (buffer[i] && buffer[i] != '\n') + i++; + line = ft_calloc(i + 2, sizeof(char)); + i = 0; + while (buffer[i] && buffer[i] != '\n') + { + line[i] = buffer[i]; + i++; + } + if (buffer[i] && buffer[i] == '\n') + line[i] = '\n'; + return (line); +} + +char *ft_readfile(int fd, char *buffer) +{ + int byte_read; + char *buff_read; + + buff_read = ft_calloc(BUFFER_SIZE + 1, sizeof(char)); + byte_read = 1; + while (byte_read > 0) + { + byte_read = read(fd, buff_read, BUFFER_SIZE); + if (byte_read == 0) + break ; + if (byte_read == -1) + { + free(buff_read); + return (NULL); + } + buff_read[byte_read] = 0; + buffer = ft_join(buffer, buff_read); + if (ft_strrchr(buff_read, '\n')) + break ; + } + free (buff_read); + return (buffer); +} + +char *get_next_line(int fd) +{ + char *line; + static char *buffer = NULL; + + if (fd < 0 || BUFFER_SIZE <= 0 || read(fd, 0, 0) < 0) + return (NULL); + buffer = ft_readfile(fd, buffer); + if (!buffer) + return (NULL); + line = ft_line(buffer); + buffer = ft_nextline(buffer); + return (line); +} diff --git a/Libft/get_next_line_utils.c b/Libft/get_next_line_utils.c new file mode 100644 index 0000000..6878058 --- /dev/null +++ b/Libft/get_next_line_utils.c @@ -0,0 +1,53 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/05 20:41:39 by grobledo #+# #+# */ +/* Updated: 2023/05/05 20:41:41 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +size_t ft_strleng(const char *str) +{ + size_t i; + + i = 0; + while (str && str[i]) + { + i++; + } + return (i); +} + +char *ft_strjoing(char const *s1, char const *s2) +{ + size_t i; + size_t j; + char *dest; + + if (!s2) + return (NULL); + dest = ft_calloc ((ft_strleng(s1) + ft_strleng(s2) + 1), sizeof (char)); + if (dest == 0) + return (NULL); + i = 0; + j = 0; + while (s2[j]) + { + while (i < ft_strleng(s1)) + { + dest[i] = s1[i]; + i++; + } + while (j < ft_strleng(s2)) + { + dest[i + j] = s2[j]; + j++; + } + } + return (dest); +} diff --git a/Libft/libft.h b/Libft/libft.h new file mode 100644 index 0000000..c98ec10 --- /dev/null +++ b/Libft/libft.h @@ -0,0 +1,89 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/10 12:14:34 by grobledo #+# #+# */ +/* Updated: 2023/02/13 21:31:19 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ +#ifndef LIBFT_H +# define LIBFT_H +# include +# include +# include +# include +# include +# include +# include + +# ifndef BUFFER_SIZE +# define BUFFER_SIZE 10000 +# endif + +typedef struct s_list +{ + void *content; + struct s_list *next; +} t_list; + +int ft_atoi(const char *str); +void ft_bzero(void *s, size_t n); +void *ft_calloc(size_t count, size_t size); +int ft_isalnum(int c); +int ft_isalpha(int c); +int ft_isascii(int c); +int ft_isdigit(int c); +int ft_isprint(int c); +void *ft_memchr(const void *str, int c, size_t n); +int ft_memcmp(const void *s1, const void *s2, size_t n); +void *ft_memcpy(void *dest, const void *src, size_t n); +void *ft_memmove(void *dest, const void *src, size_t n); +void *ft_memset(void *str, int c, size_t n); +char *ft_strchr(const char *str, int tofind); +char *ft_strdup(const char *src); +int ft_strlcat(char *dest, const char *src, size_t size); +int ft_strlcpy(char *dest, const char *src, size_t size); +size_t ft_strlen(const char *str); +int ft_strncmp(const char *s1, const char *s2, size_t size); +char *ft_strrchr(const char *str, int tofind); +int ft_tolower(int c); +int ft_toupper(int c); +char *ft_strnstr(const char *big, const char *little, size_t len); +char *ft_substr(char const *s, unsigned int start, size_t len); +char *ft_strjoin(char const *s1, char const *s2); +char *ft_strtrim(const char *s1, const char *set); +char *ft_itoa(int nb); +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); +void ft_striteri(char *s, void (*f)(unsigned int, char*)); +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); +char **ft_split(const char *s, char c); +t_list *ft_lstnew(void *content); +void ft_lstadd_front(t_list **lst, t_list *new); +int ft_lstsize(t_list *lst); +t_list *ft_lstlast(t_list *lst); +void ft_lstadd_back(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 *)); +t_list *ft_lstmap(t_list *lst, void *(f)(void *), void (*del)(void *)); +int ft_hexa(unsigned int args, char format, int count); +int ft_format(const char format, va_list args, int count); +int ft_printf(const char *format, ...); +int ft_putstrf(char *s, int count); +int ft_putcharf(char c, int count); +int ft_putnbrposf(unsigned int n, int count); +int ft_putnbrf(int n, int count); +int ft_starthexa(unsigned int args, char format, int count); +int ft_pointer(unsigned long long int args, char format, int count); +int ft_startpointer(unsigned long long int args, char format, int count); +char *get_next_line(int fd); +size_t ft_strleng(const char *str); +char *ft_strjoing(char const *s1, char const *s2); +#endif diff --git a/Makefile b/Makefile index 8ba5229..2e563ef 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: greg +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/07/29 13:08:42 by greg #+# #+# # -# Updated: 2024/10/03 17:00:43 by greg ### ########.fr # +# Updated: 2024/10/09 03:07:50 by greg ### ########.fr # # # # **************************************************************************** # @@ -24,15 +24,15 @@ CC = gcc -g CFLAGS = -Wall -Werror -Wextra -obj : ${OBJS} - all: $(NAME) +obj : ${OBJS} + $(NAME): ${OBJS} make -C ${LIBFT} make -C ${MLX} - gcc ${OBJS} Libft/libft.a Minilibx/libmlx.a -lX11 -lXext -o cub3d + gcc ${OBJS} Libft/libft.a Minilibx/libmlx.a -lX11 -lXext -o cub3d -lm clean : rm -f ${OBJS} diff --git a/Minilibx b/Minilibx new file mode 160000 index 0000000..7dc53a4 --- /dev/null +++ b/Minilibx @@ -0,0 +1 @@ +Subproject commit 7dc53a411a7d4ae286c60c6229bd1e395b0efb82 diff --git a/algo.c b/algo.c index b67db6a..62414a9 100644 --- a/algo.c +++ b/algo.c @@ -6,11 +6,41 @@ /* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/03 18:59:06 by greg ### ########.fr */ +/* Updated: 2024/10/09 03:30:08 by greg ### ########.fr */ /* */ /* ************************************************************************** */ #include "algo.h" +#include +#include + +int worldMap[mapWidth][mapHeight]= +{ + {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1}, + {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1}, + {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,0,0,0,0,1,1,0,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1}, + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} +}; static int initalgo(t_ray *ray) @@ -21,20 +51,60 @@ static int initalgo(t_ray *ray) ray->dirY = 0; ray->planeX = 0; ray->planeY = 0.66; // FOV de 66 degres - ray->currtime = 0; - ray->oldtime = 0; ray->movespeed = 0.1; ray->rotspeed = 0.1; return (0); } +static int keypress(int keycode, t_ray *ray, int **worldMap) +{ + //move forward if no wall in front of you + if (keycode == 119) + { + if(worldMap[(int)(ray->posX + ray->dirX * ray->movespeed)][(int)(ray->posY)] == 0) + ray->posX += ray->dirX * ray->movespeed; + if(worldMap[(int)(ray->posX)][((int)ray->posY + (int)ray->dirY * (int)ray->movespeed)] == 0) + ray->posY += ray->dirY * ray->movespeed; + } + //move backwards if no wall behind you + if (keycode == 115) + { + if(worldMap[(int)(ray->posX - ray->dirX * ray->movespeed)][(int)(ray->posY)] == 0) + ray->posX -= ray->dirX * ray->movespeed; + if(worldMap[(int)(ray->posX)][((int)ray->posY - (int)ray->dirY * (int)ray->movespeed)] == 0) + ray->posY -= ray->dirY * ray->movespeed; + } + //rotate to the right + if (keycode == 100) + { + //both camera direction and camera plane must be rotated + ray->oldDirX = ray->dirX; + ray->dirX = ray->dirX * cos(-ray->rotspeed) - ray->dirY * sin(-ray->rotspeed); + ray->dirY = ray->oldDirX * sin(-ray->rotspeed) + ray->dirY * cos(-ray->rotspeed); + ray->oldPlaneX = ray->planeX; + ray->planeX = ray->planeX * cos(-ray->rotspeed) - ray->planeY * sin(-ray->rotspeed); + ray->planeY = ray->oldPlaneX * sin(-ray->rotspeed) + ray->planeY * cos(-ray->rotspeed); + } + //rotate to the left + if (keycode == 97) + { + //both camera direction and camera plane must be rotated + ray->oldDirX = ray->dirX; + ray->dirX = ray->dirX * cos(ray->rotspeed) - ray->dirY * sin(ray->rotspeed); + ray->dirY = ray->oldDirX * sin(ray->rotspeed) + ray->dirY * cos(ray->rotspeed); + ray->oldPlaneX = ray->planeX; + ray->planeX = ray->planeX * cos(ray->rotspeed) - ray->planeY * sin(ray->rotspeed); + ray->planeY = ray->oldPlaneX * sin(ray->rotspeed) + ray->planeY * cos(ray->rotspeed); + } + return (0); +} -int algo() +int main(int /*argc*/, char */*argv*/[]) { t_ray ray; int x; double width; - int height; + double height; // quelle box sur la map on est int mapX; int mapY; @@ -43,12 +113,17 @@ int algo() int side; initalgo(&ray); - // init image; - x = 0; width = 640; height = 480; + + void *mlx_ptr; + void *win_ptr; + + mlx_ptr = mlx_init(); // Initialise la connexion à la MLX + win_ptr = mlx_new_window(mlx_ptr, width, height, "cub3d"); + while (x < width) { // position et direction du rayon @@ -118,67 +193,28 @@ int algo() if(drawStart < 0) drawStart = 0; int drawEnd; + drawEnd = lineHeight / 2 + height / 2; if(drawEnd >= height) drawEnd = height - 1; - - /*mlx fontction color - - give x and y sides different brightness - if (side == 1) {color = color / 2;} + int y = drawStart; + while (y <= drawEnd) + { + mlx_pixel_put(mlx_ptr, win_ptr, x, y, 0xFF0000); + y++; + } + x++; + } //draw the pixels of the stripe as a vertical line - verLine(x, drawStart, drawEnd, color); */ + //verLine(x, drawStart, drawEnd, color); */ - //timing for input to dissociate speed from speed processor (same speed on all pc) - ray.oldtime = ray.currtime; - ray.currtime = getTicks(); // put image to window // destroy old image + + mlx_hook(win_ptr, 2, 1L<<0, keypress, &ray); - // hook event - - readKeys(); - //move forward if no wall in front of you - if (keyDown(move_up)) - { - if(worldMap[(ray.posX + ray.dirX * ray.movespeed)][(int)(ray.posY)] == 0) - ray.posX += ray.dirX * ray.movespeed; - if(worldMap[(ray.posX)][((int)ray.posY + (int)ray.dirY * (int)ray.movespeed)] == 0) - ray.posY += ray.dirY * ray.movespeed; - } - //move backwards if no wall behind you - if (keyDown(moove_down)) - { - if(worldMap[(ray.posX - ray.dirX * ray.movespeed)][(int)(ray.posY)] == 0) - ray.posX -= ray.dirX * ray.movespeed; - if(worldMap[(ray.posX)][((int)ray.posY - (int)ray.dirY * (int)ray.movespeed)] == 0) - ray.posY -= ray.dirY * ray.movespeed; - } - //rotate to the right - if (keyDown(moove_right)) - { - //both camera direction and camera plane must be rotated - ray.oldDirX = ray.dirX; - ray.dirX = ray.dirX * cos(-ray.rotspeed) - ray.dirY * sin(-ray.rotspeed); - ray.dirY = ray.oldDirX * sin(-ray.rotspeed) + ray.dirY * cos(-ray.rotspeed); - ray.oldPlaneX = ray.planeX; - ray.planeX = ray.planeX * cos(-ray.rotspeed) - ray.planeY * sin(-ray.rotspeed); - ray.planeY = ray.oldPlaneX * sin(-ray.rotspeed) + ray.planeY * cos(-ray.rotspeed); - } - //rotate to the left - if (keyDown(moove_left)) - { - //both camera direction and camera plane must be rotated - ray.oldDirX = ray.dirX; - ray.dirX = ray.dirX * cos(ray.rotspeed) - ray.dirY * sin(ray.rotspeed); - ray.dirY = ray.oldDirX * sin(ray.rotspeed) + ray.dirY * cos(ray.rotspeed); - ray.oldPlaneX = ray.planeX; - ray.planeX = ray.planeX * cos(ray.rotspeed) - ray.planeY * sin(ray.rotspeed); - ray.planeY = ray.oldPlaneX * sin(ray.rotspeed) + ray.planeY * cos(ray.rotspeed); - } - } return (0); } diff --git a/algo.h b/algo.h index acb137f..47a1836 100644 --- a/algo.h +++ b/algo.h @@ -6,7 +6,7 @@ /* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/03 18:59:43 by greg ### ########.fr */ +/* Updated: 2024/10/09 02:51:53 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,10 @@ #include #include +#include "Minilibx/mlx.h" +#include "Minilibx/mlx_int.h" +#define mapWidth 24 +#define mapHeight 24 typedef struct s_ray { From 613f0665475f914f32ae2d5fb748e570a2b1654f Mon Sep 17 00:00:00 2001 From: ReverseSky Date: Wed, 9 Oct 2024 03:36:39 +0200 Subject: [PATCH 08/80] s --- Libft/Makefile | 30 ---------- Libft/ft_atoi.c | 34 ----------- Libft/ft_bzero.c | 26 --------- Libft/ft_calloc.c | 29 ---------- Libft/ft_hexa.c | 64 --------------------- Libft/ft_isalnum.c | 19 ------- Libft/ft_isalpha.c | 19 ------- Libft/ft_isascii.c | 19 ------- Libft/ft_isdigit.c | 19 ------- Libft/ft_isprint.c | 19 ------- Libft/ft_itoa.c | 62 -------------------- Libft/ft_lstadd_back.c | 30 ---------- Libft/ft_lstadd_front.c | 18 ------ Libft/ft_lstclear.c | 30 ---------- Libft/ft_lstdelone.c | 22 -------- Libft/ft_lstiter.c | 27 --------- Libft/ft_lstlast.c | 21 ------- Libft/ft_lstmap.c | 41 -------------- Libft/ft_lstnew.c | 24 -------- Libft/ft_lstsize.c | 25 -------- Libft/ft_memchr.c | 26 --------- Libft/ft_memcmp.c | 26 --------- Libft/ft_memcpy.c | 28 --------- Libft/ft_memmove.c | 39 ------------- Libft/ft_memset.c | 26 --------- Libft/ft_printf.c | 63 --------------------- Libft/ft_put.c | 75 ------------------------ Libft/ft_putchar_fd.c | 17 ------ Libft/ft_putendl_fd.c | 27 --------- Libft/ft_putnbr_fd.c | 33 ----------- Libft/ft_putstr_fd.c | 26 --------- Libft/ft_split.c | 78 ------------------------- Libft/ft_strchr.c | 28 --------- Libft/ft_strdup.c | 25 -------- Libft/ft_striteri.c | 26 --------- Libft/ft_strjoin.c | 41 -------------- Libft/ft_strlcat.c | 37 ------------ Libft/ft_strlcpy.c | 28 --------- Libft/ft_strlen.c | 24 -------- Libft/ft_strmapi.c | 33 ----------- Libft/ft_strncmp.c | 26 --------- Libft/ft_strnstr.c | 38 ------------- Libft/ft_strrchr.c | 28 --------- Libft/ft_strtrim.c | 40 ------------- Libft/ft_substr.c | 39 ------------- Libft/ft_tolower.c | 19 ------- Libft/ft_toupper.c | 19 ------- Libft/get_next_line.c | 110 ------------------------------------ Libft/get_next_line_utils.c | 53 ----------------- Libft/libft.h | 89 ----------------------------- Minilibx | 1 - 51 files changed, 1746 deletions(-) delete mode 100644 Libft/Makefile delete mode 100644 Libft/ft_atoi.c delete mode 100644 Libft/ft_bzero.c delete mode 100644 Libft/ft_calloc.c delete mode 100644 Libft/ft_hexa.c delete mode 100644 Libft/ft_isalnum.c delete mode 100644 Libft/ft_isalpha.c delete mode 100644 Libft/ft_isascii.c delete mode 100644 Libft/ft_isdigit.c delete mode 100644 Libft/ft_isprint.c delete mode 100644 Libft/ft_itoa.c delete mode 100644 Libft/ft_lstadd_back.c delete mode 100644 Libft/ft_lstadd_front.c delete mode 100644 Libft/ft_lstclear.c delete mode 100644 Libft/ft_lstdelone.c delete mode 100644 Libft/ft_lstiter.c delete mode 100644 Libft/ft_lstlast.c delete mode 100644 Libft/ft_lstmap.c delete mode 100644 Libft/ft_lstnew.c delete mode 100644 Libft/ft_lstsize.c delete mode 100644 Libft/ft_memchr.c delete mode 100644 Libft/ft_memcmp.c delete mode 100644 Libft/ft_memcpy.c delete mode 100644 Libft/ft_memmove.c delete mode 100644 Libft/ft_memset.c delete mode 100644 Libft/ft_printf.c delete mode 100644 Libft/ft_put.c delete mode 100644 Libft/ft_putchar_fd.c delete mode 100644 Libft/ft_putendl_fd.c delete mode 100644 Libft/ft_putnbr_fd.c delete mode 100644 Libft/ft_putstr_fd.c delete mode 100644 Libft/ft_split.c delete mode 100644 Libft/ft_strchr.c delete mode 100644 Libft/ft_strdup.c delete mode 100644 Libft/ft_striteri.c delete mode 100644 Libft/ft_strjoin.c delete mode 100644 Libft/ft_strlcat.c delete mode 100644 Libft/ft_strlcpy.c delete mode 100644 Libft/ft_strlen.c delete mode 100644 Libft/ft_strmapi.c delete mode 100644 Libft/ft_strncmp.c delete mode 100644 Libft/ft_strnstr.c delete mode 100644 Libft/ft_strrchr.c delete mode 100644 Libft/ft_strtrim.c delete mode 100644 Libft/ft_substr.c delete mode 100644 Libft/ft_tolower.c delete mode 100644 Libft/ft_toupper.c delete mode 100644 Libft/get_next_line.c delete mode 100644 Libft/get_next_line_utils.c delete mode 100644 Libft/libft.h delete mode 160000 Minilibx diff --git a/Libft/Makefile b/Libft/Makefile deleted file mode 100644 index fa0de42..0000000 --- a/Libft/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -NAME = libft.a - -SRC = ft_atoi.c ft_bzero.c ft_calloc.c ft_isalnum.c ft_isalpha.c ft_isascii.c \ -ft_isdigit.c ft_isprint.c ft_memchr.c ft_memcmp.c ft_memcpy.c ft_memmove.c \ -ft_memset.c ft_strchr.c ft_strdup.c ft_strlcat.c ft_strlcpy.c ft_strlen.c \ -ft_strncmp.c ft_strrchr.c ft_tolower.c ft_toupper.c ft_strnstr.c ft_substr.c\ -ft_strjoin.c ft_strtrim.c ft_itoa.c ft_strmapi.c ft_striteri.c ft_putchar_fd.c\ -ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c ft_split.c 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_lstmap.c ft_hexa.c ft_printf.c\ -ft_put.c get_next_line.c get_next_line_utils.c - -OBJS = ${SRC:.c=.o} - -CC = gcc - -CFLAGS = -Wall -Werror -Wextra - -all: $(NAME) - -$(NAME): ${OBJS} - ar rc ${NAME} ${OBJS} - -clean : - rm -f ${OBJS} - -fclean : clean - rm -f $(NAME) - -re : fclean all diff --git a/Libft/ft_atoi.c b/Libft/ft_atoi.c deleted file mode 100644 index 8504ede..0000000 --- a/Libft/ft_atoi.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_atoi.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/04 14:30:22 by grobledo #+# #+# */ -/* Updated: 2023/02/04 14:30:24 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -int ft_atoi(const char *str) -{ - int i; - int is_neg; - int number; - - i = 0; - is_neg = 1; - number = 0; - while ((str[i] >= 9 && str[i] <= 13) || str[i] == 32) - i++; - if (str[i] == '-' || str[i] == '+') - { - if (str[i] == '-') - is_neg *= -1; - i++; - } - while (str [i] >= '0' && str[i] <= '9') - number = (number * 10) + str[i++] - 48; - return (number * is_neg); -} diff --git a/Libft/ft_bzero.c b/Libft/ft_bzero.c deleted file mode 100644 index b322d22..0000000 --- a/Libft/ft_bzero.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_bzero.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/08 14:32:10 by grobledo #+# #+# */ -/* Updated: 2023/02/08 14:32:22 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_bzero(void *s, size_t n) -{ - unsigned char *str; - size_t i; - - i = 0; - str = s; - while (i < n) - { - str[i] = 0; - i++; - } -} diff --git a/Libft/ft_calloc.c b/Libft/ft_calloc.c deleted file mode 100644 index ca1c5d6..0000000 --- a/Libft/ft_calloc.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_calloc.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/08 19:35:13 by grobledo #+# #+# */ -/* Updated: 2023/02/08 19:35:23 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void *ft_calloc(size_t count, size_t size) -{ - void *str; - size_t tmp; - - tmp = size * count; - if (size == 0 || count == 0) - return (malloc(0)); - if (tmp / count != size) - return (NULL); - str = malloc(size * count); - if (str == NULL) - return (NULL); - ft_bzero (str, size * count); - return (str); -} diff --git a/Libft/ft_hexa.c b/Libft/ft_hexa.c deleted file mode 100644 index a439086..0000000 --- a/Libft/ft_hexa.c +++ /dev/null @@ -1,64 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_hexa.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/04/04 09:38:27 by grobledo #+# #+# */ -/* Updated: 2023/04/04 09:38:28 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -int ft_hexa(unsigned int args, char format, int count) -{ - char *base; - char *shiftbase; - - base = "0123456789abcdef"; - shiftbase = "0123456789ABCDEF"; - if (format == 'x') - { - if (args >= 16) - count = ft_hexa(args / 16, format, count); - count = ft_putcharf(base[args % 16], count); - return (count); - } - if (format == 'X') - { - if (args >= 16) - count = ft_hexa(args / 16, format, count); - count = ft_putcharf(shiftbase[args % 16], count); - return (count); - } - return (0); -} - -int ft_starthexa(unsigned int args, char format, int count) -{ - if (!args && (format == 'x' || format == 'X')) - return (ft_putcharf('0', count)); - count = ft_hexa(args, format, count); - return (count); -} - -int ft_startpointer(unsigned long long int args, char format, int count) -{ - if (!args) - return (ft_putstrf("(nil)", count)); - count = ft_putstrf("0x", count); - count = ft_pointer(args, format, count); - return (count); -} - -int ft_pointer(unsigned long long int args, char format, int count) -{ - char *base; - - base = "0123456789abcdef"; - if (args >= 16) - count = ft_pointer(args / 16, format, count); - count = ft_putcharf(base[args % 16], count); - return (count); -} diff --git a/Libft/ft_isalnum.c b/Libft/ft_isalnum.c deleted file mode 100644 index f5a8ec6..0000000 --- a/Libft/ft_isalnum.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isalnum.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/02 18:17:39 by grobledo #+# #+# */ -/* Updated: 2023/02/02 18:17:41 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -int ft_isalnum(int c) -{ - if (ft_isalpha(c) || ft_isdigit(c)) - return (1); - return (0); -} diff --git a/Libft/ft_isalpha.c b/Libft/ft_isalpha.c deleted file mode 100644 index 351bf89..0000000 --- a/Libft/ft_isalpha.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isalpha.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/02 17:36:30 by grobledo #+# #+# */ -/* Updated: 2023/02/02 17:36:34 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -int ft_isalpha(int c) -{ - if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) - return (1); - return (0); -} diff --git a/Libft/ft_isascii.c b/Libft/ft_isascii.c deleted file mode 100644 index f95ded8..0000000 --- a/Libft/ft_isascii.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isascii.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/02 18:20:38 by grobledo #+# #+# */ -/* Updated: 2023/02/02 18:20:40 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -int ft_isascii(int c) -{ - if (c >= 0 && c <= 127) - return (1); - return (0); -} diff --git a/Libft/ft_isdigit.c b/Libft/ft_isdigit.c deleted file mode 100644 index beb94d6..0000000 --- a/Libft/ft_isdigit.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isdigit.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/02 17:48:20 by grobledo #+# #+# */ -/* Updated: 2023/02/02 17:48:22 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -int ft_isdigit(int c) -{ - if (c >= '0' && c <= '9') - return (1); - return (0); -} diff --git a/Libft/ft_isprint.c b/Libft/ft_isprint.c deleted file mode 100644 index acaa9b7..0000000 --- a/Libft/ft_isprint.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isprint.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/02 18:27:24 by grobledo #+# #+# */ -/* Updated: 2023/02/02 18:27:25 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -int ft_isprint(int c) -{ - if (c >= 32 && c <= 126) - return (1); - return (0); -} diff --git a/Libft/ft_itoa.c b/Libft/ft_itoa.c deleted file mode 100644 index 3f1cdf6..0000000 --- a/Libft/ft_itoa.c +++ /dev/null @@ -1,62 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_itoa.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/19 19:32:47 by grobledo #+# #+# */ -/* Updated: 2023/02/19 19:32:48 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -int countsize(int nb) -{ - long int temp; - int size; - - size = 0; - temp = nb; - if (nb < 0) - { - temp = -nb; - size = size +1; - } - while (temp > 9) - { - temp = (temp / 10); - size++; - } - size++; - return (size); -} - -char *ft_itoa(int nb) -{ - long int temp; - char *res; - int size; - - if (nb == -2147483648) - return (ft_strdup("-2147483648")); - temp = nb; - size = countsize(nb); - res = ft_calloc(size + 1, sizeof (char)); - if (!res) - return (NULL); - if (nb < 0) - { - res[0] = '-'; - temp *= -1; - } - if (nb == 0) - res[0] = '0'; - while (temp > 0) - { - res[size - 1] = (temp % 10 + 48); - size--; - temp /= 10; - } - return (res); -} diff --git a/Libft/ft_lstadd_back.c b/Libft/ft_lstadd_back.c deleted file mode 100644 index fd2389e..0000000 --- a/Libft/ft_lstadd_back.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstadd_back.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/23 11:38:44 by grobledo #+# #+# */ -/* Updated: 2023/02/23 11:38:46 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_lstadd_back(t_list **lst, t_list *new) -{ - t_list *temp; - - if (!new) - return ; - if (!*lst) - { - *lst = new; - return ; - } - else - { - temp = ft_lstlast(*lst); - temp->next = new; - } -} diff --git a/Libft/ft_lstadd_front.c b/Libft/ft_lstadd_front.c deleted file mode 100644 index a24ae19..0000000 --- a/Libft/ft_lstadd_front.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstadd_front.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/21 23:42:28 by grobledo #+# #+# */ -/* Updated: 2023/02/21 23:42:30 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_lstadd_front(t_list **lst, t_list *new) -{ - new->next = *lst; - *lst = new; -} diff --git a/Libft/ft_lstclear.c b/Libft/ft_lstclear.c deleted file mode 100644 index 3d8d38d..0000000 --- a/Libft/ft_lstclear.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstclear.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/23 22:05:11 by grobledo #+# #+# */ -/* Updated: 2023/02/23 22:05:12 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_lstclear(t_list **lst, void (*del)(void*)) -{ - t_list *next; - t_list *current; - - if (lst == NULL || del == NULL || *lst == NULL) - return ; - current = *lst; - while (current != NULL) - { - next = current->next; - del(current->content); - free(current); - current = next; - } - *lst = NULL; -} diff --git a/Libft/ft_lstdelone.c b/Libft/ft_lstdelone.c deleted file mode 100644 index da37e72..0000000 --- a/Libft/ft_lstdelone.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstdelone.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/23 20:15:05 by grobledo #+# #+# */ -/* Updated: 2023/02/23 20:15:06 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_lstdelone(t_list *lst, void (*del)(void*)) -{ - if (!lst) - return ; - if (!del) - return ; - del(lst->content); - free(lst); -} diff --git a/Libft/ft_lstiter.c b/Libft/ft_lstiter.c deleted file mode 100644 index 67041a2..0000000 --- a/Libft/ft_lstiter.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstiter.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/23 22:42:44 by grobledo #+# #+# */ -/* Updated: 2023/02/23 22:42:45 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_lstiter(t_list *lst, void (*f)(void *)) -{ - t_list *node; - - node = lst; - if (lst == NULL || f == NULL) - return ; - node = lst; - while (node != NULL) - { - f(node->content); - node = node->next; - } -} diff --git a/Libft/ft_lstlast.c b/Libft/ft_lstlast.c deleted file mode 100644 index 9024c06..0000000 --- a/Libft/ft_lstlast.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstlast.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/23 10:27:02 by grobledo #+# #+# */ -/* Updated: 2023/02/23 10:27:07 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -t_list *ft_lstlast(t_list *lst) -{ - if (!lst) - return (NULL); - while (lst->next) - lst = lst->next; - return (lst); -} diff --git a/Libft/ft_lstmap.c b/Libft/ft_lstmap.c deleted file mode 100644 index 8329e15..0000000 --- a/Libft/ft_lstmap.c +++ /dev/null @@ -1,41 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstmap.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/24 11:59:12 by grobledo #+# #+# */ -/* Updated: 2023/02/24 11:59:13 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -t_list *ft_lstmap(t_list *lst, void *(f)(void *), void (*del)(void *)) -{ - t_list *new; - t_list *current; - - if (!lst || !f ||!del) - return (NULL); - new = ft_lstnew(NULL); - if (!new) - return (NULL); - current = new; - while (lst) - { - current->content = f(lst->content); - if (lst->next) - { - current->next = ft_lstnew(NULL); - if (!current) - { - ft_lstclear(&new, del); - return (NULL); - } - current = current ->next; - } - lst = lst->next; - } - return (new); -} diff --git a/Libft/ft_lstnew.c b/Libft/ft_lstnew.c deleted file mode 100644 index 1cf613c..0000000 --- a/Libft/ft_lstnew.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstnew.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/21 19:40:32 by grobledo #+# #+# */ -/* Updated: 2023/02/21 22:58:42 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -t_list *ft_lstnew(void *content) -{ - t_list *new; - - new = malloc(sizeof(t_list)); - if (new == 0) - return (NULL); - new->content = content; - new->next = NULL; - return (new); -} diff --git a/Libft/ft_lstsize.c b/Libft/ft_lstsize.c deleted file mode 100644 index c489c1a..0000000 --- a/Libft/ft_lstsize.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstsize.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/23 10:14:39 by grobledo #+# #+# */ -/* Updated: 2023/02/23 10:14:41 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -int ft_lstsize(t_list *lst) -{ - int i; - - i = 0; - while (lst) - { - lst = lst->next; - i++; - } - return (i); -} diff --git a/Libft/ft_memchr.c b/Libft/ft_memchr.c deleted file mode 100644 index 6a35922..0000000 --- a/Libft/ft_memchr.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memchr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/08 20:08:44 by grobledo #+# #+# */ -/* Updated: 2023/02/08 20:08:45 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void *ft_memchr(const void *str, int c, size_t n) -{ - size_t i; - - i = 0; - while (i < n) - { - if ((((unsigned char *)str)[i]) == (unsigned char)c) - return ((void *)str + i); - i++; - } - return (NULL); -} diff --git a/Libft/ft_memcmp.c b/Libft/ft_memcmp.c deleted file mode 100644 index 112ccee..0000000 --- a/Libft/ft_memcmp.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memcmp.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/08 20:15:03 by grobledo #+# #+# */ -/* Updated: 2023/02/08 20:15:05 by grobledo ### ########.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_memcpy.c b/Libft/ft_memcpy.c deleted file mode 100644 index 407ca30..0000000 --- a/Libft/ft_memcpy.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memcpy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/08 15:04:22 by grobledo #+# #+# */ -/* Updated: 2023/02/08 15:04:24 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void *ft_memcpy(void *dest, const void *src, size_t n) -{ - int i; - - if (!dest && !src) - return (NULL); - i = 0; - while (n != 0) - { - ((unsigned char *)dest)[i] = ((unsigned char *)src)[i]; - i++; - n--; - } - return ((void *)dest); -} diff --git a/Libft/ft_memmove.c b/Libft/ft_memmove.c deleted file mode 100644 index c6e9153..0000000 --- a/Libft/ft_memmove.c +++ /dev/null @@ -1,39 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memmove.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/10 10:32:23 by grobledo #+# #+# */ -/* Updated: 2023/02/10 10:32:25 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void *ft_memmove(void *dest, const void *src, size_t n) -{ - size_t i; - - if (!dest && !src) - return (NULL); - i = 0; - if (dest < src) - { - while (n--) - { - (((unsigned char *)dest)[i]) = (((unsigned char *)src)[i]); - i++; - } - } - else - { - i = i + n - 1; - while (n--) - { - (((unsigned char *)dest)[i]) = (((unsigned char *)src)[i]); - i--; - } - } - return ((void *)dest); -} diff --git a/Libft/ft_memset.c b/Libft/ft_memset.c deleted file mode 100644 index ca28cfe..0000000 --- a/Libft/ft_memset.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memset.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/02 18:40:30 by grobledo #+# #+# */ -/* Updated: 2023/02/02 18:40:33 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void *ft_memset(void *str, int c, size_t n) -{ - int i; - - i = 0; - while (n != 0) - { - (((unsigned char *)str)[i]) = c; - i++; - n--; - } - return ((void *)str); -} diff --git a/Libft/ft_printf.c b/Libft/ft_printf.c deleted file mode 100644 index f2c233c..0000000 --- a/Libft/ft_printf.c +++ /dev/null @@ -1,63 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_printf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/03/13 10:48:34 by grobledo #+# #+# */ -/* Updated: 2023/03/13 10:48:35 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -int ft_format(const char format, va_list args, int count) -{ - if (format == 'c') - count = ft_putcharf((char)va_arg(args, int), count); - else if (format == 's') - count = ft_putstrf(va_arg(args, char *), count); - else if (format == 'd') - count = ft_putnbrf(va_arg(args, int), count); - else if (format == 'i') - count = ft_putnbrf(va_arg(args, int), count); - else if (format == 'u') - count = ft_putnbrposf(va_arg(args, unsigned int), count); - else if (format == 'x') - count = ft_starthexa (va_arg(args, unsigned int), 'x', count); - else if (format == 'X') - count = ft_starthexa (va_arg(args, unsigned int), 'X', count); - else if (format == 'p') - count = ft_startpointer - (va_arg(args, unsigned long long int), 'p', count); - else if (format == '%') - count = ft_putcharf('%', count); - return (count); -} - -int ft_printf(const char *format, ...) -{ - va_list args; - int i; - int count; - - va_start(args, format); - i = 0; - count = 0; - while (format[i]) - { - if (format[i] != '%') - { - write(1, &format[i], 1); - count++; - } - else - { - i++; - count = ft_format(format[i], args, count); - } - i++; - } - va_end(args); - return (count); -} diff --git a/Libft/ft_put.c b/Libft/ft_put.c deleted file mode 100644 index b29ff4d..0000000 --- a/Libft/ft_put.c +++ /dev/null @@ -1,75 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_put.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/04/13 10:26:43 by grobledo #+# #+# */ -/* Updated: 2023/04/13 10:26:45 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -int ft_putcharf(char c, int count) -{ - write(1, &c, 1); - count++; - return (count); -} - -int ft_putnbrf(int n, int count) -{ - if (n == -2147483648) - { - (write(1, "-2147483648", 11)); - count += 11; - return (count); - } - if (n < 0) - { - count = ft_putcharf('-', count); - n *= -1; - count = ft_putnbrf(n, count); - } - else if (n >= 10) - { - count = ft_putnbrf(n / 10, count); - count = ft_putnbrf(n % 10, count); - } - else - { - count = ft_putcharf(n + '0', count); - } - return (count); -} - -int ft_putnbrposf(unsigned int n, int count) -{ - if (n >= 10) - { - count = ft_putnbrposf(n / 10, count); - count = ft_putnbrposf(n % 10, count); - } - else - { - count = ft_putcharf(n + '0', count); - } - return (count); -} - -int ft_putstrf(char *s, int count) -{ - int i; - - if (!s) - return (ft_putstrf("(null)", count)); - i = 0; - while (s[i]) - { - write(1, &s[i], 1); - i++; - count++; - } - return (count); -} diff --git a/Libft/ft_putchar_fd.c b/Libft/ft_putchar_fd.c deleted file mode 100644 index 33fe262..0000000 --- a/Libft/ft_putchar_fd.c +++ /dev/null @@ -1,17 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putchar_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/20 23:21:04 by grobledo #+# #+# */ -/* Updated: 2023/02/20 23:21:05 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_putchar_fd(char c, int fd) -{ - write(fd, &c, 1); -} diff --git a/Libft/ft_putendl_fd.c b/Libft/ft_putendl_fd.c deleted file mode 100644 index bed0653..0000000 --- a/Libft/ft_putendl_fd.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putendl_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/20 23:36:08 by grobledo #+# #+# */ -/* Updated: 2023/02/20 23:36:09 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_putendl_fd(char *s, int fd) -{ - int i; - - if (!s) - return ; - i = 0; - while (s[i]) - { - write(fd, &s[i], 1); - i++; - } - ft_putchar_fd('\n', fd); -} diff --git a/Libft/ft_putnbr_fd.c b/Libft/ft_putnbr_fd.c deleted file mode 100644 index 89e7851..0000000 --- a/Libft/ft_putnbr_fd.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putnbr_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/20 23:43:01 by grobledo #+# #+# */ -/* Updated: 2023/02/20 23:43:02 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_putnbr_fd(int n, int fd) -{ - if (n == -2147483648) - { - write(fd, "-2147483648", 11); - } - else if (n < 0) - { - ft_putchar_fd('-', fd); - n *= -1; - ft_putnbr_fd(n, fd); - } - else if (n >= 10) - { - ft_putnbr_fd(n / 10, fd); - ft_putnbr_fd(n % 10, fd); - } - else - ft_putchar_fd(n + '0', fd); -} diff --git a/Libft/ft_putstr_fd.c b/Libft/ft_putstr_fd.c deleted file mode 100644 index 7a53068..0000000 --- a/Libft/ft_putstr_fd.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putstr_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/20 23:29:21 by grobledo #+# #+# */ -/* Updated: 2023/02/20 23:29:26 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_putstr_fd(char *s, int fd) -{ - int i; - - if (!s) - return ; - i = 0; - while (s[i]) - { - write(fd, &s[i], 1); - i++; - } -} diff --git a/Libft/ft_split.c b/Libft/ft_split.c deleted file mode 100644 index f48337c..0000000 --- a/Libft/ft_split.c +++ /dev/null @@ -1,78 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_split.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/21 11:11:19 by grobledo #+# #+# */ -/* Updated: 2023/02/21 18:03:11 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -int ft_countword(const char *s, char c) -{ - int i; - int j; - - i = 0; - j = 0; - while (s[i]) - { - while (s[i] == c) - i++; - if (s[i] != '\0') - j++; - while (s[i] != c && s[i]) - i++; - } - return (j); -} - -char *ft_strdup_modif(const char *s, char c, size_t i) -{ - size_t k; - char *dest; - - k = 0; - while (s[i + k] && s[i + k] != c) - k++; - dest = ft_calloc(sizeof(char), (k + 1)); - k = 0; - if (dest == 0) - return (NULL); - while (s[i + k] && s[i + k] != c) - { - dest[k] = s[i + k]; - k++; - } - return (dest); -} - -char **ft_split(const char *s, char c) -{ - size_t i; - size_t j; - char **res; - - if (!s) - return (NULL); - res = ft_calloc(sizeof (char *), (ft_countword(s, c) + 1)); - if (!res) - return (NULL); - i = 0; - j = 0; - while (s[i]) - { - while (s[i] == c) - i++; - if (s[i] == '\0') - break ; - res[j] = ft_strdup_modif(s, c, i); - j++; - while (s[i] != c && s[i]) - i++; - } - return (res); -} diff --git a/Libft/ft_strchr.c b/Libft/ft_strchr.c deleted file mode 100644 index 8bb7eee..0000000 --- a/Libft/ft_strchr.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strchr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/04 12:59:29 by grobledo #+# #+# */ -/* Updated: 2023/02/04 12:59:31 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -char *ft_strchr(const char *str, int tofind) -{ - int i; - - i = 0; - while (str[i]) - { - if ((unsigned char)str[i] == (unsigned char)tofind) - return ((char *)&str[i]); - i++; - } - if (tofind == '\0') - return ((char *)&str[i]); - return (0); -} diff --git a/Libft/ft_strdup.c b/Libft/ft_strdup.c deleted file mode 100644 index b743a62..0000000 --- a/Libft/ft_strdup.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strdup.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/08 20:55:55 by grobledo #+# #+# */ -/* Updated: 2023/02/13 21:30:44 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -char *ft_strdup(const char *src) -{ - size_t size; - char *dest; - - size = ft_strlen(src); - dest = (char *)malloc(size + 1); - if (dest == 0) - return (NULL); - ft_strlcpy(dest, src, size + 1); - return (dest); -} diff --git a/Libft/ft_striteri.c b/Libft/ft_striteri.c deleted file mode 100644 index 934c9d8..0000000 --- a/Libft/ft_striteri.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_striteri.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/20 22:29:06 by grobledo #+# #+# */ -/* Updated: 2023/02/20 22:29:07 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_striteri(char *s, void (*f)(unsigned int, char*)) -{ - size_t i; - - if (!s || !(*f)) - return ; - i = 0; - while (i < ft_strlen(s)) - { - (*f)(i, &s[i]); - i++; - } -} diff --git a/Libft/ft_strjoin.c b/Libft/ft_strjoin.c deleted file mode 100644 index 735da25..0000000 --- a/Libft/ft_strjoin.c +++ /dev/null @@ -1,41 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strjoin.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/14 16:41:00 by grobledo #+# #+# */ -/* Updated: 2023/02/14 16:41:02 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -char *ft_strjoin(char const *s1, char const *s2) -{ - size_t i; - size_t j; - char *dest; - - if (!s1 || !s2) - return (NULL); - dest = ft_calloc ((ft_strlen(s1) + ft_strlen(s2) + 1), sizeof (char)); - if (dest == 0) - return (NULL); - i = 0; - j = 0; - while (s1[i] || s2[j]) - { - while (i < ft_strlen(s1)) - { - dest[i] = s1[i]; - i++; - } - while (j < ft_strlen(s2)) - { - dest[i + j] = s2[j]; - j++; - } - } - return (dest); -} diff --git a/Libft/ft_strlcat.c b/Libft/ft_strlcat.c deleted file mode 100644 index 89ae6b0..0000000 --- a/Libft/ft_strlcat.c +++ /dev/null @@ -1,37 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strlcat.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/02 19:33:00 by grobledo #+# #+# */ -/* Updated: 2023/02/02 19:33:01 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -int ft_strlcat(char *dest, const char *src, size_t size) -{ - unsigned int i; - unsigned int j; - unsigned int dlen; - unsigned int slen; - - if ((dest == NULL || src == NULL) && size == 0) - return (0); - i = 0; - j = ft_strlen(dest); - dlen = j; - slen = ft_strlen(src); - if (size <= dlen) - return (slen + size); - while (src[i] != '\0' && i < size - dlen - 1) - { - dest[j] = src[i]; - i++; - j++; - } - dest[j] = '\0'; - return (dlen + slen); -} diff --git a/Libft/ft_strlcpy.c b/Libft/ft_strlcpy.c deleted file mode 100644 index 5201ec0..0000000 --- a/Libft/ft_strlcpy.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strlcpy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/02 19:33:21 by grobledo #+# #+# */ -/* Updated: 2023/02/02 19:33:24 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -int ft_strlcpy(char *dest, const char *src, size_t size) -{ - unsigned int i; - - i = 0; - if (size == 0) - return (ft_strlen(src)); - while (src[i] && i < size - 1) - { - dest[i] = src[i]; - i++; - } - dest[i] = '\0'; - return (ft_strlen(src)); -} diff --git a/Libft/ft_strlen.c b/Libft/ft_strlen.c deleted file mode 100644 index 45c7ee9..0000000 --- a/Libft/ft_strlen.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strlen.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/02 18:31:38 by grobledo #+# #+# */ -/* Updated: 2023/02/02 18:31:39 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -size_t ft_strlen(const char *str) -{ - size_t i; - - i = 0; - while (str[i]) - { - i++; - } - return (i); -} diff --git a/Libft/ft_strmapi.c b/Libft/ft_strmapi.c deleted file mode 100644 index 6ce2ee1..0000000 --- a/Libft/ft_strmapi.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strmapi.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/20 21:51:01 by grobledo #+# #+# */ -/* Updated: 2023/02/20 21:51:02 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) -{ - size_t i; - size_t dlen; - char *dest; - - if (!s || !(*f)) - return (NULL); - i = 0; - dlen = ft_strlen(s); - dest = ft_calloc(dlen + 1, sizeof (char)); - if (!dest) - return (NULL); - while (i < ft_strlen(s)) - { - dest[i] = (*f)(i, s[i]); - i++; - } - return (dest); -} diff --git a/Libft/ft_strncmp.c b/Libft/ft_strncmp.c deleted file mode 100644 index 8a35309..0000000 --- a/Libft/ft_strncmp.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strncmp.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/04 14:33:04 by grobledo #+# #+# */ -/* Updated: 2023/02/04 14:33:06 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -int ft_strncmp(const char *s1, const char *s2, size_t size) -{ - size_t i; - - i = 0; - while ((s1[i] || s2[i]) && (i < size)) - { - if (s1[i] != s2[i]) - return (((unsigned char)(s1[i]) - ((unsigned char)s2[i]))); - i++; - } - return (0); -} diff --git a/Libft/ft_strnstr.c b/Libft/ft_strnstr.c deleted file mode 100644 index 1a8660a..0000000 --- a/Libft/ft_strnstr.c +++ /dev/null @@ -1,38 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strnstr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/13 22:07:12 by grobledo #+# #+# */ -/* Updated: 2023/02/13 22:07:14 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -char *ft_strnstr(const char *big, const char *little, size_t len) -{ - size_t i; - size_t j; - - if ((big == NULL || little == NULL) && !len) - return (0); - i = 0; - j = 0; - if (little[i] == '\0') - return ((char *)big); - while (big[i] && i < len) - { - if (big[i] == little[j]) - { - while (big[i + j] == little[j] && (i + j) < len && little[j]) - j++; - if (little[j] == '\0') - return ((char *)&big[i]); - j = 0; - } - i++; - } - return (NULL); -} diff --git a/Libft/ft_strrchr.c b/Libft/ft_strrchr.c deleted file mode 100644 index c1fb9e4..0000000 --- a/Libft/ft_strrchr.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strrchr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/04 14:00:32 by grobledo #+# #+# */ -/* Updated: 2023/02/13 21:32:54 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -char *ft_strrchr(const char *str, int tofind) -{ - int i; - - i = 0; - while (str[i]) - i++; - while (i >= 0) - { - if ((unsigned char)str[i] == (unsigned char)tofind) - return ((char *)&str[i]); - i--; - } - return (0); -} diff --git a/Libft/ft_strtrim.c b/Libft/ft_strtrim.c deleted file mode 100644 index 02a14e6..0000000 --- a/Libft/ft_strtrim.c +++ /dev/null @@ -1,40 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strtrim.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/18 18:34:05 by grobledo #+# #+# */ -/* Updated: 2023/02/18 18:34:08 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -char *ft_strtrim(const char *s1, const char *set) -{ - size_t i; - size_t j; - size_t k; - size_t dlen; - char *dest; - - if (!s1) - return (NULL); - i = 0; - j = ft_strlen(s1); - k = -1; - while (ft_strchr(set, s1[i]) != 0 && s1[i]) - i++; - if (!s1[i]) - return (ft_strdup("")); - while (ft_strchr(set, s1[j]) != 0 && j > 0) - j--; - dlen = (j - i); - dest = ft_calloc ((dlen + 2), sizeof (char)); - if (dest == 0) - return (NULL); - while (++k <= dlen) - dest[k] = s1[i + k]; - return (dest); -} diff --git a/Libft/ft_substr.c b/Libft/ft_substr.c deleted file mode 100644 index 22c55ea..0000000 --- a/Libft/ft_substr.c +++ /dev/null @@ -1,39 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_substr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/14 14:52:48 by grobledo #+# #+# */ -/* Updated: 2023/02/14 14:52:51 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -char *ft_substr(const char *s, unsigned int start, size_t len) -{ - size_t i; - size_t j; - char *dest; - - if (!s) - return (NULL); - i = start; - j = 0; - if (start >= ft_strlen(s)) - return (ft_calloc(1, 1)); - if (ft_strlen(s + start) < len) - dest = (char *)ft_calloc((ft_strlen(s + start) + 1), sizeof(char)); - else - dest = (char *)ft_calloc((len + 1), sizeof(char)); - if (dest == 0) - return (NULL); - while (j < len && s[i]) - { - dest[j] = s[i]; - i++; - j++; - } - return (dest); -} diff --git a/Libft/ft_tolower.c b/Libft/ft_tolower.c deleted file mode 100644 index 7eae236..0000000 --- a/Libft/ft_tolower.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_tolower.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/02 20:49:29 by grobledo #+# #+# */ -/* Updated: 2023/02/02 20:49:30 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -int ft_tolower(int c) -{ - if (c >= 65 && c <= 90) - c += 32; - return (c); -} diff --git a/Libft/ft_toupper.c b/Libft/ft_toupper.c deleted file mode 100644 index 2f7e5f2..0000000 --- a/Libft/ft_toupper.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_toupper.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/02 20:19:23 by grobledo #+# #+# */ -/* Updated: 2023/02/02 20:19:25 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -int ft_toupper(int c) -{ - if (c >= 97 && c <= 122) - c -= 32; - return (c); -} diff --git a/Libft/get_next_line.c b/Libft/get_next_line.c deleted file mode 100644 index da04a89..0000000 --- a/Libft/get_next_line.c +++ /dev/null @@ -1,110 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_next_line.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/05/05 20:41:22 by grobledo #+# #+# */ -/* Updated: 2023/05/05 20:41:25 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -char *ft_join( char *buffer, char *buff_read) -{ - char *temp; - - temp = ft_strjoing(buffer, buff_read); - free (buffer); - return (temp); -} - -char *ft_nextline(char *buffer) -{ - int i; - int j; - char *nextline; - - i = 0; - while (buffer[i] && buffer[i] != '\n') - i++; - if (buffer[i] == '\n') - i++; - if (!buffer[i]) - { - free (buffer); - return (NULL); - } - j = 0; - nextline = ft_calloc(ft_strleng(buffer) - i + 1, sizeof(char)); - while (buffer[i]) - { - nextline[j++] = buffer[i++]; - } - free (buffer); - return (nextline); -} - -char *ft_line(char *buffer) -{ - char *line; - int i; - - i = 0; - if (!buffer) - return (NULL); - while (buffer[i] && buffer[i] != '\n') - i++; - line = ft_calloc(i + 2, sizeof(char)); - i = 0; - while (buffer[i] && buffer[i] != '\n') - { - line[i] = buffer[i]; - i++; - } - if (buffer[i] && buffer[i] == '\n') - line[i] = '\n'; - return (line); -} - -char *ft_readfile(int fd, char *buffer) -{ - int byte_read; - char *buff_read; - - buff_read = ft_calloc(BUFFER_SIZE + 1, sizeof(char)); - byte_read = 1; - while (byte_read > 0) - { - byte_read = read(fd, buff_read, BUFFER_SIZE); - if (byte_read == 0) - break ; - if (byte_read == -1) - { - free(buff_read); - return (NULL); - } - buff_read[byte_read] = 0; - buffer = ft_join(buffer, buff_read); - if (ft_strrchr(buff_read, '\n')) - break ; - } - free (buff_read); - return (buffer); -} - -char *get_next_line(int fd) -{ - char *line; - static char *buffer = NULL; - - if (fd < 0 || BUFFER_SIZE <= 0 || read(fd, 0, 0) < 0) - return (NULL); - buffer = ft_readfile(fd, buffer); - if (!buffer) - return (NULL); - line = ft_line(buffer); - buffer = ft_nextline(buffer); - return (line); -} diff --git a/Libft/get_next_line_utils.c b/Libft/get_next_line_utils.c deleted file mode 100644 index 6878058..0000000 --- a/Libft/get_next_line_utils.c +++ /dev/null @@ -1,53 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_next_line_utils.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/05/05 20:41:39 by grobledo #+# #+# */ -/* Updated: 2023/05/05 20:41:41 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -size_t ft_strleng(const char *str) -{ - size_t i; - - i = 0; - while (str && str[i]) - { - i++; - } - return (i); -} - -char *ft_strjoing(char const *s1, char const *s2) -{ - size_t i; - size_t j; - char *dest; - - if (!s2) - return (NULL); - dest = ft_calloc ((ft_strleng(s1) + ft_strleng(s2) + 1), sizeof (char)); - if (dest == 0) - return (NULL); - i = 0; - j = 0; - while (s2[j]) - { - while (i < ft_strleng(s1)) - { - dest[i] = s1[i]; - i++; - } - while (j < ft_strleng(s2)) - { - dest[i + j] = s2[j]; - j++; - } - } - return (dest); -} diff --git a/Libft/libft.h b/Libft/libft.h deleted file mode 100644 index c98ec10..0000000 --- a/Libft/libft.h +++ /dev/null @@ -1,89 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* libft.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/02/10 12:14:34 by grobledo #+# #+# */ -/* Updated: 2023/02/13 21:31:19 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ -#ifndef LIBFT_H -# define LIBFT_H -# include -# include -# include -# include -# include -# include -# include - -# ifndef BUFFER_SIZE -# define BUFFER_SIZE 10000 -# endif - -typedef struct s_list -{ - void *content; - struct s_list *next; -} t_list; - -int ft_atoi(const char *str); -void ft_bzero(void *s, size_t n); -void *ft_calloc(size_t count, size_t size); -int ft_isalnum(int c); -int ft_isalpha(int c); -int ft_isascii(int c); -int ft_isdigit(int c); -int ft_isprint(int c); -void *ft_memchr(const void *str, int c, size_t n); -int ft_memcmp(const void *s1, const void *s2, size_t n); -void *ft_memcpy(void *dest, const void *src, size_t n); -void *ft_memmove(void *dest, const void *src, size_t n); -void *ft_memset(void *str, int c, size_t n); -char *ft_strchr(const char *str, int tofind); -char *ft_strdup(const char *src); -int ft_strlcat(char *dest, const char *src, size_t size); -int ft_strlcpy(char *dest, const char *src, size_t size); -size_t ft_strlen(const char *str); -int ft_strncmp(const char *s1, const char *s2, size_t size); -char *ft_strrchr(const char *str, int tofind); -int ft_tolower(int c); -int ft_toupper(int c); -char *ft_strnstr(const char *big, const char *little, size_t len); -char *ft_substr(char const *s, unsigned int start, size_t len); -char *ft_strjoin(char const *s1, char const *s2); -char *ft_strtrim(const char *s1, const char *set); -char *ft_itoa(int nb); -char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); -void ft_striteri(char *s, void (*f)(unsigned int, char*)); -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); -char **ft_split(const char *s, char c); -t_list *ft_lstnew(void *content); -void ft_lstadd_front(t_list **lst, t_list *new); -int ft_lstsize(t_list *lst); -t_list *ft_lstlast(t_list *lst); -void ft_lstadd_back(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 *)); -t_list *ft_lstmap(t_list *lst, void *(f)(void *), void (*del)(void *)); -int ft_hexa(unsigned int args, char format, int count); -int ft_format(const char format, va_list args, int count); -int ft_printf(const char *format, ...); -int ft_putstrf(char *s, int count); -int ft_putcharf(char c, int count); -int ft_putnbrposf(unsigned int n, int count); -int ft_putnbrf(int n, int count); -int ft_starthexa(unsigned int args, char format, int count); -int ft_pointer(unsigned long long int args, char format, int count); -int ft_startpointer(unsigned long long int args, char format, int count); -char *get_next_line(int fd); -size_t ft_strleng(const char *str); -char *ft_strjoing(char const *s1, char const *s2); -#endif diff --git a/Minilibx b/Minilibx deleted file mode 160000 index 7dc53a4..0000000 --- a/Minilibx +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7dc53a411a7d4ae286c60c6229bd1e395b0efb82 From 40d8462689da9ecb74427efb99277e1ae1bf98de Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 10 Oct 2024 13:34:24 +0200 Subject: [PATCH 09/80] Add map checks * add: - check if map is surronded by walls - check file extension dev: - Makefile: now can include libraries - add library libft - add testmaps - norm --- Makefile | 18 +- include/map.h | 11 +- include/util.h | 5 +- libft/Makefile | 47 +++++ libft/ft_atoi.c | 50 +++++ libft/ft_bzero.c | 18 ++ libft/ft_calloc.c | 29 +++ libft/ft_isalnum.c | 18 ++ libft/ft_isalpha.c | 16 ++ libft/ft_isascii.c | 16 ++ libft/ft_isdigit.c | 16 ++ libft/ft_isprint.c | 16 ++ libft/ft_itoa.c | 67 ++++++ libft/ft_lstadd_back.c | 24 +++ libft/ft_lstadd_front.c | 19 ++ libft/ft_lstclear.c | 25 +++ libft/ft_lstdelone.c | 22 ++ libft/ft_lstiter.c | 22 ++ libft/ft_lstlast.c | 22 ++ libft/ft_lstmap.c | 38 ++++ libft/ft_lstnew.c | 26 +++ libft/ft_lstsize.c | 26 +++ libft/ft_memchr.c | 28 +++ libft/ft_memcmp.c | 25 +++ libft/ft_memcpy.c | 30 +++ libft/ft_memmove.c | 31 +++ libft/ft_memset.c | 28 +++ libft/ft_putchar_fd.c | 18 ++ libft/ft_putendl_fd.c | 20 ++ libft/ft_putnbr_fd.c | 40 ++++ libft/ft_putstr_fd.c | 19 ++ libft/ft_split.c | 98 +++++++++ libft/ft_strchr.c | 29 +++ libft/ft_strdup.c | 35 ++++ libft/ft_striteri.c | 25 +++ libft/ft_strjoin.c | 42 ++++ libft/ft_strlcat.c | 44 ++++ libft/ft_strlcpy.c | 30 +++ libft/ft_strlen.c | 23 ++ libft/ft_strmapi.c | 32 +++ libft/ft_strncmp.c | 25 +++ libft/ft_strnstr.c | 47 +++++ libft/ft_strrchr.c | 31 +++ libft/ft_strtrim.c | 80 +++++++ libft/ft_substr.c | 41 ++++ libft/ft_tolower.c | 18 ++ libft/ft_toupper.c | 18 ++ libft/libft.h | 196 ++++++++++++++++++ src/main.c | 6 +- src/map.c | 80 ++++++- src/map_mapping.c | 18 +- src/map_utils1.c | 15 +- src/read_all_text.c | 9 +- src/util.c | 15 +- .../{hdhd.cub => err_doubleparameters.cub} | 17 +- testmaps/err_extension.cud | 11 + .../{idid.cub => err_nomapdescription.cub} | 9 - testmaps/err_nonclosed1.cub | 11 + testmaps/err_nonclosed2.cub | 11 + testmaps/err_nonclosed3.cub | 11 + testmaps/err_nonclosed4.cub | 11 + testmaps/good.cub | 11 + testmaps/{jdjd.cub => good_weirdblank.cub} | 0 testmaps/good_weirdshape.cub | 19 ++ 64 files changed, 1786 insertions(+), 72 deletions(-) create mode 100644 libft/Makefile create mode 100644 libft/ft_atoi.c create mode 100644 libft/ft_bzero.c create mode 100644 libft/ft_calloc.c create mode 100644 libft/ft_isalnum.c create mode 100644 libft/ft_isalpha.c create mode 100644 libft/ft_isascii.c create mode 100644 libft/ft_isdigit.c create mode 100644 libft/ft_isprint.c create mode 100644 libft/ft_itoa.c create mode 100644 libft/ft_lstadd_back.c create mode 100644 libft/ft_lstadd_front.c create mode 100644 libft/ft_lstclear.c create mode 100644 libft/ft_lstdelone.c create mode 100644 libft/ft_lstiter.c create mode 100644 libft/ft_lstlast.c create mode 100644 libft/ft_lstmap.c create mode 100644 libft/ft_lstnew.c create mode 100644 libft/ft_lstsize.c create mode 100644 libft/ft_memchr.c create mode 100644 libft/ft_memcmp.c create mode 100644 libft/ft_memcpy.c create mode 100644 libft/ft_memmove.c create mode 100644 libft/ft_memset.c create mode 100644 libft/ft_putchar_fd.c create mode 100644 libft/ft_putendl_fd.c create mode 100644 libft/ft_putnbr_fd.c create mode 100644 libft/ft_putstr_fd.c create mode 100644 libft/ft_split.c create mode 100644 libft/ft_strchr.c create mode 100644 libft/ft_strdup.c create mode 100644 libft/ft_striteri.c create mode 100644 libft/ft_strjoin.c create mode 100644 libft/ft_strlcat.c create mode 100644 libft/ft_strlcpy.c create mode 100644 libft/ft_strlen.c create mode 100644 libft/ft_strmapi.c create mode 100644 libft/ft_strncmp.c create mode 100644 libft/ft_strnstr.c create mode 100644 libft/ft_strrchr.c create mode 100644 libft/ft_strtrim.c create mode 100644 libft/ft_substr.c create mode 100644 libft/ft_tolower.c create mode 100644 libft/ft_toupper.c create mode 100644 libft/libft.h rename testmaps/{hdhd.cub => err_doubleparameters.cub} (80%) create mode 100644 testmaps/err_extension.cud rename testmaps/{idid.cub => err_nomapdescription.cub} (90%) create mode 100644 testmaps/err_nonclosed1.cub create mode 100644 testmaps/err_nonclosed2.cub create mode 100644 testmaps/err_nonclosed3.cub create mode 100644 testmaps/err_nonclosed4.cub create mode 100644 testmaps/good.cub rename testmaps/{jdjd.cub => good_weirdblank.cub} (100%) create mode 100644 testmaps/good_weirdshape.cub diff --git a/Makefile b/Makefile index 255c719..3bfa1b7 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ NAME = cub3D -CPP = gcc -Wall -Wextra -Werror -I include $(FLAGS) -C_FILES = $(wildcard **/*.c) +CPP = gcc -Wall -Wextra -Werror -I include -I libft $(FLAGS) +LIBRARIES_DIR = libft +LIBRARIES_A = libft/libft.a +CPP_2 = $(CPP) $(FLAGS_2) +C_FILES = $(wildcard src/**.c) O_FILES = $(patsubst %.c,%.o,$(C_FILES)) ECHO = echoo(){ \ @@ -13,6 +16,11 @@ ECHO = echoo(){ \ all : $(NAME) +$(LIBRARIES_DIR): + @$(ECHO) + @$(ECHO) "\e[30;47;1m $(NAME): making library $@... \e[0m" + $(MAKE) -C $@ + clean : @$(ECHO) @$(ECHO) "\e[30;47;1m $(NAME): clean... \e[0m" @@ -25,10 +33,10 @@ fclean : clean re : fclean all -$(NAME) : $(O_FILES) +$(NAME) : $(O_FILES) $(LIBRARIES_DIR) @$(ECHO) @$(ECHO) "\e[30;47;1m $(NAME): linking... \e[0m" - $(CPP) $(FLAGS_2) -o $(NAME) $(O_FILES) + $(CPP_2) -o $(NAME) $(O_FILES) $(LIBRARIES_A) @$(ECHO) @$(ECHO) "\t\t \e[0;92m\(^o^)/ \e[0;102;30;1m $(NAME) made! \e[0;92m \(^o^)/\e[0m" @$(ECHO) @@ -58,4 +66,4 @@ check_headers : 2> /dev/null rm __tmp_check_header.out __tmp_check_header.c; \ if [ $$ERROR -eq 0 ]; then true; else false; fi; -.PHONY : all clean fclean re check_headers +.PHONY : all clean fclean re check_headers $(LIBRARIES_DIR) diff --git a/include/map.h b/include/map.h index 2224a3c..7f99713 100644 --- a/include/map.h +++ b/include/map.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */ -/* Updated: 2024/10/04 13:13:04 by mcolonna ### ########.fr */ +/* Updated: 2024/10/10 11:59:39 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,6 +50,9 @@ typedef struct s_object /// @brief Represents a case of the map. typedef struct s_map_case { + /// @brief 'true' if the case is inside of the room (false with ' ' char) + bool inside; + /// @brief Is the case empty or a wall? t_map_wall wall; @@ -103,4 +106,10 @@ bool map_from_file(t_map *dest, const char *file); /// @brief Destroy the map to avoid leaks. void map_destroy(t_map *map); +/// @brief Return true if the map is valid. Write an error message on stderr. +/// +/// @param map The map to check. +/// @return true if the map is valid, false if not. +bool check_map(const t_map *map); + #endif diff --git a/include/util.h b/include/util.h index bab8592..3561fb6 100644 --- a/include/util.h +++ b/include/util.h @@ -6,16 +6,13 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 14:19:03 by mc #+# #+# */ -/* Updated: 2024/10/04 15:27:07 by mcolonna ### ########.fr */ +/* Updated: 2024/10/10 12:37:34 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef UTIL_H # define UTIL_H -/// @brief Get the length of a string. -int getlen(const char *str); - /// @brief Write an error message on stderr. /// /// @param str... All the strings to write. The last parameter MUST BE NULL. diff --git a/libft/Makefile b/libft/Makefile new file mode 100644 index 0000000..432bd30 --- /dev/null +++ b/libft/Makefile @@ -0,0 +1,47 @@ +# The interesting part +NAME = libft.a +SRCS = ./ +INCLUDES = ./ +FUNCTIONS = \ + isalpha isdigit isalnum isascii isprint \ + toupper tolower \ + strncmp strlen strlcpy strlcat strchr strrchr strnstr strdup \ + strmapi striteri substr strjoin strtrim split \ + memset bzero memcpy memmove memchr memcmp calloc \ + atoi itoa \ + putchar_fd putstr_fd putendl_fd putnbr_fd +FUNCTIONS_BONUS = \ + lstnew lstadd_front lstsize lstlast lstadd_back \ + lstdelone lstclear lstiter lstmap +CODE = $(addprefix ft_, $(FUNCTIONS)) +CODE_BONUS = $(addprefix ft_, $(FUNCTIONS_BONUS)) + +# It works and I probably won't change it for the rest of my life +C_FILES = $(addsuffix .c,$(addprefix $(SRCS),$(CODE))) +O_FILES = $(addsuffix .o,$(addprefix $(SRCS),$(CODE))) +C_FILES_BONUS = $(addsuffix .c,$(addprefix $(SRCS),$(CODE_BONUS))) +O_FILES_BONUS = $(addsuffix .o,$(addprefix $(SRCS),$(CODE_BONUS))) +CC = cc -Wall -Wextra -Werror +AR = ar rcs +MAKE = make + +all : $(NAME) + +$(NAME) : $(O_FILES) + $(AR) $(NAME) $(O_FILES) + +%.o : %.c + $(CC) -I $(INCLUDES) -c $< -o $@ + +clean : + rm -f $(O_FILES) $(O_FILES_BONUS) + +fclean : clean + rm -f $(NAME) + +re : fclean all + +bonus : $(O_FILES_BONUS) + $(AR) $(NAME) $(O_FILES_BONUS) + +.PHONY : all clean fclean re bonus diff --git a/libft/ft_atoi.c b/libft/ft_atoi.c new file mode 100644 index 0000000..20d8598 --- /dev/null +++ b/libft/ft_atoi.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/28 17:45:41 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 12:03:52 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +static int is_in(char c, char *chars) +{ + int i; + + i = 0; + while (chars[i]) + { + if (c == chars[i]) + return (1); + i++; + } + return (0); +} + +int ft_atoi(const char *nptr) +{ + int sign; + int i; + int r; + + sign = 1; + i = 0; + r = 0; + while (is_in(nptr[i], " \f\n\r\t\v")) + i++; + if (is_in(nptr[i], "+-")) + { + if (nptr[i] == '-') + sign *= -1; + i++; + } + while (is_in(nptr[i], "0123456789")) + { + r = r * 10 + (nptr[i] - '0'); + i++; + } + return (r * sign); +} diff --git a/libft/ft_bzero.c b/libft/ft_bzero.c new file mode 100644 index 0000000..026084e --- /dev/null +++ b/libft/ft_bzero.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:10:31 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 13:12:35 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_bzero(void *s, size_t n) +{ + ft_memset(s, '\0', n); +} diff --git a/libft/ft_calloc.c b/libft/ft_calloc.c new file mode 100644 index 0000000..c1fd1b0 --- /dev/null +++ b/libft/ft_calloc.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_calloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:41:02 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 15:58:33 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +void *ft_calloc(size_t nmemb, size_t size) +{ + void *dest; + int len; + + if ((long)nmemb * (long)size > (long)INT_MAX) + return (NULL); + len = size * nmemb; + dest = malloc(len); + if (!dest) + return (NULL); + ft_bzero(dest, len); + return (dest); +} diff --git a/libft/ft_isalnum.c b/libft/ft_isalnum.c new file mode 100644 index 0000000..e0492c9 --- /dev/null +++ b/libft/ft_isalnum.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 15:02:39 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalnum(int c) +{ + return (ft_isdigit(c) || ft_isalpha(c)); +} diff --git a/libft/ft_isalpha.c b/libft/ft_isalpha.c new file mode 100644 index 0000000..0719231 --- /dev/null +++ b/libft/ft_isalpha.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */ +/* Updated: 2023/10/02 16:46:27 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isalpha(int c) +{ + return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')); +} diff --git a/libft/ft_isascii.c b/libft/ft_isascii.c new file mode 100644 index 0000000..addccb1 --- /dev/null +++ b/libft/ft_isascii.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */ +/* Updated: 2023/10/02 16:50:28 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isascii(int c) +{ + return ((c >= 0 && c <= 127)); +} diff --git a/libft/ft_isdigit.c b/libft/ft_isdigit.c new file mode 100644 index 0000000..618ea3a --- /dev/null +++ b/libft/ft_isdigit.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */ +/* Updated: 2023/10/02 16:47:07 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isdigit(int c) +{ + return (c >= '0' && c <= '9'); +} diff --git a/libft/ft_isprint.c b/libft/ft_isprint.c new file mode 100644 index 0000000..725a23e --- /dev/null +++ b/libft/ft_isprint.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */ +/* Updated: 2023/10/02 16:51:08 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isprint(int c) +{ + return (c >= 32 && c <= 126); +} diff --git a/libft/ft_itoa.c b/libft/ft_itoa.c new file mode 100644 index 0000000..2b509b5 --- /dev/null +++ b/libft/ft_itoa.c @@ -0,0 +1,67 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:51:10 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 16:49:44 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +static char get_digit_at(long pos_n, int i, int nb_len) +{ + int w; + long ten_power; + + w = nb_len - i - 1; + ten_power = 1; + while (w--) + ten_power *= 10; + return ('0' + pos_n / ten_power % 10); +} + +static int get_nb_len(long pos_n) +{ + int r; + long ten_powers; + + r = 1; + ten_powers = 10; + while (pos_n >= ten_powers) + { + r++; + ten_powers *= 10; + } + return (r); +} + +char *ft_itoa(int n) +{ + long pos_n; + int sign; + int nb_len; + char *dest; + int i; + + sign = (n >= 0) - (n < 0); + pos_n = (long)n * sign; + nb_len = get_nb_len(pos_n); + dest = malloc(((sign == -1) + nb_len + 1) * sizeof(char)); + if (!dest) + return (NULL); + i = 0; + if (sign == -1) + dest[i++] = '-'; + while (i - (sign == -1) < nb_len) + { + dest[i] = get_digit_at(pos_n, i - (sign == -1), nb_len); + i++; + } + dest[i] = '\0'; + return (dest); +} diff --git a/libft/ft_lstadd_back.c b/libft/ft_lstadd_back.c new file mode 100644 index 0000000..f2668da --- /dev/null +++ b/libft/ft_lstadd_back.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_back.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:24:03 by mcolonna #+# #+# */ +/* Updated: 2023/10/05 12:56:42 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstadd_back(t_list **lst, t_list *new) +{ + t_list *last; + + last = ft_lstlast(*lst); + if (last) + last->next = new; + else + *lst = new; +} diff --git a/libft/ft_lstadd_front.c b/libft/ft_lstadd_front.c new file mode 100644 index 0000000..432dffc --- /dev/null +++ b/libft/ft_lstadd_front.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_front.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:19:20 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 16:20:44 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstadd_front(t_list **lst, t_list *new) +{ + new->next = *lst; + *lst = new; +} diff --git a/libft/ft_lstclear.c b/libft/ft_lstclear.c new file mode 100644 index 0000000..8a440e2 --- /dev/null +++ b/libft/ft_lstclear.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstclear.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:31:06 by mcolonna #+# #+# */ +/* Updated: 2023/10/05 11:40:24 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstclear(t_list **lst, void (*del)(void *)) +{ + t_list *next; + + while (*lst) + { + next = (*lst)->next; + ft_lstdelone(*lst, del); + *lst = next; + } +} diff --git a/libft/ft_lstdelone.c b/libft/ft_lstdelone.c new file mode 100644 index 0000000..0a29cbf --- /dev/null +++ b/libft/ft_lstdelone.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdelone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:28:18 by mcolonna #+# #+# */ +/* Updated: 2023/10/05 12:55:39 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +void ft_lstdelone(t_list *lst, void (*del)(void *)) +{ + if (!lst) + return ; + (*del)(lst->content); + free(lst); +} diff --git a/libft/ft_lstiter.c b/libft/ft_lstiter.c new file mode 100644 index 0000000..9bc8cdf --- /dev/null +++ b/libft/ft_lstiter.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstiter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:36:27 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 16:37:48 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstiter(t_list *lst, void (*f)(void *)) +{ + while (lst) + { + (*f)(lst->content); + lst = lst->next; + } +} diff --git a/libft/ft_lstlast.c b/libft/ft_lstlast.c new file mode 100644 index 0000000..bf5d7a2 --- /dev/null +++ b/libft/ft_lstlast.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstlast.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:22:57 by mcolonna #+# #+# */ +/* Updated: 2023/10/05 12:53:31 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstlast(t_list *lst) +{ + if (!lst) + return (NULL); + while (lst->next) + lst = lst->next; + return (lst); +} diff --git a/libft/ft_lstmap.c b/libft/ft_lstmap.c new file mode 100644 index 0000000..64561be --- /dev/null +++ b/libft/ft_lstmap.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstmap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:37:57 by mcolonna #+# #+# */ +/* Updated: 2023/10/12 13:17:57 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) +{ + t_list *dest; + t_list *new; + void *new_content; + + dest = NULL; + if (!lst) + return (NULL); + while (lst) + { + new_content = (*f)(lst->content); + new = ft_lstnew(new_content); + if (!new) + { + (*del)(new_content); + ft_lstclear(&dest, del); + return (NULL); + } + ft_lstadd_back(&dest, new); + lst = lst->next; + } + return (dest); +} diff --git a/libft/ft_lstnew.c b/libft/ft_lstnew.c new file mode 100644 index 0000000..adbf062 --- /dev/null +++ b/libft/ft_lstnew.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:14:54 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 16:51:08 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +t_list *ft_lstnew(void *content) +{ + t_list *r; + + r = malloc(sizeof(t_list)); + if (!r) + return (NULL); + r->content = content; + r->next = NULL; + return (r); +} diff --git a/libft/ft_lstsize.c b/libft/ft_lstsize.c new file mode 100644 index 0000000..5323ea2 --- /dev/null +++ b/libft/ft_lstsize.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstsize.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:21:29 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 16:44:08 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_lstsize(t_list *lst) +{ + int i; + + i = 0; + while (lst) + { + lst = lst->next; + i++; + } + return (i); +} diff --git a/libft/ft_memchr.c b/libft/ft_memchr.c new file mode 100644 index 0000000..44a6ae3 --- /dev/null +++ b/libft/ft_memchr.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:28:00 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 15:31:16 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memchr(const void *s, int c, size_t n) +{ + size_t i; + const char *s2 = s; + + i = 0; + while (i < n) + { + if (s2[i] == (char) c) + return ((void *) s + i); + i++; + } + return (NULL); +} diff --git a/libft/ft_memcmp.c b/libft/ft_memcmp.c new file mode 100644 index 0000000..ff7039f --- /dev/null +++ b/libft/ft_memcmp.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:37:06 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 12:00:22 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + size_t i; + + if (n == 0) + return (0); + i = 0; + while (i < n - 1 && ((unsigned char *)s1)[i] == ((unsigned char *)s2)[i]) + i++; + return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]); +} diff --git a/libft/ft_memcpy.c b/libft/ft_memcpy.c new file mode 100644 index 0000000..33e973f --- /dev/null +++ b/libft/ft_memcpy.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:12:53 by mcolonna #+# #+# */ +/* Updated: 2023/10/16 13:40:19 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memcpy(void *dest, const void *src, size_t n) +{ + size_t i; + char *dest2; + char *src2; + + dest2 = (char *)dest; + src2 = (char *)src; + i = 0; + while (i < n) + { + dest2[i] = src2[i]; + i++; + } + return (dest); +} diff --git a/libft/ft_memmove.c b/libft/ft_memmove.c new file mode 100644 index 0000000..985be90 --- /dev/null +++ b/libft/ft_memmove.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:17:41 by mcolonna #+# #+# */ +/* Updated: 2023/10/12 10:44:37 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memmove(void *dest, const void *src, size_t n) +{ + size_t i; + + if (!dest || !src) + return (NULL); + i = 0; + while (i < n) + { + if (dest < src) + ((char *)dest)[i] = ((char *)src)[i]; + else + ((char *)dest)[n - i - 1] = ((char *)src)[n - i - 1]; + i++; + } + return (dest); +} diff --git a/libft/ft_memset.c b/libft/ft_memset.c new file mode 100644 index 0000000..2ce9b1c --- /dev/null +++ b/libft/ft_memset.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:05:27 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 15:27:09 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memset(void *s, int c, size_t n) +{ + size_t i; + char *dest; + + dest = (char *)s; + i = 0; + while (i < n) + { + dest[i] = (char)c; + i++; + } + return (dest); +} diff --git a/libft/ft_putchar_fd.c b/libft/ft_putchar_fd.c new file mode 100644 index 0000000..9b4b60a --- /dev/null +++ b/libft/ft_putchar_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 14:25:02 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 14:29:09 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} diff --git a/libft/ft_putendl_fd.c b/libft/ft_putendl_fd.c new file mode 100644 index 0000000..d38533e --- /dev/null +++ b/libft/ft_putendl_fd.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 14:25:02 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 14:17:01 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +void ft_putendl_fd(char *s, int fd) +{ + write(fd, s, ft_strlen(s)); + write(fd, "\n", 1); +} diff --git a/libft/ft_putnbr_fd.c b/libft/ft_putnbr_fd.c new file mode 100644 index 0000000..426a0eb --- /dev/null +++ b/libft/ft_putnbr_fd.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 14:32:29 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 17:23:02 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft.h" + +static void putunsigned(long nb, int fd) +{ + if (nb == 0) + return ; + putunsigned(nb / 10, fd); + ft_putchar_fd((char)(nb % 10) + '0', fd); +} + +void ft_putnbr_fd(int n, int fd) +{ + long nb; + + if (n < 0) + { + ft_putchar_fd('-', fd); + nb = -(long)n; + } + else + nb = n; + if (n == 0) + ft_putchar_fd('0', fd); + else + putunsigned(nb, fd); +} diff --git a/libft/ft_putstr_fd.c b/libft/ft_putstr_fd.c new file mode 100644 index 0000000..ce573ed --- /dev/null +++ b/libft/ft_putstr_fd.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 14:25:02 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 14:34:35 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +void ft_putstr_fd(char *s, int fd) +{ + write(fd, s, ft_strlen(s)); +} diff --git a/libft/ft_split.c b/libft/ft_split.c new file mode 100644 index 0000000..6bf5d24 --- /dev/null +++ b/libft/ft_split.c @@ -0,0 +1,98 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 11:47:18 by mcolonna #+# #+# */ +/* Updated: 2023/10/12 13:24:04 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +static int count_until(char const *s, char const c) +{ + int i; + + i = 0; + while (s[i] && s[i] != c) + i++; + return (i); +} + +static int count_words(char const *s, char c) +{ + int i; + int r; + int in_a_word; + + i = 0; + r = 0; + in_a_word = 0; + while (s[i]) + { + if (s[i] == c) + { + in_a_word = 0; + } + else if (!in_a_word) + { + in_a_word = 1; + r++; + } + i++; + } + return (r); +} + +static char **free_array(char ***array, int size) +{ + int i; + + i = 0; + while (i < size) + { + free((*array)[i]); + (*array)[i] = NULL; + i++; + } + free(*array); + *array = NULL; + return (NULL); +} + +static void ignore_sep(char const *s, char c, int *i) +{ + while (s[*i] == c) + (*i)++; +} + +char **ft_split(char const *s, char c) +{ + int size; + char **dest; + int i; + int str_i; + int len_until; + + size = count_words(s, c); + dest = malloc((size + 1) * sizeof(char *)); + if (!dest) + return (NULL); + i = -1; + str_i = 0; + while (++i < size) + { + ignore_sep(s, c, &str_i); + len_until = count_until(s + str_i, c); + dest[i] = ft_substr(s, str_i, len_until); + if (!dest[i]) + return (free_array(&dest, i)); + str_i += len_until; + } + dest[i] = NULL; + return (dest); +} diff --git a/libft/ft_strchr.c b/libft/ft_strchr.c new file mode 100644 index 0000000..9905568 --- /dev/null +++ b/libft/ft_strchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 10:43:17 by mcolonna #+# #+# */ +/* Updated: 2023/10/10 13:17:35 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +char *ft_strchr(const char *s, int c) +{ + int i; + + i = 0; + while (s[i]) + { + if (s[i] == c) + return ((char *)s + i); + i++; + } + if (s[i] == c) + return ((char *)s + i); + return (NULL); +} diff --git a/libft/ft_strdup.c b/libft/ft_strdup.c new file mode 100644 index 0000000..532571e --- /dev/null +++ b/libft/ft_strdup.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/30 09:18:39 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 11:27:46 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +char *ft_strdup(const char *s) +{ + int len; + int i; + char *dest; + + len = 0; + while (s[len]) + len++; + dest = malloc((len + 1) * sizeof(char)); + if (!dest) + return (NULL); + i = 0; + while (s[i]) + { + dest[i] = s[i]; + i++; + } + dest[i] = '\0'; + return (dest); +} diff --git a/libft/ft_striteri.c b/libft/ft_striteri.c new file mode 100644 index 0000000..7b5d2f7 --- /dev/null +++ b/libft/ft_striteri.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 11:08:18 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 11:10:28 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_striteri(char *s, void (*f)(unsigned int, char *)) +{ + unsigned int i; + + i = 0; + while (s[i]) + { + (*f)(i, s + i); + i++; + } +} diff --git a/libft/ft_strjoin.c b/libft/ft_strjoin.c new file mode 100644 index 0000000..f57b64d --- /dev/null +++ b/libft/ft_strjoin.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 11:31:45 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 11:25:38 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +char *ft_strjoin(char const *s1, char const *s2) +{ + int len; + char *dest; + int i; + int j; + + len = ft_strlen(s1) + ft_strlen(s2); + dest = malloc((len + 1) * sizeof(char)); + if (!dest) + return (NULL); + i = 0; + while (s1[i]) + { + dest[i] = s1[i]; + i++; + } + j = 0; + while (s2[j]) + { + dest[i] = s2[j]; + i++; + j++; + } + dest[i] = '\0'; + return (dest); +} diff --git a/libft/ft_strlcat.c b/libft/ft_strlcat.c new file mode 100644 index 0000000..ec95531 --- /dev/null +++ b/libft/ft_strlcat.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/28 10:40:23 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 16:20:20 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static size_t min(size_t a, size_t b) +{ + if (a < b) + return (a); + else + return (b); +} + +size_t ft_strlcat(char *dest, const char *src, size_t size) +{ + size_t dest_len; + size_t dest_i; + size_t src_i; + + dest_len = min(ft_strlen(dest), size); + if (dest_len < size - 1) + { + dest_i = dest_len; + src_i = 0; + while (src[src_i] && size > 0 && dest_i < size - 1) + { + dest[dest_i] = src[src_i]; + src_i++; + dest_i++; + } + if (size > 0) + dest[dest_i] = '\0'; + } + return (dest_len + ft_strlen(src)); +} diff --git a/libft/ft_strlcpy.c b/libft/ft_strlcpy.c new file mode 100644 index 0000000..80de6c9 --- /dev/null +++ b/libft/ft_strlcpy.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/25 20:39:39 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 11:44:13 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcpy(char *dest, const char *src, size_t size) +{ + size_t i; + + i = 0; + while (src[i] && size > 0 && i < size - 1) + { + dest[i] = src[i]; + i++; + } + if (i < size) + dest[i] = '\0'; + while (src[i]) + i++; + return (i); +} diff --git a/libft/ft_strlen.c b/libft/ft_strlen.c new file mode 100644 index 0000000..f6c8804 --- /dev/null +++ b/libft/ft_strlen.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/24 13:10:16 by mcolonna #+# #+# */ +/* Updated: 2023/10/10 14:09:44 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlen(const char *s) +{ + int i; + + i = 0; + while (s[i]) + i++; + return (i); +} diff --git a/libft/ft_strmapi.c b/libft/ft_strmapi.c new file mode 100644 index 0000000..556ad76 --- /dev/null +++ b/libft/ft_strmapi.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 11:08:18 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 15:20:49 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) +{ + char *dest; + unsigned int i; + + dest = malloc((ft_strlen(s) + 1) * sizeof(char)); + if (!dest) + return (NULL); + i = 0; + while (s[i]) + { + dest[i] = (*f)(i, s[i]); + i++; + } + dest[i] = '\0'; + return (dest); +} diff --git a/libft/ft_strncmp.c b/libft/ft_strncmp.c new file mode 100644 index 0000000..c10af4c --- /dev/null +++ b/libft/ft_strncmp.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/10 12:21:33 by mcolonna #+# #+# */ +/* Updated: 2023/10/10 14:39:03 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strncmp(const char *s1, const char *s2, size_t n) +{ + unsigned int i; + + if (n == 0) + return (0); + i = 0; + while (i < n - 1 && s1[i] && s1[i] == s2[i]) + i++; + return ((unsigned char)s1[i] - (unsigned char)s2[i]); +} diff --git a/libft/ft_strnstr.c b/libft/ft_strnstr.c new file mode 100644 index 0000000..ca93e48 --- /dev/null +++ b/libft/ft_strnstr.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 10:50:23 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 16:09:21 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +// Return 1 if there is 'little' at the pos 'i' of 'big', or else 0. +static int match(const char *big, const char *little, size_t len, size_t i) +{ + int j; + + j = 0; + while (little[j]) + { + if (len <= i || big[i] != little[j]) + return (0); + i++; + j++; + } + return (1); +} + +char *ft_strnstr(const char *big, const char *little, size_t len) +{ + size_t i; + + i = 0; + if (!little[0]) + return ((char *)big); + if (!big[i] || i >= len) + return (NULL); + while (!match(big, little, len, i)) + { + i++; + if (!big[i] || i >= len) + return (NULL); + } + return ((char *)big + i); +} diff --git a/libft/ft_strrchr.c b/libft/ft_strrchr.c new file mode 100644 index 0000000..8b76716 --- /dev/null +++ b/libft/ft_strrchr.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 10:43:17 by mcolonna #+# #+# */ +/* Updated: 2023/10/10 13:16:58 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +char *ft_strrchr(const char *s, int c) +{ + char *r; + int i; + + r = NULL; + i = 0; + while (s[i]) + { + if (s[i] == c) + r = (char *)s + i; + i++; + } + if (s[i] == c) + r = (char *)s + i; + return (r); +} diff --git a/libft/ft_strtrim.c b/libft/ft_strtrim.c new file mode 100644 index 0000000..e6d422e --- /dev/null +++ b/libft/ft_strtrim.c @@ -0,0 +1,80 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 11:39:33 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 13:07:54 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +static int is_in(char const c, char const *set) +{ + int i; + + i = 0; + while (set[i]) + { + if (set[i] == c) + return (1); + i++; + } + return (0); +} + +static size_t get_length(char const *s1, char const *set) +{ + size_t i; + size_t r; + size_t tmp; + + i = 0; + while (is_in(s1[i], set)) + i++; + r = 0; + tmp = 0; + while (s1[i]) + { + if (is_in(s1[i], set)) + { + tmp++; + } + else + { + r += tmp; + tmp = 0; + r++; + } + i++; + } + return (r); +} + +char *ft_strtrim(char const *s1, char const *set) +{ + size_t len; + char *dest; + size_t start; + size_t i; + + len = get_length(s1, set); + dest = malloc((len + 1) * sizeof(char)); + if (!dest) + return (NULL); + start = 0; + while (is_in(s1[start], set)) + start++; + i = 0; + while (i < len) + { + dest[i] = s1[start + i]; + i++; + } + dest[i] = '\0'; + return (dest); +} diff --git a/libft/ft_substr.c b/libft/ft_substr.c new file mode 100644 index 0000000..3a98490 --- /dev/null +++ b/libft/ft_substr.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 11:17:12 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 13:27:30 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + char *dest; + size_t s_len; + size_t dest_len; + size_t i; + + s_len = ft_strlen(s); + if (s_len < start) + dest_len = 0; + else if (s_len < start + len) + dest_len = s_len - start; + else + dest_len = len; + dest = malloc((dest_len + 1) * sizeof(char)); + if (!dest) + return (NULL); + i = 0; + while (i < dest_len) + { + dest[i] = s[start + i]; + i++; + } + dest[i] = '\0'; + return (dest); +} diff --git a/libft/ft_tolower.c b/libft/ft_tolower.c new file mode 100644 index 0000000..aa8f85f --- /dev/null +++ b/libft/ft_tolower.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:53:06 by mcolonna #+# #+# */ +/* Updated: 2023/10/02 16:58:02 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_tolower(int c) +{ + if (c >= 'A' && c <= 'Z') + return (c - 'A' + 'a'); + return (c); +} diff --git a/libft/ft_toupper.c b/libft/ft_toupper.c new file mode 100644 index 0000000..f1b6727 --- /dev/null +++ b/libft/ft_toupper.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:53:06 by mcolonna #+# #+# */ +/* Updated: 2023/10/02 16:56:52 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_toupper(int c) +{ + if (c >= 'a' && c <= 'z') + return (c - 'a' + 'A'); + return (c); +} diff --git a/libft/libft.h b/libft/libft.h new file mode 100644 index 0000000..6dbd635 --- /dev/null +++ b/libft/libft.h @@ -0,0 +1,196 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 11:46:15 by mcolonna #+# #+# */ +/* Updated: 2023/10/10 14:11:08 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H + +# include +# include + +///// CHAR ///// + +// (In libc) Return 1 if the char 'c' is a specific type of char, or else 0. +int ft_isalpha(int c); // A-Za-z +int ft_isdigit(int c); // 0-9 +int ft_isalnum(int c); // A-Za-z0-9 +int ft_isascii(int c); // (0)-(127) +int ft_isprint(int c); // (32)-(126) + +// (In libc) Return the uppercase/lowercase version of the letter, +// or the char itself if it's not a letter. +int ft_toupper(int c); +int ft_tolower(int c); + +///// STR ///// + +// (In libc) Compare 2 strings until n +int ft_strncmp(const char *s1, const char *s2, size_t n); + +// (In libc) Return the length of the string 's'. +size_t ft_strlen(const char *s); + +// (In libc) Copy/Append src on dst. +// 'dst' will be 'size' chars max, including \0, +// except if 'dst' is already longer for strlcat(). +// 1. Never do more than size. +// 2. Always end by \0, except if it doesn't respect 1. +size_t ft_strlcpy(char *dst, const char *src, size_t size); +size_t ft_strlcat(char *dst, const char *src, size_t size); + +// (In libc) Return a pointer to the first of last char 'c' in 's', +// or return NULL if there aren't any. +char *ft_strchr(const char *s, int c); // First char. +char *ft_strrchr(const char *s, int c); // Last char. + +// (In libc) Return a pointer to the first occurence +// of string 'little' in string 'big'. +// Don't look chars after 'size'. +char *ft_strnstr(const char *big, const char *little, size_t len); + +// (In libc) Return an malloced duplicate of 's'. +// Uses: malloc +// Error: return NULL +char *ft_strdup(const char *s); + +// (Perso) Apply 'f' on each char of the string 's' and returns the result. +// Uses: malloc +// Error: return NULL +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); + +// (Perso) Call 'f' for each char of 's'. +void ft_striteri(char *s, void (*f)(unsigned int, char *)); + +// (Perso) Return the substring of 's' which starts at 'start' +// and is of length 'len'. +// Don't take chars after the end of the string. +// Uses: malloc +// Error: return NULL +char *ft_substr(char const *s, unsigned int start, size_t len); + +// (Perso) Concatenate the two strings. +// Uses: malloc +// Error: return NULL +char *ft_strjoin(char const *s1, char const *s2); + +// (Perso) Remove the characters 'set' from the beginning +// and the end of the string. +// Uses: malloc +// Error: return NULL +char *ft_strtrim(char const *s1, char const *set); + +// (Perso) Split 's' by the chars 'c'. +// Return an array ended by NULL. +// Uses: malloc +// Error: return NULL +char **ft_split(char const *s, char c); + +///// MEM ///// + +// (In libc) Fills 's' with 'n' times the char 'c'. +// Return 'c'. +void *ft_memset(void *s, int c, size_t n); + +// (In libc) Just ft_memset(s, '\0', n) lol. +void ft_bzero(void *s, size_t n); + +// (In libc) Copy 'n' bytes from 'src' to 'dest'. +// The 'src' and 'dest' areas mustn't overlap. +// Return 'dest'. +void *ft_memcpy(void *dest, const void *src, size_t n); + +// (In libc) Same, but the areas can overlap. +// Return 'dest'. +void *ft_memmove(void *dest, const void *src, size_t n); + +// (In libc) Find the character 'c' in 's', 's' being of length 'n'. +// NULL if none. +void *ft_memchr(const void *s, int c, size_t n); + +// (In libc) Compare 'n' bytes of 's1' and 's2'. +int ft_memcmp(const void *s1, const void *s2, size_t n); + +// (In libc) Alloc an array of 'size' elements with each element +// being of size 'size'. +// Uses: malloc +// Error: return NULL +void *ft_calloc(size_t nmemb, size_t size); + +///// CAST ///// + +// (In libc) Cast a string to an int. +// /[ \f\n\r\t\v]*[-+]?[0-9]*.*/ +int ft_atoi(const char *nptr); + +// (Perso) Cast an int to a string. +// Uses: malloc +// Error: return NULL +char *ft_itoa(int n); + +///// WRITE ///// + +// (Perso) Write the char/string on the file descriptor 'fd'. +// Uses: write +void ft_putchar_fd(char c, int fd); +void ft_putstr_fd(char *s, int fd); + +// (Perso) Write the string 's' followed by a newline. +// Uses: write +void ft_putendl_fd(char *s, int fd); + +// (Perso) Write the number 'n'. +// Uses: write +void ft_putnbr_fd(int n, int fd); + +typedef struct s_list +{ + void *content; + struct s_list *next; +} t_list; + +///// BONUS ///// + +// Create an malloced list of size = 1: {content} +// Uses: malloc +// Error: return NULL +t_list *ft_lstnew(void *content); + +// Add 'new' at the beginning of the list. +void ft_lstadd_front(t_list **lst, t_list *new); + +// Get the length of the list. +int ft_lstsize(t_list *lst); + +// Return the last node of the list. +t_list *ft_lstlast(t_list *lst); + +// Add 'new' at the end of the list. +void ft_lstadd_back(t_list **lst, t_list *new); + +// Apply 'del' on the element's content, then free lst. +// Uses: free +void ft_lstdelone(t_list *lst, void (*del)(void *)); + +// Free every element's content with del and free the elements. +// *lst will be set to NULL. +// Uses: free +void ft_lstclear(t_list **lst, void (*del)(void *)); + +// Apply f on the content of each node. +void ft_lstiter(t_list *lst, void (*f)(void *)); + +// Apply f on the content of each node +// and create a new list with the resulting contents. +// Uses: free, malloc +// Error: return NULL +t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)); + +#endif diff --git a/src/main.c b/src/main.c index 115ee5a..793fa38 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/02 15:45:49 by mcolonna #+# #+# */ -/* Updated: 2024/10/04 15:10:50 by mcolonna ### ########.fr */ +/* Updated: 2024/10/10 12:44:12 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,9 +26,11 @@ int main(int argc, char *argv[]) success = map_from_file(&map, argv[1]); printf("--> Success: %i <--\n", success); if (success) + { printf("C 0x%08x\nF 0x%08x\nEA %s\nWE %s\nNO %s\nSO %s\n", map.color_ceiling, map.color_floor, map.texture_east, map.texture_west, map.texture_north, map.texture_south); - map_destroy(&map); + map_destroy(&map); + } } diff --git a/src/map.c b/src/map.c index 475b024..e2b9c46 100644 --- a/src/map.c +++ b/src/map.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 17:12:58 by mcolonna #+# #+# */ -/* Updated: 2024/10/04 15:25:32 by mcolonna ### ########.fr */ +/* Updated: 2024/10/10 13:11:43 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,18 +14,41 @@ #include "map_utils.h" #include "stream.h" #include "read_all_text.h" +#include "libft.h" #include #include #include #include #include +#include + +static bool map_from_file2(t_map *dest, t_stream *stream, int fd) +{ + bool success; + + stream->i = 0; + success = read_map(dest, stream); + if (success) + { + success = check_map(dest); + if (!success) + map_destroy(dest); + } + close(fd); + free((void *)stream->str); + return (success); +} bool map_from_file(t_map *dest, const char *file) { int fd; t_stream stream; - bool err; + if (ft_strncmp(file + ft_strlen(file) - 4, ".cub", 5)) + { + write_err("File extension must be .cub\n", NULL); + return (false); + } fd = open(file, O_RDONLY); if (fd < 0) { @@ -37,12 +60,10 @@ bool map_from_file(t_map *dest, const char *file) if (!stream.str) { write_err("Can't read file.\n", NULL); + close(fd); return (false); } - stream.i = 0; - err = read_map(dest, &stream); - free((void *)stream.str); - return (err); + return (map_from_file2(dest, &stream, fd)); } void map_destroy(t_map *map) @@ -53,3 +74,50 @@ void map_destroy(t_map *map) free((void *)map->texture_south); free(map->cases); } + +static bool check_map2(const t_map *map, unsigned int x, unsigned int y) +{ + unsigned int x2; + unsigned int y2; + const t_map_case *c; + + c = &map->cases[y * map->width + x]; + if (c->inside && c->wall != WALL) + { + if (x == 0 || x == map->width - 1 + || y == 0 || y == map->height - 1) + return (write_err("Map is not surrounded by walls\n", NULL), false); + x2 = x - 2; + while (++x2 < x + 2) + { + y2 = y - 2; + while (++y2 < y + 2) + { + if (x < map->width && y < map->height + && !map->cases[y2 * map->width + x2].inside) + return (write_err("Map is not surrounded by walls\n", NULL), + false); + } + } + } + return (true); +} + +// TODO check player +bool check_map(const t_map *map) +{ + unsigned int x; + unsigned int y; + + x = -1; + while (++x < map->width) + { + y = -1; + while (++y < map->height) + { + if (!check_map2(map, x, y)) + return (false); + } + } + return (true); +} diff --git a/src/map_mapping.c b/src/map_mapping.c index e4b575f..35a9054 100644 --- a/src/map_mapping.c +++ b/src/map_mapping.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/04 12:05:21 by mcolonna #+# #+# */ -/* Updated: 2024/10/04 15:23:28 by mcolonna ### ########.fr */ +/* Updated: 2024/10/10 11:59:02 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,11 +14,11 @@ #include const t_map_mapping_element g_map_mapping[] = { -{' ', {EMPTY, {NULL, NULL, NULL, NULL}}}, -{'0', {EMPTY, {NULL, NULL, NULL, NULL}}}, -{'1', {WALL, {NULL, NULL, NULL, NULL}}}, -{'N', {EMPTY, {NULL, NULL, NULL, NULL}}}, // TODO add player object -{'S', {EMPTY, {NULL, NULL, NULL, NULL}}}, // -- -{'E', {EMPTY, {NULL, NULL, NULL, NULL}}}, // -- -{'W', {EMPTY, {NULL, NULL, NULL, NULL}}}, // -- -{'\0', {EMPTY, {NULL, NULL, NULL, NULL}}}}; +{' ', {false, EMPTY, {NULL, NULL, NULL, NULL}}}, +{'0', {true, EMPTY, {NULL, NULL, NULL, NULL}}}, +{'1', {true, WALL, {NULL, NULL, NULL, NULL}}}, +{'N', {true, EMPTY, {NULL, NULL, NULL, NULL}}}, // TODO add player object +{'S', {true, EMPTY, {NULL, NULL, NULL, NULL}}}, // -- +{'E', {true, EMPTY, {NULL, NULL, NULL, NULL}}}, // -- +{'W', {true, EMPTY, {NULL, NULL, NULL, NULL}}}, // -- +{'\0', {true, EMPTY, {NULL, NULL, NULL, NULL}}}}; diff --git a/src/map_utils1.c b/src/map_utils1.c index 6377db0..e0ce97e 100644 --- a/src/map_utils1.c +++ b/src/map_utils1.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 15:02:09 by mc #+# #+# */ -/* Updated: 2024/10/04 15:28:06 by mcolonna ### ########.fr */ +/* Updated: 2024/10/10 13:32:39 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,10 +62,9 @@ bool read_string_parameter(const char *name, const char **dest, if (!err && *dest) { *redefined = true; - write_err("Parameter '", name, "' was defined several times\n", - NULL); + write_err("Parameter '", name, "' was defined several times\n", NULL); } - if (err || (!err && *dest)) + if (*redefined || err) { *stream = old; free(r); @@ -96,8 +95,7 @@ bool read_map(t_map *dest, t_stream *stream) rdf = false; while (!rdf && !err && stream->str[stream->i]) { - if (true - && (read_expected_string("\n", stream, &err), err) + if ((read_expected_string("\n", stream, &err), err) && !read_string_parameter("NO", &dest->texture_north, stream, &rdf) && !read_string_parameter("SO", &dest->texture_south, stream, &rdf) && !read_string_parameter("WE", &dest->texture_west, stream, &rdf) @@ -106,11 +104,12 @@ bool read_map(t_map *dest, t_stream *stream) && !read_color_parameter("C", &dest->color_ceiling, stream, &rdf)) { err = !read_map_description(dest, stream); - return (!err); + break ; } err = false; } if (!rdf && !dest->cases) - write_err("Map description missing\n", NULL); + err = (write_err("Map description missing\n", NULL), true); + (rdf || err) && (map_destroy(dest), false); return (!err && !rdf && dest->cases); } diff --git a/src/read_all_text.c b/src/read_all_text.c index 490efc3..eeea2f8 100644 --- a/src/read_all_text.c +++ b/src/read_all_text.c @@ -3,15 +3,16 @@ /* ::: :::::::: */ /* read_all_text.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/02 16:18:35 by mcolonna #+# #+# */ -/* Updated: 2024/10/03 14:20:37 by mc ### ########.fr */ +/* Updated: 2024/10/10 12:38:19 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #include "read_all_text.h" #include "util.h" +#include "libft.h" #include #include #include @@ -27,7 +28,7 @@ /// @return true if success, false if error. static bool strconcat(char **dest, char *src, int n) { - const int len_dest = getlen(*dest); + const int len_dest = ft_strlen(*dest); char *old_dest; int i; @@ -59,7 +60,7 @@ static char *add_endline_if_necessary(char *str) { char *endline; - if (str[0] == '\0' || str[getlen(str) - 1] == '\n') + if (str[0] == '\0' || str[ft_strlen(str) - 1] == '\n') return (str); endline = malloc(1 * sizeof(char)); if (!endline) diff --git a/src/util.c b/src/util.c index a18b2c5..e61707c 100644 --- a/src/util.c +++ b/src/util.c @@ -6,24 +6,15 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 14:19:38 by mc #+# #+# */ -/* Updated: 2024/10/04 15:26:32 by mcolonna ### ########.fr */ +/* Updated: 2024/10/10 12:38:42 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #include "util.h" +#include "libft.h" #include #include -int getlen(const char *str) -{ - int i; - - i = 0; - while (str[i]) - i++; - return (i); -} - void write_err(const char *str, ...) { va_list args; @@ -32,7 +23,7 @@ void write_err(const char *str, ...) write(2, "Error\n", 6); while (str) { - write(2, str, getlen(str)); + write(2, str, ft_strlen(str)); str = va_arg(args, const char *); } } diff --git a/testmaps/hdhd.cub b/testmaps/err_doubleparameters.cub similarity index 80% rename from testmaps/hdhd.cub rename to testmaps/err_doubleparameters.cub index df272c6..94251e8 100644 --- a/testmaps/hdhd.cub +++ b/testmaps/err_doubleparameters.cub @@ -1,19 +1,12 @@ - - F 255,127,0 - EA eastimage - - - NO theimageforthenorthwall C 0,2,67 - SO SOUTH!!!!!!1 -SO jde: - WE weeeee - - - SO south2 + +11111 +10N01 +10001 +11111 diff --git a/testmaps/err_extension.cud b/testmaps/err_extension.cud new file mode 100644 index 0000000..82b2ea9 --- /dev/null +++ b/testmaps/err_extension.cud @@ -0,0 +1,11 @@ +F 255,127,0 +EA eastimage +NO theimageforthenorthwall +C 0,2,67 +SO SOUTH!!!!!!1 +WE weeeee +1111111 +1000001 +10W0001 +1000001 +1111111 diff --git a/testmaps/idid.cub b/testmaps/err_nomapdescription.cub similarity index 90% rename from testmaps/idid.cub rename to testmaps/err_nomapdescription.cub index 0eb3904..75bff64 100644 --- a/testmaps/idid.cub +++ b/testmaps/err_nomapdescription.cub @@ -1,15 +1,6 @@ F 255,127,0 - EA eastimage - NO theimageforthenorthwall C 0,2,67 - SO SOUTH!!!!!!1 - WE weeeee - - - - - diff --git a/testmaps/err_nonclosed1.cub b/testmaps/err_nonclosed1.cub new file mode 100644 index 0000000..4cfef19 --- /dev/null +++ b/testmaps/err_nonclosed1.cub @@ -0,0 +1,11 @@ +F 255,127,0 +EA eastimage +NO theimageforthenorthwall +C 0,2,67 +SO SOUTH!!!!!!1 +WE weeeee +1101111 +1000001 +10W0001 +1000001 +1111111 diff --git a/testmaps/err_nonclosed2.cub b/testmaps/err_nonclosed2.cub new file mode 100644 index 0000000..64fd7c6 --- /dev/null +++ b/testmaps/err_nonclosed2.cub @@ -0,0 +1,11 @@ +F 255,127,0 +EA eastimage +NO theimageforthenorthwall +C 0,2,67 +SO SOUTH!!!!!!1 +WE weeeee +0111111 +1000001 +10W0001 +1000001 +1111111 diff --git a/testmaps/err_nonclosed3.cub b/testmaps/err_nonclosed3.cub new file mode 100644 index 0000000..d8e44be --- /dev/null +++ b/testmaps/err_nonclosed3.cub @@ -0,0 +1,11 @@ +F 255,127,0 +EA eastimage +NO theimageforthenorthwall +C 0,2,67 +SO SOUTH!!!!!!1 +WE weeeee + 111111 +1000001 +10W0001 +1000001 +1111111 diff --git a/testmaps/err_nonclosed4.cub b/testmaps/err_nonclosed4.cub new file mode 100644 index 0000000..536d61f --- /dev/null +++ b/testmaps/err_nonclosed4.cub @@ -0,0 +1,11 @@ +F 255,127,0 +EA eastimage +NO theimageforthenorthwall +C 0,2,67 +SO SOUTH!!!!!!1 +WE weeeee +1111111 +1000001 +10W0 01 +1000001 +1111111 diff --git a/testmaps/good.cub b/testmaps/good.cub new file mode 100644 index 0000000..82b2ea9 --- /dev/null +++ b/testmaps/good.cub @@ -0,0 +1,11 @@ +F 255,127,0 +EA eastimage +NO theimageforthenorthwall +C 0,2,67 +SO SOUTH!!!!!!1 +WE weeeee +1111111 +1000001 +10W0001 +1000001 +1111111 diff --git a/testmaps/jdjd.cub b/testmaps/good_weirdblank.cub similarity index 100% rename from testmaps/jdjd.cub rename to testmaps/good_weirdblank.cub diff --git a/testmaps/good_weirdshape.cub b/testmaps/good_weirdshape.cub new file mode 100644 index 0000000..edf7730 --- /dev/null +++ b/testmaps/good_weirdshape.cub @@ -0,0 +1,19 @@ +F 255,127,0 +EA eastimage +NO theimageforthenorthwall +C 0,2,67 +SO SOUTH!!!!!!1 +WE weeeee + + 111 + 111 101 + 111 101111101 + 101111101100001 + 100001101101111 + 1111111111101100101 + 1000000000101110101 +11011111110W00010101 +1001 10000010101 +1111 111111100000001111111 + 110000000000100000001 + 111111111111111111111 From c1e17997ffe3a8e26e650aa5b1d6f26c7b185245 Mon Sep 17 00:00:00 2001 From: ReverseSky Date: Thu, 10 Oct 2024 18:38:37 +0200 Subject: [PATCH 10/80] render termine manque textures --- algo.c | 242 ++++++++++++++++++++++++++++----------------------------- algo.h | 7 +- cub3d | Bin 0 -> 39080 bytes 3 files changed, 125 insertions(+), 124 deletions(-) create mode 100755 cub3d diff --git a/algo.c b/algo.c index 62414a9..569e103 100644 --- a/algo.c +++ b/algo.c @@ -6,7 +6,7 @@ /* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/09 03:30:08 by greg ### ########.fr */ +/* Updated: 2024/10/10 18:22:08 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,8 +45,8 @@ int worldMap[mapWidth][mapHeight]= static int initalgo(t_ray *ray) { - ray->posX = 2; - ray->posY = 2; + ray->posX = 13; + ray->posY = 10; ray->dirX = -1; ray->dirY = 0; ray->planeX = 0; @@ -56,123 +56,67 @@ static int initalgo(t_ray *ray) return (0); } -static int keypress(int keycode, t_ray *ray, int **worldMap) +static int render(t_ray *ray) { - //move forward if no wall in front of you - if (keycode == 119) - { - if(worldMap[(int)(ray->posX + ray->dirX * ray->movespeed)][(int)(ray->posY)] == 0) - ray->posX += ray->dirX * ray->movespeed; - if(worldMap[(int)(ray->posX)][((int)ray->posY + (int)ray->dirY * (int)ray->movespeed)] == 0) - ray->posY += ray->dirY * ray->movespeed; - } - //move backwards if no wall behind you - if (keycode == 115) - { - if(worldMap[(int)(ray->posX - ray->dirX * ray->movespeed)][(int)(ray->posY)] == 0) - ray->posX -= ray->dirX * ray->movespeed; - if(worldMap[(int)(ray->posX)][((int)ray->posY - (int)ray->dirY * (int)ray->movespeed)] == 0) - ray->posY -= ray->dirY * ray->movespeed; - } - //rotate to the right - if (keycode == 100) - { - //both camera direction and camera plane must be rotated - ray->oldDirX = ray->dirX; - ray->dirX = ray->dirX * cos(-ray->rotspeed) - ray->dirY * sin(-ray->rotspeed); - ray->dirY = ray->oldDirX * sin(-ray->rotspeed) + ray->dirY * cos(-ray->rotspeed); - ray->oldPlaneX = ray->planeX; - ray->planeX = ray->planeX * cos(-ray->rotspeed) - ray->planeY * sin(-ray->rotspeed); - ray->planeY = ray->oldPlaneX * sin(-ray->rotspeed) + ray->planeY * cos(-ray->rotspeed); - } - //rotate to the left - if (keycode == 97) - { - //both camera direction and camera plane must be rotated - ray->oldDirX = ray->dirX; - ray->dirX = ray->dirX * cos(ray->rotspeed) - ray->dirY * sin(ray->rotspeed); - ray->dirY = ray->oldDirX * sin(ray->rotspeed) + ray->dirY * cos(ray->rotspeed); - ray->oldPlaneX = ray->planeX; - ray->planeX = ray->planeX * cos(ray->rotspeed) - ray->planeY * sin(ray->rotspeed); - ray->planeY = ray->oldPlaneX * sin(ray->rotspeed) + ray->planeY * cos(ray->rotspeed); - } - return (0); -} - -int main(int /*argc*/, char */*argv*/[]) -{ - t_ray ray; - int x; - double width; - double height; - // quelle box sur la map on est - int mapX; - int mapY; - // wall hit and if yes in wich direction - int hit; - int side; - - initalgo(&ray); - + int x; + double width = 640; + double height = 480; + int mapX, mapY, hit, side; + int *img_data = (int *)mlx_get_data_addr(ray->img_ptr, &(int){32}, &(int){width * 4}, &(int){0}); + + // clear image data + ft_bzero(img_data, width * height * sizeof(int)); + x = 0; - width = 640; - height = 480; - - void *mlx_ptr; - void *win_ptr; - - mlx_ptr = mlx_init(); // Initialise la connexion à la MLX - win_ptr = mlx_new_window(mlx_ptr, width, height, "cub3d"); - while (x < width) { // position et direction du rayon - ray.cameraX = 2 * x / width - 1; - ray.raydirX = ray.dirX + ray.planeX * ray.cameraX; - ray.raydirY = ray.dirY + ray.planeY * ray.cameraX; + ray->cameraX = 2 * x / width - 1; + ray->raydirX = ray->dirX + ray->planeX * ray->cameraX; + ray->raydirY = ray->dirY + ray->planeY * ray->cameraX; - mapX = (int)ray.posX; - mapY = (int)ray.posY; + mapX = (int)ray->posX; + mapY = (int)ray->posY; - ray.deltadistX = (ray.raydirX == 0) ? 1e30 : fabs(1 / ray.raydirX); - ray.deltadistY = (ray.raydirY == 0) ? 1e30 : fabs(1 / ray.raydirY); + ray->deltadistX = (ray->raydirX == 0) ? 1e30 : fabs(1 / ray->raydirX); + ray->deltadistY = (ray->raydirY == 0) ? 1e30 : fabs(1 / ray->raydirY); + + //calculate step and initial sideDist + if (ray->raydirX < 0) + { + ray->stepX = -1; + ray->sidedistX = (ray->posX - mapX) * ray->deltadistX; + } + else + { + ray->stepX = 1; + ray->sidedistX = (mapX + 1.0 - ray->posX) * ray->deltadistX; + } + if (ray->raydirY < 0) + { + ray->stepY = -1; + ray->sidedistY = (ray->posY - mapY) * ray->deltadistY; + } + else + { + ray->stepY = 1; + ray->sidedistY = (mapY + 1.0 - ray->posY) * ray->deltadistY; + } hit = 0; - - //calculate step and initial sideDist - if (ray.raydirX < 0) - { - ray.stepX = -1; - ray.sidedistX = (ray.posX - mapX) * ray.deltadistX; - } - else - { - ray.stepX = 1; - ray.sidedistX = (mapX + 1.0 - ray.posX) * ray.deltadistX; - } - if (ray.raydirY < 0) - { - ray.stepY = -1; - ray.sidedistY = (ray.posY - mapY) * ray.deltadistY; - } - else - { - ray.stepY = 1; - ray.sidedistY = (mapY + 1.0 - ray.posY) * ray.deltadistY; - } while(hit == 0) { //jump to next map square, either in x-direction, or in y-direction - if(ray.sidedistX < ray.sidedistY) + if(ray->sidedistX < ray->sidedistY) { - ray.sidedistX += ray.deltadistX; - mapX += ray.stepX; + ray->sidedistX += ray->deltadistX; + mapX += ray->stepX; side = 0; } else { - ray.sidedistY += ray.deltadistY; - mapY += ray.stepY; + ray->sidedistY += ray->deltadistY; + mapY += ray->stepY; side = 1; } //Check if ray has hit a wall @@ -180,45 +124,97 @@ int main(int /*argc*/, char */*argv*/[]) hit = 1; } if(side == 0) - ray.perpwalldist = (ray.sidedistX - ray.deltadistX); + ray->perpwalldist = (ray->sidedistX - ray->deltadistX); else - ray.perpwalldist = (ray.sidedistY - ray.deltadistY); + ray->perpwalldist = (ray->sidedistY - ray->deltadistY); //Calculate height of line to draw on screen - int lineHeight = (int)(height / ray.perpwalldist); - lineHeight = (int)(height / ray.perpwalldist); + int lineHeight = (int)(height / ray->perpwalldist); //calculate lowest and highest pixel to fill in current stripe - int drawStart; - drawStart = -lineHeight / 2 + height / 2; + int drawStart = -lineHeight / 2 + height / 2; if(drawStart < 0) drawStart = 0; - int drawEnd; - drawEnd = lineHeight / 2 + height / 2; + int drawEnd = lineHeight / 2 + height / 2; if(drawEnd >= height) drawEnd = height - 1; + + // draw vertical line int y = drawStart; while (y <= drawEnd) { - mlx_pixel_put(mlx_ptr, win_ptr, x, y, 0xFF0000); + img_data[y * (int)width + x] = 0xFF0000; y++; } x++; } - //draw the pixels of the stripe as a vertical line - //verLine(x, drawStart, drawEnd, color); */ - - - // put image to window - // destroy old image - - - mlx_hook(win_ptr, 2, 1L<<0, keypress, &ray); - + // put image to window + mlx_put_image_to_window(ray->mlx_ptr, ray->win_ptr, ray->img_ptr, 0, 0); return (0); - } +static int keypress(int keycode, t_ray *ray) +{ + //move forward if no wall in front of you + if (keycode == 119) + { + ray->posX += ray->dirX * ray->movespeed; + ray->posY += ray->dirY * ray->movespeed; + } + //move backwards if no wall behind you + if (keycode == 115) + { + ray->posX -= ray->dirX * ray->movespeed; + ray->posY -= ray->dirY * ray->movespeed; + } + //rotate to the right + if (keycode == 100) + { + //both camera direction and camera plane must be rotated + ray->oldDirX = ray->dirX; + ray->dirX = ray->dirX * cos(-ray->rotspeed) - ray->dirY * sin(-ray->rotspeed); + ray->dirY = ray->oldDirX * sin(-ray->rotspeed) + ray->dirY * cos(-ray->rotspeed); + ray->oldPlaneX = ray->planeX; + ray->planeX = ray->planeX * cos(-ray->rotspeed) - ray->planeY * sin(-ray->rotspeed); + ray->planeY = ray->oldPlaneX * sin(-ray->rotspeed) + ray->planeY * cos(-ray->rotspeed); + } + //rotate to the left + if (keycode == 97) + { + //both camera direction and camera plane must be rotated + ray->oldDirX = ray->dirX; + ray->dirX = ray->dirX * cos(ray->rotspeed) - ray->dirY * sin(ray->rotspeed); + ray->dirY = ray->oldDirX * sin(ray->rotspeed) + ray->dirY * cos(ray->rotspeed); + ray->oldPlaneX = ray->planeX; + ray->planeX = ray->planeX * cos(ray->rotspeed) - ray->planeY * sin(ray->rotspeed); + ray->planeY = ray->oldPlaneX * sin(ray->rotspeed) + ray->planeY * cos(ray->rotspeed); + } + // render the updated frame after key press + render(ray); + return (0); +} + +int main(void) +{ + t_ray ray; + + // Initialisation + ray.mlx_ptr = mlx_init(); + ray.win_ptr = mlx_new_window(ray.mlx_ptr, 640, 480, "cub3d"); + ray.img_ptr = mlx_new_image(ray.mlx_ptr, 640, 480); + + initalgo(&ray); + + // hook keypress + mlx_hook(ray.win_ptr, 2, 1L<<0, keypress, &ray); + // render the initial frame + render(&ray); + + // start the mlx loop + mlx_loop(ray.mlx_ptr); + + return (0); +} diff --git a/algo.h b/algo.h index 47a1836..bae8383 100644 --- a/algo.h +++ b/algo.h @@ -6,7 +6,7 @@ /* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/09 02:51:53 by greg ### ########.fr */ +/* Updated: 2024/10/10 17:53:01 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,7 @@ #include #include "Minilibx/mlx.h" #include "Minilibx/mlx_int.h" +# include "Libft/libft.h" #define mapWidth 24 #define mapHeight 24 @@ -51,6 +52,10 @@ typedef struct s_ray double rotspeed; double oldDirX; double oldPlaneX; + void *mlx_ptr; + void *win_ptr; + void *img_ptr; + int *img_data; } t_ray; #endif diff --git a/cub3d b/cub3d new file mode 100755 index 0000000000000000000000000000000000000000..e95c3fcd32b6daebfd0908341c01b025f9618055 GIT binary patch literal 39080 zcmeHwdwg5PmH(CO>nJZtd4U6zD8Yb36UR;h7($3-Th4WG5;b;+QUbDK%a*~GR9Q+K zO2EVkjaCF4(g*F2ve~xV&2GDGw(YN*rWBm;NYVlu(vnRJZ4Ct~H9*sp(scXK?|bGU zU0wSE`)hxn{o|MM$2xPqbIzGFXXehG89nYj-sVQD#iGbmqTHwuxAzK;xJ5zuL6HG* zE49jGyk4$UC}rSF8OF=qoS>AaQ`TZ?6L<+I>6KGv40;KN6-lLsL`lyq*)HHEk}6Kl zlb%Xh7rh|4*lV7C{z}eEs@G%n`GmZIJ|-F@sa}s_bM6+dckYg2s@Xa36IAL^xJb{o zftTBQim6M)Q&JgE@{#^)MLdnPnwwE1HR^?ho{=^PJxQq!N-eJ^I{t6!^9eoeBixRW z-as9NB&n?LBhaI`e9+_+f@?&5X8m9j6-X+oR~GbiZ@gylf}W1~J>8LH|NQ>iYvy0G zxT-H&wUAjRH5dMAOf6rvRzbH66DGo_SO+*S?NQluQBLw}dwlLU3B`$ zmYrQ6{S3*F-=sq_l*pdwa>i4>7XKu}<8d#;38VBv==olr8~as*fvIB@-3NnX;a`L7 zSonv4yT-6H$He}%Cid%1$wzD+3*&c&MwpFA<8juB`8g zMnbK@jXfbH5a{ZSMgo0_U_22BC`@!rL4SQb6ikGgdV^gd#qUcd>VoZecsGS23B|uE z)SnR9mQbR;r#rSf-rdz5QT&ZP$-c1SZ`l%QSA+#$cYkj%1}+?obcNP+M>?XLJ&8oT zdt)*Y>Qns7Ly2`OS4HE!!5*zUk^lmm288>ML9*@SgV5Flb6c-A5M9VZc#Kvr`6fXnk*Y1iga{Gy3mAZ zY>NkBQT%soyeYJ$J=zg!jUv;x1*W-=_0b+`3fkL}h{i*!g1v~|>R2e!(A^j732u>c z%j*^Y%3y3wu)8nR0pV~j*O$=(@R4LFzUAgnystZoRscXJ2#>%Zgu!+SwbU#WaT|@~ zM?z_j_9=bnnyyeH9PLX)$e~ygVeSi4ae#(G`yGMy@Ew89V0Vww84rb&P=9xV1Um4V zi1&md3VNp}+759nI@-nX=?%heAkZ7??F%Ky0+{yxV4$-*671=|Gej0pEma+gY*N~} ziOuou1S@J!^pN#Pdv8pERewzltzE8Rc?_^T)0@w=^W5_0rn>sT!m5Q;S1U5VXmKH1 zRmd;K#bL!tg#L)~yj9Q=QBqvWr3ipS-Ah zJgt&m0Y-_e{ii4={#(00jb&1q@|M67Gf7@m&Ix{cclTskIhSIgMK-xTYu=t*x6AeN zfY>J}a$Qc9Ah`u@i*a7cOWw7m7>{{4Uul9@8}RBnE?;ZFV*+;@@Bv|8GvNCL?la&c z0{0tmr?B5mb9UTK0?o8Yx3_^BxOpY}wwkCJIb zhfk9rXhw%$sKd|baJi?V;&VE@Mknu%aAq8cMTcuT+^WNUI$Z7*so1Z>**S&KY183+ zzsC#0I-Kg3DW=2a97JXPIvf*VJ`L#b33*gecIxnnI($fnPtxHJ>u^k{`LtJu+w-WR z?9<^69ll?O(|jz`0UbU?f}q1XT)$2{s>5mDEz@xwK0|__r*ybDLSm&OI=oybpV8qn zb@&+_evuA8r^7GS;ffen)Q9q{i;8VJoc7u>Id%A@5(F*R;j?tOONYC3c%=@Xt;4Hz z_#7QxtHUqT;cgvXp~E#Dez^|!>F_IbxL=2hTPZ7T)8Umm`LGV3tHWbD{3;#ZufspA z!v}OY?S*C9sl(?>5Ohd~SLyJFb@&1uzE_7=>+pR#e4!5CufrGV@B=!W)?G3U>+q{3 z2zpe9U!%j1>+oxJ`1$Pl2%L|=`3Rhk!1)NAkHGl|oR7f&9})PiS+Tc^RCs_b;S5H`_D7nig;ngwAt&n_}O0uu!a=FeS#?!_(d!oS8hBte- zz|%%I`;7um8}#fK3OsFivkw(`+URDt6?oblW#a{&Hn!P~1)esv*);{8HnQ2e0#6&* z?7{+18`tcd0#6&(?9>8pC*E4%9mJpgOTN9dG0nbO;AumeJyGCkBbq&2;OXEY`;7um z8`A6-3OsE@vkw(`+JI)a6?i(J$i@piZA7yh3p{N=vug@GZ9KDe1)esX*@Xq3Hk#Qv z1)esT*{KDdHkMgyfu{{+_UxbY?ROFXYJsN>WcEaXr;TIwaDk@{WA+;bo;HfvFBEv% zAZ8yb@U$_^ZY%J#ANe%D^`o_!|xUHAQ^QTTQ7KZqrh)YJ;zx z@wIwuhHH*#yOxf}G@hHW2%_(FRyk&E$3=%5*si7B_^g1oOWjE1x^sycxV62j@mt&Y z+=ye=0LeWmDCDnW@>ee;GWRc9>Wp^i?Pc1bb0wPP8SRC?B&Nf__k;mkZiHXQQlIXB z151Cm1}2jqUaJi*{Tw6}E%kb0l9pcjWiXjP{4tlybl`6CjQSkpEVn{8Uq9(*H=~d; zYoVv5ww}|{-g9RiPIYsoqMUV1Q6wMbyc>6GF3>3eCjp&~Uk^jtU9M+bQnX%(R!ZP{ z0rX2?E(Zn%(0~K@S8jbW@6_O%ZE$Q~hn6nA9Aapo_goEXbE<#Dg5K{nioheivCud-rMSfqj(SweoPRMmdmbt| z0}Eb+yz=N-$NH5Ss^fFQRHtKs`f23*#+}t*_4K7EoVOV98JV8;8cpsyZY_wES(%#1`!#sLdp-s23woI-QrpQSOYcze(Sh<@+Xn+bhI8i4Kq&l)8M%16t`a*bW1a18FZ7{GM&NtB7^(51lj3)Z#%-e=FU5{lp9XyoO0WwS5FzOwduX`on9`K^yU5eq2i(*DS-D<+yfe1XJEoZP)Z2WEE3rt{$SL*1>a@huCCA0f=~b?>RvVVXjYYY*pRm-e1PM32CcoHFP= zWl4KaE%E;7?qh?H6Yi{hjM<co_eJ*!QKX}J+HUT?qy6=+8!m!YlZ#x8Q94~L>Ahd@HvzbBJ4IsGvU9?rg>!Dp-#s>gy-e12vM!kNj_f}Rf8j)B3 zt&7~Q%)s?5xt`(P-1W{_-pJUwUA*;E28Q64h(y?h3VKKR_YkX~C@!;v@uIl+Dxto1 zbX?|$#uUdzIN;n%4nT2qe_S-W-v1o4Kd4^bANshwgv}`8f*E1mk0~yvcw9PuJ62pO zF)D+O9W>{OV91Uu8ae$ma(E9Gb-hCvEs94Q^;c+gJf^Znu=URRqwttU7n|rXHVfnB zVKH8AW&Kf9+Y4hwKTNgtj;<|ncC7Zk=Q!}uI9NNn-nqh5Q7ii^A-r{Tz4MrpX03FI zC>QsBQ7cc671J2i#{0TR_<`Sy)yhh$g=WB85pp&I>Snup-yFusGb~h@Q06#IAega4aeNV_}G&oR;n;qYVBxm8I(p@ur%dMUb*i|)9Se9h` z2wduL_EvbExeIl576QP|E4B3Ia=PDZN0xV>PQ@{0d8?LgEZ=8IUdXzQ>UklPdSURe zWuGPSPHJ_lfZaMg`Hq%q#0A&rO0D)ob!yECuE(|BO|9F&wD^9pV2|m!pjVk%-8QCP zhq)ef!cQ98)A9sODw&$M5pnd*cKRR^y5S6t0kzbVnH1rv62zL7{)EEZJ}^Qg^>ZzC z2KEXi_(opI~^x)asqH={#c4d;JKV*`=ca(q`n%2 zqF!?Xeb+`+9;vTo*pYfS(IfTrnQVpir<7}AuGPmfOVP>9i~9bW;YKewEgX$z z4!oJmJ;8i<9=XC`kmuQ+o10S4d)9hVFM3)%sdxCraqpWHM%~4+z2Y2v!1a+{?s{S$ zO%q3OEik{3DW_{hOEpxq5v+kxGJ8=QzXTlHzt8+1A(!E>H@b3f?}K2_b2$~NG@BjrV_v1z4Xe1xrkk`(M_T$zVYLo&@+ZC6X|JFI~p zqCjx4)3FKHa&txO;5gLnn9@+u56@z7T*+KPV!PIA-{}FzZlKr~*9|{^ZU7_Zf%HxN z+I7tpwTTa52d3>RZPEtsI_y&t-+&vepFO$h&z}Ag21-o3E>WQ+al87v4C18iIF@); zOSNKNP9Ho20G3}MhqN@X?Cq?+?G+TELbuq_Eh9k06q)HoJM|X;>km&WF8A-_|Ipe_ zNAv|P_2(8`^Vk^vw$ssbLc8}(TFVvRDYjS8lv6WI^M5sbx+K+HQQnLJivd^Zm^-~9 zvnWeVj!v&2H1#uBZ?3omueem`3aP$<+1#o)=C)Q~kA8P^1tyxi8!B2eTcAk;jA|%u z3Hc#g^2J}}a_Db%LUm9Xz&8@yw!!kSRor-9N<5vrRWL8!G%Y!$+1^!Vo6cdh`iS5NTTdM23*G+dbItEX5R6 zp13AmKb^vadu%K2omf>Uh({%+RRz;WMdo^Pif)Kn8pFGit`O3riKn%~4>zZ?eO_`h zrir#&o;-kl&z=57W)GSr;(=Sz&pOY|G(A2?)8miUrhfN0IYm);!cX1}zFD4WrKr-) z=T4M0VanR&uEmv+ZkbM#B8F^VInHgHQinXPnA+B67H4R^R2J~~nbxPEwJYhu_;Am| zi?6yS=W%@folcJ<@-q16yr~HAjfe67gM&HDVHlZ*4!vRZIHuqp-2QInHQ4i{8r`WQ z?B?_f__Z>9W6cR%mY;=dO{wM1rc|Sb|7wj%&;g9+NF$p*aHDvN?lfxEQlLng7h#S~ ze~AiP6BcP9@aU6|0fWU0!KJTOA-v<=6p9 z^{a-|D-G!T%x6)2kfIM~Z0UNRCv`L3@>U}3xP;Eg>C+QHA7ELP%Vx+{}xx{LzDmtFk^D;*-^OFtn`ueZ~*Nr~i@L;p3qxm1A9xabdV~qK?cy7-PM9 z1_nHst8q7f65aXMq1UZi`&+cQ+d(2J+-+#cJO?o?mDN(es(F`I#2M7*Nw1sUgmoGX zn)I^U5vxNDso&i0!Z>WrTu9o3Pr+;n3?x1-hmBv{Hfh+rNH5RA1lqg|!v^!)#wW2h zaZ;E+XD1UaVEmuJQ!Obw~NdGN>PNiX+_iw<2fm97L@b%;9}x&+2DHj2k>>unxAJDfMVf+mDA5_Udqe{clvv}#ae#7Augkq^l}Xs5n3?wJ2W0L58^FDYS4tj zdKQZSc3)ru1ZVH0_hs|%cd-5#!ya9snPu-`j|7;#t47&NFTW&JmR??-vTEsZX?J-F z`-$b%7>y15{!R0NH}#B|5}L4LqFaWR`XS8(&FMRx&FPzMD|h7Ros(q^)N#LRPW>hG z3gWRc^!U75uV5fQRj%t2ai89biAaxUgRkXsL$J|I_e^PgViVmh`S{SgLvHbD8Jl(>~gB#v)y!oF#lmj2uTENbb0*$Gl} zB9nQA#S&M}5w@uLG2OFsue^u;!(4wa*WdR(`sv163`TeT&@KRg>tB9=|HvaF223O#tb&^`clOZM713+IkumnyG`C` zdaxgSde0D{j$gmkoO;DEcU}cnI?v(%McnjVj=5N!YU2?*-1vyWJT<){y{8Q-+UyJ= z)!O*u={*{N)UbBwRTpEcshn<>=|TEc3^FCGl+&`$nchRc1^^38I)fQQr_9ebu((PO z9zcmsxssG!={jdBZKbro)L;Z1>>s~0~BeB2fe|dYtnuafq5-G_%LM)@$i!oUwY2~H^P*| z#mcnjBxQeku(nt^Ov-KPJuaOxb-S+SGvpDJ!|B0Olr7ZUPs*|Mo?(JTF!v#!S0=T7 z3=d$Pj?U%^Y^S3e*eh1*$X8UP>-%vl`f;b@_Cw$&Vd$KG5}BV;El|0nf`yAOf3?&n zD+XXH-O`5Ip!N%>{eVf2KMvsy6;L_-Y#NjAFwhRhlG$bqI*hBaG^$C131hFvt2wCH zn7h0(uEbx_bWZn_S^^q$$&&t|R#&wXR zGDD3(QDZD$BXYVL35PbT>k$?sExm|pYr_2lKHbkSsQd(ixc8GFa|K5keLuEw<|N-P zWj^t9Ojzk#u+e+TvEw4TX<}1AW1_GraAH$HGX~#&c(5^;^D|8C{5+}sUCfo6@Q?XU z^EId3{*+HE+%GXlW*c6na6STm!wAstYUopYa^s?oJaCnpXDb9f^Tezjr$2Jw($|-L?z5D>vy7K- z7v*;g>J)UOo|m5ya(wrN4cI*#SCn7fzxTTJH_mMoywFnyWO+kVi?7+UUcv991bgT= zR+M!s0}bA0Z>u-3u4z@n>U9M8)~s$_UB9}yMOoP$>89U1aj_qka=@Tuo>IognxpUCBC=TZqun;HL$xtt%=b268sz0OI{ z4Cq5x3);{P1K9V{=4$<`Sb>7>0}T_!@y8>e{Wx9N4|)IxDYW0K#K9H)&YuR_40-@3 zf;&O`ao{-&ngONV>rR~RmY2dW&}z^O-lupNv=VO&z6071IuGwc9|aAAW3!Pr zGW^~g=seIcs2lWQ&{oi+pkdGq=v|Je>0NjesvMsfSqxeU zs)5#mZUCi(Q)refcdk(^{Z7lplg8PG5F5hr?yqw0hq>GpB+)R=Nu&b*i}By~9DG6> z6}z+1UcSOHakFheS$5HNS1qcT1C;4+0PR1X%P~a)k;rZW|1sdS@s^3|x*z`^`%y0U zDFVHA=Y7`t$z|62;Su-ctAO7?`D2JtzP#j{DhZJOv-scklU(j?#I{iWdZ{db6R;0k zjvs^O%dN-r_9vm;<41Dz>AOPtovfJse&alp*P{F#DsQwq@3(sF<@c3%?5@Gm<@Pq~ z(-Z8jdV9IY?yR%h8Yi;fwP}M+DaO}Rq=Q6$CV&kCTL?;i3|g(HC)jNoeO;yl|DOat zf-xARa@6yH)oU-`RpPa~?k{bySKg<3?A3#1EA0EN)?4fctj+deYrXxbwa$JV|EKUj zVr`xFi*@H{)p^j{4!!-*3n9<@1w(4EWQF~V#o9Q* zUS4l^dh9k{6^*}dLH-QnKQH75t;_8(>)-^P7#n9VLoSRnV|-E_fwen3>^2tPcYyB& zJ^_^4_#i@7{y<5c-L4_a4HJ?KY$Jszs3!S1%MwQHK) zS4S10I=3}6W>p9S#rgnj&%->^h&=D728wk(#rmU&nH+?xWENu7zcep3{5SQe3K}Ex za9#PKtN$I1PXccM-UfV8zMU+dhITekJD1yi)<(PEYj10?ha2oM#8*QzF`x|*ZJcO^ z2Uvg9*~4}ASd-ni-tPBHYjyViI{SbHC>!4|!!H}=UYaf_(U?C2tP~iV(*#xu0ha+Q z2X+In*`$a>x-?h&fywq)0CNND0JemL_?$&!x54gevzIrs5y|FEn&0nwA33UH2y&m) z)q4Z5F9F*R>^AsLeZ7n3gZpXTxv%sld*z_I95X=4!qN%$O7uVGB;B=6HeZAOaok&^ z--Mk5_A;9_av<@8&7l;riRxEPDy2j^*MIj8g$RZ8;r^yD0XB^68fKp0OwoY4A&k}Ut-Uvli1 zYxd*5K?&0aOV#wLK_pBMES(bNa)E9ayj*XT3%MDBN+QIR$_Ph9vy`JW*CEk;hmu&X zD)KkO-1OaF9qtkhmwvm1zHn2K^^6kUt|5^JGcczLrWqEr=V6nwuyz~o8ZpPmz z%KsqvD}~*^HIctVZnRtN;)q*NpP+4m#snP@bV$&>g6ipP+4m#snP@ zbV$&>g6Y{lCUXqfI@pxBp&wz0Q9p|6Vr#R%P;cx+Sfy z;~vHYmA|vS-@|eFJK9cB{(f}-2b6n1JO5MV%j@f}cU7+4n2aQnu9`*o+4$=D3l}9B zzj&@dlz9k_l?90Ji&A2nQZ9BcJa&cGr?G3oFTyin`y0SNL}j%18cVapVoRaFORVGG zAW}N+e-p8dqxW1&EM;j{rqYipIZ9PL1p#F$eILhZE9(V;$U_hr@1p$43+suLmVT9p zt#k`Br9RELabF?MSxN`zQ|M&%Yxtj_lzkCo>LxVsfVJHD3JR@VU@jj23E+yg2l-1_ z-ez5o{G}}Kv`$BU7R#4gJrJDD@-C}}{2Z3Aw0;rBDp6y&dDdAIde z$j@bY&Dw?hRV?qbegpY=Ebq6{V|nJYe4BL}@C7U%wtfcoYsOJiV%E*SYwN@-JNoQhFH^`Z}@` zlu7gq2sicilcdDDeG)wz;zr8S5ediCKcFQyF)x)8;SqC-zvTT@E@*{b+3d0l^HK=_ zin;(V-f`r`l6(mT)RKQuE?kXL%hRlqqYIHoVsA8oS{~_z+PFBLlyStyu9e;U?^Y($ zGj1NC%6~GSq!op|aRq95M6Esy*!T+2*n$wj17visqC#`P;p*$61v{ndL)>Ftvn**LQ9_Lb6iwU-IbUwRkp zx`pWedrI#mb`sT7vin>2j0@vI8t$o_J#bIy$Efr|&OUZeDUCM|8*lJ)X6amLA<+-M zP%8Z)UIy84x9)B(Jq+Rd1m`Zj5@jjDHH_P$JRtI#qFgipNlO)TLQY2PjY6nc9$^iw zx`YP@{bW&mqo1oR z%Vv^7DPdR6Y?^k%Obg7EIh2XBZDep9bZpnp*6G+(BQpL1vOAHR#W00osKcKHvvGPg ziPZrcDgv1Hc8vj}#=kVCY@h6xq^ zp>0!USemAhzf-5d)WnJ02Lh&9M9Fm4X5rhinbhbRqR|56ExtexUOAJ47Z!uX9^ws? zLaWK{%!w9q6+Ooq#>^L*btfH6{yV$f*pwFPLyP5)_Q^!h&$J{(W|j(dWe)yt!arS` zoAGb8%(6PDK%}iix8vWk3oq6^cq#dNyp*aIWxQ36m69rpI_bN=wN0~4Q|-r&sZ&6m z_#baus#@09oK?raaZJ7K`|6s6dXsIcx-6m2OsE%IFPouOoK&p`)l%z?(^Xqioqmg2 z?pIw$Rp&u<#%^`?kh)+;YW0wMqhc+!*ltj- zBRZs36FG<%YuQP48faV(8n)%M9^ ze#U0C%vv>79lu_kToO&FYRR-m)l0h6`9tK?1uN7`zE;Rz@eoCC+>knJvwGP{b>24h zGB`hOg{mf1dzX4iQgt0v=WbJ79JMD^bx56&R3{O?SsmY{PN`NMhLC@>yNIY?b#O9$w|W)oopVrikr=edKWMEYa#C$1a!_pmp?a?&npal$sQD&ed{VTR z*8mGQa0}Nn)fH+LQACy#wD(ff%Nx6b*@en7u0oL_S8IsoLzHjjtdpXND`b%BxE=+G z^jLH-@`*)UcB^wx6>r}PmHa_fUamsHA(g9%<{M_+qmKVBUHh-8&Wvj38qS+|&IV9s z{i?P3m)5JM|56?Q804)NU~byn9SOt|aU~I;+j4JDKjZqs(Rji|OWi&^Dk_jrI^x02 z-be=%z!Rea9l=B}5bWrPD|l{JB;@C0J)T5`l}u+Mu<_1NJPPHGPzN4!=FjKWD|hfm zb19pn@tzJmWJ`&K;<3$m`V5&(9*6@ zBoyy%2OEsHhnMn4bh_qux#o8U`|yyoa6B4`Ci~_mBZyMR`~-dCs}F_jp(j(vSakE6Qrz@%?BYoXn5qv_d9Um0K zqqjmaL=CU&@o28zP&}w_WnPw=OI_1KPmEK-g+^2VD8125As#v2pG9h{tCI;H=|CbH zpf*M~D;NeH-Es6Jh5|WPh&SuISUl9%m+vO2gJ-beQE%uDA0G|eh@Z)YqtQE*ShNpg zB-*#0jRd8SkG3G%h{v(<%6g*Fm_nhbYF8G7qrIU8U3m80f`({&vKJ4w>s!D-TDTzD z7pI4-F6e4+Uw|$PT(ej_Vzn!hTu`%UL3gCRC)p8_pUmr5n1(<{Yi#Vs$4)L89WV1hT8;H@Tj*aY8Zg45?f$MT1cD#pUi#?>(7EqFKjfFBJvq_ONg4|y7; z@;S>=g>4w|ZnS*ATjIZG_AgXMz2A$y)l`g!YW4vmMWIa_r5|AF>{76Z7Q1tfqDIJ1 z0q)wu5f}3VhZe$)Jg<_U16V5Xw&h%29t_c;2h}?uaO{^@`VZ7gxO`5zyv#NVdAE?4 z_U~Z0P}Y&HCiqTar`pYh*=Nd--7E0n>p33cM4>PAPZfDRc^0@!4~YCrCh~8Z;D2N| z;(sGIP$S|w8S~Lt^D|N)tOl6Fed8$n#R! zUk{kb?=``{W`aL%g1=ybzrt|DvyQh%G*3BaB45VF8<*9;PGjR=kMR5gF+SzFux#&5 zz^7n7ZxHi2SeDia`4Qm{`-~k*;!GYr?BjA${$3`}G5za9Cio*J_}78E^ae!!7;xtp z*Y!!@bH2r}JZ~PoYlF2(2d9FWO7^2Tdj&k5Ip=!3XO>@(w_OBv3fqL&pW_$?-Q1UOyqa-AuSB~9c9 zP4EXy@V_^~A2Y$9H^G0(aHn#H7R*TRaH6~|@R)}KxExrr;#iWcL*)8|7V=0Ffsb|l zUTlKXFTGKJ8IRQGn#g~Mu170YF)mhJ{$+`Ye2cLE529W5Qlq6ko~Wsc;_1)9jopDn zuuB2Zmq_AwJKC|glaChNtNSRxRNB)S9Gw9+{SWudeen2Ua&Wws>0ut)9AOF9aLbukx&Hsu$5p1PTqx zLpp~Hm^c_=D8>SM0YiYEm`+b^kK+03)CVY_LlTx}dwljta<_cuH$DGb_n39k7$ZLU zibr+E7|)&$1iE^o5%GNU0DDk+adpKHiRS|)5y*EPdvbcQ27j)5;pyx}&v|Dfnx2y$ zz<2lpv5oS9=tU;@v)79uc60&_*5h@_L?RmTv2zoDODM5!ZthWo5K#cNaG{PP<+eHp?Dw8>lFVgJmKC;7pmgt z9mAPG03L}ek@utzXMoZ6Xb+n-`=WtxFw!w9iYucDSY3tJ&MgYAL;4nK1T$l?+rDI? zF4%qtuZf%w7en8fp=e4!ju%j>DOP-Ih4MI=j8Bk%nHoDr^e+!3 z_;+=iBAwBEeVAzJh?A_tjP4Ly)<;hDqY`ocOzp_GmU^6hDOh8jj5FGBZ+oH;8S*<2 zVh6AOqG`mBQ|>jvZn_wl!R~&Xc{b7^itRk~nEks8SHq&k%I0`?!Z1qULw!$o zY<0Z53kU7e?T!#`)o>>d@MtG-D%)8&Xvc>PiX-R45WrWK`Jp}3gNDe~V>ow(_!WTe zjCXHLCa^w`_hNj|p>InsPQ^hJaZbZBhsh1+`bt#1TJu;iWV%8j64C8{~v%+T%~=*1%{G~y()5_ z%em3x=Mfa>^<6?wQn%<&sgIpCOOpN*IK6(`WxQNcDaTRT3-cuDez1D|n9!HB`hDvE zjzM3ZTTA-3i`OS#WxbMr0vUb%@|;%E$x={IwgYqBqH_Y z`w5cLZ(rz>vHq7(sMp`QhD%GjI6p8rF2|3w`8qOm_AkRMzejlPma*lfzNEi_m_w(Z zf8T7w2h;yE#K=WizkGkhCiGn*Fm(M68cREvL)-6=REG)xrD4o${YJ{im1O@3J5CouQ1@`Dj#|7oF5=hgaT)W6z9KM>_wUp6QhSf$=XU!{p1>AUY!|7xLc zZ0B&2>pv(jEY9ZRCjI!RiT>(-u0ZpfK1n@2HB`aG&k6l~;(l@&&^h>*<3Y~ Date: Fri, 11 Oct 2024 05:23:55 +0200 Subject: [PATCH 11/80] manque texture et direction --- .gitignore | 5 +++++ algo.c | 53 +++++++++++++++++++++++++++++++++++++---------------- algo.h | 4 +++- cub3d | Bin 39080 -> 0 bytes 4 files changed, 45 insertions(+), 17 deletions(-) delete mode 100755 cub3d diff --git a/.gitignore b/.gitignore index c6127b3..9b2387a 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,8 @@ modules.order Module.symvers Mkfile.old dkms.conf + +# Files +Libft +Minilibx +.vscode diff --git a/algo.c b/algo.c index 569e103..4c40eb5 100644 --- a/algo.c +++ b/algo.c @@ -6,7 +6,7 @@ /* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/10 18:22:08 by greg ### ########.fr */ +/* Updated: 2024/10/11 05:16:06 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -61,7 +61,8 @@ static int render(t_ray *ray) int x; double width = 640; double height = 480; - int mapX, mapY, hit, side; + int hit; + int side; int *img_data = (int *)mlx_get_data_addr(ray->img_ptr, &(int){32}, &(int){width * 4}, &(int){0}); // clear image data @@ -75,8 +76,8 @@ static int render(t_ray *ray) ray->raydirX = ray->dirX + ray->planeX * ray->cameraX; ray->raydirY = ray->dirY + ray->planeY * ray->cameraX; - mapX = (int)ray->posX; - mapY = (int)ray->posY; + ray->mapX = (int)ray->posX; + ray->mapY = (int)ray->posY; ray->deltadistX = (ray->raydirX == 0) ? 1e30 : fabs(1 / ray->raydirX); ray->deltadistY = (ray->raydirY == 0) ? 1e30 : fabs(1 / ray->raydirY); @@ -85,22 +86,22 @@ static int render(t_ray *ray) if (ray->raydirX < 0) { ray->stepX = -1; - ray->sidedistX = (ray->posX - mapX) * ray->deltadistX; + ray->sidedistX = (ray->posX - ray->mapX) * ray->deltadistX; } else { ray->stepX = 1; - ray->sidedistX = (mapX + 1.0 - ray->posX) * ray->deltadistX; + ray->sidedistX = (ray->mapX + 1.0 - ray->posX) * ray->deltadistX; } if (ray->raydirY < 0) { ray->stepY = -1; - ray->sidedistY = (ray->posY - mapY) * ray->deltadistY; + ray->sidedistY = (ray->posY - ray->mapY) * ray->deltadistY; } else { ray->stepY = 1; - ray->sidedistY = (mapY + 1.0 - ray->posY) * ray->deltadistY; + ray->sidedistY = (ray->mapY + 1.0 - ray->posY) * ray->deltadistY; } hit = 0; @@ -110,17 +111,17 @@ static int render(t_ray *ray) if(ray->sidedistX < ray->sidedistY) { ray->sidedistX += ray->deltadistX; - mapX += ray->stepX; + ray->mapX += ray->stepX; side = 0; } else { ray->sidedistY += ray->deltadistY; - mapY += ray->stepY; + ray->mapY += ray->stepY; side = 1; } //Check if ray has hit a wall - if(worldMap[mapX][mapY] == 1) + if(worldMap[ray->mapX][ray->mapY] == 1) hit = 1; } if(side == 0) @@ -139,12 +140,25 @@ static int render(t_ray *ray) drawEnd = height - 1; // draw vertical line - int y = drawStart; + int y = 0; + while (y <= drawStart) + { + img_data[y * (int)width + x] = 0x29f8ff;; + y++; + } + y = drawStart; while (y <= drawEnd) { img_data[y * (int)width + x] = 0xFF0000; y++; } + y++; + while (y <= height) + { + img_data[y * (int)width + x] = 0xFF985C; + y++; + } + x++; } @@ -158,14 +172,18 @@ static int keypress(int keycode, t_ray *ray) //move forward if no wall in front of you if (keycode == 119) { - ray->posX += ray->dirX * ray->movespeed; - ray->posY += ray->dirY * ray->movespeed; + if (worldMap[(int)((ray->posX + ray->dirX * ray->movespeed))][(int)(ray->posY)] != 1) + ray->posX += ray->dirX * ray->movespeed; + if (worldMap[(int)(ray->posX)][(int)(ray->posY + ray->dirY * ray->movespeed)] != 1) + ray->posY += ray->dirY * ray->movespeed; } //move backwards if no wall behind you if (keycode == 115) { - ray->posX -= ray->dirX * ray->movespeed; - ray->posY -= ray->dirY * ray->movespeed; + if (worldMap[(int)(ray->posX - ray->dirX * ray->movespeed)][(int)(ray->posY)] != 1) + ray->posX -= ray->dirX * ray->movespeed; + if (worldMap[(int)(ray->posX)][(int)(ray->posY - ray->dirY * ray->movespeed)] != 1) + ray->posY -= ray->dirY * ray->movespeed; } //rotate to the right if (keycode == 100) @@ -189,6 +207,9 @@ static int keypress(int keycode, t_ray *ray) ray->planeX = ray->planeX * cos(ray->rotspeed) - ray->planeY * sin(ray->rotspeed); ray->planeY = ray->oldPlaneX * sin(ray->rotspeed) + ray->planeY * cos(ray->rotspeed); } + + if (keycode == 65307) + exit(0); // render the updated frame after key press render(ray); return (0); diff --git a/algo.h b/algo.h index bae8383..3b5585c 100644 --- a/algo.h +++ b/algo.h @@ -6,7 +6,7 @@ /* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/10 17:53:01 by greg ### ########.fr */ +/* Updated: 2024/10/11 04:32:39 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,6 +56,8 @@ typedef struct s_ray void *win_ptr; void *img_ptr; int *img_data; + int mapX; + int mapY; } t_ray; #endif diff --git a/cub3d b/cub3d deleted file mode 100755 index e95c3fcd32b6daebfd0908341c01b025f9618055..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 39080 zcmeHwdwg5PmH(CO>nJZtd4U6zD8Yb36UR;h7($3-Th4WG5;b;+QUbDK%a*~GR9Q+K zO2EVkjaCF4(g*F2ve~xV&2GDGw(YN*rWBm;NYVlu(vnRJZ4Ct~H9*sp(scXK?|bGU zU0wSE`)hxn{o|MM$2xPqbIzGFXXehG89nYj-sVQD#iGbmqTHwuxAzK;xJ5zuL6HG* zE49jGyk4$UC}rSF8OF=qoS>AaQ`TZ?6L<+I>6KGv40;KN6-lLsL`lyq*)HHEk}6Kl zlb%Xh7rh|4*lV7C{z}eEs@G%n`GmZIJ|-F@sa}s_bM6+dckYg2s@Xa36IAL^xJb{o zftTBQim6M)Q&JgE@{#^)MLdnPnwwE1HR^?ho{=^PJxQq!N-eJ^I{t6!^9eoeBixRW z-as9NB&n?LBhaI`e9+_+f@?&5X8m9j6-X+oR~GbiZ@gylf}W1~J>8LH|NQ>iYvy0G zxT-H&wUAjRH5dMAOf6rvRzbH66DGo_SO+*S?NQluQBLw}dwlLU3B`$ zmYrQ6{S3*F-=sq_l*pdwa>i4>7XKu}<8d#;38VBv==olr8~as*fvIB@-3NnX;a`L7 zSonv4yT-6H$He}%Cid%1$wzD+3*&c&MwpFA<8juB`8g zMnbK@jXfbH5a{ZSMgo0_U_22BC`@!rL4SQb6ikGgdV^gd#qUcd>VoZecsGS23B|uE z)SnR9mQbR;r#rSf-rdz5QT&ZP$-c1SZ`l%QSA+#$cYkj%1}+?obcNP+M>?XLJ&8oT zdt)*Y>Qns7Ly2`OS4HE!!5*zUk^lmm288>ML9*@SgV5Flb6c-A5M9VZc#Kvr`6fXnk*Y1iga{Gy3mAZ zY>NkBQT%soyeYJ$J=zg!jUv;x1*W-=_0b+`3fkL}h{i*!g1v~|>R2e!(A^j732u>c z%j*^Y%3y3wu)8nR0pV~j*O$=(@R4LFzUAgnystZoRscXJ2#>%Zgu!+SwbU#WaT|@~ zM?z_j_9=bnnyyeH9PLX)$e~ygVeSi4ae#(G`yGMy@Ew89V0Vww84rb&P=9xV1Um4V zi1&md3VNp}+759nI@-nX=?%heAkZ7??F%Ky0+{yxV4$-*671=|Gej0pEma+gY*N~} ziOuou1S@J!^pN#Pdv8pERewzltzE8Rc?_^T)0@w=^W5_0rn>sT!m5Q;S1U5VXmKH1 zRmd;K#bL!tg#L)~yj9Q=QBqvWr3ipS-Ah zJgt&m0Y-_e{ii4={#(00jb&1q@|M67Gf7@m&Ix{cclTskIhSIgMK-xTYu=t*x6AeN zfY>J}a$Qc9Ah`u@i*a7cOWw7m7>{{4Uul9@8}RBnE?;ZFV*+;@@Bv|8GvNCL?la&c z0{0tmr?B5mb9UTK0?o8Yx3_^BxOpY}wwkCJIb zhfk9rXhw%$sKd|baJi?V;&VE@Mknu%aAq8cMTcuT+^WNUI$Z7*so1Z>**S&KY183+ zzsC#0I-Kg3DW=2a97JXPIvf*VJ`L#b33*gecIxnnI($fnPtxHJ>u^k{`LtJu+w-WR z?9<^69ll?O(|jz`0UbU?f}q1XT)$2{s>5mDEz@xwK0|__r*ybDLSm&OI=oybpV8qn zb@&+_evuA8r^7GS;ffen)Q9q{i;8VJoc7u>Id%A@5(F*R;j?tOONYC3c%=@Xt;4Hz z_#7QxtHUqT;cgvXp~E#Dez^|!>F_IbxL=2hTPZ7T)8Umm`LGV3tHWbD{3;#ZufspA z!v}OY?S*C9sl(?>5Ohd~SLyJFb@&1uzE_7=>+pR#e4!5CufrGV@B=!W)?G3U>+q{3 z2zpe9U!%j1>+oxJ`1$Pl2%L|=`3Rhk!1)NAkHGl|oR7f&9})PiS+Tc^RCs_b;S5H`_D7nig;ngwAt&n_}O0uu!a=FeS#?!_(d!oS8hBte- zz|%%I`;7um8}#fK3OsFivkw(`+URDt6?oblW#a{&Hn!P~1)esv*);{8HnQ2e0#6&* z?7{+18`tcd0#6&(?9>8pC*E4%9mJpgOTN9dG0nbO;AumeJyGCkBbq&2;OXEY`;7um z8`A6-3OsE@vkw(`+JI)a6?i(J$i@piZA7yh3p{N=vug@GZ9KDe1)esX*@Xq3Hk#Qv z1)esT*{KDdHkMgyfu{{+_UxbY?ROFXYJsN>WcEaXr;TIwaDk@{WA+;bo;HfvFBEv% zAZ8yb@U$_^ZY%J#ANe%D^`o_!|xUHAQ^QTTQ7KZqrh)YJ;zx z@wIwuhHH*#yOxf}G@hHW2%_(FRyk&E$3=%5*si7B_^g1oOWjE1x^sycxV62j@mt&Y z+=ye=0LeWmDCDnW@>ee;GWRc9>Wp^i?Pc1bb0wPP8SRC?B&Nf__k;mkZiHXQQlIXB z151Cm1}2jqUaJi*{Tw6}E%kb0l9pcjWiXjP{4tlybl`6CjQSkpEVn{8Uq9(*H=~d; zYoVv5ww}|{-g9RiPIYsoqMUV1Q6wMbyc>6GF3>3eCjp&~Uk^jtU9M+bQnX%(R!ZP{ z0rX2?E(Zn%(0~K@S8jbW@6_O%ZE$Q~hn6nA9Aapo_goEXbE<#Dg5K{nioheivCud-rMSfqj(SweoPRMmdmbt| z0}Eb+yz=N-$NH5Ss^fFQRHtKs`f23*#+}t*_4K7EoVOV98JV8;8cpsyZY_wES(%#1`!#sLdp-s23woI-QrpQSOYcze(Sh<@+Xn+bhI8i4Kq&l)8M%16t`a*bW1a18FZ7{GM&NtB7^(51lj3)Z#%-e=FU5{lp9XyoO0WwS5FzOwduX`on9`K^yU5eq2i(*DS-D<+yfe1XJEoZP)Z2WEE3rt{$SL*1>a@huCCA0f=~b?>RvVVXjYYY*pRm-e1PM32CcoHFP= zWl4KaE%E;7?qh?H6Yi{hjM<co_eJ*!QKX}J+HUT?qy6=+8!m!YlZ#x8Q94~L>Ahd@HvzbBJ4IsGvU9?rg>!Dp-#s>gy-e12vM!kNj_f}Rf8j)B3 zt&7~Q%)s?5xt`(P-1W{_-pJUwUA*;E28Q64h(y?h3VKKR_YkX~C@!;v@uIl+Dxto1 zbX?|$#uUdzIN;n%4nT2qe_S-W-v1o4Kd4^bANshwgv}`8f*E1mk0~yvcw9PuJ62pO zF)D+O9W>{OV91Uu8ae$ma(E9Gb-hCvEs94Q^;c+gJf^Znu=URRqwttU7n|rXHVfnB zVKH8AW&Kf9+Y4hwKTNgtj;<|ncC7Zk=Q!}uI9NNn-nqh5Q7ii^A-r{Tz4MrpX03FI zC>QsBQ7cc671J2i#{0TR_<`Sy)yhh$g=WB85pp&I>Snup-yFusGb~h@Q06#IAega4aeNV_}G&oR;n;qYVBxm8I(p@ur%dMUb*i|)9Se9h` z2wduL_EvbExeIl576QP|E4B3Ia=PDZN0xV>PQ@{0d8?LgEZ=8IUdXzQ>UklPdSURe zWuGPSPHJ_lfZaMg`Hq%q#0A&rO0D)ob!yECuE(|BO|9F&wD^9pV2|m!pjVk%-8QCP zhq)ef!cQ98)A9sODw&$M5pnd*cKRR^y5S6t0kzbVnH1rv62zL7{)EEZJ}^Qg^>ZzC z2KEXi_(opI~^x)asqH={#c4d;JKV*`=ca(q`n%2 zqF!?Xeb+`+9;vTo*pYfS(IfTrnQVpir<7}AuGPmfOVP>9i~9bW;YKewEgX$z z4!oJmJ;8i<9=XC`kmuQ+o10S4d)9hVFM3)%sdxCraqpWHM%~4+z2Y2v!1a+{?s{S$ zO%q3OEik{3DW_{hOEpxq5v+kxGJ8=QzXTlHzt8+1A(!E>H@b3f?}K2_b2$~NG@BjrV_v1z4Xe1xrkk`(M_T$zVYLo&@+ZC6X|JFI~p zqCjx4)3FKHa&txO;5gLnn9@+u56@z7T*+KPV!PIA-{}FzZlKr~*9|{^ZU7_Zf%HxN z+I7tpwTTa52d3>RZPEtsI_y&t-+&vepFO$h&z}Ag21-o3E>WQ+al87v4C18iIF@); zOSNKNP9Ho20G3}MhqN@X?Cq?+?G+TELbuq_Eh9k06q)HoJM|X;>km&WF8A-_|Ipe_ zNAv|P_2(8`^Vk^vw$ssbLc8}(TFVvRDYjS8lv6WI^M5sbx+K+HQQnLJivd^Zm^-~9 zvnWeVj!v&2H1#uBZ?3omueem`3aP$<+1#o)=C)Q~kA8P^1tyxi8!B2eTcAk;jA|%u z3Hc#g^2J}}a_Db%LUm9Xz&8@yw!!kSRor-9N<5vrRWL8!G%Y!$+1^!Vo6cdh`iS5NTTdM23*G+dbItEX5R6 zp13AmKb^vadu%K2omf>Uh({%+RRz;WMdo^Pif)Kn8pFGit`O3riKn%~4>zZ?eO_`h zrir#&o;-kl&z=57W)GSr;(=Sz&pOY|G(A2?)8miUrhfN0IYm);!cX1}zFD4WrKr-) z=T4M0VanR&uEmv+ZkbM#B8F^VInHgHQinXPnA+B67H4R^R2J~~nbxPEwJYhu_;Am| zi?6yS=W%@folcJ<@-q16yr~HAjfe67gM&HDVHlZ*4!vRZIHuqp-2QInHQ4i{8r`WQ z?B?_f__Z>9W6cR%mY;=dO{wM1rc|Sb|7wj%&;g9+NF$p*aHDvN?lfxEQlLng7h#S~ ze~AiP6BcP9@aU6|0fWU0!KJTOA-v<=6p9 z^{a-|D-G!T%x6)2kfIM~Z0UNRCv`L3@>U}3xP;Eg>C+QHA7ELP%Vx+{}xx{LzDmtFk^D;*-^OFtn`ueZ~*Nr~i@L;p3qxm1A9xabdV~qK?cy7-PM9 z1_nHst8q7f65aXMq1UZi`&+cQ+d(2J+-+#cJO?o?mDN(es(F`I#2M7*Nw1sUgmoGX zn)I^U5vxNDso&i0!Z>WrTu9o3Pr+;n3?x1-hmBv{Hfh+rNH5RA1lqg|!v^!)#wW2h zaZ;E+XD1UaVEmuJQ!Obw~NdGN>PNiX+_iw<2fm97L@b%;9}x&+2DHj2k>>unxAJDfMVf+mDA5_Udqe{clvv}#ae#7Augkq^l}Xs5n3?wJ2W0L58^FDYS4tj zdKQZSc3)ru1ZVH0_hs|%cd-5#!ya9snPu-`j|7;#t47&NFTW&JmR??-vTEsZX?J-F z`-$b%7>y15{!R0NH}#B|5}L4LqFaWR`XS8(&FMRx&FPzMD|h7Ros(q^)N#LRPW>hG z3gWRc^!U75uV5fQRj%t2ai89biAaxUgRkXsL$J|I_e^PgViVmh`S{SgLvHbD8Jl(>~gB#v)y!oF#lmj2uTENbb0*$Gl} zB9nQA#S&M}5w@uLG2OFsue^u;!(4wa*WdR(`sv163`TeT&@KRg>tB9=|HvaF223O#tb&^`clOZM713+IkumnyG`C` zdaxgSde0D{j$gmkoO;DEcU}cnI?v(%McnjVj=5N!YU2?*-1vyWJT<){y{8Q-+UyJ= z)!O*u={*{N)UbBwRTpEcshn<>=|TEc3^FCGl+&`$nchRc1^^38I)fQQr_9ebu((PO z9zcmsxssG!={jdBZKbro)L;Z1>>s~0~BeB2fe|dYtnuafq5-G_%LM)@$i!oUwY2~H^P*| z#mcnjBxQeku(nt^Ov-KPJuaOxb-S+SGvpDJ!|B0Olr7ZUPs*|Mo?(JTF!v#!S0=T7 z3=d$Pj?U%^Y^S3e*eh1*$X8UP>-%vl`f;b@_Cw$&Vd$KG5}BV;El|0nf`yAOf3?&n zD+XXH-O`5Ip!N%>{eVf2KMvsy6;L_-Y#NjAFwhRhlG$bqI*hBaG^$C131hFvt2wCH zn7h0(uEbx_bWZn_S^^q$$&&t|R#&wXR zGDD3(QDZD$BXYVL35PbT>k$?sExm|pYr_2lKHbkSsQd(ixc8GFa|K5keLuEw<|N-P zWj^t9Ojzk#u+e+TvEw4TX<}1AW1_GraAH$HGX~#&c(5^;^D|8C{5+}sUCfo6@Q?XU z^EId3{*+HE+%GXlW*c6na6STm!wAstYUopYa^s?oJaCnpXDb9f^Tezjr$2Jw($|-L?z5D>vy7K- z7v*;g>J)UOo|m5ya(wrN4cI*#SCn7fzxTTJH_mMoywFnyWO+kVi?7+UUcv991bgT= zR+M!s0}bA0Z>u-3u4z@n>U9M8)~s$_UB9}yMOoP$>89U1aj_qka=@Tuo>IognxpUCBC=TZqun;HL$xtt%=b268sz0OI{ z4Cq5x3);{P1K9V{=4$<`Sb>7>0}T_!@y8>e{Wx9N4|)IxDYW0K#K9H)&YuR_40-@3 zf;&O`ao{-&ngONV>rR~RmY2dW&}z^O-lupNv=VO&z6071IuGwc9|aAAW3!Pr zGW^~g=seIcs2lWQ&{oi+pkdGq=v|Je>0NjesvMsfSqxeU zs)5#mZUCi(Q)refcdk(^{Z7lplg8PG5F5hr?yqw0hq>GpB+)R=Nu&b*i}By~9DG6> z6}z+1UcSOHakFheS$5HNS1qcT1C;4+0PR1X%P~a)k;rZW|1sdS@s^3|x*z`^`%y0U zDFVHA=Y7`t$z|62;Su-ctAO7?`D2JtzP#j{DhZJOv-scklU(j?#I{iWdZ{db6R;0k zjvs^O%dN-r_9vm;<41Dz>AOPtovfJse&alp*P{F#DsQwq@3(sF<@c3%?5@Gm<@Pq~ z(-Z8jdV9IY?yR%h8Yi;fwP}M+DaO}Rq=Q6$CV&kCTL?;i3|g(HC)jNoeO;yl|DOat zf-xARa@6yH)oU-`RpPa~?k{bySKg<3?A3#1EA0EN)?4fctj+deYrXxbwa$JV|EKUj zVr`xFi*@H{)p^j{4!!-*3n9<@1w(4EWQF~V#o9Q* zUS4l^dh9k{6^*}dLH-QnKQH75t;_8(>)-^P7#n9VLoSRnV|-E_fwen3>^2tPcYyB& zJ^_^4_#i@7{y<5c-L4_a4HJ?KY$Jszs3!S1%MwQHK) zS4S10I=3}6W>p9S#rgnj&%->^h&=D728wk(#rmU&nH+?xWENu7zcep3{5SQe3K}Ex za9#PKtN$I1PXccM-UfV8zMU+dhITekJD1yi)<(PEYj10?ha2oM#8*QzF`x|*ZJcO^ z2Uvg9*~4}ASd-ni-tPBHYjyViI{SbHC>!4|!!H}=UYaf_(U?C2tP~iV(*#xu0ha+Q z2X+In*`$a>x-?h&fywq)0CNND0JemL_?$&!x54gevzIrs5y|FEn&0nwA33UH2y&m) z)q4Z5F9F*R>^AsLeZ7n3gZpXTxv%sld*z_I95X=4!qN%$O7uVGB;B=6HeZAOaok&^ z--Mk5_A;9_av<@8&7l;riRxEPDy2j^*MIj8g$RZ8;r^yD0XB^68fKp0OwoY4A&k}Ut-Uvli1 zYxd*5K?&0aOV#wLK_pBMES(bNa)E9ayj*XT3%MDBN+QIR$_Ph9vy`JW*CEk;hmu&X zD)KkO-1OaF9qtkhmwvm1zHn2K^^6kUt|5^JGcczLrWqEr=V6nwuyz~o8ZpPmz z%KsqvD}~*^HIctVZnRtN;)q*NpP+4m#snP@bV$&>g6ipP+4m#snP@ zbV$&>g6Y{lCUXqfI@pxBp&wz0Q9p|6Vr#R%P;cx+Sfy z;~vHYmA|vS-@|eFJK9cB{(f}-2b6n1JO5MV%j@f}cU7+4n2aQnu9`*o+4$=D3l}9B zzj&@dlz9k_l?90Ji&A2nQZ9BcJa&cGr?G3oFTyin`y0SNL}j%18cVapVoRaFORVGG zAW}N+e-p8dqxW1&EM;j{rqYipIZ9PL1p#F$eILhZE9(V;$U_hr@1p$43+suLmVT9p zt#k`Br9RELabF?MSxN`zQ|M&%Yxtj_lzkCo>LxVsfVJHD3JR@VU@jj23E+yg2l-1_ z-ez5o{G}}Kv`$BU7R#4gJrJDD@-C}}{2Z3Aw0;rBDp6y&dDdAIde z$j@bY&Dw?hRV?qbegpY=Ebq6{V|nJYe4BL}@C7U%wtfcoYsOJiV%E*SYwN@-JNoQhFH^`Z}@` zlu7gq2sicilcdDDeG)wz;zr8S5ediCKcFQyF)x)8;SqC-zvTT@E@*{b+3d0l^HK=_ zin;(V-f`r`l6(mT)RKQuE?kXL%hRlqqYIHoVsA8oS{~_z+PFBLlyStyu9e;U?^Y($ zGj1NC%6~GSq!op|aRq95M6Esy*!T+2*n$wj17visqC#`P;p*$61v{ndL)>Ftvn**LQ9_Lb6iwU-IbUwRkp zx`pWedrI#mb`sT7vin>2j0@vI8t$o_J#bIy$Efr|&OUZeDUCM|8*lJ)X6amLA<+-M zP%8Z)UIy84x9)B(Jq+Rd1m`Zj5@jjDHH_P$JRtI#qFgipNlO)TLQY2PjY6nc9$^iw zx`YP@{bW&mqo1oR z%Vv^7DPdR6Y?^k%Obg7EIh2XBZDep9bZpnp*6G+(BQpL1vOAHR#W00osKcKHvvGPg ziPZrcDgv1Hc8vj}#=kVCY@h6xq^ zp>0!USemAhzf-5d)WnJ02Lh&9M9Fm4X5rhinbhbRqR|56ExtexUOAJ47Z!uX9^ws? zLaWK{%!w9q6+Ooq#>^L*btfH6{yV$f*pwFPLyP5)_Q^!h&$J{(W|j(dWe)yt!arS` zoAGb8%(6PDK%}iix8vWk3oq6^cq#dNyp*aIWxQ36m69rpI_bN=wN0~4Q|-r&sZ&6m z_#baus#@09oK?raaZJ7K`|6s6dXsIcx-6m2OsE%IFPouOoK&p`)l%z?(^Xqioqmg2 z?pIw$Rp&u<#%^`?kh)+;YW0wMqhc+!*ltj- zBRZs36FG<%YuQP48faV(8n)%M9^ ze#U0C%vv>79lu_kToO&FYRR-m)l0h6`9tK?1uN7`zE;Rz@eoCC+>knJvwGP{b>24h zGB`hOg{mf1dzX4iQgt0v=WbJ79JMD^bx56&R3{O?SsmY{PN`NMhLC@>yNIY?b#O9$w|W)oopVrikr=edKWMEYa#C$1a!_pmp?a?&npal$sQD&ed{VTR z*8mGQa0}Nn)fH+LQACy#wD(ff%Nx6b*@en7u0oL_S8IsoLzHjjtdpXND`b%BxE=+G z^jLH-@`*)UcB^wx6>r}PmHa_fUamsHA(g9%<{M_+qmKVBUHh-8&Wvj38qS+|&IV9s z{i?P3m)5JM|56?Q804)NU~byn9SOt|aU~I;+j4JDKjZqs(Rji|OWi&^Dk_jrI^x02 z-be=%z!Rea9l=B}5bWrPD|l{JB;@C0J)T5`l}u+Mu<_1NJPPHGPzN4!=FjKWD|hfm zb19pn@tzJmWJ`&K;<3$m`V5&(9*6@ zBoyy%2OEsHhnMn4bh_qux#o8U`|yyoa6B4`Ci~_mBZyMR`~-dCs}F_jp(j(vSakE6Qrz@%?BYoXn5qv_d9Um0K zqqjmaL=CU&@o28zP&}w_WnPw=OI_1KPmEK-g+^2VD8125As#v2pG9h{tCI;H=|CbH zpf*M~D;NeH-Es6Jh5|WPh&SuISUl9%m+vO2gJ-beQE%uDA0G|eh@Z)YqtQE*ShNpg zB-*#0jRd8SkG3G%h{v(<%6g*Fm_nhbYF8G7qrIU8U3m80f`({&vKJ4w>s!D-TDTzD z7pI4-F6e4+Uw|$PT(ej_Vzn!hTu`%UL3gCRC)p8_pUmr5n1(<{Yi#Vs$4)L89WV1hT8;H@Tj*aY8Zg45?f$MT1cD#pUi#?>(7EqFKjfFBJvq_ONg4|y7; z@;S>=g>4w|ZnS*ATjIZG_AgXMz2A$y)l`g!YW4vmMWIa_r5|AF>{76Z7Q1tfqDIJ1 z0q)wu5f}3VhZe$)Jg<_U16V5Xw&h%29t_c;2h}?uaO{^@`VZ7gxO`5zyv#NVdAE?4 z_U~Z0P}Y&HCiqTar`pYh*=Nd--7E0n>p33cM4>PAPZfDRc^0@!4~YCrCh~8Z;D2N| z;(sGIP$S|w8S~Lt^D|N)tOl6Fed8$n#R! zUk{kb?=``{W`aL%g1=ybzrt|DvyQh%G*3BaB45VF8<*9;PGjR=kMR5gF+SzFux#&5 zz^7n7ZxHi2SeDia`4Qm{`-~k*;!GYr?BjA${$3`}G5za9Cio*J_}78E^ae!!7;xtp z*Y!!@bH2r}JZ~PoYlF2(2d9FWO7^2Tdj&k5Ip=!3XO>@(w_OBv3fqL&pW_$?-Q1UOyqa-AuSB~9c9 zP4EXy@V_^~A2Y$9H^G0(aHn#H7R*TRaH6~|@R)}KxExrr;#iWcL*)8|7V=0Ffsb|l zUTlKXFTGKJ8IRQGn#g~Mu170YF)mhJ{$+`Ye2cLE529W5Qlq6ko~Wsc;_1)9jopDn zuuB2Zmq_AwJKC|glaChNtNSRxRNB)S9Gw9+{SWudeen2Ua&Wws>0ut)9AOF9aLbukx&Hsu$5p1PTqx zLpp~Hm^c_=D8>SM0YiYEm`+b^kK+03)CVY_LlTx}dwljta<_cuH$DGb_n39k7$ZLU zibr+E7|)&$1iE^o5%GNU0DDk+adpKHiRS|)5y*EPdvbcQ27j)5;pyx}&v|Dfnx2y$ zz<2lpv5oS9=tU;@v)79uc60&_*5h@_L?RmTv2zoDODM5!ZthWo5K#cNaG{PP<+eHp?Dw8>lFVgJmKC;7pmgt z9mAPG03L}ek@utzXMoZ6Xb+n-`=WtxFw!w9iYucDSY3tJ&MgYAL;4nK1T$l?+rDI? zF4%qtuZf%w7en8fp=e4!ju%j>DOP-Ih4MI=j8Bk%nHoDr^e+!3 z_;+=iBAwBEeVAzJh?A_tjP4Ly)<;hDqY`ocOzp_GmU^6hDOh8jj5FGBZ+oH;8S*<2 zVh6AOqG`mBQ|>jvZn_wl!R~&Xc{b7^itRk~nEks8SHq&k%I0`?!Z1qULw!$o zY<0Z53kU7e?T!#`)o>>d@MtG-D%)8&Xvc>PiX-R45WrWK`Jp}3gNDe~V>ow(_!WTe zjCXHLCa^w`_hNj|p>InsPQ^hJaZbZBhsh1+`bt#1TJu;iWV%8j64C8{~v%+T%~=*1%{G~y()5_ z%em3x=Mfa>^<6?wQn%<&sgIpCOOpN*IK6(`WxQNcDaTRT3-cuDez1D|n9!HB`hDvE zjzM3ZTTA-3i`OS#WxbMr0vUb%@|;%E$x={IwgYqBqH_Y z`w5cLZ(rz>vHq7(sMp`QhD%GjI6p8rF2|3w`8qOm_AkRMzejlPma*lfzNEi_m_w(Z zf8T7w2h;yE#K=WizkGkhCiGn*Fm(M68cREvL)-6=REG)xrD4o${YJ{im1O@3J5CouQ1@`Dj#|7oF5=hgaT)W6z9KM>_wUp6QhSf$=XU!{p1>AUY!|7xLc zZ0B&2>pv(jEY9ZRCjI!RiT>(-u0ZpfK1n@2HB`aG&k6l~;(l@&&^h>*<3Y~ Date: Mon, 14 Oct 2024 11:14:04 +0200 Subject: [PATCH 12/80] dev: add Libft and Minilibx --- .gitignore | 3 +- Libft/Makefile | 47 + Libft/ft_atoi.c | 50 + Libft/ft_bzero.c | 18 + Libft/ft_calloc.c | 29 + Libft/ft_isalnum.c | 18 + Libft/ft_isalpha.c | 16 + Libft/ft_isascii.c | 16 + Libft/ft_isdigit.c | 16 + Libft/ft_isprint.c | 16 + Libft/ft_itoa.c | 67 ++ Libft/ft_lstadd_back.c | 24 + Libft/ft_lstadd_front.c | 19 + Libft/ft_lstclear.c | 25 + Libft/ft_lstdelone.c | 22 + Libft/ft_lstiter.c | 22 + Libft/ft_lstlast.c | 22 + Libft/ft_lstmap.c | 38 + Libft/ft_lstnew.c | 26 + Libft/ft_lstsize.c | 26 + Libft/ft_memchr.c | 28 + Libft/ft_memcmp.c | 25 + Libft/ft_memcpy.c | 30 + Libft/ft_memmove.c | 31 + Libft/ft_memset.c | 28 + Libft/ft_putchar_fd.c | 18 + Libft/ft_putendl_fd.c | 20 + Libft/ft_putnbr_fd.c | 40 + Libft/ft_putstr_fd.c | 19 + Libft/ft_split.c | 98 ++ Libft/ft_strchr.c | 29 + Libft/ft_strdup.c | 35 + Libft/ft_striteri.c | 25 + Libft/ft_strjoin.c | 42 + Libft/ft_strlcat.c | 44 + Libft/ft_strlcpy.c | 30 + Libft/ft_strlen.c | 23 + Libft/ft_strmapi.c | 32 + Libft/ft_strncmp.c | 25 + Libft/ft_strnstr.c | 47 + Libft/ft_strrchr.c | 31 + Libft/ft_strtrim.c | 80 ++ Libft/ft_substr.c | 41 + Libft/ft_tolower.c | 18 + Libft/ft_toupper.c | 18 + Libft/libft.h | 196 ++++ Minilibx/.github/workflows/ci.yml | 88 ++ Minilibx/.gitignore | 67 ++ Minilibx/LICENSE | 25 + Minilibx/Makefile | 22 + Minilibx/Makefile.mk | 66 ++ Minilibx/README.md | 55 + Minilibx/configure | 126 +++ Minilibx/man/man1/mlx.1 | 93 ++ Minilibx/man/man1/mlx_loop.1 | 141 +++ Minilibx/man/man1/mlx_new_image.1 | 192 ++++ Minilibx/man/man1/mlx_new_window.1 | 79 ++ Minilibx/man/man1/mlx_pixel_put.1 | 84 ++ Minilibx/man/man3/mlx.3 | 93 ++ Minilibx/man/man3/mlx_loop.3 | 141 +++ Minilibx/man/man3/mlx_new_image.3 | 192 ++++ Minilibx/man/man3/mlx_new_window.3 | 79 ++ Minilibx/man/man3/mlx_pixel_put.3 | 81 ++ Minilibx/mlx.h | 139 +++ Minilibx/mlx_clear_window.c | 21 + Minilibx/mlx_destroy_display.c | 18 + Minilibx/mlx_destroy_image.c | 31 + Minilibx/mlx_destroy_window.c | 38 + Minilibx/mlx_expose_hook.c | 22 + Minilibx/mlx_ext_randr.c | 104 ++ Minilibx/mlx_flush_event.c | 25 + Minilibx/mlx_get_color_value.c | 33 + Minilibx/mlx_get_data_addr.c | 23 + Minilibx/mlx_hook.c | 40 + Minilibx/mlx_init.c | 99 ++ Minilibx/mlx_int.h | 140 +++ Minilibx/mlx_int_anti_resize_win.c | 28 + Minilibx/mlx_int_do_nothing.c | 16 + Minilibx/mlx_int_get_visual.c | 39 + Minilibx/mlx_int_param_event.c | 100 ++ Minilibx/mlx_int_set_win_event_mask.c | 34 + Minilibx/mlx_int_str_to_wordtab.c | 113 ++ Minilibx/mlx_int_wait_first_expose.c | 23 + Minilibx/mlx_key_hook.c | 22 + Minilibx/mlx_lib_xpm.c | 96 ++ Minilibx/mlx_loop.c | 63 ++ Minilibx/mlx_loop_hook.c | 21 + Minilibx/mlx_mouse.c | 48 + Minilibx/mlx_mouse_hook.c | 22 + Minilibx/mlx_new_image.c | 159 +++ Minilibx/mlx_new_window.c | 62 ++ Minilibx/mlx_pixel_put.c | 26 + Minilibx/mlx_put_image_to_window.c | 37 + Minilibx/mlx_rgb.c | 764 +++++++++++++ Minilibx/mlx_screen_size.c | 13 + Minilibx/mlx_set_font.c | 30 + Minilibx/mlx_string_put.c | 26 + Minilibx/mlx_xpm.c | 345 ++++++ Minilibx/mlx_xpm.c.ok | 310 ++++++ Minilibx/rgb2c.pl | 38 + Minilibx/source | 151 +++ Minilibx/test/Makefile.mk | 45 + Minilibx/test/main.c | 287 +++++ Minilibx/test/new_win.c | 31 + Minilibx/test/open.xpm | 1439 +++++++++++++++++++++++++ Minilibx/test/open24.xpm | 230 ++++ Minilibx/test/open30.xpm | 1439 +++++++++++++++++++++++++ Minilibx/test/run_tests.sh | 94 ++ 108 files changed, 10079 insertions(+), 2 deletions(-) create mode 100644 Libft/Makefile create mode 100644 Libft/ft_atoi.c create mode 100644 Libft/ft_bzero.c create mode 100644 Libft/ft_calloc.c create mode 100644 Libft/ft_isalnum.c create mode 100644 Libft/ft_isalpha.c create mode 100644 Libft/ft_isascii.c create mode 100644 Libft/ft_isdigit.c create mode 100644 Libft/ft_isprint.c create mode 100644 Libft/ft_itoa.c create mode 100644 Libft/ft_lstadd_back.c create mode 100644 Libft/ft_lstadd_front.c create mode 100644 Libft/ft_lstclear.c create mode 100644 Libft/ft_lstdelone.c create mode 100644 Libft/ft_lstiter.c create mode 100644 Libft/ft_lstlast.c create mode 100644 Libft/ft_lstmap.c create mode 100644 Libft/ft_lstnew.c create mode 100644 Libft/ft_lstsize.c create mode 100644 Libft/ft_memchr.c create mode 100644 Libft/ft_memcmp.c create mode 100644 Libft/ft_memcpy.c create mode 100644 Libft/ft_memmove.c create mode 100644 Libft/ft_memset.c create mode 100644 Libft/ft_putchar_fd.c create mode 100644 Libft/ft_putendl_fd.c create mode 100644 Libft/ft_putnbr_fd.c create mode 100644 Libft/ft_putstr_fd.c create mode 100644 Libft/ft_split.c create mode 100644 Libft/ft_strchr.c create mode 100644 Libft/ft_strdup.c create mode 100644 Libft/ft_striteri.c create mode 100644 Libft/ft_strjoin.c create mode 100644 Libft/ft_strlcat.c create mode 100644 Libft/ft_strlcpy.c create mode 100644 Libft/ft_strlen.c create mode 100644 Libft/ft_strmapi.c create mode 100644 Libft/ft_strncmp.c create mode 100644 Libft/ft_strnstr.c create mode 100644 Libft/ft_strrchr.c create mode 100644 Libft/ft_strtrim.c create mode 100644 Libft/ft_substr.c create mode 100644 Libft/ft_tolower.c create mode 100644 Libft/ft_toupper.c create mode 100644 Libft/libft.h create mode 100644 Minilibx/.github/workflows/ci.yml create mode 100644 Minilibx/.gitignore create mode 100644 Minilibx/LICENSE create mode 100644 Minilibx/Makefile create mode 100644 Minilibx/Makefile.mk create mode 100755 Minilibx/README.md create mode 100755 Minilibx/configure create mode 100644 Minilibx/man/man1/mlx.1 create mode 100644 Minilibx/man/man1/mlx_loop.1 create mode 100644 Minilibx/man/man1/mlx_new_image.1 create mode 100644 Minilibx/man/man1/mlx_new_window.1 create mode 100644 Minilibx/man/man1/mlx_pixel_put.1 create mode 100644 Minilibx/man/man3/mlx.3 create mode 100644 Minilibx/man/man3/mlx_loop.3 create mode 100644 Minilibx/man/man3/mlx_new_image.3 create mode 100644 Minilibx/man/man3/mlx_new_window.3 create mode 100644 Minilibx/man/man3/mlx_pixel_put.3 create mode 100644 Minilibx/mlx.h create mode 100644 Minilibx/mlx_clear_window.c create mode 100644 Minilibx/mlx_destroy_display.c create mode 100644 Minilibx/mlx_destroy_image.c create mode 100644 Minilibx/mlx_destroy_window.c create mode 100644 Minilibx/mlx_expose_hook.c create mode 100644 Minilibx/mlx_ext_randr.c create mode 100644 Minilibx/mlx_flush_event.c create mode 100644 Minilibx/mlx_get_color_value.c create mode 100644 Minilibx/mlx_get_data_addr.c create mode 100644 Minilibx/mlx_hook.c create mode 100644 Minilibx/mlx_init.c create mode 100644 Minilibx/mlx_int.h create mode 100644 Minilibx/mlx_int_anti_resize_win.c create mode 100644 Minilibx/mlx_int_do_nothing.c create mode 100644 Minilibx/mlx_int_get_visual.c create mode 100644 Minilibx/mlx_int_param_event.c create mode 100644 Minilibx/mlx_int_set_win_event_mask.c create mode 100644 Minilibx/mlx_int_str_to_wordtab.c create mode 100644 Minilibx/mlx_int_wait_first_expose.c create mode 100644 Minilibx/mlx_key_hook.c create mode 100644 Minilibx/mlx_lib_xpm.c create mode 100644 Minilibx/mlx_loop.c create mode 100644 Minilibx/mlx_loop_hook.c create mode 100644 Minilibx/mlx_mouse.c create mode 100644 Minilibx/mlx_mouse_hook.c create mode 100644 Minilibx/mlx_new_image.c create mode 100644 Minilibx/mlx_new_window.c create mode 100644 Minilibx/mlx_pixel_put.c create mode 100644 Minilibx/mlx_put_image_to_window.c create mode 100644 Minilibx/mlx_rgb.c create mode 100644 Minilibx/mlx_screen_size.c create mode 100644 Minilibx/mlx_set_font.c create mode 100644 Minilibx/mlx_string_put.c create mode 100644 Minilibx/mlx_xpm.c create mode 100644 Minilibx/mlx_xpm.c.ok create mode 100755 Minilibx/rgb2c.pl create mode 100644 Minilibx/source create mode 100644 Minilibx/test/Makefile.mk create mode 100644 Minilibx/test/main.c create mode 100644 Minilibx/test/new_win.c create mode 100644 Minilibx/test/open.xpm create mode 100644 Minilibx/test/open24.xpm create mode 100644 Minilibx/test/open30.xpm create mode 100755 Minilibx/test/run_tests.sh diff --git a/.gitignore b/.gitignore index 9b2387a..c306efd 100644 --- a/.gitignore +++ b/.gitignore @@ -52,6 +52,5 @@ Mkfile.old dkms.conf # Files -Libft -Minilibx .vscode +/cub3d diff --git a/Libft/Makefile b/Libft/Makefile new file mode 100644 index 0000000..432bd30 --- /dev/null +++ b/Libft/Makefile @@ -0,0 +1,47 @@ +# The interesting part +NAME = libft.a +SRCS = ./ +INCLUDES = ./ +FUNCTIONS = \ + isalpha isdigit isalnum isascii isprint \ + toupper tolower \ + strncmp strlen strlcpy strlcat strchr strrchr strnstr strdup \ + strmapi striteri substr strjoin strtrim split \ + memset bzero memcpy memmove memchr memcmp calloc \ + atoi itoa \ + putchar_fd putstr_fd putendl_fd putnbr_fd +FUNCTIONS_BONUS = \ + lstnew lstadd_front lstsize lstlast lstadd_back \ + lstdelone lstclear lstiter lstmap +CODE = $(addprefix ft_, $(FUNCTIONS)) +CODE_BONUS = $(addprefix ft_, $(FUNCTIONS_BONUS)) + +# It works and I probably won't change it for the rest of my life +C_FILES = $(addsuffix .c,$(addprefix $(SRCS),$(CODE))) +O_FILES = $(addsuffix .o,$(addprefix $(SRCS),$(CODE))) +C_FILES_BONUS = $(addsuffix .c,$(addprefix $(SRCS),$(CODE_BONUS))) +O_FILES_BONUS = $(addsuffix .o,$(addprefix $(SRCS),$(CODE_BONUS))) +CC = cc -Wall -Wextra -Werror +AR = ar rcs +MAKE = make + +all : $(NAME) + +$(NAME) : $(O_FILES) + $(AR) $(NAME) $(O_FILES) + +%.o : %.c + $(CC) -I $(INCLUDES) -c $< -o $@ + +clean : + rm -f $(O_FILES) $(O_FILES_BONUS) + +fclean : clean + rm -f $(NAME) + +re : fclean all + +bonus : $(O_FILES_BONUS) + $(AR) $(NAME) $(O_FILES_BONUS) + +.PHONY : all clean fclean re bonus diff --git a/Libft/ft_atoi.c b/Libft/ft_atoi.c new file mode 100644 index 0000000..20d8598 --- /dev/null +++ b/Libft/ft_atoi.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/28 17:45:41 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 12:03:52 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +static int is_in(char c, char *chars) +{ + int i; + + i = 0; + while (chars[i]) + { + if (c == chars[i]) + return (1); + i++; + } + return (0); +} + +int ft_atoi(const char *nptr) +{ + int sign; + int i; + int r; + + sign = 1; + i = 0; + r = 0; + while (is_in(nptr[i], " \f\n\r\t\v")) + i++; + if (is_in(nptr[i], "+-")) + { + if (nptr[i] == '-') + sign *= -1; + i++; + } + while (is_in(nptr[i], "0123456789")) + { + r = r * 10 + (nptr[i] - '0'); + i++; + } + return (r * sign); +} diff --git a/Libft/ft_bzero.c b/Libft/ft_bzero.c new file mode 100644 index 0000000..026084e --- /dev/null +++ b/Libft/ft_bzero.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:10:31 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 13:12:35 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_bzero(void *s, size_t n) +{ + ft_memset(s, '\0', n); +} diff --git a/Libft/ft_calloc.c b/Libft/ft_calloc.c new file mode 100644 index 0000000..c1fd1b0 --- /dev/null +++ b/Libft/ft_calloc.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_calloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:41:02 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 15:58:33 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +void *ft_calloc(size_t nmemb, size_t size) +{ + void *dest; + int len; + + if ((long)nmemb * (long)size > (long)INT_MAX) + return (NULL); + len = size * nmemb; + dest = malloc(len); + if (!dest) + return (NULL); + ft_bzero(dest, len); + return (dest); +} diff --git a/Libft/ft_isalnum.c b/Libft/ft_isalnum.c new file mode 100644 index 0000000..e0492c9 --- /dev/null +++ b/Libft/ft_isalnum.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 15:02:39 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalnum(int c) +{ + return (ft_isdigit(c) || ft_isalpha(c)); +} diff --git a/Libft/ft_isalpha.c b/Libft/ft_isalpha.c new file mode 100644 index 0000000..0719231 --- /dev/null +++ b/Libft/ft_isalpha.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */ +/* Updated: 2023/10/02 16:46:27 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isalpha(int c) +{ + return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')); +} diff --git a/Libft/ft_isascii.c b/Libft/ft_isascii.c new file mode 100644 index 0000000..addccb1 --- /dev/null +++ b/Libft/ft_isascii.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */ +/* Updated: 2023/10/02 16:50:28 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isascii(int c) +{ + return ((c >= 0 && c <= 127)); +} diff --git a/Libft/ft_isdigit.c b/Libft/ft_isdigit.c new file mode 100644 index 0000000..618ea3a --- /dev/null +++ b/Libft/ft_isdigit.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */ +/* Updated: 2023/10/02 16:47:07 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isdigit(int c) +{ + return (c >= '0' && c <= '9'); +} diff --git a/Libft/ft_isprint.c b/Libft/ft_isprint.c new file mode 100644 index 0000000..725a23e --- /dev/null +++ b/Libft/ft_isprint.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */ +/* Updated: 2023/10/02 16:51:08 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isprint(int c) +{ + return (c >= 32 && c <= 126); +} diff --git a/Libft/ft_itoa.c b/Libft/ft_itoa.c new file mode 100644 index 0000000..2b509b5 --- /dev/null +++ b/Libft/ft_itoa.c @@ -0,0 +1,67 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:51:10 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 16:49:44 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +static char get_digit_at(long pos_n, int i, int nb_len) +{ + int w; + long ten_power; + + w = nb_len - i - 1; + ten_power = 1; + while (w--) + ten_power *= 10; + return ('0' + pos_n / ten_power % 10); +} + +static int get_nb_len(long pos_n) +{ + int r; + long ten_powers; + + r = 1; + ten_powers = 10; + while (pos_n >= ten_powers) + { + r++; + ten_powers *= 10; + } + return (r); +} + +char *ft_itoa(int n) +{ + long pos_n; + int sign; + int nb_len; + char *dest; + int i; + + sign = (n >= 0) - (n < 0); + pos_n = (long)n * sign; + nb_len = get_nb_len(pos_n); + dest = malloc(((sign == -1) + nb_len + 1) * sizeof(char)); + if (!dest) + return (NULL); + i = 0; + if (sign == -1) + dest[i++] = '-'; + while (i - (sign == -1) < nb_len) + { + dest[i] = get_digit_at(pos_n, i - (sign == -1), nb_len); + i++; + } + dest[i] = '\0'; + return (dest); +} diff --git a/Libft/ft_lstadd_back.c b/Libft/ft_lstadd_back.c new file mode 100644 index 0000000..f2668da --- /dev/null +++ b/Libft/ft_lstadd_back.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_back.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:24:03 by mcolonna #+# #+# */ +/* Updated: 2023/10/05 12:56:42 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstadd_back(t_list **lst, t_list *new) +{ + t_list *last; + + last = ft_lstlast(*lst); + if (last) + last->next = new; + else + *lst = new; +} diff --git a/Libft/ft_lstadd_front.c b/Libft/ft_lstadd_front.c new file mode 100644 index 0000000..432dffc --- /dev/null +++ b/Libft/ft_lstadd_front.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_front.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:19:20 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 16:20:44 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstadd_front(t_list **lst, t_list *new) +{ + new->next = *lst; + *lst = new; +} diff --git a/Libft/ft_lstclear.c b/Libft/ft_lstclear.c new file mode 100644 index 0000000..8a440e2 --- /dev/null +++ b/Libft/ft_lstclear.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstclear.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:31:06 by mcolonna #+# #+# */ +/* Updated: 2023/10/05 11:40:24 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstclear(t_list **lst, void (*del)(void *)) +{ + t_list *next; + + while (*lst) + { + next = (*lst)->next; + ft_lstdelone(*lst, del); + *lst = next; + } +} diff --git a/Libft/ft_lstdelone.c b/Libft/ft_lstdelone.c new file mode 100644 index 0000000..0a29cbf --- /dev/null +++ b/Libft/ft_lstdelone.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdelone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:28:18 by mcolonna #+# #+# */ +/* Updated: 2023/10/05 12:55:39 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +void ft_lstdelone(t_list *lst, void (*del)(void *)) +{ + if (!lst) + return ; + (*del)(lst->content); + free(lst); +} diff --git a/Libft/ft_lstiter.c b/Libft/ft_lstiter.c new file mode 100644 index 0000000..9bc8cdf --- /dev/null +++ b/Libft/ft_lstiter.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstiter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:36:27 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 16:37:48 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstiter(t_list *lst, void (*f)(void *)) +{ + while (lst) + { + (*f)(lst->content); + lst = lst->next; + } +} diff --git a/Libft/ft_lstlast.c b/Libft/ft_lstlast.c new file mode 100644 index 0000000..bf5d7a2 --- /dev/null +++ b/Libft/ft_lstlast.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstlast.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:22:57 by mcolonna #+# #+# */ +/* Updated: 2023/10/05 12:53:31 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstlast(t_list *lst) +{ + if (!lst) + return (NULL); + while (lst->next) + lst = lst->next; + return (lst); +} diff --git a/Libft/ft_lstmap.c b/Libft/ft_lstmap.c new file mode 100644 index 0000000..64561be --- /dev/null +++ b/Libft/ft_lstmap.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstmap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:37:57 by mcolonna #+# #+# */ +/* Updated: 2023/10/12 13:17:57 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) +{ + t_list *dest; + t_list *new; + void *new_content; + + dest = NULL; + if (!lst) + return (NULL); + while (lst) + { + new_content = (*f)(lst->content); + new = ft_lstnew(new_content); + if (!new) + { + (*del)(new_content); + ft_lstclear(&dest, del); + return (NULL); + } + ft_lstadd_back(&dest, new); + lst = lst->next; + } + return (dest); +} diff --git a/Libft/ft_lstnew.c b/Libft/ft_lstnew.c new file mode 100644 index 0000000..adbf062 --- /dev/null +++ b/Libft/ft_lstnew.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:14:54 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 16:51:08 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +t_list *ft_lstnew(void *content) +{ + t_list *r; + + r = malloc(sizeof(t_list)); + if (!r) + return (NULL); + r->content = content; + r->next = NULL; + return (r); +} diff --git a/Libft/ft_lstsize.c b/Libft/ft_lstsize.c new file mode 100644 index 0000000..5323ea2 --- /dev/null +++ b/Libft/ft_lstsize.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstsize.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:21:29 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 16:44:08 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_lstsize(t_list *lst) +{ + int i; + + i = 0; + while (lst) + { + lst = lst->next; + i++; + } + return (i); +} diff --git a/Libft/ft_memchr.c b/Libft/ft_memchr.c new file mode 100644 index 0000000..44a6ae3 --- /dev/null +++ b/Libft/ft_memchr.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:28:00 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 15:31:16 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memchr(const void *s, int c, size_t n) +{ + size_t i; + const char *s2 = s; + + i = 0; + while (i < n) + { + if (s2[i] == (char) c) + return ((void *) s + i); + i++; + } + return (NULL); +} diff --git a/Libft/ft_memcmp.c b/Libft/ft_memcmp.c new file mode 100644 index 0000000..ff7039f --- /dev/null +++ b/Libft/ft_memcmp.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:37:06 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 12:00:22 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + size_t i; + + if (n == 0) + return (0); + i = 0; + while (i < n - 1 && ((unsigned char *)s1)[i] == ((unsigned char *)s2)[i]) + i++; + return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]); +} diff --git a/Libft/ft_memcpy.c b/Libft/ft_memcpy.c new file mode 100644 index 0000000..33e973f --- /dev/null +++ b/Libft/ft_memcpy.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:12:53 by mcolonna #+# #+# */ +/* Updated: 2023/10/16 13:40:19 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memcpy(void *dest, const void *src, size_t n) +{ + size_t i; + char *dest2; + char *src2; + + dest2 = (char *)dest; + src2 = (char *)src; + i = 0; + while (i < n) + { + dest2[i] = src2[i]; + i++; + } + return (dest); +} diff --git a/Libft/ft_memmove.c b/Libft/ft_memmove.c new file mode 100644 index 0000000..985be90 --- /dev/null +++ b/Libft/ft_memmove.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:17:41 by mcolonna #+# #+# */ +/* Updated: 2023/10/12 10:44:37 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memmove(void *dest, const void *src, size_t n) +{ + size_t i; + + if (!dest || !src) + return (NULL); + i = 0; + while (i < n) + { + if (dest < src) + ((char *)dest)[i] = ((char *)src)[i]; + else + ((char *)dest)[n - i - 1] = ((char *)src)[n - i - 1]; + i++; + } + return (dest); +} diff --git a/Libft/ft_memset.c b/Libft/ft_memset.c new file mode 100644 index 0000000..2ce9b1c --- /dev/null +++ b/Libft/ft_memset.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:05:27 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 15:27:09 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memset(void *s, int c, size_t n) +{ + size_t i; + char *dest; + + dest = (char *)s; + i = 0; + while (i < n) + { + dest[i] = (char)c; + i++; + } + return (dest); +} diff --git a/Libft/ft_putchar_fd.c b/Libft/ft_putchar_fd.c new file mode 100644 index 0000000..9b4b60a --- /dev/null +++ b/Libft/ft_putchar_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 14:25:02 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 14:29:09 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} diff --git a/Libft/ft_putendl_fd.c b/Libft/ft_putendl_fd.c new file mode 100644 index 0000000..d38533e --- /dev/null +++ b/Libft/ft_putendl_fd.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 14:25:02 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 14:17:01 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +void ft_putendl_fd(char *s, int fd) +{ + write(fd, s, ft_strlen(s)); + write(fd, "\n", 1); +} diff --git a/Libft/ft_putnbr_fd.c b/Libft/ft_putnbr_fd.c new file mode 100644 index 0000000..426a0eb --- /dev/null +++ b/Libft/ft_putnbr_fd.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 14:32:29 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 17:23:02 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft.h" + +static void putunsigned(long nb, int fd) +{ + if (nb == 0) + return ; + putunsigned(nb / 10, fd); + ft_putchar_fd((char)(nb % 10) + '0', fd); +} + +void ft_putnbr_fd(int n, int fd) +{ + long nb; + + if (n < 0) + { + ft_putchar_fd('-', fd); + nb = -(long)n; + } + else + nb = n; + if (n == 0) + ft_putchar_fd('0', fd); + else + putunsigned(nb, fd); +} diff --git a/Libft/ft_putstr_fd.c b/Libft/ft_putstr_fd.c new file mode 100644 index 0000000..ce573ed --- /dev/null +++ b/Libft/ft_putstr_fd.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 14:25:02 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 14:34:35 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +void ft_putstr_fd(char *s, int fd) +{ + write(fd, s, ft_strlen(s)); +} diff --git a/Libft/ft_split.c b/Libft/ft_split.c new file mode 100644 index 0000000..6bf5d24 --- /dev/null +++ b/Libft/ft_split.c @@ -0,0 +1,98 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 11:47:18 by mcolonna #+# #+# */ +/* Updated: 2023/10/12 13:24:04 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +static int count_until(char const *s, char const c) +{ + int i; + + i = 0; + while (s[i] && s[i] != c) + i++; + return (i); +} + +static int count_words(char const *s, char c) +{ + int i; + int r; + int in_a_word; + + i = 0; + r = 0; + in_a_word = 0; + while (s[i]) + { + if (s[i] == c) + { + in_a_word = 0; + } + else if (!in_a_word) + { + in_a_word = 1; + r++; + } + i++; + } + return (r); +} + +static char **free_array(char ***array, int size) +{ + int i; + + i = 0; + while (i < size) + { + free((*array)[i]); + (*array)[i] = NULL; + i++; + } + free(*array); + *array = NULL; + return (NULL); +} + +static void ignore_sep(char const *s, char c, int *i) +{ + while (s[*i] == c) + (*i)++; +} + +char **ft_split(char const *s, char c) +{ + int size; + char **dest; + int i; + int str_i; + int len_until; + + size = count_words(s, c); + dest = malloc((size + 1) * sizeof(char *)); + if (!dest) + return (NULL); + i = -1; + str_i = 0; + while (++i < size) + { + ignore_sep(s, c, &str_i); + len_until = count_until(s + str_i, c); + dest[i] = ft_substr(s, str_i, len_until); + if (!dest[i]) + return (free_array(&dest, i)); + str_i += len_until; + } + dest[i] = NULL; + return (dest); +} diff --git a/Libft/ft_strchr.c b/Libft/ft_strchr.c new file mode 100644 index 0000000..9905568 --- /dev/null +++ b/Libft/ft_strchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 10:43:17 by mcolonna #+# #+# */ +/* Updated: 2023/10/10 13:17:35 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +char *ft_strchr(const char *s, int c) +{ + int i; + + i = 0; + while (s[i]) + { + if (s[i] == c) + return ((char *)s + i); + i++; + } + if (s[i] == c) + return ((char *)s + i); + return (NULL); +} diff --git a/Libft/ft_strdup.c b/Libft/ft_strdup.c new file mode 100644 index 0000000..532571e --- /dev/null +++ b/Libft/ft_strdup.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/30 09:18:39 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 11:27:46 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +char *ft_strdup(const char *s) +{ + int len; + int i; + char *dest; + + len = 0; + while (s[len]) + len++; + dest = malloc((len + 1) * sizeof(char)); + if (!dest) + return (NULL); + i = 0; + while (s[i]) + { + dest[i] = s[i]; + i++; + } + dest[i] = '\0'; + return (dest); +} diff --git a/Libft/ft_striteri.c b/Libft/ft_striteri.c new file mode 100644 index 0000000..7b5d2f7 --- /dev/null +++ b/Libft/ft_striteri.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 11:08:18 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 11:10:28 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_striteri(char *s, void (*f)(unsigned int, char *)) +{ + unsigned int i; + + i = 0; + while (s[i]) + { + (*f)(i, s + i); + i++; + } +} diff --git a/Libft/ft_strjoin.c b/Libft/ft_strjoin.c new file mode 100644 index 0000000..f57b64d --- /dev/null +++ b/Libft/ft_strjoin.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 11:31:45 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 11:25:38 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +char *ft_strjoin(char const *s1, char const *s2) +{ + int len; + char *dest; + int i; + int j; + + len = ft_strlen(s1) + ft_strlen(s2); + dest = malloc((len + 1) * sizeof(char)); + if (!dest) + return (NULL); + i = 0; + while (s1[i]) + { + dest[i] = s1[i]; + i++; + } + j = 0; + while (s2[j]) + { + dest[i] = s2[j]; + i++; + j++; + } + dest[i] = '\0'; + return (dest); +} diff --git a/Libft/ft_strlcat.c b/Libft/ft_strlcat.c new file mode 100644 index 0000000..ec95531 --- /dev/null +++ b/Libft/ft_strlcat.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/28 10:40:23 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 16:20:20 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static size_t min(size_t a, size_t b) +{ + if (a < b) + return (a); + else + return (b); +} + +size_t ft_strlcat(char *dest, const char *src, size_t size) +{ + size_t dest_len; + size_t dest_i; + size_t src_i; + + dest_len = min(ft_strlen(dest), size); + if (dest_len < size - 1) + { + dest_i = dest_len; + src_i = 0; + while (src[src_i] && size > 0 && dest_i < size - 1) + { + dest[dest_i] = src[src_i]; + src_i++; + dest_i++; + } + if (size > 0) + dest[dest_i] = '\0'; + } + return (dest_len + ft_strlen(src)); +} diff --git a/Libft/ft_strlcpy.c b/Libft/ft_strlcpy.c new file mode 100644 index 0000000..80de6c9 --- /dev/null +++ b/Libft/ft_strlcpy.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/25 20:39:39 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 11:44:13 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcpy(char *dest, const char *src, size_t size) +{ + size_t i; + + i = 0; + while (src[i] && size > 0 && i < size - 1) + { + dest[i] = src[i]; + i++; + } + if (i < size) + dest[i] = '\0'; + while (src[i]) + i++; + return (i); +} diff --git a/Libft/ft_strlen.c b/Libft/ft_strlen.c new file mode 100644 index 0000000..f6c8804 --- /dev/null +++ b/Libft/ft_strlen.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/24 13:10:16 by mcolonna #+# #+# */ +/* Updated: 2023/10/10 14:09:44 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlen(const char *s) +{ + int i; + + i = 0; + while (s[i]) + i++; + return (i); +} diff --git a/Libft/ft_strmapi.c b/Libft/ft_strmapi.c new file mode 100644 index 0000000..556ad76 --- /dev/null +++ b/Libft/ft_strmapi.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 11:08:18 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 15:20:49 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) +{ + char *dest; + unsigned int i; + + dest = malloc((ft_strlen(s) + 1) * sizeof(char)); + if (!dest) + return (NULL); + i = 0; + while (s[i]) + { + dest[i] = (*f)(i, s[i]); + i++; + } + dest[i] = '\0'; + return (dest); +} diff --git a/Libft/ft_strncmp.c b/Libft/ft_strncmp.c new file mode 100644 index 0000000..c10af4c --- /dev/null +++ b/Libft/ft_strncmp.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/10 12:21:33 by mcolonna #+# #+# */ +/* Updated: 2023/10/10 14:39:03 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strncmp(const char *s1, const char *s2, size_t n) +{ + unsigned int i; + + if (n == 0) + return (0); + i = 0; + while (i < n - 1 && s1[i] && s1[i] == s2[i]) + i++; + return ((unsigned char)s1[i] - (unsigned char)s2[i]); +} diff --git a/Libft/ft_strnstr.c b/Libft/ft_strnstr.c new file mode 100644 index 0000000..ca93e48 --- /dev/null +++ b/Libft/ft_strnstr.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 10:50:23 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 16:09:21 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +// Return 1 if there is 'little' at the pos 'i' of 'big', or else 0. +static int match(const char *big, const char *little, size_t len, size_t i) +{ + int j; + + j = 0; + while (little[j]) + { + if (len <= i || big[i] != little[j]) + return (0); + i++; + j++; + } + return (1); +} + +char *ft_strnstr(const char *big, const char *little, size_t len) +{ + size_t i; + + i = 0; + if (!little[0]) + return ((char *)big); + if (!big[i] || i >= len) + return (NULL); + while (!match(big, little, len, i)) + { + i++; + if (!big[i] || i >= len) + return (NULL); + } + return ((char *)big + i); +} diff --git a/Libft/ft_strrchr.c b/Libft/ft_strrchr.c new file mode 100644 index 0000000..8b76716 --- /dev/null +++ b/Libft/ft_strrchr.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 10:43:17 by mcolonna #+# #+# */ +/* Updated: 2023/10/10 13:16:58 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +char *ft_strrchr(const char *s, int c) +{ + char *r; + int i; + + r = NULL; + i = 0; + while (s[i]) + { + if (s[i] == c) + r = (char *)s + i; + i++; + } + if (s[i] == c) + r = (char *)s + i; + return (r); +} diff --git a/Libft/ft_strtrim.c b/Libft/ft_strtrim.c new file mode 100644 index 0000000..e6d422e --- /dev/null +++ b/Libft/ft_strtrim.c @@ -0,0 +1,80 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 11:39:33 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 13:07:54 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +static int is_in(char const c, char const *set) +{ + int i; + + i = 0; + while (set[i]) + { + if (set[i] == c) + return (1); + i++; + } + return (0); +} + +static size_t get_length(char const *s1, char const *set) +{ + size_t i; + size_t r; + size_t tmp; + + i = 0; + while (is_in(s1[i], set)) + i++; + r = 0; + tmp = 0; + while (s1[i]) + { + if (is_in(s1[i], set)) + { + tmp++; + } + else + { + r += tmp; + tmp = 0; + r++; + } + i++; + } + return (r); +} + +char *ft_strtrim(char const *s1, char const *set) +{ + size_t len; + char *dest; + size_t start; + size_t i; + + len = get_length(s1, set); + dest = malloc((len + 1) * sizeof(char)); + if (!dest) + return (NULL); + start = 0; + while (is_in(s1[start], set)) + start++; + i = 0; + while (i < len) + { + dest[i] = s1[start + i]; + i++; + } + dest[i] = '\0'; + return (dest); +} diff --git a/Libft/ft_substr.c b/Libft/ft_substr.c new file mode 100644 index 0000000..3a98490 --- /dev/null +++ b/Libft/ft_substr.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 11:17:12 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 13:27:30 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + char *dest; + size_t s_len; + size_t dest_len; + size_t i; + + s_len = ft_strlen(s); + if (s_len < start) + dest_len = 0; + else if (s_len < start + len) + dest_len = s_len - start; + else + dest_len = len; + dest = malloc((dest_len + 1) * sizeof(char)); + if (!dest) + return (NULL); + i = 0; + while (i < dest_len) + { + dest[i] = s[start + i]; + i++; + } + dest[i] = '\0'; + return (dest); +} diff --git a/Libft/ft_tolower.c b/Libft/ft_tolower.c new file mode 100644 index 0000000..aa8f85f --- /dev/null +++ b/Libft/ft_tolower.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:53:06 by mcolonna #+# #+# */ +/* Updated: 2023/10/02 16:58:02 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_tolower(int c) +{ + if (c >= 'A' && c <= 'Z') + return (c - 'A' + 'a'); + return (c); +} diff --git a/Libft/ft_toupper.c b/Libft/ft_toupper.c new file mode 100644 index 0000000..f1b6727 --- /dev/null +++ b/Libft/ft_toupper.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:53:06 by mcolonna #+# #+# */ +/* Updated: 2023/10/02 16:56:52 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_toupper(int c) +{ + if (c >= 'a' && c <= 'z') + return (c - 'a' + 'A'); + return (c); +} diff --git a/Libft/libft.h b/Libft/libft.h new file mode 100644 index 0000000..6dbd635 --- /dev/null +++ b/Libft/libft.h @@ -0,0 +1,196 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 11:46:15 by mcolonna #+# #+# */ +/* Updated: 2023/10/10 14:11:08 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H + +# include +# include + +///// CHAR ///// + +// (In libc) Return 1 if the char 'c' is a specific type of char, or else 0. +int ft_isalpha(int c); // A-Za-z +int ft_isdigit(int c); // 0-9 +int ft_isalnum(int c); // A-Za-z0-9 +int ft_isascii(int c); // (0)-(127) +int ft_isprint(int c); // (32)-(126) + +// (In libc) Return the uppercase/lowercase version of the letter, +// or the char itself if it's not a letter. +int ft_toupper(int c); +int ft_tolower(int c); + +///// STR ///// + +// (In libc) Compare 2 strings until n +int ft_strncmp(const char *s1, const char *s2, size_t n); + +// (In libc) Return the length of the string 's'. +size_t ft_strlen(const char *s); + +// (In libc) Copy/Append src on dst. +// 'dst' will be 'size' chars max, including \0, +// except if 'dst' is already longer for strlcat(). +// 1. Never do more than size. +// 2. Always end by \0, except if it doesn't respect 1. +size_t ft_strlcpy(char *dst, const char *src, size_t size); +size_t ft_strlcat(char *dst, const char *src, size_t size); + +// (In libc) Return a pointer to the first of last char 'c' in 's', +// or return NULL if there aren't any. +char *ft_strchr(const char *s, int c); // First char. +char *ft_strrchr(const char *s, int c); // Last char. + +// (In libc) Return a pointer to the first occurence +// of string 'little' in string 'big'. +// Don't look chars after 'size'. +char *ft_strnstr(const char *big, const char *little, size_t len); + +// (In libc) Return an malloced duplicate of 's'. +// Uses: malloc +// Error: return NULL +char *ft_strdup(const char *s); + +// (Perso) Apply 'f' on each char of the string 's' and returns the result. +// Uses: malloc +// Error: return NULL +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); + +// (Perso) Call 'f' for each char of 's'. +void ft_striteri(char *s, void (*f)(unsigned int, char *)); + +// (Perso) Return the substring of 's' which starts at 'start' +// and is of length 'len'. +// Don't take chars after the end of the string. +// Uses: malloc +// Error: return NULL +char *ft_substr(char const *s, unsigned int start, size_t len); + +// (Perso) Concatenate the two strings. +// Uses: malloc +// Error: return NULL +char *ft_strjoin(char const *s1, char const *s2); + +// (Perso) Remove the characters 'set' from the beginning +// and the end of the string. +// Uses: malloc +// Error: return NULL +char *ft_strtrim(char const *s1, char const *set); + +// (Perso) Split 's' by the chars 'c'. +// Return an array ended by NULL. +// Uses: malloc +// Error: return NULL +char **ft_split(char const *s, char c); + +///// MEM ///// + +// (In libc) Fills 's' with 'n' times the char 'c'. +// Return 'c'. +void *ft_memset(void *s, int c, size_t n); + +// (In libc) Just ft_memset(s, '\0', n) lol. +void ft_bzero(void *s, size_t n); + +// (In libc) Copy 'n' bytes from 'src' to 'dest'. +// The 'src' and 'dest' areas mustn't overlap. +// Return 'dest'. +void *ft_memcpy(void *dest, const void *src, size_t n); + +// (In libc) Same, but the areas can overlap. +// Return 'dest'. +void *ft_memmove(void *dest, const void *src, size_t n); + +// (In libc) Find the character 'c' in 's', 's' being of length 'n'. +// NULL if none. +void *ft_memchr(const void *s, int c, size_t n); + +// (In libc) Compare 'n' bytes of 's1' and 's2'. +int ft_memcmp(const void *s1, const void *s2, size_t n); + +// (In libc) Alloc an array of 'size' elements with each element +// being of size 'size'. +// Uses: malloc +// Error: return NULL +void *ft_calloc(size_t nmemb, size_t size); + +///// CAST ///// + +// (In libc) Cast a string to an int. +// /[ \f\n\r\t\v]*[-+]?[0-9]*.*/ +int ft_atoi(const char *nptr); + +// (Perso) Cast an int to a string. +// Uses: malloc +// Error: return NULL +char *ft_itoa(int n); + +///// WRITE ///// + +// (Perso) Write the char/string on the file descriptor 'fd'. +// Uses: write +void ft_putchar_fd(char c, int fd); +void ft_putstr_fd(char *s, int fd); + +// (Perso) Write the string 's' followed by a newline. +// Uses: write +void ft_putendl_fd(char *s, int fd); + +// (Perso) Write the number 'n'. +// Uses: write +void ft_putnbr_fd(int n, int fd); + +typedef struct s_list +{ + void *content; + struct s_list *next; +} t_list; + +///// BONUS ///// + +// Create an malloced list of size = 1: {content} +// Uses: malloc +// Error: return NULL +t_list *ft_lstnew(void *content); + +// Add 'new' at the beginning of the list. +void ft_lstadd_front(t_list **lst, t_list *new); + +// Get the length of the list. +int ft_lstsize(t_list *lst); + +// Return the last node of the list. +t_list *ft_lstlast(t_list *lst); + +// Add 'new' at the end of the list. +void ft_lstadd_back(t_list **lst, t_list *new); + +// Apply 'del' on the element's content, then free lst. +// Uses: free +void ft_lstdelone(t_list *lst, void (*del)(void *)); + +// Free every element's content with del and free the elements. +// *lst will be set to NULL. +// Uses: free +void ft_lstclear(t_list **lst, void (*del)(void *)); + +// Apply f on the content of each node. +void ft_lstiter(t_list *lst, void (*f)(void *)); + +// Apply f on the content of each node +// and create a new list with the resulting contents. +// Uses: free, malloc +// Error: return NULL +t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)); + +#endif diff --git a/Minilibx/.github/workflows/ci.yml b/Minilibx/.github/workflows/ci.yml new file mode 100644 index 0000000..8c880cb --- /dev/null +++ b/Minilibx/.github/workflows/ci.yml @@ -0,0 +1,88 @@ +name: Build + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ${{ matrix.os }} + env: + DISPLAY: ":99" + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest] + + timeout-minutes: 20 + steps: + - uses: actions/checkout@v2 + - name: Install mlx dependencies + run: | + set -x + if [ "$RUNNER_OS" == "Linux" ]; then + sudo apt-get update -qq + sudo apt-get install -y -qq gcc make xorg libxext-dev libbsd-dev + elif [ "$RUNNER_OS" == "macOS" ]; then + brew install xquartz + echo "/usr/X11/bin" >> $GITHUB_PATH + else + echo "$RUNNER_OS not supported" + exit 1 + fi + - name: Setup x11 headless testing environment + run: | + set -x + if [ "$RUNNER_OS" == "Linux" ]; then + sudo apt-get install xvfb xdotool valgrind + Xvfb $DISPLAY -screen 0 1280x1024x24 & + elif [ "$RUNNER_OS" == "macOS" ]; then + brew install xdotool + defaults write org.x.X11 enable_test_extensions -boolean true + sudo Xvfb $DISPLAY -screen 0 1280x1024x24 & + else + echo "$RUNNER_OS not supported" + exit 1 + fi + - name: Run ./configure + run: ./configure + + - name: make check Linux + if: matrix.os == 'ubuntu-latest' + run: make -f Makefile.gen check + - name: make check MacOS + continue-on-error: true + if: matrix.os == 'macos-latest' + run: make -f Makefile.gen check + # Didn't find a way to simulate inputs on Macos. libxdo seem to no longer work on macos. + # It can be partially fixed writing proper unit-tests, thus avoiding the need of libxdo. + + - name: Check leaks from binary "test/mlx-test" + run: | + cd test + if [ "$RUNNER_OS" == "Linux" ]; then + echo "Info: Still reachable doesn't matter. Valgrind will return success on thoses reports. + It is fine, we searching for lost pointers. Valgrind will return exit status 42 if any block is lost." + valgrind --leak-check=full --show-leak-kinds=definite,indirect,possible --errors-for-leak-kinds=definite,indirect,possible --error-exitcode=42 ./mlx-test > /dev/null & + PID=$! + sleep 30 + xdotool search --name Title3 windowfocus key Escape + xdotool search --name Title2 windowfocus key Escape + wait $PID + elif [ "$RUNNER_OS" == "macOS" ]; then + MallocStackLoggingNoCompact=1 + ./mlx-test & + sleep 30 + leaks mlx-test + pkill mlx-test + fi + + - name: Norminette, just for fun + continue-on-error: true + run: | + pip3 install Norminette + norminette *.c *.h + norminette --version diff --git a/Minilibx/.gitignore b/Minilibx/.gitignore new file mode 100644 index 0000000..9595e5f --- /dev/null +++ b/Minilibx/.gitignore @@ -0,0 +1,67 @@ +## Mlx related +Makefile.gen +/test/mlx-test + +## Editor +.vscode/* +*~ +\#*\# + +## Other +.DS_STORE + + + +## Template from https://github.com/github/gitignore +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf \ No newline at end of file diff --git a/Minilibx/LICENSE b/Minilibx/LICENSE new file mode 100644 index 0000000..ed2de25 --- /dev/null +++ b/Minilibx/LICENSE @@ -0,0 +1,25 @@ +BSD 2-Clause License + +Copyright (c) 2021, Ecole 42 +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Minilibx/Makefile b/Minilibx/Makefile new file mode 100644 index 0000000..5c418c5 --- /dev/null +++ b/Minilibx/Makefile @@ -0,0 +1,22 @@ +## +## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx +## +## Made by Olivier Crouzet +## Login +## +## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet +## Last update Tue May 15 15:44:41 2007 Olivier Crouzet +## + +## Please use configure script + + +all : do_configure + +do_configure : + ./configure + +clean : + ./configure clean + +re : clean all diff --git a/Minilibx/Makefile.mk b/Minilibx/Makefile.mk new file mode 100644 index 0000000..1bae8df --- /dev/null +++ b/Minilibx/Makefile.mk @@ -0,0 +1,66 @@ +## +## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx +## +## Made by Olivier Crouzet +## Login +## +## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet +## Last update Tue May 15 15:41:20 2007 Olivier Crouzet +## + +## Please use configure script + + +INC =%%%% + +UNAME = $(shell uname) +CC = gcc +ifeq ($(UNAME),FreeBSD) + CC = clang +endif + +NAME = libmlx.a +NAME_UNAME = libmlx_$(UNAME).a + +SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \ + mlx_mouse_hook.c mlx_key_hook.c mlx_expose_hook.c mlx_loop_hook.c \ + mlx_int_anti_resize_win.c mlx_int_do_nothing.c \ + mlx_int_wait_first_expose.c mlx_int_get_visual.c \ + mlx_flush_event.c mlx_string_put.c mlx_set_font.c \ + mlx_new_image.c mlx_get_data_addr.c \ + mlx_put_image_to_window.c mlx_get_color_value.c mlx_clear_window.c \ + mlx_xpm.c mlx_int_str_to_wordtab.c mlx_destroy_window.c \ + mlx_int_param_event.c mlx_int_set_win_event_mask.c mlx_hook.c \ + mlx_rgb.c mlx_destroy_image.c mlx_mouse.c mlx_screen_size.c \ + mlx_destroy_display.c + +OBJ_DIR = obj +OBJ = $(addprefix $(OBJ_DIR)/,$(SRC:%.c=%.o)) +CFLAGS = -O3 -I$(INC) + +all : $(NAME) + +$(OBJ_DIR)/%.o: %.c + @mkdir -p $(OBJ_DIR) + $(CC) $(CFLAGS) $(IFLAGS) -c $< -o $@ + +$(NAME) : $(OBJ) + ar -r $(NAME) $(OBJ) + ranlib $(NAME) + cp $(NAME) $(NAME_UNAME) + +check: all + @test/run_tests.sh + +show: + @printf "NAME : $(NAME)\n" + @printf "NAME_UNAME : $(NAME_UNAME)\n" + @printf "CC : $(CC)\n" + @printf "CFLAGS : $(CFLAGS)\n" + @printf "SRC :\n $(SRC)\n" + @printf "OBJ :\n $(OBJ)\n" + +clean : + rm -rf $(OBJ_DIR)/ $(NAME) $(NAME_UNAME) *~ core *.core + +.PHONY: all check show clean diff --git a/Minilibx/README.md b/Minilibx/README.md new file mode 100755 index 0000000..cb60744 --- /dev/null +++ b/Minilibx/README.md @@ -0,0 +1,55 @@ +[![Build](https://github.com/42Paris/minilibx-linux/actions/workflows/ci.yml/badge.svg)](https://github.com/42Paris/minilibx-linux/actions/workflows/ci.yml) + +This is the MinilibX, a simple X-Window (X11R6) programming API +in C, designed for students, suitable for X-beginners. + + +Contents + + - source code in C to create the mlx library + - man pages (in man/ directory) + - a test program (in test/ directory) is built + with the library + - a public include file mlx.h + - a tiny configure script to generate an appropriate Makefile.gen + +Requirements for Linux + + - MinilibX only support TrueColor visual type (8,15,16,24 or 32 bits depth) + - gcc + - make + - X11 include files (package xorg) + - XShm extension must be present (package libxext-dev) + - Utility functions from BSD systems - development files (package libbsd-dev) + - **e.g. _sudo apt-get install gcc make xorg libxext-dev libbsd-dev_ (Debian/Ubuntu)** + +Requirements for MacOS + - [Xquartz](https://www.xquartz.org/) + +```bash +➜ ~ Brew install Xquartz +➜ ~ reboot +➜ ~ xeyes # run an hello world X11 app +``` + +MlX Color Opacity / Transparency / Alpha (32 bits depth) + - 0xFF (fully transparent) or 0x00 (fully opaque) + +Compile MinilibX + + - run ./configure or make + both will make a few tests, create Makefile.gen + and then automatically run make on this generated Makefile.gen . + libmlx.a and libmlx_$(HOSTTYPE).a are created. + test/mlx-test binary is also created. + + +Install MinilibX + + - no installation script is provided. You may want to install + - libmlx.a and/or libmlx_$(HOSTTYPE).a in /usr/X11/lib or /usr/local/lib + - mlx.h in /usr/X11/include or /usr/local/include + - man/man3/mlx*.1 in /usr/X11/man/man3 or /usr/local/man/man3 + + + Olivier CROUZET - 2014-01-06 - diff --git a/Minilibx/configure b/Minilibx/configure new file mode 100755 index 0000000..18d1e4d --- /dev/null +++ b/Minilibx/configure @@ -0,0 +1,126 @@ +#!/usr/bin/env sh + +set -e + +BOLD="\033[1m" +RESET="\033[0m" +LIGHT_RED="\033[91m" +LIGHT_GREEN="\033[92m" +LIGHT_CYAN="\033[96m" + +logging(){ + local type=$1; shift + printf "${LIGHT_CYAN}${BOLD}configure${RESET} [%b] : %b\n" "$type" "$*" +} +log_info(){ + logging "${LIGHT_GREEN}info${RESET}" "$@" +} +log_error(){ + logging "${LIGHT_RED}error${RESET}" "$@" >&2 +} + +# find and print x11 header path +get_xlib_include_path(){ + local result="" + + for inc in \ + /usr/X11/include \ + /usr/X11R6/include \ + /usr/X11R5/include \ + /usr/X11R4/include \ + \ + /usr/include \ + /usr/include/X11 \ + /usr/include/X11R6 \ + /usr/include/X11R5 \ + /usr/include/X11R4 \ + \ + /usr/local/X11/include \ + /usr/local/X11R6/include \ + /usr/local/X11R5/include \ + /usr/local/X11R4/include \ + \ + /usr/local/include/X11 \ + /usr/local/include/X11R6 \ + /usr/local/include/X11R5 \ + /usr/local/include/X11R4 \ + \ + /usr/X386/include \ + /usr/x386/include \ + /usr/XFree86/include/X11 \ + \ + /usr/local/include \ + /usr/athena/include \ + /usr/local/x11r5/include \ + /usr/lpp/Xamples/include \ + \ + /usr/openwin/include \ + /usr/openwin/share/include + do + if [ -f "$inc/X11/Xlib.h" -a -f "$inc/X11/extensions/XShm.h" ]; then + result=$inc + break + fi + done + echo $result +} + +show_help(){ +cat < Makefile.gen + cat Makefile.mk | grep -v %%%% >> Makefile.gen + log_info 'Generate "test/makefile.gen" from template "test/makefile.mk"' + echo "INC=$xlib_inc" > test/Makefile.gen + cat test/Makefile.mk | grep -v %%%% >> test/Makefile.gen + + log_info 'Execute "make all" from file "makefile.gen"' + ${MAKE} -f Makefile.gen all + log_info 'Execute "make all" from file "test/makefile.gen"' + (cd test ; ${MAKE} -f Makefile.gen all ) +} + +main "$@" diff --git a/Minilibx/man/man1/mlx.1 b/Minilibx/man/man1/mlx.1 new file mode 100644 index 0000000..9ad0ac1 --- /dev/null +++ b/Minilibx/man/man1/mlx.1 @@ -0,0 +1,93 @@ +.TH MiniLibX 3 "September 19, 2002" +.SH NAME +MiniLibX - Simple X-Window Interface Library for students +.SH SYNOPSYS +#include + +.nf +.I void * +.fi +.B mlx_init +(); + +.SH DESCRIPTION +MiniLibX is an easy way to create graphical software, +without any X-Window programming knowledge. It provides +simple window creation, a drawing tool, image and basic events +management. + +.SH X-WINDOW CONCEPT + +X-Window is a network-oriented graphical system for Unix. +It is based on two main parts: +.br +On one side, your software wants to draw something on the screen and/or +get keyboard & mouse entries. +.br +On the other side, the X-Server manages the screen, keyboard and mouse +(It is often refered to as a "display"). +.br +A network connection must be established between these two entities to send +drawing orders (from the software to the X-Server), and keyboard/mouse +events (from the X-Server to the software). + +.SH INCLUDE FILE +.B mlx.h +should be included for a correct use of the MiniLibX API. +It only contains function prototypes, no structure is needed. + +.SH LIBRARY FUNCTIONS +.P +First of all, you need to initialize the connection +between your software and the display. +Once this connection is established, you'll be able to +use other MiniLibX functions to send the X-Server messages, +like "I want to draw a yellow pixel in this window" or "did the +user hit a key?". +.P +The +.B mlx_init +function will create this connection. No parameters are needed, ant it will +return a +.I "void *" +identifier, used for further calls to the library routines. +.P +All other MiniLibX functions are described in the following man pages: + +.TP 20 +.B mlx_new_window +: manage windows +.TP 20 +.B mlx_pixel_put +: draw inside window +.TP 20 +.B mlx_new_image +: manipulate images +.TP 20 +.B mlx_loop +: handle keyboard or mouse events + +.SH LINKING MiniLibX +To use MiniLibX functions, you'll need to link +your software with several libraries, including the MiniLibX library itself. +To do this, simply add the following arguments at linking time: + +.B -lmlx -lXext -lX11 + +You may also need to specify the path to these libraries, using +the +.B -L +flag. + + +.SH RETURN VALUES +If +.B mlx_init() +fails to set up the connection to the X server, it will return NULL, otherwise +a non-null pointer is returned as a connection identifier. + +.SH SEE ALSO +mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3) + +.SH AUTHOR +Copyright ol@ - 2002-2014 - Olivier Crouzet diff --git a/Minilibx/man/man1/mlx_loop.1 b/Minilibx/man/man1/mlx_loop.1 new file mode 100644 index 0000000..3397ce2 --- /dev/null +++ b/Minilibx/man/man1/mlx_loop.1 @@ -0,0 +1,141 @@ +.TH MiniLibX 3 "September 19, 2002" +.SH NAME +MiniLibX - Handle events +.SH SYNOPSYS + +.nf +.I int +.fi +.B mlx_loop +( +.I void *mlx_ptr +); + +.nf +.I int +.fi +.B mlx_key_hook +( +.I void *win_ptr, int (*funct_ptr)(), void *param +); + +.nf +.I int +.fi +.B mlx_mouse_hook +( +.I void *win_ptr, int (*funct_ptr)(), void *param +); + +.nf +.I int +.fi +.B mlx_expose_hook +( +.I void *win_ptr, int (*funct_ptr)(), void *param +); + +.nf +.I int +.fi +.B mlx_loop_hook +( +.I void *mlx_ptr, int (*funct_ptr)(), void *param +); + +.SH X-WINDOW EVENTS + +The X-Window system is bi-directionnal. On one hand, the program sends orders to +the screen to display pixels, images, and so on. On the other hand, +it can get information from the keyboard and mouse associated to +the screen. To do so, the program receives "events" from the keyboard or the +mouse. + +.SH DESCRIPTION + +To receive events, you must use +.B mlx_loop +(). This function never returns. It is an infinite loop that waits for +an event, and then calls a user-defined function associated with this event. +A single parameter is needed, the connection identifier +.I mlx_ptr +(see the +.B mlx manual). + +You can assign different functions to the three following events: +.br +- A key is pressed +.br +- The mouse button is pressed +.br +- A part of the window should be re-drawn +(this is called an "expose" event, and it is your program's job to handle it). +.br + +Each window can define a different function for the same event. + +The three functions +.B mlx_key_hook +(), +.B mlx_mouse_hook +() and +.B mlx_expose_hook +() work exactly the same way. +.I funct_ptr +is a pointer to the function you want to be called +when an event occurs. This assignment is specific to the window defined by the +.I win_ptr +identifier. The +.I param +adress will be passed to the function everytime it is called, and should be +used to store the parameters it might need. + +The syntax for the +.B mlx_loop_hook +() function is identical to the previous ones, but the given function will be +called when no event occurs. + +When it catches an event, the MiniLibX calls the corresponding function +with fixed parameters: +.nf + + expose_hook(void *param); + key_hook(int keycode,void *param); + mouse_hook(int button,int x,int y,void *param); + loop_hook(void *param); + +.fi +These function names are arbitrary. They here are used to distinguish +parameters according to the event. These functions are NOT part of the +MiniLibX. + +.I param +is the address specified in the mlx_*_hook calls. This address is never +used nor modified by the MiniLibX. On key and mouse events, additional +information is passed: +.I keycode +tells you which key is pressed (look for the X11 include file "keysymdef.h"), +( +.I x +, +.I y +) are the coordinates of the mouse click in the window, and +.I button +tells you which mouse button was pressed. + +.SH GOING FURTHER WITH EVENTS +The MiniLibX provides a much generic access to all X-Window events. The +.I mlx.h +include define +.B mlx_hook() +in the same manner mlx_*_hook functions work. The event and mask values +will be taken from the X11 include file "X.h". + +See source code of mlx_int_param_event.c to find out how the MiniLibX will +call your own function for a specific event. + +.SH SEE ALSO +mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3) + +.SH AUTHOR +Copyright ol@ - 2002-2014 - Olivier Crouzet diff --git a/Minilibx/man/man1/mlx_new_image.1 b/Minilibx/man/man1/mlx_new_image.1 new file mode 100644 index 0000000..f2160a2 --- /dev/null +++ b/Minilibx/man/man1/mlx_new_image.1 @@ -0,0 +1,192 @@ +.TH MiniLibX 3 "September 19, 2002" +.SH NAME +MiniLibX - Manipulating images +.SH SYNOPSYS + +.nf +.I void * +.fi +.B mlx_new_image +( +.I void *mlx_ptr, int width, int height +); + +.nf +.I char * +.fi +.B mlx_get_data_addr +( +.I void *img_ptr, int *bits_per_pixel, int *size_line, int *endian +); + +.nf +.I int +.fi +.B mlx_put_image_to_window +( +.I void *mlx_ptr, void *win_ptr, void *img_ptr, int x, int y +); + +.nf +.I unsigned int +.fi +.B mlx_get_color_value +( +.I void *mlx_ptr, int color +); + +.nf +.I void * +.fi +.B mlx_xpm_to_image +( +.I void *mlx_ptr, char **xpm_data, int *width, int *height +); + +.nf +.I void * +.fi +.B mlx_xpm_file_to_image +( +.I void *mlx_ptr, char *filename, int *width, int *height +); + +.nf +.I int +.fi +.B mlx_destroy_image +( +.I void *mlx_ptr, void *img_ptr +); + + +.SH DESCRIPTION + +.B mlx_new_image +() creates a new image in memory. It returns a +.I void * +identifier needed to manipulate this image later. It only needs +the size of the image to be created, using the +.I width +and +.I height +parameters, and the +.I mlx_ptr +connection identifier (see the +.B mlx +manual). + +The user can draw inside the image (see below), and +can dump the image inside a specified window at any time to +display it on the screen. This is done using +.B mlx_put_image_to_window +(). Three identifiers are needed here, for the connection to the +display, the window to use, and the image (respectively +.I mlx_ptr +, +.I win_ptr +and +.I img_ptr +). The ( +.I x +, +.I y +) coordinates define where the image should be placed in the window. + +.B mlx_get_data_addr +() returns information about the created image, allowing a user +to modify it later. The +.I img_ptr +parameter specifies the image to use. The three next parameters should +be the addresses of three different valid integers. +.I bits_per_pixel +will be filled with the number of bits needed to represent a pixel color +(also called the depth of the image). +.I size_line +is the number of bytes used to store one line of the image in memory. +This information is needed to move from one line to another in the image. +.I endian +tells you wether the pixel color in the image needs to be stored in +little endian ( +.I endian +== 0), or big endian ( +.I endian +== 1). + +.B mlx_get_data_addr +returns a +.I char * +address that represents the begining of the memory area where the image +is stored. From this adress, the first +.I bits_per_pixel +bits represent the color of the first pixel in the first line of +the image. The second group of +.I bits_per_pixel +bits represent the second pixel of the first line, and so on. +Add +.I size_line +to the adress to get the begining of the second line. You can reach any +pixels of the image that way. + +.B mlx_destroy_image +destroys the given image ( +.I img_ptr +). + +.SH STORING COLOR INSIDE IMAGES + +Depending on the display, the number of bits used to store a pixel color +can change. The user usually represents a color in RGB mode, using +one byte for each component (see +.B mlx_pixel_put +manual). This must be translated to fit the +.I bits_per_pixel +requirement of the image, and make the color understandable to the X-Server. +That is the purpose of the +.B mlx_get_color_value +() function. It takes a standard RGB +.I color +parameter, and returns an +.I unsigned int +value. +The +.I bits_per_pixel +least significant bits of this value can be stored in the image. + +Keep in mind that the least significant bits position depends on the local +computer's endian. If the endian of the image (in fact the endian of +the X-Server's computer) differs from the local endian, then the value should +be transformed before being used. + +.SH XPM IMAGES + +The +.B mlx_xpm_to_image +() and +.B mlx_xpm_file_to_image +() functions will create a new image the same way. +They will fill it using the specified +.I xpm_data +or +.I filename +, depending on which function is used. +Note that MiniLibX does not use the standard +Xpm library to deal with xpm images. You may not be able to +read all types of xpm images. It however handles transparency. + +.SH RETURN VALUES +The three functions that create images, +.B mlx_new_image() +, +.B mlx_xpm_to_image() +and +.B mlx_xpm_file_to_image() +, will return NULL if an error occurs. Otherwise they return a non-null pointer +as an image identifier. + + +.SH SEE ALSO +mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_loop(3) + +.SH AUTHOR +Copyright ol@ - 2002-2014 - Olivier Crouzet diff --git a/Minilibx/man/man1/mlx_new_window.1 b/Minilibx/man/man1/mlx_new_window.1 new file mode 100644 index 0000000..90f6d47 --- /dev/null +++ b/Minilibx/man/man1/mlx_new_window.1 @@ -0,0 +1,79 @@ +.TH MiniLibX 3 "September 19, 2002" +.SH NAME +MiniLibX - Managing windows +.SH SYNOPSYS + +.nf +.I void * +.fi +.B mlx_new_window +( +.I void *mlx_ptr, int size_x, int size_y, char *title +); + +.nf +.I int +.fi +.B mlx_clear_window +( +.I void *mlx_ptr, void *win_ptr +); + +.nf +.I int +.fi +.B mlx_destroy_window +( +.I void *mlx_ptr, void *win_ptr +); + + +.SH DESCRIPTION +The +.B mlx_new_window +() function creates a new window on the screen, using the +.I size_x +and +.I size_y +parameters to determine its size, and +.I title +as the text that should be displayed in the window's title bar. +The +.I mlx_ptr +parameter is the connection identifier returned by +.B mlx_init +() (see the +.B mlx +man page). +.B mlx_new_window +() returns a +.I void * +window identifier that can be used by other MiniLibX calls. +Note that the MiniLibX +can handle an arbitrary number of separate windows. + +.B mlx_clear_window +() and +.B mlx_destroy_window +() respectively clear (in black) and destroy the given window. They both have +the same parameters: +.I mlx_ptr +is the screen connection identifier, and +.I win_ptr +is a window identifier. + +.SH RETURN VALUES +If +.B mlx_new_window() +fails to create a new window (for wathever reason), it will return NULL, +otherwise a non-null pointer is returned as a window identifier. +.B mlx_clear_window +and +.B mlx_destroy_window +right now return nothing. + +.SH SEE ALSO +mlx(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3) + +.SH AUTHOR +Copyright ol@ - 2002-2014 - Olivier Crouzet diff --git a/Minilibx/man/man1/mlx_pixel_put.1 b/Minilibx/man/man1/mlx_pixel_put.1 new file mode 100644 index 0000000..258df58 --- /dev/null +++ b/Minilibx/man/man1/mlx_pixel_put.1 @@ -0,0 +1,84 @@ +.TH MiniLibX 3 "September 19, 2002" +.SH NAME +MiniLibX - Drawing inside windows +.SH SYNOPSYS + +.nf +.I int +.fi +.B mlx_pixel_put +( +.I void *mlx_ptr, void *win_ptr, int x, int y, int color +); + +.nf +.I int +.fi +.B mlx_string_put +( +.I void *mlx_ptr, void *win_ptr, int x, int y, int color, char *string +); + + +.SH DESCRIPTION +The +.B mlx_pixel_put +() function draws a defined pixel in the window +.I win_ptr +using the ( +.I x +, +.I y +) coordinates, and the specified +.I color +\&. The origin (0,0) is the upper left corner of the window, the x and y axis +respectively pointing right and down. The connection +identifier, +.I mlx_ptr +, is needed (see the +.B mlx +man page). + +Parameters for +.B mlx_string_put +() have the same meaning. Instead of a simple pixel, the specified +.I string +will be displayed at ( +.I x +, +.I y +). + +In both functions, it is impossible to display anything outside the +specified window, nor display in another window in front of the selected one. + +.SH COLOR MANAGEMENT +The +.I color +parameter has an integer type. The displayed color needs to be encoded +in this integer, following a defined scheme. All displayable colors +can be split in 3 basic colors: red, green and blue. Three associated +values, in the 0-255 range, represent how much of each color is mixed up +to create the original color. Theses three values must be set inside the +integer to display the right color. The three least significant bytes of +this integer are filled as shown in the picture below: + +.TS +allbox; +c s s s s +r c c c c. +Color Integer +Interpretation \[*a] R G B +Bit numbers 31..24 23..16 15..8 7..0 +.TE + +While filling the integer, make sure you avoid endian problems. Remember +that the "blue" byte should always be the least significant one. + + +.SH SEE ALSO +mlx(3), mlx_new_window(3), mlx_new_image(3), mlx_loop(3) + + +.SH AUTHOR +Copyright ol@ - 2002-2014 - Olivier Crouzet diff --git a/Minilibx/man/man3/mlx.3 b/Minilibx/man/man3/mlx.3 new file mode 100644 index 0000000..9ad0ac1 --- /dev/null +++ b/Minilibx/man/man3/mlx.3 @@ -0,0 +1,93 @@ +.TH MiniLibX 3 "September 19, 2002" +.SH NAME +MiniLibX - Simple X-Window Interface Library for students +.SH SYNOPSYS +#include + +.nf +.I void * +.fi +.B mlx_init +(); + +.SH DESCRIPTION +MiniLibX is an easy way to create graphical software, +without any X-Window programming knowledge. It provides +simple window creation, a drawing tool, image and basic events +management. + +.SH X-WINDOW CONCEPT + +X-Window is a network-oriented graphical system for Unix. +It is based on two main parts: +.br +On one side, your software wants to draw something on the screen and/or +get keyboard & mouse entries. +.br +On the other side, the X-Server manages the screen, keyboard and mouse +(It is often refered to as a "display"). +.br +A network connection must be established between these two entities to send +drawing orders (from the software to the X-Server), and keyboard/mouse +events (from the X-Server to the software). + +.SH INCLUDE FILE +.B mlx.h +should be included for a correct use of the MiniLibX API. +It only contains function prototypes, no structure is needed. + +.SH LIBRARY FUNCTIONS +.P +First of all, you need to initialize the connection +between your software and the display. +Once this connection is established, you'll be able to +use other MiniLibX functions to send the X-Server messages, +like "I want to draw a yellow pixel in this window" or "did the +user hit a key?". +.P +The +.B mlx_init +function will create this connection. No parameters are needed, ant it will +return a +.I "void *" +identifier, used for further calls to the library routines. +.P +All other MiniLibX functions are described in the following man pages: + +.TP 20 +.B mlx_new_window +: manage windows +.TP 20 +.B mlx_pixel_put +: draw inside window +.TP 20 +.B mlx_new_image +: manipulate images +.TP 20 +.B mlx_loop +: handle keyboard or mouse events + +.SH LINKING MiniLibX +To use MiniLibX functions, you'll need to link +your software with several libraries, including the MiniLibX library itself. +To do this, simply add the following arguments at linking time: + +.B -lmlx -lXext -lX11 + +You may also need to specify the path to these libraries, using +the +.B -L +flag. + + +.SH RETURN VALUES +If +.B mlx_init() +fails to set up the connection to the X server, it will return NULL, otherwise +a non-null pointer is returned as a connection identifier. + +.SH SEE ALSO +mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3) + +.SH AUTHOR +Copyright ol@ - 2002-2014 - Olivier Crouzet diff --git a/Minilibx/man/man3/mlx_loop.3 b/Minilibx/man/man3/mlx_loop.3 new file mode 100644 index 0000000..3397ce2 --- /dev/null +++ b/Minilibx/man/man3/mlx_loop.3 @@ -0,0 +1,141 @@ +.TH MiniLibX 3 "September 19, 2002" +.SH NAME +MiniLibX - Handle events +.SH SYNOPSYS + +.nf +.I int +.fi +.B mlx_loop +( +.I void *mlx_ptr +); + +.nf +.I int +.fi +.B mlx_key_hook +( +.I void *win_ptr, int (*funct_ptr)(), void *param +); + +.nf +.I int +.fi +.B mlx_mouse_hook +( +.I void *win_ptr, int (*funct_ptr)(), void *param +); + +.nf +.I int +.fi +.B mlx_expose_hook +( +.I void *win_ptr, int (*funct_ptr)(), void *param +); + +.nf +.I int +.fi +.B mlx_loop_hook +( +.I void *mlx_ptr, int (*funct_ptr)(), void *param +); + +.SH X-WINDOW EVENTS + +The X-Window system is bi-directionnal. On one hand, the program sends orders to +the screen to display pixels, images, and so on. On the other hand, +it can get information from the keyboard and mouse associated to +the screen. To do so, the program receives "events" from the keyboard or the +mouse. + +.SH DESCRIPTION + +To receive events, you must use +.B mlx_loop +(). This function never returns. It is an infinite loop that waits for +an event, and then calls a user-defined function associated with this event. +A single parameter is needed, the connection identifier +.I mlx_ptr +(see the +.B mlx manual). + +You can assign different functions to the three following events: +.br +- A key is pressed +.br +- The mouse button is pressed +.br +- A part of the window should be re-drawn +(this is called an "expose" event, and it is your program's job to handle it). +.br + +Each window can define a different function for the same event. + +The three functions +.B mlx_key_hook +(), +.B mlx_mouse_hook +() and +.B mlx_expose_hook +() work exactly the same way. +.I funct_ptr +is a pointer to the function you want to be called +when an event occurs. This assignment is specific to the window defined by the +.I win_ptr +identifier. The +.I param +adress will be passed to the function everytime it is called, and should be +used to store the parameters it might need. + +The syntax for the +.B mlx_loop_hook +() function is identical to the previous ones, but the given function will be +called when no event occurs. + +When it catches an event, the MiniLibX calls the corresponding function +with fixed parameters: +.nf + + expose_hook(void *param); + key_hook(int keycode,void *param); + mouse_hook(int button,int x,int y,void *param); + loop_hook(void *param); + +.fi +These function names are arbitrary. They here are used to distinguish +parameters according to the event. These functions are NOT part of the +MiniLibX. + +.I param +is the address specified in the mlx_*_hook calls. This address is never +used nor modified by the MiniLibX. On key and mouse events, additional +information is passed: +.I keycode +tells you which key is pressed (look for the X11 include file "keysymdef.h"), +( +.I x +, +.I y +) are the coordinates of the mouse click in the window, and +.I button +tells you which mouse button was pressed. + +.SH GOING FURTHER WITH EVENTS +The MiniLibX provides a much generic access to all X-Window events. The +.I mlx.h +include define +.B mlx_hook() +in the same manner mlx_*_hook functions work. The event and mask values +will be taken from the X11 include file "X.h". + +See source code of mlx_int_param_event.c to find out how the MiniLibX will +call your own function for a specific event. + +.SH SEE ALSO +mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3) + +.SH AUTHOR +Copyright ol@ - 2002-2014 - Olivier Crouzet diff --git a/Minilibx/man/man3/mlx_new_image.3 b/Minilibx/man/man3/mlx_new_image.3 new file mode 100644 index 0000000..f2160a2 --- /dev/null +++ b/Minilibx/man/man3/mlx_new_image.3 @@ -0,0 +1,192 @@ +.TH MiniLibX 3 "September 19, 2002" +.SH NAME +MiniLibX - Manipulating images +.SH SYNOPSYS + +.nf +.I void * +.fi +.B mlx_new_image +( +.I void *mlx_ptr, int width, int height +); + +.nf +.I char * +.fi +.B mlx_get_data_addr +( +.I void *img_ptr, int *bits_per_pixel, int *size_line, int *endian +); + +.nf +.I int +.fi +.B mlx_put_image_to_window +( +.I void *mlx_ptr, void *win_ptr, void *img_ptr, int x, int y +); + +.nf +.I unsigned int +.fi +.B mlx_get_color_value +( +.I void *mlx_ptr, int color +); + +.nf +.I void * +.fi +.B mlx_xpm_to_image +( +.I void *mlx_ptr, char **xpm_data, int *width, int *height +); + +.nf +.I void * +.fi +.B mlx_xpm_file_to_image +( +.I void *mlx_ptr, char *filename, int *width, int *height +); + +.nf +.I int +.fi +.B mlx_destroy_image +( +.I void *mlx_ptr, void *img_ptr +); + + +.SH DESCRIPTION + +.B mlx_new_image +() creates a new image in memory. It returns a +.I void * +identifier needed to manipulate this image later. It only needs +the size of the image to be created, using the +.I width +and +.I height +parameters, and the +.I mlx_ptr +connection identifier (see the +.B mlx +manual). + +The user can draw inside the image (see below), and +can dump the image inside a specified window at any time to +display it on the screen. This is done using +.B mlx_put_image_to_window +(). Three identifiers are needed here, for the connection to the +display, the window to use, and the image (respectively +.I mlx_ptr +, +.I win_ptr +and +.I img_ptr +). The ( +.I x +, +.I y +) coordinates define where the image should be placed in the window. + +.B mlx_get_data_addr +() returns information about the created image, allowing a user +to modify it later. The +.I img_ptr +parameter specifies the image to use. The three next parameters should +be the addresses of three different valid integers. +.I bits_per_pixel +will be filled with the number of bits needed to represent a pixel color +(also called the depth of the image). +.I size_line +is the number of bytes used to store one line of the image in memory. +This information is needed to move from one line to another in the image. +.I endian +tells you wether the pixel color in the image needs to be stored in +little endian ( +.I endian +== 0), or big endian ( +.I endian +== 1). + +.B mlx_get_data_addr +returns a +.I char * +address that represents the begining of the memory area where the image +is stored. From this adress, the first +.I bits_per_pixel +bits represent the color of the first pixel in the first line of +the image. The second group of +.I bits_per_pixel +bits represent the second pixel of the first line, and so on. +Add +.I size_line +to the adress to get the begining of the second line. You can reach any +pixels of the image that way. + +.B mlx_destroy_image +destroys the given image ( +.I img_ptr +). + +.SH STORING COLOR INSIDE IMAGES + +Depending on the display, the number of bits used to store a pixel color +can change. The user usually represents a color in RGB mode, using +one byte for each component (see +.B mlx_pixel_put +manual). This must be translated to fit the +.I bits_per_pixel +requirement of the image, and make the color understandable to the X-Server. +That is the purpose of the +.B mlx_get_color_value +() function. It takes a standard RGB +.I color +parameter, and returns an +.I unsigned int +value. +The +.I bits_per_pixel +least significant bits of this value can be stored in the image. + +Keep in mind that the least significant bits position depends on the local +computer's endian. If the endian of the image (in fact the endian of +the X-Server's computer) differs from the local endian, then the value should +be transformed before being used. + +.SH XPM IMAGES + +The +.B mlx_xpm_to_image +() and +.B mlx_xpm_file_to_image +() functions will create a new image the same way. +They will fill it using the specified +.I xpm_data +or +.I filename +, depending on which function is used. +Note that MiniLibX does not use the standard +Xpm library to deal with xpm images. You may not be able to +read all types of xpm images. It however handles transparency. + +.SH RETURN VALUES +The three functions that create images, +.B mlx_new_image() +, +.B mlx_xpm_to_image() +and +.B mlx_xpm_file_to_image() +, will return NULL if an error occurs. Otherwise they return a non-null pointer +as an image identifier. + + +.SH SEE ALSO +mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_loop(3) + +.SH AUTHOR +Copyright ol@ - 2002-2014 - Olivier Crouzet diff --git a/Minilibx/man/man3/mlx_new_window.3 b/Minilibx/man/man3/mlx_new_window.3 new file mode 100644 index 0000000..90f6d47 --- /dev/null +++ b/Minilibx/man/man3/mlx_new_window.3 @@ -0,0 +1,79 @@ +.TH MiniLibX 3 "September 19, 2002" +.SH NAME +MiniLibX - Managing windows +.SH SYNOPSYS + +.nf +.I void * +.fi +.B mlx_new_window +( +.I void *mlx_ptr, int size_x, int size_y, char *title +); + +.nf +.I int +.fi +.B mlx_clear_window +( +.I void *mlx_ptr, void *win_ptr +); + +.nf +.I int +.fi +.B mlx_destroy_window +( +.I void *mlx_ptr, void *win_ptr +); + + +.SH DESCRIPTION +The +.B mlx_new_window +() function creates a new window on the screen, using the +.I size_x +and +.I size_y +parameters to determine its size, and +.I title +as the text that should be displayed in the window's title bar. +The +.I mlx_ptr +parameter is the connection identifier returned by +.B mlx_init +() (see the +.B mlx +man page). +.B mlx_new_window +() returns a +.I void * +window identifier that can be used by other MiniLibX calls. +Note that the MiniLibX +can handle an arbitrary number of separate windows. + +.B mlx_clear_window +() and +.B mlx_destroy_window +() respectively clear (in black) and destroy the given window. They both have +the same parameters: +.I mlx_ptr +is the screen connection identifier, and +.I win_ptr +is a window identifier. + +.SH RETURN VALUES +If +.B mlx_new_window() +fails to create a new window (for wathever reason), it will return NULL, +otherwise a non-null pointer is returned as a window identifier. +.B mlx_clear_window +and +.B mlx_destroy_window +right now return nothing. + +.SH SEE ALSO +mlx(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3) + +.SH AUTHOR +Copyright ol@ - 2002-2014 - Olivier Crouzet diff --git a/Minilibx/man/man3/mlx_pixel_put.3 b/Minilibx/man/man3/mlx_pixel_put.3 new file mode 100644 index 0000000..f4d131e --- /dev/null +++ b/Minilibx/man/man3/mlx_pixel_put.3 @@ -0,0 +1,81 @@ +.TH MiniLibX 3 "September 19, 2002" +.SH NAME +MiniLibX - Drawing inside windows +.SH SYNOPSYS + +.nf +.I int +.fi +.B mlx_pixel_put +( +.I void *mlx_ptr, void *win_ptr, int x, int y, int color +); + +.nf +.I int +.fi +.B mlx_string_put +( +.I void *mlx_ptr, void *win_ptr, int x, int y, int color, char *string +); + + +.SH DESCRIPTION +The +.B mlx_pixel_put +() function draws a defined pixel in the window +.I win_ptr +using the ( +.I x +, +.I y +) coordinates, and the specified +.I color +\&. The origin (0,0) is the upper left corner of the window, the x and y axis +respectively pointing right and down. The connection +identifier, +.I mlx_ptr +, is needed (see the +.B mlx +man page). + +Parameters for +.B mlx_string_put +() have the same meaning. Instead of a simple pixel, the specified +.I string +will be displayed at ( +.I x +, +.I y +). + +In both functions, it is impossible to display anything outside the +specified window, nor display in another window in front of the selected one. + +.SH COLOR MANAGEMENT +The +.I color +parameter has an integer type. The displayed color needs to be encoded +in this integer, following a defined scheme. All displayable colors +can be split in 3 basic colors: red, green and blue. Three associated +values, in the 0-255 range, represent how much of each color is mixed up +to create the original color. Theses three values must be set inside the +integer to display the right color. The three least significant bytes of +this integer are filled as shown in the picture below: + +.nf + | 0 | R | G | B | color integer + +---+---+---+---+ +.fi + + +While filling the integer, make sure you avoid endian problems. Remember +that the "blue" byte should always be the least significant one. + + +.SH SEE ALSO +mlx(3), mlx_new_window(3), mlx_new_image(3), mlx_loop(3) + + +.SH AUTHOR +Copyright ol@ - 2002-2014 - Olivier Crouzet diff --git a/Minilibx/mlx.h b/Minilibx/mlx.h new file mode 100644 index 0000000..b323412 --- /dev/null +++ b/Minilibx/mlx.h @@ -0,0 +1,139 @@ +/* +** 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. +*/ + + +#ifndef 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 +*/ + +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 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); +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); +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 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 */ diff --git a/Minilibx/mlx_clear_window.c b/Minilibx/mlx_clear_window.c new file mode 100644 index 0000000..f621090 --- /dev/null +++ b/Minilibx/mlx_clear_window.c @@ -0,0 +1,21 @@ +/* +** mlx_clear_window.c for MiniLibX in +** +** Made by Charlie Root +** Login +** +** Started on Thu Sep 7 19:46:15 2000 Charlie Root +** Last update Tue Sep 25 17:11:19 2001 Charlie Root +*/ + + + +#include "mlx_int.h" + + +int mlx_clear_window(t_xvar *xvar,t_win_list *win) +{ + XClearWindow(xvar->display,win->window); + if (xvar->do_flush) + XFlush(xvar->display); +} diff --git a/Minilibx/mlx_destroy_display.c b/Minilibx/mlx_destroy_display.c new file mode 100644 index 0000000..d2970b8 --- /dev/null +++ b/Minilibx/mlx_destroy_display.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* mlx_destroy_display.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/10/03 18:56:35 by mg #+# #+# */ +/* Updated: 2020/10/04 01:55:35 by mg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "mlx_int.h" + +int mlx_destroy_display(t_xvar *xvar) +{ + XCloseDisplay(xvar->display); +} diff --git a/Minilibx/mlx_destroy_image.c b/Minilibx/mlx_destroy_image.c new file mode 100644 index 0000000..afd4d1a --- /dev/null +++ b/Minilibx/mlx_destroy_image.c @@ -0,0 +1,31 @@ +/* +** mlx_destroy_image.c for MinilibX in +** +** Made by Charlie Root +** Login +** +** Started on Tue Mar 12 10:25:15 2002 Charlie Root +** Last update Tue May 15 16:45:54 2007 Olivier Crouzet +*/ + + +#include "mlx_int.h" + + +int mlx_destroy_image(t_xvar *xvar, t_img *img) +{ + if (img->type == MLX_TYPE_SHM_PIXMAP || + img->type == MLX_TYPE_SHM) + { + XShmDetach(xvar->display, &(img->shm)); + shmdt(img->shm.shmaddr); + /* shmctl IPC_RMID already done */ + } + XDestroyImage(img->image); /* For image & shm-image. Also free img->data */ + XFreePixmap(xvar->display, img->pix); + if (img->gc) + XFreeGC(xvar->display, img->gc); + free(img); + if (xvar->do_flush) + XFlush(xvar->display); +} diff --git a/Minilibx/mlx_destroy_window.c b/Minilibx/mlx_destroy_window.c new file mode 100644 index 0000000..464790c --- /dev/null +++ b/Minilibx/mlx_destroy_window.c @@ -0,0 +1,38 @@ +/* +** mlx_destroy_window.c for MinilibX in +** +** Made by Charlie Root +** Login +** +** Started on Tue Mar 12 10:25:15 2002 Charlie Root +** Last update Tue May 15 16:46:08 2007 Olivier Crouzet +*/ + + +#include "mlx_int.h" + + +int mlx_destroy_window(t_xvar *xvar,t_win_list *win) +{ + t_win_list *w; + t_win_list *prev; + t_win_list first; + + first.next = xvar->win_list; + prev = &first; + w = prev->next; + while (w) + { + if (w==win) + prev->next = w->next; + else + prev = w; + w = w->next; + } + xvar->win_list = first.next; + XDestroyWindow(xvar->display,win->window); + XFreeGC(xvar->display,win->gc); + free(win); + if (xvar->do_flush) + XFlush(xvar->display); +} diff --git a/Minilibx/mlx_expose_hook.c b/Minilibx/mlx_expose_hook.c new file mode 100644 index 0000000..b00b675 --- /dev/null +++ b/Minilibx/mlx_expose_hook.c @@ -0,0 +1,22 @@ +/* +** mlx_expose_hook.c for MiniLibX in +** +** Made by Charlie Root +** Login +** +** Started on Thu Aug 3 11:49:06 2000 Charlie Root +** Last update Fri Feb 23 17:07:42 2001 Charlie Root +*/ + + +#include "mlx_int.h" + + + + +int mlx_expose_hook(t_win_list *win,int (*funct)(),void *param) +{ + win->hooks[Expose].hook = funct; + win->hooks[Expose].param = param; + win->hooks[Expose].mask = ExposureMask; +} diff --git a/Minilibx/mlx_ext_randr.c b/Minilibx/mlx_ext_randr.c new file mode 100644 index 0000000..34ddb91 --- /dev/null +++ b/Minilibx/mlx_ext_randr.c @@ -0,0 +1,104 @@ + + + +#include "mlx_int.h" + +#include +#include + +/* global for independant extension */ + +RRMode saved_mode = 0; + + +int mlx_ext_fullscreen(t_xvar *xvar, t_win_list *win, int fullscreen) +{ + XWindowAttributes watt; + int i; + int j; + XRRScreenResources *res; + XRROutputInfo *o_info; + XRRCrtcInfo *crtc; + RRMode mode_candidate; + int idx_output; + int idx_candidate; + + if (!XGetWindowAttributes(xvar->display, win->window, &watt)) + return (0); + + res = XRRGetScreenResources(xvar->display, xvar->root); + o_info = NULL; + idx_output = -1; + i = res->noutput; + while (i--) + { + o_info = XRRGetOutputInfo(xvar->display, res, res->outputs[i]); + if (o_info->connection == RR_Connected) + { + idx_output = i; + i = 0; + } + else + XRRFreeOutputInfo(o_info); + } + if (!o_info) + { + XRRFreeScreenResources(res); + return (0); + } + + idx_candidate = -1; + i = o_info->nmode; + while (i--) + { + j = res->nmode; + while (j--) + if (res->modes[j].id == o_info->modes[i]) + if (res->modes[j].width >= watt.width && res->modes[j].height >= watt.height && + (idx_candidate == -1 || res->modes[idx_candidate].width > res->modes[j].width || + res->modes[idx_candidate].height > res->modes[j].height) ) + idx_candidate = i; + } + if (idx_candidate < 0) + { + XRRFreeOutputInfo(o_info); + XRRFreeScreenResources(res); + return (0); + } + if (!fullscreen && saved_mode == -1) + idx_candidate = 0; /* if no clue, uses first mode, usually part of npreferred */ + mode_candidate = o_info->modes[idx_candidate]; + if (!fullscreen) + mode_candidate = saved_mode; + + crtc = XRRGetCrtcInfo(xvar->display, res, o_info->crtc); + saved_mode = crtc->mode; + + i = XRRSetCrtcConfig(xvar->display, res, o_info->crtc, CurrentTime, 0, 0, mode_candidate, + crtc->rotation, &res->outputs[idx_output], 1); + if (fullscreen) + printf("found mode : %d x %d\n Status %d\n", res->modes[idx_candidate].width, res->modes[idx_candidate].height, i); + else + printf("back previous mode\n"); + + XMoveWindow(xvar->display, win->window, 0, 0); + XMapRaised(xvar->display, win->window); + + if (fullscreen) + { + // XGrabPointer(xvar->display, win->window, True, 0, GrabModeAsync, GrabModeAsync, win->window, 0L, CurrentTime); + XGrabKeyboard(xvar->display, win->window, False, GrabModeAsync, GrabModeAsync, CurrentTime); + } + else + { + XUngrabPointer(xvar->display, CurrentTime); + XUngrabKeyboard(xvar->display, CurrentTime); + } + + XSync(xvar->display, False); + sleep(1); + + XRRFreeCrtcInfo(crtc); + XRRFreeOutputInfo(o_info); + XRRFreeScreenResources(res); +} diff --git a/Minilibx/mlx_flush_event.c b/Minilibx/mlx_flush_event.c new file mode 100644 index 0000000..1e586ad --- /dev/null +++ b/Minilibx/mlx_flush_event.c @@ -0,0 +1,25 @@ +/* +** mlx_flush_event.c for MiniLibX in +** +** Made by Charlie Root +** Login +** +** Started on Wed Aug 2 18:58:11 2000 Charlie Root +** Last update Fri Feb 23 17:08:48 2001 Charlie Root +*/ + + +#include "mlx_int.h" + + + + +int mlx_flush_event(t_xvar *xvar) +{ + XEvent ev; + + while (XPending(xvar->display)) + { + XNextEvent(xvar->display,&ev); + } +} diff --git a/Minilibx/mlx_get_color_value.c b/Minilibx/mlx_get_color_value.c new file mode 100644 index 0000000..b620970 --- /dev/null +++ b/Minilibx/mlx_get_color_value.c @@ -0,0 +1,33 @@ +/* +** mlx_get_color_value.c for MiniLibX in +** +** Made by Charlie Root +** Login +** +** Started on Mon Jul 31 19:01:33 2000 Charlie Root +** Last update Thu Oct 4 15:04:13 2001 Charlie Root +*/ + + +#include "mlx_int.h" + + +int mlx_get_color_value(t_xvar *xvar,int color) +{ + return(mlx_int_get_good_color(xvar,color)); +} + +int mlx_int_get_good_color(t_xvar *xvar,int color) +{ + XColor xc; + + if (xvar->depth>=24) + return (color); + xc.red = (color>>8)&0xFF00; + xc.green = color&0xFF00; + xc.blue = (color<<8)&0xFF00; + xc.pixel = ((xc.red>>(16-xvar->decrgb[1]))<decrgb[0])+ + ((xc.green>>(16-xvar->decrgb[3]))<decrgb[2])+ + ((xc.blue>>(16-xvar->decrgb[5]))<decrgb[4]); + return (xc.pixel); +} diff --git a/Minilibx/mlx_get_data_addr.c b/Minilibx/mlx_get_data_addr.c new file mode 100644 index 0000000..45e7a85 --- /dev/null +++ b/Minilibx/mlx_get_data_addr.c @@ -0,0 +1,23 @@ +/* +** mlx_get_data_addr.c for MiniLibX in raytraceur +** +** Made by Charlie Root +** Login +** +** Started on Mon Aug 14 15:45:57 2000 Charlie Root +** Last update Thu Sep 27 19:05:25 2001 Charlie Root +*/ + + + +#include "mlx_int.h" + + +char *mlx_get_data_addr(t_img *img,int *bits_per_pixel, + int *size_line,int *endian) +{ + *bits_per_pixel = img->bpp; + *size_line = img->size_line; + *endian = img->image->byte_order; + return (img->data); +} diff --git a/Minilibx/mlx_hook.c b/Minilibx/mlx_hook.c new file mode 100644 index 0000000..98e509a --- /dev/null +++ b/Minilibx/mlx_hook.c @@ -0,0 +1,40 @@ +/* +** mlx_hook.c for MiniLibX in +** +** Made by Charlie Root +** Login +** +** Started on Thu Aug 3 11:49:06 2000 Charlie Root +** Last update Fri Jan 28 17:05:28 2005 Olivier Crouzet +*/ + + +#include "mlx_int.h" + + + + +int mlx_hook(t_win_list *win, int x_event, int x_mask, + int (*funct)(),void *param) +{ + win->hooks[x_event].hook = funct; + win->hooks[x_event].param = param; + win->hooks[x_event].mask = x_mask; +} + + +int mlx_do_key_autorepeatoff(t_xvar *xvar) +{ + XAutoRepeatOff(xvar->display); +} + +int mlx_do_key_autorepeaton(t_xvar *xvar) +{ + XAutoRepeatOn(xvar->display); +} + + +int mlx_do_sync(t_xvar *xvar) +{ + XSync(xvar->display, False); +} diff --git a/Minilibx/mlx_init.c b/Minilibx/mlx_init.c new file mode 100644 index 0000000..c9d7463 --- /dev/null +++ b/Minilibx/mlx_init.c @@ -0,0 +1,99 @@ +/* +** mlx_init.c for MiniLibX in +** +** Made by Charlie Root +** Login +** +** Started on Mon Jul 31 16:52:42 2000 Charlie Root +** Last update Fri Jan 28 17:05:09 2005 Olivier Crouzet +*/ + + +#include "mlx_int.h" + + + +void *mlx_init() +{ + t_xvar *xvar; + + if (!(xvar = malloc(sizeof(*xvar)))) + return ((void*)0); + if ((xvar->display = XOpenDisplay("")) == 0) + { + free(xvar); + return ((void*)0); + } + xvar->screen = DefaultScreen(xvar->display); + xvar->root = DefaultRootWindow(xvar->display); + xvar->cmap = DefaultColormap(xvar->display,xvar->screen); + xvar->depth = DefaultDepth(xvar->display,xvar->screen); + if (mlx_int_get_visual(xvar)==-1) + { + printf(ERR_NO_TRUECOLOR); + exit(1); + } + xvar->win_list = 0; + xvar->loop_hook = 0; + xvar->loop_param = (void *)0; + xvar->do_flush = 1; + xvar->wm_delete_window = XInternAtom (xvar->display, "WM_DELETE_WINDOW", False); + xvar->wm_protocols = XInternAtom (xvar->display, "WM_PROTOCOLS", False); + mlx_int_deal_shm(xvar); + if (xvar->private_cmap) + xvar->cmap = XCreateColormap(xvar->display,xvar->root, + xvar->visual,AllocNone); + mlx_int_rgb_conversion(xvar); + xvar->end_loop = 0; + return (xvar); +} + + +/* +** pshm_format of -1 : Not XYBitmap|XYPixmap|ZPixmap +** alpha libX need a check of the DISPLAY env var, or shm is allowed +** in remote Xserver connections. +*/ + +int mlx_int_deal_shm(t_xvar *xvar) +{ + int use_pshm; + int bidon; + char *dpy; + char buff[33]; + + xvar->use_xshm = XShmQueryVersion(xvar->display,&bidon,&bidon,&(use_pshm)); + if (xvar->use_xshm && use_pshm) + xvar->pshm_format = XShmPixmapFormat(xvar->display); + else + xvar->pshm_format = -1; + gethostname(buff,32); + dpy = getenv(ENV_DISPLAY); + if (dpy && strlen(dpy) && *dpy!=':' && strncmp(dpy,buff,strlen(buff)) && + strncmp(dpy,LOCALHOST,strlen(LOCALHOST)) ) + { + xvar->pshm_format = -1; + xvar->use_xshm = 0; + } +} + +/* +** TrueColor Visual is needed to have *_mask correctly set +*/ + +int mlx_int_rgb_conversion(t_xvar *xvar) +{ + bzero(xvar->decrgb,sizeof(int)*6); + while (!(xvar->visual->red_mask&1)) + { xvar->visual->red_mask >>= 1; xvar->decrgb[0] ++; } + while (xvar->visual->red_mask&1) + { xvar->visual->red_mask >>= 1; xvar->decrgb[1] ++; } + while (!(xvar->visual->green_mask&1)) + { xvar->visual->green_mask >>= 1; xvar->decrgb[2] ++; } + while (xvar->visual->green_mask&1) + { xvar->visual->green_mask >>= 1; xvar->decrgb[3] ++; } + while (!(xvar->visual->blue_mask&1)) + { xvar->visual->blue_mask >>= 1; xvar->decrgb[4] ++; } + while (xvar->visual->blue_mask&1) + { xvar->visual->blue_mask >>= 1; xvar->decrgb[5] ++; } +} diff --git a/Minilibx/mlx_int.h b/Minilibx/mlx_int.h new file mode 100644 index 0000000..c49d1b7 --- /dev/null +++ b/Minilibx/mlx_int.h @@ -0,0 +1,140 @@ +/* +** mlx_int.h for mlx in +** +** Made by Charlie Root +** Login +** +** Started on Mon Jul 31 16:45:48 2000 Charlie Root +** Last update Wed May 25 16:44:16 2011 Olivier Crouzet +*/ + + + +/* +** Internal settings for MiniLibX +*/ + +#ifndef MLX_INT_H + +# define MLX_INT_H + +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +/* #include */ + + +# define MLX_TYPE_SHM_PIXMAP 3 +# define MLX_TYPE_SHM 2 +# define MLX_TYPE_XIMAGE 1 + +# define MLX_MAX_EVENT LASTEvent + + +# define ENV_DISPLAY "DISPLAY" +# define LOCALHOST "localhost" +# define ERR_NO_TRUECOLOR "MinilibX Error : No TrueColor Visual available.\n" +# define WARN_SHM_ATTACH "MinilibX Warning : X server can't attach shared memory.\n" + + +typedef struct s_xpm_col +{ + int name; + int col; +} t_xpm_col; + + +struct s_col_name +{ + char *name; + int color; +}; + +typedef struct s_event_list +{ + int mask; + int (*hook)(); + void *param; +} t_event_list; + + +typedef struct s_win_list +{ + Window window; + GC gc; + struct s_win_list *next; + int (*mouse_hook)(); + int (*key_hook)(); + int (*expose_hook)(); + void *mouse_param; + void *key_param; + void *expose_param; + t_event_list hooks[MLX_MAX_EVENT]; +} t_win_list; + + +typedef struct s_img +{ + XImage *image; + Pixmap pix; + GC gc; + int size_line; + int bpp; + int width; + int height; + int type; + int format; + char *data; + XShmSegmentInfo shm; +} t_img; + +typedef struct s_xvar +{ + Display *display; + Window root; + int screen; + int depth; + Visual *visual; + Colormap cmap; + int private_cmap; + t_win_list *win_list; + int (*loop_hook)(); + void *loop_param; + int use_xshm; + int pshm_format; + int do_flush; + int decrgb[6]; + Atom wm_delete_window; + Atom wm_protocols; + int end_loop; +} t_xvar; + + +int mlx_int_do_nothing(); +int mlx_get_color_value(); +int mlx_int_get_good_color(); +int mlx_int_find_in_pcm(); +int mlx_int_anti_resize_win(); +int mlx_int_wait_first_expose(); +int mlx_int_rgb_conversion(); +int mlx_int_deal_shm(); +void *mlx_int_new_xshm_image(); +char **mlx_int_str_to_wordtab(); +void *mlx_new_image(); +int shm_att_pb(); +int mlx_int_get_visual(t_xvar *xvar); +int mlx_int_set_win_event_mask(t_xvar *xvar); +int mlx_int_str_str_cote(char *str,char *find,int len); +int mlx_int_str_str(char *str,char *find,int len); + + +#endif diff --git a/Minilibx/mlx_int_anti_resize_win.c b/Minilibx/mlx_int_anti_resize_win.c new file mode 100644 index 0000000..2f20b44 --- /dev/null +++ b/Minilibx/mlx_int_anti_resize_win.c @@ -0,0 +1,28 @@ +/* +** mlx_int_anti_resize_win.c for MiniLibX in +** +** Made by Charlie Root +** Login +** +** Started on Tue Aug 8 14:31:05 2000 Charlie Root +** Last update Tue Sep 25 15:56:58 2001 Charlie Root +*/ + +#include "mlx_int.h" + + +int mlx_int_anti_resize_win(t_xvar *xvar,Window win,int w,int h) +{ + XSizeHints hints; + long toto; + + XGetWMNormalHints(xvar->display,win,&hints,&toto); + hints.width = w; + hints.height = h; + hints.min_width = w; + hints.min_height = h; + hints.max_width = w; + hints.max_height = h; + hints.flags = PPosition | PSize | PMinSize | PMaxSize; + XSetWMNormalHints(xvar->display,win,&hints); +} diff --git a/Minilibx/mlx_int_do_nothing.c b/Minilibx/mlx_int_do_nothing.c new file mode 100644 index 0000000..49524e4 --- /dev/null +++ b/Minilibx/mlx_int_do_nothing.c @@ -0,0 +1,16 @@ +/* +** mlx_int_do_nothing.c for MiniLibX in +** +** Made by Charlie Root +** Login +** +** Started on Tue Aug 8 12:58:24 2000 Charlie Root +** Last update Tue Sep 25 15:56:22 2001 Charlie Root +*/ + + + +int mlx_int_do_nothing(void *param) +{ + +} diff --git a/Minilibx/mlx_int_get_visual.c b/Minilibx/mlx_int_get_visual.c new file mode 100644 index 0000000..440a7ca --- /dev/null +++ b/Minilibx/mlx_int_get_visual.c @@ -0,0 +1,39 @@ +/* +** mlx_int_get_visual.c for MinilibX in +** +** Made by Charlie Root +** Login +** +** Started on Wed Oct 3 17:01:51 2001 Charlie Root +** Last update Thu Oct 4 15:00:45 2001 Charlie Root +*/ + + + +#include "mlx_int.h" + + +/* +** We need a private colormap for non-default Visual. +*/ + + +int mlx_int_get_visual(t_xvar *xvar) +{ + XVisualInfo *vi; + XVisualInfo template; + int nb_item; + + xvar->private_cmap = 0; + xvar->visual = DefaultVisual(xvar->display,xvar->screen); + if (xvar->visual->class == TrueColor) + return (0); + template.class = TrueColor; + template.depth = xvar->depth; + if (!(vi = XGetVisualInfo(xvar->display,VisualDepthMask|VisualClassMask, + &template,&nb_item)) ) + return (-1); + xvar->visual = vi->visual; + xvar->private_cmap = 1; + return (0); +} diff --git a/Minilibx/mlx_int_param_event.c b/Minilibx/mlx_int_param_event.c new file mode 100644 index 0000000..8756a22 --- /dev/null +++ b/Minilibx/mlx_int_param_event.c @@ -0,0 +1,100 @@ +/* +** mlx_int_param_event.c for MinilibX in +** +** Made by Charlie Root +** Login +** +** Started on Mon Jul 31 16:37:50 2000 Charlie Root +** Last update Wed Oct 6 13:14:52 2004 Olivier Crouzet +*/ + +#include "mlx_int.h" + +int mlx_int_param_undef() +{ +} + +int mlx_int_param_KeyPress(t_xvar *xvar, XEvent *ev, t_win_list *win) +{ + win->hooks[KeyPress].hook(XkbKeycodeToKeysym(xvar->display, + ev->xkey.keycode, 0, 0), + win->hooks[KeyPress].param); +} + +int mlx_int_param_KeyRelease(t_xvar *xvar, XEvent *ev, t_win_list *win) +{ + win->hooks[KeyRelease].hook(XkbKeycodeToKeysym(xvar->display, + ev->xkey.keycode, 0, 0), + win->hooks[KeyRelease].param); +} + +int mlx_int_param_ButtonPress(t_xvar *xvar, XEvent *ev, t_win_list *win) +{ + win->hooks[ButtonPress].hook(ev->xbutton.button,ev->xbutton.x,ev->xbutton.y, + win->hooks[ButtonPress].param); +} + +int mlx_int_param_ButtonRelease(t_xvar *xvar, XEvent *ev, t_win_list *win) +{ + win->hooks[ButtonRelease].hook(ev->xbutton.button, + ev->xbutton.x, ev->xbutton.y, + win->hooks[ButtonRelease].param); +} + +int mlx_int_param_MotionNotify(t_xvar *xvar, XEvent *ev, t_win_list *win) +{ + win->hooks[MotionNotify].hook(ev->xbutton.x,ev->xbutton.y, + win->hooks[MotionNotify].param); +} + +int mlx_int_param_Expose(t_xvar *xvar, XEvent *ev, t_win_list *win) +{ + if (!ev->xexpose.count) + win->hooks[Expose].hook(win->hooks[Expose].param); +} + + +int mlx_int_param_generic(t_xvar *xvar, XEvent *ev, t_win_list *win) +{ + win->hooks[ev->type].hook(win->hooks[ev->type].param); +} + +int (*(mlx_int_param_event[]))() = +{ + mlx_int_param_undef, /* 0 */ + mlx_int_param_undef, + mlx_int_param_KeyPress, + mlx_int_param_KeyRelease, /* 3 */ + mlx_int_param_ButtonPress, + mlx_int_param_ButtonRelease, + mlx_int_param_MotionNotify, /* 6 */ + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_Expose, /* 12 */ + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic, + mlx_int_param_generic +}; diff --git a/Minilibx/mlx_int_set_win_event_mask.c b/Minilibx/mlx_int_set_win_event_mask.c new file mode 100644 index 0000000..55650cd --- /dev/null +++ b/Minilibx/mlx_int_set_win_event_mask.c @@ -0,0 +1,34 @@ +/* +** mlx_int_set_win_event_mask.c for MiniLibX in +** +** Made by Charlie Root +** Login +** +** Started on Thu Aug 3 11:49:06 2000 Charlie Root +** Last update Fri Feb 23 17:07:42 2001 Charlie Root +*/ + + +#include "mlx_int.h" + + + + +int mlx_int_set_win_event_mask(t_xvar *xvar) +{ + t_win_list *win; + int mask; + int i; + XSetWindowAttributes xwa; + + win = xvar->win_list; + while (win) + { + xwa.event_mask = 0; + i = MLX_MAX_EVENT; + while (i--) + xwa.event_mask |= win->hooks[i].mask; + XChangeWindowAttributes(xvar->display, win->window, CWEventMask, &xwa); + win = win->next; + } +} diff --git a/Minilibx/mlx_int_str_to_wordtab.c b/Minilibx/mlx_int_str_to_wordtab.c new file mode 100644 index 0000000..7f92089 --- /dev/null +++ b/Minilibx/mlx_int_str_to_wordtab.c @@ -0,0 +1,113 @@ +/* +** mlx_int_str_to_wordtab.c for MinilibX in +** +** Made by Charlie Root +** Login +** +** Started on Wed Sep 13 11:36:09 2000 Charlie Root +** Last update Fri Dec 14 11:02:09 2001 Charlie Root +*/ + + +#include "mlx_int.h" + + +int mlx_int_str_str(char *str,char *find,int len) +{ + int len_f; + int pos; + char *s; + char *f; + + len_f = strlen(find); + if (len_f>len) + return (-1); + pos = 0; + while (*(str+len_f-1)) + { + s = str; + f = find; + while (*(f++) == *(s++)) + if (!*f) + return (pos); + str ++; + pos ++; + } + return (-1); +} + + + +int mlx_int_str_str_cote(char *str,char *find,int len) +{ + int len_f; + int pos; + char *s; + char *f; + int cote; + + len_f = strlen(find); + if (len_f>len) + return (-1); + cote = 0; + pos = 0; + while (*(str+len_f-1)) + { + if (*str=='"') + cote = 1-cote; + if (!cote) + { + s = str; + f = find; + while (*(f++) == *(s++)) + if (!*f) + return (pos); + } + str ++; + pos ++; + } + return (-1); +} + + +char **mlx_int_str_to_wordtab(char *str) +{ + char **tab; + int pos; + int nb_word; + int len; + + len = strlen(str); + nb_word = 0; + pos = 0; + while (pos +** +** Started on Tue Oct 17 09:26:45 2000 olivier crouzet +** Last update Fri Feb 23 17:27:10 2001 Charlie Root +*/ + + + +#include "mlx_int.h" + + + +int mlx_int_wait_first_expose(t_xvar *xvar,Window win) +{ + XEvent ev; + + XWindowEvent(xvar->display,win,ExposureMask,&ev); + XPutBackEvent(xvar->display,&ev); +} diff --git a/Minilibx/mlx_key_hook.c b/Minilibx/mlx_key_hook.c new file mode 100644 index 0000000..eea6484 --- /dev/null +++ b/Minilibx/mlx_key_hook.c @@ -0,0 +1,22 @@ +/* +** mlx_key_hook.c for MiniLibX in +** +** Made by Charlie Root +** Login +** +** Started on Thu Aug 3 11:49:06 2000 Charlie Root +** Last update Fri Feb 23 17:10:09 2001 Charlie Root +*/ + + +#include "mlx_int.h" + + + + +int mlx_key_hook(t_win_list *win,int (*funct)(),void *param) +{ + win->hooks[KeyRelease].hook = funct; + win->hooks[KeyRelease].param = param; + win->hooks[KeyRelease].mask = KeyReleaseMask; +} diff --git a/Minilibx/mlx_lib_xpm.c b/Minilibx/mlx_lib_xpm.c new file mode 100644 index 0000000..b8cf184 --- /dev/null +++ b/Minilibx/mlx_lib_xpm.c @@ -0,0 +1,96 @@ +/* +** mlx_xpm.c for minilibX in +** +** Made by Charlie Root +** Login +** +** Started on Fri Dec 8 11:07:24 2000 Charlie Root +** Last update Thu Oct 4 16:00:22 2001 Charlie Root +*/ + + +#include "mlx_int.h" + + + + +void *mlx_int_xpm_f_image(t_xvar *xvar,int *width,int *height, + int (*xpm_func)(),void *param) +{ + XImage *img1; + XImage *img2; + t_img *im2; + XpmAttributes xpm_att; + + xpm_att.visual = xvar->visual; + xpm_att.colormap = xvar->cmap; + xpm_att.depth = xvar->depth; + xpm_att.bitmap_format = ZPixmap; + xpm_att.valuemask = XpmDepth|XpmBitmapFormat|XpmVisual|XpmColormap; + if (xpm_func(xvar->display,param,&img1,&img2,&xpm_att)) + return ((void *)0); + if (img2) + XDestroyImage(img2); + + if (!(im2 = (void *)mlx_new_image(xvar,img1->width,img1->height))) + { + XDestroyImage(img1); + return ((void *)0); + } + *width = img1->width; + *height = img1->height; + if (mlx_int_egal_img(im2->image,img1)) + { + bcopy(img1->data,im2->data,img1->height*img1->bytes_per_line); + XDestroyImage(img1); + return (im2); + } + if (im2->type==MLX_TYPE_SHM_PIXMAP) + { + XFreePixmap(xvar->display,im2->pix); + im2->pix = XCreatePixmap(xvar->display,xvar->root, + *width,*height,xvar->depth); + } + if (im2->type>MLX_TYPE_XIMAGE) + { + XShmDetach(xvar->display,&(im2->shm)); + shmdt(im2->data); + } + XDestroyImage(im2->image); + im2->image = img1; + im2->data = img1->data; + im2->type = MLX_TYPE_XIMAGE; + im2->size_line = img1->bytes_per_line; + im2->bpp = img1->bits_per_pixel; + return (im2); +} + + +int mlx_int_egal_img(XImage *img1,XImage *img2) +{ + if (img1->width!=img2->width || img1->height!=img2->height || + img1->xoffset!=img2->xoffset || img1->format!=img2->format || + img1->byte_order!=img2->byte_order || + img1->bitmap_unit!=img2->bitmap_unit || + img1->bitmap_bit_order!=img2->bitmap_bit_order || + img1->bitmap_pad!=img2->bitmap_pad || img1->depth!=img2->depth || + img1->bytes_per_line!=img2->bytes_per_line || + img1->bits_per_pixel!=img2->bits_per_pixel || + img1->red_mask!=img2->red_mask || img1->green_mask!=img2->green_mask || + img1->blue_mask!=img2->blue_mask ) + return (0); + return (1); +} + + +void *mlx_xpm_file_to_image(t_xvar *xvar,char *filename, + int *width,int *height) +{ + return (mlx_int_xpm_f_image(xvar,width,height,XpmReadFileToImage,filename)); +} + + +void *mlx_xpm_to_image(t_xvar *xvar,char **data,int *width,int *height) +{ + return (mlx_int_xpm_f_image(xvar,width,height,XpmCreateImageFromData,(void *)data)); +} diff --git a/Minilibx/mlx_loop.c b/Minilibx/mlx_loop.c new file mode 100644 index 0000000..cc4e119 --- /dev/null +++ b/Minilibx/mlx_loop.c @@ -0,0 +1,63 @@ +/* +** mlx_loop.c for MiniLibX in +** +** Made by Charlie Root +** Login +** +** Started on Wed Aug 2 18:58:11 2000 Charlie Root +** Last update Fri Sep 30 14:47:41 2005 Olivier Crouzet +*/ + + +#include "mlx_int.h" + +extern int (*(mlx_int_param_event[]))(); + +static int win_count(t_xvar *xvar) +{ + int i; + t_win_list *win; + + i = 0; + win = xvar->win_list; + while (win) + { + win = win->next; + ++i; + } + return (i); +} + +int mlx_loop_end(t_xvar *xvar) +{ + xvar->end_loop = 1; + return (1); +} + +int mlx_loop(t_xvar *xvar) +{ + XEvent ev; + t_win_list *win; + + mlx_int_set_win_event_mask(xvar); + xvar->do_flush = 0; + while (win_count(xvar) && !xvar->end_loop) + { + while (!xvar->end_loop && (!xvar->loop_hook || XPending(xvar->display))) + { + XNextEvent(xvar->display,&ev); + win = xvar->win_list; + while (win && (win->window!=ev.xany.window)) + win = win->next; + + if (win && ev.type == ClientMessage && ev.xclient.message_type == xvar->wm_protocols && ev.xclient.data.l[0] == xvar->wm_delete_window && win->hooks[DestroyNotify].hook) + win->hooks[DestroyNotify].hook(win->hooks[DestroyNotify].param); + if (win && ev.type < MLX_MAX_EVENT && win->hooks[ev.type].hook) + mlx_int_param_event[ev.type](xvar, &ev, win); + } + XSync(xvar->display, False); + if (xvar->loop_hook) + xvar->loop_hook(xvar->loop_param); + } + return (0); +} diff --git a/Minilibx/mlx_loop_hook.c b/Minilibx/mlx_loop_hook.c new file mode 100644 index 0000000..1f8b9ed --- /dev/null +++ b/Minilibx/mlx_loop_hook.c @@ -0,0 +1,21 @@ +/* +** mlx_loop_hook.c for MiniLibX in +** +** Made by Charlie Root +** Login +** +** Started on Thu Aug 3 11:49:06 2000 Charlie Root +** Last update Fri Feb 23 17:11:39 2001 Charlie Root +*/ + + +#include "mlx_int.h" + + + + +int mlx_loop_hook(t_xvar *xvar,int (*funct)(),void *param) +{ + xvar->loop_hook = funct; + xvar->loop_param = param; +} diff --git a/Minilibx/mlx_mouse.c b/Minilibx/mlx_mouse.c new file mode 100644 index 0000000..ce0d4c9 --- /dev/null +++ b/Minilibx/mlx_mouse.c @@ -0,0 +1,48 @@ +#include "mlx_int.h" + +int mlx_mouse_move(t_xvar *xvar, t_win_list *win, int x, int y) +{ + XWarpPointer(xvar->display, None, win->window, 0, 0, 0, 0, x, y); + return (0); +} + +int mlx_mouse_hide(t_xvar *xvar, t_win_list *win) +{ + static char data[1] = {0}; + Cursor cursor; + Pixmap blank; + XColor dummy; + + blank = XCreateBitmapFromData(xvar->display, win->window, data, 1, 1); + cursor = XCreatePixmapCursor(xvar->display, blank, blank, &dummy, &dummy, 0, 0); + XDefineCursor(xvar->display, win->window, cursor); + XFreePixmap(xvar->display, blank); + XFreeCursor(xvar->display, cursor); +} + +int mlx_mouse_show(t_xvar *xvar, t_win_list *win) +{ + XUndefineCursor(xvar->display, win->window); +} + +/* +** Queries the position of the mouse pointer relative to the origin of the +** specified window and saves it to the provided location. +** +** If the pointer is not on the same screen as the specified window, both +** win_x_return and win_y_return are set to zero and the function returns 0. +*/ + +int mlx_mouse_get_pos(t_xvar *xvar, t_win_list *win, \ + int *win_x_return, int *win_y_return) +{ + Window root_return; + Window child_return; + int root_x_return; + int root_y_return; + unsigned mask_return; + + return (XQueryPointer(xvar->display, win->window, \ + &root_return, &child_return, &root_x_return, &root_y_return, \ + win_x_return, win_y_return, &mask_return)); +} diff --git a/Minilibx/mlx_mouse_hook.c b/Minilibx/mlx_mouse_hook.c new file mode 100644 index 0000000..cb567ab --- /dev/null +++ b/Minilibx/mlx_mouse_hook.c @@ -0,0 +1,22 @@ +/* +** mlx_mouse_hook.c for MiniLibX in +** +** Made by Charlie Root +** Login +** +** Started on Thu Aug 3 11:49:06 2000 Charlie Root +** Last update Fri Feb 23 17:11:05 2001 Charlie Root +*/ + + +#include "mlx_int.h" + + + + +int mlx_mouse_hook(t_win_list *win,int (*funct)(),void *param) +{ + win->hooks[ButtonPress].hook = funct; + win->hooks[ButtonPress].param = param; + win->hooks[ButtonPress].mask = ButtonPressMask; +} diff --git a/Minilibx/mlx_new_image.c b/Minilibx/mlx_new_image.c new file mode 100644 index 0000000..d2cbfc1 --- /dev/null +++ b/Minilibx/mlx_new_image.c @@ -0,0 +1,159 @@ +/* +** mlx_new_image.c for MiniLibX in raytraceur +** +** Made by Charlie Root +** Login +** +** Started on Mon Aug 14 15:29:14 2000 Charlie Root +** Last update Wed May 25 16:46:31 2011 Olivier Crouzet +*/ + + + + +#include "mlx_int.h" + +/* +** To handle X errors +*/ + +#define X_ShmAttach 1 + +int mlx_X_error; + +int shm_att_pb(Display *d,XErrorEvent *ev) +{ + if (ev->request_code==146 && ev->minor_code==X_ShmAttach) + write(2,WARN_SHM_ATTACH,strlen(WARN_SHM_ATTACH)); + mlx_X_error = 1; +} + + +/* +** Data malloc : width+32 ( bitmap_pad=32 ), *4 = *32 / 8bit +*/ + + +void *mlx_int_new_xshm_image(t_xvar *xvar,int width,int height,int format) +{ + t_img *img; + int (*save_handler)(); + + if (!(img = malloc(sizeof(*img)))) + return ((void *)0); + bzero(img,sizeof(*img)); + img->data = 0; + img->image = XShmCreateImage(xvar->display,xvar->visual,xvar->depth, + format,img->data,&(img->shm),width,height); + if (!img->image) + { + free(img); + return ((void *)0); + } + img->width = width; + img->height = height; + img->size_line = img->image->bytes_per_line; + img->bpp = img->image->bits_per_pixel; + img->format = format; + img->shm.shmid = shmget(IPC_PRIVATE,(width+32)*height*4,IPC_CREAT|0777); + if (img->shm.shmid==-1) + { + XDestroyImage(img->image); + free(img); + return ((void *)0); + } + img->data = img->shm.shmaddr = img->image->data = shmat(img->shm.shmid,0,0); + if (img->data==(void *)-1) + { + shmctl(img->shm.shmid,IPC_RMID,0); + XDestroyImage(img->image); + free(img); + return ((void *)0); + } + img->shm.readOnly = False; + mlx_X_error = 0; + save_handler = XSetErrorHandler(shm_att_pb); + if (!XShmAttach(xvar->display,&(img->shm)) || + 0&XSync(xvar->display,False) || mlx_X_error) + { + XSetErrorHandler(save_handler); + shmdt(img->data); + shmctl(img->shm.shmid,IPC_RMID,0); + XDestroyImage(img->image); + free(img); + return ((void *)0); + } + XSetErrorHandler(save_handler); + shmctl(img->shm.shmid,IPC_RMID,0); + if (xvar->pshm_format==format) + { + img->pix = XShmCreatePixmap(xvar->display,xvar->root,img->shm.shmaddr, + &(img->shm),width,height,xvar->depth); + img->type = MLX_TYPE_SHM_PIXMAP; + } + else + { + img->pix = XCreatePixmap(xvar->display,xvar->root, + width,height,xvar->depth); + img->type = MLX_TYPE_SHM; + } + if (xvar->do_flush) + XFlush(xvar->display); + return (img); +} + + + +void *mlx_int_new_image(t_xvar *xvar,int width, int height,int format) +{ + t_img *img; + + if (!(img = malloc(sizeof(*img)))) + return ((void *)0); + if (!(img->data = malloc((width+32)*height*4))) + { + free(img); + return ((void *)0); + } + bzero(img->data,(width+32)*height*4); + img->image = XCreateImage(xvar->display,xvar->visual,xvar->depth,format,0, + img->data,width,height,32,0); + if (!img->image) + { + free(img->data); + free(img); + return ((void *)0); + } + img->gc = 0; + img->size_line = img->image->bytes_per_line; + img->bpp = img->image->bits_per_pixel; + img->width = width; + img->height = height; + img->pix = XCreatePixmap(xvar->display,xvar->root,width,height,xvar->depth); + img->format = format; + img->type = MLX_TYPE_XIMAGE; + if (xvar->do_flush) + XFlush(xvar->display); + return (img); +} + + +void *mlx_new_image(t_xvar *xvar,int width, int height) +{ + t_img *img; + + if (xvar->use_xshm) + if (img = mlx_int_new_xshm_image(xvar,width,height,ZPixmap)) + return (img); + return (mlx_int_new_image(xvar,width,height,ZPixmap)); +} + +void *mlx_new_image2(t_xvar *xvar,int width, int height) +{ + t_img *img; + + if (xvar->use_xshm) + if (img = mlx_int_new_xshm_image(xvar,width,height,XYPixmap)) + return (img); + return (mlx_int_new_image(xvar,width,height,XYPixmap)); +} diff --git a/Minilibx/mlx_new_window.c b/Minilibx/mlx_new_window.c new file mode 100644 index 0000000..3f05914 --- /dev/null +++ b/Minilibx/mlx_new_window.c @@ -0,0 +1,62 @@ +/* +** mlx_new_window.c for MiniLibX in +** +** Made by Charlie Root +** Login +** +** Started on Mon Jul 31 17:29:02 2000 Charlie Root +** Last update Thu Oct 4 15:44:43 2001 Charlie Root +*/ + + +/* +** We do not use White/BlackPixel macro, TrueColor Visual make sure +** 0 is black & -1 is white +** +** With mlx_int_wait_first_expose, no flush is needed. +*/ + +#include "mlx_int.h" + + +void *mlx_new_window(t_xvar *xvar,int size_x,int size_y,char *title) +{ + t_win_list *new_win; + XSetWindowAttributes xswa; + XGCValues xgcv; + + xswa.background_pixel = 0; + xswa.border_pixel = -1; + xswa.colormap = xvar->cmap; + /* + xswa.event_mask = ButtonPressMask | ButtonReleaseMask | ExposureMask | + KeyPressMask | KeyReleaseMask | StructureNotifyMask; + */ + /* xswa.event_mask = ExposureMask; */ + xswa.event_mask = 0xFFFFFF; /* all events */ + if (!(new_win = malloc(sizeof(*new_win)))) + return ((void *)0); + new_win->window = XCreateWindow(xvar->display,xvar->root,0,0,size_x,size_y, + 0,CopyFromParent,InputOutput,xvar->visual, + CWEventMask|CWBackPixel|CWBorderPixel| + CWColormap,&xswa); + mlx_int_anti_resize_win(xvar,new_win->window,size_x,size_y); + XStoreName(xvar->display,new_win->window,title); + XSetWMProtocols(xvar->display, new_win->window, &(xvar->wm_delete_window), 1); + xgcv.foreground = -1; + xgcv.function = GXcopy; + xgcv.plane_mask = AllPlanes; + new_win->gc = XCreateGC(xvar->display,new_win->window, + GCFunction|GCPlaneMask|GCForeground,&xgcv); + new_win->next = xvar->win_list; + xvar->win_list = new_win; + /* + new_win->mouse_hook = mlx_int_do_nothing; + new_win->key_hook = mlx_int_do_nothing; + new_win->expose_hook = mlx_int_do_nothing; + */ + bzero(&(new_win->hooks), sizeof(new_win->hooks)); + XMapRaised(xvar->display,new_win->window); + mlx_int_wait_first_expose(xvar,new_win->window); + return (new_win); +} diff --git a/Minilibx/mlx_pixel_put.c b/Minilibx/mlx_pixel_put.c new file mode 100644 index 0000000..c411f36 --- /dev/null +++ b/Minilibx/mlx_pixel_put.c @@ -0,0 +1,26 @@ +/* + ** mlx_pixel_put.c for MiniLibX in + ** + ** Made by Charlie Root + ** Login + ** + ** Started on Mon Jul 31 19:01:33 2000 Charlie Root +** Last update Tue Sep 25 17:09:49 2001 Charlie Root + */ + + +#include "mlx_int.h" + + + +int mlx_pixel_put(t_xvar *xvar,t_win_list *win, + int x,int y,int color) +{ + XGCValues xgcv; + + xgcv.foreground = mlx_int_get_good_color(xvar,color); + XChangeGC(xvar->display,win->gc,GCForeground,&xgcv); + XDrawPoint(xvar->display,win->window,win->gc,x,y); + if (xvar->do_flush) + XFlush(xvar->display); +} diff --git a/Minilibx/mlx_put_image_to_window.c b/Minilibx/mlx_put_image_to_window.c new file mode 100644 index 0000000..86ba3f4 --- /dev/null +++ b/Minilibx/mlx_put_image_to_window.c @@ -0,0 +1,37 @@ +/* +** mlx_put_image_to_window.c for MiniLibX in raytraceur +** +** Made by Charlie Root +** Login +** +** Started on Mon Aug 14 15:55:49 2000 Charlie Root +** Last update Sun Oct 2 09:53:00 2005 Olivier Crouzet +*/ + + + +#include "mlx_int.h" + + +int mlx_put_image_to_window(t_xvar *xvar,t_win_list *win,t_img *img, + int x,int y) +{ + GC gc; + + gc = win->gc; + if (img->gc) + { + gc = img->gc; + XSetClipOrigin(xvar->display, gc, x, y); + } + if (img->type==MLX_TYPE_SHM) + XShmPutImage(xvar->display,img->pix, win->gc, img->image,0,0,0,0, + img->width,img->height,False); + if (img->type==MLX_TYPE_XIMAGE) + XPutImage(xvar->display,img->pix, win->gc, img->image,0,0,0,0, + img->width,img->height); + XCopyArea(xvar->display,img->pix,win->window, gc, + 0,0,img->width,img->height,x,y); + if (xvar->do_flush) + XFlush(xvar->display); +} diff --git a/Minilibx/mlx_rgb.c b/Minilibx/mlx_rgb.c new file mode 100644 index 0000000..0cfccf6 --- /dev/null +++ b/Minilibx/mlx_rgb.c @@ -0,0 +1,764 @@ +/* +** This is a generated file with rgb2c.pl and rgb.txt from +** the XFree86 distribution. +*/ + +#include "mlx_int.h" + +struct s_col_name mlx_col_name[] = +{ + { "snow" , 0xfffafa }, + { "ghost white" , 0xf8f8ff }, + { "ghostwhite" , 0xf8f8ff }, + { "white smoke" , 0xf5f5f5 }, + { "whitesmoke" , 0xf5f5f5 }, + { "gainsboro" , 0xdcdcdc }, + { "floral white" , 0xfffaf0 }, + { "floralwhite" , 0xfffaf0 }, + { "old lace" , 0xfdf5e6 }, + { "oldlace" , 0xfdf5e6 }, + { "linen" , 0xfaf0e6 }, + { "antique white" , 0xfaebd7 }, + { "antiquewhite" , 0xfaebd7 }, + { "papaya whip" , 0xffefd5 }, + { "papayawhip" , 0xffefd5 }, + { "blanched almond" , 0xffebcd }, + { "blanchedalmond" , 0xffebcd }, + { "bisque" , 0xffe4c4 }, + { "peach puff" , 0xffdab9 }, + { "peachpuff" , 0xffdab9 }, + { "navajo white" , 0xffdead }, + { "navajowhite" , 0xffdead }, + { "moccasin" , 0xffe4b5 }, + { "cornsilk" , 0xfff8dc }, + { "ivory" , 0xfffff0 }, + { "lemon chiffon" , 0xfffacd }, + { "lemonchiffon" , 0xfffacd }, + { "seashell" , 0xfff5ee }, + { "honeydew" , 0xf0fff0 }, + { "mint cream" , 0xf5fffa }, + { "mintcream" , 0xf5fffa }, + { "azure" , 0xf0ffff }, + { "alice blue" , 0xf0f8ff }, + { "aliceblue" , 0xf0f8ff }, + { "lavender" , 0xe6e6fa }, + { "lavender blush" , 0xfff0f5 }, + { "lavenderblush" , 0xfff0f5 }, + { "misty rose" , 0xffe4e1 }, + { "mistyrose" , 0xffe4e1 }, + { "white" , 0xffffff }, + { "black" , 0x0 }, + { "dark slate" , 0x2f4f4f }, + { "darkslategray" , 0x2f4f4f }, + { "dark slate" , 0x2f4f4f }, + { "darkslategrey" , 0x2f4f4f }, + { "dim gray" , 0x696969 }, + { "dimgray" , 0x696969 }, + { "dim grey" , 0x696969 }, + { "dimgrey" , 0x696969 }, + { "slate gray" , 0x708090 }, + { "slategray" , 0x708090 }, + { "slate grey" , 0x708090 }, + { "slategrey" , 0x708090 }, + { "light slate" , 0x778899 }, + { "lightslategray" , 0x778899 }, + { "light slate" , 0x778899 }, + { "lightslategrey" , 0x778899 }, + { "gray" , 0xbebebe }, + { "grey" , 0xbebebe }, + { "light grey" , 0xd3d3d3 }, + { "lightgrey" , 0xd3d3d3 }, + { "light gray" , 0xd3d3d3 }, + { "lightgray" , 0xd3d3d3 }, + { "midnight blue" , 0x191970 }, + { "midnightblue" , 0x191970 }, + { "navy" , 0x80 }, + { "navy blue" , 0x80 }, + { "navyblue" , 0x80 }, + { "cornflower blue" , 0x6495ed }, + { "cornflowerblue" , 0x6495ed }, + { "dark slate" , 0x483d8b }, + { "darkslateblue" , 0x483d8b }, + { "slate blue" , 0x6a5acd }, + { "slateblue" , 0x6a5acd }, + { "medium slate" , 0x7b68ee }, + { "mediumslateblue" , 0x7b68ee }, + { "light slate" , 0x8470ff }, + { "lightslateblue" , 0x8470ff }, + { "medium blue" , 0xcd }, + { "mediumblue" , 0xcd }, + { "royal blue" , 0x4169e1 }, + { "royalblue" , 0x4169e1 }, + { "blue" , 0xff }, + { "dodger blue" , 0x1e90ff }, + { "dodgerblue" , 0x1e90ff }, + { "deep sky" , 0xbfff }, + { "deepskyblue" , 0xbfff }, + { "sky blue" , 0x87ceeb }, + { "skyblue" , 0x87ceeb }, + { "light sky" , 0x87cefa }, + { "lightskyblue" , 0x87cefa }, + { "steel blue" , 0x4682b4 }, + { "steelblue" , 0x4682b4 }, + { "light steel" , 0xb0c4de }, + { "lightsteelblue" , 0xb0c4de }, + { "light blue" , 0xadd8e6 }, + { "lightblue" , 0xadd8e6 }, + { "powder blue" , 0xb0e0e6 }, + { "powderblue" , 0xb0e0e6 }, + { "pale turquoise" , 0xafeeee }, + { "paleturquoise" , 0xafeeee }, + { "dark turquoise" , 0xced1 }, + { "darkturquoise" , 0xced1 }, + { "medium turquoise" , 0x48d1cc }, + { "mediumturquoise" , 0x48d1cc }, + { "turquoise" , 0x40e0d0 }, + { "cyan" , 0xffff }, + { "light cyan" , 0xe0ffff }, + { "lightcyan" , 0xe0ffff }, + { "cadet blue" , 0x5f9ea0 }, + { "cadetblue" , 0x5f9ea0 }, + { "medium aquamarine" , 0x66cdaa }, + { "mediumaquamarine" , 0x66cdaa }, + { "aquamarine" , 0x7fffd4 }, + { "dark green" , 0x6400 }, + { "darkgreen" , 0x6400 }, + { "dark olive" , 0x556b2f }, + { "darkolivegreen" , 0x556b2f }, + { "dark sea" , 0x8fbc8f }, + { "darkseagreen" , 0x8fbc8f }, + { "sea green" , 0x2e8b57 }, + { "seagreen" , 0x2e8b57 }, + { "medium sea" , 0x3cb371 }, + { "mediumseagreen" , 0x3cb371 }, + { "light sea" , 0x20b2aa }, + { "lightseagreen" , 0x20b2aa }, + { "pale green" , 0x98fb98 }, + { "palegreen" , 0x98fb98 }, + { "spring green" , 0xff7f }, + { "springgreen" , 0xff7f }, + { "lawn green" , 0x7cfc00 }, + { "lawngreen" , 0x7cfc00 }, + { "green" , 0xff00 }, + { "chartreuse" , 0x7fff00 }, + { "medium spring" , 0xfa9a }, + { "mediumspringgreen" , 0xfa9a }, + { "green yellow" , 0xadff2f }, + { "greenyellow" , 0xadff2f }, + { "lime green" , 0x32cd32 }, + { "limegreen" , 0x32cd32 }, + { "yellow green" , 0x9acd32 }, + { "yellowgreen" , 0x9acd32 }, + { "forest green" , 0x228b22 }, + { "forestgreen" , 0x228b22 }, + { "olive drab" , 0x6b8e23 }, + { "olivedrab" , 0x6b8e23 }, + { "dark khaki" , 0xbdb76b }, + { "darkkhaki" , 0xbdb76b }, + { "khaki" , 0xf0e68c }, + { "pale goldenrod" , 0xeee8aa }, + { "palegoldenrod" , 0xeee8aa }, + { "light goldenrod" , 0xfafad2 }, + { "lightgoldenrodyellow" , 0xfafad2 }, + { "light yellow" , 0xffffe0 }, + { "lightyellow" , 0xffffe0 }, + { "yellow" , 0xffff00 }, + { "gold" , 0xffd700 }, + { "light goldenrod" , 0xeedd82 }, + { "lightgoldenrod" , 0xeedd82 }, + { "goldenrod" , 0xdaa520 }, + { "dark goldenrod" , 0xb8860b }, + { "darkgoldenrod" , 0xb8860b }, + { "rosy brown" , 0xbc8f8f }, + { "rosybrown" , 0xbc8f8f }, + { "indian red" , 0xcd5c5c }, + { "indianred" , 0xcd5c5c }, + { "saddle brown" , 0x8b4513 }, + { "saddlebrown" , 0x8b4513 }, + { "sienna" , 0xa0522d }, + { "peru" , 0xcd853f }, + { "burlywood" , 0xdeb887 }, + { "beige" , 0xf5f5dc }, + { "wheat" , 0xf5deb3 }, + { "sandy brown" , 0xf4a460 }, + { "sandybrown" , 0xf4a460 }, + { "tan" , 0xd2b48c }, + { "chocolate" , 0xd2691e }, + { "firebrick" , 0xb22222 }, + { "brown" , 0xa52a2a }, + { "dark salmon" , 0xe9967a }, + { "darksalmon" , 0xe9967a }, + { "salmon" , 0xfa8072 }, + { "light salmon" , 0xffa07a }, + { "lightsalmon" , 0xffa07a }, + { "orange" , 0xffa500 }, + { "dark orange" , 0xff8c00 }, + { "darkorange" , 0xff8c00 }, + { "coral" , 0xff7f50 }, + { "light coral" , 0xf08080 }, + { "lightcoral" , 0xf08080 }, + { "tomato" , 0xff6347 }, + { "orange red" , 0xff4500 }, + { "orangered" , 0xff4500 }, + { "red" , 0xff0000 }, + { "hot pink" , 0xff69b4 }, + { "hotpink" , 0xff69b4 }, + { "deep pink" , 0xff1493 }, + { "deeppink" , 0xff1493 }, + { "pink" , 0xffc0cb }, + { "light pink" , 0xffb6c1 }, + { "lightpink" , 0xffb6c1 }, + { "pale violet" , 0xdb7093 }, + { "palevioletred" , 0xdb7093 }, + { "maroon" , 0xb03060 }, + { "medium violet" , 0xc71585 }, + { "mediumvioletred" , 0xc71585 }, + { "violet red" , 0xd02090 }, + { "violetred" , 0xd02090 }, + { "magenta" , 0xff00ff }, + { "violet" , 0xee82ee }, + { "plum" , 0xdda0dd }, + { "orchid" , 0xda70d6 }, + { "medium orchid" , 0xba55d3 }, + { "mediumorchid" , 0xba55d3 }, + { "dark orchid" , 0x9932cc }, + { "darkorchid" , 0x9932cc }, + { "dark violet" , 0x9400d3 }, + { "darkviolet" , 0x9400d3 }, + { "blue violet" , 0x8a2be2 }, + { "blueviolet" , 0x8a2be2 }, + { "purple" , 0xa020f0 }, + { "medium purple" , 0x9370db }, + { "mediumpurple" , 0x9370db }, + { "thistle" , 0xd8bfd8 }, + { "snow1" , 0xfffafa }, + { "snow2" , 0xeee9e9 }, + { "snow3" , 0xcdc9c9 }, + { "snow4" , 0x8b8989 }, + { "seashell1" , 0xfff5ee }, + { "seashell2" , 0xeee5de }, + { "seashell3" , 0xcdc5bf }, + { "seashell4" , 0x8b8682 }, + { "antiquewhite1" , 0xffefdb }, + { "antiquewhite2" , 0xeedfcc }, + { "antiquewhite3" , 0xcdc0b0 }, + { "antiquewhite4" , 0x8b8378 }, + { "bisque1" , 0xffe4c4 }, + { "bisque2" , 0xeed5b7 }, + { "bisque3" , 0xcdb79e }, + { "bisque4" , 0x8b7d6b }, + { "peachpuff1" , 0xffdab9 }, + { "peachpuff2" , 0xeecbad }, + { "peachpuff3" , 0xcdaf95 }, + { "peachpuff4" , 0x8b7765 }, + { "navajowhite1" , 0xffdead }, + { "navajowhite2" , 0xeecfa1 }, + { "navajowhite3" , 0xcdb38b }, + { "navajowhite4" , 0x8b795e }, + { "lemonchiffon1" , 0xfffacd }, + { "lemonchiffon2" , 0xeee9bf }, + { "lemonchiffon3" , 0xcdc9a5 }, + { "lemonchiffon4" , 0x8b8970 }, + { "cornsilk1" , 0xfff8dc }, + { "cornsilk2" , 0xeee8cd }, + { "cornsilk3" , 0xcdc8b1 }, + { "cornsilk4" , 0x8b8878 }, + { "ivory1" , 0xfffff0 }, + { "ivory2" , 0xeeeee0 }, + { "ivory3" , 0xcdcdc1 }, + { "ivory4" , 0x8b8b83 }, + { "honeydew1" , 0xf0fff0 }, + { "honeydew2" , 0xe0eee0 }, + { "honeydew3" , 0xc1cdc1 }, + { "honeydew4" , 0x838b83 }, + { "lavenderblush1" , 0xfff0f5 }, + { "lavenderblush2" , 0xeee0e5 }, + { "lavenderblush3" , 0xcdc1c5 }, + { "lavenderblush4" , 0x8b8386 }, + { "mistyrose1" , 0xffe4e1 }, + { "mistyrose2" , 0xeed5d2 }, + { "mistyrose3" , 0xcdb7b5 }, + { "mistyrose4" , 0x8b7d7b }, + { "azure1" , 0xf0ffff }, + { "azure2" , 0xe0eeee }, + { "azure3" , 0xc1cdcd }, + { "azure4" , 0x838b8b }, + { "slateblue1" , 0x836fff }, + { "slateblue2" , 0x7a67ee }, + { "slateblue3" , 0x6959cd }, + { "slateblue4" , 0x473c8b }, + { "royalblue1" , 0x4876ff }, + { "royalblue2" , 0x436eee }, + { "royalblue3" , 0x3a5fcd }, + { "royalblue4" , 0x27408b }, + { "blue1" , 0xff }, + { "blue2" , 0xee }, + { "blue3" , 0xcd }, + { "blue4" , 0x8b }, + { "dodgerblue1" , 0x1e90ff }, + { "dodgerblue2" , 0x1c86ee }, + { "dodgerblue3" , 0x1874cd }, + { "dodgerblue4" , 0x104e8b }, + { "steelblue1" , 0x63b8ff }, + { "steelblue2" , 0x5cacee }, + { "steelblue3" , 0x4f94cd }, + { "steelblue4" , 0x36648b }, + { "deepskyblue1" , 0xbfff }, + { "deepskyblue2" , 0xb2ee }, + { "deepskyblue3" , 0x9acd }, + { "deepskyblue4" , 0x688b }, + { "skyblue1" , 0x87ceff }, + { "skyblue2" , 0x7ec0ee }, + { "skyblue3" , 0x6ca6cd }, + { "skyblue4" , 0x4a708b }, + { "lightskyblue1" , 0xb0e2ff }, + { "lightskyblue2" , 0xa4d3ee }, + { "lightskyblue3" , 0x8db6cd }, + { "lightskyblue4" , 0x607b8b }, + { "slategray1" , 0xc6e2ff }, + { "slategray2" , 0xb9d3ee }, + { "slategray3" , 0x9fb6cd }, + { "slategray4" , 0x6c7b8b }, + { "lightsteelblue1" , 0xcae1ff }, + { "lightsteelblue2" , 0xbcd2ee }, + { "lightsteelblue3" , 0xa2b5cd }, + { "lightsteelblue4" , 0x6e7b8b }, + { "lightblue1" , 0xbfefff }, + { "lightblue2" , 0xb2dfee }, + { "lightblue3" , 0x9ac0cd }, + { "lightblue4" , 0x68838b }, + { "lightcyan1" , 0xe0ffff }, + { "lightcyan2" , 0xd1eeee }, + { "lightcyan3" , 0xb4cdcd }, + { "lightcyan4" , 0x7a8b8b }, + { "paleturquoise1" , 0xbbffff }, + { "paleturquoise2" , 0xaeeeee }, + { "paleturquoise3" , 0x96cdcd }, + { "paleturquoise4" , 0x668b8b }, + { "cadetblue1" , 0x98f5ff }, + { "cadetblue2" , 0x8ee5ee }, + { "cadetblue3" , 0x7ac5cd }, + { "cadetblue4" , 0x53868b }, + { "turquoise1" , 0xf5ff }, + { "turquoise2" , 0xe5ee }, + { "turquoise3" , 0xc5cd }, + { "turquoise4" , 0x868b }, + { "cyan1" , 0xffff }, + { "cyan2" , 0xeeee }, + { "cyan3" , 0xcdcd }, + { "cyan4" , 0x8b8b }, + { "darkslategray1" , 0x97ffff }, + { "darkslategray2" , 0x8deeee }, + { "darkslategray3" , 0x79cdcd }, + { "darkslategray4" , 0x528b8b }, + { "aquamarine1" , 0x7fffd4 }, + { "aquamarine2" , 0x76eec6 }, + { "aquamarine3" , 0x66cdaa }, + { "aquamarine4" , 0x458b74 }, + { "darkseagreen1" , 0xc1ffc1 }, + { "darkseagreen2" , 0xb4eeb4 }, + { "darkseagreen3" , 0x9bcd9b }, + { "darkseagreen4" , 0x698b69 }, + { "seagreen1" , 0x54ff9f }, + { "seagreen2" , 0x4eee94 }, + { "seagreen3" , 0x43cd80 }, + { "seagreen4" , 0x2e8b57 }, + { "palegreen1" , 0x9aff9a }, + { "palegreen2" , 0x90ee90 }, + { "palegreen3" , 0x7ccd7c }, + { "palegreen4" , 0x548b54 }, + { "springgreen1" , 0xff7f }, + { "springgreen2" , 0xee76 }, + { "springgreen3" , 0xcd66 }, + { "springgreen4" , 0x8b45 }, + { "green1" , 0xff00 }, + { "green2" , 0xee00 }, + { "green3" , 0xcd00 }, + { "green4" , 0x8b00 }, + { "chartreuse1" , 0x7fff00 }, + { "chartreuse2" , 0x76ee00 }, + { "chartreuse3" , 0x66cd00 }, + { "chartreuse4" , 0x458b00 }, + { "olivedrab1" , 0xc0ff3e }, + { "olivedrab2" , 0xb3ee3a }, + { "olivedrab3" , 0x9acd32 }, + { "olivedrab4" , 0x698b22 }, + { "darkolivegreen1" , 0xcaff70 }, + { "darkolivegreen2" , 0xbcee68 }, + { "darkolivegreen3" , 0xa2cd5a }, + { "darkolivegreen4" , 0x6e8b3d }, + { "khaki1" , 0xfff68f }, + { "khaki2" , 0xeee685 }, + { "khaki3" , 0xcdc673 }, + { "khaki4" , 0x8b864e }, + { "lightgoldenrod1" , 0xffec8b }, + { "lightgoldenrod2" , 0xeedc82 }, + { "lightgoldenrod3" , 0xcdbe70 }, + { "lightgoldenrod4" , 0x8b814c }, + { "lightyellow1" , 0xffffe0 }, + { "lightyellow2" , 0xeeeed1 }, + { "lightyellow3" , 0xcdcdb4 }, + { "lightyellow4" , 0x8b8b7a }, + { "yellow1" , 0xffff00 }, + { "yellow2" , 0xeeee00 }, + { "yellow3" , 0xcdcd00 }, + { "yellow4" , 0x8b8b00 }, + { "gold1" , 0xffd700 }, + { "gold2" , 0xeec900 }, + { "gold3" , 0xcdad00 }, + { "gold4" , 0x8b7500 }, + { "goldenrod1" , 0xffc125 }, + { "goldenrod2" , 0xeeb422 }, + { "goldenrod3" , 0xcd9b1d }, + { "goldenrod4" , 0x8b6914 }, + { "darkgoldenrod1" , 0xffb90f }, + { "darkgoldenrod2" , 0xeead0e }, + { "darkgoldenrod3" , 0xcd950c }, + { "darkgoldenrod4" , 0x8b6508 }, + { "rosybrown1" , 0xffc1c1 }, + { "rosybrown2" , 0xeeb4b4 }, + { "rosybrown3" , 0xcd9b9b }, + { "rosybrown4" , 0x8b6969 }, + { "indianred1" , 0xff6a6a }, + { "indianred2" , 0xee6363 }, + { "indianred3" , 0xcd5555 }, + { "indianred4" , 0x8b3a3a }, + { "sienna1" , 0xff8247 }, + { "sienna2" , 0xee7942 }, + { "sienna3" , 0xcd6839 }, + { "sienna4" , 0x8b4726 }, + { "burlywood1" , 0xffd39b }, + { "burlywood2" , 0xeec591 }, + { "burlywood3" , 0xcdaa7d }, + { "burlywood4" , 0x8b7355 }, + { "wheat1" , 0xffe7ba }, + { "wheat2" , 0xeed8ae }, + { "wheat3" , 0xcdba96 }, + { "wheat4" , 0x8b7e66 }, + { "tan1" , 0xffa54f }, + { "tan2" , 0xee9a49 }, + { "tan3" , 0xcd853f }, + { "tan4" , 0x8b5a2b }, + { "chocolate1" , 0xff7f24 }, + { "chocolate2" , 0xee7621 }, + { "chocolate3" , 0xcd661d }, + { "chocolate4" , 0x8b4513 }, + { "firebrick1" , 0xff3030 }, + { "firebrick2" , 0xee2c2c }, + { "firebrick3" , 0xcd2626 }, + { "firebrick4" , 0x8b1a1a }, + { "brown1" , 0xff4040 }, + { "brown2" , 0xee3b3b }, + { "brown3" , 0xcd3333 }, + { "brown4" , 0x8b2323 }, + { "salmon1" , 0xff8c69 }, + { "salmon2" , 0xee8262 }, + { "salmon3" , 0xcd7054 }, + { "salmon4" , 0x8b4c39 }, + { "lightsalmon1" , 0xffa07a }, + { "lightsalmon2" , 0xee9572 }, + { "lightsalmon3" , 0xcd8162 }, + { "lightsalmon4" , 0x8b5742 }, + { "orange1" , 0xffa500 }, + { "orange2" , 0xee9a00 }, + { "orange3" , 0xcd8500 }, + { "orange4" , 0x8b5a00 }, + { "darkorange1" , 0xff7f00 }, + { "darkorange2" , 0xee7600 }, + { "darkorange3" , 0xcd6600 }, + { "darkorange4" , 0x8b4500 }, + { "coral1" , 0xff7256 }, + { "coral2" , 0xee6a50 }, + { "coral3" , 0xcd5b45 }, + { "coral4" , 0x8b3e2f }, + { "tomato1" , 0xff6347 }, + { "tomato2" , 0xee5c42 }, + { "tomato3" , 0xcd4f39 }, + { "tomato4" , 0x8b3626 }, + { "orangered1" , 0xff4500 }, + { "orangered2" , 0xee4000 }, + { "orangered3" , 0xcd3700 }, + { "orangered4" , 0x8b2500 }, + { "red1" , 0xff0000 }, + { "red2" , 0xee0000 }, + { "red3" , 0xcd0000 }, + { "red4" , 0x8b0000 }, + { "deeppink1" , 0xff1493 }, + { "deeppink2" , 0xee1289 }, + { "deeppink3" , 0xcd1076 }, + { "deeppink4" , 0x8b0a50 }, + { "hotpink1" , 0xff6eb4 }, + { "hotpink2" , 0xee6aa7 }, + { "hotpink3" , 0xcd6090 }, + { "hotpink4" , 0x8b3a62 }, + { "pink1" , 0xffb5c5 }, + { "pink2" , 0xeea9b8 }, + { "pink3" , 0xcd919e }, + { "pink4" , 0x8b636c }, + { "lightpink1" , 0xffaeb9 }, + { "lightpink2" , 0xeea2ad }, + { "lightpink3" , 0xcd8c95 }, + { "lightpink4" , 0x8b5f65 }, + { "palevioletred1" , 0xff82ab }, + { "palevioletred2" , 0xee799f }, + { "palevioletred3" , 0xcd6889 }, + { "palevioletred4" , 0x8b475d }, + { "maroon1" , 0xff34b3 }, + { "maroon2" , 0xee30a7 }, + { "maroon3" , 0xcd2990 }, + { "maroon4" , 0x8b1c62 }, + { "violetred1" , 0xff3e96 }, + { "violetred2" , 0xee3a8c }, + { "violetred3" , 0xcd3278 }, + { "violetred4" , 0x8b2252 }, + { "magenta1" , 0xff00ff }, + { "magenta2" , 0xee00ee }, + { "magenta3" , 0xcd00cd }, + { "magenta4" , 0x8b008b }, + { "orchid1" , 0xff83fa }, + { "orchid2" , 0xee7ae9 }, + { "orchid3" , 0xcd69c9 }, + { "orchid4" , 0x8b4789 }, + { "plum1" , 0xffbbff }, + { "plum2" , 0xeeaeee }, + { "plum3" , 0xcd96cd }, + { "plum4" , 0x8b668b }, + { "mediumorchid1" , 0xe066ff }, + { "mediumorchid2" , 0xd15fee }, + { "mediumorchid3" , 0xb452cd }, + { "mediumorchid4" , 0x7a378b }, + { "darkorchid1" , 0xbf3eff }, + { "darkorchid2" , 0xb23aee }, + { "darkorchid3" , 0x9a32cd }, + { "darkorchid4" , 0x68228b }, + { "purple1" , 0x9b30ff }, + { "purple2" , 0x912cee }, + { "purple3" , 0x7d26cd }, + { "purple4" , 0x551a8b }, + { "mediumpurple1" , 0xab82ff }, + { "mediumpurple2" , 0x9f79ee }, + { "mediumpurple3" , 0x8968cd }, + { "mediumpurple4" , 0x5d478b }, + { "thistle1" , 0xffe1ff }, + { "thistle2" , 0xeed2ee }, + { "thistle3" , 0xcdb5cd }, + { "thistle4" , 0x8b7b8b }, + { "gray0" , 0x0 }, + { "grey0" , 0x0 }, + { "gray1" , 0x30303 }, + { "grey1" , 0x30303 }, + { "gray2" , 0x50505 }, + { "grey2" , 0x50505 }, + { "gray3" , 0x80808 }, + { "grey3" , 0x80808 }, + { "gray4" , 0xa0a0a }, + { "grey4" , 0xa0a0a }, + { "gray5" , 0xd0d0d }, + { "grey5" , 0xd0d0d }, + { "gray6" , 0xf0f0f }, + { "grey6" , 0xf0f0f }, + { "gray7" , 0x121212 }, + { "grey7" , 0x121212 }, + { "gray8" , 0x141414 }, + { "grey8" , 0x141414 }, + { "gray9" , 0x171717 }, + { "grey9" , 0x171717 }, + { "gray10" , 0x1a1a1a }, + { "grey10" , 0x1a1a1a }, + { "gray11" , 0x1c1c1c }, + { "grey11" , 0x1c1c1c }, + { "gray12" , 0x1f1f1f }, + { "grey12" , 0x1f1f1f }, + { "gray13" , 0x212121 }, + { "grey13" , 0x212121 }, + { "gray14" , 0x242424 }, + { "grey14" , 0x242424 }, + { "gray15" , 0x262626 }, + { "grey15" , 0x262626 }, + { "gray16" , 0x292929 }, + { "grey16" , 0x292929 }, + { "gray17" , 0x2b2b2b }, + { "grey17" , 0x2b2b2b }, + { "gray18" , 0x2e2e2e }, + { "grey18" , 0x2e2e2e }, + { "gray19" , 0x303030 }, + { "grey19" , 0x303030 }, + { "gray20" , 0x333333 }, + { "grey20" , 0x333333 }, + { "gray21" , 0x363636 }, + { "grey21" , 0x363636 }, + { "gray22" , 0x383838 }, + { "grey22" , 0x383838 }, + { "gray23" , 0x3b3b3b }, + { "grey23" , 0x3b3b3b }, + { "gray24" , 0x3d3d3d }, + { "grey24" , 0x3d3d3d }, + { "gray25" , 0x404040 }, + { "grey25" , 0x404040 }, + { "gray26" , 0x424242 }, + { "grey26" , 0x424242 }, + { "gray27" , 0x454545 }, + { "grey27" , 0x454545 }, + { "gray28" , 0x474747 }, + { "grey28" , 0x474747 }, + { "gray29" , 0x4a4a4a }, + { "grey29" , 0x4a4a4a }, + { "gray30" , 0x4d4d4d }, + { "grey30" , 0x4d4d4d }, + { "gray31" , 0x4f4f4f }, + { "grey31" , 0x4f4f4f }, + { "gray32" , 0x525252 }, + { "grey32" , 0x525252 }, + { "gray33" , 0x545454 }, + { "grey33" , 0x545454 }, + { "gray34" , 0x575757 }, + { "grey34" , 0x575757 }, + { "gray35" , 0x595959 }, + { "grey35" , 0x595959 }, + { "gray36" , 0x5c5c5c }, + { "grey36" , 0x5c5c5c }, + { "gray37" , 0x5e5e5e }, + { "grey37" , 0x5e5e5e }, + { "gray38" , 0x616161 }, + { "grey38" , 0x616161 }, + { "gray39" , 0x636363 }, + { "grey39" , 0x636363 }, + { "gray40" , 0x666666 }, + { "grey40" , 0x666666 }, + { "gray41" , 0x696969 }, + { "grey41" , 0x696969 }, + { "gray42" , 0x6b6b6b }, + { "grey42" , 0x6b6b6b }, + { "gray43" , 0x6e6e6e }, + { "grey43" , 0x6e6e6e }, + { "gray44" , 0x707070 }, + { "grey44" , 0x707070 }, + { "gray45" , 0x737373 }, + { "grey45" , 0x737373 }, + { "gray46" , 0x757575 }, + { "grey46" , 0x757575 }, + { "gray47" , 0x787878 }, + { "grey47" , 0x787878 }, + { "gray48" , 0x7a7a7a }, + { "grey48" , 0x7a7a7a }, + { "gray49" , 0x7d7d7d }, + { "grey49" , 0x7d7d7d }, + { "gray50" , 0x7f7f7f }, + { "grey50" , 0x7f7f7f }, + { "gray51" , 0x828282 }, + { "grey51" , 0x828282 }, + { "gray52" , 0x858585 }, + { "grey52" , 0x858585 }, + { "gray53" , 0x878787 }, + { "grey53" , 0x878787 }, + { "gray54" , 0x8a8a8a }, + { "grey54" , 0x8a8a8a }, + { "gray55" , 0x8c8c8c }, + { "grey55" , 0x8c8c8c }, + { "gray56" , 0x8f8f8f }, + { "grey56" , 0x8f8f8f }, + { "gray57" , 0x919191 }, + { "grey57" , 0x919191 }, + { "gray58" , 0x949494 }, + { "grey58" , 0x949494 }, + { "gray59" , 0x969696 }, + { "grey59" , 0x969696 }, + { "gray60" , 0x999999 }, + { "grey60" , 0x999999 }, + { "gray61" , 0x9c9c9c }, + { "grey61" , 0x9c9c9c }, + { "gray62" , 0x9e9e9e }, + { "grey62" , 0x9e9e9e }, + { "gray63" , 0xa1a1a1 }, + { "grey63" , 0xa1a1a1 }, + { "gray64" , 0xa3a3a3 }, + { "grey64" , 0xa3a3a3 }, + { "gray65" , 0xa6a6a6 }, + { "grey65" , 0xa6a6a6 }, + { "gray66" , 0xa8a8a8 }, + { "grey66" , 0xa8a8a8 }, + { "gray67" , 0xababab }, + { "grey67" , 0xababab }, + { "gray68" , 0xadadad }, + { "grey68" , 0xadadad }, + { "gray69" , 0xb0b0b0 }, + { "grey69" , 0xb0b0b0 }, + { "gray70" , 0xb3b3b3 }, + { "grey70" , 0xb3b3b3 }, + { "gray71" , 0xb5b5b5 }, + { "grey71" , 0xb5b5b5 }, + { "gray72" , 0xb8b8b8 }, + { "grey72" , 0xb8b8b8 }, + { "gray73" , 0xbababa }, + { "grey73" , 0xbababa }, + { "gray74" , 0xbdbdbd }, + { "grey74" , 0xbdbdbd }, + { "gray75" , 0xbfbfbf }, + { "grey75" , 0xbfbfbf }, + { "gray76" , 0xc2c2c2 }, + { "grey76" , 0xc2c2c2 }, + { "gray77" , 0xc4c4c4 }, + { "grey77" , 0xc4c4c4 }, + { "gray78" , 0xc7c7c7 }, + { "grey78" , 0xc7c7c7 }, + { "gray79" , 0xc9c9c9 }, + { "grey79" , 0xc9c9c9 }, + { "gray80" , 0xcccccc }, + { "grey80" , 0xcccccc }, + { "gray81" , 0xcfcfcf }, + { "grey81" , 0xcfcfcf }, + { "gray82" , 0xd1d1d1 }, + { "grey82" , 0xd1d1d1 }, + { "gray83" , 0xd4d4d4 }, + { "grey83" , 0xd4d4d4 }, + { "gray84" , 0xd6d6d6 }, + { "grey84" , 0xd6d6d6 }, + { "gray85" , 0xd9d9d9 }, + { "grey85" , 0xd9d9d9 }, + { "gray86" , 0xdbdbdb }, + { "grey86" , 0xdbdbdb }, + { "gray87" , 0xdedede }, + { "grey87" , 0xdedede }, + { "gray88" , 0xe0e0e0 }, + { "grey88" , 0xe0e0e0 }, + { "gray89" , 0xe3e3e3 }, + { "grey89" , 0xe3e3e3 }, + { "gray90" , 0xe5e5e5 }, + { "grey90" , 0xe5e5e5 }, + { "gray91" , 0xe8e8e8 }, + { "grey91" , 0xe8e8e8 }, + { "gray92" , 0xebebeb }, + { "grey92" , 0xebebeb }, + { "gray93" , 0xededed }, + { "grey93" , 0xededed }, + { "gray94" , 0xf0f0f0 }, + { "grey94" , 0xf0f0f0 }, + { "gray95" , 0xf2f2f2 }, + { "grey95" , 0xf2f2f2 }, + { "gray96" , 0xf5f5f5 }, + { "grey96" , 0xf5f5f5 }, + { "gray97" , 0xf7f7f7 }, + { "grey97" , 0xf7f7f7 }, + { "gray98" , 0xfafafa }, + { "grey98" , 0xfafafa }, + { "gray99" , 0xfcfcfc }, + { "grey99" , 0xfcfcfc }, + { "gray100" , 0xffffff }, + { "grey100" , 0xffffff }, + { "dark grey" , 0xa9a9a9 }, + { "darkgrey" , 0xa9a9a9 }, + { "dark gray" , 0xa9a9a9 }, + { "darkgray" , 0xa9a9a9 }, + { "dark blue" , 0x8b }, + { "darkblue" , 0x8b }, + { "dark cyan" , 0x8b8b }, + { "darkcyan" , 0x8b8b }, + { "dark magenta" , 0x8b008b }, + { "darkmagenta" , 0x8b008b }, + { "dark red" , 0x8b0000 }, + { "darkred" , 0x8b0000 }, + { "light green" , 0x90ee90 }, + { "lightgreen" , 0x90ee90 }, + { "none", -1 }, + { 0, 0 } +}; diff --git a/Minilibx/mlx_screen_size.c b/Minilibx/mlx_screen_size.c new file mode 100644 index 0000000..835730d --- /dev/null +++ b/Minilibx/mlx_screen_size.c @@ -0,0 +1,13 @@ +#include "mlx_int.h" + +int mlx_get_screen_size(void *mlx_ptr, int *sizex, int *sizey) +{ + XWindowAttributes xwAttr; + Status ret; + t_xvar *xvar; + + xvar = mlx_ptr; + ret = XGetWindowAttributes(xvar->display, xvar->root, &xwAttr); + (*sizex) = xwAttr.width; + (*sizey) = xwAttr.height; +} diff --git a/Minilibx/mlx_set_font.c b/Minilibx/mlx_set_font.c new file mode 100644 index 0000000..111e3b8 --- /dev/null +++ b/Minilibx/mlx_set_font.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* mlx_set_font.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: amalliar +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/09/30 13:30:47 by amalliar #+# #+# */ +/* Updated: 2020/09/30 17:08:36 by amalliar ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "mlx_int.h" + +/* +** Allows to specify the font that will be used by mlx_string_put. +** +** Note: only fixed-width bitmap fonts are supported by Xlib, refer to xfontsel +** utility to get valid font names for this function. +*/ + +void mlx_set_font(t_xvar *xvar, t_win_list *win, char *name) +{ + static Font font = 0; + + if (font) + XUnloadFont(xvar->display, font); + font = XLoadFont(xvar->display, name); + XSetFont(xvar->display, win->gc, font); +} diff --git a/Minilibx/mlx_string_put.c b/Minilibx/mlx_string_put.c new file mode 100644 index 0000000..8492a09 --- /dev/null +++ b/Minilibx/mlx_string_put.c @@ -0,0 +1,26 @@ +/* + ** mlx_string_put.c for MiniLibX in + ** + ** Made by Charlie Root + ** Login + ** + ** Started on Mon Jul 31 19:01:33 2000 Charlie Root +** Last update Tue Sep 25 17:11:47 2001 Charlie Root + */ + + +#include "mlx_int.h" + + + +int mlx_string_put(t_xvar *xvar,t_win_list *win, + int x,int y,int color,char *string) +{ + XGCValues xgcv; + + xgcv.foreground = mlx_int_get_good_color(xvar,color); + XChangeGC(xvar->display,win->gc,GCForeground,&xgcv); + XDrawString(xvar->display,win->window,win->gc,x,y,string,strlen(string)); + if (xvar->do_flush) + XFlush(xvar->display); +} diff --git a/Minilibx/mlx_xpm.c b/Minilibx/mlx_xpm.c new file mode 100644 index 0000000..688cc94 --- /dev/null +++ b/Minilibx/mlx_xpm.c @@ -0,0 +1,345 @@ +/* + ** xpm-read.c for MinilibX in + ** + ** Made by Charlie Root + ** Login + ** + ** Started on Tue Dec 11 15:25:27 2001 olivier crouzet + ** Last update Sat Oct 1 14:56:13 2005 Olivier Crouzet + */ + + +#include "mlx_int.h" + +extern struct s_col_name mlx_col_name[]; + + +#define RETURN { if (colors) free(colors); if (tab) free(tab); \ + tab = (void *)0; if (colors_direct) free(colors_direct); \ + if (img) {XDestroyImage(img->image); \ + XFreePixmap(xvar->display,img->pix);free(img);} \ + return ((void *)0);} + + + + +char *mlx_int_get_line(char *ptr,int *pos,int size) +{ + int pos2; + int pos3; + int pos4; + + if ((pos2 = mlx_int_str_str(ptr+*pos,"\"",size-*pos))==-1) + return ((char *)0); + if ((pos3 = mlx_int_str_str(ptr+*pos+pos2+1,"\"",size-*pos-pos2-1))==-1) + return ((char *)0); + *(ptr+*pos+pos2) = 0; + *(ptr+*pos+pos2+1+pos3) = 0; + pos4 = *pos+pos2+1; + *pos += pos2+pos3+2; + return (ptr+pos4); +} + + +unsigned int strlcpy_is_not_posix(char *dest, char *src, unsigned int size) +{ + unsigned count; + unsigned i; + + count = 0; + while (src[count] != '\0') + ++count; + i = 0; + while (src[i] != '\0' && i < (size - 1)) + { + dest[i] = src[i]; + ++i; + } + dest[i] = '\0'; + return (count); +} + +char *mlx_int_static_line(char **xpm_data,int *pos,int size) +{ + static char *copy = 0; + static int len = 0; + int len2; + char *str; + + str = xpm_data[(*pos)++]; + if ((len2 = strlen(str))>len) + { + if (copy) + free(copy); + if (!(copy = malloc(len2+1))) + return ((char *)0); + len = len2; + } + strlcpy_is_not_posix(copy, str, len2); + + return (copy); +} + + +int mlx_int_get_col_name(char *str,int size) +{ + int result; + + result = 0; + while (size--) + result = (result<<8)+*(str++); + + return (result); +} + +int mlx_int_get_text_rgb(char *name, char *end) +{ + int i; + char buff[64]; + + if (*name == '#') + return (strtol(name+1,0,16)); + if (end) + { + snprintf(buff, 64, "%s %s", name, end); + name = buff; + } + i = 0; + while (mlx_col_name[i].name) + { + if (!strcasecmp(mlx_col_name[i].name, name)) + return (mlx_col_name[i].color); + i ++; + } + return (0); +} + + +int mlx_int_xpm_set_pixel(t_img *img, char *data, int opp, int col, int x) +{ + int dec; + + dec = opp; + while (dec--) + { + if (img->image->byte_order) + *(data+x*opp+dec) = col&0xFF; + else + *(data+x*opp+opp-dec-1) = col&0xFF; + col >>= 8; + } +} + + +void *mlx_int_parse_xpm(t_xvar *xvar,void *info,int info_size,char *(*f)()) +{ + int pos; + char *line; + char **tab; + char *data; + char *clip_data; + int nc; + int opp; + int cpp; + int col; + int rgb_col; + int col_name; + int method; + int x; + int i; + int j; + t_img *img; + t_xpm_col *colors; + int *colors_direct; + int width; + int height; + XImage *clip_img; + XGCValues xgcv; + Pixmap clip_pix; + + colors = 0; + colors_direct = 0; + img = 0; + tab = 0; + pos = 0; + if (!(line = f(info,&pos,info_size)) || + !(tab = mlx_int_str_to_wordtab(line)) || !(width = atoi(tab[0])) || + !(height = atoi(tab[1])) || !(nc = atoi(tab[2])) || + !(cpp = atoi(tab[3])) ) + RETURN; + free(tab); + tab = 0; + + method = 0; + if (cpp<=2) + { + method = 1; + if (!(colors_direct = malloc((cpp==2?65536:256)*sizeof(int)))) + RETURN; + } + else + if (!(colors = malloc(nc*sizeof(*colors)))) + RETURN; + + clip_data = 0; + + i = nc; + while (i--) + { + if (!(line = f(info,&pos,info_size)) || + !(tab = mlx_int_str_to_wordtab(line+cpp)) ) + RETURN; + j = 0; + while (tab[j] && strcmp(tab[j++],"c")); + + if (!tab[j]) + RETURN; + rgb_col = mlx_int_get_text_rgb(tab[j], tab[j+1]); + /* + if ((rgb_col = mlx_int_get_text_rgb(tab[j], tab[j+1]))==-1) + { + if (!(clip_data = malloc(4*width*height)) || ok, nice size .. + !(clip_img = XCreateImage(xvar->display, xvar->visual, + 1, XYPixmap, 0, clip_data, + width, height, 8, (width+7)/8)) ) + RETURN; + memset(clip_data, 0xFF, 4*width*height); + } + */ + if (method) + colors_direct[mlx_int_get_col_name(line,cpp)] = rgb_col; + // rgb_col>=0?mlx_get_color_value(xvar, rgb_col):rgb_col; + else + { + colors[i].name = mlx_int_get_col_name(line,cpp); + colors[i].col = rgb_col; //rgb_col>=0?mlx_get_color_value(xvar,rgb_col):rgb_col; + } + free(tab); + tab = (void *)0; + } + + if (!(img = mlx_new_image(xvar,width,height))) + RETURN; + opp = img->bpp/8; + + + i = height; + data = img->data; + while (i--) + { + if (!(line = f(info,&pos,info_size))) + RETURN; + x = 0; + while (xsize_line; + } + /* + if (clip_data) + { + if (!(clip_pix = XCreatePixmap(xvar->display, xvar->root, + width, height, 1)) ) + RETURN; + img->gc = XCreateGC(xvar->display, clip_pix, 0, &xgcv); + XPutImage(xvar->display, clip_pix, img->gc, clip_img, + 0, 0, 0, 0, width, height); + XFreeGC(xvar->display, img->gc); + xgcv.clip_mask = clip_pix; + xgcv.function = GXcopy; + xgcv.plane_mask = AllPlanes; + img->gc = XCreateGC(xvar->display, xvar->root, GCClipMask|GCFunction| + GCPlaneMask, &xgcv); + XSync(xvar->display, False); + XDestroyImage(clip_img); + } + */ + if (colors) + free(colors); + if (colors_direct) + free(colors_direct); + return (img); +} + + +int mlx_int_file_get_rid_comment(char *ptr, int size) +{ + int com_begin; + int com_end; + + while ((com_begin = mlx_int_str_str_cote(ptr,"/*",size))!=-1) + { + com_end = mlx_int_str_str(ptr+com_begin+2,"*/",size-com_begin-2); + memset(ptr+com_begin,' ',com_end+4); + } + while ((com_begin = mlx_int_str_str_cote(ptr,"//",size))!=-1) + { + com_end = mlx_int_str_str(ptr+com_begin+2,"\n",size-com_begin-2); + memset(ptr+com_begin,' ',com_end+3); + } +} + + +void *mlx_xpm_file_to_image(t_xvar *xvar,char *file,int *width,int *height) +{ + int fd; + int size; + char *ptr; + t_img *img; + + fd = -1; + if ((fd = open(file,O_RDONLY))==-1 || (size = lseek(fd,0,SEEK_END))==-1 || + (ptr = mmap(0,size,PROT_WRITE|PROT_READ,MAP_PRIVATE,fd,0))== + (void *)MAP_FAILED) + { + if (fd>=0) + close(fd); + return ((void *)0); + } + mlx_int_file_get_rid_comment(ptr, size); + if (img = mlx_int_parse_xpm(xvar,ptr,size,mlx_int_get_line)) + { + *width = img->width; + *height = img->height; + } + munmap(ptr,size); + close(fd); + return (img); +} + +void *mlx_xpm_to_image(t_xvar *xvar,char **xpm_data,int *width,int *height) +{ + t_img *img; + + if (img = mlx_int_parse_xpm(xvar,xpm_data,0,mlx_int_static_line)) + { + *width = img->width; + *height = img->height; + } + return (img); +} diff --git a/Minilibx/mlx_xpm.c.ok b/Minilibx/mlx_xpm.c.ok new file mode 100644 index 0000000..225ea3c --- /dev/null +++ b/Minilibx/mlx_xpm.c.ok @@ -0,0 +1,310 @@ +/* +** xpm-read.c for MinilibX in +** +** Made by Charlie Root +** Login +** +** Started on Tue Dec 11 15:25:27 2001 olivier crouzet +** Last update Sat Oct 1 14:40:55 2005 Olivier Crouzet +*/ + + +#include "mlx_int.h" + +extern struct s_col_name mlx_col_name[]; + + +#define RETURN { if (colors) free(colors); if (tab) free(tab); \ + if (colors_direct) free(colors_direct); \ + if (img) {XDestroyImage(img->image); \ + XFreePixmap(xvar->display,img->pix);free(img);} \ + return ((void *)0);} + + + + +char *mlx_int_get_line(char *ptr,int *pos,int size) +{ + int pos2; + int pos3; + int pos4; + + if ((pos2 = mlx_int_str_str(ptr+*pos,"\"",size-*pos))==-1) + return ((char *)0); + if ((pos3 = mlx_int_str_str(ptr+*pos+pos2+1,"\"",size-*pos-pos2-1))==-1) + return ((char *)0); + *(ptr+*pos+pos2) = 0; + *(ptr+*pos+pos2+1+pos3) = 0; + pos4 = *pos+pos2+1; + *pos += pos2+pos3+2; + return (ptr+pos4); +} + + + +char *mlx_int_static_line(char **xpm_data,int *pos,int size) +{ + static char *copy = 0; + static int len = 0; + int len2; + char *str; + + str = xpm_data[(*pos)++]; + if ((len2 = strlen(str))>len) + { + if (copy) + free(copy); + if (!(copy = malloc(len2+1))) + return ((char *)0); + len = len2; + } + /* strcpy(copy,str); */ + strlcpy(copy, str, len2+1); + return (copy); +} + + +int mlx_int_get_col_name(char *str,int size) +{ + int result; + + result = 0; + while (size--) + result = (result<<8)+*(str++); + return (result); +} + +int mlx_int_get_text_rgb(char *name) +{ + int i; + + if (*name == '#') + return (strtol(name+1,0,16)); + i = 0; + while (mlx_col_name[i].name) + { + if (!strcasecmp(mlx_col_name[i].name, name)) + return (mlx_col_name[i].color); + i ++; + } + return (0); +} + + +int mlx_int_xpm_set_pixel(t_img *img, char *data, int opp, int col, int x) +{ + int dec; + + dec = opp; + while (dec--) + { + if (img->image->byte_order) + *(data+x*opp+dec) = col&0xFF; + else + *(data+x*opp+opp-dec-1) = col&0xFF; + col >>= 8; + } +} + + +void *mlx_int_parse_xpm(t_xvar *xvar,void *info,int info_size,char *(*f)()) +{ + int pos; + char *line; + char **tab; + char *data; + char *clip_data; + int nc; + int opp; + int cpp; + int col; + int rgb_col; + int col_name; + int method; + int x; + int i; + int j; + t_img *img; + t_xpm_col *colors; + int *colors_direct; + int width; + int height; + XImage *clip_img; + XGCValues xgcv; + Pixmap clip_pix; + + colors = 0; + colors_direct = 0; + img = 0; + tab = 0; + pos = 0; + if (!(line = f(info,&pos,info_size)) || + !(tab = mlx_int_str_to_wordtab(line)) || !(width = atoi(tab[0])) || + !(height = atoi(tab[1])) || !(nc = atoi(tab[2])) || + !(cpp = atoi(tab[3])) ) + RETURN; + free(tab); + tab = 0; + + method = 0; + if (cpp<=2) + { + method = 1; + if (!(colors_direct = malloc((cpp==2?65536:256)*sizeof(int)))) + RETURN; + } + else + if (!(colors = malloc(nc*sizeof(*colors)))) + RETURN; + + clip_data = 0; + + i = nc; + while (i--) + { + if (!(line = f(info,&pos,info_size)) || + !(tab = mlx_int_str_to_wordtab(line+cpp)) ) + RETURN; + j = 0; + while (tab[j] && strcmp(tab[j++],"c")); + if (!tab[j]) + RETURN; + + if ((rgb_col = mlx_int_get_text_rgb(tab[j]))==-1) + { + if (!(clip_data = malloc(4*width*height)) || /* ok, nice size .. */ + !(clip_img = XCreateImage(xvar->display, xvar->visual, + 1, XYPixmap, 0, clip_data, + width, height, 8, (width+7)/8)) ) + RETURN; + memset(clip_data, 0xFF, 4*width*height); + } + + if (method) + colors_direct[mlx_int_get_col_name(line,cpp)] = + rgb_col>=0?mlx_get_color_value(xvar, rgb_col):rgb_col; + else + { + colors[i].name = mlx_int_get_col_name(line,cpp); + colors[i].col = rgb_col>=0?mlx_get_color_value(xvar,rgb_col):rgb_col; + } + free(tab); + } + + if (!(img = mlx_new_image(xvar,width,height))) + RETURN; + opp = img->bpp/8; + + + i = height; + data = img->data; + while (i--) + { + if (!(line = f(info,&pos,info_size))) + RETURN; + x = 0; + while (xsize_line; + } + if (clip_data) + { + if (!(clip_pix = XCreatePixmap(xvar->display, xvar->root, + width, height, 1)) ) + RETURN; + img->gc = XCreateGC(xvar->display, clip_pix, 0, &xgcv); + XPutImage(xvar->display, clip_pix, img->gc, clip_img, + 0, 0, 0, 0, width, height); + XFreeGC(xvar->display, img->gc); + xgcv.clip_mask = clip_pix; + xgcv.function = GXcopy; + xgcv.plane_mask = AllPlanes; + img->gc = XCreateGC(xvar->display, xvar->root, GCClipMask|GCFunction| + GCPlaneMask, &xgcv); + XSync(xvar->display, False); + XDestroyImage(clip_img); + } + if (colors) + free(colors); + if (colors_direct) + free(colors_direct); + return (img); +} + + +int mlx_int_file_get_rid_comment(char *ptr, int size) +{ + int com_begin; + int com_end; + + while ((com_begin = mlx_int_str_str_cote(ptr,"/*",size))!=-1) + { + com_end = mlx_int_str_str(ptr+com_begin+2,"*/",size-com_begin-2); + memset(ptr+com_begin,' ',com_end+4); + } + while ((com_begin = mlx_int_str_str_cote(ptr,"//",size))!=-1) + { + com_end = mlx_int_str_str(ptr+com_begin+2,"\n",size-com_begin-2); + memset(ptr+com_begin,' ',com_end+3); + } +} + + +void *mlx_xpm_file_to_image(t_xvar *xvar,char *file,int *width,int *height) +{ + int fd; + int size; + char *ptr; + t_img *img; + + fd = -1; + if ((fd = open(file,O_RDONLY))==-1 || (size = lseek(fd,0,SEEK_END))==-1 || + (ptr = mmap(0,size,PROT_WRITE|PROT_READ,MAP_PRIVATE,fd,0))== + (void *)MAP_FAILED) + { + if (fd>=0) + close(fd); + return ((void *)0); + } + mlx_int_file_get_rid_comment(ptr, size); + if (img = mlx_int_parse_xpm(xvar,ptr,size,mlx_int_get_line)) + { + *width = img->width; + *height = img->height; + } + munmap(ptr,size); + close(fd); + return (img); +} + +void *mlx_xpm_to_image(t_xvar *xvar,char **xpm_data,int *width,int *height) +{ + t_img *img; + + if (img = mlx_int_parse_xpm(xvar,xpm_data,0,mlx_int_static_line)) + { + *width = img->width; + *height = img->height; + } + return (img); +} diff --git a/Minilibx/rgb2c.pl b/Minilibx/rgb2c.pl new file mode 100755 index 0000000..9ef39a0 --- /dev/null +++ b/Minilibx/rgb2c.pl @@ -0,0 +1,38 @@ +#!/usr/bin/perl +# +## rgb2c.pl for MiniLibX in /home/boulon/work/c/raytraceur/minilibx +## +## Made by Olivier Crouzet +## Login +## +## Started on Tue Oct 5 16:33:46 2004 Olivier Crouzet +## Last update Tue Oct 5 16:36:11 2004 Olivier Crouzet +## + + +# +# Generate a .c file with encoded colors, from the XFree86 rgb.txt file. +# + +open(RGB, "/usr/X11/lib/X11/rgb.txt"); + + +printf("/*\n** This is a generated file with rgb2c.pl and rgb.txt from\n"); +printf("** the XFree86 distribution.\n*/\n\n"); +printf("struct s_col_name mlx_col_name[] =\n{\n"); + +while () +{ + @tab = split; + if ($tab[0] ne "!") + { + $color = $tab[3]; + if ("$tab[4]" ne "") + { + $color = "$tab[3] $tab[4]"; + } + printf(" { \"%s\" , 0x%x },\n", $color, $tab[0]*65536+$tab[1]*256+$tab[2]); + } +} + +printf(" { 0, 0 }\n};\n"); diff --git a/Minilibx/source b/Minilibx/source new file mode 100644 index 0000000..311d44c --- /dev/null +++ b/Minilibx/source @@ -0,0 +1,151 @@ +/* Definitions for BSD-style memory management. + Copyright (C) 1994-2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _SYS_MMAN_H +#define _SYS_MMAN_H 1 + +#include +#include +#define __need_size_t +#include + +#ifndef __off_t_defined +# ifndef __USE_FILE_OFFSET64 +typedef __off_t off_t; +# else +typedef __off64_t off_t; +# endif +# define __off_t_defined +#endif + +#ifndef __mode_t_defined +typedef __mode_t mode_t; +# define __mode_t_defined +#endif + +#include + +/* Return value of `mmap' in case of an error. */ +#define MAP_FAILED ((void *) -1) + +__BEGIN_DECLS +/* Map addresses starting near ADDR and extending for LEN bytes. from + OFFSET into the file FD describes according to PROT and FLAGS. If ADDR + is nonzero, it is the desired mapping address. If the MAP_FIXED bit is + set in FLAGS, the mapping will be at ADDR exactly (which must be + page-aligned); otherwise the system chooses a convenient nearby address. + The return value is the actual mapping address chosen or MAP_FAILED + for errors (in which case `errno' is set). A successful `mmap' call + deallocates any previous mapping for the affected region. */ + +#ifndef __USE_FILE_OFFSET64 +extern void *mmap (void *__addr, size_t __len, int __prot, + int __flags, int __fd, __off_t __offset) __THROW; +#else +# ifdef __REDIRECT_NTH +extern void * __REDIRECT_NTH (mmap, + (void *__addr, size_t __len, int __prot, + int __flags, int __fd, __off64_t __offset), + mmap64); +# else +# define mmap mmap64 +# endif +#endif +#ifdef __USE_LARGEFILE64 +extern void *mmap64 (void *__addr, size_t __len, int __prot, + int __flags, int __fd, __off64_t __offset) __THROW; +#endif + +/* Deallocate any mapping for the region starting at ADDR and extending LEN + bytes. Returns 0 if successful, -1 for errors (and sets errno). */ +extern int munmap (void *__addr, size_t __len) __THROW; + +/* Change the memory protection of the region starting at ADDR and + extending LEN bytes to PROT. Returns 0 if successful, -1 for errors + (and sets errno). */ +extern int mprotect (void *__addr, size_t __len, int __prot) __THROW; + +/* Synchronize the region starting at ADDR and extending LEN bytes with the + file it maps. Filesystem operations on a file being mapped are + unpredictable before this is done. Flags are from the MS_* set. + + This function is a cancellation point and therefore not marked with + __THROW. */ +extern int msync (void *__addr, size_t __len, int __flags); + +#ifdef __USE_MISC +/* Advise the system about particular usage patterns the program follows + for the region starting at ADDR and extending LEN bytes. */ +extern int madvise (void *__addr, size_t __len, int __advice) __THROW; +#endif +#ifdef __USE_XOPEN2K +/* This is the POSIX name for this function. */ +extern int posix_madvise (void *__addr, size_t __len, int __advice) __THROW; +#endif + +/* Guarantee all whole pages mapped by the range [ADDR,ADDR+LEN) to + be memory resident. */ +extern int mlock (const void *__addr, size_t __len) __THROW; + +/* Unlock whole pages previously mapped by the range [ADDR,ADDR+LEN). */ +extern int munlock (const void *__addr, size_t __len) __THROW; + +/* Cause all currently mapped pages of the process to be memory resident + until unlocked by a call to the `munlockall', until the process exits, + or until the process calls `execve'. */ +extern int mlockall (int __flags) __THROW; + +/* All currently mapped pages of the process' address space become + unlocked. */ +extern int munlockall (void) __THROW; + +#ifdef __USE_MISC +/* mincore returns the memory residency status of the pages in the + current process's address space specified by [start, start + len). + The status is returned in a vector of bytes. The least significant + bit of each byte is 1 if the referenced page is in memory, otherwise + it is zero. */ +extern int mincore (void *__start, size_t __len, unsigned char *__vec) + __THROW; +#endif + +#ifdef __USE_GNU +/* Remap pages mapped by the range [ADDR,ADDR+OLD_LEN) to new length + NEW_LEN. If MREMAP_MAYMOVE is set in FLAGS the returned address + may differ from ADDR. If MREMAP_FIXED is set in FLAGS the function + takes another parameter which is a fixed address at which the block + resides after a successful call. */ +extern void *mremap (void *__addr, size_t __old_len, size_t __new_len, + int __flags, ...) __THROW; + +/* Remap arbitrary pages of a shared backing store within an existing + VMA. */ +extern int remap_file_pages (void *__start, size_t __size, int __prot, + size_t __pgoff, int __flags) __THROW; +#endif + + +/* Open shared memory segment. */ +extern int shm_open (const char *__name, int __oflag, mode_t __mode); + +/* Remove shared memory segment. */ +extern int shm_unlink (const char *__name); + +__END_DECLS + +#endif /* sys/mman.h */ diff --git a/Minilibx/test/Makefile.mk b/Minilibx/test/Makefile.mk new file mode 100644 index 0000000..256235b --- /dev/null +++ b/Minilibx/test/Makefile.mk @@ -0,0 +1,45 @@ + +INC=%%%% + +INCLIB=$(INC)/../lib + +UNAME := $(shell uname) + +CFLAGS= -I$(INC) -O3 -I.. -g + +NAME= mlx-test +SRC = main.c +OBJ = $(SRC:%.c=%.o) + +LFLAGS = -L.. -lmlx -L$(INCLIB) -lXext -lX11 -lm + +ifeq ($(UNAME), Darwin) + # mac + CC = clang +else ifeq ($(UNAME), FreeBSD) + # FreeBSD + CC = clang +else + #Linux and others... + CC = gcc + LFLAGS += -lbsd +endif + +all: $(NAME) + +$(NAME): $(OBJ) + $(CC) -o $(NAME) $(OBJ) $(LFLAGS) + +show: + @printf "UNAME : $(UNAME)\n" + @printf "NAME : $(NAME)\n" + @printf "CC : $(CC)\n" + @printf "CFLAGS : $(CFLAGS)\n" + @printf "LFLAGS : $(LFLAGS)\n" + @printf "SRC :\n $(SRC)\n" + @printf "OBJ :\n $(OBJ)\n" + +clean: + rm -f $(NAME) $(OBJ) *~ core *.core + +re: clean all diff --git a/Minilibx/test/main.c b/Minilibx/test/main.c new file mode 100644 index 0000000..578eaae --- /dev/null +++ b/Minilibx/test/main.c @@ -0,0 +1,287 @@ + +#include "mlx.h" +#include "mlx_int.h" + +#define WIN1_SX 242 +#define WIN1_SY 242 +#define IM1_SX 42 +#define IM1_SY 42 +#define IM3_SX 242 +#define IM3_SY 242 + +void *mlx; +void *win1; +void *win2; +void *win3; +void *im1; +void *im2; +void *im3; +void *im4; +int bpp1; +int bpp2; +int bpp3; +int bpp4; +int sl1; +int sl2; +int sl3; +int sl4; +int endian1; +int endian2; +int endian3; +int endian4; +char *data1; +char *data2; +char *data3; +char *data4; +int xpm1_x; +int xpm1_y; + +int local_endian; + +int color_map_1(void *win,int w,int h); +int color_map_2(unsigned char *data,int bpp,int sl,int w,int h,int endian, int type); + +int expose_win1(void *p) +{ + mlx_put_image_to_window(mlx,win1,im3,0,0); +} + +int expose_win2(void *p) +{ + mlx_put_image_to_window(mlx,win2,im4,0,0); + mlx_put_image_to_window(mlx,win2,im2,0,0); +} + +int key_win1(int key,void *p) +{ + printf("Key in Win1 : %d\n",key); + if (key==0xFF1B) + exit(0); +} + +int key_win2(int key,void *p) +{ + printf("Key in Win2 : %d\n",key); + if (key==0xFF1B) + exit(0); +} + +int key_win3(int key,void *p) +{ + printf("Key in Win3 : %d\n",key); + if (key==0xFF1B) + mlx_destroy_window(mlx,win3); +} + +int mouse_win1(int button,int x,int y, void *p) +{ + printf("Mouse in Win1, button %d at %dx%d.\n",button,x,y); +} + +int mouse_win2(int button,int x,int y, void *p) +{ + printf("Mouse in Win2, button %d at %dx%d.\n",button,x,y); +} + +int mouse_win3(int x,int y, void *p) +{ + printf("Mouse moving in Win3, at %dx%d.\n",x,y); +} + + +int main() +{ + int a; + + printf("MinilibX Test Program\n"); + a = 0x11223344; + if (((unsigned char *)&a)[0] == 0x11) + local_endian = 1; + else + local_endian = 0; + printf(" => Local Endian : %d\n",local_endian); + + printf(" => Connection ..."); + if (!(mlx = mlx_init())) + { + printf(" !! KO !!\n"); + exit(1); + } + printf("OK (use_xshm %d pshm_format %d)\n",((t_xvar *)mlx)->use_xshm,((t_xvar *)mlx)->pshm_format); + + printf(" => Window1 %dx%d \"Title 1\" ...",WIN1_SX,WIN1_SY); + if (!(win1 = mlx_new_window(mlx,WIN1_SX,WIN1_SY,"Title1"))) + { + printf(" !! KO !!\n"); + exit(1); + } + printf("OK\n"); + + printf(" => Colormap sans event ..."); + color_map_1(win1,WIN1_SX,WIN1_SY); + printf("OK\n"); + sleep(2); + + printf(" => Clear Window ..."); + mlx_clear_window(mlx,win1); + printf("OK\n"); + sleep(2); + + printf(" => Image1 ZPixmap %dx%d ...",IM1_SX,IM1_SY); + if (!(im1 = mlx_new_image(mlx,IM1_SX,IM1_SY))) + { + printf(" !! KO !!\n"); + exit(1); + } + data1 = mlx_get_data_addr(im1,&bpp1,&sl1,&endian1); + printf("OK (bpp1: %d, sizeline1: %d endian: %d type: %d)\n",bpp1,sl1,endian1, + ((t_img *)im1)->type); + + printf(" => Fill Image1 ..."); + color_map_2(data1,bpp1,sl1,IM1_SX,IM1_SY,endian1, 1); + printf("OK (pixmap : %d)\n",(int)((t_img *)im1)->pix); + + printf(" => Put Image1 ..."); + mlx_put_image_to_window(mlx,win1,im1,20,20); + printf("OK\n"); + sleep(2); + + printf(" => Destroy Image1 ... "); + mlx_destroy_image(mlx, im1); + printf("OK\n"); + sleep(2); + + printf(" => Image3 ZPixmap %dx%d ...",IM3_SX,IM3_SY); + if (!(im3 = mlx_new_image(mlx,IM3_SX,IM3_SY))) + { + printf(" !! KO !!\n"); + exit(1); + } + data3 = mlx_get_data_addr(im3,&bpp3,&sl3,&endian3); + printf("OK (bpp3 %d, sizeline3 %d endian3 %d type %d)\n",bpp3,sl3,endian3, + ((t_img *)im3)->type); + + printf(" => Fill Image3 ..."); + color_map_2(data3,bpp3,sl3,IM3_SX,IM3_SY,endian3, 1); + printf("OK (pixmap : %d)\n",(int)((t_img *)im3)->pix); + + printf(" => Put Image3 ..."); + mlx_put_image_to_window(mlx,win1,im3,20,20); + printf("OK\n"); + sleep(2); + + printf(" => String ..."); + mlx_string_put(mlx,win1,5,WIN1_SY/2,0xFF99FF,"String output"); + mlx_string_put(mlx,win1,15,WIN1_SY/2+20,0x00FFFF,"MinilibX test"); + printf("OK\n"); + sleep(2); + + printf(" => Xpm from file ..."); + if (!(im2 = mlx_xpm_file_to_image(mlx,"open.xpm",&xpm1_x,&xpm1_y))) + { + printf(" !! KO !!\n"); + exit(1); + } + data2 = mlx_get_data_addr(im2,&bpp2,&sl2,&endian2); + printf("OK (xpm %dx%d)(img bpp2: %d, sizeline2: %d endian: %d type: %d)\n", + xpm1_x,xpm1_y,bpp2,sl2,endian2,((t_img *)im2)->type); + sleep(2); + + printf(" => Put xpm ..."); + mlx_put_image_to_window(mlx,win1,im2,0,0); + mlx_put_image_to_window(mlx,win1,im2,100,100); + printf("OK\n"); + sleep(2); + + printf(" => 2nd window,"); + win2 = mlx_new_window(mlx,WIN1_SX,WIN1_SY,"Title2"); + if (!(im4 = mlx_new_image(mlx,IM3_SX, IM3_SY))) + { + printf(" !! KO !!\n"); + exit(1); + } + data4 = mlx_get_data_addr(im4,&bpp4,&sl4,&endian4); + color_map_2(data4,bpp4,sl4,IM3_SX,IM3_SY,endian4, 2); + + printf(" 3rd window, Installing hooks ..."); + win3 = mlx_new_window(mlx,WIN1_SX,WIN1_SY,"Title3"); + mlx_expose_hook(win1,expose_win1,0); + mlx_mouse_hook(win1,mouse_win1,0); + mlx_key_hook(win1,key_win1,0); + mlx_expose_hook(win2,expose_win2,0); + mlx_mouse_hook(win2,mouse_win2,0); + mlx_key_hook(win2,key_win2,0); + mlx_key_hook(win3,key_win3,0); + + mlx_hook(win3, MotionNotify, PointerMotionMask, mouse_win3, 0); + + printf("OK\nNow in Loop. Just play. Esc in 3 to destroy, 1&2 to quit.\n"); + + mlx_loop(mlx); +} + + +int color_map_1(void *win,int w,int h) +{ + int x; + int y; + int color; + + x = w; + while (x--) + { + y = h; + while (y--) + { + color = (x*255)/w+((((w-x)*255)/w)<<16)+(((y*255)/h)<<8); + mlx_pixel_put(mlx,win,x,y,color); + } + } +} + + +int color_map_2(unsigned char *data,int bpp,int sl,int w,int h,int endian, int type) +{ + int x; + int y; + int opp; + int dec; + int color; + int color2; + unsigned char *ptr; + + opp = bpp/8; + printf("(opp : %d) ",opp); + y = h; + while (y--) + { + ptr = data+y*sl; + x = w; + while (x--) + { + if (type==2) + color = (y*255)/w+((((w-x)*255)/w)<<16) + +(((y*255)/h)<<8); + else + color = (x*255)/w+((((w-x)*255)/w)<<16)+(((y*255)/h)<<8); + color2 = mlx_get_color_value(mlx,color); + dec = opp; + while (dec--) + if (endian==local_endian) + { + if (endian) + *(ptr+x*opp+dec) = ((unsigned char *)(&color2))[4-opp+dec]; + else + *(ptr+x*opp+dec) = ((unsigned char *)(&color2))[dec]; + } + else + { + if (endian) + *(ptr+x*opp+dec) = ((unsigned char *)(&color2))[opp-1-dec]; + else + *(ptr+x*opp+dec) = ((unsigned char *)(&color2))[3-dec]; + } + } + } + +} diff --git a/Minilibx/test/new_win.c b/Minilibx/test/new_win.c new file mode 100644 index 0000000..62bed4b --- /dev/null +++ b/Minilibx/test/new_win.c @@ -0,0 +1,31 @@ + + + +#include "mlx.h" + + +void *mlx; +void *win1; +void *win2; + + + +int gere_mouse(int x,int y,int button,void*toto) +{ + printf("Mouse event - new win\n"); + mlx_destroy_window(mlx,win1); + win1 = mlx_new_window(mlx,random()%500,random()%500,"new win"); + mlx_mouse_hook(win1,gere_mouse,0); +} + + +int main() +{ + srandom(time(0)); + mlx = mlx_init(); + win1 = mlx_new_window(mlx,300,300,"win1"); + win2 = mlx_new_window(mlx,600,600,"win2"); + mlx_mouse_hook(win1,gere_mouse,0); + mlx_mouse_hook(win2,gere_mouse,0); + mlx_loop(mlx); +} diff --git a/Minilibx/test/open.xpm b/Minilibx/test/open.xpm new file mode 100644 index 0000000..87be371 --- /dev/null +++ b/Minilibx/test/open.xpm @@ -0,0 +1,1439 @@ +/* XPM */ +static char * open30_2_xpm[] = { +"64 64 1372 2", +" c None", +". c #08090D", +"+ c #1A1E23", +"@ c #1F2124", +"# c #060809", +"$ c #1A1E21", +"% c #4F606C", +"& c #3D4145", +"* c #868D93", +"= c #454E56", +"- c #627481", +"; c #667C8A", +"> c #2D3031", +", c #D7E1E7", +"' c #4D5157", +") c #8997A5", +"! c #282E31", +"~ c #333B41", +"{ c #A5C6DB", +"] c #718C9B", +"^ c #000000", +"/ c #181B1F", +"( c #262828", +"_ c #D2DEE7", +": c #B8C5D0", +"< c #151719", +"[ c #08090B", +"} c #272B30", +"| c #2D3037", +"1 c #26282C", +"2 c #1A1D1F", +"3 c #B1CADB", +"4 c #56646E", +"5 c #080809", +"6 c #080A0C", +"7 c #1E2126", +"8 c #98B7C9", +"9 c #A2CAE2", +"0 c #7FA1B5", +"a c #06080A", +"b c #252729", +"c c #A7ADB2", +"d c #272B2E", +"e c #1E2023", +"f c #C8D8E5", +"g c #C9DDED", +"h c #8996A3", +"i c #6B7782", +"j c #C7DFF0", +"k c #CCE0F0", +"l c #AFC1CF", +"m c #47535B", +"n c #B0D3E8", +"o c #7E99A9", +"p c #738493", +"q c #97B4C7", +"r c #53606A", +"s c #6E8996", +"t c #A1CBE3", +"u c #9CC6DE", +"v c #90B5CB", +"w c #171D22", +"x c #1E2629", +"y c #020202", +"z c #ABB3BA", +"A c #BBC4C8", +"B c #222323", +"C c #141617", +"D c #5D6164", +"E c #ACB5BC", +"F c #676D74", +"G c #BDD4E5", +"H c #B3D1E7", +"I c #B0D1E7", +"J c #728A99", +"K c #94AEBF", +"L c #B1D1E7", +"M c #505C64", +"N c #7B98A9", +"O c #A1CBE0", +"P c #99C3D9", +"Q c #475863", +"R c #A0C9DE", +"S c #9CC6DA", +"T c #9ECAE1", +"U c #9CC5DD", +"V c #9AC4DC", +"W c #263137", +"X c #3C4A55", +"Y c #658190", +"Z c #66686B", +"` c #7D8085", +" . c #363839", +".. c #797E81", +"+. c #D2DBE1", +"@. c #DDE9F4", +"#. c #CADEEF", +"$. c #778593", +"%. c #AED0E5", +"&. c #9EC9DE", +"*. c #9EC8DF", +"=. c #9BC1D8", +"-. c #9EC8DE", +";. c #6B8596", +">. c #9BC5DC", +",. c #9BC6DF", +"'. c #9CC5DC", +"). c #688595", +"!. c #6B8698", +"~. c #9CC4DC", +"{. c #9BC4DC", +"]. c #9DC5DD", +"^. c #647D8C", +"/. c #485864", +"(. c #161A1D", +"_. c #36444C", +":. c #95BDD5", +"<. c #566E7E", +"[. c #A4AAAD", +"}. c #E9F2F7", +"|. c #DEEAF6", +"1. c #B5D4E9", +"2. c #A9CFE3", +"3. c #90B3C9", +"4. c #9FCAE1", +"5. c #9BC4DD", +"6. c #7490A2", +"7. c #99C2DB", +"8. c #81A5BA", +"9. c #9CC5DE", +"0. c #98C1DA", +"a. c #5F7889", +"b. c #96BFD8", +"c. c #44545F", +"d. c #565A5E", +"e. c #DFE6EC", +"f. c #E6EEF7", +"g. c #D6E4F2", +"h. c #BFD6E9", +"i. c #A9CCE3", +"j. c #9FC8DD", +"k. c #9DC6DD", +"l. c #9CC4DD", +"m. c #7D9FB0", +"n. c #98C0D6", +"o. c #9AC5DD", +"p. c #97BFD8", +"q. c #9BC5DF", +"r. c #2D3840", +"s. c #626567", +"t. c #E7ECF5", +"u. c #E1EAF5", +"v. c #CEE3F3", +"w. c #B7D6EA", +"x. c #A4CBE0", +"y. c #8AAFC5", +"z. c #647F90", +"A. c #648092", +"B. c #89B0C7", +"C. c #9CC6DF", +"D. c #5D7486", +"E. c #7B9BAF", +"F. c #84A8BF", +"G. c #9BC5DD", +"H. c #96BED5", +"I. c #4B5D69", +"J. c #9BC5DE", +"K. c #536B77", +"L. c #2E3B41", +"M. c #1B2124", +"N. c #3F4F58", +"O. c #4D5152", +"P. c #E7EEF3", +"Q. c #E2EAF5", +"R. c #CEE2F2", +"S. c #BAD5E9", +"T. c #9DC2D7", +"U. c #5C7281", +"V. c #232A31", +"W. c #08090A", +"X. c #121418", +"Y. c #131619", +"Z. c #131719", +"`. c #87ACC3", +" + c #7B9BAE", +".+ c #87ADC3", +"++ c #8FB5CB", +"@+ c #678295", +"#+ c #96C0D8", +"$+ c #607787", +"%+ c #6B8595", +"&+ c #96C1DB", +"*+ c #6A8595", +"=+ c #35424A", +"-+ c #7090A1", +";+ c #15191C", +">+ c #2D3033", +",+ c #DDE5EB", +"'+ c #D2E3F1", +")+ c #BAD7EB", +"!+ c #A9CFE5", +"~+ c #272F35", +"{+ c #1C2227", +"]+ c #4F697B", +"^+ c #6B8FA9", +"/+ c #759CB6", +"(+ c #7BA0BB", +"_+ c #80A5BC", +":+ c #88B0C8", +"<+ c #96C3DB", +"[+ c #8FB6CD", +"}+ c #80A1B3", +"|+ c #556876", +"1+ c #96BFD7", +"2+ c #566B77", +"3+ c #93B8CD", +"4+ c #637A8D", +"5+ c #9DC6DE", +"6+ c #8FB4CA", +"7+ c #55697A", +"8+ c #6F8F9F", +"9+ c #91BDD5", +"0+ c #283239", +"a+ c #050406", +"b+ c #767B80", +"c+ c #BDC6CE", +"d+ c #D4E5F3", +"e+ c #C1D7EA", +"f+ c #A7CDE4", +"g+ c #9FC9DE", +"h+ c #668596", +"i+ c #6D90AA", +"j+ c #5C7994", +"k+ c #60849F", +"l+ c #6286A1", +"m+ c #688CA8", +"n+ c #7298B2", +"o+ c #82A8C2", +"p+ c #8FBAD5", +"q+ c #96C2DB", +"r+ c #89ADC4", +"s+ c #96BED6", +"t+ c #99C2DA", +"u+ c #6C899A", +"v+ c #92BBD2", +"w+ c #9AC4DD", +"x+ c #5B717D", +"y+ c #9EC6DE", +"z+ c #8BB1C9", +"A+ c #718EA0", +"B+ c #94C3DB", +"C+ c #536B78", +"D+ c #3E505F", +"E+ c #4E6373", +"F+ c #2C333C", +"G+ c #070708", +"H+ c #040404", +"I+ c #1A1C1E", +"J+ c #202326", +"K+ c #050606", +"L+ c #23292E", +"M+ c #A1C0D4", +"N+ c #9FC9DD", +"O+ c #97C2DB", +"P+ c #80A8C1", +"Q+ c #668AA6", +"R+ c #4B5D72", +"S+ c #4C647A", +"T+ c #5F80A0", +"U+ c #60859E", +"V+ c #678AA6", +"W+ c #739BB5", +"X+ c #85AEC7", +"Y+ c #92BDD7", +"Z+ c #96BFD5", +"`+ c #627B8A", +" @ c #89B1C9", +".@ c #2B353C", +"+@ c #7597B2", +"@@ c #779CB8", +"#@ c #52697C", +"$@ c #1D2328", +"%@ c #445663", +"&@ c #5E7A8D", +"*@ c #252F37", +"=@ c #090909", +"-@ c #859BB2", +";@ c #859DB8", +">@ c #6E8396", +",@ c #252C33", +"'@ c #9CC4D7", +")@ c #92C0D9", +"!@ c #79A0BA", +"~@ c #6487A3", +"{@ c #566979", +"]@ c #8CB0C2", +"^@ c #51697C", +"/@ c #60849D", +"(@ c #6D8EAC", +"_@ c #7BA0BC", +":@ c #8AB4CE", +"<@ c #95C2DB", +"[@ c #9AC5DC", +"}@ c #95C1DA", +"|@ c #607B8C", +"1@ c #597488", +"2@ c #7EA6BF", +"3@ c #597587", +"4@ c #455664", +"5@ c #668598", +"6@ c #82A9C4", +"7@ c #617F92", +"8@ c #1A2328", +"9@ c #2B3137", +"0@ c #728FAC", +"a@ c #51657B", +"b@ c #6B8AA8", +"c@ c #8EAEC7", +"d@ c #A8C8E2", +"e@ c #92BDD6", +"f@ c #769DBA", +"g@ c #526E87", +"h@ c #7490A0", +"i@ c #A6CDE4", +"j@ c #97BFD4", +"k@ c #55697D", +"l@ c #6286A0", +"m@ c #7399B3", +"n@ c #84ACC5", +"o@ c #92BFD9", +"p@ c #99C4DC", +"q@ c #94C0DA", +"r@ c #4F6575", +"s@ c #7DA5BF", +"t@ c #7FA2BC", +"u@ c #8FB6CE", +"v@ c #95C3DB", +"w@ c #8EB8D2", +"x@ c #6A879D", +"y@ c #111318", +"z@ c #252A30", +"A@ c #81868C", +"B@ c #A5ABAD", +"C@ c #70767C", +"D@ c #38434F", +"E@ c #637F9B", +"F@ c #516980", +"G@ c #799AB5", +"H@ c #A5C3D9", +"I@ c #93BDD6", +"J@ c #779EBA", +"K@ c #445A6B", +"L@ c #93B5C9", +"M@ c #B6D3E8", +"N@ c #AECFE4", +"O@ c #95BDD2", +"P@ c #52687A", +"Q@ c #6486A3", +"R@ c #7092B0", +"S@ c #90BCD6", +"T@ c #97C4DC", +"U@ c #A0C9E0", +"V@ c #99C5DD", +"W@ c #86AEC6", +"X@ c #8FBAD4", +"Y@ c #91BDD6", +"Z@ c #7094AC", +"`@ c #2A353E", +" # c #0B0E10", +".# c #888D90", +"+# c #787D82", +"@# c #465360", +"## c #56697F", +"$# c #A6CADD", +"%# c #5A7382", +"&# c #6C8CAA", +"*# c #A5BED3", +"=# c #A7CAE0", +"-# c #94C1DA", +";# c #7EA4BF", +"># c #415160", +",# c #9DC3D5", +"'# c #B3CFE1", +")# c #AAC3D4", +"!# c #A8CDE4", +"~# c #89ACBE", +"{# c #567088", +"]# c #6C91AC", +"^# c #81A7C2", +"/# c #96C4DC", +"(# c #85A9BD", +"_# c #708C9B", +":# c #5A6E7B", +"<# c #6C8695", +"[# c #97C3DB", +"}# c #8BB5CE", +"|# c #425461", +"1# c #63819E", +"2# c #415465", +"3# c #0B0D0E", +"4# c #607387", +"5# c #687D8C", +"6# c #B8D6E9", +"7# c #7893A2", +"8# c #576F85", +"9# c #A7BACF", +"0# c #B0CEE5", +"a# c #98C4DC", +"b# c #88B1CA", +"c# c #36444E", +"d# c #8FA0AD", +"e# c #73818D", +"f# c #596D81", +"g# c #B4D0E4", +"h# c #A3CDE2", +"i# c #658296", +"j# c #6A8DAB", +"k# c #7BA5C0", +"l# c #94BAD2", +"m# c #6D899B", +"n# c #99C3DC", +"o# c #8EB9D2", +"p# c #7AA0BA", +"q# c #6C8FAB", +"r# c #6484A1", +"s# c #1F252C", +"t# c #121619", +"u# c #7E96B0", +"v# c #7A8A96", +"w# c #BCD7EA", +"x# c #A0C5D9", +"y# c #3C4B57", +"z# c #A9BACD", +"A# c #BCD5E8", +"B# c #84A6BA", +"C# c #8EA1AE", +"D# c #CFD1D4", +"E# c #ECF6FA", +"F# c #ABB7C2", +"G# c #556F84", +"H# c #57626A", +"I# c #5C7078", +"J# c #6C8AA7", +"K# c #80A6C0", +"L# c #91B8D0", +"M# c #94BFD8", +"N# c #87B0CA", +"O# c #7CA2BB", +"P# c #7097AF", +"Q# c #495E6F", +"R# c #0C0E11", +"S# c #3A3F43", +"T# c #8AA3BB", +"U# c #778592", +"V# c #C0D8EB", +"W# c #B3D5E9", +"X# c #404A53", +"Y# c #B2C2D3", +"Z# c #96A1AC", +"`# c #9DB2C3", +" $ c #AEBECE", +".$ c #EDEFF3", +"+$ c #F7FAFC", +"@$ c #B6BFC7", +"#$ c #556E85", +"$$ c #121314", +"%$ c #2B2E2F", +"&$ c #555A5E", +"*$ c #3B4C5B", +"=$ c #6F8EA4", +"-$ c #92BED8", +";$ c #9DC7DF", +">$ c #87ACC1", +",$ c #546A78", +"'$ c #516874", +")$ c #4E6570", +"!$ c #4D6271", +"~$ c #4C6271", +"{$ c #4E677A", +"]$ c #38454E", +"^$ c #6C7278", +"/$ c #86A1B6", +"($ c #5C656C", +"_$ c #A4B0BA", +":$ c #555D64", +"<$ c #657178", +"[$ c #A6B0B5", +"}$ c #939CA1", +"|$ c #D4E4F1", +"1$ c #A0BACE", +"2$ c #B9C7D7", +"3$ c #F6F7F9", +"4$ c #C6CED1", +"5$ c #506A7C", +"6$ c #060607", +"7$ c #676A6B", +"8$ c #91999F", +"9$ c #7CA3BE", +"0$ c #96BCD4", +"a$ c #5B717E", +"b$ c #4B5F6C", +"c$ c #455864", +"d$ c #5B717F", +"e$ c #81A5B9", +"f$ c #98C4DD", +"g$ c #93BFD8", +"h$ c #87B1CA", +"i$ c #7BA1BC", +"j$ c #5A7489", +"k$ c #222A33", +"l$ c #838A92", +"m$ c #9DADBC", +"n$ c #ECF0F5", +"o$ c #F1F9FB", +"p$ c #818A8D", +"q$ c #4A5155", +"r$ c #6A6F72", +"s$ c #7E898F", +"t$ c #E6F1F7", +"u$ c #CADCED", +"v$ c #A0B7CC", +"w$ c #C6D1DF", +"x$ c #AFB3B4", +"y$ c #5F707D", +"z$ c #CBCFD1", +"A$ c #F4F5F6", +"B$ c #66737F", +"C$ c #87B2CB", +"D$ c #90B7CD", +"E$ c #596E7B", +"F$ c #586F7E", +"G$ c #8BB0C8", +"H$ c #91BED6", +"I$ c #83ADC7", +"J$ c #6D8EA7", +"K$ c #3F5161", +"L$ c #2D3A45", +"M$ c #1F2020", +"N$ c #BDC5CC", +"O$ c #E0EDF5", +"P$ c #BBCAD8", +"Q$ c #E1E4E7", +"R$ c #5E6368", +"S$ c #5B5F62", +"T$ c #D9E7F3", +"U$ c #A4C3D6", +"V$ c #89A3B3", +"W$ c #7B91A1", +"X$ c #627990", +"Y$ c #42505A", +"Z$ c #CACCCE", +"`$ c #F9F9F9", +" % c #FDFDFD", +".% c #BCBEC0", +"+% c #5C7689", +"@% c #8DB9D3", +"#% c #8FB5CC", +"$% c #536471", +"%% c #98C1D9", +"&% c #91BED7", +"*% c #81AAC5", +"=% c #597386", +"-% c #41535F", +";% c #6486A2", +">% c #4D667D", +",% c #070809", +"'% c #44484E", +")% c #BEC8D0", +"!% c #8096A6", +"~% c #516473", +"{% c #A9ACAF", +"]% c #8B8F91", +"^% c #A8B3BD", +"/% c #C5DAEB", +"(% c #9FC8E1", +"_% c #8FBCD6", +":% c #81A8C2", +"<% c #6C90AC", +"[% c #56728C", +"}% c #585B5F", +"|% c #CBCDCD", +"1% c #C1C3C6", +"2% c #4F565F", +"3% c #82ABC3", +"4% c #93BCD3", +"5% c #95BED7", +"6% c #8EB9D3", +"7% c #5B788B", +"8% c #627E91", +"9% c #7FA7C1", +"0% c #6C91AB", +"a% c #546F87", +"b% c #6F7376", +"c% c #D5E2EF", +"d% c #A9C4D8", +"e% c #81A1BA", +"f% c #333940", +"g% c #5F6B76", +"h% c #C0D5E8", +"i% c #AACCE2", +"j% c #8EB8D3", +"k% c #7FA5BF", +"l% c #7095B0", +"m% c #4E697E", +"n% c #07090A", +"o% c #0D0F10", +"p% c #7193A6", +"q% c #96C3DC", +"r% c #8EBCD7", +"s% c #91BDD7", +"t% c #8FBBD6", +"u% c #7699AD", +"v% c #4D626F", +"w% c #252D33", +"x% c #101215", +"y% c #0C0D0E", +"z% c #0A0C0E", +"A% c #06090A", +"B% c #7F8488", +"C% c #D7E3F1", +"D% c #B6D0E4", +"E% c #A3C2D7", +"F% c #596872", +"G% c #A9BED0", +"H% c #B4D0E5", +"I% c #9EC8DC", +"J% c #8FB9D4", +"K% c #85ADC7", +"L% c #7FA4BE", +"M% c #4B606F", +"N% c #4E6372", +"O% c #89B6D0", +"P% c #92C1DA", +"Q% c #9DC7DD", +"R% c #95C0DA", +"S% c #94BED8", +"T% c #8BB8D1", +"U% c #7AA0B9", +"V% c #4E667A", +"W% c #344151", +"X% c #0C0D0F", +"Y% c #8A8F92", +"Z% c #D4E6F5", +"`% c #BCD5E9", +" & c #8599A5", +".& c #939DA6", +"+& c #C4DAEB", +"@& c #89A6B9", +"#& c #7D9FB5", +"$& c #98C3DC", +"%& c #95C0D9", +"&& c #7CA2B9", +"*& c #7697AE", +"=& c #698498", +"-& c #7394A8", +";& c #9EC7DF", +">& c #8DB1C4", +",& c #6B8594", +"'& c #50636C", +")& c #50626C", +"!& c #7F9FB1", +"~& c #93B8D0", +"{& c #627A88", +"]& c #90B6CC", +"^& c #93BDD7", +"/& c #87AFC9", +"(& c #7291A7", +"_& c #384651", +":& c #121618", +"<& c #12171B", +"[& c #4F6986", +"}& c #597998", +"|& c #324052", +"1& c #969CA1", +"2& c #D6E6F5", +"3& c #C6DCEE", +"4& c #505A64", +"5& c #82929F", +"6& c #99ABBB", +"7& c #A1B9CA", +"8& c #87A0B0", +"9& c #718EA1", +"0& c #8DB2C9", +"a& c #8BAEC4", +"b& c #586D7D", +"c& c #97C0D9", +"d& c #8DB3C9", +"e& c #95B8CD", +"f& c #9DC0D6", +"g& c #6F8B9C", +"h& c #354249", +"i& c #464E54", +"j& c #8A98A5", +"k& c #AABAC7", +"l& c #86939E", +"m& c #41494F", +"n& c #4A5861", +"o& c #97C1DA", +"p& c #5E7888", +"q& c #5C7482", +"r& c #88ACC2", +"s& c #91BFD7", +"t& c #799CB5", +"u& c #47596A", +"v& c #0D0F12", +"w& c #1A2127", +"x& c #56778D", +"y& c #688BA9", +"z& c #5D7F9E", +"A& c #547391", +"B& c #0E1013", +"C& c #9DA6AB", +"D& c #C8DCED", +"E& c #7A8996", +"F& c #B5CEE0", +"G& c #BCDBEC", +"H& c #B9D5EA", +"I& c #8BA2B2", +"J& c #6C8A9D", +"K& c #97BFD7", +"L& c #3E4E59", +"M& c #92B5CB", +"N& c #535F68", +"O& c #454F56", +"P& c #6F7C87", +"Q& c #ABC0D1", +"R& c #C7DCEE", +"S& c #C5DBED", +"T& c #C2D7EA", +"U& c #BFD8EA", +"V& c #BCD7EB", +"W& c #62717B", +"X& c #5B6F7B", +"Y& c #95C3DC", +"Z& c #8BB2C9", +"`& c #485761", +" * c #42525F", +".* c #6686A1", +"+* c #587896", +"@* c #1B2129", +"#* c #5C7A94", +"$* c #7DA2BD", +"%* c #84AEC7", +"&* c #749BB5", +"** c #5C7E9C", +"=* c #27343F", +"-* c #A4A9B2", +";* c #D9E7F4", +">* c #C8DBEC", +",* c #B1C8DA", +"'* c #5D6C76", +")* c #A8C5D8", +"!* c #A6BDD0", +"~* c #B9D6EA", +"{* c #B9D4E9", +"]* c #8198A8", +"^* c #8AADC3", +"/* c #8CB1CA", +"(* c #96C2D8", +"_* c #A3C7DF", +":* c #ADCDE3", +"<* c #ABD0E4", +"[* c #ADCFE3", +"}* c #AACEE4", +"|* c #A4CDE3", +"1* c #A1CBE1", +"2* c #A3CCE3", +"3* c #A2C9DF", +"4* c #41515A", +"5* c #81A2B5", +"6* c #94C0D7", +"7* c #5E7789", +"8* c #526777", +"9* c #516777", +"0* c #6B8CA5", +"a* c #759CBA", +"b* c #658AA5", +"c* c #587798", +"d* c #1B242B", +"e* c #0E1110", +"f* c #101214", +"g* c #202931", +"h* c #59758E", +"i* c #799FBB", +"j* c #84B1CA", +"k* c #86ACC6", +"l* c #354758", +"m* c #A0A6AE", +"n* c #DAE6F2", +"o* c #C4DCEE", +"p* c #B4D2E8", +"q* c #3E4A53", +"r* c #698091", +"s* c #5D7581", +"t* c #A3CAE0", +"u* c #A6CFE5", +"v* c #A5CCE5", +"w* c #718A9C", +"x* c #98C3DB", +"y* c #83ABC7", +"z* c #2E3B46", +"A* c #33414A", +"B* c #678398", +"C* c #8AB3CE", +"D* c #93BED7", +"E* c #97C4DB", +"F* c #42525E", +"G* c #88ACC0", +"H* c #789EB9", +"I* c #7A9FBB", +"J* c #7EA2BD", +"K* c #779DB5", +"L* c #577081", +"M* c #5B7B9B", +"N* c #1D2229", +"O* c #547390", +"P* c #54728D", +"Q* c #6082A0", +"R* c #688EA9", +"S* c #6689A7", +"T* c #6086A0", +"U* c #6285A1", +"V* c #6B8DAA", +"W* c #718FAB", +"X* c #3E5568", +"Y* c #969DA1", +"Z* c #DBE8F4", +"`* c #95ACBD", +" = c #758B9A", +".= c #A4C9DE", +"+= c #698190", +"@= c #667E8A", +"#= c #7D99AA", +"$= c #7B9BAD", +"%= c #6F8C9A", +"&= c #536976", +"*= c #84ADC6", +"== c #6D92AD", +"-= c #62829E", +";= c #43576A", +">= c #2F3B46", +",= c #5C788A", +"'= c #86AFC8", +")= c #93BED8", +"!= c #93BAD5", +"~= c #93BAD2", +"{= c #92BCD4", +"]= c #7EA2B6", +"^= c #3D4D56", +"/= c #485B67", +"(= c #7596A9", +"_= c #8CBBD4", +":= c #90BCD5", +"<= c #91BFD9", +"[= c #789BAD", +"}= c #465B6A", +"|= c #59789A", +"1= c #5D7F9D", +"2= c #5E839C", +"3= c #59799A", +"4= c #415569", +"5= c #2D3A46", +"6= c #2E3B49", +"7= c #4A647C", +"8= c #587690", +"9= c #39485A", +"0= c #7F8589", +"a= c #D9E8F5", +"b= c #CCDEEE", +"c= c #8597A5", +"d= c #B3D2E3", +"e= c #9BB3C4", +"f= c #B2CEE1", +"g= c #B2D1E7", +"h= c #ABCFE6", +"i= c #94B7CB", +"j= c #495C6A", +"k= c #688498", +"l= c #617B8A", +"m= c #85ADC8", +"n= c #78A0B9", +"o= c #62819B", +"p= c #2E3843", +"q= c #485A6C", +"r= c #67889C", +"s= c #8AB5CF", +"t= c #8EB9D1", +"u= c #6C899B", +"v= c #6E91A7", +"w= c #678399", +"x= c #6888A1", +"y= c #323E48", +"z= c #5B7585", +"A= c #98C5DD", +"B= c #83ACC1", +"C= c #2D373F", +"D= c #4B637C", +"E= c #567694", +"F= c #26313C", +"G= c #15191F", +"H= c #4D647A", +"I= c #252F39", +"J= c #5D6163", +"K= c #DDE9F5", +"L= c #CEDFEE", +"M= c #8898A5", +"N= c #B0CBDC", +"O= c #BFDAEC", +"P= c #BFDBEC", +"Q= c #BBDAEC", +"R= c #BAD7EA", +"S= c #6B808F", +"T= c #7297B0", +"U= c #8CB8D1", +"V= c #95C1D9", +"W= c #91BCD6", +"X= c #86AEC8", +"Y= c #7496B3", +"Z= c #6587A2", +"`= c #384958", +" - c #323F4B", +".- c #546A7C", +"+- c #6C88A1", +"@- c #779AB1", +"#- c #658297", +"$- c #3B4A58", +"%- c #33404B", +"&- c #202830", +"*- c #577287", +"=- c #86B1CC", +"-- c #86ACC0", +";- c #6E8797", +">- c #9CC7DF", +",- c #92BCD5", +"'- c #91BCD5", +")- c #8EB6CE", +"!- c #344453", +"~- c #263039", +"{- c #364452", +"]- c #2B3643", +"^- c #2A2D2E", +"/- c #E1EBF4", +"(- c #D2E4F3", +"_- c #A0B2C3", +":- c #8094A1", +"<- c #BAD8EB", +"[- c #B8D6EA", +"}- c #485A6A", +"|- c #789FB9", +"1- c #90BBD3", +"2- c #94C4DC", +"3- c #88B3CD", +"4- c #7A9EB9", +"5- c #698BA8", +"6- c #4D677C", +"7- c #151A1E", +"8- c #1A2125", +"9- c #171C21", +"0- c #1D2329", +"a- c #1D262E", +"b- c #486073", +"c- c #6A8CAA", +"d- c #7CA2BE", +"e- c #90BDD7", +"f- c #9AC5DE", +"g- c #7493A2", +"h- c #708B99", +"i- c #8CB7D1", +"j- c #7494AB", +"k- c #68889F", +"l- c #6A8FA5", +"m- c #7BA2BC", +"n- c #171D21", +"o- c #1D262F", +"p- c #212B36", +"q- c #09090B", +"r- c #BBC2C9", +"s- c #D4E4F2", +"t- c #C1D9EB", +"u- c #44515A", +"v- c #92B5C9", +"w- c #6B8795", +"x- c #4E687E", +"y- c #7EA6C0", +"z- c #91BED8", +"A- c #93BFD9", +"B- c #8CB5D0", +"C- c #7DA4BE", +"D- c #6F92AE", +"E- c #6687A5", +"F- c #526C85", +"G- c #415669", +"H- c #384655", +"I- c #6589A4", +"J- c #6E92AE", +"K- c #80A8C2", +"L- c #92BCD6", +"M- c #91BFD8", +"N- c #799AAF", +"O- c #6A8796", +"P- c #81AAC3", +"Q- c #577187", +"R- c #1F2930", +"S- c #192027", +"T- c #1B2227", +"U- c #0D1010", +"V- c #0E1012", +"W- c #070709", +"X- c #5C6062", +"Y- c #DCE8F3", +"Z- c #C4DCEF", +"`- c #9BB3C6", +" ; c #3A424F", +".; c #313A44", +"+; c #35424C", +"@; c #374655", +"#; c #6E91AD", +"$; c #87B2CC", +"%; c #799EBA", +"&; c #618298", +"*; c #7095AF", +"=; c #435663", +"-; c #80A7C0", +";; c #95C4DC", +">; c #779CB3", +",; c #526D7E", +"'; c #516A7A", +"); c #526B7B", +"!; c #465764", +"~; c #34414E", +"{; c #5C7E9A", +"]; c #2B3741", +"^; c #4B657F", +"/; c #5C7D9C", +"(; c #557088", +"_; c #0F0F10", +":; c #B9C2CA", +"<; c #CCDFEF", +"[; c #B4CDE1", +"}; c #8DAEC8", +"|; c #6F93AE", +"1; c #678CA6", +"2; c #6E92AF", +"3; c #81A8C1", +"4; c #8FBBD5", +"5; c #8DB9D2", +"6; c #6D8FA2", +"7; c #586F82", +"8; c #394851", +"9; c #86B0C6", +"0; c #85AFC8", +"a; c #6F94AF", +"b; c #698DA8", +"c; c #6889A7", +"d; c #5E7E9F", +"e; c #475D75", +"f; c #2E3C4A", +"g; c #5D7E9D", +"h; c #405465", +"i; c #36393B", +"j; c #D7E5F1", +"k; c #A4C5DC", +"l; c #668496", +"m; c #7595AB", +"n; c #7798AE", +"o; c #97C2DA", +"p; c #789DB3", +"q; c #8BB1C8", +"r; c #93C0D9", +"s; c #8BB5CF", +"t; c #85AFC9", +"u; c #82AAC6", +"v; c #5F7C95", +"w; c #1E252C", +"x; c #54728E", +"y; c #587899", +"z; c #5A7B9B", +"A; c #2D3843", +"B; c #798086", +"C; c #D1E3F1", +"D; c #B7D3E8", +"E; c #7E98AB", +"F; c #181C1F", +"G; c #46525F", +"H; c #80A1B8", +"I; c #99C3DB", +"J; c #85ACC2", +"K; c #21272D", +"L; c #0A0B0D", +"M; c #53718C", +"N; c #577797", +"O; c #1B2229", +"P; c #0D0E0F", +"Q; c #B3BDC4", +"R; c #CADDED", +"S; c #B4D3E7", +"T; c #2B3339", +"U; c #2F3840", +"V; c #7899AC", +"W; c #93C1D9", +"X; c #8FBCD5", +"Y; c #8BB6D1", +"Z; c #8DB8D2", +"`; c #92BFD8", +" > c #678092", +".> c #547089", +"+> c #5C7F9B", +"@> c #1F262E", +"#> c #202223", +"$> c #B1BECB", +"%> c #C3D9EB", +"&> c #7B8D99", +"*> c #708B9A", +"=> c #85ABC1", +"-> c #7FA3BA", +";> c #92BBD3", +">> c #7CA0B4", +",> c #97BDD4", +"'> c #657E8F", +")> c #93BDD4", +"!> c #88ADC7", +"~> c #6F94AE", +"{> c #526A7E", +"]> c #65849B", +"^> c #799DBB", +"/> c #84AFC9", +"(> c #8FB9D2", +"_> c #323C45", +":> c #516C84", +"<> c #658AA4", +"[> c #5B7C9B", +"}> c #2E3A49", +"|> c #2A3038", +"1> c #252D3A", +"2> c #1B1E20", +"3> c #ADBFCF", +"4> c #C0D6E7", +"5> c #B0CDE2", +"6> c #8EB3C9", +"7> c #526975", +"8> c #6B899D", +"9> c #597183", +"0> c #90BAD5", +"a> c #94C2DA", +"b> c #82ABC5", +"c> c #495E6E", +"d> c #82A8C3", +"e> c #81A4BA", +"f> c #7594A5", +"g> c #87ABC3", +"h> c #4D6573", +"i> c #6689A6", +"j> c #526E85", +"k> c #243037", +"l> c #607B96", +"m> c #7699B6", +"n> c #789EB5", +"o> c #303D48", +"p> c #7498B4", +"q> c #7094AF", +"r> c #597792", +"s> c #242F39", +"t> c #1A1D25", +"u> c #374553", +"v> c #4D677D", +"w> c #14191E", +"x> c #040505", +"y> c #171A1D", +"z> c #8A9FAD", +"A> c #BCD9EC", +"B> c #B5D3E7", +"C> c #A2CAE1", +"D> c #9DC7DE", +"E> c #9EC7DD", +"F> c #3B4A57", +"G> c #455867", +"H> c #98C2DB", +"I> c #85B0CC", +"J> c #7496B2", +"K> c #4C606F", +"L> c #6E8EA3", +"M> c #7EA0B6", +"N> c #91BBD3", +"O> c #8DB7D1", +"P> c #90BAD4", +"Q> c #96C1DA", +"R> c #3B4853", +"S> c #688AA5", +"T> c #4C657A", +"U> c #1B2026", +"V> c #2B3C44", +"W> c #5F7A90", +"X> c #587284", +"Y> c #536978", +"Z> c #88B1CC", +"`> c #759AB8", +" , c #617E9A", +"., c #556F85", +"+, c #20272E", +"@, c #323D48", +"#, c #333E4A", +"$, c #060707", +"%, c #4A5159", +"&, c #ACC3D5", +"*, c #ACCFE5", +"=, c #5A6874", +"-, c #AACDE1", +";, c #9CC6DC", +">, c #35414C", +",, c #769AB2", +"', c #80AAC5", +"), c #6F92AB", +"!, c #38464F", +"~, c #7EA4B9", +"{, c #97C3DC", +"], c #7A9FB6", +"^, c #3F505C", +"/, c #6D8DA6", +"(, c #1E282E", +"_, c #080909", +":, c #090A0C", +"<, c #344452", +"[, c #3B4857", +"}, c #7799AE", +"|, c #8DB6D1", +"1, c #66869E", +"2, c #3D4957", +"3, c #536C84", +"4, c #353F4C", +"5, c #111215", +"6, c #65727E", +"7, c #A6BCCD", +"8, c #5D6972", +"9, c #AED0E6", +"0, c #99C5DC", +"a, c #8DB5D0", +"b, c #8DB5CE", +"c, c #90BBD5", +"d, c #84AAC5", +"e, c #8EBBD5", +"f, c #80A7C1", +"g, c #6C8DA2", +"h, c #85AFC6", +"i, c #61839B", +"j, c #374352", +"k, c #576D83", +"l, c #80A6C1", +"m, c #81A4BB", +"n, c #111315", +"o, c #111418", +"p, c #4C6378", +"q, c #33424C", +"r, c #37454D", +"s, c #8DB4CF", +"t, c #7397B3", +"u, c #3A495A", +"v, c #0D0F13", +"w, c #27303A", +"x, c #272E36", +"y, c #0F1012", +"z, c #90A4B2", +"A, c #A8CBE2", +"B, c #91BCD4", +"C, c #80ABC3", +"D, c #567083", +"E, c #67899D", +"F, c #94C2DB", +"G, c #95C1DB", +"H, c #779CB2", +"I, c #60849E", +"J, c #64849F", +"K, c #1A1F22", +"L, c #405061", +"M, c #79A1BD", +"N, c #324051", +"O, c #6183A1", +"P, c #6B8FAD", +"Q, c #6485A2", +"R, c #34444F", +"S, c #060606", +"T, c #2D3339", +"U, c #B2CBDF", +"V, c #94BCD5", +"W, c #7DA2BA", +"X, c #3F5264", +"Y, c #5A7991", +"Z, c #7195B3", +"`, c #7BA5BD", +" ' c #81AAC6", +".' c #88B2CC", +"+' c #8EBBD4", +"@' c #8AB2CC", +"#' c #82ADC7", +"$' c #7092A5", +"%' c #95C2DA", +"&' c #41525F", +"*' c #6387A3", +"=' c #475F72", +"-' c #21282F", +";' c #5B7288", +">' c #0D0F11", +",' c #0B0E11", +"'' c #212C36", +")' c #26323C", +"!' c #161B20", +"~' c #55616D", +"{' c #9BB9D0", +"]' c #799EB6", +"^' c #27313A", +"/' c #1A222B", +"(' c #5D7E99", +"_' c #6587A4", +":' c #6789A6", +"<' c #6B8EAB", +"[' c #628097", +"}' c #6D8B9D", +"|' c #769AAF", +"1' c #6E91A9", +"2' c #6C8EAD", +"3' c #6E91AF", +"4' c #3C4D59", +"5' c #8BB1CB", +"6' c #232D32", +"7' c #13171B", +"8' c #232B32", +"9' c #839AAF", +"0' c #789BB3", +"a' c #283138", +"b' c #0C0E0F", +"c' c #242B33", +"d' c #3D4D5B", +"e' c #435768", +"f' c #4B6176", +"g' c #283137", +"h' c #8DB4CC", +"i' c #41535E", +"j' c #405362", +"k' c #3C4F60", +"l' c #3C4E5B", +"m' c #2B353E", +"n' c #526876", +"o' c #92BAD3", +"p' c #1B1F23", +"q' c #31383F", +"r' c #7F9CB6", +"s' c #21292F", +"t' c #29333F", +"u' c #1F252E", +"v' c #090A0E", +"w' c #4D626E", +"x' c #96BDD3", +"y' c #191D20", +"z' c #13181B", +"A' c #80A4BC", +"B' c #1B2027", +"C' c #5D7182", +"D' c #2C383F", +"E' c #364857", +"F' c #1A2028", +"G' c #333F49", +"H' c #7FA2B5", +"I' c #4A5E6E", +"J' c #232E35", +"K' c #252D35", +"L' c #2F3A41", +"M' c #0A0B0E", +"N' c #14191D", +"O' c #5A717F", +"P' c #212931", +"Q' c #222B34", +"R' c #101216", +"S' c #21272B", +" ", +" ", +" ", +" . ", +" + ", +" @ # $ % ", +" & * = - ; ", +" > , ' ) ! ~ { ] ", +" ^ / ( _ : < [ } | 1 2 3 4 5 6 7 8 9 0 a ", +" b c d e f g h i j k l m n o p q r s t u v w x ", +" y z A B C D E F G H I J K L M N O P Q R S T U U V W X Y ", +" Z ` ...+.@.#.$.%.O &.*.=.-.;.>.,.'.).!.~.~.~.{.].^./.(._.:.<. ", +" b [.}.|.#.1.2.3.4.{.~.~.~.~.5.6.5.~.7.8.{.~.~.~.~.9.0.a.b.].c. ", +" d.e.f.g.h.i.j.k.{.~.~.~.~.l.~.m.% n.~.o.{.{.~.~.~.~.p.V 9.~.q.r. ", +" s.t.u.v.w.x.u y.z.A.B.5.~.~.5.C.D.E.F.~.~.G.~.~.~.G.H.I.J.~.~.J.K.L. M.N. ", +" O.P.Q.R.S.T.U.V.W.X.Y.Z.`.~.~.5. +.+++@+U ~.~.~.~.~.#+$+%+,.~.~.G.&+*+=+-+;+ ", +" >+,+Q.'+)+!+~+{+]+^+/+(+_+:+<+~.[+}+U 9.|+5.~.~.~.~.1+2+3+4+5+~.].6+7+8+9+0+ ", +" a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+5.U ~.U r+s+~.~.~.t+u+v+w+x+y+~.z+A+t+B+C+D+E+ F+G+ ", +" H+I+J+K+L+M+N+O+P+Q+R+S+T+U+V+W+X+Y+V ~.~.~.~.U ~.~.~.o.9.{.Z+`+9.~.~.~.V @.@+@@@#@ $@%@&@*@ ", +" =@-@;@>@,@'@'.)@!@~@{@]@^@/@l+(@_@:@<@~.~.~.U {.~.~.~.{.~.~.{.[@~.~.~.~.}@|@1@2@3@4@5@6@7@8@ ", +" 9@0@a@b@c@d@-.e@f@g@h@i@j@k@l@V+m@n@o@p@~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.{.q@r@s@t@u@v@w@x@y@ ", +"z@A@B@C@D@E@X F@G@H@R I@J@K@L@M@N@O@P@Q@R@o+S@T@~.~.~.~.~.~.~.~.~.~.~.~.~.~.9.U@V@W@X@<+V Y@Z@`@ # ", +" .#+#@###$#%#&#*#=#-#;#>#,#'#)#!#~#{#]#^#S@/#~.~.~.~.~.~.~.~.~.~.~.~.~.U (#_#:#<#p@{.[#}#|#1#2# ", +" 3#4#5#6#7#8#9#0#a#b#c#d#e#f#g#h#i#j#k#S@/#~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.l#m#9.{.~.n#o#p#q#r#s# ", +" t#u#v#w#x#y#z#A#B#C#D#E#F#G#H#I#% J#K#S@T@~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.L#0.l.~.~.{.M#N#O#P#Q#R# ", +" S#T#U#V#W#X#Y#Z#`# $.$+$@$#$$$%$&$*$=$-$a#~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.o.o.;$9.G.~.>$,$'$)$!$~${$]$ ", +" ^$/$($_$:$<$[$}$|$1$2$3$4$5$6$7$8$9$:+<+~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.G.0$a$b$c$d$e$f$g$h$i$j$k$ ", +" [ l$m$n$o$p$q$r$s$t$u$v$w$x$y$z$A$B$C$M#p@~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.;$D$E$F$G$H$I$J$K$L$ ", +" M$N$O$P$Q$R$S$T$U$V$W$X$Y$Z$`$ %.%+%@%<+{.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.#%$%%%p@&%*%=%-%;%>%,% ", +" '%)%!%~%{%]%^%/%(%_%:%<%[%}%|%1%2%3%-$T@~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.4%5%U p@6%7%8%9%0%a%y ", +" b%c%d%e%f%g%h%i%G.[#j%k%l%m%n%o%p%@%q%{.~.~.~.~.~.~.~.~.~.~.~.~.~.~.{.~.~.~.~.~.~.V G.}@r%s%t%u%v%w%M.x%y%z%A% ", +" B%C%D%E%F%G%H%I%V o.<@J%K%L%M%N%O%P%p@~.~.~.~.~.~.~.~.~.U ~.~.U 9.Q%{.~.~.~.~.~.{.%%U {.~.~.{.v@R%S%T%U%V%W% X%$ ", +" Y%Z%`% &.&+&@&#&U ~.{.$&%&&&*&=&-&T@~.~.~.~.~.~.~.~.~.~.~.;&>&,&'&)&!&5+~.~.~.~.{.~&{&]&9.~.p@^&/&(&_&:& <&[&}&|& ", +" 1&2&3&4&5&6&7&8&9&l.~.{.V 0&a&b&c&~.~.~.~.~.~.~.5.d&e&f&g&h&i&j&k&l&m&n&~.~.G.~.~.~.o&p&q&r&s&t&u&v& w&x&y&z&A&B& ", +" C&2&D&E&F&G&G&H&I&J&U ~.~.U K&L&,.~.~.~.~.~.~.~.U M&N&O&P&Q&R&S&T&U&V&W&X&].{.~.~.{./#Y&Z&`& *.*+*@* (.#*$*%*&***=* ", +" -*;*>*,*'*)*!*~*{*]*^*~.5.{.5./*U ~.~.~.~.~.~.{.[#(*_*:*<*[*[*}*|*1*2*3*4*5*U ~.~.6*7*8*9*0*a*b*c*d*e*f*g*h*i*%*j*k*<%l* ", +" m*n*o*p*q*r*s*t*u*v*w*1+~.~.~.~.~.~.~.~.~.~.~.x*y*z*A*B*C*D*E*V U ~.G.~.:.F*G*l.{.R%X+H*I*J*K*L*M*N*O*P*Q*R*S*T*U*V*W*X* ", +" Y*Z*D&`* =.=+=@=#=$=%=&={.~.~.~.~.~.~.~.~.~.~.<+*===-=;=>=,='=)=[#p@!=~={=]=^=/=(=a#&%_=:=<=-#[=}=k$|=1=2=3=4=5=6=7=8=9= ", +" 0=a=b=c=d=e=f=g=h=i=j=k=l=5.~.~.~.~.~.~.~.~.~.V -$m=n===o=p=q=r=s=t=:+u=v=w=x=y=z=A=J.V U ~.V [#B=C=D=1=E=F= G=H=I= ", +" J=K=L=M=N=O=P=Q=R=S=T=U=V=5.U ~.~.~.~.~.~.~.~.~.{.x*W=X=Y=Z=`= -.-+-@-#-$-%-&-*-=---;->-9.x*)=,-'-)-c.!-~- {-]- ", +" ^-/-(-_-:-<-<-[-%.}-|-1-T@~.{.~.~.~.~.~.~.~.~.~.~.V 2-^&3-4-5-6-7-8-9-0-a-b-c-d-e-f-g-h-V@i-j-k-l-T=m-7@n- o-p- ", +" q-r-s-t-u-v-!+2*w-x-y-z-V ~.~.~.~.~.~.~.~.~.~.~.~.~.~./#A-B-C-D-E-F-G-H-I-J-K-L-<@M-W=N-O-P-Q-R-<&S-T-U-V- W- ", +" X-Y-Z-`- ;.;+;@;#;$;q+~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~./#v@W=N#%;&;*;=;-;s=-#;;>;,;';);!;~;{;];^;/;(;H+ ", +" _;:;<;[;};|;1;2;3;4;{.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.{.T@-#5;6;7;8;9;[#V <+0;a;b;c;E-d;e;f;|=g;h; ", +" i;j;V#k;F.l;m;n;o;~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.{.~.{.p@S@s=p;q;~.~.{.r;s;t;u;~$v;w;x;y;z;A; ", +" H+B;C;D;E;F;G;H;~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.{.U ~.~.V E*E*V ~.~.~.{.T@/#I;J;K;L;M;y;N;O; ", +" P;Q;R;S;T;U;~.{.~.~.~.~.~.~.~.~.l.U {.p@~.~.{.V ~.~.5+V;].~.~.~.~.{.{.p@W;X;Y;Z;`;/# >W..>+>N;@> ", +" #>$>%>&>*>G.~.~.~.~.~.~.~.~.{.`.=>V=->;>~.n##&>>T@,>'>].~.~.~.~.~.)>!>i$~>{>]>^>/>(>_>:><>[>}> |>1> ", +" 2>3>4>5>U@U ~.~.~.~.~.~.~.{.6>7>8>9>0>a#a>b>c>d>e>f>~.~.~.V ~.~.g>h>i>1=j>,%k>l>m>n>o>p>q>r>s>t>u>v>w> ", +" x>y>z>A>B>C>5+D>E>~.~.~.~.{.%&F>G>3;s%{.H>I>J>K>L>M>~.V N>O>P>x*Q>R>S>T>U> X%V>W>X>Y>Z>P-`> ,.,+, ", +" @,#,$,%,&,1.*,=,-,;,{.p@V {.X@>,,,Z;V ~.5.`;',),!,~,~.{,],^,/,/&-$F$(,_, :,<,[,},<@|,1,2, ", +" B&3,4, 5,6,7,8,9,0,`;a,b,B+c,d,s=<+~.~.~.a#e,f,g,h,V -#9$i,j,k,l,m,n, o,p,q,r,s,t,u,v, ", +" w,x, y,z,A,B,C,D,E,o@F,G,<+~.~.~.~.~.;;P>j%}@p@H,]#I,J,K,L,M,=+ N,O,P,Q,R,S, ", +" T,U,V,W,X,Y,Z,`, '.'+'x*~.{.O+@%@'#'$'%'a#&'*'='-' ~;;'>' ,''')'!' ", +" ~'{']'^'/'('_'_':'<'['}'{.V |'1'2'3'4'5'}@6'7' 8'K; ", +" v&9'0'a' b'c'd'e'f'1@g'h'G.i'j'k'l'm'n'o'p' y ", +" q'r's' t'u'H+ v'w'x'y' z'A'B' ", +" C'D' E'F' G'H' I'J' ", +" K'L' M' N'O' P'Q' ", +" R' S' ", +" ", +" ", +" ", +" "}; diff --git a/Minilibx/test/open24.xpm b/Minilibx/test/open24.xpm new file mode 100644 index 0000000..f363254 --- /dev/null +++ b/Minilibx/test/open24.xpm @@ -0,0 +1,230 @@ +/* XPM */ +static char *open[] = { +/* width height num_colors chars_per_pixel */ +" 45 55 168 2", +/* colors */ +".. s None c None", +".# c #450304", +".a c #ce7e7c", +".b c #b94344", +".c c #b65254", +".d c #780204", +".e c #b04c4c", +".f c #b00204", +".g c #8a8a64", +".h c #969a24", +".i c #b6b60c", +".j c #cac614", +".k c #cece34", +".l c #cace54", +".m c #caca94", +".n c #c24e4c", +".o c #aa0204", +".p c #9e4244", +".q c #bc0204", +".r c #a40204", +".s c #9e262c", +".t c #8c3a3c", +".u c #5c1414", +".v c #5b0204", +".w c #700204", +".x c #722214", +".y c #b52624", +".z c #8e3234", +".A c #b60204", +".B c #c20204", +".C c #860204", +".D c #560304", +".E c #800204", +".F c #9e0204", +".G c #920204", +".H c #620204", +".I c #a41314", +".J c #996a6c", +".K c #920d09", +".L c #c80204", +".M c #690204", +".N c #980204", +".O c #984c4c", +".P c #e2dedc", +".Q c #ae5e5c", +".R c #bc6a6c", +".S c #a21a1c", +".T c #8a0a04", +".U c #671e1c", +".V c #941b1c", +".W c #b8b4b4", +".X c #e8e6e4", +".Y c #ccb4b4", +".Z c #c07c7c", +".0 c #f3f2eb", +".1 c #b49696", +".2 c #521614", +".3 c #9e5a5c", +".4 c #d4d4d4", +".5 c #a7a5a1", +".6 c #dec4c4", +".7 c #e4d6d4", +".8 c #f4f2f4", +".9 c #cccac4", +"#. c #9a161c", +"## c #8c0204", +"#a c #862c2c", +"#b c #7e5e5c", +"#c c #a39694", +"#d c #6b6667", +"#e c #322624", +"#f c #b09e9c", +"#g c #b23234", +"#h c #500304", +"#i c #222224", +"#j c #2e322c", +"#k c #925c5c", +"#l c #721a1c", +"#m c #6e6e6c", +"#n c #0a0a0c", +"#o c #b2b2b4", +"#p c #8e6264", +"#q c #884444", +"#r c #8c5c5c", +"#s c #121214", +"#t c #b2aeac", +"#u c #c21e1c", +"#v c #6e0e0c", +"#w c #623e3c", +"#x c #b64e4c", +"#y c #bc3634", +"#z c #624e1c", +"#A c #6e727c", +"#B c #824e4c", +"#C c #8b8d87", +"#D c #a09674", +"#E c #766844", +"#F c #7a663c", +"#G c #828c90", +"#H c #beb6a4", +"#I c #3a0204", +"#J c #8e9298", +"#K c #562529", +"#L c #7c3838", +"#M c #bab294", +"#N c #7e4644", +"#O c #929a9c", +"#P c #762a2c", +"#Q c #a60e0c", +"#R c #ae1e1c", +"#S c #460a0c", +"#T c #a6aaa4", +"#U c #6a4a4c", +"#V c #784c50", +"#W c #761214", +"#X c #9e1e1c", +"#Y c #988c90", +"#Z c #821e1c", +"#0 c #7a1618", +"#1 c #7a6e74", +"#2 c #7e7a77", +"#3 c #808688", +"#4 c #828284", +"#5 c #828279", +"#6 c #827a64", +"#7 c #7e765c", +"#8 c #864a34", +"#9 c #825a44", +"a. c #766e54", +"a# c #7e7e74", +"aa c #806464", +"ab c #7e724c", +"ac c #766634", +"ad c #765a2c", +"ae c #8e7e54", +"af c #a69e8c", +"ag c #c7c2ac", +"ah c #9a2a1c", +"ai c #aa3a3c", +"aj c #979894", +"ak c #70684c", +"al c #62522c", +"am c #6e5e3c", +"an c #92866c", +"ao c #968e6c", +"ap c #826e54", +"aq c #84765c", +"ar c #86522c", +"as c #7e4624", +"at c #7e3614", +"au c #6e5254", +"av c #712e2c", +"aw c #7a5654", +"ax c #82727c", +"ay c #a63634", +"az c #8a6a6c", +"aA c #863534", +"aB c #5c1a18", +"aC c #6a2c2c", +"aD c #5e0e14", +"aE c #868684", +"aF c #922624", +"aG c #901614", +"aH c #c21614", +"aI c #520e0c", +"aJ c #805654", +"aK c #b00c0c", +"aL c #c2221c", +/* pixels */ +"..........................................................................................", +"..........................................................................................", +".....................................#.a.#................................................", +"...................................#.b.c.#.#.#.#...........#.d............................", +".................................#.e.f.f.#.g.h.i.j.k.l.m...f.n............................", +".................................d.f.o.f.#.#.#.d.d.#.#.#...f.f.d..........................", +".................................p.q.q.r.s.t.u.v.w.x.d.d.#.d.r.y.d........................", +".................................z.A.B.q.C.D.E.F.G.E.H.E.I.F.q.A.d........................", +".................................J.G.f.G.w.K.f.L.B.B.r.M.f.B.L.A.d........................", +".................................d.w.N.M.O.P.Q.B.B.o.R.S.E.q.q.T.d........................", +".................................d.U.M.V.W.X.Y.q.B.Z.0.1.E.r.N.d..........................", +".................................d.2.r.3.4.5.6.A.f.7.8.9#.###a.#..........................", +"................................#b.d.L#c#d#e#f.N.V.5#d.4#g.E.d............................", +"...............................d#h.r.L#f#i#j#k.M#l#m#n#o.b.r.d............................", +"...............................d#h##.q#g#p#q##.q.N#r#s#t#u.q#v.#..........................", +"..............#j................#w.w.C.r.q##.r.B.f.T#x#y.L.r.M.d..........................", +"............#j#z#j#A#A#j.........d.D.r.M.C.f.r.r.r.q.B.C.N.E#B............................", +"..........#j#C#D#E#z#F#G#j.......d.d.#.G##.w.M.M.C.C.d.G.r.u.d............................", +"....................#E#H#C#j.........d#I.w.F.f.o.o.o.N.M.#.d..............................", +"......................#E#j#J#j......#K.M.#.#.v.w.M.v.##h.H#L.d............................", +"..........................#M#j.......v.F.q.r.d.w.w.C.E.M.v.M#N.d..........................", +"..........................#E#O#j#j#K##.f.L.L.L.B.q.f##.M.v.w.w#P.d.#...d.d................", +"............................#C#E.#.v.o.B.L.L.q.q.q.q.N.M.D#h.M.N.r#Q#R#S.H.J.#............", +"............................#j#T#U.C.q.q.o.G.F.f.q.A.N.d.v.v##.o.q.L.r.C.A###k............", +"..............................#C#V.N.A.N.f.q.F.C.E.f.F.E.H#n#W.K.I#X#a.z.V.q.d#p.d........", +"................................#Y.r.K#Z.K.q.A.G.w#0#b#1#2#3#4#5#5#6#6#7#8.q.G#9..........", +"..................#j#oa..5#j..#J#Ja##4#4aa.o.A##.E.xabacadae#Daf#M#Magah.r.qai.#..........", +"................aja#akalamanaoapaqaaarasat.r.o.E.w.T.T.E.H.#...........#.d.d.#............", +"...........E....#j#j#C#M#j#n#naa#V.O.f.N.F.q.G.d.w.r.C.d.H.#...............#..............", +"...........#.F.F.J#n#n#n#n#n#nauav#p.q.N.d.d.w.M.F.F.E.d.U................................", +".........E.F.E.E.d.z#n.d#n#n#naw.Uax.r##.d.w.D.M.r.N.E.w.d................................", +".........E.F.......d.Fay.E.F#naz.2#A.D#h.r.f.w##.r##.d.H.M................................", +".........F.#...........E.E.F.baAaB#A.#.E.f.r.w.N.N.E.waC.#................................", +".........F.#...............d.F.E#K#d.H.G.F.G.w.N##.d.D.#..................................", +".........F.#....................#Aau.v.E##.w.E.E.w.H.d.......d..av.d......................", +".........E.#..................#j#GaC.M.H.M.d.d.w.H.#.d.d.#aC.w.C##.E.d....................", +"...........F.................5#O...#aD.w.d.w.H.D.M######.G.F.o.f.o.N.3....................", +"...........F.E...........5aEakak.....#.##h#h.v.N.o.f.q.L.L.L.L.L.q.faF....................", +"...........E.E......#E#C.5aq#j.....#.v.N.F.d.N.r.F.r.F#Q.I.o.q.L.L.L.y....................", +".............E.....................#.E.B.qaG.d.d.d.....#.#.....d#x.b......................", +".............E.F...................E.w.L.LaG.#............................................", +"...............E.E.................EaA.q.qaG.#............................................", +"...............E.F.E.................E.r.r#Z.#............................................", +".................E.F.E...............E.G.NaA..............................................", +".................E#uaH.................w.dav..............................................", +"...................E.E.............EaI.M.w.v.#............................................", +"...................................E.D.d.E.waJ............................................", +".....................................C.N.N##.M............................................", +"..................................#W.f.q.A.f.G#q..........................................", +".....................................q.L.L.L.q.V.#........................................", +"...................................#.daK.q.qaL.d..........................................", +".......................................#.#.#..............................................", +"..........................................................................................", +"..........................................................................................", +".........................................................................................." +}; diff --git a/Minilibx/test/open30.xpm b/Minilibx/test/open30.xpm new file mode 100644 index 0000000..87be371 --- /dev/null +++ b/Minilibx/test/open30.xpm @@ -0,0 +1,1439 @@ +/* XPM */ +static char * open30_2_xpm[] = { +"64 64 1372 2", +" c None", +". c #08090D", +"+ c #1A1E23", +"@ c #1F2124", +"# c #060809", +"$ c #1A1E21", +"% c #4F606C", +"& c #3D4145", +"* c #868D93", +"= c #454E56", +"- c #627481", +"; c #667C8A", +"> c #2D3031", +", c #D7E1E7", +"' c #4D5157", +") c #8997A5", +"! c #282E31", +"~ c #333B41", +"{ c #A5C6DB", +"] c #718C9B", +"^ c #000000", +"/ c #181B1F", +"( c #262828", +"_ c #D2DEE7", +": c #B8C5D0", +"< c #151719", +"[ c #08090B", +"} c #272B30", +"| c #2D3037", +"1 c #26282C", +"2 c #1A1D1F", +"3 c #B1CADB", +"4 c #56646E", +"5 c #080809", +"6 c #080A0C", +"7 c #1E2126", +"8 c #98B7C9", +"9 c #A2CAE2", +"0 c #7FA1B5", +"a c #06080A", +"b c #252729", +"c c #A7ADB2", +"d c #272B2E", +"e c #1E2023", +"f c #C8D8E5", +"g c #C9DDED", +"h c #8996A3", +"i c #6B7782", +"j c #C7DFF0", +"k c #CCE0F0", +"l c #AFC1CF", +"m c #47535B", +"n c #B0D3E8", +"o c #7E99A9", +"p c #738493", +"q c #97B4C7", +"r c #53606A", +"s c #6E8996", +"t c #A1CBE3", +"u c #9CC6DE", +"v c #90B5CB", +"w c #171D22", +"x c #1E2629", +"y c #020202", +"z c #ABB3BA", +"A c #BBC4C8", +"B c #222323", +"C c #141617", +"D c #5D6164", +"E c #ACB5BC", +"F c #676D74", +"G c #BDD4E5", +"H c #B3D1E7", +"I c #B0D1E7", +"J c #728A99", +"K c #94AEBF", +"L c #B1D1E7", +"M c #505C64", +"N c #7B98A9", +"O c #A1CBE0", +"P c #99C3D9", +"Q c #475863", +"R c #A0C9DE", +"S c #9CC6DA", +"T c #9ECAE1", +"U c #9CC5DD", +"V c #9AC4DC", +"W c #263137", +"X c #3C4A55", +"Y c #658190", +"Z c #66686B", +"` c #7D8085", +" . c #363839", +".. c #797E81", +"+. c #D2DBE1", +"@. c #DDE9F4", +"#. c #CADEEF", +"$. c #778593", +"%. c #AED0E5", +"&. c #9EC9DE", +"*. c #9EC8DF", +"=. c #9BC1D8", +"-. c #9EC8DE", +";. c #6B8596", +">. c #9BC5DC", +",. c #9BC6DF", +"'. c #9CC5DC", +"). c #688595", +"!. c #6B8698", +"~. c #9CC4DC", +"{. c #9BC4DC", +"]. c #9DC5DD", +"^. c #647D8C", +"/. c #485864", +"(. c #161A1D", +"_. c #36444C", +":. c #95BDD5", +"<. c #566E7E", +"[. c #A4AAAD", +"}. c #E9F2F7", +"|. c #DEEAF6", +"1. c #B5D4E9", +"2. c #A9CFE3", +"3. c #90B3C9", +"4. c #9FCAE1", +"5. c #9BC4DD", +"6. c #7490A2", +"7. c #99C2DB", +"8. c #81A5BA", +"9. c #9CC5DE", +"0. c #98C1DA", +"a. c #5F7889", +"b. c #96BFD8", +"c. c #44545F", +"d. c #565A5E", +"e. c #DFE6EC", +"f. c #E6EEF7", +"g. c #D6E4F2", +"h. c #BFD6E9", +"i. c #A9CCE3", +"j. c #9FC8DD", +"k. c #9DC6DD", +"l. c #9CC4DD", +"m. c #7D9FB0", +"n. c #98C0D6", +"o. c #9AC5DD", +"p. c #97BFD8", +"q. c #9BC5DF", +"r. c #2D3840", +"s. c #626567", +"t. c #E7ECF5", +"u. c #E1EAF5", +"v. c #CEE3F3", +"w. c #B7D6EA", +"x. c #A4CBE0", +"y. c #8AAFC5", +"z. c #647F90", +"A. c #648092", +"B. c #89B0C7", +"C. c #9CC6DF", +"D. c #5D7486", +"E. c #7B9BAF", +"F. c #84A8BF", +"G. c #9BC5DD", +"H. c #96BED5", +"I. c #4B5D69", +"J. c #9BC5DE", +"K. c #536B77", +"L. c #2E3B41", +"M. c #1B2124", +"N. c #3F4F58", +"O. c #4D5152", +"P. c #E7EEF3", +"Q. c #E2EAF5", +"R. c #CEE2F2", +"S. c #BAD5E9", +"T. c #9DC2D7", +"U. c #5C7281", +"V. c #232A31", +"W. c #08090A", +"X. c #121418", +"Y. c #131619", +"Z. c #131719", +"`. c #87ACC3", +" + c #7B9BAE", +".+ c #87ADC3", +"++ c #8FB5CB", +"@+ c #678295", +"#+ c #96C0D8", +"$+ c #607787", +"%+ c #6B8595", +"&+ c #96C1DB", +"*+ c #6A8595", +"=+ c #35424A", +"-+ c #7090A1", +";+ c #15191C", +">+ c #2D3033", +",+ c #DDE5EB", +"'+ c #D2E3F1", +")+ c #BAD7EB", +"!+ c #A9CFE5", +"~+ c #272F35", +"{+ c #1C2227", +"]+ c #4F697B", +"^+ c #6B8FA9", +"/+ c #759CB6", +"(+ c #7BA0BB", +"_+ c #80A5BC", +":+ c #88B0C8", +"<+ c #96C3DB", +"[+ c #8FB6CD", +"}+ c #80A1B3", +"|+ c #556876", +"1+ c #96BFD7", +"2+ c #566B77", +"3+ c #93B8CD", +"4+ c #637A8D", +"5+ c #9DC6DE", +"6+ c #8FB4CA", +"7+ c #55697A", +"8+ c #6F8F9F", +"9+ c #91BDD5", +"0+ c #283239", +"a+ c #050406", +"b+ c #767B80", +"c+ c #BDC6CE", +"d+ c #D4E5F3", +"e+ c #C1D7EA", +"f+ c #A7CDE4", +"g+ c #9FC9DE", +"h+ c #668596", +"i+ c #6D90AA", +"j+ c #5C7994", +"k+ c #60849F", +"l+ c #6286A1", +"m+ c #688CA8", +"n+ c #7298B2", +"o+ c #82A8C2", +"p+ c #8FBAD5", +"q+ c #96C2DB", +"r+ c #89ADC4", +"s+ c #96BED6", +"t+ c #99C2DA", +"u+ c #6C899A", +"v+ c #92BBD2", +"w+ c #9AC4DD", +"x+ c #5B717D", +"y+ c #9EC6DE", +"z+ c #8BB1C9", +"A+ c #718EA0", +"B+ c #94C3DB", +"C+ c #536B78", +"D+ c #3E505F", +"E+ c #4E6373", +"F+ c #2C333C", +"G+ c #070708", +"H+ c #040404", +"I+ c #1A1C1E", +"J+ c #202326", +"K+ c #050606", +"L+ c #23292E", +"M+ c #A1C0D4", +"N+ c #9FC9DD", +"O+ c #97C2DB", +"P+ c #80A8C1", +"Q+ c #668AA6", +"R+ c #4B5D72", +"S+ c #4C647A", +"T+ c #5F80A0", +"U+ c #60859E", +"V+ c #678AA6", +"W+ c #739BB5", +"X+ c #85AEC7", +"Y+ c #92BDD7", +"Z+ c #96BFD5", +"`+ c #627B8A", +" @ c #89B1C9", +".@ c #2B353C", +"+@ c #7597B2", +"@@ c #779CB8", +"#@ c #52697C", +"$@ c #1D2328", +"%@ c #445663", +"&@ c #5E7A8D", +"*@ c #252F37", +"=@ c #090909", +"-@ c #859BB2", +";@ c #859DB8", +">@ c #6E8396", +",@ c #252C33", +"'@ c #9CC4D7", +")@ c #92C0D9", +"!@ c #79A0BA", +"~@ c #6487A3", +"{@ c #566979", +"]@ c #8CB0C2", +"^@ c #51697C", +"/@ c #60849D", +"(@ c #6D8EAC", +"_@ c #7BA0BC", +":@ c #8AB4CE", +"<@ c #95C2DB", +"[@ c #9AC5DC", +"}@ c #95C1DA", +"|@ c #607B8C", +"1@ c #597488", +"2@ c #7EA6BF", +"3@ c #597587", +"4@ c #455664", +"5@ c #668598", +"6@ c #82A9C4", +"7@ c #617F92", +"8@ c #1A2328", +"9@ c #2B3137", +"0@ c #728FAC", +"a@ c #51657B", +"b@ c #6B8AA8", +"c@ c #8EAEC7", +"d@ c #A8C8E2", +"e@ c #92BDD6", +"f@ c #769DBA", +"g@ c #526E87", +"h@ c #7490A0", +"i@ c #A6CDE4", +"j@ c #97BFD4", +"k@ c #55697D", +"l@ c #6286A0", +"m@ c #7399B3", +"n@ c #84ACC5", +"o@ c #92BFD9", +"p@ c #99C4DC", +"q@ c #94C0DA", +"r@ c #4F6575", +"s@ c #7DA5BF", +"t@ c #7FA2BC", +"u@ c #8FB6CE", +"v@ c #95C3DB", +"w@ c #8EB8D2", +"x@ c #6A879D", +"y@ c #111318", +"z@ c #252A30", +"A@ c #81868C", +"B@ c #A5ABAD", +"C@ c #70767C", +"D@ c #38434F", +"E@ c #637F9B", +"F@ c #516980", +"G@ c #799AB5", +"H@ c #A5C3D9", +"I@ c #93BDD6", +"J@ c #779EBA", +"K@ c #445A6B", +"L@ c #93B5C9", +"M@ c #B6D3E8", +"N@ c #AECFE4", +"O@ c #95BDD2", +"P@ c #52687A", +"Q@ c #6486A3", +"R@ c #7092B0", +"S@ c #90BCD6", +"T@ c #97C4DC", +"U@ c #A0C9E0", +"V@ c #99C5DD", +"W@ c #86AEC6", +"X@ c #8FBAD4", +"Y@ c #91BDD6", +"Z@ c #7094AC", +"`@ c #2A353E", +" # c #0B0E10", +".# c #888D90", +"+# c #787D82", +"@# c #465360", +"## c #56697F", +"$# c #A6CADD", +"%# c #5A7382", +"&# c #6C8CAA", +"*# c #A5BED3", +"=# c #A7CAE0", +"-# c #94C1DA", +";# c #7EA4BF", +"># c #415160", +",# c #9DC3D5", +"'# c #B3CFE1", +")# c #AAC3D4", +"!# c #A8CDE4", +"~# c #89ACBE", +"{# c #567088", +"]# c #6C91AC", +"^# c #81A7C2", +"/# c #96C4DC", +"(# c #85A9BD", +"_# c #708C9B", +":# c #5A6E7B", +"<# c #6C8695", +"[# c #97C3DB", +"}# c #8BB5CE", +"|# c #425461", +"1# c #63819E", +"2# c #415465", +"3# c #0B0D0E", +"4# c #607387", +"5# c #687D8C", +"6# c #B8D6E9", +"7# c #7893A2", +"8# c #576F85", +"9# c #A7BACF", +"0# c #B0CEE5", +"a# c #98C4DC", +"b# c #88B1CA", +"c# c #36444E", +"d# c #8FA0AD", +"e# c #73818D", +"f# c #596D81", +"g# c #B4D0E4", +"h# c #A3CDE2", +"i# c #658296", +"j# c #6A8DAB", +"k# c #7BA5C0", +"l# c #94BAD2", +"m# c #6D899B", +"n# c #99C3DC", +"o# c #8EB9D2", +"p# c #7AA0BA", +"q# c #6C8FAB", +"r# c #6484A1", +"s# c #1F252C", +"t# c #121619", +"u# c #7E96B0", +"v# c #7A8A96", +"w# c #BCD7EA", +"x# c #A0C5D9", +"y# c #3C4B57", +"z# c #A9BACD", +"A# c #BCD5E8", +"B# c #84A6BA", +"C# c #8EA1AE", +"D# c #CFD1D4", +"E# c #ECF6FA", +"F# c #ABB7C2", +"G# c #556F84", +"H# c #57626A", +"I# c #5C7078", +"J# c #6C8AA7", +"K# c #80A6C0", +"L# c #91B8D0", +"M# c #94BFD8", +"N# c #87B0CA", +"O# c #7CA2BB", +"P# c #7097AF", +"Q# c #495E6F", +"R# c #0C0E11", +"S# c #3A3F43", +"T# c #8AA3BB", +"U# c #778592", +"V# c #C0D8EB", +"W# c #B3D5E9", +"X# c #404A53", +"Y# c #B2C2D3", +"Z# c #96A1AC", +"`# c #9DB2C3", +" $ c #AEBECE", +".$ c #EDEFF3", +"+$ c #F7FAFC", +"@$ c #B6BFC7", +"#$ c #556E85", +"$$ c #121314", +"%$ c #2B2E2F", +"&$ c #555A5E", +"*$ c #3B4C5B", +"=$ c #6F8EA4", +"-$ c #92BED8", +";$ c #9DC7DF", +">$ c #87ACC1", +",$ c #546A78", +"'$ c #516874", +")$ c #4E6570", +"!$ c #4D6271", +"~$ c #4C6271", +"{$ c #4E677A", +"]$ c #38454E", +"^$ c #6C7278", +"/$ c #86A1B6", +"($ c #5C656C", +"_$ c #A4B0BA", +":$ c #555D64", +"<$ c #657178", +"[$ c #A6B0B5", +"}$ c #939CA1", +"|$ c #D4E4F1", +"1$ c #A0BACE", +"2$ c #B9C7D7", +"3$ c #F6F7F9", +"4$ c #C6CED1", +"5$ c #506A7C", +"6$ c #060607", +"7$ c #676A6B", +"8$ c #91999F", +"9$ c #7CA3BE", +"0$ c #96BCD4", +"a$ c #5B717E", +"b$ c #4B5F6C", +"c$ c #455864", +"d$ c #5B717F", +"e$ c #81A5B9", +"f$ c #98C4DD", +"g$ c #93BFD8", +"h$ c #87B1CA", +"i$ c #7BA1BC", +"j$ c #5A7489", +"k$ c #222A33", +"l$ c #838A92", +"m$ c #9DADBC", +"n$ c #ECF0F5", +"o$ c #F1F9FB", +"p$ c #818A8D", +"q$ c #4A5155", +"r$ c #6A6F72", +"s$ c #7E898F", +"t$ c #E6F1F7", +"u$ c #CADCED", +"v$ c #A0B7CC", +"w$ c #C6D1DF", +"x$ c #AFB3B4", +"y$ c #5F707D", +"z$ c #CBCFD1", +"A$ c #F4F5F6", +"B$ c #66737F", +"C$ c #87B2CB", +"D$ c #90B7CD", +"E$ c #596E7B", +"F$ c #586F7E", +"G$ c #8BB0C8", +"H$ c #91BED6", +"I$ c #83ADC7", +"J$ c #6D8EA7", +"K$ c #3F5161", +"L$ c #2D3A45", +"M$ c #1F2020", +"N$ c #BDC5CC", +"O$ c #E0EDF5", +"P$ c #BBCAD8", +"Q$ c #E1E4E7", +"R$ c #5E6368", +"S$ c #5B5F62", +"T$ c #D9E7F3", +"U$ c #A4C3D6", +"V$ c #89A3B3", +"W$ c #7B91A1", +"X$ c #627990", +"Y$ c #42505A", +"Z$ c #CACCCE", +"`$ c #F9F9F9", +" % c #FDFDFD", +".% c #BCBEC0", +"+% c #5C7689", +"@% c #8DB9D3", +"#% c #8FB5CC", +"$% c #536471", +"%% c #98C1D9", +"&% c #91BED7", +"*% c #81AAC5", +"=% c #597386", +"-% c #41535F", +";% c #6486A2", +">% c #4D667D", +",% c #070809", +"'% c #44484E", +")% c #BEC8D0", +"!% c #8096A6", +"~% c #516473", +"{% c #A9ACAF", +"]% c #8B8F91", +"^% c #A8B3BD", +"/% c #C5DAEB", +"(% c #9FC8E1", +"_% c #8FBCD6", +":% c #81A8C2", +"<% c #6C90AC", +"[% c #56728C", +"}% c #585B5F", +"|% c #CBCDCD", +"1% c #C1C3C6", +"2% c #4F565F", +"3% c #82ABC3", +"4% c #93BCD3", +"5% c #95BED7", +"6% c #8EB9D3", +"7% c #5B788B", +"8% c #627E91", +"9% c #7FA7C1", +"0% c #6C91AB", +"a% c #546F87", +"b% c #6F7376", +"c% c #D5E2EF", +"d% c #A9C4D8", +"e% c #81A1BA", +"f% c #333940", +"g% c #5F6B76", +"h% c #C0D5E8", +"i% c #AACCE2", +"j% c #8EB8D3", +"k% c #7FA5BF", +"l% c #7095B0", +"m% c #4E697E", +"n% c #07090A", +"o% c #0D0F10", +"p% c #7193A6", +"q% c #96C3DC", +"r% c #8EBCD7", +"s% c #91BDD7", +"t% c #8FBBD6", +"u% c #7699AD", +"v% c #4D626F", +"w% c #252D33", +"x% c #101215", +"y% c #0C0D0E", +"z% c #0A0C0E", +"A% c #06090A", +"B% c #7F8488", +"C% c #D7E3F1", +"D% c #B6D0E4", +"E% c #A3C2D7", +"F% c #596872", +"G% c #A9BED0", +"H% c #B4D0E5", +"I% c #9EC8DC", +"J% c #8FB9D4", +"K% c #85ADC7", +"L% c #7FA4BE", +"M% c #4B606F", +"N% c #4E6372", +"O% c #89B6D0", +"P% c #92C1DA", +"Q% c #9DC7DD", +"R% c #95C0DA", +"S% c #94BED8", +"T% c #8BB8D1", +"U% c #7AA0B9", +"V% c #4E667A", +"W% c #344151", +"X% c #0C0D0F", +"Y% c #8A8F92", +"Z% c #D4E6F5", +"`% c #BCD5E9", +" & c #8599A5", +".& c #939DA6", +"+& c #C4DAEB", +"@& c #89A6B9", +"#& c #7D9FB5", +"$& c #98C3DC", +"%& c #95C0D9", +"&& c #7CA2B9", +"*& c #7697AE", +"=& c #698498", +"-& c #7394A8", +";& c #9EC7DF", +">& c #8DB1C4", +",& c #6B8594", +"'& c #50636C", +")& c #50626C", +"!& c #7F9FB1", +"~& c #93B8D0", +"{& c #627A88", +"]& c #90B6CC", +"^& c #93BDD7", +"/& c #87AFC9", +"(& c #7291A7", +"_& c #384651", +":& c #121618", +"<& c #12171B", +"[& c #4F6986", +"}& c #597998", +"|& c #324052", +"1& c #969CA1", +"2& c #D6E6F5", +"3& c #C6DCEE", +"4& c #505A64", +"5& c #82929F", +"6& c #99ABBB", +"7& c #A1B9CA", +"8& c #87A0B0", +"9& c #718EA1", +"0& c #8DB2C9", +"a& c #8BAEC4", +"b& c #586D7D", +"c& c #97C0D9", +"d& c #8DB3C9", +"e& c #95B8CD", +"f& c #9DC0D6", +"g& c #6F8B9C", +"h& c #354249", +"i& c #464E54", +"j& c #8A98A5", +"k& c #AABAC7", +"l& c #86939E", +"m& c #41494F", +"n& c #4A5861", +"o& c #97C1DA", +"p& c #5E7888", +"q& c #5C7482", +"r& c #88ACC2", +"s& c #91BFD7", +"t& c #799CB5", +"u& c #47596A", +"v& c #0D0F12", +"w& c #1A2127", +"x& c #56778D", +"y& c #688BA9", +"z& c #5D7F9E", +"A& c #547391", +"B& c #0E1013", +"C& c #9DA6AB", +"D& c #C8DCED", +"E& c #7A8996", +"F& c #B5CEE0", +"G& c #BCDBEC", +"H& c #B9D5EA", +"I& c #8BA2B2", +"J& c #6C8A9D", +"K& c #97BFD7", +"L& c #3E4E59", +"M& c #92B5CB", +"N& c #535F68", +"O& c #454F56", +"P& c #6F7C87", +"Q& c #ABC0D1", +"R& c #C7DCEE", +"S& c #C5DBED", +"T& c #C2D7EA", +"U& c #BFD8EA", +"V& c #BCD7EB", +"W& c #62717B", +"X& c #5B6F7B", +"Y& c #95C3DC", +"Z& c #8BB2C9", +"`& c #485761", +" * c #42525F", +".* c #6686A1", +"+* c #587896", +"@* c #1B2129", +"#* c #5C7A94", +"$* c #7DA2BD", +"%* c #84AEC7", +"&* c #749BB5", +"** c #5C7E9C", +"=* c #27343F", +"-* c #A4A9B2", +";* c #D9E7F4", +">* c #C8DBEC", +",* c #B1C8DA", +"'* c #5D6C76", +")* c #A8C5D8", +"!* c #A6BDD0", +"~* c #B9D6EA", +"{* c #B9D4E9", +"]* c #8198A8", +"^* c #8AADC3", +"/* c #8CB1CA", +"(* c #96C2D8", +"_* c #A3C7DF", +":* c #ADCDE3", +"<* c #ABD0E4", +"[* c #ADCFE3", +"}* c #AACEE4", +"|* c #A4CDE3", +"1* c #A1CBE1", +"2* c #A3CCE3", +"3* c #A2C9DF", +"4* c #41515A", +"5* c #81A2B5", +"6* c #94C0D7", +"7* c #5E7789", +"8* c #526777", +"9* c #516777", +"0* c #6B8CA5", +"a* c #759CBA", +"b* c #658AA5", +"c* c #587798", +"d* c #1B242B", +"e* c #0E1110", +"f* c #101214", +"g* c #202931", +"h* c #59758E", +"i* c #799FBB", +"j* c #84B1CA", +"k* c #86ACC6", +"l* c #354758", +"m* c #A0A6AE", +"n* c #DAE6F2", +"o* c #C4DCEE", +"p* c #B4D2E8", +"q* c #3E4A53", +"r* c #698091", +"s* c #5D7581", +"t* c #A3CAE0", +"u* c #A6CFE5", +"v* c #A5CCE5", +"w* c #718A9C", +"x* c #98C3DB", +"y* c #83ABC7", +"z* c #2E3B46", +"A* c #33414A", +"B* c #678398", +"C* c #8AB3CE", +"D* c #93BED7", +"E* c #97C4DB", +"F* c #42525E", +"G* c #88ACC0", +"H* c #789EB9", +"I* c #7A9FBB", +"J* c #7EA2BD", +"K* c #779DB5", +"L* c #577081", +"M* c #5B7B9B", +"N* c #1D2229", +"O* c #547390", +"P* c #54728D", +"Q* c #6082A0", +"R* c #688EA9", +"S* c #6689A7", +"T* c #6086A0", +"U* c #6285A1", +"V* c #6B8DAA", +"W* c #718FAB", +"X* c #3E5568", +"Y* c #969DA1", +"Z* c #DBE8F4", +"`* c #95ACBD", +" = c #758B9A", +".= c #A4C9DE", +"+= c #698190", +"@= c #667E8A", +"#= c #7D99AA", +"$= c #7B9BAD", +"%= c #6F8C9A", +"&= c #536976", +"*= c #84ADC6", +"== c #6D92AD", +"-= c #62829E", +";= c #43576A", +">= c #2F3B46", +",= c #5C788A", +"'= c #86AFC8", +")= c #93BED8", +"!= c #93BAD5", +"~= c #93BAD2", +"{= c #92BCD4", +"]= c #7EA2B6", +"^= c #3D4D56", +"/= c #485B67", +"(= c #7596A9", +"_= c #8CBBD4", +":= c #90BCD5", +"<= c #91BFD9", +"[= c #789BAD", +"}= c #465B6A", +"|= c #59789A", +"1= c #5D7F9D", +"2= c #5E839C", +"3= c #59799A", +"4= c #415569", +"5= c #2D3A46", +"6= c #2E3B49", +"7= c #4A647C", +"8= c #587690", +"9= c #39485A", +"0= c #7F8589", +"a= c #D9E8F5", +"b= c #CCDEEE", +"c= c #8597A5", +"d= c #B3D2E3", +"e= c #9BB3C4", +"f= c #B2CEE1", +"g= c #B2D1E7", +"h= c #ABCFE6", +"i= c #94B7CB", +"j= c #495C6A", +"k= c #688498", +"l= c #617B8A", +"m= c #85ADC8", +"n= c #78A0B9", +"o= c #62819B", +"p= c #2E3843", +"q= c #485A6C", +"r= c #67889C", +"s= c #8AB5CF", +"t= c #8EB9D1", +"u= c #6C899B", +"v= c #6E91A7", +"w= c #678399", +"x= c #6888A1", +"y= c #323E48", +"z= c #5B7585", +"A= c #98C5DD", +"B= c #83ACC1", +"C= c #2D373F", +"D= c #4B637C", +"E= c #567694", +"F= c #26313C", +"G= c #15191F", +"H= c #4D647A", +"I= c #252F39", +"J= c #5D6163", +"K= c #DDE9F5", +"L= c #CEDFEE", +"M= c #8898A5", +"N= c #B0CBDC", +"O= c #BFDAEC", +"P= c #BFDBEC", +"Q= c #BBDAEC", +"R= c #BAD7EA", +"S= c #6B808F", +"T= c #7297B0", +"U= c #8CB8D1", +"V= c #95C1D9", +"W= c #91BCD6", +"X= c #86AEC8", +"Y= c #7496B3", +"Z= c #6587A2", +"`= c #384958", +" - c #323F4B", +".- c #546A7C", +"+- c #6C88A1", +"@- c #779AB1", +"#- c #658297", +"$- c #3B4A58", +"%- c #33404B", +"&- c #202830", +"*- c #577287", +"=- c #86B1CC", +"-- c #86ACC0", +";- c #6E8797", +">- c #9CC7DF", +",- c #92BCD5", +"'- c #91BCD5", +")- c #8EB6CE", +"!- c #344453", +"~- c #263039", +"{- c #364452", +"]- c #2B3643", +"^- c #2A2D2E", +"/- c #E1EBF4", +"(- c #D2E4F3", +"_- c #A0B2C3", +":- c #8094A1", +"<- c #BAD8EB", +"[- c #B8D6EA", +"}- c #485A6A", +"|- c #789FB9", +"1- c #90BBD3", +"2- c #94C4DC", +"3- c #88B3CD", +"4- c #7A9EB9", +"5- c #698BA8", +"6- c #4D677C", +"7- c #151A1E", +"8- c #1A2125", +"9- c #171C21", +"0- c #1D2329", +"a- c #1D262E", +"b- c #486073", +"c- c #6A8CAA", +"d- c #7CA2BE", +"e- c #90BDD7", +"f- c #9AC5DE", +"g- c #7493A2", +"h- c #708B99", +"i- c #8CB7D1", +"j- c #7494AB", +"k- c #68889F", +"l- c #6A8FA5", +"m- c #7BA2BC", +"n- c #171D21", +"o- c #1D262F", +"p- c #212B36", +"q- c #09090B", +"r- c #BBC2C9", +"s- c #D4E4F2", +"t- c #C1D9EB", +"u- c #44515A", +"v- c #92B5C9", +"w- c #6B8795", +"x- c #4E687E", +"y- c #7EA6C0", +"z- c #91BED8", +"A- c #93BFD9", +"B- c #8CB5D0", +"C- c #7DA4BE", +"D- c #6F92AE", +"E- c #6687A5", +"F- c #526C85", +"G- c #415669", +"H- c #384655", +"I- c #6589A4", +"J- c #6E92AE", +"K- c #80A8C2", +"L- c #92BCD6", +"M- c #91BFD8", +"N- c #799AAF", +"O- c #6A8796", +"P- c #81AAC3", +"Q- c #577187", +"R- c #1F2930", +"S- c #192027", +"T- c #1B2227", +"U- c #0D1010", +"V- c #0E1012", +"W- c #070709", +"X- c #5C6062", +"Y- c #DCE8F3", +"Z- c #C4DCEF", +"`- c #9BB3C6", +" ; c #3A424F", +".; c #313A44", +"+; c #35424C", +"@; c #374655", +"#; c #6E91AD", +"$; c #87B2CC", +"%; c #799EBA", +"&; c #618298", +"*; c #7095AF", +"=; c #435663", +"-; c #80A7C0", +";; c #95C4DC", +">; c #779CB3", +",; c #526D7E", +"'; c #516A7A", +"); c #526B7B", +"!; c #465764", +"~; c #34414E", +"{; c #5C7E9A", +"]; c #2B3741", +"^; c #4B657F", +"/; c #5C7D9C", +"(; c #557088", +"_; c #0F0F10", +":; c #B9C2CA", +"<; c #CCDFEF", +"[; c #B4CDE1", +"}; c #8DAEC8", +"|; c #6F93AE", +"1; c #678CA6", +"2; c #6E92AF", +"3; c #81A8C1", +"4; c #8FBBD5", +"5; c #8DB9D2", +"6; c #6D8FA2", +"7; c #586F82", +"8; c #394851", +"9; c #86B0C6", +"0; c #85AFC8", +"a; c #6F94AF", +"b; c #698DA8", +"c; c #6889A7", +"d; c #5E7E9F", +"e; c #475D75", +"f; c #2E3C4A", +"g; c #5D7E9D", +"h; c #405465", +"i; c #36393B", +"j; c #D7E5F1", +"k; c #A4C5DC", +"l; c #668496", +"m; c #7595AB", +"n; c #7798AE", +"o; c #97C2DA", +"p; c #789DB3", +"q; c #8BB1C8", +"r; c #93C0D9", +"s; c #8BB5CF", +"t; c #85AFC9", +"u; c #82AAC6", +"v; c #5F7C95", +"w; c #1E252C", +"x; c #54728E", +"y; c #587899", +"z; c #5A7B9B", +"A; c #2D3843", +"B; c #798086", +"C; c #D1E3F1", +"D; c #B7D3E8", +"E; c #7E98AB", +"F; c #181C1F", +"G; c #46525F", +"H; c #80A1B8", +"I; c #99C3DB", +"J; c #85ACC2", +"K; c #21272D", +"L; c #0A0B0D", +"M; c #53718C", +"N; c #577797", +"O; c #1B2229", +"P; c #0D0E0F", +"Q; c #B3BDC4", +"R; c #CADDED", +"S; c #B4D3E7", +"T; c #2B3339", +"U; c #2F3840", +"V; c #7899AC", +"W; c #93C1D9", +"X; c #8FBCD5", +"Y; c #8BB6D1", +"Z; c #8DB8D2", +"`; c #92BFD8", +" > c #678092", +".> c #547089", +"+> c #5C7F9B", +"@> c #1F262E", +"#> c #202223", +"$> c #B1BECB", +"%> c #C3D9EB", +"&> c #7B8D99", +"*> c #708B9A", +"=> c #85ABC1", +"-> c #7FA3BA", +";> c #92BBD3", +">> c #7CA0B4", +",> c #97BDD4", +"'> c #657E8F", +")> c #93BDD4", +"!> c #88ADC7", +"~> c #6F94AE", +"{> c #526A7E", +"]> c #65849B", +"^> c #799DBB", +"/> c #84AFC9", +"(> c #8FB9D2", +"_> c #323C45", +":> c #516C84", +"<> c #658AA4", +"[> c #5B7C9B", +"}> c #2E3A49", +"|> c #2A3038", +"1> c #252D3A", +"2> c #1B1E20", +"3> c #ADBFCF", +"4> c #C0D6E7", +"5> c #B0CDE2", +"6> c #8EB3C9", +"7> c #526975", +"8> c #6B899D", +"9> c #597183", +"0> c #90BAD5", +"a> c #94C2DA", +"b> c #82ABC5", +"c> c #495E6E", +"d> c #82A8C3", +"e> c #81A4BA", +"f> c #7594A5", +"g> c #87ABC3", +"h> c #4D6573", +"i> c #6689A6", +"j> c #526E85", +"k> c #243037", +"l> c #607B96", +"m> c #7699B6", +"n> c #789EB5", +"o> c #303D48", +"p> c #7498B4", +"q> c #7094AF", +"r> c #597792", +"s> c #242F39", +"t> c #1A1D25", +"u> c #374553", +"v> c #4D677D", +"w> c #14191E", +"x> c #040505", +"y> c #171A1D", +"z> c #8A9FAD", +"A> c #BCD9EC", +"B> c #B5D3E7", +"C> c #A2CAE1", +"D> c #9DC7DE", +"E> c #9EC7DD", +"F> c #3B4A57", +"G> c #455867", +"H> c #98C2DB", +"I> c #85B0CC", +"J> c #7496B2", +"K> c #4C606F", +"L> c #6E8EA3", +"M> c #7EA0B6", +"N> c #91BBD3", +"O> c #8DB7D1", +"P> c #90BAD4", +"Q> c #96C1DA", +"R> c #3B4853", +"S> c #688AA5", +"T> c #4C657A", +"U> c #1B2026", +"V> c #2B3C44", +"W> c #5F7A90", +"X> c #587284", +"Y> c #536978", +"Z> c #88B1CC", +"`> c #759AB8", +" , c #617E9A", +"., c #556F85", +"+, c #20272E", +"@, c #323D48", +"#, c #333E4A", +"$, c #060707", +"%, c #4A5159", +"&, c #ACC3D5", +"*, c #ACCFE5", +"=, c #5A6874", +"-, c #AACDE1", +";, c #9CC6DC", +">, c #35414C", +",, c #769AB2", +"', c #80AAC5", +"), c #6F92AB", +"!, c #38464F", +"~, c #7EA4B9", +"{, c #97C3DC", +"], c #7A9FB6", +"^, c #3F505C", +"/, c #6D8DA6", +"(, c #1E282E", +"_, c #080909", +":, c #090A0C", +"<, c #344452", +"[, c #3B4857", +"}, c #7799AE", +"|, c #8DB6D1", +"1, c #66869E", +"2, c #3D4957", +"3, c #536C84", +"4, c #353F4C", +"5, c #111215", +"6, c #65727E", +"7, c #A6BCCD", +"8, c #5D6972", +"9, c #AED0E6", +"0, c #99C5DC", +"a, c #8DB5D0", +"b, c #8DB5CE", +"c, c #90BBD5", +"d, c #84AAC5", +"e, c #8EBBD5", +"f, c #80A7C1", +"g, c #6C8DA2", +"h, c #85AFC6", +"i, c #61839B", +"j, c #374352", +"k, c #576D83", +"l, c #80A6C1", +"m, c #81A4BB", +"n, c #111315", +"o, c #111418", +"p, c #4C6378", +"q, c #33424C", +"r, c #37454D", +"s, c #8DB4CF", +"t, c #7397B3", +"u, c #3A495A", +"v, c #0D0F13", +"w, c #27303A", +"x, c #272E36", +"y, c #0F1012", +"z, c #90A4B2", +"A, c #A8CBE2", +"B, c #91BCD4", +"C, c #80ABC3", +"D, c #567083", +"E, c #67899D", +"F, c #94C2DB", +"G, c #95C1DB", +"H, c #779CB2", +"I, c #60849E", +"J, c #64849F", +"K, c #1A1F22", +"L, c #405061", +"M, c #79A1BD", +"N, c #324051", +"O, c #6183A1", +"P, c #6B8FAD", +"Q, c #6485A2", +"R, c #34444F", +"S, c #060606", +"T, c #2D3339", +"U, c #B2CBDF", +"V, c #94BCD5", +"W, c #7DA2BA", +"X, c #3F5264", +"Y, c #5A7991", +"Z, c #7195B3", +"`, c #7BA5BD", +" ' c #81AAC6", +".' c #88B2CC", +"+' c #8EBBD4", +"@' c #8AB2CC", +"#' c #82ADC7", +"$' c #7092A5", +"%' c #95C2DA", +"&' c #41525F", +"*' c #6387A3", +"=' c #475F72", +"-' c #21282F", +";' c #5B7288", +">' c #0D0F11", +",' c #0B0E11", +"'' c #212C36", +")' c #26323C", +"!' c #161B20", +"~' c #55616D", +"{' c #9BB9D0", +"]' c #799EB6", +"^' c #27313A", +"/' c #1A222B", +"(' c #5D7E99", +"_' c #6587A4", +":' c #6789A6", +"<' c #6B8EAB", +"[' c #628097", +"}' c #6D8B9D", +"|' c #769AAF", +"1' c #6E91A9", +"2' c #6C8EAD", +"3' c #6E91AF", +"4' c #3C4D59", +"5' c #8BB1CB", +"6' c #232D32", +"7' c #13171B", +"8' c #232B32", +"9' c #839AAF", +"0' c #789BB3", +"a' c #283138", +"b' c #0C0E0F", +"c' c #242B33", +"d' c #3D4D5B", +"e' c #435768", +"f' c #4B6176", +"g' c #283137", +"h' c #8DB4CC", +"i' c #41535E", +"j' c #405362", +"k' c #3C4F60", +"l' c #3C4E5B", +"m' c #2B353E", +"n' c #526876", +"o' c #92BAD3", +"p' c #1B1F23", +"q' c #31383F", +"r' c #7F9CB6", +"s' c #21292F", +"t' c #29333F", +"u' c #1F252E", +"v' c #090A0E", +"w' c #4D626E", +"x' c #96BDD3", +"y' c #191D20", +"z' c #13181B", +"A' c #80A4BC", +"B' c #1B2027", +"C' c #5D7182", +"D' c #2C383F", +"E' c #364857", +"F' c #1A2028", +"G' c #333F49", +"H' c #7FA2B5", +"I' c #4A5E6E", +"J' c #232E35", +"K' c #252D35", +"L' c #2F3A41", +"M' c #0A0B0E", +"N' c #14191D", +"O' c #5A717F", +"P' c #212931", +"Q' c #222B34", +"R' c #101216", +"S' c #21272B", +" ", +" ", +" ", +" . ", +" + ", +" @ # $ % ", +" & * = - ; ", +" > , ' ) ! ~ { ] ", +" ^ / ( _ : < [ } | 1 2 3 4 5 6 7 8 9 0 a ", +" b c d e f g h i j k l m n o p q r s t u v w x ", +" y z A B C D E F G H I J K L M N O P Q R S T U U V W X Y ", +" Z ` ...+.@.#.$.%.O &.*.=.-.;.>.,.'.).!.~.~.~.{.].^./.(._.:.<. ", +" b [.}.|.#.1.2.3.4.{.~.~.~.~.5.6.5.~.7.8.{.~.~.~.~.9.0.a.b.].c. ", +" d.e.f.g.h.i.j.k.{.~.~.~.~.l.~.m.% n.~.o.{.{.~.~.~.~.p.V 9.~.q.r. ", +" s.t.u.v.w.x.u y.z.A.B.5.~.~.5.C.D.E.F.~.~.G.~.~.~.G.H.I.J.~.~.J.K.L. M.N. ", +" O.P.Q.R.S.T.U.V.W.X.Y.Z.`.~.~.5. +.+++@+U ~.~.~.~.~.#+$+%+,.~.~.G.&+*+=+-+;+ ", +" >+,+Q.'+)+!+~+{+]+^+/+(+_+:+<+~.[+}+U 9.|+5.~.~.~.~.1+2+3+4+5+~.].6+7+8+9+0+ ", +" a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+5.U ~.U r+s+~.~.~.t+u+v+w+x+y+~.z+A+t+B+C+D+E+ F+G+ ", +" H+I+J+K+L+M+N+O+P+Q+R+S+T+U+V+W+X+Y+V ~.~.~.~.U ~.~.~.o.9.{.Z+`+9.~.~.~.V @.@+@@@#@ $@%@&@*@ ", +" =@-@;@>@,@'@'.)@!@~@{@]@^@/@l+(@_@:@<@~.~.~.U {.~.~.~.{.~.~.{.[@~.~.~.~.}@|@1@2@3@4@5@6@7@8@ ", +" 9@0@a@b@c@d@-.e@f@g@h@i@j@k@l@V+m@n@o@p@~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.{.q@r@s@t@u@v@w@x@y@ ", +"z@A@B@C@D@E@X F@G@H@R I@J@K@L@M@N@O@P@Q@R@o+S@T@~.~.~.~.~.~.~.~.~.~.~.~.~.~.9.U@V@W@X@<+V Y@Z@`@ # ", +" .#+#@###$#%#&#*#=#-#;#>#,#'#)#!#~#{#]#^#S@/#~.~.~.~.~.~.~.~.~.~.~.~.~.U (#_#:#<#p@{.[#}#|#1#2# ", +" 3#4#5#6#7#8#9#0#a#b#c#d#e#f#g#h#i#j#k#S@/#~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.l#m#9.{.~.n#o#p#q#r#s# ", +" t#u#v#w#x#y#z#A#B#C#D#E#F#G#H#I#% J#K#S@T@~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.L#0.l.~.~.{.M#N#O#P#Q#R# ", +" S#T#U#V#W#X#Y#Z#`# $.$+$@$#$$$%$&$*$=$-$a#~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.o.o.;$9.G.~.>$,$'$)$!$~${$]$ ", +" ^$/$($_$:$<$[$}$|$1$2$3$4$5$6$7$8$9$:+<+~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.G.0$a$b$c$d$e$f$g$h$i$j$k$ ", +" [ l$m$n$o$p$q$r$s$t$u$v$w$x$y$z$A$B$C$M#p@~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.;$D$E$F$G$H$I$J$K$L$ ", +" M$N$O$P$Q$R$S$T$U$V$W$X$Y$Z$`$ %.%+%@%<+{.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.#%$%%%p@&%*%=%-%;%>%,% ", +" '%)%!%~%{%]%^%/%(%_%:%<%[%}%|%1%2%3%-$T@~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.4%5%U p@6%7%8%9%0%a%y ", +" b%c%d%e%f%g%h%i%G.[#j%k%l%m%n%o%p%@%q%{.~.~.~.~.~.~.~.~.~.~.~.~.~.~.{.~.~.~.~.~.~.V G.}@r%s%t%u%v%w%M.x%y%z%A% ", +" B%C%D%E%F%G%H%I%V o.<@J%K%L%M%N%O%P%p@~.~.~.~.~.~.~.~.~.U ~.~.U 9.Q%{.~.~.~.~.~.{.%%U {.~.~.{.v@R%S%T%U%V%W% X%$ ", +" Y%Z%`% &.&+&@&#&U ~.{.$&%&&&*&=&-&T@~.~.~.~.~.~.~.~.~.~.~.;&>&,&'&)&!&5+~.~.~.~.{.~&{&]&9.~.p@^&/&(&_&:& <&[&}&|& ", +" 1&2&3&4&5&6&7&8&9&l.~.{.V 0&a&b&c&~.~.~.~.~.~.~.5.d&e&f&g&h&i&j&k&l&m&n&~.~.G.~.~.~.o&p&q&r&s&t&u&v& w&x&y&z&A&B& ", +" C&2&D&E&F&G&G&H&I&J&U ~.~.U K&L&,.~.~.~.~.~.~.~.U M&N&O&P&Q&R&S&T&U&V&W&X&].{.~.~.{./#Y&Z&`& *.*+*@* (.#*$*%*&***=* ", +" -*;*>*,*'*)*!*~*{*]*^*~.5.{.5./*U ~.~.~.~.~.~.{.[#(*_*:*<*[*[*}*|*1*2*3*4*5*U ~.~.6*7*8*9*0*a*b*c*d*e*f*g*h*i*%*j*k*<%l* ", +" m*n*o*p*q*r*s*t*u*v*w*1+~.~.~.~.~.~.~.~.~.~.~.x*y*z*A*B*C*D*E*V U ~.G.~.:.F*G*l.{.R%X+H*I*J*K*L*M*N*O*P*Q*R*S*T*U*V*W*X* ", +" Y*Z*D&`* =.=+=@=#=$=%=&={.~.~.~.~.~.~.~.~.~.~.<+*===-=;=>=,='=)=[#p@!=~={=]=^=/=(=a#&%_=:=<=-#[=}=k$|=1=2=3=4=5=6=7=8=9= ", +" 0=a=b=c=d=e=f=g=h=i=j=k=l=5.~.~.~.~.~.~.~.~.~.V -$m=n===o=p=q=r=s=t=:+u=v=w=x=y=z=A=J.V U ~.V [#B=C=D=1=E=F= G=H=I= ", +" J=K=L=M=N=O=P=Q=R=S=T=U=V=5.U ~.~.~.~.~.~.~.~.~.{.x*W=X=Y=Z=`= -.-+-@-#-$-%-&-*-=---;->-9.x*)=,-'-)-c.!-~- {-]- ", +" ^-/-(-_-:-<-<-[-%.}-|-1-T@~.{.~.~.~.~.~.~.~.~.~.~.V 2-^&3-4-5-6-7-8-9-0-a-b-c-d-e-f-g-h-V@i-j-k-l-T=m-7@n- o-p- ", +" q-r-s-t-u-v-!+2*w-x-y-z-V ~.~.~.~.~.~.~.~.~.~.~.~.~.~./#A-B-C-D-E-F-G-H-I-J-K-L-<@M-W=N-O-P-Q-R-<&S-T-U-V- W- ", +" X-Y-Z-`- ;.;+;@;#;$;q+~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~./#v@W=N#%;&;*;=;-;s=-#;;>;,;';);!;~;{;];^;/;(;H+ ", +" _;:;<;[;};|;1;2;3;4;{.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.{.T@-#5;6;7;8;9;[#V <+0;a;b;c;E-d;e;f;|=g;h; ", +" i;j;V#k;F.l;m;n;o;~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.{.~.{.p@S@s=p;q;~.~.{.r;s;t;u;~$v;w;x;y;z;A; ", +" H+B;C;D;E;F;G;H;~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.{.U ~.~.V E*E*V ~.~.~.{.T@/#I;J;K;L;M;y;N;O; ", +" P;Q;R;S;T;U;~.{.~.~.~.~.~.~.~.~.l.U {.p@~.~.{.V ~.~.5+V;].~.~.~.~.{.{.p@W;X;Y;Z;`;/# >W..>+>N;@> ", +" #>$>%>&>*>G.~.~.~.~.~.~.~.~.{.`.=>V=->;>~.n##&>>T@,>'>].~.~.~.~.~.)>!>i$~>{>]>^>/>(>_>:><>[>}> |>1> ", +" 2>3>4>5>U@U ~.~.~.~.~.~.~.{.6>7>8>9>0>a#a>b>c>d>e>f>~.~.~.V ~.~.g>h>i>1=j>,%k>l>m>n>o>p>q>r>s>t>u>v>w> ", +" x>y>z>A>B>C>5+D>E>~.~.~.~.{.%&F>G>3;s%{.H>I>J>K>L>M>~.V N>O>P>x*Q>R>S>T>U> X%V>W>X>Y>Z>P-`> ,.,+, ", +" @,#,$,%,&,1.*,=,-,;,{.p@V {.X@>,,,Z;V ~.5.`;',),!,~,~.{,],^,/,/&-$F$(,_, :,<,[,},<@|,1,2, ", +" B&3,4, 5,6,7,8,9,0,`;a,b,B+c,d,s=<+~.~.~.a#e,f,g,h,V -#9$i,j,k,l,m,n, o,p,q,r,s,t,u,v, ", +" w,x, y,z,A,B,C,D,E,o@F,G,<+~.~.~.~.~.;;P>j%}@p@H,]#I,J,K,L,M,=+ N,O,P,Q,R,S, ", +" T,U,V,W,X,Y,Z,`, '.'+'x*~.{.O+@%@'#'$'%'a#&'*'='-' ~;;'>' ,''')'!' ", +" ~'{']'^'/'('_'_':'<'['}'{.V |'1'2'3'4'5'}@6'7' 8'K; ", +" v&9'0'a' b'c'd'e'f'1@g'h'G.i'j'k'l'm'n'o'p' y ", +" q'r's' t'u'H+ v'w'x'y' z'A'B' ", +" C'D' E'F' G'H' I'J' ", +" K'L' M' N'O' P'Q' ", +" R' S' ", +" ", +" ", +" ", +" "}; diff --git a/Minilibx/test/run_tests.sh b/Minilibx/test/run_tests.sh new file mode 100755 index 0000000..d33cd5e --- /dev/null +++ b/Minilibx/test/run_tests.sh @@ -0,0 +1,94 @@ +#!/usr/bin/env sh + +# This very basic script simulate user inputs for the CI +# Feel free to update, improve or remove it if proper +# intergration tests and/or unit tests are added. + +set -e + +BOLD="\033[1m" +RESET="\033[0m" +LIGHT_RED="\033[91m" +LIGHT_GREEN="\033[92m" +LIGHT_CYAN="\033[96m" + +logging(){ + local type=$1; shift + printf "${LIGHT_CYAN}${BOLD}run_tests${RESET} [%b] : %b\n" "$type" "$*" +} +log_info(){ + logging "${LIGHT_GREEN}info${RESET}" "$@" +} +log_error(){ + logging "${LIGHT_RED}error${RESET}" "$@" >&2 + exit 1 +} + + +PID="" + +# to properly kill child process executed in background on exit +at_exit() { + status=$? + [ $status -eq 0 ] && log_info "Seem all went well" && exit 0 + # Code for non-zero exit: + if ! kill -s TERM "$PID" 2>/dev/null || ! wait "$PID" ; then + log_error "Pid [$PID] died with status $status " + fi + log_error "Something went wrong. Pid [$PID] has been killed. Status code $status" +} +# to properly quit from ctrl+c (SIGINT Signal) +sigint_handler(){ + kill -s TERM "$PID" + wait + log_info "Tests abort" + exit 1 +} + +# look at test/main.c and run ./mlx-test to understand what this function does +test_default_main(){ + ${MAKE} -f Makefile.gen all + ./mlx-test & + PID="$!" + log_info "./mlx-test running in background, pid:" $PID + + i=25 # waiting 25s mlx-test to be ready for inputs. + while [ $i -gt 0 ]; do + if ! ps -p $PID > /dev/null ; then + wait $PID + fi + log_info "countdown" $i + sleep 1 + i=$((i - 1)) + done + log_info "Ready to \"just play\" using xdotool" + wid1=$(xdotool search --name Title1) + wid2=$(xdotool search --name Title2) + wid3=$(xdotool search --name Title3) + + xdotool windowfocus $wid3 + log_info "Focus Win3: Testing move mouse 100 100" + xdotool mousemove 100 100 + log_info "Focus Win3: Testing move mouse 200 200" + xdotool mousemove 200 200 + log_info "Focus Win3: Pressing escape to destroy window \"Win3\"" + xdotool key Escape + + log_info "Focus Win2: Pressing escape to stop program" + xdotool windowfocus $wid2 + xdotool key Escape +} + +main(){ + case $(uname) in + FreeBSD) MAKE=gmake ;; + *) MAKE=make ;; + esac + cd $(dirname $0) + trap at_exit EXIT + trap sigint_handler INT + + test_default_main +} + +main "$@" From a8ad4d01b037c85a02ae15f698dd6f42688db83f Mon Sep 17 00:00:00 2001 From: ReverseSky Date: Mon, 14 Oct 2024 17:06:45 +0200 Subject: [PATCH 13/80] manque partie texture --- Makefile | 4 +- algo.c | 172 ++----------------------------------------------------- algo.h | 15 +++-- move.c | 86 ++++++++++++++++++++++++++++ render.c | 138 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 243 insertions(+), 172 deletions(-) create mode 100644 move.c create mode 100644 render.c diff --git a/Makefile b/Makefile index 2e563ef..914e14e 100644 --- a/Makefile +++ b/Makefile @@ -6,13 +6,13 @@ # By: greg +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/07/29 13:08:42 by greg #+# #+# # -# Updated: 2024/10/09 03:07:50 by greg ### ########.fr # +# Updated: 2024/10/14 15:33:53 by greg ### ########.fr # # # # **************************************************************************** # NAME = cub3d -SRC = algo.c +SRC = algo.c move.c render.c OBJS = ${SRC:.c=.o} diff --git a/algo.c b/algo.c index 4c40eb5..fde3b35 100644 --- a/algo.c +++ b/algo.c @@ -6,15 +6,13 @@ /* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/11 05:16:06 by greg ### ########.fr */ +/* Updated: 2024/10/14 16:47:50 by greg ### ########.fr */ /* */ /* ************************************************************************** */ #include "algo.h" -#include -#include -int worldMap[mapWidth][mapHeight]= +int worldMap[mapWidth][mapHeight] = { {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, @@ -42,7 +40,6 @@ int worldMap[mapWidth][mapHeight]= {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} }; - static int initalgo(t_ray *ray) { ray->posX = 13; @@ -53,165 +50,8 @@ static int initalgo(t_ray *ray) ray->planeY = 0.66; // FOV de 66 degres ray->movespeed = 0.1; ray->rotspeed = 0.1; - return (0); -} - -static int render(t_ray *ray) -{ - int x; - double width = 640; - double height = 480; - int hit; - int side; - int *img_data = (int *)mlx_get_data_addr(ray->img_ptr, &(int){32}, &(int){width * 4}, &(int){0}); - - // clear image data - ft_bzero(img_data, width * height * sizeof(int)); - - x = 0; - while (x < width) - { - // position et direction du rayon - ray->cameraX = 2 * x / width - 1; - ray->raydirX = ray->dirX + ray->planeX * ray->cameraX; - ray->raydirY = ray->dirY + ray->planeY * ray->cameraX; - - ray->mapX = (int)ray->posX; - ray->mapY = (int)ray->posY; - - ray->deltadistX = (ray->raydirX == 0) ? 1e30 : fabs(1 / ray->raydirX); - ray->deltadistY = (ray->raydirY == 0) ? 1e30 : fabs(1 / ray->raydirY); - - //calculate step and initial sideDist - if (ray->raydirX < 0) - { - ray->stepX = -1; - ray->sidedistX = (ray->posX - ray->mapX) * ray->deltadistX; - } - else - { - ray->stepX = 1; - ray->sidedistX = (ray->mapX + 1.0 - ray->posX) * ray->deltadistX; - } - if (ray->raydirY < 0) - { - ray->stepY = -1; - ray->sidedistY = (ray->posY - ray->mapY) * ray->deltadistY; - } - else - { - ray->stepY = 1; - ray->sidedistY = (ray->mapY + 1.0 - ray->posY) * ray->deltadistY; - } - - hit = 0; - while(hit == 0) - { - //jump to next map square, either in x-direction, or in y-direction - if(ray->sidedistX < ray->sidedistY) - { - ray->sidedistX += ray->deltadistX; - ray->mapX += ray->stepX; - side = 0; - } - else - { - ray->sidedistY += ray->deltadistY; - ray->mapY += ray->stepY; - side = 1; - } - //Check if ray has hit a wall - if(worldMap[ray->mapX][ray->mapY] == 1) - hit = 1; - } - if(side == 0) - ray->perpwalldist = (ray->sidedistX - ray->deltadistX); - else - ray->perpwalldist = (ray->sidedistY - ray->deltadistY); - //Calculate height of line to draw on screen - int lineHeight = (int)(height / ray->perpwalldist); - - //calculate lowest and highest pixel to fill in current stripe - int drawStart = -lineHeight / 2 + height / 2; - if(drawStart < 0) - drawStart = 0; - int drawEnd = lineHeight / 2 + height / 2; - if(drawEnd >= height) - drawEnd = height - 1; - - // draw vertical line - int y = 0; - while (y <= drawStart) - { - img_data[y * (int)width + x] = 0x29f8ff;; - y++; - } - y = drawStart; - while (y <= drawEnd) - { - img_data[y * (int)width + x] = 0xFF0000; - y++; - } - y++; - while (y <= height) - { - img_data[y * (int)width + x] = 0xFF985C; - y++; - } - - x++; - } - - // put image to window - mlx_put_image_to_window(ray->mlx_ptr, ray->win_ptr, ray->img_ptr, 0, 0); - return (0); -} - -static int keypress(int keycode, t_ray *ray) -{ - //move forward if no wall in front of you - if (keycode == 119) - { - if (worldMap[(int)((ray->posX + ray->dirX * ray->movespeed))][(int)(ray->posY)] != 1) - ray->posX += ray->dirX * ray->movespeed; - if (worldMap[(int)(ray->posX)][(int)(ray->posY + ray->dirY * ray->movespeed)] != 1) - ray->posY += ray->dirY * ray->movespeed; - } - //move backwards if no wall behind you - if (keycode == 115) - { - if (worldMap[(int)(ray->posX - ray->dirX * ray->movespeed)][(int)(ray->posY)] != 1) - ray->posX -= ray->dirX * ray->movespeed; - if (worldMap[(int)(ray->posX)][(int)(ray->posY - ray->dirY * ray->movespeed)] != 1) - ray->posY -= ray->dirY * ray->movespeed; - } - //rotate to the right - if (keycode == 100) - { - //both camera direction and camera plane must be rotated - ray->oldDirX = ray->dirX; - ray->dirX = ray->dirX * cos(-ray->rotspeed) - ray->dirY * sin(-ray->rotspeed); - ray->dirY = ray->oldDirX * sin(-ray->rotspeed) + ray->dirY * cos(-ray->rotspeed); - ray->oldPlaneX = ray->planeX; - ray->planeX = ray->planeX * cos(-ray->rotspeed) - ray->planeY * sin(-ray->rotspeed); - ray->planeY = ray->oldPlaneX * sin(-ray->rotspeed) + ray->planeY * cos(-ray->rotspeed); - } - //rotate to the left - if (keycode == 97) - { - //both camera direction and camera plane must be rotated - ray->oldDirX = ray->dirX; - ray->dirX = ray->dirX * cos(ray->rotspeed) - ray->dirY * sin(ray->rotspeed); - ray->dirY = ray->oldDirX * sin(ray->rotspeed) + ray->dirY * cos(ray->rotspeed); - ray->oldPlaneX = ray->planeX; - ray->planeX = ray->planeX * cos(ray->rotspeed) - ray->planeY * sin(ray->rotspeed); - ray->planeY = ray->oldPlaneX * sin(ray->rotspeed) + ray->planeY * cos(ray->rotspeed); - } - - if (keycode == 65307) - exit(0); - // render the updated frame after key press - render(ray); + ray->width = 1920; + ray->height = 1080; return (0); } @@ -221,8 +61,8 @@ int main(void) // Initialisation ray.mlx_ptr = mlx_init(); - ray.win_ptr = mlx_new_window(ray.mlx_ptr, 640, 480, "cub3d"); - ray.img_ptr = mlx_new_image(ray.mlx_ptr, 640, 480); + ray.win_ptr = mlx_new_window(ray.mlx_ptr, 1920, 1080, "cub3d"); + ray.img_ptr = mlx_new_image(ray.mlx_ptr, 1920, 1080); initalgo(&ray); diff --git a/algo.h b/algo.h index 3b5585c..e0b5081 100644 --- a/algo.h +++ b/algo.h @@ -6,7 +6,7 @@ /* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/11 04:32:39 by greg ### ########.fr */ +/* Updated: 2024/10/14 16:47:36 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,8 +18,8 @@ #include "Minilibx/mlx.h" #include "Minilibx/mlx_int.h" # include "Libft/libft.h" -#define mapWidth 24 -#define mapHeight 24 +#define mapWidth 24 // TEST +#define mapHeight 24 // TEST typedef struct s_ray { @@ -58,6 +58,13 @@ typedef struct s_ray int *img_data; int mapX; int mapY; + double width; + double height; } t_ray; -#endif + +extern int worldMap[mapWidth][mapHeight]; // TEST +int keypress(int keycode, t_ray *ray); +int render(t_ray *ray); + +#endif \ No newline at end of file diff --git a/move.c b/move.c new file mode 100644 index 0000000..00c7fef --- /dev/null +++ b/move.c @@ -0,0 +1,86 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* move.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: greg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/14 15:03:10 by greg #+# #+# */ +/* Updated: 2024/10/14 16:53:56 by greg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "algo.h" + +static int move_forward(t_ray *ray) +{ + if (worldMap[(int)((ray->posX + ray->dirX * ray->movespeed))][(int)(ray->posY)] != 1) + ray->posX += ray->dirX * ray->movespeed; + if (worldMap[(int)(ray->posX)][(int)(ray->posY + ray->dirY * ray->movespeed)] != 1) + ray->posY += ray->dirY * ray->movespeed; + return(0); +} + +static int move_backward(t_ray *ray) +{ + if (worldMap[(int)(ray->posX - ray->dirX * ray->movespeed)][(int)(ray->posY)] != 1) + ray->posX -= ray->dirX * ray->movespeed; + if (worldMap[(int)(ray->posX)][(int)(ray->posY - ray->dirY * ray->movespeed)] != 1) + ray->posY -= ray->dirY * ray->movespeed; + return(0); +} + +static int move_right(t_ray *ray) +{ + //both camera direction and camera plane must be rotated + ray->oldDirX = ray->dirX; + ray->dirX = ray->dirX * cos(ray->rotspeed) - ray->dirY * sin(ray->rotspeed); + ray->dirY = ray->oldDirX * sin(ray->rotspeed) + ray->dirY * cos(ray->rotspeed); + ray->oldPlaneX = ray->planeX; + ray->planeX = ray->planeX * cos(ray->rotspeed) - ray->planeY * sin(ray->rotspeed); + ray->planeY = ray->oldPlaneX * sin(ray->rotspeed) + ray->planeY * cos(ray->rotspeed); + return(0); +} + +static int move_left(t_ray *ray) +{ + //both camera direction and camera plane must be rotated + ray->oldDirX = ray->dirX; + ray->dirX = ray->dirX * cos(-ray->rotspeed) - ray->dirY * sin(-ray->rotspeed); + ray->dirY = ray->oldDirX * sin(-ray->rotspeed) + ray->dirY * cos(-ray->rotspeed); + ray->oldPlaneX = ray->planeX; + ray->planeX = ray->planeX * cos(-ray->rotspeed) - ray->planeY * sin(-ray->rotspeed); + ray->planeY = ray->oldPlaneX * sin(-ray->rotspeed) + ray->planeY * cos(-ray->rotspeed); + return(0); +} + + + + +int keypress(int keycode, t_ray *ray) +{ + if (keycode == 119) //move forward if no wall in front of you + { + move_forward(ray); + } + if (keycode == 115) //move backwards if no wall behind you + { + move_backward(ray); + } + if (keycode == 100) //rotate to the right + { + move_left(ray); + } + if (keycode == 97) //rotate to the left + { + move_right(ray); + } + if (keycode == 65307) + { + mlx_destroy_window(ray->mlx_ptr, ray->win_ptr); + exit(0); + } + // render the updated frame after key pressd + render(ray); + return (0); +} diff --git a/render.c b/render.c new file mode 100644 index 0000000..89bd1d3 --- /dev/null +++ b/render.c @@ -0,0 +1,138 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* render.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: greg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/14 14:55:05 by greg #+# #+# */ +/* Updated: 2024/10/14 16:53:21 by greg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "algo.h" + + +static int init_step(t_ray *ray) +{ + if (ray->raydirX < 0) + { + ray->stepX = -1; + ray->sidedistX = (ray->posX - ray->mapX) * ray->deltadistX; + } + else + { + ray->stepX = 1; + ray->sidedistX = (ray->mapX + 1.0 - ray->posX) * ray->deltadistX; + } + if (ray->raydirY < 0) + { + ray->stepY = -1; + ray->sidedistY = (ray->posY - ray->mapY) * ray->deltadistY; + } + else + { + ray->stepY = 1; + ray->sidedistY = (ray->mapY + 1.0 - ray->posY) * ray->deltadistY; + } + return (0); +} + +static int ray_pos(t_ray *ray, int x) +{ + // position et direction du rayon + ray->cameraX = 2 * x / ray->width - 1; + ray->raydirX = ray->dirX + ray->planeX * ray->cameraX; + ray->raydirY = ray->dirY + ray->planeY * ray->cameraX; + + ray->mapX = (int)ray->posX; + ray->mapY = (int)ray->posY; + + ray->deltadistX = (ray->raydirX == 0) ? 1e30 : fabs(1 / ray->raydirX); + ray->deltadistY = (ray->raydirY == 0) ? 1e30 : fabs(1 / ray->raydirY); + return (0); +} +int draw_img(t_ray *ray, int drawStart, int *img_data, int drawEnd, int x) +{ + // draw vertical line + int y = 0; + while (y <= drawStart) + { + img_data[y * (int)ray->width + x] = 0x29f8ff;; + y++; + } + y = drawStart; + while (y <= drawEnd) + { + img_data[y * (int)ray->width + x] = 0xFF0000; + y++; + } + y++; + while (y <= ray->height) + { + img_data[y * (int)ray->width + x] = 0xFF985C; + y++; + } + return (0); +} + +void find_wall(t_ray *ray) +{ + int side; + int hit; + + hit = 0; + while(hit == 0) + { + if(ray->sidedistX < ray->sidedistY) //jump to next map square, either in x-direction, or in y-direction + { + ray->sidedistX += ray->deltadistX; + ray->mapX += ray->stepX; + side = 0; + } + else + { + ray->sidedistY += ray->deltadistY; + ray->mapY += ray->stepY; + side = 1; + } + if(worldMap[ray->mapX][ray->mapY] == 1) //Check if ray has hit a wall + hit = 1; + } + if(side == 0) + ray->perpwalldist = (ray->sidedistX - ray->deltadistX); + else + ray->perpwalldist = (ray->sidedistY - ray->deltadistY); +} + +int render(t_ray *ray) +{ + int x; + int lineHeight; + int *img_data; + int drawStart; + int drawEnd; + + img_data = (int *)mlx_get_data_addr(ray->img_ptr, &(int){32}, &(int){ray->width * 4}, &(int){0}); + ft_bzero(img_data, ray->width * ray->height * sizeof(int)); // clear image data + x = 0; + while (x++ < ray->width) + { + ray_pos(ray, x); + init_step(ray); //calculate step and initial sideDist + find_wall(ray); + lineHeight = (int)(ray->height / ray->perpwalldist); //Calculate height of line to draw on screen + drawStart = -lineHeight / 2 + ray->height / 2; //calculate lowest and highest pixel to fill in current stripe + if(drawStart < 0) + drawStart = 0; + drawEnd = lineHeight / 2 + ray->height / 2; + if(drawEnd >= ray->height) + drawEnd = ray->height - 1; + draw_img(ray, drawStart, img_data, drawEnd, x); + } + mlx_put_image_to_window(ray->mlx_ptr, ray->win_ptr, ray->img_ptr, 0, 0); + return (0); +} + + + From 8c0d63300df995490317fd3bdce3ccb9cd50e3b2 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Mon, 14 Oct 2024 18:35:50 +0200 Subject: [PATCH 14/80] s --- algo.c | 338 +++++++++++++++++++++++++++++++++++---------------------- algo.h | 54 +++------ 2 files changed, 227 insertions(+), 165 deletions(-) diff --git a/algo.c b/algo.c index 4c40eb5..f6b4518 100644 --- a/algo.c +++ b/algo.c @@ -3,32 +3,67 @@ /* ::: :::::::: */ /* algo.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: greg +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/11 05:16:06 by greg ### ########.fr */ +/* Updated: 2024/10/14 18:35:03 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "algo.h" #include #include +#include +#include + +static void *g_mlx = NULL; +static void *g_win = NULL; + +static t_ray g_ray; + +// int worldMap[mapWidth][mapHeight]= +// { +// {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, +// {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, +// {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, +// {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, +// {1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1}, +// {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1}, +// {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1}, +// {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1}, +// {1,0,0,0,0,0,1,1,0,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1}, +// {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, +// {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, +// {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, +// {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, +// {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, +// {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, +// {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, +// {1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, +// {1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, +// {1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, +// {1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, +// {1,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, +// {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, +// {1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, +// {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} +// }; int worldMap[mapWidth][mapHeight]= { {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, + {1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,1,1,0,0,1,1,1,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1}, + {1,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,1,1,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1}, + {1,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,1,1,0,0,1,1,0,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1}, + {1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1}, - {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1}, - {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,0,0,0,0,1,1,0,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1}, - {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, @@ -42,197 +77,244 @@ int worldMap[mapWidth][mapHeight]= {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} }; - -static int initalgo(t_ray *ray) +static void vector_from_rotation( + double *vecX, double *vecY, double angle, double norm) { - ray->posX = 13; - ray->posY = 10; - ray->dirX = -1; - ray->dirY = 0; - ray->planeX = 0; - ray->planeY = 0.66; // FOV de 66 degres - ray->movespeed = 0.1; - ray->rotspeed = 0.1; + *vecX = -cos(angle) * norm; + *vecY = sin(angle) * norm; +} + +static int initalgo() +{ + // TODO from map + g_ray.posX = 14; + g_ray.posY = 6.5; + g_ray.rot = 0; return (0); } -static int render(t_ray *ray) +static int render(u_int32_t *img_data) { - int x; - double width = 640; - double height = 480; - int hit; - int side; - int *img_data = (int *)mlx_get_data_addr(ray->img_ptr, &(int){32}, &(int){width * 4}, &(int){0}); + int x; // px // clear image data - ft_bzero(img_data, width * height * sizeof(int)); + ft_bzero(img_data, SCREEN_WIDTH * SCREEN_HEIGHT * sizeof(int)); // TODO why + // 1 + double dirX, dirY, planeX, planeY; + vector_from_rotation(&dirX, &dirY, g_ray.rot, 1); + vector_from_rotation(&planeX, &planeY, g_ray.rot + PI/2, FOV); + x = 0; - while (x < width) + while (x < SCREEN_WIDTH) { - // position et direction du rayon - ray->cameraX = 2 * x / width - 1; - ray->raydirX = ray->dirX + ray->planeX * ray->cameraX; - ray->raydirY = ray->dirY + ray->planeY * ray->cameraX; + // case player on map (cases) + int mapX = (int)g_ray.posX; + // case player on map (cases) + int mapY = (int)g_ray.posY; - ray->mapX = (int)ray->posX; - ray->mapY = (int)ray->posY; - - ray->deltadistX = (ray->raydirX == 0) ? 1e30 : fabs(1 / ray->raydirX); - ray->deltadistY = (ray->raydirY == 0) ? 1e30 : fabs(1 / ray->raydirY); - - //calculate step and initial sideDist - if (ray->raydirX < 0) + // vector ray direction (1) + double raydirX, raydirY; { - ray->stepX = -1; - ray->sidedistX = (ray->posX - ray->mapX) * ray->deltadistX; + // ray direction in [-1;+1]. the highter the more to the right (1) + double ray_direction = 2 * x / (double)SCREEN_WIDTH - 1; + raydirX = dirX + planeX * ray_direction; + raydirY = dirY + planeY * ray_direction; + } + + // longueur du rayon dans une même colonne de cases (cases) + double deltadistX = (raydirX == 0) ? 1e30 : fabs(1 / raydirX); + // longueur du rayon dans une même ligne de cases (cases) + double deltadistY = (raydirY == 0) ? 1e30 : fabs(1 / raydirY); + + // longueur du rayon entre pos actuelle et pos du prochain coté ouest ou est d'une box + double sidedistX; + // longueur du rayon entre pos actuelle et pos du prochain coté nord ou sub d'une box + double sidedistY; + + // direction du rayon sur x (+1 or -1) + int stepX; + // direction du rayon sur y (+1 or -1) + int stepY; + + if (raydirX < 0) + { + stepX = -1; + sidedistX = (g_ray.posX - mapX) * deltadistX; } else { - ray->stepX = 1; - ray->sidedistX = (ray->mapX + 1.0 - ray->posX) * ray->deltadistX; + stepX = 1; + sidedistX = (mapX + 1.0 - g_ray.posX) * deltadistX; } - if (ray->raydirY < 0) + if (raydirY < 0) { - ray->stepY = -1; - ray->sidedistY = (ray->posY - ray->mapY) * ray->deltadistY; + stepY = -1; + sidedistY = (g_ray.posY - mapY) * deltadistY; } else { - ray->stepY = 1; - ray->sidedistY = (ray->mapY + 1.0 - ray->posY) * ray->deltadistY; + stepY = 1; + sidedistY = (mapY + 1.0 - g_ray.posY) * deltadistY; } - hit = 0; - while(hit == 0) + bool hit = false; + bool side; + while(!hit) { - //jump to next map square, either in x-direction, or in y-direction - if(ray->sidedistX < ray->sidedistY) + // jump to next map square, either in x-direction, or in y-direction + if(sidedistX < sidedistY) { - ray->sidedistX += ray->deltadistX; - ray->mapX += ray->stepX; - side = 0; + sidedistX += deltadistX; + mapX += stepX; + side = false; } else { - ray->sidedistY += ray->deltadistY; - ray->mapY += ray->stepY; - side = 1; + sidedistY += deltadistY; + mapY += stepY; + side = true; } - //Check if ray has hit a wall - if(worldMap[ray->mapX][ray->mapY] == 1) - hit = 1; + // check if ray has hit a wall + if(worldMap[mapX][mapY] == 1) + hit = true; } - if(side == 0) - ray->perpwalldist = (ray->sidedistX - ray->deltadistX); - else - ray->perpwalldist = (ray->sidedistY - ray->deltadistY); - //Calculate height of line to draw on screen - int lineHeight = (int)(height / ray->perpwalldist); - //calculate lowest and highest pixel to fill in current stripe - int drawStart = -lineHeight / 2 + height / 2; + // calcul lenght of ray (shortest perpendicular distance between wall and camera plane) (1) + double perpwalldist; + if(!side) + perpwalldist = (sidedistX - deltadistX); + else + perpwalldist = (sidedistY - deltadistY); + + // calculate height of line to draw on screen (px) + int lineHeight = (int)(SCREEN_HEIGHT / perpwalldist); + + // calculate lowest and highest pixel to fill in current stripe + int drawStart = -lineHeight / 2 + SCREEN_HEIGHT / 2; if(drawStart < 0) drawStart = 0; - int drawEnd = lineHeight / 2 + height / 2; - if(drawEnd >= height) - drawEnd = height - 1; + int drawEnd = lineHeight / 2 + SCREEN_HEIGHT / 2; + if(drawEnd >= SCREEN_HEIGHT) + drawEnd = SCREEN_HEIGHT - 1; // draw vertical line int y = 0; - while (y <= drawStart) + while (y < drawStart) { - img_data[y * (int)width + x] = 0x29f8ff;; + img_data[y * SCREEN_WIDTH + x] = COLOR_CEILING; y++; } - y = drawStart; - while (y <= drawEnd) + while (y < drawEnd) { - img_data[y * (int)width + x] = 0xFF0000; + img_data[y * SCREEN_WIDTH + x] = COLOR_WALL; y++; } - y++; - while (y <= height) + while (y < SCREEN_HEIGHT) { - img_data[y * (int)width + x] = 0xFF985C; + img_data[y * SCREEN_WIDTH + x] = COLOR_FLOOR; y++; } - + x++; } - // put image to window - mlx_put_image_to_window(ray->mlx_ptr, ray->win_ptr, ray->img_ptr, 0, 0); return (0); } -static int keypress(int keycode, t_ray *ray) -{ - //move forward if no wall in front of you - if (keycode == 119) +static void draw_screen() { + int bpp; + int size_line; + int endian; + + void *img_ptr = mlx_new_image(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT); + u_int32_t *img_data = (u_int32_t *)mlx_get_data_addr(img_ptr, &bpp, &size_line, &endian); + if (bpp != 32 || endian != 0) { - if (worldMap[(int)((ray->posX + ray->dirX * ray->movespeed))][(int)(ray->posY)] != 1) - ray->posX += ray->dirX * ray->movespeed; - if (worldMap[(int)(ray->posX)][(int)(ray->posY + ray->dirY * ray->movespeed)] != 1) - ray->posY += ray->dirY * ray->movespeed; + // TODO manage error better + printf("image format error (got bpp == %i, endian == %i)\n", bpp, endian); + exit(1); + } + render(img_data); + mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); +} + +static int keypress(int keycode) +{ + double dirX, dirY, planeX, planeY; + vector_from_rotation(&dirX, &dirY, g_ray.rot, 1); + vector_from_rotation(&planeX, &planeY, g_ray.rot + PI/2, FOV); + + //move forward if no wall in front of you + if (keycode == XK_Up || keycode == XK_z || keycode == XK_w) + { + if (worldMap[(int)((g_ray.posX + dirX * MOVE_SPEED))][(int)(g_ray.posY)] != 1) + g_ray.posX += dirX * MOVE_SPEED; + if (worldMap[(int)(g_ray.posX)][(int)(g_ray.posY + dirY * MOVE_SPEED)] != 1) + g_ray.posY += dirY * MOVE_SPEED; } //move backwards if no wall behind you - if (keycode == 115) + if (keycode == XK_Down || keycode == XK_s) { - if (worldMap[(int)(ray->posX - ray->dirX * ray->movespeed)][(int)(ray->posY)] != 1) - ray->posX -= ray->dirX * ray->movespeed; - if (worldMap[(int)(ray->posX)][(int)(ray->posY - ray->dirY * ray->movespeed)] != 1) - ray->posY -= ray->dirY * ray->movespeed; + if (worldMap[(int)(g_ray.posX - dirX * MOVE_SPEED)][(int)(g_ray.posY)] != 1) + g_ray.posX -= dirX * MOVE_SPEED; + if (worldMap[(int)(g_ray.posX)][(int)(g_ray.posY - dirY * MOVE_SPEED)] != 1) + g_ray.posY -= dirY * MOVE_SPEED; } //rotate to the right - if (keycode == 100) + if (keycode == XK_Right || keycode == XK_d) { - //both camera direction and camera plane must be rotated - ray->oldDirX = ray->dirX; - ray->dirX = ray->dirX * cos(-ray->rotspeed) - ray->dirY * sin(-ray->rotspeed); - ray->dirY = ray->oldDirX * sin(-ray->rotspeed) + ray->dirY * cos(-ray->rotspeed); - ray->oldPlaneX = ray->planeX; - ray->planeX = ray->planeX * cos(-ray->rotspeed) - ray->planeY * sin(-ray->rotspeed); - ray->planeY = ray->oldPlaneX * sin(-ray->rotspeed) + ray->planeY * cos(-ray->rotspeed); + g_ray.rot += ROT_SPEED; + // double oldDirX; + // double oldPlaneX; + // //both camera direction and camera plane must be rotated + // oldDirX = dirX; + // dirX = dirX * cos(-ROT_SPEED) - dirY * sin(-ROT_SPEED); + // dirY = oldDirX * sin(-ROT_SPEED) + dirY * cos(-ROT_SPEED); + // oldPlaneX = planeX; + // planeX = planeX * cos(-ROT_SPEED) - planeY * sin(-ROT_SPEED); + // planeY = oldPlaneX * sin(-ROT_SPEED) + planeY * cos(-ROT_SPEED); } //rotate to the left - if (keycode == 97) + if (keycode == XK_Left || keycode == XK_q || keycode == XK_a) { - //both camera direction and camera plane must be rotated - ray->oldDirX = ray->dirX; - ray->dirX = ray->dirX * cos(ray->rotspeed) - ray->dirY * sin(ray->rotspeed); - ray->dirY = ray->oldDirX * sin(ray->rotspeed) + ray->dirY * cos(ray->rotspeed); - ray->oldPlaneX = ray->planeX; - ray->planeX = ray->planeX * cos(ray->rotspeed) - ray->planeY * sin(ray->rotspeed); - ray->planeY = ray->oldPlaneX * sin(ray->rotspeed) + ray->planeY * cos(ray->rotspeed); + g_ray.rot -= ROT_SPEED; + // double oldDirX; + // double oldPlaneX; + // //both camera direction and camera plane must be rotated + // oldDirX = dirX; + // dirX = dirX * cos(ROT_SPEED) - dirY * sin(ROT_SPEED); + // dirY = oldDirX * sin(ROT_SPEED) + dirY * cos(ROT_SPEED); + // oldPlaneX = planeX; + // planeX = planeX * cos(ROT_SPEED) - planeY * sin(ROT_SPEED); + // planeY = oldPlaneX * sin(ROT_SPEED) + planeY * cos(ROT_SPEED); } - if (keycode == 65307) + if (keycode == XK_Escape) exit(0); + + printf("x:%f y:%f\n", g_ray.posX, g_ray.posY); // render the updated frame after key press - render(ray); + draw_screen(); return (0); } int main(void) { - t_ray ray; - // Initialisation - ray.mlx_ptr = mlx_init(); - ray.win_ptr = mlx_new_window(ray.mlx_ptr, 640, 480, "cub3d"); - ray.img_ptr = mlx_new_image(ray.mlx_ptr, 640, 480); + g_mlx = mlx_init(); + g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d"); - initalgo(&ray); + initalgo(); // hook keypress - mlx_hook(ray.win_ptr, 2, 1L<<0, keypress, &ray); + mlx_hook(g_win, 2, 1L<<0, keypress, NULL); + // render the initial frame - render(&ray); + draw_screen(); // start the mlx loop - mlx_loop(ray.mlx_ptr); + mlx_loop(g_mlx); return (0); } diff --git a/algo.h b/algo.h index 3b5585c..48207f2 100644 --- a/algo.h +++ b/algo.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* algo.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: greg +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/11 04:32:39 by greg ### ########.fr */ +/* Updated: 2024/10/14 18:26:05 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,46 +18,26 @@ #include "Minilibx/mlx.h" #include "Minilibx/mlx_int.h" # include "Libft/libft.h" -#define mapWidth 24 -#define mapHeight 24 +#define mapWidth 24 // cases +#define mapHeight 24 // cases +#define MOVE_SPEED 0.1 // cases +#define PI 3.1415926535 +#define ROT_SPEED (PI / 16) // rad +#define COLOR_WALL 0xFF0000 // 0xRRGGBB +#define COLOR_CEILING 0x29f8ff // 0xRRGGBB +#define COLOR_FLOOR 0xFF985C // 0xRRGGBB +#define SCREEN_WIDTH 640 // px +#define SCREEN_HEIGHT 480 // px +#define FOV 0.66 // ? TODO unit typedef struct s_ray { - // pos player on map + // pos player on map (cases) double posX; + // pos player on map (cases) double posY; - // orientation player on map - double dirX; - double dirY; - // orientation cam on map - double planeX; - double planeY; - // camera pos - double cameraX; - // direction rayon - double raydirX; - double raydirY; - // longueur du rayon entre pos actuelle et pos du prochain cote d'une box - double sidedistX; - double sidedistY; - // longueur du rayon entre pos d'un cote d'une box jusqu'a pos du prochain cote d'une box - double deltadistX; - double deltadistY; - // calcul lenght of ray (shortest perpendicular distance between wall and camera plane) - double perpwalldist; - // step direction (can be -1 or +1) - int stepX; - int stepY; - double movespeed; - double rotspeed; - double oldDirX; - double oldPlaneX; - void *mlx_ptr; - void *win_ptr; - void *img_ptr; - int *img_data; - int mapX; - int mapY; + // player rotation (rad) + double rot; } t_ray; #endif From fc2b243daa5c92ed6a33bf1d21441871708a9231 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Tue, 15 Oct 2024 12:56:03 +0200 Subject: [PATCH 15/80] s --- Makefile | 4 +- algo.c | 209 ++----------------------------------------------------- algo.h | 19 ++++- move.c | 73 +++++++++++++++++++ render.c | 142 +++++++++++++++++++++++++++++++++++++ utils.c | 19 +++++ 6 files changed, 259 insertions(+), 207 deletions(-) create mode 100644 move.c create mode 100644 render.c create mode 100644 utils.c diff --git a/Makefile b/Makefile index 2e563ef..c3df77e 100644 --- a/Makefile +++ b/Makefile @@ -6,13 +6,13 @@ # By: greg +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/07/29 13:08:42 by greg #+# #+# # -# Updated: 2024/10/09 03:07:50 by greg ### ########.fr # +# Updated: 2024/10/15 12:53:36 by marvin ### ########.fr # # # # **************************************************************************** # NAME = cub3d -SRC = algo.c +SRC = $(wildcard *.c) OBJS = ${SRC:.c=.o} diff --git a/algo.c b/algo.c index f6b4518..fbc1eec 100644 --- a/algo.c +++ b/algo.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* algo.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/14 18:35:03 by mc ### ########.fr */ +/* Updated: 2024/10/15 12:54:19 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,10 +16,9 @@ #include #include -static void *g_mlx = NULL; -static void *g_win = NULL; - -static t_ray g_ray; +void *g_mlx = NULL; +void *g_win = NULL; +t_ray g_ray; // int worldMap[mapWidth][mapHeight]= // { @@ -77,13 +76,6 @@ int worldMap[mapWidth][mapHeight]= {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} }; -static void vector_from_rotation( - double *vecX, double *vecY, double angle, double norm) -{ - *vecX = -cos(angle) * norm; - *vecY = sin(angle) * norm; -} - static int initalgo() { // TODO from map @@ -93,136 +85,7 @@ static int initalgo() return (0); } -static int render(u_int32_t *img_data) -{ - int x; // px - - // clear image data - ft_bzero(img_data, SCREEN_WIDTH * SCREEN_HEIGHT * sizeof(int)); // TODO why - - // 1 - double dirX, dirY, planeX, planeY; - vector_from_rotation(&dirX, &dirY, g_ray.rot, 1); - vector_from_rotation(&planeX, &planeY, g_ray.rot + PI/2, FOV); - - x = 0; - while (x < SCREEN_WIDTH) - { - // case player on map (cases) - int mapX = (int)g_ray.posX; - // case player on map (cases) - int mapY = (int)g_ray.posY; - - // vector ray direction (1) - double raydirX, raydirY; - { - // ray direction in [-1;+1]. the highter the more to the right (1) - double ray_direction = 2 * x / (double)SCREEN_WIDTH - 1; - raydirX = dirX + planeX * ray_direction; - raydirY = dirY + planeY * ray_direction; - } - - // longueur du rayon dans une même colonne de cases (cases) - double deltadistX = (raydirX == 0) ? 1e30 : fabs(1 / raydirX); - // longueur du rayon dans une même ligne de cases (cases) - double deltadistY = (raydirY == 0) ? 1e30 : fabs(1 / raydirY); - - // longueur du rayon entre pos actuelle et pos du prochain coté ouest ou est d'une box - double sidedistX; - // longueur du rayon entre pos actuelle et pos du prochain coté nord ou sub d'une box - double sidedistY; - - // direction du rayon sur x (+1 or -1) - int stepX; - // direction du rayon sur y (+1 or -1) - int stepY; - - if (raydirX < 0) - { - stepX = -1; - sidedistX = (g_ray.posX - mapX) * deltadistX; - } - else - { - stepX = 1; - sidedistX = (mapX + 1.0 - g_ray.posX) * deltadistX; - } - if (raydirY < 0) - { - stepY = -1; - sidedistY = (g_ray.posY - mapY) * deltadistY; - } - else - { - stepY = 1; - sidedistY = (mapY + 1.0 - g_ray.posY) * deltadistY; - } - - bool hit = false; - bool side; - while(!hit) - { - // jump to next map square, either in x-direction, or in y-direction - if(sidedistX < sidedistY) - { - sidedistX += deltadistX; - mapX += stepX; - side = false; - } - else - { - sidedistY += deltadistY; - mapY += stepY; - side = true; - } - // check if ray has hit a wall - if(worldMap[mapX][mapY] == 1) - hit = true; - } - - // calcul lenght of ray (shortest perpendicular distance between wall and camera plane) (1) - double perpwalldist; - if(!side) - perpwalldist = (sidedistX - deltadistX); - else - perpwalldist = (sidedistY - deltadistY); - - // calculate height of line to draw on screen (px) - int lineHeight = (int)(SCREEN_HEIGHT / perpwalldist); - - // calculate lowest and highest pixel to fill in current stripe - int drawStart = -lineHeight / 2 + SCREEN_HEIGHT / 2; - if(drawStart < 0) - drawStart = 0; - int drawEnd = lineHeight / 2 + SCREEN_HEIGHT / 2; - if(drawEnd >= SCREEN_HEIGHT) - drawEnd = SCREEN_HEIGHT - 1; - - // draw vertical line - int y = 0; - while (y < drawStart) - { - img_data[y * SCREEN_WIDTH + x] = COLOR_CEILING; - y++; - } - while (y < drawEnd) - { - img_data[y * SCREEN_WIDTH + x] = COLOR_WALL; - y++; - } - while (y < SCREEN_HEIGHT) - { - img_data[y * SCREEN_WIDTH + x] = COLOR_FLOOR; - y++; - } - - x++; - } - - return (0); -} - -static void draw_screen() { +void draw_screen(void) { int bpp; int size_line; int endian; @@ -239,66 +102,6 @@ static void draw_screen() { mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); } -static int keypress(int keycode) -{ - double dirX, dirY, planeX, planeY; - vector_from_rotation(&dirX, &dirY, g_ray.rot, 1); - vector_from_rotation(&planeX, &planeY, g_ray.rot + PI/2, FOV); - - //move forward if no wall in front of you - if (keycode == XK_Up || keycode == XK_z || keycode == XK_w) - { - if (worldMap[(int)((g_ray.posX + dirX * MOVE_SPEED))][(int)(g_ray.posY)] != 1) - g_ray.posX += dirX * MOVE_SPEED; - if (worldMap[(int)(g_ray.posX)][(int)(g_ray.posY + dirY * MOVE_SPEED)] != 1) - g_ray.posY += dirY * MOVE_SPEED; - } - //move backwards if no wall behind you - if (keycode == XK_Down || keycode == XK_s) - { - if (worldMap[(int)(g_ray.posX - dirX * MOVE_SPEED)][(int)(g_ray.posY)] != 1) - g_ray.posX -= dirX * MOVE_SPEED; - if (worldMap[(int)(g_ray.posX)][(int)(g_ray.posY - dirY * MOVE_SPEED)] != 1) - g_ray.posY -= dirY * MOVE_SPEED; - } - //rotate to the right - if (keycode == XK_Right || keycode == XK_d) - { - g_ray.rot += ROT_SPEED; - // double oldDirX; - // double oldPlaneX; - // //both camera direction and camera plane must be rotated - // oldDirX = dirX; - // dirX = dirX * cos(-ROT_SPEED) - dirY * sin(-ROT_SPEED); - // dirY = oldDirX * sin(-ROT_SPEED) + dirY * cos(-ROT_SPEED); - // oldPlaneX = planeX; - // planeX = planeX * cos(-ROT_SPEED) - planeY * sin(-ROT_SPEED); - // planeY = oldPlaneX * sin(-ROT_SPEED) + planeY * cos(-ROT_SPEED); - } - //rotate to the left - if (keycode == XK_Left || keycode == XK_q || keycode == XK_a) - { - g_ray.rot -= ROT_SPEED; - // double oldDirX; - // double oldPlaneX; - // //both camera direction and camera plane must be rotated - // oldDirX = dirX; - // dirX = dirX * cos(ROT_SPEED) - dirY * sin(ROT_SPEED); - // dirY = oldDirX * sin(ROT_SPEED) + dirY * cos(ROT_SPEED); - // oldPlaneX = planeX; - // planeX = planeX * cos(ROT_SPEED) - planeY * sin(ROT_SPEED); - // planeY = oldPlaneX * sin(ROT_SPEED) + planeY * cos(ROT_SPEED); - } - - if (keycode == XK_Escape) - exit(0); - - printf("x:%f y:%f\n", g_ray.posX, g_ray.posY); - // render the updated frame after key press - draw_screen(); - return (0); -} - int main(void) { // Initialisation diff --git a/algo.h b/algo.h index 48207f2..3dcacea 100644 --- a/algo.h +++ b/algo.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* algo.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/14 18:26:05 by mc ### ########.fr */ +/* Updated: 2024/10/15 12:54:12 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,7 @@ #include #include +#include #include "Minilibx/mlx.h" #include "Minilibx/mlx_int.h" # include "Libft/libft.h" @@ -40,4 +41,18 @@ typedef struct s_ray double rot; } t_ray; +extern void *g_mlx; +extern void *g_win; +extern t_ray g_ray; +extern int worldMap[mapWidth][mapHeight]; + +void vector_from_rotation( + double *vecX, double *vecY, double angle, double norm); + +int keypress(int keycode); + +int render(u_int32_t *img_data); + +void draw_screen(void); + #endif diff --git a/move.c b/move.c new file mode 100644 index 0000000..e15b271 --- /dev/null +++ b/move.c @@ -0,0 +1,73 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* move.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/15 12:47:34 by mcolonna #+# #+# */ +/* Updated: 2024/10/15 12:52:05 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "algo.h" + +int keypress(int keycode) +{ + double dirX, dirY, planeX, planeY; + vector_from_rotation(&dirX, &dirY, g_ray.rot, 1); + vector_from_rotation(&planeX, &planeY, g_ray.rot + PI/2, FOV); + + //move forward if no wall in front of you + if (keycode == XK_Up || keycode == XK_z || keycode == XK_w) + { + if (worldMap[(int)((g_ray.posX + dirX * MOVE_SPEED))][(int)(g_ray.posY)] != 1) + g_ray.posX += dirX * MOVE_SPEED; + if (worldMap[(int)(g_ray.posX)][(int)(g_ray.posY + dirY * MOVE_SPEED)] != 1) + g_ray.posY += dirY * MOVE_SPEED; + } + //move backwards if no wall behind you + if (keycode == XK_Down || keycode == XK_s) + { + if (worldMap[(int)(g_ray.posX - dirX * MOVE_SPEED)][(int)(g_ray.posY)] != 1) + g_ray.posX -= dirX * MOVE_SPEED; + if (worldMap[(int)(g_ray.posX)][(int)(g_ray.posY - dirY * MOVE_SPEED)] != 1) + g_ray.posY -= dirY * MOVE_SPEED; + } + //rotate to the right + if (keycode == XK_Right || keycode == XK_d) + { + g_ray.rot += ROT_SPEED; + // double oldDirX; + // double oldPlaneX; + // //both camera direction and camera plane must be rotated + // oldDirX = dirX; + // dirX = dirX * cos(-ROT_SPEED) - dirY * sin(-ROT_SPEED); + // dirY = oldDirX * sin(-ROT_SPEED) + dirY * cos(-ROT_SPEED); + // oldPlaneX = planeX; + // planeX = planeX * cos(-ROT_SPEED) - planeY * sin(-ROT_SPEED); + // planeY = oldPlaneX * sin(-ROT_SPEED) + planeY * cos(-ROT_SPEED); + } + //rotate to the left + if (keycode == XK_Left || keycode == XK_q || keycode == XK_a) + { + g_ray.rot -= ROT_SPEED; + // double oldDirX; + // double oldPlaneX; + // //both camera direction and camera plane must be rotated + // oldDirX = dirX; + // dirX = dirX * cos(ROT_SPEED) - dirY * sin(ROT_SPEED); + // dirY = oldDirX * sin(ROT_SPEED) + dirY * cos(ROT_SPEED); + // oldPlaneX = planeX; + // planeX = planeX * cos(ROT_SPEED) - planeY * sin(ROT_SPEED); + // planeY = oldPlaneX * sin(ROT_SPEED) + planeY * cos(ROT_SPEED); + } + + if (keycode == XK_Escape) + exit(0); + + printf("x:%f y:%f\n", g_ray.posX, g_ray.posY); + // render the updated frame after key press + draw_screen(); + return (0); +} diff --git a/render.c b/render.c new file mode 100644 index 0000000..fb370dd --- /dev/null +++ b/render.c @@ -0,0 +1,142 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* render.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/15 12:40:52 by mcolonna #+# #+# */ +/* Updated: 2024/10/15 12:51:25 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "algo.h" + +int render(u_int32_t *img_data) +{ + int x; // px + + // clear image data + ft_bzero(img_data, SCREEN_WIDTH * SCREEN_HEIGHT * sizeof(int)); // TODO why + + // 1 + double dirX, dirY, planeX, planeY; + vector_from_rotation(&dirX, &dirY, g_ray.rot, 1); + vector_from_rotation(&planeX, &planeY, g_ray.rot + PI/2, FOV); + + x = 0; + while (x < SCREEN_WIDTH) + { + // case player on map (cases) + int mapX = (int)g_ray.posX; + // case player on map (cases) + int mapY = (int)g_ray.posY; + + // vector ray direction (1) + double raydirX, raydirY; + { + // ray direction in [-1;+1]. the highter the more to the right (1) + double ray_direction = 2 * x / (double)SCREEN_WIDTH - 1; + raydirX = dirX + planeX * ray_direction; + raydirY = dirY + planeY * ray_direction; + } + + // longueur du rayon dans une même colonne de cases (cases) + double deltadistX = (raydirX == 0) ? 1e30 : fabs(1 / raydirX); + // longueur du rayon dans une même ligne de cases (cases) + double deltadistY = (raydirY == 0) ? 1e30 : fabs(1 / raydirY); + + // longueur du rayon entre pos actuelle et pos du prochain coté ouest ou est d'une box + double sidedistX; + // longueur du rayon entre pos actuelle et pos du prochain coté nord ou sub d'une box + double sidedistY; + + // direction du rayon sur x (+1 or -1) + int stepX; + // direction du rayon sur y (+1 or -1) + int stepY; + + if (raydirX < 0) + { + stepX = -1; + sidedistX = (g_ray.posX - mapX) * deltadistX; + } + else + { + stepX = 1; + sidedistX = (mapX + 1.0 - g_ray.posX) * deltadistX; + } + if (raydirY < 0) + { + stepY = -1; + sidedistY = (g_ray.posY - mapY) * deltadistY; + } + else + { + stepY = 1; + sidedistY = (mapY + 1.0 - g_ray.posY) * deltadistY; + } + + bool hit = false; + bool side; + while(!hit) + { + // jump to next map square, either in x-direction, or in y-direction + if(sidedistX < sidedistY) + { + sidedistX += deltadistX; + mapX += stepX; + side = false; + } + else + { + sidedistY += deltadistY; + mapY += stepY; + side = true; + } + // check if ray has hit a wall + if(worldMap[mapX][mapY] == 1) + hit = true; + } + + // calcul lenght of ray (shortest perpendicular distance between wall and camera plane) (1) + double perpwalldist; + if(!side) + perpwalldist = (sidedistX - deltadistX); + else + perpwalldist = (sidedistY - deltadistY); + + // calculate height of line to draw on screen (px) + int lineHeight = (int)(SCREEN_HEIGHT / perpwalldist); + + // calculate lowest and highest pixel to fill in current stripe + int drawStart = -lineHeight / 2 + SCREEN_HEIGHT / 2; + if(drawStart < 0) + drawStart = 0; + int drawEnd = lineHeight / 2 + SCREEN_HEIGHT / 2; + if(drawEnd >= SCREEN_HEIGHT) + drawEnd = SCREEN_HEIGHT - 1; + + // draw vertical line + int y = 0; + while (y < drawStart) + { + img_data[y * SCREEN_WIDTH + x] = COLOR_CEILING; + y++; + } + while (y < drawEnd) + { + img_data[y * SCREEN_WIDTH + x] = COLOR_WALL; + y++; + } + while (y < SCREEN_HEIGHT) + { + img_data[y * SCREEN_WIDTH + x] = COLOR_FLOOR; + y++; + } + + x++; + } + + return (0); +} diff --git a/utils.c b/utils.c new file mode 100644 index 0000000..4fc0b17 --- /dev/null +++ b/utils.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/15 12:38:40 by mcolonna #+# #+# */ +/* Updated: 2024/10/15 12:39:15 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "algo.h" + +void vector_from_rotation(double *vecX, double *vecY, double angle, double norm) +{ + *vecX = -cos(angle) * norm; + *vecY = sin(angle) * norm; +} From a824900a7c44578eec6be4044ef4f846861a9682 Mon Sep 17 00:00:00 2001 From: ReverseSky Date: Tue, 15 Oct 2024 13:58:25 +0200 Subject: [PATCH 16/80] a --- algo.c | 22 ++++++----- algo.h | 14 ++++++- textures/east.xpm | 95 +++++++++++++++++++++++++++++++++++++++++++++ textures/north.xpm | 96 ++++++++++++++++++++++++++++++++++++++++++++++ textures/south.xpm | 92 ++++++++++++++++++++++++++++++++++++++++++++ textures/west.xpm | 96 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 404 insertions(+), 11 deletions(-) create mode 100644 textures/east.xpm create mode 100644 textures/north.xpm create mode 100644 textures/south.xpm create mode 100644 textures/west.xpm diff --git a/algo.c b/algo.c index fde3b35..316c974 100644 --- a/algo.c +++ b/algo.c @@ -6,7 +6,7 @@ /* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/14 16:47:50 by greg ### ########.fr */ +/* Updated: 2024/10/14 18:07:09 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,6 +40,7 @@ int worldMap[mapWidth][mapHeight] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} }; +/* dirX -1 = north dirX 1 = sud dirY -1 = east dirY 1 = west*/ static int initalgo(t_ray *ray) { ray->posX = 13; @@ -55,6 +56,16 @@ static int initalgo(t_ray *ray) return (0); } +void load_textures(t_tex *tex, t_ray *ray) +{ + int width, height; + // Charger les textures + tex->tex_north = mlx_xpm_file_to_image(ray->mlx_ptr, "textures/north.xpm", &ray->width, &ray->height); + tex->tex_south = mlx_xpm_file_to_image(ray->mlx_ptr, "textures/south.xpm", &ray->width, &ray->height); + tex->tex_east = mlx_xpm_file_to_image(ray->mlx_ptr, "textures/east.xpm", &ray->width, &ray->height); + tex->tex_west = mlx_xpm_file_to_image(ray->mlx_ptr, "textures/west.xpm", &ray->width, &ray->height); +} + int main(void) { t_ray ray; @@ -76,12 +87,3 @@ int main(void) return (0); } - - - - -// https://github.com/iciamyplant/Cub3d-Linux - -// https://lodev.org/cgtutor/raycasting.html - -// https://www.youtube.com/watch?v=js7HW65MmNw&list=PL0H9-oZl_QOHM34HvD3DiGmwmj5X7GvTW diff --git a/algo.h b/algo.h index e0b5081..a057879 100644 --- a/algo.h +++ b/algo.h @@ -6,7 +6,7 @@ /* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/14 16:47:36 by greg ### ########.fr */ +/* Updated: 2024/10/14 17:54:17 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,8 @@ # include "Libft/libft.h" #define mapWidth 24 // TEST #define mapHeight 24 // TEST +#define texWidth 64 +#define texHeight 64 typedef struct s_ray { @@ -62,6 +64,16 @@ typedef struct s_ray double height; } t_ray; +typedef struct s_tex +{ + void *tex_north; + void *tex_south; + void *tex_east; + void *tex_west; + void *current_tex; + +} t_tex; + extern int worldMap[mapWidth][mapHeight]; // TEST int keypress(int keycode, t_ray *ray); diff --git a/textures/east.xpm b/textures/east.xpm new file mode 100644 index 0000000..e9557aa --- /dev/null +++ b/textures/east.xpm @@ -0,0 +1,95 @@ +/* XPM */ +static char *_620a382cef347a1b644c8e4b2d2d03a3RERGyOH81CSlLw2[] = { +/* columns rows colors chars-per-pixel */ +"64 64 25 1 ", +" c #202020", +". c #2C2C2C", +"X c gray22", +"o c #404000", +"O c #585400", +"+ c #706C00", +"@ c #484848", +"# c gray33", +"$ c #646464", +"% c gray44", +"& c #7C7C7C", +"* c #848400", +"= c #9C9C00", +"- c #B4AC00", +"; c #CCC400", +": c #E4D800", +"> c #FCF420", +", c gray55", +"< c #989898", +"1 c gray66", +"2 c #B4B4B4", +"3 c #C0C0C0", +"4 c #D0D0D0", +"5 c gainsboro", +"6 c #ECECEC", +/* pixels */ +"................................................................", +"##########@5;;;;;555555---5 X,155555;;;%,,# @@@@@@@@@@##########", +"##########@54----<1;;433;;, X,32,;&;===+##X X%====&&&%$@@@@@@@@@", +",,,,,,,, #@54---+<;;=333*-$ X151,&;&+*+#&#X X=;:=+,23;;;$$;;,,,,", +"42-221,, #@54==*+<;=11<,,=# X,3,,,11$*+#%#X X=:-+$&25;::@$;;*&44", +"11--#%&% #@53=*+%&<1<=,%,*# X@1;=1,,&O#%##X X=:+$,2:;&==@$=*+@,<", +"2<+#,,,% @@54=++&1<<<=,<%,# X@&=*-,11%$%XXX X*=+$&;;;&+=@%$@@$-&", +"22&,1,%# X@54,&&<1<4&*<1,,# X@%,1,1,,,1%XXX.X*+$,,&;&&++@%&,%&*$", +"<11%%,@@ .@531<&<;<<,<,,1,# @#%%##XXXXXXX XX&$,&11&,1&@%,<,,1&$", +",,,,%#@@ .@561&<&;-%,,,1,,#. @@XXXXXXXXX XXX&22,=&<&&<$%<,<,,1,", +"%%%%#@XX .@55,&<<;=%1,1,1,#. X@X.. ..XXXX&2&=@,1:&,%,%<$%,$$", +"##@@@ .@151<&;-=%<,,&,%$X X@@@@%111155+XXX%2,&$$&=X##$@@@@@@@", +" ....X#,54,&,=%,,1&,=,#X X@%1>>555445;+XX#,%$$#@OXXXXXX.....", +".........X#%14,1,,,1,,<,$$#X .X1>;=,,1,1=%O XXXXXXXXXXX.. ", +"XXXXXXXXXX#@,41,1<%<,&,1*##X .@1;*&1,::,=#+XX..........XXXXXXXXX", +"#@XXXXXXXX#@%3,1<;=%1,1,+#%@ .@1:*&,;:&,*#OX@@#### @@@@@@@@@@@@@", +"<<<<<<<<<. #@33*,=*1%,,,%$## @::&&1::%,+#XX@:--$#@#&<<<<<<<<<<<", +"4;-55;=%%X #@,3+$<$,%%1,%,%@ @:&,&,=+$1,#XXX--*$.@&3;;;5-11;;;5", +";-*--=+#%X #@%<$$,,%,#,%#%#@ @&,&,:$$$###X X=*#$ @<;;;&:=&1;=*%", +"-*1-=*+#%X @#@<<%,$%%%%#%#@. .1,%,%#XXXXXX $=*%# @<;;&<==&<;=*%", +"*1,-=++##X @#@$##XXXXXX. .,%XXX $,*,# @<1&,<=&&1;=*<", +"1,1-+##,#X @#@.... .X#X ......,1,1# @,1<1<1&1&1=+%", +",1&&#%,%#X X##@X @@@@@@@,,<=====&#.X$3513$ @,,1:<,1<11&&<", +",;=&,,,$@X X,;;-=,222$X@$=;;;-4666;;;;-=* X&5351% @&<1<,1<:<&1<1", +",=*1,,,$@X X;--=&&&&&X#@=;-%<11<1<=&=*=*+ X,5113: @:1<1<::&1<<1<", +"<*,,,,%#XX X-=*$$$$$$ #@<6<<=<;1<<&1*&=+O X,:,,1= @=O%$:-*+O%%#%", +"$$$$$#@XXX X-*$$<*=+$ @@<6:1<;*<;;1<*1*$O X,-%,1+ @OXX@OOOO@@###", +"#@@XXX .X-*$<<&*+$ @@<6;1;=&<;*<1<<&$o X,%,15O @.. XX@", +" ...@@@6$<1*,*+$ X@<6-<;+&1<1<&-*&$o X:6151# @XXXX... ", +"@$$%,<,,,,@ 6<<1*,$&$o @<6-1=+&<&<1<-*&#o X-6331# @XXXXXXXXXXXXX", +"$,2--,1111$ 614,+1,&$o @<61;=+&<11<1-*,#o +=511-# @+===--**@@@@#", +"$2--*$1111@ 61<1&,&,$o @&<;=+%&1<<&<-*$#o X=55-=# @%=+===---* c #4C4C4C", +", c gray33", +"< c gray36", +"1 c #646464", +"2 c gray44", +"3 c #7C7C7C", +"4 c #80502C", +"5 c gray55", +"6 c #989898", +"7 c gray66", +/* pixels */ +"333%&**-**************&$%****&&%,1332222OOOOOOO:12,1,,>>>>,<<123", +"322,%&*-*******&******&$%***&%%,13323233:OOOOO:12,1,>>,,<1111112", +"2221,%&=********&&****&$%*&&%:,11:****:11:OOO:12,1,>,<1111111111", +",2321,%=********&&****%$%&%%,13:**%%$%$%11:::12,111111<,,>>>>>>>", +">,2231%=*************&%$%%,133:*%%%%$%$%:31112,1<<<<<<<<<<<<<<<<", +">>,222%&*****&******&$$%,1331**%%%%%$%$$.1572,1,>>>>>>>>>>>>>>>>", +">>>,23,%&**********&$$:,133:*%%%%%%%$$%..173,1,>>>>>:>>>>>>>>>>>", +">>>>,23,%&*******&&$%,1131**%%%%%%%%$$%..1631,>>>>>>>>>>>>>>>>>>", +">>>>:,31,%&****&&$$,1133:*&%%%%%%$%%$.%..161,>>>>:>>>>>>>>>:>>>>", +">>>>::331,%&&&&$$,13331**&%%%%%%%$%%$.$..151,>>>:>>>>>>>>>>>>>>>", +">>>>::3231,$$$$:,1331:*&&%%%%%%%%%%%%.$.;151<>:>>>:>>>>>>>>>>>>>", +">>>>::22331,,,,,1331**&%%%&%%%%%%.%%%...>231<>>>:>>>>>>::>>>>>>:", +">>>>:#221,,,1266521*&&%&&%%%%%%%%.%%%...,251,>>>>>>>>>>::>::::>>", +">>>:#131,,,,:16551*%&&%&&%%%%%%%%.%%%...1231,>>>>>>>>>>>>>::::>>", +">>:#132,,,,,::253*&%*%%%%%%%%%%%%.%%%..;1331,>>>>>>>>>>>>>::::>>", +">:#1331,,,,,:::1,*%*&%%%%%%%%%%%$.%%%..>2331,>>>>>>>>>>>>>::::>:", +":#13321,,,,,;>,:1*%*%%&%%%%%%%%%$.%%$..,333,>>>>>>>>>>>>>>>>>>:#", +"#11::12,,,,>;,,11*%&%%%%%%%%%%%%..%%$..1=*1,>>>>>>>>:>>>>>>>>:#;", +"11:&&:11,,,;;,,,2*&&%%%%%%%%%%%%.$%$.$<=**,1;>>>>>>>>>>>>>>:;#;;", +"1:&*%&:3:,;;;,,,11&&%%%%%%%%%%%$.$..$1=***%11;:>>>>>>>>>:;#@@#;1", +":&*%%%$12:;,;,,,:3:&%%%%%%%%%%$....>13%%%%%221;;;:::::;;#@#;#,11", +"&*%%%%$:31:,;,,,:21$%%%%%%%%%%....>133311115511;#@@@@@@@#;;#,13:", +"*%%%%%$$12:,;,,,#13:%%%%%%%%%...;<1,,,,,,,356621,#;;;;;;;;#,13:&", +"%%%&%%$%131:;,,>#131$%%%%%%%..;,11,:;#;;;;,366531,#;;;;;##,13:&*", +"%%%%%%$%:331;,>:#133:.$%%%$..,131,:;;##;;;;,355231,######,131&*%", +"%%%%%%$%$132#:::#2231.......;131,:;;;#;#;;#;232,,31,####,131:*%%", +"%&&%%%.%$,231###23333:....;><3,,:;::;#;#;;#:121::,31,,,,131:&%%%", +"%&&%%%.%$:3521123,==,1::><<33,,:;;::;#;;#;@,12,:::,3335532:&%%%%", +"%%%&%%.%$:325221==****111232,,:;;;;;;@;;##+,11:::::1355321&%%%%%", +"%%%%%$.%$:32222=******&3322,,:;;;:;;;@;;##:12,,::::,1221<,&%%&&&", +"%%%%%$$%$,252221******%323,,,;;;;;;;;@;;#@,233111111132<,<&%%&&&", +"%%%%%.$$$,331,133***&%%33,,:,;;;;;;;;@;;#+1,---------%*-<1&%%&&&", +"%%%%$.%$:131,<,133&&%%13,,::,:;;;;;;;+;;@,2===*******%***3&%%%%%", +"%%%%$.$:111,<,,,1331,,31,:;:,:;;;;;;#+;#+,1=*=*******%**&1&%%&%%", +"%%%%.$:113,<,,,,,135353,:;;:,:;;;;;;#+;#+1,4*=**&****%**&1&%%%%%", +"%%%$.:1121,<,,,,,,13555,;;;:,>;;;;;;@+;+12:4*=*******%**&1$%%%%%", +"%%%.:1133,<,,,,,,,,1566,;;;:,>;;;;;;@+#:22=4*=*******%**&1:$%%%%", +"%%$:11231,<,,,,,,,,,1661;;;:,>:;;;;;++@,31=4*=*******&**&11:$%%%", +"%$:11231,<,,<,,,,,:,,152#;;:,>:;;;;;+++13,=4********&&**&131:$%%", +"$:113321,,,,,,,,,,,:,,55,##:,:>;;;;;++:22=*4*=******&***%1331:$$", +":115531,,,,,<,,,,,,;,,122+##,;>;;;;;++,31=*4=*******&***%13331::", +"116651,,,,,,<,,,,,,;:,,11:+@+;>;;;;;++,3,=*4-******&****%1OO#,11", +"13662,,,,<<,,,,<,,,:;,,,1,:++#::;;;#+:12=**-4******&****%1OOOO#,", +"O:551,,,<<<,,,,,,,,:;,,,,:,1,@@:;;;#+,23=**=4*****&*****%1OOOOXO", +"OX:3,,,,<<<,,,,,,:,:;:,,,:11,+@@#;;#+133&***-********&**%1OOOOXO", +"OX:2,,,,<<,,,,,,,,,:;:,,:#155,+@@;;@:2221&**==**********%1OOOOXO", +"X:11,,,,,,,<,,,,,:,:;:,:#:3553,+@##+,32231&**=*****&&**&%1OOOXOO", +":111:,,<<,,,,,,,,:,:@::#:,3:%:3,++++231##11&&*=****&&*&%:1OOOXOO", +"12221:,<<,,,,,,,,:,:@;#:,1:&%$:31,,131#OO#121&*******&%:11XXXXXX", +"332231::,,,,,,,,,:,;@#:,1:&%%$%$:3331#OOOO#121&&****&%:1233:::::", +"3235551::,,,,,,,::,;@:,1:&%%%$%$%:33:#OOOOO#122,&&&%%:1,,,,,,133", +"3,==,551:#,,,,,,:::@:,1:&%%%%$%$%$31#oOOOooO#132,&%::11,,,,,,:13", +"==**==,31:#:,,,:::#:,1:&%%%%%$%$%$3#OOoOOooOO#132,::13,,,>,,,:13", +"******==,1:#:,::##:1::&%%%%$%$%$$:1#OOOXoOOOOO#1321151>>,,,,>:13", +"*&******=%1:#::#:,1:&*&%%%%%%$$$:1#OOOOOXXOoOOO#13255,>>,,,,>:1=", +"*******&*%**:##:,1:&*&%%%%%$%$$$,##OOOOOoXXoOOOO#1351,,,,,,>::1=", +"**&&***&*%**&::,1:&&*&%%%%%$%$$:1#OOooOOOoXXoOOOO#13,,,,,,,::,=*", +"**&&***&*%&%%,,1:&%&*%%%%%%$%$:1:#OOoooOOoXXXoOOOO#13,,,,,:>:1=*", +"******&%&$%%,11:&%%&*%&%%%%$$$,1##OOooOoOOXXXXoOOOO#11,,,>::,=**", +"******&%%$%,333:%%%&*%%%%%%$$:1#O#OOOOOOOOoXXoXoOOOO#1>>>:>:,=**", +"******&%$$,3333,%%%&*%%%%%%$:1:#O#OOOOOOOOoXXXoXoOOOOX1>:,,:=***", +"******%$$,3,;,31:%%&*%%%%%%$,1#OO#OOOOooOOOoX ooXoOOOX,1,,>1=***", +"*****&%$,3,;;;,3,%%&*%%%%%$:1#OOO#OOOOooOOOoX XOXXoOOX,3>>1=****", +"****&$$,33;;;;;,1%%&%%%%%$:,1OOOO#OOoOOOOOOoX XOoXXoOX,3311=****" +}; diff --git a/textures/south.xpm b/textures/south.xpm new file mode 100644 index 0000000..2f7be97 --- /dev/null +++ b/textures/south.xpm @@ -0,0 +1,92 @@ +/* XPM */ +static char *e397ebaa01fc4feff5489b3ed5687b5apc4MtmZYBL5LBxLT[] = { +/* columns rows colors chars-per-pixel */ +"64 64 22 1 ", +" c gray12", +". c gray23", +"X c #3F3F3F", +"o c gray28", +"O c #4B4B4B", +"+ c gray31", +"@ c #535353", +"# c gray34", +"$ c #5F5F5F", +"% c #676767", +"& c gray42", +"* c gray45", +"= c #7B7B7B", +"- c #838383", +"; c gray56", +": c #9B9B9B", +"> c gray67", +", c #B7B7B7", +"< c gray78", +"1 c LightGray", +"2 c #DFDFDF", +"3 c #EFEFEF", +/* pixels */ +" . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .", +"#@#+#+#+#+O1222121222121222 .->,1<11<1,<>-# oooooooooo@+#+#+#+#+", +"@#@@#@@@#@o21<1,111<11,11<; .-<,;>-;;;;->+. .&;;-;;;=&%oooOoooOo", +";;-;;;-; @O2<<,1,<<,<<,,1;$ .>1>;>;>->;>-#. .;122212,,>;-;;;-;;;", +"1111,>;- #o21>>:>;>>>>:>>=@ .;,;;->>>>-;*+. .-22,<,1222121<111<1", +">>>>:>=* @o3,:>>>>:>;>->>&@ .o>;>>-;:;>&#@. .;1,>;>;>>:;;>;>->;:", +",:::>;=& Oo31>->;>;:::;;>;+ .o=;->;>>->*... .-2,;>-:-;;>-;:;>:;:", +",>-,-:$# .o3<;:;>>:;=;;>;$# .oo;>>:;;;>&... .;2>>-:=>:=;>->>;=>:", +":>>;:*oO O<,>:>->;:-:;;>&@ O@o=........ ..*22;>--:*:;>;;=>>*;", +";;-;*@oo .o>3>:>;;;;;;->-#= .o....... . ooo<<;;;;:::-;>;>>->;", +"*&**+O.. O;1;>;;=;;>->;>&#. .o. . . O@o<>;>->;-;*&%$$%$%$", +"@#ooo .X*2>-:===>:;-=;&%. .ooOO*=;>:>>:*.+O,;&*%$%#@@@oOoOooO", +" . . .@o2<;;;::-;>=;>;+. .X*>>123111:&@ @o;&%$@Ooo..... . . ", +" . . . ..+o>1;>-=;>;-:;-*+. .>,21,->;>-*. ........... ", +"..........OO;<>->:-=;=;>;+#. .X>2,>;;;-;;+. . . . . XX.......", +"@O...... .@o*<->:;>:>->->+*o O>3>;->;>->@. .o#@## oOooOoooooooX", +"::;:;:;:: #o<,:;-::*;;;;&#@ O>3-;>>->;;+. .&>21#o@=::;:::;::::", +"1<11<1,>*X #o;,;>;=;;->;&;&O O><>>;->;>-#. .>1<> o=<12221222121", +">:;>;>>&*. @o*:>->>->*;&@*@O O><>;&**&@#@. .1<>- O:11,,>,,,>,,,", +">;:;>-;&*. o@o:;**&*@@*+*@o .:;*;&....... $2>;; o:2>>:>;>;:-::", +">;;>->>&#. o@o%@#@#ooo. ;*... $2>>- O:1>;:-:;:*-;-", +">;>;>-;*+. o@o . . ..+. . . ;2>>; o;<->:>;>;:-::", +";>*=;;>&#. .+#O. +OO+OOo;;;>>;;;=# X%,2>-= O-<>-:;:-:==;;", +";--=;>-%o. .-2221<>>;$.O%=>>,<<2221222<:% .=2<:>* o-,>:;>->;==;;", +";;>>-;;$O. .1<>;::>;:.+O=1322<,,<,<,<,<&# .;2>:;& O&<->;;:;->;>;", +":>-;>-*@.. .2:;:>>;:> @O:2<;>->:->:>:;-%o .;3>-># Oo;*$#@@%%&=;-", +"%$%$%@o... .1>>>->;>$ Oo:3>:>;=>>;-;>->#o .-3>>;# @ ..ooooOoo@#@", +"@Oo... .2->;>>;=$ Oo:3->;:>-;=;>;;;+O .;3->;+ #. ..o", +" . OOo2>:->;>=$ .o:3;;>-;=;=;-;>;+O .-3>>-# #....... . ", +"o%%&;:;-;;o 2>*:;>--%. o;3>;-;=;=;>=;->@o .;3;>>+ #oXo+@+#@@#...", +"%;,21211<>* 2>>-=;>-%. o;2,:;>;>*=;=;>-#. .;1;;>+ O>21,;$#ooOoo@", +"%>1<<,>>:>X 3;:>=;>:&o O=1<>-;*;==>;>--+. .;2>;;@ O2-;,221222;.@", +"%2,>>->;>-* 3:>;>>->&O .+<2>>:;>->==;>&#. X;1;>;+ O2;->>-;>;--.+", +"%1,:->;>->* 3:-:>;>-%@ #>3>>:;;=;==>-*o. O;1>>-# o2>>-;>>->;$.o", +"%2>;>;>>=>+ 2>>>;;;>%+ .+;3,>;>-;:->;>$o .X;1:;>+ O<>;>>-;>;>$.o", +"%2>>;;::>-# 2,=:=>>:$# O&1,>;=:-;:;;;$. O;1;>+# O<>:>;>-;>:#.o", +"%1,;>>;>->@ <2-:>;;;$# O@,2>->;>;>-;%@. .o=>=+...X>>;>:;>;->#..", +"%2,>:;>;>;+ ,2=>-;;>&# .+;,>;=%$@oO.... .X#....Xo *+o@#@#@@#@..", +"%2>;>>->=>@ :1:=>>-;&# .@o;;$#o. .o+oo+@#@# .", +"%1,;-:>;>-# =2>:>-;>%+ +o. . . . . .o@#ooOoooOoo..........", +"%2,>>-:>;>@ #3;:;;>-%@ .ooo.....OoOX+OoOoo#@================*.+", +"%2>;;>->;&# o3>;-=;>&# X%=============;;;:>,><,<,<,,<,<,<,<=.+", +"%<,>>;>;>+ +3:;>;;-%#. .=<,<,<,<<,<,<,<,122333333333331211;% O", +"%1,;>;>>-# .X3;>=:->%+. =<<3333322332333332211,,,<,>,<,,<,=# +", +"%,,>;>-;;+ .o2>>->;;$#. =<<,<,<,<>,<>,<,,>>::;;>;>-;;>->;>&#..", +"O<-;>-*&*@ .o1-;>->;&#. %,2,;;-;;;>->>;;:>>>;=:->>:->;>>:;&@ .", +"o,>>:;#@@ Xo,>-;>;-*@. o<2,;;;>;:;:>-;:>>-:;:;;=-::;>->;>&#..", +"o===#@#@@ ..X::>-;;&%@. ,21>>-;;;=;->;:->:=-;>-;>;=*;=:;;*@ .", +"o. #@@# .XO=%$%%$%@@. .>11;->;>-;>;==::->;>;;>-;=;;->;*-&# .", +"@#@o. ..X........... ;1,>;;>->=;-:=:;:=>-;=;;;->;=;;-=&# .", +"oOoooOo. .O.. .-:&**&**&>;>>-;=-;;=;;>->;;>-;;;:&# .", +"o=>>>>;;%OO@.. . . . . .@o.. . . #*&=;===================%+ .", +"o><12122,>>;&$#O..........X#oo...... O@@#@#@#@#@@@#@#@@#@#@@@ ..", +"o>1>>;,1222,>>>>>>>:;;-==&%%+#oooXo.. . . . . . . .X", +"o>2>>>,>;>,222121212222<1<,>>>>>-O@o......... . . . . . . ...oO", +"o>2>->==>:;=>->;>;>>->;>>><1211,-.o+Ooo... .................XoO@", +"o><>>>;>;;;:>-;>=*;>=;-;>->;>>>=% .+O>12:=OOo@@@ooXoooXooXoo+#@@", +"o><>->==:>->>:-=>=;=:->;>;>->>:%@ .oo2>>2221,@@O,22122211<>:=Oo@", +"o>-%$%$%$%%$%$%%$%$%$%%$%$%$%$%#@. .o1,>,>,,,$#=2:>>;>->:>;>1: @", +"o;%............................... O,>,,:$:-%o,>;>->>>->;>->@ #", +"o. +.o.+%$%%$O2:::>>;:>::>;;+ #", +"@O... . . . . . . . . . . . X+#.. .@#@@@@@#+@#@#+# @", +"@#+@oooOOoOO.........................+#+@......+@ #", +"................................................................" +}; diff --git a/textures/west.xpm b/textures/west.xpm new file mode 100644 index 0000000..ad936b3 --- /dev/null +++ b/textures/west.xpm @@ -0,0 +1,96 @@ +/* XPM */ +static char *_cd234baf8884d64b1bd40cc8c2edfd60t7GgtsagB5aS77Y[] = { +/* columns rows colors chars-per-pixel */ +"64 64 26 1 ", +" c #202020", +". c #2C2C2C", +"X c gray19", +"o c #343434", +"O c gray22", +"+ c #400000", +"@ c #4C0000", +"# c #580000", +"$ c #640000", +"% c #700000", +"& c #7C0000", +"* c gray25", +"= c #484848", +"- c #4C4C4C", +"; c gray33", +": c gray36", +"> c #646464", +", c #880000", +"< c #980000", +"1 c #A40000", +"2 c #B00000", +"3 c #BC0000", +"4 c #C80000", +"5 c #D40000", +"6 c #E00000", +"7 c #EC0000", +/* pixels */ +"OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO", +";O;=====;======;=O=======;;;;;;=========;;;;;;;====OOO==;;=====O", +"O775555555551==;775555555555555555551=O;77776666665555544443331=", +"=74225,15,41$.=;73,3,3,3&3<3<3&3&341%.=O51424224%4&424,21&4<41&.", +"=51&1,1<%1,%$.=;53,,1,%11%<11%<1%1<%#.=;511&$1,%,1&,11,1&,1#1%$.", +"=5&11%<11%1#+.=;5,31,1%1,1%1%,&1%<&%#.==5%1$,1$1%1&1,1$1<&1&1%@.", +"=41&,<&1%,1%+.=;33,1,,<1%,%1,%<&,%1%+.O=3%1&1,$1%%11%1,11&1#1,@.", +"=3&11%1<%<%#+.==34,1%1%1%1%<,%&1%<&%#.O=3<1$,1&,%,&1,1$1&,1&1%+.", +"=31%,#%&#%,%+.O;<<%%@,%%,%@%,%,%@,%%+.O=3%%#%%@,@%#,@%@,$@%,%,+.", +"=&$$$++++++++.O=&$$#########+++++++++.O=,$$$$$$$$$$#########+++.", +"==........ .O;=..... .. .....=;O........... .......", +";OOOO====OOOOO=O=======OOO;===OO======;O=;;;;:>>:;;==*O*;O;===;O", +"7555333333333331=;=7755555544444443333333333333333331=*;77555555", +"2,,2<&2&<,2$2,1+O=;7%24&3$,3,,4<1,&,1,1,1&4$4,<34<41+O=O74&2,2,2", +",1,1&,,$1,$,11%+.==52%1&11,1$1%$,1&1&1$11,$1,1%,1%1%+O=;42&1,&1<", +"%11,<$1&,,<$1,%+.O=5%1,<,,$,,%1,$1,&$&,,1#,&1%1%11%%+.*=4&111&1&", +"1,,1,&&,&1<$1$%+.O=5%11&1$,1$%1$,1&,&1$1,#1$1%,%1%1%+.O=42&1&1<&", +"%1$1%,&<$1$,11%+.=;52#1&1,$,#,%$1,&#&1$,#,1$,1%,1%1%+ O=2&11#1&,", +"%2$%@&%<%<%#<%%+.=;21%,#%<%,$%,#%<%<$,%,,#<%%,@%<%,%+ *;21&%#%<%", +"+@@@@@@@@@@@@+++O=;1$$$$$$$$$$$$$##################++ =O1$+$++$+", +"... ... ... .O=O=Oo......ooOOo... ... .....O=;=.......", +";;=OO=;O;O==OOOO==;===*O*O*O*===;O;=*OOO**==;*OO*===;=;O;*O*;===", +";775555555333333333333333331=;;77555555555533333333333333333331=", +";7,23&3&3&2,2,24,2,2,32$24%+O=;73%512,12,2<2&$1,%,1&,1<,1&,1#1+.", +"O72,1<1&%,11,<,1,$1%1,$,1%2+.=:53<1$1$,%<,$1$,1$1%1&1,1$1<&1&%+.", +"=3$11%,#1$1%1,<1$,1%,1,$&1%+.;>53&1&1$1%<1&1&1,$1%%1<%<,11&1#%+.", +"=32,1@1#%,1,%&1&,$&1$1,$1%#+.;:5%1%<,$,<%1$,$,1&,%,&1,1$1&,1&%+.", +";3%$1@,&1$1#1$1,$,1,$1$,&&2+.=;54%1%1,1,%1$1#%%@1@1#1@11,$@%,%+.", +"=41$%%%#%@%%,$,%%,%%$%<%<%%+.O;41%<%,#%%%%$,%,@1#%1@%,@1#1@1%%+.", +"=1<$$$$$$$$$$$$$$@@@@@@@@@++.O;1$$$$$$$$$$$$$$############+#&#+.", +"==O.................OOO......===........ .OOO. ...........", +";;;;;==O=OOO=;>>;;;===**OO*OO*;===;O;=;=*O*O*=;;==*O*===;O;===;O", +"33333333331=O;55555555333333333333333331=;;475555555553333333333", +"1212<42241+O=O51$1%11$1,11%1,$11$11%1&1+O=;51&1%11$1&,&1%1,1&1%1", +"1&,1<1&1,%+.=;5$1&,1&1<%1,,%,,1,$1%,1$1+O;;51#1%1,$1,1&,,<%<&<,%", +",&1<&1&<1%+.=O5$11&<1%1%1,1#1@,,1,%<1&1+O;>51&1%1,1,11&1%<,1<&1%", +"1,&1<1<&,%+O=;5<$1&1&#<,,,%,1$1,$,<%,1&+O;>5&11%1$11&&1&1,<<,&%,", +"1,&1&1&<1%+O==5$1&#<1%,,1,1%,@$<$1<%1&1+O=;41&11%1,,&1&1%<,1&,1%", +"%%,<%%<%%%+O==<$11#1&%1%1$1#,$1,$<%<1$&+.=;41#1%11,1,1&1%<%<&11%", +"++@@@@@@@++.==1$$$$$$$$$##############++.==1$$$$$$$$$$$$$$$####+", +"............=;=. ..OOO. .........O===....OO=O.. .......", +";=;O=OO==OOOO==OOO=====;;==OOO;===;O=O=O==;=;O;=;:>;-==O;=;=;O;O", +"O7555555533333333333333333333331O;O7755555555333333333333333331=", +";51,,1$11&<1&1%,1$1&1,1$1$11&%1+O=;711$1$1#1%1#1,#<,%1,&1&<%,1+.", +"=51$1,$1,<&1$,#1<$1#,<,$1&1&1%<+.==5,1$,$&#,#<&1#1$1%,%1,&<1$,+.", +"=5,$1$,%$1$1,&,1$<,,#&1@<#,$,,%+.O=5,1$$,1&#<1#1%%1%1&1%,$1+.", +"O51,1,$1,&<1&1#,1$1#,1#<1&111%&+.O=51$1,$1#1%<&&#,$1&,<,<&%1,1+.", +";51$,1$1$1$1$1%1$$1#,&1&,$<$,%1+ O;51$$1$#1#<#1$,%1%&1&<,$%+.", +"O41$1$,%,<&1,,,1<$,&#$1@1%<&1%1+ O;4%1$,$1#&1&#<%,$1%1%1&<%1$1+.", +";1$$$$$$$$$@@@@@@@@@@@@@@@@@@@@+.=;1$$$$$$$$$#####@@@@@@@@@@@++.", +"O=..........OOO. ... .. ..=O=...... .oOo. .... ......", +";O;O;=;====;>>;=;O;=;=*OOO*=;==O==;O;========-;;;-====OX XO==;=", +"555553333333333331=;=77555555553333333333333331=O;75555533333333", +"&1#11$<$1&4&1$1&1+.==51111$1@1&1$1$1<1$1$1#1%$+O=;51$,1#1%1%1$1%", +"1&&1&1$<&$1#&$,$,+.==5&1%1$%@&<&1,$,<$&,%,#1$1+o=;5$1#1%1%,1%1,@", +"1&#&1$<$&1,$<&+.=*5&&%1$&&1#1@11$1$1$,#,,$%+.=;5$1%%11,%,%$%,", +"&<#<$$1$1&1#&%$1$+.=*51@%1$1@1&<$1$,&$1$1,#%<$+.=;51$#1,%%1%1$%1", +"$1&1$1$,1$1&#,1&,+.=*5@11$1&%,#&@1$1$&&$,%#,%$+.==5$1,1%1,%%#1%1", +"$1&&$<<$<$$1$<+.==5@1%1$&&,@<$,@1&$1,$1#1#,+.O=5$1#%#1%1%#$1@", +"&<#1$$,$&&1#1$%,&+.=;41@%1$1@,$1$1%$1$&1$,%,$,+.O=4$$#1#1%1%1$1%", +"@@@@@@@@@@@@@@@@++.==1+++++@@@@@@@@@@@@@@@@@@++ =;1++@@@@@@@@@@@", +"...................=;=Ooo.............. . O==...... ..", +"O;O;OOO=====;;O====;;;;;===;===;==O===*OO*OO*=*O*;==O;====*O*===", +";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;" +}; From 800ddb97ce554e408833c73bca5424cb6ee59cb6 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Tue, 15 Oct 2024 16:03:18 +0200 Subject: [PATCH 17/80] norminette --- algo.c | 125 ++++++++++++++++++++--------------------- algo.h | 86 +++++++++++++++------------- move.c | 71 +++++++++++++----------- render.c | 166 +++++++++++++++++++++++++------------------------------ utils.c | 8 +-- 5 files changed, 229 insertions(+), 227 deletions(-) diff --git a/algo.c b/algo.c index 6eb31c9..382d100 100644 --- a/algo.c +++ b/algo.c @@ -6,96 +6,97 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/15 14:10:11 by mcolonna ### ########.fr */ +/* Updated: 2024/10/15 16:00:41 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #include "algo.h" -void *g_mlx = NULL; -void *g_win = NULL; -t_ray g_ray; +void *g_mlx = NULL; +void *g_win = NULL; +t_ray g_ray; -int worldMap[mapWidth][mapHeight] = -{ - {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, - {1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,1,1,0,0,1,1,1,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1}, - {1,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,1,1,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1}, - {1,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,1,1,0,0,1,1,0,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1}, - {1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} +int g_world_map[MAP_WIDTH][MAP_HEIGHT] = { +{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, +{1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, +{1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, +{1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, +{1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1}, +{1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, +{1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1}, +{1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, +{1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1}, +{1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, +{1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, +{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, +{1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, +{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, +{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, +{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, +{1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, +{1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, +{1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, +{1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, +{1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, +{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, +{1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, +{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} }; -static int initalgo() +// TODO from map + +static int initalgo(void) { - // TODO from map - g_ray.posX = 14; - g_ray.posY = 6.5; + g_ray.pos.x = 14; + g_ray.pos.y = 6.5; g_ray.rot = 0; return (0); } -void draw_screen(void) { - int bpp; - int size_line; - int endian; - - void *img_ptr = mlx_new_image(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT); - u_int32_t *img_data = (u_int32_t *)mlx_get_data_addr(img_ptr, &bpp, &size_line, &endian); +// TODO manage image format error better + +void draw_screen(void) +{ + int bpp; + int size_line; + int endian; + void *img_ptr; + u_int32_t *img_data; + + img_ptr = mlx_new_image(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT); + img_data = (u_int32_t *) + mlx_get_data_addr(img_ptr, &bpp, &size_line, &endian); if (bpp != 32 || endian != 0) { - // TODO manage error better - printf("image format error (got bpp == %i, endian == %i)\n", bpp, endian); + printf("image format error\n"); exit(1); } render(img_data); mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); } -void load_textures(t_tex *tex) +void load_textures(t_tex *tex) { - int width, height; - // Charger les textures - tex->tex_north = mlx_xpm_file_to_image(g_mlx, "textures/north.xpm", &width, &height); - tex->tex_south = mlx_xpm_file_to_image(g_mlx, "textures/south.xpm", &width, &height); - tex->tex_east = mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", &width, &height); - tex->tex_west = mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", &width, &height); + int width; + int height; + + tex->tex_north = mlx_xpm_file_to_image(g_mlx, "textures/north.xpm", + &width, &height); + tex->tex_south = mlx_xpm_file_to_image(g_mlx, "textures/south.xpm", + &width, &height); + tex->tex_east = mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", + &width, &height); + tex->tex_west = mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", + &width, &height); } -int main(void) +int main(void) { - // Initialisation - g_mlx = mlx_init(); + g_mlx = mlx_init(); g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d"); - initalgo(); - - // hook keypress - mlx_hook(g_win, 2, 1L<<0, keypress, NULL); - - // render the initial frame + mlx_hook(g_win, KeyPress, KeyPressMask, keypress, NULL); draw_screen(); - - // start the mlx loop mlx_loop(g_mlx); - return (0); } diff --git a/algo.h b/algo.h index 7e22813..0a30eee 100644 --- a/algo.h +++ b/algo.h @@ -6,67 +6,75 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/15 14:06:42 by mcolonna ### ########.fr */ +/* Updated: 2024/10/15 15:48:45 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef ALGO_H -#define ALGO_H +# define ALGO_H -#include -#include -#include -#include "Minilibx/mlx.h" -#include "Minilibx/mlx_int.h" +# include +# include +# include +# include "Minilibx/mlx.h" +# include "Minilibx/mlx_int.h" # include "Libft/libft.h" -#define mapWidth 24 // cases (TODO test) -#define mapHeight 24 // cases (TODO test) -#define texWidth 64 -#define texHeight 64 -#define MOVE_SPEED 0.1 // cases -#define PI 3.1415926535 -#define ROT_SPEED (PI / 16) // rad -#define COLOR_WALL 0xFF0000 // 0xRRGGBB -#define COLOR_CEILING 0x29f8ff // 0xRRGGBB -#define COLOR_FLOOR 0xFF985C // 0xRRGGBB -#define SCREEN_WIDTH 640 // px -#define SCREEN_HEIGHT 480 // px -#define FOV 0.66 // ? TODO unit +# define MAP_WIDTH 24 // cases (TODO test) +# define MAP_HEIGHT 24 // cases (TODO test) +# define TEX_WIDTH 64 +# define TEX_HEIGHT 64 +# define MOVE_SPEED 0.1 // cases +# define PI 3.1415926535 +# define ROT_SPEED_DIVIDE_PI 16 // pi/n rad +# define COLOR_WALL 0xFF0000 // 0xRRGGBB +# define COLOR_CEILING 0x29f8ff // 0xRRGGBB +# define COLOR_FLOOR 0xFF985C // 0xRRGGBB +# define SCREEN_WIDTH 640 // px +# define SCREEN_HEIGHT 480 // px +# define FOV 0.66 // ? TODO unit + +typedef struct s_point_double +{ + double x; + double y; +} t_point_double; + +typedef struct s_point_int +{ + int x; + int y; +} t_point_int; typedef struct s_ray { // pos player on map (cases) - double posX; - // pos player on map (cases) - double posY; - + t_point_double pos; // player rotation (rad) - double rot; + double rot; } t_ray; -extern void *g_mlx; -extern void *g_win; -extern t_ray g_ray; -extern int worldMap[mapWidth][mapHeight]; +extern void *g_mlx; +extern void *g_win; +extern t_ray g_ray; +extern int g_world_map[MAP_WIDTH][MAP_HEIGHT]; typedef struct s_tex { - void *tex_north; - void *tex_south; - void *tex_east; - void *tex_west; - void *current_tex; + void *tex_north; + void *tex_south; + void *tex_east; + void *tex_west; + void *current_tex; } t_tex; -void vector_from_rotation( - double *vecX, double *vecY, double angle, double norm); +void vector_from_rotation(t_point_double *vec, double angle, double norm); -int keypress(int keycode); +int keypress(int keycode); -int render(u_int32_t *img_data); +int render(u_int32_t *img_data); -void draw_screen(void); +void draw_screen(void); #endif diff --git a/move.c b/move.c index 6321ef9..0646614 100644 --- a/move.c +++ b/move.c @@ -6,49 +6,59 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:47:34 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 13:27:10 by mcolonna ### ########.fr */ +/* Updated: 2024/10/15 16:01:08 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #include "algo.h" -static int move_forward(void) +static int move_forward(void) { - double dirX, dirY; - vector_from_rotation(&dirX, &dirY, g_ray.rot, 1); + t_point_double dir; - if (worldMap[(int)((g_ray.posX + dirX * MOVE_SPEED))][(int)(g_ray.posY)] != 1) - g_ray.posX += dirX * MOVE_SPEED; - if (worldMap[(int)(g_ray.posX)][(int)(g_ray.posY + dirY * MOVE_SPEED)] != 1) - g_ray.posY += dirY * MOVE_SPEED; - return(0); -} - -static int move_backward(void) -{ - double dirX, dirY; - vector_from_rotation(&dirX, &dirY, g_ray.rot, 1); - - if (worldMap[(int)(g_ray.posX - dirX * MOVE_SPEED)][(int)(g_ray.posY)] != 1) - g_ray.posX -= dirX * MOVE_SPEED; - if (worldMap[(int)(g_ray.posX)][(int)(g_ray.posY - dirY * MOVE_SPEED)] != 1) - g_ray.posY -= dirY * MOVE_SPEED; - return(0); -} - -static int move_right(void) -{ - g_ray.rot += ROT_SPEED; + vector_from_rotation(&dir, g_ray.rot, 1); + if (g_world_map[(int)((g_ray.pos.x + dir.x * MOVE_SPEED))] + [(int)(g_ray.pos.y)] != 1 + ) + g_ray.pos.x += dir.x * MOVE_SPEED; + if (g_world_map[(int)(g_ray.pos.x)] + [(int)(g_ray.pos.y + dir.y * MOVE_SPEED)] != 1 + ) + g_ray.pos.y += dir.y * MOVE_SPEED; return (0); } -static int move_left(void) +static int move_backward(void) { - g_ray.rot -= ROT_SPEED; + t_point_double dir; + + vector_from_rotation(&dir, g_ray.rot, 1); + if (g_world_map[(int)(g_ray.pos.x - dir.x * MOVE_SPEED)] + [(int)(g_ray.pos.y)] != 1 + ) + g_ray.pos.x -= dir.x * MOVE_SPEED; + if (g_world_map[(int)(g_ray.pos.x)] + [(int)(g_ray.pos.y - dir.y * MOVE_SPEED)] != 1 + ) + g_ray.pos.y -= dir.y * MOVE_SPEED; return (0); } -int keypress(int keycode) +static int move_right(void) +{ + g_ray.rot += PI / ROT_SPEED_DIVIDE_PI; + return (0); +} + +static int move_left(void) +{ + g_ray.rot -= PI / ROT_SPEED_DIVIDE_PI; + return (0); +} + +// TODO leaks when quit? + +int keypress(int keycode) { if (keycode == XK_Up || keycode == XK_z || keycode == XK_w) move_forward(); @@ -61,9 +71,8 @@ int keypress(int keycode) if (keycode == XK_Escape) { mlx_destroy_window(g_mlx, g_win); - exit(0); // TODO leaks? + exit(0); } - // render the updated frame after key pressd draw_screen(); return (0); } diff --git a/render.c b/render.c index 125ad45..6dc4581 100644 --- a/render.c +++ b/render.c @@ -6,59 +6,60 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/10/15 13:52:35 by mcolonna ### ########.fr */ +/* Updated: 2024/10/15 15:59:55 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #include "algo.h" -static void calculate_perpwalldist3(int x, - double *raydirX, double *raydirY, - double *deltadistX, double *deltadistY) +static void calculate_perpwalldist3(int x, + t_point_double *raydir, t_point_double *deltadist) { - double ray_direction = 2 * x / (double)SCREEN_WIDTH - 1; - double dirX; - double dirY; - double planeX; - double planeY; - vector_from_rotation(&dirX, &dirY, g_ray.rot, 1); - vector_from_rotation(&planeX, &planeY, g_ray.rot + PI / 2, 1); - *raydirX = dirX + planeX * ray_direction; - *raydirY = dirY + planeY * ray_direction; - *deltadistX = (raydirX == 0) ? 1e30 : fabs(1 / *raydirX); - *deltadistY = (raydirY == 0) ? 1e30 : fabs(1 / *raydirY); + const double ray_direction = 2 * x / (double)SCREEN_WIDTH - 1; + t_point_double plane; + t_point_double dir; + + vector_from_rotation(&dir, g_ray.rot, 1); + vector_from_rotation(&plane, g_ray.rot + PI / 2, 1); + raydir->x = dir.x + plane.x * ray_direction; + raydir->y = dir.y + plane.y * ray_direction; + deltadist->x = 1e30; + if (raydir->x != 0) + deltadist->x = fabs(1 / raydir->x); + deltadist->y = 1e30; + if (raydir->y != 0) + deltadist->y = fabs(1 / raydir->y); } static void calculate_perpwalldist2(int x, - double *sidedistX, double *sidedistY, - double *deltadistX, double *deltadistY, - int *stepX, int *stepY) + t_point_double *sidedist, + t_point_double *deltadist, + t_point_int *step) { - int mapX = (int)g_ray.posX; - int mapY = (int)g_ray.posY; - double raydirX; - double raydirY; + const int map_x = (int)g_ray.pos.x; + const int map_y = (int)g_ray.pos.y; + t_point_double raydir; - calculate_perpwalldist3(x, &raydirX, &raydirY, deltadistX, deltadistY); - if (raydirX < 0) + calculate_perpwalldist3(x, &raydir, deltadist); + if (raydir.x < 0) { - *stepX = -1; - *sidedistX = (g_ray.posX - mapX) * *deltadistX; + step->x = -1; + sidedist->x = (g_ray.pos.x - map_x) * deltadist->x; } else { - *stepX = 1; - *sidedistX = (mapX + 1.0 - g_ray.posX) * *deltadistX; + step->x = 1; + sidedist->x = (map_x + 1.0 - g_ray.pos.x) * deltadist->x; } - if (raydirY < 0) + if (raydir.y < 0) { - *stepY = -1; - *sidedistY = (g_ray.posY - mapY) * *deltadistY; + step->y = -1; + sidedist->y = (g_ray.pos.y - map_y) * deltadist->y; } else { - *stepY = 1; - *sidedistY = (mapY + 1.0 - g_ray.posY) * *deltadistY; + step->y = 1; + sidedist->y = (map_y + 1.0 - g_ray.pos.y) * deltadist->y; } } @@ -69,38 +70,31 @@ static void calculate_perpwalldist2(int x, /// @return Result. static double calculate_perpwalldist(int x) { - int mapX = (int)g_ray.posX; - int mapY = (int)g_ray.posY; - bool side; - double sidedistX; - double sidedistY; - double deltadistX; - double deltadistY; - int stepX; - int stepY; - calculate_perpwalldist2(x, &sidedistX, &sidedistY, &deltadistX, &deltadistY, &stepX, &stepY); - while(worldMap[mapX][mapY] != 1) + t_point_int map_pos; + bool side; + t_point_double sidedist; + t_point_double deltadist; + t_point_int step; + + map_pos.x = (int)g_ray.pos.x; + map_pos.y = (int)g_ray.pos.y; + calculate_perpwalldist2(x, &sidedist, &deltadist, &step); + while (g_world_map[map_pos.x][map_pos.y] != 1) { - // jump to next map square, either in x-direction, or in y-direction - if(sidedistX < sidedistY) + if (sidedist.x < sidedist.y) { - sidedistX += deltadistX; - mapX += stepX; + sidedist.x += deltadist.x; + map_pos.x += step.x; side = false; + continue ; } - else - { - sidedistY += deltadistY; - mapY += stepY; - side = true; - } + sidedist.y += deltadist.y; + map_pos.y += step.y; + side = true; } - double perpwalldist; - if(!side) - perpwalldist = (sidedistX - deltadistX); - else - perpwalldist = (sidedistY - deltadistY); - return (perpwalldist); + if (!side) + return (sidedist.x - deltadist.x); + return (sidedist.y - deltadist.y); } /// @brief Draw a vertical line according to the ray direction x. @@ -108,43 +102,34 @@ static double calculate_perpwalldist(int x) /// @param x Ray direction x between 0 and 1. static void draw_vertical_line(int x, u_int32_t *img_data) { - double perpwalldist = calculate_perpwalldist(x); - int lineHeight = (int)(SCREEN_HEIGHT / perpwalldist); - int drawStart = -lineHeight / 2 + SCREEN_HEIGHT / 2; - if(drawStart < 0) - drawStart = 0; - int drawEnd = lineHeight / 2 + SCREEN_HEIGHT / 2; - if(drawEnd >= SCREEN_HEIGHT) - drawEnd = SCREEN_HEIGHT - 1; - int y = 0; - while (y < drawStart) - { - img_data[y * SCREEN_WIDTH + x] = COLOR_CEILING; - y++; - } - while (y < drawEnd) - { - img_data[y * SCREEN_WIDTH + x] = COLOR_WALL; - y++; - } + const double perpwalldist = calculate_perpwalldist(x); + const int line_height = (int)(SCREEN_HEIGHT / perpwalldist); + int draw_start; + int draw_end; + int y; + + draw_start = -line_height / 2 + SCREEN_HEIGHT / 2; + if (draw_start < 0) + draw_start = 0; + draw_end = line_height / 2 + SCREEN_HEIGHT / 2; + if (draw_end >= SCREEN_HEIGHT) + draw_end = SCREEN_HEIGHT - 1; + y = 0; while (y < SCREEN_HEIGHT) { - img_data[y * SCREEN_WIDTH + x] = COLOR_FLOOR; + if (y < draw_start) + img_data[y * SCREEN_WIDTH + x] = COLOR_CEILING; + else if (y < draw_end) + img_data[y * SCREEN_WIDTH + x] = COLOR_WALL; + else + img_data[y * SCREEN_WIDTH + x] = COLOR_FLOOR; y++; } } -int render(u_int32_t *img_data) +int render(u_int32_t *img_data) { - int x; // px - - // clear image data - ft_bzero(img_data, SCREEN_WIDTH * SCREEN_HEIGHT * sizeof(int)); // TODO why - - // 1 - double dirX, dirY, planeX, planeY; - vector_from_rotation(&dirX, &dirY, g_ray.rot, 1); - vector_from_rotation(&planeX, &planeY, g_ray.rot + PI/2, FOV); + int x; x = 0; while (x < SCREEN_WIDTH) @@ -152,6 +137,5 @@ int render(u_int32_t *img_data) draw_vertical_line(x, img_data); x++; } - return (0); } diff --git a/utils.c b/utils.c index 4fc0b17..9af0d94 100644 --- a/utils.c +++ b/utils.c @@ -6,14 +6,14 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:38:40 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 12:39:15 by mcolonna ### ########.fr */ +/* Updated: 2024/10/15 15:18:43 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #include "algo.h" -void vector_from_rotation(double *vecX, double *vecY, double angle, double norm) +void vector_from_rotation(t_point_double *vec, double angle, double norm) { - *vecX = -cos(angle) * norm; - *vecY = sin(angle) * norm; + vec->x = -cos(angle) * norm; + vec->y = sin(angle) * norm; } From f2fe56a092372b5f9b081189d1262b811468b24a Mon Sep 17 00:00:00 2001 From: mcolonna Date: Tue, 15 Oct 2024 16:08:39 +0200 Subject: [PATCH 18/80] dev: remove .vscode from .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index c306efd..3e3a4d9 100644 --- a/.gitignore +++ b/.gitignore @@ -52,5 +52,4 @@ Mkfile.old dkms.conf # Files -.vscode /cub3d From 78fa8c89670b1521d0c33ace770587afde4c5b01 Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Tue, 15 Oct 2024 16:35:16 +0200 Subject: [PATCH 19/80] added spawn direction --- algo.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/algo.c b/algo.c index 6eb31c9..dcfea4a 100644 --- a/algo.c +++ b/algo.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* algo.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/15 14:10:11 by mcolonna ### ########.fr */ +/* Updated: 2024/10/15 16:34:46 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,15 +44,23 @@ int worldMap[mapWidth][mapHeight] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} }; -static int initalgo() +static int initalgo(char posplayer) { // TODO from map g_ray.posX = 14; - g_ray.posY = 6.5; - g_ray.rot = 0; + g_ray.posY = 17; + if (posplayer == 'N') + g_ray.rot = 0; + if (posplayer == 'S') + g_ray.rot = PI; + if (posplayer == 'W') + g_ray.rot = (3 * PI) / 2; + if (posplayer == 'E') + g_ray.rot = PI/2; return (0); } + void draw_screen(void) { int bpp; int size_line; From 379f2bce6cca370df5b9d06bdece764ef98ee463 Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Tue, 15 Oct 2024 16:37:55 +0200 Subject: [PATCH 20/80] added posplayer --- algo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/algo.c b/algo.c index dcfea4a..cdf9fc1 100644 --- a/algo.c +++ b/algo.c @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/15 16:34:46 by grobledo ### ########.fr */ +/* Updated: 2024/10/15 16:37:29 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -93,8 +93,8 @@ int main(void) // Initialisation g_mlx = mlx_init(); g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d"); - - initalgo(); + char posplayer = 'N'; // test + initalgo(posplayer); // hook keypress mlx_hook(g_win, 2, 1L<<0, keypress, NULL); From 571bf80c6efd0dc9e10747521998f4d6184e5788 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Wed, 16 Oct 2024 18:02:01 +0200 Subject: [PATCH 21/80] fix: map directions --- map.h | 6 +++--- utils.c | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/map.h b/map.h index cc974fd..86c6a39 100644 --- a/map.h +++ b/map.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* map.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* By: mcolonna x = -cos(angle) * norm; - vec->y = sin(angle) * norm; + vec->x = sin(angle) * norm; + vec->y = -cos(angle) * norm; } void write_err(const char *str, ...) From a714e8110d30e74039ab45ab643451957b525913 Mon Sep 17 00:00:00 2001 From: ReverseSky Date: Thu, 17 Oct 2024 12:28:34 +0200 Subject: [PATCH 22/80] temp --- utils2.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 utils2.c diff --git a/utils2.c b/utils2.c new file mode 100644 index 0000000..6e3d3b3 --- /dev/null +++ b/utils2.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* utils2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: greg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/17 01:57:03 by greg #+# #+# */ +/* Updated: 2024/10/17 12:28:01 by greg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +// #include "algo.h" +void ft_init_texture() +{ + if (ray.side == 0 && ray.raydirx < 0) + direction = 0; + if (ray.side == 0 && ray.raydirx >= 0) + direction = 1; + if (ray.side == 1 && ray.raydiry < 0) + direction = 2; + if (ray.side == 1 && ray.raydiry >= 0) + direction = 3; + if (ray.side == 0) + t.wallx = ray.posy + ray.perpwalldist \ + * ray.raydiry; + else + t.wallx = ray.posx + ray.perpwalldist \ + * ray.raydirx; + t.wallx -= floor((t.wallx)); +} + +texture[0].addr = (int *)mlx_get_data_addr(texture[0].img, &bpp, + texture[0].line_length, &endian); + + +void load_textures() +{ + g_tex.tex_width = 64; + g_tex.tex_height = 64; + + g_tex.textures[0] = mlx_xpm_file_to_image(g_mlx, "textures/north.xpm", + &g_tex.tex_width, &g_tex.tex_height); + g_tex.textures[1] = mlx_xpm_file_to_image(g_mlx, "textures/south.xpm", + &g_tex.tex_width, &g_tex.tex_height); + g_tex.textures[2]= mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", + &g_tex.tex_width, &g_tex.tex_height); + g_tex.textures[3]= mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", + &g_tex.tex_width, &g_tex.tex_height); +} \ No newline at end of file From d7903ec6150407f91c6d14e26b1bd17b0e4beeee Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 17 Oct 2024 12:29:58 +0200 Subject: [PATCH 23/80] fix: moving --- move.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/move.c b/move.c index 7d2436e..00edc79 100644 --- a/move.c +++ b/move.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:47:34 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 18:22:58 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 12:29:23 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ static int move(int factor) (int)(g_map.player.pos.y) )->wall == EMPTY ) - g_map.player.pos.x += dir.x * MOVE_SPEED; + g_map.player.pos.x += dir.x * MOVE_SPEED * factor; if (map_get_case(&g_map, (int)(g_map.player.pos.x), (int)(g_map.player.pos.y + dir.y * MOVE_SPEED * factor) From 20e92ef401fbe0d3a2e7a649f4920465a0862d79 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 17 Oct 2024 14:21:27 +0200 Subject: [PATCH 24/80] change: moving with hitbox --- algo.h | 3 ++- move.c | 53 ++++++++++++++++++++++++++++++++----------- testmaps/good_big.cub | 15 ++++++++++++ 3 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 testmaps/good_big.cub diff --git a/algo.h b/algo.h index 55be665..cec8e7b 100644 --- a/algo.h +++ b/algo.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/15 16:57:48 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 14:19:12 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,6 +39,7 @@ # define SCREEN_WIDTH 640 // px # define SCREEN_HEIGHT 480 // px # define FOV 0.66 // ? TODO unit +# define HITBOX 0.25 // cases. should be more than MOVE_SPEED extern void *g_mlx; extern void *g_win; diff --git a/move.c b/move.c index 00edc79..405faaf 100644 --- a/move.c +++ b/move.c @@ -6,29 +6,56 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:47:34 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 12:29:23 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 14:20:10 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #include "algo.h" +static void push_from_wall(t_point_int c) +{ + if (map_get_case(&g_map, c.x, c.y)->wall == EMPTY) + return ; + if (g_map.player.pos.x < c.x + 1 + HITBOX && g_map.player.pos.x > c.x + 1) + g_map.player.pos.x = c.x + 1 + HITBOX; + if (g_map.player.pos.x > c.x - HITBOX && g_map.player.pos.x < c.x) + g_map.player.pos.x = c.x - HITBOX; + if (g_map.player.pos.y < c.y + 1 + HITBOX && g_map.player.pos.y > c.y + 1) + g_map.player.pos.y = c.y + 1 + HITBOX; + if (g_map.player.pos.y > c.y - HITBOX && g_map.player.pos.y < c.y) + g_map.player.pos.y = c.y - HITBOX; +} + +static void push_from_walls(void) +{ + t_point_int c; + t_point_int p; + + p.x = g_map.player.pos.x; + p.y = g_map.player.pos.y; + c.x = p.x - 1; + c.y = p.y; + push_from_wall(c); + c.x = p.x + 1; + c.y = p.y; + push_from_wall(c); + c.x = p.x; + c.y = p.y - 1; + push_from_wall(c); + c.x = p.x; + c.y = p.y + 1; + push_from_wall(c); +} + static int move(int factor) { t_point_double dir; vector_from_rotation(&dir, g_map.player.rot, 1); - if (map_get_case(&g_map, - (int)(g_map.player.pos.x + dir.x * MOVE_SPEED * factor), - (int)(g_map.player.pos.y) - )->wall == EMPTY - ) - g_map.player.pos.x += dir.x * MOVE_SPEED * factor; - if (map_get_case(&g_map, - (int)(g_map.player.pos.x), - (int)(g_map.player.pos.y + dir.y * MOVE_SPEED * factor) - )->wall == EMPTY - ) - g_map.player.pos.y += dir.y * MOVE_SPEED * factor; + g_map.player.pos.x += dir.x * MOVE_SPEED * factor; + g_map.player.pos.y += dir.y * MOVE_SPEED * factor; + push_from_walls(); + printf("%f %f\n", g_map.player.pos.x, g_map.player.pos.y); return (0); } diff --git a/testmaps/good_big.cub b/testmaps/good_big.cub new file mode 100644 index 0000000..c118d77 --- /dev/null +++ b/testmaps/good_big.cub @@ -0,0 +1,15 @@ +F 255,127,0 +EA eastimage +NO theimageforthenorthwall +C 0,2,67 +SO SOUTH!!!!!!1 +WE weeeee +111111111 +100000001 +100000001 +100000001 +1000N0001 +100000001 +100000001 +100000001 +111111111 From 3ab5f9cb1ddfe4416837f610c7a143ee447ce434 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 17 Oct 2024 15:09:07 +0200 Subject: [PATCH 25/80] change: fluid movements --- algo.c | 24 +++++++++++++++++++++++- algo.h | 10 +++++----- input.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ input.h | 35 +++++++++++++++++++++++++++++++++++ move.c | 27 ++++++++++----------------- utils.c | 42 ++++++++++++++++++++++++++++++++++++++++-- utils.h | 9 ++++++++- 7 files changed, 173 insertions(+), 26 deletions(-) create mode 100644 input.c create mode 100644 input.h diff --git a/algo.c b/algo.c index 9d32093..d3a3668 100644 --- a/algo.c +++ b/algo.c @@ -6,11 +6,12 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/17 12:10:07 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 15:00:28 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #include "algo.h" +#include "input.h" void *g_mlx = NULL; void *g_win = NULL; @@ -54,9 +55,28 @@ void load_textures(t_tex *tex) &width, &height); } +static void loop(void) +{ + move(); + if (g_input_actions.quit) + { + mlx_destroy_window(g_mlx, g_win); + exit(0); + } + draw_screen(); +} + +static int loop_hook(void *param) +{ + (void)param; + timedloop(loop); + return (0); +} + int main(int argc, char *argv[]) { g_mlx = mlx_init(); + input_init(); if (argc != 2) { printf("Syntax: %s \n", argv[0]); @@ -66,6 +86,8 @@ int main(int argc, char *argv[]) return (1); g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d"); mlx_hook(g_win, KeyPress, KeyPressMask, keypress, NULL); + mlx_hook(g_win, KeyRelease, KeyReleaseMask, keyrelease, NULL); + mlx_loop_hook(g_mlx, loop_hook, NULL); draw_screen(); mlx_loop(g_mlx); return (0); diff --git a/algo.h b/algo.h index cec8e7b..fcff0de 100644 --- a/algo.h +++ b/algo.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/17 14:19:12 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 15:07:14 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,9 +30,9 @@ # define MAP_HEIGHT 24 // cases (TODO test) # define TEX_WIDTH 64 # define TEX_HEIGHT 64 -# define MOVE_SPEED 0.1 // cases +# define MOVE_SPEED 0.05 // cases # define PI 3.1415926535 -# define ROT_SPEED_DIVIDE_PI 16 // pi/n rad +# define ROT_SPEED_DIVIDE_PI 64 // pi/n rad # define COLOR_WALL 0xFF0000 // 0xRRGGBB # define COLOR_CEILING 0x29f8ff // 0xRRGGBB # define COLOR_FLOOR 0xFF985C // 0xRRGGBB @@ -63,10 +63,10 @@ void write_err(const char *str, ...); void vector_from_rotation(t_point_double *vec, double angle, double norm); -int keypress(int keycode); - int render(u_int32_t *img_data); void draw_screen(void); +void move(void); + #endif diff --git a/input.c b/input.c new file mode 100644 index 0000000..b336d91 --- /dev/null +++ b/input.c @@ -0,0 +1,52 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* input.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/17 14:43:36 by mcolonna #+# #+# */ +/* Updated: 2024/10/17 15:00:54 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "input.h" +#include +#include "algo.h" + +t_input_actions g_input_actions; + +static void set_action(int keycode, bool value) +{ + if (keycode == XK_Up || keycode == XK_z || keycode == XK_w) + g_input_actions.up = value; + if (keycode == XK_Down || keycode == XK_s) + g_input_actions.down = value; + if (keycode == XK_Right || keycode == XK_d) + g_input_actions.right = value; + if (keycode == XK_Left || keycode == XK_q || keycode == XK_a) + g_input_actions.left = value; + if (keycode == XK_Escape) + g_input_actions.quit = value; +} + +int keypress(int keycode) +{ + set_action(keycode, true); + return (0); +} + +int keyrelease(int keycode) +{ + set_action(keycode, false); + return (0); +} + +void input_init(void) +{ + g_input_actions.down = false; + g_input_actions.up = false; + g_input_actions.left = false; + g_input_actions.right = false; + g_input_actions.quit = false; +} diff --git a/input.h b/input.h new file mode 100644 index 0000000..becd5a1 --- /dev/null +++ b/input.h @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* input.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/17 14:43:09 by mcolonna #+# #+# */ +/* Updated: 2024/10/17 14:59:41 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef INPUT_H +# define INPUT_H + +# include + +/// @brief Modified by the input of the user. A value becomes true +/// when the user presses the corresponding key. +typedef struct s_input_actions +{ + bool left; + bool right; + bool up; + bool down; + bool quit; +} t_input_actions; + +extern t_input_actions g_input_actions; + +int keypress(int keycode); +int keyrelease(int keycode); +void input_init(void); + +#endif diff --git a/move.c b/move.c index 405faaf..8511c2f 100644 --- a/move.c +++ b/move.c @@ -6,11 +6,12 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:47:34 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 14:20:10 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 15:06:43 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #include "algo.h" +#include "input.h" static void push_from_wall(t_point_int c) { @@ -47,7 +48,7 @@ static void push_from_walls(void) push_from_wall(c); } -static int move(int factor) +static int move_forward(int factor) { t_point_double dir; @@ -55,7 +56,6 @@ static int move(int factor) g_map.player.pos.x += dir.x * MOVE_SPEED * factor; g_map.player.pos.y += dir.y * MOVE_SPEED * factor; push_from_walls(); - printf("%f %f\n", g_map.player.pos.x, g_map.player.pos.y); return (0); } @@ -67,21 +67,14 @@ static int rotate(int factor) // TODO leaks when quit? -int keypress(int keycode) +void move(void) { - if (keycode == XK_Up || keycode == XK_z || keycode == XK_w) - move(+1); - if (keycode == XK_Down || keycode == XK_s) - move(-1); - if (keycode == XK_Right || keycode == XK_d) + if (g_input_actions.up && !g_input_actions.down) + move_forward(+1); + if (g_input_actions.down && !g_input_actions.up) + move_forward(-1); + if (g_input_actions.right && !g_input_actions.left) rotate(+1); - if (keycode == XK_Left || keycode == XK_q || keycode == XK_a) + if (g_input_actions.left && !g_input_actions.right) rotate(-1); - if (keycode == XK_Escape) - { - mlx_destroy_window(g_mlx, g_win); - exit(0); - } - draw_screen(); - return (0); } diff --git a/utils.c b/utils.c index 48e0c16..6e8a570 100644 --- a/utils.c +++ b/utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:38:40 by mcolonna #+# #+# */ -/* Updated: 2024/10/16 18:01:25 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 15:05:15 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,3 +31,41 @@ void write_err(const char *str, ...) str = va_arg(args, const char *); } } + +/* FOR BONUS +static long get_nanos(void) +{ + struct timespec ts; + + timespec_get(&ts, TIME_UTC); + return ((long)ts.tv_sec * 1000000000L + ts.tv_nsec); +} + +void timedloop(void (*f)(void)) +{ + static long last_time = 0; + const long new_time = get_nanos(); + static bool checked = false; + + if (new_time - last_time >= 1000000000L / FPS) + { + if (checked) + last_time += 1000000000L / FPS; + else + last_time = new_time; + checked = false; + f(); + } + else + checked = true; +} +*/ + +void timedloop(void (*f)(void)) +{ + static int ticks; + + if (ticks % 100 == 0) + f(); + ticks++; +} diff --git a/utils.h b/utils.h index ccca448..93a619d 100644 --- a/utils.h +++ b/utils.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 16:56:47 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 17:21:10 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 14:41:09 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,4 +41,11 @@ t_color color_from_rgb(int red, int green, int blue); void write_err(const char *str, ...); +/// @brief Call the function in loop. +/// If not enough time passed since the last call, returns without doing +/// anything. +/// +/// @param f Function to call in loop. +void timedloop(void (*f)(void)); + #endif From 39158f48903aa3aac29cdcca8e08bd51f2488335 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 17 Oct 2024 16:04:45 +0200 Subject: [PATCH 26/80] fix: map parsing manages blank spaces better --- dev/cub.vim | 18 +++++++++++------- map_utils1.c | 8 +++++--- stream.c | 18 +++++++++++++++++- stream.h | 12 +++++++++++- testmaps/err_nospacebeforeparameter.cub | 11 +++++++++++ testmaps/good_reallyweirdblank.cub | 20 ++++++++++++++++++++ 6 files changed, 75 insertions(+), 12 deletions(-) create mode 100644 testmaps/err_nospacebeforeparameter.cub create mode 100644 testmaps/good_reallyweirdblank.cub diff --git a/dev/cub.vim b/dev/cub.vim index 49b1f11..7f7921c 100644 --- a/dev/cub.vim +++ b/dev/cub.vim @@ -1,23 +1,27 @@ -# Vim plugin to edit .cub files +" Vim plugin to edit .cub files +" Copy this file in ~/.vim/plugin/ function! CubSyntax() if expand('%:e') == 'cub' -highlight cubParameter ctermfg=blue -syntax match cubParameter /^(NO|SO|WE|EA|F|C) .$/ - -highlight cubDefault ctermfg=white +highlight cubDefault ctermfg=white ctermbg=red syntax match cubDefault /./ -highlight cub0 ctermfg=grey +highlight cubEmpty ctermbg=darkblue +syntax match cubEmpty / / + +highlight cub0 cterm=bold ctermfg=grey syntax match cub0 /0/ highlight cub1 cterm=bold ctermfg=white syntax match cub1 /1/ -highlight cubP cterm=bold ctermfg=blue +highlight cubP cterm=bold ctermfg=yellow syntax match cubP /[NSWE]/ +highlight cubParameter cterm=NONE ctermfg=yellow ctermbg=black +syntax match cubParameter /\v^(NO|SO|WE|EA|C|F).*$/ + endif endfunction autocmd BufReadPost * call CubSyntax() diff --git a/map_utils1.c b/map_utils1.c index 5b8acd2..68cadee 100644 --- a/map_utils1.c +++ b/map_utils1.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 15:02:09 by mc #+# #+# */ -/* Updated: 2024/10/15 17:43:29 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 15:59:15 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,8 @@ bool read_color_parameter(const char *name, t_color *dest, old = *stream; err = false; read_expected_string(name, stream, &err); - read_expected_string(" ", stream, &err); + if (!read_blank(stream)) + err = true; read_unsigned(&rgb[0], stream, &err); read_expected_string(",", stream, &err); read_unsigned(&rgb[1], stream, &err); @@ -56,7 +57,8 @@ bool read_string_parameter(const char *name, const char **dest, err = false; r = NULL; read_expected_string(name, stream, &err); - read_expected_string(" ", stream, &err); + if (!read_blank(stream)) + err = true; read_until('\n', &r, stream, &err); read_expected_string("\n", stream, &err); if (!err && *dest) diff --git a/stream.c b/stream.c index 107c464..9617970 100644 --- a/stream.c +++ b/stream.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/02 14:08:10 by mcolonna #+# #+# */ -/* Updated: 2024/10/02 17:31:34 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 16:02:33 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,7 @@ void read_expected_string(const char *str, t_stream *stream, bool *err) if (*err) return ; + read_blank(stream); i = 0; while (str[i]) { @@ -48,6 +49,7 @@ void read_unsigned(unsigned int *dest, t_stream *stream, bool *err) if (*err) return ; + read_blank(stream); if (!is_digit(stream->str[stream->i])) { *err = true; @@ -69,6 +71,7 @@ void read_until(char c, char **dest, t_stream *stream, bool *err) if (*err) return ; + read_blank(stream); len = 0; while (stream->str[stream->i + len] && stream->str[stream->i + len] != c) len++; @@ -87,3 +90,16 @@ void read_until(char c, char **dest, t_stream *stream, bool *err) } (*dest)[i] = '\0'; } + +bool read_blank(t_stream *stream) +{ + if (stream->str[stream->i] != ' ' + && stream->str[stream->i] != '\t') + return (false); + while ( + stream->str[stream->i] == ' ' + || stream->str[stream->i] == '\t' + ) + stream->i++; + return (true); +} diff --git a/stream.h b/stream.h index 741c4e2..7b071ee 100644 --- a/stream.h +++ b/stream.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/02 12:33:25 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 16:17:34 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 15:57:59 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,6 +26,7 @@ typedef struct s_stream } t_stream; /// @brief Read a specific string, error if it isn't the expected string. +/// Skip the potential blank space before the string. /// /// @param str Expected string. /// @param stream Stream to use. @@ -34,6 +35,7 @@ typedef struct s_stream void read_expected_string(const char *str, t_stream *stream, bool *err); /// @brief Read an unsigned int (which fits the pattern /[0-9]+/). +/// Skip the potential blank space before the string. /// /// @param dest Will be set to the value of the unsigned integer. /// @param stream Stream to use. @@ -42,6 +44,7 @@ void read_expected_string(const char *str, t_stream *stream, bool *err); void read_unsigned(unsigned int *dest, t_stream *stream, bool *err); /// @brief Read a string until limit char or \0. +/// Skip the potential blank space before the string. /// /// @param c Limit char. /// @param dest Will be set to an alloc'd pointer to the read string. @@ -51,4 +54,11 @@ void read_unsigned(unsigned int *dest, t_stream *stream, bool *err); /// If already true, the function won't do anything. void read_until(char c, char **dest, t_stream *stream, bool *err); +/// @brief Read blank space until the next non-blank character or the EOF. +/// ' ' and '\t' are the only characters considered blank. +/// +/// @param stream Stream to use. +/// @return false if there was no blank space to read, true otherwise. +bool read_blank(t_stream *stream); + #endif diff --git a/testmaps/err_nospacebeforeparameter.cub b/testmaps/err_nospacebeforeparameter.cub new file mode 100644 index 0000000..cfdb502 --- /dev/null +++ b/testmaps/err_nospacebeforeparameter.cub @@ -0,0 +1,11 @@ +F 255,127,0 +EA eastimage +NO theimageforthenorthwall +C0,2,67 +SO SOUTH!!!!!!1 +WE weeeee +1111111 +1000001 +10W0001 +1000001 +1111111 diff --git a/testmaps/good_reallyweirdblank.cub b/testmaps/good_reallyweirdblank.cub new file mode 100644 index 0000000..de7124d --- /dev/null +++ b/testmaps/good_reallyweirdblank.cub @@ -0,0 +1,20 @@ +F 255, 127 ,0 + +EA eastimage + +NO theimageforthenorthwall +C 0, 2 , 67 + +SO SOUTH!!!!!!1 + +WE weeeee + + + + + +1111111 +1000001 +10W0001 +1000001 +1111111 From fa7e448c707bd8caabe0c9dc03e17af8a197a50d Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 17 Oct 2024 16:10:54 +0200 Subject: [PATCH 27/80] norm --- input.c | 6 +++--- map_utils1.c | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/input.c b/input.c index b336d91..45168e0 100644 --- a/input.c +++ b/input.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:36 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 15:00:54 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 16:05:50 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,13 +30,13 @@ static void set_action(int keycode, bool value) g_input_actions.quit = value; } -int keypress(int keycode) +int keypress(int keycode) { set_action(keycode, true); return (0); } -int keyrelease(int keycode) +int keyrelease(int keycode) { set_action(keycode, false); return (0); diff --git a/map_utils1.c b/map_utils1.c index 68cadee..4e12115 100644 --- a/map_utils1.c +++ b/map_utils1.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 15:02:09 by mc #+# #+# */ -/* Updated: 2024/10/17 15:59:15 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 16:09:31 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,8 +36,7 @@ bool read_color_parameter(const char *name, t_color *dest, if (!err && *dest != 0xFF000000) { *redefined = true; - write_err("Parameter '", name, "' was defined several times\n", - NULL); + write_err("Parameter '", name, "' was defined several times\n", NULL); } else if (!err) *dest = color_from_rgb(rgb[0], rgb[1], rgb[2]); From bc2d42d9417d70fbb7778b68ab23232bc67e8ee8 Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Thu, 17 Oct 2024 16:32:01 +0200 Subject: [PATCH 28/80] add texture --- Makefile | 2 +- algo.c | 29 +++++++++++---------- algo.h | 33 +++++++++++++++--------- render.c | 76 ++++++++++++++++++++++++++++++++++++++++++-------------- utils.c | 4 +-- utils2.c | 76 ++++++++++++++++++++++++++++++-------------------------- 6 files changed, 138 insertions(+), 82 deletions(-) diff --git a/Makefile b/Makefile index 4ef9264..ad84bcb 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ NAME = cub3d CPP = gcc $(FLAGS) LIBRARIES_DIR = Libft Minilibx LIBRARIES_A = Libft/libft.a Minilibx/libmlx.a -CPP_1 = $(CPP) -Wall -Wextra -Werror -I Libft -I Minilibx $(FLAGS_1) +CPP_1 = $(CPP) -Wall -Wextra -Werror -I Libft -I Minilibx $(FLAGS_1) -g CPP_2 = $(CPP) $(FLAGS_2) SHARED = -lX11 -lXext -lm C_FILES = $(wildcard **.c) diff --git a/algo.c b/algo.c index 08bdf5c..f042a1b 100644 --- a/algo.c +++ b/algo.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* algo.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/15 16:38:31 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 16:20:19 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,8 @@ void *g_mlx = NULL; void *g_win = NULL; t_map g_map; t_player g_player; +t_tex g_tex; +t_ray g_ray; // TODO manage image format error better @@ -39,24 +41,25 @@ void draw_screen(void) mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); } -void load_textures(t_tex *tex) +void load_textures() { - int width; - int height; + g_tex.tex_width = 64; + g_tex.tex_height = 64; - tex->tex_north = mlx_xpm_file_to_image(g_mlx, "textures/north.xpm", - &width, &height); - tex->tex_south = mlx_xpm_file_to_image(g_mlx, "textures/south.xpm", - &width, &height); - tex->tex_east = mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", - &width, &height); - tex->tex_west = mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", - &width, &height); + g_tex.textures[0] = mlx_xpm_file_to_image(g_mlx, "textures/north.xpm", + &g_tex.tex_width, &g_tex.tex_height); + g_tex.textures[1] = mlx_xpm_file_to_image(g_mlx, "textures/south.xpm", + &g_tex.tex_width, &g_tex.tex_height); + g_tex.textures[2]= mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", + &g_tex.tex_width, &g_tex.tex_height); + g_tex.textures[3]= mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", + &g_tex.tex_width, &g_tex.tex_height); } int main(int argc, char *argv[]) { g_mlx = mlx_init(); + load_textures(); if (argc != 2) { printf("Syntax: %s \n", argv[0]); diff --git a/algo.h b/algo.h index 55be665..03dafc2 100644 --- a/algo.h +++ b/algo.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* algo.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/15 16:57:48 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 15:17:36 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,20 +40,29 @@ # define SCREEN_HEIGHT 480 // px # define FOV 0.66 // ? TODO unit +typedef struct s_tex +{ + void *textures[4]; + void *current_tex; + int tex_height; + int tex_width; + int tex_dir; +} t_tex; + +typedef struct s_ray +{ + // pos player on map (cases) + t_point_double dir; + bool side; + double wallx; +} t_ray; + extern void *g_mlx; extern void *g_win; extern t_player g_player; extern t_map g_map; - -typedef struct s_tex -{ - void *tex_north; - void *tex_south; - void *tex_east; - void *tex_west; - void *current_tex; - -} t_tex; +extern t_tex g_tex; +extern t_ray g_ray; /// @brief Write an error message on stderr. /// diff --git a/render.c b/render.c index 6279fd5..26633f1 100644 --- a/render.c +++ b/render.c @@ -3,17 +3,18 @@ /* ::: :::::::: */ /* render.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/10/15 16:55:02 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 16:28:20 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ #include "algo.h" +#include static void calculate_perpwalldist3(int x, - t_point_double *raydir, t_point_double *deltadist) + t_point_double *deltadist) { const double ray_direction = 2 * x / (double)SCREEN_WIDTH - 1; t_point_double plane; @@ -21,14 +22,14 @@ static void calculate_perpwalldist3(int x, vector_from_rotation(&dir, g_map.player.rot, 1); vector_from_rotation(&plane, g_map.player.rot + PI / 2, 1); - raydir->x = dir.x + plane.x * ray_direction; - raydir->y = dir.y + plane.y * ray_direction; + g_ray.dir.x = dir.x + plane.x * ray_direction; + g_ray.dir.y = dir.y + plane.y * ray_direction; deltadist->x = 1e30; - if (raydir->x != 0) - deltadist->x = fabs(1 / raydir->x); + if (g_ray.dir.x != 0) + deltadist->x = fabs(1 / g_ray.dir.x); deltadist->y = 1e30; - if (raydir->y != 0) - deltadist->y = fabs(1 / raydir->y); + if (g_ray.dir.y != 0) + deltadist->y = fabs(1 / g_ray.dir.y); } static void calculate_perpwalldist2(int x, @@ -38,10 +39,10 @@ static void calculate_perpwalldist2(int x, { const int map_x = (int)g_map.player.pos.x; const int map_y = (int)g_map.player.pos.y; - t_point_double raydir; + // t_point_double raydir; - calculate_perpwalldist3(x, &raydir, deltadist); - if (raydir.x < 0) + calculate_perpwalldist3(x, deltadist); + if (g_ray.dir.x < 0) { step->x = -1; sidedist->x = (g_map.player.pos.x - map_x) * deltadist->x; @@ -51,7 +52,7 @@ static void calculate_perpwalldist2(int x, step->x = 1; sidedist->x = (map_x + 1.0 - g_map.player.pos.x) * deltadist->x; } - if (raydir.y < 0) + if (g_ray.dir.y < 0) { step->y = -1; sidedist->y = (g_map.player.pos.y - map_y) * deltadist->y; @@ -71,7 +72,7 @@ static void calculate_perpwalldist2(int x, static double calculate_perpwalldist(int x) { t_point_int map_pos; - bool side; + // bool side; t_point_double sidedist; t_point_double deltadist; t_point_int step; @@ -85,18 +86,37 @@ static double calculate_perpwalldist(int x) { sidedist.x += deltadist.x; map_pos.x += step.x; - side = false; + g_ray.side = false; continue ; } sidedist.y += deltadist.y; map_pos.y += step.y; - side = true; + g_ray.side = true; } - if (!side) + if (!g_ray.side) return (sidedist.x - deltadist.x); return (sidedist.y - deltadist.y); } +static void ft_init_texture(const double perpwalldist) +{ + if (g_ray.side == 0 && g_ray.dir.x < 0) + g_tex.tex_dir = 0; + if (g_ray.side == 0 && g_ray.dir.x >= 0) + g_tex.tex_dir = 1; + if (g_ray.side == 1 && g_ray.dir.y < 0) + g_tex.tex_dir = 2; + if (g_ray.side == 1 && g_ray.dir.y >= 0) + g_tex.tex_dir = 3; + if (g_ray.side == 0) + g_ray.wallx = g_player.pos.y + perpwalldist \ + * g_ray.dir.y; + else + g_ray.wallx = g_player.pos.x + perpwalldist \ + * g_ray.dir.x; + g_ray.wallx -= floor((g_ray.wallx)); +} + /// @brief Draw a vertical line according to the ray direction x. /// /// @param x Ray direction x between 0 and 1. @@ -107,7 +127,14 @@ static void draw_vertical_line(int x, u_int32_t *img_data) int draw_start; int draw_end; int y; + int tex_y; + int tex_x; + int bpp; + int size_line; + int endian; + u_int32_t color; + ft_init_texture(perpwalldist); draw_start = -line_height / 2 + SCREEN_HEIGHT / 2; if (draw_start < 0) draw_start = 0; @@ -120,7 +147,18 @@ static void draw_vertical_line(int x, u_int32_t *img_data) if (y < draw_start) img_data[y * SCREEN_WIDTH + x] = COLOR_CEILING; else if (y < draw_end) - img_data[y * SCREEN_WIDTH + x] = COLOR_WALL; + { + tex_y = ((y - draw_start) * g_tex.tex_height) / line_height; + tex_x = (int)(g_ray.wallx * g_tex.tex_width); + if (g_ray.side == 0 && g_ray.dir.x > 0) + tex_x = g_tex.tex_width - tex_x - 1; + if (g_ray.side == 1 && g_ray.dir.y < 0) + tex_x = g_tex.tex_height - tex_x - 1; + u_int32_t *texture_data = (u_int32_t *)mlx_get_data_addr(g_tex.textures[g_tex.tex_dir], &bpp, &size_line, &endian); + color = texture_data[tex_y * g_tex.tex_width + tex_x]; + img_data[y * SCREEN_WIDTH + x] = color; + // img_data[y * SCREEN_WIDTH + x] = COLOR_WALL; + } else img_data[y * SCREEN_WIDTH + x] = COLOR_FLOOR; y++; @@ -138,4 +176,4 @@ int render(u_int32_t *img_data) x++; } return (0); -} +} \ No newline at end of file diff --git a/utils.c b/utils.c index 48e0c16..283a990 100644 --- a/utils.c +++ b/utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:38:40 by mcolonna #+# #+# */ -/* Updated: 2024/10/16 18:01:25 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 13:43:50 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/utils2.c b/utils2.c index 6e3d3b3..dc81ffa 100644 --- a/utils2.c +++ b/utils2.c @@ -3,48 +3,54 @@ /* ::: :::::::: */ /* utils2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: greg +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 01:57:03 by greg #+# #+# */ -/* Updated: 2024/10/17 12:28:01 by greg ### ########.fr */ +/* Updated: 2024/10/17 14:58:33 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ // #include "algo.h" -void ft_init_texture() -{ - if (ray.side == 0 && ray.raydirx < 0) - direction = 0; - if (ray.side == 0 && ray.raydirx >= 0) - direction = 1; - if (ray.side == 1 && ray.raydiry < 0) - direction = 2; - if (ray.side == 1 && ray.raydiry >= 0) - direction = 3; - if (ray.side == 0) - t.wallx = ray.posy + ray.perpwalldist \ - * ray.raydiry; - else - t.wallx = ray.posx + ray.perpwalldist \ - * ray.raydirx; - t.wallx -= floor((t.wallx)); -} -texture[0].addr = (int *)mlx_get_data_addr(texture[0].img, &bpp, - texture[0].line_length, &endian); +// void ft_init_texture(const double perpwalldist) +// { +// if (g_ray.side == 0 && g_ray.dir.x < 0) +// g_tex.tex_dir = 0; +// if (g_ray.side == 0 && g_ray.dir.x >= 0) +// g_tex.tex_dir = 1; +// if (g_ray.side == 1 && g_ray.dir.y < 0) +// g_tex.tex_dir = 2; +// if (g_ray.side == 1 && g_ray.dir.y >= 0) +// g_tex.tex_dir = 3; +// if (g_ray.side == 0) +// g_ray.wallx = g_player.pos.y + perpwalldist +// * g_ray.dir.y; +// else +// g_ray.wallx = g_player.pos.x + perpwalldist +// * g_ray.dir.x; +// g_ray.wallx -= floor((g_ray.wallx)); +// } + +// void *tex_ptr = (int *)mlx_get_data_addr(texture[0].img, &bpp, +// g_tex, &endian); -void load_textures() -{ - g_tex.tex_width = 64; - g_tex.tex_height = 64; +// tex_y = ((y - draw_start) * texture_height) / line_height; - g_tex.textures[0] = mlx_xpm_file_to_image(g_mlx, "textures/north.xpm", - &g_tex.tex_width, &g_tex.tex_height); - g_tex.textures[1] = mlx_xpm_file_to_image(g_mlx, "textures/south.xpm", - &g_tex.tex_width, &g_tex.tex_height); - g_tex.textures[2]= mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", - &g_tex.tex_width, &g_tex.tex_height); - g_tex.textures[3]= mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", - &g_tex.tex_width, &g_tex.tex_height); -} \ No newline at end of file +// tex_x = (int)(wall_x * (double)texture_width); +// if ((!side && raydir.x > 0) || (side && raydir.y < 0)) +// { +// tex_x = texture_width - tex_x - 1; +// } + +// u_int32_t color = textures[direction][tex_y * texture_width + tex_x]; + + + // else if (y < draw_end) + // { + // tex_y = ((y - draw_start) * g_tex.tex_height) / line_height; + // tex_x = (int)(g_ray.wallx * g_tex.tex_width); + // u_int32_t *texture_data = (u_int32_t *)g_tex.textures[g_tex.tex_dir]; + // u_int32_t color = texture_data[tex_y * g_tex.tex_width + tex_x]; + // img_data[y * SCREEN_WIDTH + x] = color; + // } \ No newline at end of file From e74045d3189fa6935f7cb21423f325420e199869 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 17 Oct 2024 16:59:35 +0200 Subject: [PATCH 29/80] fix: leak --- algo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/algo.c b/algo.c index 24e3964..d60b6cd 100644 --- a/algo.c +++ b/algo.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/17 16:35:28 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 16:59:16 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,6 +40,7 @@ void draw_screen(void) } render(img_data); mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); + mlx_destroy_image(g_mlx, img_ptr); } void load_textures() From dee20e3897fee371afeb7f31a2867df37e82e8d8 Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Thu, 17 Oct 2024 17:06:31 +0200 Subject: [PATCH 30/80] mini correction --- render.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/render.c b/render.c index 26633f1..b1e3958 100644 --- a/render.c +++ b/render.c @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/10/17 16:28:20 by grobledo ### ########.fr */ +/* Updated: 2024/10/17 16:56:10 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -153,9 +153,9 @@ static void draw_vertical_line(int x, u_int32_t *img_data) if (g_ray.side == 0 && g_ray.dir.x > 0) tex_x = g_tex.tex_width - tex_x - 1; if (g_ray.side == 1 && g_ray.dir.y < 0) - tex_x = g_tex.tex_height - tex_x - 1; + tex_x = g_tex.tex_width - tex_x - 1; u_int32_t *texture_data = (u_int32_t *)mlx_get_data_addr(g_tex.textures[g_tex.tex_dir], &bpp, &size_line, &endian); - color = texture_data[tex_y * g_tex.tex_width + tex_x]; + color = texture_data[tex_x * g_tex.tex_width + tex_y]; img_data[y * SCREEN_WIDTH + x] = color; // img_data[y * SCREEN_WIDTH + x] = COLOR_WALL; } From 88c3d128fd3db3a3b6d4cf50be031dfa3abf3ad5 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 17 Oct 2024 17:44:39 +0200 Subject: [PATCH 31/80] fix: leak screen image buffer --- algo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/algo.c b/algo.c index d3a3668..8ce0356 100644 --- a/algo.c +++ b/algo.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/17 15:00:28 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 17:43:07 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,6 +38,7 @@ void draw_screen(void) } render(img_data); mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); + mlx_destroy_image(g_mlx, img_ptr); } void load_textures(t_tex *tex) From aaf2b0adc8a5b3ece05a6b68c826068d97956006 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 17 Oct 2024 17:59:41 +0200 Subject: [PATCH 32/80] fix: map parsing error --- map_utils.h | 7 +------ map_utils1.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/map_utils.h b/map_utils.h index 733d6f4..6f35bba 100644 --- a/map_utils.h +++ b/map_utils.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 15:05:13 by mc #+# #+# */ -/* Updated: 2024/10/15 17:23:40 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 17:58:23 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,11 +43,6 @@ bool read_color_parameter(const char *name, t_color *dest, bool read_string_parameter(const char *name, const char **dest, t_stream *stream, bool *redefined); -/// @brief Set the map to initial values. Every texture becomes NULL -/// and every color becomes 0xFF000000. -/// @param dest Map to reset. -void reset_map(t_map *dest); - /// @brief Read a map-formatted string. /// If an error occurs, write an error message on stderr. /// @param dest Will be set to the map. diff --git a/map_utils1.c b/map_utils1.c index 4e12115..9edd47a 100644 --- a/map_utils1.c +++ b/map_utils1.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 15:02:09 by mc #+# #+# */ -/* Updated: 2024/10/17 16:09:31 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 17:59:05 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -75,7 +75,7 @@ bool read_string_parameter(const char *name, const char **dest, return (!err); } -void reset_map(t_map *dest) +static void read_map2(t_map *dest, bool *err, bool *rdf) { dest->cases = NULL; dest->color_ceiling = 0xFF000000; @@ -84,18 +84,20 @@ void reset_map(t_map *dest) dest->texture_west = NULL; dest->texture_north = NULL; dest->texture_south = NULL; + *err = false; + *rdf = false; } bool read_map(t_map *dest, t_stream *stream) { bool err; bool rdf; + int old_stream_i; - reset_map(dest); - err = false; - rdf = false; + read_map2(dest, &err, &rdf); while (!rdf && !err && stream->str[stream->i]) { + old_stream_i = stream->i; if ((read_expected_string("\n", stream, &err), err) && !read_string_parameter("NO", &dest->texture_north, stream, &rdf) && !read_string_parameter("SO", &dest->texture_south, stream, &rdf) @@ -104,6 +106,7 @@ bool read_map(t_map *dest, t_stream *stream) && !read_color_parameter("F", &dest->color_floor, stream, &rdf) && !read_color_parameter("C", &dest->color_ceiling, stream, &rdf)) { + stream->i = old_stream_i; err = !read_map_description(dest, stream); break ; } From fab7758283d833d67d93e06cdd6e0bbb46df8028 Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Thu, 17 Oct 2024 18:04:40 +0200 Subject: [PATCH 33/80] manque render mur pas fixe --- render.c | 9 ++++----- testmaps/good_directions.cub | 2 +- utils2.c | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/render.c b/render.c index b1e3958..cbcbc5c 100644 --- a/render.c +++ b/render.c @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/10/17 16:56:10 by grobledo ### ########.fr */ +/* Updated: 2024/10/17 18:02:06 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -148,16 +148,15 @@ static void draw_vertical_line(int x, u_int32_t *img_data) img_data[y * SCREEN_WIDTH + x] = COLOR_CEILING; else if (y < draw_end) { - tex_y = ((y - draw_start) * g_tex.tex_height) / line_height; - tex_x = (int)(g_ray.wallx * g_tex.tex_width); + tex_y = ((y - (-line_height / 2 + SCREEN_HEIGHT / 2)) * g_tex.tex_height) / line_height; + tex_x = (int)(g_ray.wallx * (double)g_tex.tex_width); if (g_ray.side == 0 && g_ray.dir.x > 0) tex_x = g_tex.tex_width - tex_x - 1; if (g_ray.side == 1 && g_ray.dir.y < 0) - tex_x = g_tex.tex_width - tex_x - 1; + tex_x = g_tex.tex_height - tex_x - 1; u_int32_t *texture_data = (u_int32_t *)mlx_get_data_addr(g_tex.textures[g_tex.tex_dir], &bpp, &size_line, &endian); color = texture_data[tex_x * g_tex.tex_width + tex_y]; img_data[y * SCREEN_WIDTH + x] = color; - // img_data[y * SCREEN_WIDTH + x] = COLOR_WALL; } else img_data[y * SCREEN_WIDTH + x] = COLOR_FLOOR; diff --git a/testmaps/good_directions.cub b/testmaps/good_directions.cub index 0701362..d27f00d 100644 --- a/testmaps/good_directions.cub +++ b/testmaps/good_directions.cub @@ -4,7 +4,7 @@ NO theimageforthenorthwall C 0,2,67 SO SOUTH!!!!!!1 WE weeeee - 111 +111111111 111110111 10000N001 111110111 diff --git a/utils2.c b/utils2.c index dc81ffa..9a323a8 100644 --- a/utils2.c +++ b/utils2.c @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 01:57:03 by greg #+# #+# */ -/* Updated: 2024/10/17 14:58:33 by grobledo ### ########.fr */ +/* Updated: 2024/10/17 17:39:18 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ From ff7ba8760db7ce1b8e9a6648d03a5f413371aeec Mon Sep 17 00:00:00 2001 From: ReverseSky Date: Fri, 18 Oct 2024 02:03:07 +0200 Subject: [PATCH 34/80] textures fixed --- render.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/render.c b/render.c index cbcbc5c..adfc5f4 100644 --- a/render.c +++ b/render.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* render.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ +/* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/10/17 18:02:06 by grobledo ### ########.fr */ +/* Updated: 2024/10/18 02:02:32 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -109,10 +109,10 @@ static void ft_init_texture(const double perpwalldist) if (g_ray.side == 1 && g_ray.dir.y >= 0) g_tex.tex_dir = 3; if (g_ray.side == 0) - g_ray.wallx = g_player.pos.y + perpwalldist \ + g_ray.wallx = g_map.player.pos.y + perpwalldist \ * g_ray.dir.y; else - g_ray.wallx = g_player.pos.x + perpwalldist \ + g_ray.wallx = g_map.player.pos.x + perpwalldist \ * g_ray.dir.x; g_ray.wallx -= floor((g_ray.wallx)); } From 50c4e563032a70c92692b2e5cdc076e087eaf9f6 Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Tue, 22 Oct 2024 15:59:58 +0200 Subject: [PATCH 35/80] removed g_ray and g_tex --- algo.c | 44 +++++++++---------- algo.h | 9 ++-- render.c | 100 +++++++++++++++++++++--------------------- testmaps/good_big.cub | 2 +- 4 files changed, 77 insertions(+), 78 deletions(-) diff --git a/algo.c b/algo.c index d60b6cd..95bcf92 100644 --- a/algo.c +++ b/algo.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* algo.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/17 16:59:16 by mcolonna ### ########.fr */ +/* Updated: 2024/10/22 15:48:47 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,19 +17,35 @@ void *g_mlx = NULL; void *g_win = NULL; t_map g_map; t_player g_player; -t_tex g_tex; -t_ray g_ray; +// t_tex g_tex; // TODO manage image format error better -void draw_screen(void) +static void load_textures(t_tex *tex) +{ + tex->tex_width = 64; + tex->tex_height = 64; + + tex->textures[0] = mlx_xpm_file_to_image(g_mlx, "textures/north.xpm", + &tex->tex_width, &tex->tex_height); + tex->textures[1] = mlx_xpm_file_to_image(g_mlx, "textures/south.xpm", + &tex->tex_width, &tex->tex_height); + tex->textures[2]= mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", + &tex->tex_width, &tex->tex_height); + tex->textures[3]= mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", + &tex->tex_width, &tex->tex_height); +} + +void draw_screen() { int bpp; int size_line; int endian; void *img_ptr; u_int32_t *img_data; + t_tex tex; + load_textures(&tex); img_ptr = mlx_new_image(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT); img_data = (u_int32_t *) mlx_get_data_addr(img_ptr, &bpp, &size_line, &endian); @@ -38,26 +54,11 @@ void draw_screen(void) printf("image format error\n"); exit(1); } - render(img_data); + render(img_data, &tex); mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); mlx_destroy_image(g_mlx, img_ptr); } -void load_textures() -{ - g_tex.tex_width = 64; - g_tex.tex_height = 64; - - g_tex.textures[0] = mlx_xpm_file_to_image(g_mlx, "textures/north.xpm", - &g_tex.tex_width, &g_tex.tex_height); - g_tex.textures[1] = mlx_xpm_file_to_image(g_mlx, "textures/south.xpm", - &g_tex.tex_width, &g_tex.tex_height); - g_tex.textures[2]= mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", - &g_tex.tex_width, &g_tex.tex_height); - g_tex.textures[3]= mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", - &g_tex.tex_width, &g_tex.tex_height); -} - static void loop(void) { move(); @@ -80,7 +81,6 @@ int main(int argc, char *argv[]) { g_mlx = mlx_init(); input_init(); - load_textures(); if (argc != 2) { printf("Syntax: %s \n", argv[0]); diff --git a/algo.h b/algo.h index 0700d7a..270937f 100644 --- a/algo.h +++ b/algo.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* algo.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/17 16:34:32 by mcolonna ### ########.fr */ +/* Updated: 2024/10/22 15:48:21 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,8 +62,7 @@ extern void *g_mlx; extern void *g_win; extern t_player g_player; extern t_map g_map; -extern t_tex g_tex; -extern t_ray g_ray; +// extern t_tex g_tex; /// @brief Write an error message on stderr. /// @@ -72,7 +71,7 @@ void write_err(const char *str, ...); void vector_from_rotation(t_point_double *vec, double angle, double norm); -int render(u_int32_t *img_data); +int render(u_int32_t *img_data, t_tex *tex); void draw_screen(void); diff --git a/render.c b/render.c index adfc5f4..27bb911 100644 --- a/render.c +++ b/render.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* render.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: greg +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/10/18 02:02:32 by greg ### ########.fr */ +/* Updated: 2024/10/22 15:50:27 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,8 @@ #include static void calculate_perpwalldist3(int x, - t_point_double *deltadist) + t_point_double *deltadist, + t_ray *ray) { const double ray_direction = 2 * x / (double)SCREEN_WIDTH - 1; t_point_double plane; @@ -22,27 +23,27 @@ static void calculate_perpwalldist3(int x, vector_from_rotation(&dir, g_map.player.rot, 1); vector_from_rotation(&plane, g_map.player.rot + PI / 2, 1); - g_ray.dir.x = dir.x + plane.x * ray_direction; - g_ray.dir.y = dir.y + plane.y * ray_direction; + ray->dir.x = dir.x + plane.x * ray_direction; + ray->dir.y = dir.y + plane.y * ray_direction; deltadist->x = 1e30; - if (g_ray.dir.x != 0) - deltadist->x = fabs(1 / g_ray.dir.x); + if (ray->dir.x != 0) + deltadist->x = fabs(1 / ray->dir.x); deltadist->y = 1e30; - if (g_ray.dir.y != 0) - deltadist->y = fabs(1 / g_ray.dir.y); + if (ray->dir.y != 0) + deltadist->y = fabs(1 / ray->dir.y); } static void calculate_perpwalldist2(int x, t_point_double *sidedist, t_point_double *deltadist, - t_point_int *step) + t_point_int *step, + t_ray *ray) { const int map_x = (int)g_map.player.pos.x; const int map_y = (int)g_map.player.pos.y; - // t_point_double raydir; - calculate_perpwalldist3(x, deltadist); - if (g_ray.dir.x < 0) + calculate_perpwalldist3(x, deltadist, ray); + if (ray->dir.x < 0) { step->x = -1; sidedist->x = (g_map.player.pos.x - map_x) * deltadist->x; @@ -52,7 +53,7 @@ static void calculate_perpwalldist2(int x, step->x = 1; sidedist->x = (map_x + 1.0 - g_map.player.pos.x) * deltadist->x; } - if (g_ray.dir.y < 0) + if (ray->dir.y < 0) { step->y = -1; sidedist->y = (g_map.player.pos.y - map_y) * deltadist->y; @@ -69,60 +70,59 @@ static void calculate_perpwalldist2(int x, /// /// @param x Ray direction x between 0 and 1. /// @return Result. -static double calculate_perpwalldist(int x) +static double calculate_perpwalldist(int x, t_ray *ray) { t_point_int map_pos; - // bool side; t_point_double sidedist; t_point_double deltadist; t_point_int step; map_pos.x = (int)g_map.player.pos.x; map_pos.y = (int)g_map.player.pos.y; - calculate_perpwalldist2(x, &sidedist, &deltadist, &step); + calculate_perpwalldist2(x, &sidedist, &deltadist, &step, ray); while (map_get_case(&g_map, map_pos.x, map_pos.y)->wall == EMPTY) { if (sidedist.x < sidedist.y) { sidedist.x += deltadist.x; map_pos.x += step.x; - g_ray.side = false; + ray->side = false; continue ; } sidedist.y += deltadist.y; map_pos.y += step.y; - g_ray.side = true; + ray->side = true; } - if (!g_ray.side) + if (!ray->side) return (sidedist.x - deltadist.x); return (sidedist.y - deltadist.y); } -static void ft_init_texture(const double perpwalldist) +static void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex) { - if (g_ray.side == 0 && g_ray.dir.x < 0) - g_tex.tex_dir = 0; - if (g_ray.side == 0 && g_ray.dir.x >= 0) - g_tex.tex_dir = 1; - if (g_ray.side == 1 && g_ray.dir.y < 0) - g_tex.tex_dir = 2; - if (g_ray.side == 1 && g_ray.dir.y >= 0) - g_tex.tex_dir = 3; - if (g_ray.side == 0) - g_ray.wallx = g_map.player.pos.y + perpwalldist \ - * g_ray.dir.y; + if (ray->side == 0 && ray->dir.x < 0) + tex->tex_dir = 0; + if (ray->side == 0 && ray->dir.x >= 0) + tex->tex_dir = 1; + if (ray->side == 1 && ray->dir.y < 0) + tex->tex_dir = 2; + if (ray->side == 1 && ray->dir.y >= 0) + tex->tex_dir = 3; + if (ray->side == 0) + ray->wallx = g_map.player.pos.y + perpwalldist \ + * ray->dir.y; else - g_ray.wallx = g_map.player.pos.x + perpwalldist \ - * g_ray.dir.x; - g_ray.wallx -= floor((g_ray.wallx)); + ray->wallx = g_map.player.pos.x + perpwalldist \ + * ray->dir.x; + ray->wallx -= floor((ray->wallx)); } /// @brief Draw a vertical line according to the ray direction x. /// /// @param x Ray direction x between 0 and 1. -static void draw_vertical_line(int x, u_int32_t *img_data) +static void draw_vertical_line(int x, u_int32_t *img_data, t_ray *ray, t_tex *tex) { - const double perpwalldist = calculate_perpwalldist(x); + const double perpwalldist = calculate_perpwalldist(x, ray); const int line_height = (int)(SCREEN_HEIGHT / perpwalldist); int draw_start; int draw_end; @@ -134,7 +134,7 @@ static void draw_vertical_line(int x, u_int32_t *img_data) int endian; u_int32_t color; - ft_init_texture(perpwalldist); + ft_init_texture(perpwalldist, ray, tex); draw_start = -line_height / 2 + SCREEN_HEIGHT / 2; if (draw_start < 0) draw_start = 0; @@ -148,14 +148,14 @@ static void draw_vertical_line(int x, u_int32_t *img_data) img_data[y * SCREEN_WIDTH + x] = COLOR_CEILING; else if (y < draw_end) { - tex_y = ((y - (-line_height / 2 + SCREEN_HEIGHT / 2)) * g_tex.tex_height) / line_height; - tex_x = (int)(g_ray.wallx * (double)g_tex.tex_width); - if (g_ray.side == 0 && g_ray.dir.x > 0) - tex_x = g_tex.tex_width - tex_x - 1; - if (g_ray.side == 1 && g_ray.dir.y < 0) - tex_x = g_tex.tex_height - tex_x - 1; - u_int32_t *texture_data = (u_int32_t *)mlx_get_data_addr(g_tex.textures[g_tex.tex_dir], &bpp, &size_line, &endian); - color = texture_data[tex_x * g_tex.tex_width + tex_y]; + tex_y = ((y - (-line_height / 2 + SCREEN_HEIGHT / 2)) * tex->tex_height) / line_height; + tex_x = (int)(ray->wallx * (double)tex->tex_width); + if (ray->side == 0 && ray->dir.x > 0) + tex_x = tex->tex_width - tex_x - 1; + if (ray->side == 1 && ray->dir.y < 0) + tex_x = tex->tex_height - tex_x - 1; + u_int32_t *texture_data = (u_int32_t *)mlx_get_data_addr(tex->textures[tex->tex_dir], &bpp, &size_line, &endian); + color = texture_data[tex_x * tex->tex_width + tex_y]; img_data[y * SCREEN_WIDTH + x] = color; } else @@ -164,14 +164,14 @@ static void draw_vertical_line(int x, u_int32_t *img_data) } } -int render(u_int32_t *img_data) +int render(u_int32_t *img_data, t_tex *tex) { - int x; - + int x; + t_ray ray; x = 0; while (x < SCREEN_WIDTH) { - draw_vertical_line(x, img_data); + draw_vertical_line(x, img_data, &ray, tex); x++; } return (0); diff --git a/testmaps/good_big.cub b/testmaps/good_big.cub index c118d77..fbf802a 100644 --- a/testmaps/good_big.cub +++ b/testmaps/good_big.cub @@ -6,7 +6,7 @@ SO SOUTH!!!!!!1 WE weeeee 111111111 100000001 -100000001 +100010001 100000001 1000N0001 100000001 From 8e650871e75fda1e5cbdb20425221ca9a92332b6 Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Tue, 29 Oct 2024 13:52:11 +0100 Subject: [PATCH 36/80] norme --- algo.c | 10 +++++----- algo.h | 11 ++++++++++- render.c | 46 +++++++-------------------------------------- render2.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ utils2.c | 56 ------------------------------------------------------- 5 files changed, 73 insertions(+), 101 deletions(-) create mode 100644 render2.c delete mode 100644 utils2.c diff --git a/algo.c b/algo.c index 95bcf92..51f24f0 100644 --- a/algo.c +++ b/algo.c @@ -6,12 +6,13 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/22 15:48:47 by grobledo ### ########.fr */ +/* Updated: 2024/10/24 14:37:04 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ #include "algo.h" #include "input.h" +#include void *g_mlx = NULL; void *g_win = NULL; @@ -25,18 +26,17 @@ static void load_textures(t_tex *tex) { tex->tex_width = 64; tex->tex_height = 64; - tex->textures[0] = mlx_xpm_file_to_image(g_mlx, "textures/north.xpm", &tex->tex_width, &tex->tex_height); tex->textures[1] = mlx_xpm_file_to_image(g_mlx, "textures/south.xpm", &tex->tex_width, &tex->tex_height); - tex->textures[2]= mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", + tex->textures[2] = mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", &tex->tex_width, &tex->tex_height); - tex->textures[3]= mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", + tex->textures[3] = mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", &tex->tex_width, &tex->tex_height); } -void draw_screen() +void draw_screen(void) { int bpp; int size_line; diff --git a/algo.h b/algo.h index 270937f..32839ac 100644 --- a/algo.h +++ b/algo.h @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/22 15:48:21 by grobledo ### ########.fr */ +/* Updated: 2024/10/24 14:27:27 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,6 +48,11 @@ typedef struct s_tex int tex_height; int tex_width; int tex_dir; + int tex_x; + int tex_y; + int bpp; + int size_line; + int endian; } t_tex; typedef struct s_ray @@ -77,4 +82,8 @@ void draw_screen(void); void move(void); +void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex); + +void draw_wall(t_tex *tex, t_ray *ray, const int line_height, int x, + int y, u_int32_t *img_data); #endif diff --git a/render.c b/render.c index 27bb911..15985c7 100644 --- a/render.c +++ b/render.c @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/10/22 15:50:27 by grobledo ### ########.fr */ +/* Updated: 2024/10/24 14:27:52 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -98,41 +98,17 @@ static double calculate_perpwalldist(int x, t_ray *ray) return (sidedist.y - deltadist.y); } -static void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex) -{ - if (ray->side == 0 && ray->dir.x < 0) - tex->tex_dir = 0; - if (ray->side == 0 && ray->dir.x >= 0) - tex->tex_dir = 1; - if (ray->side == 1 && ray->dir.y < 0) - tex->tex_dir = 2; - if (ray->side == 1 && ray->dir.y >= 0) - tex->tex_dir = 3; - if (ray->side == 0) - ray->wallx = g_map.player.pos.y + perpwalldist \ - * ray->dir.y; - else - ray->wallx = g_map.player.pos.x + perpwalldist \ - * ray->dir.x; - ray->wallx -= floor((ray->wallx)); -} - /// @brief Draw a vertical line according to the ray direction x. /// /// @param x Ray direction x between 0 and 1. -static void draw_vertical_line(int x, u_int32_t *img_data, t_ray *ray, t_tex *tex) +static void draw_vertical_line(int x, u_int32_t *img_data, + t_ray *ray, t_tex *tex) { const double perpwalldist = calculate_perpwalldist(x, ray); const int line_height = (int)(SCREEN_HEIGHT / perpwalldist); int draw_start; int draw_end; int y; - int tex_y; - int tex_x; - int bpp; - int size_line; - int endian; - u_int32_t color; ft_init_texture(perpwalldist, ray, tex); draw_start = -line_height / 2 + SCREEN_HEIGHT / 2; @@ -142,25 +118,16 @@ static void draw_vertical_line(int x, u_int32_t *img_data, t_ray *ray, t_tex *te if (draw_end >= SCREEN_HEIGHT) draw_end = SCREEN_HEIGHT - 1; y = 0; - while (y < SCREEN_HEIGHT) + while (y++ < SCREEN_HEIGHT) { if (y < draw_start) img_data[y * SCREEN_WIDTH + x] = COLOR_CEILING; else if (y < draw_end) { - tex_y = ((y - (-line_height / 2 + SCREEN_HEIGHT / 2)) * tex->tex_height) / line_height; - tex_x = (int)(ray->wallx * (double)tex->tex_width); - if (ray->side == 0 && ray->dir.x > 0) - tex_x = tex->tex_width - tex_x - 1; - if (ray->side == 1 && ray->dir.y < 0) - tex_x = tex->tex_height - tex_x - 1; - u_int32_t *texture_data = (u_int32_t *)mlx_get_data_addr(tex->textures[tex->tex_dir], &bpp, &size_line, &endian); - color = texture_data[tex_x * tex->tex_width + tex_y]; - img_data[y * SCREEN_WIDTH + x] = color; + draw_wall(tex, ray, line_height, x, y, img_data); } else img_data[y * SCREEN_WIDTH + x] = COLOR_FLOOR; - y++; } } @@ -168,6 +135,7 @@ int render(u_int32_t *img_data, t_tex *tex) { int x; t_ray ray; + x = 0; while (x < SCREEN_WIDTH) { @@ -175,4 +143,4 @@ int render(u_int32_t *img_data, t_tex *tex) x++; } return (0); -} \ No newline at end of file +} diff --git a/render2.c b/render2.c new file mode 100644 index 0000000..f6df898 --- /dev/null +++ b/render2.c @@ -0,0 +1,51 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* render2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/24 14:26:22 by grobledo #+# #+# */ +/* Updated: 2024/10/24 14:27:37 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "algo.h" + +void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex) +{ + if (ray->side == 0 && ray->dir.x < 0) + tex->tex_dir = 0; + if (ray->side == 0 && ray->dir.x >= 0) + tex->tex_dir = 1; + if (ray->side == 1 && ray->dir.y < 0) + tex->tex_dir = 2; + if (ray->side == 1 && ray->dir.y >= 0) + tex->tex_dir = 3; + if (ray->side == 0) + ray->wallx = g_map.player.pos.y + perpwalldist \ + * ray->dir.y; + else + ray->wallx = g_map.player.pos.x + perpwalldist \ + * ray->dir.x; + ray->wallx -= floor((ray->wallx)); +} + +void draw_wall(t_tex *tex, t_ray *ray, const int line_height, int x, + int y, u_int32_t *img_data) +{ + u_int32_t color; + u_int32_t *texture_data; + + tex->tex_y = ((y - (-line_height / 2 + SCREEN_HEIGHT / 2)) \ + * tex->tex_height) / line_height; + tex->tex_x = (int)(ray->wallx * (double)tex->tex_width); + if (ray->side == 0 && ray->dir.x > 0) + tex->tex_x = tex->tex_width - tex->tex_x - 1; + if (ray->side == 1 && ray->dir.y < 0) + tex->tex_x = tex->tex_height - tex->tex_x - 1; + texture_data = (u_int32_t *)mlx_get_data_addr(tex->textures[tex->tex_dir], + &tex->bpp, &tex->size_line, &tex->endian); + color = texture_data[tex->tex_x * tex->tex_width + tex->tex_y]; + img_data[y * SCREEN_WIDTH + x] = color; +} \ No newline at end of file diff --git a/utils2.c b/utils2.c deleted file mode 100644 index 9a323a8..0000000 --- a/utils2.c +++ /dev/null @@ -1,56 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* utils2.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/17 01:57:03 by greg #+# #+# */ -/* Updated: 2024/10/17 17:39:18 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ - -// #include "algo.h" - -// void ft_init_texture(const double perpwalldist) -// { -// if (g_ray.side == 0 && g_ray.dir.x < 0) -// g_tex.tex_dir = 0; -// if (g_ray.side == 0 && g_ray.dir.x >= 0) -// g_tex.tex_dir = 1; -// if (g_ray.side == 1 && g_ray.dir.y < 0) -// g_tex.tex_dir = 2; -// if (g_ray.side == 1 && g_ray.dir.y >= 0) -// g_tex.tex_dir = 3; -// if (g_ray.side == 0) -// g_ray.wallx = g_player.pos.y + perpwalldist -// * g_ray.dir.y; -// else -// g_ray.wallx = g_player.pos.x + perpwalldist -// * g_ray.dir.x; -// g_ray.wallx -= floor((g_ray.wallx)); -// } - -// void *tex_ptr = (int *)mlx_get_data_addr(texture[0].img, &bpp, -// g_tex, &endian); - - -// tex_y = ((y - draw_start) * texture_height) / line_height; - -// tex_x = (int)(wall_x * (double)texture_width); -// if ((!side && raydir.x > 0) || (side && raydir.y < 0)) -// { -// tex_x = texture_width - tex_x - 1; -// } - -// u_int32_t color = textures[direction][tex_y * texture_width + tex_x]; - - - // else if (y < draw_end) - // { - // tex_y = ((y - draw_start) * g_tex.tex_height) / line_height; - // tex_x = (int)(g_ray.wallx * g_tex.tex_width); - // u_int32_t *texture_data = (u_int32_t *)g_tex.textures[g_tex.tex_dir]; - // u_int32_t color = texture_data[tex_y * g_tex.tex_width + tex_x]; - // img_data[y * SCREEN_WIDTH + x] = color; - // } \ No newline at end of file From b688144a43ee1579e630834bcd1b8c46532b0398 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Tue, 29 Oct 2024 14:12:51 +0100 Subject: [PATCH 37/80] create and use get_data_addr() --- algo.c | 15 +++------------ utils.c | 2 +- utils.h | 15 +++++++++++---- utils2.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 utils2.c diff --git a/algo.c b/algo.c index 8ce0356..07e582e 100644 --- a/algo.c +++ b/algo.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/17 17:43:07 by mcolonna ### ########.fr */ +/* Updated: 2024/10/29 14:10:10 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,24 +18,15 @@ void *g_win = NULL; t_map g_map; t_player g_player; -// TODO manage image format error better - void draw_screen(void) { - int bpp; - int size_line; - int endian; void *img_ptr; u_int32_t *img_data; img_ptr = mlx_new_image(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT); - img_data = (u_int32_t *) - mlx_get_data_addr(img_ptr, &bpp, &size_line, &endian); - if (bpp != 32 || endian != 0) - { - printf("image format error\n"); + img_data = get_data_addr(img_ptr); + if (!img_data) exit(1); - } render(img_data); mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); mlx_destroy_image(g_mlx, img_ptr); diff --git a/utils.c b/utils.c index 6e8a570..758e64b 100644 --- a/utils.c +++ b/utils.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:38:40 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 15:05:15 by mcolonna ### ########.fr */ +/* Updated: 2024/10/29 14:01:59 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/utils.h b/utils.h index 93a619d..3c4f080 100644 --- a/utils.h +++ b/utils.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 16:56:47 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 14:41:09 by mcolonna ### ########.fr */ +/* Updated: 2024/10/29 14:01:34 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,15 +37,22 @@ typedef __u32 t_color; /// @param green Level of green from 0 to 255. /// @param blue Level of blue from 0 to 255. /// @return The result. -t_color color_from_rgb(int red, int green, int blue); +t_color color_from_rgb(int red, int green, int blue); -void write_err(const char *str, ...); +void write_err(const char *str, ...); /// @brief Call the function in loop. /// If not enough time passed since the last call, returns without doing /// anything. /// /// @param f Function to call in loop. -void timedloop(void (*f)(void)); +void timedloop(void (*f)(void)); + +/// @brief Get an address to the image data, but only if +/// bpp == 32 and endian == 0. +/// +/// @param img_ptr mlx image to use. +/// @return Address to the data, or NULL if error. +u_int32_t *get_data_addr(void *img_ptr); #endif diff --git a/utils2.c b/utils2.c new file mode 100644 index 0000000..dcc1914 --- /dev/null +++ b/utils2.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* utils2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/29 14:02:37 by mcolonna #+# #+# */ +/* Updated: 2024/10/29 14:12:14 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "utils.h" +#include "mlx.h" + +u_int32_t *get_data_addr(void *img_ptr) +{ + int bpp; + int size_line; + int endian; + u_int32_t *r; + + r = (u_int32_t *)mlx_get_data_addr(img_ptr, &bpp, &size_line, &endian); + if (bpp != 32 || endian != 0) + { + write_err("Wrong bpp or wrong endian when using mlx_get_data_addr().\n", + NULL); + return (NULL); + } + return (r); +} From c46536d78ec9362c7a284be8c35dacd8594b21b9 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Tue, 29 Oct 2024 14:19:45 +0100 Subject: [PATCH 38/80] clean TODO --- utils.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils.h b/utils.h index 3c4f080..23b10f8 100644 --- a/utils.h +++ b/utils.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 16:56:47 by mcolonna #+# #+# */ -/* Updated: 2024/10/29 14:01:34 by mcolonna ### ########.fr */ +/* Updated: 2024/10/29 14:13:28 by marvin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,6 @@ typedef struct s_point_int int y; } t_point_int; -// TODO Must the transparency be 0 or 255? /// @brief Represents an TRGB color in 0xTTRRGGBB format. typedef __u32 t_color; From b593057cd55bacdd488efd06dbbf535d269d644b Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Tue, 29 Oct 2024 14:23:48 +0100 Subject: [PATCH 39/80] repush --- algo.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/algo.c b/algo.c index 51f24f0..52271f0 100644 --- a/algo.c +++ b/algo.c @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/24 14:37:04 by grobledo ### ########.fr */ +/* Updated: 2024/10/29 14:23:34 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -77,6 +77,8 @@ static int loop_hook(void *param) return (0); } + + int main(int argc, char *argv[]) { g_mlx = mlx_init(); From 33b3b06c075fb8f887472c75e3301027c163d719 Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Tue, 29 Oct 2024 15:04:36 +0100 Subject: [PATCH 40/80] added cross click --- algo.c | 5 ++--- input.c | 9 +++++++-- input.h | 6 +++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/algo.c b/algo.c index 52271f0..2d2eef2 100644 --- a/algo.c +++ b/algo.c @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/29 14:23:34 by grobledo ### ########.fr */ +/* Updated: 2024/10/29 14:33:28 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -77,8 +77,6 @@ static int loop_hook(void *param) return (0); } - - int main(int argc, char *argv[]) { g_mlx = mlx_init(); @@ -93,6 +91,7 @@ int main(int argc, char *argv[]) g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d"); mlx_hook(g_win, KeyPress, KeyPressMask, keypress, NULL); mlx_hook(g_win, KeyRelease, KeyReleaseMask, keyrelease, NULL); + mlx_hook(g_win, 17, 1L<<17, ft_exit, NULL); mlx_loop_hook(g_mlx, loop_hook, NULL); draw_screen(); mlx_loop(g_mlx); diff --git a/input.c b/input.c index 45168e0..d3c2358 100644 --- a/input.c +++ b/input.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* input.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:36 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 16:05:50 by mcolonna ### ########.fr */ +/* Updated: 2024/10/29 14:32:46 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,3 +50,8 @@ void input_init(void) g_input_actions.right = false; g_input_actions.quit = false; } +int ft_exit(void) +{ + g_input_actions.quit = true; + return(0); +} \ No newline at end of file diff --git a/input.h b/input.h index becd5a1..51f67d8 100644 --- a/input.h +++ b/input.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* input.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:09 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 14:59:41 by mcolonna ### ########.fr */ +/* Updated: 2024/10/29 14:33:04 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,5 +31,5 @@ extern t_input_actions g_input_actions; int keypress(int keycode); int keyrelease(int keycode); void input_init(void); - +int ft_exit(void); #endif From d193b99c568f0bf56b8b4361956546d3ebea5101 Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Tue, 29 Oct 2024 15:31:18 +0100 Subject: [PATCH 41/80] fixed leak --- algo.c | 4 ++-- algo.h | 5 +++-- utils.c | 17 +++++++++++++++-- utils.h | 4 ++-- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/algo.c b/algo.c index 2d2eef2..a157ed8 100644 --- a/algo.c +++ b/algo.c @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/29 14:33:28 by grobledo ### ########.fr */ +/* Updated: 2024/10/29 15:28:25 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,6 @@ void *g_mlx = NULL; void *g_win = NULL; t_map g_map; t_player g_player; -// t_tex g_tex; // TODO manage image format error better @@ -57,6 +56,7 @@ void draw_screen(void) render(img_data, &tex); mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); mlx_destroy_image(g_mlx, img_ptr); + clean_img(&tex); } static void loop(void) diff --git a/algo.h b/algo.h index 32839ac..22561c4 100644 --- a/algo.h +++ b/algo.h @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/24 14:27:27 by grobledo ### ########.fr */ +/* Updated: 2024/10/29 15:29:30 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,7 +67,6 @@ extern void *g_mlx; extern void *g_win; extern t_player g_player; extern t_map g_map; -// extern t_tex g_tex; /// @brief Write an error message on stderr. /// @@ -86,4 +85,6 @@ void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex); void draw_wall(t_tex *tex, t_ray *ray, const int line_height, int x, int y, u_int32_t *img_data); + +void clean_img(t_tex *tex); #endif diff --git a/utils.c b/utils.c index e265cdf..fd4555e 100644 --- a/utils.c +++ b/utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:38:40 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 16:36:14 by mcolonna ### ########.fr */ +/* Updated: 2024/10/29 15:28:56 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -69,3 +69,16 @@ void timedloop(void (*f)(void)) f(); ticks++; } + +void clean_img(t_tex *tex) +{ + int i; + + i = 0; + while (i <= 3) + { + if (tex->textures[i]) + mlx_destroy_image(g_mlx, tex->textures[i]); + i++; + } +} \ No newline at end of file diff --git a/utils.h b/utils.h index 93a619d..bb83116 100644 --- a/utils.h +++ b/utils.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* utils.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 16:56:47 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 14:41:09 by mcolonna ### ########.fr */ +/* Updated: 2024/10/29 15:27:17 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ From aa8d446a87c146cdce5351eda5855670357f256d Mon Sep 17 00:00:00 2001 From: mcolonna Date: Tue, 29 Oct 2024 18:04:38 +0100 Subject: [PATCH 42/80] add TODO --- TODO | 1 + 1 file changed, 1 insertion(+) create mode 100644 TODO diff --git a/TODO b/TODO new file mode 100644 index 0000000..279024f --- /dev/null +++ b/TODO @@ -0,0 +1 @@ +TODO replace all mlx_get_data_addr by util which check the image format From 609bd90b54bf70f9b6e371e501d75864a14a6a6e Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 31 Oct 2024 15:43:53 +0100 Subject: [PATCH 43/80] dev: Makefile: fclean cleans libraries too --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index ad84bcb..d4eefac 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,9 @@ fclean : clean @$(ECHO) @$(ECHO) "\e[30;47;1m $(NAME): fclean... \e[0m" -rm -f $(NAME) + $(MAKE) -C Libft fclean + $(MAKE) -C Minilibx clean + -rm $$(find Minilibx -name "Makefile.gen") re : fclean all From 878de1098b1c14cc3909ae5668a899e8050c46eb Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 31 Oct 2024 16:06:33 +0100 Subject: [PATCH 44/80] reorganize all files (only renamings) --- Makefile | 20 +++++++++++++------- TODO => dev/TODO | 0 algo.h => include/algo.h | 11 ++++++----- input.h => include/input.h | 0 map.h => include/map.h | 4 ++-- map_mapping.h => include/map_mapping.h | 0 map_utils.h => include/map_utils.h | 0 player.h => include/player.h | 0 read_all_text.h => include/read_all_text.h | 0 stream.h => include/stream.h | 0 utils.h => include/utils.h | 0 algo.c => src/algo.c | 0 color.c => src/color.c | 0 input.c => src/input.c | 0 map1.c => src/map1.c | 0 map2.c => src/map2.c | 0 map_mapping.c => src/map_mapping.c | 0 map_utils1.c => src/map_utils1.c | 0 map_utils2.c => src/map_utils2.c | 0 move.c => src/move.c | 0 player.c => src/player.c | 0 read_all_text.c => src/read_all_text.c | 0 render.c => src/render.c | 0 render2.c => src/render2.c | 0 stream.c => src/stream.c | 0 utils.c => src/utils.c | 0 utils2.c => src/utils2.c | 0 27 files changed, 21 insertions(+), 14 deletions(-) rename TODO => dev/TODO (100%) rename algo.h => include/algo.h (91%) rename input.h => include/input.h (100%) rename map.h => include/map.h (96%) rename map_mapping.h => include/map_mapping.h (100%) rename map_utils.h => include/map_utils.h (100%) rename player.h => include/player.h (100%) rename read_all_text.h => include/read_all_text.h (100%) rename stream.h => include/stream.h (100%) rename utils.h => include/utils.h (100%) rename algo.c => src/algo.c (100%) rename color.c => src/color.c (100%) rename input.c => src/input.c (100%) rename map1.c => src/map1.c (100%) rename map2.c => src/map2.c (100%) rename map_mapping.c => src/map_mapping.c (100%) rename map_utils1.c => src/map_utils1.c (100%) rename map_utils2.c => src/map_utils2.c (100%) rename move.c => src/move.c (100%) rename player.c => src/player.c (100%) rename read_all_text.c => src/read_all_text.c (100%) rename render.c => src/render.c (100%) rename render2.c => src/render2.c (100%) rename stream.c => src/stream.c (100%) rename utils.c => src/utils.c (100%) rename utils2.c => src/utils2.c (100%) diff --git a/Makefile b/Makefile index d4eefac..6de71a6 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,11 @@ NAME = cub3d -CPP = gcc $(FLAGS) +CPP = gcc LIBRARIES_DIR = Libft Minilibx LIBRARIES_A = Libft/libft.a Minilibx/libmlx.a -CPP_1 = $(CPP) -Wall -Wextra -Werror -I Libft -I Minilibx $(FLAGS_1) -g -CPP_2 = $(CPP) $(FLAGS_2) SHARED = -lX11 -lXext -lm -C_FILES = $(wildcard **.c) +CPP_1 = $(CPP) -Wall -Wextra -Werror -I Libft -I Minilibx -I include $(FLAGS) $(FLAGS_1) +CPP_2 = $(CPP) $(FLAGS) $(FLAGS_2) +C_FILES = $(wildcard src/*.c) O_FILES = $(patsubst %.c,%.o,$(C_FILES)) ECHO = echoo(){ \ @@ -18,6 +18,12 @@ ECHO = echoo(){ \ all : $(NAME) +debug : + $(MAKE) all FLAGS_1="$(FLAGS_1) -g" + +debugre : + $(MAKE) re FLAGS_1="$(FLAGS_1) -g" + $(LIBRARIES_DIR): @$(ECHO) @$(ECHO) "\e[30;47;1m $(NAME): making library $@... \e[0m" @@ -32,8 +38,8 @@ fclean : clean @$(ECHO) @$(ECHO) "\e[30;47;1m $(NAME): fclean... \e[0m" -rm -f $(NAME) - $(MAKE) -C Libft fclean - $(MAKE) -C Minilibx clean + -$(MAKE) -C Libft fclean + -$(MAKE) -C Minilibx clean -rm $$(find Minilibx -name "Makefile.gen") re : fclean all @@ -59,7 +65,7 @@ check_headers : > __tmp_check_header.c echo "#include \"$$HEADER\""; \ >> __tmp_check_header.c echo "#include \"$$HEADER\""; \ >> __tmp_check_header.c echo "int main(void) {}"; \ - $(CPP) -o __tmp_check_header.out __tmp_check_header.c; \ + $(CPP_1) -o __tmp_check_header.out __tmp_check_header.c; \ if [ $$? -ne 0 ]; \ then \ ERROR=1; \ diff --git a/TODO b/dev/TODO similarity index 100% rename from TODO rename to dev/TODO diff --git a/algo.h b/include/algo.h similarity index 91% rename from algo.h rename to include/algo.h index 32839ac..8cc0bf9 100644 --- a/algo.h +++ b/include/algo.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* algo.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/24 14:27:27 by grobledo ### ########.fr */ +/* Updated: 2024/10/31 16:03:42 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,9 +17,10 @@ # include # include # include -# include "Minilibx/mlx.h" -# include "Minilibx/mlx_int.h" -# include "Libft/libft.h" +# include +# include +# include "mlx.h" +# include "libft.h" # include "stream.h" # include "read_all_text.h" diff --git a/input.h b/include/input.h similarity index 100% rename from input.h rename to include/input.h diff --git a/map.h b/include/map.h similarity index 96% rename from map.h rename to include/map.h index 86c6a39..73802dd 100644 --- a/map.h +++ b/include/map.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* map.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */ -/* Updated: 2024/10/16 17:59:12 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 15:57:58 by mc ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/map_mapping.h b/include/map_mapping.h similarity index 100% rename from map_mapping.h rename to include/map_mapping.h diff --git a/map_utils.h b/include/map_utils.h similarity index 100% rename from map_utils.h rename to include/map_utils.h diff --git a/player.h b/include/player.h similarity index 100% rename from player.h rename to include/player.h diff --git a/read_all_text.h b/include/read_all_text.h similarity index 100% rename from read_all_text.h rename to include/read_all_text.h diff --git a/stream.h b/include/stream.h similarity index 100% rename from stream.h rename to include/stream.h diff --git a/utils.h b/include/utils.h similarity index 100% rename from utils.h rename to include/utils.h diff --git a/algo.c b/src/algo.c similarity index 100% rename from algo.c rename to src/algo.c diff --git a/color.c b/src/color.c similarity index 100% rename from color.c rename to src/color.c diff --git a/input.c b/src/input.c similarity index 100% rename from input.c rename to src/input.c diff --git a/map1.c b/src/map1.c similarity index 100% rename from map1.c rename to src/map1.c diff --git a/map2.c b/src/map2.c similarity index 100% rename from map2.c rename to src/map2.c diff --git a/map_mapping.c b/src/map_mapping.c similarity index 100% rename from map_mapping.c rename to src/map_mapping.c diff --git a/map_utils1.c b/src/map_utils1.c similarity index 100% rename from map_utils1.c rename to src/map_utils1.c diff --git a/map_utils2.c b/src/map_utils2.c similarity index 100% rename from map_utils2.c rename to src/map_utils2.c diff --git a/move.c b/src/move.c similarity index 100% rename from move.c rename to src/move.c diff --git a/player.c b/src/player.c similarity index 100% rename from player.c rename to src/player.c diff --git a/read_all_text.c b/src/read_all_text.c similarity index 100% rename from read_all_text.c rename to src/read_all_text.c diff --git a/render.c b/src/render.c similarity index 100% rename from render.c rename to src/render.c diff --git a/render2.c b/src/render2.c similarity index 100% rename from render2.c rename to src/render2.c diff --git a/stream.c b/src/stream.c similarity index 100% rename from stream.c rename to src/stream.c diff --git a/utils.c b/src/utils.c similarity index 100% rename from utils.c rename to src/utils.c diff --git a/utils2.c b/src/utils2.c similarity index 100% rename from utils2.c rename to src/utils2.c From 47a6b6df3584740903195ba407c5fa792c15572d Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 31 Oct 2024 18:04:34 +0100 Subject: [PATCH 45/80] reorganize file content --- Makefile | 2 +- include/algo.h | 90 ------------------------------- include/const.h | 31 +++++++++++ include/global.h | 25 +++++++++ include/include.h | 33 ++++++++++++ include/input.h | 6 +-- src/color.c => include/main.h | 18 +++---- include/map.h | 18 ++++++- include/map_mapping.h | 31 ----------- include/move.h | 20 +++++++ include/player.h | 6 ++- include/read_all_text.h | 29 ---------- include/render.h | 23 ++++++++ include/stream.h | 6 +-- include/temp.h | 47 ++++++++++++++++ include/utils.h | 24 +++++++-- src/global.c | 18 +++++++ src/input.c | 6 +-- src/{algo.c => main.c} | 24 ++++----- src/map1.c | 23 ++++---- src/map2.c | 12 +---- src/map_mapping.c | 25 --------- {include => src}/map_utils.h | 9 ++-- src/map_utils1.c | 7 +-- src/map_utils2.c | 7 +-- src/move.c | 11 ++-- src/player.c | 9 ++-- src/render.c | 11 ++-- src/{render2.c => render_utils.c} | 13 +++-- src/render_utils.h | 23 ++++++++ src/stream.c | 5 +- src/utils.c | 7 ++- src/utils2.c | 10 ++-- src/{read_all_text.c => utils3.c} | 17 +++--- 34 files changed, 358 insertions(+), 288 deletions(-) delete mode 100644 include/algo.h create mode 100644 include/const.h create mode 100644 include/global.h create mode 100644 include/include.h rename src/color.c => include/main.h (63%) delete mode 100644 include/map_mapping.h create mode 100644 include/move.h delete mode 100644 include/read_all_text.h create mode 100644 include/render.h create mode 100644 include/temp.h create mode 100644 src/global.c rename src/{algo.c => main.c} (86%) delete mode 100644 src/map_mapping.c rename {include => src}/map_utils.h (94%) rename src/{render2.c => render_utils.c} (88%) create mode 100644 src/render_utils.h rename src/{read_all_text.c => utils3.c} (85%) diff --git a/Makefile b/Makefile index 6de71a6..8689b64 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ check_headers : echo "check header $$HEADER..."; \ > __tmp_check_header.c echo "#include \"$$HEADER\""; \ >> __tmp_check_header.c echo "#include \"$$HEADER\""; \ - >> __tmp_check_header.c echo "int main(void) {}"; \ + >> __tmp_check_header.c echo "int main() {}"; \ $(CPP_1) -o __tmp_check_header.out __tmp_check_header.c; \ if [ $$? -ne 0 ]; \ then \ diff --git a/include/algo.h b/include/algo.h deleted file mode 100644 index 8cc0bf9..0000000 --- a/include/algo.h +++ /dev/null @@ -1,90 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* algo.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/31 16:03:42 by mc ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef ALGO_H -# define ALGO_H - -# include -# include -# include -# include -# include -# include -# include "mlx.h" -# include "libft.h" - -# include "stream.h" -# include "read_all_text.h" -# include "map.h" -# include "map_mapping.h" - -# define MAP_WIDTH 24 // cases (TODO test) -# define MAP_HEIGHT 24 // cases (TODO test) -# define TEX_WIDTH 64 -# define TEX_HEIGHT 64 -# define MOVE_SPEED 0.05 // cases -# define PI 3.1415926535 -# define ROT_SPEED_DIVIDE_PI 64 // pi/n rad -# define COLOR_WALL 0xFF0000 // 0xRRGGBB -# define COLOR_CEILING 0x29f8ff // 0xRRGGBB -# define COLOR_FLOOR 0xFF985C // 0xRRGGBB -# define SCREEN_WIDTH 640 // px -# define SCREEN_HEIGHT 480 // px -# define FOV 0.66 // ? TODO unit -# define HITBOX 0.25 // cases. should be more than MOVE_SPEED - -typedef struct s_tex -{ - void *textures[4]; - void *current_tex; - int tex_height; - int tex_width; - int tex_dir; - int tex_x; - int tex_y; - int bpp; - int size_line; - int endian; -} t_tex; - -typedef struct s_ray -{ - // pos player on map (cases) - t_point_double dir; - bool side; - double wallx; -} t_ray; - -extern void *g_mlx; -extern void *g_win; -extern t_player g_player; -extern t_map g_map; -// extern t_tex g_tex; - -/// @brief Write an error message on stderr. -/// -/// @param str... All the strings to write. The last parameter MUST BE NULL. -void write_err(const char *str, ...); - -void vector_from_rotation(t_point_double *vec, double angle, double norm); - -int render(u_int32_t *img_data, t_tex *tex); - -void draw_screen(void); - -void move(void); - -void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex); - -void draw_wall(t_tex *tex, t_ray *ray, const int line_height, int x, - int y, u_int32_t *img_data); -#endif diff --git a/include/const.h b/include/const.h new file mode 100644 index 0000000..173da3d --- /dev/null +++ b/include/const.h @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* const.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/31 17:00:59 by mc #+# #+# */ +/* Updated: 2024/10/31 17:06:00 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef CONST_H +# define CONST_H + +# include "include.h" + +# define MAP_WIDTH 24 // cases (TODO test) +# define MAP_HEIGHT 24 // cases (TODO test) +# define MOVE_SPEED 0.05 // cases +# define PI 3.1415926535 +# define ROT_SPEED_DIVIDE_PI 64 // pi/n rad +# define COLOR_WALL 0xFF0000 // 0xRRGGBB +# define COLOR_CEILING 0x29f8ff // 0xRRGGBB +# define COLOR_FLOOR 0xFF985C // 0xRRGGBB +# define SCREEN_WIDTH 640 // px +# define SCREEN_HEIGHT 480 // px +# define FOV 0.66 // ? TODO unit +# define HITBOX 0.25 // cases. should be more than MOVE_SPEED + +#endif diff --git a/include/global.h b/include/global.h new file mode 100644 index 0000000..5be9d0b --- /dev/null +++ b/include/global.h @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* global.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/31 17:06:31 by mc #+# #+# */ +/* Updated: 2024/10/31 17:29:00 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef GLOBAL_H +# define GLOBAL_H + +# include "include.h" + +# include "map.h" + +extern void *g_mlx; +extern void *g_win; +extern t_player g_player; +extern t_map g_map; + +#endif diff --git a/include/include.h b/include/include.h new file mode 100644 index 0000000..58ae764 --- /dev/null +++ b/include/include.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* include.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/31 16:22:09 by mc #+# #+# */ +/* Updated: 2024/10/31 18:03:26 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef INCLUDE_H +# define INCLUDE_H + +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include + +# include "libft.h" +# include "mlx.h" + +#endif diff --git a/include/input.h b/include/input.h index becd5a1..6fda136 100644 --- a/include/input.h +++ b/include/input.h @@ -3,17 +3,17 @@ /* ::: :::::::: */ /* input.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:09 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 14:59:41 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 16:24:16 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef INPUT_H # define INPUT_H -# include +# include "include.h" /// @brief Modified by the input of the user. A value becomes true /// when the user presses the corresponding key. diff --git a/src/color.c b/include/main.h similarity index 63% rename from src/color.c rename to include/main.h index 13b2deb..0d413ad 100644 --- a/src/color.c +++ b/include/main.h @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* color.c :+: :+: :+: */ +/* main.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/01 17:04:56 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 16:26:52 by mcolonna ### ########.fr */ +/* Created: 2024/10/31 17:19:59 by mc #+# #+# */ +/* Updated: 2024/10/31 17:55:11 by mc ### ########.fr */ /* */ /* ************************************************************************** */ -#include "map.h" +#ifndef MAIN_H +# define MAIN_H -t_color color_from_rgb(int red, int green, int blue) -{ - return (red << 16 | green << 8 | blue); -} +# include "include.h" + +#endif diff --git a/include/map.h b/include/map.h index 73802dd..228be5c 100644 --- a/include/map.h +++ b/include/map.h @@ -6,14 +6,15 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 15:57:58 by mc ### ########.fr */ +/* Updated: 2024/10/31 17:55:39 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef MAP_H # define MAP_H -# include +# include "include.h" + # include "utils.h" /// @brief The type of a case. @@ -61,6 +62,19 @@ typedef struct s_map_case t_object object; } t_map_case; +/// @brief Each element of g_map_mapping. A case and its associated char. +typedef struct s_map_mapping_element +{ + /// @brief char representing the case. + char name; + /// @brief associated case. + t_map_case value; +} t_map_mapping_element; + +/// @brief List of each char and its according case. +/// Ended by an element with the name '\0'. +extern const t_map_mapping_element g_map_mapping[]; + typedef struct s_player { // pos player on map (cases) diff --git a/include/map_mapping.h b/include/map_mapping.h deleted file mode 100644 index 5a3b2c9..0000000 --- a/include/map_mapping.h +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* map_mapping.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/04 12:00:07 by mcolonna #+# #+# */ -/* Updated: 2024/10/04 15:24:14 by mcolonna ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef MAP_MAPPING_H -# define MAP_MAPPING_H - -# include "map.h" - -/// @brief Each element of g_map_mapping. A case and its associated char. -typedef struct s_map_mapping_element -{ - /// @brief char representing the case. - char name; - /// @brief associated case. - t_map_case value; -} t_map_mapping_element; - -/// @brief List of each char and its according case. -/// Ended by an element with the name '\0'. -extern const t_map_mapping_element g_map_mapping[]; - -#endif diff --git a/include/move.h b/include/move.h new file mode 100644 index 0000000..03804d0 --- /dev/null +++ b/include/move.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* move.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/31 16:59:27 by mc #+# #+# */ +/* Updated: 2024/10/31 16:59:48 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MOVE_H +# define MOVE_H + +# include "include.h" + +void move(void); + +#endif diff --git a/include/player.h b/include/player.h index e9dfb28..09a7177 100644 --- a/include/player.h +++ b/include/player.h @@ -3,16 +3,18 @@ /* ::: :::::::: */ /* player.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 17:31:35 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 17:43:52 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:30:01 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef PLAYER_H # define PLAYER_H +# include "include.h" + # include "utils.h" void init_player_n(void **data, t_point_int pos); diff --git a/include/read_all_text.h b/include/read_all_text.h deleted file mode 100644 index f86eec9..0000000 --- a/include/read_all_text.h +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* read_all_text.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/02 15:39:02 by mcolonna #+# #+# */ -/* Updated: 2024/10/02 17:04:33 by mcolonna ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef READ_ALL_TEXT_H -# define READ_ALL_TEXT_H - -/// @brief Size of buffer used in read_all_text(). -# define BUFFER_SIZE 1000 - -/// @brief Read all the text of the given file. -/// -/// If the last line isn't ended by a '\\n', add one. -/// -/// If error, returns NULL and set errno accordingly. -/// -/// @param fd File descriptor of the file. -/// @return Alloc'd string of the file content. NULL if error. -char *read_all_text(int fd); - -#endif diff --git a/include/render.h b/include/render.h new file mode 100644 index 0000000..7f7eec2 --- /dev/null +++ b/include/render.h @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* render.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/31 17:13:20 by mc #+# #+# */ +/* Updated: 2024/10/31 17:27:33 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef RENDER_H +# define RENDER_H + +# include "include.h" + +# include "utils.h" +# include "temp.h" + +int render(u_int32_t *img_data, t_tex *tex); + +#endif diff --git a/include/stream.h b/include/stream.h index 7b071ee..8374b16 100644 --- a/include/stream.h +++ b/include/stream.h @@ -3,17 +3,17 @@ /* ::: :::::::: */ /* stream.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/02 12:33:25 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 15:57:59 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 16:25:10 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef STREAM_H # define STREAM_H -# include +# include "include.h" /// @brief Represents a string and an associated cursor. typedef struct s_stream diff --git a/include/temp.h b/include/temp.h new file mode 100644 index 0000000..d447a27 --- /dev/null +++ b/include/temp.h @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* temp.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/31 17:04:08 by mc #+# #+# */ +/* Updated: 2024/10/31 17:28:09 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +// DEBUG remove temp.h + +#ifndef TEMP_H +# define TEMP_H + +# include "include.h" + +# include "utils.h" + +# define TEX_WIDTH 64 +# define TEX_HEIGHT 64 + +typedef struct s_tex +{ + void *textures[4]; + void *current_tex; + int tex_height; + int tex_width; + int tex_dir; + int tex_x; + int tex_y; + int bpp; + int size_line; + int endian; +} t_tex; + +typedef struct s_ray +{ + // pos player on map (cases) + t_point_double dir; + bool side; + double wallx; +} t_ray; + +#endif diff --git a/include/utils.h b/include/utils.h index e0e9c0c..76da5af 100644 --- a/include/utils.h +++ b/include/utils.h @@ -6,16 +6,14 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 16:56:47 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 15:31:21 by mc ### ########.fr */ +/* Updated: 2024/10/31 17:15:31 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef UTILS_H # define UTILS_H -# include -# include -# include +# include "include.h" typedef uint32_t u_int32_t; @@ -43,6 +41,9 @@ typedef __u32 t_color; /// @return The result. t_color color_from_rgb(int red, int green, int blue); +/// @brief Write an error message on stderr. +/// +/// @param str... All the strings to write. The last parameter MUST BE NULL. void write_err(const char *str, ...); /// @brief Call the function in loop. @@ -59,4 +60,19 @@ void timedloop(void (*f)(void)); /// @return Address to the data, or NULL if error. u_int32_t *get_data_addr(void *img_ptr); +void vector_from_rotation(t_point_double *vec, double angle, double norm); + +/// @brief Size of buffer used in read_all_text(). +# define READ_ALL_TEXT_BUFFER_SIZE 1000 + +/// @brief Read all the text of the given file. +/// +/// If the last line isn't ended by a '\\n', add one. +/// +/// If error, returns NULL and set errno accordingly. +/// +/// @param fd File descriptor of the file. +/// @return Alloc'd string of the file content. NULL if error. +char *read_all_text(int fd); + #endif diff --git a/src/global.c b/src/global.c new file mode 100644 index 0000000..b0e9111 --- /dev/null +++ b/src/global.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* global.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ +/* Updated: 2024/10/31 17:20:56 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "global.h" + +void *g_mlx = NULL; +void *g_win = NULL; +t_map g_map; +t_player g_player; diff --git a/src/input.c b/src/input.c index 45168e0..9f0ee6c 100644 --- a/src/input.c +++ b/src/input.c @@ -3,16 +3,14 @@ /* ::: :::::::: */ /* input.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:36 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 16:05:50 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:21:00 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "input.h" -#include -#include "algo.h" t_input_actions g_input_actions; diff --git a/src/algo.c b/src/main.c similarity index 86% rename from src/algo.c rename to src/main.c index 56e2a2a..69352d9 100644 --- a/src/algo.c +++ b/src/main.c @@ -1,24 +1,22 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* algo.c :+: :+: :+: */ +/* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/31 15:26:48 by mc ### ########.fr */ +/* Created: 2024/10/31 16:57:40 by mc #+# #+# */ +/* Updated: 2024/10/31 17:55:18 by mc ### ########.fr */ /* */ /* ************************************************************************** */ -#include "algo.h" -#include "input.h" -#include +#include "main.h" -void *g_mlx = NULL; -void *g_win = NULL; -t_map g_map; -t_player g_player; -// t_tex g_tex; +# include "render.h" +# include "move.h" +# include "input.h" +# include "const.h" +# include "global.h" static void load_textures(t_tex *tex) { @@ -34,7 +32,7 @@ static void load_textures(t_tex *tex) &tex->tex_width, &tex->tex_height); } -void draw_screen(void) +static void draw_screen(void) { void *img_ptr; u_int32_t *img_data; @@ -68,8 +66,6 @@ static int loop_hook(void *param) return (0); } - - int main(int argc, char *argv[]) { g_mlx = mlx_init(); diff --git a/src/map1.c b/src/map1.c index aaba9c0..931ad2a 100644 --- a/src/map1.c +++ b/src/map1.c @@ -3,23 +3,28 @@ /* ::: :::::::: */ /* map1.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 17:12:58 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 17:22:53 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:56:25 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "map.h" #include "map_utils.h" + #include "stream.h" -#include "read_all_text.h" -#include "libft.h" -#include -#include -#include -#include -#include +#include "player.h" + +const t_map_mapping_element g_map_mapping[] = { +{' ', {false, EMPTY, {NULL, NULL, NULL, NULL}}}, +{'0', {true, EMPTY, {NULL, NULL, NULL, NULL}}}, +{'1', {true, WALL, {NULL, NULL, NULL, NULL}}}, +{'N', {true, EMPTY, {init_player_n, NULL, NULL, NULL}}}, +{'S', {true, EMPTY, {init_player_s, NULL, NULL, NULL}}}, +{'E', {true, EMPTY, {init_player_e, NULL, NULL, NULL}}}, +{'W', {true, EMPTY, {init_player_w, NULL, NULL, NULL}}}, +{'\0', {true, EMPTY, {NULL, NULL, NULL, NULL}}}}; static bool map_from_file2(t_map *dest, t_stream *stream, int fd) { diff --git a/src/map2.c b/src/map2.c index f4b99f5..c40818a 100644 --- a/src/map2.c +++ b/src/map2.c @@ -3,23 +3,15 @@ /* ::: :::::::: */ /* map2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 17:12:58 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 16:44:40 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:51:49 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "map.h" #include "map_utils.h" -#include "stream.h" -#include "read_all_text.h" -#include "libft.h" -#include -#include -#include -#include -#include const t_map_case *map_get_case(const t_map *map, int x, int y) { diff --git a/src/map_mapping.c b/src/map_mapping.c deleted file mode 100644 index 129ce34..0000000 --- a/src/map_mapping.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* map_mapping.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/04 12:05:21 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 17:19:26 by mcolonna ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "map_mapping.h" -#include "player.h" -#include - -const t_map_mapping_element g_map_mapping[] = { -{' ', {false, EMPTY, {NULL, NULL, NULL, NULL}}}, -{'0', {true, EMPTY, {NULL, NULL, NULL, NULL}}}, -{'1', {true, WALL, {NULL, NULL, NULL, NULL}}}, -{'N', {true, EMPTY, {init_player_n, NULL, NULL, NULL}}}, -{'S', {true, EMPTY, {init_player_s, NULL, NULL, NULL}}}, -{'E', {true, EMPTY, {init_player_e, NULL, NULL, NULL}}}, -{'W', {true, EMPTY, {init_player_w, NULL, NULL, NULL}}}, -{'\0', {true, EMPTY, {NULL, NULL, NULL, NULL}}}}; diff --git a/include/map_utils.h b/src/map_utils.h similarity index 94% rename from include/map_utils.h rename to src/map_utils.h index 6f35bba..c0b5184 100644 --- a/include/map_utils.h +++ b/src/map_utils.h @@ -3,20 +3,19 @@ /* ::: :::::::: */ /* map_utils.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 15:05:13 by mc #+# #+# */ -/* Updated: 2024/10/17 17:58:23 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:56:54 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef MAP_UTILS_H # define MAP_UTILS_H -# include "stream.h" # include "map.h" -# include -# include + +# include "stream.h" /// @brief Read a parameter of the map which has a color as an argument. /// Color format: [0-255],[0-255],[0-255] diff --git a/src/map_utils1.c b/src/map_utils1.c index 9edd47a..da844e8 100644 --- a/src/map_utils1.c +++ b/src/map_utils1.c @@ -3,17 +3,14 @@ /* ::: :::::::: */ /* map_utils1.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 15:02:09 by mc #+# #+# */ -/* Updated: 2024/10/17 17:59:05 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:21:36 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "map_utils.h" -#include "map.h" -#include "map_mapping.h" -#include bool read_color_parameter(const char *name, t_color *dest, t_stream *stream, bool *redefined) diff --git a/src/map_utils2.c b/src/map_utils2.c index b15565a..c159465 100644 --- a/src/map_utils2.c +++ b/src/map_utils2.c @@ -3,17 +3,14 @@ /* ::: :::::::: */ /* map_utils2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/04 15:12:08 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 16:27:41 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:21:44 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "map_utils.h" -#include "map_mapping.h" -#include "map.h" -#include /// @brief Read the map description to get the dimensions. /// The map must be at least 1x1. diff --git a/src/move.c b/src/move.c index 8511c2f..421af95 100644 --- a/src/move.c +++ b/src/move.c @@ -3,14 +3,19 @@ /* ::: :::::::: */ /* move.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:47:34 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 15:06:43 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:58:27 by mc ### ########.fr */ /* */ /* ************************************************************************** */ -#include "algo.h" +#include "move.h" + +#include "utils.h" +#include "map.h" +#include "global.h" +#include "const.h" #include "input.h" static void push_from_wall(t_point_int c) diff --git a/src/player.c b/src/player.c index 98b46af..c1fc4cb 100644 --- a/src/player.c +++ b/src/player.c @@ -3,16 +3,17 @@ /* ::: :::::::: */ /* player.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 17:33:11 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 17:38:27 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:59:13 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "player.h" -#include "utils.h" -#include "algo.h" + +#include "global.h" +#include "const.h" static void init_player(t_point_int pos, double rot) { diff --git a/src/render.c b/src/render.c index 15985c7..288ee6c 100644 --- a/src/render.c +++ b/src/render.c @@ -3,15 +3,18 @@ /* ::: :::::::: */ /* render.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/10/24 14:27:52 by grobledo ### ########.fr */ +/* Updated: 2024/10/31 18:02:59 by mc ### ########.fr */ /* */ /* ************************************************************************** */ -#include "algo.h" -#include +#include "render.h" +#include "render_utils.h" + +#include "const.h" +#include "global.h" static void calculate_perpwalldist3(int x, t_point_double *deltadist, diff --git a/src/render2.c b/src/render_utils.c similarity index 88% rename from src/render2.c rename to src/render_utils.c index f6df898..a12f90a 100644 --- a/src/render2.c +++ b/src/render_utils.c @@ -1,16 +1,19 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* render2.c :+: :+: :+: */ +/* render_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/24 14:26:22 by grobledo #+# #+# */ -/* Updated: 2024/10/24 14:27:37 by grobledo ### ########.fr */ +/* Updated: 2024/10/31 18:02:20 by mc ### ########.fr */ /* */ /* ************************************************************************** */ -#include "algo.h" +#include "render_utils.h" + +#include "const.h" +#include "global.h" void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex) { @@ -48,4 +51,4 @@ void draw_wall(t_tex *tex, t_ray *ray, const int line_height, int x, &tex->bpp, &tex->size_line, &tex->endian); color = texture_data[tex->tex_x * tex->tex_width + tex->tex_y]; img_data[y * SCREEN_WIDTH + x] = color; -} \ No newline at end of file +} diff --git a/src/render_utils.h b/src/render_utils.h new file mode 100644 index 0000000..01a826e --- /dev/null +++ b/src/render_utils.h @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* render_utils.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/24 14:26:22 by grobledo #+# #+# */ +/* Updated: 2024/10/31 18:01:59 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef RENDER_UTILS_H +# define RENDER_UTILS_H + +# include "render.h" + +void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex); + +void draw_wall(t_tex *tex, t_ray *ray, const int line_height, int x, + int y, u_int32_t *img_data); + +#endif diff --git a/src/stream.c b/src/stream.c index 9617970..c58e24c 100644 --- a/src/stream.c +++ b/src/stream.c @@ -3,15 +3,14 @@ /* ::: :::::::: */ /* stream.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/02 14:08:10 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 16:02:33 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:25:23 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "stream.h" -#include void read_expected_string(const char *str, t_stream *stream, bool *err) { diff --git a/src/utils.c b/src/utils.c index e265cdf..21f928c 100644 --- a/src/utils.c +++ b/src/utils.c @@ -3,15 +3,14 @@ /* ::: :::::::: */ /* utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:38:40 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 16:36:14 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:25:30 by mc ### ########.fr */ /* */ /* ************************************************************************** */ -#include "algo.h" -#include +#include "utils.h" void vector_from_rotation(t_point_double *vec, double angle, double norm) { diff --git a/src/utils2.c b/src/utils2.c index dcc1914..60a922b 100644 --- a/src/utils2.c +++ b/src/utils2.c @@ -3,15 +3,14 @@ /* ::: :::::::: */ /* utils2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/29 14:02:37 by mcolonna #+# #+# */ -/* Updated: 2024/10/29 14:12:14 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:25:34 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "utils.h" -#include "mlx.h" u_int32_t *get_data_addr(void *img_ptr) { @@ -29,3 +28,8 @@ u_int32_t *get_data_addr(void *img_ptr) } return (r); } + +t_color color_from_rgb(int red, int green, int blue) +{ + return (red << 16 | green << 8 | blue); +} diff --git a/src/read_all_text.c b/src/utils3.c similarity index 85% rename from src/read_all_text.c rename to src/utils3.c index 42abe10..d6dbe30 100644 --- a/src/read_all_text.c +++ b/src/utils3.c @@ -1,21 +1,16 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* read_all_text.c :+: :+: :+: */ +/* utils3.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/02 16:18:35 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 16:28:22 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:25:53 by mc ### ########.fr */ /* */ /* ************************************************************************** */ -#include "read_all_text.h" -#include "map.h" -#include "libft.h" -#include -#include -#include +#include "utils.h" /// @brief Concatenate *dest and src and put the result in *dest. /// @@ -73,7 +68,7 @@ static char *add_endline_if_necessary(char *str) char *read_all_text(int fd) { - char buf[BUFFER_SIZE]; + char buf[READ_ALL_TEXT_BUFFER_SIZE]; int n; char *r; @@ -84,7 +79,7 @@ char *read_all_text(int fd) n = 1; while (n) { - n = read(fd, buf, BUFFER_SIZE); + n = read(fd, buf, READ_ALL_TEXT_BUFFER_SIZE); if (n < 0 || (n && !strconcat(&r, buf, n))) { free(r); From 0396180cd8ca5b7361fe5de06baf2d5802109e57 Mon Sep 17 00:00:00 2001 From: ReverseSky Date: Wed, 6 Nov 2024 15:21:24 +0100 Subject: [PATCH 46/80] add mouse movement --- algo.c | 22 ++++++++++++++++++++-- algo.h | 8 ++++++-- map.h | 6 ++++-- move.c | 6 +++--- move2.c | 24 ++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 move2.c diff --git a/algo.c b/algo.c index a157ed8..d2f51a7 100644 --- a/algo.c +++ b/algo.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* algo.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ +/* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/29 15:28:25 by grobledo ### ########.fr */ +/* Updated: 2024/11/06 15:16:02 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -77,6 +77,23 @@ static int loop_hook(void *param) return (0); } +// static int rotate( int dx) +// { +// g_map.player.rot += PI / ROT_SPEED_DIVIDE_PI * dx; +// return (0); +// } + +int mouse_move(int x, int y) +{ + (void)y; + int dx = x - g_player.old_mouse_x; // Calcul de la différence de mouvement + if (dx != 0) { + rotate(dx); + g_player.old_mouse_x = x; // Mise à jour de la position précédente + } + return (0); +} + int main(int argc, char *argv[]) { g_mlx = mlx_init(); @@ -92,6 +109,7 @@ int main(int argc, char *argv[]) mlx_hook(g_win, KeyPress, KeyPressMask, keypress, NULL); mlx_hook(g_win, KeyRelease, KeyReleaseMask, keyrelease, NULL); mlx_hook(g_win, 17, 1L<<17, ft_exit, NULL); + mlx_hook(g_win, 6, 1L<< 6, mouse_move, NULL); mlx_loop_hook(g_mlx, loop_hook, NULL); draw_screen(); mlx_loop(g_mlx); diff --git a/algo.h b/algo.h index 22561c4..02f81db 100644 --- a/algo.h +++ b/algo.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* algo.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ +/* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/29 15:29:30 by grobledo ### ########.fr */ +/* Updated: 2024/11/06 15:18:45 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -87,4 +87,8 @@ void draw_wall(t_tex *tex, t_ray *ray, const int line_height, int x, int y, u_int32_t *img_data); void clean_img(t_tex *tex); + +int rotate(int factor); + +int mouse_move(int x, int y); #endif diff --git a/map.h b/map.h index 86c6a39..55ce662 100644 --- a/map.h +++ b/map.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* map.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */ -/* Updated: 2024/10/16 17:59:12 by mcolonna ### ########.fr */ +/* Updated: 2024/11/06 14:48:12 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,6 +67,8 @@ typedef struct s_player t_point_double pos; // player rotation (rad) double rot; + + int old_mouse_x; } t_player; /// @brief Represents a map. diff --git a/move.c b/move.c index 8511c2f..3a61b59 100644 --- a/move.c +++ b/move.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* move.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:47:34 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 15:06:43 by mcolonna ### ########.fr */ +/* Updated: 2024/11/06 15:17:15 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -59,7 +59,7 @@ static int move_forward(int factor) return (0); } -static int rotate(int factor) +int rotate(int factor) { g_map.player.rot += PI / ROT_SPEED_DIVIDE_PI * factor; return (0); diff --git a/move2.c b/move2.c new file mode 100644 index 0000000..473d1b1 --- /dev/null +++ b/move2.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* move2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: greg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/06 15:18:21 by greg #+# #+# */ +/* Updated: 2024/11/06 15:18:34 by greg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "algo.h" + +int mouse_move(int x, int y) +{ + (void)y; + int dx = x - g_player.old_mouse_x; // Calcul de la différence de mouvement + if (dx != 0) { + rotate(dx); + g_player.old_mouse_x = x; // Mise à jour de la position précédente + } + return (0); +} \ No newline at end of file From 26621c72c6ae3f3b4f4d741a78a02fb0e6bb8d5a Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 7 Nov 2024 01:03:05 +0100 Subject: [PATCH 47/80] docs, clean, several things... * - add docs - remove unused things - redo modifications i accidentally erased from spacetime --- include/const.h | 27 +++++++++++----------- include/global.h | 8 +++++-- include/input.h | 22 +++++++++++++----- include/map.h | 36 ++++++++++++++++++++---------- include/move.h | 3 ++- include/player.h | 9 +++++++- include/render.h | 12 +++++++--- include/utils.h | 10 ++++++++- src/global.c | 3 +-- src/input.c | 12 ++++------ src/main.c | 24 ++++---------------- src/map1.c | 19 +++++++++++----- src/map_utils.h | 4 +++- src/map_utils1.c | 32 ++++++++++++-------------- src/map_utils2.c | 18 ++++++++++++++- src/render.c | 18 +++++++++------ src/render_utils.c | 16 +++++++------ src/render_utils.h | 4 ++-- src/utils.c | 2 +- testmaps/good_big.cub | 8 +++---- testmaps/good_directions.cub | 10 ++++----- testmaps/good_little.cub | 8 +++---- testmaps/good_reallyweirdblank.cub | 16 ++++++++----- testmaps/good_weirdblank.cub | 10 ++++----- testmaps/good_weirdshape.cub | 8 +++---- 25 files changed, 199 insertions(+), 140 deletions(-) diff --git a/include/const.h b/include/const.h index 173da3d..74a709d 100644 --- a/include/const.h +++ b/include/const.h @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 17:00:59 by mc #+# #+# */ -/* Updated: 2024/10/31 17:06:00 by mc ### ########.fr */ +/* Updated: 2024/10/31 18:15:13 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,17 +15,18 @@ # include "include.h" -# define MAP_WIDTH 24 // cases (TODO test) -# define MAP_HEIGHT 24 // cases (TODO test) -# define MOVE_SPEED 0.05 // cases -# define PI 3.1415926535 -# define ROT_SPEED_DIVIDE_PI 64 // pi/n rad -# define COLOR_WALL 0xFF0000 // 0xRRGGBB -# define COLOR_CEILING 0x29f8ff // 0xRRGGBB -# define COLOR_FLOOR 0xFF985C // 0xRRGGBB -# define SCREEN_WIDTH 640 // px -# define SCREEN_HEIGHT 480 // px -# define FOV 0.66 // ? TODO unit -# define HITBOX 0.25 // cases. should be more than MOVE_SPEED +# define PI 3.1415926535 // it's just pi + +# define MOVE_SPEED 0.05 // Player oves by N cases by tick +# define ROT_SPEED_DIVIDE_PI 64 // Player turns by pi/N rad by tick +# define HITBOX 0.25 // Hitbox of N cases around player. + +# define COLOR_CEILING 0x29f8ff // TODO get from cub file +# define COLOR_FLOOR 0xFF985C // TODO get from cub file + +# define SCREEN_WIDTH 640 // Width of the window +# define SCREEN_HEIGHT 480 // Height of the window + +# define FOV 0.66 // ? TODO no idea #endif diff --git a/include/global.h b/include/global.h index 5be9d0b..2c75fd7 100644 --- a/include/global.h +++ b/include/global.h @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 17:06:31 by mc #+# #+# */ -/* Updated: 2024/10/31 17:29:00 by mc ### ########.fr */ +/* Updated: 2024/10/31 18:11:08 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,9 +17,13 @@ # include "map.h" +/// @brief mlx connection identifier extern void *g_mlx; + +/// @brief Identifier to the opened window extern void *g_win; -extern t_player g_player; + +/// @brief Current map extern t_map g_map; #endif diff --git a/include/input.h b/include/input.h index 6fda136..ee61d05 100644 --- a/include/input.h +++ b/include/input.h @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:09 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 16:24:16 by mc ### ########.fr */ +/* Updated: 2024/11/01 20:59:28 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,8 +15,7 @@ # include "include.h" -/// @brief Modified by the input of the user. A value becomes true -/// when the user presses the corresponding key. +/// @brief For g_input_actions typedef struct s_input_actions { bool left; @@ -26,10 +25,23 @@ typedef struct s_input_actions bool quit; } t_input_actions; +/// @brief Modified by the input of the user. A value becomes true +/// when the user presses the corresponding key. extern t_input_actions g_input_actions; -int keypress(int keycode); -int keyrelease(int keycode); +/// @brief To call when a specific key is newly pressed. +/// +/// @param keycode Key pressed. +/// @return Unused. +int hook_keypress(int keycode); + +/// @brief To call when a specific key is released. +/// +/// @param keycode Key released. +/// @return Unused. +int hook_keyrelease(int keycode); + +/// @brief To call at the start of the program. void input_init(void); #endif diff --git a/include/map.h b/include/map.h index 228be5c..60f549a 100644 --- a/include/map.h +++ b/include/map.h @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 17:55:39 by mc ### ########.fr */ +/* Updated: 2024/11/06 19:24:03 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ # include "utils.h" -/// @brief The type of a case. +/// @brief The type of a case. typedef enum e_map_wall { /// @brief Empty case, for '0' and ' '. @@ -32,16 +32,19 @@ typedef struct s_object /// @brief Function called when creating the object. /// /// @param data Address of the s_object.data pointer. + /// @param pos Start position of the object. void (*init)(void **data, t_point_int pos); /// @brief Function called when destroying the object (to avoid leaks). /// /// @param data Address of the s_object.data pointer. + /// @param pos Start position of the object. void (*destroy)(void **data, t_point_int pos); /// @brief Function called each tick. /// /// @param data Address of the s_object.data pointer. + /// @param pos Start position of the object. void (*tick)(void **data, t_point_int pos); /// @brief Pointer the object can use to save data. @@ -83,6 +86,21 @@ typedef struct s_player double rot; } t_player; +typedef enum e_direction +{ + NORTH, + SOUTH, + EAST, + WEST, +} t_direction; + +typedef struct s_texture +{ + int width; + int height; + void *image; +} t_texture; + /// @brief Represents a map. typedef struct s_map { @@ -92,17 +110,11 @@ typedef struct s_map /// @brief Color of the ceiling. t_color color_ceiling; - /// @brief Path to the image file for the wall face north. - const char *texture_north; + /// @brief File path for each texture. Index is t_direction. + const char *texture_srcs[4]; - /// @brief Path to the image file for the wall face south. - const char *texture_south; - - /// @brief Path to the image file for the wall face west. - const char *texture_west; - - /// @brief Path to the image file for the wall face east. - const char *texture_east; + /// @brief All textures. Index is t_direction. + t_texture textures[4]; /// @brief Width of the map. unsigned int width; diff --git a/include/move.h b/include/move.h index 03804d0..e5326d8 100644 --- a/include/move.h +++ b/include/move.h @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 16:59:27 by mc #+# #+# */ -/* Updated: 2024/10/31 16:59:48 by mc ### ########.fr */ +/* Updated: 2024/11/01 21:05:51 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,7 @@ # include "include.h" +/// @brief Move the player according to the user input. void move(void); #endif diff --git a/include/player.h b/include/player.h index 09a7177..2795edf 100644 --- a/include/player.h +++ b/include/player.h @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 17:31:35 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 17:30:01 by mc ### ########.fr */ +/* Updated: 2024/11/01 20:41:30 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,9 +17,16 @@ # include "utils.h" +/// @brief Create a player facing north (to use with t_object.init). void init_player_n(void **data, t_point_int pos); + +/// @brief Create a player facing south (to use with t_object.init). void init_player_s(void **data, t_point_int pos); + +/// @brief Create a player facing west (to use with t_object.init). void init_player_w(void **data, t_point_int pos); + +/// @brief Create a player facing east (to use with t_object.init). void init_player_e(void **data, t_point_int pos); #endif diff --git a/include/render.h b/include/render.h index 7f7eec2..86d5134 100644 --- a/include/render.h +++ b/include/render.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* render.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 17:13:20 by mc #+# #+# */ -/* Updated: 2024/10/31 17:27:33 by mc ### ########.fr */ +/* Updated: 2024/11/04 13:47:47 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,13 @@ # include "utils.h" # include "temp.h" +# include "const.h" +# include "global.h" -int render(u_int32_t *img_data, t_tex *tex); +/// @brief Draw the camera image using raycasting. +/// +/// @param img_data Data addr of the image to draw on. +/// @return Unused. +int render(u_int32_t *img_data); #endif diff --git a/include/utils.h b/include/utils.h index 76da5af..597362d 100644 --- a/include/utils.h +++ b/include/utils.h @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 16:56:47 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 17:15:31 by mc ### ########.fr */ +/* Updated: 2024/11/01 20:55:00 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,12 +17,14 @@ typedef uint32_t u_int32_t; +/// @brief Represents a point of double type. typedef struct s_point_double { double x; double y; } t_point_double; +/// @brief Represents a point of int type. typedef struct s_point_int { int x; @@ -60,6 +62,12 @@ void timedloop(void (*f)(void)); /// @return Address to the data, or NULL if error. u_int32_t *get_data_addr(void *img_ptr); +/// @brief Create a vector according to the angle with a specific norm. +/// (0 rad returns (0;-1) / pi/2 rad returns (1;0)) +/// +/// @param vec This will be set to the result. +/// @param angle Angle to use in radians. +/// @param norm Norm the vector must have. void vector_from_rotation(t_point_double *vec, double angle, double norm); /// @brief Size of buffer used in read_all_text(). diff --git a/src/global.c b/src/global.c index b0e9111..710298b 100644 --- a/src/global.c +++ b/src/global.c @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/31 17:20:56 by mc ### ########.fr */ +/* Updated: 2024/11/01 20:56:43 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,4 +15,3 @@ void *g_mlx = NULL; void *g_win = NULL; t_map g_map; -t_player g_player; diff --git a/src/input.c b/src/input.c index 9f0ee6c..0897563 100644 --- a/src/input.c +++ b/src/input.c @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:36 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 17:21:00 by mc ### ########.fr */ +/* Updated: 2024/11/01 20:59:32 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,13 +28,13 @@ static void set_action(int keycode, bool value) g_input_actions.quit = value; } -int keypress(int keycode) +int hook_keypress(int keycode) { set_action(keycode, true); return (0); } -int keyrelease(int keycode) +int hook_keyrelease(int keycode) { set_action(keycode, false); return (0); @@ -42,9 +42,5 @@ int keyrelease(int keycode) void input_init(void) { - g_input_actions.down = false; - g_input_actions.up = false; - g_input_actions.left = false; - g_input_actions.right = false; - g_input_actions.quit = false; + ft_memset(&g_input_actions, 0, sizeof(g_input_actions)); } diff --git a/src/main.c b/src/main.c index 69352d9..30db71a 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 16:57:40 by mc #+# #+# */ -/* Updated: 2024/10/31 17:55:18 by mc ### ########.fr */ +/* Updated: 2024/11/07 00:07:35 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,32 +18,16 @@ # include "const.h" # include "global.h" -static void load_textures(t_tex *tex) -{ - tex->tex_width = 64; - tex->tex_height = 64; - tex->textures[0] = mlx_xpm_file_to_image(g_mlx, "textures/north.xpm", - &tex->tex_width, &tex->tex_height); - tex->textures[1] = mlx_xpm_file_to_image(g_mlx, "textures/south.xpm", - &tex->tex_width, &tex->tex_height); - tex->textures[2] = mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", - &tex->tex_width, &tex->tex_height); - tex->textures[3] = mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", - &tex->tex_width, &tex->tex_height); -} - static void draw_screen(void) { void *img_ptr; u_int32_t *img_data; - t_tex tex; - load_textures(&tex); img_ptr = mlx_new_image(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT); img_data = get_data_addr(img_ptr); if (!img_data) exit(1); - render(img_data, &tex); + render(img_data); mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); mlx_destroy_image(g_mlx, img_ptr); } @@ -78,8 +62,8 @@ int main(int argc, char *argv[]) if (!map_from_file(&g_map, argv[1])) return (1); g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d"); - mlx_hook(g_win, KeyPress, KeyPressMask, keypress, NULL); - mlx_hook(g_win, KeyRelease, KeyReleaseMask, keyrelease, NULL); + mlx_hook(g_win, KeyPress, KeyPressMask, hook_keypress, NULL); + mlx_hook(g_win, KeyRelease, KeyReleaseMask, hook_keyrelease, NULL); mlx_loop_hook(g_mlx, loop_hook, NULL); draw_screen(); mlx_loop(g_mlx); diff --git a/src/map1.c b/src/map1.c index 931ad2a..72955a8 100644 --- a/src/map1.c +++ b/src/map1.c @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 17:12:58 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 17:56:25 by mc ### ########.fr */ +/* Updated: 2024/11/06 19:29:59 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -68,15 +68,21 @@ bool map_from_file(t_map *dest, const char *file) close(fd); return (false); } - return (map_from_file2(dest, &stream, fd)); + if (!map_from_file2(dest, &stream, fd)) + return (false); + return (load_textures(dest)); } void map_destroy(t_map *map) { - free((void *)map->texture_east); - free((void *)map->texture_west); - free((void *)map->texture_north); - free((void *)map->texture_south); + t_direction d; + + d = 0; + while (d < 4) + { + free((void *)map->textures[d].image); + free((void *)map->texture_srcs[d]); + } free(map->cases); } @@ -109,6 +115,7 @@ static bool check_map2(const t_map *map, unsigned int x, unsigned int y) } // TODO check player + bool check_map(const t_map *map) { unsigned int x; diff --git a/src/map_utils.h b/src/map_utils.h index c0b5184..db5f72b 100644 --- a/src/map_utils.h +++ b/src/map_utils.h @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 15:05:13 by mc #+# #+# */ -/* Updated: 2024/10/31 17:56:54 by mc ### ########.fr */ +/* Updated: 2024/11/06 19:34:01 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -74,4 +74,6 @@ bool read_map_description(t_map *map, t_stream *stream); /// @param map Map to use. void map_init_objects(t_map *map); +bool load_textures(t_map *map); + #endif diff --git a/src/map_utils1.c b/src/map_utils1.c index da844e8..74abb76 100644 --- a/src/map_utils1.c +++ b/src/map_utils1.c @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 15:02:09 by mc #+# #+# */ -/* Updated: 2024/10/31 17:21:36 by mc ### ########.fr */ +/* Updated: 2024/11/06 19:33:31 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -74,37 +74,33 @@ bool read_string_parameter(const char *name, const char **dest, static void read_map2(t_map *dest, bool *err, bool *rdf) { - dest->cases = NULL; + ft_memset(dest, '\0', sizeof(dest)); dest->color_ceiling = 0xFF000000; dest->color_floor = 0xFF000000; - dest->texture_east = NULL; - dest->texture_west = NULL; - dest->texture_north = NULL; - dest->texture_south = NULL; *err = false; *rdf = false; } -bool read_map(t_map *dest, t_stream *stream) +bool read_map(t_map *dest, t_stream *s) { bool err; bool rdf; int old_stream_i; read_map2(dest, &err, &rdf); - while (!rdf && !err && stream->str[stream->i]) + while (!rdf && !err && s->str[s->i]) { - old_stream_i = stream->i; - if ((read_expected_string("\n", stream, &err), err) - && !read_string_parameter("NO", &dest->texture_north, stream, &rdf) - && !read_string_parameter("SO", &dest->texture_south, stream, &rdf) - && !read_string_parameter("WE", &dest->texture_west, stream, &rdf) - && !read_string_parameter("EA", &dest->texture_east, stream, &rdf) - && !read_color_parameter("F", &dest->color_floor, stream, &rdf) - && !read_color_parameter("C", &dest->color_ceiling, stream, &rdf)) + old_stream_i = s->i; + if ((read_expected_string("\n", s, &err), err) + && !read_string_parameter("NO", &dest->texture_srcs[NORTH], s, &rdf) + && !read_string_parameter("SO", &dest->texture_srcs[SOUTH], s, &rdf) + && !read_string_parameter("WE", &dest->texture_srcs[WEST], s, &rdf) + && !read_string_parameter("EA", &dest->texture_srcs[EAST], s, &rdf) + && !read_color_parameter("F", &dest->color_floor, s, &rdf) + && !read_color_parameter("C", &dest->color_ceiling, s, &rdf)) { - stream->i = old_stream_i; - err = !read_map_description(dest, stream); + s->i = old_stream_i; + err = !read_map_description(dest, s); break ; } err = false; diff --git a/src/map_utils2.c b/src/map_utils2.c index c159465..ecb7e8d 100644 --- a/src/map_utils2.c +++ b/src/map_utils2.c @@ -6,12 +6,14 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/04 15:12:08 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 17:21:44 by mc ### ########.fr */ +/* Updated: 2024/11/07 00:08:13 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "map_utils.h" +#include "global.h" + /// @brief Read the map description to get the dimensions. /// The map must be at least 1x1. /// @@ -100,3 +102,17 @@ bool read_map_description(t_map *map, t_stream *stream) } return (true); } + +bool load_textures(t_map *map) +{ + t_direction d; + + d = 0; + while (d < 4) { + map->textures[d].image = mlx_xpm_file_to_image(g_mlx, + (char *)(map->texture_srcs[d]), + &map->textures[d].width, &map->textures[d].height); + d++; + } + return (true); +} diff --git a/src/render.c b/src/render.c index 288ee6c..90c10b1 100644 --- a/src/render.c +++ b/src/render.c @@ -6,16 +6,13 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/10/31 18:02:59 by mc ### ########.fr */ +/* Updated: 2024/11/07 00:54:17 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "render.h" #include "render_utils.h" -#include "const.h" -#include "global.h" - static void calculate_perpwalldist3(int x, t_point_double *deltadist, t_ray *ray) @@ -134,15 +131,22 @@ static void draw_vertical_line(int x, u_int32_t *img_data, } } -int render(u_int32_t *img_data, t_tex *tex) +int render(u_int32_t *img_data) { int x; t_ray ray; - + t_tex tex; + + tex.tex_width = 64; // TODO fix + tex.tex_height = 64; // TODO fix + tex.textures[NORTH] = g_map.textures[NORTH].image; + tex.textures[SOUTH] = g_map.textures[SOUTH].image; + tex.textures[WEST] = g_map.textures[WEST].image; + tex.textures[EAST] = g_map.textures[EAST].image; x = 0; while (x < SCREEN_WIDTH) { - draw_vertical_line(x, img_data, &ray, tex); + draw_vertical_line(x, img_data, &ray, &tex); x++; } return (0); diff --git a/src/render_utils.c b/src/render_utils.c index a12f90a..53289aa 100644 --- a/src/render_utils.c +++ b/src/render_utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* render_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/24 14:26:22 by grobledo #+# #+# */ -/* Updated: 2024/10/31 18:02:20 by mc ### ########.fr */ +/* Updated: 2024/11/04 14:00:25 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,16 +39,18 @@ void draw_wall(t_tex *tex, t_ray *ray, const int line_height, int x, { u_int32_t color; u_int32_t *texture_data; + int texx; + int texy; - tex->tex_y = ((y - (-line_height / 2 + SCREEN_HEIGHT / 2)) \ + texy = ((y - (-line_height / 2 + SCREEN_HEIGHT / 2)) \ * tex->tex_height) / line_height; - tex->tex_x = (int)(ray->wallx * (double)tex->tex_width); + texx = (int)(ray->wallx * (double)tex->tex_width); if (ray->side == 0 && ray->dir.x > 0) - tex->tex_x = tex->tex_width - tex->tex_x - 1; + texx = tex->tex_width - texx - 1; if (ray->side == 1 && ray->dir.y < 0) - tex->tex_x = tex->tex_height - tex->tex_x - 1; + texx = tex->tex_height - texx - 1; texture_data = (u_int32_t *)mlx_get_data_addr(tex->textures[tex->tex_dir], &tex->bpp, &tex->size_line, &tex->endian); - color = texture_data[tex->tex_x * tex->tex_width + tex->tex_y]; + color = texture_data[texx * tex->tex_width + texy]; img_data[y * SCREEN_WIDTH + x] = color; } diff --git a/src/render_utils.h b/src/render_utils.h index 01a826e..f3d8444 100644 --- a/src/render_utils.h +++ b/src/render_utils.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* render_utils.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/24 14:26:22 by grobledo #+# #+# */ -/* Updated: 2024/10/31 18:01:59 by mc ### ########.fr */ +/* Updated: 2024/11/04 13:07:42 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/utils.c b/src/utils.c index 21f928c..724b4cd 100644 --- a/src/utils.c +++ b/src/utils.c @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:38:40 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 17:25:30 by mc ### ########.fr */ +/* Updated: 2024/11/07 00:05:39 by mc ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/testmaps/good_big.cub b/testmaps/good_big.cub index fbf802a..621a6e5 100644 --- a/testmaps/good_big.cub +++ b/testmaps/good_big.cub @@ -1,9 +1,9 @@ F 255,127,0 -EA eastimage -NO theimageforthenorthwall C 0,2,67 -SO SOUTH!!!!!!1 -WE weeeee +EA textures/east.xpm +NO textures/north.xpm +SO textures/south.xpm +WE textures/west.xpm 111111111 100000001 100010001 diff --git a/testmaps/good_directions.cub b/testmaps/good_directions.cub index d27f00d..dbe596e 100644 --- a/testmaps/good_directions.cub +++ b/testmaps/good_directions.cub @@ -1,10 +1,10 @@ F 255,127,0 -EA eastimage -NO theimageforthenorthwall C 0,2,67 -SO SOUTH!!!!!!1 -WE weeeee -111111111 +EA textures/east.xpm +NO textures/north.xpm +SO textures/south.xpm +WE textures/west.xpm + 111 111110111 10000N001 111110111 diff --git a/testmaps/good_little.cub b/testmaps/good_little.cub index 7122765..06ef59c 100644 --- a/testmaps/good_little.cub +++ b/testmaps/good_little.cub @@ -1,9 +1,9 @@ F 255,127,0 -EA eastimage -NO theimageforthenorthwall C 0,2,67 -SO SOUTH!!!!!!1 -WE weeeee +EA textures/east.xpm +NO textures/north.xpm +SO textures/south.xpm +WE textures/west.xpm 111 1N1 111 diff --git a/testmaps/good_reallyweirdblank.cub b/testmaps/good_reallyweirdblank.cub index de7124d..cb0bdff 100644 --- a/testmaps/good_reallyweirdblank.cub +++ b/testmaps/good_reallyweirdblank.cub @@ -1,15 +1,19 @@ F 255, 127 ,0 -EA eastimage - -NO theimageforthenorthwall C 0, 2 , 67 -SO SOUTH!!!!!!1 - -WE weeeee +EA textures/east.xpm +NO textures/north.xpm + +SO textures/south.xpm + + + + + +WE textures/west.xpm diff --git a/testmaps/good_weirdblank.cub b/testmaps/good_weirdblank.cub index cf473b2..0710fa6 100644 --- a/testmaps/good_weirdblank.cub +++ b/testmaps/good_weirdblank.cub @@ -1,15 +1,13 @@ F 255,127,0 -EA eastimage +EA textures/east.xpm -NO theimageforthenorthwall +NO textures/north.xpm C 0,2,67 -SO SOUTH!!!!!!1 - -WE weeeee - +SO textures/south.xpm +WE textures/west.xpm diff --git a/testmaps/good_weirdshape.cub b/testmaps/good_weirdshape.cub index edf7730..a28197a 100644 --- a/testmaps/good_weirdshape.cub +++ b/testmaps/good_weirdshape.cub @@ -1,9 +1,9 @@ F 255,127,0 -EA eastimage -NO theimageforthenorthwall C 0,2,67 -SO SOUTH!!!!!!1 -WE weeeee +EA textures/east.xpm +NO textures/north.xpm +SO textures/south.xpm +WE textures/west.xpm 111 111 101 From 14828813ea5633f3ea18c88de977591a869c67a7 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 7 Nov 2024 01:09:01 +0100 Subject: [PATCH 48/80] add to TODO --- dev/TODO | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/TODO b/dev/TODO index 279024f..0cc1dcf 100644 --- a/dev/TODO +++ b/dev/TODO @@ -1 +1,2 @@ TODO replace all mlx_get_data_addr by util which check the image format +TODO different texture dimensions From 8ad8eb1fbcf2915517354eb6b5f807151e063b10 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 7 Nov 2024 14:27:17 +0100 Subject: [PATCH 50/80] handle cross click --- include/input.h | 8 +++++--- src/input.c | 16 +++++++++++++--- src/main.c | 6 ++---- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/include/input.h b/include/input.h index ee61d05..6887ad7 100644 --- a/include/input.h +++ b/include/input.h @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:09 by mcolonna #+# #+# */ -/* Updated: 2024/11/01 20:59:28 by mc ### ########.fr */ +/* Updated: 2024/11/07 14:26:28 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,7 +41,9 @@ int hook_keypress(int keycode); /// @return Unused. int hook_keyrelease(int keycode); -/// @brief To call at the start of the program. -void input_init(void); +/// @brief To handle the input of a window. +/// +/// @param win_ptr Reference to the window to use. +void input_init(void *win_ptr); #endif diff --git a/src/input.c b/src/input.c index 0897563..2d09381 100644 --- a/src/input.c +++ b/src/input.c @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:36 by mcolonna #+# #+# */ -/* Updated: 2024/11/01 20:59:32 by mc ### ########.fr */ +/* Updated: 2024/11/07 14:25:46 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,13 @@ t_input_actions g_input_actions; +static int set_quit(void *_) +{ + (void)_; + g_input_actions.quit = true; + return (0); +} + static void set_action(int keycode, bool value) { if (keycode == XK_Up || keycode == XK_z || keycode == XK_w) @@ -25,7 +32,7 @@ static void set_action(int keycode, bool value) if (keycode == XK_Left || keycode == XK_q || keycode == XK_a) g_input_actions.left = value; if (keycode == XK_Escape) - g_input_actions.quit = value; + set_quit(NULL); } int hook_keypress(int keycode) @@ -40,7 +47,10 @@ int hook_keyrelease(int keycode) return (0); } -void input_init(void) +void input_init(void *win_ptr) { ft_memset(&g_input_actions, 0, sizeof(g_input_actions)); + mlx_hook(win_ptr, DestroyNotify, StructureNotifyMask, set_quit, NULL); + mlx_hook(win_ptr, KeyPress, KeyPressMask, hook_keypress, NULL); + mlx_hook(win_ptr, KeyRelease, KeyReleaseMask, hook_keyrelease, NULL); } diff --git a/src/main.c b/src/main.c index 30db71a..23ab3c1 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 16:57:40 by mc #+# #+# */ -/* Updated: 2024/11/07 00:07:35 by mc ### ########.fr */ +/* Updated: 2024/11/07 14:25:29 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -53,7 +53,6 @@ static int loop_hook(void *param) int main(int argc, char *argv[]) { g_mlx = mlx_init(); - input_init(); if (argc != 2) { printf("Syntax: %s \n", argv[0]); @@ -62,8 +61,7 @@ int main(int argc, char *argv[]) if (!map_from_file(&g_map, argv[1])) return (1); g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d"); - mlx_hook(g_win, KeyPress, KeyPressMask, hook_keypress, NULL); - mlx_hook(g_win, KeyRelease, KeyReleaseMask, hook_keyrelease, NULL); + input_init(g_win); mlx_loop_hook(g_mlx, loop_hook, NULL); draw_screen(); mlx_loop(g_mlx); From a2a0a914954a31f7e66b2c02e0a6a6d1948a7ffc Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 7 Nov 2024 15:55:54 +0100 Subject: [PATCH 51/80] fix all leaks --- src/main.c | 42 +++++++++++++++++++++++++++--------------- src/map1.c | 6 ++++-- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/main.c b/src/main.c index 23ab3c1..66a2f01 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 16:57:40 by mc #+# #+# */ -/* Updated: 2024/11/07 14:25:29 by mc ### ########.fr */ +/* Updated: 2024/11/07 14:52:00 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,6 +18,8 @@ # include "const.h" # include "global.h" +static int g_return_value = 0; + static void draw_screen(void) { void *img_ptr; @@ -26,7 +28,10 @@ static void draw_screen(void) img_ptr = mlx_new_image(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT); img_data = get_data_addr(img_ptr); if (!img_data) - exit(1); + { + g_return_value = 1; + mlx_loop_end(g_mlx); + } render(img_data); mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); mlx_destroy_image(g_mlx, img_ptr); @@ -36,10 +41,7 @@ static void loop(void) { move(); if (g_input_actions.quit) - { - mlx_destroy_window(g_mlx, g_win); - exit(0); - } + mlx_loop_end(g_mlx); draw_screen(); } @@ -56,14 +58,24 @@ int main(int argc, char *argv[]) if (argc != 2) { printf("Syntax: %s \n", argv[0]); - return (1); + g_return_value = 1; } - if (!map_from_file(&g_map, argv[1])) - return (1); - g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d"); - input_init(g_win); - mlx_loop_hook(g_mlx, loop_hook, NULL); - draw_screen(); - mlx_loop(g_mlx); - return (0); + else + { + if (!map_from_file(&g_map, argv[1])) + g_return_value = 1; + else + { + g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d"); + input_init(g_win); + mlx_loop_hook(g_mlx, loop_hook, NULL); + draw_screen(); + mlx_loop(g_mlx); + mlx_destroy_window(g_mlx, g_win); + map_destroy(&g_map); + } + } + mlx_destroy_display(g_mlx); + free(g_mlx); + return (g_return_value); } diff --git a/src/map1.c b/src/map1.c index 72955a8..97a6d4a 100644 --- a/src/map1.c +++ b/src/map1.c @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 17:12:58 by mcolonna #+# #+# */ -/* Updated: 2024/11/06 19:29:59 by mc ### ########.fr */ +/* Updated: 2024/11/07 15:49:39 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,7 @@ #include "stream.h" #include "player.h" +#include "global.h" const t_map_mapping_element g_map_mapping[] = { {' ', {false, EMPTY, {NULL, NULL, NULL, NULL}}}, @@ -80,8 +81,9 @@ void map_destroy(t_map *map) d = 0; while (d < 4) { - free((void *)map->textures[d].image); + mlx_destroy_image(g_mlx, map->textures[d].image); free((void *)map->texture_srcs[d]); + d++; } free(map->cases); } From f77a4446b6441886bad0dc93a1715bda37507ed5 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 7 Nov 2024 18:03:38 +0100 Subject: [PATCH 52/80] add rotate with mouse --- include/const.h | 3 ++- include/input.h | 6 ++++-- src/input.c | 23 +++++++++++++++++++++-- src/main.c | 4 ++-- src/move.c | 4 +++- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/include/const.h b/include/const.h index 74a709d..b4e4e51 100644 --- a/include/const.h +++ b/include/const.h @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 17:00:59 by mc #+# #+# */ -/* Updated: 2024/10/31 18:15:13 by mc ### ########.fr */ +/* Updated: 2024/11/07 17:10:50 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,7 @@ # define MOVE_SPEED 0.05 // Player oves by N cases by tick # define ROT_SPEED_DIVIDE_PI 64 // Player turns by pi/N rad by tick +# define MOUSE_ROTATION_SPEED 0.001 // rad/px # define HITBOX 0.25 // Hitbox of N cases around player. # define COLOR_CEILING 0x29f8ff // TODO get from cub file diff --git a/include/input.h b/include/input.h index 6887ad7..c0e2c55 100644 --- a/include/input.h +++ b/include/input.h @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:09 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 14:26:28 by mc ### ########.fr */ +/* Updated: 2024/11/07 17:13:28 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,7 @@ typedef struct s_input_actions bool up; bool down; bool quit; + int rotate; } t_input_actions; /// @brief Modified by the input of the user. A value becomes true @@ -43,7 +44,8 @@ int hook_keyrelease(int keycode); /// @brief To handle the input of a window. /// +/// @param mlx_ptr mlx connection identifier /// @param win_ptr Reference to the window to use. -void input_init(void *win_ptr); +void input_init(void *mlx_ptr, void *win_ptr); #endif diff --git a/src/input.c b/src/input.c index 2d09381..3695cac 100644 --- a/src/input.c +++ b/src/input.c @@ -6,11 +6,13 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:36 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 14:25:46 by mc ### ########.fr */ +/* Updated: 2024/11/07 18:03:00 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "input.h" +#include "global.h" +#include "const.h" t_input_actions g_input_actions; @@ -47,10 +49,27 @@ int hook_keyrelease(int keycode) return (0); } -void input_init(void *win_ptr) +static int hook_mousemove(int x, int y) +{ + static const t_point_int window_middle = { + SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2}; + static bool first_call = true; + const int dx = x - window_middle.x; + + if (!first_call && dx) + g_input_actions.rotate += dx; + first_call = false; + if (x != window_middle.x || y != window_middle.y) + mlx_mouse_move(g_mlx, g_win, window_middle.x, window_middle.y); + return (0); +} + +void input_init(void *mlx_ptr, void *win_ptr) { ft_memset(&g_input_actions, 0, sizeof(g_input_actions)); mlx_hook(win_ptr, DestroyNotify, StructureNotifyMask, set_quit, NULL); mlx_hook(win_ptr, KeyPress, KeyPressMask, hook_keypress, NULL); mlx_hook(win_ptr, KeyRelease, KeyReleaseMask, hook_keyrelease, NULL); + mlx_hook(win_ptr, MotionNotify, PointerMotionMask, hook_mousemove, NULL); + mlx_mouse_hide(mlx_ptr, win_ptr); } diff --git a/src/main.c b/src/main.c index 66a2f01..dc27d99 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 16:57:40 by mc #+# #+# */ -/* Updated: 2024/11/07 14:52:00 by mc ### ########.fr */ +/* Updated: 2024/11/07 17:12:44 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,7 +67,7 @@ int main(int argc, char *argv[]) else { g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d"); - input_init(g_win); + input_init(g_mlx, g_win); mlx_loop_hook(g_mlx, loop_hook, NULL); draw_screen(); mlx_loop(g_mlx); diff --git a/src/move.c b/src/move.c index 421af95..e977685 100644 --- a/src/move.c +++ b/src/move.c @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:47:34 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 17:58:27 by mc ### ########.fr */ +/* Updated: 2024/11/07 17:09:31 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -82,4 +82,6 @@ void move(void) rotate(+1); if (g_input_actions.left && !g_input_actions.right) rotate(-1); + g_map.player.rot += (double)g_input_actions.rotate * MOUSE_ROTATION_SPEED; + g_input_actions.rotate = 0; } From f22e02bfc1381e3bff66f6c1e9e6e85087a70c9b Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 7 Nov 2024 18:39:42 +0100 Subject: [PATCH 53/80] fix leak by removing mlx_mouse_hide() :( --- src/input.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/input.c b/src/input.c index 3695cac..ac940fe 100644 --- a/src/input.c +++ b/src/input.c @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:36 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 18:03:00 by mc ### ########.fr */ +/* Updated: 2024/11/07 18:37:52 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,12 +64,13 @@ static int hook_mousemove(int x, int y) return (0); } +// TODO hide cursor without leak? void input_init(void *mlx_ptr, void *win_ptr) { + (void)mlx_ptr; ft_memset(&g_input_actions, 0, sizeof(g_input_actions)); mlx_hook(win_ptr, DestroyNotify, StructureNotifyMask, set_quit, NULL); mlx_hook(win_ptr, KeyPress, KeyPressMask, hook_keypress, NULL); mlx_hook(win_ptr, KeyRelease, KeyReleaseMask, hook_keyrelease, NULL); mlx_hook(win_ptr, MotionNotify, PointerMotionMask, hook_mousemove, NULL); - mlx_mouse_hide(mlx_ptr, win_ptr); } From fd4fb3c93f4a274f407a1abd884e9bc610346813 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 7 Nov 2024 19:08:00 +0100 Subject: [PATCH 54/80] some norminette and some cleaning --- include/input.h | 14 +------------- include/temp.h | 6 +++--- include/utils.h | 15 +++++++-------- src/input.c | 23 +++++------------------ src/input_utils.c | 28 ++++++++++++++++++++++++++++ src/input_utils.h | 20 ++++++++++++++++++++ src/main.c | 12 ++++++------ src/map1.c | 5 +++-- src/map_utils.h | 4 ++-- src/map_utils1.c | 39 +++++++++++++++++++-------------------- src/map_utils2.c | 11 ++++++----- src/utils2.c | 4 ++-- 12 files changed, 102 insertions(+), 79 deletions(-) create mode 100644 src/input_utils.c create mode 100644 src/input_utils.h diff --git a/include/input.h b/include/input.h index c0e2c55..76da466 100644 --- a/include/input.h +++ b/include/input.h @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:09 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 17:13:28 by mc ### ########.fr */ +/* Updated: 2024/11/07 19:03:25 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,18 +30,6 @@ typedef struct s_input_actions /// when the user presses the corresponding key. extern t_input_actions g_input_actions; -/// @brief To call when a specific key is newly pressed. -/// -/// @param keycode Key pressed. -/// @return Unused. -int hook_keypress(int keycode); - -/// @brief To call when a specific key is released. -/// -/// @param keycode Key released. -/// @return Unused. -int hook_keyrelease(int keycode); - /// @brief To handle the input of a window. /// /// @param mlx_ptr mlx connection identifier diff --git a/include/temp.h b/include/temp.h index d447a27..73f1248 100644 --- a/include/temp.h +++ b/include/temp.h @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 17:04:08 by mc #+# #+# */ -/* Updated: 2024/10/31 17:28:09 by mc ### ########.fr */ +/* Updated: 2024/11/07 19:07:25 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,8 +40,8 @@ typedef struct s_ray { // pos player on map (cases) t_point_double dir; - bool side; - double wallx; + bool side; + double wallx; } t_ray; #endif diff --git a/include/utils.h b/include/utils.h index 597362d..c8f82ae 100644 --- a/include/utils.h +++ b/include/utils.h @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 16:56:47 by mcolonna #+# #+# */ -/* Updated: 2024/11/01 20:55:00 by mc ### ########.fr */ +/* Updated: 2024/11/07 19:07:03 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,21 +15,19 @@ # include "include.h" -typedef uint32_t u_int32_t; - /// @brief Represents a point of double type. typedef struct s_point_double { double x; double y; -} t_point_double; +} t_point_double; /// @brief Represents a point of int type. typedef struct s_point_int { int x; int y; -} t_point_int; +} t_point_int; // TODO Must the transparency be 0 or 255? /// @brief Represents an TRGB color in 0xTTRRGGBB format. @@ -60,7 +58,7 @@ void timedloop(void (*f)(void)); /// /// @param img_ptr mlx image to use. /// @return Address to the data, or NULL if error. -u_int32_t *get_data_addr(void *img_ptr); +uint32_t *get_data_addr(void *img_ptr); /// @brief Create a vector according to the angle with a specific norm. /// (0 rad returns (0;-1) / pi/2 rad returns (1;0)) @@ -68,7 +66,8 @@ u_int32_t *get_data_addr(void *img_ptr); /// @param vec This will be set to the result. /// @param angle Angle to use in radians. /// @param norm Norm the vector must have. -void vector_from_rotation(t_point_double *vec, double angle, double norm); +void vector_from_rotation(t_point_double *vec, double angle, + double norm); /// @brief Size of buffer used in read_all_text(). # define READ_ALL_TEXT_BUFFER_SIZE 1000 @@ -81,6 +80,6 @@ void vector_from_rotation(t_point_double *vec, double angle, double norm); /// /// @param fd File descriptor of the file. /// @return Alloc'd string of the file content. NULL if error. -char *read_all_text(int fd); +char *read_all_text(int fd); #endif diff --git a/src/input.c b/src/input.c index ac940fe..bebde7b 100644 --- a/src/input.c +++ b/src/input.c @@ -6,11 +6,13 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:36 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 18:37:52 by mc ### ########.fr */ +/* Updated: 2024/11/07 19:03:15 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "input.h" +#include "input_utils.h" + #include "global.h" #include "const.h" @@ -37,33 +39,18 @@ static void set_action(int keycode, bool value) set_quit(NULL); } -int hook_keypress(int keycode) +static int hook_keypress(int keycode) { set_action(keycode, true); return (0); } -int hook_keyrelease(int keycode) +static int hook_keyrelease(int keycode) { set_action(keycode, false); return (0); } -static int hook_mousemove(int x, int y) -{ - static const t_point_int window_middle = { - SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2}; - static bool first_call = true; - const int dx = x - window_middle.x; - - if (!first_call && dx) - g_input_actions.rotate += dx; - first_call = false; - if (x != window_middle.x || y != window_middle.y) - mlx_mouse_move(g_mlx, g_win, window_middle.x, window_middle.y); - return (0); -} - // TODO hide cursor without leak? void input_init(void *mlx_ptr, void *win_ptr) { diff --git a/src/input_utils.c b/src/input_utils.c new file mode 100644 index 0000000..1e8e415 --- /dev/null +++ b/src/input_utils.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* input_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/07 19:02:04 by mc #+# #+# */ +/* Updated: 2024/11/07 19:02:15 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "input_utils.h" + +static int hook_mousemove(int x, int y) +{ + static const t_point_int window_middle = { + SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2}; + static bool first_call = true; + const int dx = x - window_middle.x; + + if (!first_call && dx) + g_input_actions.rotate += dx; + first_call = false; + if (x != window_middle.x || y != window_middle.y) + mlx_mouse_move(g_mlx, g_win, window_middle.x, window_middle.y); + return (0); +} diff --git a/src/input_utils.h b/src/input_utils.h new file mode 100644 index 0000000..0006b00 --- /dev/null +++ b/src/input_utils.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* input_utils.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/07 19:02:26 by mc #+# #+# */ +/* Updated: 2024/11/07 19:03:02 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef INPUT_UTILS_H +# define INPUT_UTILS_H + +# include "input.h" + +static int hook_mousemove(int x, int y); + +#endif diff --git a/src/main.c b/src/main.c index dc27d99..ebc393e 100644 --- a/src/main.c +++ b/src/main.c @@ -6,17 +6,17 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 16:57:40 by mc #+# #+# */ -/* Updated: 2024/11/07 17:12:44 by mc ### ########.fr */ +/* Updated: 2024/11/07 18:44:01 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "main.h" -# include "render.h" -# include "move.h" -# include "input.h" -# include "const.h" -# include "global.h" +#include "render.h" +#include "move.h" +#include "input.h" +#include "const.h" +#include "global.h" static int g_return_value = 0; diff --git a/src/map1.c b/src/map1.c index 97a6d4a..ce75afc 100644 --- a/src/map1.c +++ b/src/map1.c @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 17:12:58 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 15:49:39 by mc ### ########.fr */ +/* Updated: 2024/11/07 18:58:34 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -81,7 +81,8 @@ void map_destroy(t_map *map) d = 0; while (d < 4) { - mlx_destroy_image(g_mlx, map->textures[d].image); + if (map->textures[d].image) + mlx_destroy_image(g_mlx, map->textures[d].image); free((void *)map->texture_srcs[d]); d++; } diff --git a/src/map_utils.h b/src/map_utils.h index db5f72b..15a3713 100644 --- a/src/map_utils.h +++ b/src/map_utils.h @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 15:05:13 by mc #+# #+# */ -/* Updated: 2024/11/06 19:34:01 by mc ### ########.fr */ +/* Updated: 2024/11/07 19:04:19 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -74,6 +74,6 @@ bool read_map_description(t_map *map, t_stream *stream); /// @param map Map to use. void map_init_objects(t_map *map); -bool load_textures(t_map *map); +bool load_textures(t_map *map); #endif diff --git a/src/map_utils1.c b/src/map_utils1.c index 74abb76..728d2c5 100644 --- a/src/map_utils1.c +++ b/src/map_utils1.c @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 15:02:09 by mc #+# #+# */ -/* Updated: 2024/11/06 19:33:31 by mc ### ########.fr */ +/* Updated: 2024/11/07 18:59:07 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -74,41 +74,40 @@ bool read_string_parameter(const char *name, const char **dest, static void read_map2(t_map *dest, bool *err, bool *rdf) { - ft_memset(dest, '\0', sizeof(dest)); + ft_memset(dest, '\0', sizeof(t_map)); dest->color_ceiling = 0xFF000000; dest->color_floor = 0xFF000000; *err = false; *rdf = false; } -bool read_map(t_map *dest, t_stream *s) +bool read_map(t_map *d, t_stream *s) { - bool err; - bool rdf; + bool err[2]; int old_stream_i; - read_map2(dest, &err, &rdf); - while (!rdf && !err && s->str[s->i]) + read_map2(d, &err[0], &err[1]); + while (!err[1] && !err[0] && s->str[s->i]) { old_stream_i = s->i; - if ((read_expected_string("\n", s, &err), err) - && !read_string_parameter("NO", &dest->texture_srcs[NORTH], s, &rdf) - && !read_string_parameter("SO", &dest->texture_srcs[SOUTH], s, &rdf) - && !read_string_parameter("WE", &dest->texture_srcs[WEST], s, &rdf) - && !read_string_parameter("EA", &dest->texture_srcs[EAST], s, &rdf) - && !read_color_parameter("F", &dest->color_floor, s, &rdf) - && !read_color_parameter("C", &dest->color_ceiling, s, &rdf)) + if ((read_expected_string("\n", s, &err[0]), err[0]) + && !read_string_parameter("NO", &d->texture_srcs[NORTH], s, &err[1]) + && !read_string_parameter("SO", &d->texture_srcs[SOUTH], s, &err[1]) + && !read_string_parameter("WE", &d->texture_srcs[WEST], s, &err[1]) + && !read_string_parameter("EA", &d->texture_srcs[EAST], s, &err[1]) + && !read_color_parameter("F", &d->color_floor, s, &err[1]) + && !read_color_parameter("C", &d->color_ceiling, s, &err[1])) { s->i = old_stream_i; - err = !read_map_description(dest, s); + err[0] = !read_map_description(d, s); break ; } - err = false; + err[0] = false; } - if (!rdf && !dest->cases) - err = (write_err("Map description missing\n", NULL), true); - (rdf || err) && (map_destroy(dest), false); - return (!err && !rdf && dest->cases); + if (!err[1] && !d->cases) + err[0] = (write_err("Map description missing\n", NULL), true); + (err[1] || err[0]) && (map_destroy(d), false); + return (!err[0] && !err[1] && d->cases); } void map_init_objects(t_map *map) diff --git a/src/map_utils2.c b/src/map_utils2.c index ecb7e8d..3f55963 100644 --- a/src/map_utils2.c +++ b/src/map_utils2.c @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/04 15:12:08 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 00:08:13 by mc ### ########.fr */ +/* Updated: 2024/11/07 19:05:06 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -103,15 +103,16 @@ bool read_map_description(t_map *map, t_stream *stream) return (true); } -bool load_textures(t_map *map) +bool load_textures(t_map *map) { t_direction d; d = 0; - while (d < 4) { + while (d < 4) + { map->textures[d].image = mlx_xpm_file_to_image(g_mlx, - (char *)(map->texture_srcs[d]), - &map->textures[d].width, &map->textures[d].height); + (char *)(map->texture_srcs[d]), + &map->textures[d].width, &map->textures[d].height); d++; } return (true); diff --git a/src/utils2.c b/src/utils2.c index 60a922b..bf686a5 100644 --- a/src/utils2.c +++ b/src/utils2.c @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/29 14:02:37 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 17:25:34 by mc ### ########.fr */ +/* Updated: 2024/11/07 18:44:16 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,7 @@ u_int32_t *get_data_addr(void *img_ptr) if (bpp != 32 || endian != 0) { write_err("Wrong bpp or wrong endian when using mlx_get_data_addr().\n", - NULL); + NULL); return (NULL); } return (r); From 6eb1479fc50500b572633204f7f36a83f30208fd Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 7 Nov 2024 19:25:28 +0100 Subject: [PATCH 55/80] little compilation fix --- src/input_utils.c | 8 ++++++-- src/input_utils.h | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/input_utils.c b/src/input_utils.c index 1e8e415..59ebd65 100644 --- a/src/input_utils.c +++ b/src/input_utils.c @@ -6,13 +6,17 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/07 19:02:04 by mc #+# #+# */ -/* Updated: 2024/11/07 19:02:15 by mc ### ########.fr */ +/* Updated: 2024/11/07 19:24:05 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "input_utils.h" -static int hook_mousemove(int x, int y) +#include "const.h" +#include "utils.h" +#include "global.h" + +int hook_mousemove(int x, int y) { static const t_point_int window_middle = { SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2}; diff --git a/src/input_utils.h b/src/input_utils.h index 0006b00..1abf508 100644 --- a/src/input_utils.h +++ b/src/input_utils.h @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/07 19:02:26 by mc #+# #+# */ -/* Updated: 2024/11/07 19:03:02 by mc ### ########.fr */ +/* Updated: 2024/11/07 19:22:55 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,6 @@ # include "input.h" -static int hook_mousemove(int x, int y); +int hook_mousemove(int x, int y); #endif From 184c8a60afcb465e0a303f2ce99938a5d3a933c6 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 7 Nov 2024 19:29:58 +0100 Subject: [PATCH 56/80] use ceiling and floor colors from the map file --- include/const.h | 5 +---- src/render.c | 6 +++--- testmaps/good_floor_ceiling.cub | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 testmaps/good_floor_ceiling.cub diff --git a/include/const.h b/include/const.h index b4e4e51..62ce444 100644 --- a/include/const.h +++ b/include/const.h @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 17:00:59 by mc #+# #+# */ -/* Updated: 2024/11/07 17:10:50 by mc ### ########.fr */ +/* Updated: 2024/11/07 19:26:53 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,9 +22,6 @@ # define MOUSE_ROTATION_SPEED 0.001 // rad/px # define HITBOX 0.25 // Hitbox of N cases around player. -# define COLOR_CEILING 0x29f8ff // TODO get from cub file -# define COLOR_FLOOR 0xFF985C // TODO get from cub file - # define SCREEN_WIDTH 640 // Width of the window # define SCREEN_HEIGHT 480 // Height of the window diff --git a/src/render.c b/src/render.c index 90c10b1..2a96395 100644 --- a/src/render.c +++ b/src/render.c @@ -6,7 +6,7 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/11/07 00:54:17 by mc ### ########.fr */ +/* Updated: 2024/11/07 19:27:54 by mc ### ########.fr */ /* */ /* ************************************************************************** */ @@ -121,13 +121,13 @@ static void draw_vertical_line(int x, u_int32_t *img_data, while (y++ < SCREEN_HEIGHT) { if (y < draw_start) - img_data[y * SCREEN_WIDTH + x] = COLOR_CEILING; + img_data[y * SCREEN_WIDTH + x] = g_map.color_ceiling; else if (y < draw_end) { draw_wall(tex, ray, line_height, x, y, img_data); } else - img_data[y * SCREEN_WIDTH + x] = COLOR_FLOOR; + img_data[y * SCREEN_WIDTH + x] = g_map.color_floor; } } diff --git a/testmaps/good_floor_ceiling.cub b/testmaps/good_floor_ceiling.cub new file mode 100644 index 0000000..bf3a6c2 --- /dev/null +++ b/testmaps/good_floor_ceiling.cub @@ -0,0 +1,15 @@ +F 255,0,127 +C 0,255,255 +EA textures/east.xpm +NO textures/north.xpm +SO textures/south.xpm +WE textures/west.xpm +111111111 +100000001 +100010001 +100000001 +1000N0001 +100000001 +100000001 +100000001 +111111111 From 6007f2751095c0b708e2bc63c21722e068ea6576 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Tue, 12 Nov 2024 13:07:09 +0100 Subject: [PATCH 57/80] fix: render * fix: - fix texture for each direction (north texture is in north etc) - fix mirror textures (the left of each texture is at its left) - fix dimensions (walls are 1x1 for any window dimensions or FOV) - optimize render() dev: - add testmaps/good_directions_test.cub - add textures/test/*.xpm --- include/const.h | 4 +- include/include.h | 5 +- include/map.h | 6 +- include/render.h | 3 +- include/temp.h | 47 ------------ include/utils.h | 6 +- src/render.c | 122 +++++++++++++----------------- src/render_utils.c | 59 +++++++-------- src/render_utils.h | 38 +++++++++- testmaps/good_directions_test.cub | 13 ++++ textures/test/east.xpm | 89 ++++++++++++++++++++++ textures/test/north.xpm | 99 ++++++++++++++++++++++++ textures/test/south.xpm | 88 +++++++++++++++++++++ textures/test/west.xpm | 73 ++++++++++++++++++ 14 files changed, 488 insertions(+), 164 deletions(-) delete mode 100644 include/temp.h create mode 100644 testmaps/good_directions_test.cub create mode 100644 textures/test/east.xpm create mode 100644 textures/test/north.xpm create mode 100644 textures/test/south.xpm create mode 100644 textures/test/west.xpm diff --git a/include/const.h b/include/const.h index 62ce444..151cfe2 100644 --- a/include/const.h +++ b/include/const.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* const.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 17:00:59 by mc #+# #+# */ -/* Updated: 2024/11/07 19:26:53 by mc ### ########.fr */ +/* Updated: 2024/11/12 17:56:05 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/include/include.h b/include/include.h index 58ae764..188bf43 100644 --- a/include/include.h +++ b/include/include.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* include.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 16:22:09 by mc #+# #+# */ -/* Updated: 2024/10/31 18:03:26 by mc ### ########.fr */ +/* Updated: 2024/11/12 17:41:11 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,7 @@ # include # include # include +# include # include # include # include diff --git a/include/map.h b/include/map.h index 60f549a..b63873b 100644 --- a/include/map.h +++ b/include/map.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* map.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */ -/* Updated: 2024/11/06 19:24:03 by mc ### ########.fr */ +/* Updated: 2024/11/12 15:10:07 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -82,7 +82,7 @@ typedef struct s_player { // pos player on map (cases) t_point_double pos; - // player rotation (rad) + // player rotation (rad) (0 rad is -y / pi/2 rad is +x) double rot; } t_player; diff --git a/include/render.h b/include/render.h index 86d5134..da4d780 100644 --- a/include/render.h +++ b/include/render.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 17:13:20 by mc #+# #+# */ -/* Updated: 2024/11/04 13:47:47 by mcolonna ### ########.fr */ +/* Updated: 2024/11/12 12:24:02 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,6 @@ # include "include.h" # include "utils.h" -# include "temp.h" # include "const.h" # include "global.h" diff --git a/include/temp.h b/include/temp.h deleted file mode 100644 index 73f1248..0000000 --- a/include/temp.h +++ /dev/null @@ -1,47 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* temp.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/31 17:04:08 by mc #+# #+# */ -/* Updated: 2024/11/07 19:07:25 by mc ### ########.fr */ -/* */ -/* ************************************************************************** */ - -// DEBUG remove temp.h - -#ifndef TEMP_H -# define TEMP_H - -# include "include.h" - -# include "utils.h" - -# define TEX_WIDTH 64 -# define TEX_HEIGHT 64 - -typedef struct s_tex -{ - void *textures[4]; - void *current_tex; - int tex_height; - int tex_width; - int tex_dir; - int tex_x; - int tex_y; - int bpp; - int size_line; - int endian; -} t_tex; - -typedef struct s_ray -{ - // pos player on map (cases) - t_point_double dir; - bool side; - double wallx; -} t_ray; - -#endif diff --git a/include/utils.h b/include/utils.h index c8f82ae..a8c5c66 100644 --- a/include/utils.h +++ b/include/utils.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* utils.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 16:56:47 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 19:07:03 by mc ### ########.fr */ +/* Updated: 2024/11/12 17:01:35 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -61,7 +61,7 @@ void timedloop(void (*f)(void)); uint32_t *get_data_addr(void *img_ptr); /// @brief Create a vector according to the angle with a specific norm. -/// (0 rad returns (0;-1) / pi/2 rad returns (1;0)) +/// (0 rad is -y / pi/2 rad is +x) /// /// @param vec This will be set to the result. /// @param angle Angle to use in radians. diff --git a/src/render.c b/src/render.c index 2a96395..0ae21df 100644 --- a/src/render.c +++ b/src/render.c @@ -3,21 +3,21 @@ /* ::: :::::::: */ /* render.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: Zy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/11/07 19:27:54 by mc ### ########.fr */ +/* Updated: 2024/11/13 17:53:57 by Zy ### ########.fr */ /* */ /* ************************************************************************** */ #include "render.h" #include "render_utils.h" -static void calculate_perpwalldist3(int x, - t_point_double *deltadist, - t_ray *ray) +// needs ray->x to be defined. +static void calculate_dir_and_deltadist(t_ray *ray) { - const double ray_direction = 2 * x / (double)SCREEN_WIDTH - 1; + const double ray_direction + = FOV * 2 * ray->x / (double)SCREEN_WIDTH - FOV; t_point_double plane; t_point_double dir; @@ -25,129 +25,111 @@ static void calculate_perpwalldist3(int x, vector_from_rotation(&plane, g_map.player.rot + PI / 2, 1); ray->dir.x = dir.x + plane.x * ray_direction; ray->dir.y = dir.y + plane.y * ray_direction; - deltadist->x = 1e30; + ray->deltadist.x = 1e30; if (ray->dir.x != 0) - deltadist->x = fabs(1 / ray->dir.x); - deltadist->y = 1e30; + ray->deltadist.x = fabs(1 / ray->dir.x); + ray->deltadist.y = 1e30; if (ray->dir.y != 0) - deltadist->y = fabs(1 / ray->dir.y); + ray->deltadist.y = fabs(1 / ray->dir.y); } -static void calculate_perpwalldist2(int x, - t_point_double *sidedist, - t_point_double *deltadist, - t_point_int *step, - t_ray *ray) +// needs ray->x to be defined. +// also defines ->dir and ->deltadist. +static void calculate_step_and_sidedist(t_ray *ray) { const int map_x = (int)g_map.player.pos.x; const int map_y = (int)g_map.player.pos.y; - calculate_perpwalldist3(x, deltadist, ray); + calculate_dir_and_deltadist(ray); if (ray->dir.x < 0) { - step->x = -1; - sidedist->x = (g_map.player.pos.x - map_x) * deltadist->x; + ray->step.x = -1; + ray->sidedist.x = (g_map.player.pos.x - map_x) * ray->deltadist.x; } else { - step->x = 1; - sidedist->x = (map_x + 1.0 - g_map.player.pos.x) * deltadist->x; + ray->step.x = +1; + ray->sidedist.x = (map_x + 1.0 - g_map.player.pos.x) * ray->deltadist.x; } if (ray->dir.y < 0) { - step->y = -1; - sidedist->y = (g_map.player.pos.y - map_y) * deltadist->y; + ray->step.y = -1; + ray->sidedist.y = (g_map.player.pos.y - map_y) * ray->deltadist.y; } else { - step->y = 1; - sidedist->y = (map_y + 1.0 - g_map.player.pos.y) * deltadist->y; + ray->step.y = +1; + ray->sidedist.y = (map_y + 1.0 - g_map.player.pos.y) * ray->deltadist.y; } } -/// @brief Calculate the distance of the wall perpendicularly to the camera -/// plane. -/// -/// @param x Ray direction x between 0 and 1. -/// @return Result. -static double calculate_perpwalldist(int x, t_ray *ray) +// needs ray->x to be defined. +// also defines ->dir, ->deltadist, ->step and ->sidedist. +static void calculate_side_and_perpwalldist(t_ray *ray) { t_point_int map_pos; - t_point_double sidedist; - t_point_double deltadist; - t_point_int step; map_pos.x = (int)g_map.player.pos.x; map_pos.y = (int)g_map.player.pos.y; - calculate_perpwalldist2(x, &sidedist, &deltadist, &step, ray); + calculate_step_and_sidedist(ray); while (map_get_case(&g_map, map_pos.x, map_pos.y)->wall == EMPTY) { - if (sidedist.x < sidedist.y) + if (ray->sidedist.x < ray->sidedist.y) { - sidedist.x += deltadist.x; - map_pos.x += step.x; + ray->sidedist.x += ray->deltadist.x; + map_pos.x += ray->step.x; ray->side = false; continue ; } - sidedist.y += deltadist.y; - map_pos.y += step.y; + ray->sidedist.y += ray->deltadist.y; + map_pos.y += ray->step.y; ray->side = true; } if (!ray->side) - return (sidedist.x - deltadist.x); - return (sidedist.y - deltadist.y); + ray->perpwalldist = ray->sidedist.x - ray->deltadist.x; + else + ray->perpwalldist = ray->sidedist.y - ray->deltadist.y; } /// @brief Draw a vertical line according to the ray direction x. /// /// @param x Ray direction x between 0 and 1. -static void draw_vertical_line(int x, u_int32_t *img_data, - t_ray *ray, t_tex *tex) +static void draw_vertical_line(u_int32_t *img_data, t_ray *ray) { - const double perpwalldist = calculate_perpwalldist(x, ray); - const int line_height = (int)(SCREEN_HEIGHT / perpwalldist); - int draw_start; - int draw_end; - int y; + int line_height; + int draw_start; + int draw_end; - ft_init_texture(perpwalldist, ray, tex); + calculate_side_and_perpwalldist(ray); + calculate_texdir_and_wallx(ray); + line_height = (int)(SCREEN_WIDTH / FOV / 2 / ray->perpwalldist); draw_start = -line_height / 2 + SCREEN_HEIGHT / 2; if (draw_start < 0) draw_start = 0; draw_end = line_height / 2 + SCREEN_HEIGHT / 2; if (draw_end >= SCREEN_HEIGHT) draw_end = SCREEN_HEIGHT - 1; - y = 0; - while (y++ < SCREEN_HEIGHT) + ray->y = 0; + while (ray->y++ < SCREEN_HEIGHT) { - if (y < draw_start) - img_data[y * SCREEN_WIDTH + x] = g_map.color_ceiling; - else if (y < draw_end) - { - draw_wall(tex, ray, line_height, x, y, img_data); - } + if (ray->y < draw_start) + img_data[ray->y * SCREEN_WIDTH + ray->x] = g_map.color_ceiling; + else if (ray->y < draw_end) + draw_wall(ray, line_height, img_data); else - img_data[y * SCREEN_WIDTH + x] = g_map.color_floor; + img_data[ray->y * SCREEN_WIDTH + ray->x] = g_map.color_floor; } } int render(u_int32_t *img_data) { - int x; t_ray ray; - t_tex tex; - tex.tex_width = 64; // TODO fix - tex.tex_height = 64; // TODO fix - tex.textures[NORTH] = g_map.textures[NORTH].image; - tex.textures[SOUTH] = g_map.textures[SOUTH].image; - tex.textures[WEST] = g_map.textures[WEST].image; - tex.textures[EAST] = g_map.textures[EAST].image; - x = 0; - while (x < SCREEN_WIDTH) + ray.x = 0; + while (ray.x < SCREEN_WIDTH) { - draw_vertical_line(x, img_data, &ray, &tex); - x++; + draw_vertical_line(img_data, &ray); + ray.x++; } return (0); } diff --git a/src/render_utils.c b/src/render_utils.c index 53289aa..6cfd96c 100644 --- a/src/render_utils.c +++ b/src/render_utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* render_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: Zy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/24 14:26:22 by grobledo #+# #+# */ -/* Updated: 2024/11/04 14:00:25 by mcolonna ### ########.fr */ +/* Updated: 2024/11/13 18:11:14 by Zy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,42 +15,39 @@ #include "const.h" #include "global.h" -void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex) +void calculate_texdir_and_wallx(t_ray *ray) { - if (ray->side == 0 && ray->dir.x < 0) - tex->tex_dir = 0; - if (ray->side == 0 && ray->dir.x >= 0) - tex->tex_dir = 1; - if (ray->side == 1 && ray->dir.y < 0) - tex->tex_dir = 2; - if (ray->side == 1 && ray->dir.y >= 0) - tex->tex_dir = 3; - if (ray->side == 0) - ray->wallx = g_map.player.pos.y + perpwalldist \ + if (ray->side && ray->dir.y < 0) + ray->texdir = NORTH; + if (ray->side && ray->dir.y >= 0) + ray->texdir = SOUTH; + if (!ray->side && ray->dir.x < 0) + ray->texdir = EAST; + if (!ray->side && ray->dir.x >= 0) + ray->texdir = WEST; + if (!ray->side) + ray->wallx = g_map.player.pos.y + ray->perpwalldist \ * ray->dir.y; else - ray->wallx = g_map.player.pos.x + perpwalldist \ + ray->wallx = g_map.player.pos.x + ray->perpwalldist \ * ray->dir.x; + if (ray->texdir == SOUTH || ray->texdir == EAST) + ray->wallx = -ray->wallx; ray->wallx -= floor((ray->wallx)); } -void draw_wall(t_tex *tex, t_ray *ray, const int line_height, int x, - int y, u_int32_t *img_data) +void draw_wall(t_ray *ray, const int line_height, u_int32_t *img_data) { - u_int32_t color; - u_int32_t *texture_data; - int texx; - int texy; + u_int32_t color; + u_int32_t *texture_data; + int texx; + int texy; + const t_texture texture = g_map.textures[ray->texdir]; - texy = ((y - (-line_height / 2 + SCREEN_HEIGHT / 2)) \ - * tex->tex_height) / line_height; - texx = (int)(ray->wallx * (double)tex->tex_width); - if (ray->side == 0 && ray->dir.x > 0) - texx = tex->tex_width - texx - 1; - if (ray->side == 1 && ray->dir.y < 0) - texx = tex->tex_height - texx - 1; - texture_data = (u_int32_t *)mlx_get_data_addr(tex->textures[tex->tex_dir], - &tex->bpp, &tex->size_line, &tex->endian); - color = texture_data[texx * tex->tex_width + texy]; - img_data[y * SCREEN_WIDTH + x] = color; + texy = ((ray->y - (-line_height / 2 + SCREEN_HEIGHT / 2)) + * texture.height) / line_height; + texx = (int)(ray->wallx * (double)texture.width); + texture_data = get_data_addr(texture.image); + color = texture_data[texy * texture.width + texx]; + img_data[ray->y * SCREEN_WIDTH + ray->x] = color; } diff --git a/src/render_utils.h b/src/render_utils.h index f3d8444..a0a055e 100644 --- a/src/render_utils.h +++ b/src/render_utils.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/24 14:26:22 by grobledo #+# #+# */ -/* Updated: 2024/11/04 13:07:42 by mcolonna ### ########.fr */ +/* Updated: 2024/11/12 17:38:08 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,9 +15,39 @@ # include "render.h" -void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex); +typedef struct s_ray +{ + // Column of pixels currently drawing. + // Define the angle of the projected ray. + int x; + // With x, pixel to draw. + int y; + // Let the plane 1 case in front of the camera, of size FOV: + // point at which the ray projected touches the plane, relative to + // the camera position. + t_point_double dir; + // Transversal distance between two cases horizontally (for x) / + // vertically (for y), following the ray angle. + t_point_double deltadist; + // Direction of the ray, each component is either -1 or +1. + t_point_int step; + // Iterating perpwalldist for both north/south walls and east/west walls. + t_point_double sidedist; + // If true, the texture touched by the ray is facing north or south. + bool side; + // Distance between the wall touched by the ray and the camera plane. + double perpwalldist; + // x position of the point at which the ray touches the wall + // on the wall texture. + // Is in [0, 1[: 0 is the left side, 1 is the right side. + double wallx; + // Direction of the wall that the ray touches. + t_direction texdir; +} t_ray; -void draw_wall(t_tex *tex, t_ray *ray, const int line_height, int x, - int y, u_int32_t *img_data); +// needs ray->x, ->side and ->dir to be defined. +void calculate_texdir_and_wallx(t_ray *ray); + +void draw_wall(t_ray *ray, const int line_height, u_int32_t *img_data); #endif diff --git a/testmaps/good_directions_test.cub b/testmaps/good_directions_test.cub new file mode 100644 index 0000000..e405e17 --- /dev/null +++ b/testmaps/good_directions_test.cub @@ -0,0 +1,13 @@ +F 255,127,0 +C 0,2,67 +EA textures/test/east.xpm +NO textures/test/north.xpm +SO textures/test/south.xpm +WE textures/test/west.xpm + 111 +111110111 +10000N001 +111110111 + 101 + 101 + 111 diff --git a/textures/test/east.xpm b/textures/test/east.xpm new file mode 100644 index 0000000..f2d0762 --- /dev/null +++ b/textures/test/east.xpm @@ -0,0 +1,89 @@ +/* XPM */ +static char *east[] = { +/* columns rows colors chars-per-pixel */ +"79 80 3 1 ", +" c #FFB600", +". c #FFD000", +"X c white", +/* pixels */ +"......................................... ", +"......................................... ", +"......................................... ", +"........................................ ", +"........................................ ", +"...............................XXXXXXXXXXXXXXXXXXXXX ", +"..........................XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ", +"....................XXXXXXXXXXXXX....... XXXXXXXXXXXXXXX ", +"...............XXXXXXXXXXXX............. XXXXXXXXXXXXXXXXX ", +"...........XXXXXXXXXXX.................. XXXXXXXXXX ", +".......XXXXXXXXXX....................... XXX ", +".......XXXXXX........................... XX ", +".......XX............................... XX ", +".......XX............................... XX ", +"......XXX............................... XXX ", +"......XX................................ XXX ", +"......XX................................ XX ", +"......XX................................ XX ", +"......XX................................ XX ", +"......XX................................ XX ", +"......XX................................ XX ", +"......XX................................ XXX ", +"......XX............................... XX ", +"......XX............................... XX ", +".....XXX............................... XX ", +".....XXX....................XXXX....... XXXXXXXXX XXXXX XX ", +".....XX.......XXXXXXXXXXX..XXXXXX......XXXXXXXXXXX XXXXXXXX XX ", +".....XX......XXXXXXXXXXXX.XXXXXXXX....XXXXX XXXXXXXX XX ", +".....XX......XXX..........XXX..XXXX...XXX XXXXXXXX XX ", +".....XX......XX...........XX.....XXX..XX XXXXXXXXXX XX ", +".....XX......XX..........XXX.....XXX..XXX XXXXX XX XX ", +".....XX......XX..........XX.......XX..XXX XX XX ", +".....XX......XX..........XX.......XXX..XX XX XX ", +".....XX......XX..........XX.......XXX..XXX XX XX ", +".....XX......XX.........XXX........XX..XXXX XX XX ", +".....XX......XXXXXXXX...XXX........XX.. XXXX XX XX ", +".....XX......XXXXXXXX...XX.........XX.. XXXX XX XX ", +"....XXX......XX.........XX.........XX.. XXX XX XX ", +"....XXX......XX........XXXXXXXXXXXXXX.. XXX XX XX ", +"....XX.......XX........XXXXXXXXXXXXXX.. XXXX XX XX ", +"....XX.......XX........XX..........XX.. XXX XXX XX ", +"....XX.......XX........XX..........XX.. XXX XX XX ", +"....XX.......XX........XX..........XX.. XXXX XX XX ", +"....XX.......XX........XX..........XX.. XXX XX XX ", +"....XX.......XX........XX..........XX.. XX XX XX ", +"....XX.......XX........XX..........XX. XX XX XX ", +"....XX.......XX........XX..........XX. XX XXX XX ", +"....XX.......XX........XX..........XX. XX XXX XX ", +"....XX.......XX........XX..........XX. XXX XX XXX ", +"....XX.......XX........XX..........XX. XXXX XX XXX ", +"....XX.......XX........XX..........XX. XXXX XX XX ", +"....XX......XXXXXXXX...XX..........XX. XXXXXXXX XX XX ", +"....XX......XXXXXXXX...XX..........XX. XXXXXXX XX ", +"....XX................................ XX ", +"....XX................................ XX ", +"....XX............................... XX ", +"....XX............................... XX ", +"....XX............................... XX ", +"....XX............................... XX ", +"....XX............................... XX ", +"....XX............................... XX ", +"....XX............................... XX ", +"....XX............................... XXX ", +"....XX............................... XX ", +"....XX............................... XX ", +"....XX............................... XX ", +"....XX............................... XXX ", +".....XXX............................. XXXX ", +".....XXXXXXX......................... XXXXX ", +"......XXXXXXXXXXXXXXXXX.............. XXXXXXXXXXXXXXXX ", +"..........XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ", +".....................XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ", +".................................... ", +".................................... ", +".................................... ", +".................................... ", +".................................... ", +".................................... ", +".................................... ", +".................................... " +}; diff --git a/textures/test/north.xpm b/textures/test/north.xpm new file mode 100644 index 0000000..e43acfa --- /dev/null +++ b/textures/test/north.xpm @@ -0,0 +1,99 @@ +/* XPM */ +static char *north[] = { +/* columns rows colors chars-per-pixel */ +"127 90 3 1 ", +" c #003BFF", +". c #006AFF", +"X c white", +/* pixels */ +"............................................................... ", +"............................................................... ", +"............................................................... ", +"............................................................... ", +"............................................................... XXXXXXXXXXXXX ", +"....XX.....................................................XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ", +"....XXX........XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ", +"....XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.. XXXXXXXXXXXXXX ", +"....XXXXXXXXXXXXX............................................. XXXXXXXXXXXX ", +"....XX........................................................ XXXXXXXX ", +"....XX........................................................ XX ", +"....XX........................................................ XX ", +"....XX........................................................ XX ", +"....XX........................................................ XXX ", +"....XX........................................................ XX ", +"....XX........................................................ XX ", +"....XX........................................................ XX ", +"....XX........................................................ XX ", +"....XX........................................................ XX ", +"....XXX....................................................... XXX ", +"....XXX....................................................... XXX ", +".....XX...................................................... XX ", +".....XX...................................................... XX ", +".....XX...................................................... XX ", +".....XX...................................................... XX ", +".....XX...................................................... XXX ", +".....XX...................................................... XXX ", +".....XX...................................................... XX ", +".....XX.....................................XXXX............. XX ", +".....XX...........................XX.......XXXXXX.......XXXXXX XX ", +".....XX...................XX......XX......XXXXXXX...XXXXXXXXXXXX XXXXXX XXX XX XXX ", +".....XX...................XXX.....XX.....XXXXX.XXX..XXXXXX.. XXXX XXXXXXXXXXXXXX XX XX XXX ", +".....XX...................XXXX....XXX...XXXXXX..XX....XXX... XXX XXXXXXXXXXXX XX XX XX ", +".....XX...................XXXX....XXX...XXX.....XX.....XX... XX XX XX XX XX ", +".....XX...................XXXXX....XX...XX......XX.....XX... XX XX XX XX XX ", +".....XX...................XX.XXX...XX..XXX......XXX...XXX... XX XX XX XX XX ", +".....XX...................XX.XXX...XX..XXX.......XX...XXX... XXX XX XXXXXXXX XX XX ", +".....XX...................XX..XXX..XX..XX........XX...XX.XXXXXXX XX XXXXXXXXXXXX XX ", +".....XX...................XX..XXX..XX..XX........XX...XX.XXXXXXX XXX XX XXXXXX XX ", +".....XX...................XX...XXX.XX..XX.......XXX...XX...XXXX XXX XX XXX XX ", +".....XX...................XX...XXX.XX..XXX......XXX...XX....XXXX XX XX XXX XX ", +".....XX...................XXX...XXXXX...XX.....XXX....XX... XXXX XXX XX XX XXX ", +".....XX...................XXX...XXXXX...XXX...XXXX....XX... XXX XXX XX XX XXX ", +".....XX....................XX....XXXX...XXXXXXXXX.....XX... XX XX XX XX ", +".....XX....................XX....XXXX....XXXXXXX......XX... XX XX ", +".....XX.................................................... XX ", +".....XX.................................................... XX ", +".....XX.................................................... XX ", +".....XX.................................................... XX ", +".....XX.................................................... XX ", +".....XX................................................... XX ", +".....XX................................................... XX ", +".....XXX.................................................. XX ", +".....XXX.................................................. XX ", +"......XX.................................................. XX ", +"......XX.................................................. XX ", +"......XX.................................................. XX ", +"......XX.................................................. XX ", +"......XXXX............................................... XX ", +"......XXXX............................................... XX ", +"......XXXX............................................... XXX ", +"......XXXX............................................... XXX ", +"......XXXX............................................... XX ", +".......XXX............................................... XX ", +".......XX................................................ XX ", +".......XX................................................ XX ", +".......XX................................................ XX ", +".......XX............................................... XX ", +".......XXX.............................................. XX ", +".......XXX.............................................. XX ", +"........XX.............................................. XX ", +"........XX.............................................. XX ", +"........XX.............................................. XX ", +"........XX.............................................. XX ", +"........XXXX............................................ XX ", +"........XXXXXXXX........................................ XX ", +"..........XXXXXXXXX..................................... XX ", +"...............XXXXXX................................... XX ", +".................XXXXXXX................................ XXXXXXX ", +"...................XXXXXXXXX............................ XXXXXXXXXXXXX ", +"......................XXXXXXXXXXX....................... XXXXXXXXXXXXXXX ", +"..........................XXXXXXXXXXXXXX................ XXXXXXXXXXXXXXXXXXX ", +"...............................XXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX ", +"......................................XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ", +"........................................................XXXXXXXXXXXXXXXXXXXXXX ", +"........................................................ ", +"........................................................ ", +"........................................................ ", +"........................................................ ", +"........................................................ " +}; diff --git a/textures/test/south.xpm b/textures/test/south.xpm new file mode 100644 index 0000000..445a39d --- /dev/null +++ b/textures/test/south.xpm @@ -0,0 +1,88 @@ +/* XPM */ +static char *south[] = { +/* columns rows colors chars-per-pixel */ +"121 79 3 1 ", +" c #DD0E00", +". c #FF3B00", +"X c white", +/* pixels */ +"............................................................... ", +"............................................................... ", +"............................................................... ", +"............................................................... ", +"............................................................... ", +".................................XXXXXXXXXXXXXXXXXXXXXXXXXXXXX. ", +"..........XXXX.......XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ", +"..........XXXXXXXXXXXXXXXXXXXXXXXXX.........................XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ", +"..........XXXXXXXXXXXX......................................... XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ", +"..........XXX.................................................. XXXXXXXXXXXXXXXXXXXX ", +"..........XXX.................................................. XXXXXXXXXXX ", +"...........XX.................................................. XXX ", +"...........XX.................................................. XX ", +"..........XXX.................................................. XX ", +"..........XXX.................................................. XX ", +"..........XX................................................... XX ", +"..........XX.................................................. XX ", +"..........XX.................................................. XX ", +"..........XX.................................................. XX ", +"..........XX.................................................. XX ", +"..........XX.................................................. XX ", +"..........XX.................................................. XX ", +"..........XX.................................................. XX ", +"..........XX.................................................. XX ", +"..........XX.................................................. XX ", +"..........XX.................................................. XX ", +"..........XX..................XXXX............................ XX ", +".........XXX................XXXXXXX....................XX..... XX XX ", +".........XXX..............XXXXXX.XX......XX..XX........XX..... XX XX XX XX ", +".........XX...............XXXX..........XXX..XXXX......XX..... XX XXXXXXXX XX XX XX ", +".........XX..............XXX...........XXXX..XXXXX.....XX..... XX XXXXXXXXXXXXXX XX XX XX ", +".........XX..............XXX...........XXX.....XXXX....XX..... XXX XXXXXXXXX XX XX XX ", +".........XX..............XX...........XXX.......XXXX...XX..... XXX XXXXX XX XX XX ", +".........XX..............XX...........XXX.........XXX.XXX..... XX XXXX XXX XX XX ", +".........XX..............XXX..........XX...........XX.XX...... XX XXX XXX XX XX ", +".........XX..............XXXX........XXX...........XXXXX...... XX XXX XX XX XX ", +".........XX...............XXXXX......XX.............XXXX...... XX XX XX XXXX XX ", +".........XX................XXXXX.....XX.............XXXX...... XX XXX XXXXXXXXXXXXXX XX ", +".........XX..................XXXXX...XX.............XXXX...... XX XXX XXXXXXXXXXXXX XX ", +".........XX....................XXXX..XX.............XXXX...... XX XX XX XX XX ", +".........XX.....................XXXX.XX.............XXXX...... XXX XX XX XX XX ", +".........XX......................XXX.XX.............XXXXX..... XXX XX XX XX XX ", +".........XX.......................XX.XX.............XXXXX..... XX XX XX XX XX ", +".........XX.......................XX.XX............XXX.XXX....XXX XX XXX XX XX ", +".........XX.......................XX.XXX...........XX..XXX...XXXX XX XXX XX XX ", +".........XX.....................XXXX.XXX..........XXX...XXXXXXXX XX XX XXX XX ", +".........XX....................XXXX...XXX.........XXX....XXXXXX XX XX XXX XX ", +".........XX..................XXXXX....XXXX.......XXX......XXXX XX XX ", +".........XX.............XXXXXXXXX......XXXX.....XXXX.......... XX XX ", +".........XX.............XXXXXXX.........XXXXXXXXXXX........... XX XX ", +".........XX..............................XXXXXXXX............. XX ", +".........XX................................................... XXX ", +".........XX................................................... XX ", +".........XX................................................... XX ", +".........XX................................................... XX ", +".........XX................................................... XX ", +".........XX................................................... XX ", +".........XX................................................... XX ", +".........XX................................................... XX ", +".........XX................................................... XX ", +".........XX................................................... XX ", +".........XX................................................... XX ", +".........XX................................................... XX ", +".........XX................................................... XX ", +".........XX................................................... XX ", +".........XX................................................... XX ", +".........XX................................................... XXX ", +".........XX................................................... XXX ", +".......XXXX....................XXXXXXXX....................... XX ", +".......XXXX...XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XX ", +".......XXXXXXXXXXXXXXXXXXXXXXXXXX.....XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX ", +"........XXXXXXXX............................................. XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXX ", +"............................................................. XXXXXXXXXXXXXXXXXXXXXXXXXXXX ", +"............................................................. XXXXXXX ", +"............................................................. ", +"............................................................. ", +"............................................................. ", +"............................................................. ", +"............................................................. " +}; diff --git a/textures/test/west.xpm b/textures/test/west.xpm new file mode 100644 index 0000000..1ebae09 --- /dev/null +++ b/textures/test/west.xpm @@ -0,0 +1,73 @@ +/* XPM */ +static char *west[] = { +/* columns rows colors chars-per-pixel */ +"117 64 3 1 ", +" c #38E200", +". c #3CF300", +"X c white", +/* pixels */ +"...................................................... ", +"....................................................... ", +"....................................................... ", +"....................................................... ", +"....................................................... ", +"....................................................... ", +"....................................................... ", +"....................................................... ", +"....................................................... ", +"....................................................... ", +"............XXXX....................................... ", +"............XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.......... XXXXXXXXXXXXXXXXXXXXXXXXX ", +"............XX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ", +"............XX.............................XXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX ", +"............XX......................................... XX ", +"............XX......................................... XX ", +"............XX......................................... XX ", +"............XX......................................... XXX ", +"............XX......................................... XX ", +"............XX......................................... XX ", +"............XX......................................... XX ", +"............XX......................................... XX ", +"............XX......................................... XX ", +"............XX......................................... XX ", +"............XX......................................... XX ", +"............XX......................................... XX ", +"............XX..............XXX.............XX.....XXXXXX XXXXXXX XXXXXX XX ", +"............XX..............XXX....XX.......XX...XXXXXXXX XXXXXXXXXX XXXXXXXXXXXX XX ", +"............XX..............XX.....XXX......XX..XXXX... XXXX XXXXXXX XXXXXX XX ", +"............XX..............XX.....XXX......XXX.XXX.... XX XXX XX XXX XX ", +"............XX..............XX.....XXX......XXX.XX..... XXXX XXX XX ", +"............XX..............XX.....XXX.......XX.XXX.... XXXXX XX XX ", +"............XX..............XX......XX......XXX..XXXX.. XXXXX XX XX ", +"............XX..............XX......XX......XXX..XXXXXXXXX XXXXX XXX XX ", +"............XX..............XX.....XXX......XX...XXXXXXXXX XXXX XX XX ", +"............XX..............XXX....XXXX....XXX..XXX.... XXX XXX XX ", +"............XX..............XXXX..XXXXXX..XXXX..XX..... XXX XXX XX ", +"............XX...............XXXXXXXXXXXXXXXX...XX..... XX XXX XX XX ", +"............XX................XXXXXX..XXXXXX....XXX...XXXXX XXXXXXXXXXX XX XX ", +"............XX..................XXX....XXXX.....XXXXXXXXXXX XXXXXXXXX XX XX ", +"............XX....................................XXXXXX XX ", +"............XX......................................... XX ", +"............XX......................................... XX ", +"............XX......................................... XX ", +"............XX.......................................... XX ", +"............XXX......................................... XX ", +"............XXX......................................... XX ", +".............XX......................................... XX ", +".............XX......................................... XX ", +".............XX......................................... XX ", +".............XX......................................... XX ", +".............XX......................................... XXX ", +".............XX..................................XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ", +".............XXXXXX..XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ", +".............XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX..... ", +".................XXXXXX................................. ", +"........................................................ ", +"........................................................ ", +"........................................................ ", +"........................................................ ", +"........................................................ ", +"........................................................ ", +"........................................................ ", +"........................................................ " +}; From a09cf69412ef284e6bc33ce3e3e5faed0e8683dc Mon Sep 17 00:00:00 2001 From: Zy Date: Wed, 13 Nov 2024 18:33:41 +0100 Subject: [PATCH 58/80] misc: optimize render --- src/render.c | 17 ++--------------- src/render_utils.c | 28 ++++++++++++++++++++-------- src/render_utils.h | 7 ++++--- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/render.c b/src/render.c index 0ae21df..945c40d 100644 --- a/src/render.c +++ b/src/render.c @@ -6,7 +6,7 @@ /* By: Zy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/11/13 17:53:57 by Zy ### ########.fr */ +/* Updated: 2024/11/13 18:33:00 by Zy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -104,21 +104,8 @@ static void draw_vertical_line(u_int32_t *img_data, t_ray *ray) calculate_texdir_and_wallx(ray); line_height = (int)(SCREEN_WIDTH / FOV / 2 / ray->perpwalldist); draw_start = -line_height / 2 + SCREEN_HEIGHT / 2; - if (draw_start < 0) - draw_start = 0; draw_end = line_height / 2 + SCREEN_HEIGHT / 2; - if (draw_end >= SCREEN_HEIGHT) - draw_end = SCREEN_HEIGHT - 1; - ray->y = 0; - while (ray->y++ < SCREEN_HEIGHT) - { - if (ray->y < draw_start) - img_data[ray->y * SCREEN_WIDTH + ray->x] = g_map.color_ceiling; - else if (ray->y < draw_end) - draw_wall(ray, line_height, img_data); - else - img_data[ray->y * SCREEN_WIDTH + ray->x] = g_map.color_floor; - } + draw_vertical_line_end(ray, draw_start, draw_end, img_data); } int render(u_int32_t *img_data) diff --git a/src/render_utils.c b/src/render_utils.c index 6cfd96c..f93e2f9 100644 --- a/src/render_utils.c +++ b/src/render_utils.c @@ -6,7 +6,7 @@ /* By: Zy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/24 14:26:22 by grobledo #+# #+# */ -/* Updated: 2024/11/13 18:11:14 by Zy ### ########.fr */ +/* Updated: 2024/11/13 18:31:15 by Zy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,7 +36,8 @@ void calculate_texdir_and_wallx(t_ray *ray) ray->wallx -= floor((ray->wallx)); } -void draw_wall(t_ray *ray, const int line_height, u_int32_t *img_data) +void draw_vertical_line_end(t_ray *ray, int draw_start, int draw_end, + u_int32_t *img_data) { u_int32_t color; u_int32_t *texture_data; @@ -44,10 +45,21 @@ void draw_wall(t_ray *ray, const int line_height, u_int32_t *img_data) int texy; const t_texture texture = g_map.textures[ray->texdir]; - texy = ((ray->y - (-line_height / 2 + SCREEN_HEIGHT / 2)) - * texture.height) / line_height; - texx = (int)(ray->wallx * (double)texture.width); - texture_data = get_data_addr(texture.image); - color = texture_data[texy * texture.width + texx]; - img_data[ray->y * SCREEN_WIDTH + ray->x] = color; + ray->y = 0; + while (ray->y++ < SCREEN_HEIGHT) + { + if (ray->y < draw_start) + img_data[ray->y * SCREEN_WIDTH + ray->x] = g_map.color_ceiling; + else if (ray->y < draw_end) + { + texy = ((ray->y - ((draw_start - draw_end) / 2 + SCREEN_HEIGHT / 2)) + * texture.height) / (draw_end - draw_start); + texx = (int)(ray->wallx * (double)texture.width); + texture_data = get_data_addr(texture.image); + color = texture_data[texy * texture.width + texx]; + img_data[ray->y * SCREEN_WIDTH + ray->x] = color; + } + else + img_data[ray->y * SCREEN_WIDTH + ray->x] = g_map.color_floor; + } } diff --git a/src/render_utils.h b/src/render_utils.h index a0a055e..a10f359 100644 --- a/src/render_utils.h +++ b/src/render_utils.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* render_utils.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: Zy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/24 14:26:22 by grobledo #+# #+# */ -/* Updated: 2024/11/12 17:38:08 by mcolonna ### ########.fr */ +/* Updated: 2024/11/13 18:31:28 by Zy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,6 +48,7 @@ typedef struct s_ray // needs ray->x, ->side and ->dir to be defined. void calculate_texdir_and_wallx(t_ray *ray); -void draw_wall(t_ray *ray, const int line_height, u_int32_t *img_data); +void draw_vertical_line_end(t_ray *ray, int draw_start, int draw_end, + u_int32_t *img_data); #endif From f0680246a67f2de573b7f942b0134b0b3a63bee4 Mon Sep 17 00:00:00 2001 From: Zy Date: Wed, 13 Nov 2024 18:40:29 +0100 Subject: [PATCH 59/80] dev: clean TODOs --- dev/TODO | 2 -- include/const.h | 2 +- include/utils.h | 3 +-- src/move.c | 6 ++---- 4 files changed, 4 insertions(+), 9 deletions(-) delete mode 100644 dev/TODO diff --git a/dev/TODO b/dev/TODO deleted file mode 100644 index 0cc1dcf..0000000 --- a/dev/TODO +++ /dev/null @@ -1,2 +0,0 @@ -TODO replace all mlx_get_data_addr by util which check the image format -TODO different texture dimensions diff --git a/include/const.h b/include/const.h index 151cfe2..5f798b6 100644 --- a/include/const.h +++ b/include/const.h @@ -25,6 +25,6 @@ # define SCREEN_WIDTH 640 // Width of the window # define SCREEN_HEIGHT 480 // Height of the window -# define FOV 0.66 // ? TODO no idea +# define FOV 0.66 // Width of the view plane (unit: cases) #endif diff --git a/include/utils.h b/include/utils.h index a8c5c66..28214c0 100644 --- a/include/utils.h +++ b/include/utils.h @@ -29,8 +29,7 @@ typedef struct s_point_int int y; } t_point_int; -// TODO Must the transparency be 0 or 255? -/// @brief Represents an TRGB color in 0xTTRRGGBB format. +/// @brief Represents an TRGB color in 0xTTRRGGBB format. TT is 0x00 if opaque typedef __u32 t_color; /// @brief Convert a color from each color value to a t_color. diff --git a/src/move.c b/src/move.c index e977685..5937aa9 100644 --- a/src/move.c +++ b/src/move.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* move.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: Zy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:47:34 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 17:09:31 by mc ### ########.fr */ +/* Updated: 2024/11/13 18:39:22 by Zy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,8 +70,6 @@ static int rotate(int factor) return (0); } -// TODO leaks when quit? - void move(void) { if (g_input_actions.up && !g_input_actions.down) From e7fc155581c6234508c7641603ebf975977bdbcf Mon Sep 17 00:00:00 2001 From: mcolonna Date: Wed, 13 Nov 2024 21:47:04 +0100 Subject: [PATCH 60/80] fix: collisions on corners --- src/move.c | 40 ++------------------------ src/move_utils.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ src/move_utils.h | 18 ++++++++++++ 3 files changed, 94 insertions(+), 37 deletions(-) create mode 100644 src/move_utils.c create mode 100644 src/move_utils.h diff --git a/src/move.c b/src/move.c index 5937aa9..b9888d5 100644 --- a/src/move.c +++ b/src/move.c @@ -3,14 +3,15 @@ /* ::: :::::::: */ /* move.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: Zy +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:47:34 by mcolonna #+# #+# */ -/* Updated: 2024/11/13 18:39:22 by Zy ### ########.fr */ +/* Updated: 2024/11/13 21:42:40 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "move.h" +#include "move_utils.h" #include "utils.h" #include "map.h" @@ -18,41 +19,6 @@ #include "const.h" #include "input.h" -static void push_from_wall(t_point_int c) -{ - if (map_get_case(&g_map, c.x, c.y)->wall == EMPTY) - return ; - if (g_map.player.pos.x < c.x + 1 + HITBOX && g_map.player.pos.x > c.x + 1) - g_map.player.pos.x = c.x + 1 + HITBOX; - if (g_map.player.pos.x > c.x - HITBOX && g_map.player.pos.x < c.x) - g_map.player.pos.x = c.x - HITBOX; - if (g_map.player.pos.y < c.y + 1 + HITBOX && g_map.player.pos.y > c.y + 1) - g_map.player.pos.y = c.y + 1 + HITBOX; - if (g_map.player.pos.y > c.y - HITBOX && g_map.player.pos.y < c.y) - g_map.player.pos.y = c.y - HITBOX; -} - -static void push_from_walls(void) -{ - t_point_int c; - t_point_int p; - - p.x = g_map.player.pos.x; - p.y = g_map.player.pos.y; - c.x = p.x - 1; - c.y = p.y; - push_from_wall(c); - c.x = p.x + 1; - c.y = p.y; - push_from_wall(c); - c.x = p.x; - c.y = p.y - 1; - push_from_wall(c); - c.x = p.x; - c.y = p.y + 1; - push_from_wall(c); -} - static int move_forward(int factor) { t_point_double dir; diff --git a/src/move_utils.c b/src/move_utils.c new file mode 100644 index 0000000..1a5917d --- /dev/null +++ b/src/move_utils.c @@ -0,0 +1,73 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* move_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/13 21:42:57 by mc #+# #+# */ +/* Updated: 2024/11/13 21:46:49 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "move_utils.h" + +#include "utils.h" +#include "map.h" +#include "global.h" +#include "const.h" + +static void move_in_direction(t_point_double *pos, t_direction dir, + double value) +{ + if (dir == NORTH) + pos->y -= value; + else if (dir == SOUTH) + pos->y += value; + else if (dir == EAST) + pos->x -= value; + else if (dir == WEST) + pos->x += value; +} + +static void push_from_wall(int cx, int cy) +{ + const t_point_double p = g_map.player.pos; + double distance_with_side[4]; + t_direction d; + t_direction d_min; + const t_point_double c_d = {cx, cy}; + + if (map_get_case(&g_map, cx, cy)->wall == EMPTY) + return ; + if (p.x > c_d.x - HITBOX && p.x < c_d.x + 1 + HITBOX + && p.y > c_d.y - HITBOX && p.y < c_d.y + 1 + HITBOX) + { + distance_with_side[NORTH] = p.y - (c_d.y - HITBOX); + distance_with_side[SOUTH] = (c_d.y + 1 + HITBOX) - p.y; + distance_with_side[EAST] = p.x - (c_d.x - HITBOX); + distance_with_side[WEST] = (c_d.x + 1 + HITBOX) - p.x; + d_min = 0; + d = 0; + while (++d < 4) + if (distance_with_side[d] < distance_with_side[d_min]) + d_min = d; + move_in_direction(&g_map.player.pos, d_min, distance_with_side[d_min]); + } +} + +void push_from_walls(void) +{ + t_point_int p; + + p.x = (int)g_map.player.pos.x; + p.y = (int)g_map.player.pos.y; + push_from_wall(p.x - 1, p.y); + push_from_wall(p.x + 1, p.y); + push_from_wall(p.x, p.y - 1); + push_from_wall(p.x, p.y + 1); + push_from_wall(p.x - 1, p.y - 1); + push_from_wall(p.x - 1, p.y + 1); + push_from_wall(p.x + 1, p.y - 1); + push_from_wall(p.x + 1, p.y + 1); +} diff --git a/src/move_utils.h b/src/move_utils.h new file mode 100644 index 0000000..48f2b5f --- /dev/null +++ b/src/move_utils.h @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* move_utils.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/13 21:43:25 by mc #+# #+# */ +/* Updated: 2024/11/13 21:43:51 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MOVE_UTILS_H +# define MOVE_UTILS_H + +void push_from_walls(void); + +#endif From 96cc9096cd4056a08336b072420b74fb512cdeeb Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 14 Nov 2024 13:32:31 +0100 Subject: [PATCH 61/80] dev: fix all 42 headers with the good names&emails --- include/const.h | 4 ++-- include/global.h | 6 +++--- include/include.h | 4 ++-- include/input.h | 4 ++-- include/main.h | 6 +++--- include/map.h | 2 +- include/move.h | 6 +++--- include/player.h | 4 ++-- include/render.h | 4 ++-- include/stream.h | 4 ++-- include/utils.h | 2 +- src/global.c | 4 ++-- src/input.c | 4 ++-- src/input_utils.c | 6 +++--- src/input_utils.h | 6 +++--- src/main.c | 6 +++--- src/map1.c | 4 ++-- src/map2.c | 4 ++-- src/map_utils.h | 6 +++--- src/map_utils1.c | 6 +++--- src/map_utils2.c | 4 ++-- src/move.c | 4 ++-- src/move_utils.c | 6 +++--- src/move_utils.h | 6 +++--- src/player.c | 4 ++-- src/render.c | 6 +++--- src/render_utils.c | 4 ++-- src/render_utils.h | 4 ++-- src/stream.c | 4 ++-- src/utils.c | 4 ++-- src/utils2.c | 4 ++-- src/utils3.c | 4 ++-- 32 files changed, 73 insertions(+), 73 deletions(-) diff --git a/include/const.h b/include/const.h index 5f798b6..c9fec1a 100644 --- a/include/const.h +++ b/include/const.h @@ -3,9 +3,9 @@ /* ::: :::::::: */ /* const.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/31 17:00:59 by mc #+# #+# */ +/* Created: 2024/10/31 17:00:59 by mcolonna #+# #+# */ /* Updated: 2024/11/12 17:56:05 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/include/global.h b/include/global.h index 2c75fd7..cbc36fb 100644 --- a/include/global.h +++ b/include/global.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* global.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/31 17:06:31 by mc #+# #+# */ -/* Updated: 2024/10/31 18:11:08 by mc ### ########.fr */ +/* Created: 2024/10/31 17:06:31 by mcolonna #+# #+# */ +/* Updated: 2024/10/31 18:11:08 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/include/include.h b/include/include.h index 188bf43..5e903b3 100644 --- a/include/include.h +++ b/include/include.h @@ -3,9 +3,9 @@ /* ::: :::::::: */ /* include.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/31 16:22:09 by mc #+# #+# */ +/* Created: 2024/10/31 16:22:09 by mcolonna #+# #+# */ /* Updated: 2024/11/12 17:41:11 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/include/input.h b/include/input.h index 76da466..8d7e3a8 100644 --- a/include/input.h +++ b/include/input.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* input.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:09 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 19:03:25 by mc ### ########.fr */ +/* Updated: 2024/11/07 19:03:25 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/include/main.h b/include/main.h index 0d413ad..179c2d8 100644 --- a/include/main.h +++ b/include/main.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* main.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/31 17:19:59 by mc #+# #+# */ -/* Updated: 2024/10/31 17:55:11 by mc ### ########.fr */ +/* Created: 2024/10/31 17:19:59 by mcolonna #+# #+# */ +/* Updated: 2024/10/31 17:55:11 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/include/map.h b/include/map.h index b63873b..370075a 100644 --- a/include/map.h +++ b/include/map.h @@ -3,7 +3,7 @@ /* ::: :::::::: */ /* map.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */ /* Updated: 2024/11/12 15:10:07 by mcolonna ### ########.fr */ diff --git a/include/move.h b/include/move.h index e5326d8..9b1bbb4 100644 --- a/include/move.h +++ b/include/move.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* move.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/31 16:59:27 by mc #+# #+# */ -/* Updated: 2024/11/01 21:05:51 by mc ### ########.fr */ +/* Created: 2024/10/31 16:59:27 by mcolonna #+# #+# */ +/* Updated: 2024/11/01 21:05:51 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/include/player.h b/include/player.h index 2795edf..ad06e08 100644 --- a/include/player.h +++ b/include/player.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* player.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 17:31:35 by mcolonna #+# #+# */ -/* Updated: 2024/11/01 20:41:30 by mc ### ########.fr */ +/* Updated: 2024/11/01 20:41:30 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/include/render.h b/include/render.h index da4d780..7c07161 100644 --- a/include/render.h +++ b/include/render.h @@ -3,9 +3,9 @@ /* ::: :::::::: */ /* render.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/31 17:13:20 by mc #+# #+# */ +/* Created: 2024/10/31 17:13:20 by mcolonna #+# #+# */ /* Updated: 2024/11/12 12:24:02 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/include/stream.h b/include/stream.h index 8374b16..bcbe855 100644 --- a/include/stream.h +++ b/include/stream.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* stream.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/02 12:33:25 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 16:25:10 by mc ### ########.fr */ +/* Updated: 2024/10/31 16:25:10 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/include/utils.h b/include/utils.h index 28214c0..ecc5f06 100644 --- a/include/utils.h +++ b/include/utils.h @@ -3,7 +3,7 @@ /* ::: :::::::: */ /* utils.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 16:56:47 by mcolonna #+# #+# */ /* Updated: 2024/11/12 17:01:35 by mcolonna ### ########.fr */ diff --git a/src/global.c b/src/global.c index 710298b..ff4138a 100644 --- a/src/global.c +++ b/src/global.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* global.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/11/01 20:56:43 by mc ### ########.fr */ +/* Updated: 2024/11/01 20:56:43 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/input.c b/src/input.c index bebde7b..3e2a1d1 100644 --- a/src/input.c +++ b/src/input.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* input.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:36 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 19:03:15 by mc ### ########.fr */ +/* Updated: 2024/11/07 19:03:15 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/input_utils.c b/src/input_utils.c index 59ebd65..1aff5af 100644 --- a/src/input_utils.c +++ b/src/input_utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* input_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/11/07 19:02:04 by mc #+# #+# */ -/* Updated: 2024/11/07 19:24:05 by mc ### ########.fr */ +/* Created: 2024/11/07 19:02:04 by mcolonna #+# #+# */ +/* Updated: 2024/11/07 19:24:05 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/input_utils.h b/src/input_utils.h index 1abf508..6e4b216 100644 --- a/src/input_utils.h +++ b/src/input_utils.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* input_utils.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/11/07 19:02:26 by mc #+# #+# */ -/* Updated: 2024/11/07 19:22:55 by mc ### ########.fr */ +/* Created: 2024/11/07 19:02:26 by mcolonna #+# #+# */ +/* Updated: 2024/11/07 19:22:55 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/main.c b/src/main.c index ebc393e..ca96b89 100644 --- a/src/main.c +++ b/src/main.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/31 16:57:40 by mc #+# #+# */ -/* Updated: 2024/11/07 18:44:01 by mc ### ########.fr */ +/* Created: 2024/10/31 16:57:40 by mcolonna #+# #+# */ +/* Updated: 2024/11/07 18:44:01 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/map1.c b/src/map1.c index ce75afc..55f3d02 100644 --- a/src/map1.c +++ b/src/map1.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* map1.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 17:12:58 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 18:58:34 by mc ### ########.fr */ +/* Updated: 2024/11/07 18:58:34 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/map2.c b/src/map2.c index c40818a..5e71fb7 100644 --- a/src/map2.c +++ b/src/map2.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* map2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 17:12:58 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 17:51:49 by mc ### ########.fr */ +/* Updated: 2024/10/31 17:51:49 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/map_utils.h b/src/map_utils.h index 15a3713..dd000d3 100644 --- a/src/map_utils.h +++ b/src/map_utils.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* map_utils.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/03 15:05:13 by mc #+# #+# */ -/* Updated: 2024/11/07 19:04:19 by mc ### ########.fr */ +/* Created: 2024/10/03 15:05:13 by mcolonna #+# #+# */ +/* Updated: 2024/11/07 19:04:19 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/map_utils1.c b/src/map_utils1.c index 728d2c5..fcb9c2f 100644 --- a/src/map_utils1.c +++ b/src/map_utils1.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* map_utils1.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/03 15:02:09 by mc #+# #+# */ -/* Updated: 2024/11/07 18:59:07 by mc ### ########.fr */ +/* Created: 2024/10/03 15:02:09 by mcolonna #+# #+# */ +/* Updated: 2024/11/07 18:59:07 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/map_utils2.c b/src/map_utils2.c index 3f55963..e2cc612 100644 --- a/src/map_utils2.c +++ b/src/map_utils2.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* map_utils2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/04 15:12:08 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 19:05:06 by mc ### ########.fr */ +/* Updated: 2024/11/07 19:05:06 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/move.c b/src/move.c index b9888d5..e1d7eba 100644 --- a/src/move.c +++ b/src/move.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* move.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:47:34 by mcolonna #+# #+# */ -/* Updated: 2024/11/13 21:42:40 by mc ### ########.fr */ +/* Updated: 2024/11/13 21:42:40 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/move_utils.c b/src/move_utils.c index 1a5917d..695aac6 100644 --- a/src/move_utils.c +++ b/src/move_utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* move_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/11/13 21:42:57 by mc #+# #+# */ -/* Updated: 2024/11/13 21:46:49 by mc ### ########.fr */ +/* Created: 2024/11/13 21:42:57 by mcolonna #+# #+# */ +/* Updated: 2024/11/13 21:46:49 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/move_utils.h b/src/move_utils.h index 48f2b5f..f7f69f6 100644 --- a/src/move_utils.h +++ b/src/move_utils.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* move_utils.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/11/13 21:43:25 by mc #+# #+# */ -/* Updated: 2024/11/13 21:43:51 by mc ### ########.fr */ +/* Created: 2024/11/13 21:43:25 by mcolonna #+# #+# */ +/* Updated: 2024/11/13 21:43:51 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/player.c b/src/player.c index c1fc4cb..02ae593 100644 --- a/src/player.c +++ b/src/player.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* player.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 17:33:11 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 17:59:13 by mc ### ########.fr */ +/* Updated: 2024/10/31 17:59:13 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/render.c b/src/render.c index 945c40d..d5c88e5 100644 --- a/src/render.c +++ b/src/render.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* render.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: Zy +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/11/13 18:33:00 by Zy ### ########.fr */ +/* Created: 2024/10/14 14:55:05 by grobledo #+# #+# */ +/* Updated: 2024/11/13 18:33:00 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/render_utils.c b/src/render_utils.c index f93e2f9..d006c6f 100644 --- a/src/render_utils.c +++ b/src/render_utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* render_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: Zy +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/24 14:26:22 by grobledo #+# #+# */ -/* Updated: 2024/11/13 18:31:15 by Zy ### ########.fr */ +/* Updated: 2024/11/13 18:31:15 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/render_utils.h b/src/render_utils.h index a10f359..982efba 100644 --- a/src/render_utils.h +++ b/src/render_utils.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* render_utils.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: Zy +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/24 14:26:22 by grobledo #+# #+# */ -/* Updated: 2024/11/13 18:31:28 by Zy ### ########.fr */ +/* Updated: 2024/11/13 18:31:28 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/stream.c b/src/stream.c index c58e24c..d1506b8 100644 --- a/src/stream.c +++ b/src/stream.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* stream.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/02 14:08:10 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 17:25:23 by mc ### ########.fr */ +/* Updated: 2024/10/31 17:25:23 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/utils.c b/src/utils.c index 724b4cd..d9b6787 100644 --- a/src/utils.c +++ b/src/utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:38:40 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 00:05:39 by mc ### ########.fr */ +/* Updated: 2024/11/07 00:05:39 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/utils2.c b/src/utils2.c index bf686a5..960ef72 100644 --- a/src/utils2.c +++ b/src/utils2.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* utils2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/29 14:02:37 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 18:44:16 by mc ### ########.fr */ +/* Updated: 2024/11/07 18:44:16 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/utils3.c b/src/utils3.c index d6dbe30..b58040f 100644 --- a/src/utils3.c +++ b/src/utils3.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* utils3.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/02 16:18:35 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 17:25:53 by mc ### ########.fr */ +/* Updated: 2024/10/31 17:25:53 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ From 57b099d013d5790183e40c8c885c0ea6eb24c9f3 Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Fri, 15 Nov 2024 15:39:12 +0100 Subject: [PATCH 62/80] added minimap --- include/const.h | 5 +-- include/map.h | 8 +++-- src/main.c | 7 ++-- src/minimap.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++ src/render.c | 5 +-- 5 files changed, 110 insertions(+), 8 deletions(-) create mode 100644 src/minimap.c diff --git a/include/const.h b/include/const.h index c9fec1a..569cb65 100644 --- a/include/const.h +++ b/include/const.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* const.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 17:00:59 by mcolonna #+# #+# */ -/* Updated: 2024/11/12 17:56:05 by mcolonna ### ########.fr */ +/* Updated: 2024/11/15 14:58:24 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,4 +27,5 @@ # define FOV 0.66 // Width of the view plane (unit: cases) +# define MINIMAP_SCALE 8 #endif diff --git a/include/map.h b/include/map.h index 370075a..9bcddf3 100644 --- a/include/map.h +++ b/include/map.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* map.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */ -/* Updated: 2024/11/12 15:10:07 by mcolonna ### ########.fr */ +/* Updated: 2024/11/15 14:56:55 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -157,4 +157,8 @@ bool check_map(const t_map *map); /// @return Wanted case. const t_map_case *map_get_case(const t_map *map, int x, int y); +void create_minimap(u_int32_t *img_data); +void draw_minimap(uint32_t *img_data, int map_x, int map_y); +void minimap_player(u_int32_t *img_data); + #endif diff --git a/src/main.c b/src/main.c index ca96b89..57b9f21 100644 --- a/src/main.c +++ b/src/main.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 16:57:40 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 18:44:01 by mcolonna ### ########.fr */ +/* Updated: 2024/11/15 12:47:03 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -79,3 +79,6 @@ int main(int argc, char *argv[]) free(g_mlx); return (g_return_value); } + + + diff --git a/src/minimap.c b/src/minimap.c new file mode 100644 index 0000000..bfaeaf1 --- /dev/null +++ b/src/minimap.c @@ -0,0 +1,93 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* minimap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/15 11:41:15 by grobledo #+# #+# */ +/* Updated: 2024/11/15 15:10:06 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../include/global.h" +#include "../include/const.h" + +// g_map.width +// g_map.height +// g_map.player.pos.x +// g_map.player.pos.y +// g_map.cases[y * g_map.width + x].wall == WALL / EMPTY + +void create_minimap(u_int32_t *img_data) +{ + unsigned int map_x; + unsigned int map_y; + + map_x = 0; + map_y = 0; + + while (map_y < g_map.width) + { + map_x = 0; + while (map_x < g_map.height) + { + draw_minimap(img_data, map_x, map_y); + map_x++; + } + map_y++; + } + minimap_player(img_data); +} + +void draw_minimap(uint32_t *img_data, int map_y, int map_x) +{ + int pixel_x; + int pixel_y; + int i; + int j; + + i = 0; + + while (i++ < MINIMAP_SCALE) + { + j = 0; + while (j++ < MINIMAP_SCALE) + { + pixel_y = map_y * MINIMAP_SCALE + j; + pixel_x = map_x * MINIMAP_SCALE + i; + if (pixel_x < SCREEN_WIDTH && pixel_y < SCREEN_HEIGHT) + { + if (g_map.cases[map_y * g_map.width + map_x].wall == WALL) + img_data[pixel_y * SCREEN_WIDTH + pixel_x] = 0xFFAF33; + else if (g_map.cases[map_y * g_map.width + map_x].wall == EMPTY && g_map.cases[map_y * g_map.width + map_x].inside) + img_data[pixel_y * SCREEN_WIDTH + pixel_x] = 0xFFFC33; + } + } + } +} +void minimap_player(u_int32_t *img_data) +{ + int player_x; + int player_y; + int pixel_x; + int pixel_y; + int i; + int j; + + i = -2; + player_x = g_map.player.pos.x * MINIMAP_SCALE; + player_y = g_map.player.pos.y * MINIMAP_SCALE; + while(i++ < 2) + { + j = -2; + while(j++ < 2) + { + pixel_x = player_x + i; + pixel_y = player_y + j; + if (pixel_x < SCREEN_WIDTH && pixel_y < SCREEN_HEIGHT) + img_data[pixel_y * SCREEN_WIDTH + pixel_x] = 0xFF0000; + } + } + +} \ No newline at end of file diff --git a/src/render.c b/src/render.c index d5c88e5..6823640 100644 --- a/src/render.c +++ b/src/render.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* render.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by grobledo #+# #+# */ -/* Updated: 2024/11/13 18:33:00 by mcolonna ### ########.fr */ +/* Updated: 2024/11/15 13:00:52 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -118,5 +118,6 @@ int render(u_int32_t *img_data) draw_vertical_line(img_data, &ray); ray.x++; } + create_minimap(img_data); return (0); } From e7d5a5ce697fe4a544cd6c363084cccde4ad5f86 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Mon, 18 Nov 2024 14:13:08 +0100 Subject: [PATCH 63/80] clean code * - add constants for each minimap color - rename, reorganize and make static minimap functions - main.c:draw_screen() calls draw_minimap() instead of render(). - clean code and norm --- include/const.h | 10 +++-- include/map.h | 8 +--- include/minimap.h | 22 ++++++++++ src/main.c | 9 ++-- src/minimap.c | 106 ++++++++++++++++++++++------------------------ src/render.c | 5 +-- 6 files changed, 88 insertions(+), 72 deletions(-) create mode 100644 include/minimap.h diff --git a/include/const.h b/include/const.h index 569cb65..9d5a34d 100644 --- a/include/const.h +++ b/include/const.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* const.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 17:00:59 by mcolonna #+# #+# */ -/* Updated: 2024/11/15 14:58:24 by grobledo ### ########.fr */ +/* Updated: 2024/11/18 13:40:04 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,5 +27,9 @@ # define FOV 0.66 // Width of the view plane (unit: cases) -# define MINIMAP_SCALE 8 +# define MINIMAP_SCALE 8 // Size of a case on the minimap. +# define MINIMAP_COLOR_WALL 0xFFAF33 // Color of the walls on the minimap +# define MINIMAP_COLOR_EMPTY 0xFFFC33 // Color of the empty cases on the minimap +# define MINIMAP_COLOR_PLAYER 0xFF0000 // Color of the player on the minimap + #endif diff --git a/include/map.h b/include/map.h index 9bcddf3..370075a 100644 --- a/include/map.h +++ b/include/map.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* map.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */ -/* Updated: 2024/11/15 14:56:55 by grobledo ### ########.fr */ +/* Updated: 2024/11/12 15:10:07 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -157,8 +157,4 @@ bool check_map(const t_map *map); /// @return Wanted case. const t_map_case *map_get_case(const t_map *map, int x, int y); -void create_minimap(u_int32_t *img_data); -void draw_minimap(uint32_t *img_data, int map_x, int map_y); -void minimap_player(u_int32_t *img_data); - #endif diff --git a/include/minimap.h b/include/minimap.h new file mode 100644 index 0000000..3a3d243 --- /dev/null +++ b/include/minimap.h @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* minimap.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/18 13:09:05 by mcolonna #+# #+# */ +/* Updated: 2024/11/18 13:14:12 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MINIMAP_H +# define MINIMAP_H + +# include "utils.h" + +/// @brief Draw the minimap on the image. +/// @param img_data Data of the image to draw the minimap on. +void draw_minimap(u_int32_t *img_data); + +#endif diff --git a/src/main.c b/src/main.c index 57b9f21..69b1b19 100644 --- a/src/main.c +++ b/src/main.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 16:57:40 by mcolonna #+# #+# */ -/* Updated: 2024/11/15 12:47:03 by grobledo ### ########.fr */ +/* Updated: 2024/11/18 13:29:26 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,7 @@ #include "input.h" #include "const.h" #include "global.h" +#include "minimap.h" static int g_return_value = 0; @@ -33,6 +34,7 @@ static void draw_screen(void) mlx_loop_end(g_mlx); } render(img_data); + draw_minimap(img_data); mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); mlx_destroy_image(g_mlx, img_ptr); } @@ -79,6 +81,3 @@ int main(int argc, char *argv[]) free(g_mlx); return (g_return_value); } - - - diff --git a/src/minimap.c b/src/minimap.c index bfaeaf1..10a667f 100644 --- a/src/minimap.c +++ b/src/minimap.c @@ -3,91 +3,87 @@ /* ::: :::::::: */ /* minimap.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/15 11:41:15 by grobledo #+# #+# */ -/* Updated: 2024/11/15 15:10:06 by grobledo ### ########.fr */ +/* Updated: 2024/11/18 14:19:40 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ -#include "../include/global.h" -#include "../include/const.h" +#include "minimap.h" -// g_map.width -// g_map.height -// g_map.player.pos.x -// g_map.player.pos.y -// g_map.cases[y * g_map.width + x].wall == WALL / EMPTY +#include "const.h" +#include "map.h" +#include "global.h" -void create_minimap(u_int32_t *img_data) +static void draw_minimap_wall(uint32_t *img_data, int map_y, int map_x); +static void draw_minimap_player(u_int32_t *img_data); + +void draw_minimap(u_int32_t *img_data) { unsigned int map_x; unsigned int map_y; map_x = 0; map_y = 0; - while (map_y < g_map.width) { map_x = 0; while (map_x < g_map.height) { - draw_minimap(img_data, map_x, map_y); - map_x++; + draw_minimap_wall(img_data, map_x, map_y); + map_x++; } map_y++; } - minimap_player(img_data); + draw_minimap_player(img_data); } -void draw_minimap(uint32_t *img_data, int map_y, int map_x) +static void draw_minimap_wall(uint32_t *img_data, int map_y, int map_x) { - int pixel_x; - int pixel_y; - int i; - int j; + const int map_case = map_y * g_map.width + map_x; + int pixel_x; + int pixel_y; + int pixel; - i = 0; - - while (i++ < MINIMAP_SCALE) + pixel_y = map_y * MINIMAP_SCALE; + while (pixel_y < (map_y + 1) * MINIMAP_SCALE) { - j = 0; - while (j++ < MINIMAP_SCALE) + pixel_x = map_x * MINIMAP_SCALE; + while (pixel_x < (map_x + 1) * MINIMAP_SCALE) { - pixel_y = map_y * MINIMAP_SCALE + j; - pixel_x = map_x * MINIMAP_SCALE + i; if (pixel_x < SCREEN_WIDTH && pixel_y < SCREEN_HEIGHT) { - if (g_map.cases[map_y * g_map.width + map_x].wall == WALL) - img_data[pixel_y * SCREEN_WIDTH + pixel_x] = 0xFFAF33; - else if (g_map.cases[map_y * g_map.width + map_x].wall == EMPTY && g_map.cases[map_y * g_map.width + map_x].inside) - img_data[pixel_y * SCREEN_WIDTH + pixel_x] = 0xFFFC33; + pixel = pixel_y * SCREEN_WIDTH + pixel_x; + if (g_map.cases[map_case].wall == WALL) + img_data[pixel] = MINIMAP_COLOR_WALL; + else if (g_map.cases[map_case].wall == EMPTY + && g_map.cases[map_case].inside) + img_data[pixel] = MINIMAP_COLOR_EMPTY; } + pixel_x++; + } + pixel_y++; + } +} + +static void draw_minimap_player(u_int32_t *img_data) +{ + const int player_x = g_map.player.pos.x * MINIMAP_SCALE; + const int player_y = g_map.player.pos.y * MINIMAP_SCALE; + int pixel_x; + int pixel_y; + int pixel; + + pixel_x = player_x - 2; + while (++pixel_x < player_x + 2) + { + pixel_y = player_y - 2; + while (++pixel_y < player_y + 2) + { + pixel = pixel_y * SCREEN_WIDTH + pixel_x; + if (pixel_x < SCREEN_WIDTH && pixel_y < SCREEN_HEIGHT) + img_data[pixel] = MINIMAP_COLOR_PLAYER; } } } -void minimap_player(u_int32_t *img_data) -{ - int player_x; - int player_y; - int pixel_x; - int pixel_y; - int i; - int j; - - i = -2; - player_x = g_map.player.pos.x * MINIMAP_SCALE; - player_y = g_map.player.pos.y * MINIMAP_SCALE; - while(i++ < 2) - { - j = -2; - while(j++ < 2) - { - pixel_x = player_x + i; - pixel_y = player_y + j; - if (pixel_x < SCREEN_WIDTH && pixel_y < SCREEN_HEIGHT) - img_data[pixel_y * SCREEN_WIDTH + pixel_x] = 0xFF0000; - } - } - -} \ No newline at end of file diff --git a/src/render.c b/src/render.c index 6823640..d5c88e5 100644 --- a/src/render.c +++ b/src/render.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* render.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ +/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by grobledo #+# #+# */ -/* Updated: 2024/11/15 13:00:52 by grobledo ### ########.fr */ +/* Updated: 2024/11/13 18:33:00 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -118,6 +118,5 @@ int render(u_int32_t *img_data) draw_vertical_line(img_data, &ray); ray.x++; } - create_minimap(img_data); return (0); } From 465aacdefeff0f642a72f76bc9147265bcc38291 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Fri, 15 Nov 2024 16:25:16 +0100 Subject: [PATCH 64/80] fix: add check for 0 or 2+ players on a map --- include/map.h | 34 ++++++-------------------------- include/player.h | 19 +++++++++--------- src/map1.c | 21 +++++++++----------- src/map_utils.h | 8 +++++--- src/map_utils1.c | 32 +++++++++++++++++++----------- src/player.c | 30 ++++++++++++---------------- testmaps/err_manymanyplayers.cub | 13 ++++++++++++ testmaps/err_manyplayers.cub | 13 ++++++++++++ testmaps/err_noplayer.cub | 13 ++++++++++++ testmaps/err_playeroutside.cub | 13 ++++++++++++ 10 files changed, 115 insertions(+), 81 deletions(-) create mode 100644 testmaps/err_manymanyplayers.cub create mode 100644 testmaps/err_manyplayers.cub create mode 100644 testmaps/err_noplayer.cub create mode 100644 testmaps/err_playeroutside.cub diff --git a/include/map.h b/include/map.h index 370075a..6225673 100644 --- a/include/map.h +++ b/include/map.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */ -/* Updated: 2024/11/12 15:10:07 by mcolonna ### ########.fr */ +/* Updated: 2024/11/18 14:26:30 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,30 +26,7 @@ typedef enum e_map_wall WALL, } t_map_wall; -/// @brief An object of the map (player, enemies?) -typedef struct s_object -{ - /// @brief Function called when creating the object. - /// - /// @param data Address of the s_object.data pointer. - /// @param pos Start position of the object. - void (*init)(void **data, t_point_int pos); - - /// @brief Function called when destroying the object (to avoid leaks). - /// - /// @param data Address of the s_object.data pointer. - /// @param pos Start position of the object. - void (*destroy)(void **data, t_point_int pos); - - /// @brief Function called each tick. - /// - /// @param data Address of the s_object.data pointer. - /// @param pos Start position of the object. - void (*tick)(void **data, t_point_int pos); - - /// @brief Pointer the object can use to save data. - void *data; -} t_object; +typedef struct s_player t_player; /// @brief Represents a case of the map. typedef struct s_map_case @@ -60,9 +37,10 @@ typedef struct s_map_case /// @brief Is the case empty or a wall? t_map_wall wall; - /// @brief The object that appears on this case. If there is none, - /// every pointer of the struct will be NULL. - t_object object; + /// @brief Initialize the player. NULL if there is no player on this case. + /// @param dest Will be set to the player. + /// @param pos Position of the case the player is on. + void (*init_player)(t_player *dest, t_point_int pos); } t_map_case; /// @brief Each element of g_map_mapping. A case and its associated char. diff --git a/include/player.h b/include/player.h index ad06e08..e966df4 100644 --- a/include/player.h +++ b/include/player.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 17:31:35 by mcolonna #+# #+# */ -/* Updated: 2024/11/01 20:41:30 by mcolonna ### ########.fr */ +/* Updated: 2024/11/15 15:54:36 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,17 +16,18 @@ # include "include.h" # include "utils.h" +# include "map.h" -/// @brief Create a player facing north (to use with t_object.init). -void init_player_n(void **data, t_point_int pos); +/// @brief Create a player facing north (to use with t_map_case.init_player). +void init_player_n(t_player *dest, t_point_int pos); -/// @brief Create a player facing south (to use with t_object.init). -void init_player_s(void **data, t_point_int pos); +/// @brief Create a player facing south (to use with t_map_case.init_player). +void init_player_s(t_player *dest, t_point_int pos); -/// @brief Create a player facing west (to use with t_object.init). -void init_player_w(void **data, t_point_int pos); +/// @brief Create a player facing west (to use with t_map_case.init_player). +void init_player_w(t_player *dest, t_point_int pos); -/// @brief Create a player facing east (to use with t_object.init). -void init_player_e(void **data, t_point_int pos); +/// @brief Create a player facing east (to use with t_map_case.init_player). +void init_player_e(t_player *dest, t_point_int pos); #endif diff --git a/src/map1.c b/src/map1.c index 55f3d02..5ed80db 100644 --- a/src/map1.c +++ b/src/map1.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 17:12:58 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 18:58:34 by mcolonna ### ########.fr */ +/* Updated: 2024/11/15 15:58:14 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,14 +18,14 @@ #include "global.h" const t_map_mapping_element g_map_mapping[] = { -{' ', {false, EMPTY, {NULL, NULL, NULL, NULL}}}, -{'0', {true, EMPTY, {NULL, NULL, NULL, NULL}}}, -{'1', {true, WALL, {NULL, NULL, NULL, NULL}}}, -{'N', {true, EMPTY, {init_player_n, NULL, NULL, NULL}}}, -{'S', {true, EMPTY, {init_player_s, NULL, NULL, NULL}}}, -{'E', {true, EMPTY, {init_player_e, NULL, NULL, NULL}}}, -{'W', {true, EMPTY, {init_player_w, NULL, NULL, NULL}}}, -{'\0', {true, EMPTY, {NULL, NULL, NULL, NULL}}}}; +{' ', {false, EMPTY, NULL}}, +{'0', {true, EMPTY, NULL}}, +{'1', {true, WALL, NULL}}, +{'N', {true, EMPTY, init_player_n}}, +{'S', {true, EMPTY, init_player_s}}, +{'E', {true, EMPTY, init_player_e}}, +{'W', {true, EMPTY, init_player_w}}, +{'\0', {true, EMPTY, NULL}}}; static bool map_from_file2(t_map *dest, t_stream *stream, int fd) { @@ -41,7 +41,6 @@ static bool map_from_file2(t_map *dest, t_stream *stream, int fd) } close(fd); free((void *)stream->str); - map_init_objects(dest); return (success); } @@ -117,8 +116,6 @@ static bool check_map2(const t_map *map, unsigned int x, unsigned int y) return (true); } -// TODO check player - bool check_map(const t_map *map) { unsigned int x; diff --git a/src/map_utils.h b/src/map_utils.h index dd000d3..11ece40 100644 --- a/src/map_utils.h +++ b/src/map_utils.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 15:05:13 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 19:04:19 by mcolonna ### ########.fr */ +/* Updated: 2024/11/15 15:52:16 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,9 +70,11 @@ void fill_zeros(void *dest, size_t size); /// @return true if success, false if error. bool read_map_description(t_map *map, t_stream *stream); -/// @brief Initialize all objects of the map. +/// @brief Initialize map->player. /// @param map Map to use. -void map_init_objects(t_map *map); +/// @return true if success, false if error +/// (0 or >2 players found instead of only one). +bool map_init_player(t_map *map); bool load_textures(t_map *map); diff --git a/src/map_utils1.c b/src/map_utils1.c index fcb9c2f..46fd51a 100644 --- a/src/map_utils1.c +++ b/src/map_utils1.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 15:02:09 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 18:59:07 by mcolonna ### ########.fr */ +/* Updated: 2024/11/15 16:24:09 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -106,26 +106,34 @@ bool read_map(t_map *d, t_stream *s) } if (!err[1] && !d->cases) err[0] = (write_err("Map description missing\n", NULL), true); - (err[1] || err[0]) && (map_destroy(d), false); - return (!err[0] && !err[1] && d->cases); + return ((!err[1] && !err[0] && d->cases && map_init_player(d)) + || (map_destroy(d), false)); } -void map_init_objects(t_map *map) +bool map_init_player(t_map *map) { t_point_int pos; int i; - pos.x = 0; - while (pos.x < (int)map->width) + map->player.pos.x = -1; + pos.x = -1; + while (++pos.x < (int)map->width) { - pos.y = 0; - while (pos.y < (int)map->height) + pos.y = -1; + while (++pos.y < (int)map->height) { i = pos.y * map->width + pos.x; - if (map->cases[i].object.init) - map->cases[i].object.init(&map->cases[i].object.data, pos); - pos.y++; + if (map->cases[i].init_player) + { + if (map->player.pos.x == -1) + map->cases[i].init_player(&map->player, pos); + else + return (write_err("Map has more than one player.\n", NULL), + false); + } } - pos.x++; } + if (map->player.pos.x == -1) + return (write_err("Map has no player.\n", NULL), false); + return (true); } diff --git a/src/player.c b/src/player.c index 02ae593..bf54377 100644 --- a/src/player.c +++ b/src/player.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 17:33:11 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 17:59:13 by mcolonna ### ########.fr */ +/* Updated: 2024/11/15 15:52:25 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,33 +15,29 @@ #include "global.h" #include "const.h" -static void init_player(t_point_int pos, double rot) +static void init_player(t_player *dest, t_point_int pos, double rot) { - g_map.player.pos.x = pos.x + 0.5; - g_map.player.pos.y = pos.y + 0.5; - g_map.player.rot = rot; + dest->pos.x = pos.x + 0.5; + dest->pos.y = pos.y + 0.5; + dest->rot = rot; } -void init_player_n(void **data, t_point_int pos) +void init_player_n(t_player *dest, t_point_int pos) { - (void)data; - init_player(pos, 0); + init_player(dest, pos, 0); } -void init_player_s(void **data, t_point_int pos) +void init_player_s(t_player *dest, t_point_int pos) { - (void)data; - init_player(pos, PI); + init_player(dest, pos, PI); } -void init_player_w(void **data, t_point_int pos) +void init_player_w(t_player *dest, t_point_int pos) { - (void)data; - init_player(pos, 3 * PI / 2); + init_player(dest, pos, 3 * PI / 2); } -void init_player_e(void **data, t_point_int pos) +void init_player_e(t_player *dest, t_point_int pos) { - (void)data; - init_player(pos, PI / 2); + init_player(dest, pos, PI / 2); } diff --git a/testmaps/err_manymanyplayers.cub b/testmaps/err_manymanyplayers.cub new file mode 100644 index 0000000..ab590f5 --- /dev/null +++ b/testmaps/err_manymanyplayers.cub @@ -0,0 +1,13 @@ +F 255,127,0 +C 0,2,67 +EA textures/east.xpm +NO textures/north.xpm +SO textures/south.xpm +WE textures/west.xpm + 111 +111110111 +1E000N0W1 +111110111 + 101 + 101 + 111 diff --git a/testmaps/err_manyplayers.cub b/testmaps/err_manyplayers.cub new file mode 100644 index 0000000..50aab36 --- /dev/null +++ b/testmaps/err_manyplayers.cub @@ -0,0 +1,13 @@ +F 255,127,0 +C 0,2,67 +EA textures/east.xpm +NO textures/north.xpm +SO textures/south.xpm +WE textures/west.xpm + 111 +111110111 +10000N0W1 +111110111 + 101 + 101 + 111 diff --git a/testmaps/err_noplayer.cub b/testmaps/err_noplayer.cub new file mode 100644 index 0000000..a65fef6 --- /dev/null +++ b/testmaps/err_noplayer.cub @@ -0,0 +1,13 @@ +F 255,127,0 +C 0,2,67 +EA textures/east.xpm +NO textures/north.xpm +SO textures/south.xpm +WE textures/west.xpm + 111 +111110111 +100000001 +111110111 + 101 + 101 + 111 diff --git a/testmaps/err_playeroutside.cub b/testmaps/err_playeroutside.cub new file mode 100644 index 0000000..6abce40 --- /dev/null +++ b/testmaps/err_playeroutside.cub @@ -0,0 +1,13 @@ +F 255,127,0 +C 0,2,67 +EA textures/east.xpm +NO textures/north.xpm +SO textures/south.xpm +WE textures/west.xpm + 111 +111110111 +100000001 +111110111 + N101 + 101 + 111 From d4c0e5faf968e0f1d50e6100a64597fef5a8f50b Mon Sep 17 00:00:00 2001 From: mcolonna Date: Mon, 18 Nov 2024 14:33:48 +0100 Subject: [PATCH 65/80] fix: render(): remove black line on top of image --- src/render_utils.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/render_utils.c b/src/render_utils.c index d006c6f..6db8d0a 100644 --- a/src/render_utils.c +++ b/src/render_utils.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/24 14:26:22 by grobledo #+# #+# */ -/* Updated: 2024/11/13 18:31:15 by mcolonna ### ########.fr */ +/* Updated: 2024/11/18 14:33:01 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,8 +45,8 @@ void draw_vertical_line_end(t_ray *ray, int draw_start, int draw_end, int texy; const t_texture texture = g_map.textures[ray->texdir]; - ray->y = 0; - while (ray->y++ < SCREEN_HEIGHT) + ray->y = -1; + while (++ray->y < SCREEN_HEIGHT) { if (ray->y < draw_start) img_data[ray->y * SCREEN_WIDTH + ray->x] = g_map.color_ceiling; From 2ec9ce4f8ee4936de51f31e89d5a9307988ca27f Mon Sep 17 00:00:00 2001 From: mcolonna Date: Tue, 19 Nov 2024 13:30:01 +0100 Subject: [PATCH 66/80] change: minimap: pretty player with fov --- include/const.h | 5 ++- src/minimap.c | 59 +++++++++++++++++++++++++++-------- src/minimap_inline.h | 72 +++++++++++++++++++++++++++++++++++++++++++ src/minimap_inline2.h | 46 +++++++++++++++++++++++++++ 4 files changed, 168 insertions(+), 14 deletions(-) create mode 100644 src/minimap_inline.h create mode 100644 src/minimap_inline2.h diff --git a/include/const.h b/include/const.h index 9d5a34d..6a34c4b 100644 --- a/include/const.h +++ b/include/const.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 17:00:59 by mcolonna #+# #+# */ -/* Updated: 2024/11/18 13:40:04 by mcolonna ### ########.fr */ +/* Updated: 2024/11/19 13:05:50 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,5 +31,8 @@ # define MINIMAP_COLOR_WALL 0xFFAF33 // Color of the walls on the minimap # define MINIMAP_COLOR_EMPTY 0xFFFC33 // Color of the empty cases on the minimap # define MINIMAP_COLOR_PLAYER 0xFF0000 // Color of the player on the minimap +// Distance from the player until where the FOV is drawn (unit: cases). +# define MINIMAP_DISTANCE_FOV 3 // Size of the FOV on the minimap +# define MINIMAP_OPACITY_FOV 0.8 // Opacity of the FOV on the minimap #endif diff --git a/src/minimap.c b/src/minimap.c index 10a667f..e9834e8 100644 --- a/src/minimap.c +++ b/src/minimap.c @@ -6,11 +6,12 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/15 11:41:15 by grobledo #+# #+# */ -/* Updated: 2024/11/18 14:19:40 by mcolonna ### ########.fr */ +/* Updated: 2024/11/19 13:20:54 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #include "minimap.h" +#include "minimap_inline.h" #include "const.h" #include "map.h" @@ -18,6 +19,7 @@ static void draw_minimap_wall(uint32_t *img_data, int map_y, int map_x); static void draw_minimap_player(u_int32_t *img_data); +static void draw_minimap_player_fov(u_int32_t *img_data); void draw_minimap(u_int32_t *img_data) { @@ -69,21 +71,52 @@ static void draw_minimap_wall(uint32_t *img_data, int map_y, int map_x) static void draw_minimap_player(u_int32_t *img_data) { - const int player_x = g_map.player.pos.x * MINIMAP_SCALE; - const int player_y = g_map.player.pos.y * MINIMAP_SCALE; - int pixel_x; - int pixel_y; - int pixel; + const t_point_int player = { + g_map.player.pos.x * MINIMAP_SCALE, + g_map.player.pos.y * MINIMAP_SCALE, + }; + t_point_int pixel; + int pixel_i; - pixel_x = player_x - 2; - while (++pixel_x < player_x + 2) + draw_minimap_player_fov(img_data); + pixel.x = player.x - HITBOX * MINIMAP_SCALE; + while (++pixel.x < player.x + HITBOX * MINIMAP_SCALE) { - pixel_y = player_y - 2; - while (++pixel_y < player_y + 2) + pixel.y = player.y - HITBOX * MINIMAP_SCALE; + while (++pixel.y < player.y + HITBOX * MINIMAP_SCALE) { - pixel = pixel_y * SCREEN_WIDTH + pixel_x; - if (pixel_x < SCREEN_WIDTH && pixel_y < SCREEN_HEIGHT) - img_data[pixel] = MINIMAP_COLOR_PLAYER; + pixel_i = pixel.y * SCREEN_WIDTH + pixel.x; + if (pixel.x < SCREEN_WIDTH && pixel.y < SCREEN_HEIGHT + && distance_between_int(player, pixel) < HITBOX * MINIMAP_SCALE) + img_data[pixel_i] = MINIMAP_COLOR_PLAYER; + } + } +} + +static void draw_minimap_player_fov(u_int32_t *img_data) +{ + const double fov_angle = atan(FOV); + const t_point_int player = { + g_map.player.pos.x * MINIMAP_SCALE, + g_map.player.pos.y * MINIMAP_SCALE, + }; + t_point_int p; + int p_i; + + p.x = player.x - MINIMAP_DISTANCE_FOV * MINIMAP_SCALE - 1; + while (++p.x < player.x + MINIMAP_DISTANCE_FOV * MINIMAP_SCALE) + { + p.y = player.y - MINIMAP_DISTANCE_FOV * MINIMAP_SCALE - 1; + while (++p.y < player.y + MINIMAP_DISTANCE_FOV * MINIMAP_SCALE) + { + p_i = p.y * SCREEN_WIDTH + p.x; + if (p_i >= 0 && p_i < SCREEN_HEIGHT * SCREEN_WIDTH) + if (angle_in_between(get_angle(player, p), g_map.player.rot + - fov_angle, g_map.player.rot + fov_angle)) + draw_transparent_pixel(&img_data[p_i], + MINIMAP_COLOR_PLAYER, MINIMAP_OPACITY_FOV + - (distance_between(pixel_to_pos(p), g_map.player.pos) + / MINIMAP_DISTANCE_FOV * MINIMAP_OPACITY_FOV)); } } } diff --git a/src/minimap_inline.h b/src/minimap_inline.h new file mode 100644 index 0000000..8c4a22c --- /dev/null +++ b/src/minimap_inline.h @@ -0,0 +1,72 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* minimap_inline.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/19 13:01:34 by mcolonna #+# #+# */ +/* Updated: 2024/11/19 13:26:01 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MINIMAP_INLINE_H +# define MINIMAP_INLINE_H + +# include "minimap.h" +# include "minimap_inline2.h" + +# include "const.h" + +static inline double distance_between(t_point_double a, t_point_double b) +{ + return (sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y))); +} + +static inline double distance_between_int(t_point_int a, t_point_int b) +{ + return (sqrt((double)( + (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + ))); +} + +static inline t_point_double pixel_to_pos(t_point_int pixel) +{ + return ((t_point_double){ + (double)pixel.x / MINIMAP_SCALE, + (double)pixel.y / MINIMAP_SCALE, + }); +} + +static inline double get_angle(t_point_int base, t_point_int vector) +{ + double r; + + vector.x -= base.x; + vector.y -= base.y; + if (!vector.y) + { + if (vector.x > 0) + return (PI / 2); + else + return (3 * PI / 2); + } + r = atan((double)vector.x / -(double)vector.y); + if (vector.y > 0) + return (r + PI); + else + return (r); +} + +static inline bool angle_in_between(double angle, double min, double max) +{ + while (max < min) + max += 2 * PI; + while (angle < min) + angle += 2 * PI; + while (angle >= max) + angle -= 2 * PI; + return (angle >= min); +} + +#endif diff --git a/src/minimap_inline2.h b/src/minimap_inline2.h new file mode 100644 index 0000000..a69f535 --- /dev/null +++ b/src/minimap_inline2.h @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* minimap_inline2.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/19 13:07:02 by mcolonna #+# #+# */ +/* Updated: 2024/11/19 13:12:31 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MINIMAP_INLINE2_H +# define MINIMAP_INLINE2_H + +# include "minimap.h" + +static inline double srgb_to_gamma(u_int8_t value) +{ + return (pow((double)value / 0xFF, 2.2)); +} + +static inline u_int8_t gamma_to_srgb(double value) +{ + return (pow((double)value, 1 / 2.2) * 0xFF); +} + +static inline void draw_transparent_pixel(u_int32_t *pixel, u_int32_t color, + double opacity) +{ + if (opacity <= 0) + return ; + if (opacity >= 1) + *pixel = color; + ((u_int8_t *)pixel)[0] = gamma_to_srgb( + (1 - opacity) * srgb_to_gamma(((u_int8_t *)pixel)[0]) + + opacity * srgb_to_gamma(((u_int8_t *)&color)[0])); + ((u_int8_t *)pixel)[1] = gamma_to_srgb( + (1 - opacity) * srgb_to_gamma(((u_int8_t *)pixel)[1]) + + opacity * srgb_to_gamma(((u_int8_t *)&color)[1])); + ((u_int8_t *)pixel)[2] = gamma_to_srgb( + (1 - opacity) * srgb_to_gamma(((u_int8_t *)pixel)[2]) + + opacity * srgb_to_gamma(((u_int8_t *)&color)[2])); +} + +#endif From 7684e02cc5809ad3c6a7cd066224fbbb3589490b Mon Sep 17 00:00:00 2001 From: mcolonna Date: Tue, 19 Nov 2024 13:31:46 +0100 Subject: [PATCH 67/80] change: minimap: change player color to blue --- include/const.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/const.h b/include/const.h index 6a34c4b..c7ae95b 100644 --- a/include/const.h +++ b/include/const.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 17:00:59 by mcolonna #+# #+# */ -/* Updated: 2024/11/19 13:05:50 by mcolonna ### ########.fr */ +/* Updated: 2024/11/19 13:31:42 by marvin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ # define MINIMAP_SCALE 8 // Size of a case on the minimap. # define MINIMAP_COLOR_WALL 0xFFAF33 // Color of the walls on the minimap # define MINIMAP_COLOR_EMPTY 0xFFFC33 // Color of the empty cases on the minimap -# define MINIMAP_COLOR_PLAYER 0xFF0000 // Color of the player on the minimap +# define MINIMAP_COLOR_PLAYER 0x0000FF // Color of the player on the minimap // Distance from the player until where the FOV is drawn (unit: cases). # define MINIMAP_DISTANCE_FOV 3 // Size of the FOV on the minimap # define MINIMAP_OPACITY_FOV 0.8 // Opacity of the FOV on the minimap From 54f61ee4b07ac643736ee25dc1cb2b7e05439724 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Tue, 19 Nov 2024 13:33:58 +0100 Subject: [PATCH 68/80] dev: norm --- include/map.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/map.h b/include/map.h index 6225673..a46d578 100644 --- a/include/map.h +++ b/include/map.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */ -/* Updated: 2024/11/18 14:26:30 by mcolonna ### ########.fr */ +/* Updated: 2024/11/19 13:25:42 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,7 +26,7 @@ typedef enum e_map_wall WALL, } t_map_wall; -typedef struct s_player t_player; +typedef struct s_player t_player; /// @brief Represents a case of the map. typedef struct s_map_case From fc318fc8514aef9969a543ac83b29723538b17ca Mon Sep 17 00:00:00 2001 From: ReverseSky Date: Tue, 19 Nov 2024 13:11:42 +0100 Subject: [PATCH 69/80] modified scaling minimap --- include/const.h | 4 +-- src/minimap.c | 73 ++++++++++++++++++++++++++----------------- src/minimap_inline.h | 8 ++--- testmaps/good_big.cub | 18 +++++------ 4 files changed, 60 insertions(+), 43 deletions(-) diff --git a/include/const.h b/include/const.h index c7ae95b..7e77f8b 100644 --- a/include/const.h +++ b/include/const.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 17:00:59 by mcolonna #+# #+# */ -/* Updated: 2024/11/19 13:31:42 by marvin ### ########.fr */ +/* Updated: 2024/11/19 13:54:46 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,7 @@ # define FOV 0.66 // Width of the view plane (unit: cases) -# define MINIMAP_SCALE 8 // Size of a case on the minimap. +# define MINIMAP_SIZE_INVERT 4 // The minimap takes 1/N of the window. # define MINIMAP_COLOR_WALL 0xFFAF33 // Color of the walls on the minimap # define MINIMAP_COLOR_EMPTY 0xFFFC33 // Color of the empty cases on the minimap # define MINIMAP_COLOR_PLAYER 0x0000FF // Color of the player on the minimap diff --git a/src/minimap.c b/src/minimap.c index e9834e8..cccec12 100644 --- a/src/minimap.c +++ b/src/minimap.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/15 11:41:15 by grobledo #+# #+# */ -/* Updated: 2024/11/19 13:20:54 by mcolonna ### ########.fr */ +/* Updated: 2024/11/19 13:59:36 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,14 +17,29 @@ #include "map.h" #include "global.h" -static void draw_minimap_wall(uint32_t *img_data, int map_y, int map_x); -static void draw_minimap_player(u_int32_t *img_data); -static void draw_minimap_player_fov(u_int32_t *img_data); +static void draw_minimap_wall(uint32_t *img_data, int map_y, int map_x, + double scale); +static void draw_minimap_player(u_int32_t *img_data, double scale); +static void draw_minimap_player_fov(u_int32_t *img_data, double scale); + +static double scale_calcul(void) +{ + const int minimap_width = SCREEN_WIDTH / MINIMAP_SIZE_INVERT; + const int minimap_height = SCREEN_HEIGHT / MINIMAP_SIZE_INVERT; + const double scale_x = (double)minimap_width / g_map.width; + const double scale_y = (double)minimap_height / g_map.height; + + if (scale_x < scale_y) + return (scale_x); + else + return (scale_y); +} void draw_minimap(u_int32_t *img_data) { unsigned int map_x; unsigned int map_y; + const double scale = scale_calcul(); map_x = 0; map_y = 0; @@ -33,26 +48,27 @@ void draw_minimap(u_int32_t *img_data) map_x = 0; while (map_x < g_map.height) { - draw_minimap_wall(img_data, map_x, map_y); + draw_minimap_wall(img_data, map_x, map_y, scale); map_x++; } map_y++; } - draw_minimap_player(img_data); + draw_minimap_player(img_data, scale); } -static void draw_minimap_wall(uint32_t *img_data, int map_y, int map_x) +static void draw_minimap_wall(uint32_t *img_data, int map_y, int map_x, + double scale) { const int map_case = map_y * g_map.width + map_x; int pixel_x; int pixel_y; int pixel; - pixel_y = map_y * MINIMAP_SCALE; - while (pixel_y < (map_y + 1) * MINIMAP_SCALE) + pixel_y = map_y * scale; + while (pixel_y < (map_y + 1) * scale) { - pixel_x = map_x * MINIMAP_SCALE; - while (pixel_x < (map_x + 1) * MINIMAP_SCALE) + pixel_x = map_x * scale; + while (pixel_x < (map_x + 1) * scale) { if (pixel_x < SCREEN_WIDTH && pixel_y < SCREEN_HEIGHT) { @@ -69,45 +85,45 @@ static void draw_minimap_wall(uint32_t *img_data, int map_y, int map_x) } } -static void draw_minimap_player(u_int32_t *img_data) +static void draw_minimap_player(u_int32_t *img_data, double scale) { const t_point_int player = { - g_map.player.pos.x * MINIMAP_SCALE, - g_map.player.pos.y * MINIMAP_SCALE, + g_map.player.pos.x * scale, + g_map.player.pos.y * scale, }; t_point_int pixel; int pixel_i; - draw_minimap_player_fov(img_data); - pixel.x = player.x - HITBOX * MINIMAP_SCALE; - while (++pixel.x < player.x + HITBOX * MINIMAP_SCALE) + draw_minimap_player_fov(img_data, scale); + pixel.x = player.x - HITBOX * scale; + while (++pixel.x < player.x + HITBOX * scale) { - pixel.y = player.y - HITBOX * MINIMAP_SCALE; - while (++pixel.y < player.y + HITBOX * MINIMAP_SCALE) + pixel.y = player.y - HITBOX * scale; + while (++pixel.y < player.y + HITBOX * scale) { pixel_i = pixel.y * SCREEN_WIDTH + pixel.x; if (pixel.x < SCREEN_WIDTH && pixel.y < SCREEN_HEIGHT - && distance_between_int(player, pixel) < HITBOX * MINIMAP_SCALE) + && distance_between_int(player, pixel) < HITBOX * scale) img_data[pixel_i] = MINIMAP_COLOR_PLAYER; } } } -static void draw_minimap_player_fov(u_int32_t *img_data) +static void draw_minimap_player_fov(u_int32_t *img_data, double scale) { const double fov_angle = atan(FOV); const t_point_int player = { - g_map.player.pos.x * MINIMAP_SCALE, - g_map.player.pos.y * MINIMAP_SCALE, + g_map.player.pos.x * scale, + g_map.player.pos.y * scale, }; t_point_int p; int p_i; - p.x = player.x - MINIMAP_DISTANCE_FOV * MINIMAP_SCALE - 1; - while (++p.x < player.x + MINIMAP_DISTANCE_FOV * MINIMAP_SCALE) + p.x = player.x - MINIMAP_DISTANCE_FOV * scale - 1; + while (++p.x < player.x + MINIMAP_DISTANCE_FOV * scale) { - p.y = player.y - MINIMAP_DISTANCE_FOV * MINIMAP_SCALE - 1; - while (++p.y < player.y + MINIMAP_DISTANCE_FOV * MINIMAP_SCALE) + p.y = player.y - MINIMAP_DISTANCE_FOV * scale - 1; + while (++p.y < player.y + MINIMAP_DISTANCE_FOV * scale) { p_i = p.y * SCREEN_WIDTH + p.x; if (p_i >= 0 && p_i < SCREEN_HEIGHT * SCREEN_WIDTH) @@ -115,7 +131,8 @@ static void draw_minimap_player_fov(u_int32_t *img_data) - fov_angle, g_map.player.rot + fov_angle)) draw_transparent_pixel(&img_data[p_i], MINIMAP_COLOR_PLAYER, MINIMAP_OPACITY_FOV - - (distance_between(pixel_to_pos(p), g_map.player.pos) + - (distance_between(pixel_to_pos(p, scale), + g_map.player.pos) / MINIMAP_DISTANCE_FOV * MINIMAP_OPACITY_FOV)); } } diff --git a/src/minimap_inline.h b/src/minimap_inline.h index 8c4a22c..c5f003b 100644 --- a/src/minimap_inline.h +++ b/src/minimap_inline.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/19 13:01:34 by mcolonna #+# #+# */ -/* Updated: 2024/11/19 13:26:01 by mcolonna ### ########.fr */ +/* Updated: 2024/11/19 13:51:57 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,11 +30,11 @@ static inline double distance_between_int(t_point_int a, t_point_int b) ))); } -static inline t_point_double pixel_to_pos(t_point_int pixel) +static inline t_point_double pixel_to_pos(t_point_int pixel, double scale) { return ((t_point_double){ - (double)pixel.x / MINIMAP_SCALE, - (double)pixel.y / MINIMAP_SCALE, + (double)pixel.x / scale, + (double)pixel.y / scale, }); } diff --git a/testmaps/good_big.cub b/testmaps/good_big.cub index 621a6e5..1845aac 100644 --- a/testmaps/good_big.cub +++ b/testmaps/good_big.cub @@ -4,12 +4,12 @@ EA textures/east.xpm NO textures/north.xpm SO textures/south.xpm WE textures/west.xpm -111111111 -100000001 -100010001 -100000001 -1000N0001 -100000001 -100000001 -100000001 -111111111 +111111111111111111111111111111111111111111111 +100000001100000001100000001100000001100000001 +100010000000000001100000001100000001100000001 +100000001100000000000000001100000001100000001 +1000N0001100000001100000001100000001100000001 +100000001100000001100000000000000001100000001 +100000001100000001100000001100000000000000001 +100000001100000001100000001100000001100000001 +111111111111111111111111111111111111111111111 From ec6d5931a48fd6706873cd40b96243cb7202cc41 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Tue, 19 Nov 2024 14:43:43 +0100 Subject: [PATCH 70/80] change Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8689b64..f63a460 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ fclean : clean -$(MAKE) -C Minilibx clean -rm $$(find Minilibx -name "Makefile.gen") -re : fclean all +re : clean all $(NAME) : $(O_FILES) $(LIBRARIES_DIR) @$(ECHO) From 08db89f6dcae9bbd1ff6fb846493da1411b12a78 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Tue, 19 Nov 2024 15:00:16 +0100 Subject: [PATCH 71/80] dev: add TODO --- dev/TODO | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 dev/TODO diff --git a/dev/TODO b/dev/TODO new file mode 100644 index 0000000..1f67171 --- /dev/null +++ b/dev/TODO @@ -0,0 +1,9 @@ +TODO check when project is finished: +- all testmaps work or don't (no error found at ec6d593) +- check leaks (no error found at ec6d593) +- check errors (no error found at ec6d593) +- separate mandatory and bonus +- check used functions (no error found at ec6d593) +- check norminette on cluster + +TODO: better timedloop for bonus From c8b3a42d13a521e6bcdb74740b0036a1b76fcfd8 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Tue, 19 Nov 2024 15:36:39 +0100 Subject: [PATCH 72/80] add: better timedloop (uses FPS) for bonus --- Makefile | 15 +++++++++++-- include/const.h | 15 +++++++++---- include/include.h | 3 ++- src/main.c | 5 +++-- src/utils.c | 40 +-------------------------------- src/utils_timedloop_bonus.c | 42 +++++++++++++++++++++++++++++++++++ src/utils_timedloop_nobonus.c | 22 ++++++++++++++++++ 7 files changed, 94 insertions(+), 48 deletions(-) create mode 100644 src/utils_timedloop_bonus.c create mode 100644 src/utils_timedloop_nobonus.c diff --git a/Makefile b/Makefile index f63a460..d5ad61d 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,13 @@ SHARED = -lX11 -lXext -lm CPP_1 = $(CPP) -Wall -Wextra -Werror -I Libft -I Minilibx -I include $(FLAGS) $(FLAGS_1) CPP_2 = $(CPP) $(FLAGS) $(FLAGS_2) C_FILES = $(wildcard src/*.c) +ifeq ($(BONUS), yes) + C_FILES_REAL = $(filter-out $(wildcard src/*_nobonus.c),$(C_FILES)) +else + C_FILES_REAL = $(filter-out $(wildcard src/*_bonus.c),$(C_FILES)) +endif O_FILES = $(patsubst %.c,%.o,$(C_FILES)) +O_FILES_REAL = $(patsubst %.c,%.o,$(C_FILES_REAL)) ECHO = echoo(){ \ if [ -t 1 ]; then \ @@ -18,6 +24,9 @@ ECHO = echoo(){ \ all : $(NAME) +bonus : + $(MAKE) all BONUS=yes FLAGS_1="$(FLAGS_1) -DBONUS" + debug : $(MAKE) all FLAGS_1="$(FLAGS_1) -g" @@ -44,10 +53,12 @@ fclean : clean re : clean all -$(NAME) : $(O_FILES) $(LIBRARIES_DIR) +rebonus : clean bonus + +$(NAME) : $(O_FILES_REAL) $(LIBRARIES_DIR) @$(ECHO) @$(ECHO) "\e[30;47;1m $(NAME): linking... \e[0m" - $(CPP_2) $(O_FILES) $(LIBRARIES_A) $(SHARED) -o $@ + $(CPP_2) $(O_FILES_REAL) $(LIBRARIES_A) $(SHARED) -o $@ @$(ECHO) @$(ECHO) "\t\t \e[0;92m\(^o^)/ \e[0;102;30;1m $(NAME) made! \e[0;92m \(^o^)/\e[0m" @$(ECHO) diff --git a/include/const.h b/include/const.h index 7e77f8b..85da448 100644 --- a/include/const.h +++ b/include/const.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 17:00:59 by mcolonna #+# #+# */ -/* Updated: 2024/11/19 13:54:46 by mcolonna ### ########.fr */ +/* Updated: 2024/11/19 15:29:31 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,11 +17,18 @@ # define PI 3.1415926535 // it's just pi -# define MOVE_SPEED 0.05 // Player oves by N cases by tick -# define ROT_SPEED_DIVIDE_PI 64 // Player turns by pi/N rad by tick -# define MOUSE_ROTATION_SPEED 0.001 // rad/px +# define FPS 30 // Number of frames per second (bonus only) + +# define MOVE_SPEED 0.1 // Player oves by N cases by tick +# define ROT_SPEED_DIVIDE_PI 48 // Player turns by pi/N rad by tick +# define MOUSE_ROTATION_SPEED 0.001 // Rotation speed from mouse: rad/px # define HITBOX 0.25 // Hitbox of N cases around player. +# ifdef BONUS +# define WINDOW_NAME "cub3d (bonus)" +# else +# define WINDOW_NAME "cub3d (mandatory)" +# endif # define SCREEN_WIDTH 640 // Width of the window # define SCREEN_HEIGHT 480 // Height of the window diff --git a/include/include.h b/include/include.h index 5e903b3..60a38f5 100644 --- a/include/include.h +++ b/include/include.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 16:22:09 by mcolonna #+# #+# */ -/* Updated: 2024/11/12 17:41:11 by mcolonna ### ########.fr */ +/* Updated: 2024/11/19 15:08:27 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,6 +24,7 @@ # include # include # include +# include # include # include # include diff --git a/src/main.c b/src/main.c index 69b1b19..287ea7d 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 16:57:40 by mcolonna #+# #+# */ -/* Updated: 2024/11/18 13:29:26 by mcolonna ### ########.fr */ +/* Updated: 2024/11/19 15:35:50 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -68,7 +68,8 @@ int main(int argc, char *argv[]) g_return_value = 1; else { - g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d"); + g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, + WINDOW_NAME); input_init(g_mlx, g_win); mlx_loop_hook(g_mlx, loop_hook, NULL); draw_screen(); diff --git a/src/utils.c b/src/utils.c index d9b6787..688531a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:38:40 by mcolonna #+# #+# */ -/* Updated: 2024/11/07 00:05:39 by mcolonna ### ########.fr */ +/* Updated: 2024/11/19 15:07:05 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,41 +30,3 @@ void write_err(const char *str, ...) str = va_arg(args, const char *); } } - -/* FOR BONUS -static long get_nanos(void) -{ - struct timespec ts; - - timespec_get(&ts, TIME_UTC); - return ((long)ts.tv_sec * 1000000000L + ts.tv_nsec); -} - -void timedloop(void (*f)(void)) -{ - static long last_time = 0; - const long new_time = get_nanos(); - static bool checked = false; - - if (new_time - last_time >= 1000000000L / FPS) - { - if (checked) - last_time += 1000000000L / FPS; - else - last_time = new_time; - checked = false; - f(); - } - else - checked = true; -} -*/ - -void timedloop(void (*f)(void)) -{ - static int ticks; - - if (ticks % 100 == 0) - f(); - ticks++; -} diff --git a/src/utils_timedloop_bonus.c b/src/utils_timedloop_bonus.c new file mode 100644 index 0000000..9358daa --- /dev/null +++ b/src/utils_timedloop_bonus.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* utils_timedloop_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/19 15:05:10 by mcolonna #+# #+# */ +/* Updated: 2024/11/19 15:13:02 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "utils.h" + +#include "const.h" + +static long get_nanos(void) +{ + struct timespec ts; + + timespec_get(&ts, TIME_UTC); + return ((long)ts.tv_sec * 1000000000L + ts.tv_nsec); +} + +void timedloop(void (*f)(void)) +{ + static long last_time = 0; + const long new_time = get_nanos(); + static bool checked = false; + + if (new_time - last_time >= 1000000000L / FPS) + { + if (checked) + last_time += 1000000000L / FPS; + else + last_time = new_time; + checked = false; + f(); + } + else + checked = true; +} diff --git a/src/utils_timedloop_nobonus.c b/src/utils_timedloop_nobonus.c new file mode 100644 index 0000000..26d6c1e --- /dev/null +++ b/src/utils_timedloop_nobonus.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* utils_timedloop_nobonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/19 15:05:10 by mcolonna #+# #+# */ +/* Updated: 2024/11/19 15:36:17 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "utils.h" + +void timedloop(void (*f)(void)) +{ + static int ticks; + + if (ticks % 100 == 0) + f(); + ticks++; +} From f3da11b105bf93e88bdc7a24547ac0ca2b24ecec Mon Sep 17 00:00:00 2001 From: mcolonna Date: Wed, 20 Nov 2024 16:58:44 +0100 Subject: [PATCH 73/80] dev: add TODOs of things to fix --- dev/TODO | 5 +++++ testmaps/err_badcolors1.cub | 13 +++++++++++++ testmaps/err_badcolors2.cub | 13 +++++++++++++ testmaps/err_badcolors3.cub | 13 +++++++++++++ testmaps/err_badcolors4.cub | 13 +++++++++++++ testmaps/err_badtextures.cub | 13 +++++++++++++ testmaps/good_reallyreallyweirdblank.cub | 24 ++++++++++++++++++++++++ 7 files changed, 94 insertions(+) create mode 100644 testmaps/err_badcolors1.cub create mode 100644 testmaps/err_badcolors2.cub create mode 100644 testmaps/err_badcolors3.cub create mode 100644 testmaps/err_badcolors4.cub create mode 100644 testmaps/err_badtextures.cub create mode 100644 testmaps/good_reallyreallyweirdblank.cub diff --git a/dev/TODO b/dev/TODO index 1f67171..1c5bd73 100644 --- a/dev/TODO +++ b/dev/TODO @@ -7,3 +7,8 @@ TODO check when project is finished: - check norminette on cluster TODO: better timedloop for bonus +TODO: map parsing: fix segfault if bad texture +TODO: map parsing: fix when color value > 255 +TODO: what if the pointer goes outside of the window? +TODO: fix inverted west and east textures +TODO: fix nobonus speed diff --git a/testmaps/err_badcolors1.cub b/testmaps/err_badcolors1.cub new file mode 100644 index 0000000..5308152 --- /dev/null +++ b/testmaps/err_badcolors1.cub @@ -0,0 +1,13 @@ +F 255,256,0 +C 0,2,67 +EA textures/east.xpm +NO textures/north.xpm +SO textures/south.xpm +WE textures/west.xpm + 111 +111110111 +10000N001 +111110111 + 101 + 101 + 111 diff --git a/testmaps/err_badcolors2.cub b/testmaps/err_badcolors2.cub new file mode 100644 index 0000000..dc5127c --- /dev/null +++ b/testmaps/err_badcolors2.cub @@ -0,0 +1,13 @@ +F ",127,0 +C 0,2,67 +EA textures/east.xpm +NO textures/north.xpm +SO textures/south.xpm +WE textures/west.xpm + 111 +111110111 +10000N001 +111110111 + 101 + 101 + 111 diff --git a/testmaps/err_badcolors3.cub b/testmaps/err_badcolors3.cub new file mode 100644 index 0000000..6f5ae7c --- /dev/null +++ b/testmaps/err_badcolors3.cub @@ -0,0 +1,13 @@ +F 255,127,0 +C 2,349,67 +EA textures/east.xpm +NO textures/north.xpm +SO textures/south.xpm +WE textures/west.xpm + 111 +111110111 +10000N001 +111110111 + 101 + 101 + 111 diff --git a/testmaps/err_badcolors4.cub b/testmaps/err_badcolors4.cub new file mode 100644 index 0000000..9ece5fe --- /dev/null +++ b/testmaps/err_badcolors4.cub @@ -0,0 +1,13 @@ +F 255,127,0 +C 0,\(^.^)/,67 +EA textures/east.xpm +NO textures/north.xpm +SO textures/south.xpm +WE textures/west.xpm + 111 +111110111 +10000N001 +111110111 + 101 + 101 + 111 diff --git a/testmaps/err_badtextures.cub b/testmaps/err_badtextures.cub new file mode 100644 index 0000000..3b52091 --- /dev/null +++ b/testmaps/err_badtextures.cub @@ -0,0 +1,13 @@ +F 255,127,0 +C 0,2,67 +EA textures/nowhere.xpm +NO textures/nowhere.xpm +SO textures/nowhere.xpm +WE textures/nowhere.xpm + 111 +111110111 +10000N001 +111110111 + 101 + 101 + 111 diff --git a/testmaps/good_reallyreallyweirdblank.cub b/testmaps/good_reallyreallyweirdblank.cub new file mode 100644 index 0000000..48c3ae4 --- /dev/null +++ b/testmaps/good_reallyreallyweirdblank.cub @@ -0,0 +1,24 @@ +F 255, 127 ,0 + +C 0, 2 , 67 + + + +EA textures/east.xpm +NO textures/north.xpm + +SO textures/south.xpm + + + + + +WE textures/west.xpm + + + +1111111 +1000001 +10W0001 +1000001 +1111111 From 424b9aa7b2ffe9204c99dfb246e0c534140149a7 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 21 Nov 2024 15:18:08 +0100 Subject: [PATCH 74/80] fixings and improvements dev: - add documentation - main() is more readable fix: - unmanaged errors: - map parsing: error if color value is >255 - map parsing: load_textures(): check return value of xml_xpm_file_to_image() - main.c: draw_screen(): check return value of mlx_new_image() other details: - dev: color_from_rgb(): change signature - fix: nullize map in map_destroy - change: change error message for read_all_text() errors - change: change rotation speed - change: add and use contant NOOBONUS_SPEED --- dev/TODO | 1 - include/const.h | 4 +- include/map.h | 3 + include/stream.h | 3 +- include/utils.h | 2 +- src/main.c | 73 ++++++++++++------- src/map1.c | 3 +- src/map_utils.h | 16 +++- src/map_utils1.c | 6 +- src/map_utils2.c | 7 ++ src/minimap_inline.h | 35 ++++++++- src/minimap_inline2.h | 9 +++ src/move_utils.h | 1 + src/stream.c | 7 +- src/utils2.c | 2 +- src/utils_timedloop_nobonus.c | 4 +- ...ank.cub => err_reallyreallyweirdblank.cub} | 0 testmaps/good_reallyweirdblank.cub | 6 +- 18 files changed, 135 insertions(+), 47 deletions(-) rename testmaps/{good_reallyreallyweirdblank.cub => err_reallyreallyweirdblank.cub} (100%) diff --git a/dev/TODO b/dev/TODO index 1c5bd73..6632cc5 100644 --- a/dev/TODO +++ b/dev/TODO @@ -11,4 +11,3 @@ TODO: map parsing: fix segfault if bad texture TODO: map parsing: fix when color value > 255 TODO: what if the pointer goes outside of the window? TODO: fix inverted west and east textures -TODO: fix nobonus speed diff --git a/include/const.h b/include/const.h index 85da448..6accd5f 100644 --- a/include/const.h +++ b/include/const.h @@ -18,9 +18,11 @@ # define PI 3.1415926535 // it's just pi # define FPS 30 // Number of frames per second (bonus only) +# define NOBONUS_SPEED 500 // Number of calls to timedloop for one frame + // (mandatory only) # define MOVE_SPEED 0.1 // Player oves by N cases by tick -# define ROT_SPEED_DIVIDE_PI 48 // Player turns by pi/N rad by tick +# define ROT_SPEED_DIVIDE_PI 32 // Player turns by pi/N rad by tick # define MOUSE_ROTATION_SPEED 0.001 // Rotation speed from mouse: rad/px # define HITBOX 0.25 // Hitbox of N cases around player. diff --git a/include/map.h b/include/map.h index a46d578..31f5f1a 100644 --- a/include/map.h +++ b/include/map.h @@ -111,6 +111,7 @@ typedef struct s_map } t_map; /// @brief Create a t_map from the content of a .cub file. +/// If error, write an error text. /// /// @param dest Pointer to the t_map to set. /// @param file .cub file to use to create the t_map. @@ -122,12 +123,14 @@ bool map_from_file(t_map *dest, const char *file); void map_destroy(t_map *map); /// @brief Return true if the map is valid. Write an error message on stderr. +/// If error, write an error text. /// /// @param map The map to check. /// @return true if the map is valid, false if not. bool check_map(const t_map *map); /// @brief Get a case of the map from its coordinates. +/// If x or y are outside the map, undefined behaviour. /// /// @param map Map to get the case from. /// @param x x position of the case to return. diff --git a/include/stream.h b/include/stream.h index bcbe855..3992371 100644 --- a/include/stream.h +++ b/include/stream.h @@ -35,13 +35,14 @@ typedef struct s_stream void read_expected_string(const char *str, t_stream *stream, bool *err); /// @brief Read an unsigned int (which fits the pattern /[0-9]+/). +/// It must be between 0 and 255. /// Skip the potential blank space before the string. /// /// @param dest Will be set to the value of the unsigned integer. /// @param stream Stream to use. /// @param err Set to true if an error occured. /// If already true, the function won't do anything. -void read_unsigned(unsigned int *dest, t_stream *stream, bool *err); +void read_unsigned_max_255(unsigned int *dest, t_stream *stream, bool *err); /// @brief Read a string until limit char or \0. /// Skip the potential blank space before the string. diff --git a/include/utils.h b/include/utils.h index ecc5f06..0e2bedb 100644 --- a/include/utils.h +++ b/include/utils.h @@ -38,7 +38,7 @@ typedef __u32 t_color; /// @param green Level of green from 0 to 255. /// @param blue Level of blue from 0 to 255. /// @return The result. -t_color color_from_rgb(int red, int green, int blue); +t_color color_from_rgb(u_int8_t red, u_int8_t green, u_int8_t blue); /// @brief Write an error message on stderr. /// diff --git a/src/main.c b/src/main.c index 287ea7d..13ed0c0 100644 --- a/src/main.c +++ b/src/main.c @@ -21,22 +21,25 @@ static int g_return_value = 0; -static void draw_screen(void) +// If error: write the error and returns false. +static bool draw_screen(void) { void *img_ptr; u_int32_t *img_data; img_ptr = mlx_new_image(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT); + if (!img_ptr) + return (write_err("mlx_new_image() failed.\n"), false); img_data = get_data_addr(img_ptr); if (!img_data) { - g_return_value = 1; - mlx_loop_end(g_mlx); + return (false); } render(img_data); draw_minimap(img_data); mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); mlx_destroy_image(g_mlx, img_ptr); + return (true); } static void loop(void) @@ -44,7 +47,11 @@ static void loop(void) move(); if (g_input_actions.quit) mlx_loop_end(g_mlx); - draw_screen(); + if (!draw_screen()) + { + g_return_value = 1; + mlx_loop_end(g_mlx); + } } static int loop_hook(void *param) @@ -54,31 +61,41 @@ static int loop_hook(void *param) return (0); } +static void destroy_g_mlx_g_win_and_map(t_map *map) +{ + if (map) + map_destroy(map); + if (g_mlx) + { + if (g_win) + { + mlx_destroy_window(g_mlx, g_win); + g_win = NULL; + } + mlx_destroy_display(g_mlx); + free(g_mlx); + g_mlx = NULL; + } +} + int main(int argc, char *argv[]) { - g_mlx = mlx_init(); + g_mlx = NULL; + g_win = NULL; if (argc != 2) - { - printf("Syntax: %s \n", argv[0]); - g_return_value = 1; - } - else - { - if (!map_from_file(&g_map, argv[1])) - g_return_value = 1; - else - { - g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, - WINDOW_NAME); - input_init(g_mlx, g_win); - mlx_loop_hook(g_mlx, loop_hook, NULL); - draw_screen(); - mlx_loop(g_mlx); - mlx_destroy_window(g_mlx, g_win); - map_destroy(&g_map); - } - } - mlx_destroy_display(g_mlx); - free(g_mlx); - return (g_return_value); + return (printf("Syntax: %s \n", argv[0]), 1); + g_mlx = mlx_init(); + if (!g_mlx) + return (write_err("mlx_init() failed.\n", NULL), 1); + if (!map_from_file(&g_map, argv[1])) + return (destroy_g_mlx_g_win_and_map(NULL), 1); + g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, WINDOW_NAME); + if (!g_win) + return (write_err("mlx_new_window() failed.\n", NULL), + destroy_g_mlx_g_win_and_map(&g_map), 1); + input_init(g_mlx, g_win); + mlx_loop_hook(g_mlx, loop_hook, NULL); + draw_screen(); + mlx_loop(g_mlx); + return (destroy_g_mlx_g_win_and_map(&g_map), g_return_value); } diff --git a/src/map1.c b/src/map1.c index 5ed80db..5f25ca5 100644 --- a/src/map1.c +++ b/src/map1.c @@ -64,7 +64,7 @@ bool map_from_file(t_map *dest, const char *file) stream.str = read_all_text(fd); if (!stream.str) { - write_err("Can't read file.\n", NULL); + write_err(strerror(errno), NULL); close(fd); return (false); } @@ -86,6 +86,7 @@ void map_destroy(t_map *map) d++; } free(map->cases); + ft_bzero(map, sizeof(t_map)); } static bool check_map2(const t_map *map, unsigned int x, unsigned int y) diff --git a/src/map_utils.h b/src/map_utils.h index 11ece40..ddb862d 100644 --- a/src/map_utils.h +++ b/src/map_utils.h @@ -18,7 +18,9 @@ # include "stream.h" /// @brief Read a parameter of the map which has a color as an argument. -/// Color format: [0-255],[0-255],[0-255] +/// Color format: [0-255],[0-255],[0-255]. +/// If redefined, write an error text. +/// /// @param name Name of the parameter. /// @param dest Will be set to the value of the parameter. /// Unchanged if error. @@ -31,6 +33,8 @@ bool read_color_parameter(const char *name, t_color *dest, t_stream *stream, bool *redefined); /// @brief Read a parameter of the map which has a string as an argument. +/// If redefined, write an error text. +/// /// @param name Name of the parameter. /// @param dest Will be set to an alloc'd pointer to the value of the parameter. /// Unchanged if error. @@ -44,12 +48,14 @@ bool read_string_parameter(const char *name, const char **dest, /// @brief Read a map-formatted string. /// If an error occurs, write an error message on stderr. +/// /// @param dest Will be set to the map. /// @param stream Stream to use. /// @return true if success, false if error. bool read_map(t_map *dest, t_stream *stream); /// @brief Get the case associated with the char. +/// If an error occurs, write an error message on stderr. /// /// @param dest Will be set to the char. /// @param name Name of the case. @@ -64,6 +70,7 @@ void fill_zeros(void *dest, size_t size); /// @brief Read the map description part of the map. /// Read until the end of the file. +/// If an error occurs, write an error message on stderr. /// /// @param map The .width, .height and .cases members will be set. /// @param stream Stream to use. @@ -71,11 +78,18 @@ void fill_zeros(void *dest, size_t size); bool read_map_description(t_map *map, t_stream *stream); /// @brief Initialize map->player. +/// If error, write an error text. +/// /// @param map Map to use. /// @return true if success, false if error /// (0 or >2 players found instead of only one). bool map_init_player(t_map *map); +/// @brief Init map->textures from map->texture_srcs. +/// If error, write an error text and destroy map. +/// +/// @param map Map to use. +/// @return true if success, false if error. bool load_textures(t_map *map); #endif diff --git a/src/map_utils1.c b/src/map_utils1.c index 46fd51a..938bc90 100644 --- a/src/map_utils1.c +++ b/src/map_utils1.c @@ -24,11 +24,11 @@ bool read_color_parameter(const char *name, t_color *dest, read_expected_string(name, stream, &err); if (!read_blank(stream)) err = true; - read_unsigned(&rgb[0], stream, &err); + read_unsigned_max_255(&rgb[0], stream, &err); read_expected_string(",", stream, &err); - read_unsigned(&rgb[1], stream, &err); + read_unsigned_max_255(&rgb[1], stream, &err); read_expected_string(",", stream, &err); - read_unsigned(&rgb[2], stream, &err); + read_unsigned_max_255(&rgb[2], stream, &err); read_expected_string("\n", stream, &err); if (!err && *dest != 0xFF000000) { diff --git a/src/map_utils2.c b/src/map_utils2.c index e2cc612..2e4f588 100644 --- a/src/map_utils2.c +++ b/src/map_utils2.c @@ -113,6 +113,13 @@ bool load_textures(t_map *map) map->textures[d].image = mlx_xpm_file_to_image(g_mlx, (char *)(map->texture_srcs[d]), &map->textures[d].width, &map->textures[d].height); + if (!map->textures[d].image) + { + write_err("The texture file '", map->texture_srcs[d], + "' can't be opened.\n", NULL); + map_destroy(map); + return (false); + } d++; } return (true); diff --git a/src/minimap_inline.h b/src/minimap_inline.h index c5f003b..e36ecdb 100644 --- a/src/minimap_inline.h +++ b/src/minimap_inline.h @@ -18,11 +18,21 @@ # include "const.h" +/// @brief Return the distance between the two points. +/// +/// @param a Point A. +/// @param b Point B. +/// @return Distance. static inline double distance_between(t_point_double a, t_point_double b) { return (sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y))); } +/// @brief Return the distance between the two points. +/// +/// @param a Point A. +/// @param b Point B. +/// @return Distance. static inline double distance_between_int(t_point_int a, t_point_int b) { return (sqrt((double)( @@ -30,6 +40,12 @@ static inline double distance_between_int(t_point_int a, t_point_int b) ))); } +/// @brief From a pixel position on the minimap relative to the window, +/// get the corresponding position on the map. +/// +/// @param pixel Position of the pixel on the minimap. +/// @param scale Scale of the map. +/// @return Position on the map. static inline t_point_double pixel_to_pos(t_point_int pixel, double scale) { return ((t_point_double){ @@ -38,12 +54,18 @@ static inline t_point_double pixel_to_pos(t_point_int pixel, double scale) }); } -static inline double get_angle(t_point_int base, t_point_int vector) +/// @brief Get the angle of the vector AB. (0, -1) is 0 rad, (1, 0) is PI/2 rad. +/// +/// @param A Point A. +/// @param B Point B. +/// @return Resulting angle in rad. +static inline double get_angle(t_point_int A, t_point_int B) { - double r; + double r; + t_point_int vector; - vector.x -= base.x; - vector.y -= base.y; + vector.x = B.x - A.x; + vector.y = B.y - A.y; if (!vector.y) { if (vector.x > 0) @@ -58,6 +80,11 @@ static inline double get_angle(t_point_int base, t_point_int vector) return (r); } +/// @brief Check if an angle is between two other angles. +/// @param angle Angle to test. +/// @param min Minimum angle. +/// @param max Maximum angle. +/// @return Either 'angle' is between 'min' and 'max'. static inline bool angle_in_between(double angle, double min, double max) { while (max < min) diff --git a/src/minimap_inline2.h b/src/minimap_inline2.h index a69f535..6eb416f 100644 --- a/src/minimap_inline2.h +++ b/src/minimap_inline2.h @@ -15,16 +15,25 @@ # include "minimap.h" +// Gamma correction. static inline double srgb_to_gamma(u_int8_t value) { return (pow((double)value / 0xFF, 2.2)); } +// Inverts the gamma correction. Inverts srgb_to_gamma. static inline u_int8_t gamma_to_srgb(double value) { return (pow((double)value, 1 / 2.2) * 0xFF); } +/// @brief Draw a color on a pixel with a specific opacity. +/// +/// @param pixel Pixel to draw on. +/// @param color Color to use. +/// @param opacity Opacity to use. If 0, 'pixel' is unchanged. If 1, 'pixel' +/// is set to 'color'. If outside of [0;1], the closest value is +/// used. static inline void draw_transparent_pixel(u_int32_t *pixel, u_int32_t color, double opacity) { diff --git a/src/move_utils.h b/src/move_utils.h index f7f69f6..f6c8cb9 100644 --- a/src/move_utils.h +++ b/src/move_utils.h @@ -13,6 +13,7 @@ #ifndef MOVE_UTILS_H # define MOVE_UTILS_H +/// @brief If the player is in a wall, move it outside of the wall. void push_from_walls(void); #endif diff --git a/src/stream.c b/src/stream.c index d1506b8..50dddf5 100644 --- a/src/stream.c +++ b/src/stream.c @@ -42,7 +42,7 @@ static bool is_digit(char c) return (c >= '0' && c <= '9'); } -void read_unsigned(unsigned int *dest, t_stream *stream, bool *err) +void read_unsigned_max_255(unsigned int *dest, t_stream *stream, bool *err) { int r; @@ -60,6 +60,11 @@ void read_unsigned(unsigned int *dest, t_stream *stream, bool *err) r = r * 10 + stream->str[stream->i] - '0'; stream->i++; } + if (r < 0 || r > 255) + { + *err = true; + return ; + } *dest = r; } diff --git a/src/utils2.c b/src/utils2.c index 960ef72..81f2649 100644 --- a/src/utils2.c +++ b/src/utils2.c @@ -29,7 +29,7 @@ u_int32_t *get_data_addr(void *img_ptr) return (r); } -t_color color_from_rgb(int red, int green, int blue) +t_color color_from_rgb(u_int8_t red, u_int8_t green, u_int8_t blue) { return (red << 16 | green << 8 | blue); } diff --git a/src/utils_timedloop_nobonus.c b/src/utils_timedloop_nobonus.c index 26d6c1e..8b3c6b3 100644 --- a/src/utils_timedloop_nobonus.c +++ b/src/utils_timedloop_nobonus.c @@ -12,11 +12,13 @@ #include "utils.h" +#include "const.h" + void timedloop(void (*f)(void)) { static int ticks; - if (ticks % 100 == 0) + if (ticks % NOBONUS_SPEED == 0) f(); ticks++; } diff --git a/testmaps/good_reallyreallyweirdblank.cub b/testmaps/err_reallyreallyweirdblank.cub similarity index 100% rename from testmaps/good_reallyreallyweirdblank.cub rename to testmaps/err_reallyreallyweirdblank.cub diff --git a/testmaps/good_reallyweirdblank.cub b/testmaps/good_reallyweirdblank.cub index cb0bdff..3c10029 100644 --- a/testmaps/good_reallyweirdblank.cub +++ b/testmaps/good_reallyweirdblank.cub @@ -1,13 +1,13 @@ -F 255, 127 ,0 +F 255, 127 ,0 C 0, 2 , 67 -EA textures/east.xpm +EA textures/east.xpm NO textures/north.xpm -SO textures/south.xpm +SO textures/south.xpm From 189190b3c84897dcb5f0726ee5d83685e4c6c1e7 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 21 Nov 2024 15:24:26 +0100 Subject: [PATCH 75/80] fix: directions WEST and EAST --- src/move_utils.c | 8 ++++---- src/render_utils.c | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/move_utils.c b/src/move_utils.c index 695aac6..4772783 100644 --- a/src/move_utils.c +++ b/src/move_utils.c @@ -24,9 +24,9 @@ static void move_in_direction(t_point_double *pos, t_direction dir, pos->y -= value; else if (dir == SOUTH) pos->y += value; - else if (dir == EAST) - pos->x -= value; else if (dir == WEST) + pos->x -= value; + else if (dir == EAST) pos->x += value; } @@ -45,8 +45,8 @@ static void push_from_wall(int cx, int cy) { distance_with_side[NORTH] = p.y - (c_d.y - HITBOX); distance_with_side[SOUTH] = (c_d.y + 1 + HITBOX) - p.y; - distance_with_side[EAST] = p.x - (c_d.x - HITBOX); - distance_with_side[WEST] = (c_d.x + 1 + HITBOX) - p.x; + distance_with_side[WEST] = p.x - (c_d.x - HITBOX); + distance_with_side[EAST] = (c_d.x + 1 + HITBOX) - p.x; d_min = 0; d = 0; while (++d < 4) diff --git a/src/render_utils.c b/src/render_utils.c index 6db8d0a..2a4a16e 100644 --- a/src/render_utils.c +++ b/src/render_utils.c @@ -22,16 +22,16 @@ void calculate_texdir_and_wallx(t_ray *ray) if (ray->side && ray->dir.y >= 0) ray->texdir = SOUTH; if (!ray->side && ray->dir.x < 0) - ray->texdir = EAST; - if (!ray->side && ray->dir.x >= 0) ray->texdir = WEST; + if (!ray->side && ray->dir.x >= 0) + ray->texdir = EAST; if (!ray->side) ray->wallx = g_map.player.pos.y + ray->perpwalldist \ * ray->dir.y; else ray->wallx = g_map.player.pos.x + ray->perpwalldist \ * ray->dir.x; - if (ray->texdir == SOUTH || ray->texdir == EAST) + if (ray->texdir == SOUTH || ray->texdir == WEST) ray->wallx = -ray->wallx; ray->wallx -= floor((ray->wallx)); } From decd33cafb1663d0d6bc8d2d486a7c7f2bcfa1d0 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 21 Nov 2024 15:53:39 +0100 Subject: [PATCH 76/80] clean TODO --- dev/TODO | 6 ------ 1 file changed, 6 deletions(-) diff --git a/dev/TODO b/dev/TODO index 6632cc5..bb253ca 100644 --- a/dev/TODO +++ b/dev/TODO @@ -5,9 +5,3 @@ TODO check when project is finished: - separate mandatory and bonus - check used functions (no error found at ec6d593) - check norminette on cluster - -TODO: better timedloop for bonus -TODO: map parsing: fix segfault if bad texture -TODO: map parsing: fix when color value > 255 -TODO: what if the pointer goes outside of the window? -TODO: fix inverted west and east textures From a41dae7d23c8795d32ba179225a160c5d3a1ee47 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 21 Nov 2024 16:08:46 +0100 Subject: [PATCH 77/80] add: switch to use/free the pointer --- src/input.c | 2 ++ src/input_utils.c | 33 ++++++++++++++++++++++++++++----- src/input_utils.h | 4 ++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/input.c b/src/input.c index 3e2a1d1..f676654 100644 --- a/src/input.c +++ b/src/input.c @@ -60,4 +60,6 @@ void input_init(void *mlx_ptr, void *win_ptr) mlx_hook(win_ptr, KeyPress, KeyPressMask, hook_keypress, NULL); mlx_hook(win_ptr, KeyRelease, KeyReleaseMask, hook_keyrelease, NULL); mlx_hook(win_ptr, MotionNotify, PointerMotionMask, hook_mousemove, NULL); + mlx_hook(win_ptr, ButtonPress, ButtonPressMask, hook_buttonpress, NULL); + printf(MOUSE_UNUSED_MSG); } diff --git a/src/input_utils.c b/src/input_utils.c index 1aff5af..814f2df 100644 --- a/src/input_utils.c +++ b/src/input_utils.c @@ -16,6 +16,8 @@ #include "utils.h" #include "global.h" +static bool g_intercept_mouse = false; + int hook_mousemove(int x, int y) { static const t_point_int window_middle = { @@ -23,10 +25,31 @@ int hook_mousemove(int x, int y) static bool first_call = true; const int dx = x - window_middle.x; - if (!first_call && dx) - g_input_actions.rotate += dx; - first_call = false; - if (x != window_middle.x || y != window_middle.y) - mlx_mouse_move(g_mlx, g_win, window_middle.x, window_middle.y); + if (g_intercept_mouse) + { + if (!first_call && dx) + g_input_actions.rotate += dx; + first_call = false; + if (x != window_middle.x || y != window_middle.y) + mlx_mouse_move(g_mlx, g_win, window_middle.x, window_middle.y); + } + return (0); +} + +int hook_buttonpress(int button) +{ + static const t_point_int window_middle = { + SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2}; + if (button == Button1) + { + g_intercept_mouse = !g_intercept_mouse; + if (g_intercept_mouse) + { + mlx_mouse_move(g_mlx, g_win, window_middle.x, window_middle.y); + printf(MOUSE_USED_MSG); + } + else + printf(MOUSE_UNUSED_MSG); + } return (0); } diff --git a/src/input_utils.h b/src/input_utils.h index 6e4b216..b12f669 100644 --- a/src/input_utils.h +++ b/src/input_utils.h @@ -15,6 +15,10 @@ # include "input.h" +# define MOUSE_UNUSED_MSG "Click in the window to use the pointer.\n" +# define MOUSE_USED_MSG "Click again to free the pointer.\n" + int hook_mousemove(int x, int y); +int hook_buttonpress(int button); #endif From 041bce29810075974c77fcc6d181843354e09570 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 21 Nov 2024 16:11:42 +0100 Subject: [PATCH 78/80] dev: clean TODO --- src/input.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/input.c b/src/input.c index f676654..1e6c8a8 100644 --- a/src/input.c +++ b/src/input.c @@ -51,7 +51,6 @@ static int hook_keyrelease(int keycode) return (0); } -// TODO hide cursor without leak? void input_init(void *mlx_ptr, void *win_ptr) { (void)mlx_ptr; From da5f45a32efee4217397b331619cb2352940f7bf Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 21 Nov 2024 16:21:44 +0100 Subject: [PATCH 79/80] norm --- include/const.h | 2 +- src/input_utils.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/const.h b/include/const.h index 6accd5f..38fe110 100644 --- a/include/const.h +++ b/include/const.h @@ -19,7 +19,7 @@ # define FPS 30 // Number of frames per second (bonus only) # define NOBONUS_SPEED 500 // Number of calls to timedloop for one frame - // (mandatory only) +// (mandatory only) # define MOVE_SPEED 0.1 // Player oves by N cases by tick # define ROT_SPEED_DIVIDE_PI 32 // Player turns by pi/N rad by tick diff --git a/src/input_utils.c b/src/input_utils.c index 814f2df..ae3f6dd 100644 --- a/src/input_utils.c +++ b/src/input_utils.c @@ -40,6 +40,7 @@ int hook_buttonpress(int button) { static const t_point_int window_middle = { SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2}; + if (button == Button1) { g_intercept_mouse = !g_intercept_mouse; From 607302bebb0b9187404408c33591cbcb3c09c96a Mon Sep 17 00:00:00 2001 From: mcolonna Date: Fri, 22 Nov 2024 12:12:55 +0100 Subject: [PATCH 80/80] change: adapt to cluster screen size --- include/const.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/const.h b/include/const.h index 38fe110..ef82548 100644 --- a/include/const.h +++ b/include/const.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 17:00:59 by mcolonna #+# #+# */ -/* Updated: 2024/11/19 15:29:31 by mcolonna ### ########.fr */ +/* Updated: 2024/11/22 12:11:11 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,7 @@ # define MOVE_SPEED 0.1 // Player oves by N cases by tick # define ROT_SPEED_DIVIDE_PI 32 // Player turns by pi/N rad by tick -# define MOUSE_ROTATION_SPEED 0.001 // Rotation speed from mouse: rad/px +# define MOUSE_ROTATION_SPEED 0.0005 // Rotation speed from mouse: rad/px # define HITBOX 0.25 // Hitbox of N cases around player. # ifdef BONUS @@ -31,8 +31,8 @@ # else # define WINDOW_NAME "cub3d (mandatory)" # endif -# define SCREEN_WIDTH 640 // Width of the window -# define SCREEN_HEIGHT 480 // Height of the window +# define SCREEN_WIDTH 1280 // Width of the window +# define SCREEN_HEIGHT 960 // Height of the window # define FOV 0.66 // Width of the view plane (unit: cases)