Projet de 42 : Fil de fer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
3.2 KiB

3 years ago
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fdf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/04 08:19:48 by narnaud #+# #+# */
/* Updated: 2022/05/21 17:32:20 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FDF_H
# define FDF_H
# define SPLIT_SIZE 512
# define BUFFER_SIZE 4096
# define WIN_X_SZ 900
# define WIN_Y_SZ 600
# define DEF_YAW 0
# define DEF_PITCH -45
# define SCALE 0.9
# define LINES_LEN 20
# ifdef __linux__
# include "./mlx/mlx.h"
# elif __APPLE__
# include <mlx.h>
# endif
# include "mlx_keycode.h"
# include <math.h>
# include <stdio.h>
# include <stddef.h>
# include <sys/stat.h>
# include <fcntl.h>
# include "./libft/libft.h"
typedef struct s_2d_float
{
float x;
float y;
} t_2df;
typedef struct s_2d_int
{
int x;
int y;
int len;
} t_2di;
typedef struct s_trigo
{
float raw;
float cos;
float sin;
} t_trigo;
typedef struct s_3d_pos
{
int x;
int y;
float z;
t_trigo yaw;
t_trigo pitch;
} t_3d;
typedef struct s_axis
{
t_trigo yaw;
t_trigo pitch;
} t_axis;
typedef struct s_map
{
int **altitude;
float z_mult;
int hightest;
int width;
int depth;
} t_map;
typedef struct s_camera
{
t_2di **render;
t_2di center;
t_axis ang;
float zoom;
int color;
} t_camera;
typedef struct s_datas
{
t_camera *cam;
t_map *map;
void *mlx;
void *win;
void *img;
int pixel_bits;
int line_bytes;
int endian;
} t_datas;
typedef struct s_buffer
{
char *content;
size_t pos;
size_t read_length;
} t_buffer;
typedef struct s_line_split
{
char *content;
size_t i;
size_t count;
struct s_line_split *next;
} t_split;
//fdf.c
void init_map(t_datas *datas, int fd);
void init_window(t_datas *datas);
//fdf_parsing.c
void parse_line(t_map *map, t_2di p, char ***splited);
t_map *parse_file(int fd, t_map *map);
const char *get_file_ext(const char *filename);
//fdf_drawing.c
int get_color(t_datas *datas, t_2di coord, float coef);
void draw_horiz_line(t_datas *datas, t_2di coord, int *buffer);
void draw_vert_line(t_datas *datas, t_2di coord, int *buffer);
void get_coords(t_2di coord, t_datas *datas);
void draw_map(t_datas *datas);
//fdf_commands.c
void key_hook_third(int keycode, t_datas *datas);
void key_hook_second(int keycode, t_datas *datas);
int key_hook_primary(int keycode, void *param);
//fdf_utils.c
int error_msg(char *msg, int sys);
t_trigo trigo_calc(float rad);
void clean_exit(t_datas *datas);
void draw_infos(t_datas *datas);
//gnl
char *get_next_line(int fd);
t_split *ft_new_split(char *content);
t_split *ft_splitlast(t_split *lst);
void ft_splitadd_back(t_split **alst, t_split *new);
#endif