diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2011-06-01 19:02:52 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2011-06-01 19:02:52 +0200 |
commit | dc104e37842049e040f7e39f4e1aab56cde1488c (patch) | |
tree | 7a2b98b1007fe7325752ae5a8e728d1410072dfb /terrain_cache.h |
Moved common files here.
Diffstat (limited to 'terrain_cache.h')
-rw-r--r-- | terrain_cache.h | 51 |
1 files changed, 51 insertions, 0 deletions
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 <boost/shared_ptr.hpp> + +#include <map> +#include <cstddef> + +class TerrainCache; + +struct TerrainCacheObject { + typedef boost::shared_ptr<TerrainCacheObject> 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<int64_t, int64_t> intpair; + typedef std::map<intpair, TerrainCacheObject::p> 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<TerrainCache> 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 |