aboutsummaryrefslogtreecommitdiff
path: root/src/tilemap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tilemap.c')
-rw-r--r--src/tilemap.c80
1 files changed, 39 insertions, 41 deletions
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#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");
+// }
+// }