reorganize file content

This commit is contained in:
mcolonna 2024-10-31 18:04:34 +01:00
parent 878de1098b
commit 47a6b6df35
34 changed files with 358 additions and 288 deletions

View file

@ -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 \

View file

@ -1,90 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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

31
include/const.h Normal file
View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* const.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

25
include/global.h Normal file
View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* global.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

33
include/include.h Normal file
View file

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* include.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <errno.h>
# include <fcntl.h>
# include <linux/types.h>
# include <math.h>
# include <stdarg.h>
# include <stdbool.h>
# include <stdint.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <unistd.h>
# include <X11/keysym.h>
# include <X11/X.h>
# include "libft.h"
# include "mlx.h"
#endif

View file

@ -3,17 +3,17 @@
/* ::: :::::::: */
/* input.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdbool.h>
# include "include.h"
/// @brief Modified by the input of the user. A value becomes true
/// when the user presses the corresponding key.

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* color.c :+: :+: :+: */
/* main.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -6,14 +6,15 @@
/* 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 */
/* Updated: 2024/10/31 17:55:39 by mc ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MAP_H
# define MAP_H
# include <stdbool.h>
# 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)

View file

@ -1,31 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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

20
include/move.h Normal file
View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* move.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -3,16 +3,18 @@
/* ::: :::::::: */
/* player.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

View file

@ -1,29 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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

23
include/render.h Normal file
View file

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* render.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -3,17 +3,17 @@
/* ::: :::::::: */
/* stream.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdbool.h>
# include "include.h"
/// @brief Represents a string and an associated cursor.
typedef struct s_stream

47
include/temp.h Normal file
View file

@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* temp.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -6,16 +6,14 @@
/* 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 */
/* Updated: 2024/10/31 17:15:31 by mc ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef UTILS_H
# define UTILS_H
# include <linux/types.h>
# include <stdint.h>
# include <stddef.h>
# 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

18
src/global.c Normal file
View file

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* global.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View file

@ -3,16 +3,14 @@
/* ::: :::::::: */
/* input.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <X11/keysym.h>
#include "algo.h"
t_input_actions g_input_actions;

View file

@ -1,24 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* algo.c :+: :+: :+: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdio.h>
#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();

View file

@ -3,23 +3,28 @@
/* ::: :::::::: */
/* map1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <fcntl.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#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)
{

View file

@ -3,23 +3,15 @@
/* ::: :::::::: */
/* map2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <fcntl.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
const t_map_case *map_get_case(const t_map *map, int x, int y)
{

View file

@ -1,25 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map_mapping.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdlib.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}}}};

View file

@ -3,20 +3,19 @@
/* ::: :::::::: */
/* map_utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdbool.h>
# include <stddef.h>
# 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]

View file

@ -3,17 +3,14 @@
/* ::: :::::::: */
/* map_utils1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdlib.h>
bool read_color_parameter(const char *name, t_color *dest,
t_stream *stream, bool *redefined)

View file

@ -3,17 +3,14 @@
/* ::: :::::::: */
/* map_utils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdlib.h>
/// @brief Read the map description to get the dimensions.
/// The map must be at least 1x1.

View file

@ -3,14 +3,19 @@
/* ::: :::::::: */
/* move.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)

View file

@ -3,16 +3,17 @@
/* ::: :::::::: */
/* player.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)
{

View file

@ -3,15 +3,18 @@
/* ::: :::::::: */
/* render.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: grobledo <grobledo@student.42.fr> +#+ +:+ +#+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdio.h>
#include "render.h"
#include "render_utils.h"
#include "const.h"
#include "global.h"
static void calculate_perpwalldist3(int x,
t_point_double *deltadist,

View file

@ -1,16 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* render2.c :+: :+: :+: */
/* render_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: grobledo <grobledo@student.42.fr> +#+ +:+ +#+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
}
}

23
src/render_utils.h Normal file
View file

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* render_utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -3,15 +3,14 @@
/* ::: :::::::: */
/* stream.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdlib.h>
void read_expected_string(const char *str, t_stream *stream, bool *err)
{

View file

@ -3,15 +3,14 @@
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdarg.h>
#include "utils.h"
void vector_from_rotation(t_point_double *vec, double angle, double norm)
{

View file

@ -3,15 +3,14 @@
/* ::: :::::::: */
/* utils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -1,21 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* read_all_text.c :+: :+: :+: */
/* utils3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#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);