/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #include #include #include #include #include "EngineConfiguration.hpp" #include "IO/AppFolders.hpp" #include "Utils.hpp" namespace OpenVulkano { namespace { const char* NUM_THREADS_STR = "NumThreads"; const char* FRAMEBUFFER_CLEAR_COLOR_STR = "FramebufferClearColor"; const char* PREFER_FRAMEBUFFER_FORMAT_SRGB_STR = "PreferFramebufferFormatSRGB"; const char* LAZY_RENDERING_STR = "LazyRendering"; } EngineConfiguration::EngineConfiguration() { const std::string filePath = (AppFolders::GetAppConfigHomeDir() / "EngineConfig.yml").string(); Array fileContents = Utils::ReadFile(filePath, true); if(fileContents.Size() == 0) return; ryml::Tree tree = ryml::parse_in_arena(ryml::to_csubstr(fileContents.Data())); ryml::NodeRef root = tree.rootref(); if (root.has_child(NUM_THREADS_STR) && root[NUM_THREADS_STR].val().is_integer()) { root[NUM_THREADS_STR] >> m_numThreads; } if (root.has_child(FRAMEBUFFER_CLEAR_COLOR_STR) && root[FRAMEBUFFER_CLEAR_COLOR_STR].is_seq() && root[FRAMEBUFFER_CLEAR_COLOR_STR].num_children() == 4) { auto clearColorNode = root[FRAMEBUFFER_CLEAR_COLOR_STR]; for (size_t i = 0; i < 4; ++i) { clearColorNode[i] >> m_frameBufferClearColor[i]; } } if (root.has_child(PREFER_FRAMEBUFFER_FORMAT_SRGB_STR)) { root[PREFER_FRAMEBUFFER_FORMAT_SRGB_STR] >> m_preferFramebufferFormatSRGB; } if (root.has_child(LAZY_RENDERING_STR)) { root[LAZY_RENDERING_STR] >> m_lazyRendering; } } EngineConfiguration* EngineConfiguration::GetEngineConfiguration() { static EngineConfiguration config; return &config; } }