42_cub3d/include/utils.h
mcolonna 26621c72c6 docs, clean, several things... *
- add docs
- remove unused things
- redo modifications i accidentally erased from spacetime
2024-11-07 01:03:05 +01:00

86 lines
2.9 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/15 16:56:47 by mcolonna #+# #+# */
/* Updated: 2024/11/01 20:55:00 by mc ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef UTILS_H
# define UTILS_H
# include "include.h"
typedef uint32_t u_int32_t;
/// @brief Represents a point of double type.
typedef struct s_point_double
{
double x;
double y;
} t_point_double;
/// @brief Represents a point of int type.
typedef struct s_point_int
{
int x;
int y;
} t_point_int;
// TODO Must the transparency be 0 or 255?
/// @brief Represents an TRGB color in 0xTTRRGGBB format.
typedef __u32 t_color;
/// @brief Convert a color from each color value to a t_color.
///
/// @param red Level of red from 0 to 255.
/// @param green Level of green from 0 to 255.
/// @param blue Level of blue from 0 to 255.
/// @return The result.
t_color color_from_rgb(int red, int green, int blue);
/// @brief Write an error message on stderr.
///
/// @param str... All the strings to write. The last parameter MUST BE NULL.
void write_err(const char *str, ...);
/// @brief Call the function in loop.
/// If not enough time passed since the last call, returns without doing
/// anything.
///
/// @param f Function to call in loop.
void timedloop(void (*f)(void));
/// @brief Get an address to the image data, but only if
/// bpp == 32 and endian == 0.
///
/// @param img_ptr mlx image to use.
/// @return Address to the data, or NULL if error.
u_int32_t *get_data_addr(void *img_ptr);
/// @brief Create a vector according to the angle with a specific norm.
/// (0 rad returns (0;-1) / pi/2 rad returns (1;0))
///
/// @param vec This will be set to the result.
/// @param angle Angle to use in radians.
/// @param norm Norm the vector must have.
void vector_from_rotation(t_point_double *vec, double angle, double norm);
/// @brief Size of buffer used in read_all_text().
# define READ_ALL_TEXT_BUFFER_SIZE 1000
/// @brief Read all the text of the given file.
///
/// If the last line isn't ended by a '\\n', add one.
///
/// If error, returns NULL and set errno accordingly.
///
/// @param fd File descriptor of the file.
/// @return Alloc'd string of the file content. NULL if error.
char *read_all_text(int fd);
#endif