aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md10
-rwxr-xr-xbuild.sh2
-rw-r--r--files/tilesets/knots/blank.ppm4
-rw-r--r--files/tilesets/knots/corner.ppm (renamed from files/tilesets/corner.ppm)bin313 -> 313 bytes
-rw-r--r--files/tilesets/knots/line.ppm (renamed from files/tilesets/line.ppm)bin313 -> 313 bytes
-rw-r--r--files/tilesets/knots/plus.ppm (renamed from files/tilesets/cross.ppm)bin313 -> 313 bytes
-rw-r--r--files/tilesets/knots/t.ppmbin0 -> 313 bytes
-rw-r--r--src/config.h43
-rw-r--r--src/gen_tiles.c28
9 files changed, 53 insertions, 34 deletions
diff --git a/README.md b/README.md
index 424e9c6..4d9aa08 100644
--- a/README.md
+++ b/README.md
@@ -23,6 +23,7 @@ Two files will be build in the bin directory,
I am pretty sure the `bin/wfc` should work on Windows,
`bin/gen_tiles` uses linux-only header to
create the directories for the files (files and files/tiles)
+and uses `cp` to copy files around.
It would be easy to make everything work on windows,
I just dont want to take my time and make it cross platform.
@@ -41,11 +42,10 @@ The `bin/gen_tiles` generates the `tiles.dat` file and optionally the tiles them
There is a file called `config.h` under the src directory which is used to specify things about
`tiles.dat` and basically configuring `bin/gen_tiles`. More info in the file as comments.
-To use a tileset, different from the one that can be generated from `bin/gen_tiles`
-you need to specify the tile-types you are going to use in `src/config.h`, then copy-paste
-the tiles into `files/tiles` directory and then name them `tile_<num>.ppm`, where
-num is the index of the tile in the `tiles_to_load` array in `src/config.h` (Not the tile index in the table).
-
+To use a tileset different generated one it is explained in `src/config.h`.
+For a tilset to be compatable with this project, it needs to be all ppm files,
+and files should be named exactly like the names in the table in `src/config.h`.
+For example see the tileset in `files/tilesets/knots`.
### Limitations
diff --git a/build.sh b/build.sh
index c5cfef3..3c5ac3d 100755
--- a/build.sh
+++ b/build.sh
@@ -49,5 +49,5 @@ gcc -o $BIN/gen_tiles $ODIR/gen_tiles.o $ODIR/ppm.o $FLAGS
if ! { [[ $RUN -eq 0 ]]; } 2> /dev/null
then
$VALGRND $BIN/gen_tiles
- $VALGRND $BIN/wfc
+ $VALGRND $BIN/wfc -s 69 -m 4
fi
diff --git a/files/tilesets/knots/blank.ppm b/files/tilesets/knots/blank.ppm
new file mode 100644
index 0000000..ac75fdf
--- /dev/null
+++ b/files/tilesets/knots/blank.ppm
@@ -0,0 +1,4 @@
+P6
+10 10
+255
+ΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓΓ \ No newline at end of file
diff --git a/files/tilesets/corner.ppm b/files/tilesets/knots/corner.ppm
index caea47c..caea47c 100644
--- a/files/tilesets/corner.ppm
+++ b/files/tilesets/knots/corner.ppm
Binary files differ
diff --git a/files/tilesets/line.ppm b/files/tilesets/knots/line.ppm
index 8d1a6d0..8d1a6d0 100644
--- a/files/tilesets/line.ppm
+++ b/files/tilesets/knots/line.ppm
Binary files differ
diff --git a/files/tilesets/cross.ppm b/files/tilesets/knots/plus.ppm
index 17f3c82..17f3c82 100644
--- a/files/tilesets/cross.ppm
+++ b/files/tilesets/knots/plus.ppm
Binary files differ
diff --git a/files/tilesets/knots/t.ppm b/files/tilesets/knots/t.ppm
new file mode 100644
index 0000000..2627d1e
--- /dev/null
+++ b/files/tilesets/knots/t.ppm
Binary files differ
diff --git a/src/config.h b/src/config.h
index 8e2910b..4135b5c 100644
--- a/src/config.h
+++ b/src/config.h
@@ -1,23 +1,27 @@
-// comment this if you dont want to
-// generate the tiles, only the
-// tiles.dat file
-#define GENERATE_PPM_TILES
+// 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
+
+// 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"
/* The TILES are
------------------------------------------------
-|0: ... blank | 1: ... T-piece (down) |
-| ... X symetry | ### T symetry |
-| ... | .#. |
-|-------------------+-------------------------|
-|2: .#. cross | 3: ... bar |
-| ### X symetry | ### I symetry |
-| .#. | ... |
-|-------------------+-------------------------|
-|4: .#. corner | |
-| .## T symetry | |
-| ... | |
------------------------------------------------
+--------------------------------------------------
+| 0: ... blank | 1: ... t (down) |
+| ... X symetry | ### T symetry |
+| ... | .#. |
+| -------------------+--------------------------|
+| 2: .#. plus | 3: ... line |
+| ### X symetry | ### I symetry |
+| .#. | ... |
+| -------------------+--------------------------|
+| 4: .#. corner | |
+| .## T symetry | |
+| ... | |
+--------------------------------------------------
The number are the tile indexes, the values that you
need to put in the tiles_to_load array
@@ -26,6 +30,7 @@ need to put in the tiles_to_load array
// Array for which tiles to include the tiles.dat
int tiles_to_load[] = {
- 0,
- 1,
+ 2,g
+ 4,
+ 3,
};
diff --git a/src/gen_tiles.c b/src/gen_tiles.c
index 6a73872..de07f30 100644
--- a/src/gen_tiles.c
+++ b/src/gen_tiles.c
@@ -6,13 +6,18 @@
#include "ppm.h"
#include "config.h"
+#define TILE_TYPES 5
#define TILE_WIDTH 3
#define TILE_HEIGHT 3
// possible types: X T I
-char symetry[TILES_CAP] = "XTIIT";
+char symetry[TILE_TYPES] = "XTIIT";
-small_t tiles[TILES_CAP][TILE_WIDTH*TILE_HEIGHT] = {
+char tile_names[TILE_TYPES][7] = {
+ "blank", "t", "plus", "line", "corner"
+};
+
+small_t tiles[TILE_TYPES][TILE_WIDTH*TILE_HEIGHT] = {
{
0, 0, 0,
0, 0, 0,
@@ -36,7 +41,7 @@ small_t tiles[TILES_CAP][TILE_WIDTH*TILE_HEIGHT] = {
}
};
-small_t tiles_connections[TILES_CAP][4] = {
+small_t tiles_connections[TILE_TYPES][4] = {
{ 0, 0, 0, 0 },
{ 0, 1, 1, 1 },
{ 1, 1, 1, 1 },
@@ -51,12 +56,12 @@ void set_color(small_t *pixels, small_t *t, int x, int y, char k, char blank, ch
}
FILE *fp;
-void save(small_t *t, small_t *n, int i)
+void save(small_t *t, small_t *c, int n, int i)
{
#ifdef GENERATE_PPM_TILES
char file_name[64] = {0};
- sprintf(file_name, "files/tiles/tile_%d.ppm", i);
+ sprintf(file_name, "files/tiles/tile_%d.ppm", n);
small_t *pixels = malloc(TILE_WIDTH * TILE_HEIGHT *3);
for(int y = 0; y < TILE_HEIGHT; y++)
@@ -70,11 +75,16 @@ void save(small_t *t, small_t *n, int i)
free(pixels);
printf("Saved file: %s\n", file_name);
#endif
+#ifdef TILESET_NAME
+ char command[128];
+ sprintf(command, "cp files/tilesets/%s/%s.ppm files/tiles/tile_%d.ppm", TILESET_NAME, tile_names[i], n);
+ system(command);
+#endif
small_t connections = 0;
- for(int c = 0; c < 4; c++)
+ for(int ci = 0; ci < 4; ci++)
{
- connections |= (n[c] << (3-c));
+ connections |= (c[ci] << (3-ci));
}
fwrite(&connections, sizeof(connections), 1, fp);
@@ -90,13 +100,13 @@ void gen_rotations()
size_t tiles_sz = sizeof(tiles_to_load)/sizeof(int);
fwrite(&tiles_sz, sizeof(size_t), sizeof(size_t), fp);
- char syms[TILES_CAP];
+ char syms[TILE_TYPES];
size_t sym_sz = 0;
for(size_t n = 0; n < tiles_sz; n++)
{
int i = tiles_to_load[n];
- save(tiles[i], tiles_connections[i], n);
+ save(tiles[i], tiles_connections[i], n, i);
syms[sym_sz++] = symetry[i];
}