From 851a3f34efd456295b21849199c3eaf4e70f9fb9 Mon Sep 17 00:00:00 2001 From: kartofen Date: Wed, 10 Aug 2022 17:18:45 +0300 Subject: big refactor --- src/tiles.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/tiles.c') diff --git a/src/tiles.c b/src/tiles.c index 2432736..6b7a39b 100644 --- a/src/tiles.c +++ b/src/tiles.c @@ -1,14 +1,16 @@ #include #include +#include "typedef.h" +#include "tiles.h" #include "ppm.h" -extern small_t *(tiles[]); extern size_t TILES; extern size_t TILE_WIDTH; extern size_t TILE_HEIGHT; -extern small_t tile_connections[]; +small_t *(tiles[TILES_CAP]); +small_t tile_connections[TILES_CAP]; void load_tiles() { @@ -33,6 +35,7 @@ void print_tiles() { for(size_t i = 0; i < TILES; i++) { + printf("%ld\n", i); for(size_t y = 0; y < TILE_HEIGHT; y++) { for(size_t x = 0; x < TILE_WIDTH; x++) @@ -43,7 +46,12 @@ void print_tiles() } } -void load_connections() +int get_tile_pixel(size_t t, size_t x, size_t y) +{ + return tiles[t][y * TILE_WIDTH + x]; +} + +small_t *load_tile_connections() { char file_path[32] = "files/tiles/tiles.dat"; FILE *fp = fopen(file_path, "rb"); @@ -55,11 +63,13 @@ void load_connections() fread(tile_connections, sizeof(small_t), TILES, fp); fclose(fp); + + return tile_connections; } #include -size_t calc_tiles() +void calc_tiles() { size_t file_count = 0; DIR * dirp; @@ -73,5 +83,5 @@ size_t calc_tiles() } closedir(dirp); - return file_count-1; + TILES = file_count - 1; } -- cgit v1.2.3