summaryrefslogtreecommitdiff
path: root/src/tiledmap.h
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2023-07-23 15:30:42 +0200
committerdavidovski <david@davidovski.xyz>2023-07-23 15:30:42 +0200
commit0d78ec0e53d9824a029840e74bf0721ed2187e6a (patch)
tree74781baff855e3f3760730c9897e932994f3a8a4 /src/tiledmap.h
parent5ec62c0a2a0357a79f92b8bb37f67272e7f910ff (diff)
add chunk caching
Diffstat (limited to 'src/tiledmap.h')
-rw-r--r--src/tiledmap.h36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/tiledmap.h b/src/tiledmap.h
index fb9c789..2c4cf94 100644
--- a/src/tiledmap.h
+++ b/src/tiledmap.h
@@ -1,23 +1,33 @@
#include <raylib.h>
+#include "kdtree.h"
-typedef struct TiledMap {
- int width;
- int height;
- char * tilelayout;
+#define CHUNK_CACHE_SIZE 32
+
+typedef char * Chunk;
+
+typedef struct CachedChunk {
+ long filePos;
+ Chunk chunk;
+} CachedChunk;
+
+typedef struct ChunkedTiledMap {
+ FILE * file;
+ int chunkWidth;
+ int chunkHeight;
int tileSize;
int atlasSize[2];
int tileCount;
Color * atlasData;
+ kdtree_t * chunkTree;
} TiledMap;
void textureFromPixels(Texture2D *texOut, Color *pixels, int width, int height);
+TiledMap openTiledMap(char * filename);
+CachedChunk * loadChunk(TiledMap *tiledMap, int x, int y);
+char getChunkedTile(TiledMap *tiledMap, int x, int y);
+char setChunkedTile(TiledMap * tiledMap, int x, int y, char value);
+CachedChunk * createChunk(TiledMap * tiledMap, int x, int y, Chunk chunk);
+void writeTiledMapHeader(TiledMap tiledMap);
+TiledMap openNewTiledMap(char * filename, Image atlas, int tileSize, int chunkWidth, int chunkHeight, int width, int height);
+void closeTiledMap(TiledMap * tiledMap);
-void setTiledMapTile(TiledMap tiledMap, int pos[2], char tile);
-
-char getTiledMapTile(TiledMap tiledMap, int pos[2]);
-
-TiledMap loadTiledMap(char * filename);
-
-void saveTiledMap(char * filename, TiledMap tiledMap);
-
-TiledMap newTiledMap(Image atlas, int tileSize, int width, int height);