diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b33fd19..03a367c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.25.2 FATAL_ERROR) # ---- Project ---- -project(RAYX VERSION 0.21.35) +project(RAYX VERSION 0.21.36) set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CUDA_STANDARD 20) diff --git a/Intern/rayx-core/src/Data/Locate.cpp b/Intern/rayx-core/src/Data/Locate.cpp index 61110152..a4e48681 100644 --- a/Intern/rayx-core/src/Data/Locate.cpp +++ b/Intern/rayx-core/src/Data/Locate.cpp @@ -15,10 +15,10 @@ namespace RAYX { // Check if a file exists -bool ResourceFinder::fileExists(const std::string& path) { return std::filesystem::exists(path); } -bool ResourceFinder::fileExists(const std::filesystem::path& path) { return std::filesystem::exists(path); } +bool ResourceHandler::fileExists(const std::string& path) { return std::filesystem::exists(path); } +bool ResourceHandler::fileExists(const std::filesystem::path& path) { return std::filesystem::exists(path); } -std::filesystem::path ResourceFinder::getExecutablePath() { +std::filesystem::path ResourceHandler::getExecutablePath() { #if defined(_WIN32) // Start with a reasonable buffer size std::vector buffer(MAX_PATH); @@ -59,7 +59,7 @@ std::filesystem::path ResourceFinder::getExecutablePath() { } // General method to get the full path based on the base directory (e.g., data or font directory) -std::filesystem::path ResourceFinder::getFullPath(const std::string& baseDir, const std::string& relativePath) { +std::filesystem::path ResourceHandler::getFullPath(const std::string& baseDir, const std::string& relativePath) { #if defined(__linux__) // First, check in /usr (package install) std::string path = std::string("/usr/") + baseDir + "/" + relativePath; @@ -89,9 +89,9 @@ std::filesystem::path ResourceFinder::getFullPath(const std::string& baseDir, co } // Retrieve the full path of a resource based on the platform -std::filesystem::path ResourceFinder::getResourcePath(const std::string& relativePath) { return getFullPath(RAYX_DATA_DIR, relativePath); } +std::filesystem::path ResourceHandler::getResourcePath(const std::string& relativePath) { return getFullPath(RAYX_DATA_DIR, relativePath); } // Retrieve the full path of a font based on the platform -std::filesystem::path ResourceFinder::getFontPath(const std::string& relativePath) { return getFullPath(RAYX_FONTS_DIR, relativePath); } +std::filesystem::path ResourceHandler::getFontPath(const std::string& relativePath) { return getFullPath(RAYX_FONTS_DIR, relativePath); } } // namespace RAYX \ No newline at end of file diff --git a/Intern/rayx-core/src/Data/Locate.h b/Intern/rayx-core/src/Data/Locate.h index 4ac908c2..bfbe23b9 100644 --- a/Intern/rayx-core/src/Data/Locate.h +++ b/Intern/rayx-core/src/Data/Locate.h @@ -2,14 +2,19 @@ #include #include -#include +#include #include "Core.h" namespace RAYX { -class RAYX_API ResourceFinder { +class RAYX_API ResourceHandler { public: + static ResourceHandler& getInstance() { + thread_local ResourceHandler instance; + return instance; + } + // Platform-specific implementations for resource path search std::filesystem::path getExecutablePath(); @@ -20,16 +25,15 @@ class RAYX_API ResourceFinder { std::filesystem::path getFontPath(const std::string& relativePath); private: + ResourceHandler() = default; bool fileExists(const std::string& path); bool fileExists(const std::filesystem::path& path); std::filesystem::path getFullPath(const std::string& baseDir, const std::string& relativePath); - std::vector lookUpPaths = { + std::set lookUpPaths = { #if defined(__linux__) std::filesystem::path("/usr"), // std::filesystem::path("/usr/local"), // -#elif defined(_WIN32) -#elif defined(__APPLE__) #endif }; }; diff --git a/Intern/rayx-core/src/Material/NffTable.cpp b/Intern/rayx-core/src/Material/NffTable.cpp index d16d486f..6de1b8ce 100644 --- a/Intern/rayx-core/src/Material/NffTable.cpp +++ b/Intern/rayx-core/src/Material/NffTable.cpp @@ -14,7 +14,7 @@ bool NffTable::load(const char* element, NffTable* out) { std::transform(elementString.begin(), elementString.end(), elementString.begin(), [](unsigned char c) { return std::tolower(c); }); - std::filesystem::path f = getResourcePath("Data/nff/" + elementString + ".nff"); + std::filesystem::path f = ResourceHandler::getInstance().getResourcePath("Data/nff/" + elementString + ".nff"); RAYX_VERB << "Loading NffTable from " << f; std::ifstream s(f); diff --git a/Intern/rayx-core/src/Material/PalikTable.cpp b/Intern/rayx-core/src/Material/PalikTable.cpp index b6288761..b154221c 100644 --- a/Intern/rayx-core/src/Material/PalikTable.cpp +++ b/Intern/rayx-core/src/Material/PalikTable.cpp @@ -12,7 +12,7 @@ bool PalikTable::load(const char* element, PalikTable* out) { std::string elementString = element; std::transform(elementString.begin(), elementString.end(), elementString.begin(), [](unsigned char c) { return std::toupper(c); }); - std::filesystem::path f = getResourcePath("Data/PALIK/" + elementString + ".NKP"); + std::filesystem::path f = ResourceHandler::getInstance().getResourcePath("Data/PALIK/" + elementString + ".NKP"); RAYX_VERB << "Loading PalikTable from " << f; std::ifstream s(f); diff --git a/Intern/rayx-ui/src/GraphicsCore/Texture.cpp b/Intern/rayx-ui/src/GraphicsCore/Texture.cpp index 261b215f..62250ea7 100644 --- a/Intern/rayx-ui/src/GraphicsCore/Texture.cpp +++ b/Intern/rayx-ui/src/GraphicsCore/Texture.cpp @@ -18,7 +18,7 @@ Texture::Texture(const Device& device) m_layout{VK_IMAGE_LAYOUT_UNDEFINED}, m_usageFlags{VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT}, m_aspectFlags{VK_IMAGE_ASPECT_COLOR_BIT} { - std::vector data = dataFromPath(RAYX::getResourcePath("Textures/default.png")); + std::vector data = dataFromPath(RAYX::ResourceHandler::getInstance().getResourcePath("Textures/default.png")); createImage(VK_IMAGE_TILING_OPTIMAL, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); createImageView(); createSampler(); diff --git a/Intern/rayx-ui/src/RenderSystem/GridRenderSystem.cpp b/Intern/rayx-ui/src/RenderSystem/GridRenderSystem.cpp index d41a5700..5957bf20 100644 --- a/Intern/rayx-ui/src/RenderSystem/GridRenderSystem.cpp +++ b/Intern/rayx-ui/src/RenderSystem/GridRenderSystem.cpp @@ -21,8 +21,8 @@ void GridRenderSystem::render(FrameInfo& frameInfo, [[maybe_unused]] const std:: RenderSystem::Input GridRenderSystem::fillInput(VkRenderPass renderPass) const { return RenderSystem::Input{.renderPass = renderPass, - .vertShaderPath = RAYX::getResourcePath("Shaders/grid_shader_vert.spv").string(), - .fragShaderPath = RAYX::getResourcePath("Shaders/grid_shader_frag.spv").string(), + .vertShaderPath = RAYX::ResourceHandler::getInstance().getResourcePath("Shaders/grid_shader_vert.spv").string(), + .fragShaderPath = RAYX::ResourceHandler::getInstance().getResourcePath("Shaders/grid_shader_frag.spv").string(), .bindingDescriptions = std::vector{}, .attributeDescriptions = std::vector{}, .topology = std::nullopt, diff --git a/Intern/rayx-ui/src/RenderSystem/ObjectRenderSystem.cpp b/Intern/rayx-ui/src/RenderSystem/ObjectRenderSystem.cpp index 86d9c181..cd0b7028 100644 --- a/Intern/rayx-ui/src/RenderSystem/ObjectRenderSystem.cpp +++ b/Intern/rayx-ui/src/RenderSystem/ObjectRenderSystem.cpp @@ -32,8 +32,8 @@ void ObjectRenderSystem::render(FrameInfo& frameInfo, const std::vectorAddFontFromFileTTF(fontPath.string().c_str(), 8.0f)); m_fonts.push_back(m_IO.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 16.0f)); m_fonts.push_back(m_IO.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 32.0f)); diff --git a/Intern/rayx/src/TerminalApp.cpp b/Intern/rayx/src/TerminalApp.cpp index e961b4cd..8a0558c8 100644 --- a/Intern/rayx/src/TerminalApp.cpp +++ b/Intern/rayx/src/TerminalApp.cpp @@ -111,7 +111,7 @@ void TerminalApp::tracePath(const std::filesystem::path& path) { RAYX_EXIT << "Have you selected .csv exporting?"; } - auto cmd = std::string("python ") + RAYX::getResourcePath("Scripts/plot.py").string() + " " + file; + auto cmd = std::string("python ") + RAYX::ResourceHandler::getInstance().getResourcePath("Scripts/plot.py").string() + " " + file; auto ret = system(cmd.c_str()); if (ret != 0) { RAYX_WARN << "received error code while printing";