aboutsummaryrefslogtreecommitdiff
path: root/src/tilemap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tilemap.c')
-rw-r--r--src/tilemap.c58
1 files changed, 31 insertions, 27 deletions
diff --git a/src/tilemap.c b/src/tilemap.c
index 70d534f..85d76bd 100644
--- a/src/tilemap.c
+++ b/src/tilemap.c
@@ -14,58 +14,62 @@ big_t tilemap[TILEMAP_CAP];
// least significant bit is tile index 0
big_t tile_masks[TILES_CAP][4];
-void set(int i, int n)
+void set(int t, int n)
{
- tilemap[i] |= (1 << n);
+ tilemap[t] |= (1 << n);
}
-int is_set(int i, int n)
+int is_set(int t, int n)
{
- return (tilemap[i] >> n) & 1;
+ 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++)
- for(size_t n = 0; n < TILES; n++)
- set(i, n);
+ tilemap[i] = ((1 << TILES) - 1);
+
}
-size_t count_entropy(int i)
+int has_collapsed(int t)
{
- if(has_collapsed(i)) return TILES+1;
-
- size_t c = 0;
- for (size_t j = 0; j < TILES; j++)
- c += is_set(i, j);
-
- return c;
+ return is_set(t, TILES);
}
-void collapse(int i, int n)
+int get_collapsed_tile(int t)
{
- tilemap[i] = 0;
- set(i, n);
- set(i, TILES);
+ for(size_t i = 0; i < TILES; i++)
+ if(is_set(t, i)) return i;
+
+ return TILES;
}
-int has_collapsed(int i)
+void collapse(int t, int n)
{
- return is_set(i, TILES);
+ tilemap[t] = 0;
+ set(t, n);
+ set(t, TILES);
}
-int get_collapsed_tile(int i)
+size_t count_entropy(int t)
{
- for(size_t t = 0; t < TILES; t++)
- if(is_set(i, t)) return t;
+ if(has_collapsed(t)) return TILES+1;
- return TILES;
-}
+ size_t c = 0;
+ for (size_t j = 0; j < TILES; j++)
+ c += is_set(t, j);
+ return c;
+}
-void mask(int i, int m, int r)
+void mask(int t, int m, int r)
{
- tilemap[i] &= tile_masks[m][r];
+ tilemap[t] &= tile_masks[m][r];
}
void generate_tile_masks(small_t* tile_connections)