Cub3D
 
Loading...
Searching...
No Matches
cub3d.h
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* cub3d.h :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: ppontet <ppontet@student.42lyon.fr> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/01/10 13:08:27 by ppontet #+# #+# */
9/* Updated: 2025/10/22 15:55:20 by ppontet ### ########lyon.fr */
10/* */
11/* ************************************************************************** */
12
13#ifndef CUB3D_H
14# define CUB3D_H
15
22
23# include "data_structure.h"
24# include <stddef.h>
25# include <stdint.h>
26# include <unistd.h>
27# include <sys/time.h>
28
35
39# define PI 3.141592653589793238462643383279502884197169399375105820974944592307
40
44# define MINIMAP_DEFAULT_VALUE true
48# define FIELD_OF_VIEW_DEFAULT_VALUE true
52# define COLLISION_DEFAULT_VALUE true
53
57# define ENABLE_FILTERS true
58
59// Playability settings
66# define MOUSE_SENSITIVITY_FACTOR 0.001f
72# define MOVEMENT_SPEED_TURNING 0.015f
79# define MOVEMENT_SPEED_FWD_BWD 0.025f
86# define MOVEMENT_SPEED_LEFT_RIGHT 0.015f
87
88// Minimap settings
89# define MINIMAP_PLAYER_COLOR 0xffffff00
90# define MINIMAP_PLAYER_LINE_SIGHT_COLOR 0xffffff00
91# define MINIMAP_PLAYER_CONE_SIGHT_COLOR 0xffffaaaa
92# define MINIMAP_FLOOR_COLOR 0xff000000
93# define MINIMAP_WALL_COLOR 0xffffffff
94# define MINIMAP_KEY_COLOR 0xffffff00
95# define MINIMAP_DOOR_COLOR 0xff0000ff
99# define MINIMAP_NUM_TILES_X 15
103# define MINIMAP_NUM_TILES_Y 15
104# define MINIMAP_TILE_SIZE 16
105# define MINIMAP_TILES_X 15
106# define MINIMAP_TILES_Y 15
107// Any size higher half of MINIMAP_TILE_SIZE will be strange
108# define MINIMAP_PLAYER_SIZE 4
109# define MINIMAP_LINE_OF_SIGHT_FACTOR 2
110
111// Debug printing settings
115# define DEBUG_PRINT_KEYCODE 0
119# define DEBUG_PRINT_FPS 0
125# define DEBUG_FPS_REFRESH 0
126
130# define DEBUG_PRINT_TEXTURE_SWAP 0
131
135# define DEBUG_PRINT_TEXTURE_ALTERED 0
136
137// If you want to follow closely to the subject, you need to set these to 0
141# define CROSS_APPLY_SETTINGS 0
145# define ESCAPE_APPLY_SETTINGS 0
147
153
161int cub3d(int argc, char **argv);
162
171int cub_read_args(int argc, char **argv, t_args *args);
172
179char **fill_config_region(t_map *map);
180
187char **fill_map_region(t_map *map);
188
196char **read_file_lines(t_map *map, char *map_name);
197
204size_t count_file_lines(char *file_name);
205
212void ft_exit(t_mlx mlx, t_map *map);
213
220int ft_mlx_init(t_data *data);
221
227void ft_mlx_end(t_mlx *mlx);
229
235
242void *ft_settings(t_mlx *mlx);
250enum e_screen_size circle_state(int x, int y);
258int ft_set_screen_size(t_mlx *mlx, enum e_screen_size size);
264void ft_free_settings(t_mlx *mlx);
270void settings_hooks(t_data *data);
277void state_machine(int keycode, t_mlx *mlx);
279
285
293int cub_keydown_hook(int keycode, void *param);
301int cub_keyup_hook(int keycode, void *param);
311int cub_mouse_click_hook(int button, int x, int y, void *param);
320int cub_mouse_hook(int x, int y, void *param);
321// Settings hooks
331int hook_settings_handle_mouse_click(int button, int x, int y,
332 void *param);
341int hook_settings_handle_mouse_motion(int x, int y,
342 void *param);
349int hook_settings_close_window(void *param);
350
358int hook_settings_handle_keypress(int keycode, void *param);
360
366
375t_map ft_map_check_dimensions(t_map *map, char *map_name);
376
384
392
399size_t is_config_line(char *line);
400
409
417t_coordinates find_position(t_map *map, const char *charset);
418
425int validate_map(t_map *map);
426
433bool is_only_whitespace(const char *str);
434
440void suppress_newlines(char **lines);
441
448int is_walkable(char c);
449
458int is_in_bounds(char **map, size_t y, size_t x);
460
466
473int safe_open(char *file_name);
474
482int safe_close(int *fd);
483
490int try_to_open_close_file(char *file_name);
491
499size_t count_array_length(char **array);
500
506void ft_free_all(t_data *data);
507
513void ft_free_file(t_map *map);
514
521void ft_free_textures(t_mlx *mlx, t_textures *textures);
522
529
535void ft_free_map(t_map_raoul *map);
536
542uint64_t get_time_ms(void);
543
549uint64_t timeval_to_us(const struct timeval *tv);
550
557uint16_t count_fps(bool print);
559
560#endif
Header file for all the types and structures of the project.
struct s_data t_data
Definition data_structure.h:32
e_screen_size
Enum used to store the screen size. It is used to set the screen size in the settings....
Definition data_structure.h:52
struct s_map_raoul t_map_raoul
Definition data_structure.h:31
struct s_args t_args
Definition data_structure.h:39
struct s_mlx t_mlx
Definition data_structure.h:29
struct s_map t_map
Definition data_structure.h:30
struct s_textures t_textures
Definition data_structure.h:27
struct s_coordinates t_coordinates
Definition data_structure.h:35
int cub_mouse_click_hook(int button, int x, int y, void *param)
Hook when the mouse is moved while clicking.
Definition ft_hooks.c:74
int cub_keydown_hook(int keycode, void *param)
Hook when a key is pressed.
Definition ft_hooks.c:21
int hook_settings_close_window(void *param)
Hook used to close window or set the window size if MACRO Enabled.
Definition ft_settings_hooks.c:19
int hook_settings_handle_mouse_motion(int x, int y, void *param)
Hook when the mouse is moved for the settings.
Definition ft_settings_hooks.c:57
int cub_keyup_hook(int keycode, void *param)
Hook when a key is released.
Definition ft_hooks.c:42
int hook_settings_handle_keypress(int keycode, void *param)
Handle mouse click in the settings window.
Definition ft_settings_hooks.c:31
int cub_mouse_hook(int x, int y, void *param)
Hook when the mouse is moved.
Definition ft_hooks.c:65
int hook_settings_handle_mouse_click(int button, int x, int y, void *param)
Hook when the mouse is moved while clicking for the settings.
Definition ft_settings_hooks.c:45
void ft_mlx_end(t_mlx *mlx)
Close and free the mlx structure.
Definition ft_free_mlx.c:18
void ft_exit(t_mlx mlx, t_map *map)
Exit the program.
char ** fill_map_region(t_map *map)
Fill the map region of the file.
Definition ft_search_map.c:40
char ** fill_config_region(t_map *map)
Fill the config region of the file.
Definition ft_search_config.c:37
char ** read_file_lines(t_map *map, char *map_name)
Read the map file line by line and return an array of strings.
Definition ft_file_fill.c:40
int cub3d(int argc, char **argv)
Main function of the cub3d project.
Definition cub3d.c:82
int ft_mlx_init(t_data *data)
Initialize the mlx structure, create settings window, and load game.
Definition ft_init_mlx.c:22
int cub_read_args(int argc, char **argv, t_args *args)
Reads and verifies the arguments passed to the program.
Definition read.c:50
size_t count_file_lines(char *file_name)
Simple function to count the number of lines in a file.
Definition ft_file_fill.c:17
t_coordinates find_position(t_map *map, const char *charset)
Find the position of the player with charset in the map.
Definition ft_map_boundaries.c:33
int is_in_bounds(char **map, size_t y, size_t x)
Check if a position is in bounds of map or not.
Definition ft_map_boundaries.c:24
size_t is_config_line(char *line)
Return a positive number if a config line is detected.
Definition ft_search_config.c:21
int validate_map(t_map *map)
Validate if the map has unclosed holes or an unfinished outer layer.
Definition ft_validate_map.c:60
t_map ft_map_check_dimensions(t_map *map, char *map_name)
Check the map structure and try to open the map file. sets error to -1 if an error occurred.
Definition ft_map_check.c:22
bool is_only_whitespace(const char *str)
Check if the string contains only whitespace characters.
Definition ft_map_utils.c:35
int is_walkable(char c)
Check if a character is walkable or not.
Definition ft_map_boundaries.c:19
void suppress_newlines(char **lines)
Suppress newlines in the given lines.
Definition ft_map_utils.c:16
t_map check_map_chars_borders(t_map *map)
Check if the map has only acceptable characters and if there is borders everywhere,...
Definition ft_map_check.c:51
t_map ft_check_config(t_map *map)
Check if the config is properly formatted or not.
Definition ft_search_config.c:66
t_map ft_check_floor_ceiling(t_map *map)
Check the floor and ceiling colors.
Definition ft_check_colors.c:96
void ft_free_settings(t_mlx *mlx)
Free all the settings variables.
Definition ft_free_mlx.c:40
enum e_screen_size circle_state(int x, int y)
Return an enum according to selected circle using coordinates.
Definition ft_settings_state.c:36
void settings_hooks(t_data *data)
Set the settings hooks on the settings window.
Definition ft_settings.c:51
int ft_set_screen_size(t_mlx *mlx, enum e_screen_size size)
Set screen size according to an enum.
Definition ft_settings.c:98
void * ft_settings(t_mlx *mlx)
Generate the window settings for the program.
Definition ft_settings.c:24
void state_machine(int keycode, t_mlx *mlx)
State machine for the settings window.
Definition ft_settings_state.c:17
uint64_t timeval_to_us(const struct timeval *tv)
Convert a timeval in microseconds.
Definition ft_time.c:29
void ft_free_textures_path(t_map *map)
Free the path (name) of the textures in memory.
Definition ft_free.c:79
void ft_free_file(t_map *map)
Free the strings of the file.
Definition ft_free.c:39
void ft_free_map(t_map_raoul *map)
Free the map structure.
Definition ft_free.c:30
void ft_free_all(t_data *data)
Free all the memory allocated for the data structure.
Definition ft_free.c:19
uint64_t get_time_ms(void)
Get time in milliseconds.
Definition ft_time.c:19
int safe_close(int *fd)
Close safely the file descriptor Modify the file descriptor to -1 after closing it.
Definition ft_safe.c:40
uint16_t count_fps(bool print)
Count the FPS and print it to the console. It will print the FPS every second if DEBUG_PRINT_FPS is s...
Definition ft_time.c:46
int try_to_open_close_file(char *file_name)
Try to open the file specified by file_name.
Definition ft_utils.c:19
void ft_free_textures(t_mlx *mlx, t_textures *textures)
Free all the textures stored in mlx structure and map struct.
Definition ft_free.c:61
size_t count_array_length(char **array)
Count the number of strings that an array have Should absolutely be NULL-Terminated.
Definition ft_utils.c:41
int safe_open(char *file_name)
Try to open the map file specified by map_name.
Definition ft_safe.c:22