Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
refactor: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mahautlatinis committed Oct 13, 2023
1 parent 3b7bcf4 commit 32e6457
Show file tree
Hide file tree
Showing 56 changed files with 190 additions and 1,115 deletions.
6 changes: 4 additions & 2 deletions cub3d/bonus/cub_parser/cub_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* cub_data.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qdam <qdam@student.42.fr> +#+ +:+ +#+ */
/* By: mahautlatinis <mahautlatinis@student.42 +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/23 19:01:33 by qdam #+# #+# */
/* Updated: 2021/10/09 01:55:29 by qdam ### ########.fr */
/* Updated: 2023/10/13 17:15:59 by mahautlatin ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -25,6 +25,7 @@ void init_cub_data(t_cub_data *cub)
cub->c_g = -1;
cub->c_b = -1;
cub->raw_map = NULL;
return ;
}

void free_cub_data(t_cub_data *cub)
Expand All @@ -40,4 +41,5 @@ void free_cub_data(t_cub_data *cub)
if (cub->ea)
free(cub->ea);
ft_lstclear(&cub->raw_map, free);
return ;
}
8 changes: 2 additions & 6 deletions cub3d/bonus/cub_parser/cub_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@
/* ::: :::::::: */
/* cub_parser.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qdam <qdam@student.42.fr> +#+ +:+ +#+ */
/* By: mahautlatinis <mahautlatinis@student.42 +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/21 23:15:38 by qdam #+# #+# */
/* Updated: 2021/10/09 01:55:29 by qdam ### ########.fr */
/* Updated: 2023/10/13 17:17:05 by mahautlatin ### ########.fr */
/* */
/* ************************************************************************** */

#include "../includes/cub3D.h"

char *parse_cub_line_texture(t_cub_data *cub, char *line);
char *parse_cub_line_color(t_cub_data *cub, char **tab);
char *parse_cub_line_map(t_cub_data *cub, char *line);

static inline char *parse_cub_line(t_cub_data *cub, char *line)
{
char **tab;
Expand Down
4 changes: 2 additions & 2 deletions cub3d/bonus/cub_parser/cub_parser_extra.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* cub_parser_extra.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qdam <qdam@student.42.fr> +#+ +:+ +#+ */
/* By: mahautlatinis <mahautlatinis@student.42 +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/22 00:28:11 by qdam #+# #+# */
/* Updated: 2021/10/09 01:55:29 by qdam ### ########.fr */
/* Updated: 2023/10/13 17:16:09 by mahautlatin ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
4 changes: 3 additions & 1 deletion cub3d/bonus/game/init_free.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: mahautlatinis <mahautlatinis@student.42 +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/30 22:03:48 by qdam #+# #+# */
/* Updated: 2022/03/30 18:44:49 by mahautlatin ### ########.fr */
/* Updated: 2023/10/13 17:17:29 by mahautlatin ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -38,6 +38,7 @@ static inline void set_player_initial_pos(t_game *game)
else
game->p.dir = 0.5 * M_PI;
game->map[y][x] = '0';
return ;
}

char *init_game(t_cub_data *cub, t_game *game)
Expand All @@ -59,4 +60,5 @@ void destroy_game(t_game *game, bool quit)
destroy_graphics(game);
if (quit)
exit(0);
return ;
}
8 changes: 4 additions & 4 deletions cub3d/bonus/game/player_movements.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
/* ::: :::::::: */
/* player_movements.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qdam <qdam@student.42.fr> +#+ +:+ +#+ */
/* By: mahautlatinis <mahautlatinis@student.42 +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/31 01:08:40 by qdam #+# #+# */
/* Updated: 2021/10/09 01:55:29 by qdam ### ########.fr */
/* Updated: 2023/10/13 17:17:49 by mahautlatin ### ########.fr */
/* */
/* ************************************************************************** */

#include "../includes/cub3D.h"

// Check if player can move (dx, dy). This is mostly a collison check
static inline bool can_move(t_game *game, double dx, double dy)
{
double const lim_wall = 0.05;
Expand All @@ -28,7 +27,6 @@ static inline bool can_move(t_game *game, double dx, double dy)
&& game->map[(int)(y - lim_wall)][(int)(x + lim_wall)] == '0');
}

//Check if player is moving diagonally
static inline bool moving_diagonal(t_game *game)
{
return ((game->p.move_no && game->p.move_ea)
Expand All @@ -48,6 +46,7 @@ void player_rotate(t_game *game, double angle)
game->p.dir = dir - M_PI_PI;
else
game->p.dir = dir;
return ;
}

void player_move(t_game *game, double speed, double angle)
Expand All @@ -65,4 +64,5 @@ void player_move(t_game *game, double speed, double angle)
game->p.pos.x += dx;
if (can_move(game, 0, dy))
game->p.pos.y += dy;
return ;
}
8 changes: 6 additions & 2 deletions cub3d/bonus/graphics/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* draw.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qdam <qdam@student.42.fr> +#+ +:+ +#+ */
/* By: mahautlatinis <mahautlatinis@student.42 +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/05 19:05:34 by qdam #+# #+# */
/* Updated: 2021/10/09 01:55:29 by qdam ### ########.fr */
/* Updated: 2023/10/13 17:18:20 by mahautlatin ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -36,6 +36,7 @@ static inline void
while (++dx < WIN_X / N_RAYS)
put_px(start_x + dx, start_y + dy, get_px(tx, ty, img), &game->scr);
}
return ;
}

static inline void
Expand All @@ -62,6 +63,7 @@ static inline void
while (++dx < WIN_X / N_RAYS)
put_px(start_x + dx, start_y + dy, get_px(tx, ty, img), &game->scr);
}
return ;
}

static inline void
Expand All @@ -71,6 +73,7 @@ static inline void
draw_wall_ns(game, ray, start_x, start_y);
else
draw_wall_we(game, ray, start_x, start_y);
return ;
}

void draw_screen(t_game *game, t_ray *rays)
Expand Down Expand Up @@ -99,4 +102,5 @@ void draw_screen(t_game *game, t_ray *rays)
}
draw_wall(game, &rays[i], i * (WIN_X / N_RAYS), y);
}
return ;
}
3 changes: 2 additions & 1 deletion cub3d/bonus/graphics/events_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: mahautlatinis <mahautlatinis@student.42 +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/01 19:23:49 by qdam #+# #+# */
/* Updated: 2023/10/03 21:42:14 by mahautlatin ### ########.fr */
/* Updated: 2023/10/13 17:18:38 by mahautlatin ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -39,6 +39,7 @@ static inline void update_player(t_game *game)
player_move(game, SPEED_MOV, -M_PI_2);
if (game->p.move_ea)
player_move(game, SPEED_MOV, M_PI_2);
return ;
}

int on_loop(t_game *game)
Expand Down
6 changes: 4 additions & 2 deletions cub3d/bonus/graphics/image_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* image_handlers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qdam <qdam@student.42.fr> +#+ +:+ +#+ */
/* By: mahautlatinis <mahautlatinis@student.42 +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/03 00:39:54 by qdam #+# #+# */
/* Updated: 2021/10/09 01:55:29 by qdam ### ########.fr */
/* Updated: 2023/10/13 17:18:49 by mahautlatin ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -20,6 +20,7 @@ void make_image_from_xpm(void *mlx_ptr, t_img *img, char *xpm)
if (img->img)
img->addr = mlx_get_data_addr(img->img, &img->bpp,
&img->line, &img->end);
return ;
}

void make_image_blank(void *mlx_ptr, t_img *img, int w, int h)
Expand All @@ -32,4 +33,5 @@ void make_image_blank(void *mlx_ptr, t_img *img, int w, int h)
&img->line, &img->end);
img->w = w;
img->h = h;
return ;
}
4 changes: 3 additions & 1 deletion cub3d/bonus/graphics/init_free.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: mahautlatinis <mahautlatinis@student.42 +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/30 22:54:23 by qdam #+# #+# */
/* Updated: 2023/10/03 21:58:27 by mahautlatin ### ########.fr */
/* Updated: 2023/10/13 17:19:00 by mahautlatin ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -30,6 +30,7 @@ static inline void hook_events(t_game *game)
mlx_hook(game->win, 17, 0L, on_destroy_win, game);
mlx_hook(game->win, 02, 1L << 0, on_key_press, game);
mlx_hook(game->win, 03, 1L << 1, on_key_release, game);
return ;
}

char *init_graphics(t_cub_data *cub, t_game *game)
Expand Down Expand Up @@ -73,4 +74,5 @@ void destroy_graphics(t_game *game)
mlx_destroy_display(game->ptr);
free(game->ptr);
}
return ;
}
5 changes: 3 additions & 2 deletions cub3d/bonus/graphics/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qdam <qdam@student.42.fr> +#+ +:+ +#+ */
/* By: mahautlatinis <mahautlatinis@student.42 +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/30 18:33:29 by qdam #+# #+# */
/* Updated: 2021/10/09 01:55:29 by qdam ### ########.fr */
/* Updated: 2023/10/13 17:19:06 by mahautlatin ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -23,6 +23,7 @@ void put_px(int x, int y, t_color color, t_img *img)

dst = img->addr + (y * img->line + x * (img->bpp >> 3));
*(t_color *)dst = color;
return ;
}

t_color get_px(int x, int y, t_img *img)
Expand Down
18 changes: 4 additions & 14 deletions cub3d/bonus/includes/cub3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* cub3D.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qdam <qdam@student.42.fr> +#+ +:+ +#+ */
/* By: mahautlatinis <mahautlatinis@student.42 +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/21 19:55:53 by qdam #+# #+# */
/* Updated: 2021/10/09 01:03:58 by qdam ### ########.fr */
/* Updated: 2023/10/13 17:33:53 by mahautlatin ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -39,18 +39,8 @@ int mlx_destroy_display(void *mlx_ptr);

# endif

/* ==== MISC FUNCTIONS ==== */

// Return the size of an array of pointers
size_t array_size(void **arr);

// Return the length of the longest string in the linked list
int max_list_str_len(t_list *lst);

// Deallocate a NULL-terminated array of strings
void free_tab(char **tab);

// Display an error message then exit the program with exit code 1
size_t array_size(void **arr);
void error_then_exit(char *fname, char *msg);

void free_tab(char **tab);
#endif
14 changes: 7 additions & 7 deletions cub3d/bonus/includes/cub3D_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: mahautlatinis <mahautlatinis@student.42 +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/08 15:17:42 by qdam #+# #+# */
/* Updated: 2023/10/03 22:07:50 by mahautlatin ### ########.fr */
/* Updated: 2023/10/13 17:27:30 by mahautlatin ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -33,12 +33,12 @@
# define KEY_S 1
# define KEY_D 2

# define SAND 0xF7E9DB
# define RED 0xBB4211
# define SAND 0xF7E9DB
# define RED 0xBB4211
# define RUSSIANRED 0xde300b
# define BROWN 0x54310F
# define CHOCO 0x351C04
# define MINISIDE 10
# define MINIPAD 16
# define BROWN 0x54310F
# define CHOCO 0x351C04
# define MINISIDE 10
# define MINIPAD 16

#endif
28 changes: 14 additions & 14 deletions cub3d/bonus/includes/cub3D_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
/* By: mahautlatinis <mahautlatinis@student.42 +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/25 09:30:09 by qdam #+# #+# */
/* Updated: 2023/10/03 22:13:13 by mahautlatin ### ########.fr */
/* Updated: 2023/10/13 17:28:02 by mahautlatin ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef CUB3D_ERRORS_H
# define CUB3D_ERRORS_H

/* ==== LAUNCH MESSAGES ==== */
# define ARG_ERROR "Must have a .cub file as argument"
# define NAME_ERROR "A .cub file is required"
# define READ_ERROR "\033[0;31mFile cannot be opened or is empty\033[0m"
# define UNKN_ERROR "Unknown error"
# define ARG_ERROR "Must have a .cub file as argument"
# define NAME_ERROR "A .cub file is required"
# define READ_ERROR "\033[0;31mFile cannot be opened or is empty\033[0m"
# define UNKN_ERROR "Unknown error"

/* ==== PARSER MESSAGES ==== */
# define PARSER_XPM_EXT "All texture files must have XPM extension"
Expand All @@ -33,17 +33,17 @@
# define PARSER_TEXTURE_LINE "Texture line error or direction already set"

/* ==== MALLOC MESSAGES ==== */
# define MALLOC_SPLIT "Malloc error during split"
# define MALLOC_STRDUP "Malloc error while parsing cub map (strdup)"
# define MALLOC_LSTNEW "Malloc error while parsing cub map (lstnew)"
# define MALLOC_COLLINE "Malloc error while parsing color line"
# define MALLOC_CHARMAP "Malloc error while creating map in game init"
# define MALLOC_TEXTURE "Malloc error while initializing wall textures"
# define MALLOC_SPLIT "Malloc error during split"
# define MALLOC_STRDUP "Malloc error while parsing cub map (strdup)"
# define MALLOC_LSTNEW "Malloc error while parsing cub map (lstnew)"
# define MALLOC_COLLINE "Malloc error while parsing color line"
# define MALLOC_CHARMAP "Malloc error while creating map in game init"
# define MALLOC_TEXTURE "Malloc error while initializing wall textures"

/* ==== CUBMAP MESSAGES ==== */
# define CUBMAP_NULL "Map is NULL"
# define CUBMAP_ROW_INV "A map row is not valid"
# define CUBMAP_DEF_DIR "No default direction found"
# define CUBMAP_NULL "Map is NULL"
# define CUBMAP_ROW_INV "A map row is not valid"
# define CUBMAP_DEF_DIR "No default direction found"

/* ==== GAME AND GRAPHICS MESSAGES ==== */
# define GRAPHICS_INIT "MinilibX initialization failed"
Expand Down
Loading

0 comments on commit 32e6457

Please sign in to comment.