diff --git a/src/WallpaperEngine/Application/CApplicationContext.cpp b/src/WallpaperEngine/Application/CApplicationContext.cpp index 58b94f5..ba1c098 100644 --- a/src/WallpaperEngine/Application/CApplicationContext.cpp +++ b/src/WallpaperEngine/Application/CApplicationContext.cpp @@ -296,7 +296,7 @@ void CApplicationContext::validateAssets () { } } -void CApplicationContext::validateScreenshot () { +void CApplicationContext::validateScreenshot () const { if (!this->settings.screenshot.take) return; diff --git a/src/WallpaperEngine/Application/CApplicationContext.h b/src/WallpaperEngine/Application/CApplicationContext.h index 06294f7..66b1592 100644 --- a/src/WallpaperEngine/Application/CApplicationContext.h +++ b/src/WallpaperEngine/Application/CApplicationContext.h @@ -123,7 +123,7 @@ class CApplicationContext { /** * Validates the screenshot settings */ - void validateScreenshot (); + void validateScreenshot () const; /** * Validates a background parameter and returns the real bgIdOrPath to it diff --git a/src/WallpaperEngine/Application/CApplicationState.cpp b/src/WallpaperEngine/Application/CApplicationState.cpp deleted file mode 100644 index 315d0c7..0000000 --- a/src/WallpaperEngine/Application/CApplicationState.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "CApplicationState.h" diff --git a/src/WallpaperEngine/Application/CWallpaperApplication.cpp b/src/WallpaperEngine/Application/CWallpaperApplication.cpp index 496a4c4..caf806c 100644 --- a/src/WallpaperEngine/Application/CWallpaperApplication.cpp +++ b/src/WallpaperEngine/Application/CWallpaperApplication.cpp @@ -211,7 +211,9 @@ void CWallpaperApplication::setupProperties () { } void CWallpaperApplication::setupBrowser () { - bool anyWebProject = std::any_of (this->m_backgrounds.begin (), this->m_backgrounds.end (), [](std::pair pair) -> bool { + bool anyWebProject = std::any_of ( + this->m_backgrounds.begin (), this->m_backgrounds.end (), + [](const std::pair& pair) -> bool { return pair.second->getWallpaper()->is (); }); @@ -403,10 +405,13 @@ void CWallpaperApplication::prepareOutputs () { // set all the specific wallpapers required for (const auto& [background, info] : this->m_backgrounds) { - m_renderContext->setWallpaper (background, - WallpaperEngine::Render::CWallpaper::fromWallpaper ( - info->getWallpaper (), *m_renderContext, *m_audioContext, *m_browserContext, - this->m_context.settings.general.screenScalings [background])); + m_renderContext->setWallpaper ( + background, + WallpaperEngine::Render::CWallpaper::fromWallpaper ( + info->getWallpaper (), *m_renderContext, *m_audioContext, *m_browserContext, + this->m_context.settings.general.screenScalings [background] + ) + ); } } diff --git a/src/WallpaperEngine/Assets/CPackage.cpp b/src/WallpaperEngine/Assets/CPackage.cpp index 4a3da0d..99fbe0b 100644 --- a/src/WallpaperEngine/Assets/CPackage.cpp +++ b/src/WallpaperEngine/Assets/CPackage.cpp @@ -11,7 +11,7 @@ using namespace WallpaperEngine::Assets; class CPackageEntry { public: CPackageEntry (std::string filename, uint32_t offset, uint32_t length) : - filename (std::move (filename)), + filename (filename), offset (offset), length (length) {} diff --git a/src/WallpaperEngine/Audio/CAudioStream.cpp b/src/WallpaperEngine/Audio/CAudioStream.cpp index a6d4535..3f2649e 100644 --- a/src/WallpaperEngine/Audio/CAudioStream.cpp +++ b/src/WallpaperEngine/Audio/CAudioStream.cpp @@ -6,7 +6,8 @@ // maximum size of the queue to prevent reading too much data #define MAX_QUEUE_SIZE (5 * 1024 * 1024) -#define MIN_FRAMES 25 +#define MIN_FRAMES (25) +#define NO_AUDIO_STREAM (-1) using namespace WallpaperEngine::Audio; @@ -82,7 +83,6 @@ int64_t audio_seek_data_callback (void* streamarg, int64_t offset, int whence) { switch (whence) { case SEEK_CUR: stream->setPosition (stream->getPosition () + offset); break; - case SEEK_SET: stream->setPosition (offset); break; } @@ -91,12 +91,14 @@ int64_t audio_seek_data_callback (void* streamarg, int64_t offset, int whence) { CAudioStream::CAudioStream (CAudioContext& context, const std::string& filename) : m_swrctx (nullptr), + m_audioStream(NO_AUDIO_STREAM), m_audioContext (context) { this->loadCustomContent (filename.c_str ()); } CAudioStream::CAudioStream (CAudioContext& context, const uint8_t* buffer, uint32_t length) : m_swrctx (nullptr), + m_audioStream(NO_AUDIO_STREAM), m_audioContext (context) { // setup a custom context first this->m_formatContext = avformat_alloc_context (); @@ -122,6 +124,7 @@ CAudioStream::CAudioStream (CAudioContext& context, const uint8_t* buffer, uint3 CAudioStream::CAudioStream (CAudioContext& audioContext, AVCodecContext* context) : m_swrctx (nullptr), m_audioContext (audioContext), + m_audioStream(NO_AUDIO_STREAM), m_context (context), m_queue (new PacketQueue) { this->initialize (); @@ -142,17 +145,14 @@ void CAudioStream::loadCustomContent (const char* filename) { if (avformat_find_stream_info (this->m_formatContext, nullptr) < 0) sLog.exception ("Cannot determine file format: ", filename); - bool hasAudioStream = false; - // find the audio stream for (unsigned int i = 0; i < this->m_formatContext->nb_streams; i++) { - if (this->m_formatContext->streams [i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && !hasAudioStream) { - hasAudioStream = true; + if (this->m_formatContext->streams [i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && this->m_audioStream == NO_AUDIO_STREAM) { this->m_audioStream = i; } } - if (!hasAudioStream) + if (this->m_audioStream == NO_AUDIO_STREAM) sLog.exception ("Cannot find an audio stream in file ", filename); // get the decoder for it and alloc the required context @@ -282,7 +282,7 @@ bool CAudioStream::doQueue (AVPacket* pkt) { } void CAudioStream::dequeuePacket (AVPacket* output) { - MyAVPacketList entry; + MyAVPacketList entry{}; SDL_LockMutex (this->m_queue->mutex); @@ -368,6 +368,10 @@ int CAudioStream::getQueuePacketCount () { } AVRational CAudioStream::getTimeBase () { + if (this->m_audioStream == NO_AUDIO_STREAM) { + return {0, 0}; + } + return this->m_formatContext->streams [this->m_audioStream]->time_base; } diff --git a/src/WallpaperEngine/Core/CObject.cpp b/src/WallpaperEngine/Core/CObject.cpp index 52062d1..a8cd5e5 100644 --- a/src/WallpaperEngine/Core/CObject.cpp +++ b/src/WallpaperEngine/Core/CObject.cpp @@ -6,7 +6,6 @@ #include "WallpaperEngine/Core/Objects/CSound.h" #include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h" #include "WallpaperEngine/Core/Wallpapers/CScene.h" -#include #include "WallpaperEngine/Assets/CContainer.h" #include "WallpaperEngine/Logging/CLog.h" @@ -15,48 +14,57 @@ using namespace WallpaperEngine::Core; using namespace WallpaperEngine::Assets; using namespace WallpaperEngine::Core::UserSettings; -CObject::CObject (Wallpapers::CScene* scene, CUserSettingBoolean* visible, int id, std::string name, std::string type, - CUserSettingVector3* origin, CUserSettingVector3* scale, const glm::vec3& angles) : - m_type (std::move (type)), +CObject::CObject ( + const Wallpapers::CScene* scene, const CUserSettingBoolean* visible, int id, std::string name, std::string type, + const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles, std::vector dependencies +) : + m_type (type), m_visible (visible), m_id (id), - m_name (std::move (name)), + m_name (name), m_origin (origin), m_scale (scale), m_angles (angles), - m_scene (scene) {} + m_scene (scene), + m_dependencies (dependencies) {} -CObject* CObject::fromJSON (json data, Wallpapers::CScene* scene, CContainer* container) { - std::string json = data.dump (); +const CObject* CObject::fromJSON ( + const json& data, const Wallpapers::CScene* scene, const CContainer* container +) { + const auto id = jsonFindRequired (data, "id", "Objects must have id"); + const auto visible = jsonFindUserConfig (data, "visible", true); + const auto origin = jsonFindUserConfig (data, "origin", {0, 0, 0}); + const auto scale = jsonFindUserConfig (data, "scale", {1, 1, 1}); + const auto angles_val = jsonFindDefault (data, "angles", glm::vec3 (0, 0, 0)); + const auto name = jsonFindRequired (data, "name", "Objects must have name"); + const auto effects_it = data.find ("effects"); + const auto dependencies_it = data.find ("dependencies"); - auto id_it = jsonFindRequired (data, "id", "Objects must have id"); - auto visible = jsonFindUserConfig (data, "visible", true); - auto origin = jsonFindUserConfig (data, "origin", {0, 0, 0}); - auto scale = jsonFindUserConfig (data, "scale", {1, 1, 1}); - auto angles_val = jsonFindDefault (data, "angles", "0.0 0.0 0.0"); - auto name_it = jsonFindRequired (data, "name", "Objects must have name"); - auto effects_it = data.find ("effects"); - 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"); - auto image_it = data.find ("image"); - auto sound_it = data.find ("sound"); - auto particle_it = data.find ("particle"); - auto text_it = data.find ("text"); - auto light_it = data.find ("light"); + std::vector dependencies; + std::vector effects; - CObject* object; + 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 (scene, data, container, visible, *id_it, *name_it, origin, scale, - WallpaperEngine::Core::aToVector3 (angles_val)); + object = Objects::CImage::fromJSON ( + scene, 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 (scene, data, visible, *id_it, *name_it, origin, scale, - WallpaperEngine::Core::aToVector3 (angles_val)); + object = Objects::CSound::fromJSON (scene, 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 (scene, particle_it->get (), container, visible, *id_it, - *name_it, origin, scale); + object = Objects::CParticle::fromFile ( + scene, particle_it->get (), container, visible, id, name, origin, scale, dependencies); } catch (std::runtime_error&) { return nullptr; } @@ -67,32 +75,17 @@ CObject* CObject::fromJSON (json data, Wallpapers::CScene* scene, CContainer* co /// TODO: XXXHACK -- TO REMOVE WHEN LIGHT SUPPORT IS IMPLEMENTED return nullptr; } else { - sLog.exception ("Unknown object type detected: ", *name_it); + sLog.exception ("Unknown object type detected: ", name); } - if (effects_it != data.end () && effects_it->is_array ()) { - for (auto& cur : *effects_it) { - auto effectVisible = jsonFindUserConfig (cur, "visible", true); - - if (!effectVisible->processValue (scene->getProject ().getProperties ())) - continue; - - object->insertEffect (Objects::CEffect::fromJSON (cur, effectVisible, object, container)); - } - } - - if (dependencies_it != data.end () && dependencies_it->is_array ()) - for (const auto& cur : *dependencies_it) - object->insertDependency (cur); - return object; } -glm::vec3 CObject::getOrigin () const { +const glm::vec3& CObject::getOrigin () const { return this->m_origin->processValue (this->getScene ()->getProject ().getProperties ()); } -glm::vec3 CObject::getScale () const { +const glm::vec3& CObject::getScale () const { return this->m_scale->processValue (this->getScene ()->getProject ().getProperties ()); } @@ -104,10 +97,6 @@ const std::string& CObject::getName () const { return this->m_name; } -const std::vector& CObject::getEffects () const { - return this->m_effects; -} - const std::vector& CObject::getDependencies () const { return this->m_dependencies; } @@ -117,18 +106,10 @@ bool CObject::isVisible () const { return this->m_visible->processValue (this->getScene ()->getProject ().getProperties ()); } -Wallpapers::CScene* CObject::getScene () const { +const Wallpapers::CScene* CObject::getScene () const { return this->m_scene; } int CObject::getId () const { return this->m_id; } - -void CObject::insertEffect (Objects::CEffect* effect) { - this->m_effects.push_back (effect); -} - -void CObject::insertDependency (int dependency) { - this->m_dependencies.push_back (dependency); -} \ No newline at end of file diff --git a/src/WallpaperEngine/Core/CObject.h b/src/WallpaperEngine/Core/CObject.h index e99bc31..004bcfc 100644 --- a/src/WallpaperEngine/Core/CObject.h +++ b/src/WallpaperEngine/Core/CObject.h @@ -29,7 +29,7 @@ class CObject { friend class Wallpapers::CScene; public: - static CObject* fromJSON (json data, Wallpapers::CScene* scene, CContainer* container); + static const CObject* fromJSON (const json& data, const Wallpapers::CScene* scene, const CContainer* container); template const T* as () const { assert (is ()); @@ -41,42 +41,39 @@ class CObject { return reinterpret_cast (this); } - template bool is () { + template bool is () const { return this->m_type == T::Type; } - [[nodiscard]] const std::vector& getEffects () const; [[nodiscard]] const std::vector& getDependencies () const; [[nodiscard]] int getId () const; - [[nodiscard]] glm::vec3 getOrigin () const; - [[nodiscard]] glm::vec3 getScale () 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]] Wallpapers::CScene* getScene () const; + [[nodiscard]] const Wallpapers::CScene* getScene () const; protected: - CObject (Wallpapers::CScene* scene, CUserSettingBoolean* visible, int id, std::string name, std::string type, - CUserSettingVector3* origin, CUserSettingVector3* scale, const glm::vec3& angles); - - void insertEffect (Objects::CEffect* effect); - void insertDependency (int dependency); + CObject ( + const Wallpapers::CScene* scene, const CUserSettingBoolean* visible, int id, std::string name, std::string type, + const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles, + std::vector dependencies); private: - std::string m_type; + const std::string m_type; - CUserSettingBoolean* m_visible; + const CUserSettingBoolean* m_visible; int m_id; - std::string m_name; - CUserSettingVector3* m_origin; - CUserSettingVector3* m_scale; - glm::vec3 m_angles; + const std::string m_name; + const CUserSettingVector3* m_origin; + const CUserSettingVector3* m_scale; + const glm::vec3 m_angles; - std::vector m_effects; - std::vector m_dependencies; + const std::vector m_dependencies; - Wallpapers::CScene* m_scene; + const Wallpapers::CScene* m_scene; }; } // namespace WallpaperEngine::Core diff --git a/src/WallpaperEngine/Core/CProject.cpp b/src/WallpaperEngine/Core/CProject.cpp index b51ad84..cd2ac5b 100644 --- a/src/WallpaperEngine/Core/CProject.cpp +++ b/src/WallpaperEngine/Core/CProject.cpp @@ -1,7 +1,5 @@ #include -#include - #include "CProject.h" #include "WallpaperEngine/Core/Wallpapers/CScene.h" #include "WallpaperEngine/Core/Wallpapers/CVideo.h" @@ -14,65 +12,68 @@ using namespace WallpaperEngine::Assets; static int backgroundId = -1; -CProject::CProject (std::string title, std::string type, std::string workshopid, CContainer* container) : - m_workshopid(std::move(workshopid)), - m_title (std::move (title)), - m_type (std::move (type)), +CProject::CProject (std::string title, std::string type, std::string workshopid, const CContainer* container) : + m_workshopid(workshopid), + m_title (title), + m_type (type), m_wallpaper (nullptr), - m_container (container) -{} + m_container (container) {} -CProject* CProject::fromFile (const std::string& filename, CContainer* container) { +CProject* CProject::fromFile (std::string filename, const CContainer* container) { json content = json::parse (container->readFileAsString (filename)); - std::string dependency = jsonFindDefault (content, "dependency", "No dependency"); - if (dependency == "No dependency") { - // workshopid is not required, but we have to use it for some identification stuff, - // so using a static, decreasing number should be enough - std::string workshopid = jsonFindDefault (content, "workshopid", std::to_string (backgroundId--)); - std::string title = *jsonFindRequired (content, "title", "Project title missing"); - std::string type = *jsonFindRequired (content, "type", "Project type missing"); - std::string file = *jsonFindRequired (content, "file", "Project's main file missing"); - auto general = content.find ("general"); - CWallpaper* wallpaper; + const auto dependency = jsonFindDefault (content, "dependency", "No dependency"); - std::transform (type.begin (), type.end (), type.begin (), tolower); - - CProject* project = new CProject (title, type, workshopid, container); - - if (type == "scene") - wallpaper = CScene::fromFile (file, *project, container); - else if (type == "video") - wallpaper = new CVideo (file.c_str (), *project); - else if (type == "web") - wallpaper = new CWeb (file.c_str (), *project); - else - sLog.exception ("Unsupported wallpaper type: ", type); - - project->setWallpaper (wallpaper); - - if (general != content.end ()) { - const auto properties = general->find ("properties"); - - if (properties != general->end ()) { - for (const auto& cur : properties->items ()) { - Projects::CProperty* property = Projects::CProperty::fromJSON (cur.value (), cur.key ()); - if (property != nullptr) - project->insertProperty (property); - } - } - } - return project; - } else { + 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 + auto type = jsonFindRequired (content, "type", "Project type missing"); + const auto file = jsonFindRequired (content, "file", "Project's main file missing"); + auto general = content.find ("general"); + const CWallpaper* wallpaper; + + std::transform (type.begin (), type.end (), type.begin (), tolower); + + CProject* project = new CProject ( + jsonFindRequired (content, "title", "Project title missing"), + type, + jsonFindDefault (content, "workshopid", std::to_string (backgroundId--)), + container + ); + + if (type == "scene") + wallpaper = CScene::fromFile (file, *project, container); + else if (type == "video") + wallpaper = new CVideo (file, *project); + else if (type == "web") + wallpaper = new CWeb (file, *project); + else + sLog.exception ("Unsupported wallpaper type: ", type); + + project->setWallpaper (wallpaper); + + if (general != content.end ()) { + const auto properties = general->find ("properties"); + + if (properties != general->end ()) { + for (const auto& cur : properties->items ()) { + const auto property = Projects::CProperty::fromJSON (cur.value (), cur.key ()); + if (property != nullptr) + project->insertProperty (property); + } + } + } + return project; } -void CProject::setWallpaper (CWallpaper* wallpaper) { +void CProject::setWallpaper (const CWallpaper* wallpaper) { this->m_wallpaper = wallpaper; } -CWallpaper* CProject::getWallpaper () const { +const CWallpaper* CProject::getWallpaper () const { return this->m_wallpaper; } @@ -84,7 +85,7 @@ const std::string& CProject::getType () const { return this->m_type; } -const std::vector& CProject::getProperties () const { +const std::vector& CProject::getProperties () const { return this->m_properties; } @@ -92,10 +93,10 @@ const std::string& CProject::getWorkshopId () const { return this->m_workshopid; } -CContainer* CProject::getContainer () { +const CContainer* CProject::getContainer () const { return this->m_container; } -void CProject::insertProperty (Projects::CProperty* property) { +void CProject::insertProperty (const Projects::CProperty* property) { this->m_properties.push_back (property); } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/CProject.h b/src/WallpaperEngine/Core/CProject.h index 3bb7aa7..37c1de0 100644 --- a/src/WallpaperEngine/Core/CProject.h +++ b/src/WallpaperEngine/Core/CProject.h @@ -14,30 +14,30 @@ class CWallpaper; class CProject { public: - static CProject* fromFile (const std::string& filename, CContainer* container); + static CProject* fromFile (std::string filename, const CContainer* container); - [[nodiscard]] CWallpaper* getWallpaper () const; + [[nodiscard]] const CWallpaper* getWallpaper () const; [[nodiscard]] const std::string& getTitle () const; [[nodiscard]] const std::string& getType () const; - [[nodiscard]] const std::vector& getProperties () const; + [[nodiscard]] const std::vector& getProperties () const; [[nodiscard]] const std::string& getWorkshopId () const; - CContainer* getContainer (); + const CContainer* getContainer () const; protected: - CProject (std::string title, std::string type, std::string workshopid, CContainer* container); + CProject (std::string title, std::string type, std::string workshopid, const CContainer* container); - void setWallpaper (CWallpaper* wallpaper); - void insertProperty (Projects::CProperty* property); + void setWallpaper (const CWallpaper* wallpaper); + void insertProperty (const Projects::CProperty* property); private: - std::vector m_properties; + std::vector m_properties; - std::string m_workshopid; - std::string m_title; - std::string m_type; - CWallpaper* m_wallpaper; - CContainer* m_container; + const std::string m_workshopid; + const std::string m_title; + const std::string m_type; + const CWallpaper* m_wallpaper; + const CContainer* m_container; }; } // namespace WallpaperEngine::Core diff --git a/src/WallpaperEngine/Core/CWallpaper.cpp b/src/WallpaperEngine/Core/CWallpaper.cpp index c3e848a..c59b66f 100644 --- a/src/WallpaperEngine/Core/CWallpaper.cpp +++ b/src/WallpaperEngine/Core/CWallpaper.cpp @@ -4,8 +4,10 @@ using namespace WallpaperEngine::Core; -CWallpaper::CWallpaper (std::string type, CProject& project) : m_project (project), m_type (std::move (type)) {} +CWallpaper::CWallpaper (std::string type, const CProject& project) : + m_project (project), + m_type (type) {} -CProject& CWallpaper::getProject () const { +const CProject& CWallpaper::getProject () const { return this->m_project; } diff --git a/src/WallpaperEngine/Core/CWallpaper.h b/src/WallpaperEngine/Core/CWallpaper.h index 780e2c9..c47a42a 100644 --- a/src/WallpaperEngine/Core/CWallpaper.h +++ b/src/WallpaperEngine/Core/CWallpaper.h @@ -20,20 +20,20 @@ class CWallpaper { return reinterpret_cast (this); } - template bool is () { + template bool is () const { return this->m_type == T::Type; } - CWallpaper (std::string type, CProject& project); + CWallpaper (std::string type, const CProject& project); - CProject& getProject () const; + const CProject& getProject () const; protected: friend class CProject; private: - CProject& m_project; + const CProject& m_project; - std::string m_type; + const std::string m_type; }; } // namespace WallpaperEngine::Core diff --git a/src/WallpaperEngine/Core/Core.cpp b/src/WallpaperEngine/Core/Core.cpp index 4003464..a8fe063 100644 --- a/src/WallpaperEngine/Core/Core.cpp +++ b/src/WallpaperEngine/Core/Core.cpp @@ -44,6 +44,42 @@ glm::vec2 Core::aToVector2 (const char* str) { return {x, y}; } +glm::ivec4 Core::aToVector4i (const char* str) { + int x = strtol (str, const_cast (&str), 10); + while (*str == ' ') + str++; + int y = strtol (str, const_cast (&str), 10); + while (*str == ' ') + str++; + int z = strtol (str, const_cast (&str), 10); + while (*str == ' ') + str++; + int w = strtol (str, const_cast (&str), 10); + + return {x, y, z, w}; +} + +glm::ivec3 Core::aToVector3i (const char* str) { + int x = strtol (str, const_cast (&str), 10); + while (*str == ' ') + str++; + int y = strtol (str, const_cast (&str), 10); + while (*str == ' ') + str++; + int z = strtol (str, const_cast (&str), 10); + + return {x, y, z}; +} + +glm::ivec2 Core::aToVector2i (const char* str) { + int x = strtol (str, const_cast (&str), 10); + while (*str == ' ') + str++; + int y = strtol (str, const_cast (&str), 10); + + return {x, y}; +} + glm::vec4 Core::aToVector4 (const std::string& str) { return Core::aToVector4 (str.c_str ()); } @@ -56,6 +92,18 @@ 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 (&str)); while (*str == ' ') @@ -88,17 +136,172 @@ glm::ivec3 Core::aToColori (const std::string& str) { return aToColori (str.c_str ()); } -nlohmann::json::iterator Core::jsonFindRequired (nlohmann::json& data, const char* key, const char* notFoundMsg) { - auto value = data.find (key); +template bool typeCheck (const nlohmann::json::const_iterator& value) { + if (value->type () == nlohmann::detail::value_t::null) { + return false; + } - if (value == data.end ()) - sLog.exception ("Cannot find required key (", key, ") in json: ", notFoundMsg); + // type checks + if constexpr ((std::is_same_v || std::is_same_v) ) { + 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) { + if (value->type () != nlohmann::detail::value_t::string) { + return false; + } + } else if constexpr (std::is_same_v) { + if (value->type () != nlohmann::detail::value_t::boolean) { + return false; + } + } - return value; + return true; } -nlohmann::json::iterator Core::jsonFindRequired (const nlohmann::json::iterator& data, const char* key, - const char* notFoundMsg) { +template const T Core::jsonFindRequired ( + const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg +) { + const auto iterator = jsonFindRequired (data, key, notFoundMsg); + +#define GET_TEMPLATE_NAME(T) (#T) + + // vector types need of special handling + if constexpr (std::is_same_v) { + if (!typeCheck (iterator)) { + sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string"); + } + + return aToVector4 (*iterator); + } else if constexpr (std::is_same_v) { + if (!typeCheck (iterator)) { + sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string"); + } + + return aToVector3 (*iterator); + } else if constexpr (std::is_same_v) { + if (!typeCheck (iterator)) { + sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string"); + } + + return aToVector2 (*iterator); + } else if constexpr (std::is_same_v) { + if (!typeCheck (iterator)) { + sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string"); + } + + return aToVector4i (*iterator); + } else if constexpr (std::is_same_v) { + if (!typeCheck (iterator)) { + sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string"); + } + + return aToVector3i (*iterator); + } else if constexpr (std::is_same_v) { + if (!typeCheck (iterator)) { + sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string"); + } + + return aToVector2i (*iterator); + } else if (typeCheck (iterator)) { + return *iterator; + } + + sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected ", GET_TEMPLATE_NAME (T)); +#undef GET_TEMPLATE_NAME +} + +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 const T Core::jsonFindRequired ( + const nlohmann::json& data, const char* key, const char* notFoundMsg +) { + const auto iterator = jsonFindRequired (data, key, notFoundMsg); + +#define GET_TEMPLATE_NAME(T) (#T) + + // vector types need of special handling + if constexpr (std::is_same_v) { + if (!typeCheck (iterator)) { + sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string"); + } + + return aToVector4 (*iterator); + } else if constexpr (std::is_same_v) { + if (!typeCheck (iterator)) { + sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string"); + } + + return aToVector3 (*iterator); + } else if constexpr (std::is_same_v) { + if (!typeCheck (iterator)) { + sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string"); + } + + return aToVector2 (*iterator); + } else if constexpr (std::is_same_v) { + if (!typeCheck (iterator)) { + sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string"); + } + + return aToVector4i (*iterator); + } else if constexpr (std::is_same_v) { + if (!typeCheck (iterator)) { + sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string"); + } + + return aToVector3i (*iterator); + } else if constexpr (std::is_same_v) { + if (!typeCheck (iterator)) { + sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string"); + } + + return aToVector2i (*iterator); + } else if (typeCheck (iterator)) { + return *iterator; + } + + sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected ", GET_TEMPLATE_NAME (T)); +#undef GET_TEMPLATE_NAME +} + +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); + +const 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 ()) @@ -107,46 +310,184 @@ nlohmann::json::iterator Core::jsonFindRequired (const nlohmann::json::iterator& return value; } -template T Core::jsonFindDefault (nlohmann::json& data, const char* key, T defaultValue) { +const 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 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; + + +#define GET_TEMPLATE_NAME(T) (#T) + + // vector types need of special handling + if constexpr (std::is_same_v) { + if (!typeCheck (value)) { + return defaultValue; + } + + return aToVector4 (*value); + } else if constexpr (std::is_same_v) { + if (!typeCheck (value)) { + return defaultValue; + } + + return aToVector3 (*value); + } else if constexpr (std::is_same_v) { + if (!typeCheck (value)) { + return defaultValue; + } + + return aToVector2 (*value); + } else if constexpr (std::is_same_v) { + if (!typeCheck (value)) { + return defaultValue; + } + + return aToVector4i (*value); + } else if constexpr (std::is_same_v) { + if (!typeCheck (value)) { + return defaultValue; + } + + return aToVector3i (*value); + } else if constexpr (std::is_same_v) { + if (!typeCheck (value)) { + return defaultValue; + } + + return aToVector2i (*value); + } else if (typeCheck (value)) { + return *value; + } + + return defaultValue; +#undef GET_TEMPLATE_NAME +} + +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 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; - // type checks - if ((std::is_same_v || std::is_same_v) ) { - 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) { - sLog.error (key, " is not of type double or integer, returning default value"); + +#define GET_TEMPLATE_NAME(T) (#T) + + // vector types need of special handling + if constexpr (std::is_same_v) { + if (!typeCheck (value)) { return defaultValue; } - } else if (std::is_same_v && value->type () != nlohmann::detail::value_t::string) { - sLog.error (key, " is not of type string, returning default value"); - return defaultValue; - } else if (std::is_same_v && value->type () != nlohmann::detail::value_t::boolean) { - sLog.error (key, " is not of type boolean, returning default value"); - return defaultValue; + + return aToVector4 (*value); + } else if constexpr (std::is_same_v) { + if (!typeCheck (value)) { + return defaultValue; + } + + return aToVector3 (*value); + } else if constexpr (std::is_same_v) { + if (!typeCheck (value)) { + return defaultValue; + } + + return aToVector2 (*value); + } else if constexpr (std::is_same_v) { + if (!typeCheck (value)) { + return defaultValue; + } + + return aToVector4i (*value); + } else if constexpr (std::is_same_v) { + if (!typeCheck (value)) { + return defaultValue; + } + + return aToVector3i (*value); + } else if constexpr (std::is_same_v) { + if (!typeCheck (value)) { + return defaultValue; + } + + return aToVector2i (*value); + } else if (typeCheck (value)) { + return *value; } - // TODO: SUPPORT INTEGERS AND OTHER TYPES - - return *value; + return defaultValue; +#undef GET_TEMPLATE_NAME } -template bool Core::jsonFindDefault (nlohmann::json& data, const char* key, bool defaultValue); -template std::string Core::jsonFindDefault (nlohmann::json& data, const char* key, std::string defaultValue); -template int16_t Core::jsonFindDefault (nlohmann::json& data, const char* key, int16_t defaultValue); -template uint16_t Core::jsonFindDefault (nlohmann::json& data, const char* key, uint16_t defaultValue); -template int32_t Core::jsonFindDefault (nlohmann::json& data, const char* key, int32_t defaultValue); -template uint32_t Core::jsonFindDefault (nlohmann::json& data, const char* key, uint32_t defaultValue); -template int64_t Core::jsonFindDefault (nlohmann::json& data, const char* key, int64_t defaultValue); -template uint64_t Core::jsonFindDefault (nlohmann::json& data, const char* key, uint64_t defaultValue); -template float Core::jsonFindDefault (nlohmann::json& data, const char* key, float defaultValue); -template double Core::jsonFindDefault (nlohmann::json& data, const char* key, double 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 -T* Core::jsonFindUserConfig (nlohmann::json& data, const char* key, typename T::data_type defaultValue) { +template const T* Core::jsonFindUserConfig ( + const nlohmann::json::const_iterator& data, 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); +} + +template const CUserSettingBoolean* Core::jsonFindUserConfig (const nlohmann::json::const_iterator& data, const char* key, + CUserSettingBoolean::data_type defaultValue); +template const CUserSettingVector3* Core::jsonFindUserConfig (const nlohmann::json::const_iterator& data, const char* key, + CUserSettingVector3::data_type defaultValue); +template const CUserSettingFloat* Core::jsonFindUserConfig (const nlohmann::json::const_iterator& data, const char* key, + CUserSettingFloat::data_type defaultValue); + +template const T* Core::jsonFindUserConfig ( + const nlohmann::json& data, 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) @@ -155,9 +496,9 @@ T* Core::jsonFindUserConfig (nlohmann::json& data, const char* key, typename T:: return T::fromJSON (*it); } -template CUserSettingBoolean* Core::jsonFindUserConfig (nlohmann::json& data, const char* key, +template const CUserSettingBoolean* Core::jsonFindUserConfig (const nlohmann::json& data, const char* key, CUserSettingBoolean::data_type defaultValue); -template CUserSettingVector3* Core::jsonFindUserConfig (nlohmann::json& data, const char* key, +template const CUserSettingVector3* Core::jsonFindUserConfig (const nlohmann::json& data, const char* key, CUserSettingVector3::data_type defaultValue); -template CUserSettingFloat* Core::jsonFindUserConfig (nlohmann::json& data, const char* key, - CUserSettingFloat::data_type defaultValue); \ No newline at end of file +template const CUserSettingFloat* Core::jsonFindUserConfig (const nlohmann::json& data, const char* key, + CUserSettingFloat::data_type defaultValue); diff --git a/src/WallpaperEngine/Core/Core.h b/src/WallpaperEngine/Core/Core.h index e0c9689..a575d34 100644 --- a/src/WallpaperEngine/Core/Core.h +++ b/src/WallpaperEngine/Core/Core.h @@ -15,15 +15,34 @@ 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); -nlohmann::json::iterator jsonFindRequired (nlohmann::json& data, const char* key, const char* notFoundMsg); -nlohmann::json::iterator jsonFindRequired (const nlohmann::json::iterator& data, const char* key, - const char* notFoundMsg); -template T jsonFindDefault (nlohmann::json& data, const char* key, T defaultValue); -template T* jsonFindUserConfig (nlohmann::json& data, const char* key, typename T::data_type defaultValue); +template const T jsonFindRequired ( + const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg); +template const T jsonFindRequired ( + const nlohmann::json& data, const char* key, const char* notFoundMsg); +const nlohmann::json::const_iterator jsonFindRequired ( + const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg); +const nlohmann::json::const_iterator jsonFindRequired ( + const nlohmann::json& data, const char* key, const char* notFoundMsg); +template const T jsonFindDefault ( + const nlohmann::json::const_iterator& data, const char* key, const T defaultValue); +template const T jsonFindDefault ( + const nlohmann::json& data, const char* key, const T defaultValue); +template const T* jsonFindUserConfig ( + const nlohmann::json::const_iterator& data, const char* key, typename T::data_type defaultValue); +template const T* jsonFindUserConfig ( + const nlohmann::json& data, const char* key, typename T::data_type defaultValue); } // namespace WallpaperEngine::Core diff --git a/src/WallpaperEngine/Core/Objects/CEffect.cpp b/src/WallpaperEngine/Core/Objects/CEffect.cpp index bdd8d0b..b9c0d8e 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Core/Objects/CEffect.cpp @@ -1,10 +1,10 @@ #include "CEffect.h" -#include #include #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" @@ -18,109 +18,72 @@ 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, CObject* object, - CUserSettingBoolean* visible) : - m_name (std::move (name)), - m_description (std::move (description)), - m_group (std::move (group)), - m_preview (std::move (preview)), - m_object (object), - m_visible (visible) {} +CEffect::CEffect ( + std::string name, std::string description, std::string group, std::string preview, const CProject& project, + const CUserSettingBoolean* visible, std::vector dependencies, std::vector fbos, + std::vector materials +) : + m_name (name), + m_description (description), + m_group (group), + m_preview (preview), + m_visible (visible), + m_dependencies (dependencies), + m_fbos (fbos), + m_project (project), + m_materials (materials) {} -CEffect* CEffect::fromJSON (json data, CUserSettingBoolean* visible, CObject* object, CContainer* container) { - auto file_it = jsonFindRequired (data, "file", "Object effect must have a file"); - auto effectpasses_it = data.find ("passes"); +const CEffect* CEffect::fromJSON ( + const json& data, const CUserSettingBoolean* visible, const CProject& project, const Images::CMaterial* material, + const CContainer* container +) { + const auto file = jsonFindRequired (data, "file", "Object effect must have a file"); + const auto effectpasses_it = data.find ("passes"); - json content = json::parse (container->readFileAsString(file_it->get ())); + json content = json::parse (container->readFileAsString(file)); - auto name_it = jsonFindRequired (content, "name", "Effect must have a name"); - auto description = jsonFindDefault (content, "description", ""); - auto group_it = jsonFindRequired (content, "group", "Effect must have a group"); - auto preview = jsonFindDefault (content, "preview", ""); - auto passes_it = jsonFindRequired (content, "passes", "Effect must have a pass list"); - auto dependencies_it = jsonFindRequired (content, "dependencies", ""); - auto fbos_it = content.find ("fbos"); + const auto effectName = jsonFindRequired (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"); - auto* effect = new CEffect (*name_it, description, *group_it, preview, object, visible); - - CEffect::materialsFromJSON (passes_it, effect, container); - CEffect::dependencyFromJSON (dependencies_it, effect); + // info to override in the pass information, used by material generation + std::map overrides; + std::vector fbos; if (fbos_it != content.end ()) - CEffect::fbosFromJSON (fbos_it, effect); + fbos = CEffect::fbosFromJSON (fbos_it); if (effectpasses_it != data.end ()) { - auto cur = effectpasses_it->begin (); - auto end = effectpasses_it->end (); - - for (int passNumber = 0; cur != end; ++cur, passNumber++) { - auto constants_it = cur->find ("constantshadervalues"); - auto combos_it = cur->find ("combos"); - auto textures_it = cur->find ("textures"); - - if (constants_it == cur->end () && combos_it == cur->end () && textures_it == cur->end ()) - continue; - - Images::CMaterial* material = effect->getMaterials ().at (passNumber); - - for (const auto& passCur : material->getPasses ()) { - if (textures_it != cur->end ()) { - std::vector::size_type textureNumber = 0; - - for (const auto& texturesCur : (*textures_it)) { - std::string texture; - - if (texturesCur.is_null ()) { - if (textureNumber == 0) { - auto* image = object->as (); - - auto passTextures = (*image->getMaterial ()->getPasses ().begin ())->getTextures (); - - if (passTextures.empty ()) { - // TODO: SET CHECKERBOARD TEXTURE AS DEFAULT IN THESE SITUATIONS - texture = ""; - } else { - texture = *passTextures.begin (); - } - } else { - texture = ""; - } - } else { - texture = texturesCur; - } - - const auto& passTextures = passCur->getTextures (); - - if (textureNumber < passTextures.size ()) - passCur->setTexture (textureNumber, texture); - else - passCur->insertTexture (texture); - - textureNumber++; - } - } - - if (combos_it != cur->end ()) { - CEffect::combosFromJSON (combos_it, passCur); - } - - if (constants_it != cur->end ()) { - CEffect::constantsFromJSON (constants_it, passCur); - } - } - } + overrides = overridesFromJSON (effectpasses_it, material); } - return effect; + return new CEffect ( + effectName, + jsonFindDefault (content, "description", ""), + jsonFindRequired (content, "group", "Effect must have a group"), + jsonFindDefault (content, "preview", ""), + project, + visible, + dependenciesFromJSON (jsonFindRequired (content, "dependencies", "")), + fbos, + materialsFromJSON (passes_it, effectName, container, overrides) + ); } -void CEffect::combosFromJSON (const json::const_iterator& combos_it, Core::Objects::Images::Materials::CPass* pass) { +std::map CEffect::combosFromJSON (const json::const_iterator& combos_it) { + std::map combos; + for (const auto& cur : combos_it->items ()) - pass->insertCombo (cur.key (), cur.value ()); + combos.insert (std::pair (cur.key (), cur.value ())); + + return combos; } -void CEffect::constantsFromJSON (const json::const_iterator& constants_it, - Core::Objects::Images::Materials::CPass* pass) { +std::map CEffect::constantsFromJSON ( + const json::const_iterator& constants_it +) { + std::map constants; + for (auto& cur : constants_it->items ()) { auto val = cur.value (); @@ -152,77 +115,154 @@ void CEffect::constantsFromJSON (const json::const_iterator& constants_it, sLog.exception ("unknown shader constant type ", val); } - pass->insertConstant (cur.key (), constant); + constants.insert (std::pair (cur.key (), constant)); } + + return constants; } -void CEffect::fbosFromJSON (const json::const_iterator& fbos_it, CEffect* effect) { +std::vector CEffect::fbosFromJSON (const json::const_iterator& fbos_it) { + std::vector fbos; + for (const auto& cur : (*fbos_it)) - effect->insertFBO (Effects::CFBO::fromJSON (cur)); + fbos.push_back (Effects::CFBO::fromJSON (cur)); + + return fbos; } -void CEffect::dependencyFromJSON (const json::const_iterator& dependencies_it, CEffect* effect) { +std::vector CEffect::dependenciesFromJSON (const json::const_iterator& dependencies_it) { + std::vector dependencies; + for (const auto& cur : (*dependencies_it)) - effect->insertDependency (cur); + dependencies.push_back (cur); + + return dependencies; } -void CEffect::materialsFromJSON (const json::const_iterator& passes_it, CEffect* effect, CContainer* container) { +std::vector CEffect::materialsFromJSON ( + const json::const_iterator& passes_it, std::string name, const CContainer* container, + std::map overrides +) { + std::vector materials; + + int materialNumber = -1; for (const auto& cur : (*passes_it)) { - auto materialfile = cur.find ("material"); - auto target = cur.find ("target"); - auto bind = cur.find ("bind"); + ++materialNumber; + const auto materialfile = cur.find ("material"); + const auto target = cur.find ("target"); + const auto bind_it = cur.find ("bind"); if (materialfile == cur.end ()) - sLog.exception ("Found an effect ", effect->m_name, " without material"); + sLog.exception ("Found an effect ", name, " without material"); - Images::CMaterial* material; + std::map textureBindings; - if (target == cur.end ()) - material = Images::CMaterial::fromFile (materialfile->get (), container); - else - material = Images::CMaterial::fromFile (materialfile->get (), *target, container); - - if (bind != cur.end ()) { - for (const auto& bindCur : (*bind)) - material->insertTextureBind (Effects::CBind::fromJSON (bindCur)); + if (bind_it != cur.end ()) { + for (const auto& bindCur : (*bind_it)) { + const auto* bind = Effects::CBind::fromJSON (bindCur); + textureBindings.insert (std::pair (bind->getIndex (), bind)); + } } - effect->insertMaterial (material); + const Images::CMaterial* material; + const Images::CMaterial::OverrideInfo* overrideInfo; + const auto overrideIt = overrides.find (materialNumber); + + if (overrideIt != overrides.end ()) { + overrideInfo = &overrideIt->second; + } + + if (target == cur.end ()) + material = Images::CMaterial::fromFile (materialfile->get (), container, textureBindings, overrideInfo); + else + material = Images::CMaterial::fromFile (materialfile->get (), *target, container, textureBindings, overrideInfo); + + materials.push_back (material); } + + return materials; +} + +std::map CEffect::overridesFromJSON ( + const json::const_iterator& passes_it, const Images::CMaterial* material +) { + std::map 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); + } + + 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 ()) { + if (textureNumber == 0) { + auto passTextures = (*material->getPasses ().begin ())->getTextures (); + + if (passTextures.empty ()) { + // TODO: SET CHECKERBOARD TEXTURE AS DEFAULT IN THESE SITUATIONS + name = ""; + } else { + name = passTextures.begin ()->second; + } + } else { + name = ""; + } + } else { + name = texture; + } + + override.textures.insert (std::pair (textureNumber, name)); + } + } + + result.insert (std::pair (materialNumber, override)); + } + + return result; } const std::vector& CEffect::getDependencies () const { return this->m_dependencies; } -const std::vector& CEffect::getMaterials () const { +const std::vector& CEffect::getMaterials () const { return this->m_materials; } -const std::vector& CEffect::getFbos () const { +const std::vector& CEffect::getFbos () const { return this->m_fbos; } -bool CEffect::isVisible () const { - return this->m_visible->processValue (this->m_object->getScene ()->getProject ().getProperties ()); +const Core::CProject& CEffect::getProject () const { + return this->m_project; } -Effects::CFBO* CEffect::findFBO (const std::string& name) { +bool CEffect::isVisible () const { + return this->m_visible->processValue (this->getProject ().getProperties ()); +} + +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); } - -void CEffect::insertDependency (const std::string& dep) { - this->m_dependencies.push_back (dep); -} - -void CEffect::insertMaterial (Images::CMaterial* material) { - this->m_materials.push_back (material); -} - -void CEffect::insertFBO (Effects::CFBO* fbo) { - this->m_fbos.push_back (fbo); -} \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/CEffect.h b/src/WallpaperEngine/Core/Objects/CEffect.h index e9210ff..548413e 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.h +++ b/src/WallpaperEngine/Core/Objects/CEffect.h @@ -9,6 +9,7 @@ namespace WallpaperEngine::Core { class CObject; +class CProject; } namespace WallpaperEngine::Core::UserSettings { @@ -25,11 +26,14 @@ using namespace WallpaperEngine::Core::UserSettings; */ class CEffect { public: - CEffect (std::string name, std::string description, std::string group, std::string preview, CObject* object, - CUserSettingBoolean* visible); + CEffect ( + std::string name, std::string description, std::string group, std::string preview, const CProject& project, + const CUserSettingBoolean* visible, std::vector dependencies, + std::vector fbos, std::vector materials); - static CEffect* fromJSON (json data, UserSettings::CUserSettingBoolean* visible, CObject* object, - CContainer* container); + static const CEffect* fromJSON ( + const json& data, const CUserSettingBoolean* visible, const CProject& object, const Images::CMaterial* material, + const CContainer* container); /** * @return List of dependencies for the effect to work @@ -38,15 +42,19 @@ class CEffect { /** * @return List of materials the effect applies */ - [[nodiscard]] const std::vector& getMaterials () const; + [[nodiscard]] const std::vector& getMaterials () const; /** * @return The list of FBOs to be used for this effect */ - [[nodiscard]] const std::vector& getFbos () const; + [[nodiscard]] const std::vector& 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 * @@ -54,39 +62,39 @@ class CEffect { * * @return */ - Effects::CFBO* findFBO (const std::string& name); + const Effects::CFBO* findFBO (const std::string& name); protected: - static void constantsFromJSON (const json::const_iterator& constants_it, - Core::Objects::Images::Materials::CPass* pass); - static void combosFromJSON (const json::const_iterator& combos_it, Core::Objects::Images::Materials::CPass* pass); - static void fbosFromJSON (const json::const_iterator& fbos_it, CEffect* effect); - static void dependencyFromJSON (const json::const_iterator& dependencies_it, CEffect* effect); - static void materialsFromJSON (const json::const_iterator& passes_it, CEffect* effect, CContainer* container); - - void insertDependency (const std::string& dep); - void insertMaterial (Images::CMaterial* material); - void insertFBO (Effects::CFBO* fbo); + static std::map constantsFromJSON ( + const json::const_iterator& constants_it); + static std::map combosFromJSON (const json::const_iterator& combos_it); + static std::vector fbosFromJSON (const json::const_iterator& fbos_it); + static std::vector dependenciesFromJSON (const json::const_iterator& dependencies_it); + static std::vector materialsFromJSON ( + const json::const_iterator& passes_it, std::string name, const CContainer* container, + std::map); + static std::map overridesFromJSON ( + const json::const_iterator& passes_it, const Images::CMaterial* material); private: /** Effect's name */ - std::string m_name; + const std::string m_name; /** Effect's description used in the UI */ - std::string m_description; + const std::string m_description; /** Effect's group used in the UI */ - std::string m_group; + const std::string m_group; /** A project that previews the given effect, used in the UI */ - std::string m_preview; - /** The object the effect applies to */ - CObject* m_object; + const std::string m_preview; /** If the effect is visible or not */ - UserSettings::CUserSettingBoolean* m_visible; + const UserSettings::CUserSettingBoolean* m_visible; + /** Project this effect is part of */ + const CProject& m_project; /** List of dependencies for the effect */ - std::vector m_dependencies; + const std::vector m_dependencies; /** List of materials the effect applies */ - std::vector m_materials; + const std::vector m_materials; /** List of FBOs required for this effect */ - std::vector m_fbos; + const std::vector m_fbos; }; } // namespace WallpaperEngine::Core::Objects diff --git a/src/WallpaperEngine/Core/Objects/CImage.cpp b/src/WallpaperEngine/Core/Objects/CImage.cpp index cc015e6..64c6326 100644 --- a/src/WallpaperEngine/Core/Objects/CImage.cpp +++ b/src/WallpaperEngine/Core/Objects/CImage.cpp @@ -5,53 +5,83 @@ #include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h" #include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h" #include "WallpaperEngine/Core/Wallpapers/CScene.h" -#include using namespace WallpaperEngine::Core::Objects; using namespace WallpaperEngine::Core::UserSettings; -CImage::CImage (Wallpapers::CScene* scene, Images::CMaterial* material, CUserSettingBoolean* visible, int id, std::string name, - CUserSettingVector3* origin, CUserSettingVector3* scale, const glm::vec3& angles, const glm::vec2& size, - std::string alignment, CUserSettingVector3* color, CUserSettingFloat* alpha, float brightness, - uint32_t colorBlendMode, const glm::vec2& parallaxDepth, bool fullscreen, bool passthrough, - bool autosize) : - CObject (scene, visible, id, std::move (name), Type, origin, scale, angles), +CImage::CImage ( + const Wallpapers::CScene* scene, const Images::CMaterial* material, const CUserSettingBoolean* visible, int id, + std::string name, const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 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 effects, std::vector dependencies +) : + CObject (scene, visible, id, name, Type, origin, scale, angles, dependencies), m_size (size), m_parallaxDepth (parallaxDepth), m_material (material), - m_alignment (std::move (alignment)), + m_alignment (alignment), m_alpha (alpha), m_brightness (brightness), m_color (color), m_colorBlendMode (colorBlendMode), m_fullscreen (fullscreen), m_passthrough (passthrough), - m_autosize (autosize) {} + m_autosize (autosize), + m_effects (effects) {} -WallpaperEngine::Core::CObject* CImage::fromJSON (Wallpapers::CScene* scene, json data, CContainer* container, - CUserSettingBoolean* visible, int id, std::string name, - CUserSettingVector3* origin, CUserSettingVector3* scale, - const glm::vec3& angles) { - const auto image_it = data.find ("image"); - const auto size_val = jsonFindDefault (data, "size", "0.0 0.0"); // this one might need some adjustment - const auto alignment = jsonFindDefault (data, "alignment", "center"); - const auto alpha = jsonFindUserConfig (data, "alpha", 1.0); - const auto color = jsonFindUserConfig (data, "color", {1, 1, 1}); - const auto brightness_val = jsonFindDefault (data, "brightness", 1.0); - const auto colorBlendMode_val = jsonFindDefault (data, "colorBlendMode", 0); - const auto parallaxDepth_val = jsonFindDefault (data, "parallaxDepth", "0 0"); +const WallpaperEngine::Core::CObject* CImage::fromJSON ( + const Wallpapers::CScene* scene, const json& data, const CContainer* container, + const CUserSettingBoolean* visible, int id, std::string name, const CUserSettingVector3* origin, + const CUserSettingVector3* scale, glm::vec3 angles, const json::const_iterator& effects_it, + std::vector dependencies +) { + const auto image = jsonFindRequired (data, "image", "Image must have an image"); + std::vector effects; + json content = json::parse (container->readFileAsString (image)); - json content = json::parse (container->readFileAsString (image_it->get ())); + const auto material = Images::CMaterial::fromFile ( + jsonFindRequired (content, "material", "Image must have a material"), + container + ); - const auto material_it = jsonFindRequired (content, "material", "Image must have a material"); - const auto fullscreen = jsonFindDefault (content, "fullscreen", false); - const auto passthrough = jsonFindDefault (content, "passthrough", false); - const auto autosize = jsonFindDefault (content, "autosize", false); + if (effects_it != data.end () && effects_it->is_array ()) { + for (auto& cur : *effects_it) { + const auto effectVisible = jsonFindUserConfig (cur, "visible", true); - return new CImage (scene, Images::CMaterial::fromFile (material_it->get (), container), visible, id, - std::move (name), origin, scale, angles, WallpaperEngine::Core::aToVector2 (size_val), alignment, - color, alpha, brightness_val, colorBlendMode_val, - WallpaperEngine::Core::aToVector2 (parallaxDepth_val), fullscreen, passthrough, autosize); + if (!effectVisible->processValue (scene->getProject ().getProperties ())) + continue; + + effects.push_back ( + Objects::CEffect::fromJSON ( + cur, effectVisible, scene->getProject (), material, container + ) + ); + } + } + + return new CImage ( + scene, + material, + visible, + id, + name, + origin, + scale, + angles, + jsonFindDefault (data, "size", glm::vec2 (0.0, 0.0)), + jsonFindDefault (data, "alignment", "center"), + jsonFindUserConfig (data, "color", {1, 1, 1}), + jsonFindUserConfig (data, "alpha", 1.0), + jsonFindDefault (data, "brightness", 1.0), + jsonFindDefault (data, "colorBlendMode", 0), + jsonFindDefault (data, "parallaxDepth", glm::vec2 (0.0, 0.0)), + jsonFindDefault (content, "fullscreen", false), + jsonFindDefault (content, "passthrough", false), + jsonFindDefault (content, "autosize", false), + effects, + dependencies + ); } const Images::CMaterial* CImage::getMaterial () const { @@ -70,7 +100,7 @@ float CImage::getAlpha () const { return this->m_alpha->processValue (this->getScene ()->getProject ().getProperties ()); } -glm::vec3 CImage::getColor () const { +const glm::vec3& CImage::getColor () const { return this->m_color->processValue (this->getScene ()->getProject ().getProperties ()); } @@ -98,4 +128,8 @@ bool CImage::isAutosize () const { return this->m_autosize; } +const std::vector& CImage::getEffects () const { + return this->m_effects; +} + const std::string CImage::Type = "image"; \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/CImage.h b/src/WallpaperEngine/Core/Objects/CImage.h index eb6f8f1..5d81c46 100644 --- a/src/WallpaperEngine/Core/Objects/CImage.h +++ b/src/WallpaperEngine/Core/Objects/CImage.h @@ -27,9 +27,11 @@ class CImage : public CObject { friend class CObject; public: - static CObject* fromJSON (Wallpapers::CScene* scene, json data, CContainer* container, CUserSettingBoolean* visible, - int id, std::string name, CUserSettingVector3* origin, CUserSettingVector3* scale, - const glm::vec3& angles); + static const CObject* fromJSON ( + const Wallpapers::CScene* scene, const json& data, const CContainer* container, + const CUserSettingBoolean* visible, int id, std::string name, const CUserSettingVector3* origin, + const CUserSettingVector3* scale, glm::vec3 angles, const json::const_iterator& effects_it, + std::vector dependencies); /** * @return The base material to use for the image @@ -50,7 +52,7 @@ class CImage : public CObject { /** * @return The color to use for the image */ - [[nodiscard]] glm::vec3 getColor () const; + [[nodiscard]] const glm::vec3& getColor () const; /** * @return The brightness to use for the image */ @@ -75,12 +77,18 @@ class CImage : public CObject { * @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& getEffects () const; protected: - CImage (Wallpapers::CScene* scene, Images::CMaterial* material, CUserSettingBoolean* visible, int id, std::string name, - CUserSettingVector3* origin, CUserSettingVector3* scale, const glm::vec3& angles, const glm::vec2& size, - std::string alignment, CUserSettingVector3* color, CUserSettingFloat* alpha, float brightness, - uint32_t colorBlendMode, const glm::vec2& parallaxDepth, bool fullscreen, bool passthrough, bool autosize); + CImage ( + const Wallpapers::CScene* scene, const Images::CMaterial* material, const CUserSettingBoolean* visible, int id, + std::string name, const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 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 effects, std::vector dependencies); /** * Type value used to differentiate the different types of objects in a background @@ -89,21 +97,23 @@ class CImage : public CObject { private: /** The image's size */ - glm::vec2 m_size; + const glm::vec2 m_size; /** Parallax depth */ const glm::vec2 m_parallaxDepth; /** Base material for the image */ - Images::CMaterial* m_material; + const Images::CMaterial* m_material; /** What type of alignment to use for the image's position */ - std::string m_alignment; + const std::string m_alignment; /** The alpha value for the image */ - CUserSettingFloat* m_alpha; + const CUserSettingFloat* m_alpha; /** The brightness for the image */ float m_brightness; /** The color to use for the image */ - CUserSettingVector3* m_color; + const CUserSettingVector3* m_color; /** The color blending mode used for the image, special value for shaders */ - uint32_t m_colorBlendMode; + const uint32_t m_colorBlendMode; + /** Override for effects */ + const std::vector m_effects; /** If the image is fullscreen or not */ bool m_fullscreen; /** If the image is passthrough or not */ diff --git a/src/WallpaperEngine/Core/Objects/CParticle.cpp b/src/WallpaperEngine/Core/Objects/CParticle.cpp index 85f8b8e..2376f9f 100644 --- a/src/WallpaperEngine/Core/Objects/CParticle.cpp +++ b/src/WallpaperEngine/Core/Objects/CParticle.cpp @@ -1,61 +1,70 @@ #include "CParticle.h" -#include - using namespace WallpaperEngine::Core::Objects; -CParticle* CParticle::fromFile (Wallpapers::CScene* scene, const std::string& filename, CContainer* container, - CUserSettingBoolean* visible, int id, std::string name, CUserSettingVector3* origin, - CUserSettingVector3* scale) { +const CParticle* CParticle::fromFile ( + const Wallpapers::CScene* scene, std::string filename, const CContainer* container, + const CUserSettingBoolean* visible, int id, std::string name, const CUserSettingVector3* origin, + const CUserSettingVector3* scale, std::vector dependencies +) { json data = json::parse (container->readFileAsString (filename)); const auto controlpoint_it = data.find ("controlpoint"); - const auto starttime_it = jsonFindRequired (data, "starttime", "Particles must have start time"); - const auto maxcount_it = jsonFindRequired (data, "maxcount", "Particles must have maximum count"); const auto emitter_it = jsonFindRequired (data, "emitter", "Particles must have emitters"); const auto initializer_it = jsonFindRequired (data, "initializer", "Particles must have initializers"); - auto* particle = new CParticle (scene, *starttime_it, *maxcount_it, visible, id, std::move (name), origin, scale); + std::vector controlpoints; + std::vector emitters; + std::vector initializers; if (controlpoint_it != data.end ()) for (const auto& cur : (*controlpoint_it)) - particle->insertControlPoint (Particles::CControlPoint::fromJSON (cur)); + controlpoints.push_back (Particles::CControlPoint::fromJSON (cur)); for (const auto& cur : (*emitter_it)) - particle->insertEmitter (Particles::CEmitter::fromJSON (cur)); + emitters.push_back (Particles::CEmitter::fromJSON (cur)); for (const auto& cur : (*initializer_it)) - particle->insertInitializer (Particles::CInitializer::fromJSON (cur)); + initializers.push_back (Particles::CInitializer::fromJSON (cur)); - return particle; + return new CParticle ( + scene, + jsonFindRequired (data, "starttime", "Particles must have start time"), + jsonFindRequired (data, "maxcount", "Particles must have maximum count"), + visible, + id, + name, + origin, + scale, + controlpoints, + emitters, + initializers, + dependencies + ); } -CParticle::CParticle (Wallpapers::CScene* scene, uint32_t starttime, uint32_t maxcount, CUserSettingBoolean* visible, int id, - std::string name, CUserSettingVector3* origin, CUserSettingVector3* scale) : - CObject (scene, visible, id, std::move (name), Type, origin, scale, glm::vec3 ()), +CParticle::CParticle ( + const Wallpapers::CScene* scene, uint32_t starttime, uint32_t maxcount, const CUserSettingBoolean* visible, int id, + const std::string& name, const CUserSettingVector3* origin, const CUserSettingVector3* scale, + const std::vector& controlpoints, + const std::vector& emitters, + const std::vector& initializers, std::vector dependencies +) : + CObject (scene, visible, id, name, Type, origin, scale, glm::vec3 (), dependencies), m_starttime (starttime), - m_maxcount (maxcount) {} + m_maxcount (maxcount), + m_controlpoints (controlpoints), + m_emitters (emitters), + m_initializers (initializers) {} -const std::vector& CParticle::getEmitters () const { +const std::vector& CParticle::getEmitters () const { return this->m_emitters; } -const std::vector& CParticle::getControlPoints () const { +const std::vector& CParticle::getControlPoints () const { return this->m_controlpoints; } -const std::vector& CParticle::getInitializers () const { +const std::vector& CParticle::getInitializers () const { return this->m_initializers; } -void CParticle::insertControlPoint (Particles::CControlPoint* controlpoint) { - this->m_controlpoints.push_back (controlpoint); -} - -void CParticle::insertEmitter (Particles::CEmitter* emitter) { - this->m_emitters.push_back (emitter); -} - -void CParticle::insertInitializer (Particles::CInitializer* initializer) { - this->m_initializers.push_back (initializer); -} - const std::string CParticle::Type = "particle"; \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/CParticle.h b/src/WallpaperEngine/Core/Objects/CParticle.h index 557ca2d..7b8c286 100644 --- a/src/WallpaperEngine/Core/Objects/CParticle.h +++ b/src/WallpaperEngine/Core/Objects/CParticle.h @@ -17,39 +17,31 @@ class CParticle : public CObject { friend class CObject; public: - static CParticle* fromFile (Wallpapers::CScene* scene, const std::string& filename, CContainer* container, - CUserSettingBoolean* visible, int id, std::string name, - CUserSettingVector3* origin, CUserSettingVector3* scale); + static const CParticle* fromFile ( + const Wallpapers::CScene* scene, std::string filename, const CContainer* container, + const CUserSettingBoolean* visible, int id, std::string name, const CUserSettingVector3* origin, + const CUserSettingVector3* scale, std::vector dependencies); /** * @return The list of emitters for the particle system */ - [[nodiscard]] const std::vector& getEmitters () const; + [[nodiscard]] const std::vector& getEmitters () const; /** * @return The list of control points for the particle system */ - [[nodiscard]] const std::vector& getControlPoints () const; + [[nodiscard]] const std::vector& getControlPoints () const; /** * @return The list of initializers for the particle system */ - [[nodiscard]] const std::vector& getInitializers () const; + [[nodiscard]] const std::vector& getInitializers () const; protected: - CParticle (Wallpapers::CScene* scene, uint32_t starttime, uint32_t maxcount, CUserSettingBoolean* visible, int id, - std::string name, CUserSettingVector3* origin, CUserSettingVector3* scale); - - /** - * @param controlpoint The control point to add to the particle system - */ - void insertControlPoint (Particles::CControlPoint* controlpoint); - /** - * @param emitter The emitter to add to the particle system - */ - void insertEmitter (Particles::CEmitter* emitter); - /** - * @param initializer The initializer to add to the particle system - */ - void insertInitializer (Particles::CInitializer* initializer); + CParticle ( + const Wallpapers::CScene* scene, uint32_t starttime, uint32_t maxcount, const CUserSettingBoolean* visible, + int id, const std::string& name, const CUserSettingVector3* origin, const CUserSettingVector3* scale, + const std::vector& controlpoints, + const std::vector& emitters, + const std::vector& initializers, std::vector dependencies); /** * Type value used to differentiate the different types of objects in a background @@ -58,14 +50,14 @@ class CParticle : public CObject { private: /** The time at which the particle system should start emitting */ - uint32_t m_starttime; + const uint32_t m_starttime; /** Maximum number of particles at the same time */ - uint32_t m_maxcount; + const uint32_t m_maxcount; /** List of control points */ - std::vector m_controlpoints; + const std::vector m_controlpoints; /** List of emitters */ - std::vector m_emitters; + const std::vector m_emitters; /** List of initializers */ - std::vector m_initializers; + const std::vector m_initializers; }; } // namespace WallpaperEngine::Core::Objects diff --git a/src/WallpaperEngine/Core/Objects/CSound.cpp b/src/WallpaperEngine/Core/Objects/CSound.cpp index fcba303..d9f4fbe 100644 --- a/src/WallpaperEngine/Core/Objects/CSound.cpp +++ b/src/WallpaperEngine/Core/Objects/CSound.cpp @@ -4,35 +4,42 @@ using namespace WallpaperEngine::Core::Objects; -CSound::CSound (Wallpapers::CScene* scene, CUserSettingBoolean* visible, int id, std::string name, CUserSettingVector3* origin, - CUserSettingVector3* scale, const glm::vec3& angles, bool repeat) : - CObject (scene, visible, id, std::move (name), Type, origin, scale, angles), - m_repeat (repeat) {} +CSound::CSound ( + const Wallpapers::CScene* scene, const CUserSettingBoolean* visible, int id, std::string name, + const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles, bool repeat, + std::vector sounds, std::vector dependencies +) : + CObject (scene, visible, id, name, Type, origin, scale, angles, dependencies), + m_repeat (repeat), + m_sounds (sounds) {} -WallpaperEngine::Core::CObject* CSound::fromJSON (Wallpapers::CScene* scene, json data, CUserSettingBoolean* visible, int id, - const std::string& name, CUserSettingVector3* origin, - CUserSettingVector3* scale, const glm::vec3& angles) { - bool repeat = false; +const WallpaperEngine::Core::CObject* CSound::fromJSON ( + const Wallpapers::CScene* scene, const json& data, const CUserSettingBoolean* visible, int id, + std::string name, const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles, + std::vector dependencies +) { // TODO: PARSE AUDIO VOLUME + std::vector sounds; const auto sound_it = jsonFindRequired (data, "sound", "Sound information not present"); - const auto playbackmode = jsonFindDefault (data, "playbackmode", ""); - - if (playbackmode == "loop") - repeat = true; if (!sound_it->is_array ()) sLog.exception ("Expected sound list on element ", name); - auto* sound = new CSound (scene, visible, id, name, origin, scale, angles, repeat); - for (const auto& cur : (*sound_it)) - sound->insertSound (cur); + sounds.push_back (cur); - return sound; -} - -void CSound::insertSound (const std::string& filename) { - this->m_sounds.push_back (filename); + return new CSound ( + scene, + visible, + id, + name, + origin, + scale, + angles, + jsonFindDefault (data, "playbackmode", "") == "loop", + sounds, + dependencies + ); } const std::vector& CSound::getSounds () const { diff --git a/src/WallpaperEngine/Core/Objects/CSound.h b/src/WallpaperEngine/Core/Objects/CSound.h index 7028ae5..f748a27 100644 --- a/src/WallpaperEngine/Core/Objects/CSound.h +++ b/src/WallpaperEngine/Core/Objects/CSound.h @@ -19,9 +19,10 @@ class CSound : public CObject { friend class CObject; public: - static CObject* fromJSON (Wallpapers::CScene* scene, json data, CUserSettingBoolean* visible, int id, - const std::string& name, CUserSettingVector3* origin, CUserSettingVector3* scale, - const glm::vec3& angles); + static const CObject* fromJSON ( + const Wallpapers::CScene* scene, const json& data, const CUserSettingBoolean* visible, + int id, std::string name, const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles, + std::vector dependencies); /** * @return The list of sounds to play @@ -33,13 +34,10 @@ class CSound : public CObject { [[nodiscard]] bool isRepeat () const; protected: - CSound (Wallpapers::CScene* scene, CUserSettingBoolean* visible, int id, std::string name, CUserSettingVector3* origin, - CUserSettingVector3* scale, const glm::vec3& angles, bool repeat); - - /** - * @param filename The sound to add - */ - void insertSound (const std::string& filename); + CSound ( + const Wallpapers::CScene* scene, const CUserSettingBoolean* visible, int id, std::string name, + const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles, bool repeat, + std::vector sounds, std::vector dependencies); /** * Type value used to differentiate the different types of objects in a background diff --git a/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp b/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp index 7522ff5..3d271fb 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp +++ b/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp @@ -4,13 +4,15 @@ using namespace WallpaperEngine::Core::Objects::Effects; -CBind::CBind (std::string name, uint32_t index) : m_name (std::move (name)), m_index (index) {} +CBind::CBind (std::string name, uint32_t index) : + m_name (name), + m_index (index) {} -CBind* CBind::fromJSON (json data) { - const auto name_it = jsonFindRequired (data, "name", "bind must have texture name"); - const auto index_it = jsonFindRequired (data, "index", "bind must have index"); - - return new CBind (*name_it, *index_it); +const CBind* CBind::fromJSON (const json& data) { + return new CBind ( + jsonFindRequired (data, "name", "bind must have texture name"), + jsonFindRequired (data, "index", "bind must have index") + ); } const std::string& CBind::getName () const { diff --git a/src/WallpaperEngine/Core/Objects/Effects/CBind.h b/src/WallpaperEngine/Core/Objects/Effects/CBind.h index f4a229d..6fd790c 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CBind.h +++ b/src/WallpaperEngine/Core/Objects/Effects/CBind.h @@ -20,9 +20,7 @@ class CBind { * @param data * @return */ - static CBind* fromJSON (json data); - - CBind (std::string name, uint32_t index); + static const CBind* fromJSON (const json& data); /** * @return The texture name, previous to use the one already specified by the object's passes @@ -33,10 +31,13 @@ class CBind { */ [[nodiscard]] const uint32_t& getIndex () const; + protected: + CBind (std::string name, uint32_t index); + private: /** The texture's name */ - std::string m_name; + const std::string m_name; /** The texture index to replace */ - uint32_t m_index; + const uint32_t m_index; }; } // namespace WallpaperEngine::Core::Objects::Effects diff --git a/src/WallpaperEngine/Core/Objects/Effects/CFBO.cpp b/src/WallpaperEngine/Core/Objects/Effects/CFBO.cpp index 65633a5..a88ddab 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CFBO.cpp +++ b/src/WallpaperEngine/Core/Objects/Effects/CFBO.cpp @@ -6,16 +6,16 @@ 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_name (name), m_scale (scale), - m_format (std::move (format)) {} + m_format (format) {} -CFBO* CFBO::fromJSON (json data) { - const auto name_it = jsonFindRequired (data, "name", "Name for an FBO is required"); - const auto scale = jsonFindDefault (data, "scale", 1.0); - const auto format = jsonFindDefault (data, "format", ""); - - return new CFBO (*name_it, scale, format); +const CFBO* CFBO::fromJSON (const json& data) { + return new CFBO ( + jsonFindRequired (data, "name", "Name for an FBO is required"), + jsonFindDefault (data, "scale", 1.0), + jsonFindDefault (data, "format", "") + ); } const std::string& CFBO::getName () const { diff --git a/src/WallpaperEngine/Core/Objects/Effects/CFBO.h b/src/WallpaperEngine/Core/Objects/Effects/CFBO.h index 7e35b97..cc2e694 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CFBO.h +++ b/src/WallpaperEngine/Core/Objects/Effects/CFBO.h @@ -15,9 +15,7 @@ using json = nlohmann::json; */ class CFBO { public: - CFBO (std::string name, float scale, std::string format); - - static CFBO* fromJSON (json data); + static const CFBO* fromJSON (const json& data); /** * @return The FBO name used to identify it in the background's files @@ -32,12 +30,15 @@ class CFBO { */ [[nodiscard]] const std::string& getFormat () const; + protected: + CFBO (std::string name, float scale, std::string format); + private: /** The name of the FBO */ - std::string m_name; + const std::string m_name; /** The scale factor of the FBO */ - float m_scale; + const float m_scale; /** The FBO's format for the render */ - std::string m_format; + const std::string m_format; }; } // namespace WallpaperEngine::Core::Objects::Effects \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.cpp b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.cpp index fab60c3..0358242 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.cpp +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.cpp @@ -2,7 +2,8 @@ using namespace WallpaperEngine::Core::Objects::Effects::Constants; -CShaderConstant::CShaderConstant (std::string type) : m_type (std::move (type)) {} +CShaderConstant::CShaderConstant (std::string type) : + m_type (type) {} const std::string& CShaderConstant::getType () const { return this->m_type; diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h index fa15962..08daead 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h @@ -21,7 +21,7 @@ class CShaderConstant { return reinterpret_cast (this); } - template bool is () { + template bool is () const { return this->m_type == T::Type; } @@ -31,6 +31,6 @@ class CShaderConstant { [[nodiscard]] const std::string& getType () const; private: - std::string m_type; + const std::string m_type; }; } // namespace WallpaperEngine::Core::Objects::Effects::Constants diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.cpp b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.cpp index 04b1877..372a0a2 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.cpp +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.cpp @@ -2,9 +2,11 @@ using namespace WallpaperEngine::Core::Objects::Effects::Constants; -CShaderConstantFloat::CShaderConstantFloat (float value) : CShaderConstant (Type), m_value (value) {} +CShaderConstantFloat::CShaderConstantFloat (float value) : + CShaderConstant (Type), + m_value (value) {} -float* CShaderConstantFloat::getValue () { +const float* CShaderConstantFloat::getValue () const { return &this->m_value; } diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h index 84be76e..9b02aa8 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h @@ -15,7 +15,7 @@ class CShaderConstantFloat : public CShaderConstant { /** * @return A pointer to the actual value of the constant */ - float* getValue (); + [[nodiscard]] const float* getValue () const; /** * Type string indicator @@ -24,6 +24,6 @@ class CShaderConstantFloat : public CShaderConstant { protected: /** The constant's value */ - float m_value; + const float m_value; }; } // namespace WallpaperEngine::Core::Objects::Effects::Constants diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.cpp b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.cpp index 7bc7b99..79eca49 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.cpp +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.cpp @@ -2,9 +2,11 @@ using namespace WallpaperEngine::Core::Objects::Effects::Constants; -CShaderConstantInteger::CShaderConstantInteger (int32_t value) : CShaderConstant (Type), m_value (value) {} +CShaderConstantInteger::CShaderConstantInteger (int32_t value) : + CShaderConstant (Type), + m_value (value) {} -int32_t* CShaderConstantInteger::getValue () { +const int32_t* CShaderConstantInteger::getValue () const { return &this->m_value; } diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h index 9101191..47dc0da 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h @@ -15,7 +15,7 @@ class CShaderConstantInteger : public CShaderConstant { /** * @return A pointer to the actual value of the constant */ - int32_t* getValue (); + [[nodiscard]] const int32_t* getValue () const; /** * Type string indicator @@ -24,6 +24,6 @@ class CShaderConstantInteger : public CShaderConstant { protected: /** The constant's value */ - int32_t m_value; + const int32_t m_value; }; } // namespace WallpaperEngine::Core::Objects::Effects::Constants diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.cpp b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.cpp index f361d80..ed0e158 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.cpp +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.cpp @@ -2,9 +2,11 @@ using namespace WallpaperEngine::Core::Objects::Effects::Constants; -CShaderConstantVector2::CShaderConstantVector2 (glm::vec2 value) : CShaderConstant (Type), m_value (value) {} +CShaderConstantVector2::CShaderConstantVector2 (glm::vec2 value) : + CShaderConstant (Type), + m_value (value) {} -glm::vec2* CShaderConstantVector2::getValue () { +const glm::vec2* CShaderConstantVector2::getValue () const { return &this->m_value; } diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.h index 2411825..ce5fdf4 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector2.h @@ -17,7 +17,7 @@ class CShaderConstantVector2 : public CShaderConstant { /** * @return A pointer to the actual value of the constant */ - glm::vec2* getValue (); + [[nodiscard]] const glm::vec2* getValue () const; /** * Type string indicator @@ -26,6 +26,6 @@ class CShaderConstantVector2 : public CShaderConstant { protected: /** The constant's value */ - glm::vec2 m_value; + const glm::vec2 m_value; }; } // namespace WallpaperEngine::Core::Objects::Effects::Constants diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.cpp b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.cpp index 9afa86a..dca846a 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.cpp +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.cpp @@ -2,9 +2,11 @@ using namespace WallpaperEngine::Core::Objects::Effects::Constants; -CShaderConstantVector3::CShaderConstantVector3 (glm::vec3 value) : CShaderConstant (Type), m_value (value) {} +CShaderConstantVector3::CShaderConstantVector3 (glm::vec3 value) : + CShaderConstant (Type), + m_value (value) {} -glm::vec3* CShaderConstantVector3::getValue () { +const glm::vec3* CShaderConstantVector3::getValue () const { return &this->m_value; } diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h index 989044f..ac68698 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector3.h @@ -16,7 +16,7 @@ class CShaderConstantVector3 : public CShaderConstant { /** * @return A pointer to the actual value of the constant */ - glm::vec3* getValue (); + [[nodiscard]] const glm::vec3* getValue () const; /** * Type string indicator @@ -25,6 +25,6 @@ class CShaderConstantVector3 : public CShaderConstant { protected: /** The constant's value */ - glm::vec3 m_value; + const glm::vec3 m_value; }; } // namespace WallpaperEngine::Core::Objects::Effects::Constants diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector4.cpp b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector4.cpp index 7502a95..791b621 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector4.cpp +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector4.cpp @@ -2,9 +2,11 @@ using namespace WallpaperEngine::Core::Objects::Effects::Constants; -CShaderConstantVector4::CShaderConstantVector4 (glm::vec4 value) : CShaderConstant (Type), m_value (value) {} +CShaderConstantVector4::CShaderConstantVector4 (glm::vec4 value) : + CShaderConstant (Type), + m_value (value) {} -glm::vec4* CShaderConstantVector4::getValue () { +const glm::vec4* CShaderConstantVector4::getValue () const { return &this->m_value; } diff --git a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector4.h b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector4.h index e9aa7e3..33399c2 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector4.h +++ b/src/WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantVector4.h @@ -16,7 +16,7 @@ class CShaderConstantVector4 : public CShaderConstant { /** * @return A pointer to the actual value of the constant */ - glm::vec4* getValue (); + [[nodiscard]] const glm::vec4* getValue () const; /** * Type string indicator @@ -25,6 +25,6 @@ class CShaderConstantVector4 : public CShaderConstant { protected: /** The constant's value */ - glm::vec4 m_value; + const glm::vec4 m_value; }; } // namespace WallpaperEngine::Core::Objects::Effects::Constants diff --git a/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp b/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp index ab6c046..2b52225 100644 --- a/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp @@ -1,59 +1,74 @@ #include "CMaterial.h" +#include "WallpaperEngine/Core/Objects/Images/Materials/CPass.h" #include -#include using namespace WallpaperEngine::Assets; using namespace WallpaperEngine::Core::Objects; using namespace WallpaperEngine::Core::Objects::Images; -CMaterial::CMaterial (std::string name) : m_name (std::move (name)) {} +CMaterial::CMaterial ( + std::string name, std::map textureBindings, + std::vector passes +) : + m_name (name), + m_textureBindings (textureBindings), + m_passes (passes) {} +CMaterial::CMaterial ( + std::string name, std::string target, + std::map textureBindings, std::vector passes +) : + m_name (name), + m_target (target), + m_textureBindings (textureBindings), + m_passes (passes) {} -CMaterial* CMaterial::fromFile (const std::string& filename, CContainer* container) { - return fromJSON (filename, json::parse (container->readFileAsString (filename))); +const CMaterial* CMaterial::fromFile ( + const std::filesystem::path& filename, const CContainer* container, + std::map textureBindings, const OverrideInfo* overrides +) { + return fromJSON (filename, json::parse (container->readFileAsString (filename)), textureBindings, overrides); } -CMaterial* CMaterial::fromFile (const std::string& filename, const std::string& target, CContainer* container) { - return fromJSON (filename, json::parse (container->readFileAsString (filename)), target); +const CMaterial* CMaterial::fromFile ( + const std::filesystem::path& filename, const std::string& target, + const CContainer* container, std::map textureBindings, const OverrideInfo* overrides +) { + return fromJSON (filename, json::parse (container->readFileAsString (filename)), target, textureBindings, overrides); } -CMaterial* CMaterial::fromJSON (const std::string& name, json data, const std::string& target) { - CMaterial* material = fromJSON (name, std::move (data)); - - material->setTarget (target); - - return material; -} - -CMaterial* CMaterial::fromJSON (const std::string& name, json data) { +const CMaterial* CMaterial::fromJSON ( + const std::string& name, const json& data, const std::string& target, + std::map textureBindings, const OverrideInfo* overrides +) { const auto passes_it = jsonFindRequired (data, "passes", "Material must have at least one pass"); - - auto* material = new CMaterial (name); + std::vector passes; for (const auto& cur : (*passes_it)) - material->insertPass (Materials::CPass::fromJSON (cur)); + passes.push_back (Materials::CPass::fromJSON (cur, overrides)); - return material; + return new CMaterial (name, target, textureBindings, passes); } -void CMaterial::insertPass (Materials::CPass* pass) { - this->m_passes.push_back (pass); +const CMaterial* CMaterial::fromJSON ( + const std::string& name, const json& data, std::map textureBindings, + const OverrideInfo* overrides +) { + const auto passes_it = jsonFindRequired (data, "passes", "Material must have at least one pass"); + std::vector passes; + + for (const auto& cur : (*passes_it)) + passes.push_back (Materials::CPass::fromJSON (cur, overrides)); + + return new CMaterial (name, textureBindings, passes); } -void CMaterial::insertTextureBind (Effects::CBind* bind) { - this->m_textureBindings.insert (std::make_pair (bind->getIndex (), bind)); -} - -void CMaterial::setTarget (const std::string& target) { - this->m_target = target; -} - -const std::vector& CMaterial::getPasses () const { +const std::vector& CMaterial::getPasses () const { return this->m_passes; } -const std::map& CMaterial::getTextureBinds () const { +const std::map& CMaterial::getTextureBinds () const { return this->m_textureBindings; } diff --git a/src/WallpaperEngine/Core/Objects/Images/CMaterial.h b/src/WallpaperEngine/Core/Objects/Images/CMaterial.h index 6864e62..49fcb73 100644 --- a/src/WallpaperEngine/Core/Objects/Images/CMaterial.h +++ b/src/WallpaperEngine/Core/Objects/Images/CMaterial.h @@ -1,10 +1,14 @@ #pragma once #include "WallpaperEngine/Core/Objects/Effects/CBind.h" -#include "WallpaperEngine/Core/Objects/Images/Materials/CPass.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; @@ -15,29 +19,34 @@ using namespace WallpaperEngine::Assets; */ class CMaterial { public: - static CMaterial* fromFile (const std::string& filename, Assets::CContainer* container); - static CMaterial* fromJSON (const std::string& name, json data); - static CMaterial* fromFile (const std::string& filename, const std::string& target, Assets::CContainer* container); - static CMaterial* fromJSON (const std::string& name, json data, const std::string& target); - - /** - * @param pass The rendering pass to add to the material - */ - void insertPass (Materials::CPass* pass); - /** - * @param bind Texture bind override for the material - */ - void insertTextureBind (Effects::CBind* bind); + struct OverrideInfo { + std::map combos; + std::map constants; + std::map textures; + }; + static const CMaterial* fromFile ( + const std::filesystem::path& filename, const Assets::CContainer* container, + std::map textureBindings = {}, const OverrideInfo* overrides = nullptr); + static const CMaterial* fromFile ( + const std::filesystem::path& filename, const std::string& target, + const Assets::CContainer* container, std::map textureBindings = {}, + const OverrideInfo* overrides = nullptr); + static const CMaterial* fromJSON ( + const std::string& name, const json& data, + std::map textureBindings = {}, const OverrideInfo* overrides = nullptr); + static const CMaterial* fromJSON ( + const std::string& name, const json& data, const std::string& target, + std::map textureBindings = {}, const OverrideInfo* overrides = nullptr); /** * @return All the rendering passes that happen for this material */ - [[nodiscard]] const std::vector& getPasses () const; + [[nodiscard]] const std::vector& 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& getTextureBinds () const; + [[nodiscard]] const std::map& getTextureBinds () const; /** * @return The materials destination (fbo) if required */ @@ -52,21 +61,21 @@ class CMaterial { [[nodiscard]] const std::string& getName () const; protected: - explicit CMaterial (std::string name); - - /** - * @param target The new target while rendering this material - */ - void setTarget (const std::string& target); + CMaterial ( + std::string name, std::map textureBindings, + std::vector passes); + CMaterial ( + std::string name, std::string target, std::map textureBindings, + const std::vector passes); private: /** All the shader passes required to render this material */ - std::vector m_passes; + const std::vector m_passes; /** List of texture bind overrides to use for this material */ - std::map m_textureBindings; + const std::map m_textureBindings; /** The FBO target to render to (if any) */ - std::string m_target; + const std::string m_target; /** The material's name */ - std::string m_name; + const std::string m_name; }; } // namespace WallpaperEngine::Core::Objects::Images diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp index 469fdb5..053a82e 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp @@ -7,72 +7,82 @@ 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) : - 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)) {} + std::string shader, std::map textures, std::map combos, + std::map constants) : + m_blending (blending), + m_cullmode (cullmode), + m_depthtest (depthtest), + m_depthwrite (depthwrite), + m_shader (shader), + m_textures (textures), + m_combos (combos), + m_constants (constants) +{} -CPass* CPass::fromJSON (json data) { +const CPass* CPass::fromJSON (const json& data, const CMaterial::OverrideInfo* overrides) { // TODO: FIGURE OUT DEFAULT BLENDING MODE - const auto blending = jsonFindDefault (data, "blending", "normal"); - const auto cullmode = jsonFindDefault (data, "cullmode", "nocull"); - const auto depthtest_it = jsonFindRequired (data, "depthtest", "Material pass must have depthtest specified"); - const auto depthwrite_it = jsonFindRequired (data, "depthwrite", "Material pass must have depthwrite specified"); - const auto shader_it = jsonFindRequired (data, "shader", "Material pass must have shader specified"); const auto textures_it = data.find ("textures"); const auto combos_it = data.find ("combos"); + std::map textures; + std::map combos; + std::map 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"); - } - auto* pass = new CPass (blending, cullmode, *depthtest_it, *depthwrite_it, *shader_it); - - if (textures_it != data.end ()) + int textureNumber = -1; for (const auto& cur : (*textures_it)) - pass->insertTexture (cur.is_null () ? "" : cur); + textures.insert (std::pair (++textureNumber, cur.is_null () ? "" : cur)); + } if (combos_it != data.end ()) { for (const auto& cur : combos_it->items ()) { - if (cur.value ().is_number_integer ()) - pass->insertCombo (cur.key (), cur.value ()); - else + if (cur.value ().is_number_integer ()) { + std::string uppercase = std::string (cur.key ()); + + std::transform (uppercase.begin (), uppercase.end (), uppercase.begin (), ::toupper); + combos.insert (std::pair (cur.key (), cur.value ())); + } else { sLog.exception ("unexpected non-integer combo on pass"); + } } } - return 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.insert(std::pair(id, value)); + } + + return new CPass ( + jsonFindDefault (data, "blending", "normal"), + jsonFindDefault (data, "cullmode", "nocull"), + jsonFindRequired (data, "depthtest", "Material pass must have depthtest specified"), + jsonFindRequired (data, "depthwrite", "Material pass must have depthwrite specified"), + jsonFindRequired (data, "shader", "Material pass must have shader specified"), + textures, + combos, + constants + ); } -void CPass::insertTexture (const std::string& texture) { - this->m_textures.push_back (texture); -} - -void CPass::setTexture (std::vector::size_type index, const std::string& texture) { - this->m_textures.at (index) = texture; -} - -void CPass::insertCombo (const std::string& name, int value) { - std::string uppercase = std::string (name); - - std::transform (uppercase.begin (), uppercase.end (), uppercase.begin (), ::toupper); - this->m_combos.insert (std::pair (uppercase, value)); -} - -const std::vector& CPass::getTextures () const { +const std::map& CPass::getTextures () const { return this->m_textures; } -const std::map& CPass::getConstants () const { +const std::map& CPass::getConstants () const { return this->m_constants; } -std::map* CPass::getCombos () { - return &this->m_combos; +const std::map& CPass::getCombos () const { + return this->m_combos; } const std::string& CPass::getShader () const { @@ -94,11 +104,3 @@ const std::string& CPass::getDepthTest () const { const std::string& CPass::getDepthWrite () const { return this->m_depthwrite; } - -void CPass::setBlendingMode (const std::string& mode) { - this->m_blending = mode; -} - -void CPass::insertConstant (const std::string& name, CShaderConstant* constant) { - this->m_constants.insert (std::pair (name, constant)); -} \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h index bf36152..e14889a 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h @@ -1,13 +1,17 @@ #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; @@ -18,20 +22,20 @@ class CPass { friend class WallpaperEngine::Core::Objects::CEffect; public: - static CPass* fromJSON (json data); + static const CPass* fromJSON (const json& data, const CMaterial::OverrideInfo* overrides); /** * @return The list of textures to bind while rendering */ - [[nodiscard]] const std::vector& getTextures () const; + [[nodiscard]] const std::map& getTextures () const; /** * @return Shader constants that alter how the shader should behave */ - [[nodiscard]] const std::map& getConstants () const; + [[nodiscard]] const std::map& getConstants () const; /** * @return Shader combos that alter how the shader should behave */ - [[nodiscard]] std::map* getCombos (); + [[nodiscard]] const std::map& getCombos () const; /** * @return Shader to be used while rendering the pass */ @@ -52,61 +56,29 @@ class CPass { * @return If depth write has to happen while rendering */ [[nodiscard]] const std::string& getDepthWrite () const; - /** - * @param mode The new blending mode to use - */ - void setBlendingMode (const std::string& mode); - - /** - * Add a shader combo value to the list - * - * @param name The combo name - * @param value It's value - */ - void insertCombo (const std::string& name, int value); - /** - * Adds a shader constant to the list - * - * @param name The constant's name - * @param constant It's value - */ - void insertConstant (const std::string& name, Effects::Constants::CShaderConstant* constant); protected: CPass (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite, - std::string shader); - - /** - * Adds a new texture to the list of textures to bind while rendering - * - * @param texture - */ - void insertTexture (const std::string& texture); - /** - * Updates a texture in the specified index for binding while rendering - * - * @param index - * @param texture - */ - void setTexture (std::vector::size_type index, const std::string& texture); + std::string shader, std::map textures, std::map combos, + std::map constants); private: // TODO: CREATE ENUMERATIONS FOR THESE INSTEAD OF USING STRING VALUES! /** The blending mode to use */ - std::string m_blending; + const std::string m_blending; /** The culling mode to use */ - std::string m_cullmode; + const std::string m_cullmode; /** If depthtesting has to happen while drawing */ - std::string m_depthtest; + const std::string m_depthtest; /** If depthwrite has to happen while drawing */ - std::string m_depthwrite; + const std::string m_depthwrite; /** The shader to use */ - std::string m_shader; + const std::string m_shader; /** The list of textures to use */ - std::vector m_textures; + const std::map m_textures; /** Different combo settings for shader input */ - std::map m_combos; + const std::map m_combos; /** Shader constant values to use for the shaders */ - std::map m_constants; + const std::map m_constants; }; } // namespace WallpaperEngine::Core::Objects::Images::Materials diff --git a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp index 47d55cd..586bf3a 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp @@ -2,31 +2,18 @@ using namespace WallpaperEngine::Core::Objects::Particles; -CControlPoint* CControlPoint::fromJSON (json data) { - const auto flags_it = data.find ("flags"); - const auto id_it = jsonFindRequired (data, "id", "Particle's control point must have id"); - const auto offset_it = data.find ("offset"); - - auto* controlpoint = new CControlPoint (*id_it, 0); - - if (offset_it != data.end ()) - controlpoint->setOffset (WallpaperEngine::Core::aToVector3 (*offset_it)); - - if (flags_it != data.end ()) - controlpoint->setFlags (*flags_it); - - return controlpoint; +const CControlPoint* CControlPoint::fromJSON (const json& data) { + return new CControlPoint ( + jsonFindRequired (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) : m_id (id), m_flags (flags), m_offset (glm::vec3 ()) {} - -void CControlPoint::setOffset (const glm::vec3& offset) { - this->m_offset = offset; -} - -void CControlPoint::setFlags (uint32_t flags) { - this->m_flags = flags; -} +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; diff --git a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h index b9f0725..734c714 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h +++ b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h @@ -10,7 +10,7 @@ using json = nlohmann::json; */ class CControlPoint { public: - static CControlPoint* fromJSON (json data); + static const CControlPoint* fromJSON (const json& data); /** * @return The id of the controlpoint used for ordering purposes @@ -26,23 +26,14 @@ class CControlPoint { [[nodiscard]] uint32_t getFlags () const; protected: - explicit CControlPoint (uint32_t id, uint32_t flags = 0); - - /** - * @param offset The new offset - */ - void setOffset (const glm::vec3& offset); - /** - * @param flags The new flags - */ - void setFlags (uint32_t flags); + explicit CControlPoint (uint32_t id, uint32_t flags, glm::vec3 offset); private: /** ID used for ordering purposes */ - uint32_t m_id; + const uint32_t m_id; /** Flags that control how it behaves */ - uint32_t m_flags; + const uint32_t m_flags; /** The offset from starting position */ - glm::vec3 m_offset; + const glm::vec3 m_offset; }; } // namespace WallpaperEngine::Core::Objects::Particles diff --git a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp index 35628f7..0dafe29 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp @@ -2,17 +2,12 @@ using namespace WallpaperEngine::Core::Objects::Particles; -CEmitter* CEmitter::fromJSON (json data) { - const auto directions_it = jsonFindRequired (data, "directions", "Particle emitter must have direction specified"); +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"); - const auto id_it = data.find ("id"); - const auto name_it = jsonFindRequired (data, "name", "Particle emitter must have a name"); - const auto origin_it = jsonFindRequired (data, "origin", "Particle emitter must have an origin"); - const auto rate_it = jsonFindRequired (data, "rate", "Particle emitter must have a rate"); - glm::vec3 distancemin = glm::vec3(0); - glm::vec3 distancemax = glm::vec3(0); + auto distancemin = glm::vec3(0); + auto distancemax = glm::vec3(0); if (distancemin_it->is_number()) { distancemin = glm::vec3(static_cast(*distancemin_it)); @@ -26,18 +21,26 @@ CEmitter* CEmitter::fromJSON (json data) { distancemax = WallpaperEngine::Core::aToVector3(*distancemax_it); } - return new CEmitter (WallpaperEngine::Core::aToVector3 (*directions_it), distancemax, distancemin, - (id_it == data.end () ? 0 : static_cast (*id_it)), *name_it, - WallpaperEngine::Core::aToVector3 (*origin_it), *rate_it); + return new CEmitter ( + jsonFindRequired (data, "directions", "Particle emitter must have direction specified"), + distancemax, + distancemin, + jsonFindDefault (data, "id", 0), + jsonFindRequired (data, "name", "Particle emitter must have a name"), + jsonFindRequired (data, "origin", "Particle emitter must have an origin"), + jsonFindRequired (data, "rate", "Particle emitter must have a rate") + ); } -CEmitter::CEmitter (const glm::vec3& directions, const glm::vec3& distancemax, const glm::vec3& distancemin, uint32_t id, - std::string name, const glm::vec3& origin, double 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_name (name), m_origin (origin), m_rate (rate) {} @@ -65,6 +68,6 @@ const glm::vec3& CEmitter::getOrigin () const { return this->m_origin; } -const double CEmitter::getRate () const { +double CEmitter::getRate () const { return this->m_rate; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h index ef5221e..80f3b69 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h +++ b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h @@ -10,7 +10,7 @@ using json = nlohmann::json; */ class CEmitter { public: - static CEmitter* fromJSON (json data); + static const CEmitter* fromJSON (const json& data); /** * @return The ID of the emitter @@ -39,25 +39,26 @@ class CEmitter { /** * @return The rate of particle emission */ - [[nodiscard]] const double getRate () const; + [[nodiscard]] double getRate () const; protected: - CEmitter (const glm::vec3& directions, const glm::vec3& distancemax, const glm::vec3& distancemin, uint32_t id, std::string name, - const glm::vec3& origin, double rate); + 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 */ - glm::vec3 m_directions; + const glm::vec3 m_directions; /** Maximum distance before the particle is dead */ - glm::vec3 m_distancemax; + const glm::vec3 m_distancemax; /** Minimum distance before the particle is dead */ - glm::vec3 m_distancemin; + const glm::vec3 m_distancemin; /** ID of the emitter */ - uint32_t m_id; + const uint32_t m_id; /** Name of the emitter, indicates the type of emitter */ - std::string m_name; + const std::string m_name; /** The center of the emitter */ - glm::vec3 m_origin; + const glm::vec3 m_origin; /** The rate of emission */ double m_rate; }; diff --git a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp index bf55c26..703e34a 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp @@ -12,40 +12,41 @@ using namespace WallpaperEngine::Core::Objects::Particles; -CInitializer* CInitializer::fromJSON (json data) { - const auto id_it = data.find ("id"); - const auto name_it = jsonFindRequired (data, "name", "Particle's initializer must have a name"); - const uint32_t id = ((id_it == data.end ()) ? 0 : static_cast (*id_it)); +const CInitializer* CInitializer::fromJSON (const json& data) { + const auto name = jsonFindRequired (data, "name", "Particle's initializer must have a name"); + const auto id = jsonFindDefault (data, "id", 0); - if (*name_it == "lifetimerandom") { + if (name == "lifetimerandom") { return Initializers::CLifeTimeRandom::fromJSON (data, id); } - if (*name_it == "sizerandom") { + if (name == "sizerandom") { return Initializers::CSizeRandom::fromJSON (data, id); } - if (*name_it == "rotationrandom") { + if (name == "rotationrandom") { return Initializers::CRotationRandom::fromJSON (data, id); } - if (*name_it == "velocityrandom") { + if (name == "velocityrandom") { return Initializers::CVelocityRandom::fromJSON (data, id); } - if (*name_it == "colorrandom") { + if (name == "colorrandom") { return Initializers::CColorRandom::fromJSON (data, id); } - if (*name_it == "alpharandom") { + if (name == "alpharandom") { return Initializers::CAlphaRandom::fromJSON (data, id); } - if (*name_it == "angularvelocityrandom") { + if (name == "angularvelocityrandom") { return Initializers::CAngularVelocityRandom::fromJSON (data, id); } - if (*name_it == "turbulentvelocityrandom") { + if (name == "turbulentvelocityrandom") { return Initializers::CTurbulentVelocityRandom::fromJSON (data, id); } - sLog.exception ("Found unknown initializer for particles: ", *name_it); + sLog.exception ("Found unknown initializer for particles: ", name); } -CInitializer::CInitializer (uint32_t id, std::string name) : m_id (id), m_name (std::move (name)) {} +CInitializer::CInitializer (uint32_t id, std::string name) : + m_id (id), + m_name (name) {} const std::string& CInitializer::getName () const { return this->m_name; diff --git a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h index e085f6c..e012651 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h +++ b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h @@ -11,7 +11,7 @@ using json = nlohmann::json; */ class CInitializer { public: - static CInitializer* fromJSON (json data); + static const CInitializer* fromJSON (const json& data); /** * @return The name of the particle initializer, indicates what type of initialization to do @@ -27,8 +27,8 @@ class CInitializer { private: /** ID for ordering purposes */ - uint32_t m_id; + const uint32_t m_id; /** The name of the initializer, indicates what type of initialization to do */ - std::string m_name; + const std::string m_name; }; } // namespace WallpaperEngine::Core::Objects::Particles diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp index ec2bb8c..2d33066 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp @@ -2,11 +2,12 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; -CAlphaRandom* CAlphaRandom::fromJSON (json data, uint32_t id) { - const auto min_it = jsonFindRequired (data, "min", "Alpharandom initializer must have a minimum value"); - const auto max_it = jsonFindRequired (data, "max", "Alpharandom initializer must have a maximum value"); - - return new CAlphaRandom (id, *min_it, *max_it); +const CAlphaRandom* CAlphaRandom::fromJSON (const json& data, uint32_t id) { + return new CAlphaRandom ( + id, + jsonFindRequired (data, "min", "Alpharandom initializer must have a minimum value"), + jsonFindRequired (data, "max", "Alpharandom initializer must have a maximum value") + ); } CAlphaRandom::CAlphaRandom (uint32_t id, double min, double max) : diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h index 8df942a..4c3e08b 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h @@ -21,14 +21,14 @@ class CAlphaRandom : CInitializer { protected: friend class CInitializer; - static CAlphaRandom* fromJSON (json data, uint32_t id); + static const CAlphaRandom* fromJSON (const json& data, uint32_t id); CAlphaRandom (uint32_t id, double min, double max); private: /** Maximum alpha */ - double m_max; + const double m_max; /** Minimum alpha */ - double m_min; + const double m_min; }; } // namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp index 917064c..838e90e 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp @@ -2,12 +2,12 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; -CAngularVelocityRandom* CAngularVelocityRandom::fromJSON (json data, uint32_t id) { - const auto min_it = jsonFindRequired (data, "min", "Angularvelocityrandom initializer must have a minimum value"); - const auto max_it = jsonFindRequired (data, "max", "Angularvelocityrandom initializer must have a maximum value"); - - return new CAngularVelocityRandom (id, WallpaperEngine::Core::aToVector3 (*min_it), - WallpaperEngine::Core::aToVector3 (*max_it)); +const CAngularVelocityRandom* CAngularVelocityRandom::fromJSON (const json& data, uint32_t id) { + return new CAngularVelocityRandom ( + id, + jsonFindRequired (data, "min", "Angularvelocityrandom initializer must have a minimum value"), + jsonFindRequired (data, "max", "Angularvelocityrandom initializer must have a maximum value") + ); } CAngularVelocityRandom::CAngularVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max) : diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h index b04d87d..ffc99ee 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h @@ -21,14 +21,14 @@ class CAngularVelocityRandom : CInitializer { protected: friend class CInitializer; - static CAngularVelocityRandom* fromJSON (json data, uint32_t id); + 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) */ - glm::vec3 m_max; + const glm::vec3 m_max; /** Minimum velocity (direction * speed) */ - glm::vec3 m_min; + const glm::vec3 m_min; }; } // namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp index 1ca2918..e23c019 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp @@ -2,12 +2,12 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; -CColorRandom* CColorRandom::fromJSON (json data, uint32_t id) { - const auto min_it = jsonFindRequired (data, "min", "Colorrandom initializer must have a minimum value"); - const auto max_it = jsonFindRequired (data, "max", "Colorrandom initializer must have a maximum value"); - - return new CColorRandom (id, WallpaperEngine::Core::aToColori (*min_it), - WallpaperEngine::Core::aToColori (*max_it)); +const CColorRandom* CColorRandom::fromJSON (const json& data, uint32_t id) { + return new CColorRandom ( + id, + jsonFindRequired (data, "min", "Colorrandom initializer must have a minimum value"), + jsonFindRequired (data, "max", "Colorrandom initializer must have a maximum value") + ); } CColorRandom::CColorRandom (uint32_t id, glm::ivec3 min, glm::ivec3 max) : diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h index af7cc2d..b84f30b 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h @@ -22,14 +22,14 @@ class CColorRandom : CInitializer { protected: friend class CInitializer; - static CColorRandom* fromJSON (json data, uint32_t id); + static const CColorRandom* fromJSON (const json& data, uint32_t id); CColorRandom (uint32_t id, glm::ivec3 min, glm::ivec3 max); private: /** Maximum color */ - glm::ivec3 m_max; + const glm::ivec3 m_max; /** Minimum color */ - glm::ivec3 m_min; + const glm::ivec3 m_min; }; } // namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp index e6c0ca6..421ca2e 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp @@ -2,11 +2,12 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; -CLifeTimeRandom* CLifeTimeRandom::fromJSON (json data, uint32_t id) { - const auto min_it = jsonFindRequired (data, "min", "Lifetimerandom initializer must have a minimum value"); - const auto max_it = jsonFindRequired (data, "max", "Lifetimerandom initializer must have a maximum value"); - - return new CLifeTimeRandom (id, *min_it, *max_it); +const CLifeTimeRandom* CLifeTimeRandom::fromJSON (const json& data, uint32_t id) { + return new CLifeTimeRandom ( + id, + jsonFindRequired (data, "min", "Lifetimerandom initializer must have a minimum value"), + jsonFindRequired (data, "max", "Lifetimerandom initializer must have a maximum value") + ); } CLifeTimeRandom::CLifeTimeRandom (uint32_t id, uint32_t min, uint32_t max) : diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h index 6285efb..efdf379 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h @@ -22,14 +22,14 @@ class CLifeTimeRandom : CInitializer { protected: friend class CInitializer; - static CLifeTimeRandom* fromJSON (json data, uint32_t id); + static const CLifeTimeRandom* fromJSON (const json& data, uint32_t id); CLifeTimeRandom (uint32_t id, uint32_t min, uint32_t max); private: /** Maximum lifetime */ - uint32_t m_max; + const uint32_t m_max; /** Minimum lifetime */ - uint32_t m_min; + const uint32_t m_min; }; } // namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp index adc4cf4..0787bf7 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp @@ -4,7 +4,7 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; -CRotationRandom* CRotationRandom::fromJSON (json data, uint32_t id) { +const CRotationRandom* CRotationRandom::fromJSON (const json& data, uint32_t id) { const auto min_it = data.find ("minVector"); const auto max_it = data.find ("max"); diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h index 5e92e7c..cc5d2ff 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h @@ -47,24 +47,24 @@ class CRotationRandom : CInitializer { protected: friend class CInitializer; - static CRotationRandom* fromJSON (json data, uint32_t id); + 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 */ - glm::vec3 m_maxVector; + const glm::vec3 m_maxVector; /** Maximum rotation angle */ - double m_maxNumber; + const double m_maxNumber; /** Minimum rotation vector */ - glm::vec3 m_minVector; + const glm::vec3 m_minVector; /** Minimum rotation angle */ - double m_minNumber; + const double m_minNumber; /** If minimum is a vector */ - bool m_isMinimumVector; + const bool m_isMinimumVector; /** If maximum is a vector */ - bool m_isMaximumVector; + const bool m_isMaximumVector; }; } // namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp index 687655d..191ff37 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp @@ -2,11 +2,12 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; -CSizeRandom* CSizeRandom::fromJSON (json data, uint32_t id) { - const auto min_it = jsonFindRequired (data, "min", "Sizerandom initializer must have a minimum value"); - const auto max_it = jsonFindRequired (data, "max", "Sizerandom initializer must have a maximum value"); - - return new CSizeRandom (id, *min_it, *max_it); +const CSizeRandom* CSizeRandom::fromJSON (const json& data, uint32_t id) { + return new CSizeRandom ( + id, + jsonFindRequired (data, "min", "Sizerandom initializer must have a minimum value"), + jsonFindRequired (data, "max", "Sizerandom initializer must have a maximum value") + ); } CSizeRandom::CSizeRandom (uint32_t id, uint32_t min, uint32_t max) : diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h index 9dcf4f9..a398760 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h @@ -22,14 +22,14 @@ class CSizeRandom : CInitializer { protected: friend class CInitializer; - static CSizeRandom* fromJSON (json data, uint32_t id); + static const CSizeRandom* fromJSON (const json& data, uint32_t id); CSizeRandom (uint32_t id, uint32_t min, uint32_t max); private: /** Maximum size */ - uint32_t m_max; + const uint32_t m_max; /** Minimum size */ - uint32_t m_min; + const uint32_t m_min; }; } // namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.cpp index dd3cce7..a7a95c1 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.cpp @@ -5,25 +5,15 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; -CTurbulentVelocityRandom* CTurbulentVelocityRandom::fromJSON (json data, uint32_t id) { - const auto phasemax_it = data.find ("phasemax"); - const auto scale_it = data.find ("scale"); - const auto speedmax_it = data.find ("speedmax"); - const auto speedmin_it = data.find ("speedmin"); - const auto timescale_it = data.find ("timescale"); - - if (phasemax_it == data.end ()) - sLog.exception ("TurbulentVelocityRandom initializer must have a phasemax value"); - if (scale_it == data.end ()) - sLog.exception ("TurbulentVelocityRandom initializer must have a scale value"); - if (speedmax_it == data.end ()) - sLog.exception ("TurbulentVelocityRandom initializer must have a maximum speed value"); - if (speedmin_it == data.end ()) - sLog.exception ("TurbulentVelocityRandom initializer must have a minimum speed value"); - if (timescale_it == data.end ()) - sLog.exception ("TurbulentVelocityRandom initializer must have a timescale value"); - - return new CTurbulentVelocityRandom (id, *phasemax_it, *scale_it, *timescale_it, *speedmin_it, *speedmax_it); +const CTurbulentVelocityRandom* CTurbulentVelocityRandom::fromJSON (const json& data, uint32_t id) { + return new CTurbulentVelocityRandom ( + id, + jsonFindRequired (data, "phasemax", "TurbulentVelocityRandom initializer must have a phasemax value"), + jsonFindRequired (data, "scale", "TurbulentVelocityRandom initializer must have a scale value"), + jsonFindRequired (data, "timescale", "TurbulentVelocityRandom initializer must have a timescale value"), + jsonFindRequired (data, "speedmin", "TurbulentVelocityRandom initializer must have a minimum speed value"), + jsonFindRequired (data, "speedmax", "TurbulentVelocityRandom initializer must have a maximum speed value") + ); } CTurbulentVelocityRandom::CTurbulentVelocityRandom (uint32_t id, double phasemax, double scale, double timescale, diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h index 33250fc..1e27d19 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h @@ -34,21 +34,21 @@ class CTurbulentVelocityRandom : CInitializer { protected: friend class CInitializer; - static CTurbulentVelocityRandom* fromJSON (json data, uint32_t id); + 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 */ - double m_phasemax; + const double m_phasemax; /** Scale */ - double m_scale; + const double m_scale; /** Time scale, how the time affects the scale */ - double m_timescale; + const double m_timescale; /** Minimum speed */ - uint32_t m_speedmin; + const uint32_t m_speedmin; /** Maximum speed */ - uint32_t m_speedmax; + const uint32_t m_speedmax; }; } // namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp index 1128d8d..3559850 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp @@ -2,12 +2,12 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; -CVelocityRandom* CVelocityRandom::fromJSON (json data, uint32_t id) { - const auto min_it = jsonFindRequired (data, "min", "Velocityrandom initializer must have a minimum value"); - const auto max_it = jsonFindRequired (data, "max", "Velocityrandom initializer must have a maximum value"); - - return new CVelocityRandom (id, WallpaperEngine::Core::aToVector3 (*min_it), - WallpaperEngine::Core::aToVector3 (*max_it)); +const CVelocityRandom* CVelocityRandom::fromJSON (const json& data, uint32_t id) { + return new CVelocityRandom ( + id, + jsonFindRequired (data, "min", "Velocityrandom initializer must have a minimum value"), + jsonFindRequired (data, "max", "Velocityrandom initializer must have a maximum value") + ); } CVelocityRandom::CVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max) : diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h index bce80b1..1fb390a 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h @@ -22,14 +22,14 @@ class CVelocityRandom : CInitializer { protected: friend class CInitializer; - static CVelocityRandom* fromJSON (json data, uint32_t id); + static const CVelocityRandom* fromJSON (const json& data, uint32_t id); CVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max); private: /** Maximum velocity */ - glm::vec3 m_max; + const glm::vec3 m_max; /** Minimum velocity */ - glm::vec3 m_min; + const glm::vec3 m_min; }; } // namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Projects/CProperty.cpp b/src/WallpaperEngine/Core/Projects/CProperty.cpp index e7b9a63..8738330 100644 --- a/src/WallpaperEngine/Core/Projects/CProperty.cpp +++ b/src/WallpaperEngine/Core/Projects/CProperty.cpp @@ -9,7 +9,7 @@ using namespace WallpaperEngine::Core::Projects; -CProperty* CProperty::fromJSON (json data, const std::string& name) { +const 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 == CPropertyColor::Type) @@ -31,9 +31,9 @@ CProperty* CProperty::fromJSON (json data, const std::string& name) { } CProperty::CProperty (std::string name, std::string type, std::string text) : - m_type (std::move (type)), - m_name (std::move (name)), - m_text (std::move (text)) {} + m_type (type), + m_name (name), + m_text (text) {} const std::string& CProperty::getName () const { return this->m_name; diff --git a/src/WallpaperEngine/Core/Projects/CProperty.h b/src/WallpaperEngine/Core/Projects/CProperty.h index ef26d68..5b7436d 100644 --- a/src/WallpaperEngine/Core/Projects/CProperty.h +++ b/src/WallpaperEngine/Core/Projects/CProperty.h @@ -16,7 +16,7 @@ class CPropertyColor; class CProperty { public: virtual ~CProperty () = default; - static CProperty* fromJSON (json data, const std::string& name); + static const CProperty* fromJSON (const json& data, const std::string& name); template const T* as () const { assert (is ()); @@ -28,7 +28,7 @@ class CProperty { return reinterpret_cast (this); } - template bool is () { + template bool is () const { return this->m_type == T::Type; } @@ -41,7 +41,7 @@ class CProperty { * * @param value New value for the property */ - virtual void update (const std::string& value) = 0; + virtual void update (const std::string& value) const = 0; /** * @return Name of the property @@ -60,10 +60,10 @@ class CProperty { CProperty (std::string name, std::string type, std::string text); /** Type of property */ - std::string m_type; + const std::string m_type; /** Name of the property */ - std::string m_name; + const std::string m_name; /** Description of the property for the user */ - std::string m_text; + mutable std::string m_text; }; } // namespace WallpaperEngine::Core::Projects diff --git a/src/WallpaperEngine/Core/Projects/CPropertyBoolean.cpp b/src/WallpaperEngine/Core/Projects/CPropertyBoolean.cpp index 950cd9d..4c674c2 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyBoolean.cpp +++ b/src/WallpaperEngine/Core/Projects/CPropertyBoolean.cpp @@ -5,18 +5,19 @@ using namespace WallpaperEngine::Core::Projects; -CPropertyBoolean* CPropertyBoolean::fromJSON (json data, const std::string& name) { - const json::const_iterator value = data.find ("value"); - const auto text = jsonFindDefault (data, "text", ""); - - return new CPropertyBoolean (*value, name, text); +const CPropertyBoolean* CPropertyBoolean::fromJSON (const json& data, std::string name) { + return new CPropertyBoolean ( + jsonFindRequired (data, "value", "Boolean property must have a value"), + name, + jsonFindDefault (data, "text", "") + ); } bool CPropertyBoolean::getValue () const { return this->m_value; } -void CPropertyBoolean::update (const std::string& value) { +void CPropertyBoolean::update (const std::string& value) const { this->m_value = value == "1" || value == "true"; } @@ -32,7 +33,7 @@ std::string CPropertyBoolean::dump () const { return ss.str (); } -CPropertyBoolean::CPropertyBoolean (bool value, const std::string& name, const std::string& text) : +CPropertyBoolean::CPropertyBoolean (bool value, std::string name, std::string text) : CProperty (name, Type, text), m_value (value) {} diff --git a/src/WallpaperEngine/Core/Projects/CPropertyBoolean.h b/src/WallpaperEngine/Core/Projects/CPropertyBoolean.h index de4702b..9219aa0 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyBoolean.h +++ b/src/WallpaperEngine/Core/Projects/CPropertyBoolean.h @@ -10,7 +10,7 @@ using json = nlohmann::json; */ class CPropertyBoolean final : public CProperty { public: - static CPropertyBoolean* fromJSON (json data, const std::string& name); + static const CPropertyBoolean* fromJSON (const json& data, std::string name); /** * @return The value of the property @@ -19,14 +19,14 @@ class CPropertyBoolean final : public CProperty { /** @inheritdoc */ [[nodiscard]] std::string dump () const override; /** @inheritdoc */ - void update (const std::string& value) override; + void update (const std::string& value) const override; static const std::string Type; private: - CPropertyBoolean (bool value, const std::string& name, const std::string& text); + CPropertyBoolean (bool value, std::string name, std::string text); /** Property's value */ - bool m_value; + mutable bool m_value; }; } // namespace WallpaperEngine::Core::Projects diff --git a/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp b/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp index d350465..b7146a7 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp +++ b/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp @@ -19,7 +19,7 @@ glm::vec3 ParseColor (std::string value) { return WallpaperEngine::Core::aToColorf (value); } -CPropertyColor* CPropertyColor::fromJSON (json data, const std::string& name) { +const CPropertyColor* CPropertyColor::fromJSON (const json& data, std::string name) { const std::string value = *jsonFindRequired (data, "value", "Color property must have a value"); const auto text = jsonFindDefault (data, "text", ""); @@ -30,7 +30,7 @@ const glm::vec3& CPropertyColor::getValue () const { return this->m_color; } -void CPropertyColor::update (const std::string& value) { +void CPropertyColor::update (const std::string& value) const { this->m_color = ParseColor (std::string (value)); } @@ -46,7 +46,7 @@ std::string CPropertyColor::dump () const { return ss.str (); } -CPropertyColor::CPropertyColor (glm::vec3 color, const std::string& name, const std::string& text) : +CPropertyColor::CPropertyColor (glm::vec3 color, std::string name, std::string text) : CProperty (name, Type, text), m_color (color) {} diff --git a/src/WallpaperEngine/Core/Projects/CPropertyColor.h b/src/WallpaperEngine/Core/Projects/CPropertyColor.h index cdfb083..ce2b9d4 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyColor.h +++ b/src/WallpaperEngine/Core/Projects/CPropertyColor.h @@ -12,20 +12,20 @@ using json = nlohmann::json; */ class CPropertyColor final : public CProperty { public: - static CPropertyColor* fromJSON (json data, const std::string& name); + static const CPropertyColor* fromJSON (const json& data, std::string name); /** * @return The RGB color value in the 0-1 range */ [[nodiscard]] const glm::vec3& getValue () const; [[nodiscard]] std::string dump () const override; - void update (const std::string& value) override; + void update (const std::string& value) const override; static const std::string Type; private: - CPropertyColor (glm::vec3 color, const std::string& name, const std::string& text); + CPropertyColor (glm::vec3 color, std::string name, std::string text); - glm::vec3 m_color; + mutable glm::vec3 m_color; }; } // namespace WallpaperEngine::Core::Projects diff --git a/src/WallpaperEngine/Core/Projects/CPropertyCombo.cpp b/src/WallpaperEngine/Core/Projects/CPropertyCombo.cpp index 15c5acb..51376fa 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyCombo.cpp +++ b/src/WallpaperEngine/Core/Projects/CPropertyCombo.cpp @@ -4,17 +4,13 @@ #include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Logging/CLog.h" -#include using namespace WallpaperEngine::Core::Projects; -CPropertyCombo* CPropertyCombo::fromJSON (json data, const std::string& name) { - const auto value = data.find ("value"); - const auto text = jsonFindDefault (data, "text", ""); +const CPropertyCombo* CPropertyCombo::fromJSON (const json& data, std::string name) { + std::vector values; const auto options = jsonFindRequired (data, "options", "Options for a property combo is required"); - auto* combo = new CPropertyCombo (name, text, value->dump ()); - if (!options->is_array ()) sLog.exception ("Property combo options should be an array"); @@ -24,18 +20,27 @@ CPropertyCombo* CPropertyCombo::fromJSON (json data, const std::string& name) { continue; // check for label and value to ensure they're there - auto label = jsonFindRequired (cur, "label", "Label is required for a property combo option"); - auto propertyValue = jsonFindRequired (cur, "value", "Value is required for a property combo option"); + auto prop = new CPropertyComboValue { + .label = jsonFindRequired (cur, "label", "Label is required for a property combo option"), + .value = jsonFindRequired (cur, "value", "Value is required for a property combo option") + }; - combo->addValue (*label, propertyValue->dump()); + values.push_back (prop); } - return combo; + return new CPropertyCombo ( + name, + jsonFindDefault (data, "text", ""), + jsonFindRequired (data, "value", "Value is required for a property combo")->dump (), + values + ); } -CPropertyCombo::CPropertyCombo (const std::string& name, const std::string& text, std::string defaultValue) : +CPropertyCombo::CPropertyCombo ( + std::string name, std::string text, std::string defaultValue, std::vector values +) : CProperty (name, Type, text), - m_defaultValue (std::move (defaultValue)) {} + m_defaultValue (defaultValue) {} CPropertyCombo::~CPropertyCombo () { for (const auto* value : this->m_values) @@ -63,7 +68,7 @@ std::string CPropertyCombo::dump () const { return ss.str (); } -void CPropertyCombo::update (const std::string& value) { +void CPropertyCombo::update (const std::string& value) const { bool found = false; // ensure the value is present somewhere in the value list @@ -80,13 +85,4 @@ void CPropertyCombo::update (const std::string& value) { this->m_defaultValue = value; } -void CPropertyCombo::addValue (std::string label, std::string value) { - auto* prop = new CPropertyComboValue; - - prop->label = std::move (label); - prop->value = std::move (value); - - this->m_values.push_back (prop); -} - const std::string CPropertyCombo::Type = "combo"; \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Projects/CPropertyCombo.h b/src/WallpaperEngine/Core/Projects/CPropertyCombo.h index 47275af..a4a0cde 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyCombo.h +++ b/src/WallpaperEngine/Core/Projects/CPropertyCombo.h @@ -10,8 +10,8 @@ using json = nlohmann::json; */ class CPropertyComboValue { public: - std::string label; - std::string value; + const std::string label; + const std::string value; }; /** @@ -23,7 +23,7 @@ class CPropertyComboValue { */ class CPropertyCombo final : public CProperty { public: - static CPropertyCombo* fromJSON (json data, const std::string& name); + static const CPropertyCombo* fromJSON (const json& data, std::string name); ~CPropertyCombo () override; @@ -32,24 +32,17 @@ class CPropertyCombo final : public CProperty { */ [[nodiscard]] const std::string& getValue () const; [[nodiscard]] std::string dump () const override; - void update (const std::string& value) override; + void update (const std::string& value) const override; static const std::string Type; private: - CPropertyCombo (const std::string& name, const std::string& text, std::string defaultValue); - - /** - * Adds a combo value to the list of possible values - * - * @param label - * @param value - */ - void addValue (std::string label, std::string value); + CPropertyCombo ( + std::string name, std::string text, std::string defaultValue, std::vector values); /** List of values available to select */ - std::vector m_values; + const std::vector m_values; /** The default value */ - std::string m_defaultValue; + mutable std::string m_defaultValue; }; } // namespace WallpaperEngine::Core::Projects diff --git a/src/WallpaperEngine/Core/Projects/CPropertySlider.cpp b/src/WallpaperEngine/Core/Projects/CPropertySlider.cpp index defce2f..7dd4153 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertySlider.cpp +++ b/src/WallpaperEngine/Core/Projects/CPropertySlider.cpp @@ -4,7 +4,7 @@ using namespace WallpaperEngine::Core::Projects; -CPropertySlider* CPropertySlider::fromJSON (json data, const std::string& name) { +const CPropertySlider* CPropertySlider::fromJSON (const json& data, const std::string& name) { const auto value = data.find ("value"); const auto text = jsonFindDefault (data, "text", ""); const auto min = jsonFindDefault (data, "min", 0.0); @@ -48,8 +48,8 @@ std::string CPropertySlider::dump () const { return ss.str (); } -void CPropertySlider::update (const std::string& value) { - const double newValue = strtod (value.c_str (), nullptr); +void CPropertySlider::update (const std::string& value) const { + const auto newValue = strtod (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, ")"); diff --git a/src/WallpaperEngine/Core/Projects/CPropertySlider.h b/src/WallpaperEngine/Core/Projects/CPropertySlider.h index d651526..d22f8d3 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertySlider.h +++ b/src/WallpaperEngine/Core/Projects/CPropertySlider.h @@ -12,7 +12,7 @@ using json = nlohmann::json; */ class CPropertySlider final : public CProperty { public: - static CPropertySlider* fromJSON (json data, const std::string& name); + static const CPropertySlider* fromJSON (const json& data, const std::string& name); /** * @return The slider's value @@ -31,21 +31,20 @@ class CPropertySlider final : public CProperty { */ [[nodiscard]] const double& getStep () const; [[nodiscard]] std::string dump () const override; - void update (const std::string& value) override; + void update (const std::string& value) const override; static const std::string Type; private: - CPropertySlider (double value, const std::string& name, const std::string& text, double min, double max, - double step); + CPropertySlider (double value, const std::string& name, const std::string& text, double min, double max, double step); /** Actual slider value */ - double m_value; + mutable double m_value; /** Minimum value */ - double m_min; + const double m_min; /** Maximum value */ - double m_max; + const double m_max; /** Increment steps for the slider in the UI */ - double m_step; + const double m_step; }; } // namespace WallpaperEngine::Core::Projects diff --git a/src/WallpaperEngine/Core/Projects/CPropertyText.cpp b/src/WallpaperEngine/Core/Projects/CPropertyText.cpp index b6892aa..1a9d85a 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyText.cpp +++ b/src/WallpaperEngine/Core/Projects/CPropertyText.cpp @@ -4,8 +4,8 @@ using namespace WallpaperEngine::Core::Projects; -CPropertyText* CPropertyText::fromJSON (json data, const std::string& name) { - const json::const_iterator text = data.find ("type"); +const CPropertyText* CPropertyText::fromJSON (const json& data, std::string name) { + const auto text = data.find ("type"); return new CPropertyText (name, *text); } @@ -20,10 +20,10 @@ std::string CPropertyText::dump () const { return ss.str (); } -void CPropertyText::update (const std::string& value) { +void CPropertyText::update (const std::string& value) const { this->m_text = value; } -CPropertyText::CPropertyText (const std::string& name, const std::string& text) : CProperty (name, Type, text) {} +CPropertyText::CPropertyText (std::string name, std::string text) : CProperty (name, Type, text) {} const std::string CPropertyText::Type = "text"; \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Projects/CPropertyText.h b/src/WallpaperEngine/Core/Projects/CPropertyText.h index 1586076..838f399 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyText.h +++ b/src/WallpaperEngine/Core/Projects/CPropertyText.h @@ -10,13 +10,13 @@ using json = nlohmann::json; */ class CPropertyText final : public CProperty { public: - static CPropertyText* fromJSON (json data, const std::string& name); + static const CPropertyText* fromJSON (const json& data, std::string name); [[nodiscard]] std::string dump () const override; - void update (const std::string& value) override; + void update (const std::string& value) const override; static const std::string Type; private: - CPropertyText (const std::string& name, const std::string& text); + CPropertyText (std::string name, std::string text); }; } // namespace WallpaperEngine::Core::Projects diff --git a/src/WallpaperEngine/Core/Scenes/CCamera.cpp b/src/WallpaperEngine/Core/Scenes/CCamera.cpp index 3cae285..05118bc 100644 --- a/src/WallpaperEngine/Core/Scenes/CCamera.cpp +++ b/src/WallpaperEngine/Core/Scenes/CCamera.cpp @@ -2,7 +2,10 @@ using namespace WallpaperEngine::Core::Scenes; -CCamera::CCamera (glm::vec3 center, glm::vec3 eye, glm::vec3 up) : m_center (center), m_eye (eye), m_up (up) {} +CCamera::CCamera (glm::vec3 center, glm::vec3 eye, glm::vec3 up) : + m_center (center), + m_eye (eye), + m_up (up) {} const glm::vec3& CCamera::getCenter () const { return this->m_center; @@ -16,11 +19,10 @@ const glm::vec3& CCamera::getUp () const { return this->m_up; } -CCamera* CCamera::fromJSON (json data) { - const auto center_it = jsonFindRequired (data, "center", "Camera must have a center position"); - const auto eye_it = jsonFindRequired (data, "eye", "Camera must have an eye position"); - const auto up_it = jsonFindRequired (data, "up", "Camera must have a up position"); - - return new CCamera (WallpaperEngine::Core::aToVector3 (*center_it), WallpaperEngine::Core::aToVector3 (*eye_it), - WallpaperEngine::Core::aToVector3 (*up_it)); +const CCamera* CCamera::fromJSON (const json::const_iterator& data) { + return new CCamera ( + jsonFindRequired (data, "center", "Camera must have a center position"), + jsonFindRequired (data, "eye", "Camera must have an eye position"), + jsonFindRequired (data, "up", "Camera must have a up position") + ); } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Scenes/CCamera.h b/src/WallpaperEngine/Core/Scenes/CCamera.h index 7ef63ca..5d2f17f 100644 --- a/src/WallpaperEngine/Core/Scenes/CCamera.h +++ b/src/WallpaperEngine/Core/Scenes/CCamera.h @@ -7,7 +7,7 @@ using json = nlohmann::json; class CCamera { public: - static CCamera* fromJSON (json data); + static const CCamera* fromJSON (const json::const_iterator& data); const glm::vec3& getCenter () const; const glm::vec3& getEye () const; @@ -17,8 +17,8 @@ class CCamera { CCamera (glm::vec3 center, glm::vec3 eye, glm::vec3 up); private: - glm::vec3 m_center; - glm::vec3 m_eye; - glm::vec3 m_up; + const glm::vec3 m_center; + const glm::vec3 m_eye; + const glm::vec3 m_up; }; } // namespace WallpaperEngine::Core::Scenes diff --git a/src/WallpaperEngine/Core/Scenes/CProjection.cpp b/src/WallpaperEngine/Core/Scenes/CProjection.cpp index c3e4ccd..d9ee5b0 100644 --- a/src/WallpaperEngine/Core/Scenes/CProjection.cpp +++ b/src/WallpaperEngine/Core/Scenes/CProjection.cpp @@ -2,9 +2,15 @@ using namespace WallpaperEngine::Core::Scenes; -CProjection::CProjection (int width, int height) : m_width (width), m_height (height), m_isAuto (false) {} +CProjection::CProjection (int width, int height) : + m_width (width), + m_height (height), + m_isAuto (false) {} -CProjection::CProjection (bool isAuto) : m_width (0), m_height (0), m_isAuto (isAuto) {} +CProjection::CProjection (bool isAuto) : + m_width (0), + m_height (0), + m_isAuto (isAuto) {} const int& CProjection::getWidth () const { return this->m_width; @@ -18,15 +24,15 @@ bool CProjection::isAuto () const { return this->m_isAuto; } -void CProjection::setWidth (int width) { +void CProjection::setWidth (int width) const { this->m_width = width; } -void CProjection::setHeight (int height) { +void CProjection::setHeight (int height) const { this->m_height = height; } -CProjection* CProjection::fromJSON (json data) { +const CProjection* CProjection::fromJSON (const json::const_iterator& data) { const auto auto_it = jsonFindDefault (data, "auto", false); const auto width_it = jsonFindRequired (data, "width", "Projection must have width"); diff --git a/src/WallpaperEngine/Core/Scenes/CProjection.h b/src/WallpaperEngine/Core/Scenes/CProjection.h index c531251..d3bfee4 100644 --- a/src/WallpaperEngine/Core/Scenes/CProjection.h +++ b/src/WallpaperEngine/Core/Scenes/CProjection.h @@ -7,22 +7,23 @@ using json = nlohmann::json; class CProjection { public: - static CProjection* fromJSON (json data); + static const CProjection* fromJSON (const json::const_iterator& data); [[nodiscard]] const int& getWidth () const; [[nodiscard]] const int& getHeight () const; [[nodiscard]] bool isAuto () const; - void setWidth (int width); - void setHeight (int height); + // TODO: CHANGE THIS SO THE RENDER IS THE ONE RESPONSIBLE FOR THIS? + void setWidth (int width) const; + void setHeight (int height) const; protected: CProjection (int width, int height); explicit CProjection (bool isAuto); private: - int m_width; - int m_height; - bool m_isAuto; + mutable int m_width; + mutable int m_height; + const bool m_isAuto; }; } // namespace WallpaperEngine::Core::Scenes diff --git a/src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.cpp b/src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.cpp index ea0c6bc..bac5139 100644 --- a/src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.cpp +++ b/src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.cpp @@ -12,16 +12,17 @@ using namespace WallpaperEngine::Core; using namespace WallpaperEngine::Core::Projects; using namespace WallpaperEngine::Core::UserSettings; -CUserSettingBoolean::CUserSettingBoolean (bool hasCondition, bool hasSource, bool defaultValue, std::string source, - std::string expectedValue) : +CUserSettingBoolean::CUserSettingBoolean ( + bool hasCondition,bool hasSource, bool defaultValue, std::string source, std::string expectedValue +) : CUserSettingValue (Type), m_default (defaultValue), m_hasCondition (hasCondition), m_hasSource (hasSource), - m_source (std::move (source)), - m_expectedValue (std::move (expectedValue)) {} + m_source (source), + m_expectedValue (expectedValue) {} -CUserSettingBoolean* CUserSettingBoolean::fromJSON (nlohmann::json& data) { +const CUserSettingBoolean* CUserSettingBoolean::fromJSON (const nlohmann::json& data) { bool hasCondition = false; bool hasSource = false; bool defaultValue; @@ -38,9 +39,9 @@ CUserSettingBoolean* CUserSettingBoolean::fromJSON (nlohmann::json& data) { source = *userIt; } else { hasCondition = true; - source = *jsonFindRequired (userIt, "name", "Name for conditional setting must be present"); + source = jsonFindRequired (userIt, "name", "Name for conditional setting must be present"); expectedValue = - *jsonFindRequired (userIt, "condition", "Condition for conditional setting must be present"); + jsonFindRequired (userIt, "condition", "Condition for conditional setting must be present"); } } else { sLog.error ("Boolean property doesn't have user member, this could mean an scripted value"); @@ -55,7 +56,7 @@ CUserSettingBoolean* CUserSettingBoolean::fromJSON (nlohmann::json& data) { return new CUserSettingBoolean (hasCondition, hasSource, defaultValue, source, expectedValue); } -CUserSettingBoolean* CUserSettingBoolean::fromScalar (bool value) { +const CUserSettingBoolean* CUserSettingBoolean::fromScalar (const bool value) { return new CUserSettingBoolean (false, false, value, "", ""); } @@ -63,7 +64,7 @@ bool CUserSettingBoolean::getDefaultValue () const { return this->m_default; } -bool CUserSettingBoolean::processValue (const std::vector& properties) { +bool CUserSettingBoolean::processValue (const std::vector& properties) const { if (!this->m_hasSource && !this->m_hasCondition) return this->getDefaultValue (); diff --git a/src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h b/src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h index 09bd047..1aa88c5 100644 --- a/src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h +++ b/src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h @@ -11,21 +11,21 @@ class CUserSettingBoolean : public CUserSettingValue { public: typedef bool data_type; - static CUserSettingBoolean* fromJSON (nlohmann::json& data); - static CUserSettingBoolean* fromScalar (bool value); + static const CUserSettingBoolean* fromJSON (const nlohmann::json& data); + static const CUserSettingBoolean* fromScalar (const bool value); static std::string Type; - bool processValue (const std::vector& properties); - bool getDefaultValue () const; + [[nodiscard]] bool processValue (const std::vector& properties) const; + [[nodiscard]] bool getDefaultValue () const; private: - CUserSettingBoolean (bool hasCondition, bool hasSource, bool defaultValue, std::string source, - std::string expectedValue); + CUserSettingBoolean ( + bool hasCondition, bool hasSource, bool defaultValue, std::string source, std::string expectedValue); - bool m_default; - bool m_hasCondition; - bool m_hasSource; - std::string m_source; - std::string m_expectedValue; + const bool m_default; + const bool m_hasCondition; + const bool m_hasSource; + const std::string m_source; + const std::string m_expectedValue; }; } // namespace WallpaperEngine::Core::UserSettings \ No newline at end of file diff --git a/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.cpp b/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.cpp index d786a72..bef0c09 100644 --- a/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.cpp +++ b/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.cpp @@ -9,16 +9,17 @@ using namespace WallpaperEngine::Core; using namespace WallpaperEngine::Core::Projects; using namespace WallpaperEngine::Core::UserSettings; -CUserSettingFloat::CUserSettingFloat (bool hasCondition, bool hasSource, double defaultValue, std::string source, - std::string expectedValue) : +CUserSettingFloat::CUserSettingFloat ( + bool hasCondition, bool hasSource, double defaultValue, std::string source, std::string expectedValue +) : CUserSettingValue (Type), m_default (defaultValue), m_hasCondition (hasCondition), m_hasSource (hasSource), - m_source (std::move (source)), - m_expectedValue (std::move (expectedValue)) {} + m_source (source), + m_expectedValue (expectedValue) {} -CUserSettingFloat* CUserSettingFloat::fromJSON (nlohmann::json& data) { +const CUserSettingFloat* CUserSettingFloat::fromJSON (const nlohmann::json& data) { double defaultValue; std::string source; std::string expectedValue; @@ -35,9 +36,9 @@ CUserSettingFloat* CUserSettingFloat::fromJSON (nlohmann::json& data) { source = *userIt; } else { hasCondition = true; - source = *jsonFindRequired (userIt, "name", "Name for conditional setting must be present"); + source = jsonFindRequired (userIt, "name", "Name for conditional setting must be present"); expectedValue = - *jsonFindRequired (userIt, "condition", "Condition for conditional setting must be present"); + jsonFindRequired (userIt, "condition", "Condition for conditional setting must be present"); } } else { sLog.error ("Float property doesn't have user member, this could mean an scripted value"); @@ -52,7 +53,7 @@ CUserSettingFloat* CUserSettingFloat::fromJSON (nlohmann::json& data) { return new CUserSettingFloat (hasCondition, hasSource, defaultValue, source, expectedValue); } -CUserSettingFloat* CUserSettingFloat::fromScalar (double value) { +const CUserSettingFloat* CUserSettingFloat::fromScalar (const double value) { return new CUserSettingFloat (false, false, value, "", ""); } @@ -60,7 +61,7 @@ double CUserSettingFloat::getDefaultValue () const { return this->m_default; } -double CUserSettingFloat::processValue (const std::vector& properties) { +double CUserSettingFloat::processValue (const std::vector& properties) const { if (!this->m_hasSource && !this->m_hasCondition) return this->getDefaultValue (); diff --git a/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.h b/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.h index 7ca5081..c926a71 100644 --- a/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.h +++ b/src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.h @@ -11,21 +11,21 @@ class CUserSettingFloat : public CUserSettingValue { public: typedef double data_type; - static CUserSettingFloat* fromJSON (nlohmann::json& data); - static CUserSettingFloat* fromScalar (double value); + static const CUserSettingFloat* fromJSON (const nlohmann::json& data); + static const CUserSettingFloat* fromScalar (const double value); static std::string Type; - double processValue (const std::vector& properties); - double getDefaultValue () const; + [[nodiscard]] double processValue (const std::vector& properties) const; + [[nodiscard]] double getDefaultValue () const; private: - CUserSettingFloat (bool hasCondition, bool hasSource, double defaultValue, std::string source, - std::string expectedValue); + CUserSettingFloat ( + bool hasCondition, bool hasSource, double defaultValue, std::string source, std::string expectedValue); - double m_default; - bool m_hasCondition; - bool m_hasSource; - std::string m_source; - std::string m_expectedValue; + const double m_default; + const bool m_hasCondition; + const bool m_hasSource; + const std::string m_source; + const std::string m_expectedValue; }; } // namespace WallpaperEngine::Core::UserSettings \ No newline at end of file diff --git a/src/WallpaperEngine/Core/UserSettings/CUserSettingValue.cpp b/src/WallpaperEngine/Core/UserSettings/CUserSettingValue.cpp index 3495739..0325bf8 100644 --- a/src/WallpaperEngine/Core/UserSettings/CUserSettingValue.cpp +++ b/src/WallpaperEngine/Core/UserSettings/CUserSettingValue.cpp @@ -4,4 +4,5 @@ using namespace WallpaperEngine::Core::UserSettings; -CUserSettingValue::CUserSettingValue (std::string type) : m_type (std::move (type)) {} \ No newline at end of file +CUserSettingValue::CUserSettingValue (std::string type) : + m_type (type) {} \ No newline at end of file diff --git a/src/WallpaperEngine/Core/UserSettings/CUserSettingValue.h b/src/WallpaperEngine/Core/UserSettings/CUserSettingValue.h index b20a1cf..d319e3d 100644 --- a/src/WallpaperEngine/Core/UserSettings/CUserSettingValue.h +++ b/src/WallpaperEngine/Core/UserSettings/CUserSettingValue.h @@ -15,7 +15,7 @@ class CUserSettingValue { return reinterpret_cast (this); } - template bool is () { + template bool is () const { return this->m_type == T::Type; } @@ -23,6 +23,6 @@ class CUserSettingValue { explicit CUserSettingValue (std::string type); private: - std::string m_type; + const std::string m_type; }; } // namespace WallpaperEngine::Core::UserSettings diff --git a/src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.cpp b/src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.cpp index 7c90f6c..9f517ed 100644 --- a/src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.cpp +++ b/src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.cpp @@ -10,16 +10,17 @@ using namespace WallpaperEngine::Core; using namespace WallpaperEngine::Core::Projects; using namespace WallpaperEngine::Core::UserSettings; -CUserSettingVector3::CUserSettingVector3 (bool hasCondition, bool hasSource, glm::vec3 defaultValue, std::string source, - std::string expectedValue) : +CUserSettingVector3::CUserSettingVector3 ( + bool hasCondition, bool hasSource, glm::vec3 defaultValue, std::string source, std::string expectedValue +) : CUserSettingValue (Type), m_default (defaultValue), m_hasCondition (hasCondition), m_hasSource (hasSource), - m_source (std::move (source)), - m_expectedValue (std::move (expectedValue)) {} + m_source (source), + m_expectedValue (expectedValue) {} -CUserSettingVector3* CUserSettingVector3::fromJSON (nlohmann::json& data) { +const CUserSettingVector3* CUserSettingVector3::fromJSON (const nlohmann::json& data) { bool hasCondition = false; bool hasSource = false; glm::vec3 defaultValue; @@ -29,17 +30,16 @@ CUserSettingVector3* CUserSettingVector3::fromJSON (nlohmann::json& data) { if (data.is_object ()) { hasSource = true; auto userIt = data.find ("user"); - defaultValue = WallpaperEngine::Core::aToColorf ( - jsonFindDefault (data, "value", "").c_str ()); // is this default value right? + defaultValue = jsonFindDefault (data, "value", glm::vec3()); // is this default value right? if (userIt != data.end ()) { if (userIt->is_string ()) { source = *userIt; } else { hasCondition = true; - source = *jsonFindRequired (userIt, "name", "Name for conditional setting must be present"); + source = jsonFindRequired (userIt, "name", "Name for conditional setting must be present"); expectedValue = - *jsonFindRequired (userIt, "condition", "Condition for conditional setting must be present"); + jsonFindRequired (userIt, "condition", "Condition for conditional setting must be present"); } } else { sLog.error ("Vector property doesn't have user member, this could mean an scripted value"); @@ -54,15 +54,15 @@ CUserSettingVector3* CUserSettingVector3::fromJSON (nlohmann::json& data) { return new CUserSettingVector3 (hasCondition, hasSource, defaultValue, source, expectedValue); } -CUserSettingVector3* CUserSettingVector3::fromScalar (glm::vec3 value) { +const CUserSettingVector3* CUserSettingVector3::fromScalar (const glm::vec3 value) { return new CUserSettingVector3 (false, false, value, "", ""); } -glm::vec3 CUserSettingVector3::getDefaultValue () const { +const glm::vec3& CUserSettingVector3::getDefaultValue () const { return this->m_default; } -glm::vec3 CUserSettingVector3::processValue (const std::vector& properties) { +const glm::vec3& CUserSettingVector3::processValue (const std::vector& properties) const { if (!this->m_hasSource && !this->m_hasCondition) return this->getDefaultValue (); diff --git a/src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.h b/src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.h index 924936c..c5230f3 100644 --- a/src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.h +++ b/src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.h @@ -13,21 +13,21 @@ class CUserSettingVector3 : public CUserSettingValue { public: typedef glm::vec3 data_type; - static CUserSettingVector3* fromJSON (nlohmann::json& data); - static CUserSettingVector3* fromScalar (glm::vec3 value); + static const CUserSettingVector3* fromJSON (const nlohmann::json& data); + static const CUserSettingVector3* fromScalar (const glm::vec3 value); static std::string Type; - glm::vec3 processValue (const std::vector& properties); - glm::vec3 getDefaultValue () const; + [[nodiscard]] const glm::vec3& processValue (const std::vector& properties) const; + [[nodiscard]] const glm::vec3& getDefaultValue () const; private: - CUserSettingVector3 (bool hasCondition, bool hasSource, glm::vec3 defaultValue, std::string source, - std::string expectedValue); + CUserSettingVector3 ( + bool hasCondition, bool hasSource, glm::vec3 defaultValue, std::string source, std::string expectedValue); - glm::vec3 m_default; - bool m_hasCondition; - bool m_hasSource; - std::string m_source; - std::string m_expectedValue; + const glm::vec3 m_default; + const bool m_hasCondition; + const bool m_hasSource; + const std::string m_source; + const std::string m_expectedValue; }; } // namespace WallpaperEngine::Core::UserSettings \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Wallpapers/CScene.cpp b/src/WallpaperEngine/Core/Wallpapers/CScene.cpp index 4ab6259..771aaaf 100644 --- a/src/WallpaperEngine/Core/Wallpapers/CScene.cpp +++ b/src/WallpaperEngine/Core/Wallpapers/CScene.cpp @@ -8,12 +8,14 @@ using namespace WallpaperEngine::Core; using namespace WallpaperEngine::Core::Wallpapers; -CScene::CScene (CProject& project, CContainer* container, Scenes::CCamera* camera, glm::vec3 ambientColor, - CUserSettingBoolean* bloom, CUserSettingFloat* bloomStrength, CUserSettingFloat* bloomThreshold, - bool cameraFade, bool cameraParallax, double cameraParallaxAmount, double cameraParallaxDelay, - double cameraParallaxMouseInfluence, bool cameraPreview, bool cameraShake, double cameraShakeAmplitude, - double cameraShakeRoughness, double cameraShakeSpeed, CUserSettingVector3* clearColor, - Scenes::CProjection* orthogonalProjection, glm::vec3 skylightColor) : +CScene::CScene ( + const CProject& project, const CContainer* container, const Scenes::CCamera* camera, glm::vec3 ambientColor, + const CUserSettingBoolean* bloom, const CUserSettingFloat* bloomStrength, const CUserSettingFloat* bloomThreshold, + bool cameraFade, bool cameraParallax, double cameraParallaxAmount, double cameraParallaxDelay, + double cameraParallaxMouseInfluence, bool cameraPreview, bool cameraShake, double cameraShakeAmplitude, + double cameraShakeRoughness, double cameraShakeSpeed, const CUserSettingVector3* clearColor, + const Scenes::CProjection* orthogonalProjection, glm::vec3 skylightColor +) : CWallpaper (Type, project), m_container (container), m_camera (camera), @@ -35,41 +37,36 @@ CScene::CScene (CProject& project, CContainer* container, Scenes::CCamera* camer m_orthogonalProjection (orthogonalProjection), m_skylightColor (skylightColor) {} -CScene* CScene::fromFile (const std::string& filename, CProject& project, CContainer* container) { +const CScene* CScene::fromFile (std::string filename, const CProject& project, const CContainer* container) { json content = json::parse (container->readFileAsString (filename)); - const auto camera_it = jsonFindRequired (content, "camera", "Scenes must have a defined camera"); const auto general_it = jsonFindRequired (content, "general", "Scenes must have a general section"); const auto objects_it = jsonFindRequired (content, "objects", "Scenes must have a list of objects to display"); // TODO: FIND IF THESE DEFAULTS ARE SENSIBLE OR NOT AND PERFORM PROPER VALIDATION WHEN CAMERA PREVIEW AND CAMERA // PARALLAX ARE PRESENT - const auto ambientcolor = jsonFindDefault (*general_it, "ambientcolor", "0 0 0"); - const auto bloom = jsonFindUserConfig (*general_it, "bloom", false); - const auto bloomstrength = jsonFindUserConfig (*general_it, "bloomstrength", 0.0); - const auto bloomthreshold = jsonFindUserConfig (*general_it, "bloomthreshold", 0.0); - const auto camerafade = jsonFindDefault (*general_it, "camerafade", false); - const auto cameraparallax = jsonFindDefault (*general_it, "cameraparallax", true); - const auto cameraparallaxamount = jsonFindDefault (*general_it, "cameraparallaxamount", 1.0f); - const auto cameraparallaxdelay = jsonFindDefault (*general_it, "cameraparallaxdelay", 0.0f); - const auto cameraparallaxmouseinfluence = - jsonFindDefault (*general_it, "cameraparallaxmouseinfluence", 1.0f); - const auto camerapreview = jsonFindDefault (*general_it, "camerapreview", false); - const auto camerashake = jsonFindDefault (*general_it, "camerashake", false); - const auto camerashakeamplitude = jsonFindDefault (*general_it, "camerashakeamplitude", 0.0f); - const auto camerashakeroughness = jsonFindDefault (*general_it, "camerashakeroughness", 0.0f); - const auto camerashakespeed = jsonFindDefault (*general_it, "camerashakespeed", 0.0f); - const auto clearcolor = jsonFindUserConfig (*general_it, "clearcolor", {1, 1, 1}); - const auto orthogonalprojection_it = - jsonFindRequired (*general_it, "orthogonalprojection", "General section must have orthogonal projection info"); - const auto skylightcolor = jsonFindDefault (*general_it, "skylightcolor", "0 0 0"); auto* scene = new CScene ( - project, container, Scenes::CCamera::fromJSON (*camera_it), WallpaperEngine::Core::aToColorf (ambientcolor), - bloom, bloomstrength, bloomthreshold, camerafade, cameraparallax, cameraparallaxamount, cameraparallaxdelay, - cameraparallaxmouseinfluence, camerapreview, camerashake, camerashakeamplitude, camerashakeroughness, - camerashakespeed, clearcolor, Scenes::CProjection::fromJSON (*orthogonalprojection_it), - WallpaperEngine::Core::aToColorf (skylightcolor)); + project, container, + Scenes::CCamera::fromJSON (jsonFindRequired (content, "camera", "Scenes must have a defined camera")), + jsonFindDefault (*general_it, "ambientcolor", glm::vec3 (0, 0, 0)), + jsonFindUserConfig (*general_it, "bloom", false), + jsonFindUserConfig (*general_it, "bloomstrength", 0.0), + jsonFindUserConfig (*general_it, "bloomthreshold", 0.0), + jsonFindDefault (*general_it, "camerafade", false), + jsonFindDefault (*general_it, "cameraparallax", true), + jsonFindDefault (*general_it, "cameraparallaxamount", 1.0f), + jsonFindDefault (*general_it, "cameraparallaxdelay", 0.0f), + jsonFindDefault (*general_it, "cameraparallaxmouseinfluence", 1.0f), + jsonFindDefault (*general_it, "camerapreview", false), + jsonFindDefault (*general_it, "camerashake", false), + jsonFindDefault (*general_it, "camerashakeamplitude", 0.0f), + jsonFindDefault (*general_it, "camerashakeroughness", 0.0f), + jsonFindDefault (*general_it, "camerashakespeed", 0.0f), + jsonFindUserConfig (*general_it, "clearcolor", {1, 1, 1}), + Scenes::CProjection::fromJSON (jsonFindRequired (*general_it, "orthogonalprojection", "General section must have orthogonal projection info")), + jsonFindDefault (*general_it, "skylightcolor", glm::vec3 (0, 0, 0)) + ); for (const auto& cur : *objects_it) scene->insertObject (CObject::fromJSON (cur, scene, container)); @@ -77,23 +74,23 @@ CScene* CScene::fromFile (const std::string& filename, CProject& project, CConta return scene; } -const std::map& CScene::getObjects () const { +const std::map& CScene::getObjects () const { return this->m_objects; } -const std::vector& CScene::getObjectsByRenderOrder () const { +const std::vector& CScene::getObjectsByRenderOrder () const { return this->m_objectsByRenderOrder; } -void CScene::insertObject (CObject* object) { +void CScene::insertObject (const CObject* object) { /// TODO: XXXHACK -- TO REMOVE WHEN PARTICLE SUPPORT IS PROPERLY IMPLEMENTED if (object != nullptr) { - this->m_objects.insert (std::make_pair (object->getId (), object)); + this->m_objects.insert (std::pair (object->getId (), object)); this->m_objectsByRenderOrder.emplace_back (object); } } -CContainer* CScene::getContainer () { +const CContainer* CScene::getContainer () const { return this->m_container; } @@ -105,7 +102,7 @@ const glm::vec3& CScene::getAmbientColor () const { return this->m_ambientColor; } -const bool CScene::isBloom () const { +bool CScene::isBloom () const { return this->m_bloom->processValue (this->getProject ().getProperties ()); } @@ -117,51 +114,51 @@ double CScene::getBloomThreshold () const { return this->m_bloomThreshold->processValue (this->getProject ().getProperties ()); } -const bool CScene::isCameraFade () const { +bool CScene::isCameraFade () const { return this->m_cameraFade; } -const bool CScene::isCameraParallax () const { +bool CScene::isCameraParallax () const { return this->m_cameraParallax; } -const double CScene::getCameraParallaxAmount () const { +double CScene::getCameraParallaxAmount () const { return this->m_cameraParallaxAmount; } -const double CScene::getCameraParallaxDelay () const { +double CScene::getCameraParallaxDelay () const { return this->m_cameraParallaxDelay; } -const double CScene::getCameraParallaxMouseInfluence () const { +double CScene::getCameraParallaxMouseInfluence () const { return this->m_cameraParallaxMouseInfluence; } -const bool CScene::isCameraPreview () const { +bool CScene::isCameraPreview () const { return this->m_cameraPreview; } -const bool CScene::isCameraShake () const { +bool CScene::isCameraShake () const { return this->m_cameraShake; } -const double CScene::getCameraShakeAmplitude () const { +double CScene::getCameraShakeAmplitude () const { return this->m_cameraShakeAmplitude; } -const double CScene::getCameraShakeRoughness () const { +double CScene::getCameraShakeRoughness () const { return this->m_cameraShakeRoughness; } -const double CScene::getCameraShakeSpeed () const { +double CScene::getCameraShakeSpeed () const { return this->m_cameraShakeSpeed; } -glm::vec3 CScene::getClearColor () const { +const glm::vec3& CScene::getClearColor () const { return this->m_clearColor->processValue (this->getProject ().getProperties ()); } -Scenes::CProjection* CScene::getOrthogonalProjection () const { +const Scenes::CProjection* CScene::getOrthogonalProjection () const { return this->m_orthogonalProjection; } diff --git a/src/WallpaperEngine/Core/Wallpapers/CScene.h b/src/WallpaperEngine/Core/Wallpapers/CScene.h index 86ffbef..23d1d61 100644 --- a/src/WallpaperEngine/Core/Wallpapers/CScene.h +++ b/src/WallpaperEngine/Core/Wallpapers/CScene.h @@ -17,70 +17,71 @@ using json = nlohmann::json; class CScene : public CWallpaper { public: - static CScene* fromFile (const std::string& filename, CProject& project, CContainer* container); + static const CScene* fromFile (std::string filename, const CProject& project, const CContainer* container); - const std::map& getObjects () const; - const std::vector& getObjectsByRenderOrder () const; + [[nodiscard]] const std::map& getObjects () const; + [[nodiscard]] const std::vector& getObjectsByRenderOrder () const; - const glm::vec3& getAmbientColor () const; - const bool isBloom () const; - double getBloomStrength () const; - double getBloomThreshold () const; - const bool isCameraFade () const; - const bool isCameraParallax () const; - const double getCameraParallaxAmount () const; - const double getCameraParallaxDelay () const; - const double getCameraParallaxMouseInfluence () const; - const bool isCameraPreview () const; - const bool isCameraShake () const; - const double getCameraShakeAmplitude () const; - const double getCameraShakeRoughness () const; - const double getCameraShakeSpeed () const; - glm::vec3 getClearColor () const; - Scenes::CProjection* getOrthogonalProjection () const; - const glm::vec3& getSkylightColor () const; - const Scenes::CCamera* getCamera () const; + [[nodiscard]] const glm::vec3& getAmbientColor () const; + [[nodiscard]] bool isBloom () const; + [[nodiscard]] double getBloomStrength () const; + [[nodiscard]] double getBloomThreshold () const; + [[nodiscard]] bool isCameraFade () const; + [[nodiscard]] bool isCameraParallax () const; + [[nodiscard]] double getCameraParallaxAmount () const; + [[nodiscard]] double getCameraParallaxDelay () const; + [[nodiscard]] double getCameraParallaxMouseInfluence () const; + [[nodiscard]] bool isCameraPreview () const; + [[nodiscard]] bool isCameraShake () const; + [[nodiscard]] double getCameraShakeAmplitude () const; + [[nodiscard]] double getCameraShakeRoughness () const; + [[nodiscard]] double getCameraShakeSpeed () const; + [[nodiscard]] const glm::vec3& getClearColor () const; + [[nodiscard]] const Scenes::CProjection* getOrthogonalProjection () const; + [[nodiscard]] const glm::vec3& getSkylightColor () const; + [[nodiscard]] const Scenes::CCamera* getCamera () const; protected: friend class CWallpaper; - CScene (CProject& project, CContainer* container, Scenes::CCamera* camera, glm::vec3 ambientColor, - CUserSettingBoolean* bloom, CUserSettingFloat* bloomStrength, CUserSettingFloat* bloomThreshold, - bool cameraFade, bool cameraParallax, double cameraParallaxAmount, double cameraParallaxDelay, - double cameraParallaxMouseInfluence, bool cameraPreview, bool cameraShake, double cameraShakeAmplitude, - double cameraShakeRoughness, double cameraShakeSpeed, CUserSettingVector3* clearColor, - Scenes::CProjection* orthogonalProjection, glm::vec3 skylightColor); + CScene ( + const CProject& project, const CContainer* container, const Scenes::CCamera* camera, glm::vec3 ambientColor, + const CUserSettingBoolean* bloom, const CUserSettingFloat* bloomStrength, const CUserSettingFloat* bloomThreshold, + bool cameraFade, bool cameraParallax, double cameraParallaxAmount, double cameraParallaxDelay, + double cameraParallaxMouseInfluence, bool cameraPreview, bool cameraShake, double cameraShakeAmplitude, + double cameraShakeRoughness, double cameraShakeSpeed, const CUserSettingVector3* clearColor, + const Scenes::CProjection* orthogonalProjection, glm::vec3 skylightColor); static const std::string Type; - void insertObject (CObject* object); + void insertObject (const CObject* object); - CContainer* getContainer (); + const CContainer* getContainer () const; private: - CContainer* m_container; - Scenes::CCamera* m_camera; + const CContainer* m_container; + const Scenes::CCamera* m_camera; // data from general section on the json - glm::vec3 m_ambientColor; - CUserSettingBoolean* m_bloom; - CUserSettingFloat* m_bloomStrength; - CUserSettingFloat* m_bloomThreshold; - bool m_cameraFade; - bool m_cameraParallax; - double m_cameraParallaxAmount; - double m_cameraParallaxDelay; - double m_cameraParallaxMouseInfluence; - bool m_cameraPreview; - bool m_cameraShake; - double m_cameraShakeAmplitude; - double m_cameraShakeRoughness; - double m_cameraShakeSpeed; - CUserSettingVector3* m_clearColor; - Scenes::CProjection* m_orthogonalProjection; - glm::vec3 m_skylightColor; + const glm::vec3 m_ambientColor; + const CUserSettingBoolean* m_bloom; + const CUserSettingFloat* m_bloomStrength; + const CUserSettingFloat* m_bloomThreshold; + const bool m_cameraFade; + const bool m_cameraParallax; + const double m_cameraParallaxAmount; + const double m_cameraParallaxDelay; + const double m_cameraParallaxMouseInfluence; + const bool m_cameraPreview; + const bool m_cameraShake; + const double m_cameraShakeAmplitude; + const double m_cameraShakeRoughness; + const double m_cameraShakeSpeed; + const CUserSettingVector3* m_clearColor; + const Scenes::CProjection* m_orthogonalProjection; + const glm::vec3 m_skylightColor; - std::map m_objects; - std::vector m_objectsByRenderOrder; + std::map m_objects; + std::vector m_objectsByRenderOrder; }; } // namespace WallpaperEngine::Core diff --git a/src/WallpaperEngine/Core/Wallpapers/CVideo.cpp b/src/WallpaperEngine/Core/Wallpapers/CVideo.cpp index 81df2a9..dfb1424 100644 --- a/src/WallpaperEngine/Core/Wallpapers/CVideo.cpp +++ b/src/WallpaperEngine/Core/Wallpapers/CVideo.cpp @@ -5,11 +5,11 @@ using namespace WallpaperEngine::Core; using namespace WallpaperEngine::Core::Wallpapers; -CVideo::CVideo (std::string filename, CProject& project) : +CVideo::CVideo (std::string filename, const CProject& project) : CWallpaper (Type, project), - m_filename (std::move (filename)) {} + m_filename (filename) {} -const std::string& CVideo::getFilename () { +const std::string& CVideo::getFilename () const { return this->m_filename; } diff --git a/src/WallpaperEngine/Core/Wallpapers/CVideo.h b/src/WallpaperEngine/Core/Wallpapers/CVideo.h index c8d4711..a37362a 100644 --- a/src/WallpaperEngine/Core/Wallpapers/CVideo.h +++ b/src/WallpaperEngine/Core/Wallpapers/CVideo.h @@ -13,9 +13,9 @@ extern "C" { namespace WallpaperEngine::Core::Wallpapers { class CVideo : public CWallpaper { public: - explicit CVideo (std::string filename, CProject& project); + CVideo (std::string filename, const CProject& project); - const std::string& getFilename (); + const std::string& getFilename () const; protected: friend class CWallpaper; diff --git a/src/WallpaperEngine/Core/Wallpapers/CWeb.cpp b/src/WallpaperEngine/Core/Wallpapers/CWeb.cpp index 1fdfc18..0f142bb 100644 --- a/src/WallpaperEngine/Core/Wallpapers/CWeb.cpp +++ b/src/WallpaperEngine/Core/Wallpapers/CWeb.cpp @@ -5,10 +5,12 @@ using namespace WallpaperEngine::Core; using namespace WallpaperEngine::Core::Wallpapers; -const std::string& CWeb::getFilename () { +const std::string& CWeb::getFilename () const { return this->m_filename; } -CWeb::CWeb (std::string filename, CProject& project) : CWallpaper (Type, project), m_filename (std::move (filename)) {} +CWeb::CWeb (std::string filename, const CProject& project) : + CWallpaper (Type, project), + m_filename (filename) {} const std::string CWeb::Type = "web"; diff --git a/src/WallpaperEngine/Core/Wallpapers/CWeb.h b/src/WallpaperEngine/Core/Wallpapers/CWeb.h index ded9dd3..e4c670b 100644 --- a/src/WallpaperEngine/Core/Wallpapers/CWeb.h +++ b/src/WallpaperEngine/Core/Wallpapers/CWeb.h @@ -18,12 +18,11 @@ extern "C" namespace WallpaperEngine::Core::Wallpapers { - class CWeb : public CWallpaper - { + class CWeb : public CWallpaper { public: - explicit CWeb (std::string filename, CProject& project); + CWeb (std::string filename, const CProject& project); - const std::string& getFilename (); + const std::string& getFilename () const; protected: friend class CWallpaper; diff --git a/src/WallpaperEngine/Render/CObject.cpp b/src/WallpaperEngine/Render/CObject.cpp index c58f9b2..8fb4cd2 100644 --- a/src/WallpaperEngine/Render/CObject.cpp +++ b/src/WallpaperEngine/Render/CObject.cpp @@ -6,7 +6,7 @@ using namespace WallpaperEngine; using namespace WallpaperEngine::Render; using namespace WallpaperEngine::Render::Wallpapers; -CObject::CObject (Wallpapers::CScene* scene, std::string type, Core::CObject* object) : +CObject::CObject (Wallpapers::CScene* scene, std::string type, const Core::CObject* object) : Helpers::CContextAware (scene), m_type (std::move (type)), m_scene (scene), @@ -16,7 +16,7 @@ Wallpapers::CScene* CObject::getScene () const { return this->m_scene; } -CContainer* CObject::getContainer () const { +const CContainer* CObject::getContainer () const { return this->getScene ()->getContainer (); } diff --git a/src/WallpaperEngine/Render/CObject.h b/src/WallpaperEngine/Render/CObject.h index 03f448e..008f24f 100644 --- a/src/WallpaperEngine/Render/CObject.h +++ b/src/WallpaperEngine/Render/CObject.h @@ -31,17 +31,17 @@ class CObject : public Helpers::CContextAware { virtual void render () = 0; [[nodiscard]] Wallpapers::CScene* getScene () const; - [[nodiscard]] CContainer* getContainer () const; + [[nodiscard]] const CContainer* getContainer () const; [[nodiscard]] int getId () const; protected: - CObject (Wallpapers::CScene* scene, std::string type, Core::CObject* object); + CObject (Wallpapers::CScene* scene, std::string type, const Core::CObject* object); ~CObject () override = default; private: std::string m_type; Wallpapers::CScene* m_scene; - Core::CObject* m_object; + const Core::CObject* m_object; }; } // namespace WallpaperEngine::Render \ No newline at end of file diff --git a/src/WallpaperEngine/Render/CWallpaper.cpp b/src/WallpaperEngine/Render/CWallpaper.cpp index abdfcb7..172a574 100644 --- a/src/WallpaperEngine/Render/CWallpaper.cpp +++ b/src/WallpaperEngine/Render/CWallpaper.cpp @@ -10,7 +10,7 @@ using namespace WallpaperEngine::Render; -CWallpaper::CWallpaper (Core::CWallpaper* wallpaperData, std::string type, CRenderContext& context, +CWallpaper::CWallpaper (const Core::CWallpaper* wallpaperData, std::string type, CRenderContext& context, CAudioContext& audioContext, const CWallpaperState::TextureUVsScaling& scalingMode) : CContextAware (context), m_wallpaperData (wallpaperData), @@ -49,11 +49,11 @@ CWallpaper::CWallpaper (Core::CWallpaper* wallpaperData, std::string type, CRend CWallpaper::~CWallpaper () = default; -CContainer* CWallpaper::getContainer () const { +const CContainer* CWallpaper::getContainer () const { return this->m_wallpaperData->getProject ().getContainer (); } -WallpaperEngine::Core::CWallpaper* CWallpaper::getWallpaperData () const { +const WallpaperEngine::Core::CWallpaper* CWallpaper::getWallpaperData () const { return this->m_wallpaperData; } @@ -281,7 +281,7 @@ CFBO* CWallpaper::getFBO () const { return this->m_sceneFBO; } -CWallpaper* CWallpaper::fromWallpaper (Core::CWallpaper* wallpaper, CRenderContext& context, +CWallpaper* CWallpaper::fromWallpaper (const Core::CWallpaper* wallpaper, CRenderContext& context, CAudioContext& audioContext, WebBrowser::CWebBrowserContext& browserContext, const CWallpaperState::TextureUVsScaling& scalingMode) { if (wallpaper->is ()) diff --git a/src/WallpaperEngine/Render/CWallpaper.h b/src/WallpaperEngine/Render/CWallpaper.h index ef588ab..15f912b 100644 --- a/src/WallpaperEngine/Render/CWallpaper.h +++ b/src/WallpaperEngine/Render/CWallpaper.h @@ -59,7 +59,7 @@ class CWallpaper : public Helpers::CContextAware { /** * @return The container to resolve files for this wallpaper */ - [[nodiscard]] CContainer* getContainer () const; + [[nodiscard]] const CContainer* getContainer () const; /** * @return The current audio context for this wallpaper @@ -146,12 +146,12 @@ class CWallpaper : public Helpers::CContextAware { * * @return */ - static CWallpaper* fromWallpaper (Core::CWallpaper* wallpaper, CRenderContext& context, CAudioContext& audioContext, + static CWallpaper* fromWallpaper (const Core::CWallpaper* wallpaper, CRenderContext& context, CAudioContext& audioContext, WebBrowser::CWebBrowserContext& browserContext, const CWallpaperState::TextureUVsScaling& scalingMode); protected: - CWallpaper (Core::CWallpaper* wallpaperData, std::string type, CRenderContext& context, CAudioContext& audioContext, + CWallpaper (const Core::CWallpaper* wallpaperData, std::string type, CRenderContext& context, CAudioContext& audioContext, const CWallpaperState::TextureUVsScaling& scalingMode); /** @@ -164,9 +164,9 @@ class CWallpaper : public Helpers::CContextAware { */ void setupFramebuffers (); - Core::CWallpaper* m_wallpaperData; + const Core::CWallpaper* m_wallpaperData; - [[nodiscard]] Core::CWallpaper* getWallpaperData () const; + [[nodiscard]] const Core::CWallpaper* getWallpaperData () const; /** The FBO used for scene output */ CFBO* m_sceneFBO; diff --git a/src/WallpaperEngine/Render/Objects/CEffect.cpp b/src/WallpaperEngine/Render/Objects/CEffect.cpp index 1f3dc7a..fc728bc 100644 --- a/src/WallpaperEngine/Render/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Render/Objects/CEffect.cpp @@ -3,7 +3,9 @@ using namespace WallpaperEngine::Render; using namespace WallpaperEngine::Render::Objects; -CEffect::CEffect (CImage* image, Core::Objects::CEffect* effect) : m_image (image), m_effect (effect) { +CEffect::CEffect (CImage* image, const Core::Objects::CEffect* effect) : + m_image (image), + m_effect (effect) { this->generateFBOs (); this->generatePasses (); } diff --git a/src/WallpaperEngine/Render/Objects/CEffect.h b/src/WallpaperEngine/Render/Objects/CEffect.h index 06748cb..291283a 100644 --- a/src/WallpaperEngine/Render/Objects/CEffect.h +++ b/src/WallpaperEngine/Render/Objects/CEffect.h @@ -14,7 +14,7 @@ class CImage; class CEffect { public: - CEffect (CImage* image, Core::Objects::CEffect* effect); + CEffect (CImage* image, const Core::Objects::CEffect* effect); CImage* getImage () const; @@ -28,7 +28,7 @@ class CEffect { void generateFBOs (); CImage* m_image; - Core::Objects::CEffect* m_effect; + const Core::Objects::CEffect* m_effect; std::vector m_fbos; std::vector m_materials; diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index e711f43..e41fde4 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -4,7 +4,7 @@ using namespace WallpaperEngine; using namespace WallpaperEngine::Render::Objects; -CImage::CImage (Wallpapers::CScene* scene, Core::Objects::CImage* image) : +CImage::CImage (Wallpapers::CScene* scene, const Core::Objects::CImage* image) : Render::CObject (scene, Type, image), m_texture (nullptr), m_sceneSpacePosition (GL_NONE), @@ -79,7 +79,7 @@ CImage::CImage (Wallpapers::CScene* scene, Core::Objects::CImage* image) : auto textures = (*this->m_image->getMaterial ()->getPasses ().begin ())->getTextures (); if (!textures.empty ()) { - std::string textureName = *textures.begin (); + std::string textureName = textures.begin ()->second; if (textureName.find ("_rt_") == 0) { this->m_texture = this->getScene ()->findFBO (textureName); @@ -226,17 +226,20 @@ void CImage::setup () { if (this->getImage ()->isPassthrough () && this->getImage ()->getEffects ().empty ()) return; - { - // generate the main material used to render the image - this->m_material = new Effects::CMaterial ( - new CEffect (this, new Core::Objects::CEffect ("", "", "", "", this->m_image, - Core::UserSettings::CUserSettingBoolean::fromScalar (true))), - this->m_image->getMaterial ()); + // generate the main material used to render the image + this->m_material = new Effects::CMaterial ( + new CEffect ( + this, + new Core::Objects::CEffect ( + "", "", "", "", this->m_image->getScene ()->getProject (), + Core::UserSettings::CUserSettingBoolean::fromScalar (true), + {}, {}, {})), + this->m_image->getMaterial () + ); - // add blendmode to the combos - for (const auto& cur : this->m_material->getPasses ()) - this->m_passes.push_back (cur); - } + // add blendmode to the combos + for (const auto& cur : this->m_material->getPasses ()) + this->m_passes.push_back (cur); // prepare the passes list if (!this->getImage ()->getEffects ().empty ()) { @@ -253,17 +256,23 @@ void CImage::setup () { } if (this->m_image->getColorBlendMode () > 0) { - const auto material = - Core::Objects::Images::CMaterial::fromFile ("materials/util/effectpassthrough.json", this->getContainer ()); + Core::Objects::Images::CMaterial::OverrideInfo overrides; - // effectpasshthrough only has one pass - (*material->getPasses ().begin ())->insertCombo ("BLENDMODE", this->m_image->getColorBlendMode ()); + overrides.combos.insert (std::pair ("BLENDMODE", this->m_image->getColorBlendMode ())); + const auto material = + Core::Objects::Images::CMaterial::fromFile ("materials/util/effectpassthrough.json", this->getContainer (), {}, &overrides); // generate the main material used to render the image this->m_colorBlendMaterial = new Effects::CMaterial ( - new CEffect (this, new Core::Objects::CEffect ("", "", "", "", this->m_image, - Core::UserSettings::CUserSettingBoolean::fromScalar (true))), - material); + new CEffect ( + this, + new Core::Objects::CEffect ( + "", "", "", "", this->m_image->getScene ()->getProject (), + Core::UserSettings::CUserSettingBoolean::fromScalar (true), {}, {}, {} + ) + ), + material + ); // add blendmode to the combos for (const auto& cur : this->m_colorBlendMaterial->getPasses ()) @@ -275,8 +284,8 @@ void CImage::setup () { const auto first = this->m_passes.begin (); const auto last = this->m_passes.rbegin (); - (*last)->getPass ()->setBlendingMode ((*first)->getPass ()->getBlendingMode ()); - (*first)->getPass ()->setBlendingMode ("normal"); + (*last)->setBlendingMode ((*first)->getBlendingMode ()); + (*first)->setBlendingMode ("normal"); } // calculate full animation time (if any) diff --git a/src/WallpaperEngine/Render/Objects/CImage.h b/src/WallpaperEngine/Render/Objects/CImage.h index f412448..86c2259 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.h +++ b/src/WallpaperEngine/Render/Objects/CImage.h @@ -29,7 +29,7 @@ class CImage final : public CObject { friend CObject; public: - CImage (Wallpapers::CScene* scene, Core::Objects::CImage* image); + CImage (Wallpapers::CScene* scene, const Core::Objects::CImage* image); void setup (); void render () override; @@ -84,7 +84,7 @@ class CImage final : public CObject { CFBO* m_currentMainFBO; CFBO* m_currentSubFBO; - Core::Objects::CImage* m_image; + const Core::Objects::CImage* m_image; std::vector m_effects; Effects::CMaterial* m_material; diff --git a/src/WallpaperEngine/Render/Objects/CSound.cpp b/src/WallpaperEngine/Render/Objects/CSound.cpp index 1fe662e..588e629 100644 --- a/src/WallpaperEngine/Render/Objects/CSound.cpp +++ b/src/WallpaperEngine/Render/Objects/CSound.cpp @@ -4,7 +4,9 @@ using namespace WallpaperEngine::Render::Objects; -CSound::CSound (Wallpapers::CScene* scene, Core::Objects::CSound* sound) : CObject (scene, Type, sound), m_sound (sound) { +CSound::CSound (Wallpapers::CScene* scene, const Core::Objects::CSound* sound) : + CObject (scene, Type, sound), + m_sound (sound) { if (this->getContext ().getApp ().getContext ().settings.audio.enabled) this->load (); } diff --git a/src/WallpaperEngine/Render/Objects/CSound.h b/src/WallpaperEngine/Render/Objects/CSound.h index 53770fc..ad49b1f 100644 --- a/src/WallpaperEngine/Render/Objects/CSound.h +++ b/src/WallpaperEngine/Render/Objects/CSound.h @@ -14,7 +14,7 @@ class CScene; namespace WallpaperEngine::Render::Objects { class CSound final : public CObject { public: - CSound (Wallpapers::CScene* scene, Core::Objects::CSound* sound); + CSound (Wallpapers::CScene* scene, const Core::Objects::CSound* sound); ~CSound () override; void render () override; @@ -28,6 +28,6 @@ class CSound final : public CObject { std::vector m_soundBuffer; std::vector m_audioStreams; - Core::Objects::CSound* m_sound; + const Core::Objects::CSound* m_sound; }; } // namespace WallpaperEngine::Render::Objects diff --git a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp index effc3b9..3bdd304 100644 --- a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp +++ b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp @@ -23,10 +23,11 @@ using namespace WallpaperEngine::Render::Objects::Effects; extern float g_Time; extern float g_Daytime; -CPass::CPass (CMaterial* material, Core::Objects::Images::Materials::CPass* pass) : +CPass::CPass (CMaterial* material, const Core::Objects::Images::Materials::CPass* pass) : Helpers::CContextAware (material), m_material (material), - m_pass (pass) { + m_pass (pass), + m_blendingmode (pass->getBlendingMode ()) { this->setupTextures (); this->setupShaders (); this->setupShaderVariables (); @@ -293,6 +294,14 @@ void CPass::setViewProjectionMatrix (const glm::mat4* viewProjection) { this->m_viewProjectionMatrix = viewProjection; } +void CPass::setBlendingMode (std::string blendingmode) { + this->m_blendingmode = blendingmode; +} + +const std::string& CPass::getBlendingMode () const { + return this->m_blendingmode; +} + void CPass::setTexCoord (GLuint texcoord) { this->a_TexCoord = texcoord; } @@ -301,7 +310,7 @@ void CPass::setPosition (GLuint position) { this->a_Position = position; } -Core::Objects::Images::Materials::CPass* CPass::getPass () { +const Core::Objects::Images::Materials::CPass* CPass::getPass () { return this->m_pass; } @@ -345,9 +354,9 @@ void CPass::setupShaders () { // ELEMENTS? if (texture0 != nullptr) { if (texture0->getFormat () == ITexture::TextureFormat::RG88) { - this->m_pass->insertCombo ("TEX0FORMAT", 8); + this->m_foundCombos.insert(std::pair("TEX0FORMAT", 8)); } else if (texture0->getFormat () == ITexture::TextureFormat::R8) { - this->m_pass->insertCombo ("TEX0FORMAT", 9); + this->m_foundCombos.insert (std::pair("TEX0FORMAT", 9)); } } @@ -637,11 +646,11 @@ void CPass::setupTextures () { if (index == 0) continue; - if (cur->find ("_rt_") == 0) { - const CFBO* fbo = this->m_material->m_effect->findFBO ((*cur)); + if (cur->second.find ("_rt_") == 0) { + const CFBO* fbo = this->m_material->m_effect->findFBO (cur->second); if (fbo == nullptr) - fbo = this->m_material->getImage ()->getScene ()->findFBO ((*cur)); + fbo = this->m_material->getImage ()->getScene ()->findFBO (cur->second); if (fbo != nullptr) { this->m_fbos.insert (std::make_pair (index, fbo)); @@ -649,10 +658,10 @@ void CPass::setupTextures () { } // _rt_texture } else { - if (cur->empty ()) { + if (cur->second.empty ()) { this->m_textures.emplace_back (nullptr); } else { - this->m_textures.emplace_back (this->m_material->getImage ()->getContext ().resolveTexture ((*cur))); + this->m_textures.emplace_back (this->m_material->getImage ()->getContext ().resolveTexture (cur->second)); } } } @@ -741,6 +750,15 @@ void CPass::addUniform (const std::string& name, CShaderConstant* value) { this->addUniform (name, value->as ()->getValue ()); } +void CPass::addUniform (const std::string& name, const CShaderConstant* value) { + // now determine the constant's type and register the correct uniform for it + if (value->is ()) + this->addUniform (name, value->as ()->getValue ()); + else if (value->is ()) + this->addUniform (name, value->as ()->getValue ()); + else if (value->is ()) + this->addUniform (name, value->as ()->getValue ()); +} void CPass::addUniform (const std::string& name, int value) { this->addUniform (name, UniformType::Integer, value); } diff --git a/src/WallpaperEngine/Render/Objects/Effects/CPass.h b/src/WallpaperEngine/Render/Objects/Effects/CPass.h index a2c6008..d211253 100644 --- a/src/WallpaperEngine/Render/Objects/Effects/CPass.h +++ b/src/WallpaperEngine/Render/Objects/Effects/CPass.h @@ -5,6 +5,7 @@ #include "WallpaperEngine/Assets/ITexture.h" #include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h" +#include "WallpaperEngine/Core/Objects/Images/Materials/CPass.h" #include "WallpaperEngine/Render/CFBO.h" #include "WallpaperEngine/Render/Objects/Effects/CMaterial.h" #include "WallpaperEngine/Render/Shaders/CCompiler.h" @@ -21,7 +22,7 @@ class CMaterial; class CPass final : public Helpers::CContextAware { public: - CPass (CMaterial* material, Core::Objects::Images::Materials::CPass* pass); + CPass (CMaterial* material, const Core::Objects::Images::Materials::CPass* pass); void render (); @@ -33,9 +34,11 @@ class CPass final : public Helpers::CContextAware { void setModelViewProjectionMatrixInverse (const glm::mat4* projection); void setModelMatrix (const glm::mat4* model); void setViewProjectionMatrix (const glm::mat4* viewProjection); + void setBlendingMode (std::string blendingmode); + const std::string& getBlendingMode () const; [[nodiscard]] const CMaterial* getMaterial () const; - Core::Objects::Images::Materials::CPass* getPass (); + const Core::Objects::Images::Materials::CPass* getPass (); private: enum UniformType { @@ -105,6 +108,7 @@ class CPass final : public Helpers::CContextAware { void addAttribute (const std::string& name, GLint type, GLint elements, const GLuint* value); void addUniform (CShaderVariable* value); void addUniform (const std::string& name, CShaderConstant* value); + void addUniform (const std::string& name, const CShaderConstant* value); void addUniform (const std::string& name, int value); void addUniform (const std::string& name, double value); void addUniform (const std::string& name, float value); @@ -144,13 +148,14 @@ class CPass final : public Helpers::CContextAware { const ITexture* resolveTexture (const ITexture* expected, int index, const ITexture* previous = nullptr); CMaterial* m_material; - Core::Objects::Images::Materials::CPass* m_pass; + const Core::Objects::Images::Materials::CPass* m_pass; std::vector m_textures; std::map m_fbos; std::map m_foundCombos; std::vector m_attribs; std::map m_uniforms; std::map m_referenceUniforms; + std::string m_blendingmode; const glm::mat4* m_modelViewProjectionMatrix; const glm::mat4* m_modelViewProjectionMatrixInverse; const glm::mat4* m_modelMatrix; diff --git a/src/WallpaperEngine/Render/Shaders/CCompiler.cpp b/src/WallpaperEngine/Render/Shaders/CCompiler.cpp index 675e6fb..43b75c0 100644 --- a/src/WallpaperEngine/Render/Shaders/CCompiler.cpp +++ b/src/WallpaperEngine/Render/Shaders/CCompiler.cpp @@ -24,9 +24,11 @@ using namespace WallpaperEngine::Core; using namespace WallpaperEngine::Assets; namespace WallpaperEngine::Render::Shaders { -CCompiler::CCompiler (CContainer* container, std::string filename, CGLSLContext::ShaderType type, std::map* combos, - std::map* foundCombos, const std::vector& textures, - const std::map& constants) : +CCompiler::CCompiler ( + const CContainer* container, std::string filename, CGLSLContext::ShaderType type, + std::map combos, std::map* foundCombos, + const std::map& textures, const std::map& constants +) : m_file (std::move (filename)), m_type (type), m_combos (combos), @@ -42,7 +44,7 @@ CCompiler::CCompiler (CContainer* container, std::string filename, CGLSLContext: sLog.exception ("Include shaders should never be compiled, they're part of a bigger shader: ", this->m_file); // clone the combos into the baseCombos to keep track of values that must be embedded no matter what - for (const auto& [name, value] : *this->m_combos) + for (const auto& [name, value] : this->m_combos) this->m_baseCombos.insert (std::make_pair (name, value)); } @@ -138,9 +140,9 @@ void CCompiler::precompile () { // add all the defines we have for now for (const auto& [name, value] : *this->m_foundCombos) { // find the right value for the combo in the combos map - auto combo = this->m_combos->find (name); + auto combo = this->m_combos.find (name); - if (combo == this->m_combos->end ()) + if (combo == this->m_combos.end ()) continue; precompile += "#define " + name + " " + std::to_string (combo->second) + "\n"; @@ -257,25 +259,25 @@ void CCompiler::parseComboConfiguration (const std::string& content, int default const auto defvalue = data.find ("default"); // check the combos - const auto entry = this->m_combos->find (combo->get ()); + const auto entry = this->m_combos.find (combo->get ()); // add the combo to the found list this->m_foundCombos->insert (std::make_pair (*combo, true)); // if the combo was not found in the predefined values this means that the default value in the JSON data can be // used so only define the ones that are not already defined - if (entry == this->m_combos->end ()) { + if (entry == this->m_combos.end ()) { if (type != data.end ()) sLog.error ("Resorting to default value as type ", *type, " is unknown"); // if no combo is defined just load the default settings if (defvalue == data.end ()) { // TODO: PROPERLY SUPPORT EMPTY COMBOS - this->m_combos->insert (std::make_pair (*combo, (int) defaultValue)); + this->m_combos.insert (std::make_pair (*combo, (int) defaultValue)); } else if (defvalue->is_number_float ()) { sLog.exception ("float combos are not supported in shader ", this->m_file, ". ", *combo); } else if (defvalue->is_number_integer ()) { - this->m_combos->insert (std::make_pair (*combo, defvalue->get ())); + this->m_combos.insert (std::make_pair (*combo, defvalue->get ())); } else if (defvalue->is_string ()) { sLog.exception ("string combos are not supported in shader ", this->m_file, ". ", *combo); } else { @@ -349,10 +351,11 @@ void CCompiler::parseParameterConfiguration (const std::string& type, const std: if (combo != data.end ()) { // if the texture exists (and is not null), add to the combo - if (this->m_passTextures.size () > index && - (!this->m_passTextures.at (index).empty () || textureName != data.end ())) { + auto texture = this->m_textures.find (index); + + if (texture != this->m_textures.end () && (texture->second.empty () || textureName != data.end ())) { // add the new combo to the list - this->m_combos->insert (std::make_pair (*combo, 1)); + this->m_combos.insert (std::make_pair (*combo, 1)); // textures linked to combos need to be tracked too if (this->m_foundCombos->find (*combo) == this->m_foundCombos->end ()) @@ -390,7 +393,7 @@ const std::vector& CCompiler::getParameters () cons return this->m_parameters; } -std::map* CCompiler::getCombos () const { +const std::map& CCompiler::getCombos () const { return this->m_combos; } diff --git a/src/WallpaperEngine/Render/Shaders/CCompiler.h b/src/WallpaperEngine/Render/Shaders/CCompiler.h index 7392264..e30400b 100644 --- a/src/WallpaperEngine/Render/Shaders/CCompiler.h +++ b/src/WallpaperEngine/Render/Shaders/CCompiler.h @@ -36,9 +36,10 @@ class CCompiler { * @param constants Default values for shader variables * @param recursive Whether the compiler should add base definitions or not */ - CCompiler (CContainer* container, std::string filename, CGLSLContext::ShaderType type, std::map* combos, - std::map* foundCombos, const std::vector& textures, - const std::map& constants); + CCompiler ( + const CContainer* container, std::string filename, CGLSLContext::ShaderType type, + std::map combos, std::map* foundCombos, + const std::map& textures, const std::map& constants); /** * Pre-processes the shader to detect variables, process includes and other small things WallpaperEngine * does to shaders before actually using them @@ -62,7 +63,7 @@ class CCompiler { /** * @return The list of combos available for this shader after compilation */ - [[nodiscard]] std::map* getCombos () const; + [[nodiscard]] const std::map& getCombos () const; /** * @return The list of textures inferred from the shader's code */ @@ -120,7 +121,7 @@ class CCompiler { /** * The combos the shader should be generated with */ - std::map* m_combos; + std::map m_combos; /** * Combos that come from the pass' chain that should be added @@ -135,15 +136,15 @@ class CCompiler { /** * The list of textures the pass knows about */ - const std::vector m_passTextures; + const std::map m_passTextures; /** * The shader constants with values for variables inside the shader */ - const std::map& m_constants; + const std::map& m_constants; /** * The container to load files from */ - CContainer* m_container; + const CContainer* m_container; /** * List of textures that the shader expects (inferred from sampler2D and it's JSON data) */ diff --git a/src/WallpaperEngine/Render/Wallpapers/CScene.cpp b/src/WallpaperEngine/Render/Wallpapers/CScene.cpp index ed36805..c95f951 100644 --- a/src/WallpaperEngine/Render/Wallpapers/CScene.cpp +++ b/src/WallpaperEngine/Render/Wallpapers/CScene.cpp @@ -16,7 +16,7 @@ using namespace WallpaperEngine; using namespace WallpaperEngine::Render; using namespace WallpaperEngine::Render::Wallpapers; -CScene::CScene (Core::Wallpapers::CScene* scene, CRenderContext& context, CAudioContext& audioContext, +CScene::CScene (const Core::Wallpapers::CScene* scene, CRenderContext& context, CAudioContext& audioContext, const CWallpaperState::TextureUVsScaling& scalingMode) : CWallpaper (scene, Type, context, audioContext, scalingMode), m_mousePosition (), @@ -154,7 +154,7 @@ CScene::CScene (Core::Wallpapers::CScene* scene, CRenderContext& context, CAudio } } -Render::CObject* CScene::createObject (Core::CObject* object) { +Render::CObject* CScene::createObject (const Core::CObject* object) { Render::CObject* renderObject = nullptr; // ensure the item is not loaded already @@ -241,7 +241,7 @@ void CScene::updateMouse (glm::ivec4 viewport) { // screen-space positions have to be transposed to what the screen will actually show } -Core::Wallpapers::CScene* CScene::getScene () const { +const Core::Wallpapers::CScene* CScene::getScene () const { return this->getWallpaperData ()->as (); } diff --git a/src/WallpaperEngine/Render/Wallpapers/CScene.h b/src/WallpaperEngine/Render/Wallpapers/CScene.h index 9f2562b..cf82af2 100644 --- a/src/WallpaperEngine/Render/Wallpapers/CScene.h +++ b/src/WallpaperEngine/Render/Wallpapers/CScene.h @@ -14,12 +14,12 @@ class CObject; namespace WallpaperEngine::Render::Wallpapers { class CScene final : public CWallpaper { public: - CScene (Core::Wallpapers::CScene* scene, CRenderContext& context, CAudioContext& audioContext, + CScene (const Core::Wallpapers::CScene* scene, CRenderContext& context, CAudioContext& audioContext, const CWallpaperState::TextureUVsScaling& scalingMode); CCamera* getCamera () const; - Core::Wallpapers::CScene* getScene () const; + const Core::Wallpapers::CScene* getScene () const; int getWidth () const override; int getHeight () const override; @@ -37,7 +37,7 @@ class CScene final : public CWallpaper { static const std::string Type; private: - Render::CObject* createObject (Core::CObject* object); + Render::CObject* createObject (const Core::CObject* object); CCamera* m_camera; CObject* m_bloomObject; diff --git a/src/WallpaperEngine/Render/Wallpapers/CVideo.cpp b/src/WallpaperEngine/Render/Wallpapers/CVideo.cpp index d2ed147..a427891 100644 --- a/src/WallpaperEngine/Render/Wallpapers/CVideo.cpp +++ b/src/WallpaperEngine/Render/Wallpapers/CVideo.cpp @@ -11,7 +11,7 @@ void* get_proc_address (void* ctx, const char* name) { return static_cast (ctx)->getContext ().getDriver ().getProcAddress (name); } -CVideo::CVideo (Core::Wallpapers::CVideo* video, CRenderContext& context, CAudioContext& audioContext, +CVideo::CVideo (const Core::Wallpapers::CVideo* video, CRenderContext& context, CAudioContext& audioContext, const CWallpaperState::TextureUVsScaling& scalingMode) : CWallpaper (video, Type, context, audioContext, scalingMode), m_mpvGl (nullptr), @@ -119,7 +119,7 @@ void CVideo::renderFrame (glm::ivec4 viewport) { mpv_render_context_render (this->m_mpvGl, params); } -Core::Wallpapers::CVideo* CVideo::getVideo () { +const Core::Wallpapers::CVideo* CVideo::getVideo () const { return this->getWallpaperData ()->as (); } diff --git a/src/WallpaperEngine/Render/Wallpapers/CVideo.h b/src/WallpaperEngine/Render/Wallpapers/CVideo.h index 71334dc..2dd4442 100644 --- a/src/WallpaperEngine/Render/Wallpapers/CVideo.h +++ b/src/WallpaperEngine/Render/Wallpapers/CVideo.h @@ -10,10 +10,10 @@ namespace WallpaperEngine::Render::Wallpapers { class CVideo final : public CWallpaper { public: - CVideo (Core::Wallpapers::CVideo* video, CRenderContext& context, CAudioContext& audioContext, + CVideo (const Core::Wallpapers::CVideo* video, CRenderContext& context, CAudioContext& audioContext, const CWallpaperState::TextureUVsScaling& scalingMode); - Core::Wallpapers::CVideo* getVideo (); + const Core::Wallpapers::CVideo* getVideo () const; [[nodiscard]] int getWidth () const override; [[nodiscard]] int getHeight () const override; diff --git a/src/WallpaperEngine/Render/Wallpapers/CWeb.cpp b/src/WallpaperEngine/Render/Wallpapers/CWeb.cpp index 9ab64d9..b0c3f94 100644 --- a/src/WallpaperEngine/Render/Wallpapers/CWeb.cpp +++ b/src/WallpaperEngine/Render/Wallpapers/CWeb.cpp @@ -10,7 +10,7 @@ using namespace WallpaperEngine::Render::Wallpapers; using namespace WallpaperEngine::WebBrowser; using namespace WallpaperEngine::WebBrowser::CEF; -CWeb::CWeb (Core::Wallpapers::CWeb* web, CRenderContext& context, CAudioContext& audioContext, CWebBrowserContext& browserContext, +CWeb::CWeb (const Core::Wallpapers::CWeb* web, CRenderContext& context, CAudioContext& audioContext, CWebBrowserContext& browserContext, const CWallpaperState::TextureUVsScaling& scalingMode) : CWallpaper (web, Type, context, audioContext, scalingMode), m_browserContext (browserContext), diff --git a/src/WallpaperEngine/Render/Wallpapers/CWeb.h b/src/WallpaperEngine/Render/Wallpapers/CWeb.h index 78a5d85..4f8b4ff 100644 --- a/src/WallpaperEngine/Render/Wallpapers/CWeb.h +++ b/src/WallpaperEngine/Render/Wallpapers/CWeb.h @@ -24,7 +24,7 @@ namespace WallpaperEngine::Render::Wallpapers { class CWeb : public CWallpaper { public: - CWeb (Core::Wallpapers::CWeb* scene, CRenderContext& context, CAudioContext& audioContext, WallpaperEngine::WebBrowser::CWebBrowserContext& browserContext, const CWallpaperState::TextureUVsScaling& scalingMode); + CWeb (const Core::Wallpapers::CWeb* scene, CRenderContext& context, CAudioContext& audioContext, WallpaperEngine::WebBrowser::CWebBrowserContext& browserContext, const CWallpaperState::TextureUVsScaling& scalingMode); ~CWeb() override; [[nodiscard]] int getWidth () const override { return this->m_width; } @@ -35,8 +35,7 @@ namespace WallpaperEngine::Render::Wallpapers { protected: void renderFrame (glm::ivec4 viewport) override; void updateMouse (glm::ivec4 viewport); - Core::Wallpapers::CWeb* getWeb () - { + const Core::Wallpapers::CWeb* getWeb () const { return this->getWallpaperData ()->as (); }