Valid map file

This commit is contained in:
2025-12-05 17:11:31 +01:00
parent 7acb059c20
commit f693cda860
4 changed files with 174 additions and 8 deletions

View File

@@ -6,7 +6,7 @@
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/25 19:47:02 by aortigos #+# #+# */
/* Updated: 2025/12/05 16:30:21 by aortigos ### ########.fr */
/* Updated: 2025/12/05 17:10:22 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
@@ -70,11 +70,21 @@ int check_color_textures(char *line);
int check_count_textures(t_data *m, int count);
// textures_utils.c
int is_valid_texture(char *line);
int count_comma(char *rgb);
int check_pos_cf(char *l);
int line_around_one(char *line);
char *getlastline(char **map);
int is_valid_texture(char *line);
int count_comma(char *rgb);
int check_pos_cf(char *l);
int line_around_one(char *line);
char *getlastline(char **map);
//valid_map.c
int h_map(char **map);
int v_map(char **map);
char *fixline(char *line, int maxlen);
int getsize_line(char **map);
int valid_map(t_data *m);
// frees.c
void ft_delete_texture(t_texture *texture);
void ft_exit(t_mlx *mlx);
#endif

40
src/execution/frees.c Normal file
View File

@@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* frees.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/05 17:07:58 by aortigos #+# #+# */
/* Updated: 2025/12/05 17:10:05 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/cub3d.h"
void ft_delete_texture(t_texture *texture)
{
if (texture->no)
mlx_delete_texture(texture->no);
if (texture->so)
mlx_delete_texture(texture->so);
if (texture->we)
mlx_delete_texture(texture->we);
if (texture->ea)
mlx_delete_texture(texture->ea);
}
void ft_exit(t_mlx *mlx)
{
mlx_delete_image(mlx->mlx_ptr, mlx->img);
mlx_close_window(mlx->mlx_ptr);
freelist(&mlx->dt->t_list);
free_map(mlx->dt);
ft_delete_texture(mlx->tex);
ft_memfree(mlx->tex);
ft_memfree(mlx->ply);
ft_memfree(mlx->ray);
mlx_terminate(mlx->mlx_ptr);
ft_putstr_fd("END GAME\n", 1);
exit(0);
}

14
src/execution/movement.c Normal file
View File

@@ -0,0 +1,14 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* movement.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/05 17:11:09 by aortigos #+# #+# */
/* Updated: 2025/12/05 17:11:19 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/cub3d.h"

View File

@@ -6,8 +6,110 @@
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/05 16:30:33 by aortigos #+# #+# */
/* Updated: 2025/12/05 16:30:42 by aortigos ### ########.fr */
/* Updated: 2025/12/05 16:53:44 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/cub3d.h"
#include "../../includes/cub3d.h"
int h_map(char **map)
{
int i;
int j;
i = 0;
while (map[i])
{
j = 0;
while (map[i][j])
{
if (map[i][j] != '1' && map [i][j] != ' ')
if (map[i][j - 1] == ' ' || map[i][j + 1] == ' ')
return (ft_putstr_fd(ERR_MAP_INV, 2), 0);
j++;
}
i++;
}
return (1);
}
int v_map(char **map)
{
int i;
int j;
i = 0;
while (map[i])
{
j = 0;
while (map[i][j])
{
if (map[i][j] != '1' && map[i][j] != ' ')
if (map[i - 1][j] == ' ' || map[i + 1][j] == ' ')
return (ft_putstr_fd(ERR_MAP_INV, 2), 0);
j++;
}
i++;
}
return (1);
}
char *fixline(char *line, int maxlen)
{
char *new;
int i;
i = 0;
new = ft_calloc(sizeof(char), (maxlen + 1));
if (!new)
return (NULL);
while (line[i])
{
new[i] = line[i];
i++;
}
while (i < maxlen)
{
new[i] = ' ';
i++;
}
return (new);
}
int getsize_line(char **map)
{
int i;
int max;
i = -1;
max = ft_strlen(map[0]);
while (map[++i])
if ((int)ft_strlen(map[i]) > max)
max = ft_strlen(map[i]);
return (max);
}
int valid_map(t_data *m)
{
int i;
int maxlen;
maxlen = getsize_line(m->map2d);
m->sq_map = ft_calloc(sizeof(char *), (ft_arraylen(m->map2d) + 1));
if (!m->sq_map)
return (0);
i = -1;
while (m->map2d[++i])
{
if (maxlen == (int)ft_strlen(m->map2d[i]))
m->sq_map[i] = ft_strdup(m->map2d[i]);
else
m->sq_map[i] = fixline(m->map2d[i], maxlen);
}
m->h_map = ft_arraylen(m->sq_map);
m->w_map = ft_strlen(m->sq_map[0]);
if (!h_map(m->sq_map) || !v_map(m->sq_map))
return (free2d(m->sq_map), free2d(m->map2d), free2d(m->ture2d), 0);
return (1);
}