diff --git a/Makefile b/Makefile index 1418125..3f80ddf 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: whaffman +#+ # # +#+ # # Created: 2024/10/15 11:48:46 by whaffman #+# #+# # -# Updated: 2025/05/11 13:26:58 by whaffman ######## odam.nl # +# Updated: 2025/05/14 16:06:31 by whaffman ######## odam.nl # # # # **************************************************************************** # @@ -45,7 +45,7 @@ SOURCES = $(shell basename -a $(shell find $(SRC_PATH) -type f -name "*.c")) # Build configurations BUILD_CONFIGS = release debug asan tsan -release_CFLAGS = -Wall -Werror -Werror -O3 +release_CFLAGS = -Wall -Werror -Werror -flto -Ofast -march=native -mtune=native -ffast-math debug_CFLAGS = -Wall -Werror -Werror -g3 -DDEBUG -DDBG='fprintf(stderr, RED "DEBUG: " RESET "%s:%d (%s)\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);' asan_CFLAGS = -Wall -Werror -Werror -fsanitize=address,leak,undefined -g3 tsan_CFLAGS = -Wall -Werror -Werror -fsanitize=thread -g3 diff --git a/assets/overlay2.png b/assets/overlay2.png index 2ddae1e..ab0c3ba 100644 Binary files a/assets/overlay2.png and b/assets/overlay2.png differ diff --git a/inc/allowed.h b/inc/allowed.h index f665beb..3fe8f16 100644 --- a/inc/allowed.h +++ b/inc/allowed.h @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* ::: :::::::: */ -/* allowed.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: qmennen +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2025/04/15 15:31:54 by qmennen #+# #+# */ -/* Updated: 2025/04/15 15:57:15 by qmennen ### ########.fr */ +/* :::::::: */ +/* allowed.h :+: :+: */ +/* +:+ */ +/* By: qmennen +#+ */ +/* +#+ */ +/* Created: 2025/04/15 15:31:54 by qmennen #+# #+# */ +/* Updated: 2025/05/14 12:42:06 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -19,6 +19,6 @@ # include # include # include -#include +# include # include // TODO: Check if this is allowed? #endif diff --git a/inc/collision.h b/inc/collision.h index 48fd652..3860e61 100644 --- a/inc/collision.h +++ b/inc/collision.h @@ -1,21 +1,21 @@ /* ************************************************************************** */ /* */ -/* ::: :::::::: */ -/* collision.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: qmennen +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2025/04/22 14:40:47 by qmennen #+# #+# */ -/* Updated: 2025/05/06 15:20:37 by qmennen ### ########.fr */ +/* :::::::: */ +/* collision.h :+: :+: */ +/* +:+ */ +/* By: qmennen +#+ */ +/* +#+ */ +/* Created: 2025/04/22 14:40:47 by qmennen #+# #+# */ +/* Updated: 2025/05/14 12:42:16 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #ifndef COLLISION_H -#define COLLISION_H +# define COLLISION_H -#include "cub3d.h" +# include "cub3d.h" -int collision_horizontal(t_map *map, t_player *player, double xa); -int collision_vertical(t_map *map, t_player *player, double ya); +int collision_horizontal(t_map *map, t_player *player, double xa); +int collision_vertical(t_map *map, t_player *player, double ya); #endif diff --git a/inc/cub3d.h b/inc/cub3d.h index c541d3d..4bcaab5 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -6,7 +6,7 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */ -/* Updated: 2025/05/12 11:31:51 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 12:42:27 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -32,7 +32,7 @@ # define NUM_KEYS 256 # define TILE_SIZE 8 -#define MINIMAP_SIZE 300 +# define MINIMAP_SIZE 300 # include "MLX42.h" # include "allowed.h" @@ -51,6 +51,6 @@ # include "parser.h" # include "texture.h" -int initialize_cub3d(t_game **game, const char *mapfile); +int initialize_cub3d(t_game **game, const char *mapfile); #endif diff --git a/inc/errors.h b/inc/errors.h index c93c4ec..282b3b1 100644 --- a/inc/errors.h +++ b/inc/errors.h @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* ::: :::::::: */ -/* errors.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: qmennen +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2025/04/15 15:42:55 by qmennen #+# #+# */ -/* Updated: 2025/04/15 15:59:42 by qmennen ### ########.fr */ +/* :::::::: */ +/* errors.h :+: :+: */ +/* +:+ */ +/* By: qmennen +#+ */ +/* +#+ */ +/* Created: 2025/04/15 15:42:55 by qmennen #+# #+# */ +/* Updated: 2025/05/14 12:43:01 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -15,8 +15,7 @@ # include "cub3d.h" - -const char *last_error(); -void game_error(t_game *game, const char *msg); +const char *last_error(void); +void game_error(t_game *game, const char *msg); #endif diff --git a/inc/map.h b/inc/map.h index d1c8e69..7b4b8d9 100644 --- a/inc/map.h +++ b/inc/map.h @@ -6,7 +6,7 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/04/17 19:19:19 by qmennen #+# #+# */ -/* Updated: 2025/04/25 11:37:55 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 12:42:54 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -25,8 +25,6 @@ t_tile **copy_map(t_tile **grid, int width, int height); int parse_args(const char *mapfile, t_game *game); t_tile **create_grid(int width, int height); int find_player_or_empty(t_map *map, int *x, int *y); - int floodfill(t_map *map, int x, int y); - #endif diff --git a/inc/player.h b/inc/player.h index 97e869a..1f779a2 100644 --- a/inc/player.h +++ b/inc/player.h @@ -1,22 +1,22 @@ /* ************************************************************************** */ /* */ -/* ::: :::::::: */ -/* player.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: qmennen +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2025/04/15 18:53:27 by qmennen #+# #+# */ -/* Updated: 2025/05/06 15:20:37 by qmennen ### ########.fr */ +/* :::::::: */ +/* player.h :+: :+: */ +/* +:+ */ +/* By: qmennen +#+ */ +/* +#+ */ +/* Created: 2025/04/15 18:53:27 by qmennen #+# #+# */ +/* Updated: 2025/05/14 12:43:14 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #ifndef PLAYER_H -#define PLAYER_H +# define PLAYER_H -#include "cub3d.h" +# include "cub3d.h" -int player_create(t_game **game); -void player_render(t_screen *screen, t_player *player); -void player_update(t_game *game, double delta_time); +int player_create(t_game **game); +void player_render(t_screen *screen, t_player *player); +void player_update(t_game *game, double delta_time); #endif diff --git a/inc/render.h b/inc/render.h index 6e85d87..0c1f536 100644 --- a/inc/render.h +++ b/inc/render.h @@ -6,7 +6,7 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/04/15 16:28:16 by qmennen #+# #+# */ -/* Updated: 2025/05/09 14:34:27 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 13:08:37 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -16,12 +16,18 @@ # include "cub3d.h" int render_check_bounds(t_screen *screen, t_vec2 *point); -void render_line(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color); -void render_circle(t_screen *screen, t_vec2 point, int radius, unsigned int color); +void render_line(t_screen *screen, + t_vec2 start, t_vec2 end, unsigned int color); +void render_circle( + t_screen *screen, t_vec2 point, int radius, unsigned int color); void render_clear(t_screen *screen); void render_entities(t_game *game); void render_map(t_game *game); -void cast_rays(t_game *game); -void render_sprites(t_render* render, t_game *game); +void cast_rays(t_game *game); +void render_sprites(t_render *render, t_game *game); +double dda(t_vec2 ray_dir, t_vec2 pos, t_map *map); +void draw_floor(t_game *game); +unsigned int get_texture_color(mlx_texture_t *texture, + t_render render, int tex_x, int tex_y); #endif diff --git a/inc/screen.h b/inc/screen.h index 3bad569..ccfb2d3 100644 --- a/inc/screen.h +++ b/inc/screen.h @@ -1,19 +1,19 @@ /* ************************************************************************** */ /* */ -/* ::: :::::::: */ -/* screen.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: qmennen +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2025/04/15 15:30:34 by qmennen #+# #+# */ -/* Updated: 2025/04/22 17:20:41 by qmennen ### ########.fr */ +/* :::::::: */ +/* screen.h :+: :+: */ +/* +:+ */ +/* By: qmennen +#+ */ +/* +#+ */ +/* Created: 2025/04/15 15:30:34 by qmennen #+# #+# */ +/* Updated: 2025/05/14 12:43:47 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #ifndef SCREEN_H # define SCREEN_H -#include "cub3d.h" +# include "cub3d.h" int screen_create(t_game **game); int screen_display(t_screen *screen); diff --git a/inc/types.h b/inc/types.h index 10f5b5a..7789937 100644 --- a/inc/types.h +++ b/inc/types.h @@ -6,14 +6,14 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/04/15 15:52:44 by qmennen #+# #+# */ -/* Updated: 2025/05/09 12:39:56 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 12:48:10 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #ifndef TYPES_H -#define TYPES_H +# define TYPES_H -#include "cub3d.h" +# include "cub3d.h" typedef enum TILE { @@ -22,39 +22,39 @@ typedef enum TILE TILE_EMPTY = 0, TILE_WALL = 1, TILE_PLAYER = 2, -} t_tile; +} t_tile; typedef struct s_vec2 { - double x; - double y; -} t_vec2; + double x; + double y; +} t_vec2; typedef struct s_vec2_int { - int x; - int y; -} t_vec2_int; + int x; + int y; +} t_vec2_int; typedef struct s_vec2_line { - t_vec2 support; - t_vec2 dir; -} t_vec2_line; + t_vec2 support; + t_vec2 dir; +} t_vec2_line; typedef struct s_player { - t_vec2 pos; - t_vec2 dir; - t_vec2 camera; - double speed; - double fov; - int is_moving; -} t_player; + t_vec2 pos; + t_vec2 dir; + t_vec2 camera; + double speed; + double fov; + int is_moving; +} t_player; typedef struct s_sprite { - int n_frames; + int n_frames; double dist; double cam_frac; double alpha; @@ -64,38 +64,38 @@ typedef struct s_sprite typedef struct s_map { - unsigned int width; - unsigned int height; - t_tile **grid; - char *NO_texture; - char *SO_texture; - char *WE_texture; - char *EA_texture; + unsigned int width; + unsigned int height; + t_tile **grid; + char *north_texture; + char *south_texture; + char *west_texture; + char *east_texture; mlx_texture_t *texture_floor; mlx_texture_t *texture_ceiling; mlx_texture_t *textures[4]; t_sprite *sprites; - unsigned int n_sprites; - unsigned int floor_color; - unsigned int ceiling_color; -} t_map; + unsigned int n_sprites; + unsigned int floor_color; + unsigned int ceiling_color; +} t_map; typedef struct s_keyboard { - int keys[NUM_KEYS]; - int last_keys[NUM_KEYS]; -} t_keyboard; + int keys[NUM_KEYS]; + int last_keys[NUM_KEYS]; +} t_keyboard; typedef struct s_screen { - mlx_t *mlx; - mlx_image_t *img; - mlx_image_t *minimap; - mlx_image_t *background; - mlx_image_t *hud; - unsigned int width; - unsigned int height; -} t_screen; + mlx_t *mlx; + mlx_image_t *img; + mlx_image_t *minimap; + mlx_image_t *background; + mlx_image_t *hud; + unsigned int width; + unsigned int height; +} t_screen; typedef enum e_side { @@ -103,21 +103,21 @@ typedef enum e_side SIDE_SOUTH, SIDE_WEST, SIDE_EAST, -} t_side; +} t_side; typedef struct s_render { - double perp_dist; - t_side side; - double wall_x; -} t_render; + double perp_dist; + t_side side; + double wall_x; +} t_render; typedef struct s_game { - t_map *map; - t_player *player; - t_screen *screen; - t_keyboard *keyboard; -} t_game; + t_map *map; + t_player *player; + t_screen *screen; + t_keyboard *keyboard; +} t_game; #endif diff --git a/inc/vec_math.h b/inc/vec_math.h index b21e3d8..4cf2d7b 100644 --- a/inc/vec_math.h +++ b/inc/vec_math.h @@ -6,7 +6,7 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/04/25 10:11:44 by whaffman #+# #+# */ -/* Updated: 2025/05/12 12:11:59 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 12:48:19 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -118,7 +118,6 @@ t_vec2_int vec2_to_int(t_vec2 vec); */ t_vec2 vec2_from_int(t_vec2_int vec); - /** * @brief Calculates the fractional part of each component of a 2D vector. * diff --git a/src/map/map_free.c b/src/map/map_free.c index 5f94122..d09e75f 100644 --- a/src/map/map_free.c +++ b/src/map/map_free.c @@ -6,19 +6,19 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/04/23 12:22:28 by whaffman #+# #+# */ -/* Updated: 2025/05/07 11:51:46 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 12:48:03 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include #include "cub3d.h" -void map_free(t_map *map) +void map_free(t_map *map) { grid_free(map->grid, map->height); - free(map->NO_texture); - free(map->SO_texture); - free(map->WE_texture); - free(map->EA_texture); + free(map->north_texture); + free(map->south_texture); + free(map->west_texture); + free(map->east_texture); free(map); } diff --git a/src/math/add.c b/src/math/add.c index 359d829..51001b6 100644 --- a/src/math/add.c +++ b/src/math/add.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/04/25 09:54:24 by whaffman #+# #+# */ -/* Updated: 2025/05/07 11:49:58 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 16:13:52 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ diff --git a/src/math/dist.c b/src/math/dist.c index bbfa31f..3d535bc 100644 --- a/src/math/dist.c +++ b/src/math/dist.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/04/25 10:07:59 by whaffman #+# #+# */ -/* Updated: 2025/05/07 11:50:10 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 16:13:44 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ diff --git a/src/math/dist_point_line.c b/src/math/dist_point_line.c index 3e90d7d..6a1eb1b 100644 --- a/src/math/dist_point_line.c +++ b/src/math/dist_point_line.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/04/25 10:09:45 by whaffman #+# #+# */ -/* Updated: 2025/05/07 11:50:20 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 16:13:48 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ diff --git a/src/math/dot.c b/src/math/dot.c index 1dd862a..90d48d8 100644 --- a/src/math/dot.c +++ b/src/math/dot.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/04/25 09:58:29 by whaffman #+# #+# */ -/* Updated: 2025/05/07 11:50:27 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 16:13:41 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ diff --git a/src/math/get_fraction.c b/src/math/get_fraction.c index e22a08a..8ee59d8 100644 --- a/src/math/get_fraction.c +++ b/src/math/get_fraction.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/05/12 12:09:27 by whaffman #+# #+# */ -/* Updated: 2025/05/12 12:10:01 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 16:13:38 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -19,4 +19,4 @@ t_vec2 get_fraction(t_vec2 vec) result.x = vec.x - (int)vec.x; result.y = vec.y - (int)vec.y; return (result); -} \ No newline at end of file +} diff --git a/src/math/mul.c b/src/math/mul.c index c467dd8..72ff8a5 100644 --- a/src/math/mul.c +++ b/src/math/mul.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/04/25 09:56:39 by whaffman #+# #+# */ -/* Updated: 2025/05/07 11:50:43 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 16:13:36 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ diff --git a/src/math/norm.c b/src/math/norm.c index e601c0d..b5f6907 100644 --- a/src/math/norm.c +++ b/src/math/norm.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/04/25 09:59:13 by whaffman #+# #+# */ -/* Updated: 2025/05/07 11:50:52 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 16:13:32 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ diff --git a/src/math/perp.c b/src/math/perp.c index 76fd020..ba08d52 100644 --- a/src/math/perp.c +++ b/src/math/perp.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/04/25 10:34:39 by whaffman #+# #+# */ -/* Updated: 2025/05/07 11:50:59 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 16:13:27 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ diff --git a/src/math/rot.c b/src/math/rot.c index 459e7f9..59b46b3 100644 --- a/src/math/rot.c +++ b/src/math/rot.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/04/25 10:35:58 by whaffman #+# #+# */ -/* Updated: 2025/05/07 11:51:19 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 16:13:22 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ diff --git a/src/math/rot_by_dir.c b/src/math/rot_by_dir.c index 3af850f..74abe57 100644 --- a/src/math/rot_by_dir.c +++ b/src/math/rot_by_dir.c @@ -6,18 +6,19 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/05/11 13:24:34 by whaffman #+# #+# */ -/* Updated: 2025/05/11 13:38:30 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 16:13:25 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "cub3d.h" + t_vec2 rot_by_dir(t_vec2 vec, t_vec2 dir, t_vec2 axis) { - const double sin_angle = dir.x; - const double cos_angle = -dir.y; - t_vec2 rotated_vec; + const double sin_res = dir.x; + const double cos_res = -dir.y; + t_vec2 res; - rotated_vec.x = axis.x + (vec.x - axis.x) * cos_angle - (vec.y - axis.y) * sin_angle; - rotated_vec.y = axis.y + (vec.x - axis.x) * sin_angle + (vec.y - axis.y) * cos_angle; - return (rotated_vec); + res.x = axis.x + (vec.x - axis.x) * cos_res - (vec.y - axis.y) * sin_res; + res.y = axis.y + (vec.x - axis.x) * sin_res + (vec.y - axis.y) * cos_res; + return (res); } diff --git a/src/math/sub.c b/src/math/sub.c index 6cc2a8e..fd85dad 100644 --- a/src/math/sub.c +++ b/src/math/sub.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/04/25 09:57:55 by whaffman #+# #+# */ -/* Updated: 2025/05/07 11:51:07 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 16:13:20 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ diff --git a/src/math/vec2_from_int.c b/src/math/vec2_from_int.c index a2645cf..f7b6c1c 100644 --- a/src/math/vec2_from_int.c +++ b/src/math/vec2_from_int.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/05/12 11:03:47 by whaffman #+# #+# */ -/* Updated: 2025/05/12 11:03:58 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 16:13:17 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -19,4 +19,4 @@ t_vec2 vec2_from_int(t_vec2_int vec) result.x = (double)vec.x; result.y = (double)vec.y; return (result); -} \ No newline at end of file +} diff --git a/src/math/vec2_to_int.c b/src/math/vec2_to_int.c index c523660..ea15f11 100644 --- a/src/math/vec2_to_int.c +++ b/src/math/vec2_to_int.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/05/12 11:02:49 by whaffman #+# #+# */ -/* Updated: 2025/05/12 11:03:27 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 16:13:14 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -19,4 +19,4 @@ t_vec2_int vec2_to_int(t_vec2 vec) result.x = (int)vec.x; result.y = (int)vec.y; return (result); -} \ No newline at end of file +} diff --git a/src/parser/parse_config_line.c b/src/parser/parse_config_line.c index d9ada11..0ecbce9 100644 --- a/src/parser/parse_config_line.c +++ b/src/parser/parse_config_line.c @@ -6,27 +6,27 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/04/22 13:10:06 by whaffman #+# #+# */ -/* Updated: 2025/05/07 11:48:16 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 12:48:03 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "cub3d.h" -int parse_config_line(const char *line, t_map *map) +int parse_config_line(const char *line, t_map *map) { - char **tokens; + char **tokens; tokens = ft_split(line, ' '); if (!tokens || !tokens[0] || !tokens[1] || tokens[2]) return (FAILURE); if (ft_strncmp(tokens[0], "NO", 2) == 0) - map->NO_texture = ft_strdup(tokens[1]); + map->north_texture = ft_strdup(tokens[1]); else if (ft_strncmp(tokens[0], "SO", 2) == 0) - map->SO_texture = ft_strdup(tokens[1]); + map->south_texture = ft_strdup(tokens[1]); else if (ft_strncmp(tokens[0], "WE", 2) == 0) - map->WE_texture = ft_strdup(tokens[1]); + map->west_texture = ft_strdup(tokens[1]); else if (ft_strncmp(tokens[0], "EA", 2) == 0) - map->EA_texture = ft_strdup(tokens[1]); + map->east_texture = ft_strdup(tokens[1]); else if (ft_strncmp(tokens[0], "F", 1) == 0) map->floor_color = parse_color(tokens[1]); else if (ft_strncmp(tokens[0], "C", 1) == 0) diff --git a/src/parser/print_config.c b/src/parser/print_config.c index bf8bb17..8a8bf78 100644 --- a/src/parser/print_config.c +++ b/src/parser/print_config.c @@ -6,21 +6,21 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/04/22 13:11:18 by whaffman #+# #+# */ -/* Updated: 2025/05/07 11:49:07 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 12:48:03 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "cub3d.h" -void print_config(t_map *map) +void print_config(t_map *map) { printf("Map:\n"); printf("Width: %d, Height: %d\n", map->width, map->height); printf("Textures:\n"); - printf("NO: %s\n", map->NO_texture); - printf("SO: %s\n", map->SO_texture); - printf("WE: %s\n", map->WE_texture); - printf("EA: %s\n", map->EA_texture); + printf("NO: %s\n", map->north_texture); + printf("SO: %s\n", map->south_texture); + printf("WE: %s\n", map->west_texture); + printf("EA: %s\n", map->east_texture); printf("Floor color: %u\n", map->floor_color); printf("Ceiling color: %u\n", map->ceiling_color); printf("Grid:\n"); diff --git a/src/render/DDAscratch.c b/src/render/DDAscratch.c deleted file mode 100644 index f56b11a..0000000 --- a/src/render/DDAscratch.c +++ /dev/null @@ -1,235 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* :::::::: */ -/* DDAscratch.c :+: :+: */ -/* +:+ */ -/* By: qmennen +#+ */ -/* +#+ */ -/* Created: 2025/05/02 11:58:09 by whaffman #+# #+# */ -/* Updated: 2025/05/12 12:55:30 by whaffman ######## odam.nl */ -/* */ -/* ************************************************************************** */ - -#include "cub3d.h" -#include "vec_math.h" -#include - -t_vec2 get_delta_dist(t_vec2 ray_dir) -{ - t_vec2 delta_dist; - - if (ray_dir.x == 0) - delta_dist.x = 1e30; - else - delta_dist.x = fabs(1 / ray_dir.x); - if (ray_dir.y == 0) - delta_dist.y = 1e30; - else - delta_dist.y = fabs(1 / ray_dir.y); - return (delta_dist); -} - -t_vec2 get_step(t_vec2 ray_dir) -{ - t_vec2 step; - - step.x = 2 * (ray_dir.x >= 0) - 1; - step.y = 2 * (ray_dir.y >= 0) - 1; - return (step); -} - -t_vec2 get_side_dist(t_vec2 ray_dir, t_vec2 pos, t_vec2 delta_dist) -{ - const t_vec2 frac_pos = (t_vec2){pos.x - (int)pos.x, pos.y - (int)pos.y}; - const int raydir_x_pos = (ray_dir.x >= 0); - const int raydir_y_pos = (ray_dir.y >= 0); - t_vec2 side_dist; - - side_dist.x = ((1 - raydir_x_pos) * frac_pos.x - + raydir_x_pos * (1 - frac_pos.x)) * delta_dist.x; - side_dist.y = ((1 - raydir_y_pos) * frac_pos.y - + raydir_y_pos * (1 - frac_pos.y)) * delta_dist.y; - return (side_dist); -} - -int dda_main(t_vec2 ray_dir, t_vec2_int map_pos, t_vec2 *side_dist, t_map *map) -{ - const t_vec2 delta_dist = get_delta_dist(ray_dir); - const t_vec2 step = get_step(ray_dir); - int side; - int hit; - - hit = 0; - while (hit == 0) - { - side = (side_dist->x >= side_dist->y); - side_dist->x += delta_dist.x * (1 - side); - side_dist->y += delta_dist.y * side; - map_pos.x += step.x * (1 - side); - map_pos.y += step.y * side; - if (map_pos.x < 0 - || map_pos.x >= map->width - || map_pos.y < 0 - || map_pos.y >= map->height) - printf("Out of bounds: %d %d\n", map_pos.x, map_pos.y); - hit = (map->grid[map_pos.y][map_pos.x] == TILE_WALL); - } - return (side); -} - -// Returns the distance to the wall hit if the wall is hit in y -// direction the result is negative, if the wall is hit -// in x direction the result is positive -double dda(t_vec2 ray_dir, t_vec2 pos, t_map *map) -{ - const t_vec2 delta_dist = get_delta_dist(ray_dir); - t_vec2 side_dist; - int side; - - side_dist = get_side_dist(ray_dir, pos, delta_dist); - side = dda_main(ray_dir, - (t_vec2_int){(int)pos.x, (int)pos.y}, - &side_dist, - map); - return ((1 - side) * (side_dist.x - delta_dist.x) - - side * (side_dist.y - delta_dist.y)); -} - -t_side get_side(t_vec2 ray_dir, double perp_dist) -{ - if (perp_dist > 0) - { - if (ray_dir.x > 0) - return (SIDE_WEST); - else - return (SIDE_EAST); - } - else - { - if (ray_dir.y > 0) - return (SIDE_NORTH); - else - return (SIDE_SOUTH); - } -} - -t_render cast_ray(t_game *game, int x) -{ - t_vec2 ray_dir; - t_vec2 pos; - t_render render; - double perp_dist; - - ray_dir = add(game->player->dir, - mul(game->player->camera, - (2.0f * x / (double)game->screen->width - 1))); - pos = game->player->pos; - perp_dist = dda(ray_dir, pos, game->map); - render.perp_dist = fabs(perp_dist); - render.side = get_side(ray_dir, perp_dist); - if (perp_dist < 0) - render.wall_x = pos.x + ray_dir.x * render.perp_dist; - else - render.wall_x = pos.y + ray_dir.y * render.perp_dist; - render.wall_x -= floor(render.wall_x); - return (render); -} - -unsigned int get_texture_color(mlx_texture_t *texture, - t_render render, int tex_x, int tex_y) -{ - int index; - double dist; - - index = (tex_x + tex_y * texture->height) * texture->bytes_per_pixel; - dist = (render.perp_dist == 0) * 1e30 - + (render.perp_dist > 1) * render.perp_dist - + (render.perp_dist <= 1) * 1; - return (texture->pixels[index] << 24 - | texture->pixels[index + 1] << 16 - | texture->pixels[index + 2] << 8 - | (int)(1.0 / dist * 255)); -} - -void draw_line(t_game *game, t_render render, int x) -{ - int y; - int color; - int height; - int start; - int tex_start; - int end; - int tex_x; - int tex_y; - - height = (int)(game->screen->height / render.perp_dist); - start = -height / 2 + game->screen->height / 2; - tex_start = start; - if (start < 0) - start = 0; - end = height / 2 + game->screen->height / 2; - if (end >= game->screen->height) - end = game->screen->height - 1; - tex_x = (int)(render.wall_x * (double)game->map->textures[render.side]->width); - if (render.side == SIDE_NORTH || render.side == SIDE_EAST) - tex_x = game->map->textures[render.side]->width - tex_x - 1; - y = start; - while (y < end) - { - tex_y = (int)(((double) game->map->textures[render.side]->height / (double) height) * (y - tex_start)); - color = get_texture_color(game->map->textures[render.side], render, tex_x, tex_y); - if (x < 0 || x >= game->screen->width || y < 0 || y >= game->screen->height) - break ; - mlx_put_pixel(game->screen->img, x, y, color); - y++; - } -} - -void draw_floor(t_game *game) -{ - int y; - int x; - int color; - double row_dist; - t_vec2 floor_step; - t_vec2 floor_pos; - t_vec2_int tex_coords; - const t_vec2 left_ray = sub(game->player->dir, game->player->camera); - const t_vec2 right_ray = add(game->player->dir, game->player->camera); - - y = game->screen->height / 2; - while (y < game->screen->height) - { - row_dist = 0.5 * game->screen->height / (y - game->screen->height / 2.0); - floor_step = mul(mul(sub(right_ray, left_ray), row_dist), 1.0 / game->screen->width); - floor_pos = add(game->player->pos, mul(left_ray, row_dist)); - x = 0; - while (x < game->screen->width) - { - tex_coords = vec2_to_int(mul(get_fraction(floor_pos), 64)); // & 63 is gone heap buffer overflow with asan i dont get it - color = get_texture_color(game->map->texture_floor, (t_render){row_dist, 0, 0}, tex_coords.x, tex_coords.y); - mlx_put_pixel(game->screen->img, x, y, color); - color = get_texture_color(game->map->texture_ceiling, (t_render){row_dist, 0, 0}, tex_coords.x, tex_coords.y); - mlx_put_pixel(game->screen->img, x, game->screen->height - y - 1, color); - floor_pos = add(floor_pos, floor_step); - x++; - } - y++; - } -} - -void cast_rays(t_game *game) -{ - int x; - t_render render[WIDTH]; - - x = 0; - draw_floor(game); - while (x < game->screen->width) - { - render[x] = cast_ray(game, x); - draw_line(game, render[x], x); - x++; - } - render_sprites(render, game); -} diff --git a/src/render/dda.c b/src/render/dda.c new file mode 100644 index 0000000..04c57d7 --- /dev/null +++ b/src/render/dda.c @@ -0,0 +1,235 @@ +/* ************************************************************************** */ +/* */ +/* :::::::: */ +/* dda.c :+: :+: */ +/* +:+ */ +/* By: qmennen +#+ */ +/* +#+ */ +/* Created: 2025/05/02 11:58:09 by whaffman #+# #+# */ +/* Updated: 2025/05/14 13:49:32 by whaffman ######## odam.nl */ +/* */ +/* ************************************************************************** */ + +#include "cub3d.h" +#include "vec_math.h" +#include + +t_vec2 get_delta_dist(t_vec2 ray_dir) +{ + t_vec2 delta_dist; + + if (ray_dir.x == 0) + delta_dist.x = 1e30; + else + delta_dist.x = fabs(1 / ray_dir.x); + if (ray_dir.y == 0) + delta_dist.y = 1e30; + else + delta_dist.y = fabs(1 / ray_dir.y); + return (delta_dist); +} + +t_vec2 get_step(t_vec2 ray_dir) +{ + t_vec2 step; + + step.x = 2 * (ray_dir.x >= 0) - 1; + step.y = 2 * (ray_dir.y >= 0) - 1; + return (step); +} + +t_vec2 get_side_dist(t_vec2 ray_dir, t_vec2 pos, t_vec2 delta_dist) +{ + const t_vec2 frac_pos = (t_vec2){pos.x - (int)pos.x, pos.y - (int)pos.y}; + const int raydir_x_pos = (ray_dir.x >= 0); + const int raydir_y_pos = (ray_dir.y >= 0); + t_vec2 side_dist; + + side_dist.x = ((1 - raydir_x_pos) * frac_pos.x + + raydir_x_pos * (1 - frac_pos.x)) * delta_dist.x; + side_dist.y = ((1 - raydir_y_pos) * frac_pos.y + + raydir_y_pos * (1 - frac_pos.y)) * delta_dist.y; + return (side_dist); +} + +int dda_main(t_vec2 ray_dir, t_vec2_int map_pos, t_vec2 *side_dist, t_map *map) +{ + const t_vec2 delta_dist = get_delta_dist(ray_dir); + const t_vec2 step = get_step(ray_dir); + int side; + int hit; + + hit = 0; + while (hit == 0) + { + side = (side_dist->x >= side_dist->y); + side_dist->x += delta_dist.x * (1 - side); + side_dist->y += delta_dist.y * side; + map_pos.x += step.x * (1 - side); + map_pos.y += step.y * side; + if (map_pos.x < 0 + || map_pos.x >= map->width + || map_pos.y < 0 + || map_pos.y >= map->height) + printf("Out of bounds: %d %d\n", map_pos.x, map_pos.y); + hit = (map->grid[map_pos.y][map_pos.x] == TILE_WALL); + } + return (side); +} + +// Returns the distance to the wall hit if the wall is hit in y +// direction the result is negative, if the wall is hit +// in x direction the result is positive +double dda(t_vec2 ray_dir, t_vec2 pos, t_map *map) +{ + const t_vec2 delta_dist = get_delta_dist(ray_dir); + t_vec2 side_dist; + int side; + + side_dist = get_side_dist(ray_dir, pos, delta_dist); + side = dda_main(ray_dir, + (t_vec2_int){(int)pos.x, (int)pos.y}, + &side_dist, + map); + return ((1 - side) * (side_dist.x - delta_dist.x) + - side * (side_dist.y - delta_dist.y)); +} + +// t_side get_side(t_vec2 ray_dir, double perp_dist) +// { +// if (perp_dist > 0) +// { +// if (ray_dir.x > 0) +// return (SIDE_WEST); //d=1 r.x=1 : 10 +// else +// return (SIDE_EAST); // d=1 r.x=0 : 11 +// } +// else +// { +// if (ray_dir.y > 0) +// return (SIDE_NORTH); // d=0 r.y=1 : 00 +// else +// return (SIDE_SOUTH); +// } +// } + +// t_render cast_ray(t_game *game, int x) +// { +// t_vec2 ray_dir; +// t_vec2 pos; +// t_render render; +// double perp_dist; + +// ray_dir = add(game->player->dir, +// mul(game->player->camera, +// (2.0f * x / (double)game->screen->width - 1))); +// pos = game->player->pos; +// perp_dist = dda(ray_dir, pos, game->map); +// render.perp_dist = fabs(perp_dist); +// render.side = get_side(ray_dir, perp_dist); +// if (perp_dist < 0) +// render.wall_x = pos.x + ray_dir.x * render.perp_dist; +// else +// render.wall_x = pos.y + ray_dir.y * render.perp_dist; +// render.wall_x -= floor(render.wall_x); +// return (render); +// } + +// unsigned int get_texture_color(mlx_texture_t *texture, +// t_render render, int tex_x, int tex_y) +// { +// int index; +// double dist; + +// index = (tex_x + tex_y * texture->height) * texture->bytes_per_pixel; +// dist = (render.perp_dist == 0) * 1e30 +// + (render.perp_dist > 1) * render.perp_dist +// + (render.perp_dist <= 1) * 1; +// return (texture->pixels[index] << 24 +// | texture->pixels[index + 1] << 16 +// | texture->pixels[index + 2] << 8 +// | (int)(1.0 / dist * 255)); +// } + +// void draw_line(t_game *game, t_render render, int x) +// { +// int y; +// int color; +// int height; +// int start; +// int tex_start; +// int end; +// int tex_x; +// int tex_y; + +// height = (int)(game->screen->height / render.perp_dist); +// start = -height / 2 + game->screen->height / 2; +// tex_start = start; +// if (start < 0) +// start = 0; +// end = height / 2 + game->screen->height / 2; +// if (end >= game->screen->height) +// end = game->screen->height - 1; +// tex_x = (int)(render.wall_x * (double)game->map->textures[render.side]->width); +// if (render.side == SIDE_NORTH || render.side == SIDE_EAST) +// tex_x = game->map->textures[render.side]->width - tex_x - 1; +// y = start; +// while (y < end) +// { +// tex_y = (int)(((double) game->map->textures[render.side]->height / (double) height) * (y - tex_start)); +// color = get_texture_color(game->map->textures[render.side], render, tex_x, tex_y); +// if (x < 0 || x >= game->screen->width || y < 0 || y >= game->screen->height) +// break ; +// mlx_put_pixel(game->screen->img, x, y, color); +// y++; +// } +// } + +// void draw_floor(t_game *game) +// { +// int y; +// int x; +// int color; +// double row_dist; +// t_vec2 floor_step; +// t_vec2 floor_pos; +// t_vec2_int tex_coords; +// const t_vec2 left_ray = sub(game->player->dir, game->player->camera); +// const t_vec2 right_ray = add(game->player->dir, game->player->camera); + +// y = game->screen->height / 2; +// while (y < game->screen->height) +// { +// row_dist = 0.5 * game->screen->height / (y - game->screen->height / 2.0); +// floor_step = mul(mul(sub(right_ray, left_ray), row_dist), 1.0 / game->screen->width); +// floor_pos = add(game->player->pos, mul(left_ray, row_dist)); +// x = 0; +// while (x < game->screen->width) +// { +// tex_coords = vec2_to_int(mul(get_fraction(floor_pos), 64)); // & 63 is gone heap buffer overflow with asan i dont get it +// color = get_texture_color(game->map->texture_floor, (t_render){row_dist, 0, 0}, tex_coords.x, tex_coords.y); +// mlx_put_pixel(game->screen->img, x, y, color); +// color = get_texture_color(game->map->texture_ceiling, (t_render){row_dist, 0, 0}, tex_coords.x, tex_coords.y); +// mlx_put_pixel(game->screen->img, x, game->screen->height - y - 1, color); +// floor_pos = add(floor_pos, floor_step); +// x++; +// } +// y++; +// } +// } + +// void cast_rays(t_game *game) +// { +// int x; +// t_render render[WIDTH]; + +// x = 0; +// draw_floor(game); +// while (x < game->screen->width) +// { +// render[x] = cast_ray(game, x); +// draw_line(game, render[x], x); +// x++; +// } +// render_sprites(render, game); +// } diff --git a/src/render/render_floor.c b/src/render/render_floor.c new file mode 100644 index 0000000..1abfbcb --- /dev/null +++ b/src/render/render_floor.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* :::::::: */ +/* render_floor.c :+: :+: */ +/* +:+ */ +/* By: whaffman +#+ */ +/* +#+ */ +/* Created: 2025/05/14 13:06:39 by whaffman #+# #+# */ +/* Updated: 2025/05/14 13:49:09 by whaffman ######## odam.nl */ +/* */ +/* ************************************************************************** */ + +#include "cub3d.h" + +void draw_floor(t_game *game) +{ + int y; + int x; + int color; + double row_dist; + t_vec2 floor_step; + t_vec2 floor_pos; + t_vec2_int tex_coords; + const t_vec2 left_ray = sub(game->player->dir, game->player->camera); + const t_vec2 right_ray = add(game->player->dir, game->player->camera); + + y = game->screen->height / 2; + while (y < game->screen->height) + { + row_dist = 0.5 * game->screen->height / (y - game->screen->height / 2.0); + floor_step = mul(mul(sub(right_ray, left_ray), row_dist), 1.0 / game->screen->width); + floor_pos = add(game->player->pos, mul(left_ray, row_dist)); + x = 0; + while (x < game->screen->width) + { + tex_coords = vec2_to_int(mul(get_fraction(floor_pos), 64)); // & 63 is gone heap buffer overflow with asan i dont get it + color = get_texture_color(game->map->texture_floor, (t_render){row_dist, 0, 0}, tex_coords.x, tex_coords.y); + mlx_put_pixel(game->screen->img, x, y, color); + color = get_texture_color(game->map->texture_ceiling, (t_render){row_dist, 0, 0}, tex_coords.x, tex_coords.y); + mlx_put_pixel(game->screen->img, x, game->screen->height - y - 1, color); + floor_pos = add(floor_pos, floor_step); + x++; + } + y++; + } +} \ No newline at end of file diff --git a/src/render/render_sprite.c b/src/render/render_sprite.c index 7f2c559..7bc454d 100644 --- a/src/render/render_sprite.c +++ b/src/render/render_sprite.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/05/08 12:23:17 by qmennen #+# #+# */ -/* Updated: 2025/05/12 12:46:26 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 16:10:05 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -117,7 +117,7 @@ void draw_sprite(t_game *game, t_sprite *sprite, t_render *render) int alpha; unsigned int color; - if (isnan(sprite->cam_frac) || sprite->dist <= 0) + if (isnan(sprite->cam_frac) || sprite->dist <= 0.5) return ; get_start_end(game, sprite, &start, &end); invrange.y = 1.0 / (end.y - start.y); diff --git a/src/render/render_walls.c b/src/render/render_walls.c new file mode 100644 index 0000000..ab150d4 --- /dev/null +++ b/src/render/render_walls.c @@ -0,0 +1,119 @@ +/* ************************************************************************** */ +/* */ +/* :::::::: */ +/* render_walls.c :+: :+: */ +/* +:+ */ +/* By: whaffman +#+ */ +/* +#+ */ +/* Created: 2025/05/14 13:05:28 by whaffman #+# #+# */ +/* Updated: 2025/05/14 13:49:13 by whaffman ######## odam.nl */ +/* */ +/* ************************************************************************** */ + +#include "cub3d.h" + +t_side get_side(t_vec2 ray_dir, double perp_dist) +{ + if (perp_dist > 0) + { + if (ray_dir.x > 0) + return (SIDE_WEST); //d=1 r.x=1 : 10 + else + return (SIDE_EAST); // d=1 r.x=0 : 11 + } + else + { + if (ray_dir.y > 0) + return (SIDE_NORTH); // d=0 r.y=1 : 00 + else + return (SIDE_SOUTH); + } +} + +t_render cast_ray(t_game *game, int x) +{ + t_vec2 ray_dir; + t_vec2 pos; + t_render render; + double perp_dist; + + ray_dir = add(game->player->dir, + mul(game->player->camera, + (2.0f * x / (double)game->screen->width - 1))); + pos = game->player->pos; + perp_dist = dda(ray_dir, pos, game->map); + render.perp_dist = fabs(perp_dist); + render.side = get_side(ray_dir, perp_dist); + if (perp_dist < 0) + render.wall_x = pos.x + ray_dir.x * render.perp_dist; + else + render.wall_x = pos.y + ray_dir.y * render.perp_dist; + render.wall_x -= floor(render.wall_x); + return (render); +} + +unsigned int get_texture_color(mlx_texture_t *texture, + t_render render, int tex_x, int tex_y) +{ + int index; + double dist; + + index = (tex_x + tex_y * texture->height) * texture->bytes_per_pixel; + dist = (render.perp_dist == 0) * 1e30 + + (render.perp_dist > 1) * render.perp_dist + + (render.perp_dist <= 1) * 1; + return (texture->pixels[index] << 24 + | texture->pixels[index + 1] << 16 + | texture->pixels[index + 2] << 8 + | (int)(1.0 / dist * 255)); +} + +void draw_line(t_game *game, t_render render, int x) +{ + int y; + int color; + int height; + int start; + int tex_start; + int end; + int tex_x; + int tex_y; + + height = (int)(game->screen->height / render.perp_dist); + start = -height / 2 + game->screen->height / 2; + tex_start = start; + if (start < 0) + start = 0; + end = height / 2 + game->screen->height / 2; + if (end >= game->screen->height) + end = game->screen->height - 1; + tex_x = (int)(render.wall_x * (double)game->map->textures[render.side]->width); + if (render.side == SIDE_NORTH || render.side == SIDE_EAST) + tex_x = game->map->textures[render.side]->width - tex_x - 1; + y = start; + while (y < end) + { + tex_y = (int)(((double) game->map->textures[render.side]->height / (double) height) * (y - tex_start)); + color = get_texture_color(game->map->textures[render.side], render, tex_x, tex_y); + if (x < 0 || x >= game->screen->width || y < 0 || y >= game->screen->height) + break ; + mlx_put_pixel(game->screen->img, x, y, color); + y++; + } +} + +void cast_rays(t_game *game) +{ + int x; + t_render render[WIDTH]; + + x = 0; + draw_floor(game); + while (x < game->screen->width) + { + render[x] = cast_ray(game, x); + draw_line(game, render[x], x); + x++; + } + render_sprites(render, game); +} \ No newline at end of file diff --git a/src/texture/texutre_load.c b/src/texture/texutre_load.c index a922090..bdbcb9a 100644 --- a/src/texture/texutre_load.c +++ b/src/texture/texutre_load.c @@ -6,15 +6,15 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/05/06 15:45:58 by qmennen #+# #+# */ -/* Updated: 2025/05/07 11:49:37 by whaffman ######## odam.nl */ +/* Updated: 2025/05/14 12:48:03 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "texture.h" -void texture_delete(t_game *game) +void texture_delete(t_game *game) { - int i; + int i; i = 0; while (i < 4) @@ -35,16 +35,15 @@ void texture_delete(t_game *game) } } -int texture_load(t_game *game) +int texture_load(t_game *game) { - game->map->textures[SIDE_NORTH] = mlx_load_png(game->map->NO_texture); - game->map->textures[SIDE_EAST] = mlx_load_png(game->map->EA_texture); - game->map->textures[SIDE_SOUTH] = mlx_load_png(game->map->SO_texture); - game->map->textures[SIDE_WEST] = mlx_load_png(game->map->WE_texture); + game->map->textures[SIDE_NORTH] = mlx_load_png(game->map->north_texture); + game->map->textures[SIDE_EAST] = mlx_load_png(game->map->east_texture); + game->map->textures[SIDE_SOUTH] = mlx_load_png(game->map->south_texture); + game->map->textures[SIDE_WEST] = mlx_load_png(game->map->west_texture); game->map->texture_floor = mlx_load_png("./assets/floor.png"); game->map->texture_ceiling = mlx_load_png("./assets/ceiling64x64.png"); - if (!game->map->textures[SIDE_NORTH] || !game->map->textures[SIDE_EAST] - || !game->map->textures[SIDE_SOUTH] || !game->map->textures[SIDE_WEST]) + if (!game->map->textures[SIDE_NORTH] || !game->map->textures[SIDE_EAST] || !game->map->textures[SIDE_SOUTH] || !game->map->textures[SIDE_WEST]) { texture_delete(game); return (FAILURE);