mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
refactor: put all populate_map related code in that file
This commit is contained in:
parent
b564311851
commit
3e28da1fcf
6 changed files with 66 additions and 48 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 14:39:41 by kcolin #+# #+# */
|
/* Created: 2025/07/17 14:39:41 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/07/17 15:55:09 by kcolin ### ########.fr */
|
/* Updated: 2025/07/21 15:24:14 by kcolin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
# include "mapdata.h"
|
# include "mapdata.h"
|
||||||
|
|
||||||
bool check_filename(t_mapdata *map, char *file);
|
bool check_filename(t_mapdata *map, char *file);
|
||||||
void populate_maps(t_mapdata *map, int fd);
|
|
||||||
bool check_walls(t_mapdata *map);
|
bool check_walls(t_mapdata *map);
|
||||||
bool check_bare_minimum(t_mapdata *map);
|
bool check_bare_minimum(t_mapdata *map);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,16 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */
|
/* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */
|
||||||
/* Updated: 2025/07/17 15:53:51 by kcolin ### ########.fr */
|
/* Updated: 2025/07/21 15:25:16 by kcolin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../../libft/includes/libft.h"
|
#include "../../libft/includes/libft.h"
|
||||||
#include "../utils/colors.h"
|
#include "../utils/colors.h"
|
||||||
|
#include "populate_map.h"
|
||||||
#include "checkers.h"
|
#include "checkers.h"
|
||||||
#include "setters.h"
|
#include "setters.h"
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
void print_mapdata(const t_mapdata *data)
|
void print_mapdata(const t_mapdata *data)
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,51 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 14:44:02 by kcolin #+# #+# */
|
/* Created: 2025/07/17 14:44:02 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/07/17 15:53:38 by kcolin ### ########.fr */
|
/* Updated: 2025/07/21 15:23:47 by kcolin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../../libft/includes/libft.h"
|
#include "../../libft/includes/libft.h"
|
||||||
#include "setters.h"
|
#include "../utils/frees.h"
|
||||||
|
|
||||||
|
int copy_old_map(t_mapdata *map, char **newmap, char **newmapflood, int length)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!map->map)
|
||||||
|
return (0);
|
||||||
|
while (i < length)
|
||||||
|
{
|
||||||
|
newmap[i] = ft_strdup(map->map[i]);
|
||||||
|
newmapflood[i] = ft_strdup(map->mapflood[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_map_line(const char *line, t_mapdata *map)
|
||||||
|
{
|
||||||
|
static int length = 0;
|
||||||
|
char **newmap;
|
||||||
|
char **newmapflood;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
newmap = ft_calloc(sizeof(char *), (length + 2));
|
||||||
|
if (!newmap)
|
||||||
|
return ;
|
||||||
|
newmapflood = ft_calloc(sizeof(char *), (length + 2));
|
||||||
|
if (!newmapflood)
|
||||||
|
return ;
|
||||||
|
i = copy_old_map(map, newmap, newmapflood, length);
|
||||||
|
newmap[i] = ft_strdup(line);
|
||||||
|
newmapflood[i] = ft_strdup(line);
|
||||||
|
free_tab_length(map->map, length);
|
||||||
|
free_tab_length(map->mapflood, length);
|
||||||
|
map->mapheight = ++length;
|
||||||
|
map->map = newmap;
|
||||||
|
map->mapflood = newmapflood;
|
||||||
|
}
|
||||||
|
|
||||||
void populate_maps(t_mapdata *map, int fd)
|
void populate_maps(t_mapdata *map, int fd)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
20
src/map/populate_map.h
Normal file
20
src/map/populate_map.h
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* populate_map.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/07/21 15:24:31 by kcolin #+# #+# */
|
||||||
|
/* Updated: 2025/07/21 15:25:02 by kcolin ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef POPULATE_MAP_H
|
||||||
|
# define POPULATE_MAP_H
|
||||||
|
|
||||||
|
# include "mapdata.h"
|
||||||
|
|
||||||
|
void populate_maps(t_mapdata *map, int fd);
|
||||||
|
|
||||||
|
#endif // POPULATE_MAP_H
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/06/21 19:35:43 by tchampio #+# #+# */
|
/* Created: 2025/06/21 19:35:43 by tchampio #+# #+# */
|
||||||
/* Updated: 2025/07/21 12:48:50 by kcolin ### ########.fr */
|
/* Updated: 2025/07/21 15:22:41 by kcolin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -90,42 +90,3 @@ bool add_textures(int fd, t_mapdata *map)
|
||||||
free(line);
|
free(line);
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int copy_old_map(t_mapdata *map, char **newmap, char **newmapflood, int length)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
if (!map->map)
|
|
||||||
return (0);
|
|
||||||
while (i < length)
|
|
||||||
{
|
|
||||||
newmap[i] = ft_strdup(map->map[i]);
|
|
||||||
newmapflood[i] = ft_strdup(map->mapflood[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void add_map_line(const char *line, t_mapdata *map)
|
|
||||||
{
|
|
||||||
static int length = 0;
|
|
||||||
char **newmap;
|
|
||||||
char **newmapflood;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
newmap = ft_calloc(sizeof(char *), (length + 2));
|
|
||||||
if (!newmap)
|
|
||||||
return ;
|
|
||||||
newmapflood = ft_calloc(sizeof(char *), (length + 2));
|
|
||||||
if (!newmapflood)
|
|
||||||
return ;
|
|
||||||
i = copy_old_map(map, newmap, newmapflood, length);
|
|
||||||
newmap[i] = ft_strdup(line);
|
|
||||||
newmapflood[i] = ft_strdup(line);
|
|
||||||
free_tab_length(map->map, length);
|
|
||||||
free_tab_length(map->mapflood, length);
|
|
||||||
map->mapheight = ++length;
|
|
||||||
map->map = newmap;
|
|
||||||
map->mapflood = newmapflood;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 14:40:32 by kcolin #+# #+# */
|
/* Created: 2025/07/17 14:40:32 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/07/17 15:54:11 by kcolin ### ########.fr */
|
/* Updated: 2025/07/21 15:22:57 by kcolin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,6 +17,5 @@
|
||||||
# include "mapdata.h"
|
# include "mapdata.h"
|
||||||
|
|
||||||
bool add_textures(int fd, t_mapdata *map);
|
bool add_textures(int fd, t_mapdata *map);
|
||||||
void add_map_line(const char *line, t_mapdata *map);
|
|
||||||
|
|
||||||
#endif // SETTERS_H
|
#endif // SETTERS_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue