diff options
-rwxr-xr-x | build.sh | 2 | ||||
-rw-r--r-- | src/config.h | 15 | ||||
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/tilemap.c | 65 | ||||
-rw-r--r-- | src/tilemap.h | 4 | ||||
-rw-r--r-- | src/typedef.h | 2 |
6 files changed, 62 insertions, 30 deletions
@@ -16,7 +16,7 @@ function run { } function leak { - VALGRND="valgrind --leak-check=full" + VALGRND="valgrind --leak-check=full --show-leak-kinds=all -s" RUN=1 } diff --git a/src/config.h b/src/config.h index 06525cb..36f43a6 100644 --- a/src/config.h +++ b/src/config.h @@ -1,11 +1,13 @@ // comment this if you dont want to generate the tiles, but // want to use the tileset defined in the TILESET_NAME directive -// #define GENERATE_PPM_TILES +#define GENERATE_PPM_TILES #ifdef GENERATE_PPM_TILES int generated_tile_colors[2][3] = { - { 211, 211, 211 }, // blank | default 255 - { 30, 144, 155 } // not blank | defalut 0 + { 0, 32, 63 }, // blank | default 255 + { 173, 239, 209 } // not blank | defalut 0 + // { 255, 255, 255 }, + // { 0, 0, 0 } }; #endif @@ -13,7 +15,7 @@ // name of the tileset, localated in files/tilesets directory // must be defined only when GENERATE_PPM_TILES is not // if both arent defined, only tiles.dat will be generated -#define TILESET_NAME "knots" +// #define TILESET_NAME "knots" /* The TILES are @@ -38,7 +40,6 @@ need to put in the tiles_to_load array // Array for which tiles to include the tiles.dat int tiles_to_load[] = { - 2, - 3, - 4, + 0, + 1, }; @@ -132,7 +132,6 @@ error: int main(int argc, char **argv) { - // SEED = 69; SEED = time(0); manage_arguments(argc, argv); @@ -141,8 +140,8 @@ int main(int argc, char **argv) printf("The Seed is %ld\n", SEED); load_tiles(); - generate_tile_masks(get_tile_connections()); init_tilemap(); + generate_tile_masks(get_tile_connections()); while(1) { int lei; @@ -173,6 +172,7 @@ int main(int argc, char **argv) } free_tiles(); + destroy_tilemap(); char file_name[64] = {0}; diff --git a/src/tilemap.c b/src/tilemap.c index 85d76bd..efd0b4e 100644 --- a/src/tilemap.c +++ b/src/tilemap.c @@ -1,39 +1,50 @@ +#include <stdlib.h> +#include <string.h> #include "typedef.h" #include "tilemap.h" +#define MAX(x, y) (((x) > (y)) ? (x) : (y)) +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) + extern size_t TILES; extern size_t SWIDTH; extern size_t SHEIGHT; -big_t tilemap[TILEMAP_CAP]; +big_t (*tilemap)[TILEMAP_CAP]; +size_t tsz = 0; // 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]; +big_t (*tile_masks)[TILES_CAP][4]; void set(int t, int n) { - tilemap[t] |= (1 << n); + tilemap[(n/64)][t] |= (1 << (n%64)); } int is_set(int t, int n) { - return (tilemap[t] >> n) & 1; + return (tilemap[(n/64)][t] >> (n%64)) & 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); + // 63 max tiles in 64 bit int + tsz = (TILES/64) + 1; + tilemap = malloc(sizeof(big_t[tsz][TILEMAP_CAP])); - for(size_t i = 0; i < SWIDTH * SHEIGHT; i++) - tilemap[i] = ((1 << TILES) - 1); + 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); +} +void destroy_tilemap() +{ + free(tilemap); + free(tile_masks); } int has_collapsed(int t) @@ -51,7 +62,8 @@ int get_collapsed_tile(int t) void collapse(int t, int n) { - tilemap[t] = 0; + for(size_t i = 0; i < tsz; i++) + tilemap[i][t] = 0; set(t, n); set(t, TILES); } @@ -69,29 +81,46 @@ size_t count_entropy(int t) void mask(int t, int m, int r) { - tilemap[t] &= tile_masks[m][r]; + for(size_t i = 0; i < tsz; i++) + tilemap[i][t] &= tile_masks[i][m][r]; } void generate_tile_masks(small_t* tile_connections) { - size_t wt_con[4] = {0}; - size_t no_con[4] = {0}; + 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[n] |= ((tile_connections[i] >> n) & 1) << i; + wt_con[(i/64)][n] |= ((tile_connections[i] >> n) & 1) << (i%64); - no_con[n] = (~wt_con[n]) & ((1 << TILES) - 1); + 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); } + tile_masks = malloc(sizeof(big_t[tsz][TILES_CAP][4])); + 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]; + 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]; } } + + free(wt_con); + free(no_con); } diff --git a/src/tilemap.h b/src/tilemap.h index 74344dd..f25e7df 100644 --- a/src/tilemap.h +++ b/src/tilemap.h @@ -8,10 +8,12 @@ int is_set(int t, int n); // self explanatory names int has_collapsed(int t); -int get_collapsed_tile(int i); +int get_collapsed_tile(int t); void collapse(int t, int n); size_t count_entropy(int t); + void init_tilemap(); +void destroy_tilemap(); void generate_tile_masks(small_t* tile_connections); diff --git a/src/typedef.h b/src/typedef.h index 8924dc8..cf7787e 100644 --- a/src/typedef.h +++ b/src/typedef.h @@ -3,7 +3,7 @@ // useful definitions -#define TILES_CAP 63 +#define TILES_CAP 128 #define TILEMAP_CAP 16384 #include <stdint.h> |