reorganize all files (only renamings)
This commit is contained in:
parent
609bd90b54
commit
878de1098b
27 changed files with 21 additions and 14 deletions
90
include/algo.h
Normal file
90
include/algo.h
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* algo.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */
|
||||
/* Updated: 2024/10/31 16:03:42 by mc ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ALGO_H
|
||||
# define ALGO_H
|
||||
|
||||
# include <unistd.h>
|
||||
# include <math.h>
|
||||
# include <linux/types.h>
|
||||
# include <stdbool.h>
|
||||
# include <stdlib.h>
|
||||
# include <X11/X.h>
|
||||
# include "mlx.h"
|
||||
# include "libft.h"
|
||||
|
||||
# include "stream.h"
|
||||
# include "read_all_text.h"
|
||||
# include "map.h"
|
||||
# include "map_mapping.h"
|
||||
|
||||
# define MAP_WIDTH 24 // cases (TODO test)
|
||||
# define MAP_HEIGHT 24 // cases (TODO test)
|
||||
# define TEX_WIDTH 64
|
||||
# define TEX_HEIGHT 64
|
||||
# define MOVE_SPEED 0.05 // cases
|
||||
# define PI 3.1415926535
|
||||
# define ROT_SPEED_DIVIDE_PI 64 // pi/n rad
|
||||
# define COLOR_WALL 0xFF0000 // 0xRRGGBB
|
||||
# define COLOR_CEILING 0x29f8ff // 0xRRGGBB
|
||||
# define COLOR_FLOOR 0xFF985C // 0xRRGGBB
|
||||
# define SCREEN_WIDTH 640 // px
|
||||
# define SCREEN_HEIGHT 480 // px
|
||||
# define FOV 0.66 // ? TODO unit
|
||||
# define HITBOX 0.25 // cases. should be more than MOVE_SPEED
|
||||
|
||||
typedef struct s_tex
|
||||
{
|
||||
void *textures[4];
|
||||
void *current_tex;
|
||||
int tex_height;
|
||||
int tex_width;
|
||||
int tex_dir;
|
||||
int tex_x;
|
||||
int tex_y;
|
||||
int bpp;
|
||||
int size_line;
|
||||
int endian;
|
||||
} t_tex;
|
||||
|
||||
typedef struct s_ray
|
||||
{
|
||||
// pos player on map (cases)
|
||||
t_point_double dir;
|
||||
bool side;
|
||||
double wallx;
|
||||
} t_ray;
|
||||
|
||||
extern void *g_mlx;
|
||||
extern void *g_win;
|
||||
extern t_player g_player;
|
||||
extern t_map g_map;
|
||||
// extern t_tex g_tex;
|
||||
|
||||
/// @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, ...);
|
||||
|
||||
void vector_from_rotation(t_point_double *vec, double angle, double norm);
|
||||
|
||||
int render(u_int32_t *img_data, t_tex *tex);
|
||||
|
||||
void draw_screen(void);
|
||||
|
||||
void move(void);
|
||||
|
||||
void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex);
|
||||
|
||||
void draw_wall(t_tex *tex, t_ray *ray, const int line_height, int x,
|
||||
int y, u_int32_t *img_data);
|
||||
#endif
|
||||
35
include/input.h
Normal file
35
include/input.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* input.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/17 14:43:09 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/10/17 14:59:41 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef INPUT_H
|
||||
# define INPUT_H
|
||||
|
||||
# include <stdbool.h>
|
||||
|
||||
/// @brief Modified by the input of the user. A value becomes true
|
||||
/// when the user presses the corresponding key.
|
||||
typedef struct s_input_actions
|
||||
{
|
||||
bool left;
|
||||
bool right;
|
||||
bool up;
|
||||
bool down;
|
||||
bool quit;
|
||||
} t_input_actions;
|
||||
|
||||
extern t_input_actions g_input_actions;
|
||||
|
||||
int keypress(int keycode);
|
||||
int keyrelease(int keycode);
|
||||
void input_init(void);
|
||||
|
||||
#endif
|
||||
134
include/map.h
Normal file
134
include/map.h
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* map.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/10/31 15:57:58 by mc ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MAP_H
|
||||
# define MAP_H
|
||||
|
||||
# include <stdbool.h>
|
||||
# include "utils.h"
|
||||
|
||||
/// @brief The type of a case.
|
||||
typedef enum e_map_wall
|
||||
{
|
||||
/// @brief Empty case, for '0' and ' '.
|
||||
EMPTY,
|
||||
/// @brief A wall, for '1'.
|
||||
WALL,
|
||||
} t_map_wall;
|
||||
|
||||
/// @brief An object of the map (player, enemies?)
|
||||
typedef struct s_object
|
||||
{
|
||||
/// @brief Function called when creating the object.
|
||||
///
|
||||
/// @param data Address of the s_object.data pointer.
|
||||
void (*init)(void **data, t_point_int pos);
|
||||
|
||||
/// @brief Function called when destroying the object (to avoid leaks).
|
||||
///
|
||||
/// @param data Address of the s_object.data pointer.
|
||||
void (*destroy)(void **data, t_point_int pos);
|
||||
|
||||
/// @brief Function called each tick.
|
||||
///
|
||||
/// @param data Address of the s_object.data pointer.
|
||||
void (*tick)(void **data, t_point_int pos);
|
||||
|
||||
/// @brief Pointer the object can use to save data.
|
||||
void *data;
|
||||
} t_object;
|
||||
|
||||
/// @brief Represents a case of the map.
|
||||
typedef struct s_map_case
|
||||
{
|
||||
/// @brief 'true' if the case is inside of the room (false with ' ' char)
|
||||
bool inside;
|
||||
|
||||
/// @brief Is the case empty or a wall?
|
||||
t_map_wall wall;
|
||||
|
||||
/// @brief The object that appears on this case. If there is none,
|
||||
/// every pointer of the struct will be NULL.
|
||||
t_object object;
|
||||
} t_map_case;
|
||||
|
||||
typedef struct s_player
|
||||
{
|
||||
// pos player on map (cases)
|
||||
t_point_double pos;
|
||||
// player rotation (rad)
|
||||
double rot;
|
||||
} t_player;
|
||||
|
||||
/// @brief Represents a map.
|
||||
typedef struct s_map
|
||||
{
|
||||
/// @brief Color of the floor.
|
||||
t_color color_floor;
|
||||
|
||||
/// @brief Color of the ceiling.
|
||||
t_color color_ceiling;
|
||||
|
||||
/// @brief Path to the image file for the wall face north.
|
||||
const char *texture_north;
|
||||
|
||||
/// @brief Path to the image file for the wall face south.
|
||||
const char *texture_south;
|
||||
|
||||
/// @brief Path to the image file for the wall face west.
|
||||
const char *texture_west;
|
||||
|
||||
/// @brief Path to the image file for the wall face east.
|
||||
const char *texture_east;
|
||||
|
||||
/// @brief Width of the map.
|
||||
unsigned int width;
|
||||
|
||||
/// @brief Height of the map.
|
||||
unsigned int height;
|
||||
|
||||
/// @brief An 2D array of all the cases.
|
||||
///
|
||||
/// Syntax to get a case: cases[y * width + x]
|
||||
/// x is west to east, y is north to south.
|
||||
t_map_case *cases;
|
||||
|
||||
/// @brief Represents the player in the map.
|
||||
t_player player;
|
||||
} t_map;
|
||||
|
||||
/// @brief Create a t_map from the content of a .cub file.
|
||||
///
|
||||
/// @param dest Pointer to the t_map to set.
|
||||
/// @param file .cub file to use to create the t_map.
|
||||
/// It must be destroyed with mapDestroy to avoid leaks.
|
||||
/// @return false if an error occured, otherwise true.
|
||||
bool map_from_file(t_map *dest, const char *file);
|
||||
|
||||
/// @brief Destroy the map to avoid leaks.
|
||||
void map_destroy(t_map *map);
|
||||
|
||||
/// @brief Return true if the map is valid. Write an error message on stderr.
|
||||
///
|
||||
/// @param map The map to check.
|
||||
/// @return true if the map is valid, false if not.
|
||||
bool check_map(const t_map *map);
|
||||
|
||||
/// @brief Get a case of the map from its coordinates.
|
||||
///
|
||||
/// @param map Map to get the case from.
|
||||
/// @param x x position of the case to return.
|
||||
/// @param y y position of the case to return.
|
||||
/// @return Wanted case.
|
||||
const t_map_case *map_get_case(const t_map *map, int x, int y);
|
||||
|
||||
#endif
|
||||
31
include/map_mapping.h
Normal file
31
include/map_mapping.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* map_mapping.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/04 12:00:07 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/10/04 15:24:14 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MAP_MAPPING_H
|
||||
# define MAP_MAPPING_H
|
||||
|
||||
# include "map.h"
|
||||
|
||||
/// @brief Each element of g_map_mapping. A case and its associated char.
|
||||
typedef struct s_map_mapping_element
|
||||
{
|
||||
/// @brief char representing the case.
|
||||
char name;
|
||||
/// @brief associated case.
|
||||
t_map_case value;
|
||||
} t_map_mapping_element;
|
||||
|
||||
/// @brief List of each char and its according case.
|
||||
/// Ended by an element with the name '\0'.
|
||||
extern const t_map_mapping_element g_map_mapping[];
|
||||
|
||||
#endif
|
||||
78
include/map_utils.h
Normal file
78
include/map_utils.h
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* map_utils.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/03 15:05:13 by mc #+# #+# */
|
||||
/* Updated: 2024/10/17 17:58:23 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MAP_UTILS_H
|
||||
# define MAP_UTILS_H
|
||||
|
||||
# include "stream.h"
|
||||
# include "map.h"
|
||||
# include <stdbool.h>
|
||||
# include <stddef.h>
|
||||
|
||||
/// @brief Read a parameter of the map which has a color as an argument.
|
||||
/// Color format: [0-255],[0-255],[0-255]
|
||||
/// @param name Name of the parameter.
|
||||
/// @param dest Will be set to the value of the parameter.
|
||||
/// Unchanged if error.
|
||||
/// If success but *dest is not 0xFF000000, throws an error.
|
||||
/// @param stream Stream to use.
|
||||
/// Unchanged if error.
|
||||
/// @param redefined Set to true if the parameter was already defined.
|
||||
/// @return true if success or redefined, false if non-fatal error.
|
||||
bool read_color_parameter(const char *name, t_color *dest,
|
||||
t_stream *stream, bool *redefined);
|
||||
|
||||
/// @brief Read a parameter of the map which has a string as an argument.
|
||||
/// @param name Name of the parameter.
|
||||
/// @param dest Will be set to an alloc'd pointer to the value of the parameter.
|
||||
/// Unchanged if error.
|
||||
/// If success but *dest is not null, throws an error.
|
||||
/// @param stream Stream to use.
|
||||
/// Unchanged if error.
|
||||
/// @param redefined Set to true if the parameter was already defined.
|
||||
/// @return true if success or redefined, false if non-fatal error.
|
||||
bool read_string_parameter(const char *name, const char **dest,
|
||||
t_stream *stream, bool *redefined);
|
||||
|
||||
/// @brief Read a map-formatted string.
|
||||
/// If an error occurs, write an error message on stderr.
|
||||
/// @param dest Will be set to the map.
|
||||
/// @param stream Stream to use.
|
||||
/// @return true if success, false if error.
|
||||
bool read_map(t_map *dest, t_stream *stream);
|
||||
|
||||
/// @brief Get the case associated with the char.
|
||||
///
|
||||
/// @param dest Will be set to the char.
|
||||
/// @param name Name of the case.
|
||||
/// @return true if success, false if error.
|
||||
bool get_case(t_map_case *dest, char name);
|
||||
|
||||
/// @brief Fill the pointer with 'size' null bytes.
|
||||
///
|
||||
/// @param dest The pointer to set.
|
||||
/// @param size The number of bytes.
|
||||
void fill_zeros(void *dest, size_t size);
|
||||
|
||||
/// @brief Read the map description part of the map.
|
||||
/// Read until the end of the file.
|
||||
///
|
||||
/// @param map The .width, .height and .cases members will be set.
|
||||
/// @param stream Stream to use.
|
||||
/// @return true if success, false if error.
|
||||
bool read_map_description(t_map *map, t_stream *stream);
|
||||
|
||||
/// @brief Initialize all objects of the map.
|
||||
/// @param map Map to use.
|
||||
void map_init_objects(t_map *map);
|
||||
|
||||
#endif
|
||||
23
include/player.h
Normal file
23
include/player.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* player.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/15 17:31:35 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/10/15 17:43:52 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PLAYER_H
|
||||
# define PLAYER_H
|
||||
|
||||
# include "utils.h"
|
||||
|
||||
void init_player_n(void **data, t_point_int pos);
|
||||
void init_player_s(void **data, t_point_int pos);
|
||||
void init_player_w(void **data, t_point_int pos);
|
||||
void init_player_e(void **data, t_point_int pos);
|
||||
|
||||
#endif
|
||||
29
include/read_all_text.h
Normal file
29
include/read_all_text.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* read_all_text.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/02 15:39:02 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/10/02 17:04:33 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef READ_ALL_TEXT_H
|
||||
# define READ_ALL_TEXT_H
|
||||
|
||||
/// @brief Size of buffer used in read_all_text().
|
||||
# define 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
|
||||
64
include/stream.h
Normal file
64
include/stream.h
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* stream.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/02 12:33:25 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/10/17 15:57:59 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STREAM_H
|
||||
# define STREAM_H
|
||||
|
||||
# include <stdbool.h>
|
||||
|
||||
/// @brief Represents a string and an associated cursor.
|
||||
typedef struct s_stream
|
||||
{
|
||||
/// @brief Index of the cursor.
|
||||
int i;
|
||||
|
||||
/// @brief Pointer to the string.
|
||||
const char *str;
|
||||
} t_stream;
|
||||
|
||||
/// @brief Read a specific string, error if it isn't the expected string.
|
||||
/// Skip the potential blank space before the string.
|
||||
///
|
||||
/// @param str Expected string.
|
||||
/// @param stream Stream to use.
|
||||
/// @param err Set to true if an error occured.
|
||||
/// If already true, the function won't do anything.
|
||||
void read_expected_string(const char *str, t_stream *stream, bool *err);
|
||||
|
||||
/// @brief Read an unsigned int (which fits the pattern /[0-9]+/).
|
||||
/// Skip the potential blank space before the string.
|
||||
///
|
||||
/// @param dest Will be set to the value of the unsigned integer.
|
||||
/// @param stream Stream to use.
|
||||
/// @param err Set to true if an error occured.
|
||||
/// If already true, the function won't do anything.
|
||||
void read_unsigned(unsigned int *dest, t_stream *stream, bool *err);
|
||||
|
||||
/// @brief Read a string until limit char or \0.
|
||||
/// Skip the potential blank space before the string.
|
||||
///
|
||||
/// @param c Limit char.
|
||||
/// @param dest Will be set to an alloc'd pointer to the read string.
|
||||
/// NULL if alloc error.
|
||||
/// @param stream Stream to use.
|
||||
/// @param err Set to true if an error occured.
|
||||
/// If already true, the function won't do anything.
|
||||
void read_until(char c, char **dest, t_stream *stream, bool *err);
|
||||
|
||||
/// @brief Read blank space until the next non-blank character or the EOF.
|
||||
/// ' ' and '\t' are the only characters considered blank.
|
||||
///
|
||||
/// @param stream Stream to use.
|
||||
/// @return false if there was no blank space to read, true otherwise.
|
||||
bool read_blank(t_stream *stream);
|
||||
|
||||
#endif
|
||||
62
include/utils.h
Normal file
62
include/utils.h
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* utils.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/15 16:56:47 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/10/31 15:31:21 by mc ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef UTILS_H
|
||||
# define UTILS_H
|
||||
|
||||
# include <linux/types.h>
|
||||
# include <stdint.h>
|
||||
# include <stddef.h>
|
||||
|
||||
typedef uint32_t u_int32_t;
|
||||
|
||||
typedef struct s_point_double
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
} t_point_double;
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue