Browse Source

update

master
nicolas-arnaud 2 years ago
parent
commit
9c23ccdfd7
  1. 25
      .gitignore
  2. 2
      Makefile
  3. 4
      README.md
  4. 4
      includes/cub3d.h
  5. BIN
      lib/libft.a
  6. BIN
      lib/libmlx_Linux.a
  7. 6
      maps/tester.cub
  8. 14
      maps/tests/empty_map_line.cub
  9. 15
      maps/tests/invalid_line_after_map.cub
  10. 12
      maps/tests/missing_color.cub
  11. 13
      maps/tests/missing_color_comp.cub
  12. 12
      maps/tests/no_door_tex.cub
  13. 13
      maps/tests/open_map.cub
  14. 13
      maps/tests/simple.cub
  15. 13
      maps/tests/unexistant_folder_tex.cub
  16. 13
      maps/tests/unexistant_tex_file.cub
  17. 7
      src/main.c
  18. 12
      src/mlx/mlx_1.c
  19. 5
      src/parsing/getline.c
  20. 14
      src/parsing/parsing.c
  21. 4
      src/parsing/utils.c
  22. 4
      src/render/render.c

25
.gitignore

@ -0,0 +1,25 @@
*
!.gitignore
!LICENSE
!Makefile
!README.md
!*.h
!includes/
!*.a
!lib/
!*.cub
!maps/
!maps/tests/
!*.c
!src/
!src/mlx/
!src/parsing/
!src/render/
!*.xpm
!textures/

2
Makefile

@ -19,7 +19,7 @@ endif
ifeq ($(UNAME_S), Darwin)
LFLAGS = -framework OpenGL -framework AppKit -Llib -lft -lmlx_Mac
endif
CFLAGS = -Werror -Wall -Wextra -O3 -ffast-math -funsafe-math-optimizations
CFLAGS = -g -Werror -Wall -Wextra -O3 -ffast-math -funsafe-math-optimizations
%.o:%.c
${CC} ${CFLAGS} -c $< -o ${<:.c=.o}

4
README.md

@ -28,8 +28,8 @@ CUBE3D
- [x] save player pos,
- [ ] handle errors,
- [x] not closed map
- [ ] texture files not exist, not permited or with wrong extension
- [ ] impossible color used
- [x] texture files not exist, not permited or with wrong extension
- [x] impossible color used
- [-] missing map
### Quit
- [ ] clean and exit

4
includes/cub3d.h

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/21 19:24:12 by narnaud #+# #+# */
/* Updated: 2022/11/14 10:35:59 by narnaud ### ########.fr */
/* Updated: 2022/11/14 16:33:15 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -118,7 +118,7 @@ int mouse_move_hook(int x, int y, t_env *env);
int mouse_up_hook(int buton, int x, int y, t_env *env);
int update_hook(t_env *env);
void init_window(t_env *nv);
void init_game(t_env *env);
int init_game(t_env *env);
// Utils
void vec_set(t_vec *vec, int x, int y);

BIN
lib/libft.a

Binary file not shown.

BIN
lib/libmlx_Linux.a

Binary file not shown.

6
maps/tester.cub

@ -1,11 +1,13 @@
NO ./textures/wood.xpm
EA ./textures/wood.xpm
EA ./textures/colorstone.xpm
SO ./textures/wood.xpm
WE ./textures/wood.xpm
DO ./textures/wood.xpm
F 500, 156, 8
C 27, 210,27
F 250, 156,150
C 27, 210,200
111111111111111111111111111111111111111111111111
100000000000000000010000000000000000000000000001

14
maps/tests/empty_map_line.cub

@ -0,0 +1,14 @@
NO ./textures/redbrick.xpm
EA ./textures/colorstone.xpm
SO ./textures/redbrick.xpm
WE ./textures/redbrick.xpm
DO ./textures/wood.xpm
F 147, 159, 153
C 219, 213, 213
1111111
100N001
1000001
1111111

15
maps/tests/invalid_line_after_map.cub

@ -0,0 +1,15 @@
NO ./textures/redbrick.xpm
EA ./textures/colorstone.xpm
SO ./textures/redbrick.xpm
WE ./textures/redbrick.xpm
DO ./textures/wood.xpm
F 147, 159, 153
C 219, 213, 213
1111111
100N001
1000001
1111111
test

12
maps/tests/missing_color.cub

@ -0,0 +1,12 @@
NO ./textures/redbrick.xpm
EA ./textures/colorstone.xpm
SO ./textures/redbrick.xpm
WE ./textures/redbrick.xpm
DO ./textures/wood.xpm
F 147, 159, 153
1111111
100N001
1000001
1111111

13
maps/tests/missing_color_comp.cub

@ -0,0 +1,13 @@
NO ./textures/redbrick.xpm
EA ./textures/colorstone.xpm
SO ./textures/redbrick.xpm
WE ./textures/redbrick.xpm
DO ./textures/wood.xpm
F 147, 159, 153
C 219, 213
1111111
100N001
1000001
1111111

12
maps/tests/no_door_tex.cub

@ -0,0 +1,12 @@
NO ./textures/redbrick.xpm
EA ./textures/colorstone.xpm
SO ./textures/redbrick.xpm
WE ./textures/redbrick.xpm
F 147, 159, 153
C 219, 213, 213
1111111
100N001
1000001
1111111

13
maps/tests/open_map.cub

@ -0,0 +1,13 @@
NO ./textures/redbrick.xpm
EA ./textures/colorstone.xpm
SO ./textures/redbrick.xpm
WE ./textures/redbrick.xpm
DO ./textures/wood.xpm
F 147, 159, 153
C 219, 213, 213
1111111
100N000
1000001
1111111

13
maps/tests/simple.cub

@ -0,0 +1,13 @@
NO ./textures/redbrick.xpm
EA ./textures/colorstone.xpm
SO ./textures/redbrick.xpm
WE ./textures/redbrick.xpm
DO ./textures/wood.xpm
F 147, 159, 153
C 219, 213, 213
1111111
100N001
1000001
1111111

13
maps/tests/unexistant_folder_tex.cub

@ -0,0 +1,13 @@
NO ./textures/redbrick.xpm
EA ./textures/colorstone.xpm
SO ./textures/redbrick.xpm
WE ./textures/redbrick.xpm
DO ./text/wood.xpm
F 147, 159, 153
C 219, 213, 213
1111111
100N001
10002001
11111111

13
maps/tests/unexistant_tex_file.cub

@ -0,0 +1,13 @@
NO ./textures/redbrick.xpm
EA ./textures/colorstone.xpm
SO ./textures/redbrick.xpm
WE ./textures/redbrick.xpm
DO ./textures/woody.xpm
F 147, 159, 153
C 219, 213, 213
1111111
100N001
1000001
1111111

7
src/main.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/21 19:22:50 by narnaud #+# #+# */
/* Updated: 2022/11/14 10:39:10 by narnaud ### ########.fr */
/* Updated: 2022/11/14 16:35:36 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,12 +17,13 @@ int main(int argc, char **argv)
t_env *env;
if (argc != 2)
return (EXIT_FAILURE);
return (printf("Usage: ./cub3d mapfile.cub\n"), EXIT_FAILURE);
env = load_map(argv[1]);
if (!env)
return (EXIT_FAILURE);
init_window(env);
init_game(env);
if (init_game(env) == EXIT_FAILURE)
exit(EXIT_FAILURE);
render(env);
mlx_loop_hook(env->mlx, update_hook, env);
mlx_loop(env->mlx);

12
src/mlx/mlx_1.c

@ -2,11 +2,10 @@
/* */
/* ::: :::::::: */
/* mlx_1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +:+ +:+ +:+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/25 14:14:46 by narnaud #+# #+# */
/* Updated: 2022/08/25 14:18:18 by narnaud ### ########.fr */
/* Updated: 2022/11/14 16:28:51 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,7 +22,7 @@ void init_window(t_env *env)
env->mlx = mlx;
window = mlx_new_window(mlx, WIN_X_SZ, WIN_Y_SZ, "Cub3D");
env->win = window;
mlx_mouse_hide(mlx, win);
mlx_mouse_hide(mlx, window);
}
int mouse_move_hook(int x, int y, t_env *env)
@ -67,7 +66,7 @@ int mouse_move_hook(int x, int y, t_env *env)
}
#endif
void init_game(t_env *env)
int init_game(t_env *env)
{
int y;
@ -76,6 +75,8 @@ void init_game(t_env *env)
{
env->tex[y].img = mlx_xpm_file_to_image(env->mlx,
env->tex[y].file, &env->tex[y].width, &env->tex[y].height);
if (env->tex[y].img == NULL)
return (printf("Error:\nCan't open a texture\n"), EXIT_FAILURE);
env->tex[y].buffer = (int *)mlx_get_data_addr(env->tex[y].img, \
&env->tex[y].pixel_bits,
&env->tex[y].line_bytes,
@ -90,4 +91,5 @@ void init_game(t_env *env)
mlx_hook(env->win, 2, 1L << 0, key_press_hook, env);
mlx_hook(env->win, 3, 1L << 1, key_release_hook, env);
mlx_hook(env->win, 6, 0L, mouse_move_hook, env);
return (EXIT_SUCCESS);
}

5
src/parsing/getline.c

@ -44,6 +44,7 @@ char *get_next_line(int fd)
ssize_t read_size;
char *line;
char *ret;
char *next;
if (!*buffer)
{
@ -53,8 +54,10 @@ char *get_next_line(int fd)
ret = ft_calloc(1, sizeof(char));
while (buffer[i])
{
line = ft_strjoin(ret, save_buffer(buffer, &i));
next = save_buffer(buffer, &i);
line = ft_strjoin(ret, next);
ret = (free(ret), line);
free(next);
if (buffer[i - 1] == '\n')
break ;
read_size = read(fd, buffer, BUFFER_SIZE);

14
src/parsing/parsing.c

@ -33,16 +33,16 @@ void register_settings(int *progress, t_env *env, char *line)
elem = ft_split(line, ' ');
if (!elem[0] || !elem[1])
return ;
if (!ft_strncmp(elem[0], "NO", 3))
return (ft_free_split(elem));
if (!env->tex[0].file && !ft_strncmp(elem[0], "NO", 3))
env->tex[0].file = ft_strtrim(elem[1], "\n");
else if (!ft_strncmp(elem[0], "SO", 3))
else if (!env->tex[1].file && !ft_strncmp(elem[0], "SO", 3))
env->tex[1].file = ft_strtrim(elem[1], "\n");
else if (!ft_strncmp(elem[0], "WE", 3))
else if (!env->tex[2].file && !ft_strncmp(elem[0], "WE", 3))
env->tex[2].file = ft_strtrim(elem[1], "\n");
else if (!ft_strncmp(elem[0], "EA", 3))
else if (!env->tex[3].file && !ft_strncmp(elem[0], "EA", 3))
env->tex[3].file = ft_strtrim(elem[1], "\n");
else if (!ft_strncmp(elem[0], "DO", 3))
else if (!env->tex[4].file && !ft_strncmp(elem[0], "DO", 3))
env->tex[4].file = ft_strtrim(elem[1], "\n");
else if (!ft_strncmp(elem[0], "F", 2))
env->floorColor = rgb_to_int(elem + 1);
@ -117,7 +117,7 @@ t_env *load_map(char *filename)
line = get_next_line(fd);
}
if (progress < 7 && cleanup_datas(env))
return (NULL);
return (printf("Error\nYour map isn't valid.\n"), NULL);
env->map = create_map_array(e_map, env->wide, env->deep);
if (!is_valid_map(env) && cleanup_datas(env))
return (NULL);

4
src/parsing/utils.c

@ -24,7 +24,7 @@ int rgb_to_int(char **rgb)
i = 0;
ret = 0;
colors = ft_split(*rgb, ',');
while (c < 3 && rgb)
while (c < 3 && rgb && colors)
{
if (!colors[i])
{
@ -39,6 +39,6 @@ int rgb_to_int(char **rgb)
ret |= color << (8 * (2 - c++));
}
if (c < 3)
return (ft_free_split(colors), printf("Error:\nInvalid color.\n"), -1);
return (printf("Error:\nInvalid color.\n"), -1);
return (ft_free_split(colors), ret);
}

4
src/render/render.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/31 09:33:02 by narnaud #+# #+# */
/* Updated: 2022/08/23 16:19:08 by narnaud ### ########.fr */
/* Updated: 2022/11/14 16:45:42 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -91,6 +91,6 @@ void render(t_env *env)
bzero(env->buffer, WIN_Y_SZ * WIN_X_SZ * sizeof(int));
render_view(env);
if (env->minimap)
render_minimap(env, (t_vec){env->wide * 8, env->deep * 8});
render_minimap(env, (t_vec){WIN_X_SZ / 3, WIN_Y_SZ / 3});
mlx_put_image_to_window(env->mlx, env->win, env->img, 0, 0);
}

Loading…
Cancel
Save