Merge pull request #1406 from Aesylwinn/reloadassets

Editor: Asset Reloading
pull/280/head
scrawl 7 years ago committed by GitHub
commit aa95cb3d91

@ -5,9 +5,6 @@
#include <QLocalSocket>
#include <QMessageBox>
#include <components/vfs/manager.hpp>
#include <components/vfs/registerarchives.hpp>
#include <components/fallback/validate.hpp>
#include <components/nifosg/nifloader.hpp>
@ -33,11 +30,7 @@ CS::Editor::Editor ()
NifOsg::Loader::setShowMarkers(true);
mVFS.reset(new VFS::Manager(mFsStrict));
VFS::registerArchives(mVFS.get(), Files::Collections(config.first, !mFsStrict), config.second, true);
mDocumentManager.setVFS(mVFS.get());
mDocumentManager.setFileData(mFsStrict, config.first, config.second);
mNewGame.setLocalData (mLocal);
mFileDialog.setLocalData (mLocal);

@ -1,8 +1,6 @@
#ifndef CS_EDITOR_H
#define CS_EDITOR_H
#include <memory>
#include <boost/interprocess/sync/file_lock.hpp>
#include <boost/filesystem/fstream.hpp>
@ -30,11 +28,6 @@
#include "view/tools/merge.hpp"
namespace VFS
{
class Manager;
}
namespace CSMDoc
{
class Document;
@ -46,9 +39,6 @@ namespace CS
{
Q_OBJECT
// FIXME: should be moved to document, so we can have different resources for each opened project
std::unique_ptr<VFS::Manager> mVFS;
Files::ConfigurationManager mCfgMgr;
CSMPrefs::State mSettingsState;
CSMDoc::DocumentManager mDocumentManager;

@ -269,13 +269,14 @@ void CSMDoc::Document::createBase()
}
}
CSMDoc::Document::Document (const VFS::Manager* vfs, const Files::ConfigurationManager& configuration,
const std::vector< boost::filesystem::path >& files, bool new_,
CSMDoc::Document::Document (const Files::ConfigurationManager& configuration,
const std::vector< boost::filesystem::path >& files,bool new_,
const boost::filesystem::path& savePath, const boost::filesystem::path& resDir,
const Fallback::Map* fallback,
ToUTF8::FromType encoding, const CSMWorld::ResourcesManager& resourcesManager,
const std::vector<std::string>& blacklistedScripts)
: mVFS(vfs), mSavePath (savePath), mContentFiles (files), mNew (new_), mData (encoding, resourcesManager, fallback, resDir),
ToUTF8::FromType encoding,
const std::vector<std::string>& blacklistedScripts,
bool fsStrict, const Files::PathContainer& dataPaths, const std::vector<std::string>& archives)
: mSavePath (savePath), mContentFiles (files), mNew (new_), mData (encoding, fsStrict, dataPaths, archives, fallback, resDir),
mTools (*this, encoding),
mProjectPath ((configuration.getUserDataPath() / "projects") /
(savePath.filename().string() + ".project")),
@ -337,11 +338,6 @@ CSMDoc::Document::~Document()
{
}
const VFS::Manager *CSMDoc::Document::getVFS() const
{
return mVFS;
}
QUndoStack& CSMDoc::Document::getUndoStack()
{
return mUndoStack;

@ -9,6 +9,7 @@
#include <QObject>
#include <QTimer>
#include <components/files/multidircollection.hpp>
#include <components/to_utf8/to_utf8.hpp>
#include "../world/data.hpp"
@ -59,7 +60,6 @@ namespace CSMDoc
private:
const VFS::Manager* mVFS;
boost::filesystem::path mSavePath;
std::vector<boost::filesystem::path> mContentFiles;
bool mNew;
@ -102,17 +102,15 @@ namespace CSMDoc
public:
Document (const VFS::Manager* vfs, const Files::ConfigurationManager& configuration,
Document (const Files::ConfigurationManager& configuration,
const std::vector< boost::filesystem::path >& files, bool new_,
const boost::filesystem::path& savePath, const boost::filesystem::path& resDir,
const Fallback::Map* fallback,
ToUTF8::FromType encoding, const CSMWorld::ResourcesManager& resourcesManager,
const std::vector<std::string>& blacklistedScripts);
const Fallback::Map* fallback, ToUTF8::FromType encoding,
const std::vector<std::string>& blacklistedScripts,
bool fsStrict, const Files::PathContainer& dataPaths, const std::vector<std::string>& archives);
~Document();
const VFS::Manager* getVFS() const;
QUndoStack& getUndoStack();
int getState() const;

@ -9,7 +9,7 @@
#include "document.hpp"
CSMDoc::DocumentManager::DocumentManager (const Files::ConfigurationManager& configuration)
: mConfiguration (configuration), mEncoding (ToUTF8::WINDOWS_1252), mVFS(NULL)
: mConfiguration (configuration), mEncoding (ToUTF8::WINDOWS_1252)
{
boost::filesystem::path projectPath = configuration.getUserDataPath() / "projects";
@ -62,7 +62,7 @@ CSMDoc::Document *CSMDoc::DocumentManager::makeDocument (
const std::vector< boost::filesystem::path >& files,
const boost::filesystem::path& savePath, bool new_)
{
return new Document (mVFS, mConfiguration, files, new_, savePath, mResDir, &mFallbackMap, mEncoding, mResourcesManager, mBlacklistedScripts);
return new Document (mConfiguration, files, new_, savePath, mResDir, &mFallbackMap, mEncoding, mBlacklistedScripts, mFsStrict, mDataPaths, mArchives);
}
void CSMDoc::DocumentManager::insertDocument (CSMDoc::Document *document)
@ -127,8 +127,9 @@ void CSMDoc::DocumentManager::documentNotLoaded (Document *document, const std::
removeDocument (document);
}
void CSMDoc::DocumentManager::setVFS(const VFS::Manager *vfs)
void CSMDoc::DocumentManager::setFileData(bool strict, const Files::PathContainer& dataPaths, const std::vector<std::string>& archives)
{
mResourcesManager.setVFS(vfs);
mVFS = vfs;
mFsStrict = strict;
mDataPaths = dataPaths;
mArchives = archives;
}

@ -11,8 +11,7 @@
#include <components/to_utf8/to_utf8.hpp>
#include <components/fallback/fallback.hpp>
#include "../world/resourcesmanager.hpp"
#include <components/files/multidircollection.hpp>
#include "loader.hpp"
@ -39,9 +38,14 @@ namespace CSMDoc
QThread mLoaderThread;
Loader mLoader;
ToUTF8::FromType mEncoding;
CSMWorld::ResourcesManager mResourcesManager;
std::vector<std::string> mBlacklistedScripts;
const VFS::Manager* mVFS;
boost::filesystem::path mResDir;
Fallback::Map mFallbackMap;
bool mFsStrict;
Files::PathContainer mDataPaths;
std::vector<std::string> mArchives;
DocumentManager (const DocumentManager&);
DocumentManager& operator= (const DocumentManager&);
@ -74,15 +78,11 @@ namespace CSMDoc
void setBlacklistedScripts (const std::vector<std::string>& scriptIds);
void setVFS(const VFS::Manager* vfs);
/// Sets the file data that gets passed to newly created documents.
void setFileData(bool strict, const Files::PathContainer& dataPaths, const std::vector<std::string>& archives);
bool isEmpty();
private:
boost::filesystem::path mResDir;
Fallback::Map mFallbackMap;
private slots:
void documentLoaded (Document *document);

@ -259,6 +259,7 @@ void CSMPrefs::State::declare()
declareShortcut ("document-character-topicinfos", "Open Topic Info List", QKeySequence());
declareShortcut ("document-character-journalinfos", "Open Journal Info List", QKeySequence());
declareShortcut ("document-character-bodyparts", "Open Body Part List", QKeySequence());
declareShortcut ("document-assets-reload", "Reload Assets", QKeySequence(Qt::Key_F5));
declareShortcut ("document-assets-sounds", "Open Sound Asset List", QKeySequence());
declareShortcut ("document-assets-soundgens", "Open Sound Generator List", QKeySequence());
declareShortcut ("document-assets-meshes", "Open Mesh Asset List", QKeySequence());

@ -11,6 +11,8 @@
#include <components/esm/cellref.hpp>
#include <components/resource/scenemanager.hpp>
#include <components/vfs/manager.hpp>
#include <components/vfs/registerarchives.hpp>
#include "idtable.hpp"
#include "idtree.hpp"
@ -61,11 +63,18 @@ int CSMWorld::Data::count (RecordBase::State state, const CollectionBase& collec
return number;
}
CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourcesManager, const Fallback::Map* fallback, const boost::filesystem::path& resDir)
CSMWorld::Data::Data (ToUTF8::FromType encoding, bool fsStrict, const Files::PathContainer& dataPaths,
const std::vector<std::string>& archives, const Fallback::Map* fallback, const boost::filesystem::path& resDir)
: mEncoder (encoding), mPathgrids (mCells), mRefs (mCells),
mResourcesManager (resourcesManager), mFallbackMap(fallback),
mReader (0), mDialogue (0), mReaderIndex(1), mResourceSystem(new Resource::ResourceSystem(resourcesManager.getVFS()))
mFallbackMap(fallback), mReader (0), mDialogue (0), mReaderIndex(1),
mFsStrict(fsStrict), mDataPaths(dataPaths), mArchives(archives)
{
mVFS.reset(new VFS::Manager(mFsStrict));
VFS::registerArchives(mVFS.get(), Files::Collections(mDataPaths, !mFsStrict), mArchives, true);
mResourcesManager.setVFS(mVFS.get());
mResourceSystem.reset(new Resource::ResourceSystem(mVFS.get()));
mResourceSystem->getSceneManager()->setShaderPath((resDir / "shaders").string());
int index = 0;
@ -1215,6 +1224,43 @@ std::vector<std::string> CSMWorld::Data::getIds (bool listDeleted) const
return ids;
}
void CSMWorld::Data::assetsChanged()
{
mVFS.get()->reset();
VFS::registerArchives(mVFS.get(), Files::Collections(mDataPaths, !mFsStrict), mArchives, true);
const UniversalId assetTableIds[] = {
UniversalId::Type_Meshes,
UniversalId::Type_Icons,
UniversalId::Type_Musics,
UniversalId::Type_SoundsRes,
UniversalId::Type_Textures,
UniversalId::Type_Videos
};
size_t numAssetTables = sizeof(assetTableIds) / sizeof(UniversalId);
for (size_t i = 0; i < numAssetTables; ++i)
{
ResourceTable* table = static_cast<ResourceTable*>(getTableModel(assetTableIds[i]));
table->beginReset();
}
// Trigger recreation
mResourcesManager.recreateResources();
for (size_t i = 0; i < numAssetTables; ++i)
{
ResourceTable* table = static_cast<ResourceTable*>(getTableModel(assetTableIds[i]));
table->endReset();
}
// Get rid of potentially old cached assets
mResourceSystem->clearCache();
emit assetTablesChanged();
}
void CSMWorld::Data::dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
if (topLeft.column()<=0)
@ -1228,7 +1274,7 @@ void CSMWorld::Data::rowsChanged (const QModelIndex& parent, int start, int end)
const VFS::Manager* CSMWorld::Data::getVFS() const
{
return mResourcesManager.getVFS();
return mVFS.get();
}
const Fallback::Map* CSMWorld::Data::getFallbackMap() const

@ -31,6 +31,7 @@
#include <components/resource/resourcesystem.hpp>
#include <components/files/multidircollection.hpp>
#include <components/to_utf8/to_utf8.hpp>
#include "../doc/stage.hpp"
@ -46,6 +47,7 @@
#include "infocollection.hpp"
#include "nestedinfocollection.hpp"
#include "pathgrid.hpp"
#include "resourcesmanager.hpp"
#include "metadata.hpp"
#ifndef Q_MOC_RUN
#include "subcellcollection.hpp"
@ -108,7 +110,6 @@ namespace CSMWorld
RefCollection mRefs;
IdCollection<ESM::Filter> mFilters;
Collection<MetaData> mMetaData;
const ResourcesManager& mResourcesManager;
const Fallback::Map* mFallbackMap;
std::vector<QAbstractItemModel *> mModels;
std::map<UniversalId::Type, QAbstractItemModel *> mModelIndex;
@ -119,6 +120,11 @@ namespace CSMWorld
std::map<std::string, std::map<ESM::RefNum, std::string> > mRefLoadCache;
int mReaderIndex;
bool mFsStrict;
Files::PathContainer mDataPaths;
std::vector<std::string> mArchives;
std::unique_ptr<VFS::Manager> mVFS;
ResourcesManager mResourcesManager;
std::shared_ptr<Resource::ResourceSystem> mResourceSystem;
std::vector<std::shared_ptr<ESM::ESMReader> > mReaders;
@ -140,7 +146,9 @@ namespace CSMWorld
public:
Data (ToUTF8::FromType encoding, const ResourcesManager& resourcesManager, const Fallback::Map* fallback, const boost::filesystem::path& resDir);
Data (ToUTF8::FromType encoding, bool fsStrict, const Files::PathContainer& dataPaths,
const std::vector<std::string>& archives, const Fallback::Map* fallback,
const boost::filesystem::path& resDir);
virtual ~Data();
@ -304,8 +312,12 @@ namespace CSMWorld
void idListChanged();
void assetTablesChanged();
private slots:
void assetsChanged();
void dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
void rowsChanged (const QModelIndex& parent, int start, int end);

@ -12,6 +12,14 @@ CSMWorld::Resources::Resources (const VFS::Manager* vfs, const std::string& base
const char * const *extensions)
: mBaseDirectory (baseDirectory), mType (type)
{
recreate(vfs, extensions);
}
void CSMWorld::Resources::recreate(const VFS::Manager* vfs, const char * const *extensions)
{
mFiles.clear();
mIndex.clear();
int baseSize = mBaseDirectory.size();
const std::map<std::string, VFS::File*>& index = vfs->getIndex();

@ -27,6 +27,8 @@ namespace CSMWorld
Resources (const VFS::Manager* vfs, const std::string& baseDirectory, UniversalId::Type type,
const char * const *extensions = 0);
void recreate(const VFS::Manager* vfs, const char * const *extensions = 0);
int getSize() const;
std::string getId (int index) const;

@ -14,16 +14,19 @@ void CSMWorld::ResourcesManager::addResources (const Resources& resources)
resources));
}
const char * const * CSMWorld::ResourcesManager::getMeshExtensions()
{
// maybe we could go over the osgDB::Registry to list all supported node formats
static const char * const sMeshTypes[] = { "nif", "osg", "osgt", "osgb", "osgx", "osg2", 0 };
return sMeshTypes;
}
void CSMWorld::ResourcesManager::setVFS(const VFS::Manager *vfs)
{
mVFS = vfs;
mResources.clear();
// maybe we could go over the osgDB::Registry to list all supported node formats
static const char * const sMeshTypes[] = { "nif", "osg", "osgt", "osgb", "osgx", "osg2", 0 };
addResources (Resources (vfs, "meshes", UniversalId::Type_Mesh, sMeshTypes));
addResources (Resources (vfs, "meshes", UniversalId::Type_Mesh, getMeshExtensions()));
addResources (Resources (vfs, "icons", UniversalId::Type_Icon));
addResources (Resources (vfs, "music", UniversalId::Type_Music));
addResources (Resources (vfs, "sound", UniversalId::Type_SoundRes));
@ -36,6 +39,18 @@ const VFS::Manager* CSMWorld::ResourcesManager::getVFS() const
return mVFS;
}
void CSMWorld::ResourcesManager::recreateResources()
{
std::map<UniversalId::Type, Resources>::iterator it = mResources.begin();
for ( ; it != mResources.end(); ++it)
{
if (it->first == UniversalId::Type_Mesh)
it->second.recreate(mVFS, getMeshExtensions());
else
it->second.recreate(mVFS);
}
}
const CSMWorld::Resources& CSMWorld::ResourcesManager::get (UniversalId::Type type) const
{
std::map<UniversalId::Type, Resources>::const_iterator iter = mResources.find (type);

@ -22,6 +22,8 @@ namespace CSMWorld
void addResources (const Resources& resources);
const char * const * getMeshExtensions();
public:
ResourcesManager();
@ -30,6 +32,8 @@ namespace CSMWorld
void setVFS(const VFS::Manager* vfs);
void recreateResources();
const Resources& get (UniversalId::Type type) const;
};
}

@ -154,3 +154,13 @@ int CSMWorld::ResourceTable::getColumnId (int column) const
return -1;
}
void CSMWorld::ResourceTable::beginReset()
{
beginResetModel();
}
void CSMWorld::ResourceTable::endReset()
{
endResetModel();
}

@ -52,7 +52,12 @@ namespace CSMWorld
/// Is \a id flagged as deleted?
virtual bool isDeleted (const std::string& id) const;
virtual int getColumnId (int column) const;
virtual int getColumnId (int column) const;
/// Signal Qt that the data is about to change.
void beginReset();
/// Signal Qt that the data has been changed.
void endReset();
};
}

@ -284,6 +284,13 @@ void CSVDoc::View::setupAssetsMenu()
{
QMenu *assets = menuBar()->addMenu (tr ("Assets"));
QAction *reload = new QAction (tr ("Reload"), this);
connect (reload, SIGNAL (triggered()), &mDocument->getData(), SLOT (assetsChanged()));
setupShortcut("document-assets-reload", reload);
assets->addAction (reload);
assets->addSeparator();
QAction *sounds = new QAction (tr ("Sounds"), this);
connect (sounds, SIGNAL (triggered()), this, SLOT (addSoundsSubView()));
setupShortcut("document-assets-sounds", sounds);

@ -283,6 +283,24 @@ void CSVRender::Cell::pathgridRemoved()
mPathgrid->removeGeometry();
}
void CSVRender::Cell::reloadAssets()
{
for (std::map<std::string, Object *>::const_iterator iter (mObjects.begin());
iter != mObjects.end(); ++iter)
{
iter->second->reloadAssets();
}
if (mTerrain)
{
mTerrain->unloadCell(mCoordinates.getX(), mCoordinates.getY());
mTerrain->loadCell(mCoordinates.getX(), mCoordinates.getY());
}
if (mCellWater)
mCellWater->reloadAssets();
}
void CSVRender::Cell::setSelection (int elementMask, Selection mode)
{
if (elementMask & Mask_Reference)

@ -118,6 +118,8 @@ namespace CSVRender
void pathgridRemoved();
void reloadAssets();
void setSelection (int elementMask, Selection mode);
// Select everything that references the same ID as at least one of the elements

@ -92,6 +92,11 @@ namespace CSVRender
}
}
void CellWater::reloadAssets()
{
recreate();
}
void CellWater::cellDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
const CSMWorld::Collection<CSMWorld::Cell>& cells = mData.getCells();

@ -42,6 +42,8 @@ namespace CSVRender
void updateCellData(const CSMWorld::Record<CSMWorld::Cell>& cellRecord);
void reloadAssets();
private slots:
void cellDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);

@ -532,6 +532,12 @@ bool CSVRender::Object::referenceDataChanged (const QModelIndex& topLeft,
return false;
}
void CSVRender::Object::reloadAssets()
{
update();
updateMarker();
}
std::string CSVRender::Object::getReferenceId() const
{
return mReferenceId;

@ -151,6 +151,9 @@ namespace CSVRender
/// this object?
bool referenceDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
/// Reloads the underlying asset
void reloadAssets();
/// Returns an empty string if this is a refereceable-type object.
std::string getReferenceId() const;

@ -472,6 +472,9 @@ CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget* parent, CSMDoc
connect (cells, SIGNAL (rowsInserted (const QModelIndex&, int, int)),
this, SLOT (cellAdded (const QModelIndex&, int, int)));
connect (&document.getData(), SIGNAL (assetTablesChanged ()),
this, SLOT (assetTablesChanged ()));
// Shortcuts
CSMPrefs::Shortcut* loadCameraCellShortcut = new CSMPrefs::Shortcut("scene-load-cam-cell", this);
connect(loadCameraCellShortcut, SIGNAL(activated()), this, SLOT(loadCameraCell()));
@ -520,7 +523,7 @@ void CSVRender::PagedWorldspaceWidget::useViewHint (const std::string& hint)
// Loop through all the coordinates to add them to selection
while (stream >> ignore1 >> ignore2 >> x >> y)
selection.add (CSMWorld::CellCoordinates (x, y));
// Mark that camera needs setup
mCamPositionSet=false;
}
@ -763,6 +766,15 @@ void CSVRender::PagedWorldspaceWidget::cellAdded (const QModelIndex& index, int
flagAsModified();
}
void CSVRender::PagedWorldspaceWidget::assetTablesChanged()
{
std::map<CSMWorld::CellCoordinates, Cell *>::iterator iter = mCells.begin();
for ( ; iter != mCells.end(); ++iter)
{
iter->second->reloadAssets();
}
}
void CSVRender::PagedWorldspaceWidget::loadCameraCell()
{
addCellToSceneFromCamera(0, 0);

@ -84,7 +84,7 @@ namespace CSVRender
/// hint system.
virtual ~PagedWorldspaceWidget();
/// Decodes the the hint string to set of cell that are rendered.
void useViewHint (const std::string& hint);
@ -155,6 +155,8 @@ namespace CSVRender
virtual void cellAdded (const QModelIndex& index, int start, int end);
void assetTablesChanged ();
void loadCameraCell();
void loadEastCell();

@ -17,6 +17,9 @@ CSVRender::PreviewWidget::PreviewWidget (CSMWorld::Data& data,
connect (referenceables, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
this, SLOT (referenceableAboutToBeRemoved (const QModelIndex&, int, int)));
connect (&mData, SIGNAL (assetTablesChanged ()),
this, SLOT (assetTablesChanged ()));
if (!referenceable)
{
QAbstractItemModel *references =
@ -119,3 +122,8 @@ void CSVRender::PreviewWidget::referenceAboutToBeRemoved (const QModelIndex& par
if (index.row()>=start && index.row()<=end)
emit closeRequest();
}
void CSVRender::PreviewWidget::assetTablesChanged ()
{
mObject.reloadAssets();
}

@ -47,6 +47,8 @@ namespace CSVRender
void referenceDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
void referenceAboutToBeRemoved (const QModelIndex& parent, int start, int end);
void assetTablesChanged ();
};
}

@ -47,6 +47,9 @@ CSVRender::UnpagedWorldspaceWidget::UnpagedWorldspaceWidget (const std::string&
connect (mCellsModel, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
this, SLOT (cellRowsAboutToBeRemoved (const QModelIndex&, int, int)));
connect (&document.getData(), SIGNAL (assetTablesChanged ()),
this, SLOT (assetTablesChanged ()));
update();
mCell.reset (new Cell (document.getData(), mRootNode, mCellId));
@ -82,6 +85,12 @@ void CSVRender::UnpagedWorldspaceWidget::cellRowsAboutToBeRemoved (const QModelI
emit closeRequest();
}
void CSVRender::UnpagedWorldspaceWidget::assetTablesChanged()
{
if (mCell)
mCell->reloadAssets();
}
bool CSVRender::UnpagedWorldspaceWidget::handleDrop (const std::vector<CSMWorld::UniversalId>& universalIdData, DropType type)
{
if (WorldspaceWidget::handleDrop (universalIdData, type))

@ -108,6 +108,8 @@ namespace CSVRender
void cellRowsAboutToBeRemoved (const QModelIndex& parent, int start, int end);
void assetTablesChanged ();
signals:
void cellChanged(const CSMWorld::UniversalId& id);

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

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

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

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

@ -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);

@ -68,6 +68,12 @@ namespace Resource
(*it)->updateCache(referenceTime);
}
void ResourceSystem::clearCache()
{
for (std::vector<ResourceManager*>::iterator it = mResourceManagers.begin(); it != mResourceManagers.end(); ++it)
(*it)->clearCache();
}
void ResourceSystem::addResourceManager(ResourceManager *resourceMgr)
{
mResourceManagers.push_back(resourceMgr);

@ -41,6 +41,10 @@ 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.
/// @note May be called from any thread if you do not add or remove resource managers at that point.
void clearCache();
/// Add this ResourceManager to be handled by the ResourceSystem.
/// @note Does not transfer ownership.
void addResourceManager(ResourceManager* resourceMgr);

@ -122,6 +122,13 @@ namespace Resource
{
return _sharedStateSetList.size();
}
void clearCache()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_listMutex);
_sharedTextureList.clear();
_sharedStateSetList.clear();
}
};
/// Set texture filtering settings on textures contained in a FlipController.
@ -710,6 +717,15 @@ namespace Resource
mSharedStateMutex.unlock();
}
void SceneManager::clearCache()
{
ResourceManager::clearCache();
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mSharedStateMutex);
mSharedStateManager->clearCache();
mInstanceCache->clear();
}
void SceneManager::reportStats(unsigned int frameNumber, osg::Stats *stats) const
{
{

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

@ -231,4 +231,16 @@ namespace Terrain
return buffer;
}
void BufferCache::clearCache()
{
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mIndexBufferMutex);
mIndexBufferMap.clear();
}
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mUvBufferMutex);
mUvBufferMap.clear();
}
}
}

@ -22,6 +22,8 @@ namespace Terrain
/// @note Thread safe.
osg::ref_ptr<osg::Vec2Array> getUVBuffer(unsigned int numVerts);
void clearCache();
// TODO: add releaseGLObjects() for our vertex/element buffer objects
private:

@ -55,6 +55,13 @@ void ChunkManager::reportStats(unsigned int frameNumber, osg::Stats *stats) cons
stats->setAttribute(frameNumber, "Terrain Chunk", mCache->getCacheSize());
}
void ChunkManager::clearCache()
{
ResourceManager::clearCache();
mBufferCache.clearCache();
}
void ChunkManager::setCullingActive(bool active)
{
mCullingActive = active;

@ -34,6 +34,8 @@ namespace Terrain
virtual void reportStats(unsigned int frameNumber, osg::Stats* stats) const;
virtual void clearCache();
void setCullingActive(bool active);
private:

@ -39,6 +39,12 @@ namespace VFS
Manager::~Manager()
{
reset();
}
void Manager::reset()
{
mIndex.clear();
for (std::vector<Archive*>::iterator it = mArchives.begin(); it != mArchives.end(); ++it)
delete *it;
mArchives.clear();

@ -26,6 +26,9 @@ namespace VFS
~Manager();
// Empty the file index and unregister archives.
void reset();
/// Register the given archive. All files contained in it will be added to the index on the next buildIndex() call.
/// @note Takes ownership of the given pointer.
void addArchive(Archive* archive);

Loading…
Cancel
Save