First shot on structures, First shot on option
option:
Added options for help, debug, save, file using bgoulard lib
structures:
Moved cub3d.h structures to cub3d_struct.h
Added color, dpoint, ipoint, tile, cli, error
Modified t_map, t_player to use previously mentioned struct :
ipoint, dpoint, tyle
This commit is contained in:
parent
be6038dcc8
commit
8ee1c5f85a
14 changed files with 580 additions and 79 deletions
|
|
@ -6,59 +6,25 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/30 16:30:26 by rparodi #+# #+# */
|
||||
/* Updated: 2024/11/08 11:40:44 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/11/09 01:19:41 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CUB3D_H
|
||||
# define CUB3D_H
|
||||
|
||||
# include <stdio.h>
|
||||
# include <math.h>
|
||||
# include <fcntl.h>
|
||||
# include <stdlib.h>
|
||||
# include <sys/time.h>
|
||||
# include <unistd.h>
|
||||
# include <stdbool.h>
|
||||
|
||||
# include "libft.h"
|
||||
# include "../minilibx-linux/mlx.h"
|
||||
# include "message_error.h"
|
||||
|
||||
#include "cub3d_struct.h"
|
||||
# ifndef BONUS
|
||||
# define BONUS 0
|
||||
# endif
|
||||
|
||||
typedef struct s_map
|
||||
{
|
||||
int fd;
|
||||
char *path;
|
||||
char *oneline;
|
||||
char **content;
|
||||
double spawn_x;
|
||||
double spawn_y;
|
||||
} t_map;
|
||||
# include <stdbool.h>
|
||||
|
||||
typedef struct s_player
|
||||
{
|
||||
double pos_x;
|
||||
double pos_y;
|
||||
double dir_x;
|
||||
double dir_y;
|
||||
double view_x;
|
||||
double view_y;
|
||||
} t_player;
|
||||
|
||||
typedef struct s_info
|
||||
{
|
||||
void *mlx_ptr;
|
||||
void *win_ptr;
|
||||
t_map *map;
|
||||
t_player player;
|
||||
} t_info;
|
||||
|
||||
void print_error(char *msg);
|
||||
bool ft_parse_args(int argc, char *argv[]);
|
||||
void cleanup_info(t_info *info);
|
||||
int c3_options(t_info *info, int argc, char *argv[]);
|
||||
void c3_perror(t_info *info);
|
||||
void print_error(const char *msg);
|
||||
void parse_args(char *arg, t_info *inf);
|
||||
int main(int argc, char *argv[]);
|
||||
|
||||
#endif
|
||||
#endif /* CUB3D_H */
|
||||
|
|
|
|||
22
includes/cub3d_options.h
Normal file
22
includes/cub3d_options.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* cub3d_options.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/09 01:15:15 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/11/09 01:33:17 by bgoulard ### ########.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);
|
||||
|
||||
|
||||
# endif /* CUB3D_OPTIONS_H */
|
||||
120
includes/cub3d_struct.h
Normal file
120
includes/cub3d_struct.h
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* cub3d_struct.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/08 23:55:29 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/11/09 01:50:35 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CUB3D_STRUCT_H
|
||||
# define CUB3D_STRUCT_H
|
||||
|
||||
# include <stdbool.h>
|
||||
|
||||
# define FILE_EXTENSION ".cub"
|
||||
# define FILE_EXTENSION_LEN 4
|
||||
|
||||
// -- graphic utils
|
||||
|
||||
typedef struct s_color
|
||||
{
|
||||
union
|
||||
{
|
||||
unsigned int color;
|
||||
struct
|
||||
{
|
||||
unsigned char b;
|
||||
unsigned char g;
|
||||
unsigned char r;
|
||||
unsigned char a;
|
||||
};
|
||||
};
|
||||
} t_color;
|
||||
|
||||
typedef struct s_point
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} t_ipoint;
|
||||
|
||||
typedef struct s_dpoint
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
} t_dpoint;
|
||||
|
||||
// -- map utils
|
||||
|
||||
typedef enum e_tile
|
||||
{
|
||||
EMPTY,
|
||||
WALL
|
||||
} t_tile;
|
||||
|
||||
typedef struct s_map
|
||||
{
|
||||
int fd;
|
||||
char *path;
|
||||
|
||||
t_dpoint player_pos;
|
||||
t_ipoint size;
|
||||
t_tile *map;
|
||||
char **raw;
|
||||
} t_map;
|
||||
|
||||
// -- player utils
|
||||
|
||||
typedef struct s_player
|
||||
{
|
||||
t_dpoint pos;
|
||||
t_dpoint dir;
|
||||
t_dpoint view;
|
||||
} t_player;
|
||||
|
||||
// -- cli utils
|
||||
|
||||
typedef struct s_cli {
|
||||
int debug;
|
||||
char *file;
|
||||
bool save;
|
||||
bool help;
|
||||
} t_cli;
|
||||
|
||||
// -- error utils
|
||||
|
||||
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
|
||||
} t_error;
|
||||
|
||||
// -- main struct
|
||||
|
||||
typedef struct s_info
|
||||
{
|
||||
t_error last_error;
|
||||
|
||||
void *mlx_ptr;
|
||||
void *win_ptr;
|
||||
t_map map;
|
||||
t_player player;
|
||||
t_cli cli_ctx;
|
||||
} t_info;
|
||||
|
||||
#endif /* CUB3D_STRUCT_H */
|
||||
152
includes/fixed_mlx.h
Normal file
152
includes/fixed_mlx.h
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fixed_mlx.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/08 21:54:56 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/11/09 00:16:25 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FIXED_MLX_H
|
||||
# define FIXED_MLX_H
|
||||
|
||||
# include <unistd.h>
|
||||
# include <fcntl.h>
|
||||
# include <sys/mman.h>
|
||||
# include <X11/Xlib.h>
|
||||
# include <X11/Xutil.h>
|
||||
# include <sys/ipc.h>
|
||||
# include <sys/shm.h>
|
||||
# include <X11/extensions/XShm.h>
|
||||
# include <X11/XKBlib.h>
|
||||
/* #include <X11/xpm.h> */
|
||||
|
||||
|
||||
# define MLX_TYPE_SHM_PIXMAP 3
|
||||
# define MLX_TYPE_SHM 2
|
||||
# define MLX_TYPE_XIMAGE 1
|
||||
|
||||
# define MLX_MAX_EVENT LASTEvent
|
||||
|
||||
# define ENV_DISPLAY "DISPLAY"
|
||||
# define LOCALHOST "localhost"
|
||||
# define ERR_NO_TRUECOLOR "MinilibX Error : No TrueColor Visual available.\n"
|
||||
# define WARN_SHM_ATTACH "MinilibX Warning : X server can't attach shared memory.\n"
|
||||
|
||||
typedef struct s_xpm_col
|
||||
{
|
||||
int name;
|
||||
int col;
|
||||
} t_xpm_col;
|
||||
|
||||
|
||||
struct s_col_name
|
||||
{
|
||||
char *name;
|
||||
int color;
|
||||
};
|
||||
|
||||
typedef struct s_event_list
|
||||
{
|
||||
int mask;
|
||||
int (*hook)();
|
||||
void *param;
|
||||
} t_event_list;
|
||||
|
||||
|
||||
typedef struct s_win_list
|
||||
{
|
||||
Window window;
|
||||
GC gc;
|
||||
struct s_win_list *next;
|
||||
int (*mouse_hook)();
|
||||
int (*key_hook)();
|
||||
int (*expose_hook)();
|
||||
void *mouse_param;
|
||||
void *key_param;
|
||||
void *expose_param;
|
||||
t_event_list hooks[MLX_MAX_EVENT];
|
||||
} t_win_list;
|
||||
|
||||
|
||||
typedef struct s_img
|
||||
{
|
||||
XImage *image;
|
||||
Pixmap pix;
|
||||
GC gc;
|
||||
int size_line;
|
||||
int bpp;
|
||||
int width;
|
||||
int height;
|
||||
int type;
|
||||
int format;
|
||||
char *data;
|
||||
XShmSegmentInfo shm;
|
||||
} t_img;
|
||||
|
||||
typedef struct s_xvar
|
||||
{
|
||||
Display *display;
|
||||
Window root;
|
||||
int screen;
|
||||
int depth;
|
||||
Visual *visual;
|
||||
Colormap cmap;
|
||||
int private_cmap;
|
||||
t_win_list *win_list;
|
||||
int (*loop_hook)();
|
||||
void *loop_param;
|
||||
int use_xshm;
|
||||
int pshm_format;
|
||||
int do_flush;
|
||||
int decrgb[6];
|
||||
Atom wm_delete_window;
|
||||
Atom wm_protocols;
|
||||
int end_loop;
|
||||
} t_xvar;
|
||||
|
||||
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);
|
||||
|
||||
int mlx_get_screen_size(t_xvar *mlx_ptr, int *sizex, int *sizey);
|
||||
|
||||
#endif /* FIXED_MLX_H */
|
||||
|
|
@ -6,15 +6,16 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/30 16:43:20 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 11:23:20 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/11/09 00:42:02 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MESSAGE_ERROR_H
|
||||
# define MESSAGE_ERROR_H
|
||||
|
||||
# define ERR_ARGS_COUNT "You have to give only the map on arguments !\n"
|
||||
# define INV_NAME_MAP "The name of the map have to finish by `.cub` !\n"
|
||||
# define E_STR_AC "You have to give map as an argument !\n"
|
||||
# define E_STR_EXT_MAP "The name of the map have to finish by `.cub` !\n"
|
||||
# define E_STR_NAME_MAP "The name of the map is invalid !\n"
|
||||
|
||||
# define RED "\x1b[31m"
|
||||
# define BOLD_RED "\033[1;31m"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue