-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_utils.c
67 lines (60 loc) · 1.59 KB
/
list_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ikourkji <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/15 03:24:29 by ikourkji #+# #+# */
/* Updated: 2019/01/18 14:02:06 by ikourkji ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
static t_int64 embiggen(t_int16 bits)
{
t_int64 ret;
int i;
ret = 0;
i = 3;
while (i > 0)
{
ret |= (bits >> (i * 4)) & 0xF;
ret <<= 16;
i--;
}
ret |= bits & 0xF;
return (ret);
}
t_etromino *enlist(t_int16 bits)
{
t_etromino *piece;
int i;
piece = (t_etromino *)malloc(sizeof(*piece));
piece->bits = embiggen(bits);
piece->x = 0;
piece->y = 0;
i = 0;
piece->width = 0;
while ((0x1111 << i++) & bits)
piece->width++;
i = 0;
piece->height = 0;
while ((0xF << i) & bits)
{
piece->height++;
i += 4;
}
return (piece);
}
void list_del(t_etromino **list, int count)
{
int i;
i = 0;
while (i < count)
{
free(list[i]);
list[i] = NULL;
i++;
}
ft_memdel((void **)&list);
}