Added ryml to linker list, loading EngineConfiguration from a file(if exists)
This commit is contained in:
@@ -94,7 +94,7 @@ endif()
|
|||||||
|
|
||||||
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/deps/INSTALL)
|
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/deps/INSTALL)
|
||||||
|
|
||||||
target_link_libraries(openVulkanoCpp PRIVATE magic_enum yaml-cpp fmt spdlog glm pugixml stb eigen utf8cpp imgui_internal TracyClient stud-uuid)
|
target_link_libraries(openVulkanoCpp PRIVATE magic_enum yaml-cpp fmt spdlog glm pugixml stb eigen utf8cpp imgui_internal TracyClient stud-uuid ryml)
|
||||||
|
|
||||||
add_compile_definitions(LIBARCHIVE_STATIC)
|
add_compile_definitions(LIBARCHIVE_STATIC)
|
||||||
add_compile_definitions(NOMINMAX)
|
add_compile_definitions(NOMINMAX)
|
||||||
|
|||||||
94
openVulkanoCpp/Base/EngineConfiguration.cpp
Normal file
94
openVulkanoCpp/Base/EngineConfiguration.cpp
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* 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 <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <ryml.hpp>
|
||||||
|
#include <ryml_std.hpp>
|
||||||
|
|
||||||
|
#include "EngineConfiguration.hpp"
|
||||||
|
#include "IO/AppFolders.hpp"
|
||||||
|
|
||||||
|
namespace OpenVulkano
|
||||||
|
{
|
||||||
|
EngineConfiguration::EngineConfiguration()
|
||||||
|
{
|
||||||
|
const std::string filePath = AppFolders::GetAppConfigHomeDir().string() + "/EngineConfig.yml";
|
||||||
|
std::ifstream file(filePath);
|
||||||
|
if (!file.is_open())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *NUM_THREADS_STR = "num_threads";
|
||||||
|
const char *FRAMEBUFFER_CLEAR_COLOR_STR = "framebuffer_clear_color";
|
||||||
|
const char *PREFER_FRAMEBUFFER_FORMAT_SRGB_STR = "prefer_framebuffer_format_srgb";
|
||||||
|
|
||||||
|
file.seekg(0, std::ios::end);
|
||||||
|
size_t size = file.tellg();
|
||||||
|
std::string buffer(size, ' ');
|
||||||
|
file.seekg(0);
|
||||||
|
file.read(buffer.data(), size);
|
||||||
|
|
||||||
|
ryml::Tree tree = ryml::parse_in_arena(ryml::to_csubstr(buffer));
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EngineConfiguration* EngineConfiguration::GetEngineConfiguration()
|
||||||
|
{
|
||||||
|
static EngineConfiguration config;
|
||||||
|
return &config;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EngineConfiguration::SetNumThreads(uint32_t numThreads)
|
||||||
|
{
|
||||||
|
m_numThreads = numThreads;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t EngineConfiguration::GetNumThreads() const
|
||||||
|
{
|
||||||
|
return std::max(static_cast<uint32_t>(1), m_numThreads);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EngineConfiguration::SetFrameBufferClearColor(std::array<float, 4> frameBufferClearColor)
|
||||||
|
{
|
||||||
|
m_frameBufferClearColor = frameBufferClearColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::array<float, 4>& EngineConfiguration::GetFrameBufferClearColor() const
|
||||||
|
{
|
||||||
|
return m_frameBufferClearColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EngineConfiguration::GetPreferFramebufferFormatSRGB() const
|
||||||
|
{
|
||||||
|
return m_preferFramebufferFormatSRGB;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EngineConfiguration::SetPreferFramebufferFormatSRGB(bool sRGB)
|
||||||
|
{
|
||||||
|
m_preferFramebufferFormatSRGB = sRGB;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
#undef max
|
#undef max
|
||||||
|
|
||||||
namespace OpenVulkano
|
namespace OpenVulkano
|
||||||
@@ -15,7 +16,7 @@ namespace OpenVulkano
|
|||||||
class EngineConfiguration
|
class EngineConfiguration
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
EngineConfiguration() = default;
|
EngineConfiguration();
|
||||||
~EngineConfiguration() = default;
|
~EngineConfiguration() = default;
|
||||||
|
|
||||||
uint32_t m_numThreads = 1;
|
uint32_t m_numThreads = 1;
|
||||||
@@ -23,40 +24,15 @@ namespace OpenVulkano
|
|||||||
bool m_preferFramebufferFormatSRGB = true;
|
bool m_preferFramebufferFormatSRGB = true;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
[[nodiscard]] static EngineConfiguration* GetEngineConfiguration()
|
[[nodiscard]] static EngineConfiguration* GetEngineConfiguration();
|
||||||
{
|
|
||||||
static EngineConfiguration config;
|
|
||||||
return &config;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetNumThreads(uint32_t numThreads)
|
void SetNumThreads(uint32_t numThreads);
|
||||||
{
|
[[nodiscard]] uint32_t GetNumThreads() const;
|
||||||
m_numThreads = numThreads;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] uint32_t GetNumThreads() const
|
void SetFrameBufferClearColor(std::array<float, 4> frameBufferClearColor);
|
||||||
{
|
[[nodiscard]] const std::array<float, 4>& GetFrameBufferClearColor() const;
|
||||||
return std::max(static_cast<uint32_t>(1), m_numThreads);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetFrameBufferClearColor(std::array<float, 4> frameBufferClearColor)
|
[[nodiscard]] bool GetPreferFramebufferFormatSRGB() const;
|
||||||
{
|
void SetPreferFramebufferFormatSRGB(bool sRGB);
|
||||||
m_frameBufferClearColor = frameBufferClearColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] const std::array<float, 4>& GetFrameBufferClearColor() const
|
|
||||||
{
|
|
||||||
return m_frameBufferClearColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] bool GetPreferFramebufferFormatSRGB() const
|
|
||||||
{
|
|
||||||
return m_preferFramebufferFormatSRGB;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetPreferFramebufferFormatSRGB(bool sRGB)
|
|
||||||
{
|
|
||||||
m_preferFramebufferFormatSRGB = sRGB;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user