mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 09:39:40 +00:00
Add Nif::FileView as read only interface for Nif::NIFFile
To make sure interface is scoped to what users require.
This commit is contained in:
parent
f2fb3d6de8
commit
c338c1e5d3
7 changed files with 45 additions and 33 deletions
|
@ -51,28 +51,40 @@ namespace Nif
|
|||
: mPath(path)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class FileView
|
||||
{
|
||||
public:
|
||||
FileView(const NIFFile& file)
|
||||
: mFile(&file)
|
||||
{
|
||||
}
|
||||
|
||||
/// Get a given root
|
||||
Record* getRoot(size_t index = 0) const { return mRoots.at(index); }
|
||||
const Record* getRoot(std::size_t index) const { return mFile->mRoots.at(index); }
|
||||
|
||||
/// Number of roots
|
||||
std::size_t numRoots() const { return mRoots.size(); }
|
||||
std::size_t numRoots() const { return mFile->mRoots.size(); }
|
||||
|
||||
/// Get the name of the file
|
||||
const std::filesystem::path& getFilename() const { return mPath; }
|
||||
const std::filesystem::path& getFilename() const { return mFile->mPath; }
|
||||
|
||||
const std::string& getHash() const { return mHash; }
|
||||
const std::string& getHash() const { return mFile->mHash; }
|
||||
|
||||
/// Get the version of the NIF format used
|
||||
unsigned int getVersion() const { return mVersion; }
|
||||
unsigned int getVersion() const { return mFile->mVersion; }
|
||||
|
||||
/// Get the user version of the NIF format used
|
||||
unsigned int getUserVersion() const { return mUserVersion; }
|
||||
unsigned int getUserVersion() const { return mFile->mUserVersion; }
|
||||
|
||||
/// Get the Bethesda version of the NIF format used
|
||||
unsigned int getBethVersion() const { return mBethVersion; }
|
||||
unsigned int getBethVersion() const { return mFile->mBethVersion; }
|
||||
|
||||
bool getUseSkinning() const { return mUseSkinning; }
|
||||
bool getUseSkinning() const { return mFile->mUseSkinning; }
|
||||
|
||||
private:
|
||||
const NIFFile* mFile;
|
||||
};
|
||||
|
||||
class Reader
|
||||
|
|
|
@ -160,7 +160,7 @@ namespace
|
|||
namespace NifBullet
|
||||
{
|
||||
|
||||
osg::ref_ptr<Resource::BulletShape> BulletNifLoader::load(const Nif::NIFFile& nif)
|
||||
osg::ref_ptr<Resource::BulletShape> BulletNifLoader::load(Nif::FileView nif)
|
||||
{
|
||||
mShape = new Resource::BulletShape;
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace NifBullet
|
|||
abort();
|
||||
}
|
||||
|
||||
osg::ref_ptr<Resource::BulletShape> load(const Nif::NIFFile& file);
|
||||
osg::ref_ptr<Resource::BulletShape> load(Nif::FileView file);
|
||||
|
||||
private:
|
||||
bool findBoundingBox(const Nif::Node& node, const std::string& filename);
|
||||
|
|
|
@ -250,13 +250,13 @@ namespace NifOsg
|
|||
// This is used to queue emitters that weren't attached to their node yet.
|
||||
std::vector<std::pair<size_t, osg::ref_ptr<Emitter>>> mEmitterQueue;
|
||||
|
||||
void loadKf(Nif::NIFFilePtr nif, SceneUtil::KeyframeHolder& target) const
|
||||
void loadKf(Nif::FileView nif, SceneUtil::KeyframeHolder& target) const
|
||||
{
|
||||
const Nif::NiSequenceStreamHelper* seq = nullptr;
|
||||
const size_t numRoots = nif->numRoots();
|
||||
const size_t numRoots = nif.numRoots();
|
||||
for (size_t i = 0; i < numRoots; ++i)
|
||||
{
|
||||
const Nif::Record* r = nif->getRoot(i);
|
||||
const Nif::Record* r = nif.getRoot(i);
|
||||
if (r && r->recType == Nif::RC_NiSequenceStreamHelper)
|
||||
{
|
||||
seq = static_cast<const Nif::NiSequenceStreamHelper*>(r);
|
||||
|
@ -267,7 +267,7 @@ namespace NifOsg
|
|||
if (!seq)
|
||||
{
|
||||
Log(Debug::Warning) << "NIFFile Warning: Found no NiSequenceStreamHelper root record. File: "
|
||||
<< nif->getFilename();
|
||||
<< nif.getFilename();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -276,7 +276,7 @@ namespace NifOsg
|
|||
{
|
||||
Log(Debug::Warning) << "NIFFile Warning: First extra data was not a NiTextKeyExtraData, but a "
|
||||
<< (extra.empty() ? std::string_view("nil") : std::string_view(extra->recName))
|
||||
<< ". File: " << nif->getFilename();
|
||||
<< ". File: " << nif.getFilename();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -289,7 +289,7 @@ namespace NifOsg
|
|||
if (extra->recType != Nif::RC_NiStringExtraData || ctrl->recType != Nif::RC_NiKeyframeController)
|
||||
{
|
||||
Log(Debug::Warning) << "NIFFile Warning: Unexpected extra data " << extra->recName
|
||||
<< " with controller " << ctrl->recName << ". File: " << nif->getFilename();
|
||||
<< " with controller " << ctrl->recName << ". File: " << nif.getFilename();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -314,17 +314,17 @@ namespace NifOsg
|
|||
|
||||
if (!target.mKeyframeControllers.emplace(strdata->string, callback).second)
|
||||
Log(Debug::Verbose) << "Controller " << strdata->string << " present more than once in "
|
||||
<< nif->getFilename() << ", ignoring later version";
|
||||
<< nif.getFilename() << ", ignoring later version";
|
||||
}
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Node> load(Nif::NIFFilePtr nif, Resource::ImageManager* imageManager)
|
||||
osg::ref_ptr<osg::Node> load(Nif::FileView nif, Resource::ImageManager* imageManager)
|
||||
{
|
||||
const size_t numRoots = nif->numRoots();
|
||||
const size_t numRoots = nif.numRoots();
|
||||
std::vector<const Nif::Node*> roots;
|
||||
for (size_t i = 0; i < numRoots; ++i)
|
||||
{
|
||||
const Nif::Record* r = nif->getRoot(i);
|
||||
const Nif::Record* r = nif.getRoot(i);
|
||||
if (!r)
|
||||
continue;
|
||||
const Nif::Node* nifNode = dynamic_cast<const Nif::Node*>(r);
|
||||
|
@ -332,7 +332,7 @@ namespace NifOsg
|
|||
roots.emplace_back(nifNode);
|
||||
}
|
||||
if (roots.empty())
|
||||
throw Nif::Exception("Found no root nodes", nif->getFilename());
|
||||
throw Nif::Exception("Found no root nodes", nif.getFilename());
|
||||
|
||||
osg::ref_ptr<SceneUtil::TextKeyMapHolder> textkeys(new SceneUtil::TextKeyMapHolder);
|
||||
|
||||
|
@ -352,7 +352,7 @@ namespace NifOsg
|
|||
// Attach particle emitters to their nodes which should all be loaded by now.
|
||||
handleQueuedParticleEmitters(created, nif);
|
||||
|
||||
if (nif->getUseSkinning())
|
||||
if (nif.getUseSkinning())
|
||||
{
|
||||
osg::ref_ptr<SceneUtil::Skeleton> skel = new SceneUtil::Skeleton;
|
||||
skel->setStateSet(created->getStateSet());
|
||||
|
@ -366,7 +366,7 @@ namespace NifOsg
|
|||
if (!textkeys->mTextKeys.empty())
|
||||
created->getOrCreateUserDataContainer()->addUserObject(textkeys);
|
||||
|
||||
created->setUserValue(Misc::OsgUserValues::sFileHash, nif->getHash());
|
||||
created->setUserValue(Misc::OsgUserValues::sFileHash, nif.getHash());
|
||||
|
||||
return created;
|
||||
}
|
||||
|
@ -1192,7 +1192,7 @@ namespace NifOsg
|
|||
return emitter;
|
||||
}
|
||||
|
||||
void handleQueuedParticleEmitters(osg::Group* rootNode, Nif::NIFFilePtr nif)
|
||||
void handleQueuedParticleEmitters(osg::Group* rootNode, Nif::FileView nif)
|
||||
{
|
||||
for (const auto& emitterPair : mEmitterQueue)
|
||||
{
|
||||
|
@ -1204,7 +1204,7 @@ namespace NifOsg
|
|||
{
|
||||
Log(Debug::Warning)
|
||||
<< "NIFFile Warning: Failed to find particle emitter emitter node (node record index "
|
||||
<< recIndex << "). File: " << nif->getFilename();
|
||||
<< recIndex << "). File: " << nif.getFilename();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -2500,15 +2500,15 @@ namespace NifOsg
|
|||
}
|
||||
};
|
||||
|
||||
osg::ref_ptr<osg::Node> Loader::load(Nif::NIFFilePtr file, Resource::ImageManager* imageManager)
|
||||
osg::ref_ptr<osg::Node> Loader::load(Nif::FileView file, Resource::ImageManager* imageManager)
|
||||
{
|
||||
LoaderImpl impl(file->getFilename(), file->getVersion(), file->getUserVersion(), file->getBethVersion());
|
||||
LoaderImpl impl(file.getFilename(), file.getVersion(), file.getUserVersion(), file.getBethVersion());
|
||||
return impl.load(file, imageManager);
|
||||
}
|
||||
|
||||
void Loader::loadKf(Nif::NIFFilePtr kf, SceneUtil::KeyframeHolder& target)
|
||||
void Loader::loadKf(Nif::FileView kf, SceneUtil::KeyframeHolder& target)
|
||||
{
|
||||
LoaderImpl impl(kf->getFilename(), kf->getVersion(), kf->getUserVersion(), kf->getBethVersion());
|
||||
LoaderImpl impl(kf.getFilename(), kf.getVersion(), kf.getUserVersion(), kf.getBethVersion());
|
||||
impl.loadKf(kf, target);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,10 +28,10 @@ namespace NifOsg
|
|||
public:
|
||||
/// Create a scene graph for the given NIF. Auto-detects when skinning is used and wraps the graph in a Skeleton
|
||||
/// if so.
|
||||
static osg::ref_ptr<osg::Node> load(Nif::NIFFilePtr file, Resource::ImageManager* imageManager);
|
||||
static osg::ref_ptr<osg::Node> load(Nif::FileView file, Resource::ImageManager* imageManager);
|
||||
|
||||
/// Load keyframe controllers from the given kf file.
|
||||
static void loadKf(Nif::NIFFilePtr kf, SceneUtil::KeyframeHolder& target);
|
||||
static void loadKf(Nif::FileView kf, SceneUtil::KeyframeHolder& target);
|
||||
|
||||
/// Set whether or not nodes marked as "MRK" should be shown.
|
||||
/// These should be hidden ingame, but visible in the editor.
|
||||
|
|
|
@ -159,7 +159,7 @@ namespace Resource
|
|||
auto file = std::make_shared<Nif::NIFFile>(normalized);
|
||||
Nif::Reader reader(*file);
|
||||
reader.parse(mVFS->getNormalized(normalized));
|
||||
NifOsg::Loader::loadKf(std::move(file), *loaded.get());
|
||||
NifOsg::Loader::loadKf(*file, *loaded.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -714,7 +714,7 @@ namespace Resource
|
|||
{
|
||||
auto ext = Misc::getFileExtension(normalizedFilename);
|
||||
if (ext == "nif")
|
||||
return NifOsg::Loader::load(nifFileManager->get(normalizedFilename), imageManager);
|
||||
return NifOsg::Loader::load(*nifFileManager->get(normalizedFilename), imageManager);
|
||||
else
|
||||
return loadNonNif(normalizedFilename, *vfs->get(normalizedFilename), imageManager);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue