mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +08:00
Merge 2d6675db0b
into be0fc25e72
This commit is contained in:
commit
061b3bd2e8
195
CMakeLists.txt
195
CMakeLists.txt
@ -7,7 +7,7 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
set_property(GLOBAL PROPERTY OS_FOLDERS ON)
|
set_property(GLOBAL PROPERTY OS_FOLDERS ON)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
|
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
|
||||||
set(OpenGL_GL_PREFERENCE "LEGACY")
|
set(OpenGL_GL_PREFERENCE "LEGACY")
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
@ -104,6 +104,8 @@ find_package(CEF REQUIRED)
|
|||||||
# remove some switches that forbid us from using things that are commonplace in our codebase
|
# remove some switches that forbid us from using things that are commonplace in our codebase
|
||||||
list(REMOVE_ITEM CEF_CXX_COMPILER_FLAGS -fno-exceptions)
|
list(REMOVE_ITEM CEF_CXX_COMPILER_FLAGS -fno-exceptions)
|
||||||
list(REMOVE_ITEM CEF_CXX_COMPILER_FLAGS -fno-rtti)
|
list(REMOVE_ITEM CEF_CXX_COMPILER_FLAGS -fno-rtti)
|
||||||
|
list(REMOVE_ITEM CEF_CXX_COMPILER_FLAGS -std=c++17)
|
||||||
|
list(APPEND CEF_CXX_COMPILER_FLAGS -std=c++20)
|
||||||
# remove the vulkan library from the files to copy so it doesn't fail after removing it
|
# remove the vulkan library from the files to copy so it doesn't fail after removing it
|
||||||
list(REMOVE_ITEM CEF_BINARY_FILES libvulkan.so.1)
|
list(REMOVE_ITEM CEF_BINARY_FILES libvulkan.so.1)
|
||||||
|
|
||||||
@ -260,34 +262,26 @@ add_executable(
|
|||||||
src/WallpaperEngine/Logging/CLog.cpp
|
src/WallpaperEngine/Logging/CLog.cpp
|
||||||
src/WallpaperEngine/Logging/CLog.h
|
src/WallpaperEngine/Logging/CLog.h
|
||||||
|
|
||||||
src/WallpaperEngine/PrettyPrinter/CPrettyPrinter.cpp
|
|
||||||
src/WallpaperEngine/PrettyPrinter/CPrettyPrinter.h
|
|
||||||
|
|
||||||
src/WallpaperEngine/Application/CApplicationContext.cpp
|
src/WallpaperEngine/Application/CApplicationContext.cpp
|
||||||
src/WallpaperEngine/Application/CApplicationContext.h
|
src/WallpaperEngine/Application/CApplicationContext.h
|
||||||
src/WallpaperEngine/Application/CWallpaperApplication.cpp
|
src/WallpaperEngine/Application/CWallpaperApplication.cpp
|
||||||
src/WallpaperEngine/Application/CWallpaperApplication.h
|
src/WallpaperEngine/Application/CWallpaperApplication.h
|
||||||
|
|
||||||
src/WallpaperEngine/Assets/CPackageLoadException.cpp
|
|
||||||
src/WallpaperEngine/Assets/CPackageLoadException.h
|
|
||||||
src/WallpaperEngine/Assets/CAssetLoadException.cpp
|
|
||||||
src/WallpaperEngine/Assets/CAssetLoadException.h
|
|
||||||
src/WallpaperEngine/Assets/CContainer.h
|
|
||||||
src/WallpaperEngine/Assets/CContainer.cpp
|
|
||||||
src/WallpaperEngine/Assets/CVirtualContainer.h
|
|
||||||
src/WallpaperEngine/Assets/CVirtualContainer.cpp
|
|
||||||
src/WallpaperEngine/Assets/CCombinedContainer.h
|
|
||||||
src/WallpaperEngine/Assets/CCombinedContainer.cpp
|
|
||||||
src/WallpaperEngine/Assets/CDirectory.h
|
|
||||||
src/WallpaperEngine/Assets/CDirectory.cpp
|
|
||||||
src/WallpaperEngine/Assets/CPackage.h
|
|
||||||
src/WallpaperEngine/Assets/CPackage.cpp
|
|
||||||
src/WallpaperEngine/Assets/ITexture.h
|
src/WallpaperEngine/Assets/ITexture.h
|
||||||
src/WallpaperEngine/Assets/CTexture.h
|
src/WallpaperEngine/Assets/CTexture.h
|
||||||
src/WallpaperEngine/Assets/CTexture.cpp
|
src/WallpaperEngine/Assets/CTexture.cpp
|
||||||
|
src/WallpaperEngine/Assets/CAssetLoadException.cpp
|
||||||
|
src/WallpaperEngine/Assets/CAssetLoadException.h
|
||||||
|
|
||||||
src/WallpaperEngine/Core/Core.h
|
src/WallpaperEngine/FileSystem/Container.h
|
||||||
src/WallpaperEngine/Core/Core.cpp
|
src/WallpaperEngine/FileSystem/Container.cpp
|
||||||
|
src/WallpaperEngine/FileSystem/Adapters/Types.h
|
||||||
|
src/WallpaperEngine/FileSystem/Adapters/Directory.cpp
|
||||||
|
src/WallpaperEngine/FileSystem/Adapters/Directory.h
|
||||||
|
src/WallpaperEngine/FileSystem/Adapters/Package.cpp
|
||||||
|
src/WallpaperEngine/FileSystem/Adapters/Package.h
|
||||||
|
src/WallpaperEngine/FileSystem/Adapters/Virtual.cpp
|
||||||
|
src/WallpaperEngine/FileSystem/Adapters/Virtual.h
|
||||||
|
|
||||||
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
|
||||||
@ -360,6 +354,8 @@ add_executable(
|
|||||||
src/WallpaperEngine/Render/CRenderContext.cpp
|
src/WallpaperEngine/Render/CRenderContext.cpp
|
||||||
src/WallpaperEngine/Render/CTextureCache.h
|
src/WallpaperEngine/Render/CTextureCache.h
|
||||||
src/WallpaperEngine/Render/CTextureCache.cpp
|
src/WallpaperEngine/Render/CTextureCache.cpp
|
||||||
|
src/WallpaperEngine/Render/CFBOProvider.cpp
|
||||||
|
src/WallpaperEngine/Render/CFBOProvider.h
|
||||||
|
|
||||||
src/WallpaperEngine/Render/Helpers/CContextAware.cpp
|
src/WallpaperEngine/Render/Helpers/CContextAware.cpp
|
||||||
src/WallpaperEngine/Render/Helpers/CContextAware.h
|
src/WallpaperEngine/Render/Helpers/CContextAware.h
|
||||||
@ -383,15 +379,11 @@ add_executable(
|
|||||||
src/WallpaperEngine/Render/Objects/CImage.cpp
|
src/WallpaperEngine/Render/Objects/CImage.cpp
|
||||||
src/WallpaperEngine/Render/Objects/CSound.h
|
src/WallpaperEngine/Render/Objects/CSound.h
|
||||||
src/WallpaperEngine/Render/Objects/CSound.cpp
|
src/WallpaperEngine/Render/Objects/CSound.cpp
|
||||||
src/WallpaperEngine/Render/Objects/CEffect.h
|
|
||||||
src/WallpaperEngine/Render/Objects/CEffect.cpp
|
|
||||||
|
|
||||||
src/WallpaperEngine/Render/CFBO.h
|
src/WallpaperEngine/Render/CFBO.h
|
||||||
src/WallpaperEngine/Render/CFBO.cpp
|
src/WallpaperEngine/Render/CFBO.cpp
|
||||||
src/WallpaperEngine/Render/Objects/Effects/CPass.h
|
src/WallpaperEngine/Render/Objects/Effects/CPass.h
|
||||||
src/WallpaperEngine/Render/Objects/Effects/CPass.cpp
|
src/WallpaperEngine/Render/Objects/Effects/CPass.cpp
|
||||||
src/WallpaperEngine/Render/Objects/Effects/CMaterial.h
|
|
||||||
src/WallpaperEngine/Render/Objects/Effects/CMaterial.cpp
|
|
||||||
|
|
||||||
src/WallpaperEngine/WebBrowser/CEF/CRenderHandler.cpp
|
src/WallpaperEngine/WebBrowser/CEF/CRenderHandler.cpp
|
||||||
src/WallpaperEngine/WebBrowser/CEF/CRenderHandler.h
|
src/WallpaperEngine/WebBrowser/CEF/CRenderHandler.h
|
||||||
@ -408,111 +400,62 @@ 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/Data/Assets/Types.h
|
||||||
src/WallpaperEngine/Core/DynamicValues/CDynamicValue.h
|
src/WallpaperEngine/Data/Assets/Texture.h
|
||||||
|
src/WallpaperEngine/Data/Assets/Package.h
|
||||||
src/WallpaperEngine/Core/UserSettings/CUserSettingValue.cpp
|
src/WallpaperEngine/Data/Model/Types.h
|
||||||
src/WallpaperEngine/Core/UserSettings/CUserSettingValue.h
|
src/WallpaperEngine/Data/Model/Project.h
|
||||||
src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.cpp
|
src/WallpaperEngine/Data/Model/Wallpaper.h
|
||||||
src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h
|
src/WallpaperEngine/Data/Model/Object.h
|
||||||
src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.cpp
|
src/WallpaperEngine/Data/Model/Material.h
|
||||||
src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.h
|
src/WallpaperEngine/Data/Model/Effect.h
|
||||||
src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.cpp
|
src/WallpaperEngine/Data/Model/Model.h
|
||||||
src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.h
|
src/WallpaperEngine/Data/Model/UserSetting.h
|
||||||
|
src/WallpaperEngine/Data/Model/DynamicValue.h
|
||||||
src/WallpaperEngine/Core/CProject.cpp
|
src/WallpaperEngine/Data/Model/DynamicValue.cpp
|
||||||
src/WallpaperEngine/Core/CProject.h
|
src/WallpaperEngine/Data/Model/Property.h
|
||||||
src/WallpaperEngine/Core/CWallpaper.cpp
|
src/WallpaperEngine/Data/Utils/TypeCaster.cpp
|
||||||
src/WallpaperEngine/Core/CWallpaper.h
|
src/WallpaperEngine/Data/Utils/TypeCaster.h
|
||||||
src/WallpaperEngine/Core/Wallpapers/CScene.cpp
|
src/WallpaperEngine/Data/Utils/BinaryReader.cpp
|
||||||
src/WallpaperEngine/Core/Wallpapers/CScene.h
|
src/WallpaperEngine/Data/Utils/BinaryReader.h
|
||||||
src/WallpaperEngine/Core/Wallpapers/CVideo.cpp
|
src/WallpaperEngine/Data/Utils/MemoryStream.h
|
||||||
src/WallpaperEngine/Core/Wallpapers/CVideo.h
|
src/WallpaperEngine/Data/Utils/SFINAE.h
|
||||||
src/WallpaperEngine/Core/Wallpapers/CWeb.cpp
|
src/WallpaperEngine/Data/Parsers/EffectParser.cpp
|
||||||
src/WallpaperEngine/Core/Wallpapers/CWeb.h
|
src/WallpaperEngine/Data/Parsers/EffectParser.h
|
||||||
src/WallpaperEngine/Core/CObject.cpp
|
src/WallpaperEngine/Data/Parsers/ProjectParser.cpp
|
||||||
src/WallpaperEngine/Core/CObject.h
|
src/WallpaperEngine/Data/Parsers/ProjectParser.h
|
||||||
|
src/WallpaperEngine/Data/Parsers/WallpaperParser.cpp
|
||||||
src/WallpaperEngine/Core/Projects/CProperty.h
|
src/WallpaperEngine/Data/Parsers/WallpaperParser.h
|
||||||
src/WallpaperEngine/Core/Projects/CProperty.cpp
|
src/WallpaperEngine/Data/Parsers/UserSettingParser.cpp
|
||||||
src/WallpaperEngine/Core/Projects/CPropertyColor.h
|
src/WallpaperEngine/Data/Parsers/UserSettingParser.h
|
||||||
src/WallpaperEngine/Core/Projects/CPropertyColor.cpp
|
src/WallpaperEngine/Data/Parsers/ObjectParser.cpp
|
||||||
src/WallpaperEngine/Core/Projects/CPropertyBoolean.h
|
src/WallpaperEngine/Data/Parsers/ObjectParser.h
|
||||||
src/WallpaperEngine/Core/Projects/CPropertyBoolean.cpp
|
src/WallpaperEngine/Data/Parsers/MaterialParser.cpp
|
||||||
src/WallpaperEngine/Core/Projects/CPropertySlider.h
|
src/WallpaperEngine/Data/Parsers/MaterialParser.h
|
||||||
src/WallpaperEngine/Core/Projects/CPropertySlider.cpp
|
src/WallpaperEngine/Data/Parsers/ModelParser.cpp
|
||||||
src/WallpaperEngine/Core/Projects/CPropertyCombo.h
|
src/WallpaperEngine/Data/Parsers/ModelParser.h
|
||||||
src/WallpaperEngine/Core/Projects/CPropertyCombo.cpp
|
src/WallpaperEngine/Data/Parsers/ShaderConstantParser.cpp
|
||||||
src/WallpaperEngine/Core/Projects/CPropertyText.h
|
src/WallpaperEngine/Data/Parsers/ShaderConstantParser.h
|
||||||
src/WallpaperEngine/Core/Projects/CPropertyText.cpp
|
src/WallpaperEngine/Data/Parsers/PackageParser.cpp
|
||||||
|
src/WallpaperEngine/Data/Parsers/PackageParser.h
|
||||||
src/WallpaperEngine/Core/Scenes/CCamera.cpp
|
src/WallpaperEngine/Data/Parsers/PropertyParser.cpp
|
||||||
src/WallpaperEngine/Core/Scenes/CCamera.h
|
src/WallpaperEngine/Data/Parsers/PropertyParser.h
|
||||||
src/WallpaperEngine/Core/Scenes/CProjection.cpp
|
src/WallpaperEngine/Data/Parsers/TextureParser.cpp
|
||||||
src/WallpaperEngine/Core/Scenes/CProjection.h
|
src/WallpaperEngine/Data/Parsers/TextureParser.h
|
||||||
|
src/WallpaperEngine/Data/Builders/UserSettingBuilder.h
|
||||||
src/WallpaperEngine/Core/Objects/CImage.cpp
|
src/WallpaperEngine/Data/Builders/VectorBuilder.cpp
|
||||||
src/WallpaperEngine/Core/Objects/CImage.h
|
src/WallpaperEngine/Data/Builders/VectorBuilder.h
|
||||||
src/WallpaperEngine/Core/Objects/CSound.cpp
|
src/WallpaperEngine/Data/Dumpers/StringPrinter.cpp
|
||||||
src/WallpaperEngine/Core/Objects/CSound.h
|
src/WallpaperEngine/Data/Dumpers/StringPrinter.h
|
||||||
src/WallpaperEngine/Core/Objects/CEffect.cpp
|
src/WallpaperEngine/Data/JSON.cpp
|
||||||
src/WallpaperEngine/Core/Objects/CEffect.h
|
|
||||||
src/WallpaperEngine/Core/Objects/CParticle.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/CParticle.h
|
|
||||||
|
|
||||||
src/WallpaperEngine/Core/Objects/Effects/CFBO.h
|
|
||||||
src/WallpaperEngine/Core/Objects/Effects/CFBO.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Effects/CBind.h
|
|
||||||
src/WallpaperEngine/Core/Objects/Effects/CBind.cpp
|
|
||||||
|
|
||||||
src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h
|
|
||||||
src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h
|
|
||||||
src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.h
|
|
||||||
src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h
|
|
||||||
src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector4.h
|
|
||||||
src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector4.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h
|
|
||||||
src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantProperty.h
|
|
||||||
src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantProperty.cpp
|
|
||||||
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/CEmitter.h
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/CInitializer.h
|
|
||||||
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h
|
|
||||||
|
|
||||||
src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Images/CMaterial.h
|
|
||||||
|
|
||||||
src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp
|
|
||||||
src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h
|
|
||||||
|
|
||||||
${WAYLAND_SOURCES}
|
${WAYLAND_SOURCES}
|
||||||
${X11_SOURCES}
|
${X11_SOURCES}
|
||||||
${DEMOMODE_SOURCES})
|
${DEMOMODE_SOURCES}
|
||||||
|
src/WallpaperEngine/FileSystem/Adapters/Package.h
|
||||||
|
src/WallpaperEngine/FileSystem/Adapters/Package.cpp
|
||||||
|
src/WallpaperEngine/FileSystem/Adapters/Virtual.h
|
||||||
|
src/WallpaperEngine/FileSystem/Adapters/Virtual.cpp)
|
||||||
|
|
||||||
target_link_libraries (linux-wallpaperengine PUBLIC
|
target_link_libraries (linux-wallpaperengine PUBLIC
|
||||||
${OPENGL_LIBRARIES}
|
${OPENGL_LIBRARIES}
|
||||||
|
@ -52,8 +52,8 @@ endfunction()
|
|||||||
# SET_EXECUTABLE_TARGET_PROPERTIES() instead of calling this macro directly.
|
# SET_EXECUTABLE_TARGET_PROPERTIES() instead of calling this macro directly.
|
||||||
macro(REPLACED_SET_COMMON_TARGET_PROPERTIES target)
|
macro(REPLACED_SET_COMMON_TARGET_PROPERTIES target)
|
||||||
# Compile flags. (MODIFIED FOR C/C++ SEPARATION)
|
# Compile flags. (MODIFIED FOR C/C++ SEPARATION)
|
||||||
target_compile_options(${target} PRIVATE $<$<COMPILE_LANGUAGE:C>:${CEF_COMPILER_FLAGS}>)
|
target_compile_options(${target} PRIVATE $<$<COMPILE_LANGUAGE:C>:${CEF_COMPILER_FLAGS} ${CEF_C_COMPILER_FLAGS}>)
|
||||||
target_compile_options(${target} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${CEF_CXX_COMPILER_FLAGS}>)
|
target_compile_options(${target} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${CEF_COMPILER_FLAGS} ${CEF_CXX_COMPILER_FLAGS}>)
|
||||||
target_compile_options(${target} PRIVATE $<$<CONFIG:Debug>:${CEF_COMPILER_FLAGS_DEBUG} ${CEF_CXX_COMPILER_FLAGS_DEBUG}>)
|
target_compile_options(${target} PRIVATE $<$<CONFIG:Debug>:${CEF_COMPILER_FLAGS_DEBUG} ${CEF_CXX_COMPILER_FLAGS_DEBUG}>)
|
||||||
target_compile_options(${target} PRIVATE $<$<CONFIG:Release>:${CEF_COMPILER_FLAGS_RELEASE} ${CEF_CXX_COMPILER_FLAGS_RELEASE}>)
|
target_compile_options(${target} PRIVATE $<$<CONFIG:Release>:${CEF_COMPILER_FLAGS_RELEASE} ${CEF_CXX_COMPILER_FLAGS_RELEASE}>)
|
||||||
|
|
||||||
|
2
src/External/glslang-WallpaperEngine
vendored
2
src/External/glslang-WallpaperEngine
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 077d4f3c89bbfbb7951a9011d4551b075f092334
|
Subproject commit 9fba00b655d79ef2fe6f05b459571bd3b1f119ea
|
@ -118,14 +118,14 @@ CApplicationContext::CApplicationContext (int argc, char* argv []) :
|
|||||||
.help ("Clamp mode to use when rendering the background, this applies to the previous --window or --screen-root output, or the default background if no other background is specified")
|
.help ("Clamp mode to use when rendering the background, this applies to the previous --window or --screen-root output, or the default background if no other background is specified")
|
||||||
.choices("clamp", "border", "repeat")
|
.choices("clamp", "border", "repeat")
|
||||||
.action([this, &lastScreen](const std::string& value) -> void {
|
.action([this, &lastScreen](const std::string& value) -> void {
|
||||||
WallpaperEngine::Assets::ITexture::TextureFlags flags;
|
TextureFlags flags;
|
||||||
|
|
||||||
if (value == "clamp") {
|
if (value == "clamp") {
|
||||||
flags = WallpaperEngine::Assets::ITexture::TextureFlags::ClampUVs;
|
flags = TextureFlags_ClampUVs;
|
||||||
} else if (value == "border") {
|
} else if (value == "border") {
|
||||||
flags = WallpaperEngine::Assets::ITexture::TextureFlags::ClampUVsBorder;
|
flags = TextureFlags_ClampUVsBorder;
|
||||||
} else if (value == "repeat") {
|
} else if (value == "repeat") {
|
||||||
flags = WallpaperEngine::Assets::ITexture::TextureFlags::NoFlags;
|
flags = TextureFlags_NoFlags;
|
||||||
} else {
|
} else {
|
||||||
sLog.exception ("Invalid clamp mode: ", value);
|
sLog.exception ("Invalid clamp mode: ", value);
|
||||||
}
|
}
|
||||||
@ -192,7 +192,7 @@ CApplicationContext::CApplicationContext (int argc, char* argv []) :
|
|||||||
|
|
||||||
screenshotGroup.add_argument ("--screenshot-delay")
|
screenshotGroup.add_argument ("--screenshot-delay")
|
||||||
.help ("Frames to wait before taking the screenshot")
|
.help ("Frames to wait before taking the screenshot")
|
||||||
.default_value (5)
|
.default_value <uint32_t> (5)
|
||||||
.store_into (this->settings.screenshot.delay);
|
.store_into (this->settings.screenshot.delay);
|
||||||
|
|
||||||
auto& contentGroup = program.add_group ("Content options");
|
auto& contentGroup = program.add_group ("Content options");
|
||||||
@ -263,7 +263,7 @@ CApplicationContext::CApplicationContext (int argc, char* argv []) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->settings.audio.volume = std::max(0, std::min (this->settings.audio.volume, 128));
|
this->settings.audio.volume = std::max(0, std::min (this->settings.audio.volume, 128));
|
||||||
this->settings.screenshot.delay = std::max (0, std::min (this->settings.screenshot.delay, 5));
|
this->settings.screenshot.delay = std::max <uint32_t> (0, std::min <uint32_t> (this->settings.screenshot.delay, 5));
|
||||||
|
|
||||||
// use std::cout on this in case logging is disabled, this way it's easy to look at what is running
|
// use std::cout on this in case logging is disabled, this way it's easy to look at what is running
|
||||||
std::stringbuf buffer;
|
std::stringbuf buffer;
|
||||||
|
@ -12,7 +12,10 @@
|
|||||||
#include "WallpaperEngine/Assets/ITexture.h"
|
#include "WallpaperEngine/Assets/ITexture.h"
|
||||||
#include "WallpaperEngine/Render/CWallpaperState.h"
|
#include "WallpaperEngine/Render/CWallpaperState.h"
|
||||||
|
|
||||||
|
#include "WallpaperEngine/Data/Model/Project.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Application {
|
namespace WallpaperEngine::Application {
|
||||||
|
using namespace WallpaperEngine::Data::Assets;
|
||||||
/**
|
/**
|
||||||
* Application information as parsed off the command line arguments
|
* Application information as parsed off the command line arguments
|
||||||
*/
|
*/
|
||||||
@ -49,7 +52,7 @@ class CApplicationContext {
|
|||||||
/** The scaling mode for different screens */
|
/** The scaling mode for different screens */
|
||||||
std::map<std::string, WallpaperEngine::Render::CWallpaperState::TextureUVsScaling> screenScalings;
|
std::map<std::string, WallpaperEngine::Render::CWallpaperState::TextureUVsScaling> screenScalings;
|
||||||
/** The clamping mode for different screens */
|
/** The clamping mode for different screens */
|
||||||
std::map<std::string, WallpaperEngine::Assets::ITexture::TextureFlags> screenClamps;
|
std::map<std::string, TextureFlags> screenClamps;
|
||||||
} general;
|
} general;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,7 +69,7 @@ class CApplicationContext {
|
|||||||
struct {
|
struct {
|
||||||
/** The window size used in explicit window */
|
/** The window size used in explicit window */
|
||||||
glm::ivec4 geometry;
|
glm::ivec4 geometry;
|
||||||
WallpaperEngine::Assets::ITexture::TextureFlags clamp;
|
TextureFlags clamp;
|
||||||
WallpaperEngine::Render::CWallpaperState::TextureUVsScaling scalingMode;
|
WallpaperEngine::Render::CWallpaperState::TextureUVsScaling scalingMode;
|
||||||
} window;
|
} window;
|
||||||
} render;
|
} render;
|
||||||
@ -102,7 +105,7 @@ class CApplicationContext {
|
|||||||
/** If an screenshot should be taken */
|
/** If an screenshot should be taken */
|
||||||
bool take;
|
bool take;
|
||||||
/** The frames to wait until the screenshot is taken */
|
/** The frames to wait until the screenshot is taken */
|
||||||
int delay;
|
uint32_t delay;
|
||||||
/** The path to where the screenshot must be saved */
|
/** The path to where the screenshot must be saved */
|
||||||
std::filesystem::path path;
|
std::filesystem::path path;
|
||||||
} screenshot;
|
} screenshot;
|
||||||
@ -123,7 +126,7 @@ class CApplicationContext {
|
|||||||
.pauseOnFullscreen = true,
|
.pauseOnFullscreen = true,
|
||||||
.window = {
|
.window = {
|
||||||
.geometry = {},
|
.geometry = {},
|
||||||
.clamp = WallpaperEngine::Assets::ITexture::TextureFlags::ClampUVs,
|
.clamp = TextureFlags_ClampUVs,
|
||||||
.scalingMode = WallpaperEngine::Render::CWallpaperState::TextureUVsScaling::DefaultUVs,
|
.scalingMode = WallpaperEngine::Render::CWallpaperState::TextureUVsScaling::DefaultUVs,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -3,15 +3,18 @@
|
|||||||
#include "Steam/FileSystem/FileSystem.h"
|
#include "Steam/FileSystem/FileSystem.h"
|
||||||
#include "WallpaperEngine/Application/CApplicationState.h"
|
#include "WallpaperEngine/Application/CApplicationState.h"
|
||||||
#include "WallpaperEngine/Assets/CAssetLoadException.h"
|
#include "WallpaperEngine/Assets/CAssetLoadException.h"
|
||||||
#include "WallpaperEngine/Assets/CDirectory.h"
|
|
||||||
#include "WallpaperEngine/Assets/CVirtualContainer.h"
|
|
||||||
#include "WallpaperEngine/Audio/Drivers/Detectors/CPulseAudioPlayingDetector.h"
|
#include "WallpaperEngine/Audio/Drivers/Detectors/CPulseAudioPlayingDetector.h"
|
||||||
|
#include "WallpaperEngine/FileSystem/Container.h"
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
#include "WallpaperEngine/Logging/CLog.h"
|
||||||
#include "WallpaperEngine/Render/CRenderContext.h"
|
#include "WallpaperEngine/Render/CRenderContext.h"
|
||||||
#include "WallpaperEngine/PrettyPrinter/CPrettyPrinter.h"
|
|
||||||
#include "WallpaperEngine/Core/Wallpapers/CWeb.h"
|
|
||||||
#include "WallpaperEngine/Render/Drivers/CVideoFactories.h"
|
#include "WallpaperEngine/Render/Drivers/CVideoFactories.h"
|
||||||
|
|
||||||
|
#include "WallpaperEngine/Data/Parsers/ProjectParser.h"
|
||||||
|
#include "WallpaperEngine/Data/Dumpers/StringPrinter.h"
|
||||||
|
|
||||||
|
#include "WallpaperEngine/Data/Model/Wallpaper.h"
|
||||||
|
#include "WallpaperEngine/Data/Model/Property.h"
|
||||||
|
|
||||||
#if DEMOMODE
|
#if DEMOMODE
|
||||||
#include "recording.h"
|
#include "recording.h"
|
||||||
#endif /* DEMOMODE */
|
#endif /* DEMOMODE */
|
||||||
@ -26,7 +29,10 @@ float g_Time;
|
|||||||
float g_TimeLast;
|
float g_TimeLast;
|
||||||
float g_Daytime;
|
float g_Daytime;
|
||||||
|
|
||||||
namespace WallpaperEngine::Application {
|
using namespace WallpaperEngine::Application;
|
||||||
|
using namespace WallpaperEngine::Data::Model;
|
||||||
|
using namespace WallpaperEngine::FileSystem;
|
||||||
|
|
||||||
CWallpaperApplication::CWallpaperApplication (CApplicationContext& context) :
|
CWallpaperApplication::CWallpaperApplication (CApplicationContext& context) :
|
||||||
m_context (context) {
|
m_context (context) {
|
||||||
this->loadBackgrounds ();
|
this->loadBackgrounds ();
|
||||||
@ -34,21 +40,31 @@ CWallpaperApplication::CWallpaperApplication (CApplicationContext& context) :
|
|||||||
this->setupBrowser();
|
this->setupBrowser();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWallpaperApplication::setupContainer (const std::shared_ptr<CCombinedContainer>& container, const std::string& bg) const {
|
ContainerUniquePtr CWallpaperApplication::setupContainer (const std::string& bg) const {
|
||||||
const std::filesystem::path basepath = bg;
|
auto container = std::make_unique <Container> ();
|
||||||
|
|
||||||
container->add (std::make_shared<CDirectory> (basepath));
|
std::filesystem::path path (bg);
|
||||||
container->addPkg (basepath / "scene.pkg");
|
|
||||||
container->addPkg (basepath / "gifscene.pkg");
|
container->mount (path, "/");
|
||||||
|
try {
|
||||||
|
container->mount (path / "scene.pkg", "/");
|
||||||
|
} catch (std::runtime_error&) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
container->add (std::make_shared <CDirectory> (this->m_context.settings.general.assets));
|
container->mount (path / "gifscene.pkg", "/");
|
||||||
} catch (CAssetLoadException&) {
|
} catch (std::runtime_error&) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
container->mount (this->m_context.settings.general.assets, "/");
|
||||||
|
} catch (std::runtime_error&) {
|
||||||
sLog.exception ("Cannot find a valid assets folder, resolved to ", this->m_context.settings.general.assets);
|
sLog.exception ("Cannot find a valid assets folder, resolved to ", this->m_context.settings.general.assets);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: move this somewhere else?
|
auto& vfs = container->getVFS ();
|
||||||
auto virtualContainer = std::make_shared <CVirtualContainer> ();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Had to get a little creative with the effects to achieve the same bloom effect without any custom code
|
// Had to get a little creative with the effects to achieve the same bloom effect without any custom code
|
||||||
@ -59,21 +75,21 @@ void CWallpaperApplication::setupContainer (const std::shared_ptr<CCombinedConta
|
|||||||
// add the effect file for screen bloom
|
// add the effect file for screen bloom
|
||||||
|
|
||||||
// add some model for the image element even if it's going to waste rendering cycles
|
// add some model for the image element even if it's going to waste rendering cycles
|
||||||
virtualContainer->add (
|
vfs.add (
|
||||||
"effects/wpenginelinux/bloomeffect.json",
|
"effects/wpenginelinux/bloomeffect.json",
|
||||||
{
|
{
|
||||||
{"name", "camerabloom_wpengine_linux"},
|
{"name", "camerabloom_wpengine_linux"},
|
||||||
{"group", "wpengine_linux_camera"},
|
{"group", "wpengine_linux_camera"},
|
||||||
{"dependencies", json::array ()},
|
{"dependencies", JSON::array ()},
|
||||||
{"passes",
|
{"passes",
|
||||||
json::array (
|
JSON::array (
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{"material", "materials/util/downsample_quarter_bloom.json"},
|
{"material", "materials/util/downsample_quarter_bloom.json"},
|
||||||
{"target", "_rt_4FrameBuffer"},
|
{"target", "_rt_4FrameBuffer"},
|
||||||
{
|
{
|
||||||
"bind",
|
"bind",
|
||||||
json::array (
|
JSON::array (
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{"name", "_rt_FullFrameBuffer"},
|
{"name", "_rt_FullFrameBuffer"},
|
||||||
@ -88,7 +104,7 @@ void CWallpaperApplication::setupContainer (const std::shared_ptr<CCombinedConta
|
|||||||
{"target", "_rt_8FrameBuffer"},
|
{"target", "_rt_8FrameBuffer"},
|
||||||
{
|
{
|
||||||
"bind",
|
"bind",
|
||||||
json::array (
|
JSON::array (
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{"name", "_rt_4FrameBuffer"},
|
{"name", "_rt_4FrameBuffer"},
|
||||||
@ -103,7 +119,7 @@ void CWallpaperApplication::setupContainer (const std::shared_ptr<CCombinedConta
|
|||||||
{"target", "_rt_Bloom"},
|
{"target", "_rt_Bloom"},
|
||||||
{
|
{
|
||||||
"bind",
|
"bind",
|
||||||
json::array (
|
JSON::array (
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{"name", "_rt_8FrameBuffer"},
|
{"name", "_rt_8FrameBuffer"},
|
||||||
@ -118,7 +134,7 @@ void CWallpaperApplication::setupContainer (const std::shared_ptr<CCombinedConta
|
|||||||
{"target", "_rt_FullFrameBuffer"},
|
{"target", "_rt_FullFrameBuffer"},
|
||||||
{
|
{
|
||||||
"bind",
|
"bind",
|
||||||
json::array (
|
JSON::array (
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{"name", "_rt_imageLayerComposite_-1_a"},
|
{"name", "_rt_imageLayerComposite_-1_a"},
|
||||||
@ -138,17 +154,17 @@ void CWallpaperApplication::setupContainer (const std::shared_ptr<CCombinedConta
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
virtualContainer->add (
|
vfs.add (
|
||||||
"models/wpenginelinux.json",
|
"models/wpenginelinux.json",
|
||||||
{
|
{
|
||||||
{"material","materials/wpenginelinux.json"}
|
{"material","materials/wpenginelinux.json"}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
virtualContainer->add(
|
vfs.add(
|
||||||
"materials/wpenginelinux.json",
|
"materials/wpenginelinux.json",
|
||||||
{
|
{
|
||||||
{"passes", json::array (
|
{"passes", JSON::array (
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{"blending", "normal"},
|
{"blending", "normal"},
|
||||||
@ -156,13 +172,13 @@ void CWallpaperApplication::setupContainer (const std::shared_ptr<CCombinedConta
|
|||||||
{"depthtest", "disabled"},
|
{"depthtest", "disabled"},
|
||||||
{"depthwrite", "disabled"},
|
{"depthwrite", "disabled"},
|
||||||
{"shader", "genericimage2"},
|
{"shader", "genericimage2"},
|
||||||
{"textures", json::array ({"_rt_FullFrameBuffer"})}
|
{"textures", JSON::array ({"_rt_FullFrameBuffer"})}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)}}
|
)}}
|
||||||
);
|
);
|
||||||
|
|
||||||
virtualContainer->add(
|
vfs.add(
|
||||||
"shaders/commands/copy.frag",
|
"shaders/commands/copy.frag",
|
||||||
"uniform sampler2D g_Texture0;\n"
|
"uniform sampler2D g_Texture0;\n"
|
||||||
"in vec2 v_TexCoord;\n"
|
"in vec2 v_TexCoord;\n"
|
||||||
@ -170,7 +186,7 @@ void CWallpaperApplication::setupContainer (const std::shared_ptr<CCombinedConta
|
|||||||
"out_FragColor = texture (g_Texture0, v_TexCoord);\n"
|
"out_FragColor = texture (g_Texture0, v_TexCoord);\n"
|
||||||
"}"
|
"}"
|
||||||
);
|
);
|
||||||
virtualContainer->add(
|
vfs.add(
|
||||||
"shaders/commands/copy.vert",
|
"shaders/commands/copy.vert",
|
||||||
"in vec3 a_Position;\n"
|
"in vec3 a_Position;\n"
|
||||||
"in vec2 a_TexCoord;\n"
|
"in vec2 a_TexCoord;\n"
|
||||||
@ -181,7 +197,7 @@ void CWallpaperApplication::setupContainer (const std::shared_ptr<CCombinedConta
|
|||||||
"}"
|
"}"
|
||||||
);
|
);
|
||||||
|
|
||||||
container->add (virtualContainer);
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWallpaperApplication::loadBackgrounds () {
|
void CWallpaperApplication::loadBackgrounds () {
|
||||||
@ -201,42 +217,42 @@ void CWallpaperApplication::loadBackgrounds () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Core::CProject> CWallpaperApplication::loadBackground (const std::string& bg) {
|
ProjectUniquePtr CWallpaperApplication::loadBackground (const std::string& bg) {
|
||||||
const auto container = std::make_shared <CCombinedContainer> ();
|
auto container = this->setupContainer (bg);
|
||||||
|
auto json = WallpaperEngine::Data::JSON::JSON::parse (container->readString ("project.json"));
|
||||||
|
|
||||||
this->setupContainer (container, bg);
|
return WallpaperEngine::Data::Parsers::ProjectParser::parse (json, std::move(container));
|
||||||
|
|
||||||
return Core::CProject::fromFile ("project.json", container);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWallpaperApplication::setupPropertiesForProject (const std::shared_ptr<const Core::CProject>& project) {
|
void CWallpaperApplication::setupPropertiesForProject (const Project& project) {
|
||||||
// show properties if required
|
// show properties if required
|
||||||
for (const auto& [key, cur] : project->getProperties ()) {
|
for (const auto& [key, cur] : project.properties) {
|
||||||
// update the value of the property
|
// update the value of the property
|
||||||
auto override = this->m_context.settings.general.properties.find (key);
|
auto override = this->m_context.settings.general.properties.find (key);
|
||||||
|
|
||||||
if (override != this->m_context.settings.general.properties.end ()) {
|
if (override != this->m_context.settings.general.properties.end ()) {
|
||||||
sLog.out ("Applying override value for ", key);
|
sLog.out ("Applying override value for ", key);
|
||||||
|
|
||||||
cur->set (override->second);
|
cur->update (override->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->m_context.settings.general.onlyListProperties)
|
if (this->m_context.settings.general.onlyListProperties)
|
||||||
sLog.out (cur->dump ());
|
sLog.out (cur->toString ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWallpaperApplication::setupProperties () {
|
void CWallpaperApplication::setupProperties () {
|
||||||
for (const auto& [background, info] : this->m_backgrounds)
|
for (const auto& [background, info] : this->m_backgrounds)
|
||||||
this->setupPropertiesForProject (info);
|
this->setupPropertiesForProject (*info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWallpaperApplication::setupBrowser () {
|
void CWallpaperApplication::setupBrowser () {
|
||||||
bool anyWebProject = std::any_of (
|
bool anyWebProject = std::any_of (
|
||||||
this->m_backgrounds.begin (), this->m_backgrounds.end (),
|
this->m_backgrounds.begin (), this->m_backgrounds.end (),
|
||||||
[](const std::pair<const std::string, std::shared_ptr<const Core::CProject>>& pair) -> bool {
|
[](const std::pair<const std::string, ProjectUniquePtr>& pair) -> bool {
|
||||||
return pair.second->getWallpaper()->is<Core::Wallpapers::CWeb> ();
|
return pair.second->wallpaper->is<Web> ();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// do not perform any initialization if no web background is present
|
// do not perform any initialization if no web background is present
|
||||||
if (!anyWebProject) {
|
if (!anyWebProject) {
|
||||||
@ -337,9 +353,12 @@ void CWallpaperApplication::setupOutput () {
|
|||||||
|
|
||||||
void CWallpaperApplication::setupAudio () {
|
void CWallpaperApplication::setupAudio () {
|
||||||
// ensure audioprocessing is required by any background, and we have it enabled
|
// ensure audioprocessing is required by any background, and we have it enabled
|
||||||
bool audioProcessingRequired = std::any_of (this->m_backgrounds.begin (), this->m_backgrounds.end (), [](const auto& pair) -> bool {
|
bool audioProcessingRequired = std::any_of (
|
||||||
return pair.second->supportsAudioProcessing ();
|
this->m_backgrounds.begin (), this->m_backgrounds.end (),
|
||||||
});
|
[](const std::pair<const std::string, ProjectUniquePtr>& pair) -> bool {
|
||||||
|
return pair.second->supportsAudioProcessing;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
if (audioProcessingRequired && this->m_context.settings.audio.audioprocessing) {
|
if (audioProcessingRequired && this->m_context.settings.audio.audioprocessing) {
|
||||||
this->m_audioRecorder = std::make_unique <WallpaperEngine::Audio::Drivers::Recorders::CPulseAudioPlaybackRecorder> ();
|
this->m_audioRecorder = std::make_unique <WallpaperEngine::Audio::Drivers::Recorders::CPulseAudioPlaybackRecorder> ();
|
||||||
@ -369,7 +388,7 @@ void CWallpaperApplication::prepareOutputs () {
|
|||||||
m_renderContext->setWallpaper (
|
m_renderContext->setWallpaper (
|
||||||
background,
|
background,
|
||||||
WallpaperEngine::Render::CWallpaper::fromWallpaper (
|
WallpaperEngine::Render::CWallpaper::fromWallpaper (
|
||||||
info->getWallpaper (), *m_renderContext, *m_audioContext, m_browserContext.get (),
|
*info->wallpaper, *m_renderContext, *m_audioContext, m_browserContext.get (),
|
||||||
this->m_context.settings.general.screenScalings [background],
|
this->m_context.settings.general.screenScalings [background],
|
||||||
this->m_context.settings.general.screenClamps [background]
|
this->m_context.settings.general.screenClamps [background]
|
||||||
)
|
)
|
||||||
@ -386,6 +405,8 @@ void CWallpaperApplication::show () {
|
|||||||
static struct tm* timeinfo;
|
static struct tm* timeinfo;
|
||||||
|
|
||||||
if (this->m_context.settings.general.dumpStructure) {
|
if (this->m_context.settings.general.dumpStructure) {
|
||||||
|
// TODO: REWRITE TO USE THE NEW DUMPER
|
||||||
|
/*
|
||||||
auto prettyPrinter = PrettyPrinter::CPrettyPrinter ();
|
auto prettyPrinter = PrettyPrinter::CPrettyPrinter ();
|
||||||
|
|
||||||
for (const auto& [background, info] : this->m_renderContext->getWallpapers ()) {
|
for (const auto& [background, info] : this->m_renderContext->getWallpapers ()) {
|
||||||
@ -393,6 +414,7 @@ void CWallpaperApplication::show () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::cout << prettyPrinter.str () << std::endl;
|
std::cout << prettyPrinter.str () << std::endl;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEMOMODE
|
#if DEMOMODE
|
||||||
@ -406,7 +428,6 @@ void CWallpaperApplication::show () {
|
|||||||
std::vector<uint8_t> pixels(width * height * 3);
|
std::vector<uint8_t> pixels(width * height * 3);
|
||||||
bool initialized = false;
|
bool initialized = false;
|
||||||
int frame = 0;
|
int frame = 0;
|
||||||
int elapsed_frames = 0;
|
|
||||||
#endif /* DEMOMODE */
|
#endif /* DEMOMODE */
|
||||||
|
|
||||||
while (this->m_context.state.general.keepRunning) {
|
while (this->m_context.state.general.keepRunning) {
|
||||||
@ -432,12 +453,10 @@ void CWallpaperApplication::show () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if DEMOMODE
|
#if DEMOMODE
|
||||||
elapsed_frames ++;
|
|
||||||
|
|
||||||
// wait for a full render cycle before actually starting
|
// wait for a full render cycle before actually starting
|
||||||
// this gives some extra time for video and web decoders to set themselves up
|
// this gives some extra time for video and web decoders to set themselves up
|
||||||
// because of size changes
|
// because of size changes
|
||||||
if (elapsed_frames > this->m_context.settings.render.maximumFPS) {
|
if (m_videoDriver->getFrameCounter () > this->m_context.settings.render.maximumFPS) {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
width = this->m_renderContext->getWallpapers ().begin ()->second->getWidth ();
|
width = this->m_renderContext->getWallpapers ().begin ()->second->getWidth ();
|
||||||
height = this->m_renderContext->getWallpapers ().begin ()->second->getHeight ();
|
height = this->m_renderContext->getWallpapers ().begin ()->second->getHeight ();
|
||||||
@ -493,7 +512,7 @@ void CWallpaperApplication::signal (int signal) {
|
|||||||
this->m_context.state.general.keepRunning = false;
|
this->m_context.state.general.keepRunning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::map<std::string, std::shared_ptr<Core::CProject>>& CWallpaperApplication::getBackgrounds () const {
|
const std::map<std::string, ProjectUniquePtr>& CWallpaperApplication::getBackgrounds () const {
|
||||||
return this->m_backgrounds;
|
return this->m_backgrounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,4 +523,3 @@ CApplicationContext& CWallpaperApplication::getContext () const {
|
|||||||
const WallpaperEngine::Render::Drivers::Output::COutput& CWallpaperApplication::getOutput () const {
|
const WallpaperEngine::Render::Drivers::Output::COutput& CWallpaperApplication::getOutput () const {
|
||||||
return this->m_renderContext->getOutput ();
|
return this->m_renderContext->getOutput ();
|
||||||
}
|
}
|
||||||
} // namespace WallpaperEngine::Application
|
|
||||||
|
@ -2,10 +2,6 @@
|
|||||||
|
|
||||||
#include "WallpaperEngine/Application/CApplicationContext.h"
|
#include "WallpaperEngine/Application/CApplicationContext.h"
|
||||||
|
|
||||||
#include "WallpaperEngine/Assets/CCombinedContainer.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/CProject.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Render/CRenderContext.h"
|
#include "WallpaperEngine/Render/CRenderContext.h"
|
||||||
#include "WallpaperEngine/Render/CWallpaper.h"
|
#include "WallpaperEngine/Render/CWallpaper.h"
|
||||||
#include "WallpaperEngine/Render/Drivers/CGLFWOpenGLDriver.h"
|
#include "WallpaperEngine/Render/Drivers/CGLFWOpenGLDriver.h"
|
||||||
@ -17,7 +13,10 @@
|
|||||||
#include "WallpaperEngine/Input/CInputContext.h"
|
#include "WallpaperEngine/Input/CInputContext.h"
|
||||||
#include "WallpaperEngine/WebBrowser/CWebBrowserContext.h"
|
#include "WallpaperEngine/WebBrowser/CWebBrowserContext.h"
|
||||||
|
|
||||||
|
#include "WallpaperEngine/Data/Model/Types.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Application {
|
namespace WallpaperEngine::Application {
|
||||||
|
using namespace WallpaperEngine::Data::Model;
|
||||||
/**
|
/**
|
||||||
* Small wrapper class over the actual wallpaper's main application skeleton
|
* Small wrapper class over the actual wallpaper's main application skeleton
|
||||||
*
|
*
|
||||||
@ -40,7 +39,7 @@ class CWallpaperApplication {
|
|||||||
/**
|
/**
|
||||||
* @return Maps screens to loaded backgrounds
|
* @return Maps screens to loaded backgrounds
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const std::map<std::string, std::shared_ptr<Core::CProject>>& getBackgrounds () const;
|
[[nodiscard]] const std::map<std::string, ProjectUniquePtr>& getBackgrounds () const;
|
||||||
/**
|
/**
|
||||||
* @return The current application context
|
* @return The current application context
|
||||||
*/
|
*/
|
||||||
@ -61,7 +60,7 @@ class CWallpaperApplication {
|
|||||||
* @param container
|
* @param container
|
||||||
* @param bg
|
* @param bg
|
||||||
*/
|
*/
|
||||||
void setupContainer (const std::shared_ptr<CCombinedContainer>& container, const std::string& bg) const;
|
ContainerUniquePtr setupContainer (const std::string& bg) const;
|
||||||
/**
|
/**
|
||||||
* Loads projects based off the settings
|
* Loads projects based off the settings
|
||||||
*/
|
*/
|
||||||
@ -72,7 +71,7 @@ class CWallpaperApplication {
|
|||||||
* @param bg
|
* @param bg
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] std::shared_ptr<Core::CProject> loadBackground (const std::string& bg);
|
[[nodiscard]] ProjectUniquePtr loadBackground (const std::string& bg);
|
||||||
/**
|
/**
|
||||||
* Prepares all background's values and updates their properties if required
|
* Prepares all background's values and updates their properties if required
|
||||||
*/
|
*/
|
||||||
@ -82,7 +81,7 @@ class CWallpaperApplication {
|
|||||||
*
|
*
|
||||||
* @param project
|
* @param project
|
||||||
*/
|
*/
|
||||||
void setupPropertiesForProject (const std::shared_ptr<const Core::CProject>& project);
|
void setupPropertiesForProject (const Project& project);
|
||||||
/**
|
/**
|
||||||
* Prepares CEF browser to be used
|
* Prepares CEF browser to be used
|
||||||
*/
|
*/
|
||||||
@ -109,7 +108,7 @@ class CWallpaperApplication {
|
|||||||
/** The application context that contains the current app settings */
|
/** The application context that contains the current app settings */
|
||||||
CApplicationContext& m_context;
|
CApplicationContext& m_context;
|
||||||
/** Maps screens to backgrounds */
|
/** Maps screens to backgrounds */
|
||||||
std::map<std::string, std::shared_ptr <Core::CProject>> m_backgrounds {};
|
std::map<std::string, ProjectUniquePtr> m_backgrounds {};
|
||||||
|
|
||||||
std::unique_ptr <WallpaperEngine::Audio::Drivers::Detectors::CAudioPlayingDetector> m_audioDetector = nullptr;
|
std::unique_ptr <WallpaperEngine::Audio::Drivers::Detectors::CAudioPlayingDetector> m_audioDetector = nullptr;
|
||||||
std::unique_ptr <WallpaperEngine::Audio::CAudioContext> m_audioContext = nullptr;
|
std::unique_ptr <WallpaperEngine::Audio::CAudioContext> m_audioContext = nullptr;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <exception>
|
#include <exception>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
// TODO: REWRITE THIS ONE TO MAKE MORE SENSE, IT REALLY MEANS "FILE-RELATED EXCEPTION"
|
||||||
namespace WallpaperEngine::Assets {
|
namespace WallpaperEngine::Assets {
|
||||||
class CAssetLoadException final : public std::exception {
|
class CAssetLoadException final : public std::exception {
|
||||||
public:
|
public:
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
#include "CCombinedContainer.h"
|
|
||||||
#include "CAssetLoadException.h"
|
|
||||||
#include "CPackage.h"
|
|
||||||
#include "CPackageLoadException.h"
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Assets;
|
|
||||||
|
|
||||||
CCombinedContainer::CCombinedContainer () : CContainer () {}
|
|
||||||
|
|
||||||
void CCombinedContainer::add (const std::shared_ptr<CContainer>& container) {
|
|
||||||
this->m_containers.emplace_back (container);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCombinedContainer::addPkg (const std::filesystem::path& path) {
|
|
||||||
try {
|
|
||||||
// add the package to the list
|
|
||||||
this->add (std::make_shared<CPackage> (path));
|
|
||||||
sLog.out ("Detected ", path.filename (), " file at ", path, ". Adding to list of searchable paths");
|
|
||||||
} catch (CPackageLoadException&) {
|
|
||||||
// ignore this error, the package file was not found
|
|
||||||
sLog.out ("No ", path.filename (), " file found at ", path, ". Defaulting to normal folder storage");
|
|
||||||
} catch (std::runtime_error& ex) {
|
|
||||||
// the package was found but there was an error loading it (wrong header or something)
|
|
||||||
sLog.exception ("Failed to load ", path.filename(), " file: ", ex.what ());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::filesystem::path CCombinedContainer::resolveRealFile (const std::filesystem::path& filename) const {
|
|
||||||
for (const auto& cur : this->m_containers) {
|
|
||||||
try {
|
|
||||||
// try to read the file on the current container, if the file doesn't exists
|
|
||||||
// an exception will be thrown
|
|
||||||
return cur->resolveRealFile (filename);
|
|
||||||
} catch (CAssetLoadException&) {
|
|
||||||
// not found in this container, next try
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// no container was able to load the file, abort!
|
|
||||||
throw CAssetLoadException (filename, "Cannot resolve file in any of the containers");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<const uint8_t[]> CCombinedContainer::readFile (const std::filesystem::path& filename, uint32_t* length) const {
|
|
||||||
for (const auto& cur : this->m_containers) {
|
|
||||||
try {
|
|
||||||
// try to read the file on the current container, if the file doesn't exists
|
|
||||||
// an exception will be thrown
|
|
||||||
return cur->readFile (filename, length);
|
|
||||||
} catch (CAssetLoadException& e) {
|
|
||||||
// not found in this container, next try
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// no container was able to load the file, abort!
|
|
||||||
throw CAssetLoadException (filename, "Cannot find file in any of the containers");
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CContainer.h"
|
|
||||||
|
|
||||||
#include <filesystem>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Assets {
|
|
||||||
/**
|
|
||||||
* A meta-container that allows backgrounds to have files spread across different containers
|
|
||||||
*/
|
|
||||||
class CCombinedContainer final : public CContainer {
|
|
||||||
public:
|
|
||||||
CCombinedContainer ();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a container to the list
|
|
||||||
*
|
|
||||||
* @param container
|
|
||||||
*/
|
|
||||||
void add (const std::shared_ptr<CContainer>& container);
|
|
||||||
/**
|
|
||||||
* Adds the given package to the list
|
|
||||||
*
|
|
||||||
* @param path
|
|
||||||
*/
|
|
||||||
void addPkg (const std::filesystem::path& path);
|
|
||||||
|
|
||||||
[[nodiscard]] std::filesystem::path resolveRealFile (const std::filesystem::path& filename) const override;
|
|
||||||
[[nodiscard]] std::shared_ptr<const uint8_t[]> readFile (const std::filesystem::path& filename, uint32_t* length) const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** The list of containers to search files off from */
|
|
||||||
std::vector<std::shared_ptr<CContainer>> m_containers {};
|
|
||||||
};
|
|
||||||
}; // namespace WallpaperEngine::Assets
|
|
@ -1,78 +0,0 @@
|
|||||||
#include "CContainer.h"
|
|
||||||
#include "CAssetLoadException.h"
|
|
||||||
#include "CTexture.h"
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <filesystem>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Assets;
|
|
||||||
|
|
||||||
std::filesystem::path CContainer::resolveRealFile (const std::filesystem::path& filename) const {
|
|
||||||
throw CAssetLoadException (filename, "Cannot resolve physical file in this container");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr <const ITexture> CContainer::readTexture (const std::filesystem::path& filename) const {
|
|
||||||
// get the texture's filename (usually .tex)
|
|
||||||
std::filesystem::path texture = "materials" / std::filesystem::path (filename.string ().append (".tex"));
|
|
||||||
|
|
||||||
const auto textureContents = this->readFile (texture, nullptr);
|
|
||||||
const auto result = std::make_shared<CTexture> (textureContents);
|
|
||||||
|
|
||||||
#if !NDEBUG
|
|
||||||
glObjectLabel (GL_TEXTURE, result->getTextureID (0), -1, texture.c_str ());
|
|
||||||
#endif /* NDEBUG */
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CContainer::readShader (const std::filesystem::path& filename) const {
|
|
||||||
std::filesystem::path shader = filename;
|
|
||||||
auto it = shader.begin ();
|
|
||||||
|
|
||||||
// detect workshop shaders and check if there's a
|
|
||||||
if (*it++ == "workshop") {
|
|
||||||
const std::filesystem::path workshopId = *it++;
|
|
||||||
|
|
||||||
if (++it != shader.end ()) {
|
|
||||||
const std::filesystem::path& shaderfile = *it;
|
|
||||||
|
|
||||||
try {
|
|
||||||
shader = std::filesystem::path ("zcompat") / "scene" / "shaders" / workshopId / shaderfile;
|
|
||||||
// replace the old path with the new one
|
|
||||||
std::string contents = this->readFileAsString (shader);
|
|
||||||
|
|
||||||
sLog.out ("Replaced ", filename, " with compat ", shader);
|
|
||||||
|
|
||||||
return contents;
|
|
||||||
} catch (CAssetLoadException&) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this->readFileAsString ("shaders" / filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CContainer::readVertexShader (const std::filesystem::path& filename) const {
|
|
||||||
std::filesystem::path shader = filename;
|
|
||||||
shader.replace_extension (".vert");
|
|
||||||
return this->readShader (shader);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CContainer::readFragmentShader (const std::filesystem::path& filename) const {
|
|
||||||
std::filesystem::path shader = filename;
|
|
||||||
shader.replace_extension (".frag");
|
|
||||||
return this->readShader (shader);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CContainer::readIncludeShader (const std::filesystem::path& filename) const {
|
|
||||||
return this->readFileAsString ("shaders" / filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CContainer::readFileAsString (const std::filesystem::path& filename) const {
|
|
||||||
uint32_t length = 0;
|
|
||||||
|
|
||||||
return {
|
|
||||||
reinterpret_cast<const char*> (this->readFile (filename, &length).get ()), length
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,91 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Assets/ITexture.h"
|
|
||||||
|
|
||||||
#include <filesystem>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Assets {
|
|
||||||
/**
|
|
||||||
* File container, provides access to files for backgrounds
|
|
||||||
*/
|
|
||||||
class CContainer {
|
|
||||||
public:
|
|
||||||
virtual ~CContainer () = default;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resolves the full path to the specified file in the filesystem
|
|
||||||
*
|
|
||||||
* @param filename
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
[[nodiscard]] virtual std::filesystem::path resolveRealFile (const std::filesystem::path& filename) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the given file from the container and returns it's data
|
|
||||||
* Additionally sets a length parameter to return back the file's length
|
|
||||||
*
|
|
||||||
* The returned string must be deleted[] by the caller
|
|
||||||
*
|
|
||||||
* @param filename The file to read
|
|
||||||
* @param length The file's length after it's been read, null for not getting anything back
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
[[nodiscard]] virtual std::shared_ptr<const uint8_t[]> readFile (const std::filesystem::path& filename, uint32_t* length) const = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper for readFile, appends the texture extension at the end of the filename
|
|
||||||
*
|
|
||||||
* @param filename The texture name (without the .tex)
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
[[nodiscard]] std::shared_ptr <const ITexture> readTexture (const std::filesystem::path& filename) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper for readFile, checks for compat versions of the given shader file
|
|
||||||
*
|
|
||||||
* @param filename
|
|
||||||
*
|
|
||||||
* @return The shader code as an string to be used
|
|
||||||
*/
|
|
||||||
[[nodiscard]] std::string readShader (const std::filesystem::path& filename) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper for readFile, appends the .vert extension at the end and opens the given shader file
|
|
||||||
*
|
|
||||||
* @param filename
|
|
||||||
*
|
|
||||||
* @return The shader code as an string to be used
|
|
||||||
*/
|
|
||||||
[[nodiscard]] std::string readVertexShader (const std::filesystem::path& filename) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper for readFile, appends the .frag extension at the end and opens the given shader file
|
|
||||||
*
|
|
||||||
* @param filename
|
|
||||||
*
|
|
||||||
* @return The shader code as an string to be used
|
|
||||||
*/
|
|
||||||
[[nodiscard]] std::string readFragmentShader (const std::filesystem::path& filename) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper for readFile, appends the .h extension at the end and opens the given shader file
|
|
||||||
*
|
|
||||||
* @param filename
|
|
||||||
*
|
|
||||||
* @return The shader code as an string to be used
|
|
||||||
*/
|
|
||||||
[[nodiscard]] std::string readIncludeShader (const std::filesystem::path& filename) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads a file as string
|
|
||||||
*
|
|
||||||
* @param filename
|
|
||||||
*
|
|
||||||
* @return The file's contents as string
|
|
||||||
*/
|
|
||||||
[[nodiscard]] std::string readFileAsString (const std::filesystem::path& filename) const;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Assets
|
|
@ -1,85 +0,0 @@
|
|||||||
#include "CAssetLoadException.h"
|
|
||||||
#include "CDirectory.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Assets;
|
|
||||||
|
|
||||||
CDirectory::CDirectory (const std::filesystem::path& basepath) {
|
|
||||||
try {
|
|
||||||
// resolve the path to it's real location
|
|
||||||
std::filesystem::path finalpath = std::filesystem::canonical(basepath);
|
|
||||||
std::filesystem::file_status status = std::filesystem::status (finalpath);
|
|
||||||
|
|
||||||
if (!std::filesystem::exists (finalpath)) {
|
|
||||||
throw CAssetLoadException (basepath, "Cannot find directory");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!std::filesystem::is_directory(status)) {
|
|
||||||
throw CAssetLoadException (basepath, "Expected directory but found a file");
|
|
||||||
}
|
|
||||||
|
|
||||||
this->m_basepath = finalpath;
|
|
||||||
} catch (std::bad_alloc&) {
|
|
||||||
throw CAssetLoadException (basepath, "Cannot allocate memory");
|
|
||||||
} catch (std::filesystem::filesystem_error& e) {
|
|
||||||
throw CAssetLoadException (basepath, e.what ());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::filesystem::path CDirectory::resolveRealFile (const std::filesystem::path& filename) const {
|
|
||||||
try {
|
|
||||||
std::filesystem::path final = std::filesystem::canonical (this->m_basepath / filename);
|
|
||||||
|
|
||||||
// first validate the path, so the message doesn't reflect if the file exists or not unless it's under the actual directory
|
|
||||||
if (final.string ().find (this->m_basepath.string ()) != 0) {
|
|
||||||
throw CAssetLoadException (filename, "File is not a child of the given directory");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::filesystem::file_status status = std::filesystem::status (final);
|
|
||||||
|
|
||||||
if (!std::filesystem::exists (final)) {
|
|
||||||
throw CAssetLoadException (filename, "Cannot find file");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!std::filesystem::is_regular_file (status)) {
|
|
||||||
throw CAssetLoadException (filename, "Expected file but found a directory");
|
|
||||||
}
|
|
||||||
|
|
||||||
return final;
|
|
||||||
} catch (std::filesystem::filesystem_error& e) {
|
|
||||||
throw CAssetLoadException (filename, e.what ());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<const uint8_t[]> CDirectory::readFile (const std::filesystem::path& filename, uint32_t* length) const {
|
|
||||||
std::filesystem::path final = this->resolveRealFile (filename);
|
|
||||||
|
|
||||||
FILE* fp = fopen (final.c_str (), "rb");
|
|
||||||
|
|
||||||
if (fp == nullptr) {
|
|
||||||
throw CAssetLoadException (filename, "Cannot open file for reading");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// go to the end, get the position and return to the beginning
|
|
||||||
fseek (fp, 0, SEEK_END);
|
|
||||||
const long size = ftell (fp);
|
|
||||||
fseek (fp, 0, SEEK_SET);
|
|
||||||
|
|
||||||
// now read the whole file
|
|
||||||
std::shared_ptr<uint8_t[]> contents = std::shared_ptr<uint8_t[]>(new uint8_t [size]);
|
|
||||||
|
|
||||||
if (fread (contents.get(), size, 1, fp) != 1) {
|
|
||||||
throw CAssetLoadException (filename, "Unexpected error when reading the file");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (length != nullptr) {
|
|
||||||
*length = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose (fp);
|
|
||||||
return contents;
|
|
||||||
} catch (std::filesystem::filesystem_error& e) {
|
|
||||||
fclose (fp);
|
|
||||||
throw CAssetLoadException (filename, e.what ());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <filesystem>
|
|
||||||
#include <map>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "CContainer.h"
|
|
||||||
#include "CFileEntry.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Assets {
|
|
||||||
/**
|
|
||||||
* Directory container implementation, provides access to background files under a specific directory
|
|
||||||
*/
|
|
||||||
class CDirectory final : public CContainer {
|
|
||||||
public:
|
|
||||||
explicit CDirectory (const std::filesystem::path& basepath);
|
|
||||||
|
|
||||||
[[nodiscard]] std::filesystem::path resolveRealFile (const std::filesystem::path& filename) const override;
|
|
||||||
[[nodiscard]] std::shared_ptr<const uint8_t[]> readFile (const std::filesystem::path& filename, uint32_t* length) const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** The basepath for the directory */
|
|
||||||
std::filesystem::path m_basepath {};
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Assets
|
|
@ -1,22 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Assets {
|
|
||||||
/**
|
|
||||||
* File cache entry to prevent hit the disk when loading the same file multiple times
|
|
||||||
*/
|
|
||||||
class CFileEntry {
|
|
||||||
public:
|
|
||||||
CFileEntry (std::shared_ptr<const uint8_t[]> content, uint32_t length) :
|
|
||||||
content (std::move(content)),
|
|
||||||
length (length) {}
|
|
||||||
~CFileEntry() = default;
|
|
||||||
|
|
||||||
/** File contents */
|
|
||||||
std::shared_ptr<const uint8_t[]> content = nullptr;
|
|
||||||
/** File length */
|
|
||||||
uint32_t length = 0;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Assets
|
|
@ -1,135 +0,0 @@
|
|||||||
#include "CPackage.h"
|
|
||||||
#include "CAssetLoadException.h"
|
|
||||||
#include "CPackageLoadException.h"
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Assets;
|
|
||||||
|
|
||||||
class CPackageEntry {
|
|
||||||
public:
|
|
||||||
CPackageEntry (std::string filename, uint32_t offset, uint32_t length) :
|
|
||||||
filename (filename),
|
|
||||||
offset (offset),
|
|
||||||
length (length) {}
|
|
||||||
|
|
||||||
std::string filename;
|
|
||||||
uint32_t offset;
|
|
||||||
uint32_t length;
|
|
||||||
};
|
|
||||||
|
|
||||||
CPackage::CPackage (std::filesystem::path path) : m_path (std::move (path)) {
|
|
||||||
this->init ();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<const uint8_t[]> CPackage::readFile (const std::filesystem::path& filename, uint32_t* length) const {
|
|
||||||
const auto it = this->m_contents.find (filename);
|
|
||||||
|
|
||||||
if (it == this->m_contents.end ())
|
|
||||||
throw CAssetLoadException (filename, "Cannot find the file in the package");
|
|
||||||
|
|
||||||
// set file length if required
|
|
||||||
if (length != nullptr)
|
|
||||||
*length = it->second->length;
|
|
||||||
|
|
||||||
return it->second->content;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPackage::init () {
|
|
||||||
FILE* fp = fopen (this->m_path.c_str (), "rb+");
|
|
||||||
|
|
||||||
if (fp == nullptr)
|
|
||||||
throw CPackageLoadException (this->m_path, std::to_string (errno));
|
|
||||||
|
|
||||||
// first validate header
|
|
||||||
this->validateHeader (fp);
|
|
||||||
// header is okay, load everything into memory
|
|
||||||
this->loadFiles (fp);
|
|
||||||
|
|
||||||
fclose (fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
char* CPackage::readSizedString (FILE* fp) {
|
|
||||||
unsigned int length = 0;
|
|
||||||
|
|
||||||
if (fread (&length, sizeof (unsigned int), 1, fp) != 1)
|
|
||||||
sLog.exception ("Cannot read sized string length on file ", this->m_path);
|
|
||||||
|
|
||||||
// account for 0 termination of the string
|
|
||||||
length++;
|
|
||||||
|
|
||||||
char* pointer = new char [length];
|
|
||||||
memset (pointer, 0, length);
|
|
||||||
|
|
||||||
// read only the string bytes so the last one in the memory is 0
|
|
||||||
length--;
|
|
||||||
|
|
||||||
// read data from file
|
|
||||||
if (fread (pointer, sizeof (char), length, fp) != length)
|
|
||||||
sLog.exception ("Not enough bytes to read string of length ", length, " on file ", this->m_path);
|
|
||||||
|
|
||||||
return pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t CPackage::readInteger (FILE* fp) {
|
|
||||||
uint32_t output;
|
|
||||||
|
|
||||||
if (fread (&output, sizeof (uint32_t), 1, fp) != 1)
|
|
||||||
sLog.exception ("Not enough bytes to read an integer from file ", this->m_path);
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPackage::validateHeader (FILE* fp) {
|
|
||||||
const char* pointer = this->readSizedString (fp);
|
|
||||||
|
|
||||||
if (strncmp ("PKGV", pointer, 4) != 0) {
|
|
||||||
std::stringstream msg;
|
|
||||||
msg << "Expected PKGV indicator, found " << pointer;
|
|
||||||
delete [] pointer;
|
|
||||||
throw std::runtime_error (msg.str ());
|
|
||||||
}
|
|
||||||
|
|
||||||
// free memory
|
|
||||||
delete [] pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPackage::loadFiles (FILE* fp) {
|
|
||||||
const uint32_t count = this->readInteger (fp);
|
|
||||||
std::vector<CPackageEntry> list;
|
|
||||||
|
|
||||||
for (uint32_t index = 0; index < count; index++) {
|
|
||||||
// first read the filename
|
|
||||||
char* filename = this->readSizedString (fp);
|
|
||||||
uint32_t offset = this->readInteger (fp);
|
|
||||||
uint32_t length = this->readInteger (fp);
|
|
||||||
|
|
||||||
// add the file to the list
|
|
||||||
list.emplace_back (filename, offset, length);
|
|
||||||
// only free filename, the file's contents are stored in a map for a later use
|
|
||||||
delete [] filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get current baseOffset, this is where the files start
|
|
||||||
const long baseOffset = ftell (fp);
|
|
||||||
|
|
||||||
for (const auto& cur : list) {
|
|
||||||
const long offset = cur.offset + baseOffset;
|
|
||||||
|
|
||||||
// with all the data we can jump to the offset and read the content
|
|
||||||
if (fseek (fp, offset, SEEK_SET) != 0)
|
|
||||||
sLog.exception ("Cannot find file ", cur.filename, " from package ", this->m_path);
|
|
||||||
|
|
||||||
// allocate memory for the file's contents and read it from the file
|
|
||||||
std::shared_ptr<uint8_t[]> contents = std::shared_ptr<uint8_t[]>(new uint8_t [cur.length]);
|
|
||||||
|
|
||||||
if (fread (contents.get(), cur.length, 1, fp) != 1) {
|
|
||||||
sLog.exception ("Cannot read file ", cur.filename, " contents from package ", this->m_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
// add the file to the map
|
|
||||||
this->m_contents.insert_or_assign (cur.filename, std::make_unique<CFileEntry> (contents, cur.length));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <exception>
|
|
||||||
#include <filesystem>
|
|
||||||
#include <map>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "CContainer.h"
|
|
||||||
#include "CFileEntry.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Assets {
|
|
||||||
/**
|
|
||||||
* Package container implementation, provides access to background files that are stored
|
|
||||||
* inside the WallpaperEngine's pkg format
|
|
||||||
*/
|
|
||||||
class CPackage final : public CContainer {
|
|
||||||
public:
|
|
||||||
explicit CPackage (std::filesystem::path path);
|
|
||||||
|
|
||||||
[[nodiscard]] std::shared_ptr<const uint8_t[]> readFile (const std::filesystem::path& filename, uint32_t* length) const override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
/**
|
|
||||||
* Loads the current package file and loads all it's contents to memory
|
|
||||||
*/
|
|
||||||
void init ();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the header from the current position and ensures it's a compatible version
|
|
||||||
*
|
|
||||||
* @param fp The file where to read from
|
|
||||||
*/
|
|
||||||
void validateHeader (FILE* fp);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the files in the package into memory
|
|
||||||
*
|
|
||||||
* @param fp The file where to read from
|
|
||||||
*/
|
|
||||||
void loadFiles (FILE* fp);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads a size-prefixed string
|
|
||||||
*
|
|
||||||
* @param fp File to read from
|
|
||||||
*
|
|
||||||
* @return The read data, important to free it
|
|
||||||
*/
|
|
||||||
char* readSizedString (FILE* fp);
|
|
||||||
/**
|
|
||||||
* Reads a simple unsigned of 32 bits
|
|
||||||
*
|
|
||||||
* @param fp File to read from
|
|
||||||
*
|
|
||||||
* @return The read value
|
|
||||||
*/
|
|
||||||
uint32_t readInteger (FILE* fp);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** The path to the package file */
|
|
||||||
std::filesystem::path m_path {};
|
|
||||||
/** Contents of the package file */
|
|
||||||
std::map<std::string, std::unique_ptr<CFileEntry>> m_contents {};
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Assets
|
|
@ -1,10 +0,0 @@
|
|||||||
#include "CPackageLoadException.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Assets;
|
|
||||||
|
|
||||||
CPackageLoadException::CPackageLoadException (const std::string& filename, const std::string& extrainfo) :
|
|
||||||
m_message ("Cannot load package " + filename + ": " + extrainfo) {}
|
|
||||||
|
|
||||||
const char* CPackageLoadException::what () const noexcept {
|
|
||||||
return this->m_message.c_str ();
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <exception>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Assets {
|
|
||||||
class CPackageLoadException final : public std::exception {
|
|
||||||
public:
|
|
||||||
explicit CPackageLoadException (const std::string& filename, const std::string& extrainfo = "");
|
|
||||||
[[nodiscard]] const char* what () const noexcept override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string m_message {};
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Assets
|
|
@ -10,10 +10,8 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Assets;
|
using namespace WallpaperEngine::Assets;
|
||||||
|
|
||||||
CTexture::CTexture (const std::shared_ptr<const uint8_t[]>& buffer) : m_resolution () {
|
CTexture::CTexture (TextureUniquePtr header) : m_header (std::move(header)) {
|
||||||
// ensure the header is parsed
|
// ensure the header is parsed
|
||||||
const void* fileData = buffer.get ();
|
|
||||||
this->m_header = parseHeader (static_cast<const char*> (fileData));
|
|
||||||
this->setupResolution ();
|
this->setupResolution ();
|
||||||
GLint internalFormat = this->setupInternalFormat();
|
GLint internalFormat = this->setupInternalFormat();
|
||||||
|
|
||||||
@ -39,7 +37,7 @@ CTexture::CTexture (const std::shared_ptr<const uint8_t[]>& buffer) : m_resoluti
|
|||||||
uint32_t bufferSize = (*cur)->uncompressedSize;
|
uint32_t bufferSize = (*cur)->uncompressedSize;
|
||||||
GLenum textureFormat = GL_RGBA;
|
GLenum textureFormat = GL_RGBA;
|
||||||
|
|
||||||
if (this->m_header->freeImageFormat != FreeImageFormat::FIF_UNKNOWN) {
|
if (this->m_header->freeImageFormat != FIF_UNKNOWN) {
|
||||||
int fileChannels;
|
int fileChannels;
|
||||||
|
|
||||||
dataptr = handle = stbi_load_from_memory (
|
dataptr = handle = stbi_load_from_memory (
|
||||||
@ -50,11 +48,11 @@ CTexture::CTexture (const std::shared_ptr<const uint8_t[]>& buffer) : m_resoluti
|
|||||||
&fileChannels,
|
&fileChannels,
|
||||||
4);
|
4);
|
||||||
} else {
|
} else {
|
||||||
if (this->m_header->format == TextureFormat::R8) {
|
if (this->m_header->format == TextureFormat_R8) {
|
||||||
// red textures are 1-byte-per-pixel, so it's alignment has to be set manually
|
// red textures are 1-byte-per-pixel, so it's alignment has to be set manually
|
||||||
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
|
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
|
||||||
textureFormat = GL_RED;
|
textureFormat = GL_RED;
|
||||||
} else if (this->m_header->format == TextureFormat::RG88) {
|
} else if (this->m_header->format == TextureFormat_RG88) {
|
||||||
textureFormat = GL_RG;
|
textureFormat = GL_RG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,7 +76,7 @@ CTexture::CTexture (const std::shared_ptr<const uint8_t[]>& buffer) : m_resoluti
|
|||||||
}
|
}
|
||||||
|
|
||||||
// stbi_image buffer won't be used anymore, so free memory
|
// stbi_image buffer won't be used anymore, so free memory
|
||||||
if (this->m_header->freeImageFormat != FreeImageFormat::FIF_UNKNOWN) {
|
if (this->m_header->freeImageFormat != FIF_UNKNOWN) {
|
||||||
stbi_image_free (handle);
|
stbi_image_free (handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,10 +85,12 @@ CTexture::CTexture (const std::shared_ptr<const uint8_t[]>& buffer) : m_resoluti
|
|||||||
|
|
||||||
void CTexture::setupResolution () {
|
void CTexture::setupResolution () {
|
||||||
if (this->isAnimated ()) {
|
if (this->isAnimated ()) {
|
||||||
this->m_resolution = {this->m_header->textureWidth, this->m_header->textureHeight, this->m_header->gifWidth,
|
this->m_resolution = {
|
||||||
this->m_header->gifHeight};
|
this->m_header->textureWidth, this->m_header->textureHeight,
|
||||||
|
this->m_header->gifWidth, this->m_header->gifHeight
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
if (this->m_header->freeImageFormat != FreeImageFormat::FIF_UNKNOWN) {
|
if (this->m_header->freeImageFormat != FIF_UNKNOWN) {
|
||||||
// wpengine-texture format always has one mipmap
|
// wpengine-texture format always has one mipmap
|
||||||
// get first image size
|
// get first image size
|
||||||
auto element = this->m_header->images.find (0)->second.begin ();
|
auto element = this->m_header->images.find (0)->second.begin ();
|
||||||
@ -99,14 +99,16 @@ void CTexture::setupResolution () {
|
|||||||
this->m_resolution = {(*element)->width, (*element)->height, this->m_header->width, this->m_header->height};
|
this->m_resolution = {(*element)->width, (*element)->height, this->m_header->width, this->m_header->height};
|
||||||
} else {
|
} else {
|
||||||
// set the texture resolution
|
// set the texture resolution
|
||||||
this->m_resolution = {this->m_header->textureWidth, this->m_header->textureHeight, this->m_header->width,
|
this->m_resolution = {
|
||||||
this->m_header->height};
|
this->m_header->textureWidth, this->m_header->textureHeight,
|
||||||
|
this->m_header->width, this->m_header->height
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GLint CTexture::setupInternalFormat () {
|
GLint CTexture::setupInternalFormat () {
|
||||||
if (this->m_header->freeImageFormat != FreeImageFormat::FIF_UNKNOWN) {
|
if (this->m_header->freeImageFormat != FIF_UNKNOWN) {
|
||||||
return GL_RGBA8;
|
return GL_RGBA8;
|
||||||
// set some extra information too as it's used for image sizing
|
// set some extra information too as it's used for image sizing
|
||||||
// this ensures that a_TexCoord uses the full image instead of just part of it
|
// this ensures that a_TexCoord uses the full image instead of just part of it
|
||||||
@ -118,12 +120,12 @@ GLint CTexture::setupInternalFormat () {
|
|||||||
} else {
|
} else {
|
||||||
// detect the image format and hand it to openGL to be used
|
// detect the image format and hand it to openGL to be used
|
||||||
switch (this->m_header->format) {
|
switch (this->m_header->format) {
|
||||||
case TextureFormat::DXT5: return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
|
case TextureFormat_DXT5: return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
|
||||||
case TextureFormat::DXT3: return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
|
case TextureFormat_DXT3: return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
|
||||||
case TextureFormat::DXT1: return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
|
case TextureFormat_DXT1: return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
|
||||||
case TextureFormat::ARGB8888: return GL_RGBA8; break;
|
case TextureFormat_ARGB8888: return GL_RGBA8; break;
|
||||||
case TextureFormat::R8: return GL_R8; break;
|
case TextureFormat_R8: return GL_R8; break;
|
||||||
case TextureFormat::RG88: return GL_RG8; break;
|
case TextureFormat_RG88: return GL_RG8; break;
|
||||||
default: sLog.exception ("Cannot determine texture format");
|
default: sLog.exception ("Cannot determine texture format");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,7 +140,7 @@ void CTexture::setupOpenGLParameters (uint32_t textureID) {
|
|||||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, this->m_header->images [textureID].size () - 1);
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, this->m_header->images [textureID].size () - 1);
|
||||||
|
|
||||||
// setup texture wrapping and filtering
|
// setup texture wrapping and filtering
|
||||||
if (this->m_header->flags & TextureFlags::ClampUVs) {
|
if (this->m_header->flags & TextureFlags_ClampUVs) {
|
||||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
} else {
|
} else {
|
||||||
@ -146,7 +148,7 @@ void CTexture::setupOpenGLParameters (uint32_t textureID) {
|
|||||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->m_header->flags & TextureFlags::NoInterpolation) {
|
if (this->m_header->flags & TextureFlags_NoInterpolation) {
|
||||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
|
||||||
} else {
|
} else {
|
||||||
@ -167,296 +169,46 @@ GLuint CTexture::getTextureID (uint32_t imageIndex) const {
|
|||||||
|
|
||||||
uint32_t CTexture::getTextureWidth (uint32_t imageIndex) const {
|
uint32_t CTexture::getTextureWidth (uint32_t imageIndex) const {
|
||||||
if (imageIndex >= this->m_header->imageCount)
|
if (imageIndex >= this->m_header->imageCount)
|
||||||
return this->getHeader ()->textureWidth;
|
return this->getHeader ().textureWidth;
|
||||||
|
|
||||||
return (*this->m_header->images [imageIndex].begin ())->width;
|
return (*this->m_header->images [imageIndex].begin ())->width;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t CTexture::getTextureHeight (uint32_t imageIndex) const {
|
uint32_t CTexture::getTextureHeight (uint32_t imageIndex) const {
|
||||||
if (imageIndex >= this->m_header->imageCount)
|
if (imageIndex >= this->m_header->imageCount)
|
||||||
return this->getHeader ()->textureHeight;
|
return this->getHeader ().textureHeight;
|
||||||
|
|
||||||
return (*this->m_header->images [imageIndex].begin ())->height;
|
return (*this->m_header->images [imageIndex].begin ())->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t CTexture::getRealWidth () const {
|
uint32_t CTexture::getRealWidth () const {
|
||||||
return this->isAnimated () ? this->getHeader ()->gifWidth : this->getHeader ()->width;
|
return this->isAnimated () ? this->getHeader ().gifWidth : this->getHeader ().width;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t CTexture::getRealHeight () const {
|
uint32_t CTexture::getRealHeight () const {
|
||||||
return this->isAnimated () ? this->getHeader ()->gifHeight : this->getHeader ()->height;
|
return this->isAnimated () ? this->getHeader ().gifHeight : this->getHeader ().height;
|
||||||
}
|
}
|
||||||
|
|
||||||
ITexture::TextureFormat CTexture::getFormat () const {
|
TextureFormat CTexture::getFormat () const {
|
||||||
return this->getHeader ()->format;
|
return this->getHeader ().format;
|
||||||
}
|
}
|
||||||
|
|
||||||
ITexture::TextureFlags CTexture::getFlags () const {
|
uint32_t CTexture::getFlags () const {
|
||||||
return this->getHeader ()->flags;
|
return this->getHeader ().flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CTexture::TextureHeader* CTexture::getHeader () const {
|
const Texture& CTexture::getHeader () const {
|
||||||
return this->m_header.get ();
|
return *this->m_header;
|
||||||
}
|
}
|
||||||
|
|
||||||
const glm::vec4* CTexture::getResolution () const {
|
const glm::vec4* CTexture::getResolution () const {
|
||||||
return &this->m_resolution;
|
return &this->m_resolution;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::shared_ptr<ITexture::TextureFrame>>& CTexture::getFrames () const {
|
const std::vector<FrameSharedPtr>& CTexture::getFrames () const {
|
||||||
return this->getHeader ()->frames;
|
return this->getHeader ().frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CTexture::isAnimated () const {
|
bool CTexture::isAnimated () const {
|
||||||
return this->getHeader ()->isAnimated ();
|
return this->getHeader ().isAnimated ();
|
||||||
}
|
|
||||||
|
|
||||||
void CTexture::TextureMipmap::decompressData () {
|
|
||||||
if (this->compression != 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->uncompressedData = std::unique_ptr <char[]> (new char [this->uncompressedSize]);
|
|
||||||
|
|
||||||
const int result = LZ4_decompress_safe (
|
|
||||||
this->compressedData.get (), this->uncompressedData.get (), this->compressedSize,
|
|
||||||
this->uncompressedSize);
|
|
||||||
|
|
||||||
if (!result)
|
|
||||||
sLog.exception ("Cannot decompress texture data, LZ4_decompress_safe returned an error");
|
|
||||||
}
|
|
||||||
|
|
||||||
CTexture::TextureFrame::TextureFrame () :
|
|
||||||
frameNumber (0),
|
|
||||||
frametime (0.0f),
|
|
||||||
x (0),
|
|
||||||
y (0),
|
|
||||||
width1 (0),
|
|
||||||
width2 (0),
|
|
||||||
height1 (0),
|
|
||||||
height2 (0) {}
|
|
||||||
|
|
||||||
CTexture::TextureHeader::TextureHeader () :
|
|
||||||
flags (NoFlags),
|
|
||||||
width (0),
|
|
||||||
height (0),
|
|
||||||
textureWidth (0),
|
|
||||||
textureHeight (0),
|
|
||||||
gifWidth (0),
|
|
||||||
gifHeight (0),
|
|
||||||
format (TextureFormat::UNKNOWN),
|
|
||||||
imageCount (0),
|
|
||||||
isVideoMp4 (false) {}
|
|
||||||
|
|
||||||
std::unique_ptr<CTexture::TextureHeader> CTexture::parseHeader (const char* fileData) {
|
|
||||||
// check the magic value on the header first
|
|
||||||
if (strncmp (fileData, "TEXV0005", 9) != 0)
|
|
||||||
sLog.exception ("unexpected texture container type: ", std::string_view (fileData, 9));
|
|
||||||
// jump to the next value
|
|
||||||
fileData += 9;
|
|
||||||
// check the sub-magic value on the header
|
|
||||||
if (strncmp (fileData, "TEXI0001", 9) != 0)
|
|
||||||
sLog.exception ("unexpected texture sub-container type: ", std::string_view (fileData, 9));
|
|
||||||
// jump through the string again
|
|
||||||
fileData += 9;
|
|
||||||
|
|
||||||
auto header = std::make_unique <TextureHeader> ();
|
|
||||||
const auto* pointer = reinterpret_cast<const uint32_t*> (fileData);
|
|
||||||
|
|
||||||
header->format = static_cast<TextureFormat> (*pointer++);
|
|
||||||
header->flags = static_cast<TextureFlags> (*pointer++);
|
|
||||||
header->textureWidth = *pointer++;
|
|
||||||
header->textureHeight = *pointer++;
|
|
||||||
header->width = *pointer++;
|
|
||||||
header->height = *pointer++;
|
|
||||||
pointer++; // ignore some more bytes
|
|
||||||
|
|
||||||
// now we're going to parse some more data that is string
|
|
||||||
// so get the current position back as string
|
|
||||||
fileData = reinterpret_cast<const char*> (pointer);
|
|
||||||
// get the position of what comes after the texture data
|
|
||||||
pointer = reinterpret_cast<const uint32_t*> (fileData + 9);
|
|
||||||
|
|
||||||
header->imageCount = *pointer++;
|
|
||||||
|
|
||||||
if (strncmp (fileData, "TEXB0004", 9) == 0) {
|
|
||||||
header->containerVersion = ContainerVersion::TEXB0004;
|
|
||||||
header->freeImageFormat = static_cast<FreeImageFormat> (*pointer++);
|
|
||||||
header->isVideoMp4 = *pointer++ == 1;
|
|
||||||
|
|
||||||
if (header->freeImageFormat == FIF_UNKNOWN) {
|
|
||||||
header->freeImageFormat = FIF_MP4;
|
|
||||||
}
|
|
||||||
|
|
||||||
// default to TEXB0003 behavior if no mp4 video is there
|
|
||||||
if (header->freeImageFormat != FIF_MP4) {
|
|
||||||
header->containerVersion = ContainerVersion::TEXB0003;
|
|
||||||
}
|
|
||||||
} else if (strncmp (fileData, "TEXB0003", 9) == 0) {
|
|
||||||
header->containerVersion = ContainerVersion::TEXB0003;
|
|
||||||
header->freeImageFormat = static_cast<FreeImageFormat> (*pointer++);
|
|
||||||
} else if (strncmp (fileData, "TEXB0002", 9) == 0) {
|
|
||||||
header->containerVersion = ContainerVersion::TEXB0002;
|
|
||||||
} else if (strncmp (fileData, "TEXB0001", 9) == 0) {
|
|
||||||
header->containerVersion = ContainerVersion::TEXB0001;
|
|
||||||
} else {
|
|
||||||
sLog.exception ("unknown texture format type: ", std::string_view (fileData, 9));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (uint32_t image = 0; image < header->imageCount; image++) {
|
|
||||||
// read the number of mipmaps available for this image
|
|
||||||
uint32_t mipmapCount = *pointer++;
|
|
||||||
std::vector<std::shared_ptr<TextureMipmap>> mipmaps;
|
|
||||||
|
|
||||||
fileData = reinterpret_cast<const char*> (pointer);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < mipmapCount; i++)
|
|
||||||
mipmaps.emplace_back (parseMipmap (header.get (), &fileData));
|
|
||||||
|
|
||||||
// add the pixmaps back
|
|
||||||
header->images.emplace (image, mipmaps);
|
|
||||||
|
|
||||||
pointer = reinterpret_cast<const uint32_t*> (fileData);
|
|
||||||
}
|
|
||||||
|
|
||||||
// gifs have extra information after the mipmaps
|
|
||||||
if (header->isAnimated ()) {
|
|
||||||
if (strncmp (fileData, "TEXS0002", 9) == 0) {
|
|
||||||
header->animatedVersion = AnimatedVersion::TEXS0002;
|
|
||||||
} else if (strncmp (fileData, "TEXS0003", 9) == 0) {
|
|
||||||
header->animatedVersion = AnimatedVersion::TEXS0003;
|
|
||||||
} else {
|
|
||||||
sLog.exception ("found animation information of unknown type: ", std::string_view (fileData, 9));
|
|
||||||
}
|
|
||||||
|
|
||||||
// get an integer pointer back to read the frame count
|
|
||||||
pointer = reinterpret_cast<const uint32_t*> (fileData + 9);
|
|
||||||
uint32_t framecount = *pointer++;
|
|
||||||
|
|
||||||
if (header->animatedVersion == AnimatedVersion::TEXS0003) {
|
|
||||||
// ignore two extra integers as those are width and height of the git
|
|
||||||
header->gifWidth = *pointer++;
|
|
||||||
header->gifHeight = *pointer++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get back the pointer into filedata
|
|
||||||
fileData = reinterpret_cast<const char*> (pointer);
|
|
||||||
|
|
||||||
while (framecount > 0) {
|
|
||||||
// add the frame to the list
|
|
||||||
header->frames.push_back (parseAnimation (&fileData));
|
|
||||||
|
|
||||||
framecount--;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ensure gif width and height is right for TEXS0002
|
|
||||||
if (header->animatedVersion == AnimatedVersion::TEXS0002) {
|
|
||||||
auto first = *header->frames.begin ();
|
|
||||||
|
|
||||||
header->gifWidth = first->width1;
|
|
||||||
header->gifHeight = first->height1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return header;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<CTexture::TextureFrame> CTexture::parseAnimation (const char** originalFileData) {
|
|
||||||
const char* fileData = *originalFileData;
|
|
||||||
// get back the pointer into integer
|
|
||||||
const auto* pointer = reinterpret_cast<const uint32_t*> (fileData);
|
|
||||||
|
|
||||||
// start reading frame information
|
|
||||||
auto frame = std::make_shared <TextureFrame> ();
|
|
||||||
|
|
||||||
frame->frameNumber = *pointer++;
|
|
||||||
|
|
||||||
// reinterpret the pointer into float
|
|
||||||
const auto* fPointer = reinterpret_cast<const float*> (pointer);
|
|
||||||
|
|
||||||
frame->frametime = *fPointer++;
|
|
||||||
frame->x = *fPointer++;
|
|
||||||
frame->y = *fPointer++;
|
|
||||||
frame->width1 = *fPointer++;
|
|
||||||
frame->width2 = *fPointer++;
|
|
||||||
frame->height2 = *fPointer++;
|
|
||||||
frame->height1 = *fPointer++;
|
|
||||||
|
|
||||||
// get back the pointer into fileData so it can be reused later
|
|
||||||
*originalFileData = reinterpret_cast<const char*> (fPointer);
|
|
||||||
|
|
||||||
return frame;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<CTexture::TextureMipmap> CTexture::parseMipmap (const TextureHeader* header, const char** originalFileData) {
|
|
||||||
auto mipmap = std::make_shared <TextureMipmap> ();
|
|
||||||
// get the current position
|
|
||||||
const char* fileData = *originalFileData;
|
|
||||||
|
|
||||||
// get an integer pointer
|
|
||||||
const auto* pointer = reinterpret_cast<const uint32_t*> (fileData);
|
|
||||||
|
|
||||||
// TEXB004 have some extra data (and even json) that we have to take into account
|
|
||||||
if (header->containerVersion == ContainerVersion::TEXB0004) {
|
|
||||||
// ignore various params, RePKG doesn't really use them
|
|
||||||
// and could be related to the editor really, so just ignore them
|
|
||||||
pointer++;
|
|
||||||
pointer++;
|
|
||||||
|
|
||||||
fileData = reinterpret_cast<const char*> (pointer);
|
|
||||||
while (*fileData != 0) {
|
|
||||||
mipmap->json += *fileData++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// skip the null terminator
|
|
||||||
fileData ++;
|
|
||||||
|
|
||||||
pointer = reinterpret_cast<const uint32_t*> (fileData);
|
|
||||||
}
|
|
||||||
|
|
||||||
mipmap->width = *pointer++;
|
|
||||||
mipmap->height = *pointer++;
|
|
||||||
|
|
||||||
if (header->containerVersion == ContainerVersion::TEXB0002 ||
|
|
||||||
header->containerVersion == ContainerVersion::TEXB0003 ||
|
|
||||||
header->containerVersion == ContainerVersion::TEXB0004) {
|
|
||||||
mipmap->compression = *pointer++;
|
|
||||||
mipmap->uncompressedSize = *pointer++;
|
|
||||||
}
|
|
||||||
|
|
||||||
mipmap->compressedSize = *pointer++;
|
|
||||||
|
|
||||||
// get back a normal char pointer
|
|
||||||
fileData = reinterpret_cast<const char*> (pointer);
|
|
||||||
|
|
||||||
if (mipmap->compression == 0) {
|
|
||||||
// this might be better named as mipmap_bytes_size instead of compressedSize
|
|
||||||
// as in uncompressed files this variable actually holds the file length
|
|
||||||
mipmap->uncompressedSize = mipmap->compressedSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
mipmap->uncompressedData = std::unique_ptr<char[]>(new char [mipmap->uncompressedSize]);
|
|
||||||
|
|
||||||
if (mipmap->compression == 1) {
|
|
||||||
mipmap->compressedData = std::unique_ptr<char[]>(new char [mipmap->compressedSize]);
|
|
||||||
|
|
||||||
memcpy (mipmap->compressedData.get (), fileData, mipmap->compressedSize);
|
|
||||||
|
|
||||||
mipmap->decompressData ();
|
|
||||||
// advance to the end of the mipmap
|
|
||||||
fileData += mipmap->compressedSize;
|
|
||||||
} else {
|
|
||||||
memcpy (mipmap->uncompressedData.get (), fileData, mipmap->uncompressedSize);
|
|
||||||
// advance to the end of the mipmap
|
|
||||||
fileData += mipmap->uncompressedSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ensure the pointer is updated with the latest position when reading the data
|
|
||||||
*originalFileData = fileData;
|
|
||||||
|
|
||||||
return mipmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CTexture::TextureHeader::isAnimated () const {
|
|
||||||
return this->flags & TextureFlags::IsGif;
|
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ITexture.h"
|
#include "ITexture.h"
|
||||||
|
#include "WallpaperEngine/Data/Assets/Texture.h"
|
||||||
|
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <glm/vec4.hpp>
|
#include <glm/vec4.hpp>
|
||||||
@ -11,144 +12,14 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace WallpaperEngine::Assets {
|
namespace WallpaperEngine::Assets {
|
||||||
|
using namespace WallpaperEngine::Data::Assets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A normal texture file in WallpaperEngine's format
|
* A normal texture file in WallpaperEngine's format
|
||||||
*/
|
*/
|
||||||
class CTexture final : public ITexture {
|
class CTexture final : public ITexture {
|
||||||
/**
|
|
||||||
* Different texture container versions supported
|
|
||||||
*/
|
|
||||||
enum ContainerVersion : int {
|
|
||||||
UNKNOWN = -1,
|
|
||||||
TEXB0004 = 4,
|
|
||||||
TEXB0003 = 3,
|
|
||||||
TEXB0002 = 2,
|
|
||||||
TEXB0001 = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Different texture animation versions supported
|
|
||||||
*/
|
|
||||||
enum AnimatedVersion : int {
|
|
||||||
TEXSUNKN = -1,
|
|
||||||
TEXS0002 = 0,
|
|
||||||
TEXS0003 = 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum FreeImageFormat : int {
|
|
||||||
FIF_UNKNOWN = -1,
|
|
||||||
FIF_BMP = 0,
|
|
||||||
FIF_ICO = 1,
|
|
||||||
FIF_JPEG = 2,
|
|
||||||
FIF_JNG = 3,
|
|
||||||
FIF_KOALA = 4,
|
|
||||||
FIF_LBM = 5,
|
|
||||||
FIF_IFF = FIF_LBM,
|
|
||||||
FIF_MNG = 6,
|
|
||||||
FIF_PBM = 7,
|
|
||||||
FIF_PBMRAW = 8,
|
|
||||||
FIF_PCD = 9,
|
|
||||||
FIF_PCX = 10,
|
|
||||||
FIF_PGM = 11,
|
|
||||||
FIF_PGMRAW = 12,
|
|
||||||
FIF_PNG = 13,
|
|
||||||
FIF_PPM = 14,
|
|
||||||
FIF_PPMRAW = 15,
|
|
||||||
FIF_RAS = 16,
|
|
||||||
FIF_TARGA = 17,
|
|
||||||
FIF_TIFF = 18,
|
|
||||||
FIF_WBMP = 19,
|
|
||||||
FIF_PSD = 20,
|
|
||||||
FIF_CUT = 21,
|
|
||||||
FIF_XBM = 22,
|
|
||||||
FIF_XPM = 23,
|
|
||||||
FIF_DDS = 24,
|
|
||||||
FIF_GIF = 25,
|
|
||||||
FIF_HDR = 26,
|
|
||||||
FIF_FAXG3 = 27,
|
|
||||||
FIF_SGI = 28,
|
|
||||||
FIF_EXR = 29,
|
|
||||||
FIF_J2K = 30,
|
|
||||||
FIF_JP2 = 31,
|
|
||||||
FIF_PFM = 32,
|
|
||||||
FIF_PICT = 33,
|
|
||||||
FIF_RAW = 34,
|
|
||||||
FIF_WEBP = 35,
|
|
||||||
FIF_MP4 = FIF_WEBP,
|
|
||||||
FIF_JXR = 36
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Texture mipmap data
|
|
||||||
*/
|
|
||||||
class TextureMipmap {
|
|
||||||
public:
|
|
||||||
/** Width of the mipmap */
|
|
||||||
uint32_t width = 0;
|
|
||||||
/** Height of the mipmap */
|
|
||||||
uint32_t height = 0;
|
|
||||||
/** If the mipmap data is compressed */
|
|
||||||
uint32_t compression = 0;
|
|
||||||
/** Uncompressed size of the mipmap */
|
|
||||||
uint32_t uncompressedSize = 0;
|
|
||||||
/** Compress size of the mipmap */
|
|
||||||
uint32_t compressedSize = 0;
|
|
||||||
/** Pointer to the compressed data */
|
|
||||||
std::unique_ptr<char[]> compressedData = nullptr;
|
|
||||||
/** Pointer to the uncompressed data */
|
|
||||||
std::unique_ptr<char[]> uncompressedData = nullptr;
|
|
||||||
/** JSON data */
|
|
||||||
std::string json {};
|
|
||||||
/**
|
|
||||||
* Performs actual decompression of the compressed data
|
|
||||||
*/
|
|
||||||
void decompressData ();
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Texture header data
|
|
||||||
*/
|
|
||||||
class TextureHeader {
|
|
||||||
public:
|
|
||||||
TextureHeader ();
|
|
||||||
~TextureHeader () = default;
|
|
||||||
|
|
||||||
[[nodiscard]] bool isAnimated () const;
|
|
||||||
|
|
||||||
/** The version of the texture container */
|
|
||||||
ContainerVersion containerVersion = ContainerVersion::UNKNOWN;
|
|
||||||
/** The version of the animated data */
|
|
||||||
AnimatedVersion animatedVersion = AnimatedVersion::TEXSUNKN;
|
|
||||||
/** Flags with extra texture information */
|
|
||||||
TextureFlags flags = TextureFlags::NoFlags;
|
|
||||||
/** Real width of the texture */
|
|
||||||
uint32_t width = 0;
|
|
||||||
/** Real height of the texture */
|
|
||||||
uint32_t height = 0;
|
|
||||||
/** Texture width in memory (power of 2) */
|
|
||||||
uint32_t textureWidth = 0;
|
|
||||||
/** Texture height in memory (power of 2) */
|
|
||||||
uint32_t textureHeight = 0;
|
|
||||||
/** Gif width */
|
|
||||||
uint32_t gifWidth = 0;
|
|
||||||
/** Gif height */
|
|
||||||
uint32_t gifHeight = 0;
|
|
||||||
/** Texture data format */
|
|
||||||
TextureFormat format = TextureFormat::UNKNOWN;
|
|
||||||
/** Free Image format */
|
|
||||||
FreeImageFormat freeImageFormat = FreeImageFormat::FIF_UNKNOWN;
|
|
||||||
/** Indicates if we have an MP4 video */
|
|
||||||
bool isVideoMp4 = false;
|
|
||||||
/** The amount of images in the texture file */
|
|
||||||
uint32_t imageCount = 0;
|
|
||||||
/** List of mipmaps */
|
|
||||||
std::map<uint32_t, std::vector<std::shared_ptr<TextureMipmap>>> images {};
|
|
||||||
/** List of animation frames */
|
|
||||||
std::vector<std::shared_ptr<TextureFrame>> frames {};
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CTexture (const std::shared_ptr<const uint8_t[]>& fileData);
|
explicit CTexture (TextureUniquePtr header);
|
||||||
|
|
||||||
[[nodiscard]] GLuint getTextureID (uint32_t imageIndex) const override;
|
[[nodiscard]] GLuint getTextureID (uint32_t imageIndex) const override;
|
||||||
[[nodiscard]] uint32_t getTextureWidth (uint32_t imageIndex) const override;
|
[[nodiscard]] uint32_t getTextureWidth (uint32_t imageIndex) const override;
|
||||||
@ -156,39 +27,16 @@ class CTexture final : public ITexture {
|
|||||||
[[nodiscard]] uint32_t getRealWidth () const override;
|
[[nodiscard]] uint32_t getRealWidth () const override;
|
||||||
[[nodiscard]] uint32_t getRealHeight () const override;
|
[[nodiscard]] uint32_t getRealHeight () const override;
|
||||||
[[nodiscard]] TextureFormat getFormat () const override;
|
[[nodiscard]] TextureFormat getFormat () const override;
|
||||||
[[nodiscard]] TextureFlags getFlags () const override;
|
[[nodiscard]] uint32_t getFlags () const override;
|
||||||
[[nodiscard]] const glm::vec4* getResolution () const override;
|
[[nodiscard]] const glm::vec4* getResolution () const override;
|
||||||
[[nodiscard]] const std::vector<std::shared_ptr<TextureFrame>>& getFrames () const override;
|
[[nodiscard]] const std::vector<FrameSharedPtr>& getFrames () const override;
|
||||||
[[nodiscard]] bool isAnimated () const override;
|
[[nodiscard]] bool isAnimated () const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @return The texture header
|
* @return The texture header
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const TextureHeader* getHeader () const;
|
[[nodiscard]] const Texture& getHeader () const;
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to parse a header off the given data pointer
|
|
||||||
*
|
|
||||||
* @param fileData The point at which to start reading data off from
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
static std::unique_ptr<TextureHeader> parseHeader (const char* fileData);
|
|
||||||
/**
|
|
||||||
* Tries to parse an animation frame off the given data pointer
|
|
||||||
*
|
|
||||||
* @param originalFileData The point at which to start reading data off from
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
static std::shared_ptr<TextureFrame> parseAnimation (const char** originalFileData);
|
|
||||||
/**
|
|
||||||
* Tries to parse mipmap information off the given data pointer
|
|
||||||
*
|
|
||||||
* @param header The file header
|
|
||||||
* @param fileData The point at which to start reading data off from
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
static std::shared_ptr<TextureMipmap> parseMipmap (const TextureHeader* header, const char** fileData);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate's texture's resolution vec4
|
* Calculate's texture's resolution vec4
|
||||||
@ -204,7 +52,7 @@ class CTexture final : public ITexture {
|
|||||||
void setupOpenGLParameters (uint32_t textureID);
|
void setupOpenGLParameters (uint32_t textureID);
|
||||||
|
|
||||||
/** The texture header */
|
/** The texture header */
|
||||||
std::unique_ptr<TextureHeader> m_header = nullptr;
|
TextureUniquePtr m_header;
|
||||||
/** OpenGL's texture ID */
|
/** OpenGL's texture ID */
|
||||||
GLuint* m_textureID = nullptr;
|
GLuint* m_textureID = nullptr;
|
||||||
/** Resolution vector of the texture */
|
/** Resolution vector of the texture */
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
#include <memory.h>
|
|
||||||
|
|
||||||
#include "CAssetLoadException.h"
|
|
||||||
#include "CVirtualContainer.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Assets;
|
|
||||||
|
|
||||||
void CVirtualContainer::add (const std::filesystem::path& filename, const std::shared_ptr<const uint8_t[]>& contents, uint32_t length) {
|
|
||||||
this->m_virtualFiles.emplace (filename, std::make_unique<CFileEntry> (contents, length));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CVirtualContainer::add (const std::filesystem::path& filename, const std::string& contents) {
|
|
||||||
size_t length = contents.length () + 1;
|
|
||||||
std::shared_ptr<uint8_t[]> copy = std::shared_ptr<uint8_t[]> (new uint8_t [length]);
|
|
||||||
|
|
||||||
// copy the text AND the \0
|
|
||||||
memcpy (copy.get(), contents.c_str (), length);
|
|
||||||
|
|
||||||
// finally add to the container
|
|
||||||
this->add (filename, copy, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CVirtualContainer::add (const std::filesystem::path& filename, const char* contents) {
|
|
||||||
this->add (filename, std::string (contents));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CVirtualContainer::add (const std::filesystem::path& filename, const json& contents) {
|
|
||||||
this->add (filename, contents.dump ());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<const uint8_t[]> CVirtualContainer::readFile (const std::filesystem::path& filename, uint32_t* length) const {
|
|
||||||
const auto cur = this->m_virtualFiles.find (filename);
|
|
||||||
|
|
||||||
if (cur == this->m_virtualFiles.end ())
|
|
||||||
throw CAssetLoadException (filename, "Cannot find file in the virtual container");
|
|
||||||
|
|
||||||
if (length != nullptr)
|
|
||||||
*length = cur->second->length;
|
|
||||||
|
|
||||||
// clone original first
|
|
||||||
return cur->second->content;
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
#include <filesystem>
|
|
||||||
|
|
||||||
#include "CContainer.h"
|
|
||||||
#include "CFileEntry.h"
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Assets {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
/**
|
|
||||||
* Virtual container implementation, provides virtual files for the backgrounds to use
|
|
||||||
*/
|
|
||||||
class CVirtualContainer final : public CContainer {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Adds a new file to the virtual container
|
|
||||||
*
|
|
||||||
* @param filename
|
|
||||||
* @param contents
|
|
||||||
* @param length
|
|
||||||
*/
|
|
||||||
void add (const std::filesystem::path& filename, const std::shared_ptr<const uint8_t[]>& contents, uint32_t length);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a new file to the virtual container
|
|
||||||
*
|
|
||||||
* @param filename
|
|
||||||
* @param contents
|
|
||||||
*/
|
|
||||||
void add (const std::filesystem::path& filename, const std::string& contents);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a new file to the virtual container
|
|
||||||
*
|
|
||||||
* @param filename
|
|
||||||
* @param contents
|
|
||||||
*/
|
|
||||||
void add (const std::filesystem::path& filename, const char* contents);
|
|
||||||
/**
|
|
||||||
* Adds a new file to the virtual container from a json object
|
|
||||||
* @param filename
|
|
||||||
* @param contents
|
|
||||||
*/
|
|
||||||
void add (const std::filesystem::path& filename, const json& contents);
|
|
||||||
|
|
||||||
/** @inheritdoc */
|
|
||||||
std::shared_ptr<const uint8_t[]> readFile (const std::filesystem::path& filename, uint32_t* length) const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** The recorded files in this virtual container */
|
|
||||||
std::map<std::string, std::unique_ptr<CFileEntry>> m_virtualFiles = {};
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Assets
|
|
@ -6,7 +6,11 @@
|
|||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <glm/vec4.hpp>
|
#include <glm/vec4.hpp>
|
||||||
|
|
||||||
|
#include "WallpaperEngine/Data/Assets/Texture.h"
|
||||||
|
#include "WallpaperEngine/Data/Model/Types.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Assets {
|
namespace WallpaperEngine::Assets {
|
||||||
|
using namespace WallpaperEngine::Data::Assets;
|
||||||
/**
|
/**
|
||||||
* Base interface that describes the minimum information required for a texture
|
* Base interface that describes the minimum information required for a texture
|
||||||
* to be displayed by the engine
|
* to be displayed by the engine
|
||||||
@ -15,62 +19,6 @@ class ITexture {
|
|||||||
public:
|
public:
|
||||||
virtual ~ITexture () = default;
|
virtual ~ITexture () = default;
|
||||||
|
|
||||||
/**
|
|
||||||
* Texture frame information for animated textures
|
|
||||||
*/
|
|
||||||
class TextureFrame final {
|
|
||||||
public:
|
|
||||||
TextureFrame ();
|
|
||||||
virtual ~TextureFrame () = default;
|
|
||||||
|
|
||||||
/** The image index of this frame */
|
|
||||||
uint32_t frameNumber = 0;
|
|
||||||
/** The amount of time this frame spends being displayed */
|
|
||||||
float frametime = 0.0f;
|
|
||||||
/** The x position of the frame in the texture */
|
|
||||||
float x = 0.0f;
|
|
||||||
/** The y position of the frame in the texture */
|
|
||||||
float y = 0.0f;
|
|
||||||
/** The width of the frame in the texture */
|
|
||||||
float width1 = 0.0f;
|
|
||||||
float width2 = 0.0f;
|
|
||||||
/** The height of the frame in the texture */
|
|
||||||
float height1 = 0.0f;
|
|
||||||
float height2 = 0.0f;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data formats for textures in memory
|
|
||||||
*/
|
|
||||||
enum TextureFormat : uint32_t {
|
|
||||||
UNKNOWN = 0xFFFFFFFF,
|
|
||||||
ARGB8888 = 0,
|
|
||||||
RGB888 = 1,
|
|
||||||
RGB565 = 2,
|
|
||||||
DXT5 = 4,
|
|
||||||
DXT3 = 6,
|
|
||||||
DXT1 = 7,
|
|
||||||
RG88 = 8,
|
|
||||||
R8 = 9,
|
|
||||||
RG1616f = 10,
|
|
||||||
R16f = 11,
|
|
||||||
BC7 = 12,
|
|
||||||
RGBa1010102 = 13,
|
|
||||||
RGBA16161616f = 14,
|
|
||||||
RGB161616f = 15,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Different settings of the textures
|
|
||||||
*/
|
|
||||||
enum TextureFlags : uint32_t {
|
|
||||||
NoFlags = 0,
|
|
||||||
NoInterpolation = 1,
|
|
||||||
ClampUVs = 2,
|
|
||||||
IsGif = 4,
|
|
||||||
ClampUVsBorder = 8,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param imageIndex For animated textures, the frame to get the ID of
|
* @param imageIndex For animated textures, the frame to get the ID of
|
||||||
* @return The OpenGL texture to use when rendering
|
* @return The OpenGL texture to use when rendering
|
||||||
@ -101,11 +49,11 @@ class ITexture {
|
|||||||
/**
|
/**
|
||||||
* @return The texture's settings
|
* @return The texture's settings
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] virtual TextureFlags getFlags () const = 0;
|
[[nodiscard]] virtual uint32_t getFlags () const = 0;
|
||||||
/**
|
/**
|
||||||
* @return The list of frames this texture has
|
* @return The list of frames this texture has
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] virtual const std::vector<std::shared_ptr<TextureFrame>>& getFrames () const = 0;
|
[[nodiscard]] virtual const std::vector<FrameSharedPtr>& getFrames () const = 0;
|
||||||
/**
|
/**
|
||||||
* @return The texture's resolution vector
|
* @return The texture's resolution vector
|
||||||
*/
|
*/
|
||||||
|
@ -61,26 +61,24 @@ int audio_read_thread (void* arg) {
|
|||||||
|
|
||||||
static int audio_read_data_callback (void* streamarg, uint8_t* buffer, int buffer_size) {
|
static int audio_read_data_callback (void* streamarg, uint8_t* buffer, int buffer_size) {
|
||||||
const auto stream = static_cast<CAudioStream*> (streamarg);
|
const auto stream = static_cast<CAudioStream*> (streamarg);
|
||||||
const int left = stream->getLength () - stream->getPosition ();
|
|
||||||
|
|
||||||
buffer_size = FFMIN (buffer_size, left);
|
stream->getBuffer ()->read (reinterpret_cast<std::istream::char_type*> (buffer), buffer_size);
|
||||||
|
|
||||||
memcpy (buffer, stream->getBuffer ().get() + stream->getPosition (), buffer_size);
|
// return read bytes only
|
||||||
// update position
|
return stream->getBuffer ()->gcount ();
|
||||||
stream->setPosition (stream->getPosition () + buffer_size);
|
|
||||||
|
|
||||||
return buffer_size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t audio_seek_data_callback (void* streamarg, int64_t offset, int whence) {
|
int64_t audio_seek_data_callback (void* streamarg, int64_t offset, int whence) {
|
||||||
const auto stream = static_cast<CAudioStream*> (streamarg);
|
const auto stream = static_cast<CAudioStream*> (streamarg);
|
||||||
|
|
||||||
|
// this was supported before, now we don't as there's no easy way to tell length
|
||||||
|
// so returning <0 signals no support for it
|
||||||
if (whence & AVSEEK_SIZE)
|
if (whence & AVSEEK_SIZE)
|
||||||
return stream->getLength ();
|
return -1;
|
||||||
|
|
||||||
switch (whence) {
|
switch (whence) {
|
||||||
case SEEK_CUR: stream->setPosition (stream->getPosition () + offset); break;
|
case SEEK_CUR: stream->getBuffer ()->seekg (offset, std::ios_base::cur); break;
|
||||||
case SEEK_SET: stream->setPosition (offset); break;
|
case SEEK_SET: stream->getBuffer ()->seekg (offset, std::ios_base::beg); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return offset;
|
return offset;
|
||||||
@ -91,7 +89,7 @@ CAudioStream::CAudioStream (CAudioContext& context, const std::string& filename)
|
|||||||
this->loadCustomContent (filename.c_str ());
|
this->loadCustomContent (filename.c_str ());
|
||||||
}
|
}
|
||||||
|
|
||||||
CAudioStream::CAudioStream (CAudioContext& context, std::shared_ptr<const uint8_t[]> buffer, uint32_t length) :
|
CAudioStream::CAudioStream (CAudioContext& context, const ReadStreamSharedPtr& buffer, uint32_t length) :
|
||||||
m_audioContext (context) {
|
m_audioContext (context) {
|
||||||
// setup a custom context first
|
// setup a custom context first
|
||||||
this->m_formatContext = avformat_alloc_context ();
|
this->m_formatContext = avformat_alloc_context ();
|
||||||
@ -101,7 +99,6 @@ CAudioStream::CAudioStream (CAudioContext& context, std::shared_ptr<const uint8_
|
|||||||
|
|
||||||
this->m_buffer = buffer;
|
this->m_buffer = buffer;
|
||||||
this->m_length = length;
|
this->m_length = length;
|
||||||
this->m_position = 0;
|
|
||||||
|
|
||||||
// setup custom io for it
|
// setup custom io for it
|
||||||
this->m_formatContext->pb = avio_alloc_context (static_cast<uint8_t*> (av_malloc (4096)), 4096, 0, this,
|
this->m_formatContext->pb = avio_alloc_context (static_cast<uint8_t*> (av_malloc (4096)), 4096, 0, this,
|
||||||
@ -252,7 +249,7 @@ bool CAudioStream::doQueue (AVPacket* pkt) {
|
|||||||
MyAVPacketList entry {pkt};
|
MyAVPacketList entry {pkt};
|
||||||
|
|
||||||
#if FF_API_FIFO_OLD_API
|
#if FF_API_FIFO_OLD_API
|
||||||
if (av_fifo_space (this->m_queue->packetList) < sizeof (entry))
|
if (av_fifo_space (this->m_queue->packetList) < static_cast <int> (sizeof (entry)))
|
||||||
if (av_fifo_grow (this->m_queue->packetList, sizeof (entry)) < 0)
|
if (av_fifo_grow (this->m_queue->packetList, sizeof (entry)) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -281,7 +278,7 @@ void CAudioStream::dequeuePacket (AVPacket* output) {
|
|||||||
#if FF_API_FIFO_OLD_API
|
#if FF_API_FIFO_OLD_API
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (av_fifo_size (this->m_queue->packetList) >= sizeof (entry))
|
if (av_fifo_size (this->m_queue->packetList) >= static_cast <int> (sizeof (entry)))
|
||||||
ret = av_fifo_generic_read (this->m_queue->packetList, &entry, sizeof (entry), nullptr);
|
ret = av_fifo_generic_read (this->m_queue->packetList, &entry, sizeof (entry), nullptr);
|
||||||
#else
|
#else
|
||||||
int ret = av_fifo_read (this->m_queue->packetList, &entry, 1);
|
int ret = av_fifo_read (this->m_queue->packetList, &entry, 1);
|
||||||
@ -330,7 +327,7 @@ bool CAudioStream::isRepeat () const {
|
|||||||
return this->m_repeat;
|
return this->m_repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<const uint8_t[]> CAudioStream::getBuffer () {
|
ReadStreamSharedPtr& CAudioStream::getBuffer () {
|
||||||
return this->m_buffer;
|
return this->m_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,14 +335,6 @@ uint32_t CAudioStream::getLength () const {
|
|||||||
return this->m_length;
|
return this->m_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t CAudioStream::getPosition () const {
|
|
||||||
return this->m_position;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CAudioStream::setPosition (uint32_t current) {
|
|
||||||
this->m_position = current;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_cond* CAudioStream::getWaitCondition () {
|
SDL_cond* CAudioStream::getWaitCondition () {
|
||||||
return this->m_queue->wait;
|
return this->m_queue->wait;
|
||||||
}
|
}
|
||||||
|
@ -31,13 +31,15 @@ extern "C" {
|
|||||||
namespace WallpaperEngine::Audio {
|
namespace WallpaperEngine::Audio {
|
||||||
class CAudioContext;
|
class CAudioContext;
|
||||||
|
|
||||||
|
using namespace WallpaperEngine::FileSystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a playable audio stream for the audio driver
|
* Represents a playable audio stream for the audio driver
|
||||||
*/
|
*/
|
||||||
class CAudioStream {
|
class CAudioStream {
|
||||||
public:
|
public:
|
||||||
CAudioStream (CAudioContext& context, const std::string& filename);
|
CAudioStream (CAudioContext& context, const std::string& filename);
|
||||||
CAudioStream (CAudioContext& context, std::shared_ptr<const uint8_t[]> buffer, uint32_t length);
|
CAudioStream (CAudioContext& context, const ReadStreamSharedPtr& buffer, uint32_t length);
|
||||||
CAudioStream (CAudioContext& audioContext, AVCodecContext* context);
|
CAudioStream (CAudioContext& audioContext, AVCodecContext* context);
|
||||||
~CAudioStream ();
|
~CAudioStream ();
|
||||||
|
|
||||||
@ -88,21 +90,11 @@ class CAudioStream {
|
|||||||
/**
|
/**
|
||||||
* @return The file data buffer
|
* @return The file data buffer
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] std::shared_ptr<const uint8_t[]> getBuffer ();
|
[[nodiscard]] ReadStreamSharedPtr& getBuffer ();
|
||||||
/**
|
/**
|
||||||
* @return The length of the file data buffer
|
* @return The length of the file data buffer
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] uint32_t getLength () const;
|
[[nodiscard]] uint32_t getLength () const;
|
||||||
/**
|
|
||||||
* @return The read position of the data buffer
|
|
||||||
*/
|
|
||||||
[[nodiscard]] uint32_t getPosition () const;
|
|
||||||
/**
|
|
||||||
* Updates the read position of the data buffer
|
|
||||||
*
|
|
||||||
* @param current
|
|
||||||
*/
|
|
||||||
void setPosition (uint32_t current);
|
|
||||||
/**
|
/**
|
||||||
* @return The SDL_cond used to signal waiting for data
|
* @return The SDL_cond used to signal waiting for data
|
||||||
*/
|
*/
|
||||||
@ -185,11 +177,9 @@ class CAudioStream {
|
|||||||
/** The stream index for the audio being played */
|
/** The stream index for the audio being played */
|
||||||
int m_audioStream = NO_AUDIO_STREAM;
|
int m_audioStream = NO_AUDIO_STREAM;
|
||||||
/** File data pointer */
|
/** File data pointer */
|
||||||
std::shared_ptr<const uint8_t[]> m_buffer = nullptr;
|
ReadStreamSharedPtr m_buffer = nullptr;
|
||||||
/** The length of the file data pointer */
|
/** The length of the file data pointer */
|
||||||
uint32_t m_length = 0;
|
uint32_t m_length = 0;
|
||||||
/** The read position on the file data pointer */
|
|
||||||
uint32_t m_position = 0;
|
|
||||||
|
|
||||||
struct MyAVPacketList {
|
struct MyAVPacketList {
|
||||||
AVPacket* packet;
|
AVPacket* packet;
|
||||||
|
@ -16,7 +16,7 @@ void pa_stream_notify_cb (pa_stream* stream, void* /*userdata*/) {
|
|||||||
switch (pa_stream_get_state (stream)) {
|
switch (pa_stream_get_state (stream)) {
|
||||||
case PA_STREAM_FAILED: sLog.error ("Cannot open stream for capture. Audio processing is disabled"); break;
|
case PA_STREAM_FAILED: sLog.error ("Cannot open stream for capture. Audio processing is disabled"); break;
|
||||||
case PA_STREAM_READY: sLog.debug ("Capture stream ready"); break;
|
case PA_STREAM_READY: sLog.debug ("Capture stream ready"); break;
|
||||||
default: sLog.debug("pa_stream_get_state unknown result"); break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +145,6 @@ void pa_context_notify_cb (pa_context* ctx, void* userdata) {
|
|||||||
sLog.error ("PulseAudio context initialization failed. Audio processing is disabled");
|
sLog.error ("PulseAudio context initialization failed. Audio processing is disabled");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sLog.debug ("pa_context_get_state unknown result");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,116 +0,0 @@
|
|||||||
#include "CObject.h"
|
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/CProject.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/CImage.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/CParticle.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/CSound.h"
|
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
|
||||||
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Assets/CContainer.h"
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core;
|
|
||||||
using namespace WallpaperEngine::Assets;
|
|
||||||
using namespace WallpaperEngine::Core::UserSettings;
|
|
||||||
|
|
||||||
CObject::CObject (
|
|
||||||
std::shared_ptr <const Core::CProject> project, const CUserSettingBoolean* visible, int id, std::string name,
|
|
||||||
const CUserSettingVector3* origin, const CUserSettingVector3* scale, const CUserSettingVector3* angles,
|
|
||||||
std::vector<int> dependencies
|
|
||||||
) :
|
|
||||||
m_visible (visible),
|
|
||||||
m_id (id),
|
|
||||||
m_name (std::move(name)),
|
|
||||||
m_origin (origin),
|
|
||||||
m_scale (scale),
|
|
||||||
m_angles (angles),
|
|
||||||
m_project (project),
|
|
||||||
m_dependencies (std::move(dependencies)) {}
|
|
||||||
|
|
||||||
const CObject* CObject::fromJSON (
|
|
||||||
const json& data, std::shared_ptr <const Core::CProject> project, const std::shared_ptr<const CContainer>& container
|
|
||||||
) {
|
|
||||||
const auto id = jsonFindRequired <int> (data, "id", "Objects must have id");
|
|
||||||
const auto visible = jsonFindUserConfig<CUserSettingBoolean> (data, *project, "visible", true);
|
|
||||||
const auto origin = jsonFindUserConfig<CUserSettingVector3> (data, *project, "origin", {0, 0, 0});
|
|
||||||
const auto scale = jsonFindUserConfig<CUserSettingVector3> (data, *project, "scale", {1, 1, 1});
|
|
||||||
const auto angles_val = jsonFindUserConfig<CUserSettingVector3> (data, *project, "angles", glm::vec3 (0, 0, 0));
|
|
||||||
const auto name = jsonFindRequired <std::string> (data, "name", "Objects must have name");
|
|
||||||
const auto effects_it = data.find ("effects");
|
|
||||||
const auto dependencies_it = data.find ("dependencies");
|
|
||||||
|
|
||||||
const auto image_it = data.find ("image");
|
|
||||||
const auto sound_it = data.find ("sound");
|
|
||||||
const auto particle_it = data.find ("particle");
|
|
||||||
const auto text_it = data.find ("text");
|
|
||||||
const auto light_it = data.find ("light");
|
|
||||||
|
|
||||||
std::vector<int> dependencies;
|
|
||||||
std::vector<const Objects::CEffect*> effects;
|
|
||||||
|
|
||||||
const CObject* object;
|
|
||||||
|
|
||||||
if (dependencies_it != data.end () && dependencies_it->is_array ())
|
|
||||||
for (const auto& cur : *dependencies_it)
|
|
||||||
dependencies.push_back (cur);
|
|
||||||
|
|
||||||
if (image_it != data.end () && !image_it->is_null ()) {
|
|
||||||
object = Objects::CImage::fromJSON (
|
|
||||||
project, data, container, visible, id, name, origin, scale, angles_val, effects_it, dependencies);
|
|
||||||
} else if (sound_it != data.end () && !sound_it->is_null ()) {
|
|
||||||
object = Objects::CSound::fromJSON (project, data, visible, id, name, origin, scale, angles_val, dependencies);
|
|
||||||
} else if (particle_it != data.end () && !particle_it->is_null ()) {
|
|
||||||
/// TODO: XXXHACK -- TO REMOVE WHEN PARTICLE SUPPORT IS PROPERLY IMPLEMENTED
|
|
||||||
try {
|
|
||||||
object = Objects::CParticle::fromFile (
|
|
||||||
project, particle_it->get<std::string> (), container, visible, id, name, origin, angles_val, scale, dependencies);
|
|
||||||
} catch (std::runtime_error&) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
} else if (text_it != data.end () && !text_it->is_null ()) {
|
|
||||||
/// TODO: XXXHACK -- TO REMOVE WHEN TEXT SUPPORT IS IMPLEMENTED
|
|
||||||
return nullptr;
|
|
||||||
} else if (light_it != data.end () && !light_it->is_null ()) {
|
|
||||||
/// TODO: XXXHACK -- TO REMOVE WHEN LIGHT SUPPORT IS IMPLEMENTED
|
|
||||||
return nullptr;
|
|
||||||
} else {
|
|
||||||
sLog.exception ("Unknown object type detected: ", name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::vec3& CObject::getOrigin () const {
|
|
||||||
return this->m_origin->getVec3 ();
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::vec3& CObject::getScale () const {
|
|
||||||
return this->m_scale->getVec3 ();
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::vec3& CObject::getAngles () const {
|
|
||||||
return this->m_angles->getVec3 ();
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& CObject::getName () const {
|
|
||||||
return this->m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<int>& CObject::getDependencies () const {
|
|
||||||
return this->m_dependencies;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CObject::isVisible () const {
|
|
||||||
return this->m_visible->getBool ();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr <const CProject> CObject::getProject () const {
|
|
||||||
return this->m_project;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CObject::getId () const {
|
|
||||||
return this->m_id;
|
|
||||||
}
|
|
@ -1,86 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Core.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Assets/CContainer.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/CEffect.h"
|
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
|
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Wallpapers {
|
|
||||||
class CScene;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects {
|
|
||||||
class CEffect;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::UserSettings {
|
|
||||||
class CUserSettingBoolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
using namespace WallpaperEngine::Assets;
|
|
||||||
using namespace WallpaperEngine::Core::UserSettings;
|
|
||||||
|
|
||||||
class CObject {
|
|
||||||
friend class Wallpapers::CScene;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static const CObject* fromJSON ( const json& data, std::shared_ptr <const Core::CProject> project,
|
|
||||||
const std::shared_ptr<const CContainer>& container);
|
|
||||||
|
|
||||||
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::vector<int>& getDependencies () const;
|
|
||||||
[[nodiscard]] int getId () const;
|
|
||||||
|
|
||||||
[[nodiscard]] const glm::vec3& getOrigin () const;
|
|
||||||
[[nodiscard]] const glm::vec3& getScale () const;
|
|
||||||
[[nodiscard]] const glm::vec3& getAngles () const;
|
|
||||||
[[nodiscard]] const std::string& getName () const;
|
|
||||||
|
|
||||||
[[nodiscard]] bool isVisible () const;
|
|
||||||
[[nodiscard]] std::shared_ptr <const Core::CProject> getProject () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
CObject (
|
|
||||||
std::shared_ptr <const Core::CProject> scene, const CUserSettingBoolean* visible, int id, std::string name,
|
|
||||||
const CUserSettingVector3* origin, const CUserSettingVector3* scale, const CUserSettingVector3* angles,
|
|
||||||
std::vector<int> dependencies);
|
|
||||||
|
|
||||||
virtual ~CObject () = default;
|
|
||||||
|
|
||||||
private:
|
|
||||||
const CUserSettingBoolean* m_visible;
|
|
||||||
int m_id = 0;
|
|
||||||
const std::string m_name;
|
|
||||||
const CUserSettingVector3* m_origin;
|
|
||||||
const CUserSettingVector3* m_scale;
|
|
||||||
const CUserSettingVector3* m_angles;
|
|
||||||
|
|
||||||
const std::vector<int> m_dependencies;
|
|
||||||
|
|
||||||
const std::shared_ptr <const Core::CProject> m_project;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core
|
|
@ -1,118 +0,0 @@
|
|||||||
#include <WallpaperEngine/Assets/CContainer.h>
|
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "CProject.h"
|
|
||||||
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
|
|
||||||
#include "WallpaperEngine/Core/Wallpapers/CVideo.h"
|
|
||||||
#include "WallpaperEngine/Core/Wallpapers/CWeb.h"
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core;
|
|
||||||
using namespace WallpaperEngine::Core::Wallpapers;
|
|
||||||
using namespace WallpaperEngine::Assets;
|
|
||||||
|
|
||||||
static int backgroundId = -1;
|
|
||||||
|
|
||||||
CProject::CProject (
|
|
||||||
std::string title, std::string type, std::string workshopid, std::shared_ptr<const CContainer> container,
|
|
||||||
bool supportsaudioprocessing, const std::map<std::string, std::shared_ptr<Projects::CProperty>>& properties
|
|
||||||
) :
|
|
||||||
m_workshopid(std::move(workshopid)),
|
|
||||||
m_title (std::move(title)),
|
|
||||||
m_type (std::move(type)),
|
|
||||||
m_container (std::move(container)),
|
|
||||||
m_properties (properties),
|
|
||||||
m_supportsaudioprocessing (supportsaudioprocessing) {}
|
|
||||||
|
|
||||||
std::shared_ptr<CProject> CProject::fromFile (const std::string& filename, std::shared_ptr<const CContainer> container) {
|
|
||||||
json content = json::parse (container->readFileAsString (filename));
|
|
||||||
|
|
||||||
const auto dependency = jsonFindDefault<std::string> (content, "dependency", "No dependency");
|
|
||||||
|
|
||||||
if (dependency != "No dependency") {
|
|
||||||
sLog.exception ("Project have dependency. They are not supported, quiting");
|
|
||||||
}
|
|
||||||
|
|
||||||
// workshopid is not required, but we have to use it for some identification stuff,
|
|
||||||
// so using a static, decreasing number should be enough
|
|
||||||
bool supportsaudioprocessing = false;
|
|
||||||
auto type = jsonFindRequired <std::string> (content, "type", "Project type missing");
|
|
||||||
const auto file = jsonFindRequired <std::string> (content, "file", "Project's main file missing");
|
|
||||||
auto general = content.find ("general");
|
|
||||||
std::shared_ptr <const CWallpaper> wallpaper = nullptr;
|
|
||||||
std::map<std::string, std::shared_ptr <Projects::CProperty>> properties;
|
|
||||||
|
|
||||||
std::transform (type.begin (), type.end (), type.begin (), tolower);
|
|
||||||
|
|
||||||
if (general != content.end ()) {
|
|
||||||
supportsaudioprocessing = jsonFindDefault (general, "supportsaudioprocessing", false);
|
|
||||||
const auto properties_it = general->find ("properties");
|
|
||||||
|
|
||||||
if (properties_it != general->end ()) {
|
|
||||||
for (const auto& cur : properties_it->items ()) {
|
|
||||||
auto property = Projects::CProperty::fromJSON (cur.value (), cur.key ());
|
|
||||||
|
|
||||||
if (property == nullptr) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
properties.emplace (property->getName (), std::move (property));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<CProject> project = std::make_shared <CProject> (
|
|
||||||
jsonFindRequired <std::string> (content, "title", "Project title missing"),
|
|
||||||
type,
|
|
||||||
jsonFindDefault <std::string> (content, "workshopid", std::to_string (backgroundId--)),
|
|
||||||
container,
|
|
||||||
supportsaudioprocessing,
|
|
||||||
properties
|
|
||||||
);
|
|
||||||
|
|
||||||
if (type == "scene")
|
|
||||||
wallpaper = CScene::fromFile (file, project, container);
|
|
||||||
else if (type == "video")
|
|
||||||
wallpaper = std::make_shared<CVideo> (file, project);
|
|
||||||
else if (type == "web")
|
|
||||||
wallpaper = std::make_shared<CWeb> (file, project);
|
|
||||||
else
|
|
||||||
sLog.exception ("Unsupported wallpaper type: ", type);
|
|
||||||
|
|
||||||
project->setWallpaper (wallpaper);
|
|
||||||
|
|
||||||
return project;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CProject::setWallpaper (std::shared_ptr <const CWallpaper> wallpaper) {
|
|
||||||
this->m_wallpaper = wallpaper;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::shared_ptr <const CWallpaper> CProject::getWallpaper () const {
|
|
||||||
return this->m_wallpaper;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& CProject::getTitle () const {
|
|
||||||
return this->m_title;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& CProject::getType () const {
|
|
||||||
return this->m_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::map<std::string, std::shared_ptr <Projects::CProperty>>& CProject::getProperties () const {
|
|
||||||
return this->m_properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& CProject::getWorkshopId () const {
|
|
||||||
return this->m_workshopid;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<const CContainer> CProject::getContainer () const {
|
|
||||||
return this->m_container;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CProject::supportsAudioProcessing () const {
|
|
||||||
return this->m_supportsaudioprocessing;
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
#include "CWallpaper.h"
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
#include "WallpaperEngine/Core/Projects/CProperty.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Assets/CContainer.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
|
||||||
class CProperty;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
using namespace WallpaperEngine::Assets;
|
|
||||||
|
|
||||||
class CWallpaper;
|
|
||||||
|
|
||||||
class CProject {
|
|
||||||
public:
|
|
||||||
CProject (
|
|
||||||
std::string title, std::string type, std::string workshopid, std::shared_ptr<const CContainer> container,
|
|
||||||
bool supportsaudioprocessing, const std::map<std::string, std::shared_ptr<Projects::CProperty>>& properties);
|
|
||||||
|
|
||||||
static std::shared_ptr<CProject> fromFile (const std::string& filename, std::shared_ptr<const CContainer> container);
|
|
||||||
|
|
||||||
[[nodiscard]] const std::shared_ptr <const CWallpaper> getWallpaper () const;
|
|
||||||
[[nodiscard]] const std::string& getTitle () const;
|
|
||||||
[[nodiscard]] const std::string& getType () const;
|
|
||||||
[[nodiscard]] const std::map<std::string, std::shared_ptr <Projects::CProperty>>& getProperties () const;
|
|
||||||
[[nodiscard]] const std::string& getWorkshopId () const;
|
|
||||||
|
|
||||||
[[nodiscard]] bool supportsAudioProcessing () const;
|
|
||||||
|
|
||||||
[[nodiscard]] std::shared_ptr<const CContainer> getContainer () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void setWallpaper (std::shared_ptr <const CWallpaper> wallpaper);
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::map<std::string, std::shared_ptr<Projects::CProperty>> m_properties;
|
|
||||||
|
|
||||||
const std::string m_workshopid;
|
|
||||||
const std::string m_title;
|
|
||||||
const std::string m_type;
|
|
||||||
const bool m_supportsaudioprocessing;
|
|
||||||
std::shared_ptr <const CWallpaper> m_wallpaper = nullptr;
|
|
||||||
std::shared_ptr<const CContainer> m_container = nullptr;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core
|
|
@ -1,12 +0,0 @@
|
|||||||
#include "CWallpaper.h"
|
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core;
|
|
||||||
|
|
||||||
CWallpaper::CWallpaper (std::shared_ptr <const CProject> project) :
|
|
||||||
m_project (project) {}
|
|
||||||
|
|
||||||
std::shared_ptr <const CProject> CWallpaper::getProject () const {
|
|
||||||
return this->m_project;
|
|
||||||
}
|
|
@ -1,541 +0,0 @@
|
|||||||
#include "Core.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
|
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h"
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine;
|
|
||||||
using namespace WallpaperEngine::Core::UserSettings;
|
|
||||||
|
|
||||||
glm::vec4 Core::aToVector4 (const char* str) {
|
|
||||||
float x = strtof (str, const_cast<char**> (&str));
|
|
||||||
while (*str == ' ')
|
|
||||||
str++;
|
|
||||||
float y = strtof (str, const_cast<char**> (&str));
|
|
||||||
while (*str == ' ')
|
|
||||||
str++;
|
|
||||||
float z = strtof (str, const_cast<char**> (&str));
|
|
||||||
while (*str == ' ')
|
|
||||||
str++;
|
|
||||||
float w = strtof (str, const_cast<char**> (&str));
|
|
||||||
|
|
||||||
return {x, y, z, w};
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::vec3 Core::aToVector3 (const char* str) {
|
|
||||||
float x = strtof (str, const_cast<char**> (&str));
|
|
||||||
while (*str == ' ')
|
|
||||||
str++;
|
|
||||||
float y = strtof (str, const_cast<char**> (&str));
|
|
||||||
while (*str == ' ')
|
|
||||||
str++;
|
|
||||||
float z = strtof (str, const_cast<char**> (&str));
|
|
||||||
|
|
||||||
return {x, y, z};
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::vec2 Core::aToVector2 (const char* str) {
|
|
||||||
float x = strtof (str, const_cast<char**> (&str));
|
|
||||||
while (*str == ' ')
|
|
||||||
str++;
|
|
||||||
float y = strtof (str, const_cast<char**> (&str));
|
|
||||||
|
|
||||||
return {x, y};
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::ivec4 Core::aToVector4i (const char* str) {
|
|
||||||
int x = strtol (str, const_cast<char**> (&str), 10);
|
|
||||||
while (*str == ' ')
|
|
||||||
str++;
|
|
||||||
int y = strtol (str, const_cast<char**> (&str), 10);
|
|
||||||
while (*str == ' ')
|
|
||||||
str++;
|
|
||||||
int z = strtol (str, const_cast<char**> (&str), 10);
|
|
||||||
while (*str == ' ')
|
|
||||||
str++;
|
|
||||||
int w = strtol (str, const_cast<char**> (&str), 10);
|
|
||||||
|
|
||||||
return {x, y, z, w};
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::ivec3 Core::aToVector3i (const char* str) {
|
|
||||||
int x = strtol (str, const_cast<char**> (&str), 10);
|
|
||||||
while (*str == ' ')
|
|
||||||
str++;
|
|
||||||
int y = strtol (str, const_cast<char**> (&str), 10);
|
|
||||||
while (*str == ' ')
|
|
||||||
str++;
|
|
||||||
int z = strtol (str, const_cast<char**> (&str), 10);
|
|
||||||
|
|
||||||
return {x, y, z};
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::ivec2 Core::aToVector2i (const char* str) {
|
|
||||||
int x = strtol (str, const_cast<char**> (&str), 10);
|
|
||||||
while (*str == ' ')
|
|
||||||
str++;
|
|
||||||
int y = strtol (str, const_cast<char**> (&str), 10);
|
|
||||||
|
|
||||||
return {x, y};
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::vec4 Core::aToVector4 (const std::string& str) {
|
|
||||||
return Core::aToVector4 (str.c_str ());
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::vec3 Core::aToVector3 (const std::string& str) {
|
|
||||||
return Core::aToVector3 (str.c_str ());
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::vec2 Core::aToVector2 (const std::string& str) {
|
|
||||||
return Core::aToVector2 (str.c_str ());
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::ivec4 Core::aToVector4i (const std::string& str) {
|
|
||||||
return Core::aToVector4i (str.c_str ());
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::ivec3 Core::aToVector3i (const std::string& str) {
|
|
||||||
return Core::aToVector3i (str.c_str ());
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::ivec2 Core::aToVector2i (const std::string& str) {
|
|
||||||
return Core::aToVector2i (str.c_str ());
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::vec3 Core::aToColorf (const char* str) {
|
|
||||||
float r = strtof (str, const_cast<char**> (&str));
|
|
||||||
while (*str == ' ')
|
|
||||||
str++;
|
|
||||||
float g = strtof (str, const_cast<char**> (&str));
|
|
||||||
while (*str == ' ')
|
|
||||||
str++;
|
|
||||||
float b = strtof (str, const_cast<char**> (&str));
|
|
||||||
|
|
||||||
return {r, g, b};
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::vec3 Core::aToColorf (const std::string& str) {
|
|
||||||
return aToColorf (str.c_str ());
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::ivec3 Core::aToColori (const char* str) {
|
|
||||||
auto r = static_cast<uint8_t> (strtol (str, const_cast<char**> (&str), 10));
|
|
||||||
while (*str == ' ')
|
|
||||||
str++;
|
|
||||||
auto g = static_cast<uint8_t> (strtol (str, const_cast<char**> (&str), 10));
|
|
||||||
while (*str == ' ')
|
|
||||||
str++;
|
|
||||||
auto b = static_cast<uint8_t> (strtol (str, const_cast<char**> (&str), 10));
|
|
||||||
|
|
||||||
return {r, g, b};
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::ivec3 Core::aToColori (const std::string& str) {
|
|
||||||
return aToColori (str.c_str ());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T> bool typeCheck (const nlohmann::json::const_iterator& value) {
|
|
||||||
if (value->type () == nlohmann::detail::value_t::null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// type checks
|
|
||||||
if constexpr ((std::is_same_v<T, float> || std::is_same_v<T, double>) ) {
|
|
||||||
if (value->type () != nlohmann::detail::value_t::number_float &&
|
|
||||||
value->type () != nlohmann::detail::value_t::number_integer &&
|
|
||||||
value->type () != nlohmann::detail::value_t::number_unsigned) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if constexpr (std::is_same_v<T, std::string>) {
|
|
||||||
if (value->type () != nlohmann::detail::value_t::string) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if constexpr (std::is_same_v<T, bool>) {
|
|
||||||
if (value->type () != nlohmann::detail::value_t::boolean) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if constexpr (
|
|
||||||
std::is_same_v<T, glm::vec2> || std::is_same_v<T, glm::vec3> || std::is_same_v<T, glm::vec4> ||
|
|
||||||
std::is_same_v<T, glm::ivec2> || std::is_same_v<T, glm::ivec3> || std::is_same_v<T, glm::ivec4>) {
|
|
||||||
if (value->type () != nlohmann::detail::value_t::string) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T> const T Core::jsonFindRequired (
|
|
||||||
const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg
|
|
||||||
) {
|
|
||||||
const auto iterator = jsonFindRequired (data, key, notFoundMsg);
|
|
||||||
|
|
||||||
// vector types need of special handling
|
|
||||||
if constexpr (std::is_same_v<T, std::string>) {
|
|
||||||
// std::strings are special, type checking doesn't need to happen, we just want the string representation
|
|
||||||
// of whatever is in there
|
|
||||||
if (iterator->is_number_integer ()) {
|
|
||||||
return std::to_string (iterator->get <int> ());
|
|
||||||
} else if (iterator->is_number_float ()) {
|
|
||||||
return std::to_string (iterator->get <float> ());
|
|
||||||
} else if (iterator->is_boolean()) {
|
|
||||||
return std::to_string (iterator->get <bool> ());
|
|
||||||
} else if (iterator->is_null ()) {
|
|
||||||
return "null";
|
|
||||||
} else if (iterator->is_string ()) {
|
|
||||||
return *iterator;
|
|
||||||
}
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::vec4>) {
|
|
||||||
if (!typeCheck<T> (iterator)) {
|
|
||||||
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector4 (*iterator);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::vec3>) {
|
|
||||||
if (!typeCheck<T> (iterator)) {
|
|
||||||
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector3 (*iterator);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::vec2>) {
|
|
||||||
if (!typeCheck<T> (iterator)) {
|
|
||||||
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector2 (*iterator);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::ivec4>) {
|
|
||||||
if (!typeCheck<T> (iterator)) {
|
|
||||||
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector4i (*iterator);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::ivec3>) {
|
|
||||||
if (!typeCheck<T> (iterator)) {
|
|
||||||
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector3i (*iterator);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::ivec2>) {
|
|
||||||
if (!typeCheck<T> (iterator)) {
|
|
||||||
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector2i (*iterator);
|
|
||||||
} else if (typeCheck<T> (iterator)) {
|
|
||||||
return *iterator;
|
|
||||||
}
|
|
||||||
|
|
||||||
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), ": ", notFoundMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
template const bool Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const std::string Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const int16_t Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const uint16_t Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const int32_t Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const uint32_t Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const int64_t Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const uint64_t Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const float Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const double Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const glm::vec4 Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const glm::vec3 Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const glm::vec2 Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const glm::ivec4 Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const glm::ivec3 Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const glm::ivec2 Core::jsonFindRequired (const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
|
||||||
|
|
||||||
template <typename T> const T Core::jsonFindRequired (
|
|
||||||
const nlohmann::json& data, const char* key, const char* notFoundMsg
|
|
||||||
) {
|
|
||||||
const auto iterator = jsonFindRequired (data, key, notFoundMsg);
|
|
||||||
|
|
||||||
// vector types need of special handling
|
|
||||||
if constexpr (std::is_same_v<T, std::string>) {
|
|
||||||
// std::strings are special, type checking doesn't need to happen, we just want the string representation
|
|
||||||
// of whatever is in there
|
|
||||||
if (iterator->is_number_integer ()) {
|
|
||||||
return std::to_string (iterator->get <int> ());
|
|
||||||
} else if (iterator->is_number_float ()) {
|
|
||||||
return std::to_string (iterator->get <float> ());
|
|
||||||
} else if (iterator->is_boolean()) {
|
|
||||||
return std::to_string (iterator->get <bool> ());
|
|
||||||
} else if (iterator->is_null ()) {
|
|
||||||
return "null";
|
|
||||||
} else if (iterator->is_string ()) {
|
|
||||||
return *iterator;
|
|
||||||
}
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::vec4>) {
|
|
||||||
if (!typeCheck<T> (iterator)) {
|
|
||||||
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector4 (*iterator);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::vec3>) {
|
|
||||||
if (!typeCheck<T> (iterator)) {
|
|
||||||
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector3 (*iterator);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::vec2>) {
|
|
||||||
if (!typeCheck<T> (iterator)) {
|
|
||||||
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector2 (*iterator);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::ivec4>) {
|
|
||||||
if (!typeCheck<T> (iterator)) {
|
|
||||||
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector4i (*iterator);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::ivec3>) {
|
|
||||||
if (!typeCheck<T> (iterator)) {
|
|
||||||
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector3i (*iterator);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::ivec2>) {
|
|
||||||
if (!typeCheck<T> (iterator)) {
|
|
||||||
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string", ": ", notFoundMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector2i (*iterator);
|
|
||||||
} else if (typeCheck<T> (iterator)) {
|
|
||||||
return *iterator;
|
|
||||||
}
|
|
||||||
|
|
||||||
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), ": ", notFoundMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
template const bool Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const std::string Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const int16_t Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const uint16_t Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const int32_t Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const uint32_t Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const int64_t Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const uint64_t Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const float Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const double Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const glm::vec4 Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const glm::vec3 Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const glm::vec2 Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const glm::ivec4 Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const glm::ivec3 Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
||||||
template const glm::ivec2 Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
|
||||||
|
|
||||||
nlohmann::json::const_iterator Core::jsonFindRequired (
|
|
||||||
const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg
|
|
||||||
) {
|
|
||||||
auto value = data->find (key);
|
|
||||||
|
|
||||||
if (value == data->end ())
|
|
||||||
sLog.exception ("Cannot find required key (", key, ") in json: ", notFoundMsg);
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
nlohmann::json::const_iterator Core::jsonFindRequired (
|
|
||||||
const nlohmann::json& data, const char* key, const char* notFoundMsg
|
|
||||||
) {
|
|
||||||
auto value = data.find (key);
|
|
||||||
|
|
||||||
if (value == data.end ())
|
|
||||||
sLog.exception ("Cannot find required key (", key, ") in json: ", notFoundMsg);
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T> const T Core::jsonFindDefault (
|
|
||||||
const nlohmann::json::const_iterator& data, const char* key, const T defaultValue
|
|
||||||
) {
|
|
||||||
const auto value = data->find (key);
|
|
||||||
|
|
||||||
if (value == data->end () || value->type () == nlohmann::detail::value_t::null)
|
|
||||||
return defaultValue;
|
|
||||||
|
|
||||||
// vector types need of special handling
|
|
||||||
if constexpr (std::is_same_v<T, std::string>) {
|
|
||||||
// std::strings are special, type checking doesn't need to happen, we just want the string representation
|
|
||||||
// of whatever is in there
|
|
||||||
if (value->is_number_integer ()) {
|
|
||||||
return std::to_string (value->get <int> ());
|
|
||||||
} else if (value->is_number_float ()) {
|
|
||||||
return std::to_string (value->get <float> ());
|
|
||||||
} else if (value->is_boolean()) {
|
|
||||||
return std::to_string (value->get <bool> ());
|
|
||||||
} else if (value->is_null ()) {
|
|
||||||
return "null";
|
|
||||||
} else if (value->is_string ()) {
|
|
||||||
return *value;
|
|
||||||
}
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::vec4>) {
|
|
||||||
if (!typeCheck<T> (value)) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector4 (*value);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::vec3>) {
|
|
||||||
if (!typeCheck<T> (value)) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector3 (*value);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::vec2>) {
|
|
||||||
if (!typeCheck<T> (value)) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector2 (*value);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::ivec4>) {
|
|
||||||
if (!typeCheck<T> (value)) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector4i (*value);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::ivec3>) {
|
|
||||||
if (!typeCheck<T> (value)) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector3i (*value);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::ivec2>) {
|
|
||||||
if (!typeCheck<T> (value)) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector2i (*value);
|
|
||||||
} else if (typeCheck<T> (value)) {
|
|
||||||
return *value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
template const bool Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const bool defaultValue);
|
|
||||||
template const std::string Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const std::string defaultValue);
|
|
||||||
template const int16_t Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const int16_t defaultValue);
|
|
||||||
template const uint16_t Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const uint16_t defaultValue);
|
|
||||||
template const int32_t Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const int32_t defaultValue);
|
|
||||||
template const uint32_t Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const uint32_t defaultValue);
|
|
||||||
template const int64_t Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const int64_t defaultValue);
|
|
||||||
template const uint64_t Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const uint64_t defaultValue);
|
|
||||||
template const float Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const float defaultValue);
|
|
||||||
template const double Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const double defaultValue);
|
|
||||||
template const glm::vec2 Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const glm::vec2 defaultValue);
|
|
||||||
template const glm::vec3 Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const glm::vec3 defaultValue);
|
|
||||||
template const glm::vec4 Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const glm::vec4 defaultValue);
|
|
||||||
template const glm::ivec2 Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const glm::ivec2 defaultValue);
|
|
||||||
template const glm::ivec3 Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const glm::ivec3 defaultValue);
|
|
||||||
template const glm::ivec4 Core::jsonFindDefault (const nlohmann::json::const_iterator& data, const char* key, const glm::ivec4 defaultValue);
|
|
||||||
|
|
||||||
template <typename T> const T Core::jsonFindDefault (
|
|
||||||
const nlohmann::json& data, const char* key, const T defaultValue
|
|
||||||
) {
|
|
||||||
const auto value = data.find (key);
|
|
||||||
|
|
||||||
if (value == data.end () || value->type () == nlohmann::detail::value_t::null)
|
|
||||||
return defaultValue;
|
|
||||||
|
|
||||||
// vector types need of special handling
|
|
||||||
if constexpr (std::is_same_v<T, glm::vec4>) {
|
|
||||||
if (!typeCheck<T> (value)) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector4 (*value);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::vec3>) {
|
|
||||||
if (!typeCheck<T> (value)) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector3 (*value);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::vec2>) {
|
|
||||||
if (!typeCheck<T> (value)) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector2 (*value);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::ivec4>) {
|
|
||||||
if (!typeCheck<T> (value)) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector4i (*value);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::ivec3>) {
|
|
||||||
if (!typeCheck<T> (value)) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector3i (*value);
|
|
||||||
} else if constexpr (std::is_same_v<T, glm::ivec2>) {
|
|
||||||
if (!typeCheck<T> (value)) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return aToVector2i (*value);
|
|
||||||
} else if (typeCheck<T> (value)) {
|
|
||||||
return *value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
template const bool Core::jsonFindDefault (const nlohmann::json& data, const char* key, const bool defaultValue);
|
|
||||||
template const std::string Core::jsonFindDefault (const nlohmann::json& data, const char* key, const std::string defaultValue);
|
|
||||||
template const int16_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const int16_t defaultValue);
|
|
||||||
template const uint16_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const uint16_t defaultValue);
|
|
||||||
template const int32_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const int32_t defaultValue);
|
|
||||||
template const uint32_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const uint32_t defaultValue);
|
|
||||||
template const int64_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const int64_t defaultValue);
|
|
||||||
template const uint64_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const uint64_t defaultValue);
|
|
||||||
template const float Core::jsonFindDefault (const nlohmann::json& data, const char* key, const float defaultValue);
|
|
||||||
template const double Core::jsonFindDefault (const nlohmann::json& data, const char* key, const double defaultValue);
|
|
||||||
template const glm::vec2 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::vec2 defaultValue);
|
|
||||||
template const glm::vec3 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::vec3 defaultValue);
|
|
||||||
template const glm::vec4 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::vec4 defaultValue);
|
|
||||||
template const glm::ivec2 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::ivec2 defaultValue);
|
|
||||||
template const glm::ivec3 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::ivec3 defaultValue);
|
|
||||||
template const glm::ivec4 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::ivec4 defaultValue);
|
|
||||||
|
|
||||||
template <typename T> const T* Core::jsonFindUserConfig (
|
|
||||||
const nlohmann::json::const_iterator& data, const CProject& project, const char* key, typename T::data_type defaultValue
|
|
||||||
) {
|
|
||||||
const auto it = data->find (key);
|
|
||||||
|
|
||||||
if (it == data->end () || it->type () == nlohmann::detail::value_t::null)
|
|
||||||
return T::fromScalar (defaultValue);
|
|
||||||
|
|
||||||
return T::fromJSON (*it, project);
|
|
||||||
}
|
|
||||||
|
|
||||||
template const CUserSettingBoolean* Core::jsonFindUserConfig (
|
|
||||||
const nlohmann::json::const_iterator& data, const CProject& project, const char* key,
|
|
||||||
CUserSettingBoolean::data_type defaultValue);
|
|
||||||
template const CUserSettingVector3* Core::jsonFindUserConfig (
|
|
||||||
const nlohmann::json::const_iterator& data, const CProject& project, const char* key,
|
|
||||||
CUserSettingVector3::data_type defaultValue);
|
|
||||||
template const CUserSettingFloat* Core::jsonFindUserConfig (
|
|
||||||
const nlohmann::json::const_iterator& data, const CProject& project, const char* key,
|
|
||||||
CUserSettingFloat::data_type defaultValue);
|
|
||||||
|
|
||||||
template <typename T> const T* Core::jsonFindUserConfig (
|
|
||||||
const nlohmann::json& data, const CProject& project, const char* key, typename T::data_type defaultValue
|
|
||||||
) {
|
|
||||||
const auto it = data.find (key);
|
|
||||||
|
|
||||||
if (it == data.end () || it->type () == nlohmann::detail::value_t::null)
|
|
||||||
return T::fromScalar (defaultValue);
|
|
||||||
|
|
||||||
return T::fromJSON (*it, project);
|
|
||||||
}
|
|
||||||
|
|
||||||
template const CUserSettingBoolean* Core::jsonFindUserConfig (
|
|
||||||
const nlohmann::json& data, const CProject& project, const char* key, CUserSettingBoolean::data_type defaultValue);
|
|
||||||
template const CUserSettingVector3* Core::jsonFindUserConfig (
|
|
||||||
const nlohmann::json& data, const CProject& project, const char* key, CUserSettingVector3::data_type defaultValue);
|
|
||||||
template const CUserSettingFloat* Core::jsonFindUserConfig (
|
|
||||||
const nlohmann::json& data, const CProject& project, const char* key, CUserSettingFloat::data_type defaultValue);
|
|
@ -1,51 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CProject.h"
|
|
||||||
#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);
|
|
||||||
template <typename T> const T* jsonFindUserConfig (
|
|
||||||
const nlohmann::json::const_iterator& data, const CProject& project, const char* key, typename T::data_type defaultValue);
|
|
||||||
template <typename T> const T* jsonFindUserConfig (
|
|
||||||
const nlohmann::json& data, const CProject& project, const char* key, typename T::data_type defaultValue);
|
|
||||||
} // namespace WallpaperEngine::Core
|
|
@ -1,205 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include "CDynamicValue.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::DynamicValues;
|
|
||||||
|
|
||||||
CDynamicValue::~CDynamicValue() {
|
|
||||||
for (auto* connection : this->m_incomingConnections) {
|
|
||||||
connection->destroyOutgoingConnection (this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDynamicValue::update(float newValue) {
|
|
||||||
this->m_ivec4 = glm::ivec4(static_cast<int> (newValue));
|
|
||||||
this->m_ivec3 = glm::ivec3(static_cast<int> (newValue));
|
|
||||||
this->m_ivec2 = glm::ivec2(static_cast<int> (newValue));
|
|
||||||
this->m_vec4 = glm::vec4(newValue);
|
|
||||||
this->m_vec3 = glm::vec3(newValue);
|
|
||||||
this->m_vec2 = glm::vec2(newValue);
|
|
||||||
this->m_float = newValue;
|
|
||||||
this->m_int = static_cast<int> (newValue);
|
|
||||||
this->m_bool = static_cast<int> (newValue) != 0;
|
|
||||||
|
|
||||||
this->propagate ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDynamicValue::update(int newValue) {
|
|
||||||
this->m_ivec4 = glm::ivec4(newValue);
|
|
||||||
this->m_ivec3 = glm::ivec3(newValue);
|
|
||||||
this->m_ivec2 = glm::ivec2(newValue);
|
|
||||||
this->m_vec4 = glm::vec4(static_cast<float> (newValue));
|
|
||||||
this->m_vec3 = glm::vec3(static_cast<float> (newValue));
|
|
||||||
this->m_vec2 = glm::vec2(static_cast<float> (newValue));
|
|
||||||
this->m_float = static_cast<float> (newValue);
|
|
||||||
this->m_int = newValue;
|
|
||||||
this->m_bool = newValue != 0;
|
|
||||||
|
|
||||||
this->propagate ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDynamicValue::update(bool newValue) {
|
|
||||||
this->m_ivec4 = glm::ivec4(newValue);
|
|
||||||
this->m_ivec3 = glm::ivec3(newValue);
|
|
||||||
this->m_ivec2 = glm::ivec2(newValue);
|
|
||||||
this->m_vec4 = glm::vec4(newValue);
|
|
||||||
this->m_vec3 = glm::vec3(newValue);
|
|
||||||
this->m_vec2 = glm::vec2(newValue);
|
|
||||||
this->m_float = newValue;
|
|
||||||
this->m_int = newValue;
|
|
||||||
this->m_bool = newValue;
|
|
||||||
|
|
||||||
this->propagate ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDynamicValue::update(const glm::vec2& newValue) {
|
|
||||||
this->m_ivec4 = glm::ivec4(newValue, 0, 0);
|
|
||||||
this->m_ivec3 = glm::ivec3(newValue, 0);
|
|
||||||
this->m_ivec2 = glm::ivec2(newValue);
|
|
||||||
this->m_vec2 = newValue;
|
|
||||||
this->m_vec3 = glm::vec3(newValue, 0.0f);
|
|
||||||
this->m_vec4 = glm::vec4(newValue, 0.0f, 0.0f);
|
|
||||||
this->m_float = newValue.x;
|
|
||||||
this->m_int = static_cast<int> (newValue.x);
|
|
||||||
this->m_bool = newValue.x != 0.0f;
|
|
||||||
|
|
||||||
this->propagate ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDynamicValue::update(const glm::vec3& newValue) {
|
|
||||||
this->m_ivec4 = glm::ivec4(newValue, 0);
|
|
||||||
this->m_ivec3 = glm::ivec3(newValue);
|
|
||||||
this->m_ivec2 = glm::ivec2(newValue);
|
|
||||||
this->m_vec2 = glm::vec2(newValue);
|
|
||||||
this->m_vec3 = newValue;
|
|
||||||
this->m_vec4 = glm::vec4(newValue, 0.0f);
|
|
||||||
this->m_float = newValue.x;
|
|
||||||
this->m_int = static_cast<int> (newValue.x);
|
|
||||||
this->m_bool = newValue.x != 0.0f;
|
|
||||||
|
|
||||||
this->propagate ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDynamicValue::update(const glm::vec4& newValue) {
|
|
||||||
this->m_ivec4 = glm::ivec4(newValue);
|
|
||||||
this->m_ivec3 = glm::ivec3(newValue);
|
|
||||||
this->m_ivec2 = glm::ivec2(newValue);
|
|
||||||
this->m_vec2 = glm::vec2(newValue);
|
|
||||||
this->m_vec3 = glm::vec3(newValue);
|
|
||||||
this->m_vec4 = newValue;
|
|
||||||
this->m_float = newValue.x;
|
|
||||||
this->m_int = static_cast<int> (newValue.x);
|
|
||||||
this->m_bool = newValue.x != 0.0f;
|
|
||||||
|
|
||||||
this->propagate ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDynamicValue::update(const glm::ivec2& newValue) {
|
|
||||||
this->m_ivec4 = glm::ivec4(newValue, 0, 0);
|
|
||||||
this->m_ivec3 = glm::ivec3(newValue, 0);
|
|
||||||
this->m_ivec2 = glm::ivec2(newValue);
|
|
||||||
this->m_vec2 = newValue;
|
|
||||||
this->m_vec3 = glm::vec3(newValue, 0.0f);
|
|
||||||
this->m_vec4 = glm::vec4(newValue, 0.0f, 0.0f);
|
|
||||||
this->m_float = static_cast<float> (newValue.x);
|
|
||||||
this->m_int = static_cast<int> (newValue.x);
|
|
||||||
this->m_bool = newValue.x != 0;
|
|
||||||
|
|
||||||
this->propagate ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDynamicValue::update(const glm::ivec3& newValue) {
|
|
||||||
this->m_ivec4 = glm::ivec4(newValue, 0);
|
|
||||||
this->m_ivec3 = glm::ivec3(newValue);
|
|
||||||
this->m_ivec2 = glm::ivec2(newValue);
|
|
||||||
this->m_vec2 = glm::vec2(newValue);
|
|
||||||
this->m_vec3 = newValue;
|
|
||||||
this->m_vec4 = glm::vec4(newValue, 0.0f);
|
|
||||||
this->m_float = static_cast<float> (newValue.x);
|
|
||||||
this->m_int = static_cast<int> (newValue.x);
|
|
||||||
this->m_bool = newValue.x != 0;
|
|
||||||
|
|
||||||
this->propagate ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDynamicValue::update(const glm::ivec4& newValue) {
|
|
||||||
this->m_ivec4 = glm::ivec4(newValue);
|
|
||||||
this->m_ivec3 = glm::ivec3(newValue);
|
|
||||||
this->m_ivec2 = glm::ivec2(newValue);
|
|
||||||
this->m_vec2 = glm::vec2(newValue);
|
|
||||||
this->m_vec3 = glm::vec3(newValue);
|
|
||||||
this->m_vec4 = newValue;
|
|
||||||
this->m_float = static_cast<float> (newValue.x);
|
|
||||||
this->m_int = static_cast<int> (newValue.x);
|
|
||||||
this->m_bool = newValue.x != 0;
|
|
||||||
|
|
||||||
this->propagate ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDynamicValue::connectOutgoing (CDynamicValue* value) const {
|
|
||||||
this->m_outgoingConnections.push_back (value);
|
|
||||||
|
|
||||||
// ensure that new connection has the right value
|
|
||||||
this->propagate ();
|
|
||||||
// ensure the other value keeps track of our connection too
|
|
||||||
value->connectIncoming (this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDynamicValue::connectIncoming (const CDynamicValue* value) const {
|
|
||||||
this->m_incomingConnections.push_back (value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDynamicValue::destroyOutgoingConnection (CDynamicValue* value) const {
|
|
||||||
this->m_outgoingConnections.erase (
|
|
||||||
std::remove (this->m_outgoingConnections.begin (), this->m_outgoingConnections.end (), value), this->m_outgoingConnections.end ()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDynamicValue::propagate () const {
|
|
||||||
for (auto* cur : this->m_outgoingConnections) {
|
|
||||||
cur->m_bool = this->m_bool;
|
|
||||||
cur->m_int = this->m_int;
|
|
||||||
cur->m_float = this->m_float;
|
|
||||||
cur->m_ivec2 = this->m_ivec2;
|
|
||||||
cur->m_ivec3 = this->m_ivec3;
|
|
||||||
cur->m_ivec4 = this->m_ivec4;
|
|
||||||
cur->m_vec2 = this->m_vec2;
|
|
||||||
cur->m_vec3 = this->m_vec3;
|
|
||||||
cur->m_vec4 = this->m_vec4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::ivec4& CDynamicValue::getIVec4 () const {
|
|
||||||
return this->m_ivec4;
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::ivec3& CDynamicValue::getIVec3 () const {
|
|
||||||
return this->m_ivec3;
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::ivec2& CDynamicValue::getIVec2 () const {
|
|
||||||
return this->m_ivec2;
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::vec4& CDynamicValue::getVec4 () const {
|
|
||||||
return this->m_vec4;
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::vec3& CDynamicValue::getVec3 () const {
|
|
||||||
return this->m_vec3;
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::vec2& CDynamicValue::getVec2 () const {
|
|
||||||
return this->m_vec2;
|
|
||||||
}
|
|
||||||
|
|
||||||
const float& CDynamicValue::getFloat () const {
|
|
||||||
return this->m_float;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int& CDynamicValue::getInt () const {
|
|
||||||
return this->m_int;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool& CDynamicValue::getBool () const {
|
|
||||||
return this->m_bool;
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::DynamicValues {
|
|
||||||
class CDynamicValue {
|
|
||||||
public:
|
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
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);
|
|
||||||
/**
|
|
||||||
* 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 = {};
|
|
||||||
// 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;
|
|
||||||
};
|
|
||||||
};
|
|
@ -1,319 +0,0 @@
|
|||||||
#include "CEffect.h"
|
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/CProject.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/CImage.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Images/Materials/CPass.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector4.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantProperty.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine;
|
|
||||||
using namespace WallpaperEngine::Core::Objects;
|
|
||||||
using namespace WallpaperEngine::Core::UserSettings;
|
|
||||||
|
|
||||||
CEffect::CEffect (
|
|
||||||
std::string name, std::string description, std::string group, std::string preview,
|
|
||||||
std::shared_ptr <const Core::CProject> project, const CUserSettingBoolean* visible,
|
|
||||||
std::vector<std::string> dependencies, std::vector<const Effects::CFBO*> fbos,
|
|
||||||
std::vector<const Images::CMaterial*> materials
|
|
||||||
) :
|
|
||||||
m_name (std::move(name)),
|
|
||||||
m_description (std::move(description)),
|
|
||||||
m_group (std::move(group)),
|
|
||||||
m_preview (std::move(preview)),
|
|
||||||
m_visible (visible),
|
|
||||||
m_dependencies (std::move(dependencies)),
|
|
||||||
m_fbos (std::move(fbos)),
|
|
||||||
m_project (project),
|
|
||||||
m_materials (std::move(materials)) {}
|
|
||||||
|
|
||||||
const CEffect* CEffect::fromJSON (
|
|
||||||
const json& data, const CUserSettingBoolean* visible, std::shared_ptr <const Core::CProject> project,
|
|
||||||
const Images::CMaterial* material, const std::shared_ptr<const CContainer>& container
|
|
||||||
) {
|
|
||||||
const auto file = jsonFindRequired <std::string> (data, "file", "Object effect must have a file");
|
|
||||||
const auto effectpasses_it = data.find ("passes");
|
|
||||||
|
|
||||||
json content = json::parse (container->readFileAsString(file));
|
|
||||||
|
|
||||||
const auto effectName = jsonFindRequired <std::string> (content, "name", "Effect must have a name");
|
|
||||||
const auto passes_it = jsonFindRequired (content, "passes", "Effect must have a pass list");
|
|
||||||
const auto fbos_it = content.find ("fbos");
|
|
||||||
|
|
||||||
// info to override in the pass information, used by material generation
|
|
||||||
std::map<int, Images::CMaterial::OverrideInfo> overrides;
|
|
||||||
std::vector<const Effects::CFBO*> fbos;
|
|
||||||
|
|
||||||
if (fbos_it != content.end ())
|
|
||||||
fbos = CEffect::fbosFromJSON (fbos_it);
|
|
||||||
|
|
||||||
if (effectpasses_it != data.end ()) {
|
|
||||||
overrides = overridesFromJSON (effectpasses_it, material, project);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CEffect (
|
|
||||||
effectName,
|
|
||||||
jsonFindDefault<std::string> (content, "description", ""),
|
|
||||||
jsonFindRequired <std::string> (content, "group", "Effect must have a group"),
|
|
||||||
jsonFindDefault<std::string> (content, "preview", ""),
|
|
||||||
project,
|
|
||||||
visible,
|
|
||||||
dependenciesFromJSON (jsonFindRequired (content, "dependencies", "")),
|
|
||||||
fbos,
|
|
||||||
materialsFromJSON (passes_it, effectName, container, overrides)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::map<std::string, int> CEffect::combosFromJSON (const json::const_iterator& combos_it) {
|
|
||||||
std::map<std::string, int> combos;
|
|
||||||
|
|
||||||
for (const auto& cur : combos_it->items ()) {
|
|
||||||
auto uppercase = std::string (cur.key ());
|
|
||||||
|
|
||||||
std::transform (uppercase.begin (), uppercase.end (), uppercase.begin (), ::toupper);
|
|
||||||
combos.emplace (uppercase, cur.value ());
|
|
||||||
}
|
|
||||||
|
|
||||||
return combos;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> CEffect::constantsFromJSON (
|
|
||||||
const json::const_iterator& constants_it, std::shared_ptr <const Core::CProject> project
|
|
||||||
) {
|
|
||||||
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants;
|
|
||||||
|
|
||||||
for (auto& cur : constants_it->items ()) {
|
|
||||||
auto val = cur.value ();
|
|
||||||
|
|
||||||
Effects::Constants::CShaderConstant* constant = nullptr;
|
|
||||||
|
|
||||||
// if the constant is an object, that means the constant has some extra information
|
|
||||||
// for the UI, take the value, which is what we need
|
|
||||||
|
|
||||||
if (cur.value ().is_object ()) {
|
|
||||||
auto user = cur.value ().find ("user");
|
|
||||||
auto it = cur.value ().find ("value");
|
|
||||||
|
|
||||||
if (user == cur.value ().end () && it == cur.value ().end ()) {
|
|
||||||
sLog.error (R"(Found object for shader constant without "value" and "user" setting)");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user != cur.value ().end () && user->is_string ()) {
|
|
||||||
// look for a property with the correct name
|
|
||||||
const auto& properties = project->getProperties ();
|
|
||||||
const auto property = properties.find (*user);
|
|
||||||
|
|
||||||
if (property != properties.end ()) {
|
|
||||||
constant = new Effects::Constants::CShaderConstantProperty (property->second);
|
|
||||||
} else {
|
|
||||||
sLog.error ("Shader constant pointing to non-existant project property: ", user->get <std::string> ());
|
|
||||||
val = it.value ();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val = it.value ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: REFACTOR THIS SO IT'S NOT SO DEEP INTO THE FUNCTION
|
|
||||||
if (constant == nullptr) {
|
|
||||||
if (val.is_number_float ()) {
|
|
||||||
constant = new Effects::Constants::CShaderConstantFloat (val.get<float> ());
|
|
||||||
} else if (val.is_number_integer ()) {
|
|
||||||
constant = new Effects::Constants::CShaderConstantInteger (val.get<int> ());
|
|
||||||
} else if (val.is_string ()) {
|
|
||||||
// count the amount of spaces to determine which type of vector we have
|
|
||||||
std::string value = val;
|
|
||||||
|
|
||||||
size_t spaces =
|
|
||||||
std::count_if (value.begin (), value.end (), [&] (const auto& item) { return item == ' '; });
|
|
||||||
|
|
||||||
if (spaces == 1) {
|
|
||||||
constant =
|
|
||||||
new Effects::Constants::CShaderConstantVector2 (WallpaperEngine::Core::aToVector2 (value));
|
|
||||||
} else if (spaces == 2) {
|
|
||||||
constant =
|
|
||||||
new Effects::Constants::CShaderConstantVector3 (WallpaperEngine::Core::aToVector3 (value));
|
|
||||||
} else if (spaces == 3) {
|
|
||||||
constant =
|
|
||||||
new Effects::Constants::CShaderConstantVector4 (WallpaperEngine::Core::aToVector4 (value));
|
|
||||||
} else {
|
|
||||||
sLog.exception ("unknown shader constant type ", value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sLog.exception ("unknown shader constant type ", val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
constants.emplace (cur.key (), constant);
|
|
||||||
}
|
|
||||||
|
|
||||||
return constants;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<const Effects::CFBO*> CEffect::fbosFromJSON (const json::const_iterator& fbos_it) {
|
|
||||||
std::vector<const Effects::CFBO*> fbos;
|
|
||||||
|
|
||||||
for (const auto& cur : (*fbos_it))
|
|
||||||
fbos.push_back (Effects::CFBO::fromJSON (cur));
|
|
||||||
|
|
||||||
return fbos;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::string> CEffect::dependenciesFromJSON (const json::const_iterator& dependencies_it) {
|
|
||||||
std::vector<std::string> dependencies;
|
|
||||||
|
|
||||||
for (const auto& cur : (*dependencies_it))
|
|
||||||
dependencies.push_back (cur);
|
|
||||||
|
|
||||||
return dependencies;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<const Images::CMaterial*> CEffect::materialsFromJSON (
|
|
||||||
const json::const_iterator& passes_it, const std::string& name, const std::shared_ptr<const CContainer>& container,
|
|
||||||
std::map<int, Images::CMaterial::OverrideInfo> overrides
|
|
||||||
) {
|
|
||||||
std::vector<const Images::CMaterial*> materials;
|
|
||||||
|
|
||||||
int materialNumber = -1;
|
|
||||||
for (const auto& cur : (*passes_it)) {
|
|
||||||
++materialNumber;
|
|
||||||
const auto materialfile = cur.find ("material");
|
|
||||||
const auto target_it = cur.find ("target");
|
|
||||||
const auto bind_it = cur.find ("bind");
|
|
||||||
const auto command_it = cur.find ("command");
|
|
||||||
const auto compose_it = cur.find ("compose");
|
|
||||||
const Images::CMaterial* material = nullptr;
|
|
||||||
|
|
||||||
if (compose_it != cur.end ()) {
|
|
||||||
sLog.error ("Composing materials is not supported yet...");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (materialfile != cur.end ()) {
|
|
||||||
std::map<int, const Effects::CBind*> textureBindings;
|
|
||||||
|
|
||||||
if (bind_it != cur.end ()) {
|
|
||||||
for (const auto& bindCur : (*bind_it)) {
|
|
||||||
const auto* bind = Effects::CBind::fromJSON (bindCur);
|
|
||||||
textureBindings.emplace (bind->getIndex (), bind);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const Images::CMaterial::OverrideInfo* overrideInfo = nullptr;
|
|
||||||
const auto overrideIt = overrides.find (materialNumber);
|
|
||||||
|
|
||||||
if (overrideIt != overrides.end ()) {
|
|
||||||
overrideInfo = &overrideIt->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (target_it == cur.end ()) {
|
|
||||||
material = Images::CMaterial::fromFile (
|
|
||||||
materialfile->get<std::string> (), container, false, textureBindings, overrideInfo);
|
|
||||||
} else {
|
|
||||||
material = Images::CMaterial::fromFile (
|
|
||||||
materialfile->get<std::string> (), *target_it, container, false, textureBindings, overrideInfo);
|
|
||||||
}
|
|
||||||
} else if (command_it != cur.end ()) {
|
|
||||||
material = Images::CMaterial::fromCommand (cur);
|
|
||||||
} else {
|
|
||||||
sLog.exception ("Material without command nor material file: ", name, " (", materialNumber,")");
|
|
||||||
}
|
|
||||||
|
|
||||||
materials.push_back (material);
|
|
||||||
}
|
|
||||||
|
|
||||||
return materials;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::map<int, Images::CMaterial::OverrideInfo> CEffect::overridesFromJSON (
|
|
||||||
const json::const_iterator& passes_it, const Images::CMaterial* material,
|
|
||||||
std::shared_ptr <const Core::CProject> project
|
|
||||||
) {
|
|
||||||
std::map<int, Images::CMaterial::OverrideInfo> result;
|
|
||||||
|
|
||||||
int materialNumber = -1;
|
|
||||||
for (const auto& cur : (*passes_it)) {
|
|
||||||
++materialNumber;
|
|
||||||
auto constants_it = cur.find ("constantshadervalues");
|
|
||||||
auto combos_it = cur.find ("combos");
|
|
||||||
auto textures_it = cur.find ("textures");
|
|
||||||
Images::CMaterial::OverrideInfo override;
|
|
||||||
int textureNumber = -1;
|
|
||||||
|
|
||||||
if (combos_it != cur.end ()) {
|
|
||||||
override.combos = CEffect::combosFromJSON (combos_it);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (constants_it != cur.end ()) {
|
|
||||||
override.constants = CEffect::constantsFromJSON (constants_it, project);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (textures_it != cur.end ()) {
|
|
||||||
// TODO: MAYBE CHANGE THIS TO BE SOMEWHERE ELSE? THIS IS REALLY MODIFYING THE DATA
|
|
||||||
// BUT IT'S USEFUL TO HAVE TO SIMPLIFY RENDERING CODE
|
|
||||||
for (const auto& texture : (*textures_it)) {
|
|
||||||
++textureNumber;
|
|
||||||
std::string name;
|
|
||||||
|
|
||||||
if (texture.is_null () && textureNumber > 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (textureNumber == 0) {
|
|
||||||
auto passTextures = (*material->getPasses ().begin ())->getTextures ();
|
|
||||||
|
|
||||||
if (passTextures.empty()) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
name = passTextures.begin ()->second;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
name = texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
override.textures.emplace (textureNumber, name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result.emplace (materialNumber, override);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<std::string>& CEffect::getDependencies () const {
|
|
||||||
return this->m_dependencies;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<const Images::CMaterial*>& CEffect::getMaterials () const {
|
|
||||||
return this->m_materials;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<const Effects::CFBO*>& CEffect::getFbos () const {
|
|
||||||
return this->m_fbos;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Core::CProject& CEffect::getProject () const {
|
|
||||||
return *this->m_project;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CEffect::isVisible () const {
|
|
||||||
return this->m_visible->getBool ();
|
|
||||||
}
|
|
||||||
|
|
||||||
const Effects::CFBO* CEffect::findFBO (const std::string& name) {
|
|
||||||
for (const auto& cur : this->m_fbos)
|
|
||||||
if (cur->getName () == name)
|
|
||||||
return cur;
|
|
||||||
|
|
||||||
sLog.exception ("cannot find fbo ", name);
|
|
||||||
}
|
|
@ -1,102 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Assets/CContainer.h"
|
|
||||||
#include "WallpaperEngine/Core/CObject.h"
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Effects/CFBO.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Images/CMaterial.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core {
|
|
||||||
class CObject;
|
|
||||||
class CProject;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::UserSettings {
|
|
||||||
class CUserSettingBoolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
using namespace WallpaperEngine::Assets;
|
|
||||||
using namespace WallpaperEngine::Core::UserSettings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents an effect applied to background objects
|
|
||||||
*/
|
|
||||||
class CEffect {
|
|
||||||
public:
|
|
||||||
CEffect (
|
|
||||||
std::string name, std::string description, std::string group, std::string preview,
|
|
||||||
std::shared_ptr <const Core::CProject>, const CUserSettingBoolean* visible,
|
|
||||||
std::vector<std::string> dependencies, std::vector<const Effects::CFBO*> fbos,
|
|
||||||
std::vector<const Images::CMaterial*> materials);
|
|
||||||
|
|
||||||
static const CEffect* fromJSON (
|
|
||||||
const json& data, const CUserSettingBoolean* visible, std::shared_ptr <const Core::CProject> project,
|
|
||||||
const Images::CMaterial* material, const std::shared_ptr<const CContainer>& container);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return List of dependencies for the effect to work
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::vector<std::string>& getDependencies () const;
|
|
||||||
/**
|
|
||||||
* @return List of materials the effect applies
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::vector<const Images::CMaterial*>& getMaterials () const;
|
|
||||||
/**
|
|
||||||
* @return The list of FBOs to be used for this effect
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::vector<const Effects::CFBO*>& getFbos () const;
|
|
||||||
/**
|
|
||||||
* @return If the effect is visible or not
|
|
||||||
*/
|
|
||||||
[[nodiscard]] bool isVisible () const;
|
|
||||||
/**
|
|
||||||
* @return The project this effect is part of
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const CProject& getProject () const;
|
|
||||||
/**
|
|
||||||
* Searches the FBOs list for the given FBO
|
|
||||||
*
|
|
||||||
* @param name The FBO to search for
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
const Effects::CFBO* findFBO (const std::string& name);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
static std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constantsFromJSON (
|
|
||||||
const json::const_iterator& constants_it, std::shared_ptr <const Core::CProject> project);
|
|
||||||
static std::map<std::string, int> combosFromJSON (const json::const_iterator& combos_it);
|
|
||||||
static std::vector<const Effects::CFBO*> fbosFromJSON (const json::const_iterator& fbos_it);
|
|
||||||
static std::vector<std::string> dependenciesFromJSON (const json::const_iterator& dependencies_it);
|
|
||||||
static std::vector<const Images::CMaterial*> materialsFromJSON (
|
|
||||||
const json::const_iterator& passes_it, const std::string& name,
|
|
||||||
const std::shared_ptr<const CContainer>& container, std::map<int, Images::CMaterial::OverrideInfo>);
|
|
||||||
static std::map<int, Images::CMaterial::OverrideInfo> overridesFromJSON (
|
|
||||||
const json::const_iterator& passes_it, const Images::CMaterial* material,
|
|
||||||
std::shared_ptr <const Core::CProject> project);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** Effect's name */
|
|
||||||
const std::string m_name;
|
|
||||||
/** Effect's description used in the UI */
|
|
||||||
const std::string m_description;
|
|
||||||
/** Effect's group used in the UI */
|
|
||||||
const std::string m_group;
|
|
||||||
/** A project that previews the given effect, used in the UI */
|
|
||||||
const std::string m_preview;
|
|
||||||
/** If the effect is visible or not */
|
|
||||||
const UserSettings::CUserSettingBoolean* m_visible;
|
|
||||||
/** Project this effect is part of */
|
|
||||||
std::shared_ptr <const Core::CProject> m_project;
|
|
||||||
|
|
||||||
/** List of dependencies for the effect */
|
|
||||||
const std::vector<std::string> m_dependencies;
|
|
||||||
/** List of materials the effect applies */
|
|
||||||
const std::vector<const Images::CMaterial*> m_materials;
|
|
||||||
/** List of FBOs required for this effect */
|
|
||||||
const std::vector<const Effects::CFBO*> m_fbos;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects
|
|
@ -1,142 +0,0 @@
|
|||||||
#include "CImage.h"
|
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Objects/Images/CMaterial.h"
|
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
|
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h"
|
|
||||||
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects;
|
|
||||||
using namespace WallpaperEngine::Core::UserSettings;
|
|
||||||
|
|
||||||
CImage::CImage (
|
|
||||||
std::shared_ptr <const Core::CProject> project, const Images::CMaterial* material,
|
|
||||||
const CUserSettingBoolean* visible, int id, std::string name, const CUserSettingVector3* origin,
|
|
||||||
const CUserSettingVector3* scale, const CUserSettingVector3* angles, glm::vec2 size, std::string alignment,
|
|
||||||
const CUserSettingVector3* color, const CUserSettingFloat* alpha, float brightness, uint32_t colorBlendMode,
|
|
||||||
glm::vec2 parallaxDepth, bool fullscreen, bool passthrough, bool autosize,
|
|
||||||
std::vector<const Objects::CEffect*> effects, std::vector<int> dependencies
|
|
||||||
) :
|
|
||||||
CObject (project, visible, id, std::move(name), origin, scale, angles, std::move(dependencies)),
|
|
||||||
m_size (size),
|
|
||||||
m_parallaxDepth (parallaxDepth),
|
|
||||||
m_material (material),
|
|
||||||
m_alignment (std::move(alignment)),
|
|
||||||
m_alpha (alpha),
|
|
||||||
m_brightness (brightness),
|
|
||||||
m_color (color),
|
|
||||||
m_colorBlendMode (colorBlendMode),
|
|
||||||
m_fullscreen (fullscreen),
|
|
||||||
m_passthrough (passthrough),
|
|
||||||
m_autosize (autosize),
|
|
||||||
m_effects (std::move(effects)) {}
|
|
||||||
|
|
||||||
const WallpaperEngine::Core::CObject* CImage::fromJSON (
|
|
||||||
std::shared_ptr <const Core::CProject> project, const json& data, const std::shared_ptr<const CContainer>& container,
|
|
||||||
const CUserSettingBoolean* visible, int id, std::string name, const CUserSettingVector3* origin,
|
|
||||||
const CUserSettingVector3* scale, const CUserSettingVector3* angles, const json::const_iterator& effects_it,
|
|
||||||
std::vector<int> dependencies
|
|
||||||
) {
|
|
||||||
const auto image = jsonFindRequired <std::string>(data, "image", "Image must have an image");
|
|
||||||
std::vector<const Objects::CEffect*> effects;
|
|
||||||
json content = json::parse (container->readFileAsString (image));
|
|
||||||
|
|
||||||
const auto material = Images::CMaterial::fromFile (
|
|
||||||
jsonFindRequired<std::string> (content, "material", "Image must have a material"),
|
|
||||||
container,
|
|
||||||
jsonFindDefault (content, "solidlayer", false)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (effects_it != data.end () && effects_it->is_array ()) {
|
|
||||||
for (auto& cur : *effects_it) {
|
|
||||||
const auto effectVisible = jsonFindUserConfig<CUserSettingBoolean> (cur, *project, "visible", true);
|
|
||||||
|
|
||||||
// TODO: USER CANNOT MODIFY VALUES ON THE FLY, BUT IT MIGHT BE INTERESTING TO SUPPORT THAT AT SOME POINT?
|
|
||||||
// TODO: AT LEAST THE ORIGINAL SOFTWARE ALLOWS YOU TO DO THAT IN THE PREVIEW WINDOW
|
|
||||||
// TODO: THAT MIGHT INCREASE COMPLEXITY THO...
|
|
||||||
// TODO: ESPECIALLY IF THAT CHANGES RENDERING OF PASSES/IMAGES
|
|
||||||
// TODO: DECISIONS, DECISIONS, DECISIONS...
|
|
||||||
if (!effectVisible->getBool ())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
effects.push_back (
|
|
||||||
Objects::CEffect::fromJSON (
|
|
||||||
cur, effectVisible, project, material, container
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CImage (
|
|
||||||
project,
|
|
||||||
material,
|
|
||||||
visible,
|
|
||||||
id,
|
|
||||||
std::move(name),
|
|
||||||
origin,
|
|
||||||
scale,
|
|
||||||
angles,
|
|
||||||
jsonFindDefault<glm::vec2> (data, "size", glm::vec2 (0.0, 0.0)),
|
|
||||||
jsonFindDefault<std::string> (data, "alignment", "center"),
|
|
||||||
jsonFindUserConfig<CUserSettingVector3> (data, *project, "color", {1, 1, 1}),
|
|
||||||
jsonFindUserConfig<CUserSettingFloat> (data, *project, "alpha", 1.0),
|
|
||||||
jsonFindDefault<float> (data, "brightness", 1.0),
|
|
||||||
jsonFindDefault<uint32_t> (data, "colorBlendMode", 0),
|
|
||||||
jsonFindDefault<glm::vec2> (data, "parallaxDepth", glm::vec2 (0.0, 0.0)),
|
|
||||||
jsonFindDefault<bool> (content, "fullscreen", false),
|
|
||||||
jsonFindDefault<bool> (content, "passthrough", false),
|
|
||||||
jsonFindDefault<bool> (content, "autosize", false),
|
|
||||||
effects,
|
|
||||||
std::move(dependencies)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const Images::CMaterial* CImage::getMaterial () const {
|
|
||||||
return this->m_material;
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::vec2& CImage::getSize () const {
|
|
||||||
return this->m_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& CImage::getAlignment () const {
|
|
||||||
return this->m_alignment;
|
|
||||||
}
|
|
||||||
|
|
||||||
float CImage::getAlpha () const {
|
|
||||||
return this->m_alpha->getFloat ();
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::vec3& CImage::getColor () const {
|
|
||||||
return this->m_color->getVec3 ();
|
|
||||||
}
|
|
||||||
|
|
||||||
float CImage::getBrightness () const {
|
|
||||||
return this->m_brightness;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t CImage::getColorBlendMode () const {
|
|
||||||
return this->m_colorBlendMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::vec2& CImage::getParallaxDepth () const {
|
|
||||||
return this->m_parallaxDepth;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CImage::isFullscreen () const {
|
|
||||||
return this->m_fullscreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CImage::isPassthrough () const {
|
|
||||||
return this->m_passthrough;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CImage::isAutosize () const {
|
|
||||||
return this->m_autosize;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<const CEffect*>& CImage::getEffects () const {
|
|
||||||
return this->m_effects;
|
|
||||||
}
|
|
@ -1,122 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Objects/Images/CMaterial.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/CObject.h"
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Assets/CContainer.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
|
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Wallpapers {
|
|
||||||
class CScene;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
using namespace WallpaperEngine::Assets;
|
|
||||||
using namespace WallpaperEngine::Core::UserSettings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents an image in a background
|
|
||||||
*/
|
|
||||||
class CImage : public CObject {
|
|
||||||
friend class CObject;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static const CObject* fromJSON (
|
|
||||||
std::shared_ptr <const Core::CProject> project, const json& data,
|
|
||||||
const std::shared_ptr<const CContainer>& container, const CUserSettingBoolean* visible, int id,
|
|
||||||
std::string name, const CUserSettingVector3* origin, const CUserSettingVector3* scale,
|
|
||||||
const CUserSettingVector3* angles, const json::const_iterator& effects_it, std::vector<int> dependencies);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The base material to use for the image
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const Images::CMaterial* getMaterial () const;
|
|
||||||
/**
|
|
||||||
* @return The size of the image
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const glm::vec2& getSize () const;
|
|
||||||
/**
|
|
||||||
* @return The type of alignment to use for image positioning
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::string& getAlignment () const;
|
|
||||||
/**
|
|
||||||
* @return The alpha value for the image's rendering
|
|
||||||
*/
|
|
||||||
[[nodiscard]] float getAlpha () const;
|
|
||||||
/**
|
|
||||||
* @return The color to use for the image
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const glm::vec3& getColor () const;
|
|
||||||
/**
|
|
||||||
* @return The brightness to use for the image
|
|
||||||
*/
|
|
||||||
[[nodiscard]] float getBrightness () const;
|
|
||||||
/**
|
|
||||||
* @return The color blending mode to be used, special value for shaders
|
|
||||||
*/
|
|
||||||
[[nodiscard]] uint32_t getColorBlendMode () const;
|
|
||||||
/**
|
|
||||||
* @return Parallax depth of the image
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const glm::vec2& getParallaxDepth () const;
|
|
||||||
/**
|
|
||||||
* @return If the image is fullscreen or not
|
|
||||||
*/
|
|
||||||
[[nodiscard]] bool isFullscreen () const;
|
|
||||||
/**
|
|
||||||
* @return If the image is passthrough or not
|
|
||||||
*/
|
|
||||||
[[nodiscard]] bool isPassthrough () const;
|
|
||||||
/**
|
|
||||||
* @return If the image is autosized or not
|
|
||||||
*/
|
|
||||||
[[nodiscard]] bool isAutosize () const;
|
|
||||||
/**
|
|
||||||
* @return All of the effects applied to this image
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::vector<const Objects::CEffect*>& getEffects () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
CImage (
|
|
||||||
std::shared_ptr <const Core::CProject> project, const Images::CMaterial* material,
|
|
||||||
const CUserSettingBoolean* visible, int id, std::string name, const CUserSettingVector3* origin,
|
|
||||||
const CUserSettingVector3* scale, const CUserSettingVector3* angles, glm::vec2 size, std::string alignment,
|
|
||||||
const CUserSettingVector3* color, const CUserSettingFloat* alpha, float brightness, uint32_t colorBlendMode,
|
|
||||||
glm::vec2 parallaxDepth, bool fullscreen, bool passthrough, bool autosize,
|
|
||||||
std::vector<const Objects::CEffect*> effects, std::vector<int> dependencies);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** The image's size */
|
|
||||||
const glm::vec2 m_size;
|
|
||||||
/** Parallax depth */
|
|
||||||
const glm::vec2 m_parallaxDepth;
|
|
||||||
/** Base material for the image */
|
|
||||||
const Images::CMaterial* m_material;
|
|
||||||
/** What type of alignment to use for the image's position */
|
|
||||||
const std::string m_alignment;
|
|
||||||
/** The alpha value for the image */
|
|
||||||
const CUserSettingFloat* m_alpha;
|
|
||||||
/** The brightness for the image */
|
|
||||||
float m_brightness;
|
|
||||||
/** The color to use for the image */
|
|
||||||
const CUserSettingVector3* m_color;
|
|
||||||
/** The color blending mode used for the image, special value for shaders */
|
|
||||||
const uint32_t m_colorBlendMode;
|
|
||||||
/** Override for effects */
|
|
||||||
const std::vector<const Objects::CEffect*> m_effects;
|
|
||||||
/** If the image is fullscreen or not */
|
|
||||||
bool m_fullscreen = false;
|
|
||||||
/** If the image is passthrough or not */
|
|
||||||
bool m_passthrough = false;
|
|
||||||
/** If the image's size should be automatically determined */
|
|
||||||
bool m_autosize = false;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects
|
|
@ -1,73 +0,0 @@
|
|||||||
#include "CParticle.h"
|
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects;
|
|
||||||
|
|
||||||
const CParticle* CParticle::fromFile (
|
|
||||||
std::shared_ptr <const Core::CProject> project, const std::string& filename,
|
|
||||||
const std::shared_ptr<const CContainer>& container, const CUserSettingBoolean* visible, int id,
|
|
||||||
const std::string& name, const CUserSettingVector3* origin, const CUserSettingVector3* angles,
|
|
||||||
const CUserSettingVector3* scale, std::vector<int> dependencies
|
|
||||||
) {
|
|
||||||
json data = json::parse (container->readFileAsString (filename));
|
|
||||||
const auto controlpoint_it = data.find ("controlpoint");
|
|
||||||
const auto emitter_it = jsonFindRequired (data, "emitter", "Particles must have emitters");
|
|
||||||
const auto initializer_it = jsonFindRequired (data, "initializer", "Particles must have initializers");
|
|
||||||
|
|
||||||
std::vector<const Particles::CControlPoint*> controlpoints;
|
|
||||||
std::vector<const Particles::CEmitter*> emitters;
|
|
||||||
std::vector<const Particles::CInitializer*> initializers;
|
|
||||||
|
|
||||||
if (controlpoint_it != data.end ())
|
|
||||||
for (const auto& cur : (*controlpoint_it))
|
|
||||||
controlpoints.push_back (Particles::CControlPoint::fromJSON (cur));
|
|
||||||
|
|
||||||
for (const auto& cur : (*emitter_it))
|
|
||||||
emitters.push_back (Particles::CEmitter::fromJSON (cur));
|
|
||||||
for (const auto& cur : (*initializer_it))
|
|
||||||
initializers.push_back (Particles::CInitializer::fromJSON (cur));
|
|
||||||
|
|
||||||
return new CParticle (
|
|
||||||
project,
|
|
||||||
jsonFindRequired <uint32_t> (data, "starttime", "Particles must have start time"),
|
|
||||||
jsonFindRequired <uint32_t> (data, "maxcount", "Particles must have maximum count"),
|
|
||||||
visible,
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
origin,
|
|
||||||
scale,
|
|
||||||
angles,
|
|
||||||
controlpoints,
|
|
||||||
emitters,
|
|
||||||
initializers,
|
|
||||||
std::move(dependencies)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
CParticle::CParticle (
|
|
||||||
std::shared_ptr <const Core::CProject> project, uint32_t starttime, uint32_t maxcount,
|
|
||||||
const CUserSettingBoolean* visible, int id, const std::string& name, const CUserSettingVector3* origin,
|
|
||||||
const CUserSettingVector3* scale, const CUserSettingVector3* angles,
|
|
||||||
const std::vector<const Particles::CControlPoint*>& controlpoints,
|
|
||||||
const std::vector<const Particles::CEmitter*>& emitters,
|
|
||||||
const std::vector<const Particles::CInitializer*>& initializers, std::vector<int> dependencies
|
|
||||||
) :
|
|
||||||
CObject (project, visible, id, name, origin, scale, angles, std::move(dependencies)),
|
|
||||||
m_starttime (starttime),
|
|
||||||
m_maxcount (maxcount),
|
|
||||||
m_controlpoints (controlpoints),
|
|
||||||
m_emitters (emitters),
|
|
||||||
m_initializers (initializers) {}
|
|
||||||
|
|
||||||
const std::vector<const Particles::CEmitter*>& CParticle::getEmitters () const {
|
|
||||||
return this->m_emitters;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<const Particles::CControlPoint*>& CParticle::getControlPoints () const {
|
|
||||||
return this->m_controlpoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<const Particles::CInitializer*>& CParticle::getInitializers () const {
|
|
||||||
return this->m_initializers;
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Objects/Particles/CControlPoint.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Particles/CEmitter.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Particles/CInitializer.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/CObject.h"
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a particle system in the background
|
|
||||||
*/
|
|
||||||
class CParticle : public CObject {
|
|
||||||
friend class CObject;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static const CParticle* fromFile (
|
|
||||||
std::shared_ptr <const Core::CProject> project, const std::string& filename,
|
|
||||||
const std::shared_ptr<const CContainer>& container, const CUserSettingBoolean* visible, int id,
|
|
||||||
const std::string& name, const CUserSettingVector3* origin, const CUserSettingVector3* angles,
|
|
||||||
const CUserSettingVector3* scale, std::vector<int> dependencies);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The list of emitters for the particle system
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::vector<const Particles::CEmitter*>& getEmitters () const;
|
|
||||||
/**
|
|
||||||
* @return The list of control points for the particle system
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::vector<const Particles::CControlPoint*>& getControlPoints () const;
|
|
||||||
/**
|
|
||||||
* @return The list of initializers for the particle system
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::vector<const Particles::CInitializer*>& getInitializers () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
CParticle (
|
|
||||||
std::shared_ptr <const Core::CProject> project, uint32_t starttime, uint32_t maxcount,
|
|
||||||
const CUserSettingBoolean* visible, int id, const std::string& name, const CUserSettingVector3* origin,
|
|
||||||
const CUserSettingVector3* scale, const CUserSettingVector3* angles,
|
|
||||||
const std::vector<const Particles::CControlPoint*>& controlpoints,
|
|
||||||
const std::vector<const Particles::CEmitter*>& emitters,
|
|
||||||
const std::vector<const Particles::CInitializer*>& initializers, std::vector<int> dependencies);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** The time at which the particle system should start emitting */
|
|
||||||
const uint32_t m_starttime;
|
|
||||||
/** Maximum number of particles at the same time */
|
|
||||||
const uint32_t m_maxcount;
|
|
||||||
/** List of control points */
|
|
||||||
const std::vector<const Particles::CControlPoint*> m_controlpoints;
|
|
||||||
/** List of emitters */
|
|
||||||
const std::vector<const Particles::CEmitter*> m_emitters;
|
|
||||||
/** List of initializers */
|
|
||||||
const std::vector<const Particles::CInitializer*> m_initializers;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects
|
|
@ -1,53 +0,0 @@
|
|||||||
#include "CSound.h"
|
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
#include "WallpaperEngine/Core/CObject.h"
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects;
|
|
||||||
|
|
||||||
CSound::CSound (
|
|
||||||
std::shared_ptr <const Core::CProject> project, const CUserSettingBoolean* visible, int id, std::string name,
|
|
||||||
const CUserSettingVector3* origin, const CUserSettingVector3* scale, const CUserSettingVector3* angles,
|
|
||||||
bool repeat, std::vector<std::string> sounds, std::vector<int> dependencies
|
|
||||||
) :
|
|
||||||
CObject (project, visible, id, std::move(name), origin, scale, angles, std::move(dependencies)),
|
|
||||||
m_repeat (repeat),
|
|
||||||
m_sounds (std::move(sounds)) {}
|
|
||||||
|
|
||||||
const WallpaperEngine::Core::CObject* CSound::fromJSON (
|
|
||||||
std::shared_ptr <const Core::CProject> project, const json& data, const CUserSettingBoolean* visible,
|
|
||||||
int id, const std::string& name, const CUserSettingVector3* origin, const CUserSettingVector3* scale,
|
|
||||||
const CUserSettingVector3* angles, std::vector<int> dependencies
|
|
||||||
) {
|
|
||||||
// TODO: PARSE AUDIO VOLUME
|
|
||||||
std::vector<std::string> sounds;
|
|
||||||
const auto sound_it = jsonFindRequired (data, "sound", "Sound information not present");
|
|
||||||
|
|
||||||
if (!sound_it->is_array ())
|
|
||||||
sLog.exception ("Expected sound list on element ", name);
|
|
||||||
|
|
||||||
for (const auto& cur : (*sound_it))
|
|
||||||
sounds.push_back (cur);
|
|
||||||
|
|
||||||
return new CSound (
|
|
||||||
project,
|
|
||||||
visible,
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
origin,
|
|
||||||
scale,
|
|
||||||
angles,
|
|
||||||
jsonFindDefault<std::string> (data, "playbackmode", "") == "loop",
|
|
||||||
sounds,
|
|
||||||
std::move(dependencies)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<std::string>& CSound::getSounds () const {
|
|
||||||
return this->m_sounds;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CSound::isRepeat () const {
|
|
||||||
return this->m_repeat;
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/CObject.h"
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Wallpapers {
|
|
||||||
class CScene;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
using namespace WallpaperEngine::Core::UserSettings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a sound played while the background is working
|
|
||||||
*/
|
|
||||||
class CSound : public CObject {
|
|
||||||
friend class CObject;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static const CObject* fromJSON (
|
|
||||||
std::shared_ptr <const Core::CProject> project, const json& data, const CUserSettingBoolean* visible,
|
|
||||||
int id, const std::string& name, const CUserSettingVector3* origin, const CUserSettingVector3* scale,
|
|
||||||
const CUserSettingVector3* angles, std::vector<int> dependencies);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The list of sounds to play
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::vector<std::string>& getSounds () const;
|
|
||||||
/**
|
|
||||||
* @return If the sound should repeat or not
|
|
||||||
*/
|
|
||||||
[[nodiscard]] bool isRepeat () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
CSound (
|
|
||||||
std::shared_ptr <const Core::CProject> project, const CUserSettingBoolean* visible, int id, std::string name,
|
|
||||||
const CUserSettingVector3* origin, const CUserSettingVector3* scale, const CUserSettingVector3* angles,
|
|
||||||
bool repeat, std::vector<std::string> sounds, std::vector<int> dependencies);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** If the sounds should repeat or not */
|
|
||||||
bool m_repeat = false;
|
|
||||||
/** The list of sounds to play */
|
|
||||||
std::vector<std::string> m_sounds = {};
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects
|
|
@ -1,24 +0,0 @@
|
|||||||
#include "CBind.h"
|
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Effects;
|
|
||||||
|
|
||||||
CBind::CBind (std::string name, uint32_t index) :
|
|
||||||
m_name (std::move(name)),
|
|
||||||
m_index (index) {}
|
|
||||||
|
|
||||||
const CBind* CBind::fromJSON (const json& data) {
|
|
||||||
return new CBind (
|
|
||||||
jsonFindRequired <std::string> (data, "name", "bind must have texture name"),
|
|
||||||
jsonFindRequired <uint32_t> (data, "index", "bind must have index")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& CBind::getName () const {
|
|
||||||
return this->m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint32_t& CBind::getIndex () const {
|
|
||||||
return this->m_index;
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Effects {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Material's bind information, describes for passes what textures to bind
|
|
||||||
* in what positions for shaders. Used to override the textures specified inside
|
|
||||||
* the object's passes
|
|
||||||
*/
|
|
||||||
class CBind {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Parses bind information off the given json data
|
|
||||||
*
|
|
||||||
* @param data
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
static const CBind* fromJSON (const json& data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The texture name, previous to use the one already specified by the object's passes
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::string& getName () const;
|
|
||||||
/**
|
|
||||||
* @return The texture index to replace
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const uint32_t& getIndex () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
CBind (std::string name, uint32_t index);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** The texture's name */
|
|
||||||
const std::string m_name;
|
|
||||||
/** The texture index to replace */
|
|
||||||
const uint32_t m_index;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Effects
|
|
@ -1,31 +0,0 @@
|
|||||||
#include "CFBO.h"
|
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core;
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Effects;
|
|
||||||
|
|
||||||
CFBO::CFBO (std::string name, float scale, std::string format) :
|
|
||||||
m_name (std::move(name)),
|
|
||||||
m_scale (scale),
|
|
||||||
m_format (std::move(format)) {}
|
|
||||||
|
|
||||||
const CFBO* CFBO::fromJSON (const json& data) {
|
|
||||||
return new CFBO (
|
|
||||||
jsonFindRequired <std::string> (data, "name", "Name for an FBO is required"),
|
|
||||||
jsonFindDefault <float> (data, "scale", 1.0),
|
|
||||||
jsonFindDefault <std::string> (data, "format", "")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& CFBO::getName () const {
|
|
||||||
return this->m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
const float& CFBO::getScale () const {
|
|
||||||
return this->m_scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& CFBO::getFormat () const {
|
|
||||||
return this->m_format;
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Effects {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* FBO = Frame Buffer Object
|
|
||||||
*
|
|
||||||
* Represents a framebuffer object used in objects with multiple effects or render passes
|
|
||||||
*/
|
|
||||||
class CFBO {
|
|
||||||
public:
|
|
||||||
static const CFBO* fromJSON (const json& data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The FBO name used to identify it in the background's files
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::string& getName () const;
|
|
||||||
/**
|
|
||||||
* @return The scale factor of the FBO
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const float& getScale () const;
|
|
||||||
/**
|
|
||||||
* @return The FBO's format for the render
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::string& getFormat () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
CFBO (std::string name, float scale, std::string format);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** The name of the FBO */
|
|
||||||
const std::string m_name;
|
|
||||||
/** The scale factor of the FBO */
|
|
||||||
const float m_scale;
|
|
||||||
/** The FBO's format for the render */
|
|
||||||
const std::string m_format;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Effects
|
|
@ -1,5 +0,0 @@
|
|||||||
#include "CShaderConstant.h"
|
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
|
|
@ -1,40 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <string>
|
|
||||||
#include "WallpaperEngine/Core/DynamicValues/CDynamicValue.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Effects::Constants {
|
|
||||||
/**
|
|
||||||
* Shader constants base class
|
|
||||||
*/
|
|
||||||
class CShaderConstant : public DynamicValues::CDynamicValue {
|
|
||||||
public:
|
|
||||||
virtual ~CShaderConstant () = default;
|
|
||||||
|
|
||||||
template <class T> [[nodiscard]] const T* as () const {
|
|
||||||
if (is <T> ()) {
|
|
||||||
return static_cast <const T*> (this);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw std::bad_cast ();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T> [[nodiscard]] T* as () {
|
|
||||||
if (is <T> ()) {
|
|
||||||
return static_cast <T*> (this);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw std::bad_cast ();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T> [[nodiscard]] bool is () const {
|
|
||||||
return typeid (*this) == typeid(T);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return String representation of the constant's value
|
|
||||||
*/
|
|
||||||
[[nodiscard]] virtual std::string toString () const = 0;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Effects::Constants
|
|
@ -1,11 +0,0 @@
|
|||||||
#include "CShaderConstantFloat.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
|
|
||||||
|
|
||||||
CShaderConstantFloat::CShaderConstantFloat (float value) {
|
|
||||||
this->update (value);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CShaderConstantFloat::toString () const {
|
|
||||||
return std::to_string (this->getFloat ());
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CShaderConstant.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Effects::Constants {
|
|
||||||
/**
|
|
||||||
* Shader constant of type float
|
|
||||||
*/
|
|
||||||
class CShaderConstantFloat : public CShaderConstant {
|
|
||||||
public:
|
|
||||||
explicit CShaderConstantFloat (float value);
|
|
||||||
|
|
||||||
[[nodiscard]] std::string toString () const override;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Effects::Constants
|
|
@ -1,11 +0,0 @@
|
|||||||
#include "CShaderConstantInteger.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
|
|
||||||
|
|
||||||
CShaderConstantInteger::CShaderConstantInteger (int32_t value) {
|
|
||||||
this->update (value);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CShaderConstantInteger::toString () const {
|
|
||||||
return std::to_string (this->getInt ());
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CShaderConstant.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Effects::Constants {
|
|
||||||
/**
|
|
||||||
* Shader constant of type integer
|
|
||||||
*/
|
|
||||||
class CShaderConstantInteger : public CShaderConstant {
|
|
||||||
public:
|
|
||||||
explicit CShaderConstantInteger (int32_t value);
|
|
||||||
|
|
||||||
[[nodiscard]] std::string toString () const override;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Effects::Constants
|
|
@ -1,12 +0,0 @@
|
|||||||
#include "WallpaperEngine/Core/DynamicValues/CDynamicValue.h"
|
|
||||||
#include "CShaderConstantProperty.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
|
|
||||||
|
|
||||||
CShaderConstantProperty::CShaderConstantProperty (const std::shared_ptr <const CProperty>& property) {
|
|
||||||
property->connectOutgoing (this);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CShaderConstantProperty::toString () const {
|
|
||||||
return "no string representation yet!";
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Projects/CProperty.h"
|
|
||||||
|
|
||||||
#include "CShaderConstant.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Effects::Constants {
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
|
||||||
/**
|
|
||||||
* Shader constant that comes from a property
|
|
||||||
*/
|
|
||||||
class CShaderConstantProperty : public CShaderConstant {
|
|
||||||
public:
|
|
||||||
explicit CShaderConstantProperty (const std::shared_ptr <const CProperty>& property);
|
|
||||||
|
|
||||||
[[nodiscard]] std::string toString () const override;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Effects::Constants
|
|
@ -1,18 +0,0 @@
|
|||||||
#include "CShaderConstantVector2.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
|
|
||||||
|
|
||||||
CShaderConstantVector2::CShaderConstantVector2 (glm::vec2 value) {
|
|
||||||
this->update (value);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CShaderConstantVector2::toString () const {
|
|
||||||
std::string result = "(";
|
|
||||||
|
|
||||||
result.append (std::to_string (this->getVec2 ().x));
|
|
||||||
result.append (",");
|
|
||||||
result.append (std::to_string (this->getVec2 ().y));
|
|
||||||
result.append (")");
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CShaderConstant.h"
|
|
||||||
|
|
||||||
#include <glm/vec2.hpp>
|
|
||||||
#include <glm/vec3.hpp>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Effects::Constants {
|
|
||||||
/**
|
|
||||||
* Shader constant of vector2 type
|
|
||||||
*/
|
|
||||||
class CShaderConstantVector2 : public CShaderConstant {
|
|
||||||
public:
|
|
||||||
explicit CShaderConstantVector2 (glm::vec2 value);
|
|
||||||
|
|
||||||
[[nodiscard]] std::string toString () const override;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Effects::Constants
|
|
@ -1,20 +0,0 @@
|
|||||||
#include "CShaderConstantVector3.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
|
|
||||||
|
|
||||||
CShaderConstantVector3::CShaderConstantVector3 (glm::vec3 value) {
|
|
||||||
this->update (value);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CShaderConstantVector3::toString () const {
|
|
||||||
std::string result = "(";
|
|
||||||
|
|
||||||
result.append (std::to_string (this->getVec3 ().x));
|
|
||||||
result.append (",");
|
|
||||||
result.append (std::to_string (this->getVec3 ().y));
|
|
||||||
result.append (",");
|
|
||||||
result.append (std::to_string (this->getVec3 ().z));
|
|
||||||
result.append (")");
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CShaderConstant.h"
|
|
||||||
|
|
||||||
#include <glm/vec3.hpp>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Effects::Constants {
|
|
||||||
/**
|
|
||||||
* Shader constant of vector3 type
|
|
||||||
*/
|
|
||||||
class CShaderConstantVector3 : public CShaderConstant {
|
|
||||||
public:
|
|
||||||
explicit CShaderConstantVector3 (glm::vec3 value);
|
|
||||||
|
|
||||||
[[nodiscard]] std::string toString () const override;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Effects::Constants
|
|
@ -1,22 +0,0 @@
|
|||||||
#include "CShaderConstantVector4.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
|
|
||||||
|
|
||||||
CShaderConstantVector4::CShaderConstantVector4 (glm::vec4 value) {
|
|
||||||
this->update (value);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CShaderConstantVector4::toString () const {
|
|
||||||
std::string result = "(";
|
|
||||||
|
|
||||||
result.append (std::to_string (this->getVec4 ().x));
|
|
||||||
result.append (",");
|
|
||||||
result.append (std::to_string (this->getVec4 ().y));
|
|
||||||
result.append (",");
|
|
||||||
result.append (std::to_string (this->getVec4 ().z));
|
|
||||||
result.append (",");
|
|
||||||
result.append (std::to_string (this->getVec4 ().w));
|
|
||||||
result.append (")");
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CShaderConstant.h"
|
|
||||||
|
|
||||||
#include <glm/vec4.hpp>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Effects::Constants {
|
|
||||||
/**
|
|
||||||
* Shader constant of vector4 type
|
|
||||||
*/
|
|
||||||
class CShaderConstantVector4 : public CShaderConstant {
|
|
||||||
public:
|
|
||||||
explicit CShaderConstantVector4 (glm::vec4 value);
|
|
||||||
|
|
||||||
[[nodiscard]] std::string toString () const override;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Effects::Constants
|
|
@ -1,120 +0,0 @@
|
|||||||
#include "CMaterial.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Objects/Images/Materials/CPass.h"
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Assets;
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects;
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Images;
|
|
||||||
|
|
||||||
CMaterial::CMaterial (
|
|
||||||
std::string name, bool solidlayer, std::map<int, const Effects::CBind*> textureBindings,
|
|
||||||
std::vector<const Materials::CPass*> passes
|
|
||||||
) :
|
|
||||||
m_name (std::move(name)),
|
|
||||||
m_textureBindings (std::move(textureBindings)),
|
|
||||||
m_passes (std::move(passes)),
|
|
||||||
m_solidlayer (solidlayer) {}
|
|
||||||
CMaterial::CMaterial (
|
|
||||||
std::string name, std::string target, bool solidlayer,
|
|
||||||
std::map<int, const Effects::CBind*> textureBindings, std::vector<const Materials::CPass*> passes
|
|
||||||
) :
|
|
||||||
m_name (std::move(name)),
|
|
||||||
m_target (std::move(target)),
|
|
||||||
m_textureBindings (std::move(textureBindings)),
|
|
||||||
m_passes (std::move(passes)),
|
|
||||||
m_solidlayer (solidlayer) {}
|
|
||||||
|
|
||||||
const CMaterial* CMaterial::fromFile (
|
|
||||||
const std::filesystem::path& filename, const std::shared_ptr<const CContainer>& container, bool solidlayer,
|
|
||||||
std::map<int, const Effects::CBind*> textureBindings, const OverrideInfo* overrides
|
|
||||||
) {
|
|
||||||
return fromJSON (filename, json::parse (container->readFileAsString (filename)), solidlayer, std::move(textureBindings), overrides);
|
|
||||||
}
|
|
||||||
|
|
||||||
const CMaterial* CMaterial::fromFile (
|
|
||||||
const std::filesystem::path& filename, const std::string& target, const std::shared_ptr<const CContainer>& container, bool solidlayer,
|
|
||||||
std::map<int, const Effects::CBind*> textureBindings, const OverrideInfo* overrides
|
|
||||||
) {
|
|
||||||
return fromJSON (filename, json::parse (container->readFileAsString (filename)), target, solidlayer, std::move(textureBindings), overrides);
|
|
||||||
}
|
|
||||||
|
|
||||||
const CMaterial* CMaterial::fromJSON (
|
|
||||||
const std::string& name, const json& data, const std::string& target, bool solidlayer,
|
|
||||||
std::map<int, const Effects::CBind*> textureBindings, const OverrideInfo* overrides
|
|
||||||
) {
|
|
||||||
const auto passes_it = jsonFindRequired (data, "passes", "Material must have at least one pass");
|
|
||||||
std::vector<const Materials::CPass*> passes;
|
|
||||||
|
|
||||||
for (const auto& cur : (*passes_it))
|
|
||||||
passes.push_back (Materials::CPass::fromJSON (cur, overrides));
|
|
||||||
|
|
||||||
return new CMaterial (name, target, solidlayer, std::move(textureBindings), passes);
|
|
||||||
}
|
|
||||||
|
|
||||||
const CMaterial* CMaterial::fromJSON (
|
|
||||||
const std::string& name, const json& data, bool solidlayer, std::map<int, const Effects::CBind*> textureBindings,
|
|
||||||
const OverrideInfo* overrides
|
|
||||||
) {
|
|
||||||
const auto passes_it = jsonFindRequired (data, "passes", "Material must have at least one pass");
|
|
||||||
std::vector<const Materials::CPass*> passes;
|
|
||||||
|
|
||||||
for (const auto& cur : (*passes_it))
|
|
||||||
passes.push_back (Materials::CPass::fromJSON (cur, overrides));
|
|
||||||
|
|
||||||
return new CMaterial (name, solidlayer, std::move(textureBindings), passes);
|
|
||||||
}
|
|
||||||
|
|
||||||
const CMaterial* CMaterial::fromCommand (const json& data) {
|
|
||||||
const std::string& command = jsonFindRequired <std::string> (data, "command", "Command material must have a command");
|
|
||||||
const std::string& target = jsonFindRequired <std::string> (data, "target", "Command material must have a target");
|
|
||||||
const std::string& source = jsonFindRequired <std::string> (data, "source", "Command material must have a source");
|
|
||||||
std::vector<const Materials::CPass*> passes;
|
|
||||||
|
|
||||||
if (command == "copy") {
|
|
||||||
passes.push_back (
|
|
||||||
Materials::CPass::fromJSON ({
|
|
||||||
{"blending", "normal"},
|
|
||||||
{"cullmode", "nocull"},
|
|
||||||
{"depthtest", "disabled"},
|
|
||||||
{"depthwrite", "disabled"},
|
|
||||||
{"shader", "commands/copy"},
|
|
||||||
{"textures", json::array ({source, target})}
|
|
||||||
}, nullptr)
|
|
||||||
);
|
|
||||||
} else if (command == "swap") {
|
|
||||||
// TODO: HOW TO IMPLEMENT THIS ONE?
|
|
||||||
sLog.exception ("Command material swap not implemented yet");
|
|
||||||
} else {
|
|
||||||
sLog.exception ("Unknown command: ", command);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CMaterial (command, false, {}, passes);
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<const Materials::CPass*>& CMaterial::getPasses () const {
|
|
||||||
return this->m_passes;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::map<int, const Effects::CBind*>& CMaterial::getTextureBinds () const {
|
|
||||||
return this->m_textureBindings;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& CMaterial::getTarget () const {
|
|
||||||
return this->m_target;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& CMaterial::getName () const {
|
|
||||||
return this->m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CMaterial::hasTarget () const {
|
|
||||||
return !this->m_target.empty ();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CMaterial::isSolidLayer () const {
|
|
||||||
return this->m_solidlayer;
|
|
||||||
}
|
|
@ -1,89 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Objects/Effects/CBind.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Assets/CContainer.h"
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Images::Materials {
|
|
||||||
class CPass;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Images {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
using namespace WallpaperEngine::Assets;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a material in use in the background
|
|
||||||
*/
|
|
||||||
class CMaterial {
|
|
||||||
public:
|
|
||||||
struct OverrideInfo {
|
|
||||||
std::map<std::string, int> combos;
|
|
||||||
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants;
|
|
||||||
std::map<int, std::string> textures;
|
|
||||||
};
|
|
||||||
|
|
||||||
static const CMaterial* fromFile (
|
|
||||||
const std::filesystem::path& filename, const std::shared_ptr<const CContainer>& container, bool solidlayer = false,
|
|
||||||
std::map<int, const Effects::CBind*> textureBindings = {}, const OverrideInfo* overrides = nullptr);
|
|
||||||
static const CMaterial* fromFile (
|
|
||||||
const std::filesystem::path& filename, const std::string& target, const std::shared_ptr<const CContainer>& container,
|
|
||||||
bool solidlayer = false, std::map<int, const Effects::CBind*> textureBindings = {},
|
|
||||||
const OverrideInfo* overrides = nullptr);
|
|
||||||
static const CMaterial* fromJSON (
|
|
||||||
const std::string& name, const json& data, bool solidlayer = false,
|
|
||||||
std::map<int, const Effects::CBind*> textureBindings = {}, const OverrideInfo* overrides = nullptr);
|
|
||||||
static const CMaterial* fromJSON (
|
|
||||||
const std::string& name, const json& data, const std::string& target, bool solidlayer = false,
|
|
||||||
std::map<int, const Effects::CBind*> textureBindings = {}, const OverrideInfo* overrides = nullptr);
|
|
||||||
static const CMaterial* fromCommand (const json& data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return All the rendering passes that happen for this material
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::vector<const Materials::CPass*>& getPasses () const;
|
|
||||||
/**
|
|
||||||
* @return The textures that have to be bound while rendering the material.
|
|
||||||
* These act as an override of the textures specified by the parent effect
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::map<int, const Effects::CBind*>& getTextureBinds () const;
|
|
||||||
/**
|
|
||||||
* @return The materials destination (fbo) if required
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::string& getTarget () const;
|
|
||||||
/**
|
|
||||||
* @return Indicates if this material has a specific destination (fbo) while rendering
|
|
||||||
*/
|
|
||||||
[[nodiscard]] bool hasTarget () const;
|
|
||||||
/**
|
|
||||||
* @return The name of the material
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::string& getName () const;
|
|
||||||
/**
|
|
||||||
* @return If this material is a solidlayer or not
|
|
||||||
*/
|
|
||||||
[[nodiscard]] bool isSolidLayer () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
CMaterial (
|
|
||||||
std::string name, bool solidlayer, std::map<int, const Effects::CBind*> textureBindings,
|
|
||||||
std::vector<const Materials::CPass*> passes);
|
|
||||||
CMaterial (
|
|
||||||
std::string name, std::string target, bool solidlayer, std::map<int, const Effects::CBind*> textureBindings,
|
|
||||||
std::vector<const Materials::CPass*> passes);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** All the shader passes required to render this material */
|
|
||||||
const std::vector<const Materials::CPass*> m_passes;
|
|
||||||
/** List of texture bind overrides to use for this material */
|
|
||||||
const std::map<int, const Effects::CBind*> m_textureBindings;
|
|
||||||
/** The FBO target to render to (if any) */
|
|
||||||
const std::string m_target;
|
|
||||||
/** The material's name */
|
|
||||||
const std::string m_name;
|
|
||||||
/** If this material is a solid layer or not */
|
|
||||||
const bool m_solidlayer;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Images
|
|
@ -1,105 +0,0 @@
|
|||||||
#include "CPass.h"
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Images::Materials;
|
|
||||||
|
|
||||||
CPass::CPass (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite,
|
|
||||||
std::string shader, std::map<int, std::string> textures, std::map<std::string, int> combos,
|
|
||||||
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants) :
|
|
||||||
m_blending (std::move(blending)),
|
|
||||||
m_cullmode (std::move(cullmode)),
|
|
||||||
m_depthtest (std::move(depthtest)),
|
|
||||||
m_depthwrite (std::move(depthwrite)),
|
|
||||||
m_shader (std::move(shader)),
|
|
||||||
m_textures (std::move(textures)),
|
|
||||||
m_combos (std::move(combos)),
|
|
||||||
m_constants (std::move(constants)) {}
|
|
||||||
|
|
||||||
const CPass* CPass::fromJSON (const json& data, const CMaterial::OverrideInfo* overrides) {
|
|
||||||
// TODO: FIGURE OUT DEFAULT BLENDING MODE
|
|
||||||
const auto textures_it = data.find ("textures");
|
|
||||||
const auto combos_it = data.find ("combos");
|
|
||||||
|
|
||||||
std::map<int, std::string> textures;
|
|
||||||
std::map<std::string, int> combos;
|
|
||||||
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants;
|
|
||||||
|
|
||||||
if (textures_it != data.end ()) {
|
|
||||||
// TODO: FETCH THIS FROM CImage TO MAKE IT COMPATIBLE WITH OLDER WALLPAPERS
|
|
||||||
if (!textures_it->is_array ())
|
|
||||||
sLog.exception ("Material's textures must be a list");
|
|
||||||
|
|
||||||
int textureNumber = -1;
|
|
||||||
for (const auto& cur : (*textures_it))
|
|
||||||
textures.emplace (++textureNumber, cur.is_null () ? "" : cur);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (combos_it != data.end ()) {
|
|
||||||
for (const auto& cur : combos_it->items ()) {
|
|
||||||
if (cur.value ().is_number_integer ()) {
|
|
||||||
std::string uppercase = std::string (cur.key ());
|
|
||||||
|
|
||||||
std::transform (uppercase.begin (), uppercase.end (), uppercase.begin (), ::toupper);
|
|
||||||
combos.emplace (uppercase, cur.value ());
|
|
||||||
} else {
|
|
||||||
sLog.exception ("unexpected non-integer combo on pass");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// apply overrides
|
|
||||||
if (overrides != nullptr) {
|
|
||||||
for (const auto& [name, value] : overrides->combos)
|
|
||||||
combos[name] = value;
|
|
||||||
for (const auto& [name, value] : overrides->constants)
|
|
||||||
constants[name] = value;
|
|
||||||
for (const auto& [id, value] : overrides->textures)
|
|
||||||
textures[id] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CPass (
|
|
||||||
jsonFindDefault<std::string> (data, "blending", "normal"),
|
|
||||||
jsonFindDefault<std::string> (data, "cullmode", "nocull"),
|
|
||||||
jsonFindRequired <std::string> (data, "depthtest", "Material pass must have depthtest specified"),
|
|
||||||
jsonFindRequired <std::string> (data, "depthwrite", "Material pass must have depthwrite specified"),
|
|
||||||
jsonFindRequired <std::string> (data, "shader", "Material pass must have shader specified"),
|
|
||||||
textures,
|
|
||||||
combos,
|
|
||||||
constants
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::map<int, std::string>& CPass::getTextures () const {
|
|
||||||
return this->m_textures;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::map<std::string, const CShaderConstant*>& CPass::getConstants () const {
|
|
||||||
return this->m_constants;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::map<std::string, int>& CPass::getCombos () const {
|
|
||||||
return this->m_combos;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& CPass::getShader () const {
|
|
||||||
return this->m_shader;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& CPass::getBlendingMode () const {
|
|
||||||
return this->m_blending;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& CPass::getCullingMode () const {
|
|
||||||
return this->m_cullmode;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& CPass::getDepthTest () const {
|
|
||||||
return this->m_depthtest;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& CPass::getDepthWrite () const {
|
|
||||||
return this->m_depthwrite;
|
|
||||||
}
|
|
@ -1,84 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Images/CMaterial.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects {
|
|
||||||
class CEffect;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Images {
|
|
||||||
class CMaterial;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Images::Materials {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a shader pass of an object
|
|
||||||
*/
|
|
||||||
class CPass {
|
|
||||||
friend class WallpaperEngine::Core::Objects::CEffect;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static const CPass* fromJSON (const json& data, const CMaterial::OverrideInfo* overrides);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The list of textures to bind while rendering
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::map<int, std::string>& getTextures () const;
|
|
||||||
/**
|
|
||||||
* @return Shader constants that alter how the shader should behave
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::map<std::string, const Effects::Constants::CShaderConstant*>& getConstants () const;
|
|
||||||
/**
|
|
||||||
* @return Shader combos that alter how the shader should behave
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::map<std::string, int>& getCombos () const;
|
|
||||||
/**
|
|
||||||
* @return Shader to be used while rendering the pass
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::string& getShader () const;
|
|
||||||
/**
|
|
||||||
* @return The blending mode to use while rendering
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::string& getBlendingMode () const;
|
|
||||||
/**
|
|
||||||
* @return The culling mode to use while rendering
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::string& getCullingMode () const;
|
|
||||||
/**
|
|
||||||
* @return If depth testing has to happen while rendering
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::string& getDepthTest () const;
|
|
||||||
/**
|
|
||||||
* @return If depth write has to happen while rendering
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::string& getDepthWrite () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
CPass (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite,
|
|
||||||
std::string shader, std::map<int, std::string> textures, std::map<std::string, int> combos,
|
|
||||||
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants);
|
|
||||||
|
|
||||||
private:
|
|
||||||
// TODO: CREATE ENUMERATIONS FOR THESE INSTEAD OF USING STRING VALUES!
|
|
||||||
/** The blending mode to use */
|
|
||||||
const std::string m_blending;
|
|
||||||
/** The culling mode to use */
|
|
||||||
const std::string m_cullmode;
|
|
||||||
/** If depthtesting has to happen while drawing */
|
|
||||||
const std::string m_depthtest;
|
|
||||||
/** If depthwrite has to happen while drawing */
|
|
||||||
const std::string m_depthwrite;
|
|
||||||
/** The shader to use */
|
|
||||||
const std::string m_shader;
|
|
||||||
/** The list of textures to use */
|
|
||||||
const std::map<int, std::string> m_textures;
|
|
||||||
/** Different combo settings for shader input */
|
|
||||||
const std::map<std::string, int> m_combos;
|
|
||||||
/** Shader constant values to use for the shaders */
|
|
||||||
const std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> m_constants;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Images::Materials
|
|
@ -1,28 +0,0 @@
|
|||||||
#include "CControlPoint.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles;
|
|
||||||
|
|
||||||
const CControlPoint* CControlPoint::fromJSON (const json& data) {
|
|
||||||
return new CControlPoint (
|
|
||||||
jsonFindRequired <uint32_t> (data, "id", "Particle's control point must have id"),
|
|
||||||
jsonFindDefault (data, "flags", 0),
|
|
||||||
jsonFindDefault (data, "offset", glm::vec3())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
CControlPoint::CControlPoint (uint32_t id, uint32_t flags, glm::vec3 offset) :
|
|
||||||
m_id (id),
|
|
||||||
m_flags (flags),
|
|
||||||
m_offset (offset) {}
|
|
||||||
|
|
||||||
uint32_t CControlPoint::getId () const {
|
|
||||||
return this->m_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::vec3& CControlPoint::getOffset () const {
|
|
||||||
return this->m_offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t CControlPoint::getFlags () const {
|
|
||||||
return this->m_flags;
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Particles {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Control point for particles
|
|
||||||
*/
|
|
||||||
class CControlPoint {
|
|
||||||
public:
|
|
||||||
static const CControlPoint* fromJSON (const json& data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The id of the controlpoint used for ordering purposes
|
|
||||||
*/
|
|
||||||
[[nodiscard]] uint32_t getId () const;
|
|
||||||
/**
|
|
||||||
* @return The offset from origin
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const glm::vec3& getOffset () const;
|
|
||||||
/**
|
|
||||||
* @return Flags for the control point, controls how it should behave
|
|
||||||
*/
|
|
||||||
[[nodiscard]] uint32_t getFlags () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
explicit CControlPoint (uint32_t id, uint32_t flags, glm::vec3 offset);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** ID used for ordering purposes */
|
|
||||||
const uint32_t m_id;
|
|
||||||
/** Flags that control how it behaves */
|
|
||||||
const uint32_t m_flags;
|
|
||||||
/** The offset from starting position */
|
|
||||||
const glm::vec3 m_offset;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles
|
|
@ -1,75 +0,0 @@
|
|||||||
#include "CEmitter.h"
|
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles;
|
|
||||||
|
|
||||||
const CEmitter* CEmitter::fromJSON (const json& data) {
|
|
||||||
const auto distancemax_it = jsonFindRequired (data, "distancemax", "Particle emitter must have maximum distance");
|
|
||||||
const auto distancemin_it = jsonFindRequired (data, "distancemin", "Particle emitter must have minimum distance");
|
|
||||||
|
|
||||||
auto distancemin = glm::vec3(0);
|
|
||||||
auto distancemax = glm::vec3(0);
|
|
||||||
|
|
||||||
if (distancemin_it->is_number()) {
|
|
||||||
distancemin = glm::vec3(static_cast<uint32_t>(*distancemin_it));
|
|
||||||
} else {
|
|
||||||
distancemin = WallpaperEngine::Core::aToVector3(*distancemin_it);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (distancemax_it->is_number()) {
|
|
||||||
distancemax = glm::vec3(static_cast<uint32_t>(*distancemax_it));
|
|
||||||
} else {
|
|
||||||
distancemax = WallpaperEngine::Core::aToVector3(*distancemax_it);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CEmitter (
|
|
||||||
jsonFindRequired <glm::vec3> (data, "directions", "Particle emitter must have direction specified"),
|
|
||||||
distancemax,
|
|
||||||
distancemin,
|
|
||||||
jsonFindDefault (data, "id", 0),
|
|
||||||
jsonFindRequired <std::string> (data, "name", "Particle emitter must have a name"),
|
|
||||||
jsonFindRequired <glm::vec3> (data, "origin", "Particle emitter must have an origin"),
|
|
||||||
jsonFindRequired <double> (data, "rate", "Particle emitter must have a rate")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
CEmitter::CEmitter (
|
|
||||||
glm::vec3 directions, glm::vec3 distancemax, glm::vec3 distancemin, uint32_t id, std::string name, glm::vec3 origin,
|
|
||||||
double rate
|
|
||||||
) :
|
|
||||||
m_directions (directions),
|
|
||||||
m_distancemax (distancemax),
|
|
||||||
m_distancemin (distancemin),
|
|
||||||
m_id (id),
|
|
||||||
m_name (std::move(name)),
|
|
||||||
m_origin (origin),
|
|
||||||
m_rate (rate) {}
|
|
||||||
|
|
||||||
uint32_t CEmitter::getId () const {
|
|
||||||
return this->m_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& CEmitter::getName () const {
|
|
||||||
return this->m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::vec3& CEmitter::getDistanceMax () const {
|
|
||||||
return this->m_distancemax;
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::vec3& CEmitter::getDistanceMin () const {
|
|
||||||
return this->m_distancemin;
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::vec3& CEmitter::getDirections () const {
|
|
||||||
return this->m_directions;
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::vec3& CEmitter::getOrigin () const {
|
|
||||||
return this->m_origin;
|
|
||||||
}
|
|
||||||
|
|
||||||
const double CEmitter::getRate () const {
|
|
||||||
return this->m_rate;
|
|
||||||
}
|
|
@ -1,65 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Particles {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Particle emitter, controls the area where the particles have to be created
|
|
||||||
*/
|
|
||||||
class CEmitter {
|
|
||||||
public:
|
|
||||||
static const CEmitter* fromJSON (const json& data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The ID of the emitter
|
|
||||||
*/
|
|
||||||
[[nodiscard]] uint32_t getId () const;
|
|
||||||
/**
|
|
||||||
* @return The name of the emitter, indicates what type of emission to do
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::string& getName () const;
|
|
||||||
/**
|
|
||||||
* @return The maximum distance a particle can travel before being dead
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const glm::vec3& getDistanceMax () const;
|
|
||||||
/**
|
|
||||||
* @return The minimum distance a particle can travel before being dead
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const glm::vec3& getDistanceMin () const;
|
|
||||||
/**
|
|
||||||
* @return The direction a particle should move to
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const glm::vec3& getDirections () const;
|
|
||||||
/**
|
|
||||||
* @return The center of the particle emission
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const glm::vec3& getOrigin () const;
|
|
||||||
/**
|
|
||||||
* @return The rate of particle emission
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const double getRate () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
CEmitter (
|
|
||||||
glm::vec3 directions, glm::vec3 distancemax, glm::vec3 distancemin, uint32_t id, std::string name,
|
|
||||||
glm::vec3 origin, double rate);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** Direction the particles should move to */
|
|
||||||
const glm::vec3 m_directions;
|
|
||||||
/** Maximum distance before the particle is dead */
|
|
||||||
const glm::vec3 m_distancemax;
|
|
||||||
/** Minimum distance before the particle is dead */
|
|
||||||
const glm::vec3 m_distancemin;
|
|
||||||
/** ID of the emitter */
|
|
||||||
const uint32_t m_id;
|
|
||||||
/** Name of the emitter, indicates the type of emitter */
|
|
||||||
const std::string m_name;
|
|
||||||
/** The center of the emitter */
|
|
||||||
const glm::vec3 m_origin;
|
|
||||||
/** The rate of emission */
|
|
||||||
const double m_rate;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles
|
|
@ -1,59 +0,0 @@
|
|||||||
#include "CInitializer.h"
|
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h"
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles;
|
|
||||||
|
|
||||||
const CInitializer* CInitializer::fromJSON (const json& data) {
|
|
||||||
const auto name = jsonFindRequired <std::string> (data, "name", "Particle's initializer must have a name");
|
|
||||||
const auto id = jsonFindDefault (data, "id", 0);
|
|
||||||
|
|
||||||
if (name == "lifetimerandom") {
|
|
||||||
return Initializers::CLifeTimeRandom::fromJSON (data, id);
|
|
||||||
}
|
|
||||||
if (name == "sizerandom") {
|
|
||||||
return Initializers::CSizeRandom::fromJSON (data, id);
|
|
||||||
}
|
|
||||||
if (name == "rotationrandom") {
|
|
||||||
return Initializers::CRotationRandom::fromJSON (data, id);
|
|
||||||
}
|
|
||||||
if (name == "velocityrandom") {
|
|
||||||
return Initializers::CVelocityRandom::fromJSON (data, id);
|
|
||||||
}
|
|
||||||
if (name == "colorrandom") {
|
|
||||||
return Initializers::CColorRandom::fromJSON (data, id);
|
|
||||||
}
|
|
||||||
if (name == "alpharandom") {
|
|
||||||
return Initializers::CAlphaRandom::fromJSON (data, id);
|
|
||||||
}
|
|
||||||
if (name == "angularvelocityrandom") {
|
|
||||||
return Initializers::CAngularVelocityRandom::fromJSON (data, id);
|
|
||||||
}
|
|
||||||
if (name == "turbulentvelocityrandom") {
|
|
||||||
return Initializers::CTurbulentVelocityRandom::fromJSON (data, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
sLog.exception ("Found unknown initializer for particles: ", name);
|
|
||||||
}
|
|
||||||
|
|
||||||
CInitializer::CInitializer (uint32_t id, std::string name) :
|
|
||||||
m_id (id),
|
|
||||||
m_name (std::move(name)) {}
|
|
||||||
|
|
||||||
const std::string& CInitializer::getName () const {
|
|
||||||
return this->m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t CInitializer::getId () const {
|
|
||||||
return this->m_id;
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Particles {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializer for particles, controls the different attributes a particle will have
|
|
||||||
* on emission
|
|
||||||
*/
|
|
||||||
class CInitializer {
|
|
||||||
public:
|
|
||||||
static const CInitializer* fromJSON (const json& data);
|
|
||||||
|
|
||||||
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 The name of the particle initializer, indicates what type of initialization to do
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::string& getName () const;
|
|
||||||
/**
|
|
||||||
* @return The id of the initializer
|
|
||||||
*/
|
|
||||||
[[nodiscard]] uint32_t getId () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
CInitializer (uint32_t id, std::string name);
|
|
||||||
|
|
||||||
virtual ~CInitializer() = default;
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** ID for ordering purposes */
|
|
||||||
const uint32_t m_id;
|
|
||||||
/** The name of the initializer, indicates what type of initialization to do */
|
|
||||||
const std::string m_name;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles
|
|
@ -1,24 +0,0 @@
|
|||||||
#include "CAlphaRandom.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
|
||||||
|
|
||||||
const CAlphaRandom* CAlphaRandom::fromJSON (const json& data, uint32_t id) {
|
|
||||||
return new CAlphaRandom (
|
|
||||||
id,
|
|
||||||
jsonFindRequired<double> (data, "min", "Alpharandom initializer must have a minimum value"),
|
|
||||||
jsonFindRequired<double> (data, "max", "Alpharandom initializer must have a maximum value")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
CAlphaRandom::CAlphaRandom (uint32_t id, double min, double max) :
|
|
||||||
CInitializer (id, "alpharandom"),
|
|
||||||
m_max (max),
|
|
||||||
m_min (min) {}
|
|
||||||
|
|
||||||
double CAlphaRandom::getMinimum () const {
|
|
||||||
return this->m_min;
|
|
||||||
}
|
|
||||||
|
|
||||||
double CAlphaRandom::getMaximum () const {
|
|
||||||
return this->m_max;
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Particles/CInitializer.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Particles::Initializers {
|
|
||||||
/**
|
|
||||||
* Initializer for particles that decides the base alpha for the particles
|
|
||||||
*/
|
|
||||||
class CAlphaRandom : CInitializer {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @return The minimum alpha value to be used
|
|
||||||
*/
|
|
||||||
[[nodiscard]] double getMinimum () const;
|
|
||||||
/**
|
|
||||||
* @return The maximum alpha value to be used
|
|
||||||
*/
|
|
||||||
[[nodiscard]] double getMaximum () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
friend class CInitializer;
|
|
||||||
|
|
||||||
static const CAlphaRandom* fromJSON (const json& data, uint32_t id);
|
|
||||||
|
|
||||||
CAlphaRandom (uint32_t id, double min, double max);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** Maximum alpha */
|
|
||||||
const double m_max;
|
|
||||||
/** Minimum alpha */
|
|
||||||
const double m_min;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
|
@ -1,24 +0,0 @@
|
|||||||
#include "CAngularVelocityRandom.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
|
||||||
|
|
||||||
const CAngularVelocityRandom* CAngularVelocityRandom::fromJSON (const json& data, uint32_t id) {
|
|
||||||
return new CAngularVelocityRandom (
|
|
||||||
id,
|
|
||||||
jsonFindRequired <glm::vec3> (data, "min", "Angularvelocityrandom initializer must have a minimum value"),
|
|
||||||
jsonFindRequired <glm::vec3> (data, "max", "Angularvelocityrandom initializer must have a maximum value")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
CAngularVelocityRandom::CAngularVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max) :
|
|
||||||
CInitializer (id, "angularvelocityrandom"),
|
|
||||||
m_max (max),
|
|
||||||
m_min (min) {}
|
|
||||||
|
|
||||||
const glm::vec3& CAngularVelocityRandom::getMinimum () const {
|
|
||||||
return this->m_min;
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::vec3& CAngularVelocityRandom::getMaximum () const {
|
|
||||||
return this->m_max;
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
#include "WallpaperEngine/Core/Objects/Particles/CInitializer.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Particles::Initializers {
|
|
||||||
/**
|
|
||||||
* Initializer for particles that decides the base angular velocity for particles
|
|
||||||
*/
|
|
||||||
class CAngularVelocityRandom : CInitializer {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @return Minimum angular velocity (direction * speed)
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const glm::vec3& getMinimum () const;
|
|
||||||
/**
|
|
||||||
* @return Maximum angular velocity (direction * speed)
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const glm::vec3& getMaximum () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
friend class CInitializer;
|
|
||||||
|
|
||||||
static const CAngularVelocityRandom* fromJSON (const json& data, uint32_t id);
|
|
||||||
|
|
||||||
CAngularVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** Maximum velocity (direction * speed) */
|
|
||||||
const glm::vec3 m_max;
|
|
||||||
/** Minimum velocity (direction * speed) */
|
|
||||||
const glm::vec3 m_min;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
|
@ -1,24 +0,0 @@
|
|||||||
#include "CColorRandom.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
|
||||||
|
|
||||||
const CColorRandom* CColorRandom::fromJSON (const json& data, uint32_t id) {
|
|
||||||
return new CColorRandom (
|
|
||||||
id,
|
|
||||||
jsonFindRequired <glm::ivec3> (data, "min", "Colorrandom initializer must have a minimum value"),
|
|
||||||
jsonFindRequired <glm::ivec3> (data, "max", "Colorrandom initializer must have a maximum value")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
CColorRandom::CColorRandom (uint32_t id, glm::ivec3 min, glm::ivec3 max) :
|
|
||||||
CInitializer (id, "colorrandom"),
|
|
||||||
m_max (max),
|
|
||||||
m_min (min) {}
|
|
||||||
|
|
||||||
const glm::ivec3& CColorRandom::getMinimum () const {
|
|
||||||
return this->m_min;
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::ivec3& CColorRandom::getMaximum () const {
|
|
||||||
return this->m_max;
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Objects/Particles/CInitializer.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Particles::Initializers {
|
|
||||||
/**
|
|
||||||
* Initializer for particles that decides the base color
|
|
||||||
*/
|
|
||||||
class CColorRandom : CInitializer {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @return The minimum color to use (RGB)
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const glm::ivec3& getMinimum () const;
|
|
||||||
/**
|
|
||||||
* @return The maximum color to use (RGB)
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const glm::ivec3& getMaximum () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
friend class CInitializer;
|
|
||||||
|
|
||||||
static const CColorRandom* fromJSON (const json& data, uint32_t id);
|
|
||||||
|
|
||||||
CColorRandom (uint32_t id, glm::ivec3 min, glm::ivec3 max);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** Maximum color */
|
|
||||||
const glm::ivec3 m_max;
|
|
||||||
/** Minimum color */
|
|
||||||
const glm::ivec3 m_min;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
|
@ -1,24 +0,0 @@
|
|||||||
#include "CLifeTimeRandom.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
|
||||||
|
|
||||||
const CLifeTimeRandom* CLifeTimeRandom::fromJSON (const json& data, uint32_t id) {
|
|
||||||
return new CLifeTimeRandom (
|
|
||||||
id,
|
|
||||||
jsonFindRequired <uint32_t> (data, "min", "Lifetimerandom initializer must have a minimum value"),
|
|
||||||
jsonFindRequired <uint32_t> (data, "max", "Lifetimerandom initializer must have a maximum value")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
CLifeTimeRandom::CLifeTimeRandom (uint32_t id, uint32_t min, uint32_t max) :
|
|
||||||
CInitializer (id, "lifetimerandom"),
|
|
||||||
m_max (max),
|
|
||||||
m_min (min) {}
|
|
||||||
|
|
||||||
uint32_t CLifeTimeRandom::getMinimum () const {
|
|
||||||
return this->m_min;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t CLifeTimeRandom::getMaximum () const {
|
|
||||||
return this->m_max;
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Objects/Particles/CInitializer.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Particles::Initializers {
|
|
||||||
/**
|
|
||||||
* Initializer for particles that decides the lifetime of each particle on startup
|
|
||||||
*/
|
|
||||||
class CLifeTimeRandom : CInitializer {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @return The minimum lifetime to be used
|
|
||||||
*/
|
|
||||||
[[nodiscard]] uint32_t getMinimum () const;
|
|
||||||
/**
|
|
||||||
* @return The maximum lifetime to be used
|
|
||||||
*/
|
|
||||||
[[nodiscard]] uint32_t getMaximum () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
friend class CInitializer;
|
|
||||||
|
|
||||||
static const CLifeTimeRandom* fromJSON (const json& data, uint32_t id);
|
|
||||||
|
|
||||||
CLifeTimeRandom (uint32_t id, uint32_t min, uint32_t max);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** Maximum lifetime */
|
|
||||||
const uint32_t m_max;
|
|
||||||
/** Minimum lifetime */
|
|
||||||
const uint32_t m_min;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
|
@ -1,77 +0,0 @@
|
|||||||
#include "CRotationRandom.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
|
||||||
|
|
||||||
const CRotationRandom* CRotationRandom::fromJSON (const json& data, uint32_t id) {
|
|
||||||
const auto min_it = data.find ("minVector");
|
|
||||||
const auto max_it = data.find ("max");
|
|
||||||
|
|
||||||
glm::vec3 minVector = glm::vec3 ();
|
|
||||||
glm::vec3 maxVector = glm::vec3 ();
|
|
||||||
double minNumber = 0.0f;
|
|
||||||
double maxNumber = 0.0f;
|
|
||||||
bool isMinVector = false;
|
|
||||||
bool isMaxVector = false;
|
|
||||||
|
|
||||||
if (min_it != data.end () && min_it->is_string ()) {
|
|
||||||
minVector = WallpaperEngine::Core::aToVector3 (*min_it);
|
|
||||||
isMinVector = true;
|
|
||||||
} else if (min_it != data.end () && min_it->is_number ()) {
|
|
||||||
minNumber = *min_it;
|
|
||||||
isMinVector = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (max_it != data.end () && max_it->is_string ()) {
|
|
||||||
maxVector = WallpaperEngine::Core::aToVector3 (*max_it);
|
|
||||||
isMaxVector = true;
|
|
||||||
} else if (max_it != data.end () && max_it->is_number ()) {
|
|
||||||
maxNumber = *max_it;
|
|
||||||
isMaxVector = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CRotationRandom (id, minVector, minNumber, isMinVector, maxVector, maxNumber, isMaxVector);
|
|
||||||
}
|
|
||||||
|
|
||||||
CRotationRandom::CRotationRandom (uint32_t id, glm::vec3 minVector, double minNumber, bool isMinimumVector,
|
|
||||||
glm::vec3 maxVector, double maxNumber, bool isMaximumVector) :
|
|
||||||
CInitializer (id, "rotationrandom"),
|
|
||||||
m_maxVector (maxVector),
|
|
||||||
m_maxNumber (maxNumber),
|
|
||||||
m_minVector (minVector),
|
|
||||||
m_minNumber (minNumber),
|
|
||||||
m_isMinimumVector (isMinimumVector),
|
|
||||||
m_isMaximumVector (isMaximumVector) {}
|
|
||||||
|
|
||||||
glm::vec3 CRotationRandom::getMinimumVector () const {
|
|
||||||
return this->m_minVector;
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::vec3 CRotationRandom::getMaximumVector () const {
|
|
||||||
return this->m_maxVector;
|
|
||||||
}
|
|
||||||
|
|
||||||
double CRotationRandom::getMinimumNumber () const {
|
|
||||||
return this->m_minNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
double CRotationRandom::getMaximumNumber () const {
|
|
||||||
return this->m_maxNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CRotationRandom::isMinimumVector () const {
|
|
||||||
return this->m_isMinimumVector;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CRotationRandom::isMinimumNumber () const {
|
|
||||||
return !this->m_isMinimumVector;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CRotationRandom::isMaximumVector () const {
|
|
||||||
return this->m_isMaximumVector;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CRotationRandom::isMaximumNumber () const {
|
|
||||||
return !this->m_isMaximumVector;
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Objects/Particles/CInitializer.h"
|
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Particles::Initializers {
|
|
||||||
/**
|
|
||||||
* Initializer for particles that decides the base rotation for the particles
|
|
||||||
*/
|
|
||||||
class CRotationRandom : CInitializer {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @return The minimum rotation in vector format if available
|
|
||||||
*/
|
|
||||||
[[nodiscard]] glm::vec3 getMinimumVector () const;
|
|
||||||
/**
|
|
||||||
* @return The maximum rotation in vector format if available
|
|
||||||
*/
|
|
||||||
[[nodiscard]] glm::vec3 getMaximumVector () const;
|
|
||||||
/**
|
|
||||||
* @return The minimum rotation in angle format if available
|
|
||||||
*/
|
|
||||||
[[nodiscard]] double getMinimumNumber () const;
|
|
||||||
/**
|
|
||||||
* @return The maximum rotation in angle format if available
|
|
||||||
*/
|
|
||||||
[[nodiscard]] double getMaximumNumber () const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Indicates if the minimum rotation is a vector
|
|
||||||
*/
|
|
||||||
[[nodiscard]] bool isMinimumVector () const;
|
|
||||||
/**
|
|
||||||
* @return Indicates if the minimum rotation is an angle
|
|
||||||
*/
|
|
||||||
[[nodiscard]] bool isMinimumNumber () const;
|
|
||||||
/**
|
|
||||||
* @return Indicates if the maximum rotation is a vector
|
|
||||||
*/
|
|
||||||
[[nodiscard]] bool isMaximumVector () const;
|
|
||||||
/**
|
|
||||||
* @return Indicates if the maximum rotation is an angle
|
|
||||||
*/
|
|
||||||
[[nodiscard]] bool isMaximumNumber () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
friend class CInitializer;
|
|
||||||
|
|
||||||
static const CRotationRandom* fromJSON (const json& data, uint32_t id);
|
|
||||||
|
|
||||||
CRotationRandom (uint32_t id, glm::vec3 minVector, double minNumber, bool isMinimumVector, glm::vec3 maxVector,
|
|
||||||
double maxNumber, bool isMaximumVector);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** Maximum rotation vector */
|
|
||||||
const glm::vec3 m_maxVector;
|
|
||||||
/** Maximum rotation angle */
|
|
||||||
const double m_maxNumber;
|
|
||||||
/** Minimum rotation vector */
|
|
||||||
const glm::vec3 m_minVector;
|
|
||||||
/** Minimum rotation angle */
|
|
||||||
const double m_minNumber;
|
|
||||||
|
|
||||||
/** If minimum is a vector */
|
|
||||||
const bool m_isMinimumVector;
|
|
||||||
/** If maximum is a vector */
|
|
||||||
const bool m_isMaximumVector;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
|
@ -1,24 +0,0 @@
|
|||||||
#include "CSizeRandom.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
|
||||||
|
|
||||||
const CSizeRandom* CSizeRandom::fromJSON (const json& data, uint32_t id) {
|
|
||||||
return new CSizeRandom (
|
|
||||||
id,
|
|
||||||
jsonFindRequired <uint32_t> (data, "min", "Sizerandom initializer must have a minimum value"),
|
|
||||||
jsonFindRequired <uint32_t> (data, "max", "Sizerandom initializer must have a maximum value")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
CSizeRandom::CSizeRandom (uint32_t id, uint32_t min, uint32_t max) :
|
|
||||||
CInitializer (id, "sizerandom"),
|
|
||||||
m_max (max),
|
|
||||||
m_min (min) {}
|
|
||||||
|
|
||||||
uint32_t CSizeRandom::getMinimum () const {
|
|
||||||
return this->m_min;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t CSizeRandom::getMaximum () const {
|
|
||||||
return this->m_max;
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Objects/Particles/CInitializer.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Particles::Initializers {
|
|
||||||
/**
|
|
||||||
* Initializer for particles that decides the base size for the particles
|
|
||||||
*/
|
|
||||||
class CSizeRandom : CInitializer {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @return The minimum size to be used
|
|
||||||
*/
|
|
||||||
[[nodiscard]] uint32_t getMinimum () const;
|
|
||||||
/**
|
|
||||||
* @return The maximum size to be used
|
|
||||||
*/
|
|
||||||
[[nodiscard]] uint32_t getMaximum () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
friend class CInitializer;
|
|
||||||
|
|
||||||
static const CSizeRandom* fromJSON (const json& data, uint32_t id);
|
|
||||||
|
|
||||||
CSizeRandom (uint32_t id, uint32_t min, uint32_t max);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** Maximum size */
|
|
||||||
const uint32_t m_max;
|
|
||||||
/** Minimum size */
|
|
||||||
const uint32_t m_min;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
|
@ -1,46 +0,0 @@
|
|||||||
#include "CTurbulentVelocityRandom.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
|
||||||
|
|
||||||
const CTurbulentVelocityRandom* CTurbulentVelocityRandom::fromJSON (const json& data, uint32_t id) {
|
|
||||||
return new CTurbulentVelocityRandom (
|
|
||||||
id,
|
|
||||||
jsonFindRequired <double> (data, "phasemax", "TurbulentVelocityRandom initializer must have a phasemax value"),
|
|
||||||
jsonFindRequired <double> (data, "scale", "TurbulentVelocityRandom initializer must have a scale value"),
|
|
||||||
jsonFindRequired <double>(data, "timescale", "TurbulentVelocityRandom initializer must have a timescale value"),
|
|
||||||
jsonFindRequired <uint32_t> (data, "speedmin", "TurbulentVelocityRandom initializer must have a minimum speed value"),
|
|
||||||
jsonFindRequired <uint32_t> (data, "speedmax", "TurbulentVelocityRandom initializer must have a maximum speed value")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
CTurbulentVelocityRandom::CTurbulentVelocityRandom (uint32_t id, double phasemax, double scale, double timescale,
|
|
||||||
uint32_t speedmin, uint32_t speedmax) :
|
|
||||||
CInitializer (id, "turbulentvelocityrandom"),
|
|
||||||
m_phasemax (phasemax),
|
|
||||||
m_scale (scale),
|
|
||||||
m_timescale (timescale),
|
|
||||||
m_speedmin (speedmin),
|
|
||||||
m_speedmax (speedmax) {}
|
|
||||||
|
|
||||||
double CTurbulentVelocityRandom::getPhaseMax () const {
|
|
||||||
return this->m_phasemax;
|
|
||||||
}
|
|
||||||
|
|
||||||
double CTurbulentVelocityRandom::getScale () const {
|
|
||||||
return this->m_scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
double CTurbulentVelocityRandom::getTimeScale () const {
|
|
||||||
return this->m_timescale;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t CTurbulentVelocityRandom::getMinimumSpeed () const {
|
|
||||||
return this->m_speedmin;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t CTurbulentVelocityRandom::getMaximumSpeed () const {
|
|
||||||
return this->m_speedmax;
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Objects/Particles/CInitializer.h"
|
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Particles::Initializers {
|
|
||||||
/**
|
|
||||||
* Initializer for particles that decides the turbulent velocity for the particles
|
|
||||||
*/
|
|
||||||
class CTurbulentVelocityRandom : CInitializer {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @return The phase to use
|
|
||||||
*/
|
|
||||||
double getPhaseMax () const;
|
|
||||||
/**
|
|
||||||
* @return The scale to use
|
|
||||||
*/
|
|
||||||
double getScale () const;
|
|
||||||
/**
|
|
||||||
* @return How time affects to the scale
|
|
||||||
*/
|
|
||||||
double getTimeScale () const;
|
|
||||||
/**
|
|
||||||
* @return The minimum speed
|
|
||||||
*/
|
|
||||||
uint32_t getMinimumSpeed () const;
|
|
||||||
/**
|
|
||||||
* @return The maximum speed
|
|
||||||
*/
|
|
||||||
uint32_t getMaximumSpeed () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
friend class CInitializer;
|
|
||||||
|
|
||||||
static const CTurbulentVelocityRandom* fromJSON (const json& data, uint32_t id);
|
|
||||||
|
|
||||||
CTurbulentVelocityRandom (uint32_t id, double phasemax, double scale, double timescale, uint32_t speedmin,
|
|
||||||
uint32_t speedmax);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** Phase */
|
|
||||||
const double m_phasemax;
|
|
||||||
/** Scale */
|
|
||||||
const double m_scale;
|
|
||||||
/** Time scale, how the time affects the scale */
|
|
||||||
const double m_timescale;
|
|
||||||
/** Minimum speed */
|
|
||||||
const uint32_t m_speedmin;
|
|
||||||
/** Maximum speed */
|
|
||||||
const uint32_t m_speedmax;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
|
@ -1,24 +0,0 @@
|
|||||||
#include "CVelocityRandom.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
|
||||||
|
|
||||||
const CVelocityRandom* CVelocityRandom::fromJSON (const json& data, uint32_t id) {
|
|
||||||
return new CVelocityRandom (
|
|
||||||
id,
|
|
||||||
jsonFindRequired <glm::vec3> (data, "min", "Velocityrandom initializer must have a minimum value"),
|
|
||||||
jsonFindRequired <glm::vec3> (data, "max", "Velocityrandom initializer must have a maximum value")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
CVelocityRandom::CVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max) :
|
|
||||||
CInitializer (id, "velocityrandom"),
|
|
||||||
m_max (max),
|
|
||||||
m_min (min) {}
|
|
||||||
|
|
||||||
const glm::vec3& CVelocityRandom::getMinimum () const {
|
|
||||||
return this->m_min;
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::vec3& CVelocityRandom::getMaximum () const {
|
|
||||||
return this->m_max;
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Objects/Particles/CInitializer.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Particles::Initializers {
|
|
||||||
/**
|
|
||||||
* Initializer for particles that decides the base velocity for the particles
|
|
||||||
*/
|
|
||||||
class CVelocityRandom : CInitializer {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @return The minimum velocity (direction * speed)
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const glm::vec3& getMinimum () const;
|
|
||||||
/**
|
|
||||||
* @return The maximum velocity (direction * speed)
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const glm::vec3& getMaximum () const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
friend class CInitializer;
|
|
||||||
|
|
||||||
static const CVelocityRandom* fromJSON (const json& data, uint32_t id);
|
|
||||||
|
|
||||||
CVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max);
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** Maximum velocity */
|
|
||||||
const glm::vec3 m_max;
|
|
||||||
/** Minimum velocity */
|
|
||||||
const glm::vec3 m_min;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
|
@ -1,56 +0,0 @@
|
|||||||
#include "CProperty.h"
|
|
||||||
#include "CPropertyBoolean.h"
|
|
||||||
#include "CPropertyColor.h"
|
|
||||||
#include "CPropertyCombo.h"
|
|
||||||
#include "CPropertySlider.h"
|
|
||||||
#include "CPropertyText.h"
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
|
||||||
#include <iostream>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
|
||||||
|
|
||||||
std::shared_ptr<CProperty> CProperty::fromJSON (const json& data, const std::string& name) {
|
|
||||||
const auto type = jsonFindRequired (data, "type", "Project properties must have the type field");
|
|
||||||
|
|
||||||
if (*type == "color")
|
|
||||||
return CPropertyColor::fromJSON (data, name);
|
|
||||||
if (*type == "bool")
|
|
||||||
return CPropertyBoolean::fromJSON (data, name);
|
|
||||||
if (*type == "slider")
|
|
||||||
return CPropertySlider::fromJSON (data, name);
|
|
||||||
if (*type == "combo")
|
|
||||||
return CPropertyCombo::fromJSON (data, name);
|
|
||||||
if (*type == "text")
|
|
||||||
return CPropertyText::fromJSON (data, name);
|
|
||||||
|
|
||||||
// show the error and ignore this property
|
|
||||||
sLog.error ("Unexpected type for property: ", *type);
|
|
||||||
sLog.error (data);
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
CProperty::CProperty (std::string name, std::string text) :
|
|
||||||
m_name (std::move(name)),
|
|
||||||
m_text (std::move(text)) {}
|
|
||||||
|
|
||||||
void CProperty::subscribe (const function_type& callback) const {
|
|
||||||
this->m_subscriptions.push_back (callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CProperty::propagate () const {
|
|
||||||
CDynamicValue::propagate ();
|
|
||||||
|
|
||||||
for (const auto& callback : this->m_subscriptions) {
|
|
||||||
callback(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& CProperty::getName () const {
|
|
||||||
return this->m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& CProperty::getText () const {
|
|
||||||
return this->m_text;
|
|
||||||
}
|
|
@ -1,82 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/DynamicValues/CDynamicValue.h"
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
using namespace WallpaperEngine::Core::DynamicValues;
|
|
||||||
/**
|
|
||||||
* Represents a property in a background
|
|
||||||
*
|
|
||||||
* Properties are settings that alter how the background looks or works
|
|
||||||
* and are configurable by the user so they can customize it to their likings
|
|
||||||
*/
|
|
||||||
class CProperty : public CDynamicValue {
|
|
||||||
public:
|
|
||||||
typedef std::function<void(const CProperty*)> function_type;
|
|
||||||
virtual ~CProperty () = default;
|
|
||||||
static std::shared_ptr<CProperty> fromJSON (const json& data, const std::string& name);
|
|
||||||
|
|
||||||
template <class T> [[nodiscard]] const T* as () const {
|
|
||||||
if (is <T> ()) {
|
|
||||||
return static_cast <const T*> (this);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw std::bad_cast ();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T> [[nodiscard]] T* as () {
|
|
||||||
if (is <T> ()) {
|
|
||||||
return static_cast <T*> (this);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw std::bad_cast ();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T> [[nodiscard]] bool is () const {
|
|
||||||
return typeid (*this) == typeid(T);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Representation of what the property does and the default values
|
|
||||||
*/
|
|
||||||
[[nodiscard]] virtual std::string dump () const = 0;
|
|
||||||
/**
|
|
||||||
* Updates the value of the property with the one in the string
|
|
||||||
*
|
|
||||||
* @param value New value for the property
|
|
||||||
*/
|
|
||||||
virtual void set (const std::string& value) = 0;
|
|
||||||
/**
|
|
||||||
* @return Name of the property
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::string& getName () const;
|
|
||||||
/**
|
|
||||||
* @return Textual type representation of this property
|
|
||||||
*/
|
|
||||||
[[nodiscard]] virtual const char* getType () const = 0;
|
|
||||||
/**
|
|
||||||
* @return Text of the property
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::string& getText () const;
|
|
||||||
/**
|
|
||||||
* Registers a function to be called when this instance's value changes
|
|
||||||
*
|
|
||||||
* @param callback
|
|
||||||
*/
|
|
||||||
void subscribe (const function_type& callback) const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void propagate () const override;
|
|
||||||
|
|
||||||
CProperty (std::string name, std::string text);
|
|
||||||
|
|
||||||
/** Functions to call when this property's value changes */
|
|
||||||
mutable std::vector<function_type> m_subscriptions;
|
|
||||||
/** Name of the property */
|
|
||||||
const std::string m_name;
|
|
||||||
/** Description of the property for the user */
|
|
||||||
mutable std::string m_text;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
|
@ -1,39 +0,0 @@
|
|||||||
#include <sstream>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "CPropertyBoolean.h"
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
|
||||||
|
|
||||||
std::shared_ptr<CPropertyBoolean> CPropertyBoolean::fromJSON (const json& data, std::string name) {
|
|
||||||
return std::make_shared <CPropertyBoolean> (
|
|
||||||
jsonFindRequired <bool> (data, "value", "Boolean property must have a value"),
|
|
||||||
std::move(name),
|
|
||||||
jsonFindDefault<std::string> (data, "text", "")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CPropertyBoolean::set (const std::string& value) {
|
|
||||||
this->update (value == "1" || value == "true" || value == "on");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CPropertyBoolean::dump () const {
|
|
||||||
std::stringstream ss;
|
|
||||||
|
|
||||||
ss << this->m_name << " - boolean" << std::endl
|
|
||||||
<< "\t"
|
|
||||||
<< "Description: " << this->m_text << std::endl
|
|
||||||
<< "\t"
|
|
||||||
<< "Value: " << &this->getBool ();
|
|
||||||
|
|
||||||
return ss.str ();
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* CPropertyBoolean::getType () const {
|
|
||||||
return "bool";
|
|
||||||
}
|
|
||||||
|
|
||||||
CPropertyBoolean::CPropertyBoolean (bool value, std::string name, std::string text) :
|
|
||||||
CProperty (std::move(name), std::move(text)) {}
|
|
@ -1,21 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CProperty.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a boolean property
|
|
||||||
*/
|
|
||||||
class CPropertyBoolean final : public CProperty {
|
|
||||||
public:
|
|
||||||
CPropertyBoolean (bool value, std::string name, std::string text);
|
|
||||||
|
|
||||||
static std::shared_ptr<CPropertyBoolean> fromJSON (const json& data, std::string name);
|
|
||||||
[[nodiscard]] std::string dump () const override;
|
|
||||||
void set (const std::string& value) override;
|
|
||||||
|
|
||||||
[[nodiscard]] const char* getType () const override;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
|
@ -1,55 +0,0 @@
|
|||||||
#include <sstream>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "CPropertyColor.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
|
||||||
|
|
||||||
glm::vec3 ParseColor (std::string value) {
|
|
||||||
// TODO: ENSURE THIS PARSING IS ACTUALLY ACCURATE
|
|
||||||
if (value.find (',') != std::string::npos) {
|
|
||||||
// replace commas with dots so it can be parsed
|
|
||||||
std::replace (value.begin (), value.end (), ',', ' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value.find ('.') == std::string::npos && value != "0 0 0" && value != "1 1 1") {
|
|
||||||
const glm::ivec3 intcolor = WallpaperEngine::Core::aToColori (value);
|
|
||||||
|
|
||||||
return {intcolor.r / 255.0, intcolor.g / 255.0, intcolor.b / 255.0};
|
|
||||||
}
|
|
||||||
|
|
||||||
return WallpaperEngine::Core::aToColorf (value);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<CPropertyColor> CPropertyColor::fromJSON (const json& data, std::string name) {
|
|
||||||
const auto value = jsonFindRequired <std::string> (data, "value", "Color property must have a value");
|
|
||||||
const auto text = jsonFindDefault<std::string> (data, "text", "");
|
|
||||||
|
|
||||||
return std::make_shared <CPropertyColor> (value, std::move(name), text);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPropertyColor::set (const std::string& value) {
|
|
||||||
this->update (ParseColor (std::string (value)));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CPropertyColor::dump () const {
|
|
||||||
const auto color = this->getVec3 ();
|
|
||||||
std::stringstream ss;
|
|
||||||
|
|
||||||
ss << this->m_name << " - color" << std::endl
|
|
||||||
<< "\t"
|
|
||||||
<< "Description: " << this->m_text << std::endl
|
|
||||||
<< "\t"
|
|
||||||
<< "R: " << color.r << " G: " << color.g << " B: " << color.b;
|
|
||||||
|
|
||||||
return ss.str ();
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* CPropertyColor::getType () const {
|
|
||||||
return "color";
|
|
||||||
}
|
|
||||||
|
|
||||||
CPropertyColor::CPropertyColor (const std::string& color, std::string name, std::string text) :
|
|
||||||
CProperty (std::move(name), std::move(text)) {
|
|
||||||
this->set (color);
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CProperty.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a color property
|
|
||||||
*/
|
|
||||||
class CPropertyColor final : public CProperty {
|
|
||||||
public:
|
|
||||||
CPropertyColor (const std::string& color, std::string name, std::string text);
|
|
||||||
|
|
||||||
static std::shared_ptr<CPropertyColor> fromJSON (const json& data, std::string name);
|
|
||||||
[[nodiscard]] std::string dump () const override;
|
|
||||||
void set (const std::string& value) override;
|
|
||||||
|
|
||||||
[[nodiscard]] const char* getType () const override;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
|
@ -1,107 +0,0 @@
|
|||||||
#include <sstream>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "CPropertyCombo.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
|
||||||
|
|
||||||
std::shared_ptr<CPropertyCombo> CPropertyCombo::fromJSON (const json& data, std::string name) {
|
|
||||||
std::vector<CPropertyComboValue> values;
|
|
||||||
const auto options = jsonFindRequired (data, "options", "Options for a property combo is required");
|
|
||||||
|
|
||||||
if (!options->is_array ())
|
|
||||||
sLog.exception ("Property combo options should be an array");
|
|
||||||
|
|
||||||
for (auto& cur : (*options)) {
|
|
||||||
// TODO: PROPERLY REPORT THESE ISSUES
|
|
||||||
if (!cur.is_object ())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// check for label and value to ensure they're there
|
|
||||||
values.push_back ({
|
|
||||||
.label = jsonFindRequired<std::string> (cur, "label", "Label is required for a property combo option"),
|
|
||||||
.value = jsonFindRequired<std::string> (cur, "value", "Value is required for a property combo option")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::make_shared <CPropertyCombo> (
|
|
||||||
std::move(name),
|
|
||||||
jsonFindDefault<std::string> (data, "text", ""),
|
|
||||||
jsonFindRequired<std::string> (data, "value", "Value is required for a property combo"),
|
|
||||||
values
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
CPropertyCombo::CPropertyCombo (
|
|
||||||
std::string name, std::string text, const std::string& defaultValue,
|
|
||||||
std::vector<CPropertyComboValue> values
|
|
||||||
) :
|
|
||||||
CProperty (std::move(name), std::move(text)),
|
|
||||||
m_values (std::move(values)) {
|
|
||||||
this->set (defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CPropertyCombo::dump () const {
|
|
||||||
std::stringstream ss;
|
|
||||||
|
|
||||||
ss << this->m_name << " - combolist" << std::endl
|
|
||||||
<< "\t"
|
|
||||||
<< "Description: " << this->m_text << std::endl
|
|
||||||
<< "\t"
|
|
||||||
<< "Value: " << &this->getInt () << std::endl
|
|
||||||
<< "\t\t"
|
|
||||||
<< "Posible values:" << std::endl;
|
|
||||||
|
|
||||||
for (const auto& cur : this->m_values)
|
|
||||||
ss << "\t\t" << cur.label << " -> " << cur.value << std::endl;
|
|
||||||
|
|
||||||
return ss.str ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPropertyCombo::set (const std::string& value) {
|
|
||||||
bool found = false;
|
|
||||||
int index = 0;
|
|
||||||
|
|
||||||
// ensure the value is present somewhere in the value list
|
|
||||||
for (const auto& cur : this->m_values) {
|
|
||||||
if (cur.value == value) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
index ++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found)
|
|
||||||
sLog.exception ("Assigning invalid value to property ", this->m_name);
|
|
||||||
|
|
||||||
this->update (index);
|
|
||||||
}
|
|
||||||
|
|
||||||
int CPropertyCombo::translateValueToIndex (const std::string& value) const {
|
|
||||||
bool found = false;
|
|
||||||
int index = 0;
|
|
||||||
|
|
||||||
// ensure the value is present somewhere in the value list
|
|
||||||
for (const auto& cur : this->m_values) {
|
|
||||||
if (cur.value == value) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
index ++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* CPropertyCombo::getType () const {
|
|
||||||
return "combo";
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CProperty.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents different combo values
|
|
||||||
*/
|
|
||||||
struct CPropertyComboValue {
|
|
||||||
public:
|
|
||||||
const std::string label;
|
|
||||||
const std::string value;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a combo property
|
|
||||||
*
|
|
||||||
* Combos are properties that have different values available and only one can be selected at once
|
|
||||||
* this limits the user's possibilities, used for things like the amount of samples to use in audioprocessing
|
|
||||||
* backgrounds
|
|
||||||
*/
|
|
||||||
class CPropertyCombo final : public CProperty {
|
|
||||||
public:
|
|
||||||
static std::shared_ptr<CPropertyCombo> fromJSON (const json& data, std::string name);
|
|
||||||
|
|
||||||
CPropertyCombo (
|
|
||||||
std::string name, std::string text, const std::string& defaultValue,
|
|
||||||
std::vector<CPropertyComboValue> values);
|
|
||||||
|
|
||||||
[[nodiscard]] std::string dump () const override;
|
|
||||||
void set (const std::string& value) override;
|
|
||||||
int translateValueToIndex (const std::string& value) const;
|
|
||||||
|
|
||||||
[[nodiscard]] const char* getType () const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** List of values available to select */
|
|
||||||
const std::vector<CPropertyComboValue> m_values;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
|
@ -1,67 +0,0 @@
|
|||||||
#include "CPropertySlider.h"
|
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
|
||||||
|
|
||||||
std::shared_ptr<CPropertySlider> CPropertySlider::fromJSON (const json& data, const std::string& name) {
|
|
||||||
const auto value = data.find ("value");
|
|
||||||
const auto text = jsonFindDefault<std::string> (data, "text", "");
|
|
||||||
const auto min = jsonFindDefault (data, "min", 0.0f);
|
|
||||||
const auto max = jsonFindDefault (data, "max", 0.0f);
|
|
||||||
const auto step = jsonFindDefault (data, "step", 0.0f);
|
|
||||||
|
|
||||||
return std::make_shared <CPropertySlider> (*value, name, text, min, max, step);
|
|
||||||
}
|
|
||||||
|
|
||||||
const float& CPropertySlider::getMinValue () const {
|
|
||||||
return this->m_min;
|
|
||||||
}
|
|
||||||
|
|
||||||
const float& CPropertySlider::getMaxValue () const {
|
|
||||||
return this->m_max;
|
|
||||||
}
|
|
||||||
|
|
||||||
const float& CPropertySlider::getStep () const {
|
|
||||||
return this->m_step;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CPropertySlider::dump () const {
|
|
||||||
std::stringstream ss;
|
|
||||||
|
|
||||||
ss << this->m_name << " - slider" << std::endl
|
|
||||||
<< "\t"
|
|
||||||
<< "Description: " << this->m_text << std::endl
|
|
||||||
<< "\t"
|
|
||||||
<< "Value: " << &this->getFloat () << std::endl
|
|
||||||
<< "\t"
|
|
||||||
<< "Minimum value: " << this->m_min << std::endl
|
|
||||||
<< "\t"
|
|
||||||
<< "Maximum value: " << this->m_max << std::endl
|
|
||||||
<< "\t"
|
|
||||||
<< "Step: " << this->m_step << std::endl;
|
|
||||||
|
|
||||||
return ss.str ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPropertySlider::set (const std::string& value) {
|
|
||||||
const auto newValue = strtof (value.c_str (), nullptr);
|
|
||||||
|
|
||||||
if (newValue < this->m_min || newValue > this->m_max)
|
|
||||||
sLog.exception ("Slider value (", newValue, ") is out of range (", this->m_min, ",", this->m_max, ")");
|
|
||||||
|
|
||||||
this->update (newValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* CPropertySlider::getType () const {
|
|
||||||
return "slider";
|
|
||||||
}
|
|
||||||
|
|
||||||
CPropertySlider::CPropertySlider (float value, const std::string& name, const std::string& text, float min,
|
|
||||||
float max, float step) :
|
|
||||||
CProperty (name, text),
|
|
||||||
m_min (min),
|
|
||||||
m_max (max),
|
|
||||||
m_step (step) {
|
|
||||||
this->update (value);
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CProperty.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a slider value with a minimum and maximum value
|
|
||||||
*/
|
|
||||||
class CPropertySlider final : public CProperty {
|
|
||||||
public:
|
|
||||||
CPropertySlider (float value, const std::string& name, const std::string& text, float min, float max, float step);
|
|
||||||
|
|
||||||
static std::shared_ptr<CPropertySlider> fromJSON (const json& data, const std::string& name);
|
|
||||||
/**
|
|
||||||
* @return The slider's minimum value
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const float& getMinValue () const;
|
|
||||||
/**
|
|
||||||
* @return The slider's maximum value
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const float& getMaxValue () const;
|
|
||||||
/**
|
|
||||||
* @return The slider's value increment steps, only really used in the UI
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const float& getStep () const;
|
|
||||||
[[nodiscard]] std::string dump () const override;
|
|
||||||
void set (const std::string& value) override;
|
|
||||||
|
|
||||||
[[nodiscard]] const char* getType () const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** Minimum value */
|
|
||||||
const float m_min;
|
|
||||||
/** Maximum value */
|
|
||||||
const float m_max;
|
|
||||||
/** Increment steps for the slider in the UI */
|
|
||||||
const float m_step;
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
|
@ -1,32 +0,0 @@
|
|||||||
#include "CPropertyText.h"
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
|
||||||
#include <sstream>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
|
||||||
|
|
||||||
std::shared_ptr<CPropertyText> CPropertyText::fromJSON (const json& data, std::string name) {
|
|
||||||
//TODO: VALIDATE THIS IS RIGHT
|
|
||||||
return std::make_shared <CPropertyText> (std::move(name), *data.find ("type"));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CPropertyText::dump () const {
|
|
||||||
std::stringstream ss;
|
|
||||||
|
|
||||||
ss << this->m_name << " - text" << std::endl
|
|
||||||
<< "\t"
|
|
||||||
<< "Value: " << this->m_text;
|
|
||||||
|
|
||||||
return ss.str ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPropertyText::set (const std::string& value) {
|
|
||||||
this->m_text = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* CPropertyText::getType () const {
|
|
||||||
return "text";
|
|
||||||
}
|
|
||||||
|
|
||||||
CPropertyText::CPropertyText (std::string name, std::string text) :
|
|
||||||
CProperty (std::move(name), std::move(text)) {}
|
|
@ -1,22 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CProperty.h"
|
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Projects {
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a text property
|
|
||||||
*/
|
|
||||||
class CPropertyText final : public CProperty {
|
|
||||||
public:
|
|
||||||
CPropertyText (std::string name, std::string text);
|
|
||||||
|
|
||||||
static std::shared_ptr<CPropertyText> fromJSON (const json& data, std::string name);
|
|
||||||
[[nodiscard]] std::string dump () const override;
|
|
||||||
void set (const std::string& value) override;
|
|
||||||
|
|
||||||
[[nodiscard]] const char* getType () const override;
|
|
||||||
private:
|
|
||||||
};
|
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user