This commit is contained in:
gbrochar 2020-11-22 17:31:49 +01:00
parent 0d1a909b61
commit 332b816621
87 changed files with 3093 additions and 1 deletions

43
Makefile Normal file
View File

@ -0,0 +1,43 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: gbrochar <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2016/05/10 02:28:41 by gbrochar #+# #+# #
# Updated: 2016/06/22 04:27:12 by gbrochar ### ########.fr #
# #
# **************************************************************************** #
NAME = wolf3d
SRC = main.c \
event_hook.c \
parsing.c \
parsing_2.c \
pixel_put.c \
run_game.c
OBJ = $(SRC:.c=.o)
FLAGS = -Wall -Werror -Wextra -g3
all: $(NAME)
$(NAME):
make -C libft
gcc $(FLAGS) -c $(SRC)
gcc $(OBJ) -o $(NAME) libft/libft.a -lm \
-lmlx -framework Appkit -framework OpenGL
clean:
make -C libft clean
rm -f $(OBJ)
fclean: clean
make -C libft fclean
rm -f $(NAME)
rm -rf wolf3d.dSYM
re: fclean all

View File

@ -1,3 +1,5 @@
# wolf3d
wolf3d : a raycasting engine made using minilibx. It features texture mapping and custom maps parsing.
wolf3d : a raycasting engine made using minilibx. It features texture mapping and custom maps parsing.
You need to have to minilibx installed to run it. It will not compile on linux systems.

1
auteur Normal file
View File

@ -0,0 +1 @@
gbrochar

104
event_hook.c Normal file
View File

@ -0,0 +1,104 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* event_hook.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/05/10 02:38:27 by gbrochar #+# #+# */
/* Updated: 2016/06/22 05:25:31 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf3d.h"
int red_cross(void)
{
exit(0);
}
int check_wall(t_env *e, int keycode)
{
double c_sin;
double c_cos;
c_sin = sin((e->camera_alpha - e->fov) / RAD) * 0.3;
c_cos = cos((e->camera_alpha - e->fov) / RAD) * 0.3;
if (keycode == 13 && e->map[(int)(e->camera_z - c_sin)]
[(int)(e->camera_x + c_cos)] == 1)
return (1);
if (keycode == 1 && e->map[(int)(e->camera_z + c_sin)]
[(int)(e->camera_x - c_cos)] == 1)
return (1);
if (keycode == 0 && e->map[(int)(e->camera_z + c_cos)]
[(int)(e->camera_x + c_sin)] == 1)
return (1);
if (keycode == 2 && e->map[(int)(e->camera_z - c_cos)]
[(int)(e->camera_x - c_sin)] == 1)
return (1);
return (0);
}
void check_movement(int keycode, t_env *e)
{
if (keycode == 13 || keycode == 126)
if (check_wall(e, 13) == 0)
{
e->camera_z -= sin((e->camera_alpha - e->fov) / RAD) * e->sprint;
e->camera_x += cos((e->camera_alpha - e->fov) / RAD) * e->sprint;
}
if (keycode == 1 || keycode == 125)
if (check_wall(e, 1) == 0)
{
e->camera_z += sin((e->camera_alpha - e->fov) / RAD) * e->sprint;
e->camera_x -= cos((e->camera_alpha - e->fov) / RAD) * e->sprint;
}
if (keycode == 0 || keycode == 123)
if (check_wall(e, 0) == 0)
{
e->camera_z += cos((e->camera_alpha - e->fov) / RAD) * e->sprint;
e->camera_x += sin((e->camera_alpha - e->fov) / RAD) * e->sprint;
}
if (keycode == 2 || keycode == 124)
if (check_wall(e, 2) == 0)
{
e->camera_z -= cos((e->camera_alpha - e->fov) / RAD) * e->sprint;
e->camera_x -= sin((e->camera_alpha - e->fov) / RAD) * e->sprint;
}
}
int key_hook(int keycode, void *e_void)
{
t_env *e;
e = (t_env *)e_void;
check_movement(keycode, e);
if (keycode == 12)
e->camera_alpha -= 5;
if (keycode == 14)
e->camera_alpha += 5;
if (keycode == 257)
e->sprint = (e->sprint == 0.1) ? 0.2 : 0.1;
if (keycode == 53)
{
free(e->map);
exit(0);
}
if (keycode == 78 && e->sensivity > 0.2)
e->sensivity -= 0.1;
if (keycode == 69 && e->sensivity < 2)
e->sensivity += 0.1;
ray_cast(e);
return (0);
}
int cursor_hook(int x, int y, void *e_void)
{
t_env *e;
e = (t_env *)e_void;
y = 0;
e->camera_alpha = (int)((double)x * e->sensivity) % 360;
ray_cast(e);
return (0);
}

48
libft/Makefile Normal file
View File

@ -0,0 +1,48 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: gbrochar <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2015/11/27 19:26:17 by gbrochar #+# #+# #
# Updated: 2016/05/31 08:52:14 by gbrochar ### ########.fr #
# #
# **************************************************************************** #
NAME = libft.a
SRC = ft_atoi.c ft_bzero.c ft_isalnum.c ft_isalpha.c ft_isascii.c ft_isdigit.c \
ft_isprint.c ft_isspace.c ft_itoa.c ft_lstadd.c ft_lstdel.c ft_lstdelone.c \
ft_lstiter.c ft_lstmap.c ft_lstnew.c ft_memalloc.c ft_memccpy.c ft_memchr.c \
ft_memcmp.c ft_memcpy.c ft_memdel.c ft_memmove.c ft_memset.c ft_power.c \
ft_putchar.c ft_putchar_fd.c ft_putendl.c ft_putendl_fd.c ft_putnbr.c \
ft_putnbr_fd.c ft_putstr.c ft_putstr_fd.c ft_sort_int.c ft_sqrt.c ft_strcat.c \
ft_strchr.c ft_strclr.c ft_strcmp.c ft_strcpy.c ft_strdel.c ft_strdup.c \
ft_strequ.c ft_striter.c ft_striteri.c ft_strjoin.c ft_strlcat.c ft_strlen.c \
ft_strmap.c ft_strmapi.c ft_strncat.c ft_strncmp.c ft_strncpy.c ft_strnequ.c \
ft_strnew.c ft_strnstr.c ft_strrchr.c ft_strsplit.c ft_strstr.c ft_strsub.c \
ft_strtrim.c ft_swap.c ft_tolower.c ft_toupper.c ft_lstadd_preview.c \
ft_get_last_node.c ft_ishexdigit.c ft_atoi_len.c ft_atoi_color.c ft_error.c \
get_next_line.c ft_strtab_isdigit.c ft_atoi_split.c
OBJ = $(SRC:.c=.o)
CC = gcc
FLAGS = # -Wall -Werror -Wextra -g
all: $(NAME)
$(NAME):
$(CC) $(FLAGS) -c $(SRC)
ar rc $(NAME) $(OBJ)
ranlib $(NAME)
clean:
rm -f $(OBJ)
fclean: clean
rm -f $(NAME)
re: fclean all

32
libft/ft_atoi.c Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/27 19:18:43 by gbrochar #+# #+# */
/* Updated: 2015/12/05 15:01:36 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
long result;
long sign;
result = 0;
while (ft_isspace(*str))
str++;
sign = (*str == '-') ? -1 : 1;
if (*str == '-' || *str == '+')
str++;
while (*str >= '0' && *str <= '9')
{
result = (result * 10) + (*str - '0');
str++;
}
return ((int)(result * sign));
}

33
libft/ft_atoi_color.c Normal file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi_color.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/27 19:18:43 by gbrochar #+# #+# */
/* Updated: 2016/05/06 10:25:37 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi_color(char *hexa_color)
{
int i;
int result;
result = 0;
i = 5;
while (i >= 0)
{
if (hexa_color[i] >= '0' && hexa_color[i] <= '9')
result += (hexa_color[i] - '0') * ft_power(16, (6 - i));
else if (hexa_color[i] >= 'A' && hexa_color[i] <= 'F')
result += (hexa_color[i] - '0') * ft_power(16, (6 - i));
else
return (-1);
i--;
}
return (result);
}

35
libft/ft_atoi_len.c Normal file
View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi_len.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/27 19:18:43 by gbrochar #+# #+# */
/* Updated: 2016/05/06 11:45:55 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi_len(char *str, int *len)
{
int result;
int sign;
result = 0;
*len = 0;
sign = (*str == '-') ? -1 : 1;
if (*str == '-' || *str == '+')
{
str++;
len++;
}
while (*str >= '0' && *str <= '9')
{
result = (result * 10) + (*str - '0');
str++;
len++;
}
return (result * sign);
}

38
libft/ft_atoi_split.c Normal file
View File

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/05/31 08:52:54 by gbrochar #+# #+# */
/* Updated: 2016/06/21 22:19:03 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int *ft_atoi_split(char *str, char c, int *tab_len)
{
int *tab;
char **str_tab;
int i;
if (!str || ft_isdigit(c))
return (NULL);
str_tab = ft_strsplit(str, c);
i = 0;
while (str_tab[i])
++i;
if (!(tab = (int *)malloc((i + 1) * sizeof(int))))
return (NULL);
*tab_len = i;
i = -1;
while (str_tab[++i])
tab[i] = atoi(str_tab[i]);
i = 0;
while (str_tab[i])
free(str_tab[i++]);
free(str_tab);
return (tab);
}

25
libft/ft_bzero.c Normal file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/24 11:39:18 by gbrochar #+# #+# */
/* Updated: 2015/11/24 20:46:21 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_bzero(void *s, size_t n)
{
char *byte;
byte = s;
while (n-- > 0)
{
*byte = 0;
byte++;
}
}

19
libft/ft_error.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_error.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/05/10 02:34:40 by gbrochar #+# #+# */
/* Updated: 2016/05/11 10:55:43 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_error(char *str)
{
ft_putstr_fd(str, 2);
exit(0);
}

23
libft/ft_get_last_node.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_get_last_node.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/02/28 07:10:21 by gbrochar #+# #+# */
/* Updated: 2016/02/28 07:12:12 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_get_last_node(t_list **alst)
{
t_list *tmp;
tmp = *alst;
while (tmp->next)
tmp = tmp->next;
return (tmp);
}

18
libft/ft_isalnum.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/27 18:51:03 by gbrochar #+# #+# */
/* Updated: 2015/11/28 15:22:14 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalnum(int c)
{
return (ft_isalpha(c) || ft_isdigit(c));
}

18
libft/ft_isalpha.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/27 18:59:08 by gbrochar #+# #+# */
/* Updated: 2015/11/28 15:42:21 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalpha(int c)
{
return (((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ? 1 : 0));
}

18
libft/ft_isascii.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/27 18:48:25 by gbrochar #+# #+# */
/* Updated: 2015/11/28 15:32:54 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isascii(int c)
{
return ((c >= 0 && c <= 127) ? 1 : 0);
}

18
libft/ft_isdigit.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/27 18:53:19 by gbrochar #+# #+# */
/* Updated: 2015/11/28 14:41:12 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isdigit(int c)
{
return ((c >= '0' && c <= '9') ? 1 : 0);
}

20
libft/ft_ishexdigit.c Normal file
View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ishexdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/05/05 23:22:51 by gbrochar #+# #+# */
/* Updated: 2016/05/05 23:24:26 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_ishexdigit(int c)
{
if (ft_isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))
return (1);
return (0);
}

18
libft/ft_isprint.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/27 18:44:48 by gbrochar #+# #+# */
/* Updated: 2015/11/28 15:33:24 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isprint(int c)
{
return ((c >= 32 && c <= 126) ? 1 : 0);
}

21
libft/ft_isspace.c Normal file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isspace.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/28 14:37:03 by gbrochar #+# #+# */
/* Updated: 2015/11/28 14:39:18 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isspace(int c)
{
if (c == '\t' || c == '\n' || c == '\f' || c == '\v' || c == '\r'
|| c == ' ')
return (1);
return (0);
}

37
libft/ft_itoa.c Normal file
View File

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/29 09:56:59 by gbrochar #+# #+# */
/* Updated: 2015/12/05 16:22:09 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_itoa(int n)
{
char *str;
size_t str_size;
int n_mem;
n_mem = n;
str_size = (n < 0) ? 3 : 2;
while ((n > 9 || n < -9) && str_size++)
n /= 10;
str = (char *)malloc((str_size--) * sizeof(char));
if (!str)
return (NULL);
str[str_size--] = '\0';
while (n_mem > 9 || n_mem < -9)
{
str[str_size--] = (n_mem < 0) ? -(n_mem % 10) + '0' : n_mem % 10 + '0';
n_mem = n_mem / 10;
}
str[0] = (n_mem < 0) ? '-' : (n_mem + '0');
str[1] = (n_mem < 0) ? (-n_mem + '0') : str[1];
return (str);
}

23
libft/ft_lstadd.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/12/01 14:24:17 by gbrochar #+# #+# */
/* Updated: 2016/02/26 14:02:54 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd(t_list **alst, t_list *new)
{
t_list *tmp;
tmp = *alst;
while (tmp->next != NULL)
tmp = tmp->next;
tmp->next = new;
}

19
libft/ft_lstadd_preview.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_preview.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/12/01 14:24:17 by gbrochar #+# #+# */
/* Updated: 2016/02/26 14:01:33 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_preview(t_list **alst, t_list *new)
{
new->next = *alst;
*alst = new;
}

25
libft/ft_lstdel.c Normal file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/30 21:34:50 by gbrochar #+# #+# */
/* Updated: 2015/12/05 15:10:37 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstdel(t_list **alst, void (*del)(void *, size_t))
{
t_list *tmp;
while (*alst)
{
tmp = *alst;
ft_lstdelone(alst, del);
*alst = tmp->next;
}
}

19
libft/ft_lstdelone.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/30 21:27:05 by gbrochar #+# #+# */
/* Updated: 2015/12/02 13:28:32 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t))
{
del((*alst)->content, (*alst)->content_size);
ft_memdel((void **)alst);
}

29
libft/ft_lstiter.c Normal file
View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/12/02 13:38:16 by gbrochar #+# #+# */
/* Updated: 2015/12/04 16:41:19 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstiter(t_list *lst, void (*f)(t_list *elem))
{
t_list *start;
t_list *tmp;
start = lst;
while (lst->next)
{
tmp = lst;
f(lst);
lst = tmp->next;
}
f(lst);
lst = start;
}

31
libft/ft_lstmap.c Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/12/02 14:33:07 by gbrochar #+# #+# */
/* Updated: 2015/12/02 16:17:18 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
t_list *lst_begin;
t_list *lst_new;
lst_begin = ft_lstnew((f(lst))->content, (f(lst))->content_size);
lst_new = lst_begin;
lst = lst->next;
while (lst->next)
{
lst_new->next = ft_lstnew((f(lst))->content, (f(lst))->content_size);
lst_new = lst_new->next;
lst = lst->next;
}
lst_new->next = ft_lstnew((f(lst))->content, (f(lst))->content_size);
return (lst_begin);
}

40
libft/ft_lstnew.c Normal file
View File

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/30 21:21:09 by gbrochar #+# #+# */
/* Updated: 2016/02/27 21:04:51 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstnew(void const *content, size_t content_size)
{
t_list *lst;
lst = (t_list *)malloc(sizeof(t_list));
if (!lst)
return (NULL);
if (!content)
{
lst->content = NULL;
lst->content_size = 0;
}
else
{
lst->content = ft_memalloc(content_size);
if (!lst->content)
{
free(lst);
return (NULL);
}
ft_memmove(lst->content, content, content_size);
lst->content_size = content_size;
}
lst->next = NULL;
return (lst);
}

27
libft/ft_memalloc.c Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memalloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/28 18:11:36 by gbrochar #+# #+# */
/* Updated: 2016/02/27 21:04:55 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memalloc(size_t size)
{
unsigned char *ptr;
size_t i;
i = 0;
ptr = (unsigned char *)malloc(size);
if (!ptr)
return (NULL);
while (i < size)
ptr[i++] = 0;
return (ptr);
}

37
libft/ft_memccpy.c Normal file
View File

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memccpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/24 14:40:00 by gbrochar #+# #+# */
/* Updated: 2015/12/08 14:37:54 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
{
size_t i;
unsigned char to_find;
unsigned char *dst_byte;
unsigned char *src_byte;
to_find = (unsigned char)c;
i = 0;
dst_byte = (unsigned char *)dst;
src_byte = (unsigned char *)src;
while (i != n && src_byte[i] != to_find)
{
dst_byte[i] = src_byte[i];
i++;
}
if (src_byte[i] == to_find)
{
dst_byte[i] = to_find;
return (&dst[i + 1]);
}
return (NULL);
}

31
libft/ft_memchr.c Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/25 13:03:54 by gbrochar #+# #+# */
/* Updated: 2015/11/25 14:07:56 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned char to_find;
unsigned char *str;
size_t i;
i = 0;
to_find = c;
str = (unsigned char *)s;
while (i < n)
{
if (str[i] == to_find)
return ((void *)&s[i]);
i++;
}
return (NULL);
}

33
libft/ft_memcmp.c Normal file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/25 14:13:46 by gbrochar #+# #+# */
/* Updated: 2015/11/30 14:46:05 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
unsigned char *s1_byte;
unsigned char *s2_byte;
size_t i;
s1_byte = (unsigned char *)s1;
s2_byte = (unsigned char *)s2;
i = 0;
if (n <= 0)
return (0);
while (s1_byte[i] == s2_byte[i])
{
if (i + 1 == n)
return (0);
i++;
}
return (s1_byte[i] - s2_byte[i]);
}

30
libft/ft_memcpy.c Normal file
View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/25 14:42:55 by gbrochar #+# #+# */
/* Updated: 2015/11/25 14:43:02 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memcpy(void *dst, const void *src, size_t n)
{
size_t i;
unsigned char *dst_byte;
const unsigned char *src_byte;
i = 0;
dst_byte = dst;
src_byte = src;
while (i < n)
{
dst_byte[i] = src_byte[i];
i++;
}
return (dst);
}

19
libft/ft_memdel.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/28 18:23:10 by gbrochar #+# #+# */
/* Updated: 2015/11/28 18:25:10 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_memdel(void **ap)
{
free(*ap);
*ap = NULL;
}

39
libft/ft_memmove.c Normal file
View File

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/25 12:36:04 by gbrochar #+# #+# */
/* Updated: 2015/11/25 13:03:31 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *dst, const void *src, size_t len)
{
unsigned char *dst_byte;
const unsigned char *src_byte;
size_t index;
dst_byte = dst;
src_byte = src;
if (dst_byte > src_byte)
{
index = len;
while (index-- > 0)
dst_byte[index] = src_byte[index];
}
else
{
index = 0;
while (index < len)
{
dst_byte[index] = src_byte[index];
index++;
}
}
return (dst);
}

28
libft/ft_memset.c Normal file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/23 17:53:16 by gbrochar #+# #+# */
/* Updated: 2015/11/25 12:18:32 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memset(void *b, int c, size_t len)
{
unsigned char *byte;
size_t i;
byte = b;
i = 0;
while (i++ < len)
{
*byte = c;
byte++;
}
return (b);
}

25
libft/ft_power.c Normal file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/12/05 15:23:07 by gbrochar #+# #+# */
/* Updated: 2015/12/07 11:03:41 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_power(int nb, int pow)
{
int ret;
ret = 1;
if (pow < 0)
return (-1);
while (pow--)
ret *= nb;
return (ret);
}

18
libft/ft_putchar.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/24 12:01:00 by gbrochar #+# #+# */
/* Updated: 2015/11/29 16:47:24 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putchar(char c)
{
write(1, &c, 1);
}

18
libft/ft_putchar_fd.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/29 09:01:19 by gbrochar #+# #+# */
/* Updated: 2015/11/29 09:02:06 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}

19
libft/ft_putendl.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/29 09:04:13 by gbrochar #+# #+# */
/* Updated: 2015/11/29 09:04:50 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putendl(char const *s)
{
ft_putstr(s);
ft_putchar('\n');
}

19
libft/ft_putendl_fd.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/29 09:04:58 by gbrochar #+# #+# */
/* Updated: 2015/11/29 09:05:51 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putendl_fd(char const *s, int fd)
{
ft_putstr_fd(s, fd);
ft_putchar_fd('\n', fd);
}

31
libft/ft_putnbr.c Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/29 08:58:30 by gbrochar #+# #+# */
/* Updated: 2015/11/29 10:49:28 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr(int n)
{
if (n == -2147483648)
ft_putstr("-2147483648");
else if (n < 0)
{
ft_putchar('-');
ft_putnbr(-n);
}
else if (n > 9)
{
ft_putnbr(n / 10);
ft_putchar(n % 10 + '0');
}
else
ft_putchar(n + '0');
}

31
libft/ft_putnbr_fd.c Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/29 09:10:52 by gbrochar #+# #+# */
/* Updated: 2015/11/29 10:49:38 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr_fd(int n, int fd)
{
if (n == -2147483648)
ft_putstr_fd("-2147483648", fd);
else if (n < 0)
{
ft_putchar_fd('-', fd);
ft_putnbr_fd(-n, fd);
}
else if (n > 9)
{
ft_putnbr_fd(n / 10, fd);
ft_putchar_fd(n % 10 + '0', fd);
}
else
ft_putchar_fd(n + '0', fd);
}

19
libft/ft_putstr.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/27 18:23:12 by gbrochar #+# #+# */
/* Updated: 2015/11/29 09:06:37 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putstr(char const *s)
{
while (*s)
write(1, s++, 1);
}

19
libft/ft_putstr_fd.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/29 09:02:48 by gbrochar #+# #+# */
/* Updated: 2015/11/29 09:04:05 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putstr_fd(char const *s, int fd)
{
while (*s)
write(fd, s++, 1);
}

33
libft/ft_sort_int.c Normal file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sort_int.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/12/05 18:36:08 by gbrochar #+# #+# */
/* Updated: 2015/12/07 11:04:19 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_sort_int(int *tab, int size)
{
int i;
int tmp;
i = 0;
while ((i + 1) < size)
{
if (tab[i] > tab[i + 1])
{
tmp = tab[i];
tab[i] = tab[i + 1];
tab[i + 1] = tmp;
i = 0;
}
else
i++;
}
}

23
libft/ft_sqrt.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sqrt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/12/07 08:28:11 by gbrochar #+# #+# */
/* Updated: 2015/12/07 08:50:43 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
long ft_sqrt(long n)
{
long sqrt;
sqrt = 0;
while ((sqrt * sqrt) != n && (sqrt * sqrt) < n)
sqrt++;
return (((sqrt * sqrt) == n) ? (sqrt) : (-1));
}

32
libft/ft_strcat.c Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/25 16:26:53 by gbrochar #+# #+# */
/* Updated: 2016/04/09 21:24:58 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strcat(char *s1, const char *s2)
{
char *p_s1;
const char *p_s2;
p_s2 = s2;
p_s1 = s1;
while (*p_s1)
p_s1++;
while (*p_s2)
{
*p_s1 = *p_s2;
p_s1++;
p_s2++;
}
*p_s1 = '\0';
return (s1);
}

23
libft/ft_strchr.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/27 09:50:37 by gbrochar #+# #+# */
/* Updated: 2016/04/09 21:28:38 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strchr(const char *s, int c)
{
if (s == NULL)
return (0);
while (*s != (char)c)
if (!*s++)
return (0);
return ((char *)s);
}

19
libft/ft_strclr.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strclr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/28 20:22:52 by gbrochar #+# #+# */
/* Updated: 2015/11/28 21:09:55 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_strclr(char *s)
{
while (*s)
*s++ = '\0';
}

21
libft/ft_strcmp.c Normal file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/28 14:52:37 by gbrochar #+# #+# */
/* Updated: 2015/11/28 15:34:12 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strcmp(const char *s1, const char *s2)
{
while (*s1 || *s2)
if (*s1++ != *s2++)
return ((unsigned char)*--s1 - (unsigned char)*--s2);
return (0);
}

30
libft/ft_strcpy.c Normal file
View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/25 15:10:54 by gbrochar #+# #+# */
/* Updated: 2016/04/09 16:49:30 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strcpy(char *dst, const char *src)
{
char *p_dest;
const char *p_src;
p_src = src;
p_dest = dst;
while (*p_src)
{
*p_dest = *p_src;
p_dest++;
p_src++;
}
*p_dest = '\0';
return (dst);
}

18
libft/ft_strdel.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/28 20:21:47 by gbrochar #+# #+# */
/* Updated: 2015/12/08 15:21:50 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_strdel(char **as)
{
ft_memdel((void **)as);
}

29
libft/ft_strdup.c Normal file
View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/25 14:47:23 by gbrochar #+# #+# */
/* Updated: 2016/04/09 21:27:37 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s1)
{
char *dest;
int i;
i = 0;
dest = ft_strnew(ft_strlen(s1));
while (s1[i])
{
dest[i] = s1[i];
i++;
}
dest[i] = '\0';
return (dest);
}

27
libft/ft_strequ.c Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strequ.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/29 08:35:37 by gbrochar #+# #+# */
/* Updated: 2015/11/29 15:47:45 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strequ(char const *s1, char const *s2)
{
int i;
i = 0;
while (s1[i] == s2[i])
{
if (s1[i] == '\0' && s2[i] == '\0')
return (1);
i++;
}
return (0);
}

25
libft/ft_striter.c Normal file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/28 20:37:55 by gbrochar #+# #+# */
/* Updated: 2015/11/29 10:51:54 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_striter(char *s, void (*f)(char *))
{
int i;
i = 0;
while (s[i])
{
f(&s[i]);
i++;
}
}

25
libft/ft_striteri.c Normal file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striteri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/28 21:02:16 by gbrochar #+# #+# */
/* Updated: 2015/11/29 10:30:40 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_striteri(char *s, void (*f)(unsigned int, char *s))
{
unsigned int i;
i = 0;
while (s[i])
{
f(i, &s[i]);
i++;
}
}

34
libft/ft_strjoin.c Normal file
View File

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/29 09:48:11 by gbrochar #+# #+# */
/* Updated: 2016/04/09 16:30:06 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, const char *s2)
{
size_t i;
char *new;
s1 = (s1 == NULL) ? "" : s1;
s2 = (s2 == NULL) ? "" : s2;
if (s1 && s2)
{
i = ft_strlen(s1) + ft_strlen(s2);
new = ft_strnew(i);
if (new)
{
new = ft_strcpy(new, s1);
new = ft_strcat(new, s2);
return (new);
}
}
return (NULL);
}

32
libft/ft_strlcat.c Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/26 08:00:59 by gbrochar #+# #+# */
/* Updated: 2015/11/29 15:48:23 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t dst_len;
size_t src_len;
size_t i_src;
size_t i_dst;
dst_len = ft_strlen(dst);
src_len = ft_strlen(src);
i_src = 0;
i_dst = dst_len;
if (dst_len >= size)
return (size + src_len);
while (src[i_src] && (size-- - (dst_len + 1)) > 0)
dst[i_dst++] = src[i_src++];
dst[i_dst] = '\0';
return (dst_len + src_len);
}

23
libft/ft_strlen.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/25 14:43:32 by gbrochar #+# #+# */
/* Updated: 2016/04/09 16:57:01 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlen(const char *s)
{
size_t i;
i = 0;
while (s && s[i])
i++;
return (i);
}

33
libft/ft_strmap.c Normal file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/28 21:30:34 by gbrochar #+# #+# */
/* Updated: 2015/11/29 16:53:26 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmap(char const *s, char (*f)(char))
{
char *str;
int i;
int len;
len = ft_strlen(s);
i = 0;
str = (char *)malloc((len + 1) * sizeof(char));
if (!str)
return (NULL);
while (i < len)
{
str[i] = f(s[i]);
i++;
}
str[len] = '\0';
return (str);
}

31
libft/ft_strmapi.c Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/28 21:39:30 by gbrochar #+# #+# */
/* Updated: 2015/12/02 16:22:05 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *str;
unsigned int i;
i = 0;
str = (char *)malloc((ft_strlen(s) + 1) * sizeof(char));
if (!str)
return (NULL);
while (s[i])
{
str[i] = f(i, s[i]);
i++;
}
str[i] = '\0';
return (str);
}

30
libft/ft_strncat.c Normal file
View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/25 19:29:04 by gbrochar #+# #+# */
/* Updated: 2015/11/29 12:33:35 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strncat(char *s1, const char *s2, size_t n)
{
size_t i_dst;
size_t i_src;
i_dst = ft_strlen(s1);
i_src = 0;
while (i_src < n && s2[i_src] != '\0')
{
s1[i_dst] = s2[i_src];
i_dst++;
i_src++;
}
s1[i_dst] = '\0';
return (s1);
}

21
libft/ft_strncmp.c Normal file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/28 14:57:36 by gbrochar #+# #+# */
/* Updated: 2015/11/28 15:34:45 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
while ((*s1 || *s2) && n--)
if (*s1++ != *s2++)
return ((unsigned char)*--s1 - (unsigned char)*--s2);
return (0);
}

31
libft/ft_strncpy.c Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/25 16:18:18 by gbrochar #+# #+# */
/* Updated: 2015/11/25 16:21:09 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strncpy(char *dst, const char *src, size_t n)
{
size_t i;
i = 0;
while (i != n && src[i] != '\0')
{
dst[i] = src[i];
i++;
}
while (i != n)
{
dst[i] = '\0';
i++;
}
return (dst);
}

27
libft/ft_strnequ.c Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnequ.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/29 08:37:07 by gbrochar #+# #+# */
/* Updated: 2015/12/05 16:24:50 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strnequ(char const *s1, char const *s2, size_t n)
{
size_t i;
i = 0;
while (s1[i] == s2[i] || i == n)
{
if ((s1[i] == '\0' && s2[i] == '\0') || i == n)
return (1);
i++;
}
return (0);
}

23
libft/ft_strnew.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/28 18:26:56 by gbrochar #+# #+# */
/* Updated: 2016/04/09 16:25:44 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnew(size_t size)
{
char *str;
str = (char *)malloc(sizeof(char) * (size + 1));
if (!str)
return (NULL);
return (str);
}

40
libft/ft_strnstr.c Normal file
View File

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/27 12:49:32 by gbrochar #+# #+# */
/* Updated: 2015/11/28 16:39:13 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *s1, char *s2, size_t n)
{
size_t i;
size_t i_mem;
size_t i_tofind;
i_mem = 0;
if (s2[0] == '\0')
return ((char *)s1);
while (s1[i_mem] != '\0' && i_mem < n)
{
i_tofind = 0;
while (s1[i_mem] != s2[i_tofind] && s1[i_mem] != '\0')
i_mem++;
if (s1[i_mem] == '\0')
return (NULL);
i = i_mem;
while ((s1[i] == s2[i_tofind] || s2[i_tofind] == '\0') && i++ <= n)
if (s2[i_tofind++] == '\0')
return ((char *)&s1[i_mem]);
if (i > n)
return (NULL);
i_mem++;
}
return (NULL);
}

28
libft/ft_strrchr.c Normal file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/27 10:05:56 by gbrochar #+# #+# */
/* Updated: 2015/11/27 10:24:37 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
int i;
i = ft_strlen(s);
if (c)
{
while (i--)
if (s[i] == (char)c)
return ((char *)&s[i]);
return (NULL);
}
return ((char *)&s[i]);
}

87
libft/ft_strsplit.c Normal file
View File

@ -0,0 +1,87 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsplit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/29 09:55:10 by gbrochar #+# #+# */
/* Updated: 2015/12/07 11:00:21 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_wordcount(char const *s, char c)
{
int word_count;
int i;
i = 0;
word_count = 0;
while (s[i] != '\0')
{
while (s[i] == c)
i++;
if (s[i] != '\0')
word_count++;
while (s[i] != c && s[i] != '\0')
i++;
}
return (word_count);
}
static void *ft_taballoc(char const *s, char **str_tab, char c)
{
int i;
int i2;
int wl;
i = 0;
i2 = 0;
while (s[i2])
{
wl = 0;
while (s[i2] == c && s[i2] != '\0')
i2++;
while (s[i2] != c && s[i2] != '\0')
{
wl++;
i2++;
}
if (wl != 0)
*str_tab++ = (char *)malloc((wl + 1) * sizeof(char));
if (!(str_tab - 1))
return (NULL);
}
return (*str_tab);
}
char **ft_strsplit(char const *s, char c)
{
char **str_tab;
int i;
int i2;
int i3;
int wc;
i = 0;
i3 = 0;
wc = ft_wordcount(s, c);
str_tab = (char **)malloc((wc + 1) * sizeof(char *));
if (!str_tab)
return (NULL);
ft_taballoc(s, str_tab, c);
while (i != wc)
{
i2 = 0;
while (s[i3] == c && s[i3] != '\0')
i3++;
while (s[i3] != c && s[i3] != '\0')
str_tab[i][i2++] = s[i3++];
str_tab[i][i2] = '\0';
i++;
}
str_tab[i] = NULL;
return (str_tab);
}

38
libft/ft_strstr.c Normal file
View File

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/27 10:24:53 by gbrochar #+# #+# */
/* Updated: 2015/11/28 16:38:40 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strstr(const char *s1, char *s2)
{
int i;
int i_mem;
int i_tofind;
i_mem = 0;
if (s2[0] == '\0')
return ((char *)s1);
while (s1[i_mem] != '\0')
{
i_tofind = 0;
while (s1[i_mem] != s2[i_tofind] && s1[i_mem] != '\0')
i_mem++;
if (s1[i_mem] == '\0')
return (NULL);
i = i_mem;
while (s1[i++] == s2[i_tofind] || s2[i_tofind] == '\0')
if (s2[i_tofind++] == '\0')
return ((char *)&s1[i_mem]);
i_mem++;
}
return (NULL);
}

28
libft/ft_strsub.c Normal file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsub.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/29 09:14:36 by gbrochar #+# #+# */
/* Updated: 2015/12/08 15:34:26 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strsub(char const *s, unsigned int start, size_t len)
{
char *str;
size_t i;
i = 0;
str = (char *)malloc((len + 1) * sizeof(char));
if (!str)
return (NULL);
while (i < len)
str[i++] = s[start++];
str[i] = '\0';
return (str);
}

33
libft/ft_strtab_isdigit.c Normal file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtab_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/05/31 08:48:47 by gbrochar #+# #+# */
/* Updated: 2016/05/31 08:50:05 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strtab_isdigit(char **strtab)
{
int i;
int j;
i = 0;
while (strtab[i])
{
j = 0;
while (strtab[i][j])
{
if (strtab[i][j] != ' ' && ft_isdigit(strtab[i][j] == 0))
return (0);
j++;
}
i++;
}
return (1);
}

40
libft/ft_strtrim.c Normal file
View File

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/29 09:54:12 by gbrochar #+# #+# */
/* Updated: 2015/12/07 11:00:33 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
char *str;
size_t i;
size_t i2;
size_t ws;
i = ft_strlen(s) - 1;
i2 = 0;
ws = 0;
while ((s[i] == ' ' || s[i] == '\n' || s[i] == '\t') && i--)
ws++;
i = 0;
while ((s[i] == ' ' || s[i] == '\n' || s[i] == '\t') && ws < ft_strlen(s))
{
i++;
ws++;
}
str = (char *)malloc((ft_strlen(s) + 1 - ws) * sizeof(char));
if (!str)
return (NULL);
while (i2 < (ft_strlen(s) - ws))
str[i2++] = s[i++];
str[i2] = '\0';
return (str);
}

22
libft/ft_swap.c Normal file
View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/12/07 09:44:07 by gbrochar #+# #+# */
/* Updated: 2015/12/07 11:01:13 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_swap(int *a, int *b)
{
int c;
c = *a;
*a = *b;
*b = c;
}

20
libft/ft_tolower.c Normal file
View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_tolower.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/27 18:39:55 by gbrochar #+# #+# */
/* Updated: 2015/11/29 08:40:07 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_tolower(int c)
{
if ((int)c >= 'A' && (int)c <= 'Z')
c += 32;
return (c);
}

20
libft/ft_toupper.c Normal file
View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_toupper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/27 18:43:24 by gbrochar #+# #+# */
/* Updated: 2015/11/28 16:01:01 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_toupper(int c)
{
if ((int)c >= 'a' && (int)c <= 'z')
c -= 32;
return (c);
}

95
libft/get_next_line.c Normal file
View File

@ -0,0 +1,95 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/03/22 00:00:51 by gbrochar #+# #+# */
/* Updated: 2016/05/30 16:26:59 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
char *ft_strjoin2(char *str, char *str2)
{
char *tmp;
tmp = ft_strjoin(str, str2);
free(str);
return (tmp);
}
int gnl_manage_return(char **line, char **stock)
{
char *tmp;
char *tmp2;
if ((tmp = ft_strchr(*stock, '\n')))
{
*tmp = '\0';
tmp2 = ft_strdup(tmp + 1);
*line = ft_strdup(*stock);
ft_memdel((void **)stock);
*stock = ft_strdup(tmp2);
free(tmp2);
tmp2 = NULL;
tmp = NULL;
return (1);
}
if (ft_strlen(*stock) == 0)
{
ft_memdel((void **)stock);
return (0);
}
*line = ft_strdup(*stock);
ft_memdel((void **)stock);
return (1);
}
int gnl_manage_read(char **stock, char **line)
{
char *tmp;
char *tmp2;
if ((tmp = ft_strchr(*stock, '\n')))
{
*tmp = '\0';
tmp2 = ft_strdup(tmp + 1);
*line = ft_strdup(*stock);
ft_memdel((void **)stock);
*stock = ft_strdup(tmp2);
free(tmp2);
tmp2 = NULL;
tmp = NULL;
return (1);
}
return (0);
}
int get_next_line(int fd, char **line)
{
static char *stock = NULL;
char *buffer;
int ret;
if (stock)
if (gnl_manage_read(line, &stock))
return (1);
buffer = ft_strnew(BUFF_SIZE);
while ((ret = read(fd, buffer, BUFF_SIZE)) > 0)
{
buffer[ret] = '\0';
stock = ft_strjoin2(stock, buffer);
ft_memdel((void **)&buffer);
if (gnl_manage_read(&stock, line))
return (1);
buffer = ft_strnew(BUFF_SIZE + 1);
}
if (buffer)
ft_memdel((void **)&buffer);
if (ret == -1)
return (-1);
return (gnl_manage_return(line, &stock));
}

22
libft/get_next_line.h Normal file
View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/02/28 22:19:58 by gbrochar #+# #+# */
/* Updated: 2016/05/30 16:27:35 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef GET_NEXT_LINE_H
# define GET_NEXT_LINE_H
# include "libft.h"
# define BUFF_SIZE 512
int get_next_line(int const fd, char **line);
#endif

101
libft/libft.h Normal file
View File

@ -0,0 +1,101 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/24 12:52:28 by gbrochar #+# #+# */
/* Updated: 2016/05/31 09:04:28 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBFT_H
# define LIBFT_H
# include <string.h>
# include <unistd.h>
# include <stdlib.h>
# include <fcntl.h>
# include "get_next_line.h"
typedef struct s_list
{
void *content;
size_t content_size;
struct s_list *next;
} t_list;
t_list *ft_get_last_node(t_list **alst);
void ft_lstadd(t_list **alst, t_list *new);
void ft_lstadd_preview(t_list **alst, t_list *new);
void ft_lstdel(t_list **alst, void (*del)(void *, size_t));
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t));
t_list *ft_lstnew(void const *content, size_t content_size);
void ft_lstiter(t_list *lst, void (*f)(t_list *elem));
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem));
int ft_atoi(const char *str);
int ft_atoi_color(char *hexa_color);
int ft_atoi_len(char *str, int *len);
int *ft_atoi_split(char *str, char c, int *tab_len);
void ft_bzero(void *s, size_t n);
int ft_isalnum(int c);
int ft_isalpha(int c);
int ft_isascii(int c);
int ft_isdigit(int c);
int ft_strtab_isdigit(char **strtab);
int ft_isprint(int c);
int ft_isspace(int c);
char *ft_itoa(int n);
void *ft_memalloc(size_t size);
void *ft_memccpy(void *dst, const void *src, int c, size_t n);
void *ft_memchr(const void *s, int c, size_t n);
int ft_memcmp(const void *s1, const void *s2, size_t n);
void *ft_memcpy(void *dst, const void *src, size_t n);
void ft_memdel(void **ap);
void *ft_memmove(void *dst, const void *src, size_t len);
void *ft_memset(void *b, int c, size_t len);
int ft_power(int nb, int pow);
void ft_putchar(char c);
void ft_putchar_fd(char c, int fd);
void ft_putendl(char const *s);
void ft_putendl_fd(char const *s, int fd);
void ft_putnbr(int n);
void ft_putnbr_fd(int n, int fd);
void ft_putstr(char const *s);
void ft_putstr_fd(char const *s, int fd);
void ft_sort_int(int *tab, int size);
long ft_sqrt(long n);
char *ft_strcat(char *s1, const char *s2);
char *ft_strchr(const char *s, int c);
void ft_strclr(char *s);
int ft_strcmp(const char *s1, const char *s2);
char *ft_strcpy(char *dst, const char *src);
void ft_strdel(char **as);
char *ft_strdup(const char *s1);
int ft_strequ(char const *s1, char const *s2);
void ft_striter(char *s, void (*f)(char *));
void ft_striteri(char *s, void (*f)(unsigned int, char *s));
char *ft_strjoin(char const *s1, char const *s2);
size_t ft_strlcat(char *dst, const char *src, size_t size);
size_t ft_strlen(const char *s);
char *ft_strmap(char const *s, char (*f)(char));
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
char *ft_strncat(char *s1, const char *s2, size_t n);
int ft_strncmp(const char *s1, const char *s2, size_t n);
char *ft_strncpy(char *dst, const char *src, size_t n);
int ft_strnequ(char const *s1, char const *s2, size_t n);
char *ft_strnew(size_t size);
char *ft_strnstr(const char *s1, char *s2, size_t n);
char *ft_strrchr(const char *s, int c);
char **ft_strsplit(char const *s, char c);
char *ft_strstr(const char *s1, char *s2);
char *ft_strsub(char const *s, unsigned int start, size_t len);
char *ft_strtrim(char const *s);
void ft_swap(int *a, int *b);
int ft_tolower(int c);
int ft_toupper(int c);
int ft_ishexdigit(int c);
void ft_error(char *str);
#endif

99
main.c Normal file
View File

@ -0,0 +1,99 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/05/30 13:01:43 by gbrochar #+# #+# */
/* Updated: 2016/06/22 05:29:43 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf3d.h"
int get_texture(t_env *e)
{
if (!(e->img_text = mlx_new_image(e->ptr, WINX, WINY)))
{
mlx_destroy_window(e->ptr, e->win);
free(e->ptr);
return (1);
}
if (open("textures/stone.xpm", O_RDONLY) == -1)
return (1);
e->img_text = mlx_xpm_file_to_image(e->ptr, "textures/stone.xpm",
&(e->width), &(e->height_t));
if (!(e->text = mlx_get_data_addr(e->img_text, &e->bppt, &e->t_l, &e->e_t)))
{
mlx_destroy_image(e->ptr, e->img_text);
mlx_destroy_window(e->ptr, e->win);
free(e->ptr);
return (1);
}
e->t_i = ft_strlen(e->data);
return (0);
}
int init_mlx(t_env *e)
{
if (!(e->ptr = mlx_init()))
return (1);
if (!(e->win = mlx_new_window(e->ptr, WINX, WINY, "wolf3d")))
{
free(e->ptr);
return (1);
}
if (!(e->img = mlx_new_image(e->ptr, WINX, WINY)))
{
mlx_destroy_window(e->ptr, e->win);
free(e->ptr);
return (1);
}
if (!(e->data = mlx_get_data_addr(e->img, &e->bpp, &e->sz_l, &e->endian)))
{
mlx_destroy_image(e->ptr, e->img);
mlx_destroy_window(e->ptr, e->win);
free(e->ptr);
return (1);
}
e->sz_i = ft_strlen(e->data);
mlx_hook(e->win, 2, 1L << 1, key_hook, e);
mlx_hook(e->win, 6, 1L << 1, cursor_hook, e);
mlx_hook(e->win, 17, 1L << 1, red_cross, e);
return (0);
}
int init_env(t_env *e)
{
int i;
i = 0;
e->fov = FOV;
e->screen_dist = (double)((double)WINX / (double)2) / (double)tan(30 / RAD);
e->camera_alpha = 0;
e->camera_y = 32;
e->sensivity = 1;
e->sprint = 0.1;
return (get_texture(e));
}
int main(int argc, char **argv)
{
t_env e;
if (argc == 2)
{
if (parse_map(&e, argv[1]))
ft_error("parsing error\n");
if (init_mlx(&e))
ft_error("mlx initialisation error\n");
if (init_env(&e))
ft_error("texture not found\n");
ray_cast(&e);
mlx_loop(e.ptr);
}
else
ft_putstr("usage: ./wolf3d file_name\n");
return (0);
}

3
maps/basic_map Normal file
View File

@ -0,0 +1,3 @@
1 1 1 1 1
1 2 0 0 1
1 1 1 1 1

104
parsing.c Normal file
View File

@ -0,0 +1,104 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/05/30 13:40:01 by gbrochar #+# #+# */
/* Updated: 2016/06/22 04:44:36 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf3d.h"
char **get_map(char *str)
{
int i;
int fd;
char *line;
char **map;
i = 0;
if ((fd = open(str, O_RDONLY)) == -1)
return (NULL);
while (get_next_line(fd, &line) > 0)
{
i++;
free(line);
}
close(fd);
if (!(map = (char **)malloc((i + 1) * sizeof(char *))))
return (NULL);
map[i] = NULL;
i = 0;
if ((fd = open(str, O_RDONLY)) == -1)
return (NULL);
while (get_next_line(fd, &line) > 0)
map[i++] = line;
close(fd);
return (map);
}
int check_player(int **map, t_env *e)
{
int i;
int j;
i = 0;
j = 0;
while (map[i])
++i;
while (map[0][j] != 255)
++j;
if (check_player_2(map, e, j))
return (1);
if (check_border(i, j, map))
return (1);
return (0);
}
void del(char **map_str)
{
int i;
i = 0;
while (map_str[i])
free(map_str[i++]);
free(map_str);
}
int **check_map(char **map_str, t_env *e)
{
int **map;
int tab_len;
int i;
if (!map_str)
return (NULL);
if (ft_strtab_isdigit(map_str) == 0)
return (NULL);
i = 0;
while (map_str[i])
++i;
if (!(map = (int **)malloc((i + 1) * sizeof(int *))))
return (NULL);
map[i] = NULL;
i = -1;
while (map_str[++i])
{
map[i] = ft_atoi_split(map_str[i], ' ', &tab_len);
map[i][tab_len] = 255;
}
del(map_str);
if (check_player(map, e))
return (NULL);
return (map);
}
int parse_map(t_env *e, char *str)
{
if (!(e->map = check_map(get_map(str), e)))
return (1);
return (0);
}

82
parsing_2.c Normal file
View File

@ -0,0 +1,82 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsing_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/06/22 04:04:19 by gbrochar #+# #+# */
/* Updated: 2016/06/22 05:24:30 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf3d.h"
int check_border(int i, int j, int **map)
{
int i1;
int j1;
i1 = 0;
j1 = 0;
j--;
i--;
if (map[i][j] != 1)
return (1);
while (i1 != i)
if (map[i1++][j1] != 1)
return (1);
i1 = 0;
while (i1 != i)
if (map[i1++][j] != 1)
return (1);
i1 = 0;
while (j1 != j)
if (map[i1][j1++] != 1)
return (1);
j1 = 0;
while (j1 != j)
if (map[i][j1++] != 1)
return (1);
return (0);
}
int check_i_j(int **map, int i, int j, t_env *e)
{
if (map[i][j] == 2)
{
e->camera_x = j + 0.5;
e->camera_z = i + 0.5;
return (1);
}
return (0);
}
int check_player_2(int **map, t_env *e, int size_mem)
{
int i;
int j;
int player;
int size;
player = 0;
i = 0;
while (map[i])
{
j = 0;
size = 0;
while (map[i][j] != 255)
{
if (check_i_j(map, i, j, e))
player++;
size++;
++j;
}
if (size != size_mem)
return (1);
++i;
}
if (player != 1)
return (1);
return (0);
}

55
pixel_put.c Normal file
View File

@ -0,0 +1,55 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* putpixel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/05/11 14:17:03 by gbrochar #+# #+# */
/* Updated: 2016/06/22 01:50:27 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf3d.h"
int get_y_text(t_env *e, int y)
{
int y_text;
if (e->real_height <= 240)
{
y_text = (WINY - e->height) / 2;
y_text = y - y_text;
y_text = (double)y_text / (double)e->height * 64;
}
else
{
y_text = (e->real_height - WINY) / 2;
y_text += y;
y_text = (double)y_text / (double)e->real_height * 64;
}
return (y_text);
}
void pixel_put(t_env *e, int x, int y)
{
int index;
int index_text;
int y_text;
y_text = get_y_text(e, y);
index = (x * (e->bpp / 8)) + (y * e->sz_l);
index_text = (e->text_x * (e->bppt / 8)) + (y_text * e->t_l);
if (e->sky == 0)
{
e->data[index + 2] = e->text[index_text + 2];
e->data[index + 1] = e->text[index_text + 1];
e->data[index] = e->text[index_text];
}
else
{
e->data[index + 2] = e->color_sky / (256 * 256);
e->data[index + 1] = (e->color_sky / 256) % 256;
e->data[index] = e->color_sky % 256;
}
}

124
run_game.c Normal file
View File

@ -0,0 +1,124 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* run_game.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/05/31 09:29:05 by gbrochar #+# #+# */
/* Updated: 2016/06/22 01:45:01 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf3d.h"
void reverse(double *n, double *old_n)
{
while (*n < 0)
(*n)++;
*n = 1 - *n;
while (*old_n < 0)
(*old_n)++;
*old_n = 1 - *old_n;
}
void get_color(t_env *e, double x, double y)
{
double old_x;
double old_y;
old_x = x - e->dx + e->camera_x;
old_y = y - e->dy + e->camera_z;
x += e->camera_x;
y += e->camera_z;
if (x < 0)
reverse(&x, &old_x);
if (y < 0)
reverse(&y, &old_y);
if ((int)old_y != (int)y)
{
while (x > 1)
x--;
e->text_x = (x / (double)1) * 64;
}
else
{
while (y > 1)
y--;
e->text_x = (y / (double)1) * 64;
}
}
void get_height_and_color(t_env *e, int i)
{
double x;
double y;
x = e->x / 5000;
y = e->y / 5000;
e->dx = x;
e->dy = y;
while (e->map[(int)(y + e->camera_z)][(int)(x + e->camera_x)] != 1)
{
x += e->dx;
y += e->dy;
}
get_color(e, x, y);
x *= 64;
y *= 64;
e->distance = sqrt((x * x) + (y * y));
e->distance = (double)e->distance * (double)cos((((double)i / (double)WINX
* (double)e->fov) - ((double)e->fov / (double)2)) / (double)RAD);
if (e->distance > 0)
e->height = (double)(64 * e->screen_dist) / (double)e->distance;
else
e->height = WINY;
if (e->height > WINY || e->height < 0)
e->height = WINY;
e->real_height = (double)(64 * e->screen_dist) / (double)e->distance;
}
void print_column(int column, t_env *e)
{
int i;
i = 0;
e->color_sky = 0x4444FF;
e->sky = 1;
while (i != (WINY / 2) - (e->height / 2))
{
pixel_put(e, column, i);
++i;
}
e->sky = 0;
while (i != (WINY / 2) + (e->height / 2))
{
pixel_put(e, column, i);
++i;
}
e->color_sky = 0x00888888;
e->sky = 1;
while (i != WINY)
{
pixel_put(e, column, i);
++i;
}
}
void ray_cast(t_env *e)
{
int i;
i = 0;
while (i != WINX)
{
e->alpha = (((((double)i / (double)WINX) * (double)e->fov)
+ e->camera_alpha)) / RAD;
e->y = cos(e->alpha);
e->x = sin(e->alpha);
get_height_and_color(e, i);
print_column(i, e);
++i;
}
mlx_put_image_to_window(e->ptr, e->win, e->img, 0, 0);
}

166
textures/stone.xpm Normal file
View File

@ -0,0 +1,166 @@
/* XPM */
static char *g7q3o_5dglx[] = {
/* columns rows colors chars-per-pixel */
"64 64 96 2 ",
" c #3A3637",
". c #3C3837",
"X c #3C3739",
"o c #3D393A",
"O c #463837",
"+ c #433D3C",
"@ c #46423E",
"# c #49433F",
"$ c #4C483F",
"% c #443F40",
"& c #464142",
"* c #4B4543",
"= c #4E4844",
"- c #4F4949",
"; c #504644",
": c #534B45",
"> c #594D45",
", c #514748",
"< c #554D4A",
"1 c #594E4B",
"2 c #545047",
"3 c #595047",
"4 c #57504A",
"5 c #5B534C",
"6 c #5D5451",
"7 c #5F5852",
"8 c #5E585A",
"9 c #61564D",
"0 c #63594F",
"q c #605752",
"w c #645A53",
"e c #695E54",
"r c #665D59",
"t c #695E59",
"y c #6C6156",
"u c #6D635A",
"i c #716457",
"p c #72655C",
"a c #78675F",
"s c #75695D",
"d c #7A6D5E",
"f c #79705F",
"g c #6F6763",
"h c #756760",
"j c #766A61",
"k c #7B6D63",
"l c #756E68",
"z c #7B6E68",
"x c #7E7163",
"c c #7F7168",
"v c #81705E",
"b c #816F65",
"n c #816F68",
"m c #837465",
"M c #887567",
"N c #857866",
"B c #8A7A67",
"V c #83746A",
"C c #8A766B",
"Z c #86796A",
"A c #8B7B6B",
"S c #927D66",
"D c #907669",
"F c #927E6C",
"G c #987F6B",
"H c #877B72",
"J c #8D7D71",
"K c #937E71",
"L c #987E71",
"P c #8E806D",
"I c #94816C",
"U c #99846D",
"Y c #8D8173",
"T c #8F8178",
"R c #938372",
"E c #9A8673",
"W c #9C8974",
"Q c #938479",
"! c #94897B",
"~ c #9B8B7A",
"^ c #A0886E",
"/ c #A08D75",
"( c #A28E7C",
") c #A3917C",
"_ c #A9937B",
"` c #978A81",
"' c #9B8E81",
"] c #9F9184",
"[ c #A49483",
"{ c #A99583",
"} c #AB9981",
"| c #A4968B",
" . c #A79B8D",
".. c #AB9D8C",
"X. c #AFA08D",
"o. c #B1A08C",
/* pixels */
"5 5 7 u 7 5 q r r t u t r w 6 & o , - , 6 < 1 6 q r q t h g r 1 < 6 w 6 < t h g g h k l q g h < , 6 q r r w q w w r 7 8 u 7 6 5 ",
"u V V V V V V Z V V Z Z H V z 6 & | H V V H z p p H J V V C C t q Q V n t L J H Z H H K V H ( q q z C Z V C V z Z V c V V V V p ",
"V k p h k j p h h u t p p t V 6 < Q b b n K C n n H z h h C C q u C z t h H V z c x V k V h L 5 r V g p p p u h h u j h p p x V ",
"H h j k z h h k t i h h h z t 6 ; V h k n n n V n k h h z n h 6 u C t h C n k k h k V V V t C 8 5 i j z j h p t k h j k j l s J ",
"Z k k k k p k t h h j x k k s 1 < c p m M b M n n n n z h z h r 6 r h C V b z a s l c V Z i N q q p k b c j h p u j j j j z k C ",
"7 k j k h h h p h k k k b j Z q 5 ! k a b b C n C n n n h h l 8 t K C V n b k j s k N N x V m 5 w z j k k k k k s j j j k j z 7 ",
"g p p r h h k k j k x f m m B w < R N b a b V V n C C V n h K t t J n V V x x x x N B N Z m q * w z k k k k k k k j j h r h s s ",
"h h h h u p h k x x x m v m N 9 7 _ d d M b m N C H C C C k L r q C V V m Z N B B A A A s w x < w h a k k k k k j s p u j p j k ",
"k c j u h p s d x m N N m m N 9 5 o.U y f F B B V V Z B A A Q 4 t K V C B P Z Z B B Z p u N B 4 5 x k a k k k k s u u h u j V k ",
"k k h q t s d y s P B Z m N R 5 # x P y : w s m M C A K A x r < w A N A B P P B A ! Z m A Z x + 5 B N k c k H p u j h t w l c j ",
"o % & & * * : : & # @ @ = = = # @ : : 2 $ + @ @ + O + + O % + O @ + O = = # $ = = & * = @ @ . o # # @ @ & . X X + X X + & * = + ",
"q 8 t s m V p y 2 y x d y c P N N m B P d x E p 0 d x A m k m m x d N x x N s w o q c V c m P x m x x k x i p 6 & j r r r q 7 6 ",
"u z ' V k A E m 4 ( B P y I I B P Z P P I N ) f i I Z N B N B N Z N N A Z m P i 4 ! ~ Z j N P Z A J A P Z A R w t | m b H ' V i ",
"b V j t j Z A i y P N p x P Z N N N Z B P f I f x B f m m N c N k d d x f f B i 5 B s y c J N P B Z Z B Z C A w r b k b n V C V ",
"n b b k k V x p y c i N I B N m x N B P I f B f P v Z N N m m m p f N m M M i w = w s A Z P Z N x N V B A A F p 5 z a m C M m V ",
"n n n n x x x p 0 s Z I A B N m f m Z A P m N f y P B v N x m s m N N M N N N y 2 x P m B A c x x c Z B A F W j g n a b M M b V ",
"n C C H n k C j y W I P B Z N x f x v P m P N y 7 m N m m N Z m N Z Z Z Z N Z i 7 I d A Y Z N x m N B B F A k 0 t ' k b b M M b ",
"n C C C C b B A w I P B B N c N v Z P Z P f y 2 s f m s x m H Z B Z Z N N f B y 5 E s R P P N m m Z B Y B s f s g J N m m m m M ",
"z n n H B m W Z 5 I B P B B Z B P B Z B y i P y p B x c c k m V J Z N N v x m y 5 W d Z J A Z V Z B A A y m I s l [ s d A M b k ",
"b b H L R R A t 5 R I I P A I B P B P s c R ~ y s R N s N Z Z c Z Y P P v P I y 5 ) Y T E Y B A B J W a Z A ~ u u } E e p m b n ",
"u u h V b i 6 1 $ i i v B v v v x N m x c c p @ 7 j p q e g l p r x s s p s x 5 3 I Y u Z Z m N N Z A y s s s 1 > w i 9 ; ; q i ",
"X O , , * ; > ; $ @ $ $ 2 $ $ $ = # = < 2 4 2 4 5 6 7 7 < 7 r < * @ * : : : : 2 5 2 4 q y 9 5 : 3 4 5 > : : < : > 9 9 e > > , % ",
"1 E ~ E ~ W U U I I I P U U I 0 9 R B B s ( R P R R R ~ Z ` [ q l ] m m N V s u s B R P I B f 9 w R ) I E U W C l m U U C F b k ",
"t K C L F I F I I I I I I U / i s R N s f P Z P Z A A J Y H ( 7 T R C B P [ I m m ] V x N I U 5 e E I I I I R U / A M D R n F C ",
"r K C D K F I I S G S U U S I 0 f I f s I B Z N c Z P Y P s W w j Z m B A B A A M v b b M S d 3 i F U F F I F G U U I B A k V J ",
"w K D K F U U F S I I B S I U i y s k I P Z Z m x Z P A R s R w j m M A F A D A A A M m m N f q i I U G I D F F G S U U L L A g ",
"t L D D D F I I S S U S S U U y y P I P A A N x x N A Y B V P w T Y m B A B A F A A M N v m a 7 y U U U L R A G S G S M C D R r ",
"u L K L S G U S S S S U I U U y f E P A A m m x x N Z Z Z J u < l ~ N b M A I A B F A B b v I 5 i E I G F I U G G I G M C D K w ",
"J V C K J L U G U S D S I I I i i I J Z Z C Z N Z P P Z c y s < Y A N M N C B B A D A B m m W 7 y I G U I I S G G I D M M D K q ",
"C H z C k C S ^ U S S S I S I e i I B Z Z B Z B Z Z B j y N R 5 ' ( a d F B N V m N N M m P ! < u ( S I I S S S S G D n M M K t ",
"V C D K E G M M S / U / ^ _ / 0 s W R Y R R R Y Y R B c Q ] Y < z [ R 9 y m A A F F I U I B s : y W ( E I I I U U / L L L L ( q ",
", 5 t 5 w e e > 3 9 9 3 9 e 3 > : < > y w w w w w y r w q 5 @ < 1 3 ; + ; 3 w 9 9 e y 9 5 4 . 2 9 9 9 9 9 e 9 0 9 6 6 6 t 1 % ",
"8 q < 6 r 7 5 5 # q i 9 e 0 e 0 9 5 5 5 5 5 3 1 * : < e w 7 w w e u u y w 7 @ @ * = : 1 3 5 3 5 9 w y i w 5 # 2 3 6 6 6 6 6 8 ",
"V Z V Z A A B p w ( / U U / U U W U U E W E ) e s W R Q R R I R A Q Z x Q W P : T [ A N Y ~ m s k ~ J B A I A 9 y N Z Z J A m V ",
"a j k j j j V k e U S B S I S G S F I G I I / t i R Z A B Z Z Z A Z B d y m P 5 Z A N B A W R M C A k m N S A 5 u N u s j p p j ",
"k k k c c x l Z y U S S S I U I G G I S I I U e p R J A Z N N N B B A Y x y s 4 s C m B A B A A B m m v M B d 5 q u j k k j h t ",
"u k k k k x c c e U I I S I I G I I I D G I U u x W J A A N m x x N P N Z P y 2 c c V B F A F A A A C m m m k 0 w u c c c k k l ",
"k k z z k k V < q W S S S I I G S F I I U I U y w A I R Y B m x f x Z P Z m P 0 H ' m N B B K K A F A N v b x 5 y V l c V V x V ",
"c b j j u j l u u I U ^ E U I I G I D U F U I i u s l R A Z N c N Z B P I s R 0 x ! A b N B F A A D A B b m E 5 q x c c V V V V ",
"k j j j k j j p Z B c I A F ^ U I I S B U I I i s R k s P P B N m Z P P P f W 0 R Q d B M M C Z C A B B v N W 5 q k c Z c Z Z H ",
"h s h j p j C u m I Z W A B A W I U G I I U W e s ~ B k d R B Z N P P P P N / 7 ! { x i B A B m N m Z B N I I = 7 c z z V Z Z H ",
"u h h u q k c u i x I B U I v a v I I I F ~ A w 5 B V m u ~ P P P P P I c Q / 9 y H m 5 5 y m A C B I I A k y * 1 V V k k z H z ",
"* * & * & & & + @ > 3 < 3 < 3 = + + + * , 5 > 1 = = < > 5 5 q 5 5 5 5 5 4 5 w 4 4 5 4 5 = = 4 2 : : 3 3 = = : o & & & % * & * * ",
"u j k J c k x x x f B B B Z k q ; Z x i s s i e y i m M P B p 0 3 f v f u Y P Z Z A A R j P ~ 7 q d Z Z Z B x m k c z V H x h g ",
"c Z k k x c k k x x m A m m P w 1 X.I F P [ ~ m d ~ ~ m m I U y y / Z B s R J A A A P P Y Z / y u A m m B V m x j k k k j k V l ",
"T k j k k k h x u p d f f m N w 1 A m M A A F B B M a v m I N q s P x u A P B N V Z P B P s E w e B x v x f d s k h k k k j k Z ",
"~ k k k m j k j y k f N M N s 5 1 Z m A A I B A B B M m N N v y i f p A P A A m x N P P P s I y 0 i N N Z m m p h j h z k k j K ",
"l c k k z k l u d x m N m m A q q ! k B A S A B D B M N b m f u y x P P A A B c x N Z P B x P y y N m m N N m m i j k k k k m u ",
"t x h j k k k k k k N m N c P w = ' J m N M F D A F A B m v A w x W F J A Z N x c N A Z N P f 5 p B N N N N N b d k k k h k j 8 ",
"V h g u j h k k k m N Z Z m Z 0 8 ~ N C m M A A B A B A B b I s y R A K A V N c N Z A B N y s 2 y N m N Z N N N x j h p t s i s ",
"c V s k h g h h k m m m x x N 5 8 X.M s S M M m M V N B N N ) w y F Z Z Z A B P B B B m 9 f P 5 y m x N m N N N k p i h k j k p ",
"J Z x t k k k h x P P P Z P W w 4 ) ) i w m B B B Z F U I I x 5 u W I J P R P P A R B d A W W 3 y I B Z P P Y N s k k k r k V c ",
"r w r 6 5 q t 5 6 s u u p u s - + 5 9 5 = * 3 y i e i a y 9 5 $ = y w s s s f s k c k s k p 5 . 2 y u y y y s 7 q t q 1 < r r 6 ",
"< , * < w w < , * @ : > 2 6 y y w y u u 5 6 u 4 = < 3 5 < 5 5 3 7 < 4 5 5 5 2 = . o 2 4 5 3 5 5 5 2 4 5 6 & @ & + # + * , * , * ",
"h h J H H H n p : Y R I d ! ` Y P P R ~ R A } m i I Y R I P I R P P I R R R P u @ P W ! N Z R B P I I P P P W p q .C k n H g q ",
"c H J k h n K h 5 R N f y Y Z Z Z Z A Z R x R k s A x m c x x f f x x c s s Z p 4 P P y i Z B N Z Z P Z Z Z R y g ~ b b V Q J j ",
"J b h h k V z w q Y x s Z K B Z m N P P Y j P x N m m m B N m N s s k x x x k r < x y p Z N m V N N V J A A R p w B b b b b b b ",
"C n n n j z h t 9 u s P I Z Z m x N Z Y Q N V m N B m m N f m s d N m m x c s q * w c c z V k j j f m A J A U k w m k V C n b b ",
"C n C n k h k r 7 P R I B B V x x c Z K Z B Z j 4 P m N m m V x m m m m x j c r 1 V k z c c k g s j V A K R R i h ! j k n n b n ",
"C n n n b a n z q R A B V m x x x N A A Z R j 1 y f f i x k x m f m k k k l l y 1 H t Z V V k j j k c C K V p e y T V h k b m C ",
"V n n n b h n Z 1 C V V V x c m Z Z A A Z y p w u x s p p h j k z z k k k k z r 6 J t V V V z k j k V C k h H j h L p h b b k b ",
"V z h z b z L u < C z z x n c V B V Z x u m U y u N k p h h u h k k z z k k V r < Q j Z V n z z z V V h t z Z t g ] b r k b k b ",
"K D n J C C t 1 1 H V C V H Z B c A P x P R ! 4 u H x y p k h h p C H Z V H Y q < ~ J z K C V n n H Q i V V K q , H C 5 , t k C ",
"< % % , ; % * + + * % 1 5 < 6 < 6 7 7 8 7 7 = . = 2 - & * , < < % < , < < 6 < & & r r < r r r 6 w w w < < 1 & & % * * , O % % < "
};

95
wolf3d.h Normal file
View File

@ -0,0 +1,95 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* wolf3d.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/05/30 13:00:25 by gbrochar #+# #+# */
/* Updated: 2016/06/22 05:29:58 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef WOLF3D_H
# define WOLF3D_H
# include "libft/libft.h"
# include "mlx.h"
# include "math.h"
# define WINX 720
# define WINY 600
# define FOV 60
# define RAD 57.2958
typedef struct s_env
{
void *ptr;
void *win;
void *img;
char *data;
int sz_l;
int sz_i;
int endian;
int bpp;
int width;
int height_t;
void *img_text;
char *text;
int t_l;
int t_i;
int e_t;
int bppt;
int text_x;
int **map;
double camera_x;
int camera_y;
double camera_z;
double camera_alpha;
int fov;
double screen_dist;
double alpha;
double x;
double y;
double dx;
double dy;
double sensivity;
double sprint;
double distance;
int height;
int real_height;
int color;
int color_sky;
int sky;
} t_env;
int init_mlx(t_env *e);
int init_env(t_env *e);
int parse_map(t_env *e, char *str);
char **get_map(char *str);
int **check_map(char **map_str, t_env *e);
int check_player(int **map, t_env *e);
int check_player_2(int **map, t_env *e, int size_mem);
int check_border(int i, int j, int **map);
int check_wall(t_env *e, int keycode);
int key_hook(int keycode, void *e_void);
int red_cross(void);
int cursor_hook(int x, int y, void *e_void);
void pixel_put(t_env *e, int x, int y);
void ray_cast(t_env *e);
void get_height_and_color(t_env *e, int i);
void print_column(int i, t_env *e);
#endif