github to gitea

This commit is contained in:
Leo Firmin
2025-10-27 23:12:49 +01:00
parent cd1882c3cc
commit 0c0d28ab36
134 changed files with 9850 additions and 338 deletions
+64
View File
@@ -0,0 +1,64 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/22 14:56:25 by lfirmin #+# #+# */
/* Updated: 2025/10/07 12:14:42 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CUB_H
# define CUB_H
# include "parsing.h"
# include "../libft/include/libft.h"
# include "../gnl/include/get_next_line.h"
# include "exec.h"
# include "keys.h"
# define ERROR_PREFIX "Error\n"
# define ERROR_EXT "Invalid file extension. Only .cub files are accepted."
# define ERROR_EMPT_PATH "Invalid map file path."
# define ERROR_INIT_DATA "Initialization of the data structure failed."
# define ERROR_INIT_TEX "Initialization of the textures structure failed."
# define ERROR_INIT_PARS "Initialization of the parsing structure failed."
# define ERROR_EMPTY "You have provided an empty file."
# define ERROR_COL "The RGB values provided are not valid or absent."
# define ERROR_NULL_P "Player not found or multiple players."
# define ERROR_BAD_CHAR "Invalid character in map."
# define ERROR_POS "Player position not found."
# define ERROR_ALLOC "Allocation failed."
# define ERROR_PLAYER "Player not found or multiple players."
# define ERROR_CHAR "Invalid character in map."
# define ERROR_DOUBLE "Multiple images/colors have been provided \
for the same texture."
# define ERROR_NOT_CLOSE "Map is not closed by walls."
# define ERROR_NOT_XMP "The texture file is not an xpm image."
# define ERR_I_N "Texture file provided for north is absent or inaccessible"
# define ERR_I_S "Texture file provided for south is absent or inaccessible"
# define ERR_I_E "Texture file provided for east is absent or inaccessible"
# define ERR_I_W "Texture file provided for west is absent or inaccessible"
typedef struct s_data
{
char **map;
char *map_path;
t_textures *texture;
t_data_parsing parsing;
} t_data;
//utils
void ft_error(char *message);
void free_char_array(char **array);
int ft_arrlen(char **arr);
void print_array(char **array);
int ft_strlen_2d(char **str);
//init
int init_data(t_data *data, char *path);
void free_data(t_data *data);
#endif
+157
View File
@@ -0,0 +1,157 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jle-neze <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/12 18:17:48 by jle-neze #+# #+# */
/* Updated: 2025/09/12 18:17:51 by jle-neze ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef EXEC_H
# define EXEC_H
# include <stdlib.h>
# include <stdint.h>
# include <math.h>
# include <../minilibx-linux/mlx.h>
/* Image (framebuffer) */
typedef struct s_img
{
void *ptr;
char *addr;
int bpp;
int line_len;
int endian;
int w;
int h;
} t_img;
/* Contexte MLX */
typedef struct s_mlx
{
void *mlx;
void *win;
int w;
int h;
t_img frame;
} t_mlx;
/* Couleurs de base */
typedef struct s_colors
{
int floor;
int ceil;
int wall_nsew[4]; /* 0:N 1:S 2:E 3:W → couleurs simples pour linstant */
} t_colors;
/* Entrées clavier (état des touches) */
typedef struct s_input
{
int w;
int a;
int s;
int d;
int left;
int right;
} t_input;
/* Monde (map) */
typedef struct s_world
{
int w;
int h;
char **grid; /* '0' vide, '1' mur */
} t_world;
/* Caméra / joueur (Raycasting) */
typedef struct s_cam
{
double pos_x;
double pos_y;
double dir_x;
double dir_y;
double plane_x;
double plane_y;
} t_cam;
typedef struct s_tex
{
void *ptr;
char *addr;
int bpp;
int line_len;
int endian;
int w;
int h;
} t_tex;
/* State principal */
typedef struct s_data t_data;
typedef struct s_game
{
t_mlx gfx;
t_colors colors;
t_input in;
t_world world;
t_cam cam;
double move_speed;
double rot_speed;
/* --- Textures --- */
t_tex tex[4]; /* 0:N 1:S 2:E 3:W */
int has_tex; /* 1 si chargées OK */
/* Pour le cleanup */
t_data *data; /* pointeur vers data pour cleanup */
} t_game;
/* init.c */
int init_window(t_game *g, int w, int h, char *title);
void cleanup_window(t_game *g);
/* hooks.c */
int on_destroy(t_game *g);
int on_keydown(int key, t_game *g);
int on_keyup(int key, t_game *g);
void setup_hooks(t_game *g);
/* image.c */
void img_put_pixel(t_img *img, int x, int y, int color);
/* draw.c */
void draw_background(t_game *g);
void draw_vline(t_game *g, int x, int y0, int y1, int color);
/* world.c */
int world_init_demo(t_world *w);
void world_free(t_world *w);
/* player.c */
void player_init(t_game *g, double px, double py, double dx, double dy);
void player_update(t_game *g);
/* raycast.c */
void raycast_frame(t_game *g);
/* loop.c */
int game_loop(t_game *g);
/* textures.c */
int textures_load(t_game *g, const char *no, const char *so,
const char *we, const char *ea);
void textures_free(t_game *g);
unsigned int tex_get_pixel(t_tex *t, int x, int y);
/* draw.c */
void draw_background(t_game *g);
void draw_vline(t_game *g, int x, int y0, int y1, int color);
void draw_tex_vline(t_game *g, int x, int y0, int y1,
t_tex *tex, int tex_x, double step, double tex_pos);
#endif
+35
View File
@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* keys.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jle-neze <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/12 18:18:03 by jle-neze #+# #+# */
/* Updated: 2025/09/12 18:18:07 by jle-neze ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef KEYS_H
# define KEYS_H
/* ESC */
# ifdef __APPLE__
# define KEY_ESC 53
# define KEY_W 13
# define KEY_A 0
# define KEY_S 1
# define KEY_D 2
# define KEY_LEFT 123
# define KEY_RIGHT 124
# else
# define KEY_ESC 65307
# define KEY_W 119
# define KEY_A 100 // a inverse au d car cest la camera qui deplace
# define KEY_S 115
# define KEY_D 97 // a inverse au d car cest la camera qui deplace
# define KEY_LEFT 65361
# define KEY_RIGHT 65363
# endif
#endif
+89
View File
@@ -0,0 +1,89 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsing.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/22 14:08:04 by lfirmin #+# #+# */
/* Updated: 2025/10/07 12:16:07 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PARSING_H
# define PARSING_H
# include <stdio.h>
# include <stdlib.h>
# include <unistd.h>
# include <fcntl.h>
struct s_data;
typedef struct s_data t_data;
typedef struct s_textures
{
char *north;
char *south;
char *east;
char *west;
int floor[3];
int ceiling[3];
} t_textures;
typedef struct s_data_parsing
{
char **raw_map;
int fd_map;
int fd_map_dup;
int player[3];
} t_data_parsing;
//player -> 0 = x, 1 = y, 2 = head
//parsing
int parsing(t_data *data);
//check_file
int check_extension(char *map_path);
int check_file(char *map_path, t_data_parsing *parsing);
//get_map
int get_map(t_data *data);
int line_counter(int fd);
int put_map_on_array(t_data *data);
char *clean_line(char *raw_line);
//init_parsing
int init_parsing(t_data_parsing *parsing);
int init_textures(t_textures *textures);
int free_textures(t_textures *textures);
//line_detect
int is_config_line(char *line);
int is_empty_line(char *line);
int is_texture_line(char *line);
int is_color_line(char *line);
int check_extension_2(char *str);
//get_textures
int get_texture_path(char *line, t_textures *texture, int *j);
int validate_and_convert_rgb(char **parts, int rgb[3]);
int get_rgb_values(char *line, int rgb[3]);
int is_valid_number(char *str);
//check_colors
int check_colors(t_textures *texture);
int is_rgb(int color[3]);
// check_map
int check_map_char(char **map);
void find_player_pos(char **map, int *player);
int flood_fill(char **map_cp, int x, int y);
int rep_ex_wall(char **map_cp, int x, int y);
int check_char_and_count(char c, int *p);
//check_map_2
int hasivalidchar(char **map);
int validate_map(char **map, int *player);
#endif