Fix: removed the t_img texture and left the t_texture instead.
This commit is contained in:
parent
eda859f200
commit
7f1091b721
9 changed files with 35 additions and 40 deletions
0
.c
0
.c
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/30 16:30:26 by rparodi #+# #+# */
|
/* Created: 2024/10/30 16:30:26 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/12/16 15:35:29 by bgoulard ### ########.fr */
|
/* Updated: 2024/12/17 17:18:05 by bgoulard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -30,6 +30,7 @@ t_texture *get_texture(int side, t_ipoint step, t_info *data);
|
||||||
void draw_(int *ti, double *td, t_ipoint step, t_info *data);
|
void draw_(int *ti, double *td, t_ipoint step, t_info *data);
|
||||||
|
|
||||||
// utils
|
// utils
|
||||||
|
void sv_errno(t_info *inf, int err_code);
|
||||||
void draw_floor(t_info *data);
|
void draw_floor(t_info *data);
|
||||||
int render_frame(t_info *data);
|
int render_frame(t_info *data);
|
||||||
void my_mlx_pixel_put(t_info *data, int x, int y, int color);
|
void my_mlx_pixel_put(t_info *data, int x, int y, int color);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/11/28 13:53:54 by bgoulard #+# #+# */
|
/* Created: 2024/11/28 13:53:54 by bgoulard #+# #+# */
|
||||||
/* Updated: 2024/12/17 16:52:53 by bgoulard ### ########.fr */
|
/* Updated: 2024/12/17 17:21:45 by bgoulard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -93,8 +93,7 @@ typedef struct s_map
|
||||||
t_ipoint size;
|
t_ipoint size;
|
||||||
t_tile *map;
|
t_tile *map;
|
||||||
char **fraw;
|
char **fraw;
|
||||||
t_img *texture[4];
|
t_texture texture[4];
|
||||||
t_texture texture_[4];
|
|
||||||
t_color bg_colors[2];
|
t_color bg_colors[2];
|
||||||
} t_map;
|
} t_map;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/11/11 19:53:42 by rparodi #+# #+# */
|
/* Created: 2024/11/11 19:53:42 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/12/16 15:36:35 by bgoulard ### ########.fr */
|
/* Updated: 2024/12/17 17:18:34 by bgoulard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
#include "ft_math.h"
|
#include "ft_math.h"
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -51,14 +50,9 @@ t_win_list *c3_init_mlx_window(t_info *info)
|
||||||
|
|
||||||
int init_mlx_env(t_info *info)
|
int init_mlx_env(t_info *info)
|
||||||
{
|
{
|
||||||
info->mlx_ptr = mlx_init();
|
|
||||||
if (!info->mlx_ptr)
|
|
||||||
return (info->last_error = ERROR_MLX, info->errno_state = errno, \
|
|
||||||
ERROR_MLX);
|
|
||||||
info->win_ptr = c3_init_mlx_window(info);
|
info->win_ptr = c3_init_mlx_window(info);
|
||||||
if (!info->win_ptr)
|
if (!info->win_ptr)
|
||||||
return (info->last_error = ERROR_MLX, info->errno_state = errno, \
|
return (sv_errno(info, ERROR_MLX), ERROR_MLX);
|
||||||
ERROR_MLX);
|
|
||||||
mlx_hook(info->win_ptr, KeyPress, KeyPressMask, keypress_feature, info);
|
mlx_hook(info->win_ptr, KeyPress, KeyPressMask, keypress_feature, info);
|
||||||
mlx_hook(info->win_ptr, KeyRelease, KeyReleaseMask, keyrelease_feature, \
|
mlx_hook(info->win_ptr, KeyRelease, KeyReleaseMask, keyrelease_feature, \
|
||||||
info);
|
info);
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,11 @@
|
||||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/12/01 17:46:52 by bgoulard #+# #+# */
|
/* Created: 2024/12/01 17:46:52 by bgoulard #+# #+# */
|
||||||
/* Updated: 2024/12/17 16:58:30 by bgoulard ### ########.fr */
|
/* Updated: 2024/12/17 17:22:21 by bgoulard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "cub3d.h"
|
||||||
#include "cub3d_struct.h"
|
#include "cub3d_struct.h"
|
||||||
#include "cub3d_parsing.h"
|
#include "cub3d_parsing.h"
|
||||||
|
|
||||||
|
|
@ -19,12 +20,6 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static void sv_errno(t_info *inf, int err_code)
|
|
||||||
{
|
|
||||||
inf->errno_state = errno;
|
|
||||||
inf->last_error = err_code;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool load_texture(t_info *info, const char *str, const char **id_str)
|
bool load_texture(t_info *info, const char *str, const char **id_str)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
@ -35,7 +30,7 @@ bool load_texture(t_info *info, const char *str, const char **id_str)
|
||||||
{
|
{
|
||||||
if (ft_strstart_with(str, id_str[i]))
|
if (ft_strstart_with(str, id_str[i]))
|
||||||
{
|
{
|
||||||
if (info->map.texture_[i].img != NULL)
|
if (info->map.texture[i].img != NULL)
|
||||||
return (sv_errno(info, ERROR_PARSE_ALREADY_SET), false);
|
return (sv_errno(info, ERROR_PARSE_ALREADY_SET), false);
|
||||||
texture.path = ft_strtrim(str + ft_strlen(id_str[i]), " \t");
|
texture.path = ft_strtrim(str + ft_strlen(id_str[i]), " \t");
|
||||||
if (texture.path == NULL)
|
if (texture.path == NULL)
|
||||||
|
|
@ -46,7 +41,7 @@ bool load_texture(t_info *info, const char *str, const char **id_str)
|
||||||
&texture.width, &texture.height);
|
&texture.width, &texture.height);
|
||||||
if (texture.img == NULL)
|
if (texture.img == NULL)
|
||||||
return (sv_errno(info, ERROR_MLX), false);
|
return (sv_errno(info, ERROR_MLX), false);
|
||||||
return (info->map.texture_[i] = texture, true);
|
return (info->map.texture[i] = texture, true);
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
@ -70,9 +65,9 @@ void *load_textures(void *data)
|
||||||
}
|
}
|
||||||
i = 0;
|
i = 0;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
while (i < sizeof(info->map.texture_) / sizeof(info->map.texture_[0]))
|
while (i < sizeof(info->map.texture) / sizeof(info->map.texture[0]))
|
||||||
{
|
{
|
||||||
if (info->map.texture_[i].img == NULL || info->map.texture[i] == NULL)
|
if (info->map.texture[i].img == NULL)
|
||||||
return (sv_errno(info, ERROR_TEXTURE_MISSING), NULL);
|
return (sv_errno(info, ERROR_TEXTURE_MISSING), NULL);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/12/01 17:43:17 by bgoulard #+# #+# */
|
/* Created: 2024/12/01 17:43:17 by bgoulard #+# #+# */
|
||||||
/* Updated: 2024/12/16 09:39:50 by bgoulard ### ########.fr */
|
/* Updated: 2024/12/17 17:17:53 by bgoulard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,6 +17,12 @@
|
||||||
#include <X11/X.h>
|
#include <X11/X.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void sv_errno(t_info *inf, int err_code)
|
||||||
|
{
|
||||||
|
inf->errno_state = errno;
|
||||||
|
inf->last_error = err_code;
|
||||||
|
}
|
||||||
|
|
||||||
t_tile *c3_get_cell(t_tile *map, t_ipoint dimensions, t_ipoint pos)
|
t_tile *c3_get_cell(t_tile *map, t_ipoint dimensions, t_ipoint pos)
|
||||||
{
|
{
|
||||||
if (pos.x < 0 || pos.y < 0 || pos.x >= dimensions.x
|
if (pos.x < 0 || pos.y < 0 || pos.x >= dimensions.x
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/12/16 14:46:04 by bgoulard #+# #+# */
|
/* Created: 2024/12/16 14:46:04 by bgoulard #+# #+# */
|
||||||
/* Updated: 2024/12/16 14:46:14 by bgoulard ### ########.fr */
|
/* Updated: 2024/12/17 17:23:54 by bgoulard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,11 +15,11 @@
|
||||||
t_texture *get_texture(int side, t_ipoint step, t_info *data)
|
t_texture *get_texture(int side, t_ipoint step, t_info *data)
|
||||||
{
|
{
|
||||||
if (side == 0 && step.x > 0)
|
if (side == 0 && step.x > 0)
|
||||||
return (&data->map.texture_[0]);
|
return (&data->map.texture[0]);
|
||||||
else if (side == 0 && step.x < 0)
|
else if (side == 0 && step.x < 0)
|
||||||
return (&data->map.texture_[1]);
|
return (&data->map.texture[1]);
|
||||||
else if (side == 1 && step.y > 0)
|
else if (side == 1 && step.y > 0)
|
||||||
return (&data->map.texture_[2]);
|
return (&data->map.texture[2]);
|
||||||
else
|
else
|
||||||
return (&data->map.texture_[3]);
|
return (&data->map.texture[3]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/11/09 01:11:01 by bgoulard #+# #+# */
|
/* Created: 2024/11/09 01:11:01 by bgoulard #+# #+# */
|
||||||
/* Updated: 2024/12/01 17:24:54 by bgoulard ### ########.fr */
|
/* Updated: 2024/12/17 17:23:25 by bgoulard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -39,17 +39,14 @@ static void cleanup_mlx(t_info *info)
|
||||||
return ;
|
return ;
|
||||||
if (info->win_ptr)
|
if (info->win_ptr)
|
||||||
mlx_destroy_window(info->mlx_ptr, info->win_ptr);
|
mlx_destroy_window(info->mlx_ptr, info->win_ptr);
|
||||||
while (i < sizeof(info->map.texture_) / sizeof(info->map.texture_[0]))
|
while (i < sizeof(info->map.texture) / sizeof(info->map.texture[0]))
|
||||||
{
|
{
|
||||||
if (info->map.texture_[i].img)
|
if (info->map.texture[i].img)
|
||||||
mlx_destroy_image(info->mlx_ptr, info->map.texture_[i].img);
|
mlx_destroy_image(info->mlx_ptr, info->map.texture[i].img);
|
||||||
if (info->map.texture_[i++].path)
|
if (info->map.texture[i++].path)
|
||||||
ft_free((void **)&info->map.texture_[i - 1].path);
|
ft_free((void **)&info->map.texture[i - 1].path);
|
||||||
}
|
}
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < sizeof(info->map.texture) / sizeof(info->map.texture[0]))
|
|
||||||
if (info->map.texture[i++])
|
|
||||||
mlx_destroy_image(info->mlx_ptr, info->map.texture[i - 1]);
|
|
||||||
if (info->camera.screen_buff)
|
if (info->camera.screen_buff)
|
||||||
mlx_destroy_image(info->mlx_ptr, info->camera.screen_buff);
|
mlx_destroy_image(info->mlx_ptr, info->camera.screen_buff);
|
||||||
mlx_destroy_display(info->mlx_ptr);
|
mlx_destroy_display(info->mlx_ptr);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/30 16:30:03 by rparodi #+# #+# */
|
/* Created: 2024/10/30 16:30:03 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/12/17 16:55:25 by bgoulard ### ########.fr */
|
/* Updated: 2024/12/17 17:17:12 by bgoulard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -37,9 +37,12 @@ void check_err(t_info *info)
|
||||||
|
|
||||||
void run_cub3d(t_info *info)
|
void run_cub3d(t_info *info)
|
||||||
{
|
{
|
||||||
|
info->mlx_ptr = mlx_init();
|
||||||
|
if (!info->mlx_ptr)
|
||||||
|
return (sv_errno(info, ERROR_MLX), (void)0);
|
||||||
|
parse_map(info);
|
||||||
if (init_mlx_env(info) != NO_ERROR)
|
if (init_mlx_env(info) != NO_ERROR)
|
||||||
return (c3_perror(info));
|
return (c3_perror(info));
|
||||||
parse_map(info);
|
|
||||||
if (info->cli_ctx.debug)
|
if (info->cli_ctx.debug)
|
||||||
ft_putstr_fd("no debug mod on production run", STDERR_FILENO);
|
ft_putstr_fd("no debug mod on production run", STDERR_FILENO);
|
||||||
if (info->last_error != NO_ERROR)
|
if (info->last_error != NO_ERROR)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue