From e7e6a79f8bf2855b5d1d432613151e48d2d685da Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sat, 14 May 2011 23:22:05 +0200 Subject: Implemented terrain chunk caching. --- terrain_cache.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 terrain_cache.h (limited to 'terrain_cache.h') 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 + +#include +#include + +class TerrainCache; + +struct TerrainCacheObject { + typedef boost::shared_ptr 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 intpair; + typedef std::map 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 -- cgit v1.2.3