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

7
includes/cub3d.h

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

18
libft/Makefile

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

40
sources/main.c

@ -6,12 +6,27 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/21 19:22:50 by narnaud #+# #+# */ /* 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" #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) int main(int argc, char **argv)
{ {
t_env *env; t_env *env;
@ -19,5 +34,28 @@ int main(int argc, char **argv)
if (argc != 2) if (argc != 2)
return (EXIT_FAILURE); return (EXIT_FAILURE);
env = parse_envFile(argv[1]); 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); return (EXIT_SUCCESS);
} }

21
sources/parsing.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/23 17:20:29 by narnaud #+# #+# */ /* 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) if (ret->step < 6)
return (NULL); 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); return (ret);
} }

Loading…
Cancel
Save