mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-07-13 12:52:32 +08:00

* feat: added glslang and spirv-core for handling shaders, should provide better results than current systems
* fix: brought back proper include placement, should fix some shaders not working
* chore: dial down required version to 330
* fix: crash when taking screenshot
* fix: use glReadnPixels for X11 copying to be more memory safe
* chore: reverted part of last commit
* chore: delay initialization of browser until it's used once
* chore: do not initialize web browser unless explicitly needed
* chore: cleanup filesystem functions to use containers directly
* chore: memory cleanup fixes
* chore: fix glReadPixels for older opengl versions
* chore: remove shader patches as they shouldn't be needed anymore
* chore: initialise variables
* chore: update deps, actions and readme
* chore: make use of custon glslang and SPIRV-Cross
* Revert "chore: update deps, actions and readme"
This reverts commit c3fbc9340b
.
* chore: update actions to include submodules
* chore: do not depend on SPIRV-Tools
* fix: added log10 macro
* feat: update to latest glslang (swizzle and vec2/vec3/vec4 implicit casting to float)
* revert: delayed initialization of cef was causing issues, reverted
* chore: re-organized web wallpaper support to use custom scheme and better handle multiprocessing
* chore: make use of external repos for all deps instead of copying things manually and more cleanup work
* chore: wrong include file used in CGLSLContext.cpp
* chore: fix wayland generation folder not being present
* feat: somewhat support TEXB0004
* chore: improve function call matching and fallback to more lax method if no function is found
* chore: changed shader compilation slightly so they're passed onto glsl just once
* feat: swap android's fft implementation (which wasn't right) with kissfft's and fix update frequency issues
* chore: added missing dependency
* chore: added missing dep to PKGBUILD
* feat: add testing tools to run over all backgrounds and getting output data
* chore: jail CDirectory to the basepath and prevent accessing data outside of the main directory
* chore: process script now scales the previews so the html file is not too big
* chore: add showcase gallery to the README.md
* chore: update README
* chore: some readability improvements on code
* chore: fix segfault after code cleanup
* chore: make use of std::filesystem::canonical instead of basepath and slight typing changes on texture objects
* chore: fix path detection being wrong, make use of std::filesystem::path on CContainers
* chore: cleanup of the core part of the project
* chore: bring back std::move and make some methods const where it makes sense
* feat: added a pretty printer for easier debug and comparison between different versions of linux-wallpaperengine
* chore: refactored shader compilation code once more to be easier to follow and fixed the longstanding bug of #include not being added in the right place
* chore: more debug info for the pretty printer
* fix: some textures applied were not the right ones
* chore: properly set combos based on textures
* feat: take into account project properties for shader values
feat: proper parsing of combo values in shaders
fix: shader units weren't linked as they should
chore: more support for detecting shader things automatically
* fix: blending mode for passes using the wrong value
fix: shader uniforms from project properties should now be taken into account
* chore: use ubuntu 22 and ubuntu 24 as builders, ubuntu 20 is retired
* chore: use ubuntu 22 and ubuntu 24 as builders, ubuntu 20 is retired
* chore: hopefully fix github actions build
* refactor: simplified working with properties, constants and shader variables
* chore: remove a couple of todos that aren't needed anymore
* chore: simplify the texture detection a little bit, still work left to do
* fix: regression on texture setup not working properly
* fix: filenames with dots were not being handled properly
* chore: remove some uselesss messages
* chore: fixed std::string json values not casting anything to it as it was assumed
* fix: null user value for constants means it cannot be modified by the user
* chore: remove exception when a shader constant uses a non-existant property
* fix: angles can be an user setting too, also added detection for animation frames to show a warning
* fix: ensure variable information is not commented out by a line comment
* fix: shader includes weren't being processed properly
* chore: update to latest glslang and SPIRV-Cross to support non-integer array indices
* chore: make use of auto where it made sense
* feat: make use of in/out promotion on glslang-WallpaperEngine
feat: use glslang-WallpaperEngine linkin process as an extra validation
* chore: improve scripts for running the app
* chore: hide background structure dump behind a command-line switch
* chore: rewritten bloom effect as a json object inside C++ so it's easier to follow
* chore: removed deprecated parameters and switched to argparse instead of getopt
fix: clamping mode wasn't applied by background properly, only globally
* chore: removed help prompt from the output unless actually required
* fix: web subprocesses weren't launching due to parameter's parsing, temporal fix
* feat: added material command copy support
* feat: do not initialize some subsystems if they're disabled or not used by backgrounds
* chore: ignore type in combos as only seems to be used in the editor
* chore: update to latest glslang-WallpaperEngine changes
* chore: delete uniforms if they already exist before setting
* chore: more cleanup and fixes
* chore: more cleanup and fixes
* chore: more cleanup and fixes
* chore: update file functions to make use of shared_ptr/unique_ptr instead of copying things around
* chore: more changes to unique_ptr and shared_ptr
* chore: more changes to unique_ptr and shared_ptr
* chore: more changes to unique_ptr and shared_ptr
feat: improved render initialization process to make it easier and simpler to add new drivers (no more #ifdef in CWallpaperApplication.cpp)
* chore: change all is/as castings to use typeid so no string comparison takes place
* chore: more cleanup, default initialization of values wherever possible
* chore: moved more things to std::unique_ptr and std::shared_ptr
* chore: moved more things to std::unique_ptr and std::shared_ptr
* fix: browser context usage crashed the app
* chore: the setting controls fullscreen detection creation the same way audio works
* fix: ensure that at least one frame is rendered before detecting fullscreen windows
* chore: slight changes to output and documentation to properly reflect current build configuration
* chore: fix mipmap texture creation
* chore: fix pass uniforms not taking into account fragment shader's uniforms
chore: keep processed code in the shader sent to opengl so it appears on RenderDoc
* chore: formating issues by codefactor
* chore: do not use new to allocate the pretty printer
* fix: strchr wasn't properly done for window geometry
* chore: add recording mode for status page generation
* chore: update .gitignore
* chore: update script to make use of video generation instead of the old python scripts
* chore: also copy project.json so it can be used on the site too
* fix: regression on invisible images not being rendered
* feat: add option to disable camera parallax
* chore: add the reversing tools I have locally
* chore: mention some of the common issues in the README.md
* chore: take submodules into account for archlinux
* chore: missed cd "$pkgname" in arch's prepare step
542 lines
25 KiB
C++
542 lines
25 KiB
C++
#include "Core.h"
|
|
|
|
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
|
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
|
|
#include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h"
|
|
#include "WallpaperEngine/Logging/CLog.h"
|
|
|
|
using namespace WallpaperEngine;
|
|
using namespace WallpaperEngine::Core::UserSettings;
|
|
|
|
glm::vec4 Core::aToVector4 (const char* str) {
|
|
float x = strtof (str, const_cast<char**> (&str));
|
|
while (*str == ' ')
|
|
str++;
|
|
float y = strtof (str, const_cast<char**> (&str));
|
|
while (*str == ' ')
|
|
str++;
|
|
float z = strtof (str, const_cast<char**> (&str));
|
|
while (*str == ' ')
|
|
str++;
|
|
float w = strtof (str, const_cast<char**> (&str));
|
|
|
|
return {x, y, z, w};
|
|
}
|
|
|
|
glm::vec3 Core::aToVector3 (const char* str) {
|
|
float x = strtof (str, const_cast<char**> (&str));
|
|
while (*str == ' ')
|
|
str++;
|
|
float y = strtof (str, const_cast<char**> (&str));
|
|
while (*str == ' ')
|
|
str++;
|
|
float z = strtof (str, const_cast<char**> (&str));
|
|
|
|
return {x, y, z};
|
|
}
|
|
|
|
glm::vec2 Core::aToVector2 (const char* str) {
|
|
float x = strtof (str, const_cast<char**> (&str));
|
|
while (*str == ' ')
|
|
str++;
|
|
float y = strtof (str, const_cast<char**> (&str));
|
|
|
|
return {x, y};
|
|
}
|
|
|
|
glm::ivec4 Core::aToVector4i (const char* str) {
|
|
int x = strtol (str, const_cast<char**> (&str), 10);
|
|
while (*str == ' ')
|
|
str++;
|
|
int y = strtol (str, const_cast<char**> (&str), 10);
|
|
while (*str == ' ')
|
|
str++;
|
|
int z = strtol (str, const_cast<char**> (&str), 10);
|
|
while (*str == ' ')
|
|
str++;
|
|
int w = strtol (str, const_cast<char**> (&str), 10);
|
|
|
|
return {x, y, z, w};
|
|
}
|
|
|
|
glm::ivec3 Core::aToVector3i (const char* str) {
|
|
int x = strtol (str, const_cast<char**> (&str), 10);
|
|
while (*str == ' ')
|
|
str++;
|
|
int y = strtol (str, const_cast<char**> (&str), 10);
|
|
while (*str == ' ')
|
|
str++;
|
|
int z = strtol (str, const_cast<char**> (&str), 10);
|
|
|
|
return {x, y, z};
|
|
}
|
|
|
|
glm::ivec2 Core::aToVector2i (const char* str) {
|
|
int x = strtol (str, const_cast<char**> (&str), 10);
|
|
while (*str == ' ')
|
|
str++;
|
|
int y = strtol (str, const_cast<char**> (&str), 10);
|
|
|
|
return {x, y};
|
|
}
|
|
|
|
glm::vec4 Core::aToVector4 (const std::string& str) {
|
|
return Core::aToVector4 (str.c_str ());
|
|
}
|
|
|
|
glm::vec3 Core::aToVector3 (const std::string& str) {
|
|
return Core::aToVector3 (str.c_str ());
|
|
}
|
|
|
|
glm::vec2 Core::aToVector2 (const std::string& str) {
|
|
return Core::aToVector2 (str.c_str ());
|
|
}
|
|
|
|
glm::ivec4 Core::aToVector4i (const std::string& str) {
|
|
return Core::aToVector4i (str.c_str ());
|
|
}
|
|
|
|
glm::ivec3 Core::aToVector3i (const std::string& str) {
|
|
return Core::aToVector3i (str.c_str ());
|
|
}
|
|
|
|
glm::ivec2 Core::aToVector2i (const std::string& str) {
|
|
return Core::aToVector2i (str.c_str ());
|
|
}
|
|
|
|
glm::vec3 Core::aToColorf (const char* str) {
|
|
float r = strtof (str, const_cast<char**> (&str));
|
|
while (*str == ' ')
|
|
str++;
|
|
float g = strtof (str, const_cast<char**> (&str));
|
|
while (*str == ' ')
|
|
str++;
|
|
float b = strtof (str, const_cast<char**> (&str));
|
|
|
|
return {r, g, b};
|
|
}
|
|
|
|
glm::vec3 Core::aToColorf (const std::string& str) {
|
|
return aToColorf (str.c_str ());
|
|
}
|
|
|
|
glm::ivec3 Core::aToColori (const char* str) {
|
|
auto r = static_cast<uint8_t> (strtol (str, const_cast<char**> (&str), 10));
|
|
while (*str == ' ')
|
|
str++;
|
|
auto g = static_cast<uint8_t> (strtol (str, const_cast<char**> (&str), 10));
|
|
while (*str == ' ')
|
|
str++;
|
|
auto b = static_cast<uint8_t> (strtol (str, const_cast<char**> (&str), 10));
|
|
|
|
return {r, g, b};
|
|
}
|
|
|
|
glm::ivec3 Core::aToColori (const std::string& str) {
|
|
return aToColori (str.c_str ());
|
|
}
|
|
|
|
template <typename T> bool typeCheck (const nlohmann::json::const_iterator& value) {
|
|
if (value->type () == nlohmann::detail::value_t::null) {
|
|
return false;
|
|
}
|
|
|
|
// type checks
|
|
if constexpr ((std::is_same_v<T, float> || std::is_same_v<T, double>) ) {
|
|
if (value->type () != nlohmann::detail::value_t::number_float &&
|
|
value->type () != nlohmann::detail::value_t::number_integer &&
|
|
value->type () != nlohmann::detail::value_t::number_unsigned) {
|
|
return false;
|
|
}
|
|
} else if constexpr (std::is_same_v<T, std::string>) {
|
|
if (value->type () != nlohmann::detail::value_t::string) {
|
|
return false;
|
|
}
|
|
} else if constexpr (std::is_same_v<T, bool>) {
|
|
if (value->type () != nlohmann::detail::value_t::boolean) {
|
|
return false;
|
|
}
|
|
} else if constexpr (
|
|
std::is_same_v<T, glm::vec2> || std::is_same_v<T, glm::vec3> || std::is_same_v<T, glm::vec4> ||
|
|
std::is_same_v<T, glm::ivec2> || std::is_same_v<T, glm::ivec3> || std::is_same_v<T, glm::ivec4>) {
|
|
if (value->type () != nlohmann::detail::value_t::string) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
template <typename T> const T Core::jsonFindRequired (
|
|
const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg
|
|
) {
|
|
const auto iterator = jsonFindRequired (data, key, notFoundMsg);
|
|
|
|
// vector types need of special handling
|
|
if constexpr (std::is_same_v<T, std::string>) {
|
|
// std::strings are special, type checking doesn't need to happen, we just want the string representation
|
|
// of whatever is in there
|
|
if (iterator->is_number_integer ()) {
|
|
return std::to_string (iterator->get <int> ());
|
|
} else if (iterator->is_number_float ()) {
|
|
return std::to_string (iterator->get <float> ());
|
|
} else if (iterator->is_boolean()) {
|
|
return std::to_string (iterator->get <bool> ());
|
|
} else if (iterator->is_null ()) {
|
|
return "null";
|
|
} else if (iterator->is_string ()) {
|
|
return *iterator;
|
|
}
|
|
} else if constexpr (std::is_same_v<T, glm::vec4>) {
|
|
if (!typeCheck<T> (iterator)) {
|
|
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
}
|
|
|
|
return aToVector4 (*iterator);
|
|
} else if constexpr (std::is_same_v<T, glm::vec3>) {
|
|
if (!typeCheck<T> (iterator)) {
|
|
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
}
|
|
|
|
return aToVector3 (*iterator);
|
|
} else if constexpr (std::is_same_v<T, glm::vec2>) {
|
|
if (!typeCheck<T> (iterator)) {
|
|
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
}
|
|
|
|
return aToVector2 (*iterator);
|
|
} else if constexpr (std::is_same_v<T, glm::ivec4>) {
|
|
if (!typeCheck<T> (iterator)) {
|
|
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
}
|
|
|
|
return aToVector4i (*iterator);
|
|
} else if constexpr (std::is_same_v<T, glm::ivec3>) {
|
|
if (!typeCheck<T> (iterator)) {
|
|
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
}
|
|
|
|
return aToVector3i (*iterator);
|
|
} else if constexpr (std::is_same_v<T, glm::ivec2>) {
|
|
if (!typeCheck<T> (iterator)) {
|
|
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
}
|
|
|
|
return aToVector2i (*iterator);
|
|
} else if (typeCheck<T> (iterator)) {
|
|
return *iterator;
|
|
}
|
|
|
|
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), ": ", notFoundMsg);
|
|
}
|
|
|
|
template const bool Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
template const std::string Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
template const int16_t Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
template const uint16_t Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
template const int32_t Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
template const uint32_t Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
template const int64_t Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
template const uint64_t Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
template const float Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
template const double Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
template const glm::vec4 Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
template const glm::vec3 Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
template const glm::vec2 Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
template const glm::ivec4 Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
template const glm::ivec3 Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
template const glm::ivec2 Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
|
|
template <typename T> const T Core::jsonFindRequired (
|
|
const nlohmann::json& data, const char* key, const char* notFoundMsg
|
|
) {
|
|
const auto iterator = jsonFindRequired (data, key, notFoundMsg);
|
|
|
|
// vector types need of special handling
|
|
if constexpr (std::is_same_v<T, std::string>) {
|
|
// std::strings are special, type checking doesn't need to happen, we just want the string representation
|
|
// of whatever is in there
|
|
if (iterator->is_number_integer ()) {
|
|
return std::to_string (iterator->get <int> ());
|
|
} else if (iterator->is_number_float ()) {
|
|
return std::to_string (iterator->get <float> ());
|
|
} else if (iterator->is_boolean()) {
|
|
return std::to_string (iterator->get <bool> ());
|
|
} else if (iterator->is_null ()) {
|
|
return "null";
|
|
} else if (iterator->is_string ()) {
|
|
return *iterator;
|
|
}
|
|
} else if constexpr (std::is_same_v<T, glm::vec4>) {
|
|
if (!typeCheck<T> (iterator)) {
|
|
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
}
|
|
|
|
return aToVector4 (*iterator);
|
|
} else if constexpr (std::is_same_v<T, glm::vec3>) {
|
|
if (!typeCheck<T> (iterator)) {
|
|
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
}
|
|
|
|
return aToVector3 (*iterator);
|
|
} else if constexpr (std::is_same_v<T, glm::vec2>) {
|
|
if (!typeCheck<T> (iterator)) {
|
|
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
}
|
|
|
|
return aToVector2 (*iterator);
|
|
} else if constexpr (std::is_same_v<T, glm::ivec4>) {
|
|
if (!typeCheck<T> (iterator)) {
|
|
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
}
|
|
|
|
return aToVector4i (*iterator);
|
|
} else if constexpr (std::is_same_v<T, glm::ivec3>) {
|
|
if (!typeCheck<T> (iterator)) {
|
|
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
}
|
|
|
|
return aToVector3i (*iterator);
|
|
} else if constexpr (std::is_same_v<T, glm::ivec2>) {
|
|
if (!typeCheck<T> (iterator)) {
|
|
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
}
|
|
|
|
return aToVector2i (*iterator);
|
|
} else if (typeCheck<T> (iterator)) {
|
|
return *iterator;
|
|
}
|
|
|
|
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), ": ", notFoundMsg);
|
|
}
|
|
|
|
template const bool Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
template const std::string Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
template const int16_t Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
template const uint16_t Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
template const int32_t Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
template const uint32_t Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
template const int64_t Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
template const uint64_t Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
template const float Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
template const double Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
template const glm::vec4 Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
template const glm::vec3 Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
template const glm::vec2 Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
template const glm::ivec4 Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
template const glm::ivec3 Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
template const glm::ivec2 Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
|
|
nlohmann::json::const_iterator Core::jsonFindRequired (
|
|
const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg
|
|
) {
|
|
auto value = data->find (key);
|
|
|
|
if (value == data->end ())
|
|
sLog.exception ("Cannot find required key (", key, ") in json: ", notFoundMsg);
|
|
|
|
return value;
|
|
}
|
|
|
|
nlohmann::json::const_iterator Core::jsonFindRequired (
|
|
const nlohmann::json& data, const char* key, const char* notFoundMsg
|
|
) {
|
|
auto value = data.find (key);
|
|
|
|
if (value == data.end ())
|
|
sLog.exception ("Cannot find required key (", key, ") in json: ", notFoundMsg);
|
|
|
|
return value;
|
|
}
|
|
|
|
template <typename T> const T Core::jsonFindDefault (
|
|
const nlohmann::json::const_iterator& data, const char* key, const T defaultValue
|
|
) {
|
|
const auto value = data->find (key);
|
|
|
|
if (value == data->end () || value->type () == nlohmann::detail::value_t::null)
|
|
return defaultValue;
|
|
|
|
// vector types need of special handling
|
|
if constexpr (std::is_same_v<T, std::string>) {
|
|
// std::strings are special, type checking doesn't need to happen, we just want the string representation
|
|
// of whatever is in there
|
|
if (value->is_number_integer ()) {
|
|
return std::to_string (value->get <int> ());
|
|
} else if (value->is_number_float ()) {
|
|
return std::to_string (value->get <float> ());
|
|
} else if (value->is_boolean()) {
|
|
return std::to_string (value->get <bool> ());
|
|
} else if (value->is_null ()) {
|
|
return "null";
|
|
} else if (value->is_string ()) {
|
|
return *value;
|
|
}
|
|
} else if constexpr (std::is_same_v<T, glm::vec4>) {
|
|
if (!typeCheck<T> (value)) {
|
|
return defaultValue;
|
|
}
|
|
|
|
return aToVector4 (*value);
|
|
} else if constexpr (std::is_same_v<T, glm::vec3>) {
|
|
if (!typeCheck<T> (value)) {
|
|
return defaultValue;
|
|
}
|
|
|
|
return aToVector3 (*value);
|
|
} else if constexpr (std::is_same_v<T, glm::vec2>) {
|
|
if (!typeCheck<T> (value)) {
|
|
return defaultValue;
|
|
}
|
|
|
|
return aToVector2 (*value);
|
|
} else if constexpr (std::is_same_v<T, glm::ivec4>) {
|
|
if (!typeCheck<T> (value)) {
|
|
return defaultValue;
|
|
}
|
|
|
|
return aToVector4i (*value);
|
|
} else if constexpr (std::is_same_v<T, glm::ivec3>) {
|
|
if (!typeCheck<T> (value)) {
|
|
return defaultValue;
|
|
}
|
|
|
|
return aToVector3i (*value);
|
|
} else if constexpr (std::is_same_v<T, glm::ivec2>) {
|
|
if (!typeCheck<T> (value)) {
|
|
return defaultValue;
|
|
}
|
|
|
|
return aToVector2i (*value);
|
|
} else if (typeCheck<T> (value)) {
|
|
return *value;
|
|
}
|
|
|
|
return defaultValue;
|
|
}
|
|
|
|
template const bool Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const bool defaultValue);
|
|
template const std::string Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const std::string defaultValue);
|
|
template const int16_t Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const int16_t defaultValue);
|
|
template const uint16_t Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const uint16_t defaultValue);
|
|
template const int32_t Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const int32_t defaultValue);
|
|
template const uint32_t Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const uint32_t defaultValue);
|
|
template const int64_t Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const int64_t defaultValue);
|
|
template const uint64_t Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const uint64_t defaultValue);
|
|
template const float Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const float defaultValue);
|
|
template const double Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const double defaultValue);
|
|
template const glm::vec2 Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const glm::vec2 defaultValue);
|
|
template const glm::vec3 Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const glm::vec3 defaultValue);
|
|
template const glm::vec4 Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const glm::vec4 defaultValue);
|
|
template const glm::ivec2 Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const glm::ivec2 defaultValue);
|
|
template const glm::ivec3 Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const glm::ivec3 defaultValue);
|
|
template const glm::ivec4 Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const glm::ivec4 defaultValue);
|
|
|
|
template <typename T> const T Core::jsonFindDefault (
|
|
const nlohmann::json& data, const char* key, const T defaultValue
|
|
) {
|
|
const auto value = data.find (key);
|
|
|
|
if (value == data.end () || value->type () == nlohmann::detail::value_t::null)
|
|
return defaultValue;
|
|
|
|
// vector types need of special handling
|
|
if constexpr (std::is_same_v<T, glm::vec4>) {
|
|
if (!typeCheck<T> (value)) {
|
|
return defaultValue;
|
|
}
|
|
|
|
return aToVector4 (*value);
|
|
} else if constexpr (std::is_same_v<T, glm::vec3>) {
|
|
if (!typeCheck<T> (value)) {
|
|
return defaultValue;
|
|
}
|
|
|
|
return aToVector3 (*value);
|
|
} else if constexpr (std::is_same_v<T, glm::vec2>) {
|
|
if (!typeCheck<T> (value)) {
|
|
return defaultValue;
|
|
}
|
|
|
|
return aToVector2 (*value);
|
|
} else if constexpr (std::is_same_v<T, glm::ivec4>) {
|
|
if (!typeCheck<T> (value)) {
|
|
return defaultValue;
|
|
}
|
|
|
|
return aToVector4i (*value);
|
|
} else if constexpr (std::is_same_v<T, glm::ivec3>) {
|
|
if (!typeCheck<T> (value)) {
|
|
return defaultValue;
|
|
}
|
|
|
|
return aToVector3i (*value);
|
|
} else if constexpr (std::is_same_v<T, glm::ivec2>) {
|
|
if (!typeCheck<T> (value)) {
|
|
return defaultValue;
|
|
}
|
|
|
|
return aToVector2i (*value);
|
|
} else if (typeCheck<T> (value)) {
|
|
return *value;
|
|
}
|
|
|
|
return defaultValue;
|
|
}
|
|
|
|
template const bool Core::jsonFindDefault (const nlohmann::json& data, const char* key, const bool defaultValue);
|
|
template const std::string Core::jsonFindDefault (const nlohmann::json& data, const char* key, const std::string defaultValue);
|
|
template const int16_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const int16_t defaultValue);
|
|
template const uint16_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const uint16_t defaultValue);
|
|
template const int32_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const int32_t defaultValue);
|
|
template const uint32_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const uint32_t defaultValue);
|
|
template const int64_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const int64_t defaultValue);
|
|
template const uint64_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const uint64_t defaultValue);
|
|
template const float Core::jsonFindDefault (const nlohmann::json& data, const char* key, const float defaultValue);
|
|
template const double Core::jsonFindDefault (const nlohmann::json& data, const char* key, const double defaultValue);
|
|
template const glm::vec2 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::vec2 defaultValue);
|
|
template const glm::vec3 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::vec3 defaultValue);
|
|
template const glm::vec4 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::vec4 defaultValue);
|
|
template const glm::ivec2 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::ivec2 defaultValue);
|
|
template const glm::ivec3 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::ivec3 defaultValue);
|
|
template const glm::ivec4 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::ivec4 defaultValue);
|
|
|
|
template <typename T> const T* Core::jsonFindUserConfig (
|
|
const nlohmann::json::const_iterator& data, const CProject& project, const char* key, typename T::data_type defaultValue
|
|
) {
|
|
const auto it = data->find (key);
|
|
|
|
if (it == data->end () || it->type () == nlohmann::detail::value_t::null)
|
|
return T::fromScalar (defaultValue);
|
|
|
|
return T::fromJSON (*it, project);
|
|
}
|
|
|
|
template const CUserSettingBoolean* Core::jsonFindUserConfig (
|
|
const nlohmann::json::const_iterator& data, const CProject& project, const char* key,
|
|
CUserSettingBoolean::data_type defaultValue);
|
|
template const CUserSettingVector3* Core::jsonFindUserConfig (
|
|
const nlohmann::json::const_iterator& data, const CProject& project, const char* key,
|
|
CUserSettingVector3::data_type defaultValue);
|
|
template const CUserSettingFloat* Core::jsonFindUserConfig (
|
|
const nlohmann::json::const_iterator& data, const CProject& project, const char* key,
|
|
CUserSettingFloat::data_type defaultValue);
|
|
|
|
template <typename T> const T* Core::jsonFindUserConfig (
|
|
const nlohmann::json& data, const CProject& project, const char* key, typename T::data_type defaultValue
|
|
) {
|
|
const auto it = data.find (key);
|
|
|
|
if (it == data.end () || it->type () == nlohmann::detail::value_t::null)
|
|
return T::fromScalar (defaultValue);
|
|
|
|
return T::fromJSON (*it, project);
|
|
}
|
|
|
|
template const CUserSettingBoolean* Core::jsonFindUserConfig (
|
|
const nlohmann::json& data, const CProject& project, const char* key, CUserSettingBoolean::data_type defaultValue);
|
|
template const CUserSettingVector3* Core::jsonFindUserConfig (
|
|
const nlohmann::json& data, const CProject& project, const char* key, CUserSettingVector3::data_type defaultValue);
|
|
template const CUserSettingFloat* Core::jsonFindUserConfig (
|
|
const nlohmann::json& data, const CProject& project, const char* key, CUserSettingFloat::data_type defaultValue);
|