Added proper mlx definition in c3d structs + updated dump_info for map

splited off mlx structures and mlx functions in said filenames
added proper mlx names for the elements in c3d structures
This commit is contained in:
B.Goulard 2024-11-10 05:49:38 +01:00
parent 8ee1c5f85a
commit ad9390eaec
4 changed files with 126 additions and 105 deletions

View file

@ -6,7 +6,7 @@
/* 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 */
/* Updated: 2024/11/10 05:37:11 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,7 @@
# define CUB3D_STRUCT_H
# include <stdbool.h>
# include "mlx_structs.h"
# define FILE_EXTENSION ".cub"
# define FILE_EXTENSION_LEN 4
@ -110,8 +111,8 @@ typedef struct s_info
{
t_error last_error;
void *mlx_ptr;
void *win_ptr;
t_xvar *mlx_ptr;
t_win_list *win_ptr;
t_map map;
t_player player;
t_cli cli_ctx;

View file

@ -1,112 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fixed_mlx.h :+: :+: :+: */
/* mlx_functions.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 */
/* Updated: 2024/11/10 05:35:44 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;
# include "mlx_structs.h"
t_xvar *mlx_init(void);
t_win_list *mlx_new_window(t_xvar *mlx_ptr, int size_x, int size_y, char *title);

103
includes/mlx_structs.h Normal file
View file

@ -0,0 +1,103 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mlx_structs.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/10 05:33:08 by bgoulard #+# #+# */
/* Updated: 2024/11/10 05:38:28 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MLX_STRUCT_H
# define MLX_STRUCT_H
# include <X11/X.h>
# include <X11/Xlib.h>
# include <X11/extensions/XShm.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;
/// @brief window pointer from mlx
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;
/// @brief mlx pointer
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;
#endif /* MLX_STRUCT_H */

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/30 16:30:03 by rparodi #+# #+# */
/* Updated: 2024/11/09 01:45:20 by bgoulard ### ########.fr */
/* Updated: 2024/11/10 05:48:09 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,12 +20,19 @@
void dump_info(t_info *info)
{
const char *bool_str[2] = { "True", "False"};
printf("t_info:\n");
printf("\tcli_ctx:\n");
printf("\t\tfile: %s\n", info->cli_ctx.file);
printf("\t\tdebug: %s\n", info->cli_ctx.debug ? "true" : "false");
printf("\t\tsave: %s\n", info->cli_ctx.save ? "true" : "false");
printf("\t\thelp: %s\n", info->cli_ctx.help ? "true" : "false");
printf("\t\tdebug: %s\n", bool_str[info->cli_ctx.debug]);
printf("\t\tsave: %s\n", bool_str[info->cli_ctx.save]);
printf("\t\thelp: %s\n", bool_str[info->cli_ctx.help]);
printf("\tmap:\n");
printf("\t\tpath:%s\n", info->map.path);
printf("\t\tfd:%d\n", info->map.fd);
printf("\t\tsize:\t(x:%d, y:%d)\n", info->map.size.x, info->map.size.y);
printf("\t\tplayer_pos:\t(x:%lf, y:%lf)\n", info->map.player_pos.x, info->map.player_pos.y);
}
void check_err(t_info *info)
@ -44,6 +51,11 @@ void check_err(t_info *info)
void run_cub3d(t_info *info)
{
// code here
// - parse map
// - validity check
// - mlx inits
// - game loop
// - mlx cleanup
(void)info;
}
@ -62,13 +74,11 @@ int main_cub3d(char *file_arg, t_info *info)
return (cleanup_info(info), EXIT_SUCCESS);
}
int main(int argc, char *argv[])
{
t_info info;
int parsed_args;
(void)argc;
parsed_args = c3_options(&info, argc, argv);
if (parsed_args == -1)
return (EXIT_FAILURE);