-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
69 lines (62 loc) · 1.76 KB
/
utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmomeni <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/24 22:11:31 by mmomeni #+# #+# */
/* Updated: 2023/07/09 20:15:47 by mmomeni ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
void terminate(char *msg, int status)
{
if (msg)
{
if (status == -1)
perror(msg);
else if (status != 0)
ft_putendl_fd(msg, STDERR_FILENO);
else
ft_putendl_fd(msg, STDOUT_FILENO);
}
exit(status);
}
void free_ctx(t_ctx *ctx)
{
while (ctx->map->height--)
free(ctx->map->points[ctx->map->height]);
free(ctx->map->points);
free(ctx->map);
free(ctx);
}
void loop_and_terminate(t_ctx *ctx, int fd)
{
close(fd);
mlx_loop(ctx->mlx);
mlx_terminate(ctx->mlx);
free_ctx(ctx);
}
t_ctx *map_apply(t_ctx *ctx, void (*fn)(t_point *, t_ctx *))
{
size_t i;
size_t j;
i = 0;
while (ctx->map->points[i])
{
j = 0;
while (!ctx->map->points[i][j].eol)
(*fn)(&ctx->map->points[i][j++], ctx);
i++;
}
return (ctx);
}
t_ctx *apply_factors(t_ctx *ctx)
{
map_apply(ctx, p_base);
map_rotate_y(ctx);
map_apply(ctx, p_isometric);
map_apply(ctx, p_center);
return (ctx);
}