#include #include #include #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; }