#include "typedef.h" #include "tilemap.h" extern size_t TILES; extern size_t SWIDTH; extern size_t SHEIGHT; big_t tilemap[TILEMAP_CAP]; // 0 up 1 right // 2 left 3 down // 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]; void set(int t, int n) { tilemap[t] |= (1 << n); } int is_set(int t, int n) { return (tilemap[t] >> n) & 1; } void init_tilemap() { // this is for support of more than 63 different tiles in // for(size_t i = 0; i < SWIDTH * SHEIGHT; i++) // for(size_t n = 0; n < TILES; n++) // set(i, n); for(size_t i = 0; i < SWIDTH * SHEIGHT; i++) tilemap[i] = ((1 << TILES) - 1); } int has_collapsed(int t) { return is_set(t, TILES); } int get_collapsed_tile(int t) { for(size_t i = 0; i < TILES; i++) if(is_set(t, i)) return i; return TILES; } void collapse(int t, int n) { tilemap[t] = 0; set(t, n); set(t, TILES); } size_t count_entropy(int t) { if(has_collapsed(t)) return TILES+1; size_t c = 0; for (size_t j = 0; j < TILES; j++) c += is_set(t, j); return c; } void mask(int t, int m, int r) { tilemap[t] &= tile_masks[m][r]; } void generate_tile_masks(small_t* tile_connections) { size_t wt_con[4] = {0}; size_t no_con[4] = {0}; for(int n = 0; n < 4; n++) { for(size_t i = 0; i < TILES; i++) wt_con[n] |= ((tile_connections[i] >> n) & 1) << i; no_con[n] = (~wt_con[n]) & ((1 << TILES) - 1); } for(size_t i = 0; i < TILES; i++) { for(int n = 0; n < 4; n++) { if((tile_connections[i] >> (3-n)) & 1) tile_masks[i][n] = wt_con[n]; else tile_masks[i][n] = no_con[n]; } } }