aboutsummaryrefslogtreecommitdiff
path: root/src/tilemap.c
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2022-12-22 22:43:44 +0200
committerkartofen <mladenovnasko0@gmail.com>2022-12-22 22:43:44 +0200
commit764070a86a7aa98480eaaff64dfba7e2f2943292 (patch)
tree830589ac702d540bfd76cfb0e5faa5e8988432b0 /src/tilemap.c
parent4c9fafc4c126af2466dc6c56b9c952f901a1c726 (diff)
refactor
Diffstat (limited to 'src/tilemap.c')
-rw-r--r--src/tilemap.c59
1 files changed, 34 insertions, 25 deletions
diff --git a/src/tilemap.c b/src/tilemap.c
index df1c1c6..8cb78f9 100644
--- a/src/tilemap.c
+++ b/src/tilemap.c
@@ -7,12 +7,15 @@
#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)
+#define INDEX ((__typeof(n))(n / BIG_SZ))
+#define OFFSET ((__typeof(n))(n % BIG_SZ))
+// from tiles.c
extern size_t TILES;
-extern size_t SWIDTH;
-extern size_t SHEIGHT;
+extern small_t tile_connections[TILES_CAP][SIDES_MAX];
+
+size_t SWIDTH;
+size_t SHEIGHT;
big_t (*tilemap)[TILEMAP_CAP];
size_t tsz = 0;
@@ -25,6 +28,27 @@ size_t tsz = 0;
// least significant bit is tile index 0
big_t (*tile_masks)[TILES_CAP][SIDES_MAX];
+void generate_tile_masks()
+{
+ 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 n = 0; n < TILES; 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] |= (tile_connections[n][3-i] == tile_connections[j][i]) << OFFSET;
+ }
+ }
+ }
+}
+
void set(int t, int n)
{
tilemap[INDEX][t] |= ((big_t)1 << OFFSET);
@@ -35,8 +59,11 @@ int is_set(int t, int n)
return (tilemap[INDEX][t] >> OFFSET) & 1;
}
-void init_tilemap()
+void init_tilemap(size_t width, size_t height)
{
+ SWIDTH = width;
+ SHEIGHT = height;
+
tsz = (TILES/BIG_SZ) + 1;
tilemap = malloc(sizeof(big_t[tsz][TILEMAP_CAP]));
@@ -44,6 +71,8 @@ void init_tilemap()
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);
+
+ generate_tile_masks();
}
void destroy_tilemap()
@@ -90,26 +119,6 @@ void mask(int t, int m, int r)
tilemap[i][t] &= tile_masks[i][m][r];
}
-void generate_tile_masks(small_t (*tc)[SIDES_MAX])
-{
- 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 n = 0; n < TILES; 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;
- }
- }
- }
-}
// void print_tilemap()
// {
// printf("tsz: %ld\n", tsz);