mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +08:00
Compare commits
5 Commits
806b65b490
...
cf3774c481
Author | SHA1 | Date | |
---|---|---|---|
![]() |
cf3774c481 | ||
![]() |
ce51cd23fa | ||
![]() |
e3e377ecdd | ||
![]() |
d6831ad40f | ||
![]() |
4dc9a61223 |
@ -198,8 +198,7 @@ if(X11_SUPPORT_FOUND)
|
|||||||
src/WallpaperEngine/Render/Drivers/Output/CX11Output.cpp
|
src/WallpaperEngine/Render/Drivers/Output/CX11Output.cpp
|
||||||
src/WallpaperEngine/Render/Drivers/Output/CX11Output.h
|
src/WallpaperEngine/Render/Drivers/Output/CX11Output.h
|
||||||
src/WallpaperEngine/Render/Drivers/Detectors/CX11FullScreenDetector.cpp
|
src/WallpaperEngine/Render/Drivers/Detectors/CX11FullScreenDetector.cpp
|
||||||
src/WallpaperEngine/Render/Drivers/Detectors/CX11FullScreenDetector.h
|
src/WallpaperEngine/Render/Drivers/Detectors/CX11FullScreenDetector.h)
|
||||||
src/WallpaperEngine/Data/Model/UserSetting.h)
|
|
||||||
SET(X11_INCLUDES
|
SET(X11_INCLUDES
|
||||||
${X11_INCLUDE_DIR}
|
${X11_INCLUDE_DIR}
|
||||||
${XRANDR_INCLUDE_DIR})
|
${XRANDR_INCLUDE_DIR})
|
||||||
@ -284,9 +283,6 @@ add_executable(
|
|||||||
src/WallpaperEngine/Assets/CTexture.h
|
src/WallpaperEngine/Assets/CTexture.h
|
||||||
src/WallpaperEngine/Assets/CTexture.cpp
|
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.cpp
|
||||||
src/WallpaperEngine/Audio/Drivers/Recorders/CPulseAudioPlaybackRecorder.h
|
src/WallpaperEngine/Audio/Drivers/Recorders/CPulseAudioPlaybackRecorder.h
|
||||||
src/WallpaperEngine/Audio/Drivers/Recorders/CPlaybackRecorder.cpp
|
src/WallpaperEngine/Audio/Drivers/Recorders/CPlaybackRecorder.cpp
|
||||||
@ -404,9 +400,6 @@ add_executable(
|
|||||||
src/WallpaperEngine/WebBrowser/CWebBrowserContext.cpp
|
src/WallpaperEngine/WebBrowser/CWebBrowserContext.cpp
|
||||||
src/WallpaperEngine/WebBrowser/CWebBrowserContext.h
|
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.h
|
||||||
src/WallpaperEngine/Core/Projects/CProperty.cpp
|
src/WallpaperEngine/Core/Projects/CProperty.cpp
|
||||||
src/WallpaperEngine/Core/Projects/CPropertyColor.h
|
src/WallpaperEngine/Core/Projects/CPropertyColor.h
|
||||||
@ -427,8 +420,12 @@ add_executable(
|
|||||||
src/WallpaperEngine/Data/Model/Material.h
|
src/WallpaperEngine/Data/Model/Material.h
|
||||||
src/WallpaperEngine/Data/Model/Effect.h
|
src/WallpaperEngine/Data/Model/Effect.h
|
||||||
src/WallpaperEngine/Data/Model/Model.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.cpp
|
||||||
src/WallpaperEngine/Data/Utils/TypeCaster.h
|
src/WallpaperEngine/Data/Utils/TypeCaster.h
|
||||||
|
src/WallpaperEngine/Data/Utils/SFINAE.h
|
||||||
src/WallpaperEngine/Data/Parsers/ProjectParser.cpp
|
src/WallpaperEngine/Data/Parsers/ProjectParser.cpp
|
||||||
src/WallpaperEngine/Data/Parsers/ProjectParser.h
|
src/WallpaperEngine/Data/Parsers/ProjectParser.h
|
||||||
src/WallpaperEngine/Data/Parsers/WallpaperParser.cpp
|
src/WallpaperEngine/Data/Parsers/WallpaperParser.cpp
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
#include "WallpaperEngine/Render/CRenderContext.h"
|
#include "WallpaperEngine/Render/CRenderContext.h"
|
||||||
#include "WallpaperEngine/Render/Drivers/CVideoFactories.h"
|
#include "WallpaperEngine/Render/Drivers/CVideoFactories.h"
|
||||||
|
|
||||||
|
#include "WallpaperEngine/Core/Projects/CProperty.h"
|
||||||
|
|
||||||
#include "WallpaperEngine/Data/Parsers/ProjectParser.h"
|
#include "WallpaperEngine/Data/Parsers/ProjectParser.h"
|
||||||
#include "WallpaperEngine/Data/Dumpers/StringPrinter.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;
|
using namespace WallpaperEngine::Core::Projects;
|
||||||
|
|
||||||
std::shared_ptr<CProperty> CProperty::fromJSON (const json& data, const std::string& name) {
|
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");
|
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);
|
return CPropertyColor::fromJSON (data, name);
|
||||||
if (*type == "bool")
|
if (type == "bool")
|
||||||
return CPropertyBoolean::fromJSON (data, name);
|
return CPropertyBoolean::fromJSON (data, name);
|
||||||
if (*type == "slider")
|
if (type == "slider")
|
||||||
return CPropertySlider::fromJSON (data, name);
|
return CPropertySlider::fromJSON (data, name);
|
||||||
if (*type == "combo")
|
if (type == "combo")
|
||||||
return CPropertyCombo::fromJSON (data, name);
|
return CPropertyCombo::fromJSON (data, name);
|
||||||
if (*type == "text")
|
if (type == "text")
|
||||||
return CPropertyText::fromJSON (data, name);
|
return CPropertyText::fromJSON (data, name);
|
||||||
|
|
||||||
if (*type != "group") {
|
if (type != "group") {
|
||||||
// show the error and ignore this property
|
// show the error and ignore this property
|
||||||
sLog.error ("Unexpected type for property: ", *type);
|
sLog.error ("Unexpected type for property: ", type);
|
||||||
sLog.error (data);
|
sLog.error (data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,18 +37,6 @@ CProperty::CProperty (std::string name, std::string text) :
|
|||||||
m_name (std::move(name)),
|
m_name (std::move(name)),
|
||||||
m_text (std::move(text)) {}
|
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 {
|
const std::string& CProperty::getName () const {
|
||||||
return this->m_name;
|
return this->m_name;
|
||||||
}
|
}
|
||||||
|
@ -1,46 +1,26 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/DynamicValues/CDynamicValue.h"
|
#include "WallpaperEngine/Data/Utils/TypeCaster.h"
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
#include "WallpaperEngine/Data/Model/DynamicValue.h"
|
||||||
|
#include "WallpaperEngine/Data/JSON.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
namespace WallpaperEngine::Core::Projects {
|
||||||
using json = nlohmann::json;
|
using JSON = WallpaperEngine::Data::JSON::JSON;
|
||||||
using namespace WallpaperEngine::Core::DynamicValues;
|
using namespace WallpaperEngine::Data::Model;
|
||||||
|
using namespace WallpaperEngine::Data::Utils;
|
||||||
/**
|
/**
|
||||||
* Represents a property in a background
|
* Represents a property in a background
|
||||||
*
|
*
|
||||||
* Properties are settings that alter how the background looks or works
|
* 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
|
* 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:
|
public:
|
||||||
using UniquePtr = std::unique_ptr<CProperty>;
|
using UniquePtr = std::unique_ptr<CProperty>;
|
||||||
using SharedPtr = std::shared_ptr<CProperty>;
|
using SharedPtr = std::shared_ptr<CProperty>;
|
||||||
using WeakPtr = std::weak_ptr<CProperty>;
|
using WeakPtr = std::weak_ptr<CProperty>;
|
||||||
|
|
||||||
typedef std::function<void(const CProperty*)> function_type;
|
static std::shared_ptr<CProperty> fromJSON (const JSON& data, const std::string& name);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Representation of what the property does and the default values
|
* @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
|
* @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
|
* @return Text of the property
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const std::string& getText () const;
|
[[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:
|
protected:
|
||||||
void propagate () const override;
|
|
||||||
|
|
||||||
CProperty (std::string name, std::string text);
|
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 */
|
/** Name of the property */
|
||||||
const std::string m_name;
|
const std::string m_name;
|
||||||
/** Description of the property for the user */
|
/** Description of the property for the user */
|
||||||
|
@ -2,15 +2,14 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "CPropertyBoolean.h"
|
#include "CPropertyBoolean.h"
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
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> (
|
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),
|
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 ();
|
return ss.str ();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* CPropertyBoolean::getType () const {
|
const char* CPropertyBoolean::getPropertyType () const {
|
||||||
return "bool";
|
return "bool";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include "CProperty.h"
|
#include "CProperty.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
namespace WallpaperEngine::Core::Projects {
|
||||||
using json = nlohmann::json;
|
using JSON = WallpaperEngine::Data::JSON::JSON;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a boolean property
|
* Represents a boolean property
|
||||||
@ -12,10 +12,10 @@ class CPropertyBoolean final : public CProperty {
|
|||||||
public:
|
public:
|
||||||
CPropertyBoolean (bool value, std::string name, std::string text);
|
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;
|
[[nodiscard]] std::string dump () const override;
|
||||||
void set (const std::string& value) override;
|
void set (const std::string& value) override;
|
||||||
|
|
||||||
[[nodiscard]] const char* getType () const override;
|
[[nodiscard]] const char* getPropertyType () const override;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
} // namespace WallpaperEngine::Core::Projects
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "CPropertyColor.h"
|
#include "CPropertyColor.h"
|
||||||
|
|
||||||
|
using namespace WallpaperEngine::Data::Builders;
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
using namespace WallpaperEngine::Core::Projects;
|
||||||
|
|
||||||
glm::vec3 ParseColor (std::string value) {
|
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") {
|
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 {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) {
|
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");
|
return std::make_shared <CPropertyColor> (
|
||||||
const auto text = jsonFindDefault<std::string> (data, "text", "");
|
data.require ("value", "Color property must have a value"),
|
||||||
|
std::move(name),
|
||||||
return std::make_shared <CPropertyColor> (value, std::move(name), text);
|
data.optional <std::string> ("text", "")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPropertyColor::set (const std::string& value) {
|
void CPropertyColor::set (const std::string& value) {
|
||||||
@ -45,7 +47,7 @@ std::string CPropertyColor::dump () const {
|
|||||||
return ss.str ();
|
return ss.str ();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* CPropertyColor::getType () const {
|
const char* CPropertyColor::getPropertyType () const {
|
||||||
return "color";
|
return "color";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
#include "CProperty.h"
|
#include "CProperty.h"
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
#include "WallpaperEngine/Data/JSON.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
namespace WallpaperEngine::Core::Projects {
|
||||||
using json = nlohmann::json;
|
using JSON = WallpaperEngine::Data::JSON::JSON;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a color property
|
* Represents a color property
|
||||||
@ -14,10 +14,10 @@ class CPropertyColor final : public CProperty {
|
|||||||
public:
|
public:
|
||||||
CPropertyColor (const std::string& color, std::string name, std::string text);
|
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;
|
[[nodiscard]] std::string dump () const override;
|
||||||
void set (const std::string& value) override;
|
void set (const std::string& value) override;
|
||||||
|
|
||||||
[[nodiscard]] const char* getType () const override;
|
[[nodiscard]] const char* getPropertyType () const override;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
} // namespace WallpaperEngine::Core::Projects
|
||||||
|
@ -3,34 +3,33 @@
|
|||||||
|
|
||||||
#include "CPropertyCombo.h"
|
#include "CPropertyCombo.h"
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
#include "WallpaperEngine/Logging/CLog.h"
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
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;
|
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");
|
sLog.exception ("Property combo options should be an array");
|
||||||
|
|
||||||
for (auto& cur : (*options)) {
|
for (auto& cur : options) {
|
||||||
// TODO: PROPERLY REPORT THESE ISSUES
|
// TODO: PROPERLY REPORT THESE ISSUES
|
||||||
if (!cur.is_object ())
|
if (!cur.is_object ())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// check for label and value to ensure they're there
|
// check for label and value to ensure they're there
|
||||||
values.push_back ({
|
values.push_back ({
|
||||||
.label = jsonFindRequired<std::string> (cur, "label", "Label is required for a property combo option"),
|
.label = cur.require ("label", "Label is required for a property combo option"),
|
||||||
.value = jsonFindRequired<std::string> (cur, "value", "Value is required for a property combo option")
|
.value = cur.require ("value", "Value is required for a property combo option")
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::make_shared <CPropertyCombo> (
|
return std::make_shared <CPropertyCombo> (
|
||||||
std::move(name),
|
std::move(name),
|
||||||
jsonFindDefault<std::string> (data, "text", ""),
|
data.optional <std::string> ("text", ""),
|
||||||
jsonFindRequired<std::string> (data, "value", "Value is required for a property combo"),
|
data.require ("value", "Value is required for a property combo"),
|
||||||
values
|
values
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -102,6 +101,6 @@ int CPropertyCombo::translateValueToIndex (const std::string& value) const {
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* CPropertyCombo::getType () const {
|
const char* CPropertyCombo::getPropertyType () const {
|
||||||
return "combo";
|
return "combo";
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include "CProperty.h"
|
#include "CProperty.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
namespace WallpaperEngine::Core::Projects {
|
||||||
using json = nlohmann::json;
|
using JSON = WallpaperEngine::Data::JSON::JSON;;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents different combo values
|
* Represents different combo values
|
||||||
@ -23,7 +23,7 @@ struct CPropertyComboValue {
|
|||||||
*/
|
*/
|
||||||
class CPropertyCombo final : public CProperty {
|
class CPropertyCombo final : public CProperty {
|
||||||
public:
|
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 (
|
CPropertyCombo (
|
||||||
std::string name, std::string text, const std::string& defaultValue,
|
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;
|
void set (const std::string& value) override;
|
||||||
int translateValueToIndex (const std::string& value) const;
|
int translateValueToIndex (const std::string& value) const;
|
||||||
|
|
||||||
[[nodiscard]] const char* getType () const override;
|
[[nodiscard]] const char* getPropertyType () const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** List of values available to select */
|
/** List of values available to select */
|
||||||
|
@ -4,12 +4,12 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
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 value = data.find ("value");
|
||||||
const auto text = jsonFindDefault<std::string> (data, "text", "");
|
const auto text = data.optional <std::string> ("text", "");
|
||||||
const auto min = jsonFindDefault (data, "min", 0.0f);
|
const auto min = data.optional ("min", 0.0f);
|
||||||
const auto max = jsonFindDefault (data, "max", 0.0f);
|
const auto max = data.optional ("max", 0.0f);
|
||||||
const auto step = jsonFindDefault (data, "step", 0.0f);
|
const auto step = data.optional ("step", 0.0f);
|
||||||
|
|
||||||
return std::make_shared <CPropertySlider> (*value, name, text, min, max, step);
|
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);
|
this->update (newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* CPropertySlider::getType () const {
|
const char* CPropertySlider::getPropertyType () const {
|
||||||
return "slider";
|
return "slider";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,10 +2,8 @@
|
|||||||
|
|
||||||
#include "CProperty.h"
|
#include "CProperty.h"
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
namespace WallpaperEngine::Core::Projects {
|
||||||
using json = nlohmann::json;
|
using JSON = WallpaperEngine::Data::JSON::JSON;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a slider value with a minimum and maximum value
|
* Represents a slider value with a minimum and maximum value
|
||||||
@ -14,7 +12,7 @@ class CPropertySlider final : public CProperty {
|
|||||||
public:
|
public:
|
||||||
CPropertySlider (float value, const std::string& name, const std::string& text, float min, float max, float step);
|
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
|
* @return The slider's minimum value
|
||||||
*/
|
*/
|
||||||
@ -30,7 +28,7 @@ class CPropertySlider final : public CProperty {
|
|||||||
[[nodiscard]] std::string dump () const override;
|
[[nodiscard]] std::string dump () const override;
|
||||||
void set (const std::string& value) override;
|
void set (const std::string& value) override;
|
||||||
|
|
||||||
[[nodiscard]] const char* getType () const override;
|
[[nodiscard]] const char* getPropertyType () const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Minimum value */
|
/** Minimum value */
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
#include "CPropertyText.h"
|
#include "CPropertyText.h"
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
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
|
//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 {
|
std::string CPropertyText::dump () const {
|
||||||
@ -24,7 +26,7 @@ void CPropertyText::set (const std::string& value) {
|
|||||||
this->m_text = value;
|
this->m_text = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* CPropertyText::getType () const {
|
const char* CPropertyText::getPropertyType () const {
|
||||||
return "text";
|
return "text";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include "CProperty.h"
|
#include "CProperty.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
namespace WallpaperEngine::Core::Projects {
|
||||||
using json = nlohmann::json;
|
using JSON = WallpaperEngine::Data::JSON::JSON;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a text property
|
* Represents a text property
|
||||||
@ -12,11 +12,11 @@ class CPropertyText final : public CProperty {
|
|||||||
public:
|
public:
|
||||||
CPropertyText (std::string name, std::string text);
|
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;
|
[[nodiscard]] std::string dump () const override;
|
||||||
void set (const std::string& value) override;
|
void set (const std::string& value) override;
|
||||||
|
|
||||||
[[nodiscard]] const char* getType () const override;
|
[[nodiscard]] const char* getPropertyType () const override;
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
} // namespace WallpaperEngine::Core::Projects
|
||||||
|
@ -9,9 +9,7 @@ class UserSettingBuilder {
|
|||||||
public:
|
public:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static UserSettingUniquePtr fromValue (T defaultValue) {
|
static UserSettingUniquePtr fromValue (T defaultValue) {
|
||||||
DynamicValueUniquePtr value = std::make_unique <DynamicValue> ();
|
DynamicValueUniquePtr value = std::make_unique <DynamicValue> (defaultValue);
|
||||||
|
|
||||||
value->update (defaultValue);
|
|
||||||
|
|
||||||
return std::make_unique <UserSetting> (UserSetting {
|
return std::make_unique <UserSetting> (UserSetting {
|
||||||
.value = std::move (value),
|
.value = std::move (value),
|
||||||
|
@ -2,11 +2,15 @@
|
|||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/detail/qualifier.hpp>
|
||||||
|
#include <glm/detail/type_vec1.hpp>
|
||||||
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
#include "WallpaperEngine/Logging/CLog.h"
|
||||||
|
#include "WallpaperEngine/Data/Utils/SFINAE.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Data::Builders {
|
namespace WallpaperEngine::Data::Builders {
|
||||||
|
using namespace WallpaperEngine::Data::Utils::SFINAE;
|
||||||
|
|
||||||
class VectorBuilder {
|
class VectorBuilder {
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
@ -60,7 +64,7 @@ class VectorBuilder {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
template <int length, typename type, glm::qualifier qualifier>
|
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 ();
|
const char* p = str.c_str ();
|
||||||
|
|
||||||
// get up to 4 spaces
|
// 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 <>
|
template <>
|
||||||
@ -127,7 +140,7 @@ inline float VectorBuilder::convert<float> (const char* str) {
|
|||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline int VectorBuilder::convert<int> (const char* str) {
|
inline int VectorBuilder::convert<int> (const char* str) {
|
||||||
return std::strtol (str, nullptr, 10);
|
return std::stoi (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
@ -265,16 +265,23 @@ void StringPrinter::printEffect (const Effect& effect) {
|
|||||||
|
|
||||||
void StringPrinter::printEffectPass (const EffectPass& effectPass) {
|
void StringPrinter::printEffectPass (const EffectPass& effectPass) {
|
||||||
if (effectPass.command.has_value ()) {
|
if (effectPass.command.has_value ()) {
|
||||||
const auto& command = effectPass.command.value ();
|
this->m_out << "Command: " << (*effectPass.command == Command_Copy ? "copy" : "swap");
|
||||||
|
|
||||||
this->m_out << "Command: " << (command.command == Command_Copy ? "copy" : "swap");
|
if (effectPass.target.has_value () || effectPass.source.has_value ()) {
|
||||||
this->lineEnd ();
|
this->lineEnd ();
|
||||||
this->m_out << "Source: " << command.source;
|
}
|
||||||
this->lineEnd ();
|
}
|
||||||
this->m_out << "Target: " << command.target;
|
|
||||||
} else {
|
|
||||||
if (effectPass.target.has_value ()) {
|
if (effectPass.target.has_value ()) {
|
||||||
this->m_out << "Target: " << effectPass.target.value ();
|
this->m_out << "Target: " << effectPass.target.value ();
|
||||||
|
|
||||||
|
if (effectPass.source.has_value ()) {
|
||||||
|
this->lineEnd ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (effectPass.source.has_value ()) {
|
||||||
|
this->m_out << "Source: " << effectPass.source.value ();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!effectPass.binds.empty ()) {
|
if (!effectPass.binds.empty ()) {
|
||||||
@ -297,7 +304,8 @@ void StringPrinter::printEffectPass (const EffectPass& effectPass) {
|
|||||||
this->lineEnd ();
|
this->lineEnd ();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->printMaterial (*effectPass.material);
|
if (effectPass.material.has_value ()) {
|
||||||
|
this->printMaterial (**effectPass.material);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Data::JSON;
|
using namespace WallpaperEngine::Data::JSON;
|
||||||
using namespace WallpaperEngine::Data::Model;
|
using namespace WallpaperEngine::Data::Model;
|
||||||
|
using namespace WallpaperEngine::Data::Parsers;
|
||||||
|
|
||||||
UserSettingUniquePtr JsonExtensions::user (const std::string& key, const Properties& properties) const {
|
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");
|
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/UserSettingBuilder.h"
|
||||||
#include "WallpaperEngine/Data/Builders/VectorBuilder.h"
|
#include "WallpaperEngine/Data/Builders/VectorBuilder.h"
|
||||||
|
#include "WallpaperEngine/Data/Utils/SFINAE.h"
|
||||||
#include "WallpaperEngine/Data/Model/Types.h"
|
#include "WallpaperEngine/Data/Model/Types.h"
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
#include "WallpaperEngine/Logging/CLog.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Data::Parsers {
|
|
||||||
class UserSettingParser;
|
|
||||||
}
|
|
||||||
namespace WallpaperEngine::Data::JSON {
|
namespace WallpaperEngine::Data::JSON {
|
||||||
using namespace WallpaperEngine::Data::Builders;
|
using namespace WallpaperEngine::Data::Builders;
|
||||||
using namespace WallpaperEngine::Data::Parsers;
|
|
||||||
using namespace WallpaperEngine::Data::Model;
|
using namespace WallpaperEngine::Data::Model;
|
||||||
|
using 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;
|
|
||||||
};
|
|
||||||
|
|
||||||
class JsonExtensions;
|
class JsonExtensions;
|
||||||
|
|
||||||
|
@ -1,223 +1,89 @@
|
|||||||
#include <algorithm>
|
#include "DynamicValue.h"
|
||||||
#include "CDynamicValue.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::DynamicValues;
|
using namespace WallpaperEngine::Data::Model;
|
||||||
|
|
||||||
CDynamicValue::~CDynamicValue() {
|
DynamicValue::DynamicValue (const glm::ivec4& value) {
|
||||||
for (auto* connection : this->m_incomingConnections) {
|
this->update (value);
|
||||||
connection->destroyOutgoingConnection (this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDynamicValue::update(float newValue) {
|
DynamicValue::DynamicValue (const glm::ivec3& value) {
|
||||||
this->m_ivec4 = glm::ivec4(static_cast<int> (newValue));
|
this->update (value);
|
||||||
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 CDynamicValue::update(int newValue) {
|
DynamicValue::DynamicValue (const glm::ivec2& value) {
|
||||||
this->m_ivec4 = glm::ivec4(newValue);
|
this->update (value);
|
||||||
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 CDynamicValue::update(bool newValue) {
|
DynamicValue::DynamicValue (const glm::vec4& value) {
|
||||||
this->m_ivec4 = glm::ivec4(newValue);
|
this->update (value);
|
||||||
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 CDynamicValue::update(const glm::vec2& newValue) {
|
DynamicValue::DynamicValue (const glm::vec3& value) {
|
||||||
this->m_ivec4 = glm::ivec4(newValue, 0, 0);
|
this->update (value);
|
||||||
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 CDynamicValue::update(const glm::vec3& newValue) {
|
DynamicValue::DynamicValue (const glm::vec2& value) {
|
||||||
this->m_ivec4 = glm::ivec4(newValue, 0);
|
this->update (value);
|
||||||
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 CDynamicValue::update(const glm::vec4& newValue) {
|
DynamicValue::DynamicValue (float value) {
|
||||||
this->m_ivec4 = glm::ivec4(newValue);
|
this->update (value);
|
||||||
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 CDynamicValue::update(const glm::ivec2& newValue) {
|
DynamicValue::DynamicValue (int value) {
|
||||||
this->m_ivec4 = glm::ivec4(newValue, 0, 0);
|
this->update (value);
|
||||||
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 CDynamicValue::update(const glm::ivec3& newValue) {
|
DynamicValue::DynamicValue (bool value) {
|
||||||
this->m_ivec4 = glm::ivec4(newValue, 0);
|
this->update (value);
|
||||||
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 CDynamicValue::update(const glm::ivec4& newValue) {
|
DynamicValue::~DynamicValue () {
|
||||||
this->m_ivec4 = glm::ivec4(newValue);
|
this->disconnect ();
|
||||||
this->m_ivec3 = glm::ivec3(newValue);
|
this->m_listeners.clear ();
|
||||||
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 CDynamicValue::connectOutgoing (CDynamicValue* value) const {
|
const glm::ivec4& DynamicValue::getIVec4 () 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 {
|
|
||||||
return this->m_ivec4;
|
return this->m_ivec4;
|
||||||
}
|
}
|
||||||
|
|
||||||
const glm::ivec3& CDynamicValue::getIVec3 () const {
|
const glm::ivec3& DynamicValue::getIVec3 () const {
|
||||||
return this->m_ivec3;
|
return this->m_ivec3;
|
||||||
}
|
}
|
||||||
|
|
||||||
const glm::ivec2& CDynamicValue::getIVec2 () const {
|
const glm::ivec2& DynamicValue::getIVec2 () const {
|
||||||
return this->m_ivec2;
|
return this->m_ivec2;
|
||||||
}
|
}
|
||||||
|
|
||||||
const glm::vec4& CDynamicValue::getVec4 () const {
|
const glm::vec4& DynamicValue::getVec4 () const {
|
||||||
return this->m_vec4;
|
return this->m_vec4;
|
||||||
}
|
}
|
||||||
|
|
||||||
const glm::vec3& CDynamicValue::getVec3 () const {
|
const glm::vec3& DynamicValue::getVec3 () const {
|
||||||
return this->m_vec3;
|
return this->m_vec3;
|
||||||
}
|
}
|
||||||
|
|
||||||
const glm::vec2& CDynamicValue::getVec2 () const {
|
const glm::vec2& DynamicValue::getVec2 () const {
|
||||||
return this->m_vec2;
|
return this->m_vec2;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float& CDynamicValue::getFloat () const {
|
const float& DynamicValue::getFloat () const {
|
||||||
return this->m_float;
|
return this->m_float;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int& CDynamicValue::getInt () const {
|
const int& DynamicValue::getInt () const {
|
||||||
return this->m_int;
|
return this->m_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool& CDynamicValue::getBool () const {
|
const bool& DynamicValue::getBool () const {
|
||||||
return this->m_bool;
|
return this->m_bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
CDynamicValue::UnderlyingType CDynamicValue::getType () const {
|
DynamicValue::UnderlyingType DynamicValue::getType () const {
|
||||||
return this->m_type;
|
return this->m_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CDynamicValue::toString () const {
|
std::string DynamicValue::toString () const {
|
||||||
switch (this->m_type) {
|
switch (this->m_type) {
|
||||||
case UnderlyingType::Float:
|
case UnderlyingType::Float:
|
||||||
return std::to_string (this->m_float);
|
return std::to_string (this->m_float);
|
||||||
@ -241,3 +107,183 @@ std::string CDynamicValue::toString () const {
|
|||||||
return "Unknown conversion for dynamic value of type: " + std::to_string (static_cast<int> (this->m_type));
|
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;
|
||||||
|
};
|
||||||
|
}
|
@ -14,24 +14,18 @@ struct FBO {
|
|||||||
std::string name;
|
std::string name;
|
||||||
std::string format;
|
std::string format;
|
||||||
float scale;
|
float scale;
|
||||||
};
|
bool unique;
|
||||||
|
|
||||||
struct PassCommand {
|
|
||||||
/** The type of command to execute */
|
|
||||||
PassCommandType command;
|
|
||||||
/** The target of the command (where to draw to) */
|
|
||||||
std::string target;
|
|
||||||
/** The source of the command (where to draw from) */
|
|
||||||
std::string source;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EffectPass {
|
struct EffectPass {
|
||||||
/** The material to use for this effect's pass */
|
/** The material to use for this effect's pass */
|
||||||
MaterialUniquePtr material;
|
std::optional<MaterialUniquePtr> material;
|
||||||
/** Texture bindings for this effect's pass */
|
/** Texture bindings for this effect's pass */
|
||||||
TextureMap binds;
|
TextureMap binds;
|
||||||
/** The command this material executes (if specified) */
|
/** The command this material executes (if specified) */
|
||||||
std::optional <PassCommand> command;
|
std::optional <PassCommandType> command;
|
||||||
|
/** The source this material renders from (if specified) */
|
||||||
|
std::optional <std::string> source;
|
||||||
/** The target this material renders to (if specified) */
|
/** The target this material renders to (if specified) */
|
||||||
std::optional <std::string> target;
|
std::optional <std::string> target;
|
||||||
};
|
};
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <optional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "WallpaperEngine/Assets/CContainer.h"
|
#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 {
|
namespace WallpaperEngine::Data::Model {
|
||||||
struct Project;
|
struct Project;
|
||||||
@ -19,6 +25,7 @@ class Image;
|
|||||||
struct ImageEffect;
|
struct ImageEffect;
|
||||||
struct ImageEffectPassOverride;
|
struct ImageEffectPassOverride;
|
||||||
class Particle;
|
class Particle;
|
||||||
|
class DynamicValue;
|
||||||
struct Material;
|
struct Material;
|
||||||
struct MaterialPass;
|
struct MaterialPass;
|
||||||
struct FBO;
|
struct FBO;
|
||||||
@ -33,7 +40,6 @@ using Property = WallpaperEngine::Core::Projects::CProperty;
|
|||||||
using PropertySharedPtr = std::shared_ptr <Property>;
|
using PropertySharedPtr = std::shared_ptr <Property>;
|
||||||
using PropertyWeakPtr = std::weak_ptr <Property>;
|
using PropertyWeakPtr = std::weak_ptr <Property>;
|
||||||
using Properties = std::map <std::string, PropertySharedPtr>;
|
using Properties = std::map <std::string, PropertySharedPtr>;
|
||||||
using DynamicValue = WallpaperEngine::Core::DynamicValues::CDynamicValue;
|
|
||||||
using DynamicValueUniquePtr = std::unique_ptr <DynamicValue>;
|
using DynamicValueUniquePtr = std::unique_ptr <DynamicValue>;
|
||||||
using DynamicValueSharedPtr = std::shared_ptr <DynamicValue>;
|
using DynamicValueSharedPtr = std::shared_ptr <DynamicValue>;
|
||||||
using DynamicValueWeakPtr = std::weak_ptr <DynamicValue>;
|
using DynamicValueWeakPtr = std::weak_ptr <DynamicValue>;
|
||||||
|
@ -3,11 +3,9 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
#include "DynamicValue.h"
|
||||||
#include "Types.h"
|
#include "Types.h"
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/DynamicValues/CDynamicValue.h"
|
|
||||||
#include "WallpaperEngine/Core/Projects/CProperty.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Data::Model {
|
namespace WallpaperEngine::Data::Model {
|
||||||
struct ConditionInfo {
|
struct ConditionInfo {
|
||||||
public:
|
public:
|
||||||
|
@ -80,7 +80,7 @@ struct SceneData {
|
|||||||
* Shake effect configuration
|
* Shake effect configuration
|
||||||
*/
|
*/
|
||||||
struct {
|
struct {
|
||||||
bool enabled;
|
UserSettingUniquePtr enabled;
|
||||||
float amplitude;
|
float amplitude;
|
||||||
float roughness;
|
float roughness;
|
||||||
float speed;
|
float speed;
|
||||||
|
@ -52,27 +52,17 @@ std::vector <EffectPassUniquePtr> EffectParser::parseEffectPasses (const JSON& i
|
|||||||
|
|
||||||
for (const auto& cur : it) {
|
for (const auto& cur : it) {
|
||||||
const auto binds = cur.optional ("bind");
|
const auto binds = cur.optional ("bind");
|
||||||
std::optional <PassCommand> command = std::nullopt;
|
const auto command = cur.optional ("command");
|
||||||
|
const auto material = cur.optional ("material");
|
||||||
|
|
||||||
if (cur.contains ("command")) {
|
// TODO: CAN TARGET BE SET IF MATERIAL IS SET?
|
||||||
command = {
|
|
||||||
.command = cur.require <std::string> ("command", "Material command must have a command") == "copy"
|
|
||||||
? Command_Copy
|
|
||||||
: Command_Swap,
|
|
||||||
.target = cur.require <std::string> ("target", "Material command must have a target"),
|
|
||||||
.source = cur.require <std::string> ("source", "Material command must have a source"),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
result.push_back (std::make_unique <EffectPass> (EffectPass {
|
result.push_back (std::make_unique <EffectPass> (EffectPass {
|
||||||
.material = MaterialParser::load (project, cur.require <std::string> ("material", "Effect pass must have a material")),
|
.material = material.has_value () ? MaterialParser::load (project, *material) : std::optional<MaterialUniquePtr> {},
|
||||||
.binds = binds.has_value () ? parseBinds (binds.value ()) : std::map<int, std::string> {},
|
.binds = binds.has_value () ? parseBinds (binds.value ()) : std::map<int, std::string> {},
|
||||||
.command = command,
|
.command = command.has_value () ? (command.value () == "copy" ? Command_Copy : Command_Swap) : std::optional<PassCommandType> {},
|
||||||
// target is a bit special: if the material is a command this will be nullopt
|
.source = command.has_value () ? cur.require <std::string> ("source", "Effect command must have a source") : cur.optional <std::string> ("source"),
|
||||||
// and the actual target will be set in the command itself, otherwise it will
|
.target = command.has_value () ? cur.require <std::string> ("target", "Effect command must have a target") : cur.optional <std::string> ("target"),
|
||||||
// be set to whatever is in the json, which is not required to be present for
|
|
||||||
// normal materials
|
|
||||||
.target = command.has_value () ? std::nullopt : cur.optional <std::string> ("target"),
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,6 +98,7 @@ std::vector <FBOUniquePtr> EffectParser::parseFBOs (const JSON& it) {
|
|||||||
.name = cur.require <std::string> ("name", "FBO must have a name"),
|
.name = cur.require <std::string> ("name", "FBO must have a name"),
|
||||||
.format = cur.optional <std::string> ("format", "rgba8888"),
|
.format = cur.optional <std::string> ("format", "rgba8888"),
|
||||||
.scale = cur.optional ("scale", 1.0f),
|
.scale = cur.optional ("scale", 1.0f),
|
||||||
|
.unique = cur.optional ("unique", false),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "WallpaperParser.h"
|
#include "WallpaperParser.h"
|
||||||
|
|
||||||
#include "WallpaperEngine/Data/Model/Wallpaper.h"
|
#include "WallpaperEngine/Data/Model/Wallpaper.h"
|
||||||
|
#include "WallpaperEngine/Core/Projects/CProperty.h"
|
||||||
|
|
||||||
using namespace WallpaperEngine::Data::Parsers;
|
using namespace WallpaperEngine::Data::Parsers;
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ SceneUniquePtr WallpaperParser::parseScene (const JSON& file, Project& project)
|
|||||||
.mouseInfluence = general.optional ("cameraparallaxmouseinfluence", 1.0f),
|
.mouseInfluence = general.optional ("cameraparallaxmouseinfluence", 1.0f),
|
||||||
},
|
},
|
||||||
.shake = {
|
.shake = {
|
||||||
.enabled = general.optional ("camerashake", false),
|
.enabled = general.user ("camerashake", properties, false),
|
||||||
.amplitude = general.optional ("camerashakeamplitude", 0.0f),
|
.amplitude = general.optional ("camerashakeamplitude", 0.0f),
|
||||||
.roughness = general.optional ("camerashakeroughness", 0.0f),
|
.roughness = general.optional ("camerashakeroughness", 0.0f),
|
||||||
.speed = general.optional ("camerashakespeed", 0.0f),
|
.speed = general.optional ("camerashakespeed", 0.0f),
|
||||||
|
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
|
#pragma once
|
||||||
|
|
||||||
|
#include <glm/vec2.hpp>
|
||||||
|
|
||||||
#include "CFBO.h"
|
#include "CFBO.h"
|
||||||
#include "WallpaperEngine/Data/Model/Effect.h"
|
#include "WallpaperEngine/Data/Model/Effect.h"
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "WallpaperEngine/Data/Parsers/MaterialParser.h"
|
#include "WallpaperEngine/Data/Parsers/MaterialParser.h"
|
||||||
#include "WallpaperEngine/Data/Builders/UserSettingBuilder.h"
|
|
||||||
#include "WallpaperEngine/Data/Model/Object.h"
|
#include "WallpaperEngine/Data/Model/Object.h"
|
||||||
#include "WallpaperEngine/Data/Model/Material.h"
|
#include "WallpaperEngine/Data/Model/Material.h"
|
||||||
|
|
||||||
@ -90,7 +89,7 @@ CImage::CImage (Wallpapers::CScene& scene, const Image& image) :
|
|||||||
if (!textures.empty ()) {
|
if (!textures.empty ()) {
|
||||||
std::string textureName = textures.begin ()->second;
|
std::string textureName = textures.begin ()->second;
|
||||||
|
|
||||||
if (textureName.find ("_rt_") == 0) {
|
if (textureName.find ("_rt_") == 0 || textureName.find ("_alias_") == 0) {
|
||||||
this->m_texture = this->getScene ().findFBO (textureName);
|
this->m_texture = this->getScene ().findFBO (textureName);
|
||||||
} else {
|
} else {
|
||||||
// get the first texture on the first pass (this one represents the image assigned to this object)
|
// get the first texture on the first pass (this one represents the image assigned to this object)
|
||||||
@ -231,25 +230,38 @@ CImage::CImage (Wallpapers::CScene& scene, const Image& image) :
|
|||||||
|
|
||||||
void CImage::setup () {
|
void CImage::setup () {
|
||||||
// do not double-init stuff, that's bad!
|
// do not double-init stuff, that's bad!
|
||||||
if (this->m_initialized)
|
if (this->m_initialized) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: SETUP RECALCULATION OF THINGS WHEN A VISIBILITY VALUE CHANGES!!
|
||||||
|
if (!this->m_image.visible->value->getBool ()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: SUPPORT PASSTHROUGH (IT'S A SHADER)
|
// TODO: SUPPORT PASSTHROUGH (IT'S A SHADER)
|
||||||
// passthrough images without effects are bad, do not draw them
|
// passthrough images without effects are bad, do not draw them
|
||||||
if (this->m_image.model->passthrough && this->m_image.effects.empty ())
|
if (this->m_image.model->passthrough && this->m_image.effects.empty ()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// add blendmode to the combos
|
// copy pass to the composite layer
|
||||||
for (const auto& cur : this->getImage ().model->material->passes)
|
for (const auto& cur : this->getImage ().model->material->passes) {
|
||||||
this->m_passes.push_back (
|
this->m_passes.push_back (
|
||||||
new CPass (*this, std::make_shared<CFBOProvider> (this), *cur, std::nullopt, std::nullopt, std::nullopt)
|
new CPass (*this, std::make_shared<CFBOProvider> (this), *cur, std::nullopt, std::nullopt, std::nullopt)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: MAYBE GET RID OF THE WHOLE EFFECT CLASS AND PROCESS THE EFFECTS DIRECTLY TO SIMPLIFY RENDERING CODE?
|
|
||||||
// prepare the passes list
|
// prepare the passes list
|
||||||
if (!this->getImage ().effects.empty ()) {
|
if (!this->getImage ().effects.empty ()) {
|
||||||
// generate the effects used by this material
|
// generate the effects used by this material
|
||||||
for (const auto& cur : this->m_image.effects) {
|
for (const auto& cur : this->m_image.effects) {
|
||||||
|
// do not add non-visible effects, this might need some adjustements tho as some effects might not be visible
|
||||||
|
// but affect the output of the image...
|
||||||
|
if (!cur->visible->value->getBool ()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
auto fboProvider = std::make_shared<CFBOProvider> (this);
|
auto fboProvider = std::make_shared<CFBOProvider> (this);
|
||||||
|
|
||||||
// create all the fbos for this effect
|
// create all the fbos for this effect
|
||||||
@ -265,10 +277,51 @@ void CImage::setup () {
|
|||||||
auto endOverride = cur->passOverrides.end ();
|
auto endOverride = cur->passOverrides.end ();
|
||||||
|
|
||||||
for (; curEffect != endEffect; curEffect++) {
|
for (; curEffect != endEffect; curEffect++) {
|
||||||
auto curPass = (*curEffect)->material->passes.begin ();
|
if (!(*curEffect)->material.has_value ()) {
|
||||||
auto endPass = (*curEffect)->material->passes.end ();
|
if (!(*curEffect)->command.has_value ()) {
|
||||||
|
sLog.error ("Pass without material and command not supported");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const auto override = curOverride != endOverride
|
if (!(*curEffect)->source.has_value ()) {
|
||||||
|
sLog.error ("Pass without material and source not supported");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(*curEffect)->target.has_value ()) {
|
||||||
|
sLog.error ("Pass without material and target not supported");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((*curEffect)->command != Command_Copy) {
|
||||||
|
sLog.error ("Only copy command is supported for pass without material");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto virtualPass = MaterialPass {
|
||||||
|
.blending = "normal",
|
||||||
|
.cullmode = "nocull",
|
||||||
|
.depthtest = "disabled",
|
||||||
|
.depthwrite = "disabled",
|
||||||
|
.shader = "commands/copy",
|
||||||
|
.textures = {
|
||||||
|
{0, *(*curEffect)->source}
|
||||||
|
},
|
||||||
|
.combos = {}
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto& config = this->m_virtualPassess.emplace_back (virtualPass);
|
||||||
|
|
||||||
|
// build a pass for a copy shader
|
||||||
|
this->m_passes.push_back (
|
||||||
|
new CPass (*this, fboProvider, config, std::nullopt, std::nullopt, (*curEffect)->target.value ())
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
auto curPass = (*curEffect)->material.value ()->passes.begin ();
|
||||||
|
auto endPass = (*curEffect)->material.value ()->passes.end ();
|
||||||
|
|
||||||
|
const auto override =
|
||||||
|
curOverride != endOverride
|
||||||
? **curOverride
|
? **curOverride
|
||||||
: std::optional<std::reference_wrapper<const ImageEffectPassOverride>> (std::nullopt);
|
: std::optional<std::reference_wrapper<const ImageEffectPassOverride>> (std::nullopt);
|
||||||
const auto target = (*curEffect)->target.has_value ()
|
const auto target = (*curEffect)->target.has_value ()
|
||||||
@ -276,9 +329,7 @@ void CImage::setup () {
|
|||||||
: std::optional<std::reference_wrapper<std::string>> (std::nullopt);
|
: std::optional<std::reference_wrapper<std::string>> (std::nullopt);
|
||||||
|
|
||||||
this->m_passes.push_back (
|
this->m_passes.push_back (
|
||||||
new CPass (
|
new CPass (*this, fboProvider, **curPass, override, (*curEffect)->binds, target));
|
||||||
*this, fboProvider, **curPass, override, (*curEffect)->binds, target)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (curOverride != endOverride) {
|
if (curOverride != endOverride) {
|
||||||
curOverride++;
|
curOverride++;
|
||||||
@ -286,7 +337,9 @@ void CImage::setup () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// extra render pass if there's any blending to be done
|
||||||
if (this->m_image.colorBlendMode > 0) {
|
if (this->m_image.colorBlendMode > 0) {
|
||||||
this->m_materials.colorBlending.material = MaterialParser::load (this->getScene ().getScene ().project, "materials/util/effectpassthrough.json");
|
this->m_materials.colorBlending.material = MaterialParser::load (this->getScene ().getScene ().project, "materials/util/effectpassthrough.json");
|
||||||
this->m_materials.colorBlending.override = std::make_unique<ImageEffectPassOverride> (ImageEffectPassOverride {
|
this->m_materials.colorBlending.override = std::make_unique<ImageEffectPassOverride> (ImageEffectPassOverride {
|
||||||
@ -322,8 +375,9 @@ void CImage::setup () {
|
|||||||
// calculate full animation time (if any)
|
// calculate full animation time (if any)
|
||||||
this->m_animationTime = 0.0f;
|
this->m_animationTime = 0.0f;
|
||||||
|
|
||||||
for (const auto& cur : this->getTexture ()->getFrames ())
|
for (const auto& cur : this->getTexture ()->getFrames ()) {
|
||||||
this->m_animationTime += cur->frametime;
|
this->m_animationTime += cur->frametime;
|
||||||
|
}
|
||||||
|
|
||||||
this->setupPasses ();
|
this->setupPasses ();
|
||||||
this->m_initialized = true;
|
this->m_initialized = true;
|
||||||
@ -341,6 +395,8 @@ void CImage::setupPasses () {
|
|||||||
|
|
||||||
for (; cur != end; ++cur) {
|
for (; cur != end; ++cur) {
|
||||||
// TODO: PROPERLY CHECK EFFECT'S VISIBILITY AND TAKE IT INTO ACCOUNT
|
// TODO: PROPERLY CHECK EFFECT'S VISIBILITY AND TAKE IT INTO ACCOUNT
|
||||||
|
// TODO: THIS REQUIRES ON-THE-FLY EVALUATION OF EFFECTS VISIBILITY TO FIGURE OUT
|
||||||
|
// TODO: WHICH ONE IS THE LAST + A FEW OTHER THINGS
|
||||||
Effects::CPass* pass = *cur;
|
Effects::CPass* pass = *cur;
|
||||||
std::shared_ptr<const CFBO> prevDrawTo = drawTo;
|
std::shared_ptr<const CFBO> prevDrawTo = drawTo;
|
||||||
GLuint spacePosition = (first) ? this->getCopySpacePosition () : this->getPassSpacePosition ();
|
GLuint spacePosition = (first) ? this->getCopySpacePosition () : this->getPassSpacePosition ();
|
||||||
|
@ -85,6 +85,7 @@ class CImage final : public CObject, public CFBOProvider {
|
|||||||
Effects::CMaterial* m_material = nullptr;
|
Effects::CMaterial* m_material = nullptr;
|
||||||
Effects::CMaterial* m_colorBlendMaterial = nullptr;
|
Effects::CMaterial* m_colorBlendMaterial = nullptr;
|
||||||
std::vector<Effects::CPass*> m_passes = {};
|
std::vector<Effects::CPass*> m_passes = {};
|
||||||
|
std::vector<MaterialPass> m_virtualPassess = {};
|
||||||
|
|
||||||
glm::vec4 m_pos = {};
|
glm::vec4 m_pos = {};
|
||||||
|
|
||||||
|
@ -53,7 +53,6 @@ CPass::CPass (
|
|||||||
m_fboProvider (std::move(fboProvider)),
|
m_fboProvider (std::move(fboProvider)),
|
||||||
m_target (target) {
|
m_target (target) {
|
||||||
this->setupShaders ();
|
this->setupShaders ();
|
||||||
this->setupShaderVariables ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<const ITexture> CPass::resolveTexture (std::shared_ptr<const ITexture> expected, int index, std::shared_ptr<const ITexture> previous) {
|
std::shared_ptr<const ITexture> CPass::resolveTexture (std::shared_ptr<const ITexture> expected, int index, std::shared_ptr<const ITexture> previous) {
|
||||||
@ -349,7 +348,7 @@ const MaterialPass& CPass::getPass () const {
|
|||||||
return this->m_pass;
|
return this->m_pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::optional<std::reference_wrapper<std::string>> CPass::getTarget () const {
|
std::optional<std::reference_wrapper<std::string>> CPass::getTarget () const {
|
||||||
return this->m_target;
|
return this->m_target;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,6 +470,8 @@ void CPass::setupShaders () {
|
|||||||
glDeleteShader (vertexShaderID);
|
glDeleteShader (vertexShaderID);
|
||||||
glDeleteShader (fragmentShaderID);
|
glDeleteShader (fragmentShaderID);
|
||||||
|
|
||||||
|
// first setup the default values, these will be overwritten by future values
|
||||||
|
this->setupShaderVariables ();
|
||||||
// setup uniforms
|
// setup uniforms
|
||||||
this->setupUniforms ();
|
this->setupUniforms ();
|
||||||
// setup attributes too
|
// setup attributes too
|
||||||
@ -727,7 +728,7 @@ void CPass::addUniform (CShaderVariable* value) {
|
|||||||
this->addUniform (value, 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> ()) {
|
if (value->is<CShaderVariableFloat> ()) {
|
||||||
this->addUniform (value->getName (), setting->getFloat ());
|
this->addUniform (value->getName (), setting->getFloat ());
|
||||||
} else if (value->is<CShaderVariableInteger> ()) {
|
} else if (value->is<CShaderVariableInteger> ()) {
|
||||||
|
@ -45,7 +45,7 @@ class CPass final : public Helpers::CContextAware {
|
|||||||
[[nodiscard]] std::shared_ptr<const CFBOProvider> getFBOProvider () const;
|
[[nodiscard]] std::shared_ptr<const CFBOProvider> getFBOProvider () const;
|
||||||
[[nodiscard]] const CImage& getImage () const;
|
[[nodiscard]] const CImage& getImage () const;
|
||||||
[[nodiscard]] const MaterialPass& getPass () const;
|
[[nodiscard]] const MaterialPass& getPass () const;
|
||||||
[[nodiscard]] const std::optional<std::reference_wrapper<std::string>> getTarget () const;
|
[[nodiscard]] std::optional<std::reference_wrapper<std::string>> getTarget () const;
|
||||||
[[nodiscard]] Render::Shaders::CShader* getShader () const;
|
[[nodiscard]] Render::Shaders::CShader* getShader () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -114,7 +114,7 @@ class CPass final : public Helpers::CContextAware {
|
|||||||
void setupAttributes ();
|
void setupAttributes ();
|
||||||
void addAttribute (const std::string& name, GLint type, GLint elements, const GLuint* value);
|
void addAttribute (const std::string& name, GLint type, GLint elements, const GLuint* value);
|
||||||
void addUniform (CShaderVariable* 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, int value);
|
||||||
void addUniform (const std::string& name, double value);
|
void addUniform (const std::string& name, double value);
|
||||||
void addUniform (const std::string& name, float value);
|
void addUniform (const std::string& name, float value);
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
#include "WallpaperEngine/Assets/CContainer.h"
|
#include "WallpaperEngine/Assets/CContainer.h"
|
||||||
#include "WallpaperEngine/Assets/ITexture.h"
|
#include "WallpaperEngine/Assets/ITexture.h"
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h"
|
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h"
|
||||||
|
|
||||||
#include "CShaderUnit.h"
|
#include "CShaderUnit.h"
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.h"
|
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.h"
|
||||||
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.h"
|
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.h"
|
||||||
|
|
||||||
|
#include "WallpaperEngine/Data/Builders/VectorBuilder.h"
|
||||||
|
|
||||||
#define SHADER_HEADER(filename) "#version 330\n" \
|
#define SHADER_HEADER(filename) "#version 330\n" \
|
||||||
"// ======================================================\n" \
|
"// ======================================================\n" \
|
||||||
"// Processed shader " + \
|
"// Processed shader " + \
|
||||||
@ -47,6 +49,7 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core;
|
using namespace WallpaperEngine::Core;
|
||||||
using namespace WallpaperEngine::Assets;
|
using namespace WallpaperEngine::Assets;
|
||||||
|
using namespace WallpaperEngine::Data::Builders;
|
||||||
using namespace WallpaperEngine::Render::Shaders;
|
using namespace WallpaperEngine::Render::Shaders;
|
||||||
|
|
||||||
CShaderUnit::CShaderUnit (
|
CShaderUnit::CShaderUnit (
|
||||||
@ -322,18 +325,18 @@ void CShaderUnit::preprocessRequires () {
|
|||||||
|
|
||||||
void CShaderUnit::parseComboConfiguration (const std::string& content, int defaultValue) {
|
void CShaderUnit::parseComboConfiguration (const std::string& content, int defaultValue) {
|
||||||
// TODO: SUPPORT REQUIRES SO WE PROPERLY FOLLOW THE REQUIRED CHAIN
|
// TODO: SUPPORT REQUIRES SO WE PROPERLY FOLLOW THE REQUIRED CHAIN
|
||||||
json data = json::parse (content);
|
const auto data = JSON::parse (content);
|
||||||
const auto combo = jsonFindRequired (data, "combo", "cannot parse combo information");
|
const auto combo = data.require <std::string> ("combo", "cannot parse combo information");
|
||||||
// ignore type as it seems to be used only on the editor
|
// ignore type as it seems to be used only on the editor
|
||||||
// const auto type = data.find ("type");
|
// const auto type = data.find ("type");
|
||||||
const auto defvalue = data.find ("default");
|
const auto defvalue = data.find ("default");
|
||||||
|
|
||||||
// check the combos
|
// check the combos
|
||||||
const auto entry = this->m_combos.find (combo->get<std::string> ());
|
const auto entry = this->m_combos.find (combo);
|
||||||
const auto entryOverride = this->m_overrideCombos.find (combo->get<std::string> ());
|
const auto entryOverride = this->m_overrideCombos.find (combo);
|
||||||
|
|
||||||
// add the combo to the found list
|
// 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
|
// 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
|
// 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 no combo is defined just load the default settings
|
||||||
if (defvalue == data.end ()) {
|
if (defvalue == data.end ()) {
|
||||||
// TODO: PROPERLY SUPPORT EMPTY COMBOS
|
// 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 ()) {
|
} 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 ()) {
|
} 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 ()) {
|
} 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 {
|
} 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 (
|
void CShaderUnit::parseParameterConfiguration (
|
||||||
const std::string& type, const std::string& name, const std::string& content
|
const std::string& type, const std::string& name, const std::string& content
|
||||||
) {
|
) {
|
||||||
json data = json::parse (content);
|
const auto data = JSON::parse (content);
|
||||||
const auto material = data.find ("material");
|
const auto material = data.optional ("material");
|
||||||
const auto defvalue = data.find ("default");
|
const auto defvalue = data.optional ("default");
|
||||||
// auto range = data.find ("range");
|
// auto range = data.find ("range");
|
||||||
const auto combo = data.find ("combo");
|
const auto combo = data.find ("combo");
|
||||||
|
|
||||||
// this is not a real parameter
|
// this is not a real parameter
|
||||||
auto constant = this->m_constants.end ();
|
auto constant = this->m_constants.end ();
|
||||||
|
|
||||||
if (material != data.end ())
|
if (material.has_value ())
|
||||||
constant = this->m_constants.find (*material);
|
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")
|
if (type != "sampler2D")
|
||||||
sLog.exception ("Cannot parse parameter data for ", name, " in shader ", this->m_file);
|
sLog.exception ("Cannot parse parameter data for ", name, " in shader ", this->m_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variables::CShaderVariable* parameter = nullptr;
|
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") {
|
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") {
|
} 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") {
|
} 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") {
|
} else if (type == "float") {
|
||||||
if (defvalue->is_string ()) {
|
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 {
|
} else {
|
||||||
parameter = new Variables::CShaderVariableFloat (*defvalue);
|
parameter = new Variables::CShaderVariableFloat (defvalue->get<float> ());
|
||||||
}
|
}
|
||||||
} else if (type == "int") {
|
} else if (type == "int") {
|
||||||
if (defvalue->is_string ()) {
|
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 {
|
} else {
|
||||||
parameter = new Variables::CShaderVariableInteger (*defvalue);
|
parameter = new Variables::CShaderVariableInteger (defvalue->get <int> ());
|
||||||
}
|
}
|
||||||
} else if (type == "sampler2D" || type == "sampler2DComparison") {
|
} else if (type == "sampler2D" || type == "sampler2DComparison") {
|
||||||
// samplers can have special requirements, check what sampler we're working with and create definitions
|
// 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 (isRequired && !textureSlotUsed) {
|
||||||
if (defvalue == data.end ()) {
|
if (!defvalue.has_value ()) {
|
||||||
isRequired = false;
|
isRequired = false;
|
||||||
} else {
|
} else {
|
||||||
// is the combo registered already?
|
// is the combo registered already?
|
||||||
@ -473,7 +473,7 @@ void CShaderUnit::parseParameterConfiguration (
|
|||||||
isRequired = false;
|
isRequired = false;
|
||||||
// otherwise a default value must be used
|
// otherwise a default value must be used
|
||||||
} else if (defvalue->is_string ()) {
|
} 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()) {
|
} else if (defvalue->is_number()) {
|
||||||
comboValue = *defvalue;
|
comboValue = *defvalue;
|
||||||
} else {
|
} else {
|
||||||
@ -500,7 +500,7 @@ void CShaderUnit::parseParameterConfiguration (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (material != data.end () && parameter != nullptr) {
|
if (material.has_value () && parameter != nullptr) {
|
||||||
parameter->setIdentifierName (*material);
|
parameter->setIdentifierName (*material);
|
||||||
parameter->setName (name);
|
parameter->setName (name);
|
||||||
|
|
||||||
@ -541,7 +541,10 @@ const std::string& CShaderUnit::compile () {
|
|||||||
|
|
||||||
for (const auto& combo : this->m_overrideCombos) {
|
for (const auto& combo : this->m_overrideCombos) {
|
||||||
if (addedCombos.find (combo.first) == addedCombos.end ()) {
|
if (addedCombos.find (combo.first) == addedCombos.end ()) {
|
||||||
this->m_final += DEFINE_COMBO (combo.first, combo.second);
|
std::string name;
|
||||||
|
std::transform (combo.first.begin (), combo.first.end (), std::back_inserter (name), ::toupper);
|
||||||
|
|
||||||
|
this->m_final += DEFINE_COMBO (name, combo.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
addedCombos.emplace (combo.first, true);
|
addedCombos.emplace (combo.first, true);
|
||||||
@ -549,14 +552,20 @@ const std::string& CShaderUnit::compile () {
|
|||||||
// now add all the combos to the source
|
// now add all the combos to the source
|
||||||
for (const auto& combo : this->m_combos) {
|
for (const auto& combo : this->m_combos) {
|
||||||
if (addedCombos.find (combo.first) == addedCombos.end ()) {
|
if (addedCombos.find (combo.first) == addedCombos.end ()) {
|
||||||
this->m_final += DEFINE_COMBO (combo.first, combo.second);
|
std::string name;
|
||||||
|
std::transform (combo.first.begin (), combo.first.end (), std::back_inserter (name), ::toupper);
|
||||||
|
|
||||||
|
this->m_final += DEFINE_COMBO (name, combo.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
addedCombos.emplace (combo.first, true);
|
addedCombos.emplace (combo.first, true);
|
||||||
}
|
}
|
||||||
for (const auto& combo : this->m_discoveredCombos) {
|
for (const auto& combo : this->m_discoveredCombos) {
|
||||||
if (addedCombos.find (combo.first) == addedCombos.end ()) {
|
if (addedCombos.find (combo.first) == addedCombos.end ()) {
|
||||||
this->m_final += DEFINE_COMBO (combo.first, combo.second);
|
std::string name;
|
||||||
|
std::transform (combo.first.begin (), combo.first.end (), std::back_inserter (name), ::toupper);
|
||||||
|
|
||||||
|
this->m_final += DEFINE_COMBO (name, combo.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
addedCombos.emplace (combo.first, true);
|
addedCombos.emplace (combo.first, true);
|
||||||
@ -564,14 +573,20 @@ const std::string& CShaderUnit::compile () {
|
|||||||
if (this->m_link != nullptr) {
|
if (this->m_link != nullptr) {
|
||||||
for (const auto& combo : this->m_link->getCombos ()) {
|
for (const auto& combo : this->m_link->getCombos ()) {
|
||||||
if (addedCombos.find (combo.first) == addedCombos.end ()) {
|
if (addedCombos.find (combo.first) == addedCombos.end ()) {
|
||||||
this->m_final += DEFINE_COMBO (combo.first, combo.second);
|
std::string name;
|
||||||
|
std::transform (combo.first.begin (), combo.first.end (), std::back_inserter (name), ::toupper);
|
||||||
|
|
||||||
|
this->m_final += DEFINE_COMBO (name, combo.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
addedCombos.emplace (combo.first, true);
|
addedCombos.emplace (combo.first, true);
|
||||||
}
|
}
|
||||||
for (const auto& combo : this->m_link->getDiscoveredCombos ()) {
|
for (const auto& combo : this->m_link->getDiscoveredCombos ()) {
|
||||||
if (addedCombos.find (combo.first) == addedCombos.end ()) {
|
if (addedCombos.find (combo.first) == addedCombos.end ()) {
|
||||||
this->m_final += DEFINE_COMBO (combo.first, combo.second);
|
std::string name;
|
||||||
|
std::transform (combo.first.begin (), combo.first.end (), std::back_inserter (name), ::toupper);
|
||||||
|
|
||||||
|
this->m_final += DEFINE_COMBO (name, combo.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
addedCombos.emplace (combo.first, true);
|
addedCombos.emplace (combo.first, true);
|
||||||
|
@ -6,14 +6,14 @@
|
|||||||
|
|
||||||
#include "CGLSLContext.h"
|
#include "CGLSLContext.h"
|
||||||
#include "WallpaperEngine/Assets/CContainer.h"
|
#include "WallpaperEngine/Assets/CContainer.h"
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
#include "WallpaperEngine/Data/JSON.h"
|
||||||
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h"
|
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h"
|
||||||
#include "nlohmann/json.hpp"
|
#include "nlohmann/json.hpp"
|
||||||
|
|
||||||
#include "WallpaperEngine/Data/Model/Types.h"
|
#include "WallpaperEngine/Data/Model/Types.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Render::Shaders {
|
namespace WallpaperEngine::Render::Shaders {
|
||||||
using json = nlohmann::json;
|
using JSON = WallpaperEngine::Data::JSON::JSON;
|
||||||
using namespace WallpaperEngine::Assets;
|
using namespace WallpaperEngine::Assets;
|
||||||
using namespace WallpaperEngine::Data::Model;
|
using namespace WallpaperEngine::Data::Model;
|
||||||
|
|
||||||
|
@ -1,32 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/DynamicValues/CDynamicValue.h"
|
#include "WallpaperEngine/Data/Utils/TypeCaster.h"
|
||||||
|
#include "WallpaperEngine/Data/Model/DynamicValue.h"
|
||||||
|
#include <exception>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace WallpaperEngine::Render::Shaders::Variables {
|
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:
|
public:
|
||||||
virtual ~CShaderVariable () = default;
|
using DynamicValue::DynamicValue;
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] const std::string& getIdentifierName () const;
|
[[nodiscard]] const std::string& getIdentifierName () const;
|
||||||
[[nodiscard]] const std::string& getName () const;
|
[[nodiscard]] const std::string& getName () const;
|
||||||
@ -35,7 +20,7 @@ class CShaderVariable : public Core::DynamicValues::CDynamicValue {
|
|||||||
void setName (const std::string& name);
|
void setName (const std::string& name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_identifierName = "";
|
std::string m_identifierName;
|
||||||
std::string m_name = "";
|
std::string m_name;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Render::Shaders::Variables
|
} // namespace WallpaperEngine::Render::Shaders::Variables
|
||||||
|
@ -4,13 +4,7 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Render::Shaders::Variables;
|
using namespace WallpaperEngine::Render::Shaders::Variables;
|
||||||
|
|
||||||
CShaderVariableFloat::CShaderVariableFloat (float defaultValue) :
|
|
||||||
CShaderVariable () {
|
|
||||||
this->update (defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
CShaderVariableFloat::CShaderVariableFloat (float defaultValue, const std::string& name) :
|
CShaderVariableFloat::CShaderVariableFloat (float defaultValue, const std::string& name) :
|
||||||
CShaderVariable () {
|
CShaderVariable (defaultValue) {
|
||||||
this->setName (name);
|
this->setName (name);
|
||||||
this->update (defaultValue);
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
namespace WallpaperEngine::Render::Shaders::Variables {
|
namespace WallpaperEngine::Render::Shaders::Variables {
|
||||||
class CShaderVariableFloat final : public CShaderVariable {
|
class CShaderVariableFloat final : public CShaderVariable {
|
||||||
public:
|
public:
|
||||||
explicit CShaderVariableFloat (float defaultValue);
|
using CShaderVariable::CShaderVariable;
|
||||||
|
|
||||||
CShaderVariableFloat (float defaultValue, const std::string& name);
|
CShaderVariableFloat (float defaultValue, const std::string& name);
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Render::Shaders::Variables
|
} // namespace WallpaperEngine::Render::Shaders::Variables
|
||||||
|
@ -4,13 +4,7 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Render::Shaders::Variables;
|
using namespace WallpaperEngine::Render::Shaders::Variables;
|
||||||
|
|
||||||
CShaderVariableInteger::CShaderVariableInteger (int32_t defaultValue) :
|
CShaderVariableInteger::CShaderVariableInteger (int defaultValue, const std::string& name) :
|
||||||
CShaderVariable () {
|
CShaderVariable (defaultValue) {
|
||||||
this->update (defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
CShaderVariableInteger::CShaderVariableInteger (int32_t defaultValue, const std::string& name) :
|
|
||||||
CShaderVariable () {
|
|
||||||
this->setName (name);
|
this->setName (name);
|
||||||
this->update (defaultValue);
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
namespace WallpaperEngine::Render::Shaders::Variables {
|
namespace WallpaperEngine::Render::Shaders::Variables {
|
||||||
class CShaderVariableInteger final : public CShaderVariable {
|
class CShaderVariableInteger final : public CShaderVariable {
|
||||||
public:
|
public:
|
||||||
explicit CShaderVariableInteger (int32_t defaultValue);
|
using CShaderVariable::CShaderVariable;
|
||||||
CShaderVariableInteger (int32_t defaultValue, const std::string& name);
|
|
||||||
|
CShaderVariableInteger (int defaultValue, const std::string& name);
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Render::Shaders::Variables
|
} // namespace WallpaperEngine::Render::Shaders::Variables
|
||||||
|
@ -4,13 +4,7 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Render::Shaders::Variables;
|
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) :
|
CShaderVariableVector2::CShaderVariableVector2 (const glm::vec2& defaultValue, const std::string& name) :
|
||||||
CShaderVariable () {
|
CShaderVariable (defaultValue) {
|
||||||
this->setName (name);
|
this->setName (name);
|
||||||
this->update (defaultValue);
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
namespace WallpaperEngine::Render::Shaders::Variables {
|
namespace WallpaperEngine::Render::Shaders::Variables {
|
||||||
class CShaderVariableVector2 final : public CShaderVariable {
|
class CShaderVariableVector2 final : public CShaderVariable {
|
||||||
public:
|
public:
|
||||||
explicit CShaderVariableVector2 (const glm::vec2& defaultValue);
|
using CShaderVariable::CShaderVariable;
|
||||||
|
|
||||||
CShaderVariableVector2 (const glm::vec2& defaultValue, const std::string& name);
|
CShaderVariableVector2 (const glm::vec2& defaultValue, const std::string& name);
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Render::Shaders::Variables
|
} // namespace WallpaperEngine::Render::Shaders::Variables
|
||||||
|
@ -2,13 +2,7 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Render::Shaders::Variables;
|
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) :
|
CShaderVariableVector3::CShaderVariableVector3 (const glm::vec3& defaultValue, const std::string& name) :
|
||||||
CShaderVariable () {
|
CShaderVariable (defaultValue) {
|
||||||
this->setName (name);
|
this->setName (name);
|
||||||
this->update (defaultValue);
|
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,8 @@
|
|||||||
namespace WallpaperEngine::Render::Shaders::Variables {
|
namespace WallpaperEngine::Render::Shaders::Variables {
|
||||||
class CShaderVariableVector3 final : public CShaderVariable {
|
class CShaderVariableVector3 final : public CShaderVariable {
|
||||||
public:
|
public:
|
||||||
explicit CShaderVariableVector3 (const glm::vec3& defaultValue);
|
using CShaderVariable::CShaderVariable;
|
||||||
|
|
||||||
CShaderVariableVector3 (const glm::vec3& defaultValue, const std::string& name);
|
CShaderVariableVector3 (const glm::vec3& defaultValue, const std::string& name);
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Render::Shaders::Variables
|
} // namespace WallpaperEngine::Render::Shaders::Variables
|
||||||
|
@ -4,13 +4,7 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Render::Shaders::Variables;
|
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) :
|
CShaderVariableVector4::CShaderVariableVector4 (const glm::vec4& defaultValue, const std::string& name) :
|
||||||
CShaderVariable () {
|
CShaderVariable (defaultValue) {
|
||||||
this->setName (name);
|
this->setName (name);
|
||||||
this->update (defaultValue);
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
namespace WallpaperEngine::Render::Shaders::Variables {
|
namespace WallpaperEngine::Render::Shaders::Variables {
|
||||||
class CShaderVariableVector4 final : public CShaderVariable {
|
class CShaderVariableVector4 final : public CShaderVariable {
|
||||||
public:
|
public:
|
||||||
explicit CShaderVariableVector4 (const glm::vec4& defaultValue);
|
using CShaderVariable::CShaderVariable;
|
||||||
|
|
||||||
CShaderVariableVector4 (const glm::vec4& defaultValue, const std::string& name);
|
CShaderVariableVector4 (const glm::vec4& defaultValue, const std::string& name);
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Render::Shaders::Variables
|
} // namespace WallpaperEngine::Render::Shaders::Variables
|
||||||
|
@ -55,7 +55,6 @@ CScene::CScene (
|
|||||||
this->alias ("_alias_lightCookie", "_rt_shadowAtlas");
|
this->alias ("_alias_lightCookie", "_rt_shadowAtlas");
|
||||||
|
|
||||||
// set clear color
|
// set clear color
|
||||||
// TODO: MAKE USE OF THE REFERENCE POSSIBILITIES?!
|
|
||||||
const glm::vec3 clearColor = scene->colors.clear->value->getVec3 ();
|
const glm::vec3 clearColor = scene->colors.clear->value->getVec3 ();
|
||||||
|
|
||||||
glClearColor (clearColor.r, clearColor.g, clearColor.b, 1.0f);
|
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)
|
// (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 bloomOrigin = glm::vec3 { sceneWidth / 2, sceneHeight / 2, 0.0f };
|
||||||
const auto bloomSize = glm::vec2 { sceneWidth, sceneHeight };
|
const auto bloomSize = glm::vec2 { sceneWidth, sceneHeight };
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user