Browse Source

Makefile modifs and starting mlx init

master
narnaud 3 years ago
parent
commit
145b6ce137
  1. 50
      Makefile
  2. 7
      includes/cub3d.h
  3. 18
      libft/Makefile
  4. 40
      sources/main.c
  5. 21
      sources/parsing.c

50
Makefile

@ -15,42 +15,42 @@ ifeq ($(UNAME_S), Darwin)
LFLAGS = -lmlx -framework OpenGL -framework AppKit -L. -lft
endif
CFLAGS = -Werror -Wall -Wextra -O3 -ffast-math -funsafe-math-optimizations
$(LIBFT):
#@git clone
@${MAKE} -C libft/
@cp libft/libft.a .
@cp libft/libft.h includes/
#@${RM} libft/
%.o:%.c
@${CC} ${CFLAGS} -c $< -o ${<:.c=.o}
${CC} ${CFLAGS} -c $< -o ${<:.c=.o}
all: $(NAME)
$(VERBOSE).SILENT:
$(LIBFT):
${MAKE} -C libft/
cp libft/libft.a .
cp libft/libft.h includes/
$(NAME): $(LIBFT) $(OBJS)
@echo "Making Cub3D."
@${CC} ${OBJS} -o ${NAME} ${LFLAGS}
@echo "Done."
echo Making Cub3D...
${CC} ${OBJS} -o ${NAME} ${LFLAGS}
echo
debug: $(LIBFT)
@echo "Making Cub3D with debug on."
@${CC} ${SRCS} -g -D DEBUG=1 ${CFLAGS} ${LFLAGS} -o ${NAME}
@echo "Done."
echo Making Cub3D with debug on...
${CC} ${SRCS} -g -D DEBUG=1 ${CFLAGS} ${LFLAGS} -o ${NAME}
echo
clean:
@echo "Cleaning objects."
@${RM} ${OBJS}
@echo "Done."
echo Cleaning objects...
${RM} ${OBJS}
echo
fclean: clean
@echo "Cleaning libft."
@${MAKE} -C libft fclean
@${RM} libft.a
@${RM} includes/libft.h
@echo "Cleaning binary."
@${RM} ${NAME}
@echo "Done."
${MAKE} -C libft fclean
${RM} libft.a
${RM} includes/libft.h
echo Cleaning binary...
${RM} ${NAME}
echo
re: fclean all

7
includes/cub3d.h

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/21 19:24:12 by narnaud #+# #+# */
/* Updated: 2022/05/23 17:31:16 by narnaud ### ########.fr */
/* Updated: 2022/05/24 16:43:16 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,6 +17,9 @@
# define DEBUG 0
# endif
# define WIN_X_SZ 900
# define WIN_Y_SZ 900
# define BUFFER_SIZE 4096
# define UNIT 200
# define WALL_HEIGHT 200
@ -59,6 +62,8 @@ typedef struct s_env
t_slist *raw_map;
int deep;
t_map *map;
void *mlx;
void *window;
} t_env;
t_env *parse_envFile(char *filename);

18
libft/Makefile

@ -37,23 +37,23 @@ RM = rm -rf
CFLAGS = -Wall -Wextra -Werror
.c.o:
@${CC} ${CFLAGS} -c $< -o ${<:.c=.o}
${CC} ${CFLAGS} -c $< -o ${<:.c=.o}
all : $(NAME)
$(NAME): $(OBJS)
@echo "Making libft."
@${AR} ${NAME} ${OBJS}
@echo "Done."
echo Making libft...
${AR} ${NAME} ${OBJS}
echo
clean:
@echo "Cleaning libft."
@${RM} ${OBJS}
@${RM} ${OBJS_BONUS}
@echo "Done."
echo Cleaning libft...
${RM} ${OBJS}
${RM} ${OBJS_BONUS}
echo
fclean: clean
@${RM} ${NAME}
${RM} ${NAME}
re: fclean all

40
sources/main.c

@ -6,12 +6,27 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/21 19:22:50 by narnaud #+# #+# */
/* Updated: 2022/05/23 17:23:39 by narnaud ### ########.fr */
/* Updated: 2022/05/24 16:47:16 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/cub3d.h"
void init_window(t_env *env)
{
void *mlx;
void *window;
mlx = mlx_init();
if (!mlx)
exit(error_msg("Mlx fail to init", 1));
env->mlx = mlx;
window = mlx_new_window(mlx, WIN_X_SZ, WIN_Y_SZ, "FdF");
if (!window)
exit(error_msg("Mlx fail to create window", 1));
env->win = window;
}
int main(int argc, char **argv)
{
t_env *env;
@ -19,5 +34,28 @@ int main(int argc, char **argv)
if (argc != 2)
return (EXIT_FAILURE);
env = parse_envFile(argv[1]);
if (DEBUG)
{
printf("\e[1;32m========> WALLS <========\e[0m\nNorth: %s\nSouth: %s\nWest: %s\nEast: %s\n",\
env->wallTexture[0], env->wallTexture[1],\
env->wallTexture[2], env->wallTexture[3]);
printf("\e[1;32m========================\e[0m\n");
printf("=> Floor color: %d\n=> Ceil color: %d\n", env->floorColor, env->ceilColor);
printf("\e[1;32m========> MAP <========\e[0m\n");
y = 0;
raw_map = env->raw_map;
while (y < env->deep)
{
printf("%s\n", (char *)raw_map->content);
y++;
raw_map = raw_map->next;
}
}
init_window(env);
lanch_game(env);
render(env);
mlx_key_hook(env->win, key_hook_primary, datas);
mlx_loop(env->mlx);
return (EXIT_SUCCESS);
}

21
sources/parsing.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/23 17:20:29 by narnaud #+# #+# */
/* Updated: 2022/05/23 17:47:07 by narnaud ### ########.fr */
/* Updated: 2022/05/24 16:17:37 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -121,24 +121,5 @@ t_env *parse_envFile(char *filename)
}
if (ret->step < 6)
return (NULL);
if (DEBUG)
{
printf("========> WALLS <========\nNorth: %s\nSouth: %s\nWest: %s\nEast: %s\n",\
ret->wallTexture[0], ret->wallTexture[1],\
ret->wallTexture[2], ret->wallTexture[3]);
printf("========================\n");
printf("=> Floor color: %d\n=> Ceil color: %d\n", ret->floorColor, ret->ceilColor);
printf("========> MAP <========\n");
y = 0;
raw_map = ret->raw_map;
while (y < ret->deep)
{
printf("%s\n", (char *)raw_map->content);
y++;
raw_map = raw_map->next;
}
}
return (ret);
}

Loading…
Cancel
Save