aboutsummaryrefslogtreecommitdiff
path: root/src/tiles.c
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2022-08-09 23:07:37 +0300
committerkartofen <mladenovnasko0@gmail.com>2022-08-09 23:07:37 +0300
commitec57f80b20e2309774b7e3a215640637e1c8e0f7 (patch)
treec68058ab9e2c8294eea5dfe36a18672644d3c67a /src/tiles.c
parent00c3363ca258f160b875ec254e701017be0314db (diff)
better
Diffstat (limited to 'src/tiles.c')
-rw-r--r--src/tiles.c64
1 files changed, 51 insertions, 13 deletions
diff --git a/src/tiles.c b/src/tiles.c
index 40608b3..2432736 100644
--- a/src/tiles.c
+++ b/src/tiles.c
@@ -1,39 +1,77 @@
#include <stdio.h>
+#include <stdlib.h>
#include "ppm.h"
-extern int *(tiles[]);
-extern int TILE_WIDTH;
-extern int TILE_HEIGHT;
+extern small_t *(tiles[]);
+extern size_t TILES;
-void load_tiles(int n)
+extern size_t TILE_WIDTH;
+extern size_t TILE_HEIGHT;
+
+extern small_t tile_connections[];
+
+void load_tiles()
{
size_t width, height;
- for(int i = 0; i < n; i++)
+ for(size_t i = 0; i < TILES; i++)
{
- char file_path[26];
- sprintf(file_path, "files/tile_%d.ppm", i);
+ char file_path[32];
+ sprintf(file_path, "files/tiles/tile_%ld.ppm", i);
tiles[i] = load_from_ppm(file_path, &width, &height);
}
TILE_WIDTH = width;
TILE_HEIGHT = height;
}
-void free_tiles(int n)
+void free_tiles()
{
- for(int i = 0; i < n; i++)
+ for(size_t i = 0; i < TILES; i++)
free_ppm(tiles[i]);
}
-void print_tiles(int n)
+void print_tiles()
{
- for(int i = 0; i < n; i++)
+ for(size_t i = 0; i < TILES; i++)
{
- for(int y = 0; y < TILE_HEIGHT; y++)
+ for(size_t y = 0; y < TILE_HEIGHT; y++)
{
- for(int x = 0; x < TILE_WIDTH; x++)
+ for(size_t x = 0; x < TILE_WIDTH; x++)
putchar(tiles[i][y * TILE_WIDTH + x] + '0');
putchar('\n');
}
putchar('\n');
}
}
+
+void load_connections()
+{
+ char file_path[32] = "files/tiles/tiles.dat";
+ FILE *fp = fopen(file_path, "rb");
+ if(!fp) {
+ fprintf(stderr, "Could not open file: %s\n", file_path);
+ exit(EXIT_FAILURE);
+ }
+
+ fread(tile_connections, sizeof(small_t), TILES, fp);
+
+ fclose(fp);
+}
+
+#include <dirent.h>
+
+size_t calc_tiles()
+{
+ size_t file_count = 0;
+ DIR * dirp;
+ struct dirent * entry;
+
+ dirp = opendir("files/tiles"); /* There should be error handling after this */
+ while ((entry = readdir(dirp)) != NULL) {
+ if (entry->d_type == DT_REG) { /* If the entry is a regular file */
+ file_count++;
+ }
+ }
+ closedir(dirp);
+
+ return file_count-1;
+}