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
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include "typedef.h"
typedef struct tile {
char name[64];
char symetry;
small_t connections[SIDES_MAX];
// small_t neighbours[TILES_CAP];
// size_t neigbours_sz;
} tile;
#include "config.h"
void copy(char *tile_set, char *name, int n)
{
char command[512];
sprintf(command, "cp files/tilesets/%s/%s.ppm files/tiles/tile_%d.ppm",
tile_set, name, n);
system(command);
}
void gen()
{
system("mkdir files");
system("mkdir files/tiles");
FILE *fp = fopen("files/tiles/tiles.dat", "wb");
if(!fp) {
fprintf(stderr, "ERROR: Could not open file files/tiles/tiles.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)
{
puts("INFO: Generating Tile Data");
gen();
puts("INFO: Successful");
return 0;
}
|