mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +08:00
chore: cleanup of the core part of the project
This commit is contained in:
parent
5e95fda88b
commit
1db86053ce
@ -296,7 +296,7 @@ void CApplicationContext::validateAssets () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CApplicationContext::validateScreenshot () {
|
void CApplicationContext::validateScreenshot () const {
|
||||||
if (!this->settings.screenshot.take)
|
if (!this->settings.screenshot.take)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ class CApplicationContext {
|
|||||||
/**
|
/**
|
||||||
* Validates the screenshot settings
|
* Validates the screenshot settings
|
||||||
*/
|
*/
|
||||||
void validateScreenshot ();
|
void validateScreenshot () const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates a background parameter and returns the real bgIdOrPath to it
|
* Validates a background parameter and returns the real bgIdOrPath to it
|
||||||
|
@ -1 +0,0 @@
|
|||||||
#include "CApplicationState.h"
|
|
@ -211,7 +211,9 @@ void CWallpaperApplication::setupProperties () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CWallpaperApplication::setupBrowser () {
|
void CWallpaperApplication::setupBrowser () {
|
||||||
bool anyWebProject = std::any_of (this->m_backgrounds.begin (), this->m_backgrounds.end (), [](std::pair<const std::string, const Core::CProject*> pair) -> bool {
|
bool anyWebProject = std::any_of (
|
||||||
|
this->m_backgrounds.begin (), this->m_backgrounds.end (),
|
||||||
|
[](const std::pair<const std::string, const Core::CProject*>& pair) -> bool {
|
||||||
return pair.second->getWallpaper()->is<Core::Wallpapers::CWeb> ();
|
return pair.second->getWallpaper()->is<Core::Wallpapers::CWeb> ();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -403,10 +405,13 @@ void CWallpaperApplication::prepareOutputs () {
|
|||||||
|
|
||||||
// set all the specific wallpapers required
|
// set all the specific wallpapers required
|
||||||
for (const auto& [background, info] : this->m_backgrounds) {
|
for (const auto& [background, info] : this->m_backgrounds) {
|
||||||
m_renderContext->setWallpaper (background,
|
m_renderContext->setWallpaper (
|
||||||
WallpaperEngine::Render::CWallpaper::fromWallpaper (
|
background,
|
||||||
info->getWallpaper (), *m_renderContext, *m_audioContext, *m_browserContext,
|
WallpaperEngine::Render::CWallpaper::fromWallpaper (
|
||||||
this->m_context.settings.general.screenScalings [background]));
|
info->getWallpaper (), *m_renderContext, *m_audioContext, *m_browserContext,
|
||||||
|
this->m_context.settings.general.screenScalings [background]
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ using namespace WallpaperEngine::Assets;
|
|||||||
class CPackageEntry {
|
class CPackageEntry {
|
||||||
public:
|
public:
|
||||||
CPackageEntry (std::string filename, uint32_t offset, uint32_t length) :
|
CPackageEntry (std::string filename, uint32_t offset, uint32_t length) :
|
||||||
filename (std::move (filename)),
|
filename (filename),
|
||||||
offset (offset),
|
offset (offset),
|
||||||
length (length) {}
|
length (length) {}
|
||||||
|
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
|
|
||||||
// maximum size of the queue to prevent reading too much data
|
// maximum size of the queue to prevent reading too much data
|
||||||
#define MAX_QUEUE_SIZE (5 * 1024 * 1024)
|
#define MAX_QUEUE_SIZE (5 * 1024 * 1024)
|
||||||
#define MIN_FRAMES 25
|
#define MIN_FRAMES (25)
|
||||||
|
#define NO_AUDIO_STREAM (-1)
|
||||||
|
|
||||||
using namespace WallpaperEngine::Audio;
|
using namespace WallpaperEngine::Audio;
|
||||||
|
|
||||||
@ -82,7 +83,6 @@ int64_t audio_seek_data_callback (void* streamarg, int64_t offset, int whence) {
|
|||||||
|
|
||||||
switch (whence) {
|
switch (whence) {
|
||||||
case SEEK_CUR: stream->setPosition (stream->getPosition () + offset); break;
|
case SEEK_CUR: stream->setPosition (stream->getPosition () + offset); break;
|
||||||
|
|
||||||
case SEEK_SET: stream->setPosition (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) :
|
CAudioStream::CAudioStream (CAudioContext& context, const std::string& filename) :
|
||||||
m_swrctx (nullptr),
|
m_swrctx (nullptr),
|
||||||
|
m_audioStream(NO_AUDIO_STREAM),
|
||||||
m_audioContext (context) {
|
m_audioContext (context) {
|
||||||
this->loadCustomContent (filename.c_str ());
|
this->loadCustomContent (filename.c_str ());
|
||||||
}
|
}
|
||||||
|
|
||||||
CAudioStream::CAudioStream (CAudioContext& context, const uint8_t* buffer, uint32_t length) :
|
CAudioStream::CAudioStream (CAudioContext& context, const uint8_t* buffer, uint32_t length) :
|
||||||
m_swrctx (nullptr),
|
m_swrctx (nullptr),
|
||||||
|
m_audioStream(NO_AUDIO_STREAM),
|
||||||
m_audioContext (context) {
|
m_audioContext (context) {
|
||||||
// setup a custom context first
|
// setup a custom context first
|
||||||
this->m_formatContext = avformat_alloc_context ();
|
this->m_formatContext = avformat_alloc_context ();
|
||||||
@ -122,6 +124,7 @@ CAudioStream::CAudioStream (CAudioContext& context, const uint8_t* buffer, uint3
|
|||||||
CAudioStream::CAudioStream (CAudioContext& audioContext, AVCodecContext* context) :
|
CAudioStream::CAudioStream (CAudioContext& audioContext, AVCodecContext* context) :
|
||||||
m_swrctx (nullptr),
|
m_swrctx (nullptr),
|
||||||
m_audioContext (audioContext),
|
m_audioContext (audioContext),
|
||||||
|
m_audioStream(NO_AUDIO_STREAM),
|
||||||
m_context (context),
|
m_context (context),
|
||||||
m_queue (new PacketQueue) {
|
m_queue (new PacketQueue) {
|
||||||
this->initialize ();
|
this->initialize ();
|
||||||
@ -142,17 +145,14 @@ void CAudioStream::loadCustomContent (const char* filename) {
|
|||||||
if (avformat_find_stream_info (this->m_formatContext, nullptr) < 0)
|
if (avformat_find_stream_info (this->m_formatContext, nullptr) < 0)
|
||||||
sLog.exception ("Cannot determine file format: ", filename);
|
sLog.exception ("Cannot determine file format: ", filename);
|
||||||
|
|
||||||
bool hasAudioStream = false;
|
|
||||||
|
|
||||||
// find the audio stream
|
// find the audio stream
|
||||||
for (unsigned int i = 0; i < this->m_formatContext->nb_streams; i++) {
|
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) {
|
if (this->m_formatContext->streams [i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && this->m_audioStream == NO_AUDIO_STREAM) {
|
||||||
hasAudioStream = true;
|
|
||||||
this->m_audioStream = i;
|
this->m_audioStream = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasAudioStream)
|
if (this->m_audioStream == NO_AUDIO_STREAM)
|
||||||
sLog.exception ("Cannot find an audio stream in file ", filename);
|
sLog.exception ("Cannot find an audio stream in file ", filename);
|
||||||
|
|
||||||
// get the decoder for it and alloc the required context
|
// get the decoder for it and alloc the required context
|
||||||
@ -282,7 +282,7 @@ bool CAudioStream::doQueue (AVPacket* pkt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CAudioStream::dequeuePacket (AVPacket* output) {
|
void CAudioStream::dequeuePacket (AVPacket* output) {
|
||||||
MyAVPacketList entry;
|
MyAVPacketList entry{};
|
||||||
|
|
||||||
SDL_LockMutex (this->m_queue->mutex);
|
SDL_LockMutex (this->m_queue->mutex);
|
||||||
|
|
||||||
@ -368,6 +368,10 @@ int CAudioStream::getQueuePacketCount () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AVRational CAudioStream::getTimeBase () {
|
AVRational CAudioStream::getTimeBase () {
|
||||||
|
if (this->m_audioStream == NO_AUDIO_STREAM) {
|
||||||
|
return {0, 0};
|
||||||
|
}
|
||||||
|
|
||||||
return this->m_formatContext->streams [this->m_audioStream]->time_base;
|
return this->m_formatContext->streams [this->m_audioStream]->time_base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include "WallpaperEngine/Core/Objects/CSound.h"
|
#include "WallpaperEngine/Core/Objects/CSound.h"
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
||||||
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
|
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Assets/CContainer.h"
|
#include "WallpaperEngine/Assets/CContainer.h"
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
#include "WallpaperEngine/Logging/CLog.h"
|
||||||
@ -15,48 +14,57 @@ using namespace WallpaperEngine::Core;
|
|||||||
using namespace WallpaperEngine::Assets;
|
using namespace WallpaperEngine::Assets;
|
||||||
using namespace WallpaperEngine::Core::UserSettings;
|
using namespace WallpaperEngine::Core::UserSettings;
|
||||||
|
|
||||||
CObject::CObject (Wallpapers::CScene* scene, CUserSettingBoolean* visible, int id, std::string name, std::string type,
|
CObject::CObject (
|
||||||
CUserSettingVector3* origin, CUserSettingVector3* scale, const glm::vec3& angles) :
|
const Wallpapers::CScene* scene, const CUserSettingBoolean* visible, int id, std::string name, std::string type,
|
||||||
m_type (std::move (type)),
|
const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles, std::vector<int> dependencies
|
||||||
|
) :
|
||||||
|
m_type (type),
|
||||||
m_visible (visible),
|
m_visible (visible),
|
||||||
m_id (id),
|
m_id (id),
|
||||||
m_name (std::move (name)),
|
m_name (name),
|
||||||
m_origin (origin),
|
m_origin (origin),
|
||||||
m_scale (scale),
|
m_scale (scale),
|
||||||
m_angles (angles),
|
m_angles (angles),
|
||||||
m_scene (scene) {}
|
m_scene (scene),
|
||||||
|
m_dependencies (dependencies) {}
|
||||||
|
|
||||||
CObject* CObject::fromJSON (json data, Wallpapers::CScene* scene, CContainer* container) {
|
const CObject* CObject::fromJSON (
|
||||||
std::string json = data.dump ();
|
const json& data, const Wallpapers::CScene* scene, const CContainer* container
|
||||||
|
) {
|
||||||
|
const auto id = jsonFindRequired <int> (data, "id", "Objects must have id");
|
||||||
|
const auto visible = jsonFindUserConfig<CUserSettingBoolean> (data, "visible", true);
|
||||||
|
const auto origin = jsonFindUserConfig<CUserSettingVector3> (data, "origin", {0, 0, 0});
|
||||||
|
const auto scale = jsonFindUserConfig<CUserSettingVector3> (data, "scale", {1, 1, 1});
|
||||||
|
const auto angles_val = jsonFindDefault<glm::vec3> (data, "angles", glm::vec3 (0, 0, 0));
|
||||||
|
const auto name = jsonFindRequired <std::string> (data, "name", "Objects must have name");
|
||||||
|
const auto effects_it = data.find ("effects");
|
||||||
|
const auto dependencies_it = data.find ("dependencies");
|
||||||
|
|
||||||
auto id_it = jsonFindRequired (data, "id", "Objects must have id");
|
const auto image_it = data.find ("image");
|
||||||
auto visible = jsonFindUserConfig<CUserSettingBoolean> (data, "visible", true);
|
const auto sound_it = data.find ("sound");
|
||||||
auto origin = jsonFindUserConfig<CUserSettingVector3> (data, "origin", {0, 0, 0});
|
const auto particle_it = data.find ("particle");
|
||||||
auto scale = jsonFindUserConfig<CUserSettingVector3> (data, "scale", {1, 1, 1});
|
const auto text_it = data.find ("text");
|
||||||
auto angles_val = jsonFindDefault<std::string> (data, "angles", "0.0 0.0 0.0");
|
const auto light_it = data.find ("light");
|
||||||
auto name_it = jsonFindRequired (data, "name", "Objects must have name");
|
|
||||||
auto effects_it = data.find ("effects");
|
|
||||||
auto dependencies_it = data.find ("dependencies");
|
|
||||||
|
|
||||||
auto image_it = data.find ("image");
|
std::vector<int> dependencies;
|
||||||
auto sound_it = data.find ("sound");
|
std::vector<const Objects::CEffect*> effects;
|
||||||
auto particle_it = data.find ("particle");
|
|
||||||
auto text_it = data.find ("text");
|
|
||||||
auto light_it = data.find ("light");
|
|
||||||
|
|
||||||
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 ()) {
|
if (image_it != data.end () && !image_it->is_null ()) {
|
||||||
object = Objects::CImage::fromJSON (scene, data, container, visible, *id_it, *name_it, origin, scale,
|
object = Objects::CImage::fromJSON (
|
||||||
WallpaperEngine::Core::aToVector3 (angles_val));
|
scene, data, container, visible, id, name, origin, scale, angles_val, effects_it, dependencies);
|
||||||
} else if (sound_it != data.end () && !sound_it->is_null ()) {
|
} else if (sound_it != data.end () && !sound_it->is_null ()) {
|
||||||
object = Objects::CSound::fromJSON (scene, data, visible, *id_it, *name_it, origin, scale,
|
object = Objects::CSound::fromJSON (scene, data, visible, id, name, origin, scale, angles_val, dependencies);
|
||||||
WallpaperEngine::Core::aToVector3 (angles_val));
|
|
||||||
} else if (particle_it != data.end () && !particle_it->is_null ()) {
|
} else if (particle_it != data.end () && !particle_it->is_null ()) {
|
||||||
/// TODO: XXXHACK -- TO REMOVE WHEN PARTICLE SUPPORT IS PROPERLY IMPLEMENTED
|
/// TODO: XXXHACK -- TO REMOVE WHEN PARTICLE SUPPORT IS PROPERLY IMPLEMENTED
|
||||||
try {
|
try {
|
||||||
object = Objects::CParticle::fromFile (scene, particle_it->get<std::string> (), container, visible, *id_it,
|
object = Objects::CParticle::fromFile (
|
||||||
*name_it, origin, scale);
|
scene, particle_it->get<std::string> (), container, visible, id, name, origin, scale, dependencies);
|
||||||
} catch (std::runtime_error&) {
|
} catch (std::runtime_error&) {
|
||||||
return nullptr;
|
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
|
/// TODO: XXXHACK -- TO REMOVE WHEN LIGHT SUPPORT IS IMPLEMENTED
|
||||||
return nullptr;
|
return nullptr;
|
||||||
} else {
|
} 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<CUserSettingBoolean> (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;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 CObject::getOrigin () const {
|
const glm::vec3& CObject::getOrigin () const {
|
||||||
return this->m_origin->processValue (this->getScene ()->getProject ().getProperties ());
|
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 ());
|
return this->m_scale->processValue (this->getScene ()->getProject ().getProperties ());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,10 +97,6 @@ const std::string& CObject::getName () const {
|
|||||||
return this->m_name;
|
return this->m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<Objects::CEffect*>& CObject::getEffects () const {
|
|
||||||
return this->m_effects;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<int>& CObject::getDependencies () const {
|
const std::vector<int>& CObject::getDependencies () const {
|
||||||
return this->m_dependencies;
|
return this->m_dependencies;
|
||||||
}
|
}
|
||||||
@ -117,18 +106,10 @@ bool CObject::isVisible () const {
|
|||||||
return this->m_visible->processValue (this->getScene ()->getProject ().getProperties ());
|
return this->m_visible->processValue (this->getScene ()->getProject ().getProperties ());
|
||||||
}
|
}
|
||||||
|
|
||||||
Wallpapers::CScene* CObject::getScene () const {
|
const Wallpapers::CScene* CObject::getScene () const {
|
||||||
return this->m_scene;
|
return this->m_scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CObject::getId () const {
|
int CObject::getId () const {
|
||||||
return this->m_id;
|
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);
|
|
||||||
}
|
|
@ -29,7 +29,7 @@ class CObject {
|
|||||||
friend class Wallpapers::CScene;
|
friend class Wallpapers::CScene;
|
||||||
|
|
||||||
public:
|
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 <class T> const T* as () const {
|
template <class T> const T* as () const {
|
||||||
assert (is<T> ());
|
assert (is<T> ());
|
||||||
@ -41,42 +41,39 @@ class CObject {
|
|||||||
return reinterpret_cast<T*> (this);
|
return reinterpret_cast<T*> (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> bool is () {
|
template <class T> bool is () const {
|
||||||
return this->m_type == T::Type;
|
return this->m_type == T::Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] const std::vector<Objects::CEffect*>& getEffects () const;
|
|
||||||
[[nodiscard]] const std::vector<int>& getDependencies () const;
|
[[nodiscard]] const std::vector<int>& getDependencies () const;
|
||||||
[[nodiscard]] int getId () const;
|
[[nodiscard]] int getId () const;
|
||||||
|
|
||||||
[[nodiscard]] glm::vec3 getOrigin () const;
|
[[nodiscard]] const glm::vec3& getOrigin () const;
|
||||||
[[nodiscard]] glm::vec3 getScale () const;
|
[[nodiscard]] const glm::vec3& getScale () const;
|
||||||
[[nodiscard]] const glm::vec3& getAngles () const;
|
[[nodiscard]] const glm::vec3& getAngles () const;
|
||||||
[[nodiscard]] const std::string& getName () const;
|
[[nodiscard]] const std::string& getName () const;
|
||||||
|
|
||||||
[[nodiscard]] bool isVisible () const;
|
[[nodiscard]] bool isVisible () const;
|
||||||
[[nodiscard]] Wallpapers::CScene* getScene () const;
|
[[nodiscard]] const Wallpapers::CScene* getScene () const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CObject (Wallpapers::CScene* scene, CUserSettingBoolean* visible, int id, std::string name, std::string type,
|
CObject (
|
||||||
CUserSettingVector3* origin, CUserSettingVector3* scale, const glm::vec3& angles);
|
const Wallpapers::CScene* scene, const CUserSettingBoolean* visible, int id, std::string name, std::string type,
|
||||||
|
const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles,
|
||||||
void insertEffect (Objects::CEffect* effect);
|
std::vector<int> dependencies);
|
||||||
void insertDependency (int dependency);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_type;
|
const std::string m_type;
|
||||||
|
|
||||||
CUserSettingBoolean* m_visible;
|
const CUserSettingBoolean* m_visible;
|
||||||
int m_id;
|
int m_id;
|
||||||
std::string m_name;
|
const std::string m_name;
|
||||||
CUserSettingVector3* m_origin;
|
const CUserSettingVector3* m_origin;
|
||||||
CUserSettingVector3* m_scale;
|
const CUserSettingVector3* m_scale;
|
||||||
glm::vec3 m_angles;
|
const glm::vec3 m_angles;
|
||||||
|
|
||||||
std::vector<Objects::CEffect*> m_effects;
|
const std::vector<int> m_dependencies;
|
||||||
std::vector<int> m_dependencies;
|
|
||||||
|
|
||||||
Wallpapers::CScene* m_scene;
|
const Wallpapers::CScene* m_scene;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core
|
} // namespace WallpaperEngine::Core
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#include <WallpaperEngine/Assets/CContainer.h>
|
#include <WallpaperEngine/Assets/CContainer.h>
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "CProject.h"
|
#include "CProject.h"
|
||||||
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
|
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
|
||||||
#include "WallpaperEngine/Core/Wallpapers/CVideo.h"
|
#include "WallpaperEngine/Core/Wallpapers/CVideo.h"
|
||||||
@ -14,65 +12,68 @@ using namespace WallpaperEngine::Assets;
|
|||||||
|
|
||||||
static int backgroundId = -1;
|
static int backgroundId = -1;
|
||||||
|
|
||||||
CProject::CProject (std::string title, std::string type, std::string workshopid, CContainer* container) :
|
CProject::CProject (std::string title, std::string type, std::string workshopid, const CContainer* container) :
|
||||||
m_workshopid(std::move(workshopid)),
|
m_workshopid(workshopid),
|
||||||
m_title (std::move (title)),
|
m_title (title),
|
||||||
m_type (std::move (type)),
|
m_type (type),
|
||||||
m_wallpaper (nullptr),
|
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));
|
json content = json::parse (container->readFileAsString (filename));
|
||||||
|
|
||||||
std::string dependency = jsonFindDefault<std::string> (content, "dependency", "No dependency");
|
const auto dependency = jsonFindDefault<std::string> (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 <std::string> (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;
|
|
||||||
|
|
||||||
std::transform (type.begin (), type.end (), type.begin (), tolower);
|
if (dependency != "No dependency") {
|
||||||
|
|
||||||
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 {
|
|
||||||
sLog.exception ("Project have dependency. They are not supported, quiting");
|
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 <std::string> (content, "type", "Project type missing");
|
||||||
|
const auto file = jsonFindRequired <std::string> (content, "file", "Project's main file missing");
|
||||||
|
auto general = content.find ("general");
|
||||||
|
const CWallpaper* wallpaper;
|
||||||
|
|
||||||
|
std::transform (type.begin (), type.end (), type.begin (), tolower);
|
||||||
|
|
||||||
|
CProject* project = new CProject (
|
||||||
|
jsonFindRequired <std::string> (content, "title", "Project title missing"),
|
||||||
|
type,
|
||||||
|
jsonFindDefault <std::string> (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;
|
this->m_wallpaper = wallpaper;
|
||||||
}
|
}
|
||||||
|
|
||||||
CWallpaper* CProject::getWallpaper () const {
|
const CWallpaper* CProject::getWallpaper () const {
|
||||||
return this->m_wallpaper;
|
return this->m_wallpaper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +85,7 @@ const std::string& CProject::getType () const {
|
|||||||
return this->m_type;
|
return this->m_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<Projects::CProperty*>& CProject::getProperties () const {
|
const std::vector<const Projects::CProperty*>& CProject::getProperties () const {
|
||||||
return this->m_properties;
|
return this->m_properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,10 +93,10 @@ const std::string& CProject::getWorkshopId () const {
|
|||||||
return this->m_workshopid;
|
return this->m_workshopid;
|
||||||
}
|
}
|
||||||
|
|
||||||
CContainer* CProject::getContainer () {
|
const CContainer* CProject::getContainer () const {
|
||||||
return this->m_container;
|
return this->m_container;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CProject::insertProperty (Projects::CProperty* property) {
|
void CProject::insertProperty (const Projects::CProperty* property) {
|
||||||
this->m_properties.push_back (property);
|
this->m_properties.push_back (property);
|
||||||
}
|
}
|
@ -14,30 +14,30 @@ class CWallpaper;
|
|||||||
|
|
||||||
class CProject {
|
class CProject {
|
||||||
public:
|
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& getTitle () const;
|
||||||
[[nodiscard]] const std::string& getType () const;
|
[[nodiscard]] const std::string& getType () const;
|
||||||
[[nodiscard]] const std::vector<Projects::CProperty*>& getProperties () const;
|
[[nodiscard]] const std::vector<const Projects::CProperty*>& getProperties () const;
|
||||||
[[nodiscard]] const std::string& getWorkshopId () const;
|
[[nodiscard]] const std::string& getWorkshopId () const;
|
||||||
|
|
||||||
CContainer* getContainer ();
|
const CContainer* getContainer () const;
|
||||||
|
|
||||||
protected:
|
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 setWallpaper (const CWallpaper* wallpaper);
|
||||||
void insertProperty (Projects::CProperty* property);
|
void insertProperty (const Projects::CProperty* property);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Projects::CProperty*> m_properties;
|
std::vector<const Projects::CProperty*> m_properties;
|
||||||
|
|
||||||
std::string m_workshopid;
|
const std::string m_workshopid;
|
||||||
std::string m_title;
|
const std::string m_title;
|
||||||
std::string m_type;
|
const std::string m_type;
|
||||||
CWallpaper* m_wallpaper;
|
const CWallpaper* m_wallpaper;
|
||||||
CContainer* m_container;
|
const CContainer* m_container;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core
|
} // namespace WallpaperEngine::Core
|
||||||
|
@ -4,8 +4,10 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core;
|
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;
|
return this->m_project;
|
||||||
}
|
}
|
||||||
|
@ -20,20 +20,20 @@ class CWallpaper {
|
|||||||
return reinterpret_cast<T*> (this);
|
return reinterpret_cast<T*> (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> bool is () {
|
template <class T> bool is () const {
|
||||||
return this->m_type == T::Type;
|
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:
|
protected:
|
||||||
friend class CProject;
|
friend class CProject;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CProject& m_project;
|
const CProject& m_project;
|
||||||
|
|
||||||
std::string m_type;
|
const std::string m_type;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core
|
} // namespace WallpaperEngine::Core
|
||||||
|
@ -44,6 +44,42 @@ glm::vec2 Core::aToVector2 (const char* str) {
|
|||||||
return {x, y};
|
return {x, y};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::ivec4 Core::aToVector4i (const char* str) {
|
||||||
|
int x = strtol (str, const_cast<char**> (&str), 10);
|
||||||
|
while (*str == ' ')
|
||||||
|
str++;
|
||||||
|
int y = strtol (str, const_cast<char**> (&str), 10);
|
||||||
|
while (*str == ' ')
|
||||||
|
str++;
|
||||||
|
int z = strtol (str, const_cast<char**> (&str), 10);
|
||||||
|
while (*str == ' ')
|
||||||
|
str++;
|
||||||
|
int w = strtol (str, const_cast<char**> (&str), 10);
|
||||||
|
|
||||||
|
return {x, y, z, w};
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::ivec3 Core::aToVector3i (const char* str) {
|
||||||
|
int x = strtol (str, const_cast<char**> (&str), 10);
|
||||||
|
while (*str == ' ')
|
||||||
|
str++;
|
||||||
|
int y = strtol (str, const_cast<char**> (&str), 10);
|
||||||
|
while (*str == ' ')
|
||||||
|
str++;
|
||||||
|
int z = strtol (str, const_cast<char**> (&str), 10);
|
||||||
|
|
||||||
|
return {x, y, z};
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::ivec2 Core::aToVector2i (const char* str) {
|
||||||
|
int x = strtol (str, const_cast<char**> (&str), 10);
|
||||||
|
while (*str == ' ')
|
||||||
|
str++;
|
||||||
|
int y = strtol (str, const_cast<char**> (&str), 10);
|
||||||
|
|
||||||
|
return {x, y};
|
||||||
|
}
|
||||||
|
|
||||||
glm::vec4 Core::aToVector4 (const std::string& str) {
|
glm::vec4 Core::aToVector4 (const std::string& str) {
|
||||||
return Core::aToVector4 (str.c_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 ());
|
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) {
|
glm::vec3 Core::aToColorf (const char* str) {
|
||||||
float r = strtof (str, const_cast<char**> (&str));
|
float r = strtof (str, const_cast<char**> (&str));
|
||||||
while (*str == ' ')
|
while (*str == ' ')
|
||||||
@ -88,17 +136,172 @@ glm::ivec3 Core::aToColori (const std::string& str) {
|
|||||||
return aToColori (str.c_str ());
|
return aToColori (str.c_str ());
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json::iterator Core::jsonFindRequired (nlohmann::json& data, const char* key, const char* notFoundMsg) {
|
template <typename T> bool typeCheck (const nlohmann::json::const_iterator& value) {
|
||||||
auto value = data.find (key);
|
if (value->type () == nlohmann::detail::value_t::null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (value == data.end ())
|
// type checks
|
||||||
sLog.exception ("Cannot find required key (", key, ") in json: ", notFoundMsg);
|
if constexpr ((std::is_same_v<T, float> || std::is_same_v<T, double>) ) {
|
||||||
|
if (value->type () != nlohmann::detail::value_t::number_float &&
|
||||||
|
value->type () != nlohmann::detail::value_t::number_integer &&
|
||||||
|
value->type () != nlohmann::detail::value_t::number_unsigned) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if constexpr (std::is_same_v<T, std::string>) {
|
||||||
|
if (value->type () != nlohmann::detail::value_t::string) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if constexpr (std::is_same_v<T, bool>) {
|
||||||
|
if (value->type () != nlohmann::detail::value_t::boolean) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json::iterator Core::jsonFindRequired (const nlohmann::json::iterator& data, const char* key,
|
template <typename T> const T Core::jsonFindRequired (
|
||||||
const char* notFoundMsg) {
|
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<T, glm::vec4>) {
|
||||||
|
if (!typeCheck<T> (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<T, glm::vec3>) {
|
||||||
|
if (!typeCheck<T> (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<T, glm::vec2>) {
|
||||||
|
if (!typeCheck<T> (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<T, glm::ivec4>) {
|
||||||
|
if (!typeCheck<T> (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<T, glm::ivec3>) {
|
||||||
|
if (!typeCheck<T> (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<T, glm::ivec2>) {
|
||||||
|
if (!typeCheck<T> (iterator)) {
|
||||||
|
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string");
|
||||||
|
}
|
||||||
|
|
||||||
|
return aToVector2i (*iterator);
|
||||||
|
} else if (typeCheck<T> (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 <typename T> 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<T, glm::vec4>) {
|
||||||
|
if (!typeCheck<T> (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<T, glm::vec3>) {
|
||||||
|
if (!typeCheck<T> (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<T, glm::vec2>) {
|
||||||
|
if (!typeCheck<T> (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<T, glm::ivec4>) {
|
||||||
|
if (!typeCheck<T> (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<T, glm::ivec3>) {
|
||||||
|
if (!typeCheck<T> (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<T, glm::ivec2>) {
|
||||||
|
if (!typeCheck<T> (iterator)) {
|
||||||
|
sLog.exception ("key value doesn't match expected type. Got ", iterator->type_name(), " expected vector-like-string");
|
||||||
|
}
|
||||||
|
|
||||||
|
return aToVector2i (*iterator);
|
||||||
|
} else if (typeCheck<T> (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);
|
auto value = data->find (key);
|
||||||
|
|
||||||
if (value == data->end ())
|
if (value == data->end ())
|
||||||
@ -107,46 +310,184 @@ nlohmann::json::iterator Core::jsonFindRequired (const nlohmann::json::iterator&
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> 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 <typename T> const T Core::jsonFindDefault (
|
||||||
|
const nlohmann::json::const_iterator& data, const char* key, const T defaultValue
|
||||||
|
) {
|
||||||
|
const auto value = data->find (key);
|
||||||
|
|
||||||
|
if (value == data->end () || value->type () == nlohmann::detail::value_t::null)
|
||||||
|
return defaultValue;
|
||||||
|
|
||||||
|
|
||||||
|
#define GET_TEMPLATE_NAME(T) (#T)
|
||||||
|
|
||||||
|
// vector types need of special handling
|
||||||
|
if constexpr (std::is_same_v<T, glm::vec4>) {
|
||||||
|
if (!typeCheck<T> (value)) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return aToVector4 (*value);
|
||||||
|
} else if constexpr (std::is_same_v<T, glm::vec3>) {
|
||||||
|
if (!typeCheck<T> (value)) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return aToVector3 (*value);
|
||||||
|
} else if constexpr (std::is_same_v<T, glm::vec2>) {
|
||||||
|
if (!typeCheck<T> (value)) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return aToVector2 (*value);
|
||||||
|
} else if constexpr (std::is_same_v<T, glm::ivec4>) {
|
||||||
|
if (!typeCheck<T> (value)) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return aToVector4i (*value);
|
||||||
|
} else if constexpr (std::is_same_v<T, glm::ivec3>) {
|
||||||
|
if (!typeCheck<T> (value)) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return aToVector3i (*value);
|
||||||
|
} else if constexpr (std::is_same_v<T, glm::ivec2>) {
|
||||||
|
if (!typeCheck<T> (value)) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return aToVector2i (*value);
|
||||||
|
} else if (typeCheck<T> (value)) {
|
||||||
|
return *value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultValue;
|
||||||
|
#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 <typename T> const T Core::jsonFindDefault (
|
||||||
|
const nlohmann::json& data, const char* key, const T defaultValue
|
||||||
|
) {
|
||||||
const auto value = data.find (key);
|
const auto value = data.find (key);
|
||||||
|
|
||||||
if (value == data.end () || value->type () == nlohmann::detail::value_t::null)
|
if (value == data.end () || value->type () == nlohmann::detail::value_t::null)
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
|
|
||||||
// type checks
|
|
||||||
if ((std::is_same_v<T, float> || std::is_same_v<T, double>) ) {
|
#define GET_TEMPLATE_NAME(T) (#T)
|
||||||
if (value->type () != nlohmann::detail::value_t::number_float &&
|
|
||||||
value->type () != nlohmann::detail::value_t::number_integer &&
|
// vector types need of special handling
|
||||||
value->type () != nlohmann::detail::value_t::number_unsigned) {
|
if constexpr (std::is_same_v<T, glm::vec4>) {
|
||||||
sLog.error (key, " is not of type double or integer, returning default value");
|
if (!typeCheck<T> (value)) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
} else if (std::is_same_v<T, std::string> && value->type () != nlohmann::detail::value_t::string) {
|
|
||||||
sLog.error (key, " is not of type string, returning default value");
|
return aToVector4 (*value);
|
||||||
return defaultValue;
|
} else if constexpr (std::is_same_v<T, glm::vec3>) {
|
||||||
} else if (std::is_same_v<T, bool> && value->type () != nlohmann::detail::value_t::boolean) {
|
if (!typeCheck<T> (value)) {
|
||||||
sLog.error (key, " is not of type boolean, returning default value");
|
return defaultValue;
|
||||||
return defaultValue;
|
}
|
||||||
|
|
||||||
|
return aToVector3 (*value);
|
||||||
|
} else if constexpr (std::is_same_v<T, glm::vec2>) {
|
||||||
|
if (!typeCheck<T> (value)) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return aToVector2 (*value);
|
||||||
|
} else if constexpr (std::is_same_v<T, glm::ivec4>) {
|
||||||
|
if (!typeCheck<T> (value)) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return aToVector4i (*value);
|
||||||
|
} else if constexpr (std::is_same_v<T, glm::ivec3>) {
|
||||||
|
if (!typeCheck<T> (value)) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return aToVector3i (*value);
|
||||||
|
} else if constexpr (std::is_same_v<T, glm::ivec2>) {
|
||||||
|
if (!typeCheck<T> (value)) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return aToVector2i (*value);
|
||||||
|
} else if (typeCheck<T> (value)) {
|
||||||
|
return *value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: SUPPORT INTEGERS AND OTHER TYPES
|
return defaultValue;
|
||||||
|
#undef GET_TEMPLATE_NAME
|
||||||
return *value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template bool Core::jsonFindDefault (nlohmann::json& data, const char* key, bool defaultValue);
|
template const bool Core::jsonFindDefault (const nlohmann::json& data, const char* key, const bool defaultValue);
|
||||||
template std::string Core::jsonFindDefault (nlohmann::json& data, const char* key, std::string defaultValue);
|
template const std::string Core::jsonFindDefault (const nlohmann::json& data, const char* key, const std::string defaultValue);
|
||||||
template int16_t Core::jsonFindDefault (nlohmann::json& data, const char* key, int16_t defaultValue);
|
template const int16_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const int16_t defaultValue);
|
||||||
template uint16_t Core::jsonFindDefault (nlohmann::json& data, const char* key, uint16_t defaultValue);
|
template const uint16_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const uint16_t defaultValue);
|
||||||
template int32_t Core::jsonFindDefault (nlohmann::json& data, const char* key, int32_t defaultValue);
|
template const int32_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const int32_t defaultValue);
|
||||||
template uint32_t Core::jsonFindDefault (nlohmann::json& data, const char* key, uint32_t defaultValue);
|
template const uint32_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const uint32_t defaultValue);
|
||||||
template int64_t Core::jsonFindDefault (nlohmann::json& data, const char* key, int64_t defaultValue);
|
template const int64_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const int64_t defaultValue);
|
||||||
template uint64_t Core::jsonFindDefault (nlohmann::json& data, const char* key, uint64_t defaultValue);
|
template const uint64_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const uint64_t defaultValue);
|
||||||
template float Core::jsonFindDefault (nlohmann::json& data, const char* key, float defaultValue);
|
template const float Core::jsonFindDefault (const nlohmann::json& data, const char* key, const float defaultValue);
|
||||||
template double Core::jsonFindDefault (nlohmann::json& data, const char* key, double defaultValue);
|
template const double Core::jsonFindDefault (const nlohmann::json& data, const char* key, const double defaultValue);
|
||||||
|
template const glm::vec2 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::vec2 defaultValue);
|
||||||
|
template const glm::vec3 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::vec3 defaultValue);
|
||||||
|
template const glm::vec4 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::vec4 defaultValue);
|
||||||
|
template const glm::ivec2 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::ivec2 defaultValue);
|
||||||
|
template const glm::ivec3 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::ivec3 defaultValue);
|
||||||
|
template const glm::ivec4 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::ivec4 defaultValue);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> const T* Core::jsonFindUserConfig (
|
||||||
T* Core::jsonFindUserConfig (nlohmann::json& data, const char* key, typename T::data_type defaultValue) {
|
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 <typename T> const T* Core::jsonFindUserConfig (
|
||||||
|
const nlohmann::json& data, const char* key, typename T::data_type defaultValue
|
||||||
|
) {
|
||||||
const auto it = data.find (key);
|
const auto it = data.find (key);
|
||||||
|
|
||||||
if (it == data.end () || it->type () == nlohmann::detail::value_t::null)
|
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);
|
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);
|
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);
|
CUserSettingVector3::data_type defaultValue);
|
||||||
template CUserSettingFloat* Core::jsonFindUserConfig (nlohmann::json& data, const char* key,
|
template const CUserSettingFloat* Core::jsonFindUserConfig (const nlohmann::json& data, const char* key,
|
||||||
CUserSettingFloat::data_type defaultValue);
|
CUserSettingFloat::data_type defaultValue);
|
||||||
|
@ -15,15 +15,34 @@ glm::vec4 aToVector4 (const std::string& str);
|
|||||||
glm::vec3 aToVector3 (const std::string& str);
|
glm::vec3 aToVector3 (const std::string& str);
|
||||||
glm::vec2 aToVector2 (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 char* str);
|
||||||
glm::vec3 aToColorf (const std::string& str);
|
glm::vec3 aToColorf (const std::string& str);
|
||||||
|
|
||||||
glm::ivec3 aToColori (const char* str);
|
glm::ivec3 aToColori (const char* str);
|
||||||
glm::ivec3 aToColori (const std::string& str);
|
glm::ivec3 aToColori (const std::string& str);
|
||||||
|
|
||||||
nlohmann::json::iterator jsonFindRequired (nlohmann::json& data, const char* key, const char* notFoundMsg);
|
template <typename T> const T jsonFindRequired (
|
||||||
nlohmann::json::iterator jsonFindRequired (const nlohmann::json::iterator& data, const char* key,
|
const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
||||||
const char* notFoundMsg);
|
template <typename T> const T jsonFindRequired (
|
||||||
template <typename T> T jsonFindDefault (nlohmann::json& data, const char* key, T defaultValue);
|
const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
||||||
template <typename T> T* jsonFindUserConfig (nlohmann::json& data, const char* key, typename T::data_type defaultValue);
|
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 <typename T> const T jsonFindDefault (
|
||||||
|
const nlohmann::json::const_iterator& data, const char* key, const T defaultValue);
|
||||||
|
template <typename T> const T jsonFindDefault (
|
||||||
|
const nlohmann::json& data, const char* key, const T defaultValue);
|
||||||
|
template <typename T> const T* jsonFindUserConfig (
|
||||||
|
const nlohmann::json::const_iterator& data, const char* key, typename T::data_type defaultValue);
|
||||||
|
template <typename T> const T* jsonFindUserConfig (
|
||||||
|
const nlohmann::json& data, const char* key, typename T::data_type defaultValue);
|
||||||
} // namespace WallpaperEngine::Core
|
} // namespace WallpaperEngine::Core
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#include "CEffect.h"
|
#include "CEffect.h"
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/CProject.h"
|
#include "WallpaperEngine/Core/CProject.h"
|
||||||
#include "WallpaperEngine/Core/Objects/CImage.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/CShaderConstant.h"
|
||||||
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h"
|
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h"
|
||||||
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.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::Objects;
|
||||||
using namespace WallpaperEngine::Core::UserSettings;
|
using namespace WallpaperEngine::Core::UserSettings;
|
||||||
|
|
||||||
CEffect::CEffect (std::string name, std::string description, std::string group, std::string preview, CObject* object,
|
CEffect::CEffect (
|
||||||
CUserSettingBoolean* visible) :
|
std::string name, std::string description, std::string group, std::string preview, const CProject& project,
|
||||||
m_name (std::move (name)),
|
const CUserSettingBoolean* visible, std::vector<std::string> dependencies, std::vector<const Effects::CFBO*> fbos,
|
||||||
m_description (std::move (description)),
|
std::vector<const Images::CMaterial*> materials
|
||||||
m_group (std::move (group)),
|
) :
|
||||||
m_preview (std::move (preview)),
|
m_name (name),
|
||||||
m_object (object),
|
m_description (description),
|
||||||
m_visible (visible) {}
|
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) {
|
const CEffect* CEffect::fromJSON (
|
||||||
auto file_it = jsonFindRequired (data, "file", "Object effect must have a file");
|
const json& data, const CUserSettingBoolean* visible, const CProject& project, const Images::CMaterial* material,
|
||||||
auto effectpasses_it = data.find ("passes");
|
const CContainer* container
|
||||||
|
) {
|
||||||
|
const auto file = jsonFindRequired <std::string> (data, "file", "Object effect must have a file");
|
||||||
|
const auto effectpasses_it = data.find ("passes");
|
||||||
|
|
||||||
json content = json::parse (container->readFileAsString(file_it->get<std::string> ()));
|
json content = json::parse (container->readFileAsString(file));
|
||||||
|
|
||||||
auto name_it = jsonFindRequired (content, "name", "Effect must have a name");
|
const auto effectName = jsonFindRequired <std::string> (content, "name", "Effect must have a name");
|
||||||
auto description = jsonFindDefault<std::string> (content, "description", "");
|
const auto passes_it = jsonFindRequired (content, "passes", "Effect must have a pass list");
|
||||||
auto group_it = jsonFindRequired (content, "group", "Effect must have a group");
|
const auto fbos_it = content.find ("fbos");
|
||||||
auto preview = jsonFindDefault<std::string> (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");
|
|
||||||
|
|
||||||
auto* effect = new CEffect (*name_it, description, *group_it, preview, object, visible);
|
// info to override in the pass information, used by material generation
|
||||||
|
std::map<int, Images::CMaterial::OverrideInfo> overrides;
|
||||||
CEffect::materialsFromJSON (passes_it, effect, container);
|
std::vector<const Effects::CFBO*> fbos;
|
||||||
CEffect::dependencyFromJSON (dependencies_it, effect);
|
|
||||||
|
|
||||||
if (fbos_it != content.end ())
|
if (fbos_it != content.end ())
|
||||||
CEffect::fbosFromJSON (fbos_it, effect);
|
fbos = CEffect::fbosFromJSON (fbos_it);
|
||||||
|
|
||||||
if (effectpasses_it != data.end ()) {
|
if (effectpasses_it != data.end ()) {
|
||||||
auto cur = effectpasses_it->begin ();
|
overrides = overridesFromJSON (effectpasses_it, material);
|
||||||
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<std::string>::size_type textureNumber = 0;
|
|
||||||
|
|
||||||
for (const auto& texturesCur : (*textures_it)) {
|
|
||||||
std::string texture;
|
|
||||||
|
|
||||||
if (texturesCur.is_null ()) {
|
|
||||||
if (textureNumber == 0) {
|
|
||||||
auto* image = object->as<CImage> ();
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return effect;
|
return new CEffect (
|
||||||
|
effectName,
|
||||||
|
jsonFindDefault<std::string> (content, "description", ""),
|
||||||
|
jsonFindRequired <std::string> (content, "group", "Effect must have a group"),
|
||||||
|
jsonFindDefault<std::string> (content, "preview", ""),
|
||||||
|
project,
|
||||||
|
visible,
|
||||||
|
dependenciesFromJSON (jsonFindRequired (content, "dependencies", "")),
|
||||||
|
fbos,
|
||||||
|
materialsFromJSON (passes_it, effectName, container, overrides)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CEffect::combosFromJSON (const json::const_iterator& combos_it, Core::Objects::Images::Materials::CPass* pass) {
|
std::map<std::string, int> CEffect::combosFromJSON (const json::const_iterator& combos_it) {
|
||||||
|
std::map<std::string, int> combos;
|
||||||
|
|
||||||
for (const auto& cur : combos_it->items ())
|
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,
|
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> CEffect::constantsFromJSON (
|
||||||
Core::Objects::Images::Materials::CPass* pass) {
|
const json::const_iterator& constants_it
|
||||||
|
) {
|
||||||
|
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants;
|
||||||
|
|
||||||
for (auto& cur : constants_it->items ()) {
|
for (auto& cur : constants_it->items ()) {
|
||||||
auto val = cur.value ();
|
auto val = cur.value ();
|
||||||
|
|
||||||
@ -152,77 +115,154 @@ void CEffect::constantsFromJSON (const json::const_iterator& constants_it,
|
|||||||
sLog.exception ("unknown shader constant type ", val);
|
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<const Effects::CFBO*> CEffect::fbosFromJSON (const json::const_iterator& fbos_it) {
|
||||||
|
std::vector<const Effects::CFBO*> fbos;
|
||||||
|
|
||||||
for (const auto& cur : (*fbos_it))
|
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<std::string> CEffect::dependenciesFromJSON (const json::const_iterator& dependencies_it) {
|
||||||
|
std::vector<std::string> dependencies;
|
||||||
|
|
||||||
for (const auto& cur : (*dependencies_it))
|
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<const Images::CMaterial*> CEffect::materialsFromJSON (
|
||||||
|
const json::const_iterator& passes_it, std::string name, const CContainer* container,
|
||||||
|
std::map<int, Images::CMaterial::OverrideInfo> overrides
|
||||||
|
) {
|
||||||
|
std::vector<const Images::CMaterial*> materials;
|
||||||
|
|
||||||
|
int materialNumber = -1;
|
||||||
for (const auto& cur : (*passes_it)) {
|
for (const auto& cur : (*passes_it)) {
|
||||||
auto materialfile = cur.find ("material");
|
++materialNumber;
|
||||||
auto target = cur.find ("target");
|
const auto materialfile = cur.find ("material");
|
||||||
auto bind = cur.find ("bind");
|
const auto target = cur.find ("target");
|
||||||
|
const auto bind_it = cur.find ("bind");
|
||||||
|
|
||||||
if (materialfile == cur.end ())
|
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<int, const Effects::CBind*> textureBindings;
|
||||||
|
|
||||||
if (target == cur.end ())
|
if (bind_it != cur.end ()) {
|
||||||
material = Images::CMaterial::fromFile (materialfile->get<std::string> (), container);
|
for (const auto& bindCur : (*bind_it)) {
|
||||||
else
|
const auto* bind = Effects::CBind::fromJSON (bindCur);
|
||||||
material = Images::CMaterial::fromFile (materialfile->get<std::string> (), *target, container);
|
textureBindings.insert (std::pair (bind->getIndex (), bind));
|
||||||
|
}
|
||||||
if (bind != cur.end ()) {
|
|
||||||
for (const auto& bindCur : (*bind))
|
|
||||||
material->insertTextureBind (Effects::CBind::fromJSON (bindCur));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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<std::string> (), container, textureBindings, overrideInfo);
|
||||||
|
else
|
||||||
|
material = Images::CMaterial::fromFile (materialfile->get<std::string> (), *target, container, textureBindings, overrideInfo);
|
||||||
|
|
||||||
|
materials.push_back (material);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return materials;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<int, Images::CMaterial::OverrideInfo> CEffect::overridesFromJSON (
|
||||||
|
const json::const_iterator& passes_it, const Images::CMaterial* material
|
||||||
|
) {
|
||||||
|
std::map<int, Images::CMaterial::OverrideInfo> result;
|
||||||
|
|
||||||
|
int materialNumber = -1;
|
||||||
|
for (const auto& cur : (*passes_it)) {
|
||||||
|
++materialNumber;
|
||||||
|
auto constants_it = cur.find ("constantshadervalues");
|
||||||
|
auto combos_it = cur.find ("combos");
|
||||||
|
auto textures_it = cur.find ("textures");
|
||||||
|
Images::CMaterial::OverrideInfo override;
|
||||||
|
int textureNumber = -1;
|
||||||
|
|
||||||
|
if (combos_it != cur.end ()) {
|
||||||
|
override.combos = CEffect::combosFromJSON (combos_it);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (constants_it != cur.end ()) {
|
||||||
|
override.constants = CEffect::constantsFromJSON (constants_it);
|
||||||
|
}
|
||||||
|
|
||||||
|
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<std::string>& CEffect::getDependencies () const {
|
const std::vector<std::string>& CEffect::getDependencies () const {
|
||||||
return this->m_dependencies;
|
return this->m_dependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<Images::CMaterial*>& CEffect::getMaterials () const {
|
const std::vector<const Images::CMaterial*>& CEffect::getMaterials () const {
|
||||||
return this->m_materials;
|
return this->m_materials;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<Effects::CFBO*>& CEffect::getFbos () const {
|
const std::vector<const Effects::CFBO*>& CEffect::getFbos () const {
|
||||||
return this->m_fbos;
|
return this->m_fbos;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CEffect::isVisible () const {
|
const Core::CProject& CEffect::getProject () const {
|
||||||
return this->m_visible->processValue (this->m_object->getScene ()->getProject ().getProperties ());
|
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)
|
for (const auto& cur : this->m_fbos)
|
||||||
if (cur->getName () == name)
|
if (cur->getName () == name)
|
||||||
return cur;
|
return cur;
|
||||||
|
|
||||||
sLog.exception ("cannot find fbo ", name);
|
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);
|
|
||||||
}
|
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
namespace WallpaperEngine::Core {
|
namespace WallpaperEngine::Core {
|
||||||
class CObject;
|
class CObject;
|
||||||
|
class CProject;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::UserSettings {
|
namespace WallpaperEngine::Core::UserSettings {
|
||||||
@ -25,11 +26,14 @@ using namespace WallpaperEngine::Core::UserSettings;
|
|||||||
*/
|
*/
|
||||||
class CEffect {
|
class CEffect {
|
||||||
public:
|
public:
|
||||||
CEffect (std::string name, std::string description, std::string group, std::string preview, CObject* object,
|
CEffect (
|
||||||
CUserSettingBoolean* visible);
|
std::string name, std::string description, std::string group, std::string preview, const CProject& project,
|
||||||
|
const CUserSettingBoolean* visible, std::vector<std::string> dependencies,
|
||||||
|
std::vector<const Effects::CFBO*> fbos, std::vector<const Images::CMaterial*> materials);
|
||||||
|
|
||||||
static CEffect* fromJSON (json data, UserSettings::CUserSettingBoolean* visible, CObject* object,
|
static const CEffect* fromJSON (
|
||||||
CContainer* container);
|
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
|
* @return List of dependencies for the effect to work
|
||||||
@ -38,15 +42,19 @@ class CEffect {
|
|||||||
/**
|
/**
|
||||||
* @return List of materials the effect applies
|
* @return List of materials the effect applies
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const std::vector<Images::CMaterial*>& getMaterials () const;
|
[[nodiscard]] const std::vector<const Images::CMaterial*>& getMaterials () const;
|
||||||
/**
|
/**
|
||||||
* @return The list of FBOs to be used for this effect
|
* @return The list of FBOs to be used for this effect
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const std::vector<Effects::CFBO*>& getFbos () const;
|
[[nodiscard]] const std::vector<const Effects::CFBO*>& getFbos () const;
|
||||||
/**
|
/**
|
||||||
* @return If the effect is visible or not
|
* @return If the effect is visible or not
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] bool isVisible () const;
|
[[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
|
* Searches the FBOs list for the given FBO
|
||||||
*
|
*
|
||||||
@ -54,39 +62,39 @@ class CEffect {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Effects::CFBO* findFBO (const std::string& name);
|
const Effects::CFBO* findFBO (const std::string& name);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void constantsFromJSON (const json::const_iterator& constants_it,
|
static std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constantsFromJSON (
|
||||||
Core::Objects::Images::Materials::CPass* pass);
|
const json::const_iterator& constants_it);
|
||||||
static void combosFromJSON (const json::const_iterator& combos_it, Core::Objects::Images::Materials::CPass* pass);
|
static std::map<std::string, int> combosFromJSON (const json::const_iterator& combos_it);
|
||||||
static void fbosFromJSON (const json::const_iterator& fbos_it, CEffect* effect);
|
static std::vector<const Effects::CFBO*> fbosFromJSON (const json::const_iterator& fbos_it);
|
||||||
static void dependencyFromJSON (const json::const_iterator& dependencies_it, CEffect* effect);
|
static std::vector<std::string> dependenciesFromJSON (const json::const_iterator& dependencies_it);
|
||||||
static void materialsFromJSON (const json::const_iterator& passes_it, CEffect* effect, CContainer* container);
|
static std::vector<const Images::CMaterial*> materialsFromJSON (
|
||||||
|
const json::const_iterator& passes_it, std::string name, const CContainer* container,
|
||||||
void insertDependency (const std::string& dep);
|
std::map<int, Images::CMaterial::OverrideInfo>);
|
||||||
void insertMaterial (Images::CMaterial* material);
|
static std::map<int, Images::CMaterial::OverrideInfo> overridesFromJSON (
|
||||||
void insertFBO (Effects::CFBO* fbo);
|
const json::const_iterator& passes_it, const Images::CMaterial* material);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Effect's name */
|
/** Effect's name */
|
||||||
std::string m_name;
|
const std::string m_name;
|
||||||
/** Effect's description used in the UI */
|
/** Effect's description used in the UI */
|
||||||
std::string m_description;
|
const std::string m_description;
|
||||||
/** Effect's group used in the UI */
|
/** 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 */
|
/** A project that previews the given effect, used in the UI */
|
||||||
std::string m_preview;
|
const std::string m_preview;
|
||||||
/** The object the effect applies to */
|
|
||||||
CObject* m_object;
|
|
||||||
/** If the effect is visible or not */
|
/** 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 */
|
/** List of dependencies for the effect */
|
||||||
std::vector<std::string> m_dependencies;
|
const std::vector<std::string> m_dependencies;
|
||||||
/** List of materials the effect applies */
|
/** List of materials the effect applies */
|
||||||
std::vector<Images::CMaterial*> m_materials;
|
const std::vector<const Images::CMaterial*> m_materials;
|
||||||
/** List of FBOs required for this effect */
|
/** List of FBOs required for this effect */
|
||||||
std::vector<Effects::CFBO*> m_fbos;
|
const std::vector<const Effects::CFBO*> m_fbos;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects
|
} // namespace WallpaperEngine::Core::Objects
|
||||||
|
@ -5,53 +5,83 @@
|
|||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
|
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h"
|
#include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h"
|
||||||
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
|
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects;
|
using namespace WallpaperEngine::Core::Objects;
|
||||||
using namespace WallpaperEngine::Core::UserSettings;
|
using namespace WallpaperEngine::Core::UserSettings;
|
||||||
|
|
||||||
CImage::CImage (Wallpapers::CScene* scene, Images::CMaterial* material, CUserSettingBoolean* visible, int id, std::string name,
|
CImage::CImage (
|
||||||
CUserSettingVector3* origin, CUserSettingVector3* scale, const glm::vec3& angles, const glm::vec2& size,
|
const Wallpapers::CScene* scene, const Images::CMaterial* material, const CUserSettingBoolean* visible, int id,
|
||||||
std::string alignment, CUserSettingVector3* color, CUserSettingFloat* alpha, float brightness,
|
std::string name, const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles,
|
||||||
uint32_t colorBlendMode, const glm::vec2& parallaxDepth, bool fullscreen, bool passthrough,
|
glm::vec2 size, std::string alignment, const CUserSettingVector3* color, const CUserSettingFloat* alpha,
|
||||||
bool autosize) :
|
float brightness, uint32_t colorBlendMode, glm::vec2 parallaxDepth, bool fullscreen, bool passthrough,
|
||||||
CObject (scene, visible, id, std::move (name), Type, origin, scale, angles),
|
bool autosize, std::vector<const Objects::CEffect*> effects, std::vector<int> dependencies
|
||||||
|
) :
|
||||||
|
CObject (scene, visible, id, name, Type, origin, scale, angles, dependencies),
|
||||||
m_size (size),
|
m_size (size),
|
||||||
m_parallaxDepth (parallaxDepth),
|
m_parallaxDepth (parallaxDepth),
|
||||||
m_material (material),
|
m_material (material),
|
||||||
m_alignment (std::move (alignment)),
|
m_alignment (alignment),
|
||||||
m_alpha (alpha),
|
m_alpha (alpha),
|
||||||
m_brightness (brightness),
|
m_brightness (brightness),
|
||||||
m_color (color),
|
m_color (color),
|
||||||
m_colorBlendMode (colorBlendMode),
|
m_colorBlendMode (colorBlendMode),
|
||||||
m_fullscreen (fullscreen),
|
m_fullscreen (fullscreen),
|
||||||
m_passthrough (passthrough),
|
m_passthrough (passthrough),
|
||||||
m_autosize (autosize) {}
|
m_autosize (autosize),
|
||||||
|
m_effects (effects) {}
|
||||||
|
|
||||||
WallpaperEngine::Core::CObject* CImage::fromJSON (Wallpapers::CScene* scene, json data, CContainer* container,
|
const WallpaperEngine::Core::CObject* CImage::fromJSON (
|
||||||
CUserSettingBoolean* visible, int id, std::string name,
|
const Wallpapers::CScene* scene, const json& data, const CContainer* container,
|
||||||
CUserSettingVector3* origin, CUserSettingVector3* scale,
|
const CUserSettingBoolean* visible, int id, std::string name, const CUserSettingVector3* origin,
|
||||||
const glm::vec3& angles) {
|
const CUserSettingVector3* scale, glm::vec3 angles, const json::const_iterator& effects_it,
|
||||||
const auto image_it = data.find ("image");
|
std::vector<int> dependencies
|
||||||
const auto size_val = jsonFindDefault<std::string> (data, "size", "0.0 0.0"); // this one might need some adjustment
|
) {
|
||||||
const auto alignment = jsonFindDefault<std::string> (data, "alignment", "center");
|
const auto image = jsonFindRequired <std::string>(data, "image", "Image must have an image");
|
||||||
const auto alpha = jsonFindUserConfig<CUserSettingFloat> (data, "alpha", 1.0);
|
std::vector<const Objects::CEffect*> effects;
|
||||||
const auto color = jsonFindUserConfig<CUserSettingVector3> (data, "color", {1, 1, 1});
|
json content = json::parse (container->readFileAsString (image));
|
||||||
const auto brightness_val = jsonFindDefault<float> (data, "brightness", 1.0);
|
|
||||||
const auto colorBlendMode_val = jsonFindDefault<uint32_t> (data, "colorBlendMode", 0);
|
|
||||||
const auto parallaxDepth_val = jsonFindDefault<std::string> (data, "parallaxDepth", "0 0");
|
|
||||||
|
|
||||||
json content = json::parse (container->readFileAsString (image_it->get<std::string> ()));
|
const auto material = Images::CMaterial::fromFile (
|
||||||
|
jsonFindRequired<std::string> (content, "material", "Image must have a material"),
|
||||||
|
container
|
||||||
|
);
|
||||||
|
|
||||||
const auto material_it = jsonFindRequired (content, "material", "Image must have a material");
|
if (effects_it != data.end () && effects_it->is_array ()) {
|
||||||
const auto fullscreen = jsonFindDefault<bool> (content, "fullscreen", false);
|
for (auto& cur : *effects_it) {
|
||||||
const auto passthrough = jsonFindDefault<bool> (content, "passthrough", false);
|
const auto effectVisible = jsonFindUserConfig<CUserSettingBoolean> (cur, "visible", true);
|
||||||
const auto autosize = jsonFindDefault<bool> (content, "autosize", false);
|
|
||||||
|
|
||||||
return new CImage (scene, Images::CMaterial::fromFile (material_it->get<std::string> (), container), visible, id,
|
if (!effectVisible->processValue (scene->getProject ().getProperties ()))
|
||||||
std::move (name), origin, scale, angles, WallpaperEngine::Core::aToVector2 (size_val), alignment,
|
continue;
|
||||||
color, alpha, brightness_val, colorBlendMode_val,
|
|
||||||
WallpaperEngine::Core::aToVector2 (parallaxDepth_val), fullscreen, passthrough, autosize);
|
effects.push_back (
|
||||||
|
Objects::CEffect::fromJSON (
|
||||||
|
cur, effectVisible, scene->getProject (), material, container
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CImage (
|
||||||
|
scene,
|
||||||
|
material,
|
||||||
|
visible,
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
origin,
|
||||||
|
scale,
|
||||||
|
angles,
|
||||||
|
jsonFindDefault<glm::vec2> (data, "size", glm::vec2 (0.0, 0.0)),
|
||||||
|
jsonFindDefault<std::string> (data, "alignment", "center"),
|
||||||
|
jsonFindUserConfig<CUserSettingVector3> (data, "color", {1, 1, 1}),
|
||||||
|
jsonFindUserConfig<CUserSettingFloat> (data, "alpha", 1.0),
|
||||||
|
jsonFindDefault<float> (data, "brightness", 1.0),
|
||||||
|
jsonFindDefault<uint32_t> (data, "colorBlendMode", 0),
|
||||||
|
jsonFindDefault<glm::vec2> (data, "parallaxDepth", glm::vec2 (0.0, 0.0)),
|
||||||
|
jsonFindDefault<bool> (content, "fullscreen", false),
|
||||||
|
jsonFindDefault<bool> (content, "passthrough", false),
|
||||||
|
jsonFindDefault<bool> (content, "autosize", false),
|
||||||
|
effects,
|
||||||
|
dependencies
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Images::CMaterial* CImage::getMaterial () const {
|
const Images::CMaterial* CImage::getMaterial () const {
|
||||||
@ -70,7 +100,7 @@ float CImage::getAlpha () const {
|
|||||||
return this->m_alpha->processValue (this->getScene ()->getProject ().getProperties ());
|
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 ());
|
return this->m_color->processValue (this->getScene ()->getProject ().getProperties ());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,4 +128,8 @@ bool CImage::isAutosize () const {
|
|||||||
return this->m_autosize;
|
return this->m_autosize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::vector<const CEffect*>& CImage::getEffects () const {
|
||||||
|
return this->m_effects;
|
||||||
|
}
|
||||||
|
|
||||||
const std::string CImage::Type = "image";
|
const std::string CImage::Type = "image";
|
@ -27,9 +27,11 @@ class CImage : public CObject {
|
|||||||
friend class CObject;
|
friend class CObject;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static CObject* fromJSON (Wallpapers::CScene* scene, json data, CContainer* container, CUserSettingBoolean* visible,
|
static const CObject* fromJSON (
|
||||||
int id, std::string name, CUserSettingVector3* origin, CUserSettingVector3* scale,
|
const Wallpapers::CScene* scene, const json& data, const CContainer* container,
|
||||||
const glm::vec3& angles);
|
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<int> dependencies);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The base material to use for the image
|
* @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
|
* @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
|
* @return The brightness to use for the image
|
||||||
*/
|
*/
|
||||||
@ -75,12 +77,18 @@ class CImage : public CObject {
|
|||||||
* @return If the image is autosized or not
|
* @return If the image is autosized or not
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] bool isAutosize () const;
|
[[nodiscard]] bool isAutosize () const;
|
||||||
|
/**
|
||||||
|
* @return All of the effects applied to this image
|
||||||
|
*/
|
||||||
|
[[nodiscard]] const std::vector<const Objects::CEffect*>& getEffects () const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CImage (Wallpapers::CScene* scene, Images::CMaterial* material, CUserSettingBoolean* visible, int id, std::string name,
|
CImage (
|
||||||
CUserSettingVector3* origin, CUserSettingVector3* scale, const glm::vec3& angles, const glm::vec2& size,
|
const Wallpapers::CScene* scene, const Images::CMaterial* material, const CUserSettingBoolean* visible, int id,
|
||||||
std::string alignment, CUserSettingVector3* color, CUserSettingFloat* alpha, float brightness,
|
std::string name, const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles,
|
||||||
uint32_t colorBlendMode, const glm::vec2& parallaxDepth, bool fullscreen, bool passthrough, bool autosize);
|
glm::vec2 size, std::string alignment, const CUserSettingVector3* color, const CUserSettingFloat* alpha,
|
||||||
|
float brightness, uint32_t colorBlendMode, glm::vec2 parallaxDepth, bool fullscreen, bool passthrough,
|
||||||
|
bool autosize, std::vector<const Objects::CEffect*> effects, std::vector<int> dependencies);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type value used to differentiate the different types of objects in a background
|
* Type value used to differentiate the different types of objects in a background
|
||||||
@ -89,21 +97,23 @@ class CImage : public CObject {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
/** The image's size */
|
/** The image's size */
|
||||||
glm::vec2 m_size;
|
const glm::vec2 m_size;
|
||||||
/** Parallax depth */
|
/** Parallax depth */
|
||||||
const glm::vec2 m_parallaxDepth;
|
const glm::vec2 m_parallaxDepth;
|
||||||
/** Base material for the image */
|
/** 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 */
|
/** 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 */
|
/** The alpha value for the image */
|
||||||
CUserSettingFloat* m_alpha;
|
const CUserSettingFloat* m_alpha;
|
||||||
/** The brightness for the image */
|
/** The brightness for the image */
|
||||||
float m_brightness;
|
float m_brightness;
|
||||||
/** The color to use for the image */
|
/** 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 */
|
/** 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<const Objects::CEffect*> m_effects;
|
||||||
/** If the image is fullscreen or not */
|
/** If the image is fullscreen or not */
|
||||||
bool m_fullscreen;
|
bool m_fullscreen;
|
||||||
/** If the image is passthrough or not */
|
/** If the image is passthrough or not */
|
||||||
|
@ -1,61 +1,70 @@
|
|||||||
#include "CParticle.h"
|
#include "CParticle.h"
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects;
|
using namespace WallpaperEngine::Core::Objects;
|
||||||
|
|
||||||
CParticle* CParticle::fromFile (Wallpapers::CScene* scene, const std::string& filename, CContainer* container,
|
const CParticle* CParticle::fromFile (
|
||||||
CUserSettingBoolean* visible, int id, std::string name, CUserSettingVector3* origin,
|
const Wallpapers::CScene* scene, std::string filename, const CContainer* container,
|
||||||
CUserSettingVector3* scale) {
|
const CUserSettingBoolean* visible, int id, std::string name, const CUserSettingVector3* origin,
|
||||||
|
const CUserSettingVector3* scale, std::vector<int> dependencies
|
||||||
|
) {
|
||||||
json data = json::parse (container->readFileAsString (filename));
|
json data = json::parse (container->readFileAsString (filename));
|
||||||
const auto controlpoint_it = data.find ("controlpoint");
|
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 emitter_it = jsonFindRequired (data, "emitter", "Particles must have emitters");
|
||||||
const auto initializer_it = jsonFindRequired (data, "initializer", "Particles must have initializers");
|
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<const Particles::CControlPoint*> controlpoints;
|
||||||
|
std::vector<const Particles::CEmitter*> emitters;
|
||||||
|
std::vector<const Particles::CInitializer*> initializers;
|
||||||
|
|
||||||
if (controlpoint_it != data.end ())
|
if (controlpoint_it != data.end ())
|
||||||
for (const auto& cur : (*controlpoint_it))
|
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))
|
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))
|
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 <uint32_t> (data, "starttime", "Particles must have start time"),
|
||||||
|
jsonFindRequired <uint32_t> (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,
|
CParticle::CParticle (
|
||||||
std::string name, CUserSettingVector3* origin, CUserSettingVector3* scale) :
|
const Wallpapers::CScene* scene, uint32_t starttime, uint32_t maxcount, const CUserSettingBoolean* visible, int id,
|
||||||
CObject (scene, visible, id, std::move (name), Type, origin, scale, glm::vec3 ()),
|
const std::string& name, const CUserSettingVector3* origin, const CUserSettingVector3* scale,
|
||||||
|
const std::vector<const Particles::CControlPoint*>& controlpoints,
|
||||||
|
const std::vector<const Particles::CEmitter*>& emitters,
|
||||||
|
const std::vector<const Particles::CInitializer*>& initializers, std::vector<int> dependencies
|
||||||
|
) :
|
||||||
|
CObject (scene, visible, id, name, Type, origin, scale, glm::vec3 (), dependencies),
|
||||||
m_starttime (starttime),
|
m_starttime (starttime),
|
||||||
m_maxcount (maxcount) {}
|
m_maxcount (maxcount),
|
||||||
|
m_controlpoints (controlpoints),
|
||||||
|
m_emitters (emitters),
|
||||||
|
m_initializers (initializers) {}
|
||||||
|
|
||||||
const std::vector<Particles::CEmitter*>& CParticle::getEmitters () const {
|
const std::vector<const Particles::CEmitter*>& CParticle::getEmitters () const {
|
||||||
return this->m_emitters;
|
return this->m_emitters;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<Particles::CControlPoint*>& CParticle::getControlPoints () const {
|
const std::vector<const Particles::CControlPoint*>& CParticle::getControlPoints () const {
|
||||||
return this->m_controlpoints;
|
return this->m_controlpoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<Particles::CInitializer*>& CParticle::getInitializers () const {
|
const std::vector<const Particles::CInitializer*>& CParticle::getInitializers () const {
|
||||||
return this->m_initializers;
|
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";
|
const std::string CParticle::Type = "particle";
|
@ -17,39 +17,31 @@ class CParticle : public CObject {
|
|||||||
friend class CObject;
|
friend class CObject;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static CParticle* fromFile (Wallpapers::CScene* scene, const std::string& filename, CContainer* container,
|
static const CParticle* fromFile (
|
||||||
CUserSettingBoolean* visible, int id, std::string name,
|
const Wallpapers::CScene* scene, std::string filename, const CContainer* container,
|
||||||
CUserSettingVector3* origin, CUserSettingVector3* scale);
|
const CUserSettingBoolean* visible, int id, std::string name, const CUserSettingVector3* origin,
|
||||||
|
const CUserSettingVector3* scale, std::vector<int> dependencies);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The list of emitters for the particle system
|
* @return The list of emitters for the particle system
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const std::vector<Particles::CEmitter*>& getEmitters () const;
|
[[nodiscard]] const std::vector<const Particles::CEmitter*>& getEmitters () const;
|
||||||
/**
|
/**
|
||||||
* @return The list of control points for the particle system
|
* @return The list of control points for the particle system
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const std::vector<Particles::CControlPoint*>& getControlPoints () const;
|
[[nodiscard]] const std::vector<const Particles::CControlPoint*>& getControlPoints () const;
|
||||||
/**
|
/**
|
||||||
* @return The list of initializers for the particle system
|
* @return The list of initializers for the particle system
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const std::vector<Particles::CInitializer*>& getInitializers () const;
|
[[nodiscard]] const std::vector<const Particles::CInitializer*>& getInitializers () const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CParticle (Wallpapers::CScene* scene, uint32_t starttime, uint32_t maxcount, CUserSettingBoolean* visible, int id,
|
CParticle (
|
||||||
std::string name, CUserSettingVector3* origin, CUserSettingVector3* scale);
|
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<const Particles::CControlPoint*>& controlpoints,
|
||||||
* @param controlpoint The control point to add to the particle system
|
const std::vector<const Particles::CEmitter*>& emitters,
|
||||||
*/
|
const std::vector<const Particles::CInitializer*>& initializers, std::vector<int> dependencies);
|
||||||
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);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type value used to differentiate the different types of objects in a background
|
* Type value used to differentiate the different types of objects in a background
|
||||||
@ -58,14 +50,14 @@ class CParticle : public CObject {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
/** The time at which the particle system should start emitting */
|
/** 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 */
|
/** Maximum number of particles at the same time */
|
||||||
uint32_t m_maxcount;
|
const uint32_t m_maxcount;
|
||||||
/** List of control points */
|
/** List of control points */
|
||||||
std::vector<Particles::CControlPoint*> m_controlpoints;
|
const std::vector<const Particles::CControlPoint*> m_controlpoints;
|
||||||
/** List of emitters */
|
/** List of emitters */
|
||||||
std::vector<Particles::CEmitter*> m_emitters;
|
const std::vector<const Particles::CEmitter*> m_emitters;
|
||||||
/** List of initializers */
|
/** List of initializers */
|
||||||
std::vector<Particles::CInitializer*> m_initializers;
|
const std::vector<const Particles::CInitializer*> m_initializers;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects
|
} // namespace WallpaperEngine::Core::Objects
|
||||||
|
@ -4,35 +4,42 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects;
|
using namespace WallpaperEngine::Core::Objects;
|
||||||
|
|
||||||
CSound::CSound (Wallpapers::CScene* scene, CUserSettingBoolean* visible, int id, std::string name, CUserSettingVector3* origin,
|
CSound::CSound (
|
||||||
CUserSettingVector3* scale, const glm::vec3& angles, bool repeat) :
|
const Wallpapers::CScene* scene, const CUserSettingBoolean* visible, int id, std::string name,
|
||||||
CObject (scene, visible, id, std::move (name), Type, origin, scale, angles),
|
const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles, bool repeat,
|
||||||
m_repeat (repeat) {}
|
std::vector<std::string> sounds, std::vector<int> 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 WallpaperEngine::Core::CObject* CSound::fromJSON (
|
||||||
const std::string& name, CUserSettingVector3* origin,
|
const Wallpapers::CScene* scene, const json& data, const CUserSettingBoolean* visible, int id,
|
||||||
CUserSettingVector3* scale, const glm::vec3& angles) {
|
std::string name, const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles,
|
||||||
bool repeat = false;
|
std::vector<int> dependencies
|
||||||
|
) {
|
||||||
// TODO: PARSE AUDIO VOLUME
|
// TODO: PARSE AUDIO VOLUME
|
||||||
|
std::vector<std::string> sounds;
|
||||||
const auto sound_it = jsonFindRequired (data, "sound", "Sound information not present");
|
const auto sound_it = jsonFindRequired (data, "sound", "Sound information not present");
|
||||||
const auto playbackmode = jsonFindDefault<std::string> (data, "playbackmode", "");
|
|
||||||
|
|
||||||
if (playbackmode == "loop")
|
|
||||||
repeat = true;
|
|
||||||
|
|
||||||
if (!sound_it->is_array ())
|
if (!sound_it->is_array ())
|
||||||
sLog.exception ("Expected sound list on element ", name);
|
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))
|
for (const auto& cur : (*sound_it))
|
||||||
sound->insertSound (cur);
|
sounds.push_back (cur);
|
||||||
|
|
||||||
return sound;
|
return new CSound (
|
||||||
}
|
scene,
|
||||||
|
visible,
|
||||||
void CSound::insertSound (const std::string& filename) {
|
id,
|
||||||
this->m_sounds.push_back (filename);
|
name,
|
||||||
|
origin,
|
||||||
|
scale,
|
||||||
|
angles,
|
||||||
|
jsonFindDefault<std::string> (data, "playbackmode", "") == "loop",
|
||||||
|
sounds,
|
||||||
|
dependencies
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::string>& CSound::getSounds () const {
|
const std::vector<std::string>& CSound::getSounds () const {
|
||||||
|
@ -19,9 +19,10 @@ class CSound : public CObject {
|
|||||||
friend class CObject;
|
friend class CObject;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static CObject* fromJSON (Wallpapers::CScene* scene, json data, CUserSettingBoolean* visible, int id,
|
static const CObject* fromJSON (
|
||||||
const std::string& name, CUserSettingVector3* origin, CUserSettingVector3* scale,
|
const Wallpapers::CScene* scene, const json& data, const CUserSettingBoolean* visible,
|
||||||
const glm::vec3& angles);
|
int id, std::string name, const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles,
|
||||||
|
std::vector<int> dependencies);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The list of sounds to play
|
* @return The list of sounds to play
|
||||||
@ -33,13 +34,10 @@ class CSound : public CObject {
|
|||||||
[[nodiscard]] bool isRepeat () const;
|
[[nodiscard]] bool isRepeat () const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CSound (Wallpapers::CScene* scene, CUserSettingBoolean* visible, int id, std::string name, CUserSettingVector3* origin,
|
CSound (
|
||||||
CUserSettingVector3* scale, const glm::vec3& angles, bool repeat);
|
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<std::string> sounds, std::vector<int> dependencies);
|
||||||
* @param filename The sound to add
|
|
||||||
*/
|
|
||||||
void insertSound (const std::string& filename);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type value used to differentiate the different types of objects in a background
|
* Type value used to differentiate the different types of objects in a background
|
||||||
|
@ -4,13 +4,15 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Effects;
|
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 CBind* CBind::fromJSON (const json& data) {
|
||||||
const auto name_it = jsonFindRequired (data, "name", "bind must have texture name");
|
return new CBind (
|
||||||
const auto index_it = jsonFindRequired (data, "index", "bind must have index");
|
jsonFindRequired <std::string> (data, "name", "bind must have texture name"),
|
||||||
|
jsonFindRequired <uint32_t> (data, "index", "bind must have index")
|
||||||
return new CBind (*name_it, *index_it);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& CBind::getName () const {
|
const std::string& CBind::getName () const {
|
||||||
|
@ -20,9 +20,7 @@ class CBind {
|
|||||||
* @param data
|
* @param data
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static CBind* fromJSON (json data);
|
static const CBind* fromJSON (const json& data);
|
||||||
|
|
||||||
CBind (std::string name, uint32_t index);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The texture name, previous to use the one already specified by the object's passes
|
* @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;
|
[[nodiscard]] const uint32_t& getIndex () const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CBind (std::string name, uint32_t index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** The texture's name */
|
/** The texture's name */
|
||||||
std::string m_name;
|
const std::string m_name;
|
||||||
/** The texture index to replace */
|
/** The texture index to replace */
|
||||||
uint32_t m_index;
|
const uint32_t m_index;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects::Effects
|
} // namespace WallpaperEngine::Core::Objects::Effects
|
||||||
|
@ -6,16 +6,16 @@ using namespace WallpaperEngine::Core;
|
|||||||
using namespace WallpaperEngine::Core::Objects::Effects;
|
using namespace WallpaperEngine::Core::Objects::Effects;
|
||||||
|
|
||||||
CFBO::CFBO (std::string name, float scale, std::string format) :
|
CFBO::CFBO (std::string name, float scale, std::string format) :
|
||||||
m_name (std::move (name)),
|
m_name (name),
|
||||||
m_scale (scale),
|
m_scale (scale),
|
||||||
m_format (std::move (format)) {}
|
m_format (format) {}
|
||||||
|
|
||||||
CFBO* CFBO::fromJSON (json data) {
|
const CFBO* CFBO::fromJSON (const json& data) {
|
||||||
const auto name_it = jsonFindRequired (data, "name", "Name for an FBO is required");
|
return new CFBO (
|
||||||
const auto scale = jsonFindDefault<float> (data, "scale", 1.0);
|
jsonFindRequired <std::string> (data, "name", "Name for an FBO is required"),
|
||||||
const auto format = jsonFindDefault<std::string> (data, "format", "");
|
jsonFindDefault <float> (data, "scale", 1.0),
|
||||||
|
jsonFindDefault <std::string> (data, "format", "")
|
||||||
return new CFBO (*name_it, scale, format);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& CFBO::getName () const {
|
const std::string& CFBO::getName () const {
|
||||||
|
@ -15,9 +15,7 @@ using json = nlohmann::json;
|
|||||||
*/
|
*/
|
||||||
class CFBO {
|
class CFBO {
|
||||||
public:
|
public:
|
||||||
CFBO (std::string name, float scale, std::string format);
|
static const CFBO* fromJSON (const json& data);
|
||||||
|
|
||||||
static CFBO* fromJSON (json data);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The FBO name used to identify it in the background's files
|
* @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;
|
[[nodiscard]] const std::string& getFormat () const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CFBO (std::string name, float scale, std::string format);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** The name of the FBO */
|
/** The name of the FBO */
|
||||||
std::string m_name;
|
const std::string m_name;
|
||||||
/** The scale factor of the FBO */
|
/** The scale factor of the FBO */
|
||||||
float m_scale;
|
const float m_scale;
|
||||||
/** The FBO's format for the render */
|
/** The FBO's format for the render */
|
||||||
std::string m_format;
|
const std::string m_format;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects::Effects
|
} // namespace WallpaperEngine::Core::Objects::Effects
|
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
|
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 {
|
const std::string& CShaderConstant::getType () const {
|
||||||
return this->m_type;
|
return this->m_type;
|
||||||
|
@ -21,7 +21,7 @@ class CShaderConstant {
|
|||||||
return reinterpret_cast<T*> (this);
|
return reinterpret_cast<T*> (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> bool is () {
|
template <class T> bool is () const {
|
||||||
return this->m_type == T::Type;
|
return this->m_type == T::Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,6 +31,6 @@ class CShaderConstant {
|
|||||||
[[nodiscard]] const std::string& getType () const;
|
[[nodiscard]] const std::string& getType () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_type;
|
const std::string m_type;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects::Effects::Constants
|
} // namespace WallpaperEngine::Core::Objects::Effects::Constants
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
|
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;
|
return &this->m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ class CShaderConstantFloat : public CShaderConstant {
|
|||||||
/**
|
/**
|
||||||
* @return A pointer to the actual value of the constant
|
* @return A pointer to the actual value of the constant
|
||||||
*/
|
*/
|
||||||
float* getValue ();
|
[[nodiscard]] const float* getValue () const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type string indicator
|
* Type string indicator
|
||||||
@ -24,6 +24,6 @@ class CShaderConstantFloat : public CShaderConstant {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** The constant's value */
|
/** The constant's value */
|
||||||
float m_value;
|
const float m_value;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects::Effects::Constants
|
} // namespace WallpaperEngine::Core::Objects::Effects::Constants
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
|
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;
|
return &this->m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ class CShaderConstantInteger : public CShaderConstant {
|
|||||||
/**
|
/**
|
||||||
* @return A pointer to the actual value of the constant
|
* @return A pointer to the actual value of the constant
|
||||||
*/
|
*/
|
||||||
int32_t* getValue ();
|
[[nodiscard]] const int32_t* getValue () const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type string indicator
|
* Type string indicator
|
||||||
@ -24,6 +24,6 @@ class CShaderConstantInteger : public CShaderConstant {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** The constant's value */
|
/** The constant's value */
|
||||||
int32_t m_value;
|
const int32_t m_value;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects::Effects::Constants
|
} // namespace WallpaperEngine::Core::Objects::Effects::Constants
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
|
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;
|
return &this->m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ class CShaderConstantVector2 : public CShaderConstant {
|
|||||||
/**
|
/**
|
||||||
* @return A pointer to the actual value of the constant
|
* @return A pointer to the actual value of the constant
|
||||||
*/
|
*/
|
||||||
glm::vec2* getValue ();
|
[[nodiscard]] const glm::vec2* getValue () const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type string indicator
|
* Type string indicator
|
||||||
@ -26,6 +26,6 @@ class CShaderConstantVector2 : public CShaderConstant {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** The constant's value */
|
/** The constant's value */
|
||||||
glm::vec2 m_value;
|
const glm::vec2 m_value;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects::Effects::Constants
|
} // namespace WallpaperEngine::Core::Objects::Effects::Constants
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
|
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;
|
return &this->m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ class CShaderConstantVector3 : public CShaderConstant {
|
|||||||
/**
|
/**
|
||||||
* @return A pointer to the actual value of the constant
|
* @return A pointer to the actual value of the constant
|
||||||
*/
|
*/
|
||||||
glm::vec3* getValue ();
|
[[nodiscard]] const glm::vec3* getValue () const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type string indicator
|
* Type string indicator
|
||||||
@ -25,6 +25,6 @@ class CShaderConstantVector3 : public CShaderConstant {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** The constant's value */
|
/** The constant's value */
|
||||||
glm::vec3 m_value;
|
const glm::vec3 m_value;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects::Effects::Constants
|
} // namespace WallpaperEngine::Core::Objects::Effects::Constants
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
|
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;
|
return &this->m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ class CShaderConstantVector4 : public CShaderConstant {
|
|||||||
/**
|
/**
|
||||||
* @return A pointer to the actual value of the constant
|
* @return A pointer to the actual value of the constant
|
||||||
*/
|
*/
|
||||||
glm::vec4* getValue ();
|
[[nodiscard]] const glm::vec4* getValue () const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type string indicator
|
* Type string indicator
|
||||||
@ -25,6 +25,6 @@ class CShaderConstantVector4 : public CShaderConstant {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** The constant's value */
|
/** The constant's value */
|
||||||
glm::vec4 m_value;
|
const glm::vec4 m_value;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects::Effects::Constants
|
} // namespace WallpaperEngine::Core::Objects::Effects::Constants
|
||||||
|
@ -1,59 +1,74 @@
|
|||||||
#include "CMaterial.h"
|
#include "CMaterial.h"
|
||||||
|
|
||||||
|
#include "WallpaperEngine/Core/Objects/Images/Materials/CPass.h"
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Assets;
|
using namespace WallpaperEngine::Assets;
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects;
|
using namespace WallpaperEngine::Core::Objects;
|
||||||
using namespace WallpaperEngine::Core::Objects::Images;
|
using namespace WallpaperEngine::Core::Objects::Images;
|
||||||
|
|
||||||
CMaterial::CMaterial (std::string name) : m_name (std::move (name)) {}
|
CMaterial::CMaterial (
|
||||||
|
std::string name, std::map<int, const Effects::CBind*> textureBindings,
|
||||||
|
std::vector<const Materials::CPass*> passes
|
||||||
|
) :
|
||||||
|
m_name (name),
|
||||||
|
m_textureBindings (textureBindings),
|
||||||
|
m_passes (passes) {}
|
||||||
|
CMaterial::CMaterial (
|
||||||
|
std::string name, std::string target,
|
||||||
|
std::map<int, const Effects::CBind*> textureBindings, std::vector<const Materials::CPass*> passes
|
||||||
|
) :
|
||||||
|
m_name (name),
|
||||||
|
m_target (target),
|
||||||
|
m_textureBindings (textureBindings),
|
||||||
|
m_passes (passes) {}
|
||||||
|
|
||||||
CMaterial* CMaterial::fromFile (const std::string& filename, CContainer* container) {
|
const CMaterial* CMaterial::fromFile (
|
||||||
return fromJSON (filename, json::parse (container->readFileAsString (filename)));
|
const std::filesystem::path& filename, const CContainer* container,
|
||||||
|
std::map<int, const Effects::CBind*> 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) {
|
const CMaterial* CMaterial::fromFile (
|
||||||
return fromJSON (filename, json::parse (container->readFileAsString (filename)), target);
|
const std::filesystem::path& filename, const std::string& target,
|
||||||
|
const CContainer* container, std::map<int, const Effects::CBind*> 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) {
|
const CMaterial* CMaterial::fromJSON (
|
||||||
CMaterial* material = fromJSON (name, std::move (data));
|
const std::string& name, const json& data, const std::string& target,
|
||||||
|
std::map<int, const Effects::CBind*> textureBindings, const OverrideInfo* overrides
|
||||||
material->setTarget (target);
|
) {
|
||||||
|
|
||||||
return material;
|
|
||||||
}
|
|
||||||
|
|
||||||
CMaterial* CMaterial::fromJSON (const std::string& name, json data) {
|
|
||||||
const auto passes_it = jsonFindRequired (data, "passes", "Material must have at least one pass");
|
const auto passes_it = jsonFindRequired (data, "passes", "Material must have at least one pass");
|
||||||
|
std::vector<const Materials::CPass*> passes;
|
||||||
auto* material = new CMaterial (name);
|
|
||||||
|
|
||||||
for (const auto& cur : (*passes_it))
|
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) {
|
const CMaterial* CMaterial::fromJSON (
|
||||||
this->m_passes.push_back (pass);
|
const std::string& name, const json& data, std::map<int, const Effects::CBind*> textureBindings,
|
||||||
|
const OverrideInfo* overrides
|
||||||
|
) {
|
||||||
|
const auto passes_it = jsonFindRequired (data, "passes", "Material must have at least one pass");
|
||||||
|
std::vector<const Materials::CPass*> passes;
|
||||||
|
|
||||||
|
for (const auto& cur : (*passes_it))
|
||||||
|
passes.push_back (Materials::CPass::fromJSON (cur, overrides));
|
||||||
|
|
||||||
|
return new CMaterial (name, textureBindings, passes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMaterial::insertTextureBind (Effects::CBind* bind) {
|
const std::vector<const Materials::CPass*>& CMaterial::getPasses () const {
|
||||||
this->m_textureBindings.insert (std::make_pair (bind->getIndex (), bind));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMaterial::setTarget (const std::string& target) {
|
|
||||||
this->m_target = target;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<Materials::CPass*>& CMaterial::getPasses () const {
|
|
||||||
return this->m_passes;
|
return this->m_passes;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::map<int, Effects::CBind*>& CMaterial::getTextureBinds () const {
|
const std::map<int, const Effects::CBind*>& CMaterial::getTextureBinds () const {
|
||||||
return this->m_textureBindings;
|
return this->m_textureBindings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Objects/Effects/CBind.h"
|
#include "WallpaperEngine/Core/Objects/Effects/CBind.h"
|
||||||
#include "WallpaperEngine/Core/Objects/Images/Materials/CPass.h"
|
|
||||||
|
|
||||||
#include "WallpaperEngine/Assets/CContainer.h"
|
#include "WallpaperEngine/Assets/CContainer.h"
|
||||||
#include "WallpaperEngine/Core/Core.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 {
|
namespace WallpaperEngine::Core::Objects::Images {
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
@ -15,29 +19,34 @@ using namespace WallpaperEngine::Assets;
|
|||||||
*/
|
*/
|
||||||
class CMaterial {
|
class CMaterial {
|
||||||
public:
|
public:
|
||||||
static CMaterial* fromFile (const std::string& filename, Assets::CContainer* container);
|
struct OverrideInfo {
|
||||||
static CMaterial* fromJSON (const std::string& name, json data);
|
std::map<std::string, int> combos;
|
||||||
static CMaterial* fromFile (const std::string& filename, const std::string& target, Assets::CContainer* container);
|
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants;
|
||||||
static CMaterial* fromJSON (const std::string& name, json data, const std::string& target);
|
std::map<int, std::string> textures;
|
||||||
|
};
|
||||||
/**
|
|
||||||
* @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);
|
|
||||||
|
|
||||||
|
static const CMaterial* fromFile (
|
||||||
|
const std::filesystem::path& filename, const Assets::CContainer* container,
|
||||||
|
std::map<int, const Effects::CBind*> textureBindings = {}, const OverrideInfo* overrides = nullptr);
|
||||||
|
static const CMaterial* fromFile (
|
||||||
|
const std::filesystem::path& filename, const std::string& target,
|
||||||
|
const Assets::CContainer* container, std::map<int, const Effects::CBind*> textureBindings = {},
|
||||||
|
const OverrideInfo* overrides = nullptr);
|
||||||
|
static const CMaterial* fromJSON (
|
||||||
|
const std::string& name, const json& data,
|
||||||
|
std::map<int, const Effects::CBind*> textureBindings = {}, const OverrideInfo* overrides = nullptr);
|
||||||
|
static const CMaterial* fromJSON (
|
||||||
|
const std::string& name, const json& data, const std::string& target,
|
||||||
|
std::map<int, const Effects::CBind*> textureBindings = {}, const OverrideInfo* overrides = nullptr);
|
||||||
/**
|
/**
|
||||||
* @return All the rendering passes that happen for this material
|
* @return All the rendering passes that happen for this material
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const std::vector<Materials::CPass*>& getPasses () const;
|
[[nodiscard]] const std::vector<const Materials::CPass*>& getPasses () const;
|
||||||
/**
|
/**
|
||||||
* @return The textures that have to be bound while rendering the material.
|
* @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
|
* These act as an override of the textures specified by the parent effect
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const std::map<int, Effects::CBind*>& getTextureBinds () const;
|
[[nodiscard]] const std::map<int, const Effects::CBind*>& getTextureBinds () const;
|
||||||
/**
|
/**
|
||||||
* @return The materials destination (fbo) if required
|
* @return The materials destination (fbo) if required
|
||||||
*/
|
*/
|
||||||
@ -52,21 +61,21 @@ class CMaterial {
|
|||||||
[[nodiscard]] const std::string& getName () const;
|
[[nodiscard]] const std::string& getName () const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit CMaterial (std::string name);
|
CMaterial (
|
||||||
|
std::string name, std::map<int, const Effects::CBind*> textureBindings,
|
||||||
/**
|
std::vector<const Materials::CPass*> passes);
|
||||||
* @param target The new target while rendering this material
|
CMaterial (
|
||||||
*/
|
std::string name, std::string target, std::map<int, const Effects::CBind*> textureBindings,
|
||||||
void setTarget (const std::string& target);
|
const std::vector<const Materials::CPass*> passes);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** All the shader passes required to render this material */
|
/** All the shader passes required to render this material */
|
||||||
std::vector<Materials::CPass*> m_passes;
|
const std::vector<const Materials::CPass*> m_passes;
|
||||||
/** List of texture bind overrides to use for this material */
|
/** List of texture bind overrides to use for this material */
|
||||||
std::map<int, Effects::CBind*> m_textureBindings;
|
const std::map<int, const Effects::CBind*> m_textureBindings;
|
||||||
/** The FBO target to render to (if any) */
|
/** The FBO target to render to (if any) */
|
||||||
std::string m_target;
|
const std::string m_target;
|
||||||
/** The material's name */
|
/** The material's name */
|
||||||
std::string m_name;
|
const std::string m_name;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects::Images
|
} // namespace WallpaperEngine::Core::Objects::Images
|
||||||
|
@ -7,72 +7,82 @@ using namespace WallpaperEngine::Core::Objects::Effects::Constants;
|
|||||||
using namespace WallpaperEngine::Core::Objects::Images::Materials;
|
using namespace WallpaperEngine::Core::Objects::Images::Materials;
|
||||||
|
|
||||||
CPass::CPass (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite,
|
CPass::CPass (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite,
|
||||||
std::string shader) :
|
std::string shader, std::map<int, std::string> textures, std::map<std::string, int> combos,
|
||||||
m_blending (std::move (blending)),
|
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants) :
|
||||||
m_cullmode (std::move (cullmode)),
|
m_blending (blending),
|
||||||
m_depthtest (std::move (depthtest)),
|
m_cullmode (cullmode),
|
||||||
m_depthwrite (std::move (depthwrite)),
|
m_depthtest (depthtest),
|
||||||
m_shader (std::move (shader)) {}
|
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
|
// TODO: FIGURE OUT DEFAULT BLENDING MODE
|
||||||
const auto blending = jsonFindDefault<std::string> (data, "blending", "normal");
|
|
||||||
const auto cullmode = jsonFindDefault<std::string> (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 textures_it = data.find ("textures");
|
||||||
const auto combos_it = data.find ("combos");
|
const auto combos_it = data.find ("combos");
|
||||||
|
|
||||||
|
std::map<int, std::string> textures;
|
||||||
|
std::map<std::string, int> combos;
|
||||||
|
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants;
|
||||||
|
|
||||||
if (textures_it != data.end ()) {
|
if (textures_it != data.end ()) {
|
||||||
// TODO: FETCH THIS FROM CImage TO MAKE IT COMPATIBLE WITH OLDER WALLPAPERS
|
// TODO: FETCH THIS FROM CImage TO MAKE IT COMPATIBLE WITH OLDER WALLPAPERS
|
||||||
if (!textures_it->is_array ())
|
if (!textures_it->is_array ())
|
||||||
sLog.exception ("Material's textures must be a list");
|
sLog.exception ("Material's textures must be a list");
|
||||||
}
|
|
||||||
|
|
||||||
auto* pass = new CPass (blending, cullmode, *depthtest_it, *depthwrite_it, *shader_it);
|
int textureNumber = -1;
|
||||||
|
|
||||||
if (textures_it != data.end ())
|
|
||||||
for (const auto& cur : (*textures_it))
|
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 ()) {
|
if (combos_it != data.end ()) {
|
||||||
for (const auto& cur : combos_it->items ()) {
|
for (const auto& cur : combos_it->items ()) {
|
||||||
if (cur.value ().is_number_integer ())
|
if (cur.value ().is_number_integer ()) {
|
||||||
pass->insertCombo (cur.key (), cur.value ());
|
std::string uppercase = std::string (cur.key ());
|
||||||
else
|
|
||||||
|
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");
|
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<std::string> (data, "blending", "normal"),
|
||||||
|
jsonFindDefault<std::string> (data, "cullmode", "nocull"),
|
||||||
|
jsonFindRequired <std::string> (data, "depthtest", "Material pass must have depthtest specified"),
|
||||||
|
jsonFindRequired <std::string> (data, "depthwrite", "Material pass must have depthwrite specified"),
|
||||||
|
jsonFindRequired <std::string> (data, "shader", "Material pass must have shader specified"),
|
||||||
|
textures,
|
||||||
|
combos,
|
||||||
|
constants
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPass::insertTexture (const std::string& texture) {
|
const std::map<int, std::string>& CPass::getTextures () const {
|
||||||
this->m_textures.push_back (texture);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPass::setTexture (std::vector<std::string>::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<std::string>& CPass::getTextures () const {
|
|
||||||
return this->m_textures;
|
return this->m_textures;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::map<std::string, CShaderConstant*>& CPass::getConstants () const {
|
const std::map<std::string, const CShaderConstant*>& CPass::getConstants () const {
|
||||||
return this->m_constants;
|
return this->m_constants;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, int>* CPass::getCombos () {
|
const std::map<std::string, int>& CPass::getCombos () const {
|
||||||
return &this->m_combos;
|
return this->m_combos;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& CPass::getShader () const {
|
const std::string& CPass::getShader () const {
|
||||||
@ -94,11 +104,3 @@ const std::string& CPass::getDepthTest () const {
|
|||||||
const std::string& CPass::getDepthWrite () const {
|
const std::string& CPass::getDepthWrite () const {
|
||||||
return this->m_depthwrite;
|
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));
|
|
||||||
}
|
|
@ -1,13 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
#include "WallpaperEngine/Core/Core.h"
|
||||||
|
#include "WallpaperEngine/Core/Objects/Images/CMaterial.h"
|
||||||
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h"
|
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects {
|
namespace WallpaperEngine::Core::Objects {
|
||||||
class CEffect;
|
class CEffect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace WallpaperEngine::Core::Objects::Images {
|
||||||
|
class CMaterial;
|
||||||
|
}
|
||||||
|
|
||||||
namespace WallpaperEngine::Core::Objects::Images::Materials {
|
namespace WallpaperEngine::Core::Objects::Images::Materials {
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
@ -18,20 +22,20 @@ class CPass {
|
|||||||
friend class WallpaperEngine::Core::Objects::CEffect;
|
friend class WallpaperEngine::Core::Objects::CEffect;
|
||||||
|
|
||||||
public:
|
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
|
* @return The list of textures to bind while rendering
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const std::vector<std::string>& getTextures () const;
|
[[nodiscard]] const std::map<int, std::string>& getTextures () const;
|
||||||
/**
|
/**
|
||||||
* @return Shader constants that alter how the shader should behave
|
* @return Shader constants that alter how the shader should behave
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const std::map<std::string, Effects::Constants::CShaderConstant*>& getConstants () const;
|
[[nodiscard]] const std::map<std::string, const Effects::Constants::CShaderConstant*>& getConstants () const;
|
||||||
/**
|
/**
|
||||||
* @return Shader combos that alter how the shader should behave
|
* @return Shader combos that alter how the shader should behave
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] std::map<std::string, int>* getCombos ();
|
[[nodiscard]] const std::map<std::string, int>& getCombos () const;
|
||||||
/**
|
/**
|
||||||
* @return Shader to be used while rendering the pass
|
* @return Shader to be used while rendering the pass
|
||||||
*/
|
*/
|
||||||
@ -52,61 +56,29 @@ class CPass {
|
|||||||
* @return If depth write has to happen while rendering
|
* @return If depth write has to happen while rendering
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const std::string& getDepthWrite () const;
|
[[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:
|
protected:
|
||||||
CPass (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite,
|
CPass (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite,
|
||||||
std::string shader);
|
std::string shader, std::map<int, std::string> textures, std::map<std::string, int> combos,
|
||||||
|
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants);
|
||||||
/**
|
|
||||||
* 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<std::string>::size_type index, const std::string& texture);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// TODO: CREATE ENUMERATIONS FOR THESE INSTEAD OF USING STRING VALUES!
|
// TODO: CREATE ENUMERATIONS FOR THESE INSTEAD OF USING STRING VALUES!
|
||||||
/** The blending mode to use */
|
/** The blending mode to use */
|
||||||
std::string m_blending;
|
const std::string m_blending;
|
||||||
/** The culling mode to use */
|
/** The culling mode to use */
|
||||||
std::string m_cullmode;
|
const std::string m_cullmode;
|
||||||
/** If depthtesting has to happen while drawing */
|
/** If depthtesting has to happen while drawing */
|
||||||
std::string m_depthtest;
|
const std::string m_depthtest;
|
||||||
/** If depthwrite has to happen while drawing */
|
/** If depthwrite has to happen while drawing */
|
||||||
std::string m_depthwrite;
|
const std::string m_depthwrite;
|
||||||
/** The shader to use */
|
/** The shader to use */
|
||||||
std::string m_shader;
|
const std::string m_shader;
|
||||||
/** The list of textures to use */
|
/** The list of textures to use */
|
||||||
std::vector<std::string> m_textures;
|
const std::map<int, std::string> m_textures;
|
||||||
/** Different combo settings for shader input */
|
/** Different combo settings for shader input */
|
||||||
std::map<std::string, int> m_combos;
|
const std::map<std::string, int> m_combos;
|
||||||
/** Shader constant values to use for the shaders */
|
/** Shader constant values to use for the shaders */
|
||||||
std::map<std::string, Core::Objects::Effects::Constants::CShaderConstant*> m_constants;
|
const std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> m_constants;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects::Images::Materials
|
} // namespace WallpaperEngine::Core::Objects::Images::Materials
|
||||||
|
@ -2,31 +2,18 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles;
|
using namespace WallpaperEngine::Core::Objects::Particles;
|
||||||
|
|
||||||
CControlPoint* CControlPoint::fromJSON (json data) {
|
const CControlPoint* CControlPoint::fromJSON (const json& data) {
|
||||||
const auto flags_it = data.find ("flags");
|
return new CControlPoint (
|
||||||
const auto id_it = jsonFindRequired (data, "id", "Particle's control point must have id");
|
jsonFindRequired <uint32_t> (data, "id", "Particle's control point must have id"),
|
||||||
const auto offset_it = data.find ("offset");
|
jsonFindDefault (data, "flags", 0),
|
||||||
|
jsonFindDefault (data, "offset", glm::vec3())
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CControlPoint::CControlPoint (uint32_t id, uint32_t flags) : m_id (id), m_flags (flags), m_offset (glm::vec3 ()) {}
|
CControlPoint::CControlPoint (uint32_t id, uint32_t flags, glm::vec3 offset) :
|
||||||
|
m_id (id),
|
||||||
void CControlPoint::setOffset (const glm::vec3& offset) {
|
m_flags (flags),
|
||||||
this->m_offset = offset;
|
m_offset (offset) {}
|
||||||
}
|
|
||||||
|
|
||||||
void CControlPoint::setFlags (uint32_t flags) {
|
|
||||||
this->m_flags = flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t CControlPoint::getId () const {
|
uint32_t CControlPoint::getId () const {
|
||||||
return this->m_id;
|
return this->m_id;
|
||||||
|
@ -10,7 +10,7 @@ using json = nlohmann::json;
|
|||||||
*/
|
*/
|
||||||
class CControlPoint {
|
class CControlPoint {
|
||||||
public:
|
public:
|
||||||
static CControlPoint* fromJSON (json data);
|
static const CControlPoint* fromJSON (const json& data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The id of the controlpoint used for ordering purposes
|
* @return The id of the controlpoint used for ordering purposes
|
||||||
@ -26,23 +26,14 @@ class CControlPoint {
|
|||||||
[[nodiscard]] uint32_t getFlags () const;
|
[[nodiscard]] uint32_t getFlags () const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit CControlPoint (uint32_t id, uint32_t flags = 0);
|
explicit CControlPoint (uint32_t id, uint32_t flags, glm::vec3 offset);
|
||||||
|
|
||||||
/**
|
|
||||||
* @param offset The new offset
|
|
||||||
*/
|
|
||||||
void setOffset (const glm::vec3& offset);
|
|
||||||
/**
|
|
||||||
* @param flags The new flags
|
|
||||||
*/
|
|
||||||
void setFlags (uint32_t flags);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** ID used for ordering purposes */
|
/** ID used for ordering purposes */
|
||||||
uint32_t m_id;
|
const uint32_t m_id;
|
||||||
/** Flags that control how it behaves */
|
/** Flags that control how it behaves */
|
||||||
uint32_t m_flags;
|
const uint32_t m_flags;
|
||||||
/** The offset from starting position */
|
/** The offset from starting position */
|
||||||
glm::vec3 m_offset;
|
const glm::vec3 m_offset;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles
|
} // namespace WallpaperEngine::Core::Objects::Particles
|
||||||
|
@ -2,17 +2,12 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles;
|
using namespace WallpaperEngine::Core::Objects::Particles;
|
||||||
|
|
||||||
CEmitter* CEmitter::fromJSON (json data) {
|
const CEmitter* CEmitter::fromJSON (const json& data) {
|
||||||
const auto directions_it = jsonFindRequired (data, "directions", "Particle emitter must have direction specified");
|
|
||||||
const auto distancemax_it = jsonFindRequired (data, "distancemax", "Particle emitter must have maximum distance");
|
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 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);
|
auto distancemin = glm::vec3(0);
|
||||||
glm::vec3 distancemax = glm::vec3(0);
|
auto distancemax = glm::vec3(0);
|
||||||
|
|
||||||
if (distancemin_it->is_number()) {
|
if (distancemin_it->is_number()) {
|
||||||
distancemin = glm::vec3(static_cast<uint32_t>(*distancemin_it));
|
distancemin = glm::vec3(static_cast<uint32_t>(*distancemin_it));
|
||||||
@ -26,18 +21,26 @@ CEmitter* CEmitter::fromJSON (json data) {
|
|||||||
distancemax = WallpaperEngine::Core::aToVector3(*distancemax_it);
|
distancemax = WallpaperEngine::Core::aToVector3(*distancemax_it);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CEmitter (WallpaperEngine::Core::aToVector3 (*directions_it), distancemax, distancemin,
|
return new CEmitter (
|
||||||
(id_it == data.end () ? 0 : static_cast<uint32_t> (*id_it)), *name_it,
|
jsonFindRequired <glm::vec3> (data, "directions", "Particle emitter must have direction specified"),
|
||||||
WallpaperEngine::Core::aToVector3 (*origin_it), *rate_it);
|
distancemax,
|
||||||
|
distancemin,
|
||||||
|
jsonFindDefault (data, "id", 0),
|
||||||
|
jsonFindRequired <std::string> (data, "name", "Particle emitter must have a name"),
|
||||||
|
jsonFindRequired <glm::vec3> (data, "origin", "Particle emitter must have an origin"),
|
||||||
|
jsonFindRequired <double> (data, "rate", "Particle emitter must have a rate")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
CEmitter::CEmitter (const glm::vec3& directions, const glm::vec3& distancemax, const glm::vec3& distancemin, uint32_t id,
|
CEmitter::CEmitter (
|
||||||
std::string name, const glm::vec3& origin, double rate) :
|
glm::vec3 directions, glm::vec3 distancemax, glm::vec3 distancemin, uint32_t id, std::string name, glm::vec3 origin,
|
||||||
|
double rate
|
||||||
|
) :
|
||||||
m_directions (directions),
|
m_directions (directions),
|
||||||
m_distancemax (distancemax),
|
m_distancemax (distancemax),
|
||||||
m_distancemin (distancemin),
|
m_distancemin (distancemin),
|
||||||
m_id (id),
|
m_id (id),
|
||||||
m_name (std::move (name)),
|
m_name (name),
|
||||||
m_origin (origin),
|
m_origin (origin),
|
||||||
m_rate (rate) {}
|
m_rate (rate) {}
|
||||||
|
|
||||||
@ -65,6 +68,6 @@ const glm::vec3& CEmitter::getOrigin () const {
|
|||||||
return this->m_origin;
|
return this->m_origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double CEmitter::getRate () const {
|
double CEmitter::getRate () const {
|
||||||
return this->m_rate;
|
return this->m_rate;
|
||||||
}
|
}
|
@ -10,7 +10,7 @@ using json = nlohmann::json;
|
|||||||
*/
|
*/
|
||||||
class CEmitter {
|
class CEmitter {
|
||||||
public:
|
public:
|
||||||
static CEmitter* fromJSON (json data);
|
static const CEmitter* fromJSON (const json& data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The ID of the emitter
|
* @return The ID of the emitter
|
||||||
@ -39,25 +39,26 @@ class CEmitter {
|
|||||||
/**
|
/**
|
||||||
* @return The rate of particle emission
|
* @return The rate of particle emission
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const double getRate () const;
|
[[nodiscard]] double getRate () const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CEmitter (const glm::vec3& directions, const glm::vec3& distancemax, const glm::vec3& distancemin, uint32_t id, std::string name,
|
CEmitter (
|
||||||
const glm::vec3& origin, double rate);
|
glm::vec3 directions, glm::vec3 distancemax, glm::vec3 distancemin, uint32_t id, std::string name,
|
||||||
|
glm::vec3 origin, double rate);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Direction the particles should move to */
|
/** Direction the particles should move to */
|
||||||
glm::vec3 m_directions;
|
const glm::vec3 m_directions;
|
||||||
/** Maximum distance before the particle is dead */
|
/** Maximum distance before the particle is dead */
|
||||||
glm::vec3 m_distancemax;
|
const glm::vec3 m_distancemax;
|
||||||
/** Minimum distance before the particle is dead */
|
/** Minimum distance before the particle is dead */
|
||||||
glm::vec3 m_distancemin;
|
const glm::vec3 m_distancemin;
|
||||||
/** ID of the emitter */
|
/** ID of the emitter */
|
||||||
uint32_t m_id;
|
const uint32_t m_id;
|
||||||
/** Name of the emitter, indicates the type of emitter */
|
/** Name of the emitter, indicates the type of emitter */
|
||||||
std::string m_name;
|
const std::string m_name;
|
||||||
/** The center of the emitter */
|
/** The center of the emitter */
|
||||||
glm::vec3 m_origin;
|
const glm::vec3 m_origin;
|
||||||
/** The rate of emission */
|
/** The rate of emission */
|
||||||
double m_rate;
|
double m_rate;
|
||||||
};
|
};
|
||||||
|
@ -12,40 +12,41 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles;
|
using namespace WallpaperEngine::Core::Objects::Particles;
|
||||||
|
|
||||||
CInitializer* CInitializer::fromJSON (json data) {
|
const CInitializer* CInitializer::fromJSON (const json& data) {
|
||||||
const auto id_it = data.find ("id");
|
const auto name = jsonFindRequired <std::string> (data, "name", "Particle's initializer must have a name");
|
||||||
const auto name_it = jsonFindRequired (data, "name", "Particle's initializer must have a name");
|
const auto id = jsonFindDefault (data, "id", 0);
|
||||||
const uint32_t id = ((id_it == data.end ()) ? 0 : static_cast<uint32_t> (*id_it));
|
|
||||||
|
|
||||||
if (*name_it == "lifetimerandom") {
|
if (name == "lifetimerandom") {
|
||||||
return Initializers::CLifeTimeRandom::fromJSON (data, id);
|
return Initializers::CLifeTimeRandom::fromJSON (data, id);
|
||||||
}
|
}
|
||||||
if (*name_it == "sizerandom") {
|
if (name == "sizerandom") {
|
||||||
return Initializers::CSizeRandom::fromJSON (data, id);
|
return Initializers::CSizeRandom::fromJSON (data, id);
|
||||||
}
|
}
|
||||||
if (*name_it == "rotationrandom") {
|
if (name == "rotationrandom") {
|
||||||
return Initializers::CRotationRandom::fromJSON (data, id);
|
return Initializers::CRotationRandom::fromJSON (data, id);
|
||||||
}
|
}
|
||||||
if (*name_it == "velocityrandom") {
|
if (name == "velocityrandom") {
|
||||||
return Initializers::CVelocityRandom::fromJSON (data, id);
|
return Initializers::CVelocityRandom::fromJSON (data, id);
|
||||||
}
|
}
|
||||||
if (*name_it == "colorrandom") {
|
if (name == "colorrandom") {
|
||||||
return Initializers::CColorRandom::fromJSON (data, id);
|
return Initializers::CColorRandom::fromJSON (data, id);
|
||||||
}
|
}
|
||||||
if (*name_it == "alpharandom") {
|
if (name == "alpharandom") {
|
||||||
return Initializers::CAlphaRandom::fromJSON (data, id);
|
return Initializers::CAlphaRandom::fromJSON (data, id);
|
||||||
}
|
}
|
||||||
if (*name_it == "angularvelocityrandom") {
|
if (name == "angularvelocityrandom") {
|
||||||
return Initializers::CAngularVelocityRandom::fromJSON (data, id);
|
return Initializers::CAngularVelocityRandom::fromJSON (data, id);
|
||||||
}
|
}
|
||||||
if (*name_it == "turbulentvelocityrandom") {
|
if (name == "turbulentvelocityrandom") {
|
||||||
return Initializers::CTurbulentVelocityRandom::fromJSON (data, id);
|
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 {
|
const std::string& CInitializer::getName () const {
|
||||||
return this->m_name;
|
return this->m_name;
|
||||||
|
@ -11,7 +11,7 @@ using json = nlohmann::json;
|
|||||||
*/
|
*/
|
||||||
class CInitializer {
|
class CInitializer {
|
||||||
public:
|
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
|
* @return The name of the particle initializer, indicates what type of initialization to do
|
||||||
@ -27,8 +27,8 @@ class CInitializer {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
/** ID for ordering purposes */
|
/** 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 */
|
/** 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
|
} // namespace WallpaperEngine::Core::Objects::Particles
|
||||||
|
@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
||||||
|
|
||||||
CAlphaRandom* CAlphaRandom::fromJSON (json data, uint32_t id) {
|
const CAlphaRandom* CAlphaRandom::fromJSON (const json& data, uint32_t id) {
|
||||||
const auto min_it = jsonFindRequired (data, "min", "Alpharandom initializer must have a minimum value");
|
return new CAlphaRandom (
|
||||||
const auto max_it = jsonFindRequired (data, "max", "Alpharandom initializer must have a maximum value");
|
id,
|
||||||
|
jsonFindRequired<double> (data, "min", "Alpharandom initializer must have a minimum value"),
|
||||||
return new CAlphaRandom (id, *min_it, *max_it);
|
jsonFindRequired<double> (data, "max", "Alpharandom initializer must have a maximum value")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
CAlphaRandom::CAlphaRandom (uint32_t id, double min, double max) :
|
CAlphaRandom::CAlphaRandom (uint32_t id, double min, double max) :
|
||||||
|
@ -21,14 +21,14 @@ class CAlphaRandom : CInitializer {
|
|||||||
protected:
|
protected:
|
||||||
friend class CInitializer;
|
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);
|
CAlphaRandom (uint32_t id, double min, double max);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Maximum alpha */
|
/** Maximum alpha */
|
||||||
double m_max;
|
const double m_max;
|
||||||
/** Minimum alpha */
|
/** Minimum alpha */
|
||||||
double m_min;
|
const double m_min;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
||||||
|
|
||||||
CAngularVelocityRandom* CAngularVelocityRandom::fromJSON (json data, uint32_t id) {
|
const CAngularVelocityRandom* CAngularVelocityRandom::fromJSON (const json& data, uint32_t id) {
|
||||||
const auto min_it = jsonFindRequired (data, "min", "Angularvelocityrandom initializer must have a minimum value");
|
return new CAngularVelocityRandom (
|
||||||
const auto max_it = jsonFindRequired (data, "max", "Angularvelocityrandom initializer must have a maximum value");
|
id,
|
||||||
|
jsonFindRequired <glm::vec3> (data, "min", "Angularvelocityrandom initializer must have a minimum value"),
|
||||||
return new CAngularVelocityRandom (id, WallpaperEngine::Core::aToVector3 (*min_it),
|
jsonFindRequired <glm::vec3> (data, "max", "Angularvelocityrandom initializer must have a maximum value")
|
||||||
WallpaperEngine::Core::aToVector3 (*max_it));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
CAngularVelocityRandom::CAngularVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max) :
|
CAngularVelocityRandom::CAngularVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max) :
|
||||||
|
@ -21,14 +21,14 @@ class CAngularVelocityRandom : CInitializer {
|
|||||||
protected:
|
protected:
|
||||||
friend class CInitializer;
|
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);
|
CAngularVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Maximum velocity (direction * speed) */
|
/** Maximum velocity (direction * speed) */
|
||||||
glm::vec3 m_max;
|
const glm::vec3 m_max;
|
||||||
/** Minimum velocity (direction * speed) */
|
/** Minimum velocity (direction * speed) */
|
||||||
glm::vec3 m_min;
|
const glm::vec3 m_min;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
||||||
|
|
||||||
CColorRandom* CColorRandom::fromJSON (json data, uint32_t id) {
|
const CColorRandom* CColorRandom::fromJSON (const json& data, uint32_t id) {
|
||||||
const auto min_it = jsonFindRequired (data, "min", "Colorrandom initializer must have a minimum value");
|
return new CColorRandom (
|
||||||
const auto max_it = jsonFindRequired (data, "max", "Colorrandom initializer must have a maximum value");
|
id,
|
||||||
|
jsonFindRequired <glm::ivec3> (data, "min", "Colorrandom initializer must have a minimum value"),
|
||||||
return new CColorRandom (id, WallpaperEngine::Core::aToColori (*min_it),
|
jsonFindRequired <glm::ivec3> (data, "max", "Colorrandom initializer must have a maximum value")
|
||||||
WallpaperEngine::Core::aToColori (*max_it));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
CColorRandom::CColorRandom (uint32_t id, glm::ivec3 min, glm::ivec3 max) :
|
CColorRandom::CColorRandom (uint32_t id, glm::ivec3 min, glm::ivec3 max) :
|
||||||
|
@ -22,14 +22,14 @@ class CColorRandom : CInitializer {
|
|||||||
protected:
|
protected:
|
||||||
friend class CInitializer;
|
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);
|
CColorRandom (uint32_t id, glm::ivec3 min, glm::ivec3 max);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Maximum color */
|
/** Maximum color */
|
||||||
glm::ivec3 m_max;
|
const glm::ivec3 m_max;
|
||||||
/** Minimum color */
|
/** Minimum color */
|
||||||
glm::ivec3 m_min;
|
const glm::ivec3 m_min;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
||||||
|
@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
||||||
|
|
||||||
CLifeTimeRandom* CLifeTimeRandom::fromJSON (json data, uint32_t id) {
|
const CLifeTimeRandom* CLifeTimeRandom::fromJSON (const json& data, uint32_t id) {
|
||||||
const auto min_it = jsonFindRequired (data, "min", "Lifetimerandom initializer must have a minimum value");
|
return new CLifeTimeRandom (
|
||||||
const auto max_it = jsonFindRequired (data, "max", "Lifetimerandom initializer must have a maximum value");
|
id,
|
||||||
|
jsonFindRequired <uint32_t> (data, "min", "Lifetimerandom initializer must have a minimum value"),
|
||||||
return new CLifeTimeRandom (id, *min_it, *max_it);
|
jsonFindRequired <uint32_t> (data, "max", "Lifetimerandom initializer must have a maximum value")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
CLifeTimeRandom::CLifeTimeRandom (uint32_t id, uint32_t min, uint32_t max) :
|
CLifeTimeRandom::CLifeTimeRandom (uint32_t id, uint32_t min, uint32_t max) :
|
||||||
|
@ -22,14 +22,14 @@ class CLifeTimeRandom : CInitializer {
|
|||||||
protected:
|
protected:
|
||||||
friend class CInitializer;
|
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);
|
CLifeTimeRandom (uint32_t id, uint32_t min, uint32_t max);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Maximum lifetime */
|
/** Maximum lifetime */
|
||||||
uint32_t m_max;
|
const uint32_t m_max;
|
||||||
/** Minimum lifetime */
|
/** Minimum lifetime */
|
||||||
uint32_t m_min;
|
const uint32_t m_min;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
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 min_it = data.find ("minVector");
|
||||||
const auto max_it = data.find ("max");
|
const auto max_it = data.find ("max");
|
||||||
|
|
||||||
|
@ -47,24 +47,24 @@ class CRotationRandom : CInitializer {
|
|||||||
protected:
|
protected:
|
||||||
friend class CInitializer;
|
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,
|
CRotationRandom (uint32_t id, glm::vec3 minVector, double minNumber, bool isMinimumVector, glm::vec3 maxVector,
|
||||||
double maxNumber, bool isMaximumVector);
|
double maxNumber, bool isMaximumVector);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Maximum rotation vector */
|
/** Maximum rotation vector */
|
||||||
glm::vec3 m_maxVector;
|
const glm::vec3 m_maxVector;
|
||||||
/** Maximum rotation angle */
|
/** Maximum rotation angle */
|
||||||
double m_maxNumber;
|
const double m_maxNumber;
|
||||||
/** Minimum rotation vector */
|
/** Minimum rotation vector */
|
||||||
glm::vec3 m_minVector;
|
const glm::vec3 m_minVector;
|
||||||
/** Minimum rotation angle */
|
/** Minimum rotation angle */
|
||||||
double m_minNumber;
|
const double m_minNumber;
|
||||||
|
|
||||||
/** If minimum is a vector */
|
/** If minimum is a vector */
|
||||||
bool m_isMinimumVector;
|
const bool m_isMinimumVector;
|
||||||
/** If maximum is a vector */
|
/** If maximum is a vector */
|
||||||
bool m_isMaximumVector;
|
const bool m_isMaximumVector;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
||||||
|
@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
||||||
|
|
||||||
CSizeRandom* CSizeRandom::fromJSON (json data, uint32_t id) {
|
const CSizeRandom* CSizeRandom::fromJSON (const json& data, uint32_t id) {
|
||||||
const auto min_it = jsonFindRequired (data, "min", "Sizerandom initializer must have a minimum value");
|
return new CSizeRandom (
|
||||||
const auto max_it = jsonFindRequired (data, "max", "Sizerandom initializer must have a maximum value");
|
id,
|
||||||
|
jsonFindRequired <uint32_t> (data, "min", "Sizerandom initializer must have a minimum value"),
|
||||||
return new CSizeRandom (id, *min_it, *max_it);
|
jsonFindRequired <uint32_t> (data, "max", "Sizerandom initializer must have a maximum value")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
CSizeRandom::CSizeRandom (uint32_t id, uint32_t min, uint32_t max) :
|
CSizeRandom::CSizeRandom (uint32_t id, uint32_t min, uint32_t max) :
|
||||||
|
@ -22,14 +22,14 @@ class CSizeRandom : CInitializer {
|
|||||||
protected:
|
protected:
|
||||||
friend class CInitializer;
|
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);
|
CSizeRandom (uint32_t id, uint32_t min, uint32_t max);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Maximum size */
|
/** Maximum size */
|
||||||
uint32_t m_max;
|
const uint32_t m_max;
|
||||||
/** Minimum size */
|
/** Minimum size */
|
||||||
uint32_t m_min;
|
const uint32_t m_min;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
||||||
|
@ -5,25 +5,15 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
||||||
|
|
||||||
CTurbulentVelocityRandom* CTurbulentVelocityRandom::fromJSON (json data, uint32_t id) {
|
const CTurbulentVelocityRandom* CTurbulentVelocityRandom::fromJSON (const json& data, uint32_t id) {
|
||||||
const auto phasemax_it = data.find ("phasemax");
|
return new CTurbulentVelocityRandom (
|
||||||
const auto scale_it = data.find ("scale");
|
id,
|
||||||
const auto speedmax_it = data.find ("speedmax");
|
jsonFindRequired <double> (data, "phasemax", "TurbulentVelocityRandom initializer must have a phasemax value"),
|
||||||
const auto speedmin_it = data.find ("speedmin");
|
jsonFindRequired <double> (data, "scale", "TurbulentVelocityRandom initializer must have a scale value"),
|
||||||
const auto timescale_it = data.find ("timescale");
|
jsonFindRequired <double>(data, "timescale", "TurbulentVelocityRandom initializer must have a timescale value"),
|
||||||
|
jsonFindRequired <uint32_t> (data, "speedmin", "TurbulentVelocityRandom initializer must have a minimum speed value"),
|
||||||
if (phasemax_it == data.end ())
|
jsonFindRequired <uint32_t> (data, "speedmax", "TurbulentVelocityRandom initializer must have a maximum speed value")
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CTurbulentVelocityRandom::CTurbulentVelocityRandom (uint32_t id, double phasemax, double scale, double timescale,
|
CTurbulentVelocityRandom::CTurbulentVelocityRandom (uint32_t id, double phasemax, double scale, double timescale,
|
||||||
|
@ -34,21 +34,21 @@ class CTurbulentVelocityRandom : CInitializer {
|
|||||||
protected:
|
protected:
|
||||||
friend class CInitializer;
|
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,
|
CTurbulentVelocityRandom (uint32_t id, double phasemax, double scale, double timescale, uint32_t speedmin,
|
||||||
uint32_t speedmax);
|
uint32_t speedmax);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Phase */
|
/** Phase */
|
||||||
double m_phasemax;
|
const double m_phasemax;
|
||||||
/** Scale */
|
/** Scale */
|
||||||
double m_scale;
|
const double m_scale;
|
||||||
/** Time scale, how the time affects the scale */
|
/** Time scale, how the time affects the scale */
|
||||||
double m_timescale;
|
const double m_timescale;
|
||||||
/** Minimum speed */
|
/** Minimum speed */
|
||||||
uint32_t m_speedmin;
|
const uint32_t m_speedmin;
|
||||||
/** Maximum speed */
|
/** Maximum speed */
|
||||||
uint32_t m_speedmax;
|
const uint32_t m_speedmax;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
|
||||||
|
|
||||||
CVelocityRandom* CVelocityRandom::fromJSON (json data, uint32_t id) {
|
const CVelocityRandom* CVelocityRandom::fromJSON (const json& data, uint32_t id) {
|
||||||
const auto min_it = jsonFindRequired (data, "min", "Velocityrandom initializer must have a minimum value");
|
return new CVelocityRandom (
|
||||||
const auto max_it = jsonFindRequired (data, "max", "Velocityrandom initializer must have a maximum value");
|
id,
|
||||||
|
jsonFindRequired <glm::vec3> (data, "min", "Velocityrandom initializer must have a minimum value"),
|
||||||
return new CVelocityRandom (id, WallpaperEngine::Core::aToVector3 (*min_it),
|
jsonFindRequired <glm::vec3> (data, "max", "Velocityrandom initializer must have a maximum value")
|
||||||
WallpaperEngine::Core::aToVector3 (*max_it));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
CVelocityRandom::CVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max) :
|
CVelocityRandom::CVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max) :
|
||||||
|
@ -22,14 +22,14 @@ class CVelocityRandom : CInitializer {
|
|||||||
protected:
|
protected:
|
||||||
friend class CInitializer;
|
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);
|
CVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Maximum velocity */
|
/** Maximum velocity */
|
||||||
glm::vec3 m_max;
|
const glm::vec3 m_max;
|
||||||
/** Minimum velocity */
|
/** Minimum velocity */
|
||||||
glm::vec3 m_min;
|
const glm::vec3 m_min;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
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");
|
const auto type = jsonFindRequired (data, "type", "Project properties must have the type field");
|
||||||
|
|
||||||
if (*type == CPropertyColor::Type)
|
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) :
|
CProperty::CProperty (std::string name, std::string type, std::string text) :
|
||||||
m_type (std::move (type)),
|
m_type (type),
|
||||||
m_name (std::move (name)),
|
m_name (name),
|
||||||
m_text (std::move (text)) {}
|
m_text (text) {}
|
||||||
|
|
||||||
const std::string& CProperty::getName () const {
|
const std::string& CProperty::getName () const {
|
||||||
return this->m_name;
|
return this->m_name;
|
||||||
|
@ -16,7 +16,7 @@ class CPropertyColor;
|
|||||||
class CProperty {
|
class CProperty {
|
||||||
public:
|
public:
|
||||||
virtual ~CProperty () = default;
|
virtual ~CProperty () = default;
|
||||||
static CProperty* fromJSON (json data, const std::string& name);
|
static const CProperty* fromJSON (const json& data, const std::string& name);
|
||||||
|
|
||||||
template <class T> const T* as () const {
|
template <class T> const T* as () const {
|
||||||
assert (is<T> ());
|
assert (is<T> ());
|
||||||
@ -28,7 +28,7 @@ class CProperty {
|
|||||||
return reinterpret_cast<T*> (this);
|
return reinterpret_cast<T*> (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> bool is () {
|
template <class T> bool is () const {
|
||||||
return this->m_type == T::Type;
|
return this->m_type == T::Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ class CProperty {
|
|||||||
*
|
*
|
||||||
* @param value New value for the property
|
* @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
|
* @return Name of the property
|
||||||
@ -60,10 +60,10 @@ class CProperty {
|
|||||||
CProperty (std::string name, std::string type, std::string text);
|
CProperty (std::string name, std::string type, std::string text);
|
||||||
|
|
||||||
/** Type of property */
|
/** Type of property */
|
||||||
std::string m_type;
|
const std::string m_type;
|
||||||
/** Name of the property */
|
/** Name of the property */
|
||||||
std::string m_name;
|
const std::string m_name;
|
||||||
/** Description of the property for the user */
|
/** Description of the property for the user */
|
||||||
std::string m_text;
|
mutable std::string m_text;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
} // namespace WallpaperEngine::Core::Projects
|
||||||
|
@ -5,18 +5,19 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
using namespace WallpaperEngine::Core::Projects;
|
||||||
|
|
||||||
CPropertyBoolean* CPropertyBoolean::fromJSON (json data, const std::string& name) {
|
const CPropertyBoolean* CPropertyBoolean::fromJSON (const json& data, std::string name) {
|
||||||
const json::const_iterator value = data.find ("value");
|
return new CPropertyBoolean (
|
||||||
const auto text = jsonFindDefault<std::string> (data, "text", "");
|
jsonFindRequired <bool> (data, "value", "Boolean property must have a value"),
|
||||||
|
name,
|
||||||
return new CPropertyBoolean (*value, name, text);
|
jsonFindDefault<std::string> (data, "text", "")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CPropertyBoolean::getValue () const {
|
bool CPropertyBoolean::getValue () const {
|
||||||
return this->m_value;
|
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";
|
this->m_value = value == "1" || value == "true";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ std::string CPropertyBoolean::dump () const {
|
|||||||
return ss.str ();
|
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),
|
CProperty (name, Type, text),
|
||||||
m_value (value) {}
|
m_value (value) {}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ using json = nlohmann::json;
|
|||||||
*/
|
*/
|
||||||
class CPropertyBoolean final : public CProperty {
|
class CPropertyBoolean final : public CProperty {
|
||||||
public:
|
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
|
* @return The value of the property
|
||||||
@ -19,14 +19,14 @@ class CPropertyBoolean final : public CProperty {
|
|||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
[[nodiscard]] std::string dump () const override;
|
[[nodiscard]] std::string dump () const override;
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
void update (const std::string& value) override;
|
void update (const std::string& value) const override;
|
||||||
|
|
||||||
static const std::string Type;
|
static const std::string Type;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CPropertyBoolean (bool value, const std::string& name, const std::string& text);
|
CPropertyBoolean (bool value, std::string name, std::string text);
|
||||||
|
|
||||||
/** Property's value */
|
/** Property's value */
|
||||||
bool m_value;
|
mutable bool m_value;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
} // namespace WallpaperEngine::Core::Projects
|
||||||
|
@ -19,7 +19,7 @@ glm::vec3 ParseColor (std::string value) {
|
|||||||
return WallpaperEngine::Core::aToColorf (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 std::string value = *jsonFindRequired (data, "value", "Color property must have a value");
|
||||||
const auto text = jsonFindDefault<std::string> (data, "text", "");
|
const auto text = jsonFindDefault<std::string> (data, "text", "");
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ const glm::vec3& CPropertyColor::getValue () const {
|
|||||||
return this->m_color;
|
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));
|
this->m_color = ParseColor (std::string (value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ std::string CPropertyColor::dump () const {
|
|||||||
return ss.str ();
|
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),
|
CProperty (name, Type, text),
|
||||||
m_color (color) {}
|
m_color (color) {}
|
||||||
|
|
||||||
|
@ -12,20 +12,20 @@ using json = nlohmann::json;
|
|||||||
*/
|
*/
|
||||||
class CPropertyColor final : public CProperty {
|
class CPropertyColor final : public CProperty {
|
||||||
public:
|
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
|
* @return The RGB color value in the 0-1 range
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const glm::vec3& getValue () const;
|
[[nodiscard]] const glm::vec3& getValue () const;
|
||||||
[[nodiscard]] std::string dump () const override;
|
[[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;
|
static const std::string Type;
|
||||||
|
|
||||||
private:
|
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
|
} // namespace WallpaperEngine::Core::Projects
|
||||||
|
@ -4,17 +4,13 @@
|
|||||||
|
|
||||||
#include "WallpaperEngine/Core/Core.h"
|
#include "WallpaperEngine/Core/Core.h"
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
#include "WallpaperEngine/Logging/CLog.h"
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
using namespace WallpaperEngine::Core::Projects;
|
||||||
|
|
||||||
CPropertyCombo* CPropertyCombo::fromJSON (json data, const std::string& name) {
|
const CPropertyCombo* CPropertyCombo::fromJSON (const json& data, std::string name) {
|
||||||
const auto value = data.find ("value");
|
std::vector<const CPropertyComboValue*> values;
|
||||||
const auto text = jsonFindDefault<std::string> (data, "text", "");
|
|
||||||
const auto options = jsonFindRequired (data, "options", "Options for a property combo is required");
|
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 ())
|
if (!options->is_array ())
|
||||||
sLog.exception ("Property combo options should be an array");
|
sLog.exception ("Property combo options should be an array");
|
||||||
|
|
||||||
@ -24,18 +20,27 @@ CPropertyCombo* CPropertyCombo::fromJSON (json data, const std::string& name) {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// check for label and value to ensure they're there
|
// check for label and value to ensure they're there
|
||||||
auto label = jsonFindRequired (cur, "label", "Label is required for a property combo option");
|
auto prop = new CPropertyComboValue {
|
||||||
auto propertyValue = jsonFindRequired (cur, "value", "Value is required for a property combo option");
|
.label = jsonFindRequired <std::string> (cur, "label", "Label is required for a property combo option"),
|
||||||
|
.value = jsonFindRequired <std::string> (cur, "value", "Value is required for a property combo option")
|
||||||
|
};
|
||||||
|
|
||||||
combo->addValue (*label, propertyValue->dump());
|
values.push_back (prop);
|
||||||
}
|
}
|
||||||
|
|
||||||
return combo;
|
return new CPropertyCombo (
|
||||||
|
name,
|
||||||
|
jsonFindDefault<std::string> (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<const CPropertyComboValue*> values
|
||||||
|
) :
|
||||||
CProperty (name, Type, text),
|
CProperty (name, Type, text),
|
||||||
m_defaultValue (std::move (defaultValue)) {}
|
m_defaultValue (defaultValue) {}
|
||||||
|
|
||||||
CPropertyCombo::~CPropertyCombo () {
|
CPropertyCombo::~CPropertyCombo () {
|
||||||
for (const auto* value : this->m_values)
|
for (const auto* value : this->m_values)
|
||||||
@ -63,7 +68,7 @@ std::string CPropertyCombo::dump () const {
|
|||||||
return ss.str ();
|
return ss.str ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPropertyCombo::update (const std::string& value) {
|
void CPropertyCombo::update (const std::string& value) const {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
// ensure the value is present somewhere in the value list
|
// 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;
|
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";
|
const std::string CPropertyCombo::Type = "combo";
|
@ -10,8 +10,8 @@ using json = nlohmann::json;
|
|||||||
*/
|
*/
|
||||||
class CPropertyComboValue {
|
class CPropertyComboValue {
|
||||||
public:
|
public:
|
||||||
std::string label;
|
const std::string label;
|
||||||
std::string value;
|
const std::string value;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,7 +23,7 @@ class CPropertyComboValue {
|
|||||||
*/
|
*/
|
||||||
class CPropertyCombo final : public CProperty {
|
class CPropertyCombo final : public CProperty {
|
||||||
public:
|
public:
|
||||||
static CPropertyCombo* fromJSON (json data, const std::string& name);
|
static const CPropertyCombo* fromJSON (const json& data, std::string name);
|
||||||
|
|
||||||
~CPropertyCombo () override;
|
~CPropertyCombo () override;
|
||||||
|
|
||||||
@ -32,24 +32,17 @@ class CPropertyCombo final : public CProperty {
|
|||||||
*/
|
*/
|
||||||
[[nodiscard]] const std::string& getValue () const;
|
[[nodiscard]] const std::string& getValue () const;
|
||||||
[[nodiscard]] std::string dump () const override;
|
[[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;
|
static const std::string Type;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CPropertyCombo (const std::string& name, const std::string& text, std::string defaultValue);
|
CPropertyCombo (
|
||||||
|
std::string name, std::string text, std::string defaultValue, std::vector<const CPropertyComboValue*> values);
|
||||||
/**
|
|
||||||
* Adds a combo value to the list of possible values
|
|
||||||
*
|
|
||||||
* @param label
|
|
||||||
* @param value
|
|
||||||
*/
|
|
||||||
void addValue (std::string label, std::string value);
|
|
||||||
|
|
||||||
/** List of values available to select */
|
/** List of values available to select */
|
||||||
std::vector<CPropertyComboValue*> m_values;
|
const std::vector<const CPropertyComboValue*> m_values;
|
||||||
/** The default value */
|
/** The default value */
|
||||||
std::string m_defaultValue;
|
mutable std::string m_defaultValue;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
} // namespace WallpaperEngine::Core::Projects
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
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 value = data.find ("value");
|
||||||
const auto text = jsonFindDefault<std::string> (data, "text", "");
|
const auto text = jsonFindDefault<std::string> (data, "text", "");
|
||||||
const auto min = jsonFindDefault (data, "min", 0.0);
|
const auto min = jsonFindDefault (data, "min", 0.0);
|
||||||
@ -48,8 +48,8 @@ std::string CPropertySlider::dump () const {
|
|||||||
return ss.str ();
|
return ss.str ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPropertySlider::update (const std::string& value) {
|
void CPropertySlider::update (const std::string& value) const {
|
||||||
const double newValue = strtod (value.c_str (), nullptr);
|
const auto newValue = strtod (value.c_str (), nullptr);
|
||||||
|
|
||||||
if (newValue < this->m_min || newValue > this->m_max)
|
if (newValue < this->m_min || newValue > this->m_max)
|
||||||
sLog.exception ("Slider value (", newValue, ") is out of range (", this->m_min, ",", this->m_max, ")");
|
sLog.exception ("Slider value (", newValue, ") is out of range (", this->m_min, ",", this->m_max, ")");
|
||||||
|
@ -12,7 +12,7 @@ using json = nlohmann::json;
|
|||||||
*/
|
*/
|
||||||
class CPropertySlider final : public CProperty {
|
class CPropertySlider final : public CProperty {
|
||||||
public:
|
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
|
* @return The slider's value
|
||||||
@ -31,21 +31,20 @@ class CPropertySlider final : public CProperty {
|
|||||||
*/
|
*/
|
||||||
[[nodiscard]] const double& getStep () const;
|
[[nodiscard]] const double& getStep () const;
|
||||||
[[nodiscard]] std::string dump () const override;
|
[[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;
|
static const std::string Type;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CPropertySlider (double value, const std::string& name, const std::string& text, double min, double max,
|
CPropertySlider (double value, const std::string& name, const std::string& text, double min, double max, double step);
|
||||||
double step);
|
|
||||||
|
|
||||||
/** Actual slider value */
|
/** Actual slider value */
|
||||||
double m_value;
|
mutable double m_value;
|
||||||
/** Minimum value */
|
/** Minimum value */
|
||||||
double m_min;
|
const double m_min;
|
||||||
/** Maximum value */
|
/** Maximum value */
|
||||||
double m_max;
|
const double m_max;
|
||||||
/** Increment steps for the slider in the UI */
|
/** Increment steps for the slider in the UI */
|
||||||
double m_step;
|
const double m_step;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
} // namespace WallpaperEngine::Core::Projects
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
using namespace WallpaperEngine::Core::Projects;
|
||||||
|
|
||||||
CPropertyText* CPropertyText::fromJSON (json data, const std::string& name) {
|
const CPropertyText* CPropertyText::fromJSON (const json& data, std::string name) {
|
||||||
const json::const_iterator text = data.find ("type");
|
const auto text = data.find ("type");
|
||||||
|
|
||||||
return new CPropertyText (name, *text);
|
return new CPropertyText (name, *text);
|
||||||
}
|
}
|
||||||
@ -20,10 +20,10 @@ std::string CPropertyText::dump () const {
|
|||||||
return ss.str ();
|
return ss.str ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPropertyText::update (const std::string& value) {
|
void CPropertyText::update (const std::string& value) const {
|
||||||
this->m_text = value;
|
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";
|
const std::string CPropertyText::Type = "text";
|
@ -10,13 +10,13 @@ using json = nlohmann::json;
|
|||||||
*/
|
*/
|
||||||
class CPropertyText final : public CProperty {
|
class CPropertyText final : public CProperty {
|
||||||
public:
|
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;
|
[[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;
|
static const std::string Type;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CPropertyText (const std::string& name, const std::string& text);
|
CPropertyText (std::string name, std::string text);
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Projects
|
} // namespace WallpaperEngine::Core::Projects
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Scenes;
|
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 {
|
const glm::vec3& CCamera::getCenter () const {
|
||||||
return this->m_center;
|
return this->m_center;
|
||||||
@ -16,11 +19,10 @@ const glm::vec3& CCamera::getUp () const {
|
|||||||
return this->m_up;
|
return this->m_up;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCamera* CCamera::fromJSON (json data) {
|
const CCamera* CCamera::fromJSON (const json::const_iterator& data) {
|
||||||
const auto center_it = jsonFindRequired (data, "center", "Camera must have a center position");
|
return new CCamera (
|
||||||
const auto eye_it = jsonFindRequired (data, "eye", "Camera must have an eye position");
|
jsonFindRequired <glm::vec3> (data, "center", "Camera must have a center position"),
|
||||||
const auto up_it = jsonFindRequired (data, "up", "Camera must have a up position");
|
jsonFindRequired <glm::vec3> (data, "eye", "Camera must have an eye position"),
|
||||||
|
jsonFindRequired <glm::vec3> (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));
|
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ using json = nlohmann::json;
|
|||||||
|
|
||||||
class CCamera {
|
class CCamera {
|
||||||
public:
|
public:
|
||||||
static CCamera* fromJSON (json data);
|
static const CCamera* fromJSON (const json::const_iterator& data);
|
||||||
|
|
||||||
const glm::vec3& getCenter () const;
|
const glm::vec3& getCenter () const;
|
||||||
const glm::vec3& getEye () const;
|
const glm::vec3& getEye () const;
|
||||||
@ -17,8 +17,8 @@ class CCamera {
|
|||||||
CCamera (glm::vec3 center, glm::vec3 eye, glm::vec3 up);
|
CCamera (glm::vec3 center, glm::vec3 eye, glm::vec3 up);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
glm::vec3 m_center;
|
const glm::vec3 m_center;
|
||||||
glm::vec3 m_eye;
|
const glm::vec3 m_eye;
|
||||||
glm::vec3 m_up;
|
const glm::vec3 m_up;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Scenes
|
} // namespace WallpaperEngine::Core::Scenes
|
||||||
|
@ -2,9 +2,15 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Scenes;
|
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 {
|
const int& CProjection::getWidth () const {
|
||||||
return this->m_width;
|
return this->m_width;
|
||||||
@ -18,15 +24,15 @@ bool CProjection::isAuto () const {
|
|||||||
return this->m_isAuto;
|
return this->m_isAuto;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CProjection::setWidth (int width) {
|
void CProjection::setWidth (int width) const {
|
||||||
this->m_width = width;
|
this->m_width = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CProjection::setHeight (int height) {
|
void CProjection::setHeight (int height) const {
|
||||||
this->m_height = height;
|
this->m_height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
CProjection* CProjection::fromJSON (json data) {
|
const CProjection* CProjection::fromJSON (const json::const_iterator& data) {
|
||||||
const auto auto_it = jsonFindDefault<bool> (data, "auto", false);
|
const auto auto_it = jsonFindDefault<bool> (data, "auto", false);
|
||||||
|
|
||||||
const auto width_it = jsonFindRequired (data, "width", "Projection must have width");
|
const auto width_it = jsonFindRequired (data, "width", "Projection must have width");
|
||||||
|
@ -7,22 +7,23 @@ using json = nlohmann::json;
|
|||||||
|
|
||||||
class CProjection {
|
class CProjection {
|
||||||
public:
|
public:
|
||||||
static CProjection* fromJSON (json data);
|
static const CProjection* fromJSON (const json::const_iterator& data);
|
||||||
|
|
||||||
[[nodiscard]] const int& getWidth () const;
|
[[nodiscard]] const int& getWidth () const;
|
||||||
[[nodiscard]] const int& getHeight () const;
|
[[nodiscard]] const int& getHeight () const;
|
||||||
[[nodiscard]] bool isAuto () const;
|
[[nodiscard]] bool isAuto () const;
|
||||||
|
|
||||||
void setWidth (int width);
|
// TODO: CHANGE THIS SO THE RENDER IS THE ONE RESPONSIBLE FOR THIS?
|
||||||
void setHeight (int height);
|
void setWidth (int width) const;
|
||||||
|
void setHeight (int height) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CProjection (int width, int height);
|
CProjection (int width, int height);
|
||||||
explicit CProjection (bool isAuto);
|
explicit CProjection (bool isAuto);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_width;
|
mutable int m_width;
|
||||||
int m_height;
|
mutable int m_height;
|
||||||
bool m_isAuto;
|
const bool m_isAuto;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::Scenes
|
} // namespace WallpaperEngine::Core::Scenes
|
||||||
|
@ -12,16 +12,17 @@ using namespace WallpaperEngine::Core;
|
|||||||
using namespace WallpaperEngine::Core::Projects;
|
using namespace WallpaperEngine::Core::Projects;
|
||||||
using namespace WallpaperEngine::Core::UserSettings;
|
using namespace WallpaperEngine::Core::UserSettings;
|
||||||
|
|
||||||
CUserSettingBoolean::CUserSettingBoolean (bool hasCondition, bool hasSource, bool defaultValue, std::string source,
|
CUserSettingBoolean::CUserSettingBoolean (
|
||||||
std::string expectedValue) :
|
bool hasCondition,bool hasSource, bool defaultValue, std::string source, std::string expectedValue
|
||||||
|
) :
|
||||||
CUserSettingValue (Type),
|
CUserSettingValue (Type),
|
||||||
m_default (defaultValue),
|
m_default (defaultValue),
|
||||||
m_hasCondition (hasCondition),
|
m_hasCondition (hasCondition),
|
||||||
m_hasSource (hasSource),
|
m_hasSource (hasSource),
|
||||||
m_source (std::move (source)),
|
m_source (source),
|
||||||
m_expectedValue (std::move (expectedValue)) {}
|
m_expectedValue (expectedValue) {}
|
||||||
|
|
||||||
CUserSettingBoolean* CUserSettingBoolean::fromJSON (nlohmann::json& data) {
|
const CUserSettingBoolean* CUserSettingBoolean::fromJSON (const nlohmann::json& data) {
|
||||||
bool hasCondition = false;
|
bool hasCondition = false;
|
||||||
bool hasSource = false;
|
bool hasSource = false;
|
||||||
bool defaultValue;
|
bool defaultValue;
|
||||||
@ -38,9 +39,9 @@ CUserSettingBoolean* CUserSettingBoolean::fromJSON (nlohmann::json& data) {
|
|||||||
source = *userIt;
|
source = *userIt;
|
||||||
} else {
|
} else {
|
||||||
hasCondition = true;
|
hasCondition = true;
|
||||||
source = *jsonFindRequired (userIt, "name", "Name for conditional setting must be present");
|
source = jsonFindRequired <std::string> (userIt, "name", "Name for conditional setting must be present");
|
||||||
expectedValue =
|
expectedValue =
|
||||||
*jsonFindRequired (userIt, "condition", "Condition for conditional setting must be present");
|
jsonFindRequired <std::string> (userIt, "condition", "Condition for conditional setting must be present");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sLog.error ("Boolean property doesn't have user member, this could mean an scripted value");
|
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);
|
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, "", "");
|
return new CUserSettingBoolean (false, false, value, "", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +64,7 @@ bool CUserSettingBoolean::getDefaultValue () const {
|
|||||||
return this->m_default;
|
return this->m_default;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CUserSettingBoolean::processValue (const std::vector<Projects::CProperty*>& properties) {
|
bool CUserSettingBoolean::processValue (const std::vector<const Projects::CProperty*>& properties) const {
|
||||||
if (!this->m_hasSource && !this->m_hasCondition)
|
if (!this->m_hasSource && !this->m_hasCondition)
|
||||||
return this->getDefaultValue ();
|
return this->getDefaultValue ();
|
||||||
|
|
||||||
|
@ -11,21 +11,21 @@ class CUserSettingBoolean : public CUserSettingValue {
|
|||||||
public:
|
public:
|
||||||
typedef bool data_type;
|
typedef bool data_type;
|
||||||
|
|
||||||
static CUserSettingBoolean* fromJSON (nlohmann::json& data);
|
static const CUserSettingBoolean* fromJSON (const nlohmann::json& data);
|
||||||
static CUserSettingBoolean* fromScalar (bool value);
|
static const CUserSettingBoolean* fromScalar (const bool value);
|
||||||
static std::string Type;
|
static std::string Type;
|
||||||
|
|
||||||
bool processValue (const std::vector<Projects::CProperty*>& properties);
|
[[nodiscard]] bool processValue (const std::vector<const Projects::CProperty*>& properties) const;
|
||||||
bool getDefaultValue () const;
|
[[nodiscard]] bool getDefaultValue () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CUserSettingBoolean (bool hasCondition, bool hasSource, bool defaultValue, std::string source,
|
CUserSettingBoolean (
|
||||||
std::string expectedValue);
|
bool hasCondition, bool hasSource, bool defaultValue, std::string source, std::string expectedValue);
|
||||||
|
|
||||||
bool m_default;
|
const bool m_default;
|
||||||
bool m_hasCondition;
|
const bool m_hasCondition;
|
||||||
bool m_hasSource;
|
const bool m_hasSource;
|
||||||
std::string m_source;
|
const std::string m_source;
|
||||||
std::string m_expectedValue;
|
const std::string m_expectedValue;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::UserSettings
|
} // namespace WallpaperEngine::Core::UserSettings
|
@ -9,16 +9,17 @@ using namespace WallpaperEngine::Core;
|
|||||||
using namespace WallpaperEngine::Core::Projects;
|
using namespace WallpaperEngine::Core::Projects;
|
||||||
using namespace WallpaperEngine::Core::UserSettings;
|
using namespace WallpaperEngine::Core::UserSettings;
|
||||||
|
|
||||||
CUserSettingFloat::CUserSettingFloat (bool hasCondition, bool hasSource, double defaultValue, std::string source,
|
CUserSettingFloat::CUserSettingFloat (
|
||||||
std::string expectedValue) :
|
bool hasCondition, bool hasSource, double defaultValue, std::string source, std::string expectedValue
|
||||||
|
) :
|
||||||
CUserSettingValue (Type),
|
CUserSettingValue (Type),
|
||||||
m_default (defaultValue),
|
m_default (defaultValue),
|
||||||
m_hasCondition (hasCondition),
|
m_hasCondition (hasCondition),
|
||||||
m_hasSource (hasSource),
|
m_hasSource (hasSource),
|
||||||
m_source (std::move (source)),
|
m_source (source),
|
||||||
m_expectedValue (std::move (expectedValue)) {}
|
m_expectedValue (expectedValue) {}
|
||||||
|
|
||||||
CUserSettingFloat* CUserSettingFloat::fromJSON (nlohmann::json& data) {
|
const CUserSettingFloat* CUserSettingFloat::fromJSON (const nlohmann::json& data) {
|
||||||
double defaultValue;
|
double defaultValue;
|
||||||
std::string source;
|
std::string source;
|
||||||
std::string expectedValue;
|
std::string expectedValue;
|
||||||
@ -35,9 +36,9 @@ CUserSettingFloat* CUserSettingFloat::fromJSON (nlohmann::json& data) {
|
|||||||
source = *userIt;
|
source = *userIt;
|
||||||
} else {
|
} else {
|
||||||
hasCondition = true;
|
hasCondition = true;
|
||||||
source = *jsonFindRequired (userIt, "name", "Name for conditional setting must be present");
|
source = jsonFindRequired <std::string> (userIt, "name", "Name for conditional setting must be present");
|
||||||
expectedValue =
|
expectedValue =
|
||||||
*jsonFindRequired (userIt, "condition", "Condition for conditional setting must be present");
|
jsonFindRequired <std::string> (userIt, "condition", "Condition for conditional setting must be present");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sLog.error ("Float property doesn't have user member, this could mean an scripted value");
|
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);
|
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, "", "");
|
return new CUserSettingFloat (false, false, value, "", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ double CUserSettingFloat::getDefaultValue () const {
|
|||||||
return this->m_default;
|
return this->m_default;
|
||||||
}
|
}
|
||||||
|
|
||||||
double CUserSettingFloat::processValue (const std::vector<Projects::CProperty*>& properties) {
|
double CUserSettingFloat::processValue (const std::vector<const Projects::CProperty*>& properties) const {
|
||||||
if (!this->m_hasSource && !this->m_hasCondition)
|
if (!this->m_hasSource && !this->m_hasCondition)
|
||||||
return this->getDefaultValue ();
|
return this->getDefaultValue ();
|
||||||
|
|
||||||
|
@ -11,21 +11,21 @@ class CUserSettingFloat : public CUserSettingValue {
|
|||||||
public:
|
public:
|
||||||
typedef double data_type;
|
typedef double data_type;
|
||||||
|
|
||||||
static CUserSettingFloat* fromJSON (nlohmann::json& data);
|
static const CUserSettingFloat* fromJSON (const nlohmann::json& data);
|
||||||
static CUserSettingFloat* fromScalar (double value);
|
static const CUserSettingFloat* fromScalar (const double value);
|
||||||
static std::string Type;
|
static std::string Type;
|
||||||
|
|
||||||
double processValue (const std::vector<Projects::CProperty*>& properties);
|
[[nodiscard]] double processValue (const std::vector<const Projects::CProperty*>& properties) const;
|
||||||
double getDefaultValue () const;
|
[[nodiscard]] double getDefaultValue () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CUserSettingFloat (bool hasCondition, bool hasSource, double defaultValue, std::string source,
|
CUserSettingFloat (
|
||||||
std::string expectedValue);
|
bool hasCondition, bool hasSource, double defaultValue, std::string source, std::string expectedValue);
|
||||||
|
|
||||||
double m_default;
|
const double m_default;
|
||||||
bool m_hasCondition;
|
const bool m_hasCondition;
|
||||||
bool m_hasSource;
|
const bool m_hasSource;
|
||||||
std::string m_source;
|
const std::string m_source;
|
||||||
std::string m_expectedValue;
|
const std::string m_expectedValue;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::UserSettings
|
} // namespace WallpaperEngine::Core::UserSettings
|
@ -4,4 +4,5 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::UserSettings;
|
using namespace WallpaperEngine::Core::UserSettings;
|
||||||
|
|
||||||
CUserSettingValue::CUserSettingValue (std::string type) : m_type (std::move (type)) {}
|
CUserSettingValue::CUserSettingValue (std::string type) :
|
||||||
|
m_type (type) {}
|
@ -15,7 +15,7 @@ class CUserSettingValue {
|
|||||||
return reinterpret_cast<T*> (this);
|
return reinterpret_cast<T*> (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> bool is () {
|
template <class T> bool is () const {
|
||||||
return this->m_type == T::Type;
|
return this->m_type == T::Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,6 +23,6 @@ class CUserSettingValue {
|
|||||||
explicit CUserSettingValue (std::string type);
|
explicit CUserSettingValue (std::string type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_type;
|
const std::string m_type;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::UserSettings
|
} // namespace WallpaperEngine::Core::UserSettings
|
||||||
|
@ -10,16 +10,17 @@ using namespace WallpaperEngine::Core;
|
|||||||
using namespace WallpaperEngine::Core::Projects;
|
using namespace WallpaperEngine::Core::Projects;
|
||||||
using namespace WallpaperEngine::Core::UserSettings;
|
using namespace WallpaperEngine::Core::UserSettings;
|
||||||
|
|
||||||
CUserSettingVector3::CUserSettingVector3 (bool hasCondition, bool hasSource, glm::vec3 defaultValue, std::string source,
|
CUserSettingVector3::CUserSettingVector3 (
|
||||||
std::string expectedValue) :
|
bool hasCondition, bool hasSource, glm::vec3 defaultValue, std::string source, std::string expectedValue
|
||||||
|
) :
|
||||||
CUserSettingValue (Type),
|
CUserSettingValue (Type),
|
||||||
m_default (defaultValue),
|
m_default (defaultValue),
|
||||||
m_hasCondition (hasCondition),
|
m_hasCondition (hasCondition),
|
||||||
m_hasSource (hasSource),
|
m_hasSource (hasSource),
|
||||||
m_source (std::move (source)),
|
m_source (source),
|
||||||
m_expectedValue (std::move (expectedValue)) {}
|
m_expectedValue (expectedValue) {}
|
||||||
|
|
||||||
CUserSettingVector3* CUserSettingVector3::fromJSON (nlohmann::json& data) {
|
const CUserSettingVector3* CUserSettingVector3::fromJSON (const nlohmann::json& data) {
|
||||||
bool hasCondition = false;
|
bool hasCondition = false;
|
||||||
bool hasSource = false;
|
bool hasSource = false;
|
||||||
glm::vec3 defaultValue;
|
glm::vec3 defaultValue;
|
||||||
@ -29,17 +30,16 @@ CUserSettingVector3* CUserSettingVector3::fromJSON (nlohmann::json& data) {
|
|||||||
if (data.is_object ()) {
|
if (data.is_object ()) {
|
||||||
hasSource = true;
|
hasSource = true;
|
||||||
auto userIt = data.find ("user");
|
auto userIt = data.find ("user");
|
||||||
defaultValue = WallpaperEngine::Core::aToColorf (
|
defaultValue = jsonFindDefault (data, "value", glm::vec3()); // is this default value right?
|
||||||
jsonFindDefault<std::string> (data, "value", "").c_str ()); // is this default value right?
|
|
||||||
|
|
||||||
if (userIt != data.end ()) {
|
if (userIt != data.end ()) {
|
||||||
if (userIt->is_string ()) {
|
if (userIt->is_string ()) {
|
||||||
source = *userIt;
|
source = *userIt;
|
||||||
} else {
|
} else {
|
||||||
hasCondition = true;
|
hasCondition = true;
|
||||||
source = *jsonFindRequired (userIt, "name", "Name for conditional setting must be present");
|
source = jsonFindRequired <std::string> (userIt, "name", "Name for conditional setting must be present");
|
||||||
expectedValue =
|
expectedValue =
|
||||||
*jsonFindRequired (userIt, "condition", "Condition for conditional setting must be present");
|
jsonFindRequired <std::string> (userIt, "condition", "Condition for conditional setting must be present");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sLog.error ("Vector property doesn't have user member, this could mean an scripted value");
|
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);
|
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, "", "");
|
return new CUserSettingVector3 (false, false, value, "", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 CUserSettingVector3::getDefaultValue () const {
|
const glm::vec3& CUserSettingVector3::getDefaultValue () const {
|
||||||
return this->m_default;
|
return this->m_default;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 CUserSettingVector3::processValue (const std::vector<Projects::CProperty*>& properties) {
|
const glm::vec3& CUserSettingVector3::processValue (const std::vector<const Projects::CProperty*>& properties) const {
|
||||||
if (!this->m_hasSource && !this->m_hasCondition)
|
if (!this->m_hasSource && !this->m_hasCondition)
|
||||||
return this->getDefaultValue ();
|
return this->getDefaultValue ();
|
||||||
|
|
||||||
|
@ -13,21 +13,21 @@ class CUserSettingVector3 : public CUserSettingValue {
|
|||||||
public:
|
public:
|
||||||
typedef glm::vec3 data_type;
|
typedef glm::vec3 data_type;
|
||||||
|
|
||||||
static CUserSettingVector3* fromJSON (nlohmann::json& data);
|
static const CUserSettingVector3* fromJSON (const nlohmann::json& data);
|
||||||
static CUserSettingVector3* fromScalar (glm::vec3 value);
|
static const CUserSettingVector3* fromScalar (const glm::vec3 value);
|
||||||
static std::string Type;
|
static std::string Type;
|
||||||
|
|
||||||
glm::vec3 processValue (const std::vector<Projects::CProperty*>& properties);
|
[[nodiscard]] const glm::vec3& processValue (const std::vector<const Projects::CProperty*>& properties) const;
|
||||||
glm::vec3 getDefaultValue () const;
|
[[nodiscard]] const glm::vec3& getDefaultValue () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CUserSettingVector3 (bool hasCondition, bool hasSource, glm::vec3 defaultValue, std::string source,
|
CUserSettingVector3 (
|
||||||
std::string expectedValue);
|
bool hasCondition, bool hasSource, glm::vec3 defaultValue, std::string source, std::string expectedValue);
|
||||||
|
|
||||||
glm::vec3 m_default;
|
const glm::vec3 m_default;
|
||||||
bool m_hasCondition;
|
const bool m_hasCondition;
|
||||||
bool m_hasSource;
|
const bool m_hasSource;
|
||||||
std::string m_source;
|
const std::string m_source;
|
||||||
std::string m_expectedValue;
|
const std::string m_expectedValue;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core::UserSettings
|
} // namespace WallpaperEngine::Core::UserSettings
|
@ -8,12 +8,14 @@
|
|||||||
using namespace WallpaperEngine::Core;
|
using namespace WallpaperEngine::Core;
|
||||||
using namespace WallpaperEngine::Core::Wallpapers;
|
using namespace WallpaperEngine::Core::Wallpapers;
|
||||||
|
|
||||||
CScene::CScene (CProject& project, CContainer* container, Scenes::CCamera* camera, glm::vec3 ambientColor,
|
CScene::CScene (
|
||||||
CUserSettingBoolean* bloom, CUserSettingFloat* bloomStrength, CUserSettingFloat* bloomThreshold,
|
const CProject& project, const CContainer* container, const Scenes::CCamera* camera, glm::vec3 ambientColor,
|
||||||
bool cameraFade, bool cameraParallax, double cameraParallaxAmount, double cameraParallaxDelay,
|
const CUserSettingBoolean* bloom, const CUserSettingFloat* bloomStrength, const CUserSettingFloat* bloomThreshold,
|
||||||
double cameraParallaxMouseInfluence, bool cameraPreview, bool cameraShake, double cameraShakeAmplitude,
|
bool cameraFade, bool cameraParallax, double cameraParallaxAmount, double cameraParallaxDelay,
|
||||||
double cameraShakeRoughness, double cameraShakeSpeed, CUserSettingVector3* clearColor,
|
double cameraParallaxMouseInfluence, bool cameraPreview, bool cameraShake, double cameraShakeAmplitude,
|
||||||
Scenes::CProjection* orthogonalProjection, glm::vec3 skylightColor) :
|
double cameraShakeRoughness, double cameraShakeSpeed, const CUserSettingVector3* clearColor,
|
||||||
|
const Scenes::CProjection* orthogonalProjection, glm::vec3 skylightColor
|
||||||
|
) :
|
||||||
CWallpaper (Type, project),
|
CWallpaper (Type, project),
|
||||||
m_container (container),
|
m_container (container),
|
||||||
m_camera (camera),
|
m_camera (camera),
|
||||||
@ -35,41 +37,36 @@ CScene::CScene (CProject& project, CContainer* container, Scenes::CCamera* camer
|
|||||||
m_orthogonalProjection (orthogonalProjection),
|
m_orthogonalProjection (orthogonalProjection),
|
||||||
m_skylightColor (skylightColor) {}
|
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));
|
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 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");
|
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
|
// TODO: FIND IF THESE DEFAULTS ARE SENSIBLE OR NOT AND PERFORM PROPER VALIDATION WHEN CAMERA PREVIEW AND CAMERA
|
||||||
// PARALLAX ARE PRESENT
|
// PARALLAX ARE PRESENT
|
||||||
const auto ambientcolor = jsonFindDefault<std::string> (*general_it, "ambientcolor", "0 0 0");
|
|
||||||
const auto bloom = jsonFindUserConfig<CUserSettingBoolean> (*general_it, "bloom", false);
|
|
||||||
const auto bloomstrength = jsonFindUserConfig<CUserSettingFloat> (*general_it, "bloomstrength", 0.0);
|
|
||||||
const auto bloomthreshold = jsonFindUserConfig<CUserSettingFloat> (*general_it, "bloomthreshold", 0.0);
|
|
||||||
const auto camerafade = jsonFindDefault<bool> (*general_it, "camerafade", false);
|
|
||||||
const auto cameraparallax = jsonFindDefault<bool> (*general_it, "cameraparallax", true);
|
|
||||||
const auto cameraparallaxamount = jsonFindDefault<double> (*general_it, "cameraparallaxamount", 1.0f);
|
|
||||||
const auto cameraparallaxdelay = jsonFindDefault<double> (*general_it, "cameraparallaxdelay", 0.0f);
|
|
||||||
const auto cameraparallaxmouseinfluence =
|
|
||||||
jsonFindDefault<double> (*general_it, "cameraparallaxmouseinfluence", 1.0f);
|
|
||||||
const auto camerapreview = jsonFindDefault<bool> (*general_it, "camerapreview", false);
|
|
||||||
const auto camerashake = jsonFindDefault<bool> (*general_it, "camerashake", false);
|
|
||||||
const auto camerashakeamplitude = jsonFindDefault<double> (*general_it, "camerashakeamplitude", 0.0f);
|
|
||||||
const auto camerashakeroughness = jsonFindDefault<double> (*general_it, "camerashakeroughness", 0.0f);
|
|
||||||
const auto camerashakespeed = jsonFindDefault<double> (*general_it, "camerashakespeed", 0.0f);
|
|
||||||
const auto clearcolor = jsonFindUserConfig<CUserSettingVector3> (*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<std::string> (*general_it, "skylightcolor", "0 0 0");
|
|
||||||
|
|
||||||
auto* scene = new CScene (
|
auto* scene = new CScene (
|
||||||
project, container, Scenes::CCamera::fromJSON (*camera_it), WallpaperEngine::Core::aToColorf (ambientcolor),
|
project, container,
|
||||||
bloom, bloomstrength, bloomthreshold, camerafade, cameraparallax, cameraparallaxamount, cameraparallaxdelay,
|
Scenes::CCamera::fromJSON (jsonFindRequired (content, "camera", "Scenes must have a defined camera")),
|
||||||
cameraparallaxmouseinfluence, camerapreview, camerashake, camerashakeamplitude, camerashakeroughness,
|
jsonFindDefault<glm::vec3> (*general_it, "ambientcolor", glm::vec3 (0, 0, 0)),
|
||||||
camerashakespeed, clearcolor, Scenes::CProjection::fromJSON (*orthogonalprojection_it),
|
jsonFindUserConfig<CUserSettingBoolean> (*general_it, "bloom", false),
|
||||||
WallpaperEngine::Core::aToColorf (skylightcolor));
|
jsonFindUserConfig<CUserSettingFloat> (*general_it, "bloomstrength", 0.0),
|
||||||
|
jsonFindUserConfig<CUserSettingFloat> (*general_it, "bloomthreshold", 0.0),
|
||||||
|
jsonFindDefault<bool> (*general_it, "camerafade", false),
|
||||||
|
jsonFindDefault<bool> (*general_it, "cameraparallax", true),
|
||||||
|
jsonFindDefault<double> (*general_it, "cameraparallaxamount", 1.0f),
|
||||||
|
jsonFindDefault<double> (*general_it, "cameraparallaxdelay", 0.0f),
|
||||||
|
jsonFindDefault<double> (*general_it, "cameraparallaxmouseinfluence", 1.0f),
|
||||||
|
jsonFindDefault<bool> (*general_it, "camerapreview", false),
|
||||||
|
jsonFindDefault<bool> (*general_it, "camerashake", false),
|
||||||
|
jsonFindDefault<double> (*general_it, "camerashakeamplitude", 0.0f),
|
||||||
|
jsonFindDefault<double> (*general_it, "camerashakeroughness", 0.0f),
|
||||||
|
jsonFindDefault<double> (*general_it, "camerashakespeed", 0.0f),
|
||||||
|
jsonFindUserConfig<CUserSettingVector3> (*general_it, "clearcolor", {1, 1, 1}),
|
||||||
|
Scenes::CProjection::fromJSON (jsonFindRequired (*general_it, "orthogonalprojection", "General section must have orthogonal projection info")),
|
||||||
|
jsonFindDefault<glm::vec3> (*general_it, "skylightcolor", glm::vec3 (0, 0, 0))
|
||||||
|
);
|
||||||
|
|
||||||
for (const auto& cur : *objects_it)
|
for (const auto& cur : *objects_it)
|
||||||
scene->insertObject (CObject::fromJSON (cur, scene, container));
|
scene->insertObject (CObject::fromJSON (cur, scene, container));
|
||||||
@ -77,23 +74,23 @@ CScene* CScene::fromFile (const std::string& filename, CProject& project, CConta
|
|||||||
return scene;
|
return scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::map<uint32_t, CObject*>& CScene::getObjects () const {
|
const std::map<uint32_t, const CObject*>& CScene::getObjects () const {
|
||||||
return this->m_objects;
|
return this->m_objects;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<CObject*>& CScene::getObjectsByRenderOrder () const {
|
const std::vector<const CObject*>& CScene::getObjectsByRenderOrder () const {
|
||||||
return this->m_objectsByRenderOrder;
|
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
|
/// TODO: XXXHACK -- TO REMOVE WHEN PARTICLE SUPPORT IS PROPERLY IMPLEMENTED
|
||||||
if (object != nullptr) {
|
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);
|
this->m_objectsByRenderOrder.emplace_back (object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CContainer* CScene::getContainer () {
|
const CContainer* CScene::getContainer () const {
|
||||||
return this->m_container;
|
return this->m_container;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +102,7 @@ const glm::vec3& CScene::getAmbientColor () const {
|
|||||||
return this->m_ambientColor;
|
return this->m_ambientColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool CScene::isBloom () const {
|
bool CScene::isBloom () const {
|
||||||
return this->m_bloom->processValue (this->getProject ().getProperties ());
|
return this->m_bloom->processValue (this->getProject ().getProperties ());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,51 +114,51 @@ double CScene::getBloomThreshold () const {
|
|||||||
return this->m_bloomThreshold->processValue (this->getProject ().getProperties ());
|
return this->m_bloomThreshold->processValue (this->getProject ().getProperties ());
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool CScene::isCameraFade () const {
|
bool CScene::isCameraFade () const {
|
||||||
return this->m_cameraFade;
|
return this->m_cameraFade;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool CScene::isCameraParallax () const {
|
bool CScene::isCameraParallax () const {
|
||||||
return this->m_cameraParallax;
|
return this->m_cameraParallax;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double CScene::getCameraParallaxAmount () const {
|
double CScene::getCameraParallaxAmount () const {
|
||||||
return this->m_cameraParallaxAmount;
|
return this->m_cameraParallaxAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double CScene::getCameraParallaxDelay () const {
|
double CScene::getCameraParallaxDelay () const {
|
||||||
return this->m_cameraParallaxDelay;
|
return this->m_cameraParallaxDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double CScene::getCameraParallaxMouseInfluence () const {
|
double CScene::getCameraParallaxMouseInfluence () const {
|
||||||
return this->m_cameraParallaxMouseInfluence;
|
return this->m_cameraParallaxMouseInfluence;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool CScene::isCameraPreview () const {
|
bool CScene::isCameraPreview () const {
|
||||||
return this->m_cameraPreview;
|
return this->m_cameraPreview;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool CScene::isCameraShake () const {
|
bool CScene::isCameraShake () const {
|
||||||
return this->m_cameraShake;
|
return this->m_cameraShake;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double CScene::getCameraShakeAmplitude () const {
|
double CScene::getCameraShakeAmplitude () const {
|
||||||
return this->m_cameraShakeAmplitude;
|
return this->m_cameraShakeAmplitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double CScene::getCameraShakeRoughness () const {
|
double CScene::getCameraShakeRoughness () const {
|
||||||
return this->m_cameraShakeRoughness;
|
return this->m_cameraShakeRoughness;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double CScene::getCameraShakeSpeed () const {
|
double CScene::getCameraShakeSpeed () const {
|
||||||
return this->m_cameraShakeSpeed;
|
return this->m_cameraShakeSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 CScene::getClearColor () const {
|
const glm::vec3& CScene::getClearColor () const {
|
||||||
return this->m_clearColor->processValue (this->getProject ().getProperties ());
|
return this->m_clearColor->processValue (this->getProject ().getProperties ());
|
||||||
}
|
}
|
||||||
|
|
||||||
Scenes::CProjection* CScene::getOrthogonalProjection () const {
|
const Scenes::CProjection* CScene::getOrthogonalProjection () const {
|
||||||
return this->m_orthogonalProjection;
|
return this->m_orthogonalProjection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,70 +17,71 @@ using json = nlohmann::json;
|
|||||||
|
|
||||||
class CScene : public CWallpaper {
|
class CScene : public CWallpaper {
|
||||||
public:
|
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<uint32_t, CObject*>& getObjects () const;
|
[[nodiscard]] const std::map<uint32_t, const CObject*>& getObjects () const;
|
||||||
const std::vector<CObject*>& getObjectsByRenderOrder () const;
|
[[nodiscard]] const std::vector<const CObject*>& getObjectsByRenderOrder () const;
|
||||||
|
|
||||||
const glm::vec3& getAmbientColor () const;
|
[[nodiscard]] const glm::vec3& getAmbientColor () const;
|
||||||
const bool isBloom () const;
|
[[nodiscard]] bool isBloom () const;
|
||||||
double getBloomStrength () const;
|
[[nodiscard]] double getBloomStrength () const;
|
||||||
double getBloomThreshold () const;
|
[[nodiscard]] double getBloomThreshold () const;
|
||||||
const bool isCameraFade () const;
|
[[nodiscard]] bool isCameraFade () const;
|
||||||
const bool isCameraParallax () const;
|
[[nodiscard]] bool isCameraParallax () const;
|
||||||
const double getCameraParallaxAmount () const;
|
[[nodiscard]] double getCameraParallaxAmount () const;
|
||||||
const double getCameraParallaxDelay () const;
|
[[nodiscard]] double getCameraParallaxDelay () const;
|
||||||
const double getCameraParallaxMouseInfluence () const;
|
[[nodiscard]] double getCameraParallaxMouseInfluence () const;
|
||||||
const bool isCameraPreview () const;
|
[[nodiscard]] bool isCameraPreview () const;
|
||||||
const bool isCameraShake () const;
|
[[nodiscard]] bool isCameraShake () const;
|
||||||
const double getCameraShakeAmplitude () const;
|
[[nodiscard]] double getCameraShakeAmplitude () const;
|
||||||
const double getCameraShakeRoughness () const;
|
[[nodiscard]] double getCameraShakeRoughness () const;
|
||||||
const double getCameraShakeSpeed () const;
|
[[nodiscard]] double getCameraShakeSpeed () const;
|
||||||
glm::vec3 getClearColor () const;
|
[[nodiscard]] const glm::vec3& getClearColor () const;
|
||||||
Scenes::CProjection* getOrthogonalProjection () const;
|
[[nodiscard]] const Scenes::CProjection* getOrthogonalProjection () const;
|
||||||
const glm::vec3& getSkylightColor () const;
|
[[nodiscard]] const glm::vec3& getSkylightColor () const;
|
||||||
const Scenes::CCamera* getCamera () const;
|
[[nodiscard]] const Scenes::CCamera* getCamera () const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class CWallpaper;
|
friend class CWallpaper;
|
||||||
|
|
||||||
CScene (CProject& project, CContainer* container, Scenes::CCamera* camera, glm::vec3 ambientColor,
|
CScene (
|
||||||
CUserSettingBoolean* bloom, CUserSettingFloat* bloomStrength, CUserSettingFloat* bloomThreshold,
|
const CProject& project, const CContainer* container, const Scenes::CCamera* camera, glm::vec3 ambientColor,
|
||||||
bool cameraFade, bool cameraParallax, double cameraParallaxAmount, double cameraParallaxDelay,
|
const CUserSettingBoolean* bloom, const CUserSettingFloat* bloomStrength, const CUserSettingFloat* bloomThreshold,
|
||||||
double cameraParallaxMouseInfluence, bool cameraPreview, bool cameraShake, double cameraShakeAmplitude,
|
bool cameraFade, bool cameraParallax, double cameraParallaxAmount, double cameraParallaxDelay,
|
||||||
double cameraShakeRoughness, double cameraShakeSpeed, CUserSettingVector3* clearColor,
|
double cameraParallaxMouseInfluence, bool cameraPreview, bool cameraShake, double cameraShakeAmplitude,
|
||||||
Scenes::CProjection* orthogonalProjection, glm::vec3 skylightColor);
|
double cameraShakeRoughness, double cameraShakeSpeed, const CUserSettingVector3* clearColor,
|
||||||
|
const Scenes::CProjection* orthogonalProjection, glm::vec3 skylightColor);
|
||||||
|
|
||||||
static const std::string Type;
|
static const std::string Type;
|
||||||
|
|
||||||
void insertObject (CObject* object);
|
void insertObject (const CObject* object);
|
||||||
|
|
||||||
CContainer* getContainer ();
|
const CContainer* getContainer () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CContainer* m_container;
|
const CContainer* m_container;
|
||||||
Scenes::CCamera* m_camera;
|
const Scenes::CCamera* m_camera;
|
||||||
|
|
||||||
// data from general section on the json
|
// data from general section on the json
|
||||||
glm::vec3 m_ambientColor;
|
const glm::vec3 m_ambientColor;
|
||||||
CUserSettingBoolean* m_bloom;
|
const CUserSettingBoolean* m_bloom;
|
||||||
CUserSettingFloat* m_bloomStrength;
|
const CUserSettingFloat* m_bloomStrength;
|
||||||
CUserSettingFloat* m_bloomThreshold;
|
const CUserSettingFloat* m_bloomThreshold;
|
||||||
bool m_cameraFade;
|
const bool m_cameraFade;
|
||||||
bool m_cameraParallax;
|
const bool m_cameraParallax;
|
||||||
double m_cameraParallaxAmount;
|
const double m_cameraParallaxAmount;
|
||||||
double m_cameraParallaxDelay;
|
const double m_cameraParallaxDelay;
|
||||||
double m_cameraParallaxMouseInfluence;
|
const double m_cameraParallaxMouseInfluence;
|
||||||
bool m_cameraPreview;
|
const bool m_cameraPreview;
|
||||||
bool m_cameraShake;
|
const bool m_cameraShake;
|
||||||
double m_cameraShakeAmplitude;
|
const double m_cameraShakeAmplitude;
|
||||||
double m_cameraShakeRoughness;
|
const double m_cameraShakeRoughness;
|
||||||
double m_cameraShakeSpeed;
|
const double m_cameraShakeSpeed;
|
||||||
CUserSettingVector3* m_clearColor;
|
const CUserSettingVector3* m_clearColor;
|
||||||
Scenes::CProjection* m_orthogonalProjection;
|
const Scenes::CProjection* m_orthogonalProjection;
|
||||||
glm::vec3 m_skylightColor;
|
const glm::vec3 m_skylightColor;
|
||||||
|
|
||||||
std::map<uint32_t, CObject*> m_objects;
|
std::map<uint32_t, const CObject*> m_objects;
|
||||||
std::vector<CObject*> m_objectsByRenderOrder;
|
std::vector<const CObject*> m_objectsByRenderOrder;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Core
|
} // namespace WallpaperEngine::Core
|
||||||
|
@ -5,11 +5,11 @@
|
|||||||
using namespace WallpaperEngine::Core;
|
using namespace WallpaperEngine::Core;
|
||||||
using namespace WallpaperEngine::Core::Wallpapers;
|
using namespace WallpaperEngine::Core::Wallpapers;
|
||||||
|
|
||||||
CVideo::CVideo (std::string filename, CProject& project) :
|
CVideo::CVideo (std::string filename, const CProject& project) :
|
||||||
CWallpaper (Type, 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;
|
return this->m_filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,9 +13,9 @@ extern "C" {
|
|||||||
namespace WallpaperEngine::Core::Wallpapers {
|
namespace WallpaperEngine::Core::Wallpapers {
|
||||||
class CVideo : public CWallpaper {
|
class CVideo : public CWallpaper {
|
||||||
public:
|
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:
|
protected:
|
||||||
friend class CWallpaper;
|
friend class CWallpaper;
|
||||||
|
@ -5,10 +5,12 @@
|
|||||||
using namespace WallpaperEngine::Core;
|
using namespace WallpaperEngine::Core;
|
||||||
using namespace WallpaperEngine::Core::Wallpapers;
|
using namespace WallpaperEngine::Core::Wallpapers;
|
||||||
|
|
||||||
const std::string& CWeb::getFilename () {
|
const std::string& CWeb::getFilename () const {
|
||||||
return this->m_filename;
|
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";
|
const std::string CWeb::Type = "web";
|
||||||
|
@ -18,12 +18,11 @@ extern "C"
|
|||||||
|
|
||||||
namespace WallpaperEngine::Core::Wallpapers
|
namespace WallpaperEngine::Core::Wallpapers
|
||||||
{
|
{
|
||||||
class CWeb : public CWallpaper
|
class CWeb : public CWallpaper {
|
||||||
{
|
|
||||||
public:
|
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:
|
protected:
|
||||||
friend class CWallpaper;
|
friend class CWallpaper;
|
||||||
|
@ -6,7 +6,7 @@ using namespace WallpaperEngine;
|
|||||||
using namespace WallpaperEngine::Render;
|
using namespace WallpaperEngine::Render;
|
||||||
using namespace WallpaperEngine::Render::Wallpapers;
|
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),
|
Helpers::CContextAware (scene),
|
||||||
m_type (std::move (type)),
|
m_type (std::move (type)),
|
||||||
m_scene (scene),
|
m_scene (scene),
|
||||||
@ -16,7 +16,7 @@ Wallpapers::CScene* CObject::getScene () const {
|
|||||||
return this->m_scene;
|
return this->m_scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
CContainer* CObject::getContainer () const {
|
const CContainer* CObject::getContainer () const {
|
||||||
return this->getScene ()->getContainer ();
|
return this->getScene ()->getContainer ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,17 +31,17 @@ class CObject : public Helpers::CContextAware {
|
|||||||
virtual void render () = 0;
|
virtual void render () = 0;
|
||||||
|
|
||||||
[[nodiscard]] Wallpapers::CScene* getScene () const;
|
[[nodiscard]] Wallpapers::CScene* getScene () const;
|
||||||
[[nodiscard]] CContainer* getContainer () const;
|
[[nodiscard]] const CContainer* getContainer () const;
|
||||||
[[nodiscard]] int getId () const;
|
[[nodiscard]] int getId () const;
|
||||||
|
|
||||||
protected:
|
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;
|
~CObject () override = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_type;
|
std::string m_type;
|
||||||
|
|
||||||
Wallpapers::CScene* m_scene;
|
Wallpapers::CScene* m_scene;
|
||||||
Core::CObject* m_object;
|
const Core::CObject* m_object;
|
||||||
};
|
};
|
||||||
} // namespace WallpaperEngine::Render
|
} // namespace WallpaperEngine::Render
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Render;
|
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) :
|
CAudioContext& audioContext, const CWallpaperState::TextureUVsScaling& scalingMode) :
|
||||||
CContextAware (context),
|
CContextAware (context),
|
||||||
m_wallpaperData (wallpaperData),
|
m_wallpaperData (wallpaperData),
|
||||||
@ -49,11 +49,11 @@ CWallpaper::CWallpaper (Core::CWallpaper* wallpaperData, std::string type, CRend
|
|||||||
|
|
||||||
CWallpaper::~CWallpaper () = default;
|
CWallpaper::~CWallpaper () = default;
|
||||||
|
|
||||||
CContainer* CWallpaper::getContainer () const {
|
const CContainer* CWallpaper::getContainer () const {
|
||||||
return this->m_wallpaperData->getProject ().getContainer ();
|
return this->m_wallpaperData->getProject ().getContainer ();
|
||||||
}
|
}
|
||||||
|
|
||||||
WallpaperEngine::Core::CWallpaper* CWallpaper::getWallpaperData () const {
|
const WallpaperEngine::Core::CWallpaper* CWallpaper::getWallpaperData () const {
|
||||||
return this->m_wallpaperData;
|
return this->m_wallpaperData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,7 +281,7 @@ CFBO* CWallpaper::getFBO () const {
|
|||||||
return this->m_sceneFBO;
|
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,
|
CAudioContext& audioContext, WebBrowser::CWebBrowserContext& browserContext,
|
||||||
const CWallpaperState::TextureUVsScaling& scalingMode) {
|
const CWallpaperState::TextureUVsScaling& scalingMode) {
|
||||||
if (wallpaper->is<Core::Wallpapers::CScene> ())
|
if (wallpaper->is<Core::Wallpapers::CScene> ())
|
||||||
|
@ -59,7 +59,7 @@ class CWallpaper : public Helpers::CContextAware {
|
|||||||
/**
|
/**
|
||||||
* @return The container to resolve files for this wallpaper
|
* @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
|
* @return The current audio context for this wallpaper
|
||||||
@ -146,12 +146,12 @@ class CWallpaper : public Helpers::CContextAware {
|
|||||||
*
|
*
|
||||||
* @return
|
* @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,
|
WebBrowser::CWebBrowserContext& browserContext,
|
||||||
const CWallpaperState::TextureUVsScaling& scalingMode);
|
const CWallpaperState::TextureUVsScaling& scalingMode);
|
||||||
|
|
||||||
protected:
|
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);
|
const CWallpaperState::TextureUVsScaling& scalingMode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -164,9 +164,9 @@ class CWallpaper : public Helpers::CContextAware {
|
|||||||
*/
|
*/
|
||||||
void setupFramebuffers ();
|
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 */
|
/** The FBO used for scene output */
|
||||||
CFBO* m_sceneFBO;
|
CFBO* m_sceneFBO;
|
||||||
|
@ -3,7 +3,9 @@
|
|||||||
using namespace WallpaperEngine::Render;
|
using namespace WallpaperEngine::Render;
|
||||||
using namespace WallpaperEngine::Render::Objects;
|
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->generateFBOs ();
|
||||||
this->generatePasses ();
|
this->generatePasses ();
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ class CImage;
|
|||||||
|
|
||||||
class CEffect {
|
class CEffect {
|
||||||
public:
|
public:
|
||||||
CEffect (CImage* image, Core::Objects::CEffect* effect);
|
CEffect (CImage* image, const Core::Objects::CEffect* effect);
|
||||||
|
|
||||||
CImage* getImage () const;
|
CImage* getImage () const;
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ class CEffect {
|
|||||||
void generateFBOs ();
|
void generateFBOs ();
|
||||||
|
|
||||||
CImage* m_image;
|
CImage* m_image;
|
||||||
Core::Objects::CEffect* m_effect;
|
const Core::Objects::CEffect* m_effect;
|
||||||
|
|
||||||
std::vector<CFBO*> m_fbos;
|
std::vector<CFBO*> m_fbos;
|
||||||
std::vector<Effects::CMaterial*> m_materials;
|
std::vector<Effects::CMaterial*> m_materials;
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user