Code cleanup and more cache clearing

experimental
Kyle Cooley 7 years ago
parent 679a284735
commit 979b0d7211

@ -1220,29 +1220,31 @@ void CSMWorld::Data::assetsChanged()
{ {
mVFS->rebuildIndex(); mVFS->rebuildIndex();
ResourceTable* meshTable = static_cast<ResourceTable*>(getTableModel(UniversalId::Type_Meshes)); const UniversalId assetTableIds[] = {
ResourceTable* iconTable = static_cast<ResourceTable*>(getTableModel(UniversalId::Type_Icons)); UniversalId::Type_Meshes,
ResourceTable* musicTable = static_cast<ResourceTable*>(getTableModel(UniversalId::Type_Musics)); UniversalId::Type_Icons,
ResourceTable* soundResTable = static_cast<ResourceTable*>(getTableModel(UniversalId::Type_SoundsRes)); UniversalId::Type_Musics,
ResourceTable* texTable = static_cast<ResourceTable*>(getTableModel(UniversalId::Type_Textures)); UniversalId::Type_SoundsRes,
ResourceTable* vidTable = static_cast<ResourceTable*>(getTableModel(UniversalId::Type_Videos)); UniversalId::Type_Textures,
UniversalId::Type_Videos
meshTable->beginReset(); };
iconTable->beginReset();
musicTable->beginReset(); size_t numAssetTables = sizeof(assetTableIds) / sizeof(UniversalId);
soundResTable->beginReset();
texTable->beginReset(); for (size_t i = 0; i < numAssetTables; ++i)
vidTable->beginReset(); {
ResourceTable* table = static_cast<ResourceTable*>(getTableModel(assetTableIds[i]));
table->beginReset();
}
// Trigger recreation // Trigger recreation
mResourcesManager.recreateResources(); mResourcesManager.recreateResources();
meshTable->endReset(); for (size_t i = 0; i < numAssetTables; ++i)
iconTable->endReset(); {
musicTable->endReset(); ResourceTable* table = static_cast<ResourceTable*>(getTableModel(assetTableIds[i]));
soundResTable->endReset(); table->endReset();
texTable->endReset(); }
vidTable->endReset();
// Get rid of potentially old cached assets // Get rid of potentially old cached assets
mResourceSystem->clearCache(); mResourceSystem->clearCache();

@ -896,7 +896,6 @@ void CSVDoc::View::addMetaDataSubView()
addSubView (CSMWorld::UniversalId (CSMWorld::UniversalId::Type_MetaData, "sys::meta")); addSubView (CSMWorld::UniversalId (CSMWorld::UniversalId::Type_MetaData, "sys::meta"));
} }
void CSVDoc::View::abortOperation (int type) void CSVDoc::View::abortOperation (int type)
{ {
mDocument->abortOperation (type); mDocument->abortOperation (type);

@ -294,7 +294,6 @@ void CSVRender::Cell::reloadAssets()
if (mTerrain) if (mTerrain)
{ {
mTerrain->unloadCell(mCoordinates.getX(), mCoordinates.getY()); mTerrain->unloadCell(mCoordinates.getX(), mCoordinates.getY());
mTerrain->clearCache();
mTerrain->loadCell(mCoordinates.getX(), mCoordinates.getY()); mTerrain->loadCell(mCoordinates.getX(), mCoordinates.getY());
} }

@ -190,6 +190,13 @@ void BulletShapeManager::updateCache(double referenceTime)
mInstanceCache->removeUnreferencedObjectsInCache(); mInstanceCache->removeUnreferencedObjectsInCache();
} }
void BulletShapeManager::clearCache()
{
ResourceManager::clearCache();
mInstanceCache->clear();
}
void BulletShapeManager::reportStats(unsigned int frameNumber, osg::Stats *stats) const void BulletShapeManager::reportStats(unsigned int frameNumber, osg::Stats *stats) const
{ {
stats->setAttribute(frameNumber, "Shape", mCache->getCacheSize()); stats->setAttribute(frameNumber, "Shape", mCache->getCacheSize());

@ -42,6 +42,8 @@ namespace Resource
/// @see ResourceManager::updateCache /// @see ResourceManager::updateCache
virtual void updateCache(double referenceTime); virtual void updateCache(double referenceTime);
virtual void clearCache();
void reportStats(unsigned int frameNumber, osg::Stats *stats) const; void reportStats(unsigned int frameNumber, osg::Stats *stats) const;
private: private:

@ -43,6 +43,12 @@ namespace Resource
objectsToRemove.clear(); objectsToRemove.clear();
} }
void MultiObjectCache::clear()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex);
_objectCache.clear();
}
void MultiObjectCache::addEntryToObjectCache(const std::string &filename, osg::Object *object) void MultiObjectCache::addEntryToObjectCache(const std::string &filename, osg::Object *object)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex);

@ -25,6 +25,9 @@ namespace Resource
void removeUnreferencedObjectsInCache(); void removeUnreferencedObjectsInCache();
/** Remove all objects from the cache. */
void clear();
void addEntryToObjectCache(const std::string& filename, osg::Object* object); void addEntryToObjectCache(const std::string& filename, osg::Object* object);
/** Take an Object from cache. Return NULL if no object found. */ /** Take an Object from cache. Return NULL if no object found. */

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

@ -723,6 +723,7 @@ namespace Resource
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mSharedStateMutex); OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mSharedStateMutex);
mSharedStateManager->clearCache(); mSharedStateManager->clearCache();
mInstanceCache->clear();
} }
void SceneManager::reportStats(unsigned int frameNumber, osg::Stats *stats) const void SceneManager::reportStats(unsigned int frameNumber, osg::Stats *stats) const

@ -70,12 +70,6 @@ float World::getHeightAt(const osg::Vec3f &worldPos)
return mStorage->getHeightAt(worldPos); return mStorage->getHeightAt(worldPos);
} }
void World::clearCache()
{
mTextureManager->clearCache();
mChunkManager->clearCache();
}
void World::updateTextureFiltering() void World::updateTextureFiltering()
{ {
mTextureManager->updateTextureFiltering(); mTextureManager->updateTextureFiltering();

@ -67,9 +67,6 @@ namespace Terrain
/// @note Thread safe. /// @note Thread safe.
virtual void cacheCell(View* view, int x, int y) {} virtual void cacheCell(View* view, int x, int y) {}
/// Clears cached texture and chunk data.
virtual void clearCache();
/// Load the cell into the scene graph. /// Load the cell into the scene graph.
/// @note Not thread safe. /// @note Not thread safe.
/// @note May be ignored by derived implementations that don't organize the terrain into cells. /// @note May be ignored by derived implementations that don't organize the terrain into cells.

Loading…
Cancel
Save