mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-24 04:58:59 -05:00
Inject TileCache into TileProvider
This commit is contained in:
@@ -112,8 +112,10 @@ namespace openspace {
|
||||
std::shared_ptr<AsyncTileDataProvider> tileReader = std::shared_ptr<AsyncTileDataProvider>(
|
||||
new AsyncTileDataProvider(tileDataset, threadPool));
|
||||
|
||||
std::shared_ptr<TileCache> tileCache = std::shared_ptr<TileCache>(new TileCache(initData.cacheSize));
|
||||
|
||||
tileProvider = std::shared_ptr<TileProvider>(
|
||||
new CachingTileProvider(tileReader, initData.cacheSize, initData.framesUntilRequestQueueFlush));
|
||||
new CachingTileProvider(tileReader, tileCache, initData.framesUntilRequestQueueFlush));
|
||||
|
||||
return tileProvider;
|
||||
}
|
||||
|
||||
@@ -140,10 +140,11 @@ namespace openspace {
|
||||
std::shared_ptr<AsyncTileDataProvider> tileReader = std::shared_ptr<AsyncTileDataProvider>(
|
||||
new AsyncTileDataProvider(tileDataset, threadPool));
|
||||
|
||||
std::shared_ptr<TileCache> tileCache = std::shared_ptr<TileCache>(new TileCache(_tileProviderInitData.cacheSize));
|
||||
|
||||
std::shared_ptr<CachingTileProvider> tileProvider= std::shared_ptr<CachingTileProvider>(
|
||||
new CachingTileProvider(tileReader,
|
||||
_tileProviderInitData.cacheSize,
|
||||
_tileProviderInitData.framesUntilRequestQueueFlush));
|
||||
new CachingTileProvider(tileReader, tileCache,
|
||||
_tileProviderInitData.framesUntilRequestQueueFlush));
|
||||
|
||||
return tileProvider;
|
||||
}
|
||||
|
||||
@@ -46,10 +46,11 @@ namespace {
|
||||
|
||||
namespace openspace {
|
||||
|
||||
CachingTileProvider::CachingTileProvider(std::shared_ptr<AsyncTileDataProvider> tileReader, int tileCacheSize,
|
||||
CachingTileProvider::CachingTileProvider(std::shared_ptr<AsyncTileDataProvider> tileReader,
|
||||
std::shared_ptr<TileCache> tileCache,
|
||||
int framesUntilFlushRequestQueue)
|
||||
: _asyncTextureDataProvider(tileReader)
|
||||
, _tileCache(tileCacheSize)
|
||||
, _tileCache(tileCache)
|
||||
, _framesSinceLastRequestFlush(0)
|
||||
{
|
||||
|
||||
@@ -107,8 +108,8 @@ namespace openspace {
|
||||
|
||||
HashKey key = chunkIndex.hashKey();
|
||||
|
||||
if (_tileCache.exist(key) && _tileCache.get(key).ioError == CPLErr::CE_None) {
|
||||
return { _tileCache.get(key).texture, uvTransform };
|
||||
if (_tileCache->exist(key) && _tileCache->get(key).ioError == CPLErr::CE_None) {
|
||||
return { _tileCache->get(key).texture, uvTransform };
|
||||
}
|
||||
else if (chunkIndex.level < 1) {
|
||||
return { nullptr, uvTransform };
|
||||
@@ -146,8 +147,8 @@ namespace openspace {
|
||||
|
||||
std::shared_ptr<Texture> CachingTileProvider::getOrStartFetchingTile(ChunkIndex chunkIndex) {
|
||||
HashKey hashkey = chunkIndex.hashKey();
|
||||
if (_tileCache.exist(hashkey)) {
|
||||
return _tileCache.get(hashkey).texture;
|
||||
if (_tileCache->exist(hashkey)) {
|
||||
return _tileCache->get(hashkey).texture;
|
||||
}
|
||||
else {
|
||||
_asyncTextureDataProvider->enqueueTextureData(chunkIndex);
|
||||
@@ -179,9 +180,9 @@ namespace openspace {
|
||||
|
||||
texture->uploadTexture();
|
||||
|
||||
MetaTexture metaTexture = { texture, tileIOResult->error };
|
||||
TextureAndStatus metaTexture = { texture, tileIOResult->error };
|
||||
|
||||
_tileCache.put(key, metaTexture);
|
||||
_tileCache->put(key, metaTexture);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace openspace {
|
||||
TileUvTransform uvTransform;
|
||||
};
|
||||
|
||||
struct MetaTexture {
|
||||
struct TextureAndStatus {
|
||||
std::shared_ptr<Texture> texture;
|
||||
CPLErr ioError;
|
||||
};
|
||||
@@ -75,6 +75,7 @@ namespace openspace {
|
||||
};
|
||||
|
||||
|
||||
typedef LRUCache<HashKey, TextureAndStatus> TileCache;
|
||||
|
||||
|
||||
/**
|
||||
@@ -84,7 +85,10 @@ namespace openspace {
|
||||
class CachingTileProvider : public TileProvider {
|
||||
public:
|
||||
|
||||
CachingTileProvider(std::shared_ptr<AsyncTileDataProvider> tileReader, int tileCacheSize,
|
||||
|
||||
CachingTileProvider(
|
||||
std::shared_ptr<AsyncTileDataProvider> tileReader,
|
||||
std::shared_ptr<TileCache> tileCache,
|
||||
int framesUntilFlushRequestQueue);
|
||||
|
||||
virtual ~CachingTileProvider();
|
||||
@@ -125,7 +129,7 @@ namespace openspace {
|
||||
// Member variables //
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LRUCache<HashKey, MetaTexture> _tileCache;
|
||||
std::shared_ptr<TileCache> _tileCache;
|
||||
|
||||
int _framesSinceLastRequestFlush;
|
||||
int _framesUntilRequestFlush;
|
||||
|
||||
Reference in New Issue
Block a user