forked from azekillDIABLO/omicron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.h
45 lines (38 loc) · 1 KB
/
map.h
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
#ifndef _map_h_
#define _map_h_
#define EMPTY_ENTRY(entry) ((entry)->value == 0)
#define MAP_FOR_EACH(map, ex, ey, ez, ew) \
for (unsigned int i = 0; i <= map->mask; i++) { \
MapEntry *entry = map->data + i; \
if (EMPTY_ENTRY(entry)) { \
continue; \
} \
int ex = entry->e.x + map->dx; \
int ey = entry->e.y + map->dy; \
int ez = entry->e.z + map->dz; \
int ew = entry->e.w;
#define END_MAP_FOR_EACH }
typedef union {
unsigned int value;
struct {
unsigned char x;
unsigned char y;
unsigned char z;
char w;
} e;
} MapEntry;
typedef struct {
short dx;
short dy;
short dz;
unsigned int mask;
unsigned int size;
MapEntry *data;
} Map;
void map_alloc(Map *map, int dx, int dy, int dz, int mask);
void map_free(Map *map);
void map_copy(Map *dst, Map *src);
void map_grow(Map *map);
int map_set(Map *map, int x, int y, int z, int w);
int map_get(Map *map, int x, int y, int z);
#endif