Make the cache expiryDelay configurable

coverity_scan
scrawl 9 years ago
parent 41233fc8e5
commit a81b10b415

@ -123,6 +123,7 @@ namespace MWWorld
CellPreloader::CellPreloader(Resource::ResourceSystem* resourceSystem, Resource::BulletShapeManager* bulletShapeManager) CellPreloader::CellPreloader(Resource::ResourceSystem* resourceSystem, Resource::BulletShapeManager* bulletShapeManager)
: mResourceSystem(resourceSystem) : mResourceSystem(resourceSystem)
, mBulletShapeManager(bulletShapeManager) , mBulletShapeManager(bulletShapeManager)
, mExpiryDelay(0.0)
{ {
mWorkQueue = new SceneUtil::WorkQueue; mWorkQueue = new SceneUtil::WorkQueue;
} }
@ -156,13 +157,11 @@ namespace MWWorld
void CellPreloader::updateCache(double timestamp) void CellPreloader::updateCache(double timestamp)
{ {
// time (in seconds) to keep a preloaded cell in cache after it's no longer needed // TODO: add settings for a minimum/maximum size of the cache
// additionally we could support a minimum/maximum size for the cache
const double expiryTime = 60.0;
for (PreloadMap::iterator it = mPreloadCells.begin(); it != mPreloadCells.end();) for (PreloadMap::iterator it = mPreloadCells.begin(); it != mPreloadCells.end();)
{ {
if (it->second.mTimeStamp < timestamp - expiryTime) if (it->second.mTimeStamp < timestamp - mExpiryDelay)
mPreloadCells.erase(it++); mPreloadCells.erase(it++);
else else
++it; ++it;
@ -172,6 +171,11 @@ namespace MWWorld
mWorkQueue->addWorkItem(new UpdateCacheItem(mResourceSystem, timestamp)); mWorkQueue->addWorkItem(new UpdateCacheItem(mResourceSystem, timestamp));
} }
void CellPreloader::setExpiryDelay(double expiryDelay)
{
mExpiryDelay = expiryDelay;
}
void CellPreloader::setWorkQueue(osg::ref_ptr<SceneUtil::WorkQueue> workQueue) void CellPreloader::setWorkQueue(osg::ref_ptr<SceneUtil::WorkQueue> workQueue)
{ {
mWorkQueue = workQueue; mWorkQueue = workQueue;

@ -27,12 +27,16 @@ namespace MWWorld
/// Removes preloaded cells that have not had a preload request for a while. /// Removes preloaded cells that have not had a preload request for a while.
void updateCache(double timestamp); void updateCache(double timestamp);
/// How long to keep a preloaded cell in cache after it's no longer requested.
void setExpiryDelay(double expiryDelay);
void setWorkQueue(osg::ref_ptr<SceneUtil::WorkQueue> workQueue); void setWorkQueue(osg::ref_ptr<SceneUtil::WorkQueue> workQueue);
private: private:
Resource::ResourceSystem* mResourceSystem; Resource::ResourceSystem* mResourceSystem;
Resource::BulletShapeManager* mBulletShapeManager; Resource::BulletShapeManager* mBulletShapeManager;
osg::ref_ptr<SceneUtil::WorkQueue> mWorkQueue; osg::ref_ptr<SceneUtil::WorkQueue> mWorkQueue;
double mExpiryDelay;
struct PreloadEntry struct PreloadEntry
{ {

@ -455,6 +455,10 @@ namespace MWWorld
, mPreloadEnabled(Settings::Manager::getBool("preload enabled", "Cells")) , mPreloadEnabled(Settings::Manager::getBool("preload enabled", "Cells"))
{ {
mPreloader.reset(new CellPreloader(rendering.getResourceSystem(), physics->getShapeManager())); mPreloader.reset(new CellPreloader(rendering.getResourceSystem(), physics->getShapeManager()));
float cacheExpiryDelay = Settings::Manager::getFloat("cache expiry delay", "Cells");
rendering.getResourceSystem()->setExpiryDelay(cacheExpiryDelay);
mPreloader->setExpiryDelay(cacheExpiryDelay);
} }
Scene::~Scene() Scene::~Scene()

@ -29,8 +29,7 @@ namespace Resource
}; };
NifFileManager::NifFileManager(const VFS::Manager *vfs) NifFileManager::NifFileManager(const VFS::Manager *vfs)
: ResourceManager(vfs, 0.0) // NIF files aren't needed any more when the converted objects are cached in SceneManager / BulletShapeManager, : ResourceManager(vfs)
// so we'll use expiryDelay of 0 to instantly delete NIF files after use.
{ {
} }

@ -5,10 +5,10 @@
namespace Resource namespace Resource
{ {
ResourceManager::ResourceManager(const VFS::Manager *vfs, const double expiryDelay) ResourceManager::ResourceManager(const VFS::Manager *vfs)
: mVFS(vfs) : mVFS(vfs)
, mCache(new Resource::ObjectCache) , mCache(new Resource::ObjectCache)
, mExpiryDelay(expiryDelay) , mExpiryDelay(0.0)
{ {
} }
@ -26,6 +26,11 @@ namespace Resource
mCache->clear(); mCache->clear();
} }
void ResourceManager::setExpiryDelay(double expiryDelay)
{
mExpiryDelay = expiryDelay;
}
const VFS::Manager* ResourceManager::getVFS() const const VFS::Manager* ResourceManager::getVFS() const
{ {
return mVFS; return mVFS;

@ -17,8 +17,7 @@ namespace Resource
class ResourceManager class ResourceManager
{ {
public: public:
/// @param expiryDelay how long to keep objects in cache after no longer being referenced. ResourceManager(const VFS::Manager* vfs);
ResourceManager(const VFS::Manager* vfs, const double expiryDelay = 300.0);
/// Clear cache entries that have not been referenced for longer than expiryDelay. /// Clear cache entries that have not been referenced for longer than expiryDelay.
virtual void updateCache(double referenceTime); virtual void updateCache(double referenceTime);
@ -26,6 +25,9 @@ namespace Resource
/// Clear all cache entries regardless of having external references. /// Clear all cache entries regardless of having external references.
virtual void clearCache(); virtual void clearCache();
/// How long to keep objects in cache after no longer being referenced.
void setExpiryDelay (double expiryDelay);
const VFS::Manager* getVFS() const; const VFS::Manager* getVFS() const;
protected: protected:

@ -52,6 +52,16 @@ namespace Resource
return mKeyframeManager.get(); return mKeyframeManager.get();
} }
void ResourceSystem::setExpiryDelay(double expiryDelay)
{
for (std::vector<ResourceManager*>::iterator it = mResourceManagers.begin(); it != mResourceManagers.end(); ++it)
(*it)->setExpiryDelay(expiryDelay);
// NIF files aren't needed any more once the converted objects are cached in SceneManager / BulletShapeManager,
// so no point in using an expiry delay
mNifFileManager->setExpiryDelay(0.0);
}
void ResourceSystem::updateCache(double referenceTime) void ResourceSystem::updateCache(double referenceTime)
{ {
for (std::vector<ResourceManager*>::iterator it = mResourceManagers.begin(); it != mResourceManagers.end(); ++it) for (std::vector<ResourceManager*>::iterator it = mResourceManagers.begin(); it != mResourceManagers.end(); ++it)

@ -43,6 +43,9 @@ namespace Resource
/// @note Does not delete resourceMgr. /// @note Does not delete resourceMgr.
void removeResourceManager(ResourceManager* resourceMgr); void removeResourceManager(ResourceManager* resourceMgr);
/// How long to keep objects in cache after no longer being referenced.
void setExpiryDelay(double expiryDelay);
/// @note May be called from any thread. /// @note May be called from any thread.
const VFS::Manager* getVFS() const; const VFS::Manager* getVFS() const;

@ -43,6 +43,10 @@ preload enabled = true
# Preloading distance threshold # Preloading distance threshold
preload distance = 1000 preload distance = 1000
# How long to keep preloaded cells and cached models/textures/collision shapes in cache
# after they're no longer referenced/required (in seconds)
cache expiry delay = 300
[Map] [Map]
# Size of each exterior cell in pixels in the world map. (e.g. 12 to 24). # Size of each exterior cell in pixels in the world map. (e.g. 12 to 24).

Loading…
Cancel
Save