intra to gitea
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* free.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/22 18:57:21 by lfirmin #+# #+# */
|
||||
/* Updated: 2025/10/08 16:21:46 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "cub.h"
|
||||
|
||||
void free_char_array(char **array)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!array)
|
||||
return ;
|
||||
i = 0;
|
||||
while (array[i])
|
||||
free(array[i++]);
|
||||
free(array);
|
||||
}
|
||||
|
||||
void free_data(t_data *data)
|
||||
{
|
||||
if (!data)
|
||||
return ;
|
||||
if (data->texture)
|
||||
free(data->texture);
|
||||
free_char_array(data->map);
|
||||
}
|
||||
+75
-5
@@ -20,16 +20,86 @@ int init_data(t_data *data, char *path)
|
||||
return (ft_error(ERROR_INIT_TEX), 1);
|
||||
init_parsing(&data->parsing);
|
||||
init_textures(data->texture);
|
||||
if (!data->texture)
|
||||
{
|
||||
free(data);
|
||||
return (1);
|
||||
}
|
||||
data->map = NULL;
|
||||
data->map_path = path;
|
||||
return (0);
|
||||
}
|
||||
|
||||
void free_data(t_data *data)
|
||||
int world_init_from_parsing(t_world *world, t_data *data)
|
||||
{
|
||||
if (!data)
|
||||
return ;
|
||||
if (data->texture)
|
||||
free(data->texture);
|
||||
int y;
|
||||
|
||||
world->h = 0;
|
||||
while (data->map[world->h])
|
||||
world->h++;
|
||||
world->w = ft_strlen(data->map[0]);
|
||||
world->grid = malloc(sizeof(char *) * (world->h + 1));
|
||||
if (!world->grid)
|
||||
return (1);
|
||||
y = 0;
|
||||
while (y < world->h)
|
||||
{
|
||||
world->grid[y] = ft_strdup(data->map[y]);
|
||||
if (!world->grid[y])
|
||||
return (1);
|
||||
y++;
|
||||
}
|
||||
world->grid[world->h] = NULL;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int init_game_data(t_game *g, t_data *data, char *map_file)
|
||||
{
|
||||
ft_memset(g, 0, sizeof(t_game));
|
||||
if (init_data(data, map_file))
|
||||
return (1);
|
||||
if (parsing(data))
|
||||
{
|
||||
free_textures(data->texture);
|
||||
free_data(data);
|
||||
return (1);
|
||||
}
|
||||
g->colors.floor = rgb_to_int(data->texture->floor[0],
|
||||
data->texture->floor[1], data->texture->floor[2]);
|
||||
g->colors.ceil = rgb_to_int(data->texture->ceiling[0],
|
||||
data->texture->ceiling[1], data->texture->ceiling[2]);
|
||||
if (world_init_from_parsing(&g->world, data) != 0)
|
||||
return (printf("World init failed\n"), 1);
|
||||
free_char_array(data->map);
|
||||
data->map = NULL;
|
||||
return (0);
|
||||
}
|
||||
|
||||
void init_player_direction(t_player_init *p, char direction)
|
||||
{
|
||||
p->dx = 0;
|
||||
p->dy = 0;
|
||||
if (direction == 'S')
|
||||
p->dy = -1;
|
||||
else if (direction == 'N')
|
||||
p->dy = 1;
|
||||
else if (direction == 'E')
|
||||
p->dx = 1;
|
||||
else if (direction == 'W')
|
||||
p->dx = -1;
|
||||
}
|
||||
|
||||
int init_mlx_and_textures(t_game *g, t_data *data)
|
||||
{
|
||||
t_texpaths tex;
|
||||
|
||||
if (init_window(g, 1024, 768, "cub3D") != 0)
|
||||
return (1);
|
||||
tex.no = data->texture->north;
|
||||
tex.so = data->texture->south;
|
||||
tex.we = data->texture->west;
|
||||
tex.ea = data->texture->east;
|
||||
if (textures_load(g, &tex) != 0)
|
||||
g->has_tex = 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
+17
-12
@@ -24,18 +24,6 @@ void ft_error(char *message)
|
||||
write(2, "\n", 1);
|
||||
}
|
||||
|
||||
void free_char_array(char **array)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!array)
|
||||
return ;
|
||||
i = 0;
|
||||
while (array[i])
|
||||
free(array[i++]);
|
||||
free(array);
|
||||
}
|
||||
|
||||
int ft_arrlen(char **arr)
|
||||
{
|
||||
int i;
|
||||
@@ -68,3 +56,20 @@ int ft_strlen_2d(char **str)
|
||||
++i;
|
||||
return (i);
|
||||
}
|
||||
|
||||
int rgb_to_int(int r, int g, int b)
|
||||
{
|
||||
if (r < 0)
|
||||
r = 0;
|
||||
if (r > 255)
|
||||
r = 255;
|
||||
if (g < 0)
|
||||
g = 0;
|
||||
if (g > 255)
|
||||
g = 255;
|
||||
if (b < 0)
|
||||
b = 0;
|
||||
if (b > 255)
|
||||
b = 255;
|
||||
return ((r << 16) | (g << 8) | b);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user