diff --git a/CMakeLists.txt b/CMakeLists.txt index 52c4dde..121952f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,8 @@ add_executable( src/WallpaperEngine/Render/Objects/CImage.h src/WallpaperEngine/Render/Objects/CImage.cpp + src/WallpaperEngine/Render/Objects/CSound.cpp + src/WallpaperEngine/Render/Objects/CSound.h src/WallpaperEngine/FileSystem/FileSystem.cpp src/WallpaperEngine/FileSystem/FileSystem.h @@ -61,6 +63,8 @@ add_executable( src/WallpaperEngine/Core/Projects/CProperty.cpp src/WallpaperEngine/Core/Projects/CPropertyColor.h src/WallpaperEngine/Core/Projects/CPropertyColor.cpp + src/WallpaperEngine/Core/Projects/CPropertyBoolean.h + src/WallpaperEngine/Core/Projects/CPropertyBoolean.cpp src/WallpaperEngine/Core/Scenes/CCamera.cpp src/WallpaperEngine/Core/Scenes/CCamera.h @@ -97,12 +101,13 @@ add_executable( src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h + src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.cpp + src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp src/WallpaperEngine/Core/Objects/Images/CMaterial.h src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.cpp - src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.h -) + src/WallpaperEngine/Core/Objects/Images/Materials/CPassess.h) target_link_libraries(wallengine ${X11_LIBRARIES} ${XRANDR_LIBRARIES} ${X11_Xxf86vm_LIB} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${ZLIB_LIBRARIES} ${IRRLICHT_LIBRARY} ${LZ4_LIBRARY} ${SDL_LIBRARY} ${SDL_MIXER_LIBRARIES}) \ No newline at end of file diff --git a/src/WallpaperEngine/Core/CObject.cpp b/src/WallpaperEngine/Core/CObject.cpp index 52bb31e..b8ed4ef 100644 --- a/src/WallpaperEngine/Core/CObject.cpp +++ b/src/WallpaperEngine/Core/CObject.cpp @@ -68,7 +68,16 @@ CObject* CObject::fromJSON (json data) // visibility is optional if (visible_it != data.end ()) { - visible = *visible_it; + if (visible_it->is_boolean () == false) + { + // TODO: SUPPORT CONFIGURATION VALUES ON ATTRIBUTES LIKE VISIBLE + // TODO: FOR NOW JUST DEFAULT TO FALSE + visible = false; + } + else + { + visible = *visible_it; + } } json::const_iterator image_it = data.find ("image"); diff --git a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp index 7d1f506..8660eb8 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp @@ -7,6 +7,7 @@ #include "WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h" #include "WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h" #include "WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h" +#include "WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h" using namespace WallpaperEngine::Core::Objects::Particles; @@ -49,6 +50,10 @@ CInitializer* CInitializer::fromJSON (json data) { return Initializers::CAngularVelocityRandom::fromJSON (data, id); } + else if (*name_it == "turbulentvelocityrandom") + { + return Initializers::CTurbulentVelocityRandom::fromJSON (data, id); + } else { throw std::runtime_error ("Particle's got an unknown initializer"); diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp index 0de09f7..22d224a 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.cpp @@ -1,5 +1,7 @@ #include "CRotationRandom.h" +#include "WallpaperEngine/Core/Core.h" + using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CRotationRandom* CRotationRandom::fromJSON (json data, irr::u32 id) @@ -7,35 +9,35 @@ CRotationRandom* CRotationRandom::fromJSON (json data, irr::u32 id) json::const_iterator min_it = data.find ("min"); json::const_iterator max_it = data.find ("max"); - irr::f64 min = 0.0f; - irr::f64 max = 360.0f; + irr::core::vector3df min = irr::core::vector3df (); + irr::core::vector3df max = irr::core::vector3df (); if (min_it != data.end ()) { - min = *min_it; + min = WallpaperEngine::Core::ato3vf (*min_it); } if (max_it != data.end ()) { - max = *max_it; + max = WallpaperEngine::Core::ato3vf (*max_it); } return new CRotationRandom (id, min, max); } -CRotationRandom::CRotationRandom (irr::u32 id, irr::f64 min, irr::f64 max) : +CRotationRandom::CRotationRandom (irr::u32 id, irr::core::vector3df min, irr::core::vector3df max) : CInitializer (id, "rotationrandom"), m_min (min), m_max (max) { } -irr::f64 CRotationRandom::getMinimum () +irr::core::vector3df CRotationRandom::getMinimum () { return this->m_min; } -irr::f64 CRotationRandom::getMaximum () +irr::core::vector3df CRotationRandom::getMaximum () { return this->m_max; } \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h index 8b0c104..a9be8e1 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CRotationRandom.h @@ -10,16 +10,16 @@ namespace WallpaperEngine::Core::Objects::Particles::Initializers class CRotationRandom : CInitializer { public: - irr::f64 getMinimum (); - irr::f64 getMaximum (); + irr::core::vector3df getMinimum (); + irr::core::vector3df getMaximum (); protected: friend class CInitializer; static CRotationRandom* fromJSON (json data, irr::u32 id); - CRotationRandom (irr::u32 id, irr::f64 min, irr::f64 max); + CRotationRandom (irr::u32 id, irr::core::vector3df min, irr::core::vector3df max); private: - irr::f64 m_max; - irr::f64 m_min; + irr::core::vector3df m_max; + irr::core::vector3df m_min; }; }; diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.cpp new file mode 100644 index 0000000..8c26cac --- /dev/null +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.cpp @@ -0,0 +1,86 @@ +#include "CTurbulentVelocityRandom.h" + +#include "WallpaperEngine/Core/Core.h" + +using namespace WallpaperEngine::Core::Objects::Particles::Initializers; + +CTurbulentVelocityRandom* CTurbulentVelocityRandom::fromJSON (json data, irr::u32 id) +{ + json::const_iterator phasemax_it = data.find ("phasemax"); + json::const_iterator scale_it = data.find ("scale"); + json::const_iterator speedmax_it = data.find ("speedmax"); + json::const_iterator speedmin_it = data.find ("speedmin"); + json::const_iterator timescale_it = data.find ("timescale"); + + if (phasemax_it == data.end ()) + { + throw std::runtime_error ("TurbulentVelocityRandom initializer must have a phasemax value"); + } + + if (scale_it == data.end ()) + { + throw std::runtime_error ("TurbulentVelocityRandom initializer must have a scale value"); + } + + if (speedmax_it == data.end ()) + { + throw std::runtime_error ("TurbulentVelocityRandom initializer must have a maximum speed value"); + } + + if (speedmin_it == data.end ()) + { + throw std::runtime_error ("TurbulentVelocityRandom initializer must have a minimum speed value"); + } + + if (timescale_it == data.end ()) + { + throw std::runtime_error ("TurbulentVelocityRandom initializer must have a timescale value"); + } + + return new CTurbulentVelocityRandom ( + id, + *phasemax_it, + *scale_it, + *timescale_it, + *speedmin_it, + *speedmax_it + ); +} + + +CTurbulentVelocityRandom::CTurbulentVelocityRandom (irr::u32 id, + irr::f64 phasemax, irr::f64 scale, irr::f64 timescale, irr::u32 speedmin, irr::u32 speedmax) : + CInitializer (id, "turbulentvelocityrandom"), + m_phasemax (phasemax), + m_scale (scale), + m_timescale (timescale), + m_speedmin (speedmin), + m_speedmax (speedmax) +{ +} + + +irr::f64 CTurbulentVelocityRandom::getPhaseMax () +{ + return this->m_phasemax; +} + +irr::f64 CTurbulentVelocityRandom::getScale () +{ + return this->m_scale; +} + +irr::f64 CTurbulentVelocityRandom::getTimeScale () +{ + return this->m_timescale; +} + +irr::u32 CTurbulentVelocityRandom::getMinimumSpeed () +{ + return this->m_speedmin; +} + +irr::u32 CTurbulentVelocityRandom::getMaximumSpeed () +{ + return this->m_speedmax; +} diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h new file mode 100644 index 0000000..7168e9b --- /dev/null +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CTurbulentVelocityRandom.h @@ -0,0 +1,33 @@ +#pragma once + +#include "WallpaperEngine/Core/Objects/Particles/CInitializer.h" + +#include +#include + +namespace WallpaperEngine::Core::Objects::Particles::Initializers +{ + class CTurbulentVelocityRandom : CInitializer + { + public: + irr::f64 getPhaseMax (); + irr::f64 getScale (); + irr::f64 getTimeScale (); + irr::u32 getMinimumSpeed (); + irr::u32 getMaximumSpeed (); + + protected: + friend class CInitializer; + + static CTurbulentVelocityRandom* fromJSON (json data, irr::u32 id); + + CTurbulentVelocityRandom (irr::u32 id, + irr::f64 phasemax, irr::f64 scale, irr::f64 timescale, irr::u32 speedmin, irr::u32 speedmax); + private: + irr::f64 m_phasemax; + irr::f64 m_scale; + irr::f64 m_timescale; + irr::u32 m_speedmin; + irr::u32 m_speedmax; + }; +}; diff --git a/src/WallpaperEngine/Core/Projects/CProperty.cpp b/src/WallpaperEngine/Core/Projects/CProperty.cpp index 1055b20..7ff6c7a 100644 --- a/src/WallpaperEngine/Core/Projects/CProperty.cpp +++ b/src/WallpaperEngine/Core/Projects/CProperty.cpp @@ -1,5 +1,6 @@ #include "CProperty.h" #include "CPropertyColor.h" +#include "CPropertyBoolean.h" namespace WallpaperEngine::Core::Projects { @@ -24,6 +25,11 @@ namespace WallpaperEngine::Core::Projects return CPropertyColor::fromJSON (data, name); } + if (*type == CPropertyBoolean::Type) + { + return CPropertyBoolean::fromJSON (data, name); + } + throw std::runtime_error ("Unexpected type for property"); } diff --git a/src/WallpaperEngine/Core/Projects/CPropertyBoolean.cpp b/src/WallpaperEngine/Core/Projects/CPropertyBoolean.cpp new file mode 100644 index 0000000..5295aaa --- /dev/null +++ b/src/WallpaperEngine/Core/Projects/CPropertyBoolean.cpp @@ -0,0 +1,29 @@ +#include "CPropertyBoolean.h" +#include "WallpaperEngine/Core/Core.h" + +using namespace WallpaperEngine::Core::Projects; + +CPropertyBoolean* CPropertyBoolean::fromJSON (json data, const std::string& name) +{ + json::const_iterator value = data.find ("value"); + json::const_iterator text = data.find ("type"); + + return new CPropertyBoolean ( + *value, + name, + *text + ); +} + +bool CPropertyBoolean::getValue () +{ + return &this->m_value; +} + +CPropertyBoolean::CPropertyBoolean (bool value, const std::string& name, const std::string& text) : + CProperty (name, Type, text), + m_value (value) +{ +} + +const std::string CPropertyBoolean::Type = "bool"; \ No newline at end of file diff --git a/src/WallpaperEngine/Core/Projects/CPropertyBoolean.h b/src/WallpaperEngine/Core/Projects/CPropertyBoolean.h new file mode 100644 index 0000000..9a15ce1 --- /dev/null +++ b/src/WallpaperEngine/Core/Projects/CPropertyBoolean.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include "CProperty.h" + +namespace WallpaperEngine::Core::Projects +{ + using json = nlohmann::json; + + class CPropertyBoolean : public CProperty + { + public: + static CPropertyBoolean* fromJSON (json data, const std::string& name); + + bool getValue (); + + static const std::string Type; + + private: + CPropertyBoolean (bool value, const std::string& name, const std::string& text); + + bool m_value; + }; +}; diff --git a/src/WallpaperEngine/Irrlicht/CPkgReader.cpp b/src/WallpaperEngine/Irrlicht/CPkgReader.cpp index 1c41670..0804169 100644 --- a/src/WallpaperEngine/Irrlicht/CPkgReader.cpp +++ b/src/WallpaperEngine/Irrlicht/CPkgReader.cpp @@ -104,7 +104,7 @@ namespace WallpaperEngine::Irrlicht { char* headerVersion = this->readSizedString (); - if (strcmp ("PKGV0002", headerVersion) != 0 && strcmp ("PKGV0001", headerVersion) != 0) + if (strcmp ("PKGV0007", headerVersion) != 0 && strcmp ("PKGV0002", headerVersion) != 0 && strcmp ("PKGV0001", headerVersion) != 0) { delete [] headerVersion; diff --git a/src/WallpaperEngine/Render/CScene.cpp b/src/WallpaperEngine/Render/CScene.cpp index a9fcaff..8584bfb 100644 --- a/src/WallpaperEngine/Render/CScene.cpp +++ b/src/WallpaperEngine/Render/CScene.cpp @@ -1,5 +1,9 @@ #include "WallpaperEngine/Core/Objects/CImage.h" +#include "WallpaperEngine/Core/Objects/CSound.h" +#include "WallpaperEngine/Core/Objects/CParticle.h" + #include "WallpaperEngine/Render/Objects/CImage.h" +#include "WallpaperEngine/Render/Objects/CSound.h" #include "CScene.h" using namespace WallpaperEngine; @@ -14,6 +18,12 @@ CScene::CScene (Core::CProject* project, Irrlicht::CContext* context) : m_scene (project->getScene ()), m_context (context) { + this->m_camera = new CCamera (this, this->m_project->getScene ()->getCamera ()); + this->m_camera->setOrthogonalProjection ( + this->m_scene->getOrthogonalProjection ()->getWidth (), + this->m_scene->getOrthogonalProjection ()->getHeight () + ); + std::vector::const_iterator cur = this->m_scene->getObjects ()->begin (); std::vector::const_iterator end = this->m_scene->getObjects ()->end (); @@ -28,17 +38,23 @@ CScene::CScene (Core::CProject* project, Irrlicht::CContext* context) : { new Objects::CImage (this, (*cur)->As ()); } + else if ((*cur)->Is () == true) + { + new Objects::CSound (this, (*cur)->As ()); + } + else if ((*cur)->Is () == true) + { + this->getContext ()->getDevice ()->getLogger ()->log ("Particles disabled, not supported yet", irr::ELL_ERROR); + } + else + { + throw std::runtime_error ("unsupported object type found"); + } } this->m_nextId = ++highestId; this->setAutomaticCulling (irr::scene::EAC_OFF); this->m_boundingBox = irr::core::aabbox3d(0, 0, 0, 0, 0, 0); - - this->m_camera = new CCamera (this, this->m_project->getScene ()->getCamera ()); - this->m_camera->setOrthogonalProjection ( - this->m_scene->getOrthogonalProjection ()->getWidth (), - this->m_scene->getOrthogonalProjection ()->getHeight () - ); } CScene::~CScene () diff --git a/src/WallpaperEngine/Render/Objects/CSound.cpp b/src/WallpaperEngine/Render/Objects/CSound.cpp new file mode 100644 index 0000000..b7e44c1 --- /dev/null +++ b/src/WallpaperEngine/Render/Objects/CSound.cpp @@ -0,0 +1,69 @@ +#include "CSound.h" + +using namespace WallpaperEngine; +using namespace WallpaperEngine::Render::Objects; + +CSound::CSound (CScene* scene, Core::Objects::CSound* sound) : + Render::CObject (scene, Type, sound), + m_sound (sound) +{ + this->m_boundingBox = irr::core::aabbox3d(0, 0, 0, 0, 0, 0); + + this->play (); +} + +void CSound::play () +{ + std::vector* sounds = this->m_sound->getSounds (); + std::vector::const_iterator cur = sounds->begin (); + std::vector::const_iterator end = sounds->end (); + + for (; cur != end; cur ++) + { + SDL_RWops* rwops = nullptr; + Mix_Music* music = nullptr; + + // open the sound file and read it fully + irr::io::IReadFile* readfile = this->getScene ()->getContext ()->getDevice ()->getFileSystem ()->createAndOpenFile ((*cur).c_str ()); + long filesize = readfile->getSize (); + char* buffer = new char [filesize]; + + // TODO: IMPLEMENT A MAXIMUM FILESIZE TO PREVENT CRAZY ALLOCATIONS + + readfile->read (buffer, filesize); + + rwops = SDL_RWFromConstMem (buffer, filesize); + music = Mix_LoadMUS_RW (rwops); + + // free the file reader + readfile->drop (); + + if (music == nullptr) + { + this->getScene ()->getContext ()->getDevice ()->getLogger ()->log ("Cannot load audio", Mix_GetError (), irr::ELL_ERROR); + } + + this->m_bufferReader.push_back (rwops); + this->m_mixSdl.push_back (music); + this->m_soundBuffer.push_back (buffer); + } + + // after all the sounds are loaded, play them all + std::vector::const_iterator mixcur = this->m_mixSdl.begin (); + std::vector::const_iterator mixend = this->m_mixSdl.end (); + + for (; mixcur != mixend; mixcur ++) + { + if (Mix_PlayMusic ((*mixcur), -1) == -1) + { + this->getScene ()->getContext ()->getDevice ()->getLogger ()->log ("Cannot play audio", Mix_GetError (), irr::ELL_ERROR); + } + } +} + +const irr::core::aabbox3d& CSound::getBoundingBox () const +{ + return this->m_boundingBox; +} + +const std::string CSound::Type = "sound"; \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Objects/CSound.h b/src/WallpaperEngine/Render/Objects/CSound.h new file mode 100644 index 0000000..34da5d6 --- /dev/null +++ b/src/WallpaperEngine/Render/Objects/CSound.h @@ -0,0 +1,35 @@ +#pragma once + +#include + +#include "WallpaperEngine/Core/Objects/CSound.h" + +#include "WallpaperEngine/Render/CObject.h" +#include "WallpaperEngine/Render/CScene.h" + +using namespace WallpaperEngine; + +namespace WallpaperEngine::Render::Objects +{ + class CSound : public CObject + { + public: + CSound (CScene* scene, Core::Objects::CSound* sound); + + void render () override {}; + const irr::core::aabbox3d& getBoundingBox () const override; + + protected: + static const std::string Type; + + void play (); + + private: + Core::Objects::CSound* m_sound; + irr::core::aabbox3d m_boundingBox; + + std::vector m_mixSdl; + std::vector m_bufferReader; + std::vector m_soundBuffer; + }; +}