mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +08:00
chore: cleanup of properties, dynamic values and shader variables
This commit is contained in:
parent
806b65b490
commit
4dc9a61223
@ -198,8 +198,7 @@ if(X11_SUPPORT_FOUND)
|
||||
src/WallpaperEngine/Render/Drivers/Output/CX11Output.cpp
|
||||
src/WallpaperEngine/Render/Drivers/Output/CX11Output.h
|
||||
src/WallpaperEngine/Render/Drivers/Detectors/CX11FullScreenDetector.cpp
|
||||
src/WallpaperEngine/Render/Drivers/Detectors/CX11FullScreenDetector.h
|
||||
src/WallpaperEngine/Data/Model/UserSetting.h)
|
||||
src/WallpaperEngine/Render/Drivers/Detectors/CX11FullScreenDetector.h)
|
||||
SET(X11_INCLUDES
|
||||
${X11_INCLUDE_DIR}
|
||||
${XRANDR_INCLUDE_DIR})
|
||||
@ -284,9 +283,6 @@ add_executable(
|
||||
src/WallpaperEngine/Assets/CTexture.h
|
||||
src/WallpaperEngine/Assets/CTexture.cpp
|
||||
|
||||
src/WallpaperEngine/Core/Core.h
|
||||
src/WallpaperEngine/Core/Core.cpp
|
||||
|
||||
src/WallpaperEngine/Audio/Drivers/Recorders/CPulseAudioPlaybackRecorder.cpp
|
||||
src/WallpaperEngine/Audio/Drivers/Recorders/CPulseAudioPlaybackRecorder.h
|
||||
src/WallpaperEngine/Audio/Drivers/Recorders/CPlaybackRecorder.cpp
|
||||
@ -404,9 +400,6 @@ add_executable(
|
||||
src/WallpaperEngine/WebBrowser/CWebBrowserContext.cpp
|
||||
src/WallpaperEngine/WebBrowser/CWebBrowserContext.h
|
||||
|
||||
src/WallpaperEngine/Core/DynamicValues/CDynamicValue.cpp
|
||||
src/WallpaperEngine/Core/DynamicValues/CDynamicValue.h
|
||||
|
||||
src/WallpaperEngine/Core/Projects/CProperty.h
|
||||
src/WallpaperEngine/Core/Projects/CProperty.cpp
|
||||
src/WallpaperEngine/Core/Projects/CPropertyColor.h
|
||||
@ -427,8 +420,12 @@ add_executable(
|
||||
src/WallpaperEngine/Data/Model/Material.h
|
||||
src/WallpaperEngine/Data/Model/Effect.h
|
||||
src/WallpaperEngine/Data/Model/Model.h
|
||||
src/WallpaperEngine/Data/Model/UserSetting.h
|
||||
src/WallpaperEngine/Data/Model/DynamicValue.h
|
||||
src/WallpaperEngine/Data/Model/DynamicValue.cpp
|
||||
src/WallpaperEngine/Data/Utils/TypeCaster.cpp
|
||||
src/WallpaperEngine/Data/Utils/TypeCaster.h
|
||||
src/WallpaperEngine/Data/Utils/SFINAE.h
|
||||
src/WallpaperEngine/Data/Parsers/ProjectParser.cpp
|
||||
src/WallpaperEngine/Data/Parsers/ProjectParser.h
|
||||
src/WallpaperEngine/Data/Parsers/WallpaperParser.cpp
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include "WallpaperEngine/Render/CRenderContext.h"
|
||||
#include "WallpaperEngine/Render/Drivers/CVideoFactories.h"
|
||||
|
||||
#include "WallpaperEngine/Core/Projects/CProperty.h"
|
||||
|
||||
#include "WallpaperEngine/Data/Parsers/ProjectParser.h"
|
||||
#include "WallpaperEngine/Data/Dumpers/StringPrinter.h"
|
||||
|
||||
|
@ -1,498 +0,0 @@
|
||||
#include "Core.h"
|
||||
|
||||
#include "WallpaperEngine/Logging/CLog.h"
|
||||
|
||||
using namespace WallpaperEngine;
|
||||
|
||||
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);
|
@ -1,46 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace WallpaperEngine::Core {
|
||||
class CProject;
|
||||
|
||||
glm::vec4 aToVector4 (const char* str);
|
||||
glm::vec3 aToVector3 (const char* str);
|
||||
glm::vec2 aToVector2 (const char* str);
|
||||
|
||||
glm::vec4 aToVector4 (const std::string& str);
|
||||
glm::vec3 aToVector3 (const std::string& str);
|
||||
glm::vec2 aToVector2 (const std::string& str);
|
||||
|
||||
glm::ivec4 aToVector4i (const char* str);
|
||||
glm::ivec3 aToVector3i (const char* str);
|
||||
glm::ivec2 aToVector2i (const char* str);
|
||||
|
||||
glm::ivec4 aToVector4i (const std::string& str);
|
||||
glm::ivec3 aToVector3i (const std::string& str);
|
||||
glm::ivec2 aToVector2i (const std::string& str);
|
||||
|
||||
glm::vec3 aToColorf (const char* str);
|
||||
glm::vec3 aToColorf (const std::string& str);
|
||||
|
||||
glm::ivec3 aToColori (const char* str);
|
||||
glm::ivec3 aToColori (const std::string& str);
|
||||
|
||||
template <typename T> const T jsonFindRequired (
|
||||
const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
||||
template <typename T> const T jsonFindRequired (
|
||||
const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
||||
nlohmann::json::const_iterator jsonFindRequired (
|
||||
const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
||||
nlohmann::json::const_iterator jsonFindRequired (
|
||||
const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
||||
template <typename T> const T jsonFindDefault (
|
||||
const nlohmann::json::const_iterator& data, const char* key, const T defaultValue);
|
||||
template <typename T> const T jsonFindDefault (
|
||||
const nlohmann::json& data, const char* key, const T defaultValue);
|
||||
} // namespace WallpaperEngine::Core
|
@ -1,95 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace WallpaperEngine::Data::Parsers {
|
||||
class UserSettingParser;
|
||||
}
|
||||
|
||||
namespace WallpaperEngine::Data::Builders {
|
||||
class UserSettingBuilder;
|
||||
}
|
||||
|
||||
namespace WallpaperEngine::Core::DynamicValues {
|
||||
class CDynamicValue {
|
||||
//TODO: THIS SHOULD BE CHANGED ONCE THINGS ARE FINISHED
|
||||
friend class WallpaperEngine::Data::Parsers::UserSettingParser;
|
||||
friend class WallpaperEngine::Data::Builders::UserSettingBuilder;
|
||||
public:
|
||||
enum UnderlyingType {
|
||||
Unknown = -1,
|
||||
IVec4 = 0,
|
||||
IVec3 = 1,
|
||||
IVec2 = 2,
|
||||
Vec4 = 3,
|
||||
Vec3 = 4,
|
||||
Vec2 = 5,
|
||||
Float = 6,
|
||||
Int = 7,
|
||||
Boolean = 8
|
||||
};
|
||||
|
||||
virtual ~CDynamicValue ();
|
||||
|
||||
[[nodiscard]] const glm::ivec4& getIVec4 () const;
|
||||
[[nodiscard]] const glm::ivec3& getIVec3 () const;
|
||||
[[nodiscard]] const glm::ivec2& getIVec2 () const;
|
||||
[[nodiscard]] const glm::vec4& getVec4 () const;
|
||||
[[nodiscard]] const glm::vec3& getVec3 () const;
|
||||
[[nodiscard]] const glm::vec2& getVec2 () const;
|
||||
[[nodiscard]] const float& getFloat () const;
|
||||
[[nodiscard]] const int& getInt () const;
|
||||
[[nodiscard]] const bool& getBool () const;
|
||||
[[nodiscard]] UnderlyingType getType () const;
|
||||
[[nodiscard]] std::string toString () const;
|
||||
|
||||
/**
|
||||
* Connects the current instance to the given instance, updating it's values
|
||||
* based on current instance's changes
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
void connectOutgoing (CDynamicValue* value) const;
|
||||
void update (float newValue);
|
||||
void update (int newValue);
|
||||
void update (bool newValue);
|
||||
void update (const glm::vec2& newValue);
|
||||
void update (const glm::vec3& newValue);
|
||||
void update (const glm::vec4& newValue);
|
||||
void update (const glm::ivec2& newValue);
|
||||
void update (const glm::ivec3& newValue);
|
||||
void update (const glm::ivec4& newValue);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Registers an incoming connection (another CDynamicValue affecting the current instance's value)
|
||||
* Useful mainly for destroying the connection on delete
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
void connectIncoming (const CDynamicValue* value) const;
|
||||
void destroyOutgoingConnection (CDynamicValue* value) const;
|
||||
/**
|
||||
* Propagates the current value to all it's connections
|
||||
*/
|
||||
virtual void propagate () const;
|
||||
|
||||
private:
|
||||
mutable std::vector<CDynamicValue*> m_outgoingConnections = {};
|
||||
mutable std::vector<const CDynamicValue*> m_incomingConnections = {};
|
||||
UnderlyingType m_type = UnderlyingType::Unknown;
|
||||
// different values that we will be casted to automagically
|
||||
glm::ivec4 m_ivec4 = {};
|
||||
glm::ivec3 m_ivec3 = {};
|
||||
glm::ivec2 m_ivec2 = {};
|
||||
glm::vec4 m_vec4 = {};
|
||||
glm::vec3 m_vec3 = {};
|
||||
glm::vec2 m_vec2 = {};
|
||||
float m_float = 0.0f;
|
||||
int m_int = 0;
|
||||
bool m_bool = false;
|
||||
};
|
||||
};
|
@ -10,23 +10,23 @@
|
||||
|
||||
using namespace WallpaperEngine::Core::Projects;
|
||||
|
||||
std::shared_ptr<CProperty> CProperty::fromJSON (const json& data, const std::string& name) {
|
||||
const auto type = jsonFindRequired (data, "type", "Project properties must have the type field");
|
||||
std::shared_ptr<CProperty> CProperty::fromJSON (const JSON& data, const std::string& name) {
|
||||
const auto type = data.require <std::string> ("type", "Project properties must have the type field");
|
||||
|
||||
if (*type == "color")
|
||||
if (type == "color")
|
||||
return CPropertyColor::fromJSON (data, name);
|
||||
if (*type == "bool")
|
||||
if (type == "bool")
|
||||
return CPropertyBoolean::fromJSON (data, name);
|
||||
if (*type == "slider")
|
||||
if (type == "slider")
|
||||
return CPropertySlider::fromJSON (data, name);
|
||||
if (*type == "combo")
|
||||
if (type == "combo")
|
||||
return CPropertyCombo::fromJSON (data, name);
|
||||
if (*type == "text")
|
||||
if (type == "text")
|
||||
return CPropertyText::fromJSON (data, name);
|
||||
|
||||
if (*type != "group") {
|
||||
if (type != "group") {
|
||||
// show the error and ignore this property
|
||||
sLog.error ("Unexpected type for property: ", *type);
|
||||
sLog.error ("Unexpected type for property: ", type);
|
||||
sLog.error (data);
|
||||
}
|
||||
|
||||
@ -37,18 +37,6 @@ CProperty::CProperty (std::string name, std::string text) :
|
||||
m_name (std::move(name)),
|
||||
m_text (std::move(text)) {}
|
||||
|
||||
void CProperty::subscribe (const function_type& callback) const {
|
||||
this->m_subscriptions.push_back (callback);
|
||||
}
|
||||
|
||||
void CProperty::propagate () const {
|
||||
CDynamicValue::propagate ();
|
||||
|
||||
for (const auto& callback : this->m_subscriptions) {
|
||||
callback(this);
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& CProperty::getName () const {
|
||||
return this->m_name;
|
||||
}
|
||||
|
@ -1,46 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "WallpaperEngine/Core/DynamicValues/CDynamicValue.h"
|
||||
#include "WallpaperEngine/Core/Core.h"
|
||||
#include "WallpaperEngine/Data/Utils/TypeCaster.h"
|
||||
#include "WallpaperEngine/Data/Model/DynamicValue.h"
|
||||
#include "WallpaperEngine/Data/JSON.h"
|
||||
|
||||
namespace WallpaperEngine::Core::Projects {
|
||||
using json = nlohmann::json;
|
||||
using namespace WallpaperEngine::Core::DynamicValues;
|
||||
using JSON = WallpaperEngine::Data::JSON::JSON;
|
||||
using namespace WallpaperEngine::Data::Model;
|
||||
using namespace WallpaperEngine::Data::Utils;
|
||||
/**
|
||||
* Represents a property in a background
|
||||
*
|
||||
* Properties are settings that alter how the background looks or works
|
||||
* and are configurable by the user so they can customize it to their likings
|
||||
*/
|
||||
class CProperty : public CDynamicValue {
|
||||
class CProperty : public DynamicValue, public TypeCaster {
|
||||
public:
|
||||
using UniquePtr = std::unique_ptr<CProperty>;
|
||||
using SharedPtr = std::shared_ptr<CProperty>;
|
||||
using WeakPtr = std::weak_ptr<CProperty>;
|
||||
|
||||
typedef std::function<void(const CProperty*)> function_type;
|
||||
virtual ~CProperty () = default;
|
||||
static std::shared_ptr<CProperty> fromJSON (const json& data, const std::string& name);
|
||||
|
||||
template <class T> [[nodiscard]] const T* as () const {
|
||||
if (is <T> ()) {
|
||||
return static_cast <const T*> (this);
|
||||
}
|
||||
|
||||
throw std::bad_cast ();
|
||||
}
|
||||
|
||||
template <class T> [[nodiscard]] T* as () {
|
||||
if (is <T> ()) {
|
||||
return static_cast <T*> (this);
|
||||
}
|
||||
|
||||
throw std::bad_cast ();
|
||||
}
|
||||
|
||||
template <class T> [[nodiscard]] bool is () const {
|
||||
return typeid (*this) == typeid(T);
|
||||
}
|
||||
static std::shared_ptr<CProperty> fromJSON (const JSON& data, const std::string& name);
|
||||
|
||||
/**
|
||||
* @return Representation of what the property does and the default values
|
||||
@ -59,25 +39,14 @@ class CProperty : public CDynamicValue {
|
||||
/**
|
||||
* @return Textual type representation of this property
|
||||
*/
|
||||
[[nodiscard]] virtual const char* getType () const = 0;
|
||||
[[nodiscard]] virtual const char* getPropertyType () const = 0;
|
||||
/**
|
||||
* @return Text of the property
|
||||
*/
|
||||
[[nodiscard]] const std::string& getText () const;
|
||||
/**
|
||||
* Registers a function to be called when this instance's value changes
|
||||
*
|
||||
* @param callback
|
||||
*/
|
||||
void subscribe (const function_type& callback) const;
|
||||
|
||||
protected:
|
||||
void propagate () const override;
|
||||
|
||||
CProperty (std::string name, std::string text);
|
||||
|
||||
/** Functions to call when this property's value changes */
|
||||
mutable std::vector<function_type> m_subscriptions;
|
||||
/** Name of the property */
|
||||
const std::string m_name;
|
||||
/** Description of the property for the user */
|
||||
|
@ -2,15 +2,14 @@
|
||||
#include <utility>
|
||||
|
||||
#include "CPropertyBoolean.h"
|
||||
#include "WallpaperEngine/Core/Core.h"
|
||||
|
||||
using namespace WallpaperEngine::Core::Projects;
|
||||
|
||||
std::shared_ptr<CPropertyBoolean> CPropertyBoolean::fromJSON (const json& data, std::string name) {
|
||||
std::shared_ptr<CPropertyBoolean> CPropertyBoolean::fromJSON (const JSON& data, std::string name) {
|
||||
return std::make_shared <CPropertyBoolean> (
|
||||
jsonFindRequired <bool> (data, "value", "Boolean property must have a value"),
|
||||
data.require ("value", "Boolean property must have a value"),
|
||||
std::move(name),
|
||||
jsonFindDefault<std::string> (data, "text", "")
|
||||
data.optional <std::string> ("text", "")
|
||||
);
|
||||
}
|
||||
|
||||
@ -31,7 +30,7 @@ std::string CPropertyBoolean::dump () const {
|
||||
return ss.str ();
|
||||
}
|
||||
|
||||
const char* CPropertyBoolean::getType () const {
|
||||
const char* CPropertyBoolean::getPropertyType () const {
|
||||
return "bool";
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "CProperty.h"
|
||||
|
||||
namespace WallpaperEngine::Core::Projects {
|
||||
using json = nlohmann::json;
|
||||
using JSON = WallpaperEngine::Data::JSON::JSON;
|
||||
|
||||
/**
|
||||
* Represents a boolean property
|
||||
@ -12,10 +12,10 @@ class CPropertyBoolean final : public CProperty {
|
||||
public:
|
||||
CPropertyBoolean (bool value, std::string name, std::string text);
|
||||
|
||||
static std::shared_ptr<CPropertyBoolean> fromJSON (const json& data, std::string name);
|
||||
static std::shared_ptr<CPropertyBoolean> fromJSON (const JSON& data, std::string name);
|
||||
[[nodiscard]] std::string dump () const override;
|
||||
void set (const std::string& value) override;
|
||||
|
||||
[[nodiscard]] const char* getType () const override;
|
||||
[[nodiscard]] const char* getPropertyType () const override;
|
||||
};
|
||||
} // namespace WallpaperEngine::Core::Projects
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "CPropertyColor.h"
|
||||
|
||||
using namespace WallpaperEngine::Data::Builders;
|
||||
using namespace WallpaperEngine::Core::Projects;
|
||||
|
||||
glm::vec3 ParseColor (std::string value) {
|
||||
@ -13,19 +14,20 @@ glm::vec3 ParseColor (std::string value) {
|
||||
}
|
||||
|
||||
if (value.find ('.') == std::string::npos && value != "0 0 0" && value != "1 1 1") {
|
||||
const glm::ivec3 intcolor = WallpaperEngine::Core::aToColori (value);
|
||||
const auto intcolor = VectorBuilder::parse <glm::ivec3> (value);
|
||||
|
||||
return {intcolor.r / 255.0, intcolor.g / 255.0, intcolor.b / 255.0};
|
||||
}
|
||||
|
||||
return WallpaperEngine::Core::aToColorf (value);
|
||||
return VectorBuilder::parse <glm::vec3> (value);
|
||||
}
|
||||
|
||||
std::shared_ptr<CPropertyColor> CPropertyColor::fromJSON (const json& data, std::string name) {
|
||||
const auto value = jsonFindRequired <std::string> (data, "value", "Color property must have a value");
|
||||
const auto text = jsonFindDefault<std::string> (data, "text", "");
|
||||
|
||||
return std::make_shared <CPropertyColor> (value, std::move(name), text);
|
||||
std::shared_ptr<CPropertyColor> CPropertyColor::fromJSON (const JSON& data, std::string name) {
|
||||
return std::make_shared <CPropertyColor> (
|
||||
data.require ("value", "Color property must have a value"),
|
||||
std::move(name),
|
||||
data.optional <std::string> ("text", "")
|
||||
);
|
||||
}
|
||||
|
||||
void CPropertyColor::set (const std::string& value) {
|
||||
@ -45,7 +47,7 @@ std::string CPropertyColor::dump () const {
|
||||
return ss.str ();
|
||||
}
|
||||
|
||||
const char* CPropertyColor::getType () const {
|
||||
const char* CPropertyColor::getPropertyType () const {
|
||||
return "color";
|
||||
}
|
||||
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
#include "CProperty.h"
|
||||
|
||||
#include "WallpaperEngine/Core/Core.h"
|
||||
#include "WallpaperEngine/Data/JSON.h"
|
||||
|
||||
namespace WallpaperEngine::Core::Projects {
|
||||
using json = nlohmann::json;
|
||||
using JSON = WallpaperEngine::Data::JSON::JSON;
|
||||
|
||||
/**
|
||||
* Represents a color property
|
||||
@ -14,10 +14,10 @@ class CPropertyColor final : public CProperty {
|
||||
public:
|
||||
CPropertyColor (const std::string& color, std::string name, std::string text);
|
||||
|
||||
static std::shared_ptr<CPropertyColor> fromJSON (const json& data, std::string name);
|
||||
static std::shared_ptr<CPropertyColor> fromJSON (const JSON& data, std::string name);
|
||||
[[nodiscard]] std::string dump () const override;
|
||||
void set (const std::string& value) override;
|
||||
|
||||
[[nodiscard]] const char* getType () const override;
|
||||
[[nodiscard]] const char* getPropertyType () const override;
|
||||
};
|
||||
} // namespace WallpaperEngine::Core::Projects
|
||||
|
@ -3,34 +3,33 @@
|
||||
|
||||
#include "CPropertyCombo.h"
|
||||
|
||||
#include "WallpaperEngine/Core/Core.h"
|
||||
#include "WallpaperEngine/Logging/CLog.h"
|
||||
|
||||
using namespace WallpaperEngine::Core::Projects;
|
||||
|
||||
std::shared_ptr<CPropertyCombo> CPropertyCombo::fromJSON (const json& data, std::string name) {
|
||||
std::shared_ptr<CPropertyCombo> CPropertyCombo::fromJSON (const JSON& data, std::string name) {
|
||||
std::vector<CPropertyComboValue> values;
|
||||
const auto options = jsonFindRequired (data, "options", "Options for a property combo is required");
|
||||
const auto options = data.require ("options", "Options for a property combo is required");
|
||||
|
||||
if (!options->is_array ())
|
||||
if (!options.is_array ())
|
||||
sLog.exception ("Property combo options should be an array");
|
||||
|
||||
for (auto& cur : (*options)) {
|
||||
for (auto& cur : options) {
|
||||
// TODO: PROPERLY REPORT THESE ISSUES
|
||||
if (!cur.is_object ())
|
||||
continue;
|
||||
|
||||
// check for label and value to ensure they're there
|
||||
values.push_back ({
|
||||
.label = jsonFindRequired<std::string> (cur, "label", "Label is required for a property combo option"),
|
||||
.value = jsonFindRequired<std::string> (cur, "value", "Value is required for a property combo option")
|
||||
.label = cur.require ("label", "Label is required for a property combo option"),
|
||||
.value = cur.require ("value", "Value is required for a property combo option")
|
||||
});
|
||||
}
|
||||
|
||||
return std::make_shared <CPropertyCombo> (
|
||||
std::move(name),
|
||||
jsonFindDefault<std::string> (data, "text", ""),
|
||||
jsonFindRequired<std::string> (data, "value", "Value is required for a property combo"),
|
||||
data.optional <std::string> ("text", ""),
|
||||
data.require ("value", "Value is required for a property combo"),
|
||||
values
|
||||
);
|
||||
}
|
||||
@ -102,6 +101,6 @@ int CPropertyCombo::translateValueToIndex (const std::string& value) const {
|
||||
return index;
|
||||
}
|
||||
|
||||
const char* CPropertyCombo::getType () const {
|
||||
const char* CPropertyCombo::getPropertyType () const {
|
||||
return "combo";
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "CProperty.h"
|
||||
|
||||
namespace WallpaperEngine::Core::Projects {
|
||||
using json = nlohmann::json;
|
||||
using JSON = WallpaperEngine::Data::JSON::JSON;;
|
||||
|
||||
/**
|
||||
* Represents different combo values
|
||||
@ -23,7 +23,7 @@ struct CPropertyComboValue {
|
||||
*/
|
||||
class CPropertyCombo final : public CProperty {
|
||||
public:
|
||||
static std::shared_ptr<CPropertyCombo> fromJSON (const json& data, std::string name);
|
||||
static std::shared_ptr<CPropertyCombo> fromJSON (const JSON& data, std::string name);
|
||||
|
||||
CPropertyCombo (
|
||||
std::string name, std::string text, const std::string& defaultValue,
|
||||
@ -33,7 +33,7 @@ class CPropertyCombo final : public CProperty {
|
||||
void set (const std::string& value) override;
|
||||
int translateValueToIndex (const std::string& value) const;
|
||||
|
||||
[[nodiscard]] const char* getType () const override;
|
||||
[[nodiscard]] const char* getPropertyType () const override;
|
||||
|
||||
private:
|
||||
/** List of values available to select */
|
||||
|
@ -4,12 +4,12 @@
|
||||
|
||||
using namespace WallpaperEngine::Core::Projects;
|
||||
|
||||
std::shared_ptr<CPropertySlider> CPropertySlider::fromJSON (const json& data, const std::string& name) {
|
||||
std::shared_ptr<CPropertySlider> CPropertySlider::fromJSON (const JSON& data, const std::string& name) {
|
||||
const auto value = data.find ("value");
|
||||
const auto text = jsonFindDefault<std::string> (data, "text", "");
|
||||
const auto min = jsonFindDefault (data, "min", 0.0f);
|
||||
const auto max = jsonFindDefault (data, "max", 0.0f);
|
||||
const auto step = jsonFindDefault (data, "step", 0.0f);
|
||||
const auto text = data.optional <std::string> ("text", "");
|
||||
const auto min = data.optional ("min", 0.0f);
|
||||
const auto max = data.optional ("max", 0.0f);
|
||||
const auto step = data.optional ("step", 0.0f);
|
||||
|
||||
return std::make_shared <CPropertySlider> (*value, name, text, min, max, step);
|
||||
}
|
||||
@ -53,7 +53,7 @@ void CPropertySlider::set (const std::string& value) {
|
||||
this->update (newValue);
|
||||
}
|
||||
|
||||
const char* CPropertySlider::getType () const {
|
||||
const char* CPropertySlider::getPropertyType () const {
|
||||
return "slider";
|
||||
}
|
||||
|
||||
|
@ -2,10 +2,8 @@
|
||||
|
||||
#include "CProperty.h"
|
||||
|
||||
#include "WallpaperEngine/Core/Core.h"
|
||||
|
||||
namespace WallpaperEngine::Core::Projects {
|
||||
using json = nlohmann::json;
|
||||
using JSON = WallpaperEngine::Data::JSON::JSON;
|
||||
|
||||
/**
|
||||
* Represents a slider value with a minimum and maximum value
|
||||
@ -14,7 +12,7 @@ class CPropertySlider final : public CProperty {
|
||||
public:
|
||||
CPropertySlider (float value, const std::string& name, const std::string& text, float min, float max, float step);
|
||||
|
||||
static std::shared_ptr<CPropertySlider> fromJSON (const json& data, const std::string& name);
|
||||
static std::shared_ptr<CPropertySlider> fromJSON (const JSON& data, const std::string& name);
|
||||
/**
|
||||
* @return The slider's minimum value
|
||||
*/
|
||||
@ -30,7 +28,7 @@ class CPropertySlider final : public CProperty {
|
||||
[[nodiscard]] std::string dump () const override;
|
||||
void set (const std::string& value) override;
|
||||
|
||||
[[nodiscard]] const char* getType () const override;
|
||||
[[nodiscard]] const char* getPropertyType () const override;
|
||||
|
||||
private:
|
||||
/** Minimum value */
|
||||
|
@ -1,13 +1,15 @@
|
||||
#include "CPropertyText.h"
|
||||
#include "WallpaperEngine/Core/Core.h"
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
using namespace WallpaperEngine::Core::Projects;
|
||||
|
||||
std::shared_ptr<CPropertyText> CPropertyText::fromJSON (const json& data, std::string name) {
|
||||
std::shared_ptr<CPropertyText> CPropertyText::fromJSON (const JSON& data, std::string name) {
|
||||
//TODO: VALIDATE THIS IS RIGHT
|
||||
return std::make_shared <CPropertyText> (std::move(name), *data.find ("type"));
|
||||
return std::make_shared <CPropertyText> (
|
||||
std::move(name),
|
||||
data.optional <std::string> ("text", "")
|
||||
);
|
||||
}
|
||||
|
||||
std::string CPropertyText::dump () const {
|
||||
@ -24,7 +26,7 @@ void CPropertyText::set (const std::string& value) {
|
||||
this->m_text = value;
|
||||
}
|
||||
|
||||
const char* CPropertyText::getType () const {
|
||||
const char* CPropertyText::getPropertyType () const {
|
||||
return "text";
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "CProperty.h"
|
||||
|
||||
namespace WallpaperEngine::Core::Projects {
|
||||
using json = nlohmann::json;
|
||||
using JSON = WallpaperEngine::Data::JSON::JSON;
|
||||
|
||||
/**
|
||||
* Represents a text property
|
||||
@ -12,11 +12,11 @@ class CPropertyText final : public CProperty {
|
||||
public:
|
||||
CPropertyText (std::string name, std::string text);
|
||||
|
||||
static std::shared_ptr<CPropertyText> fromJSON (const json& data, std::string name);
|
||||
static std::shared_ptr<CPropertyText> fromJSON (const JSON& data, std::string name);
|
||||
[[nodiscard]] std::string dump () const override;
|
||||
void set (const std::string& value) override;
|
||||
|
||||
[[nodiscard]] const char* getType () const override;
|
||||
[[nodiscard]] const char* getPropertyType () const override;
|
||||
private:
|
||||
};
|
||||
} // namespace WallpaperEngine::Core::Projects
|
||||
|
@ -9,9 +9,7 @@ class UserSettingBuilder {
|
||||
public:
|
||||
template <typename T>
|
||||
static UserSettingUniquePtr fromValue (T defaultValue) {
|
||||
DynamicValueUniquePtr value = std::make_unique <DynamicValue> ();
|
||||
|
||||
value->update (defaultValue);
|
||||
DynamicValueUniquePtr value = std::make_unique <DynamicValue> (defaultValue);
|
||||
|
||||
return std::make_unique <UserSetting> (UserSetting {
|
||||
.value = std::move (value),
|
||||
|
@ -2,11 +2,15 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/detail/qualifier.hpp>
|
||||
#include <glm/detail/type_vec1.hpp>
|
||||
|
||||
#include "WallpaperEngine/Logging/CLog.h"
|
||||
#include "WallpaperEngine/Data/Utils/SFINAE.h"
|
||||
|
||||
namespace WallpaperEngine::Data::Builders {
|
||||
using namespace WallpaperEngine::Data::Utils::SFINAE;
|
||||
|
||||
class VectorBuilder {
|
||||
private:
|
||||
/**
|
||||
@ -60,7 +64,7 @@ class VectorBuilder {
|
||||
* @return
|
||||
*/
|
||||
template <int length, typename type, glm::qualifier qualifier>
|
||||
static glm::vec<length, type, qualifier> parse (const std::string& str) {
|
||||
[[nodiscard]] static glm::vec<length, type, qualifier> parse (const std::string& str) {
|
||||
const char* p = str.c_str ();
|
||||
|
||||
// get up to 4 spaces
|
||||
@ -118,6 +122,15 @@ class VectorBuilder {
|
||||
};
|
||||
}
|
||||
}
|
||||
template <typename T, typename std::enable_if_t<is_glm_vec<T>::value, int> = 0>
|
||||
[[nodiscard]] static T parse (const std::string& str) {
|
||||
constexpr int length = GlmVecTraits<T>::length;
|
||||
constexpr glm::qualifier qualifier = GlmVecTraits<T>::qualifier;
|
||||
|
||||
// call the specialized version of the function
|
||||
return parse<length, typename GlmVecTraits<T>::type, qualifier> (str);
|
||||
}
|
||||
private:
|
||||
};
|
||||
|
||||
template <>
|
||||
@ -127,7 +140,7 @@ inline float VectorBuilder::convert<float> (const char* str) {
|
||||
|
||||
template <>
|
||||
inline int VectorBuilder::convert<int> (const char* str) {
|
||||
return std::strtol (str, nullptr, 10);
|
||||
return std::stoi (str);
|
||||
}
|
||||
|
||||
template <>
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
using namespace WallpaperEngine::Data::JSON;
|
||||
using namespace WallpaperEngine::Data::Model;
|
||||
using namespace WallpaperEngine::Data::Parsers;
|
||||
|
||||
UserSettingUniquePtr JsonExtensions::user (const std::string& key, const Properties& properties) const {
|
||||
const auto value = this->require (key, "User setting without default value must be present");
|
||||
|
@ -9,34 +9,14 @@
|
||||
|
||||
#include "WallpaperEngine/Data/Builders/UserSettingBuilder.h"
|
||||
#include "WallpaperEngine/Data/Builders/VectorBuilder.h"
|
||||
#include "WallpaperEngine/Data/Utils/SFINAE.h"
|
||||
#include "WallpaperEngine/Data/Model/Types.h"
|
||||
#include "WallpaperEngine/Logging/CLog.h"
|
||||
|
||||
namespace WallpaperEngine::Data::Parsers {
|
||||
class UserSettingParser;
|
||||
}
|
||||
namespace WallpaperEngine::Data::JSON {
|
||||
using namespace WallpaperEngine::Data::Builders;
|
||||
using namespace WallpaperEngine::Data::Parsers;
|
||||
using namespace WallpaperEngine::Data::Model;
|
||||
|
||||
// sfinae to detect the type for template specialization
|
||||
template <typename T>
|
||||
struct is_glm_vec : std::false_type {};
|
||||
|
||||
template <glm::length_t L, typename S, glm::qualifier Q>
|
||||
struct is_glm_vec<glm::vec<L, S, Q>> : std::true_type {};
|
||||
|
||||
// traits used to guess the type of the vector and it's length
|
||||
template <typename T>
|
||||
struct GlmVecTraits;
|
||||
|
||||
template <glm::length_t L, typename T, glm::qualifier Q>
|
||||
struct GlmVecTraits<glm::vec<L, T, Q>> {
|
||||
static constexpr int length = L;
|
||||
using type = T;
|
||||
static constexpr glm::qualifier qualifier = Q;
|
||||
};
|
||||
using namespace WallpaperEngine::Data::Utils::SFINAE;
|
||||
|
||||
class JsonExtensions;
|
||||
|
||||
|
@ -1,223 +1,89 @@
|
||||
#include <algorithm>
|
||||
#include "CDynamicValue.h"
|
||||
#include "DynamicValue.h"
|
||||
|
||||
using namespace WallpaperEngine::Core::DynamicValues;
|
||||
using namespace WallpaperEngine::Data::Model;
|
||||
|
||||
CDynamicValue::~CDynamicValue() {
|
||||
for (auto* connection : this->m_incomingConnections) {
|
||||
connection->destroyOutgoingConnection (this);
|
||||
}
|
||||
DynamicValue::DynamicValue (const glm::ivec4& value) {
|
||||
this->update (value);
|
||||
}
|
||||
|
||||
void CDynamicValue::update(float newValue) {
|
||||
this->m_ivec4 = glm::ivec4(static_cast<int> (newValue));
|
||||
this->m_ivec3 = glm::ivec3(static_cast<int> (newValue));
|
||||
this->m_ivec2 = glm::ivec2(static_cast<int> (newValue));
|
||||
this->m_vec4 = glm::vec4(newValue);
|
||||
this->m_vec3 = glm::vec3(newValue);
|
||||
this->m_vec2 = glm::vec2(newValue);
|
||||
this->m_float = newValue;
|
||||
this->m_int = static_cast<int> (newValue);
|
||||
this->m_bool = static_cast<int> (newValue) != 0;
|
||||
this->m_type = UnderlyingType::Float;
|
||||
|
||||
this->propagate ();
|
||||
DynamicValue::DynamicValue (const glm::ivec3& value) {
|
||||
this->update (value);
|
||||
}
|
||||
|
||||
void CDynamicValue::update(int newValue) {
|
||||
this->m_ivec4 = glm::ivec4(newValue);
|
||||
this->m_ivec3 = glm::ivec3(newValue);
|
||||
this->m_ivec2 = glm::ivec2(newValue);
|
||||
this->m_vec4 = glm::vec4(static_cast<float> (newValue));
|
||||
this->m_vec3 = glm::vec3(static_cast<float> (newValue));
|
||||
this->m_vec2 = glm::vec2(static_cast<float> (newValue));
|
||||
this->m_float = static_cast<float> (newValue);
|
||||
this->m_int = newValue;
|
||||
this->m_bool = newValue != 0;
|
||||
this->m_type = UnderlyingType::Int;
|
||||
|
||||
this->propagate ();
|
||||
DynamicValue::DynamicValue (const glm::ivec2& value) {
|
||||
this->update (value);
|
||||
}
|
||||
|
||||
void CDynamicValue::update(bool newValue) {
|
||||
this->m_ivec4 = glm::ivec4(newValue);
|
||||
this->m_ivec3 = glm::ivec3(newValue);
|
||||
this->m_ivec2 = glm::ivec2(newValue);
|
||||
this->m_vec4 = glm::vec4(newValue);
|
||||
this->m_vec3 = glm::vec3(newValue);
|
||||
this->m_vec2 = glm::vec2(newValue);
|
||||
this->m_float = newValue;
|
||||
this->m_int = newValue;
|
||||
this->m_bool = newValue;
|
||||
this->m_type = UnderlyingType::Boolean;
|
||||
|
||||
this->propagate ();
|
||||
DynamicValue::DynamicValue (const glm::vec4& value) {
|
||||
this->update (value);
|
||||
}
|
||||
|
||||
void CDynamicValue::update(const glm::vec2& newValue) {
|
||||
this->m_ivec4 = glm::ivec4(newValue, 0, 0);
|
||||
this->m_ivec3 = glm::ivec3(newValue, 0);
|
||||
this->m_ivec2 = glm::ivec2(newValue);
|
||||
this->m_vec2 = newValue;
|
||||
this->m_vec3 = glm::vec3(newValue, 0.0f);
|
||||
this->m_vec4 = glm::vec4(newValue, 0.0f, 0.0f);
|
||||
this->m_float = newValue.x;
|
||||
this->m_int = static_cast<int> (newValue.x);
|
||||
this->m_bool = newValue.x != 0.0f;
|
||||
this->m_type = UnderlyingType::Vec2;
|
||||
|
||||
this->propagate ();
|
||||
DynamicValue::DynamicValue (const glm::vec3& value) {
|
||||
this->update (value);
|
||||
}
|
||||
|
||||
void CDynamicValue::update(const glm::vec3& newValue) {
|
||||
this->m_ivec4 = glm::ivec4(newValue, 0);
|
||||
this->m_ivec3 = glm::ivec3(newValue);
|
||||
this->m_ivec2 = glm::ivec2(newValue);
|
||||
this->m_vec2 = glm::vec2(newValue);
|
||||
this->m_vec3 = newValue;
|
||||
this->m_vec4 = glm::vec4(newValue, 0.0f);
|
||||
this->m_float = newValue.x;
|
||||
this->m_int = static_cast<int> (newValue.x);
|
||||
this->m_bool = newValue.x != 0.0f;
|
||||
this->m_type = UnderlyingType::Vec3;
|
||||
|
||||
this->propagate ();
|
||||
DynamicValue::DynamicValue (const glm::vec2& value) {
|
||||
this->update (value);
|
||||
}
|
||||
|
||||
void CDynamicValue::update(const glm::vec4& newValue) {
|
||||
this->m_ivec4 = glm::ivec4(newValue);
|
||||
this->m_ivec3 = glm::ivec3(newValue);
|
||||
this->m_ivec2 = glm::ivec2(newValue);
|
||||
this->m_vec2 = glm::vec2(newValue);
|
||||
this->m_vec3 = glm::vec3(newValue);
|
||||
this->m_vec4 = newValue;
|
||||
this->m_float = newValue.x;
|
||||
this->m_int = static_cast<int> (newValue.x);
|
||||
this->m_bool = newValue.x != 0.0f;
|
||||
this->m_type = UnderlyingType::Vec4;
|
||||
|
||||
this->propagate ();
|
||||
DynamicValue::DynamicValue (float value) {
|
||||
this->update (value);
|
||||
}
|
||||
|
||||
void CDynamicValue::update(const glm::ivec2& newValue) {
|
||||
this->m_ivec4 = glm::ivec4(newValue, 0, 0);
|
||||
this->m_ivec3 = glm::ivec3(newValue, 0);
|
||||
this->m_ivec2 = glm::ivec2(newValue);
|
||||
this->m_vec2 = newValue;
|
||||
this->m_vec3 = glm::vec3(newValue, 0.0f);
|
||||
this->m_vec4 = glm::vec4(newValue, 0.0f, 0.0f);
|
||||
this->m_float = static_cast<float> (newValue.x);
|
||||
this->m_int = static_cast<int> (newValue.x);
|
||||
this->m_bool = newValue.x != 0;
|
||||
this->m_type = UnderlyingType::IVec2;
|
||||
|
||||
this->propagate ();
|
||||
DynamicValue::DynamicValue (int value) {
|
||||
this->update (value);
|
||||
}
|
||||
|
||||
void CDynamicValue::update(const glm::ivec3& newValue) {
|
||||
this->m_ivec4 = glm::ivec4(newValue, 0);
|
||||
this->m_ivec3 = glm::ivec3(newValue);
|
||||
this->m_ivec2 = glm::ivec2(newValue);
|
||||
this->m_vec2 = glm::vec2(newValue);
|
||||
this->m_vec3 = newValue;
|
||||
this->m_vec4 = glm::vec4(newValue, 0.0f);
|
||||
this->m_float = static_cast<float> (newValue.x);
|
||||
this->m_int = static_cast<int> (newValue.x);
|
||||
this->m_bool = newValue.x != 0;
|
||||
this->m_type = UnderlyingType::IVec3;
|
||||
|
||||
this->propagate ();
|
||||
DynamicValue::DynamicValue (bool value) {
|
||||
this->update (value);
|
||||
}
|
||||
|
||||
void CDynamicValue::update(const glm::ivec4& newValue) {
|
||||
this->m_ivec4 = glm::ivec4(newValue);
|
||||
this->m_ivec3 = glm::ivec3(newValue);
|
||||
this->m_ivec2 = glm::ivec2(newValue);
|
||||
this->m_vec2 = glm::vec2(newValue);
|
||||
this->m_vec3 = glm::vec3(newValue);
|
||||
this->m_vec4 = newValue;
|
||||
this->m_float = static_cast<float> (newValue.x);
|
||||
this->m_int = static_cast<int> (newValue.x);
|
||||
this->m_bool = newValue.x != 0;
|
||||
this->m_type = UnderlyingType::IVec4;
|
||||
|
||||
this->propagate ();
|
||||
DynamicValue::~DynamicValue () {
|
||||
this->disconnect ();
|
||||
this->m_listeners.clear ();
|
||||
}
|
||||
|
||||
void CDynamicValue::connectOutgoing (CDynamicValue* value) const {
|
||||
this->m_outgoingConnections.push_back (value);
|
||||
|
||||
// ensure that new connection has the right value
|
||||
this->propagate ();
|
||||
// ensure the other value keeps track of our connection too
|
||||
value->connectIncoming (this);
|
||||
}
|
||||
|
||||
void CDynamicValue::connectIncoming (const CDynamicValue* value) const {
|
||||
this->m_incomingConnections.push_back (value);
|
||||
}
|
||||
|
||||
void CDynamicValue::destroyOutgoingConnection (CDynamicValue* value) const {
|
||||
this->m_outgoingConnections.erase (
|
||||
std::remove (this->m_outgoingConnections.begin (), this->m_outgoingConnections.end (), value), this->m_outgoingConnections.end ()
|
||||
);
|
||||
}
|
||||
|
||||
void CDynamicValue::propagate () const {
|
||||
for (auto* cur : this->m_outgoingConnections) {
|
||||
cur->m_bool = this->m_bool;
|
||||
cur->m_int = this->m_int;
|
||||
cur->m_float = this->m_float;
|
||||
cur->m_ivec2 = this->m_ivec2;
|
||||
cur->m_ivec3 = this->m_ivec3;
|
||||
cur->m_ivec4 = this->m_ivec4;
|
||||
cur->m_vec2 = this->m_vec2;
|
||||
cur->m_vec3 = this->m_vec3;
|
||||
cur->m_vec4 = this->m_vec4;
|
||||
}
|
||||
}
|
||||
|
||||
const glm::ivec4& CDynamicValue::getIVec4 () const {
|
||||
const glm::ivec4& DynamicValue::getIVec4 () const {
|
||||
return this->m_ivec4;
|
||||
}
|
||||
|
||||
const glm::ivec3& CDynamicValue::getIVec3 () const {
|
||||
const glm::ivec3& DynamicValue::getIVec3 () const {
|
||||
return this->m_ivec3;
|
||||
}
|
||||
|
||||
const glm::ivec2& CDynamicValue::getIVec2 () const {
|
||||
const glm::ivec2& DynamicValue::getIVec2 () const {
|
||||
return this->m_ivec2;
|
||||
}
|
||||
|
||||
const glm::vec4& CDynamicValue::getVec4 () const {
|
||||
const glm::vec4& DynamicValue::getVec4 () const {
|
||||
return this->m_vec4;
|
||||
}
|
||||
|
||||
const glm::vec3& CDynamicValue::getVec3 () const {
|
||||
const glm::vec3& DynamicValue::getVec3 () const {
|
||||
return this->m_vec3;
|
||||
}
|
||||
|
||||
const glm::vec2& CDynamicValue::getVec2 () const {
|
||||
const glm::vec2& DynamicValue::getVec2 () const {
|
||||
return this->m_vec2;
|
||||
}
|
||||
|
||||
const float& CDynamicValue::getFloat () const {
|
||||
const float& DynamicValue::getFloat () const {
|
||||
return this->m_float;
|
||||
}
|
||||
|
||||
const int& CDynamicValue::getInt () const {
|
||||
const int& DynamicValue::getInt () const {
|
||||
return this->m_int;
|
||||
}
|
||||
|
||||
const bool& CDynamicValue::getBool () const {
|
||||
const bool& DynamicValue::getBool () const {
|
||||
return this->m_bool;
|
||||
}
|
||||
|
||||
CDynamicValue::UnderlyingType CDynamicValue::getType () const {
|
||||
DynamicValue::UnderlyingType DynamicValue::getType () const {
|
||||
return this->m_type;
|
||||
}
|
||||
|
||||
std::string CDynamicValue::toString () const {
|
||||
std::string DynamicValue::toString () const {
|
||||
switch (this->m_type) {
|
||||
case UnderlyingType::Float:
|
||||
return std::to_string (this->m_float);
|
||||
@ -240,4 +106,184 @@ std::string CDynamicValue::toString () const {
|
||||
default:
|
||||
return "Unknown conversion for dynamic value of type: " + std::to_string (static_cast<int> (this->m_type));
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicValue::update(float newValue) {
|
||||
this->m_ivec4 = glm::ivec4(static_cast<int> (newValue));
|
||||
this->m_ivec3 = glm::ivec3(static_cast<int> (newValue));
|
||||
this->m_ivec2 = glm::ivec2(static_cast<int> (newValue));
|
||||
this->m_vec4 = glm::vec4(newValue);
|
||||
this->m_vec3 = glm::vec3(newValue);
|
||||
this->m_vec2 = glm::vec2(newValue);
|
||||
this->m_float = newValue;
|
||||
this->m_int = static_cast<int> (newValue);
|
||||
this->m_bool = static_cast<int> (newValue) != 0;
|
||||
this->m_type = UnderlyingType::Float;
|
||||
|
||||
this->propagate ();
|
||||
}
|
||||
|
||||
void DynamicValue::update(int newValue) {
|
||||
this->m_ivec4 = glm::ivec4(newValue);
|
||||
this->m_ivec3 = glm::ivec3(newValue);
|
||||
this->m_ivec2 = glm::ivec2(newValue);
|
||||
this->m_vec4 = glm::vec4(static_cast<float> (newValue));
|
||||
this->m_vec3 = glm::vec3(static_cast<float> (newValue));
|
||||
this->m_vec2 = glm::vec2(static_cast<float> (newValue));
|
||||
this->m_float = static_cast<float> (newValue);
|
||||
this->m_int = newValue;
|
||||
this->m_bool = newValue != 0;
|
||||
this->m_type = UnderlyingType::Int;
|
||||
|
||||
this->propagate ();
|
||||
}
|
||||
|
||||
void DynamicValue::update(bool newValue) {
|
||||
this->m_ivec4 = glm::ivec4(newValue);
|
||||
this->m_ivec3 = glm::ivec3(newValue);
|
||||
this->m_ivec2 = glm::ivec2(newValue);
|
||||
this->m_vec4 = glm::vec4(newValue);
|
||||
this->m_vec3 = glm::vec3(newValue);
|
||||
this->m_vec2 = glm::vec2(newValue);
|
||||
this->m_float = newValue;
|
||||
this->m_int = newValue;
|
||||
this->m_bool = newValue;
|
||||
this->m_type = UnderlyingType::Boolean;
|
||||
|
||||
this->propagate ();
|
||||
}
|
||||
|
||||
void DynamicValue::update(const glm::vec2& newValue) {
|
||||
this->m_ivec4 = glm::ivec4(newValue, 0, 0);
|
||||
this->m_ivec3 = glm::ivec3(newValue, 0);
|
||||
this->m_ivec2 = glm::ivec2(newValue);
|
||||
this->m_vec2 = newValue;
|
||||
this->m_vec3 = glm::vec3(newValue, 0.0f);
|
||||
this->m_vec4 = glm::vec4(newValue, 0.0f, 0.0f);
|
||||
this->m_float = newValue.x;
|
||||
this->m_int = static_cast<int> (newValue.x);
|
||||
this->m_bool = newValue.x != 0.0f;
|
||||
this->m_type = UnderlyingType::Vec2;
|
||||
|
||||
this->propagate ();
|
||||
}
|
||||
|
||||
void DynamicValue::update(const glm::vec3& newValue) {
|
||||
this->m_ivec4 = glm::ivec4(newValue, 0);
|
||||
this->m_ivec3 = glm::ivec3(newValue);
|
||||
this->m_ivec2 = glm::ivec2(newValue);
|
||||
this->m_vec2 = glm::vec2(newValue);
|
||||
this->m_vec3 = newValue;
|
||||
this->m_vec4 = glm::vec4(newValue, 0.0f);
|
||||
this->m_float = newValue.x;
|
||||
this->m_int = static_cast<int> (newValue.x);
|
||||
this->m_bool = newValue.x != 0.0f;
|
||||
this->m_type = UnderlyingType::Vec3;
|
||||
|
||||
this->propagate ();
|
||||
}
|
||||
|
||||
void DynamicValue::update(const glm::vec4& newValue) {
|
||||
this->m_ivec4 = glm::ivec4(newValue);
|
||||
this->m_ivec3 = glm::ivec3(newValue);
|
||||
this->m_ivec2 = glm::ivec2(newValue);
|
||||
this->m_vec2 = glm::vec2(newValue);
|
||||
this->m_vec3 = glm::vec3(newValue);
|
||||
this->m_vec4 = newValue;
|
||||
this->m_float = newValue.x;
|
||||
this->m_int = static_cast<int> (newValue.x);
|
||||
this->m_bool = newValue.x != 0.0f;
|
||||
this->m_type = UnderlyingType::Vec4;
|
||||
|
||||
this->propagate ();
|
||||
}
|
||||
|
||||
void DynamicValue::update(const glm::ivec2& newValue) {
|
||||
this->m_ivec4 = glm::ivec4(newValue, 0, 0);
|
||||
this->m_ivec3 = glm::ivec3(newValue, 0);
|
||||
this->m_ivec2 = glm::ivec2(newValue);
|
||||
this->m_vec2 = newValue;
|
||||
this->m_vec3 = glm::vec3(newValue, 0.0f);
|
||||
this->m_vec4 = glm::vec4(newValue, 0.0f, 0.0f);
|
||||
this->m_float = static_cast<float> (newValue.x);
|
||||
this->m_int = static_cast<int> (newValue.x);
|
||||
this->m_bool = newValue.x != 0;
|
||||
this->m_type = UnderlyingType::IVec2;
|
||||
|
||||
this->propagate ();
|
||||
}
|
||||
|
||||
void DynamicValue::update(const glm::ivec3& newValue) {
|
||||
this->m_ivec4 = glm::ivec4(newValue, 0);
|
||||
this->m_ivec3 = glm::ivec3(newValue);
|
||||
this->m_ivec2 = glm::ivec2(newValue);
|
||||
this->m_vec2 = glm::vec2(newValue);
|
||||
this->m_vec3 = newValue;
|
||||
this->m_vec4 = glm::vec4(newValue, 0.0f);
|
||||
this->m_float = static_cast<float> (newValue.x);
|
||||
this->m_int = static_cast<int> (newValue.x);
|
||||
this->m_bool = newValue.x != 0;
|
||||
this->m_type = UnderlyingType::IVec3;
|
||||
|
||||
this->propagate ();
|
||||
}
|
||||
|
||||
void DynamicValue::update(const glm::ivec4& newValue) {
|
||||
this->m_ivec4 = glm::ivec4(newValue);
|
||||
this->m_ivec3 = glm::ivec3(newValue);
|
||||
this->m_ivec2 = glm::ivec2(newValue);
|
||||
this->m_vec2 = glm::vec2(newValue);
|
||||
this->m_vec3 = glm::vec3(newValue);
|
||||
this->m_vec4 = newValue;
|
||||
this->m_float = static_cast<float> (newValue.x);
|
||||
this->m_int = static_cast<int> (newValue.x);
|
||||
this->m_bool = newValue.x != 0;
|
||||
this->m_type = UnderlyingType::IVec4;
|
||||
|
||||
this->propagate ();
|
||||
}
|
||||
|
||||
void DynamicValue::update (const DynamicValue& other) {
|
||||
this->m_ivec4 = other.getIVec4 ();
|
||||
this->m_ivec3 = other.getIVec3 ();
|
||||
this->m_ivec2 = other.getIVec2 ();
|
||||
this->m_vec2 = other.getVec2 ();
|
||||
this->m_vec3 = other.getVec3 ();
|
||||
this->m_vec4 = other.getVec4 ();
|
||||
this->m_float = other.getFloat ();
|
||||
this->m_int = other.getInt ();
|
||||
this->m_bool = other.getBool ();
|
||||
this->m_type = other.getType ();
|
||||
|
||||
this->propagate ();
|
||||
}
|
||||
|
||||
std::function<void ()> DynamicValue::listen (const std::function<void (const DynamicValue&)>& callback) {
|
||||
const auto it = this->m_listeners.insert (this->m_listeners.end (), callback);
|
||||
|
||||
return [this, it] {
|
||||
this->m_listeners.erase (it);
|
||||
};
|
||||
}
|
||||
|
||||
void DynamicValue::connect (DynamicValue* other) {
|
||||
const auto deregisterFunction = other->listen ([this] (const DynamicValue& other) {
|
||||
this->update (other);
|
||||
});
|
||||
|
||||
this->m_connections.push_back (deregisterFunction);
|
||||
}
|
||||
|
||||
void DynamicValue::disconnect () {
|
||||
for (const auto& deregister : this->m_connections) {
|
||||
deregister ();
|
||||
}
|
||||
|
||||
this->m_connections.clear ();
|
||||
}
|
||||
|
||||
void DynamicValue::propagate () const {
|
||||
for (const auto& callback : this->m_listeners) {
|
||||
callback(*this);
|
||||
}
|
||||
}
|
105
src/WallpaperEngine/Data/Model/DynamicValue.h
Normal file
105
src/WallpaperEngine/Data/Model/DynamicValue.h
Normal file
@ -0,0 +1,105 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
namespace WallpaperEngine::Data::Model {
|
||||
/**
|
||||
* Class that represents different types of dynamic values
|
||||
*/
|
||||
class DynamicValue {
|
||||
public:
|
||||
enum UnderlyingType {
|
||||
Null = 0,
|
||||
IVec4 = 1,
|
||||
IVec3 = 2,
|
||||
IVec2 = 3,
|
||||
Vec4 = 4,
|
||||
Vec3 = 5,
|
||||
Vec2 = 6,
|
||||
Float = 7,
|
||||
Int = 8,
|
||||
Boolean = 9
|
||||
};
|
||||
|
||||
DynamicValue () = default;
|
||||
explicit DynamicValue(const glm::ivec4& value);
|
||||
explicit DynamicValue(const glm::ivec3& value);
|
||||
explicit DynamicValue(const glm::ivec2& value);
|
||||
explicit DynamicValue(const glm::vec4& value);
|
||||
explicit DynamicValue(const glm::vec3& value);
|
||||
explicit DynamicValue(const glm::vec2& value);
|
||||
explicit DynamicValue(float value);
|
||||
explicit DynamicValue(int value);
|
||||
explicit DynamicValue(bool value);
|
||||
~DynamicValue ();
|
||||
|
||||
[[nodiscard]] const glm::ivec4& getIVec4 () const;
|
||||
[[nodiscard]] const glm::ivec3& getIVec3 () const;
|
||||
[[nodiscard]] const glm::ivec2& getIVec2 () const;
|
||||
[[nodiscard]] const glm::vec4& getVec4 () const;
|
||||
[[nodiscard]] const glm::vec3& getVec3 () const;
|
||||
[[nodiscard]] const glm::vec2& getVec2 () const;
|
||||
[[nodiscard]] const float& getFloat () const;
|
||||
[[nodiscard]] const int& getInt () const;
|
||||
[[nodiscard]] const bool& getBool () const;
|
||||
[[nodiscard]] UnderlyingType getType () const;
|
||||
[[nodiscard]] std::string toString () const;
|
||||
|
||||
void update (float newValue);
|
||||
void update (int newValue);
|
||||
void update (bool newValue);
|
||||
void update (const glm::vec2& newValue);
|
||||
void update (const glm::vec3& newValue);
|
||||
void update (const glm::vec4& newValue);
|
||||
void update (const glm::ivec2& newValue);
|
||||
void update (const glm::ivec3& newValue);
|
||||
void update (const glm::ivec4& newValue);
|
||||
void update (const DynamicValue& newValue);
|
||||
|
||||
/**
|
||||
* Registers the given callback to be called when the value changes
|
||||
*
|
||||
* @param callback
|
||||
*
|
||||
* @return The de-register function to call when the listener is no longer needed
|
||||
*/
|
||||
std::function<void ()> listen (const std::function<void (const DynamicValue&)>& callback);
|
||||
/**
|
||||
* Connects the current instance to the given instance, updating this instance's value
|
||||
* based on the given instance's value
|
||||
*
|
||||
* @param other
|
||||
*
|
||||
* @return The de-register function to call when the listener is no longer needed
|
||||
*/
|
||||
void connect (DynamicValue* other);
|
||||
|
||||
/**
|
||||
* Disconnects the current instance from all the connections to stop notifying
|
||||
* new value changes
|
||||
*/
|
||||
void disconnect ();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Notifies any listeners that the value has changed
|
||||
*/
|
||||
void propagate () const;
|
||||
|
||||
std::vector<std::function<void (const DynamicValue&)>> m_listeners = {};
|
||||
std::vector<std::function<void ()>> m_connections = {};
|
||||
|
||||
glm::ivec4 m_ivec4 = {};
|
||||
glm::ivec3 m_ivec3 = {};
|
||||
glm::ivec2 m_ivec2 = {};
|
||||
glm::vec4 m_vec4 = {};
|
||||
glm::vec3 m_vec3 = {};
|
||||
glm::vec2 m_vec2 = {};
|
||||
float m_float = 0.0f;
|
||||
int m_int = 0;
|
||||
bool m_bool = false;
|
||||
UnderlyingType m_type = Null;
|
||||
};
|
||||
}
|
@ -1,10 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <memory>
|
||||
|
||||
#include "WallpaperEngine/Assets/CContainer.h"
|
||||
#include "WallpaperEngine/Core/DynamicValues/CDynamicValue.h"
|
||||
#include "WallpaperEngine/Core/Projects/CProperty.h"
|
||||
|
||||
namespace WallpaperEngine::Core::Projects {
|
||||
class CProperty;
|
||||
}
|
||||
|
||||
namespace WallpaperEngine::Data::Model {
|
||||
struct Project;
|
||||
@ -19,6 +25,7 @@ class Image;
|
||||
struct ImageEffect;
|
||||
struct ImageEffectPassOverride;
|
||||
class Particle;
|
||||
class DynamicValue;
|
||||
struct Material;
|
||||
struct MaterialPass;
|
||||
struct FBO;
|
||||
@ -33,7 +40,6 @@ using Property = WallpaperEngine::Core::Projects::CProperty;
|
||||
using PropertySharedPtr = std::shared_ptr <Property>;
|
||||
using PropertyWeakPtr = std::weak_ptr <Property>;
|
||||
using Properties = std::map <std::string, PropertySharedPtr>;
|
||||
using DynamicValue = WallpaperEngine::Core::DynamicValues::CDynamicValue;
|
||||
using DynamicValueUniquePtr = std::unique_ptr <DynamicValue>;
|
||||
using DynamicValueSharedPtr = std::shared_ptr <DynamicValue>;
|
||||
using DynamicValueWeakPtr = std::weak_ptr <DynamicValue>;
|
||||
|
@ -3,11 +3,9 @@
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include "DynamicValue.h"
|
||||
#include "Types.h"
|
||||
|
||||
#include "WallpaperEngine/Core/DynamicValues/CDynamicValue.h"
|
||||
#include "WallpaperEngine/Core/Projects/CProperty.h"
|
||||
|
||||
namespace WallpaperEngine::Data::Model {
|
||||
struct ConditionInfo {
|
||||
public:
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "WallpaperParser.h"
|
||||
|
||||
#include "WallpaperEngine/Data/Model/Wallpaper.h"
|
||||
#include "WallpaperEngine/Core/Projects/CProperty.h"
|
||||
|
||||
using namespace WallpaperEngine::Data::Parsers;
|
||||
|
||||
|
25
src/WallpaperEngine/Data/Utils/SFINAE.h
Normal file
25
src/WallpaperEngine/Data/Utils/SFINAE.h
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/detail/qualifier.hpp>
|
||||
#include <glm/detail/type_vec1.hpp>
|
||||
|
||||
namespace WallpaperEngine::Data::Utils::SFINAE {
|
||||
// sfinae to detect the type for template specialization
|
||||
template <typename T>
|
||||
struct is_glm_vec : std::false_type {};
|
||||
|
||||
template <glm::length_t L, typename S, glm::qualifier Q>
|
||||
struct is_glm_vec<glm::vec<L, S, Q>> : std::true_type {};
|
||||
|
||||
// traits used to guess the type of the vector and it's length
|
||||
template <typename T>
|
||||
struct GlmVecTraits;
|
||||
|
||||
template <glm::length_t L, typename T, glm::qualifier Q>
|
||||
struct GlmVecTraits<glm::vec<L, T, Q>> {
|
||||
static constexpr int length = L;
|
||||
using type = T;
|
||||
static constexpr glm::qualifier qualifier = Q;
|
||||
};
|
||||
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/vec2.hpp>
|
||||
|
||||
#include "CFBO.h"
|
||||
#include "WallpaperEngine/Data/Model/Effect.h"
|
||||
|
||||
|
@ -727,7 +727,7 @@ void CPass::addUniform (CShaderVariable* value) {
|
||||
this->addUniform (value, value);
|
||||
}
|
||||
|
||||
void CPass::addUniform (CShaderVariable* value, const CDynamicValue* setting) {
|
||||
void CPass::addUniform (CShaderVariable* value, const DynamicValue* setting) {
|
||||
if (value->is<CShaderVariableFloat> ()) {
|
||||
this->addUniform (value->getName (), setting->getFloat ());
|
||||
} else if (value->is<CShaderVariableInteger> ()) {
|
||||
|
@ -114,7 +114,7 @@ class CPass final : public Helpers::CContextAware {
|
||||
void setupAttributes ();
|
||||
void addAttribute (const std::string& name, GLint type, GLint elements, const GLuint* value);
|
||||
void addUniform (CShaderVariable* value);
|
||||
void addUniform (CShaderVariable* value, const CDynamicValue* setting);
|
||||
void addUniform (CShaderVariable* value, const DynamicValue* setting);
|
||||
void addUniform (const std::string& name, int value);
|
||||
void addUniform (const std::string& name, double value);
|
||||
void addUniform (const std::string& name, float value);
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
#include "WallpaperEngine/Assets/CContainer.h"
|
||||
#include "WallpaperEngine/Assets/ITexture.h"
|
||||
#include "WallpaperEngine/Core/Core.h"
|
||||
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h"
|
||||
|
||||
#include "CShaderUnit.h"
|
||||
|
@ -15,6 +15,8 @@
|
||||
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.h"
|
||||
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.h"
|
||||
|
||||
#include "WallpaperEngine/Data/Builders/VectorBuilder.h"
|
||||
|
||||
#define SHADER_HEADER(filename) "#version 330\n" \
|
||||
"// ======================================================\n" \
|
||||
"// Processed shader " + \
|
||||
@ -47,6 +49,7 @@
|
||||
|
||||
using namespace WallpaperEngine::Core;
|
||||
using namespace WallpaperEngine::Assets;
|
||||
using namespace WallpaperEngine::Data::Builders;
|
||||
using namespace WallpaperEngine::Render::Shaders;
|
||||
|
||||
CShaderUnit::CShaderUnit (
|
||||
@ -322,18 +325,18 @@ void CShaderUnit::preprocessRequires () {
|
||||
|
||||
void CShaderUnit::parseComboConfiguration (const std::string& content, int defaultValue) {
|
||||
// TODO: SUPPORT REQUIRES SO WE PROPERLY FOLLOW THE REQUIRED CHAIN
|
||||
json data = json::parse (content);
|
||||
const auto combo = jsonFindRequired (data, "combo", "cannot parse combo information");
|
||||
const auto data = JSON::parse (content);
|
||||
const auto combo = data.require <std::string> ("combo", "cannot parse combo information");
|
||||
// ignore type as it seems to be used only on the editor
|
||||
// const auto type = data.find ("type");
|
||||
const auto defvalue = data.find ("default");
|
||||
|
||||
// check the combos
|
||||
const auto entry = this->m_combos.find (combo->get<std::string> ());
|
||||
const auto entryOverride = this->m_overrideCombos.find (combo->get<std::string> ());
|
||||
const auto entry = this->m_combos.find (combo);
|
||||
const auto entryOverride = this->m_overrideCombos.find (combo);
|
||||
|
||||
// add the combo to the found list
|
||||
this->m_usedCombos.emplace (*combo, true);
|
||||
this->m_usedCombos.emplace (combo, true);
|
||||
|
||||
// if the combo was not found in the predefined values this means that the default value in the JSON data can be
|
||||
// used so only define the ones that are not already defined
|
||||
@ -341,15 +344,15 @@ void CShaderUnit::parseComboConfiguration (const std::string& content, int defau
|
||||
// if no combo is defined just load the default settings
|
||||
if (defvalue == data.end ()) {
|
||||
// TODO: PROPERLY SUPPORT EMPTY COMBOS
|
||||
this->m_discoveredCombos.emplace (*combo, (int) defaultValue);
|
||||
this->m_discoveredCombos.emplace (combo, (int) defaultValue);
|
||||
} else if (defvalue->is_number_float ()) {
|
||||
sLog.exception ("float combos are not supported in shader ", this->m_file, ". ", *combo);
|
||||
sLog.exception ("float combos are not supported in shader ", this->m_file, ". ", combo);
|
||||
} else if (defvalue->is_number_integer ()) {
|
||||
this->m_discoveredCombos.emplace (*combo, defvalue->get<int> ());
|
||||
this->m_discoveredCombos.emplace (combo, defvalue->get<int> ());
|
||||
} else if (defvalue->is_string ()) {
|
||||
sLog.exception ("string combos are not supported in shader ", this->m_file, ". ", *combo);
|
||||
sLog.exception ("string combos are not supported in shader ", this->m_file, ". ", combo);
|
||||
} else {
|
||||
sLog.exception ("cannot parse combo information ", *combo, ". unknown type for ", defvalue->dump ());
|
||||
sLog.exception ("cannot parse combo information ", combo, ". unknown type for ", defvalue->dump ());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -357,45 +360,42 @@ void CShaderUnit::parseComboConfiguration (const std::string& content, int defau
|
||||
void CShaderUnit::parseParameterConfiguration (
|
||||
const std::string& type, const std::string& name, const std::string& content
|
||||
) {
|
||||
json data = json::parse (content);
|
||||
const auto material = data.find ("material");
|
||||
const auto defvalue = data.find ("default");
|
||||
const auto data = JSON::parse (content);
|
||||
const auto material = data.optional ("material");
|
||||
const auto defvalue = data.optional ("default");
|
||||
// auto range = data.find ("range");
|
||||
const auto combo = data.find ("combo");
|
||||
|
||||
// this is not a real parameter
|
||||
auto constant = this->m_constants.end ();
|
||||
|
||||
if (material != data.end ())
|
||||
if (material.has_value ())
|
||||
constant = this->m_constants.find (*material);
|
||||
|
||||
if (constant == this->m_constants.end () && defvalue == data.end ()) {
|
||||
if (constant == this->m_constants.end () && !defvalue.has_value ()) {
|
||||
if (type != "sampler2D")
|
||||
sLog.exception ("Cannot parse parameter data for ", name, " in shader ", this->m_file);
|
||||
}
|
||||
|
||||
Variables::CShaderVariable* parameter = nullptr;
|
||||
|
||||
// TODO: SUPPORT VALUES FOR ALL THESE TYPES
|
||||
// TODO: MAYBE EVEN CONNECT THESE TO THE CORRESPONDING PROPERTY SO THINGS ARE UPDATED AS THE ORIGIN VALUES CHANGE?
|
||||
// TODO: MAKE USE OF PARSERS INSTEAD OF CORE
|
||||
if (type == "vec4") {
|
||||
parameter = new Variables::CShaderVariableVector4 (WallpaperEngine::Core::aToVector4 (*defvalue));
|
||||
parameter = new Variables::CShaderVariableVector4 (VectorBuilder::parse <glm::vec4> (defvalue->get <std::string> ()));
|
||||
} else if (type == "vec3") {
|
||||
parameter = new Variables::CShaderVariableVector3 (WallpaperEngine::Core::aToVector3 (*defvalue));
|
||||
parameter = new Variables::CShaderVariableVector3 (VectorBuilder::parse <glm::vec3> (*defvalue));
|
||||
} else if (type == "vec2") {
|
||||
parameter = new Variables::CShaderVariableVector2 (WallpaperEngine::Core::aToVector2 (*defvalue));
|
||||
parameter = new Variables::CShaderVariableVector2 (VectorBuilder::parse <glm::vec2> (*defvalue));
|
||||
} else if (type == "float") {
|
||||
if (defvalue->is_string ()) {
|
||||
parameter = new Variables::CShaderVariableFloat (strtof32 ((defvalue->get<std::string> ()).c_str (), nullptr));
|
||||
parameter = new Variables::CShaderVariableFloat (std::stoi (defvalue->get<std::string> ()));
|
||||
} else {
|
||||
parameter = new Variables::CShaderVariableFloat (*defvalue);
|
||||
parameter = new Variables::CShaderVariableFloat (defvalue->get<float> ());
|
||||
}
|
||||
} else if (type == "int") {
|
||||
if (defvalue->is_string ()) {
|
||||
parameter = new Variables::CShaderVariableInteger (strtol((defvalue->get<std::string> ()).c_str (), nullptr, 10));
|
||||
parameter = new Variables::CShaderVariableInteger (std::stoi(defvalue->get<std::string> ()));
|
||||
} else {
|
||||
parameter = new Variables::CShaderVariableInteger (*defvalue);
|
||||
parameter = new Variables::CShaderVariableInteger (defvalue->get <int> ());
|
||||
}
|
||||
} else if (type == "sampler2D" || type == "sampler2DComparison") {
|
||||
// samplers can have special requirements, check what sampler we're working with and create definitions
|
||||
@ -460,7 +460,7 @@ void CShaderUnit::parseParameterConfiguration (
|
||||
}
|
||||
|
||||
if (isRequired && !textureSlotUsed) {
|
||||
if (defvalue == data.end ()) {
|
||||
if (!defvalue.has_value ()) {
|
||||
isRequired = false;
|
||||
} else {
|
||||
// is the combo registered already?
|
||||
@ -473,7 +473,7 @@ void CShaderUnit::parseParameterConfiguration (
|
||||
isRequired = false;
|
||||
// otherwise a default value must be used
|
||||
} else if (defvalue->is_string ()) {
|
||||
comboValue = strtol (defvalue->get <std::string> ().c_str (), nullptr, 10);
|
||||
comboValue = std::stoi (defvalue->get <std::string> ().c_str ());
|
||||
} else if (defvalue->is_number()) {
|
||||
comboValue = *defvalue;
|
||||
} else {
|
||||
@ -500,7 +500,7 @@ void CShaderUnit::parseParameterConfiguration (
|
||||
return;
|
||||
}
|
||||
|
||||
if (material != data.end () && parameter != nullptr) {
|
||||
if (material.has_value () && parameter != nullptr) {
|
||||
parameter->setIdentifierName (*material);
|
||||
parameter->setName (name);
|
||||
|
||||
|
@ -6,14 +6,14 @@
|
||||
|
||||
#include "CGLSLContext.h"
|
||||
#include "WallpaperEngine/Assets/CContainer.h"
|
||||
#include "WallpaperEngine/Core/Core.h"
|
||||
#include "WallpaperEngine/Data/JSON.h"
|
||||
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
#include "WallpaperEngine/Data/Model/Types.h"
|
||||
|
||||
namespace WallpaperEngine::Render::Shaders {
|
||||
using json = nlohmann::json;
|
||||
using JSON = WallpaperEngine::Data::JSON::JSON;
|
||||
using namespace WallpaperEngine::Assets;
|
||||
using namespace WallpaperEngine::Data::Model;
|
||||
|
||||
|
@ -1,32 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "WallpaperEngine/Core/DynamicValues/CDynamicValue.h"
|
||||
#include "WallpaperEngine/Data/Utils/TypeCaster.h"
|
||||
#include "WallpaperEngine/Data/Model/DynamicValue.h"
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
namespace WallpaperEngine::Render::Shaders::Variables {
|
||||
class CShaderVariable : public Core::DynamicValues::CDynamicValue {
|
||||
using namespace WallpaperEngine::Data::Model;
|
||||
using namespace WallpaperEngine::Data::Utils;
|
||||
|
||||
class CShaderVariable : public DynamicValue, public TypeCaster {
|
||||
public:
|
||||
virtual ~CShaderVariable () = default;
|
||||
|
||||
template <class T> [[nodiscard]] const T* as () const {
|
||||
if (is <T> ()) {
|
||||
return static_cast <const T*> (this);
|
||||
}
|
||||
|
||||
throw std::bad_cast ();
|
||||
}
|
||||
|
||||
template <class T> [[nodiscard]] T* as () {
|
||||
if (is <T> ()) {
|
||||
return static_cast <T*> (this);
|
||||
}
|
||||
|
||||
throw std::bad_cast ();
|
||||
}
|
||||
|
||||
template <class T> [[nodiscard]] bool is () const {
|
||||
return typeid (*this) == typeid(T);
|
||||
}
|
||||
using DynamicValue::DynamicValue;
|
||||
|
||||
[[nodiscard]] const std::string& getIdentifierName () const;
|
||||
[[nodiscard]] const std::string& getName () const;
|
||||
@ -35,7 +20,7 @@ class CShaderVariable : public Core::DynamicValues::CDynamicValue {
|
||||
void setName (const std::string& name);
|
||||
|
||||
private:
|
||||
std::string m_identifierName = "";
|
||||
std::string m_name = "";
|
||||
std::string m_identifierName;
|
||||
std::string m_name;
|
||||
};
|
||||
} // namespace WallpaperEngine::Render::Shaders::Variables
|
||||
|
@ -4,13 +4,7 @@
|
||||
|
||||
using namespace WallpaperEngine::Render::Shaders::Variables;
|
||||
|
||||
CShaderVariableFloat::CShaderVariableFloat (float defaultValue) :
|
||||
CShaderVariable () {
|
||||
this->update (defaultValue);
|
||||
}
|
||||
|
||||
CShaderVariableFloat::CShaderVariableFloat (float defaultValue, const std::string& name) :
|
||||
CShaderVariable () {
|
||||
CShaderVariable (defaultValue) {
|
||||
this->setName (name);
|
||||
this->update (defaultValue);
|
||||
}
|
||||
|
@ -5,7 +5,8 @@
|
||||
namespace WallpaperEngine::Render::Shaders::Variables {
|
||||
class CShaderVariableFloat final : public CShaderVariable {
|
||||
public:
|
||||
explicit CShaderVariableFloat (float defaultValue);
|
||||
using CShaderVariable::CShaderVariable;
|
||||
|
||||
CShaderVariableFloat (float defaultValue, const std::string& name);
|
||||
};
|
||||
} // namespace WallpaperEngine::Render::Shaders::Variables
|
||||
|
@ -4,13 +4,7 @@
|
||||
|
||||
using namespace WallpaperEngine::Render::Shaders::Variables;
|
||||
|
||||
CShaderVariableInteger::CShaderVariableInteger (int32_t defaultValue) :
|
||||
CShaderVariable () {
|
||||
this->update (defaultValue);
|
||||
}
|
||||
|
||||
CShaderVariableInteger::CShaderVariableInteger (int32_t defaultValue, const std::string& name) :
|
||||
CShaderVariable () {
|
||||
CShaderVariableInteger::CShaderVariableInteger (int defaultValue, const std::string& name) :
|
||||
CShaderVariable (defaultValue) {
|
||||
this->setName (name);
|
||||
this->update (defaultValue);
|
||||
}
|
||||
|
@ -5,7 +5,8 @@
|
||||
namespace WallpaperEngine::Render::Shaders::Variables {
|
||||
class CShaderVariableInteger final : public CShaderVariable {
|
||||
public:
|
||||
explicit CShaderVariableInteger (int32_t defaultValue);
|
||||
CShaderVariableInteger (int32_t defaultValue, const std::string& name);
|
||||
using CShaderVariable::CShaderVariable;
|
||||
|
||||
CShaderVariableInteger (int defaultValue, const std::string& name);
|
||||
};
|
||||
} // namespace WallpaperEngine::Render::Shaders::Variables
|
||||
|
@ -4,13 +4,7 @@
|
||||
|
||||
using namespace WallpaperEngine::Render::Shaders::Variables;
|
||||
|
||||
CShaderVariableVector2::CShaderVariableVector2 (const glm::vec2& defaultValue) :
|
||||
CShaderVariable () {
|
||||
this->update (defaultValue);
|
||||
}
|
||||
|
||||
CShaderVariableVector2::CShaderVariableVector2 (const glm::vec2& defaultValue, const std::string& name) :
|
||||
CShaderVariable () {
|
||||
CShaderVariable (defaultValue) {
|
||||
this->setName (name);
|
||||
this->update (defaultValue);
|
||||
}
|
||||
|
@ -6,7 +6,8 @@
|
||||
namespace WallpaperEngine::Render::Shaders::Variables {
|
||||
class CShaderVariableVector2 final : public CShaderVariable {
|
||||
public:
|
||||
explicit CShaderVariableVector2 (const glm::vec2& defaultValue);
|
||||
using CShaderVariable::CShaderVariable;
|
||||
|
||||
CShaderVariableVector2 (const glm::vec2& defaultValue, const std::string& name);
|
||||
};
|
||||
} // namespace WallpaperEngine::Render::Shaders::Variables
|
||||
|
@ -2,13 +2,7 @@
|
||||
|
||||
using namespace WallpaperEngine::Render::Shaders::Variables;
|
||||
|
||||
CShaderVariableVector3::CShaderVariableVector3 (const glm::vec3& defaultValue) :
|
||||
CShaderVariable () {
|
||||
this->update (defaultValue);
|
||||
}
|
||||
|
||||
CShaderVariableVector3::CShaderVariableVector3 (const glm::vec3& defaultValue, const std::string& name) :
|
||||
CShaderVariable () {
|
||||
CShaderVariable (defaultValue) {
|
||||
this->setName (name);
|
||||
this->update (defaultValue);
|
||||
}
|
||||
|
@ -7,7 +7,8 @@
|
||||
namespace WallpaperEngine::Render::Shaders::Variables {
|
||||
class CShaderVariableVector3 final : public CShaderVariable {
|
||||
public:
|
||||
explicit CShaderVariableVector3 (const glm::vec3& defaultValue);
|
||||
using CShaderVariable::CShaderVariable;
|
||||
|
||||
CShaderVariableVector3 (const glm::vec3& defaultValue, const std::string& name);
|
||||
};
|
||||
} // namespace WallpaperEngine::Render::Shaders::Variables
|
||||
|
@ -4,13 +4,7 @@
|
||||
|
||||
using namespace WallpaperEngine::Render::Shaders::Variables;
|
||||
|
||||
CShaderVariableVector4::CShaderVariableVector4 (const glm::vec4& defaultValue) :
|
||||
CShaderVariable () {
|
||||
this->update (defaultValue);
|
||||
}
|
||||
|
||||
CShaderVariableVector4::CShaderVariableVector4 (const glm::vec4& defaultValue, const std::string& name) :
|
||||
CShaderVariable () {
|
||||
CShaderVariable (defaultValue) {
|
||||
this->setName (name);
|
||||
this->update (defaultValue);
|
||||
}
|
||||
|
@ -6,7 +6,8 @@
|
||||
namespace WallpaperEngine::Render::Shaders::Variables {
|
||||
class CShaderVariableVector4 final : public CShaderVariable {
|
||||
public:
|
||||
explicit CShaderVariableVector4 (const glm::vec4& defaultValue);
|
||||
using CShaderVariable::CShaderVariable;
|
||||
|
||||
CShaderVariableVector4 (const glm::vec4& defaultValue, const std::string& name);
|
||||
};
|
||||
} // namespace WallpaperEngine::Render::Shaders::Variables
|
||||
|
@ -55,7 +55,6 @@ CScene::CScene (
|
||||
this->alias ("_alias_lightCookie", "_rt_shadowAtlas");
|
||||
|
||||
// set clear color
|
||||
// TODO: MAKE USE OF THE REFERENCE POSSIBILITIES?!
|
||||
const glm::vec3 clearColor = scene->colors.clear->value->getVec3 ();
|
||||
|
||||
glClearColor (clearColor.r, clearColor.g, clearColor.b, 1.0f);
|
||||
@ -92,7 +91,6 @@ CScene::CScene (
|
||||
// (it renders directly to the screen, whereas here we never do that from a scene)
|
||||
//
|
||||
|
||||
// TODO: TAKE THIS OUT OF HERE AND INTO THE GENERAL WALLPAPER APPLICATION?!
|
||||
const auto bloomOrigin = glm::vec3 { sceneWidth / 2, sceneHeight / 2, 0.0f };
|
||||
const auto bloomSize = glm::vec2 { sceneWidth, sceneHeight };
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user