map rendering - it actually renders, partially
[voxelands-alt.git] / inc / map.h
blobc94700c1b9a39702a5209cee49c06e4261eb6dd0
1 #ifndef _MAP_H_
2 #define _MAP_H_
4 #include "common.h"
5 #include "array.h"
7 #include "content.h"
8 #include "thread.h"
10 #define CHUNKSIZE 16
12 #define CHUNK_TIMESTAMP_UNDEFINED 0xFFFFFFFF
14 #define CHUNK_STATE_CLEAN 0x00 /* unmodified */
15 #define CHUNK_STATE_WRITE_AT_UNLOAD 0x01 /* modified, save when unloaded */
16 #define CHUNK_STATE_WRITE_NEEDED 0x02 /* modified, save ASAP */
17 #define CHUNK_STATE_UNDERGROUND 0x04 /* old is_underground = true */
18 #define CHUNK_STATE_BADLIGHT 0x08 /* old light_expired = true */
19 #define CHUNK_STATE_BADMESH 0x10 /* old mesh_expired = true */
20 #define CHUNK_STATE_UNGENERATED 0x20
21 #define CHUNK_STATE_BADSPAWN 0x40
23 #define MAPOCT_MINUS_XYZ 0
24 #define MAPOCT_MINUS_XY_PLUS_Z 1
25 #define MAPOCT_MINUS_X_PLUS_YZ 2
26 #define MAPOCT_MINUS_XZ_PLUS_Y 3
27 #define MAPOCT_MINUS_YZ_PLUS_X 4
28 #define MAPOCT_MINUS_Z_PLUS_XY 5
29 #define MAPOCT_MINUS_Y_PLUS_XZ 6
30 #define MAPOCT_PLUS_XYZ 7
32 #define MAP_NORTH 0x00
33 #define MAP_SOUTH 0x01
34 #define MAP_EAST 0x02
35 #define MAP_WEST 0x04
36 #define MAP_UP 0x08
37 #define MAP_DOWN 0x10
39 #define MAP_X_MINUS MAP_WEST
40 #define MAP_X_PLUS MAP_EAST
41 #define MAP_Y_MINUS MAP_DOWN
42 #define MAP_Y_PLUS MAP_UP
43 #define MAP_Z_MINUS MAP_NORTH
44 #define MAP_Z_PLUS MAP_SOUTH
46 #define MAP_NORTH_INDEX 0
47 #define MAP_SOUTH_INDEX 1
48 #define MAP_EAST_INDEX 2
49 #define MAP_WEST_INDEX 3
50 #define MAP_UP_INDEX 4
51 #define MAP_DOWN_INDEX 5
53 #define MAP_X_MINUS_INDEX MAP_WEST_INDEX
54 #define MAP_X_PLUS_INDEX MAP_EAST_INDEX
55 #define MAP_Y_MINUS_INDEX MAP_DOWN_INDEX
56 #define MAP_Y_PLUS_INDEX MAP_UP_INDEX
57 #define MAP_Z_MINUS_INDEX MAP_NORTH_INDEX
58 #define MAP_Z_PLUS_INDEX MAP_SOUTH_INDEX
60 #define MAP_TRIGGER_MIN 0x00
61 #define MAP_TRIGGER_MAX 0x02
62 #define MAP_TRIGGER_COUNT 3
64 #define MAP_TRIGGER_LOADED 0x00
65 #define MAP_TRIGGER_UNLOAD 0x01
66 #define MAP_TRIGGER_UPDATE 0x02
68 #ifndef _HAVE_BLOCK_TYPE
69 #define _HAVE_BLOCK_TYPE
70 typedef struct block_s {
71 content_t content;
72 uint8_t param1;
73 uint8_t param2;
74 uint16_t param3;
75 uint32_t envticks;
76 } block_t;
77 #endif
79 #ifndef _HAVE_CHUNK_TYPE
80 #define _HAVE_CHUNK_TYPE
81 struct mapoct_s;
82 typedef struct chunk_s {
83 struct chunk_s *prev;
84 struct chunk_s *next;
85 struct mapoct_s *mapoct;
86 int mapoct_index;
87 pos_t pos;
88 block_t blocks[CHUNKSIZE][CHUNKSIZE][CHUNKSIZE];
89 uint32_t timestamp;
90 float idletime;
91 uint8_t state;
93 struct {
94 array_t data;
95 pos_t spawn;
96 uint32_t last;
97 } mobs;
99 struct {
100 void *obj;
101 mutex_t *mut;
102 array_t sounds;
103 } mesh;
105 array_t metadata;
106 } chunk_t;
107 #endif
109 #ifndef _HAVE_MAPOCT_TYPE
110 #define _HAVE_MAPOCT_TYPE
111 typedef struct mapoct_s {
112 uint32_t size;
113 pos_t pos;
114 struct mapoct_s *parent;
115 int parent_index;
116 struct mapoct_s *children[8];
117 chunk_t *chunks[8];
118 } mapoct_t;
119 #endif
121 /* defined in map.c */
122 int map_init(void);
123 void map_clear(void);
124 void map_exit(void);
125 void map_add_chunk(chunk_t *ch);
126 void map_delete_chunk(chunk_t *ch);
127 chunk_t *map_get_chunk_containing(pos_t *p);
128 block_t *map_get_block(pos_t *p);
129 void map_set_block(pos_t *p, block_t *b);
131 /* defined in map_trigger.c */
132 int map_trigger(uint32_t type, chunk_t *ch, pos_t *p);
133 int map_trigger_add(uint32_t type, void (*fn)(chunk_t*,pos_t*));
134 void map_trigger_clear(void);
136 /* defined in mapgen.c */
137 int mapgen_queue_max_setter(char* v);
138 int mapgen_init(void);
139 void mapgen_exit(void);
140 void mapgen_request(pos_t *p);
142 /* defined in mapgen_noise.c */
143 void mapgen_seed(int s);
145 #ifdef _MAPGEN_LOCAL
146 /* defined in mapgen_basic.c */
147 void mapgen_underground(pos_t *p);
148 void mapgen_space(pos_t *p);
149 void mapgen_air(pos_t *p);
151 /* defined in mapgen_terrain.c */
152 void mapgen_terrain(pos_t *p);
154 /* defined in mapgen_util.c */
155 void mapgen_fill_chunk(chunk_t *ch, content_t id);
156 chunk_t *mapgen_create_chunk(pos_t *p);
158 #endif
160 #endif