
dev: - add documentation - main() is more readable fix: - unmanaged errors: - map parsing: error if color value is >255 - map parsing: load_textures(): check return value of xml_xpm_file_to_image() - main.c: draw_screen(): check return value of mlx_new_image() other details: - dev: color_from_rgb(): change signature - fix: nullize map in map_destroy - change: change error message for read_all_text() errors - change: change rotation speed - change: add and use contant NOOBONUS_SPEED
84 lines
2.9 KiB
C
84 lines
2.9 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* utils.h :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/10/15 16:56:47 by mcolonna #+# #+# */
|
|
/* Updated: 2024/11/12 17:01:35 by mcolonna ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#ifndef UTILS_H
|
|
# define UTILS_H
|
|
|
|
# include "include.h"
|
|
|
|
/// @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;
|
|
|
|
/// @brief Represents an TRGB color in 0xTTRRGGBB format. TT is 0x00 if opaque
|
|
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(u_int8_t red, u_int8_t green, u_int8_t 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.
|
|
uint32_t *get_data_addr(void *img_ptr);
|
|
|
|
/// @brief Create a vector according to the angle with a specific norm.
|
|
/// (0 rad is -y / pi/2 rad is +x)
|
|
///
|
|
/// @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
|