summaryrefslogtreecommitdiff
path: root/terrain_cache.h
diff options
context:
space:
mode:
Diffstat (limited to 'terrain_cache.h')
-rw-r--r--terrain_cache.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/terrain_cache.h b/terrain_cache.h
new file mode 100644
index 0000000..2ea4e15
--- /dev/null
+++ b/terrain_cache.h
@@ -0,0 +1,45 @@
+#ifndef TERRAIN_CACHE_H
+#define TERRAIN_CACHE_H
+
+#include "terrain_loader.h"
+
+#include <boost/shared_ptr.hpp>
+
+#include <map>
+#include <cstddef>
+
+class TerrainCache;
+
+struct TerrainCacheObject {
+ typedef boost::shared_ptr<TerrainCacheObject> p;
+
+ TerrainCache *cache;
+ float *heights;
+ int x, y, width, height;
+
+ TerrainCacheObject(TerrainCache *cache, int x, int y, int width, int height);
+ virtual ~TerrainCacheObject();
+};
+
+class TerrainCache {
+ friend class TerrainCacheObject;
+
+ private:
+ typedef std::pair<int, int> intpair;
+ typedef std::map<intpair, TerrainCacheObject::p> cache_map;
+
+ cache_map caches;
+ TerrainLoader *tl;
+ size_t max_size;
+
+ TerrainCacheObject::p make_object(int x, int y, int width, int height);
+
+ public:
+ TerrainCache(int seed, fs::path root, size_t max_size);
+ virtual ~TerrainCache();
+
+ TerrainCacheObject::p get_chunk(int x, int y, int width, int height);
+ size_t get_size();
+};
+
+#endif