diff --git a/apps/niftest/niftest.cpp b/apps/niftest/niftest.cpp index b391ce4bf1..0b8aa8e275 100644 --- a/apps/niftest/niftest.cpp +++ b/apps/niftest/niftest.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include #include @@ -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) diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index e17449aa24..1235072de5 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -108,7 +108,7 @@ add_component_dir (settings ) add_component_dir (bgsm - reader stream file + stream file ) add_component_dir (bsa diff --git a/components/bgsm/file.cpp b/components/bgsm/file.cpp index 6b763321be..2aaacaf25c 100644 --- a/components/bgsm/file.cpp +++ b/components/bgsm/file.cpp @@ -1,9 +1,37 @@ #include "file.hpp" +#include +#include + #include "stream.hpp" namespace Bgsm { + MaterialFilePtr parse(Files::IStreamPtr&& inputStream) + { + std::shared_ptr file; + BGSMStream stream(std::move(inputStream)); + + std::array signature; + stream.readArray(signature); + std::string shaderType(signature.data(), 4); + if (shaderType == "BGEM") + { + file = std::make_shared(); + file->mShaderType = Bgsm::ShaderType::Effect; + } + else if (shaderType == "BGSM") + { + file = std::make_shared(); + 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); diff --git a/components/bgsm/file.hpp b/components/bgsm/file.hpp index d3fb189256..b409752d74 100644 --- a/components/bgsm/file.hpp +++ b/components/bgsm/file.hpp @@ -10,6 +10,8 @@ #include #include +#include + namespace Bgsm { class BGSMStream; @@ -160,5 +162,6 @@ namespace Bgsm }; using MaterialFilePtr = std::shared_ptr; + MaterialFilePtr parse(Files::IStreamPtr&& stream); } #endif diff --git a/components/bgsm/reader.cpp b/components/bgsm/reader.cpp deleted file mode 100644 index eefc8b48b5..0000000000 --- a/components/bgsm/reader.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "reader.hpp" - -#include -#include -#include - -#include "stream.hpp" - -namespace Bgsm -{ - void Reader::parse(Files::IStreamPtr&& inputStream) - { - BGSMStream stream(std::move(inputStream)); - - std::array signature; - stream.readArray(signature); - std::string shaderType(signature.data(), 4); - if (shaderType == "BGEM") - { - mFile = std::make_unique(); - mFile->mShaderType = Bgsm::ShaderType::Effect; - } - else if (shaderType == "BGSM") - { - mFile = std::make_unique(); - mFile->mShaderType = Bgsm::ShaderType::Lighting; - } - else - throw std::runtime_error("Invalid material file"); - - mFile->read(stream); - } -} diff --git a/components/bgsm/reader.hpp b/components/bgsm/reader.hpp deleted file mode 100644 index 48508c9143..0000000000 --- a/components/bgsm/reader.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef OPENMW_COMPONENTS_BGSM_READER_HPP -#define OPENMW_COMPONENTS_BGSM_READER_HPP - -#include - -#include - -#include "file.hpp" - -namespace Bgsm -{ - class Reader - { - std::unique_ptr mFile; - - public: - void parse(Files::IStreamPtr&& stream); - - std::unique_ptr getFile() { return std::move(mFile); } - }; -} -#endif diff --git a/components/resource/bgsmfilemanager.cpp b/components/resource/bgsmfilemanager.cpp index 2d439ccc8a..7d93608603 100644 --- a/components/resource/bgsmfilemanager.cpp +++ b/components/resource/bgsmfilemanager.cpp @@ -2,7 +2,6 @@ #include -#include #include #include "objectcache.hpp" @@ -41,9 +40,7 @@ namespace Resource return static_cast(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;