docs, clean, several things... *

- add docs
- remove unused things
- redo modifications i accidentally erased from spacetime
This commit is contained in:
mcolonna 2024-11-07 01:03:05 +01:00
parent 47a6b6df35
commit 26621c72c6
25 changed files with 199 additions and 140 deletions

View file

@ -6,7 +6,7 @@
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */ /* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/31 17:00:59 by mc #+# #+# */ /* 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" # include "include.h"
# define MAP_WIDTH 24 // cases (TODO test) # define PI 3.1415926535 // it's just pi
# define MAP_HEIGHT 24 // cases (TODO test)
# define MOVE_SPEED 0.05 // cases # define MOVE_SPEED 0.05 // Player oves by N cases by tick
# define PI 3.1415926535 # define ROT_SPEED_DIVIDE_PI 64 // Player turns by pi/N rad by tick
# define ROT_SPEED_DIVIDE_PI 64 // pi/n rad # define HITBOX 0.25 // Hitbox of N cases around player.
# define COLOR_WALL 0xFF0000 // 0xRRGGBB
# define COLOR_CEILING 0x29f8ff // 0xRRGGBB # define COLOR_CEILING 0x29f8ff // TODO get from cub file
# define COLOR_FLOOR 0xFF985C // 0xRRGGBB # define COLOR_FLOOR 0xFF985C // TODO get from cub file
# define SCREEN_WIDTH 640 // px
# define SCREEN_HEIGHT 480 // px # define SCREEN_WIDTH 640 // Width of the window
# define FOV 0.66 // ? TODO unit # define SCREEN_HEIGHT 480 // Height of the window
# define HITBOX 0.25 // cases. should be more than MOVE_SPEED
# define FOV 0.66 // ? TODO no idea
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */ /* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/31 17:06:31 by mc #+# #+# */ /* 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" # include "map.h"
/// @brief mlx connection identifier
extern void *g_mlx; extern void *g_mlx;
/// @brief Identifier to the opened window
extern void *g_win; extern void *g_win;
extern t_player g_player;
/// @brief Current map
extern t_map g_map; extern t_map g_map;
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */ /* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/17 14:43:09 by mcolonna #+# #+# */ /* 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" # include "include.h"
/// @brief Modified by the input of the user. A value becomes true /// @brief For g_input_actions
/// when the user presses the corresponding key.
typedef struct s_input_actions typedef struct s_input_actions
{ {
bool left; bool left;
@ -26,10 +25,23 @@ typedef struct s_input_actions
bool quit; bool quit;
} t_input_actions; } 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; extern t_input_actions g_input_actions;
int keypress(int keycode); /// @brief To call when a specific key is newly pressed.
int keyrelease(int keycode); ///
/// @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); void input_init(void);
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */ /* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,16 +32,19 @@ typedef struct s_object
/// @brief Function called when creating the object. /// @brief Function called when creating the object.
/// ///
/// @param data Address of the s_object.data pointer. /// @param data Address of the s_object.data pointer.
/// @param pos Start position of the object.
void (*init)(void **data, t_point_int pos); void (*init)(void **data, t_point_int pos);
/// @brief Function called when destroying the object (to avoid leaks). /// @brief Function called when destroying the object (to avoid leaks).
/// ///
/// @param data Address of the s_object.data pointer. /// @param data Address of the s_object.data pointer.
/// @param pos Start position of the object.
void (*destroy)(void **data, t_point_int pos); void (*destroy)(void **data, t_point_int pos);
/// @brief Function called each tick. /// @brief Function called each tick.
/// ///
/// @param data Address of the s_object.data pointer. /// @param data Address of the s_object.data pointer.
/// @param pos Start position of the object.
void (*tick)(void **data, t_point_int pos); void (*tick)(void **data, t_point_int pos);
/// @brief Pointer the object can use to save data. /// @brief Pointer the object can use to save data.
@ -83,6 +86,21 @@ typedef struct s_player
double rot; double rot;
} t_player; } 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. /// @brief Represents a map.
typedef struct s_map typedef struct s_map
{ {
@ -92,17 +110,11 @@ typedef struct s_map
/// @brief Color of the ceiling. /// @brief Color of the ceiling.
t_color color_ceiling; t_color color_ceiling;
/// @brief Path to the image file for the wall face north. /// @brief File path for each texture. Index is t_direction.
const char *texture_north; const char *texture_srcs[4];
/// @brief Path to the image file for the wall face south. /// @brief All textures. Index is t_direction.
const char *texture_south; t_texture textures[4];
/// @brief Path to the image file for the wall face west.
const char *texture_west;
/// @brief Path to the image file for the wall face east.
const char *texture_east;
/// @brief Width of the map. /// @brief Width of the map.
unsigned int width; unsigned int width;

View file

@ -6,7 +6,7 @@
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */ /* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/31 16:59:27 by mc #+# #+# */ /* 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" # include "include.h"
/// @brief Move the player according to the user input.
void move(void); void move(void);
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */ /* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/15 17:31:35 by mcolonna #+# #+# */ /* 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" # 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); 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); 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); 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); void init_player_e(void **data, t_point_int pos);
#endif #endif

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* render.h :+: :+: :+: */ /* render.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */ /* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/31 17:13:20 by mc #+# #+# */ /* 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 "utils.h"
# include "temp.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 #endif

View file

@ -6,7 +6,7 @@
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */ /* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/15 16:56:47 by mcolonna #+# #+# */ /* 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; typedef uint32_t u_int32_t;
/// @brief Represents a point of double type.
typedef struct s_point_double typedef struct s_point_double
{ {
double x; double x;
double y; double y;
} t_point_double; } t_point_double;
/// @brief Represents a point of int type.
typedef struct s_point_int typedef struct s_point_int
{ {
int x; int x;
@ -60,6 +62,12 @@ void timedloop(void (*f)(void));
/// @return Address to the data, or NULL if error. /// @return Address to the data, or NULL if error.
u_int32_t *get_data_addr(void *img_ptr); 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); void vector_from_rotation(t_point_double *vec, double angle, double norm);
/// @brief Size of buffer used in read_all_text(). /// @brief Size of buffer used in read_all_text().

View file

@ -6,7 +6,7 @@
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */ /* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ /* 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_mlx = NULL;
void *g_win = NULL; void *g_win = NULL;
t_map g_map; t_map g_map;
t_player g_player;

View file

@ -6,7 +6,7 @@
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */ /* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/17 14:43:36 by mcolonna #+# #+# */ /* 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; g_input_actions.quit = value;
} }
int keypress(int keycode) int hook_keypress(int keycode)
{ {
set_action(keycode, true); set_action(keycode, true);
return (0); return (0);
} }
int keyrelease(int keycode) int hook_keyrelease(int keycode)
{ {
set_action(keycode, false); set_action(keycode, false);
return (0); return (0);
@ -42,9 +42,5 @@ int keyrelease(int keycode)
void input_init(void) void input_init(void)
{ {
g_input_actions.down = false; ft_memset(&g_input_actions, 0, sizeof(g_input_actions));
g_input_actions.up = false;
g_input_actions.left = false;
g_input_actions.right = false;
g_input_actions.quit = false;
} }

View file

@ -6,7 +6,7 @@
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */ /* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/31 16:57:40 by mc #+# #+# */ /* 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 "const.h"
# include "global.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) static void draw_screen(void)
{ {
void *img_ptr; void *img_ptr;
u_int32_t *img_data; u_int32_t *img_data;
t_tex tex;
load_textures(&tex);
img_ptr = mlx_new_image(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT); img_ptr = mlx_new_image(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT);
img_data = get_data_addr(img_ptr); img_data = get_data_addr(img_ptr);
if (!img_data) if (!img_data)
exit(1); exit(1);
render(img_data, &tex); render(img_data);
mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0);
mlx_destroy_image(g_mlx, img_ptr); 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])) if (!map_from_file(&g_map, argv[1]))
return (1); return (1);
g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d"); g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d");
mlx_hook(g_win, KeyPress, KeyPressMask, keypress, NULL); mlx_hook(g_win, KeyPress, KeyPressMask, hook_keypress, NULL);
mlx_hook(g_win, KeyRelease, KeyReleaseMask, keyrelease, NULL); mlx_hook(g_win, KeyRelease, KeyReleaseMask, hook_keyrelease, NULL);
mlx_loop_hook(g_mlx, loop_hook, NULL); mlx_loop_hook(g_mlx, loop_hook, NULL);
draw_screen(); draw_screen();
mlx_loop(g_mlx); mlx_loop(g_mlx);

View file

@ -6,7 +6,7 @@
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */ /* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/01 17:12:58 by mcolonna #+# #+# */ /* 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); close(fd);
return (false); 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) void map_destroy(t_map *map)
{ {
free((void *)map->texture_east); t_direction d;
free((void *)map->texture_west);
free((void *)map->texture_north); d = 0;
free((void *)map->texture_south); while (d < 4)
{
free((void *)map->textures[d].image);
free((void *)map->texture_srcs[d]);
}
free(map->cases); free(map->cases);
} }
@ -109,6 +115,7 @@ static bool check_map2(const t_map *map, unsigned int x, unsigned int y)
} }
// TODO check player // TODO check player
bool check_map(const t_map *map) bool check_map(const t_map *map)
{ {
unsigned int x; unsigned int x;

View file

@ -6,7 +6,7 @@
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */ /* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/03 15:05:13 by mc #+# #+# */ /* 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. /// @param map Map to use.
void map_init_objects(t_map *map); void map_init_objects(t_map *map);
bool load_textures(t_map *map);
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */ /* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/03 15:02:09 by mc #+# #+# */ /* 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) 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_ceiling = 0xFF000000;
dest->color_floor = 0xFF000000; dest->color_floor = 0xFF000000;
dest->texture_east = NULL;
dest->texture_west = NULL;
dest->texture_north = NULL;
dest->texture_south = NULL;
*err = false; *err = false;
*rdf = false; *rdf = false;
} }
bool read_map(t_map *dest, t_stream *stream) bool read_map(t_map *dest, t_stream *s)
{ {
bool err; bool err;
bool rdf; bool rdf;
int old_stream_i; int old_stream_i;
read_map2(dest, &err, &rdf); read_map2(dest, &err, &rdf);
while (!rdf && !err && stream->str[stream->i]) while (!rdf && !err && s->str[s->i])
{ {
old_stream_i = stream->i; old_stream_i = s->i;
if ((read_expected_string("\n", stream, &err), err) if ((read_expected_string("\n", s, &err), err)
&& !read_string_parameter("NO", &dest->texture_north, stream, &rdf) && !read_string_parameter("NO", &dest->texture_srcs[NORTH], s, &rdf)
&& !read_string_parameter("SO", &dest->texture_south, stream, &rdf) && !read_string_parameter("SO", &dest->texture_srcs[SOUTH], s, &rdf)
&& !read_string_parameter("WE", &dest->texture_west, stream, &rdf) && !read_string_parameter("WE", &dest->texture_srcs[WEST], s, &rdf)
&& !read_string_parameter("EA", &dest->texture_east, stream, &rdf) && !read_string_parameter("EA", &dest->texture_srcs[EAST], s, &rdf)
&& !read_color_parameter("F", &dest->color_floor, stream, &rdf) && !read_color_parameter("F", &dest->color_floor, s, &rdf)
&& !read_color_parameter("C", &dest->color_ceiling, stream, &rdf)) && !read_color_parameter("C", &dest->color_ceiling, s, &rdf))
{ {
stream->i = old_stream_i; s->i = old_stream_i;
err = !read_map_description(dest, stream); err = !read_map_description(dest, s);
break ; break ;
} }
err = false; err = false;

View file

@ -6,12 +6,14 @@
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */ /* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/04 15:12:08 by mcolonna #+# #+# */ /* 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 "map_utils.h"
#include "global.h"
/// @brief Read the map description to get the dimensions. /// @brief Read the map description to get the dimensions.
/// The map must be at least 1x1. /// The map must be at least 1x1.
/// ///
@ -100,3 +102,17 @@ bool read_map_description(t_map *map, t_stream *stream)
} }
return (true); 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);
}

View file

@ -6,16 +6,13 @@
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */ /* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 14:55:05 by greg #+# #+# */ /* 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.h"
#include "render_utils.h" #include "render_utils.h"
#include "const.h"
#include "global.h"
static void calculate_perpwalldist3(int x, static void calculate_perpwalldist3(int x,
t_point_double *deltadist, t_point_double *deltadist,
t_ray *ray) 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; int x;
t_ray ray; 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; x = 0;
while (x < SCREEN_WIDTH) while (x < SCREEN_WIDTH)
{ {
draw_vertical_line(x, img_data, &ray, tex); draw_vertical_line(x, img_data, &ray, &tex);
x++; x++;
} }
return (0); return (0);

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* render_utils.c :+: :+: :+: */ /* render_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */ /* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/24 14:26:22 by grobledo #+# #+# */ /* 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 color;
u_int32_t *texture_data; 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_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) 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) 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], texture_data = (u_int32_t *)mlx_get_data_addr(tex->textures[tex->tex_dir],
&tex->bpp, &tex->size_line, &tex->endian); &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; img_data[y * SCREEN_WIDTH + x] = color;
} }

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* render_utils.h :+: :+: :+: */ /* render_utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */ /* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/24 14:26:22 by grobledo #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */ /* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/15 12:38:40 by mcolonna #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -1,9 +1,9 @@
F 255,127,0 F 255,127,0
EA eastimage
NO theimageforthenorthwall
C 0,2,67 C 0,2,67
SO SOUTH!!!!!!1 EA textures/east.xpm
WE weeeee NO textures/north.xpm
SO textures/south.xpm
WE textures/west.xpm
111111111 111111111
100000001 100000001
100010001 100010001

View file

@ -1,10 +1,10 @@
F 255,127,0 F 255,127,0
EA eastimage
NO theimageforthenorthwall
C 0,2,67 C 0,2,67
SO SOUTH!!!!!!1 EA textures/east.xpm
WE weeeee NO textures/north.xpm
111111111 SO textures/south.xpm
WE textures/west.xpm
111
111110111 111110111
10000N001 10000N001
111110111 111110111

View file

@ -1,9 +1,9 @@
F 255,127,0 F 255,127,0
EA eastimage
NO theimageforthenorthwall
C 0,2,67 C 0,2,67
SO SOUTH!!!!!!1 EA textures/east.xpm
WE weeeee NO textures/north.xpm
SO textures/south.xpm
WE textures/west.xpm
111 111
1N1 1N1
111 111

View file

@ -1,15 +1,19 @@
F 255, 127 ,0 F 255, 127 ,0
EA eastimage
NO theimageforthenorthwall
C 0, 2 , 67 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

View file

@ -1,15 +1,13 @@
F 255,127,0 F 255,127,0
EA eastimage EA textures/east.xpm
NO theimageforthenorthwall NO textures/north.xpm
C 0,2,67 C 0,2,67
SO SOUTH!!!!!!1 SO textures/south.xpm
WE weeeee
WE textures/west.xpm

View file

@ -1,9 +1,9 @@
F 255,127,0 F 255,127,0
EA eastimage
NO theimageforthenorthwall
C 0,2,67 C 0,2,67
SO SOUTH!!!!!!1 EA textures/east.xpm
WE weeeee NO textures/north.xpm
SO textures/south.xpm
WE textures/west.xpm
111 111
111 101 111 101