#include #include #include "ppm.h" extern small_t *(tiles[]); extern size_t TILES; extern size_t TILE_WIDTH; extern size_t TILE_HEIGHT; extern small_t tile_connections[]; void load_tiles() { size_t width, height; for(size_t i = 0; i < TILES; i++) { char file_path[32]; sprintf(file_path, "files/tiles/tile_%ld.ppm", i); tiles[i] = load_from_ppm(file_path, &width, &height); } TILE_WIDTH = width; TILE_HEIGHT = height; } void free_tiles() { for(size_t i = 0; i < TILES; i++) free_ppm(tiles[i]); } void print_tiles() { for(size_t i = 0; i < TILES; i++) { for(size_t y = 0; y < TILE_HEIGHT; y++) { for(size_t x = 0; x < TILE_WIDTH; x++) putchar(tiles[i][y * TILE_WIDTH + x] + '0'); putchar('\n'); } putchar('\n'); } } void load_connections() { char file_path[32] = "files/tiles/tiles.dat"; FILE *fp = fopen(file_path, "rb"); if(!fp) { fprintf(stderr, "Could not open file: %s\n", file_path); exit(EXIT_FAILURE); } fread(tile_connections, sizeof(small_t), TILES, fp); fclose(fp); } #include size_t calc_tiles() { size_t file_count = 0; DIR * dirp; struct dirent * entry; dirp = opendir("files/tiles"); /* There should be error handling after this */ while ((entry = readdir(dirp)) != NULL) { if (entry->d_type == DT_REG) { /* If the entry is a regular file */ file_count++; } } closedir(dirp); return file_count-1; }