From 3e21d3d710839a5707a917ac95958caa1849eb56 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 11 Nov 2024 21:38:05 +0100 Subject: [PATCH] style: updated for the norme --- includes/cub3d.h | 4 +- includes/cub3d_options.h | 13 +- includes/cub3d_struct.h | 15 +- includes/mlx_functions.h | 304 ++++++++++++++++++++++++++++++++++----- raycast/mlx_init.c | 8 +- 5 files changed, 284 insertions(+), 60 deletions(-) diff --git a/includes/cub3d.h b/includes/cub3d.h index 99509de..a46e8c4 100644 --- a/includes/cub3d.h +++ b/includes/cub3d.h @@ -6,14 +6,14 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/30 16:30:26 by rparodi #+# #+# */ -/* Updated: 2024/11/11 20:00:54 by rparodi ### ########.fr */ +/* Updated: 2024/11/11 21:33:28 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef CUB3D_H # define CUB3D_H -#include "cub3d_struct.h" +# include "cub3d_struct.h" # ifndef BONUS # define BONUS 0 # endif diff --git a/includes/cub3d_options.h b/includes/cub3d_options.h index 9df387f..1d582e9 100644 --- a/includes/cub3d_options.h +++ b/includes/cub3d_options.h @@ -6,17 +6,16 @@ /* By: bgoulard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/09 01:15:15 by bgoulard #+# #+# */ -/* Updated: 2024/11/09 01:33:17 by bgoulard ### ########.fr */ +/* Updated: 2024/11/11 21:34:02 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef CUB3D_OPTIONS_H # define CUB3D_OPTIONS_H -void c3_set_file(void *usr_control_struct, const char *arg); -void c3_set_debug(void *usr_control_struct); -void c3_set_save(void *usr_control_struct); -void c3_print_help(void *usr_control_struct); +void c3_set_file(void *usr_control_struct, const char *arg); +void c3_set_debug(void *usr_control_struct); +void c3_set_save(void *usr_control_struct); +void c3_print_help(void *usr_control_struct); - -# endif /* CUB3D_OPTIONS_H */ +#endif /* CUB3D_OPTIONS_H */ diff --git a/includes/cub3d_struct.h b/includes/cub3d_struct.h index 719ec52..7aa4289 100644 --- a/includes/cub3d_struct.h +++ b/includes/cub3d_struct.h @@ -6,7 +6,7 @@ /* By: bgoulard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/08 23:55:29 by bgoulard #+# #+# */ -/* Updated: 2024/11/11 17:04:46 by rparodi ### ########.fr */ +/* Updated: 2024/11/11 21:34:38 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -58,14 +58,13 @@ typedef enum e_tile typedef struct s_map { - int fd; - char *path; - + int fd; + char *path; t_dpoint player_pos; t_ipoint size; t_tile *map; char **raw; -} t_map; +} t_map; // -- player utils @@ -77,7 +76,8 @@ typedef struct s_player // -- cli utils -typedef struct s_cli { +typedef struct s_cli +{ int debug; char *file; bool save; @@ -90,15 +90,12 @@ typedef enum e_error { NO_ERROR = 0, UNKNOWN_ERROR, - OPEN_FILE_ERROR, READ_FILE_ERROR, EXTENSION_FILE_ERROR, NAME_FILE_ERROR, MISSING_FILE_ERROR, - MALLOC_ERROR, - PARSE_ERROR, CLI_ERROR, MLX_ERROR diff --git a/includes/mlx_functions.h b/includes/mlx_functions.h index 8d06083..772a6ee 100644 --- a/includes/mlx_functions.h +++ b/includes/mlx_functions.h @@ -6,54 +6,280 @@ /* By: bgoulard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/08 21:54:56 by bgoulard #+# #+# */ -/* Updated: 2024/11/10 05:35:44 by bgoulard ### ########.fr */ +/* Updated: 2024/11/11 21:36:06 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef FIXED_MLX_H -# define FIXED_MLX_H +#ifndef MLX_FUNCTIONS_H +# define MLX_FUNCTIONS_H # include "mlx_structs.h" +/** + * @brief Initializes the MLX library. + * @return Pointer to the MLX instance structure. + */ t_xvar *mlx_init(void); -t_win_list *mlx_new_window(t_xvar *mlx_ptr, int size_x, int size_y, char *title); -int mlx_clear_window(t_xvar *mlx_ptr, t_win_list *win_ptr); -int mlx_pixel_put(t_xvar *mlx_ptr, t_win_list *win_ptr, int x, int y, int color); - -t_img *mlx_new_image(t_xvar *mlx_ptr,int width,int height); -char *mlx_get_data_addr(t_img *img_ptr, int *bits_per_pixel, int *size_line, int *endian); -int mlx_put_image_to_window(t_xvar *mlx_ptr, t_win_list *win_ptr, t_img *img_ptr, int x, int y); -int mlx_get_color_value(t_xvar *mlx_ptr, int color); - -int mlx_mouse_hook (t_win_list *win_ptr, int (*funct_ptr)(), void *param); -int mlx_key_hook (t_win_list *win_ptr, int (*funct_ptr)(), void *param); -int mlx_expose_hook (t_win_list *win_ptr, int (*funct_ptr)(), void *param); - -int mlx_loop_hook (t_xvar *mlx_ptr, int (*funct_ptr)(), void *param); -int mlx_loop (t_xvar *mlx_ptr); -int mlx_loop_end (t_xvar *mlx_ptr); - -int mlx_string_put(t_xvar *mlx_ptr, t_win_list *win_ptr, int x, int y, int color, char *string); -void mlx_set_font(t_xvar *mlx_ptr, t_win_list *win_ptr, char *name); -t_img *mlx_xpm_to_image(t_xvar *mlx_ptr, char **xpm_data, int *width, int *height); -t_img *mlx_xpm_file_to_image(t_xvar *mlx_ptr, char *filename, int *width, int *height); -int mlx_destroy_window(t_xvar *mlx_ptr, t_win_list *win_ptr); - -int mlx_destroy_image(t_xvar *mlx_ptr, t_img *img_ptr); - -int mlx_destroy_display(t_xvar *mlx_ptr); -int mlx_hook(t_win_list *win_ptr, int x_event, int x_mask, int (*funct)(), void *param); - -int mlx_do_key_autorepeatoff(t_xvar *mlx_ptr); -int mlx_do_key_autorepeaton(t_xvar *mlx_ptr); -int mlx_do_sync(t_xvar *mlx_ptr); - -int mlx_mouse_get_pos(t_xvar *mlx_ptr, t_win_list *win_ptr, int *x, int *y); -int mlx_mouse_move(t_xvar *mlx_ptr, t_win_list *win_ptr, int x, int y); -int mlx_mouse_hide(t_xvar *mlx_ptr, t_win_list *win_ptr); -int mlx_mouse_show(t_xvar *mlx_ptr, t_win_list *win_ptr); +/** + * @brief Creates a new window. + * @param mlx_ptr Pointer to the MLX instance. + * @param size_x Width of the window. + * @param size_y Height of the window. + * @param title Title of the window. + * @return Pointer to the new window structure. + */ +t_win_list *mlx_new_window(\ + t_xvar *mlx_ptr, int size_x, int size_y, char *title); +/** + * @brief Gets the screen size. + * @param mlx_ptr Pointer to the MLX instance. + * @param sizex Output parameter for the screen width. + * @param sizey Output parameter for the screen height. + * @return 0 on success, non-zero on error. + */ int mlx_get_screen_size(t_xvar *mlx_ptr, int *sizex, int *sizey); +/** + * @brief Clears the specified window. + * @param mlx_ptr Pointer to the MLX instance. + * @param win_ptr Pointer to the window to clear. + * @return 0 on success, non-zero on error. + */ +int mlx_clear_window(t_xvar *mlx_ptr, t_win_list *win_ptr); + +/** + * @brief Draws a pixel in the specified window. + * @param mlx_ptr Pointer to the MLX instance. + * @param win_ptr Pointer to the window. + * @param x X coordinate of the pixel. + * @param y Y coordinate of the pixel. + * @param color Color of the pixel. + * @return 0 on success, non-zero on error. + */ +int mlx_pixel_put(\ + t_xvar *mlx_ptr, t_win_list *win_ptr, int x, int y, int color); + + +/** + * @brief Creates a new image. + * @param mlx_ptr Pointer to the MLX instance. + * @param width Width of the image. + * @param height Height of the image. + * @return Pointer to the new image structure. + */ +t_img *mlx_new_image(t_xvar *mlx_ptr, int width, int height); + +/** + * @brief Retrieves the address of the image data. + * @param img_ptr Pointer to the image. + * @param bits_per_pixel Bits per pixel of the image. + * @param size_line Size of each line in bytes. + * @param endian Endian of the image (0 for little-endian, 1 for big-endian). + * @return Pointer to the image data. + */ +char *mlx_get_data_addr(t_img *img_ptr, int *bits_per_pixel, int *size_line, int *endian); + +/** + * @brief Puts an image into a window. + * @param mlx_ptr Pointer to the MLX instance. + * @param win_ptr Pointer to the window. + * @param img_ptr Pointer to the image. + * @param x X coordinate in the window. + * @param y Y coordinate in the window. + * @return 0 on success, non-zero on error. + */ +int mlx_put_image_to_window(t_xvar *mlx_ptr, t_win_list *win_ptr, t_img *img_ptr, int x, int y); + +/** + * @brief Gets the color value for the specified color. + * @param mlx_ptr Pointer to the MLX instance. + * @param color The color to retrieve the value for. + * @return The color value. + */ +int mlx_get_color_value(t_xvar *mlx_ptr, int color); + +/** + * @brief Sets a mouse hook on the window. + * @param win_ptr Pointer to the window. + * @param funct_ptr Pointer to the function to call on mouse events. + * @param param Parameter passed to the hook function. + * @return 0 on success, non-zero on error. + */ +int mlx_mouse_hook(t_win_list *win_ptr, int (*funct_ptr)(), void *param); + +/** + * @brief Sets a keyboard hook on the window. + * @param win_ptr Pointer to the window. + * @param funct_ptr Pointer to the function to call on key events. + * @param param Parameter passed to the hook function. + * @return 0 on success, non-zero on error. + */ +int mlx_key_hook(t_win_list *win_ptr, int (*funct_ptr)(), void *param); + +/** + * @brief Sets an expose hook on the window. + * @param win_ptr Pointer to the window. + * @param funct_ptr Pointer to the function to call on expose events. + * @param param Parameter passed to the hook function. + * @return 0 on success, non-zero on error. + */ +int mlx_expose_hook(t_win_list *win_ptr, int (*funct_ptr)(), void *param); + +/** + * @brief Sets a loop hook for repeated execution. + * @param mlx_ptr Pointer to the MLX instance. + * @param funct_ptr Pointer to the function to call in the loop. + * @param param Parameter passed to the hook function. + * @return 0 on success, non-zero on error. + */ +int mlx_loop_hook(t_xvar *mlx_ptr, int (*funct_ptr)(), void *param); + +/** + * @brief Starts the main loop for MLX. + * @param mlx_ptr Pointer to the MLX instance. + * @return 0 on success, non-zero on error. + */ +int mlx_loop(t_xvar *mlx_ptr); + +/** + * @brief Ends the main loop for MLX. + * @param mlx_ptr Pointer to the MLX instance. + * @return 0 on success, non-zero on error. + */ +int mlx_loop_end(t_xvar *mlx_ptr); + +/** + * @brief Draws a string in the specified window. + * @param mlx_ptr Pointer to the MLX instance. + * @param win_ptr Pointer to the window. + * @param x X coordinate for the string. + * @param y Y coordinate for the string. + * @param color Color of the string. + * @param string The string to display. + * @return 0 on success, non-zero on error. + */ +int mlx_string_put(t_xvar *mlx_ptr, t_win_list *win_ptr, int x, int y, int color, char *string); + +/** + * @brief Sets the font for the window. + * @param mlx_ptr Pointer to the MLX instance. + * @param win_ptr Pointer to the window. + * @param name The font name. + */ +void mlx_set_font(t_xvar *mlx_ptr, t_win_list *win_ptr, char *name); + +/** + * @brief Converts XPM data to an image. + * @param mlx_ptr Pointer to the MLX instance. + * @param xpm_data The XPM data. + * @param width Output parameter for the width of the image. + * @param height Output parameter for the height of the image. + * @return Pointer to the created image. + */ +t_img *mlx_xpm_to_image(t_xvar *mlx_ptr, char **xpm_data, int *width, int *height); + +/** + * @brief Converts an XPM file to an image. + * @param mlx_ptr Pointer to the MLX instance. + * @param filename The XPM file name. + * @param width Output parameter for the width of the image. + * @param height Output parameter for the height of the image. + * @return Pointer to the created image. + */ +t_img *mlx_xpm_file_to_image(t_xvar *mlx_ptr, char *filename, int *width, int *height); + +/** + * @brief Destroys a window. + * @param mlx_ptr Pointer to the MLX instance. + * @param win_ptr Pointer to the window. + * @return 0 on success, non-zero on error. + */ +int mlx_destroy_window(t_xvar *mlx_ptr, t_win_list *win_ptr); + +/** + * @brief Destroys an image. + * @param mlx_ptr Pointer to the MLX instance. + * @param img_ptr Pointer to the image. + * @return 0 on success, non-zero on error. + */ +int mlx_destroy_image(t_xvar *mlx_ptr, t_img *img_ptr); + +/** + * @brief Destroys the MLX display. + * @param mlx_ptr Pointer to the MLX instance. + * @return 0 on success, non-zero on error. + */ +int mlx_destroy_display(t_xvar *mlx_ptr); + +/** + * @brief Sets an event hook for a specific event. + * @param win_ptr Pointer to the window. + * @param x_event The event type. + * @param x_mask The event mask. + * @param funct Function to call for the event. + * @param param Parameter passed to the hook function. + * @return 0 on success, non-zero on error. + */ +int mlx_hook(t_win_list *win_ptr, int x_event, int x_mask, int (*funct)(), void *param); + +/** + * @brief Disables key auto-repeat. + * @param mlx_ptr Pointer to the MLX instance. + * @return 0 on success, non-zero on error. + */ +int mlx_do_key_autorepeatoff(t_xvar *mlx_ptr); + +/** + * @brief Enables key auto-repeat. + * @param mlx_ptr Pointer to the MLX instance. + * @return 0 on success, non-zero on error. + */ +int mlx_do_key_autorepeaton(t_xvar *mlx_ptr); + +/** + * @brief Synchronizes the MLX display. + * @param mlx_ptr Pointer to the MLX instance. + * @return 0 on success, non-zero on error. + */ +int mlx_do_sync(t_xvar *mlx_ptr); + +/** + * @brief Retrieves the current mouse position. + * @param mlx_ptr Pointer to the MLX instance. + * @param win_ptr Pointer to the window. + * @param x Output parameter for the X coordinate. + * @param y Output parameter for the Y coordinate. + * @return 0 on success, non-zero on error. + */ +int mlx_mouse_get_pos(t_xvar *mlx_ptr, t_win_list *win_ptr, int *x, int *y); + +/** + * @brief Moves the mouse to a specified position. + * @param mlx_ptr Pointer to the MLX instance. + * @param win_ptr Pointer to the window. + * @param x X coordinate to move to. + * @param y Y coordinate to move to. + * @return 0 on success, non-zero on error. + */ +int mlx_mouse_move(t_xvar *mlx_ptr, t_win_list *win_ptr, int x, int y); + +/** + * @brief Hides the mouse cursor. + * @param mlx_ptr Pointer to the MLX instance. + * @param win_ptr Pointer to the window. + * @return 0 on success, non-zero on error. + */ +int mlx_mouse_hide(t_xvar *mlx_ptr, t_win_list *win_ptr); + +/** + * @brief Shows the mouse cursor. + * @param mlx_ptr Pointer to the MLX instance. + * @param win_ptr Pointer to the window. + * @return 0 on success, non-zero on error. + */ +int mlx_mouse_show(t_xvar *mlx_ptr, t_win_list *win_ptr); + + #endif /* FIXED_MLX_H */ diff --git a/raycast/mlx_init.c b/raycast/mlx_init.c index 26486c5..0a5ee03 100644 --- a/raycast/mlx_init.c +++ b/raycast/mlx_init.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/11 19:53:42 by rparodi #+# #+# */ -/* Updated: 2024/11/11 20:11:11 by rparodi ### ########.fr */ +/* Updated: 2024/11/11 21:27:12 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,14 +18,16 @@ int _keyhook(int keycode, t_info *info) { + (void)info; if (keycode == 53 || keycode == 65307) - return (cleanup_info(info), EXIT_SUCCESS); + exit(EXIT_SUCCESS); // return (cleanup_info(info), EXIT_SUCCESS); /// Remove for segfault return (0); } int _redcross(t_info *info) { - return (cleanup_info(info), EXIT_SUCCESS); + (void) info; // return (cleanup_info(info), EXIT_SUCCESS); /// Remove for segfault + exit(EXIT_SUCCESS); } t_win_list *_init_mlx_window(t_info *info)