From 85601f555a3a57db44631706a25e0f933afd8551 Mon Sep 17 00:00:00 2001 From: kartofen Date: Wed, 21 Dec 2022 01:06:18 +0200 Subject: works with different connections --- src/config.h | 87 ++++++++++++++++++++------------------ src/gen_tiles.c | 127 +++++++++++--------------------------------------------- src/main.c | 88 +++++++++++++++++++-------------------- src/ppm.c | 10 ++--- src/tilemap.c | 80 +++++++++++++++++------------------ src/tilemap.h | 4 +- src/tiles.c | 53 +++++++++++++++-------- src/tiles.h | 2 +- src/typedef.h | 19 +++++++-- 9 files changed, 210 insertions(+), 260 deletions(-) (limited to 'src') diff --git a/src/config.h b/src/config.h index 19726d5..bd6fc31 100644 --- a/src/config.h +++ b/src/config.h @@ -1,46 +1,53 @@ -// comment this if you dont want to generate the tiles, but -// want to use the tileset defined in the TILESET_NAME directive -// #define GENERATE_PPM_TILES - -#ifdef GENERATE_PPM_TILES - int generated_tile_colors[2][3] = { - { 0, 32, 63 }, // blank | default 255 - { 173, 239, 209 } // not blank | defalut 0 - // { 255, 255, 255 }, - // { 0, 0, 0 } - }; -#endif +// name of the tileset, localated in files/tilesets directory +#define TILESET_NAME "black-white" +#define DIMENTIONS 2 +#define TILE_TYPES 5 -// name of the tileset, localated in files/tilesets directory -// must be defined only when GENERATE_PPM_TILES is not -// if both arent defined, only tiles.dat will be generated -#define TILESET_NAME "knots" - -/* The TILES are - --------------------------------------------------- -| 0: ... blank | 1: ... t (down) | -| ... X symetry | ### T symetry | -| ... | .#. | -| -------------------+--------------------------| -| 2: .#. plus | 3: ... line | -| ### I symetry | ### I symetry | -| .#. | ... | -| -------------------+--------------------------| -| 4: .#. corner | | -| .## T symetry | | -| ... | | --------------------------------------------------- - -The number are the tile indexes, the values that you -need to put in the tiles_to_load array - - */ +tile tiles[TILE_TYPES] = { + { "empty" , 'X', { 0, 0, 0, 0 } }, + { "t" , 'T', { 0, 1, 1, 1 } }, + { "cross" , 'X', { 1, 1, 1, 1 } }, + { "line" , 'I', { 0, 1, 1, 0 } }, + { "corner" , 'T', { 1, 1, 0, 0 } } +}; // Array for which tiles to include the tiles.dat int tiles_to_load[] = { - 2, - 3, - 4, + 3, 4 }; + +// // name of the tileset, localated in files/tilesets directory +// #define TILESET_NAME "circuit" + +// #define DIMENTIONS 2 +// #define TILE_TYPES 14 + +// // pcb green - 0 +// // green - 1, +// // grey - 2, +// // black - 3, +// // other - 4, 5 +// tile tiles[TILE_TYPES] = { +// { "bridge" , 'I', { 1, 2, 2, 1 } }, +// { "component" , 'X', { 3, 3, 3, 3 } }, +// { "connection" , 'T', { 1, 4, 5, 3 } }, +// { "corner" , 'T', { 0, 0, 4, 5 } }, +// { "dskew" , 'I', { 1, 1, 1, 1 } }, +// { "skew" , 'T', { 1, 1, 0, 0 } }, +// { "substrate" , 'X', { 0, 0, 0, 0 } }, +// { "t" , 'T', { 0, 1, 1, 1 } }, +// { "track" , 'I', { 1, 0, 0, 1 } }, +// { "transition" , 'T', { 2, 0, 0, 1 } }, +// { "turn" , 'T', { 1, 1, 0, 0 } }, +// { "viad" , 'I', { 0, 1, 1, 0 } }, +// { "vias" , 'T', { 1, 0, 0, 0 } }, +// { "wire" , 'I', { 0, 2, 2, 0 } }, +// }; + + +// // Array for which tiles to include the tiles.dat +// int tiles_to_load[] = { +// 0, 1, 2, 3, 4, 5, 6, +// 7, 8, 9, 10, 11, 12, 13, +// }; diff --git a/src/gen_tiles.c b/src/gen_tiles.c index e4e2159..c29bc29 100644 --- a/src/gen_tiles.c +++ b/src/gen_tiles.c @@ -3,135 +3,58 @@ #include #include #include "typedef.h" -#include "ppm.h" -#include "config.h" - -#define TILE_TYPES 5 -#define TILE_WIDTH 3 -#define TILE_HEIGHT 3 - -// possible types: X T I -char symetry[TILE_TYPES] = "XTIIT"; - -char tile_names[TILE_TYPES][7] = { - "blank", "t", "plus", "line", "corner" -}; - -small_t tiles[TILE_TYPES][TILE_WIDTH*TILE_HEIGHT] = { - { - 0, 0, 0, - 0, 0, 0, - 0, 0, 0 - }, { - 0, 0, 0, - 1, 1, 1, - 0, 1, 0 - }, { - 0, 1, 0, - 1, 1, 1, - 0, 1, 0 - },{ - 0, 0, 0, - 1, 1, 1, - 0, 0, 0 - }, { - 0, 1, 0, - 0, 1, 1, - 0, 0, 0 - } -}; -small_t tiles_connections[TILE_TYPES][4] = { - { 0, 0, 0, 0 }, - { 0, 1, 1, 1 }, - { 1, 1, 1, 1 }, - { 0, 1, 1, 0 }, - { 1, 1, 0, 0 }, -}; +typedef struct tile { + char name[64]; + char symetry; + small_t connections[SIDES_MAX]; + // small_t neighbours[TILES_CAP]; +// size_t neigbours_sz; +} tile; -void set_color(small_t *pixels, small_t *t, int x, int y, char k, char blank, char connection) -{ - pixels[(y * TILE_WIDTH + x)*3 + k] = (t[y * TILE_WIDTH + x] == 0) ? blank : connection; - -} -FILE *fp; +#include "config.h" -void save(small_t *t, small_t *c, int n, int i) +void copy(char *tile_set, char *name, int n) { -#ifdef GENERATE_PPM_TILES - (void)i; - - char file_name[64] = {0}; - - sprintf(file_name, "files/tiles/tile_%d.ppm", n); - - small_t *pixels = malloc(TILE_WIDTH * TILE_HEIGHT *3); - for(int y = 0; y < TILE_HEIGHT; y++) - for(int x = 0; x < TILE_WIDTH; x++) { - set_color(pixels, t, x, y, 0, - generated_tile_colors[0][0], - generated_tile_colors[1][0]); - set_color(pixels, t, x, y, 1, - generated_tile_colors[0][1], - generated_tile_colors[1][1]); - set_color(pixels, t, x, y, 2, - generated_tile_colors[0][2], - generated_tile_colors[1][2]); - } - - save_as_ppm(file_name, pixels, TILE_WIDTH, TILE_HEIGHT, 1); - free(pixels); - printf("Saved file: %s\n", file_name); -#endif -#ifdef TILESET_NAME - (void)t; (void)c; - - char command[128]; - sprintf(command, "cp files/tilesets/%s/%s.ppm files/tiles/tile_%d.ppm", TILESET_NAME, tile_names[i], n); + char command[512]; + sprintf(command, "cp files/tilesets/%s/%s.ppm files/tiles/tile_%d.ppm", + tile_set, name, n); system(command); -#endif - - small_t connections = 0; - for(int ci = 0; ci < 4; ci++) - { - connections |= (c[ci] << (3-ci)); - } - - fwrite(&connections, sizeof(connections), 1, fp); } void gen() { - mkdir("files", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); - mkdir("files/tiles", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + system("mkdir files"); + system("mkdir files/tiles"); - fp = fopen("files/tiles/tiles.dat", "wb"); + 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); - char syms[TILE_TYPES]; - size_t sym_sz = 0; - for(size_t n = 0; n < tiles_sz; n++) { - int i = tiles_to_load[n]; - save(tiles[i], tiles_connections[i], n, i); - syms[sym_sz++] = symetry[i]; - } + int t = tiles_to_load[n]; + copy(TILESET_NAME, tiles[t].name, n); - fwrite(syms, 1, sym_sz, fp); + 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; } diff --git a/src/main.c b/src/main.c index 07675b7..bba2087 100644 --- a/src/main.c +++ b/src/main.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "typedef.h" #include "ppm.h" #include "tiles.h" @@ -16,8 +17,8 @@ size_t TILE_HEIGHT; // width and height of the tilemap // to generate -size_t SWIDTH = 30; -size_t SHEIGHT = 30; +size_t SWIDTH = 15; +size_t SHEIGHT = 15; time_t SEED; size_t SCALE = 9; @@ -59,7 +60,7 @@ int get_least_entropy_index() void collapse_this(int i) { if(count_entropy(i) == 0) { - fprintf(stderr, "ERROR: No possible tiles for this position: %d\n", i); + err("No possible tiles for this position: %d\n", i); exit(EXIT_FAILURE); } @@ -92,66 +93,61 @@ void collapse_this(int i) void manage_arguments(int argc, char **argv) { - if(argc == 1) return; - - for(int n = 1; n < argc; n++) + int opt; + while((opt = getopt(argc, argv, "hd:s:m:")) != -1) { - char *arg = argv[n]; - - if((strcmp(arg, "-h") == 0) || (strcmp(argv[1], "--help") == 0)) { + switch(opt) + { + case 'd': + SWIDTH = atoi(strtok(optarg, "x")); + SHEIGHT = atoi(strtok(NULL, "x")); + break; + case 's': + SEED = atoi(optarg); + break; + case 'm': + SCALE = atoi(optarg); + break; + case 'h': + default: puts("Usage: wfc [OPTION] [VALUE(S)]...\n"); - puts("The options are the following: (No option is mandatory)\n"); - puts("-h, --help Get help"); - puts("-d Change width and height of the tilemap, defaut is 30x30"); - puts(" args: 2 numbers; width and height seperated by space"); - puts("-s Change the seed for generating the tilemap, default is time(0)"); - puts(" args: 1 number; the seed"); - puts("-m Change the number, that the tilemap is scaled by"); - puts(" args: 1 number; scaler"); + puts("The options are the following: (No option is mandatory)"); + puts("-h Get help"); + puts("-d Change width and height of the tilemap, defaut is 30x30"); + puts(" args: 2 numbers; width and height seperated by an 'x'"); + puts("-s Change the seed, default is time(0)"); + puts(" args: 1 number; the seed"); + puts("-m Change the number, that the tilemap is scaled by"); + puts(" args: 1 number; scaler"); exit(EXIT_SUCCESS); - } else if(strcmp(arg, "-d") == 0) { - if(!(n+2 < argc)) goto error; - SWIDTH = atoi(argv[++n]); - SHEIGHT = atoi(argv[++n]); - } else if(strcmp(arg, "-s") == 0) { - if(!(n+1 < argc)) goto error; - SEED = atoi(argv[++n]); - } else if(strcmp(arg, "-m") == 0) { - if(!(n+1 < argc)) goto error; - SCALE = atoi(argv[++n]); - } else goto error; + break; + } } - return; - -error: - fputs("ERROR: An error has accured with the given arguments", stderr); - exit(EXIT_FAILURE); } int main(int argc, char **argv) { - // SEED = 4; SEED = time(0); - manage_arguments(argc, argv); - srand(SEED); - printf("The Seed is %ld\n", SEED); + + info("Starting With:\n\tWidth: %ld\n\tHeight: %ld\n\tSeed: %ld\n\tScale: %ld", SWIDTH, SHEIGHT, SEED, SCALE); load_tiles(); + info("Tiles Loaded"); init_tilemap(); + info("Tilemap Initiated"); generate_tile_masks(get_tile_connections()); + info("Tile Masks Generated"); - while(1) { - int lei; - lei = get_least_entropy_index(); + // print_tiles(); + // printf("%ld\n", TILES); - if(has_collapsed(lei)) - break; // every index is set - else - collapse_this(lei); - } + for(int lei = get_least_entropy_index(); !has_collapsed(lei); lei = get_least_entropy_index()) + collapse_this(lei); + + info("Tilemap Successfully Generated"); size_t img_wdt = TILE_WIDTH * SWIDTH; size_t img_hgt = TILE_HEIGHT * SHEIGHT; @@ -178,7 +174,7 @@ int main(int argc, char **argv) sprintf(file_name, "files/file_%ld.ppm", SEED); save_as_ppm(file_name, image, img_wdt, img_hgt, SCALE); - printf("Saved file with name: %s\n", file_name); + info("Saved file with name: %s\n", file_name); free(image); return 0; diff --git a/src/ppm.c b/src/ppm.c index 57a402b..eb309cb 100644 --- a/src/ppm.c +++ b/src/ppm.c @@ -8,12 +8,12 @@ void save_as_ppm(char* file_path, small_t *t, size_t width, size_t height, size_ { FILE *fp = fopen(file_path, "wb"); if(!fp) { - fprintf(stderr, "ERROR: Could not open file: %s\n", file_path); + err("Could not open file: %s\n", file_path); exit(EXIT_FAILURE); } if(scaler == 0) { - fprintf(stderr, "ERROR: Invalid value for scaler %ld\n", scaler); + err("Invalid value for scaler %ld\n", scaler); exit(EXIT_FAILURE); } @@ -33,7 +33,7 @@ char *load_from_ppm(char *file_path, size_t *width, size_t *height) { FILE *fp = fopen(file_path, "rb"); if(!fp) { - fprintf(stderr, "ERROR: Could not open file: %s\n", file_path); + err("Could not open file: %s\n", file_path); exit(EXIT_FAILURE); } @@ -41,7 +41,7 @@ char *load_from_ppm(char *file_path, size_t *width, size_t *height) fgets(line, sizeof(line), fp); if(strncmp(line, "P6", 2) != 0) { - fprintf(stderr, "ERROR: PPM header is not correct of file: %s\n", file_path); + err("PPM header is not correct of file: %s\n", file_path); exit(EXIT_FAILURE); } @@ -51,7 +51,7 @@ char *load_from_ppm(char *file_path, size_t *width, size_t *height) fgets(line, sizeof(line), fp); if(atoi(line) != 255) { - printf("Maximum color value must be 255"); + err("Maximum color value must be 255"); exit(1); } diff --git a/src/tilemap.c b/src/tilemap.c index a09ec0b..df1c1c6 100644 --- a/src/tilemap.c +++ b/src/tilemap.c @@ -1,3 +1,4 @@ +#include #include #include #include "typedef.h" @@ -6,6 +7,8 @@ #define MIN(x, y) (((x) < (y)) ? (x) : (y)) #define BIG_SZ (sizeof(big_t) * 8) +#define INDEX (typeof(n))(n / BIG_SZ) +#define OFFSET (typeof(n))(n % BIG_SZ) extern size_t TILES; extern size_t SWIDTH; @@ -14,21 +17,22 @@ extern size_t SHEIGHT; big_t (*tilemap)[TILEMAP_CAP]; size_t tsz = 0; -// 0 up 1 right -// 2 left 3 down +// 0 up 1 right +// 2 left 3 down +// 4 front 5 back // each bit of the numbers is for every tiles // if the tile is a possibility // least significant bit is tile index 0 -big_t (*tile_masks)[TILES_CAP][4]; +big_t (*tile_masks)[TILES_CAP][SIDES_MAX]; void set(int t, int n) { - tilemap[(n/BIG_SZ)][t] |= (1 << (n%BIG_SZ)); + tilemap[INDEX][t] |= ((big_t)1 << OFFSET); } int is_set(int t, int n) { - return (tilemap[(n/BIG_SZ)][t] >> (n%BIG_SZ)) & 1; + return (tilemap[INDEX][t] >> OFFSET) & 1; } void init_tilemap() @@ -36,9 +40,10 @@ void init_tilemap() tsz = (TILES/BIG_SZ) + 1; tilemap = malloc(sizeof(big_t[tsz][TILEMAP_CAP])); - for(size_t i = 0; i < tsz; i++) - for(size_t n = 0; n < SWIDTH * SHEIGHT; n++) - tilemap[i][n] = ((1 << MIN(BIG_SZ, (TILES - (i*BIG_SZ)))) - 1); + // set everything + for(size_t n = 0; n < SWIDTH * SHEIGHT; n++) + for(size_t i = 0; i < tsz; i++) + tilemap[i][n] = (((big_t)1 << MIN(BIG_SZ, (TILES - (i*BIG_SZ)))) - 1); } void destroy_tilemap() @@ -85,42 +90,35 @@ void mask(int t, int m, int r) tilemap[i][t] &= tile_masks[i][m][r]; } -void generate_tile_masks(small_t* tile_connections) +void generate_tile_masks(small_t (*tc)[SIDES_MAX]) { - size_t (*wt_con)[4]; - size_t (*no_con)[4]; - wt_con = malloc(sizeof(size_t[tsz][4])); - no_con = malloc(sizeof(size_t[tsz][4])); - - for(int n = 0; n < 4; n++) - { - for(size_t i = 0; i < tsz; i++) { - wt_con[i][n] = 0; - no_con[i][n] = 0; - } - - for(size_t i = 0; i < TILES; i++) - wt_con[(i/BIG_SZ)][n] |= ((tile_connections[i] >> n) & 1) << (i%BIG_SZ); + tile_masks = malloc(sizeof(big_t[tsz][TILES_CAP][SIDES_MAX])); + memset(tile_masks, 0, sizeof(big_t[tsz][TILES_CAP][SIDES_MAX])); - for(size_t i = 0; i < TILES; i++) - no_con[(i/BIG_SZ)][n] |= ((wt_con[(i/BIG_SZ)][n] >> (i%BIG_SZ)) & 1) ? 0 : 1 << (i % BIG_SZ); - } - - tile_masks = malloc(sizeof(big_t[tsz][TILES_CAP][4])); - - for(size_t i = 0; i < TILES; i++) + for(size_t n = 0; n < TILES; n++) { - for(int n = 0; n < 4; n++) - { - if((tile_connections[i] >> (3-n)) & 1) - for(size_t t = 0; t < tsz; t++) - tile_masks[t][i][n] = wt_con[t][n]; - else - for(size_t t = 0; t < tsz; t++) - tile_masks[t][i][n] = no_con[t][n]; + for(size_t j = 0; j < TILES; j++) { + for(size_t i = 0; i < SIDES; i++) { + // current solution for circuits :( + // if(n == j && (n == 3 || n == 4 || n == 5 || n ==6)) + // tile_masks[INDEX][j][i] |= (tc[n][3-i] != tc[j][i]) << OFFSET; + // else if(n == j && (n == 7|| n == 8 || n == 9 || n == 10)) + // tile_masks[INDEX][j][i] |= 0 << OFFSET; + // else + tile_masks[INDEX][j][i] |= (tc[n][3-i] == tc[j][i]) << OFFSET; + } } } - - free(wt_con); - free(no_con); } +// void print_tilemap() +// { +// printf("tsz: %ld\n", tsz); +// for(size_t i = 0; i < SHEIGHT; i++) { +// for(size_t j = 0; j < SWIDTH; j++) { +// for(size_t n = tsz-1; n < tsz; n--) +// printf("%lb ", tilemap[n][i*SWIDTH + j]); +// printf("\n"); +// } +// printf("\n"); +// } +// } diff --git a/src/tilemap.h b/src/tilemap.h index f25e7df..533c3d5 100644 --- a/src/tilemap.h +++ b/src/tilemap.h @@ -15,12 +15,10 @@ size_t count_entropy(int t); void init_tilemap(); void destroy_tilemap(); -void generate_tile_masks(small_t* tile_connections); +void generate_tile_masks(small_t (*tile_connections)[SIDES_MAX]); // applly a mask m, r (from tile_masks) // to tile t in tilemap void mask(int t, int m, int r); - - #endif diff --git a/src/tiles.c b/src/tiles.c index cecee5a..0c31c05 100644 --- a/src/tiles.c +++ b/src/tiles.c @@ -9,8 +9,9 @@ extern size_t TILES; extern size_t TILE_WIDTH; extern size_t TILE_HEIGHT; +small_t DIMENTIONS = 0; small_t *(tiles[TILES_CAP]); -small_t tile_connections[TILES_CAP]; +small_t tile_connections[TILES_CAP][SIDES_MAX]; static int rotate(int x, int y, int r, int w) { @@ -38,26 +39,29 @@ static void rotate_tiles(char *t, int i, int r) tiles[i][(y * TILE_WIDTH + x)*3 + k] = t[(rotate(x, y, r, TILE_WIDTH))*3 + k]; } -static void rotate_connections(char *tc, int i, int n, int r) +static void rotate_connections(small_t (*tc)[SIDES_MAX], int i, int n, int r) { - tile_connections[n] = 0; for(int y = 0; y < 2; y++) for(int x = 0; x < 2; x++) - tile_connections[n] |= (((tc[i] >> rotate(x, y, r, 2)) & 1) << (y * 2 + x)); + tile_connections[n][y*2 + x] = tc[i][rotate(x, y, r, 2)]; } -static void load_tile_data(char *tc, char *ts, size_t *tid) +static void load_tile_data(small_t (*tc)[SIDES_MAX], char *ts, size_t *tid) { 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); + err("Could not open file: %s\n", file_path); exit(EXIT_FAILURE); } + fread(&DIMENTIONS, sizeof(DIMENTIONS), 1, fp); fread(tid, sizeof(size_t), 1, fp); - fread(tc, 1, *tid, fp); - fread(ts, 1, *tid, fp); + + for(size_t i = 0; i < *tid; i++) { + fread(tc[i], sizeof(small_t), SIDES, fp); + fread(&(ts[i]), sizeof(char), 1, fp); + } fclose(fp); } @@ -65,7 +69,7 @@ static void load_tile_data(char *tc, char *ts, size_t *tid) void load_tiles() { size_t tid = 0; - char tile_con[TILES_CAP]; + small_t tile_con[TILES_CAP][SIDES_MAX] = {0}; char tile_sym[TILES_CAP]; load_tile_data(tile_con, tile_sym, &tid); @@ -77,7 +81,7 @@ void load_tiles() size_t n = 0; for(size_t i = 0; i < tid; i++, n++) { - char file_path[32]; + char file_path[128]; sprintf(file_path, "files/tiles/tile_%ld.ppm", i); char *t = load_from_ppm(file_path, &TILE_WIDTH, &TILE_HEIGHT); @@ -88,7 +92,7 @@ void load_tiles() rotate_connections(tile_con, i, n, 0); break; case 'T': - for(int j = 0; j < 4; j++) { + for(int j = 0; j < SIDES; j++) { rotate_tiles(t, n, j); rotate_connections(tile_con, i, n, j); n++; @@ -100,17 +104,28 @@ void load_tiles() n++; rotate_tiles(t, n, 1); rotate_connections(tile_con, i, n, 1); + break; + case '/': + rotate_tiles(t, n, 0); + rotate_connections(tile_con, i, n, 0); + n++; + rotate_tiles(t, n, 3); + rotate_connections(tile_con, i, n, 3); + break; + default: + err("Symetry Character not recognized: '%c'", tile_sym[i]); + exit(EXIT_FAILURE); } free_ppm(t); + + if(n > TILES_CAP) { + err("Too many tiles: %ld\n", n); + exit(EXIT_FAILURE); + } } TILES = n; - - if(TILES > TILES_CAP) { - fprintf(stderr, "ERROR: Too many tiles: %ld\n", TILES); - exit(EXIT_FAILURE); - } } void free_tiles() @@ -124,7 +139,9 @@ void print_tiles() for(size_t i = 0; i < TILES; i++) { printf("Tile: %ld\n", i); - printf("Connections: %b\n", tile_connections[i]); + for(int n = 0; n < 4; n++) { + printf("%d", tile_connections[i][n]); + } printf("\n"); for(size_t y = 0; y < TILE_HEIGHT; y++) { for(size_t x = 0; x < TILE_WIDTH; x++) @@ -140,7 +157,7 @@ int get_tile_pixel(size_t t, size_t x, size_t y, int k) return tiles[t][(y * TILE_WIDTH + x)*3 + k]; } -small_t *get_tile_connections() +small_t (*get_tile_connections())[SIDES_MAX] { return tile_connections; } diff --git a/src/tiles.h b/src/tiles.h index d6dae58..6a4a223 100644 --- a/src/tiles.h +++ b/src/tiles.h @@ -7,6 +7,6 @@ void free_tiles(); void print_tiles(); int get_tile_pixel(size_t t, size_t x, size_t y, int k); -small_t *get_tile_connections(); +small_t (*get_tile_connections())[SIDES_MAX]; #endif diff --git a/src/typedef.h b/src/typedef.h index 730b32a..5dff622 100644 --- a/src/typedef.h +++ b/src/typedef.h @@ -2,15 +2,26 @@ #define TYPEDEF_H // useful definitions +#include +#include +typedef unsigned char small_t; +typedef uint64_t big_t; // max tiles that can be loaded #define TILES_CAP 128 // max amount of tiles in a tilemap that is being generated #define TILEMAP_CAP 16384 +// max amount of sided +#define SIDES_MAX 6 -#include -#include -typedef unsigned char small_t; -typedef uint64_t big_t; +extern small_t DIMENTIONS; +#define SIDES (2 * DIMENTIONS) + +#define __RED__ "\033[0;31m" +#define __GREEN__ "\033[0;32m" +#define __RESET__ "\033[0m" + +#define info(...) fprintf(stdout, __GREEN__"[INFO]"__RESET__" "__VA_ARGS__); printf("\n") +#define err(...) fprintf(stderr, __RED__"[ERROR]"__RESET__" "__VA_ARGS__); printf("\n") #endif -- cgit v1.2.3