67 lines
1.8 KiB
C++
67 lines
1.8 KiB
C++
/*
|
|
* 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
|
|
{
|
|
namespace
|
|
{
|
|
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";
|
|
}
|
|
|
|
EngineConfiguration::EngineConfiguration()
|
|
{
|
|
const std::string filePath = AppFolders::GetAppConfigHomeDir().string() + "/EngineConfig.yml";
|
|
std::ifstream file(filePath);
|
|
if (!file.is_open())
|
|
{
|
|
return;
|
|
}
|
|
|
|
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;
|
|
}
|
|
} |