From dc104e37842049e040f7e39f4e1aab56cde1488c Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Wed, 1 Jun 2011 19:02:52 +0200 Subject: Moved common files here. --- terrain_cache.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 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..dcc4f34 --- /dev/null +++ b/terrain_cache.h @@ -0,0 +1,51 @@ +#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; + int64_t x, y; + unsigned int width, height; + + TerrainCacheObject(TerrainCache *cache, int64_t x, int64_t y, unsigned int width, unsigned int height, float *heights = NULL); + virtual ~TerrainCacheObject(); +}; + +class TerrainCache { + friend class TerrainCacheObject; + + private: + typedef std::pair intpair; + typedef std::map cache_map; + + cache_map caches; + size_t max_size; + + TerrainCacheObject::p make_object(int64_t x, int64_t y, unsigned int width, unsigned int height, float *heights = NULL); + + public: + typedef boost::shared_ptr p; + + TerrainCache(fs::path root, size_t max_size); + TerrainCache(TerrainLoader::p loader, size_t max_size); + virtual ~TerrainCache(); + + TerrainLoader::p tl; + + TerrainCacheObject::p get_chunk(int64_t x, int64_t y, unsigned int width, unsigned int height); + void add_chunk(float *heights, int64_t x, int64_t y, unsigned int width, unsigned int height); + size_t get_size(); +}; + +#endif -- cgit v1.2.3