Clear cached resources

experimental
Kyle Cooley 7 years ago
parent d31ed83b54
commit 742bd00ec6

@ -1244,6 +1244,9 @@ void CSMWorld::Data::assetsChanged()
soundResTable->endReset();
texTable->endReset();
vidTable->endReset();
// Get rid of potentially old cached assets
mResourceSystem->clearCache();
}
void CSMWorld::Data::dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight)

@ -23,6 +23,11 @@ namespace Resource
mCache->removeExpiredObjectsInCache(referenceTime - mExpiryDelay);
}
void ResourceManager::clearCache()
{
mCache->clear();
}
void ResourceManager::setExpiryDelay(double expiryDelay)
{
mExpiryDelay = expiryDelay;

@ -28,6 +28,9 @@ namespace Resource
/// Clear cache entries that have not been referenced for longer than expiryDelay.
virtual void updateCache(double referenceTime);
/// Clear all cache entries.
virtual void clearCache();
/// How long to keep objects in cache after no longer being referenced.
void setExpiryDelay (double expiryDelay);

@ -2,6 +2,8 @@
#include <algorithm>
#include <osgDB/Registry>
#include "scenemanager.hpp"
#include "imagemanager.hpp"
#include "niffilemanager.hpp"
@ -68,6 +70,14 @@ namespace Resource
(*it)->updateCache(referenceTime);
}
void ResourceSystem::clearCache()
{
for (std::vector<ResourceManager*>::iterator it = mResourceManagers.begin(); it != mResourceManagers.end(); ++it)
(*it)->clearCache();
osgDB::Registry::instance()->clearObjectCache();
}
void ResourceSystem::addResourceManager(ResourceManager *resourceMgr)
{
mResourceManagers.push_back(resourceMgr);

@ -41,6 +41,9 @@ namespace Resource
/// @note May be called from any thread if you do not add or remove resource managers at that point.
void updateCache(double referenceTime);
/// Indicates to each resource manager to clear the entire cache.
void clearCache();
/// Add this ResourceManager to be handled by the ResourceSystem.
/// @note Does not transfer ownership.
void addResourceManager(ResourceManager* resourceMgr);

Loading…
Cancel
Save