aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2022-08-12 20:58:47 +0300
committerkartofen <mladenovnasko0@gmail.com>2022-08-12 20:58:47 +0300
commit21f514a56bc17bbb07fc73e126221d1b7d1e77ed (patch)
treeb0a902c201700eaa5b6db82a7356476cf31de911
parent3d8dfa455e8cefa869a2714cc62e05385cf098d0 (diff)
fix bug, more than 63 tiles should work
-rw-r--r--src/tilemap.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/tilemap.c b/src/tilemap.c
index efd0b4e..661671c 100644
--- a/src/tilemap.c
+++ b/src/tilemap.c
@@ -3,9 +3,10 @@
#include "typedef.h"
#include "tilemap.h"
-#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
+#define BIG_SZ (sizeof(big_t) * 8)
+
extern size_t TILES;
extern size_t SWIDTH;
extern size_t SHEIGHT;
@@ -22,23 +23,24 @@ big_t (*tile_masks)[TILES_CAP][4];
void set(int t, int n)
{
- tilemap[(n/64)][t] |= (1 << (n%64));
+ tilemap[(n/BIG_SZ)][t] |= (1 << (n%BIG_SZ));
}
int is_set(int t, int n)
{
- return (tilemap[(n/64)][t] >> (n%64)) & 1;
+ return (tilemap[(n/BIG_SZ)][t] >> (n%BIG_SZ)) & 1;
}
void init_tilemap()
{
- // 63 max tiles in 64 bit int
- tsz = (TILES/64) + 1;
+ tsz = (TILES/BIG_SZ) + 1;
+ #include <stdio.h>
+ printf("tsz %ld\n", tsz);
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(63, TILES)) - 1);
+ tilemap[i][n] = ((1 << MIN(BIG_SZ, (TILES - (i*BIG_SZ)))) - 1);
}
void destroy_tilemap()
@@ -100,10 +102,10 @@ void generate_tile_masks(small_t* tile_connections)
}
for(size_t i = 0; i < TILES; i++)
- wt_con[(i/64)][n] |= ((tile_connections[i] >> n) & 1) << (i%64);
+ wt_con[(i/BIG_SZ)][n] |= ((tile_connections[i] >> n) & 1) << (i%BIG_SZ);
for(size_t i = 0; i < TILES; i++)
- no_con[(i/64)][n] |= ((wt_con[(i/64)][n] >> (i%64)) & 1) ? 0 : 1 << (i % 64);
+ 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]));
@@ -121,6 +123,15 @@ void generate_tile_masks(small_t* tile_connections)
}
}
+
+ for(size_t t = 0; t < tsz; t++)
+ for(size_t i = 0; i < TILES; i++) {
+ for(int n = 0; n < 4; n++)
+ printf("%9b ", tile_masks[t][i][n]);
+ putchar('\n');
+ }
+
+
free(wt_con);
free(no_con);
}