summaryrefslogtreecommitdiff
path: root/terrain_cache.h
blob: 2ea4e1543dd722d86830c884768de3b72c5a5b64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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