From 47a6b6df3584740903195ba407c5fa792c15572d Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 31 Oct 2024 18:04:34 +0100 Subject: [PATCH] reorganize file content --- Makefile | 2 +- include/algo.h | 90 ------------------------------- include/const.h | 31 +++++++++++ include/global.h | 25 +++++++++ include/include.h | 33 ++++++++++++ include/input.h | 6 +-- src/color.c => include/main.h | 18 +++---- include/map.h | 18 ++++++- include/map_mapping.h | 31 ----------- include/move.h | 20 +++++++ include/player.h | 6 ++- include/read_all_text.h | 29 ---------- include/render.h | 23 ++++++++ include/stream.h | 6 +-- include/temp.h | 47 ++++++++++++++++ include/utils.h | 24 +++++++-- src/global.c | 18 +++++++ src/input.c | 6 +-- src/{algo.c => main.c} | 24 ++++----- src/map1.c | 23 ++++---- src/map2.c | 12 +---- src/map_mapping.c | 25 --------- {include => src}/map_utils.h | 9 ++-- src/map_utils1.c | 7 +-- src/map_utils2.c | 7 +-- src/move.c | 11 ++-- src/player.c | 9 ++-- src/render.c | 11 ++-- src/{render2.c => render_utils.c} | 13 +++-- src/render_utils.h | 23 ++++++++ src/stream.c | 5 +- src/utils.c | 7 ++- src/utils2.c | 10 ++-- src/{read_all_text.c => utils3.c} | 17 +++--- 34 files changed, 358 insertions(+), 288 deletions(-) delete mode 100644 include/algo.h create mode 100644 include/const.h create mode 100644 include/global.h create mode 100644 include/include.h rename src/color.c => include/main.h (63%) delete mode 100644 include/map_mapping.h create mode 100644 include/move.h delete mode 100644 include/read_all_text.h create mode 100644 include/render.h create mode 100644 include/temp.h create mode 100644 src/global.c rename src/{algo.c => main.c} (86%) delete mode 100644 src/map_mapping.c rename {include => src}/map_utils.h (94%) rename src/{render2.c => render_utils.c} (88%) create mode 100644 src/render_utils.h rename src/{read_all_text.c => utils3.c} (85%) diff --git a/Makefile b/Makefile index 6de71a6..8689b64 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ check_headers : echo "check header $$HEADER..."; \ > __tmp_check_header.c echo "#include \"$$HEADER\""; \ >> __tmp_check_header.c echo "#include \"$$HEADER\""; \ - >> __tmp_check_header.c echo "int main(void) {}"; \ + >> __tmp_check_header.c echo "int main() {}"; \ $(CPP_1) -o __tmp_check_header.out __tmp_check_header.c; \ if [ $$? -ne 0 ]; \ then \ diff --git a/include/algo.h b/include/algo.h deleted file mode 100644 index 8cc0bf9..0000000 --- a/include/algo.h +++ /dev/null @@ -1,90 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* algo.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mc +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 -# include -# include -# include -# include -# include -# 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 diff --git a/include/const.h b/include/const.h new file mode 100644 index 0000000..173da3d --- /dev/null +++ b/include/const.h @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* const.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/31 17:00:59 by mc #+# #+# */ +/* Updated: 2024/10/31 17:06:00 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef CONST_H +# define CONST_H + +# include "include.h" + +# define MAP_WIDTH 24 // cases (TODO test) +# define MAP_HEIGHT 24 // cases (TODO test) +# 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 + +#endif diff --git a/include/global.h b/include/global.h new file mode 100644 index 0000000..5be9d0b --- /dev/null +++ b/include/global.h @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* global.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/31 17:06:31 by mc #+# #+# */ +/* Updated: 2024/10/31 17:29:00 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef GLOBAL_H +# define GLOBAL_H + +# include "include.h" + +# include "map.h" + +extern void *g_mlx; +extern void *g_win; +extern t_player g_player; +extern t_map g_map; + +#endif diff --git a/include/include.h b/include/include.h new file mode 100644 index 0000000..58ae764 --- /dev/null +++ b/include/include.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* include.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/31 16:22:09 by mc #+# #+# */ +/* Updated: 2024/10/31 18:03:26 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef INCLUDE_H +# define INCLUDE_H + +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include + +# include "libft.h" +# include "mlx.h" + +#endif diff --git a/include/input.h b/include/input.h index becd5a1..6fda136 100644 --- a/include/input.h +++ b/include/input.h @@ -3,17 +3,17 @@ /* ::: :::::::: */ /* input.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:09 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 14:59:41 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 16:24:16 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef INPUT_H # define INPUT_H -# include +# include "include.h" /// @brief Modified by the input of the user. A value becomes true /// when the user presses the corresponding key. diff --git a/src/color.c b/include/main.h similarity index 63% rename from src/color.c rename to include/main.h index 13b2deb..0d413ad 100644 --- a/src/color.c +++ b/include/main.h @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* color.c :+: :+: :+: */ +/* main.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/01 17:04:56 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 16:26:52 by mcolonna ### ########.fr */ +/* Created: 2024/10/31 17:19:59 by mc #+# #+# */ +/* Updated: 2024/10/31 17:55:11 by mc ### ########.fr */ /* */ /* ************************************************************************** */ -#include "map.h" +#ifndef MAIN_H +# define MAIN_H -t_color color_from_rgb(int red, int green, int blue) -{ - return (red << 16 | green << 8 | blue); -} +# include "include.h" + +#endif diff --git a/include/map.h b/include/map.h index 73802dd..228be5c 100644 --- a/include/map.h +++ b/include/map.h @@ -6,14 +6,15 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 15:57:58 by mc ### ########.fr */ +/* Updated: 2024/10/31 17:55:39 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef MAP_H # define MAP_H -# include +# include "include.h" + # include "utils.h" /// @brief The type of a case. @@ -61,6 +62,19 @@ typedef struct s_map_case t_object object; } t_map_case; +/// @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[]; + typedef struct s_player { // pos player on map (cases) diff --git a/include/map_mapping.h b/include/map_mapping.h deleted file mode 100644 index 5a3b2c9..0000000 --- a/include/map_mapping.h +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* map_mapping.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/include/move.h b/include/move.h new file mode 100644 index 0000000..03804d0 --- /dev/null +++ b/include/move.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* move.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/31 16:59:27 by mc #+# #+# */ +/* Updated: 2024/10/31 16:59:48 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MOVE_H +# define MOVE_H + +# include "include.h" + +void move(void); + +#endif diff --git a/include/player.h b/include/player.h index e9dfb28..09a7177 100644 --- a/include/player.h +++ b/include/player.h @@ -3,16 +3,18 @@ /* ::: :::::::: */ /* player.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 17:31:35 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 17:43:52 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:30:01 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef PLAYER_H # define PLAYER_H +# include "include.h" + # include "utils.h" void init_player_n(void **data, t_point_int pos); diff --git a/include/read_all_text.h b/include/read_all_text.h deleted file mode 100644 index f86eec9..0000000 --- a/include/read_all_text.h +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* read_all_text.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/include/render.h b/include/render.h new file mode 100644 index 0000000..7f7eec2 --- /dev/null +++ b/include/render.h @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* render.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/31 17:13:20 by mc #+# #+# */ +/* Updated: 2024/10/31 17:27:33 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef RENDER_H +# define RENDER_H + +# include "include.h" + +# include "utils.h" +# include "temp.h" + +int render(u_int32_t *img_data, t_tex *tex); + +#endif diff --git a/include/stream.h b/include/stream.h index 7b071ee..8374b16 100644 --- a/include/stream.h +++ b/include/stream.h @@ -3,17 +3,17 @@ /* ::: :::::::: */ /* stream.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/02 12:33:25 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 15:57:59 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 16:25:10 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef STREAM_H # define STREAM_H -# include +# include "include.h" /// @brief Represents a string and an associated cursor. typedef struct s_stream diff --git a/include/temp.h b/include/temp.h new file mode 100644 index 0000000..d447a27 --- /dev/null +++ b/include/temp.h @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* temp.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/31 17:04:08 by mc #+# #+# */ +/* Updated: 2024/10/31 17:28:09 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +// DEBUG remove temp.h + +#ifndef TEMP_H +# define TEMP_H + +# include "include.h" + +# include "utils.h" + +# define TEX_WIDTH 64 +# define TEX_HEIGHT 64 + +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; + +#endif diff --git a/include/utils.h b/include/utils.h index e0e9c0c..76da5af 100644 --- a/include/utils.h +++ b/include/utils.h @@ -6,16 +6,14 @@ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 16:56:47 by mcolonna #+# #+# */ -/* Updated: 2024/10/31 15:31:21 by mc ### ########.fr */ +/* Updated: 2024/10/31 17:15:31 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef UTILS_H # define UTILS_H -# include -# include -# include +# include "include.h" typedef uint32_t u_int32_t; @@ -43,6 +41,9 @@ typedef __u32 t_color; /// @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. @@ -59,4 +60,19 @@ void timedloop(void (*f)(void)); /// @return Address to the data, or NULL if error. u_int32_t *get_data_addr(void *img_ptr); +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 diff --git a/src/global.c b/src/global.c new file mode 100644 index 0000000..b0e9111 --- /dev/null +++ b/src/global.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* global.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ +/* Updated: 2024/10/31 17:20:56 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "global.h" + +void *g_mlx = NULL; +void *g_win = NULL; +t_map g_map; +t_player g_player; diff --git a/src/input.c b/src/input.c index 45168e0..9f0ee6c 100644 --- a/src/input.c +++ b/src/input.c @@ -3,16 +3,14 @@ /* ::: :::::::: */ /* input.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 14:43:36 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 16:05:50 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:21:00 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "input.h" -#include -#include "algo.h" t_input_actions g_input_actions; diff --git a/src/algo.c b/src/main.c similarity index 86% rename from src/algo.c rename to src/main.c index 56e2a2a..69352d9 100644 --- a/src/algo.c +++ b/src/main.c @@ -1,24 +1,22 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* algo.c :+: :+: :+: */ +/* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/31 15:26:48 by mc ### ########.fr */ +/* Created: 2024/10/31 16:57:40 by mc #+# #+# */ +/* Updated: 2024/10/31 17:55:18 by mc ### ########.fr */ /* */ /* ************************************************************************** */ -#include "algo.h" -#include "input.h" -#include +#include "main.h" -void *g_mlx = NULL; -void *g_win = NULL; -t_map g_map; -t_player g_player; -// t_tex g_tex; +# include "render.h" +# include "move.h" +# include "input.h" +# include "const.h" +# include "global.h" static void load_textures(t_tex *tex) { @@ -34,7 +32,7 @@ static void load_textures(t_tex *tex) &tex->tex_width, &tex->tex_height); } -void draw_screen(void) +static void draw_screen(void) { void *img_ptr; u_int32_t *img_data; @@ -68,8 +66,6 @@ static int loop_hook(void *param) return (0); } - - int main(int argc, char *argv[]) { g_mlx = mlx_init(); diff --git a/src/map1.c b/src/map1.c index aaba9c0..931ad2a 100644 --- a/src/map1.c +++ b/src/map1.c @@ -3,23 +3,28 @@ /* ::: :::::::: */ /* map1.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 17:12:58 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 17:22:53 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:56:25 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "map.h" #include "map_utils.h" + #include "stream.h" -#include "read_all_text.h" -#include "libft.h" -#include -#include -#include -#include -#include +#include "player.h" + +const t_map_mapping_element g_map_mapping[] = { +{' ', {false, EMPTY, {NULL, NULL, NULL, NULL}}}, +{'0', {true, EMPTY, {NULL, NULL, NULL, NULL}}}, +{'1', {true, WALL, {NULL, NULL, NULL, NULL}}}, +{'N', {true, EMPTY, {init_player_n, NULL, NULL, NULL}}}, +{'S', {true, EMPTY, {init_player_s, NULL, NULL, NULL}}}, +{'E', {true, EMPTY, {init_player_e, NULL, NULL, NULL}}}, +{'W', {true, EMPTY, {init_player_w, NULL, NULL, NULL}}}, +{'\0', {true, EMPTY, {NULL, NULL, NULL, NULL}}}}; static bool map_from_file2(t_map *dest, t_stream *stream, int fd) { diff --git a/src/map2.c b/src/map2.c index f4b99f5..c40818a 100644 --- a/src/map2.c +++ b/src/map2.c @@ -3,23 +3,15 @@ /* ::: :::::::: */ /* map2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 17:12:58 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 16:44:40 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:51:49 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "map.h" #include "map_utils.h" -#include "stream.h" -#include "read_all_text.h" -#include "libft.h" -#include -#include -#include -#include -#include const t_map_case *map_get_case(const t_map *map, int x, int y) { diff --git a/src/map_mapping.c b/src/map_mapping.c deleted file mode 100644 index 129ce34..0000000 --- a/src/map_mapping.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* map_mapping.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/04 12:05:21 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 17:19:26 by mcolonna ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "map_mapping.h" -#include "player.h" -#include - -const t_map_mapping_element g_map_mapping[] = { -{' ', {false, EMPTY, {NULL, NULL, NULL, NULL}}}, -{'0', {true, EMPTY, {NULL, NULL, NULL, NULL}}}, -{'1', {true, WALL, {NULL, NULL, NULL, NULL}}}, -{'N', {true, EMPTY, {init_player_n, NULL, NULL, NULL}}}, -{'S', {true, EMPTY, {init_player_s, NULL, NULL, NULL}}}, -{'E', {true, EMPTY, {init_player_e, NULL, NULL, NULL}}}, -{'W', {true, EMPTY, {init_player_w, NULL, NULL, NULL}}}, -{'\0', {true, EMPTY, {NULL, NULL, NULL, NULL}}}}; diff --git a/include/map_utils.h b/src/map_utils.h similarity index 94% rename from include/map_utils.h rename to src/map_utils.h index 6f35bba..c0b5184 100644 --- a/include/map_utils.h +++ b/src/map_utils.h @@ -3,20 +3,19 @@ /* ::: :::::::: */ /* map_utils.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 15:05:13 by mc #+# #+# */ -/* Updated: 2024/10/17 17:58:23 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:56:54 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef MAP_UTILS_H # define MAP_UTILS_H -# include "stream.h" # include "map.h" -# include -# include + +# include "stream.h" /// @brief Read a parameter of the map which has a color as an argument. /// Color format: [0-255],[0-255],[0-255] diff --git a/src/map_utils1.c b/src/map_utils1.c index 9edd47a..da844e8 100644 --- a/src/map_utils1.c +++ b/src/map_utils1.c @@ -3,17 +3,14 @@ /* ::: :::::::: */ /* map_utils1.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 15:02:09 by mc #+# #+# */ -/* Updated: 2024/10/17 17:59:05 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:21:36 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "map_utils.h" -#include "map.h" -#include "map_mapping.h" -#include bool read_color_parameter(const char *name, t_color *dest, t_stream *stream, bool *redefined) diff --git a/src/map_utils2.c b/src/map_utils2.c index b15565a..c159465 100644 --- a/src/map_utils2.c +++ b/src/map_utils2.c @@ -3,17 +3,14 @@ /* ::: :::::::: */ /* map_utils2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/04 15:12:08 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 16:27:41 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:21:44 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "map_utils.h" -#include "map_mapping.h" -#include "map.h" -#include /// @brief Read the map description to get the dimensions. /// The map must be at least 1x1. diff --git a/src/move.c b/src/move.c index 8511c2f..421af95 100644 --- a/src/move.c +++ b/src/move.c @@ -3,14 +3,19 @@ /* ::: :::::::: */ /* move.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:47:34 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 15:06:43 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:58:27 by mc ### ########.fr */ /* */ /* ************************************************************************** */ -#include "algo.h" +#include "move.h" + +#include "utils.h" +#include "map.h" +#include "global.h" +#include "const.h" #include "input.h" static void push_from_wall(t_point_int c) diff --git a/src/player.c b/src/player.c index 98b46af..c1fc4cb 100644 --- a/src/player.c +++ b/src/player.c @@ -3,16 +3,17 @@ /* ::: :::::::: */ /* player.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 17:33:11 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 17:38:27 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:59:13 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "player.h" -#include "utils.h" -#include "algo.h" + +#include "global.h" +#include "const.h" static void init_player(t_point_int pos, double rot) { diff --git a/src/render.c b/src/render.c index 15985c7..288ee6c 100644 --- a/src/render.c +++ b/src/render.c @@ -3,15 +3,18 @@ /* ::: :::::::: */ /* render.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/10/24 14:27:52 by grobledo ### ########.fr */ +/* Updated: 2024/10/31 18:02:59 by mc ### ########.fr */ /* */ /* ************************************************************************** */ -#include "algo.h" -#include +#include "render.h" +#include "render_utils.h" + +#include "const.h" +#include "global.h" static void calculate_perpwalldist3(int x, t_point_double *deltadist, diff --git a/src/render2.c b/src/render_utils.c similarity index 88% rename from src/render2.c rename to src/render_utils.c index f6df898..a12f90a 100644 --- a/src/render2.c +++ b/src/render_utils.c @@ -1,16 +1,19 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* render2.c :+: :+: :+: */ +/* render_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/24 14:26:22 by grobledo #+# #+# */ -/* Updated: 2024/10/24 14:27:37 by grobledo ### ########.fr */ +/* Updated: 2024/10/31 18:02:20 by mc ### ########.fr */ /* */ /* ************************************************************************** */ -#include "algo.h" +#include "render_utils.h" + +#include "const.h" +#include "global.h" void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex) { @@ -48,4 +51,4 @@ void draw_wall(t_tex *tex, t_ray *ray, const int line_height, int x, &tex->bpp, &tex->size_line, &tex->endian); color = texture_data[tex->tex_x * tex->tex_width + tex->tex_y]; img_data[y * SCREEN_WIDTH + x] = color; -} \ No newline at end of file +} diff --git a/src/render_utils.h b/src/render_utils.h new file mode 100644 index 0000000..01a826e --- /dev/null +++ b/src/render_utils.h @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* render_utils.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mc +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/24 14:26:22 by grobledo #+# #+# */ +/* Updated: 2024/10/31 18:01:59 by mc ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef RENDER_UTILS_H +# define RENDER_UTILS_H + +# include "render.h" + +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 diff --git a/src/stream.c b/src/stream.c index 9617970..c58e24c 100644 --- a/src/stream.c +++ b/src/stream.c @@ -3,15 +3,14 @@ /* ::: :::::::: */ /* stream.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/02 14:08:10 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 16:02:33 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:25:23 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "stream.h" -#include void read_expected_string(const char *str, t_stream *stream, bool *err) { diff --git a/src/utils.c b/src/utils.c index e265cdf..21f928c 100644 --- a/src/utils.c +++ b/src/utils.c @@ -3,15 +3,14 @@ /* ::: :::::::: */ /* utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:38:40 by mcolonna #+# #+# */ -/* Updated: 2024/10/17 16:36:14 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:25:30 by mc ### ########.fr */ /* */ /* ************************************************************************** */ -#include "algo.h" -#include +#include "utils.h" void vector_from_rotation(t_point_double *vec, double angle, double norm) { diff --git a/src/utils2.c b/src/utils2.c index dcc1914..60a922b 100644 --- a/src/utils2.c +++ b/src/utils2.c @@ -3,15 +3,14 @@ /* ::: :::::::: */ /* utils2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/29 14:02:37 by mcolonna #+# #+# */ -/* Updated: 2024/10/29 14:12:14 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:25:34 by mc ### ########.fr */ /* */ /* ************************************************************************** */ #include "utils.h" -#include "mlx.h" u_int32_t *get_data_addr(void *img_ptr) { @@ -29,3 +28,8 @@ u_int32_t *get_data_addr(void *img_ptr) } return (r); } + +t_color color_from_rgb(int red, int green, int blue) +{ + return (red << 16 | green << 8 | blue); +} diff --git a/src/read_all_text.c b/src/utils3.c similarity index 85% rename from src/read_all_text.c rename to src/utils3.c index 42abe10..d6dbe30 100644 --- a/src/read_all_text.c +++ b/src/utils3.c @@ -1,21 +1,16 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* read_all_text.c :+: :+: :+: */ +/* utils3.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: mc +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/02 16:18:35 by mcolonna #+# #+# */ -/* Updated: 2024/10/15 16:28:22 by mcolonna ### ########.fr */ +/* Updated: 2024/10/31 17:25:53 by mc ### ########.fr */ /* */ /* ************************************************************************** */ -#include "read_all_text.h" -#include "map.h" -#include "libft.h" -#include -#include -#include +#include "utils.h" /// @brief Concatenate *dest and src and put the result in *dest. /// @@ -73,7 +68,7 @@ static char *add_endline_if_necessary(char *str) char *read_all_text(int fd) { - char buf[BUFFER_SIZE]; + char buf[READ_ALL_TEXT_BUFFER_SIZE]; int n; char *r; @@ -84,7 +79,7 @@ char *read_all_text(int fd) n = 1; while (n) { - n = read(fd, buf, BUFFER_SIZE); + n = read(fd, buf, READ_ALL_TEXT_BUFFER_SIZE); if (n < 0 || (n && !strconcat(&r, buf, n))) { free(r);