Skip to content

Commit

Permalink
Merge branch 'lessgoofymaterialptr' into 'master'
Browse files Browse the repository at this point in the history
Simplify material file pointer acrobatics

See merge request OpenMW/openmw!4049
  • Loading branch information
psi29a committed Apr 24, 2024
2 parents 99a0755 + 78eda53 commit a628c65
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 64 deletions.
7 changes: 3 additions & 4 deletions apps/niftest/niftest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <utility>
#include <vector>

#include <components/bgsm/reader.hpp>
#include <components/bgsm/file.hpp>
#include <components/files/configurationmanager.hpp>
#include <components/files/constrainedfilestream.hpp>
#include <components/files/conversion.hpp>
Expand Down Expand Up @@ -88,11 +88,10 @@ void readFile(
}
else
{
Bgsm::Reader reader;
if (vfs != nullptr)
reader.parse(vfs->get(pathStr));
Bgsm::parse(vfs->get(pathStr));
else
reader.parse(Files::openConstrainedFileStream(fullPath));
Bgsm::parse(Files::openConstrainedFileStream(fullPath));
}
}
catch (std::exception& e)
Expand Down
2 changes: 1 addition & 1 deletion components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ add_component_dir (settings
)

add_component_dir (bgsm
reader stream file
stream file
)

add_component_dir (bsa
Expand Down
28 changes: 28 additions & 0 deletions components/bgsm/file.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
#include "file.hpp"

#include <array>
#include <stdexcept>

#include "stream.hpp"

namespace Bgsm
{
MaterialFilePtr parse(Files::IStreamPtr&& inputStream)
{
std::shared_ptr<Bgsm::MaterialFile> file;
BGSMStream stream(std::move(inputStream));

std::array<char, 4> signature;
stream.readArray(signature);
std::string shaderType(signature.data(), 4);
if (shaderType == "BGEM")
{
file = std::make_shared<BGEMFile>();
file->mShaderType = Bgsm::ShaderType::Effect;
}
else if (shaderType == "BGSM")
{
file = std::make_shared<BGSMFile>();
file->mShaderType = Bgsm::ShaderType::Lighting;
}
else
throw std::runtime_error("Invalid material file");

file->read(stream);
return file;
}

void MaterialFile::read(BGSMStream& stream)
{
stream.read(mVersion);
Expand Down
3 changes: 3 additions & 0 deletions components/bgsm/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <osg/Vec3f>
#include <osg/Vec4f>

#include <components/files/istreamptr.hpp>

namespace Bgsm
{
class BGSMStream;
Expand Down Expand Up @@ -160,5 +162,6 @@ namespace Bgsm
};

using MaterialFilePtr = std::shared_ptr<const Bgsm::MaterialFile>;
MaterialFilePtr parse(Files::IStreamPtr&& stream);
}
#endif
33 changes: 0 additions & 33 deletions components/bgsm/reader.cpp

This file was deleted.

22 changes: 0 additions & 22 deletions components/bgsm/reader.hpp

This file was deleted.

5 changes: 1 addition & 4 deletions components/resource/bgsmfilemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <osg/Object>

#include <components/bgsm/reader.hpp>
#include <components/vfs/manager.hpp>

#include "objectcache.hpp"
Expand Down Expand Up @@ -41,9 +40,7 @@ namespace Resource
return static_cast<BgsmFileHolder*>(obj.get())->mBgsmFile;
else
{
Bgsm::Reader reader;
reader.parse(mVFS->get(name));
Bgsm::MaterialFilePtr file = reader.getFile();
Bgsm::MaterialFilePtr file = Bgsm::parse(mVFS->get(name));
obj = new BgsmFileHolder(file);
mCache->addEntryToObjectCache(name.value(), obj);
return file;
Expand Down

0 comments on commit a628c65

Please sign in to comment.