Cub3D
 
Loading...
Searching...
No Matches
Utils functions

All the functions used to help the program. More...

Functions

int safe_open (char *file_name)
 Try to open the map file specified by map_name.
 
int safe_close (int *fd)
 Close safely the file descriptor Modify the file descriptor to -1 after closing it.
 
int try_to_open_close_file (char *file_name)
 Try to open the file specified by file_name.
 
size_t count_array_length (char **array)
 Count the number of strings that an array have Should absolutely be NULL-Terminated.
 
void ft_free_all (t_data *data)
 Free all the memory allocated for the data structure.
 
void ft_free_file (t_map *map)
 Free the strings of the file.
 
void ft_free_textures (t_mlx *mlx, t_textures *textures)
 Free all the textures stored in mlx structure and map struct.
 
void ft_free_textures_path (t_map *map)
 Free the path (name) of the textures in memory.
 
void ft_free_map (t_map_raoul *map)
 Free the map structure.
 
uint64_t get_time_ms (void)
 Get time in milliseconds.
 
uint64_t timeval_to_us (const struct timeval *tv)
 Convert a timeval in microseconds.
 
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 set to 1.
 
float absf (float n)
 Returns the absolute value of a float.
 
int abs (int n)
 Returns the absolute value of an int.
 
int max (int a, int b)
 Returns the highest value between a and b.
 
double mind (double a, double b)
 Returns the lowest value between doubles a and b.
 
t_vec2 vec2rotate (t_vec2 vec, float angle)
 Returns a new vector rotated according to the angle.
 

Detailed Description

All the functions used to help the program.

Function Documentation

◆ abs()

int abs ( int n)

Returns the absolute value of an int.

Parameters
[in]nvalue
Returns
float absolute vale of n

◆ absf()

float absf ( float n)

Returns the absolute value of a float.

Parameters
[in]nvalue
Returns
float absolute value of n

◆ count_array_length()

size_t count_array_length ( char ** array)

Count the number of strings that an array have Should absolutely be NULL-Terminated.

Parameters
arrayarray of strings
Returns
size_t number of strings

◆ count_fps()

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 set to 1.

Parameters
print1 to print the FPS, 0 otherwise
Returns
uint16_t the current FPS
Here is the call graph for this function:

◆ ft_free_all()

void ft_free_all ( t_data * data)

Free all the memory allocated for the data structure.

Parameters
datadata structure
Here is the call graph for this function:

◆ ft_free_file()

void ft_free_file ( t_map * map)

Free the strings of the file.

Parameters
mapmap structure

◆ ft_free_map()

void ft_free_map ( t_map_raoul * map)

Free the map structure.

Parameters
mapmap structure

◆ ft_free_textures()

void ft_free_textures ( t_mlx * mlx,
t_textures * textures )

Free all the textures stored in mlx structure and map struct.

Parameters
mlxmlx structure
texturestextures structure

◆ ft_free_textures_path()

void ft_free_textures_path ( t_map * map)

Free the path (name) of the textures in memory.

Parameters
mapmap structure

◆ get_time_ms()

uint64_t get_time_ms ( void )

Get time in milliseconds.

Returns
uint64_t milliseconds

◆ max()

int max ( int a,
int b )

Returns the highest value between a and b.

Parameters
[in]afirst value
[in]bsecond value
Returns
int highest between a and b

◆ mind()

double mind ( double a,
double b )

Returns the lowest value between doubles a and b.

Parameters
[in]afirst value
[in]bsecond value
Returns
int lowest between a and b

◆ safe_close()

int safe_close ( int * fd)

Close safely the file descriptor Modify the file descriptor to -1 after closing it.

Parameters
fdpointer to the file descriptor to close
Returns
int 0 OK, -1 if an error occurred

◆ safe_open()

int safe_open ( char * file_name)

Try to open the map file specified by map_name.

Parameters
file_namefile name to open
Returns
int fd=OK, -1 if an error occurred

◆ timeval_to_us()

uint64_t timeval_to_us ( const struct timeval * tv)

Convert a timeval in microseconds.

Returns
uint64_t microseconds

◆ try_to_open_close_file()

int try_to_open_close_file ( char * file_name)

Try to open the file specified by file_name.

Parameters
file_namemap file name to open
Returns
int 1 OK, 0 if an error occurred
Here is the call graph for this function:

◆ vec2rotate()

t_vec2 vec2rotate ( t_vec2 vec,
float angle )

Returns a new vector rotated according to the angle.

Parameters
[in]vecvector
[in]angleangle
Returns
t_vec2 vector rotated