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
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "typedef.h"
#define TILESET_NAME (STR(TILESET))
typedef struct tile {
char name[64];
char symetry;
small_t connections[SIDES_MAX];
} tile;
#define STR_AUX(a) #a
#define STR(a) STR_AUX(a)
#define TILESET_PATH(name) STR(../PATH/tilesets/name/tileset.h)
#include "config.h"
#include TILESET_PATH(TILESET)
#define MKDIR_FILES_SLASH_TILES STR(mkdir PATH/tiles)
#define TILES_DOT_DAT STR(PATH/tiles/tiles.dat)
#define COMMAND STR(cp PATH/tilesets/%s/%s.ppm PATH/tiles/tile_%d.ppm)
void copy(char *tile_set, char *name, int n)
{
char command[512];
sprintf(command, COMMAND,
tile_set, name, n);
system(command);
}
void gen()
{
system(MKDIR_FILES_SLASH_TILES);
FILE *fp = fopen(TILES_DOT_DAT, "wb");
if(!fp) {
err("Could not open file: %s", TILES_DOT_DAT);
exit(EXIT_FAILURE);
}
small_t dim = DIMENTIONS;
fwrite(&dim, sizeof(small_t), 1, fp);
size_t tiles_sz = sizeof(tiles_to_load)/sizeof(int);
fwrite(&tiles_sz, sizeof(size_t), 1, fp);
for(size_t n = 0; n < tiles_sz; n++)
{
int t = tiles_to_load[n];
copy(TILESET_NAME, tiles[t].name, n);
fwrite(tiles[t].connections, sizeof(small_t), SIDES, fp);
fwrite(&(tiles[t].symetry), sizeof(char), 1, fp);
}
fclose(fp);
}
int main(void)
{
info("Generating Tile Data");
gen();
info("INFO: Successful");
return 0;
}
|