docs, clean, several things... *
- add docs - remove unused things - redo modifications i accidentally erased from spacetime
This commit is contained in:
		
							parent
							
								
									47a6b6df35
								
							
						
					
					
						commit
						26621c72c6
					
				
					 25 changed files with 199 additions and 140 deletions
				
			
		|  | @ -6,7 +6,7 @@ | |||
| /*   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       */ | ||||
| /*   Updated: 2024/10/31 18:15:13 by mc               ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
|  | @ -15,17 +15,18 @@ | |||
| 
 | ||||
| # 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
 | ||||
| # define PI 3.1415926535 // it's just pi
 | ||||
| 
 | ||||
| # define MOVE_SPEED 0.05 // Player oves by N cases by tick
 | ||||
| # define ROT_SPEED_DIVIDE_PI 64 // Player turns by pi/N rad by tick
 | ||||
| # define HITBOX 0.25 // Hitbox of N cases around player.
 | ||||
| 
 | ||||
| # define COLOR_CEILING 0x29f8ff // TODO get from cub file
 | ||||
| # define COLOR_FLOOR 0xFF985C // TODO get from cub file
 | ||||
| 
 | ||||
| # define SCREEN_WIDTH 640 // Width of the window
 | ||||
| # define SCREEN_HEIGHT 480 // Height of the window
 | ||||
| 
 | ||||
| # define FOV 0.66 // ? TODO no idea
 | ||||
| 
 | ||||
| #endif | ||||
|  |  | |||
|  | @ -6,7 +6,7 @@ | |||
| /*   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       */ | ||||
| /*   Updated: 2024/10/31 18:11:08 by mc               ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
|  | @ -17,9 +17,13 @@ | |||
| 
 | ||||
| # include "map.h" | ||||
| 
 | ||||
| /// @brief mlx connection identifier
 | ||||
| extern void		*g_mlx; | ||||
| 
 | ||||
| /// @brief Identifier to the opened window
 | ||||
| extern void		*g_win; | ||||
| extern t_player	g_player; | ||||
| 
 | ||||
| /// @brief Current map
 | ||||
| extern t_map	g_map; | ||||
| 
 | ||||
| #endif | ||||
|  |  | |||
|  | @ -6,7 +6,7 @@ | |||
| /*   By: mc <mc@student.42.fr>                      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2024/10/17 14:43:09 by mcolonna          #+#    #+#             */ | ||||
| /*   Updated: 2024/10/31 16:24:16 by mc               ###   ########.fr       */ | ||||
| /*   Updated: 2024/11/01 20:59:28 by mc               ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
|  | @ -15,8 +15,7 @@ | |||
| 
 | ||||
| # include "include.h" | ||||
| 
 | ||||
| /// @brief Modified by the input of the user. A value becomes true
 | ||||
| ///        when the user presses the corresponding key.
 | ||||
| /// @brief For g_input_actions
 | ||||
| typedef struct s_input_actions | ||||
| { | ||||
| 	bool	left; | ||||
|  | @ -26,10 +25,23 @@ typedef struct s_input_actions | |||
| 	bool	quit; | ||||
| }	t_input_actions; | ||||
| 
 | ||||
| /// @brief Modified by the input of the user. A value becomes true
 | ||||
| ///        when the user presses the corresponding key.
 | ||||
| extern t_input_actions	g_input_actions; | ||||
| 
 | ||||
| int		keypress(int keycode); | ||||
| int		keyrelease(int keycode); | ||||
| /// @brief To call when a specific key is newly pressed.
 | ||||
| ///
 | ||||
| /// @param keycode Key pressed.
 | ||||
| /// @return Unused.
 | ||||
| int		hook_keypress(int keycode); | ||||
| 
 | ||||
| /// @brief To call when a specific key is released.
 | ||||
| ///
 | ||||
| /// @param keycode Key released.
 | ||||
| /// @return Unused.
 | ||||
| int		hook_keyrelease(int keycode); | ||||
| 
 | ||||
| /// @brief To call at the start of the program.
 | ||||
| void	input_init(void); | ||||
| 
 | ||||
| #endif | ||||
|  |  | |||
|  | @ -6,7 +6,7 @@ | |||
| /*   By: mc <mc@student.42.fr>                      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2024/10/01 13:59:04 by mcolonna          #+#    #+#             */ | ||||
| /*   Updated: 2024/10/31 17:55:39 by mc               ###   ########.fr       */ | ||||
| /*   Updated: 2024/11/06 19:24:03 by mc               ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
|  | @ -17,7 +17,7 @@ | |||
| 
 | ||||
| # include "utils.h" | ||||
| 
 | ||||
| /// @brief The type of a case. 
 | ||||
| /// @brief The type of a case.
 | ||||
| typedef enum e_map_wall | ||||
| { | ||||
| 	/// @brief Empty case, for '0' and ' '.
 | ||||
|  | @ -32,16 +32,19 @@ typedef struct s_object | |||
| 	/// @brief Function called when creating the object.
 | ||||
| 	///
 | ||||
| 	/// @param data Address of the s_object.data pointer.
 | ||||
| 	/// @param pos Start position of the object.
 | ||||
| 	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.
 | ||||
| 	/// @param pos Start position of the object.
 | ||||
| 	void	(*destroy)(void **data, t_point_int pos); | ||||
| 
 | ||||
| 	/// @brief Function called each tick.
 | ||||
| 	///
 | ||||
| 	/// @param data Address of the s_object.data pointer.
 | ||||
| 	/// @param pos Start position of the object.
 | ||||
| 	void	(*tick)(void **data, t_point_int pos); | ||||
| 
 | ||||
| 	/// @brief Pointer the object can use to save data.
 | ||||
|  | @ -83,6 +86,21 @@ typedef struct s_player | |||
| 	double			rot; | ||||
| }	t_player; | ||||
| 
 | ||||
| typedef enum e_direction | ||||
| { | ||||
| 	NORTH, | ||||
| 	SOUTH, | ||||
| 	EAST, | ||||
| 	WEST, | ||||
| }	t_direction; | ||||
| 
 | ||||
| typedef struct s_texture | ||||
| { | ||||
| 	int		width; | ||||
| 	int		height; | ||||
| 	void	*image; | ||||
| }	t_texture; | ||||
| 
 | ||||
| /// @brief Represents a map.
 | ||||
| typedef struct s_map | ||||
| { | ||||
|  | @ -92,17 +110,11 @@ typedef struct s_map | |||
| 	/// @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 File path for each texture. Index is t_direction.
 | ||||
| 	const char		*texture_srcs[4]; | ||||
| 
 | ||||
| 	/// @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 All textures. Index is t_direction.
 | ||||
| 	t_texture		textures[4]; | ||||
| 
 | ||||
| 	/// @brief Width of the map.
 | ||||
| 	unsigned int	width; | ||||
|  |  | |||
|  | @ -6,7 +6,7 @@ | |||
| /*   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       */ | ||||
| /*   Updated: 2024/11/01 21:05:51 by mc               ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
|  | @ -15,6 +15,7 @@ | |||
| 
 | ||||
| # include "include.h" | ||||
| 
 | ||||
| /// @brief Move the player according to the user input.
 | ||||
| void	move(void); | ||||
| 
 | ||||
| #endif | ||||
|  |  | |||
|  | @ -6,7 +6,7 @@ | |||
| /*   By: mc <mc@student.42.fr>                      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2024/10/15 17:31:35 by mcolonna          #+#    #+#             */ | ||||
| /*   Updated: 2024/10/31 17:30:01 by mc               ###   ########.fr       */ | ||||
| /*   Updated: 2024/11/01 20:41:30 by mc               ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
|  | @ -17,9 +17,16 @@ | |||
| 
 | ||||
| # include "utils.h" | ||||
| 
 | ||||
| /// @brief Create a player facing north (to use with t_object.init).
 | ||||
| void	init_player_n(void **data, t_point_int pos); | ||||
| 
 | ||||
| /// @brief Create a player facing south (to use with t_object.init).
 | ||||
| void	init_player_s(void **data, t_point_int pos); | ||||
| 
 | ||||
| /// @brief Create a player facing west (to use with t_object.init).
 | ||||
| void	init_player_w(void **data, t_point_int pos); | ||||
| 
 | ||||
| /// @brief Create a player facing east (to use with t_object.init).
 | ||||
| void	init_player_e(void **data, t_point_int pos); | ||||
| 
 | ||||
| #endif | ||||
|  |  | |||
|  | @ -3,10 +3,10 @@ | |||
| /*                                                        :::      ::::::::   */ | ||||
| /*   render.h                                           :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: mc <mc@student.42.fr>                      +#+  +:+       +#+        */ | ||||
| /*   By: mcolonna <mcolonna@student.42.fr>          +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2024/10/31 17:13:20 by mc                #+#    #+#             */ | ||||
| /*   Updated: 2024/10/31 17:27:33 by mc               ###   ########.fr       */ | ||||
| /*   Updated: 2024/11/04 13:47:47 by mcolonna         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
|  | @ -17,7 +17,13 @@ | |||
| 
 | ||||
| # include "utils.h" | ||||
| # include "temp.h" | ||||
| # include "const.h" | ||||
| # include "global.h" | ||||
| 
 | ||||
| int		render(u_int32_t *img_data, t_tex *tex); | ||||
| /// @brief Draw the camera image using raycasting.
 | ||||
| ///
 | ||||
| /// @param img_data Data addr of the image to draw on.
 | ||||
| /// @return Unused.
 | ||||
| int		render(u_int32_t *img_data); | ||||
| 
 | ||||
| #endif | ||||
|  |  | |||
|  | @ -6,7 +6,7 @@ | |||
| /*   By: mc <mc@student.42.fr>                      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2024/10/15 16:56:47 by mcolonna          #+#    #+#             */ | ||||
| /*   Updated: 2024/10/31 17:15:31 by mc               ###   ########.fr       */ | ||||
| /*   Updated: 2024/11/01 20:55:00 by mc               ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
|  | @ -17,12 +17,14 @@ | |||
| 
 | ||||
| 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; | ||||
|  | @ -60,6 +62,12 @@ void		timedloop(void (*f)(void)); | |||
| /// @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().
 | ||||
|  |  | |||
|  | @ -6,7 +6,7 @@ | |||
| /*   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       */ | ||||
| /*   Updated: 2024/11/01 20:56:43 by mc               ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
|  | @ -15,4 +15,3 @@ | |||
| void		*g_mlx = NULL; | ||||
| void		*g_win = NULL; | ||||
| t_map		g_map; | ||||
| t_player	g_player; | ||||
|  |  | |||
							
								
								
									
										12
									
								
								src/input.c
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								src/input.c
									
										
									
									
									
								
							|  | @ -6,7 +6,7 @@ | |||
| /*   By: mc <mc@student.42.fr>                      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2024/10/17 14:43:36 by mcolonna          #+#    #+#             */ | ||||
| /*   Updated: 2024/10/31 17:21:00 by mc               ###   ########.fr       */ | ||||
| /*   Updated: 2024/11/01 20:59:32 by mc               ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
|  | @ -28,13 +28,13 @@ static void	set_action(int keycode, bool value) | |||
| 		g_input_actions.quit = value; | ||||
| } | ||||
| 
 | ||||
| int	keypress(int keycode) | ||||
| int	hook_keypress(int keycode) | ||||
| { | ||||
| 	set_action(keycode, true); | ||||
| 	return (0); | ||||
| } | ||||
| 
 | ||||
| int	keyrelease(int keycode) | ||||
| int	hook_keyrelease(int keycode) | ||||
| { | ||||
| 	set_action(keycode, false); | ||||
| 	return (0); | ||||
|  | @ -42,9 +42,5 @@ int	keyrelease(int keycode) | |||
| 
 | ||||
| void	input_init(void) | ||||
| { | ||||
| 	g_input_actions.down = false; | ||||
| 	g_input_actions.up = false; | ||||
| 	g_input_actions.left = false; | ||||
| 	g_input_actions.right = false; | ||||
| 	g_input_actions.quit = false; | ||||
| 	ft_memset(&g_input_actions, 0, sizeof(g_input_actions)); | ||||
| } | ||||
|  |  | |||
							
								
								
									
										24
									
								
								src/main.c
									
										
									
									
									
								
							
							
						
						
									
										24
									
								
								src/main.c
									
										
									
									
									
								
							|  | @ -6,7 +6,7 @@ | |||
| /*   By: mc <mc@student.42.fr>                      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2024/10/31 16:57:40 by mc                #+#    #+#             */ | ||||
| /*   Updated: 2024/10/31 17:55:18 by mc               ###   ########.fr       */ | ||||
| /*   Updated: 2024/11/07 00:07:35 by mc               ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
|  | @ -18,32 +18,16 @@ | |||
| # include "const.h" | ||||
| # include "global.h" | ||||
| 
 | ||||
| static void	load_textures(t_tex *tex) | ||||
| { | ||||
| 	tex->tex_width = 64; | ||||
| 	tex->tex_height = 64; | ||||
| 	tex->textures[0] = mlx_xpm_file_to_image(g_mlx, "textures/north.xpm", | ||||
| 			&tex->tex_width, &tex->tex_height); | ||||
| 	tex->textures[1] = mlx_xpm_file_to_image(g_mlx, "textures/south.xpm", | ||||
| 			&tex->tex_width, &tex->tex_height); | ||||
| 	tex->textures[2] = mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", | ||||
| 			&tex->tex_width, &tex->tex_height); | ||||
| 	tex->textures[3] = mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", | ||||
| 			&tex->tex_width, &tex->tex_height); | ||||
| } | ||||
| 
 | ||||
| static void	draw_screen(void) | ||||
| { | ||||
| 	void		*img_ptr; | ||||
| 	u_int32_t	*img_data; | ||||
| 	t_tex		tex; | ||||
| 
 | ||||
| 	load_textures(&tex); | ||||
| 	img_ptr = mlx_new_image(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT); | ||||
| 	img_data = get_data_addr(img_ptr); | ||||
| 	if (!img_data) | ||||
| 		exit(1); | ||||
| 	render(img_data, &tex); | ||||
| 	render(img_data); | ||||
| 	mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); | ||||
| 	mlx_destroy_image(g_mlx, img_ptr); | ||||
| } | ||||
|  | @ -78,8 +62,8 @@ int	main(int argc, char *argv[]) | |||
| 	if (!map_from_file(&g_map, argv[1])) | ||||
| 		return (1); | ||||
| 	g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d"); | ||||
| 	mlx_hook(g_win, KeyPress, KeyPressMask, keypress, NULL); | ||||
| 	mlx_hook(g_win, KeyRelease, KeyReleaseMask, keyrelease, NULL); | ||||
| 	mlx_hook(g_win, KeyPress, KeyPressMask, hook_keypress, NULL); | ||||
| 	mlx_hook(g_win, KeyRelease, KeyReleaseMask, hook_keyrelease, NULL); | ||||
| 	mlx_loop_hook(g_mlx, loop_hook, NULL); | ||||
| 	draw_screen(); | ||||
| 	mlx_loop(g_mlx); | ||||
|  |  | |||
							
								
								
									
										19
									
								
								src/map1.c
									
										
									
									
									
								
							
							
						
						
									
										19
									
								
								src/map1.c
									
										
									
									
									
								
							|  | @ -6,7 +6,7 @@ | |||
| /*   By: mc <mc@student.42.fr>                      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2024/10/01 17:12:58 by mcolonna          #+#    #+#             */ | ||||
| /*   Updated: 2024/10/31 17:56:25 by mc               ###   ########.fr       */ | ||||
| /*   Updated: 2024/11/06 19:29:59 by mc               ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
|  | @ -68,15 +68,21 @@ bool	map_from_file(t_map *dest, const char *file) | |||
| 		close(fd); | ||||
| 		return (false); | ||||
| 	} | ||||
| 	return (map_from_file2(dest, &stream, fd)); | ||||
| 	if (!map_from_file2(dest, &stream, fd)) | ||||
| 		return (false); | ||||
| 	return (load_textures(dest)); | ||||
| } | ||||
| 
 | ||||
| void	map_destroy(t_map *map) | ||||
| { | ||||
| 	free((void *)map->texture_east); | ||||
| 	free((void *)map->texture_west); | ||||
| 	free((void *)map->texture_north); | ||||
| 	free((void *)map->texture_south); | ||||
| 	t_direction	d; | ||||
| 
 | ||||
| 	d = 0; | ||||
| 	while (d < 4) | ||||
| 	{ | ||||
| 		free((void *)map->textures[d].image); | ||||
| 		free((void *)map->texture_srcs[d]); | ||||
| 	} | ||||
| 	free(map->cases); | ||||
| } | ||||
| 
 | ||||
|  | @ -109,6 +115,7 @@ static bool	check_map2(const t_map *map, unsigned int x, unsigned int y) | |||
| } | ||||
| 
 | ||||
| // TODO check player
 | ||||
| 
 | ||||
| bool	check_map(const t_map *map) | ||||
| { | ||||
| 	unsigned int	x; | ||||
|  |  | |||
|  | @ -6,7 +6,7 @@ | |||
| /*   By: mc <mc@student.42.fr>                      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2024/10/03 15:05:13 by mc                #+#    #+#             */ | ||||
| /*   Updated: 2024/10/31 17:56:54 by mc               ###   ########.fr       */ | ||||
| /*   Updated: 2024/11/06 19:34:01 by mc               ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
|  | @ -74,4 +74,6 @@ bool	read_map_description(t_map *map, t_stream *stream); | |||
| /// @param map Map to use.
 | ||||
| void	map_init_objects(t_map *map); | ||||
| 
 | ||||
| bool load_textures(t_map *map); | ||||
| 
 | ||||
| #endif | ||||
|  |  | |||
|  | @ -6,7 +6,7 @@ | |||
| /*   By: mc <mc@student.42.fr>                      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2024/10/03 15:02:09 by mc                #+#    #+#             */ | ||||
| /*   Updated: 2024/10/31 17:21:36 by mc               ###   ########.fr       */ | ||||
| /*   Updated: 2024/11/06 19:33:31 by mc               ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
|  | @ -74,37 +74,33 @@ bool	read_string_parameter(const char *name, const char **dest, | |||
| 
 | ||||
| static void	read_map2(t_map *dest, bool *err, bool *rdf) | ||||
| { | ||||
| 	dest->cases = NULL; | ||||
| 	ft_memset(dest, '\0', sizeof(dest)); | ||||
| 	dest->color_ceiling = 0xFF000000; | ||||
| 	dest->color_floor = 0xFF000000; | ||||
| 	dest->texture_east = NULL; | ||||
| 	dest->texture_west = NULL; | ||||
| 	dest->texture_north = NULL; | ||||
| 	dest->texture_south = NULL; | ||||
| 	*err = false; | ||||
| 	*rdf = false; | ||||
| } | ||||
| 
 | ||||
| bool	read_map(t_map *dest, t_stream *stream) | ||||
| bool	read_map(t_map *dest, t_stream *s) | ||||
| { | ||||
| 	bool	err; | ||||
| 	bool	rdf; | ||||
| 	int		old_stream_i; | ||||
| 
 | ||||
| 	read_map2(dest, &err, &rdf); | ||||
| 	while (!rdf && !err && stream->str[stream->i]) | ||||
| 	while (!rdf && !err && s->str[s->i]) | ||||
| 	{ | ||||
| 		old_stream_i = stream->i; | ||||
| 		if ((read_expected_string("\n", stream, &err), err) | ||||
| 			&& !read_string_parameter("NO", &dest->texture_north, stream, &rdf) | ||||
| 			&& !read_string_parameter("SO", &dest->texture_south, stream, &rdf) | ||||
| 			&& !read_string_parameter("WE", &dest->texture_west, stream, &rdf) | ||||
| 			&& !read_string_parameter("EA", &dest->texture_east, stream, &rdf) | ||||
| 			&& !read_color_parameter("F", &dest->color_floor, stream, &rdf) | ||||
| 			&& !read_color_parameter("C", &dest->color_ceiling, stream, &rdf)) | ||||
| 		old_stream_i = s->i; | ||||
| 		if ((read_expected_string("\n", s, &err), err) | ||||
| 			&& !read_string_parameter("NO", &dest->texture_srcs[NORTH], s, &rdf) | ||||
| 			&& !read_string_parameter("SO", &dest->texture_srcs[SOUTH], s, &rdf) | ||||
| 			&& !read_string_parameter("WE", &dest->texture_srcs[WEST], s, &rdf) | ||||
| 			&& !read_string_parameter("EA", &dest->texture_srcs[EAST], s, &rdf) | ||||
| 			&& !read_color_parameter("F", &dest->color_floor, s, &rdf) | ||||
| 			&& !read_color_parameter("C", &dest->color_ceiling, s, &rdf)) | ||||
| 		{ | ||||
| 			stream->i = old_stream_i; | ||||
| 			err = !read_map_description(dest, stream); | ||||
| 			s->i = old_stream_i; | ||||
| 			err = !read_map_description(dest, s); | ||||
| 			break ; | ||||
| 		} | ||||
| 		err = false; | ||||
|  |  | |||
|  | @ -6,12 +6,14 @@ | |||
| /*   By: mc <mc@student.42.fr>                      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2024/10/04 15:12:08 by mcolonna          #+#    #+#             */ | ||||
| /*   Updated: 2024/10/31 17:21:44 by mc               ###   ########.fr       */ | ||||
| /*   Updated: 2024/11/07 00:08:13 by mc               ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
| #include "map_utils.h" | ||||
| 
 | ||||
| #include "global.h" | ||||
| 
 | ||||
| /// @brief Read the map description to get the dimensions.
 | ||||
| ///        The map must be at least 1x1.
 | ||||
| ///
 | ||||
|  | @ -100,3 +102,17 @@ bool	read_map_description(t_map *map, t_stream *stream) | |||
| 	} | ||||
| 	return (true); | ||||
| } | ||||
| 
 | ||||
| bool load_textures(t_map *map) | ||||
| { | ||||
| 	t_direction	d; | ||||
| 
 | ||||
| 	d = 0; | ||||
| 	while (d < 4) { | ||||
| 		map->textures[d].image = mlx_xpm_file_to_image(g_mlx, | ||||
| 			(char *)(map->texture_srcs[d]), | ||||
| 			&map->textures[d].width, &map->textures[d].height); | ||||
| 		d++; | ||||
| 	} | ||||
| 	return (true); | ||||
| } | ||||
|  |  | |||
							
								
								
									
										18
									
								
								src/render.c
									
										
									
									
									
								
							
							
						
						
									
										18
									
								
								src/render.c
									
										
									
									
									
								
							|  | @ -6,16 +6,13 @@ | |||
| /*   By: mc <mc@student.42.fr>                      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2024/10/14 14:55:05 by greg              #+#    #+#             */ | ||||
| /*   Updated: 2024/10/31 18:02:59 by mc               ###   ########.fr       */ | ||||
| /*   Updated: 2024/11/07 00:54:17 by mc               ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
| #include "render.h" | ||||
| #include "render_utils.h" | ||||
| 
 | ||||
| #include "const.h" | ||||
| #include "global.h" | ||||
| 
 | ||||
| static void	calculate_perpwalldist3(int x, | ||||
| 				t_point_double *deltadist, | ||||
| 				t_ray *ray) | ||||
|  | @ -134,15 +131,22 @@ static void	draw_vertical_line(int x, u_int32_t *img_data, | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| int	render(u_int32_t *img_data, t_tex *tex) | ||||
| int	render(u_int32_t *img_data) | ||||
| { | ||||
| 	int		x; | ||||
| 	t_ray	ray; | ||||
| 	 | ||||
| 	t_tex	tex; | ||||
| 
 | ||||
| 	tex.tex_width = 64; // TODO fix
 | ||||
| 	tex.tex_height = 64; // TODO fix
 | ||||
| 	tex.textures[NORTH] = g_map.textures[NORTH].image; | ||||
| 	tex.textures[SOUTH] = g_map.textures[SOUTH].image; | ||||
| 	tex.textures[WEST] = g_map.textures[WEST].image; | ||||
| 	tex.textures[EAST] = g_map.textures[EAST].image; | ||||
| 	x = 0; | ||||
| 	while (x < SCREEN_WIDTH) | ||||
| 	{ | ||||
| 		draw_vertical_line(x, img_data, &ray, tex); | ||||
| 		draw_vertical_line(x, img_data, &ray, &tex); | ||||
| 		x++; | ||||
| 	} | ||||
| 	return (0); | ||||
|  |  | |||
|  | @ -3,10 +3,10 @@ | |||
| /*                                                        :::      ::::::::   */ | ||||
| /*   render_utils.c                                     :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: mc <mc@student.42.fr>                      +#+  +:+       +#+        */ | ||||
| /*   By: mcolonna <mcolonna@student.42.fr>          +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2024/10/24 14:26:22 by grobledo          #+#    #+#             */ | ||||
| /*   Updated: 2024/10/31 18:02:20 by mc               ###   ########.fr       */ | ||||
| /*   Updated: 2024/11/04 14:00:25 by mcolonna         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
|  | @ -39,16 +39,18 @@ void	draw_wall(t_tex *tex, t_ray *ray, const int line_height, int x, | |||
| { | ||||
| 	u_int32_t	color; | ||||
| 	u_int32_t	*texture_data; | ||||
| 	int			texx; | ||||
| 	int			texy; | ||||
| 
 | ||||
| 	tex->tex_y = ((y - (-line_height / 2 + SCREEN_HEIGHT / 2)) \ | ||||
| 	texy = ((y - (-line_height / 2 + SCREEN_HEIGHT / 2)) \ | ||||
| 		* tex->tex_height) / line_height; | ||||
| 	tex->tex_x = (int)(ray->wallx * (double)tex->tex_width); | ||||
| 	texx = (int)(ray->wallx * (double)tex->tex_width); | ||||
| 	if (ray->side == 0 && ray->dir.x > 0) | ||||
| 		tex->tex_x = tex->tex_width - tex->tex_x - 1; | ||||
| 		texx = tex->tex_width - texx - 1; | ||||
| 	if (ray->side == 1 && ray->dir.y < 0) | ||||
| 		tex->tex_x = tex->tex_height - tex->tex_x - 1; | ||||
| 		texx = tex->tex_height - texx - 1; | ||||
| 	texture_data = (u_int32_t *)mlx_get_data_addr(tex->textures[tex->tex_dir], | ||||
| 			&tex->bpp, &tex->size_line, &tex->endian); | ||||
| 	color = texture_data[tex->tex_x * tex->tex_width + tex->tex_y]; | ||||
| 	color = texture_data[texx * tex->tex_width + texy]; | ||||
| 	img_data[y * SCREEN_WIDTH + x] = color; | ||||
| } | ||||
|  |  | |||
|  | @ -3,10 +3,10 @@ | |||
| /*                                                        :::      ::::::::   */ | ||||
| /*   render_utils.h                                     :+:      :+:    :+:   */ | ||||
| /*                                                    +:+ +:+         +:+     */ | ||||
| /*   By: mc <mc@student.42.fr>                      +#+  +:+       +#+        */ | ||||
| /*   By: mcolonna <mcolonna@student.42.fr>          +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2024/10/24 14:26:22 by grobledo          #+#    #+#             */ | ||||
| /*   Updated: 2024/10/31 18:01:59 by mc               ###   ########.fr       */ | ||||
| /*   Updated: 2024/11/04 13:07:42 by mcolonna         ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
|  |  | |||
|  | @ -6,7 +6,7 @@ | |||
| /*   By: mc <mc@student.42.fr>                      +#+  +:+       +#+        */ | ||||
| /*                                                +#+#+#+#+#+   +#+           */ | ||||
| /*   Created: 2024/10/15 12:38:40 by mcolonna          #+#    #+#             */ | ||||
| /*   Updated: 2024/10/31 17:25:30 by mc               ###   ########.fr       */ | ||||
| /*   Updated: 2024/11/07 00:05:39 by mc               ###   ########.fr       */ | ||||
| /*                                                                            */ | ||||
| /* ************************************************************************** */ | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,9 +1,9 @@ | |||
| F 255,127,0 | ||||
| EA eastimage | ||||
| NO theimageforthenorthwall | ||||
| C 0,2,67 | ||||
| SO SOUTH!!!!!!1 | ||||
| WE weeeee | ||||
| EA textures/east.xpm | ||||
| NO textures/north.xpm | ||||
| SO textures/south.xpm | ||||
| WE textures/west.xpm | ||||
| 111111111 | ||||
| 100000001 | ||||
| 100010001 | ||||
|  |  | |||
|  | @ -1,10 +1,10 @@ | |||
| F 255,127,0 | ||||
| EA eastimage | ||||
| NO theimageforthenorthwall | ||||
| C 0,2,67 | ||||
| SO SOUTH!!!!!!1 | ||||
| WE weeeee | ||||
| 111111111 | ||||
| EA textures/east.xpm | ||||
| NO textures/north.xpm | ||||
| SO textures/south.xpm | ||||
| WE textures/west.xpm | ||||
|     111 | ||||
| 111110111 | ||||
| 10000N001 | ||||
| 111110111 | ||||
|  |  | |||
|  | @ -1,9 +1,9 @@ | |||
| F 255,127,0 | ||||
| EA eastimage | ||||
| NO theimageforthenorthwall | ||||
| C 0,2,67 | ||||
| SO SOUTH!!!!!!1 | ||||
| WE weeeee | ||||
| EA textures/east.xpm | ||||
| NO textures/north.xpm | ||||
| SO textures/south.xpm | ||||
| WE textures/west.xpm | ||||
| 111 | ||||
| 1N1 | ||||
| 111 | ||||
|  |  | |||
|  | @ -1,15 +1,19 @@ | |||
| F        255,  127  ,0 | ||||
| 
 | ||||
| EA     eastimage | ||||
| 
 | ||||
| NO theimageforthenorthwall | ||||
| C	0,   2  ,	67 | ||||
| 
 | ||||
| SO	  	SOUTH!!!!!!1 | ||||
| 
 | ||||
| WE weeeee      | ||||
| 
 | ||||
| 
 | ||||
| EA     textures/east.xpm | ||||
| NO textures/north.xpm | ||||
| 
 | ||||
| SO  textures/south.xpm | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| WE textures/west.xpm | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,15 +1,13 @@ | |||
| F 255,127,0 | ||||
| 
 | ||||
| EA eastimage | ||||
| EA textures/east.xpm | ||||
| 
 | ||||
| NO theimageforthenorthwall | ||||
| NO textures/north.xpm | ||||
| C 0,2,67 | ||||
| 
 | ||||
| SO SOUTH!!!!!!1 | ||||
| 
 | ||||
| WE weeeee | ||||
| 
 | ||||
| SO textures/south.xpm | ||||
| 
 | ||||
| WE textures/west.xpm | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,9 +1,9 @@ | |||
| F 255,127,0 | ||||
| EA eastimage | ||||
| NO theimageforthenorthwall | ||||
| C 0,2,67 | ||||
| SO SOUTH!!!!!!1 | ||||
| WE weeeee | ||||
| EA textures/east.xpm | ||||
| NO textures/north.xpm | ||||
| SO textures/south.xpm | ||||
| WE textures/west.xpm | ||||
| 
 | ||||
|                     111 | ||||
|               111   101 | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 mcolonna
						mcolonna