From cc35df9409cdf4060ae9261b697c7bef5b01d7b0 Mon Sep 17 00:00:00 2001 From: elsid Date: Fri, 1 Mar 2024 18:18:51 +0100 Subject: [PATCH] Use VFS::Path::Normalized for fx::Technique file path --- components/fx/technique.cpp | 26 ++++++++++++++++---------- components/fx/technique.hpp | 10 ++++++---- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/components/fx/technique.cpp b/components/fx/technique.cpp index defb581cfc..f6bc881f78 100644 --- a/components/fx/technique.cpp +++ b/components/fx/technique.cpp @@ -37,11 +37,22 @@ namespace namespace fx { + namespace + { + VFS::Path::Normalized makeFilePath(std::string_view name) + { + std::string fileName(name); + fileName += Technique::sExt; + VFS::Path::Normalized result(Technique::sSubdir); + result /= fileName; + return result; + } + } + Technique::Technique(const VFS::Manager& vfs, Resource::ImageManager& imageManager, std::string name, int width, int height, bool ubo, bool supportsNormals) : mName(std::move(name)) - , mFileName(Files::pathToUnicodeString( - (Files::pathFromUnicodeString(Technique::sSubdir) / (mName + Technique::sExt)))) + , mFilePath(makeFilePath(mName)) , mLastModificationTime(std::filesystem::file_time_type::clock::now()) , mWidth(width) , mHeight(height) @@ -98,9 +109,9 @@ namespace fx { clear(); - if (!mVFS.exists(mFileName)) + if (!mVFS.exists(mFilePath)) { - Log(Debug::Error) << "Could not load technique, file does not exist '" << mFileName << "'"; + Log(Debug::Error) << "Could not load technique, file does not exist '" << mFilePath << "'"; mStatus = Status::File_Not_exists; return false; @@ -167,7 +178,7 @@ namespace fx mStatus = Status::Parse_Error; mLastError = "Failed parsing technique '" + getName() + "' " + e.what(); - ; + Log(Debug::Error) << mLastError; } @@ -179,11 +190,6 @@ namespace fx return mName; } - std::string Technique::getFileName() const - { - return mFileName; - } - bool Technique::setLastModificationTime(std::filesystem::file_time_type timeStamp) { const bool isDirty = timeStamp != mLastModificationTime; diff --git a/components/fx/technique.hpp b/components/fx/technique.hpp index fa66996aeb..01943a2fbe 100644 --- a/components/fx/technique.hpp +++ b/components/fx/technique.hpp @@ -13,6 +13,8 @@ #include #include +#include + #include "lexer.hpp" #include "pass.hpp" #include "types.hpp" @@ -103,8 +105,8 @@ namespace fx using UniformMap = std::vector>; using RenderTargetMap = std::unordered_map; - inline static std::string sExt = ".omwfx"; - inline static std::string sSubdir = "shaders"; + static constexpr std::string_view sExt = ".omwfx"; + static constexpr std::string_view sSubdir = "shaders"; enum class Status { @@ -128,7 +130,7 @@ namespace fx std::string getName() const; - std::string getFileName() const; + const VFS::Path::Normalized& getFileName() const { return mFilePath; } bool setLastModificationTime(std::filesystem::file_time_type timeStamp); @@ -251,7 +253,7 @@ namespace fx std::string mShared; std::string mName; - std::string mFileName; + VFS::Path::Normalized mFilePath; std::string_view mBlockName; std::string_view mAuthor; std::string_view mDescription;