Skip to content

Commit

Permalink
Merge pull request OpenMW#1406 from Aesylwinn/reloadassets
Browse files Browse the repository at this point in the history
Editor: Asset Reloading
  • Loading branch information
scrawl authored Aug 22, 2017
2 parents 13ccc73 + d3d0417 commit aa95cb3
Show file tree
Hide file tree
Showing 44 changed files with 309 additions and 64 deletions.
9 changes: 1 addition & 8 deletions apps/opencs/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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);
Expand Down
10 changes: 0 additions & 10 deletions apps/opencs/editor.hpp
Original file line number Diff line number Diff line change
@@ -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>

Expand Down Expand Up @@ -30,11 +28,6 @@

#include "view/tools/merge.hpp"

namespace VFS
{
class Manager;
}

namespace CSMDoc
{
class Document;
Expand All @@ -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;
Expand Down
16 changes: 6 additions & 10 deletions apps/opencs/model/doc/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down Expand Up @@ -337,11 +338,6 @@ CSMDoc::Document::~Document()
{
}

const VFS::Manager *CSMDoc::Document::getVFS() const
{
return mVFS;
}

QUndoStack& CSMDoc::Document::getUndoStack()
{
return mUndoStack;
Expand Down
12 changes: 5 additions & 7 deletions apps/opencs/model/doc/document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QObject>
#include <QTimer>

#include <components/files/multidircollection.hpp>
#include <components/to_utf8/to_utf8.hpp>

#include "../world/data.hpp"
Expand Down Expand Up @@ -59,7 +60,6 @@ namespace CSMDoc

private:

const VFS::Manager* mVFS;
boost::filesystem::path mSavePath;
std::vector<boost::filesystem::path> mContentFiles;
bool mNew;
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 6 additions & 5 deletions apps/opencs/model/doc/documentmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
20 changes: 10 additions & 10 deletions apps/opencs/model/doc/documentmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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&);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions apps/opencs/model/prefs/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
54 changes: 50 additions & 4 deletions apps/opencs/model/world/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
16 changes: 14 additions & 2 deletions apps/opencs/model/world/data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions apps/opencs/model/world/resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions apps/opencs/model/world/resources.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit aa95cb3

Please sign in to comment.