chore: cleanup of the core part of the project

This commit is contained in:
Almamu 2025-04-14 03:19:25 +02:00
parent 5e95fda88b
commit 1db86053ce
114 changed files with 1710 additions and 1235 deletions

View File

@ -296,7 +296,7 @@ void CApplicationContext::validateAssets () {
}
}
void CApplicationContext::validateScreenshot () {
void CApplicationContext::validateScreenshot () const {
if (!this->settings.screenshot.take)
return;

View File

@ -123,7 +123,7 @@ class CApplicationContext {
/**
* Validates the screenshot settings
*/
void validateScreenshot ();
void validateScreenshot () const;
/**
* Validates a background parameter and returns the real bgIdOrPath to it

View File

@ -1 +0,0 @@
#include "CApplicationState.h"

View File

@ -211,7 +211,9 @@ void CWallpaperApplication::setupProperties () {
}
void CWallpaperApplication::setupBrowser () {
bool anyWebProject = std::any_of (this->m_backgrounds.begin (), this->m_backgrounds.end (), [](std::pair<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> ();
});
@ -403,10 +405,13 @@ void CWallpaperApplication::prepareOutputs () {
// set all the specific wallpapers required
for (const auto& [background, info] : this->m_backgrounds) {
m_renderContext->setWallpaper (background,
m_renderContext->setWallpaper (
background,
WallpaperEngine::Render::CWallpaper::fromWallpaper (
info->getWallpaper (), *m_renderContext, *m_audioContext, *m_browserContext,
this->m_context.settings.general.screenScalings [background]));
this->m_context.settings.general.screenScalings [background]
)
);
}
}

View File

@ -11,7 +11,7 @@ using namespace WallpaperEngine::Assets;
class CPackageEntry {
public:
CPackageEntry (std::string filename, uint32_t offset, uint32_t length) :
filename (std::move (filename)),
filename (filename),
offset (offset),
length (length) {}

View File

@ -6,7 +6,8 @@
// maximum size of the queue to prevent reading too much data
#define MAX_QUEUE_SIZE (5 * 1024 * 1024)
#define MIN_FRAMES 25
#define MIN_FRAMES (25)
#define NO_AUDIO_STREAM (-1)
using namespace WallpaperEngine::Audio;
@ -82,7 +83,6 @@ int64_t audio_seek_data_callback (void* streamarg, int64_t offset, int whence) {
switch (whence) {
case SEEK_CUR: stream->setPosition (stream->getPosition () + offset); break;
case SEEK_SET: stream->setPosition (offset); break;
}
@ -91,12 +91,14 @@ int64_t audio_seek_data_callback (void* streamarg, int64_t offset, int whence) {
CAudioStream::CAudioStream (CAudioContext& context, const std::string& filename) :
m_swrctx (nullptr),
m_audioStream(NO_AUDIO_STREAM),
m_audioContext (context) {
this->loadCustomContent (filename.c_str ());
}
CAudioStream::CAudioStream (CAudioContext& context, const uint8_t* buffer, uint32_t length) :
m_swrctx (nullptr),
m_audioStream(NO_AUDIO_STREAM),
m_audioContext (context) {
// setup a custom context first
this->m_formatContext = avformat_alloc_context ();
@ -122,6 +124,7 @@ CAudioStream::CAudioStream (CAudioContext& context, const uint8_t* buffer, uint3
CAudioStream::CAudioStream (CAudioContext& audioContext, AVCodecContext* context) :
m_swrctx (nullptr),
m_audioContext (audioContext),
m_audioStream(NO_AUDIO_STREAM),
m_context (context),
m_queue (new PacketQueue) {
this->initialize ();
@ -142,17 +145,14 @@ void CAudioStream::loadCustomContent (const char* filename) {
if (avformat_find_stream_info (this->m_formatContext, nullptr) < 0)
sLog.exception ("Cannot determine file format: ", filename);
bool hasAudioStream = false;
// find the audio stream
for (unsigned int i = 0; i < this->m_formatContext->nb_streams; i++) {
if (this->m_formatContext->streams [i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && !hasAudioStream) {
hasAudioStream = true;
if (this->m_formatContext->streams [i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && this->m_audioStream == NO_AUDIO_STREAM) {
this->m_audioStream = i;
}
}
if (!hasAudioStream)
if (this->m_audioStream == NO_AUDIO_STREAM)
sLog.exception ("Cannot find an audio stream in file ", filename);
// get the decoder for it and alloc the required context
@ -282,7 +282,7 @@ bool CAudioStream::doQueue (AVPacket* pkt) {
}
void CAudioStream::dequeuePacket (AVPacket* output) {
MyAVPacketList entry;
MyAVPacketList entry{};
SDL_LockMutex (this->m_queue->mutex);
@ -368,6 +368,10 @@ int CAudioStream::getQueuePacketCount () {
}
AVRational CAudioStream::getTimeBase () {
if (this->m_audioStream == NO_AUDIO_STREAM) {
return {0, 0};
}
return this->m_formatContext->streams [this->m_audioStream]->time_base;
}

View File

@ -6,7 +6,6 @@
#include "WallpaperEngine/Core/Objects/CSound.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
#include <utility>
#include "WallpaperEngine/Assets/CContainer.h"
#include "WallpaperEngine/Logging/CLog.h"
@ -15,48 +14,57 @@ using namespace WallpaperEngine::Core;
using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Core::UserSettings;
CObject::CObject (Wallpapers::CScene* scene, CUserSettingBoolean* visible, int id, std::string name, std::string type,
CUserSettingVector3* origin, CUserSettingVector3* scale, const glm::vec3& angles) :
m_type (std::move (type)),
CObject::CObject (
const Wallpapers::CScene* scene, const CUserSettingBoolean* visible, int id, std::string name, std::string type,
const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles, std::vector<int> dependencies
) :
m_type (type),
m_visible (visible),
m_id (id),
m_name (std::move (name)),
m_name (name),
m_origin (origin),
m_scale (scale),
m_angles (angles),
m_scene (scene) {}
m_scene (scene),
m_dependencies (dependencies) {}
CObject* CObject::fromJSON (json data, Wallpapers::CScene* scene, CContainer* container) {
std::string json = data.dump ();
const CObject* CObject::fromJSON (
const json& data, const Wallpapers::CScene* scene, const CContainer* container
) {
const auto id = jsonFindRequired <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");
auto visible = jsonFindUserConfig<CUserSettingBoolean> (data, "visible", true);
auto origin = jsonFindUserConfig<CUserSettingVector3> (data, "origin", {0, 0, 0});
auto scale = jsonFindUserConfig<CUserSettingVector3> (data, "scale", {1, 1, 1});
auto angles_val = jsonFindDefault<std::string> (data, "angles", "0.0 0.0 0.0");
auto name_it = jsonFindRequired (data, "name", "Objects must have name");
auto effects_it = data.find ("effects");
auto dependencies_it = data.find ("dependencies");
const auto image_it = data.find ("image");
const auto sound_it = data.find ("sound");
const auto particle_it = data.find ("particle");
const auto text_it = data.find ("text");
const auto light_it = data.find ("light");
auto image_it = data.find ("image");
auto sound_it = data.find ("sound");
auto particle_it = data.find ("particle");
auto text_it = data.find ("text");
auto light_it = data.find ("light");
std::vector<int> dependencies;
std::vector<const Objects::CEffect*> effects;
CObject* object;
const CObject* object;
if (dependencies_it != data.end () && dependencies_it->is_array ())
for (const auto& cur : *dependencies_it)
dependencies.push_back (cur);
if (image_it != data.end () && !image_it->is_null ()) {
object = Objects::CImage::fromJSON (scene, data, container, visible, *id_it, *name_it, origin, scale,
WallpaperEngine::Core::aToVector3 (angles_val));
object = Objects::CImage::fromJSON (
scene, data, container, visible, id, name, origin, scale, angles_val, effects_it, dependencies);
} else if (sound_it != data.end () && !sound_it->is_null ()) {
object = Objects::CSound::fromJSON (scene, data, visible, *id_it, *name_it, origin, scale,
WallpaperEngine::Core::aToVector3 (angles_val));
object = Objects::CSound::fromJSON (scene, data, visible, id, name, origin, scale, angles_val, dependencies);
} else if (particle_it != data.end () && !particle_it->is_null ()) {
/// TODO: XXXHACK -- TO REMOVE WHEN PARTICLE SUPPORT IS PROPERLY IMPLEMENTED
try {
object = Objects::CParticle::fromFile (scene, particle_it->get<std::string> (), container, visible, *id_it,
*name_it, origin, scale);
object = Objects::CParticle::fromFile (
scene, particle_it->get<std::string> (), container, visible, id, name, origin, scale, dependencies);
} catch (std::runtime_error&) {
return nullptr;
}
@ -67,32 +75,17 @@ CObject* CObject::fromJSON (json data, Wallpapers::CScene* scene, CContainer* co
/// TODO: XXXHACK -- TO REMOVE WHEN LIGHT SUPPORT IS IMPLEMENTED
return nullptr;
} else {
sLog.exception ("Unknown object type detected: ", *name_it);
sLog.exception ("Unknown object type detected: ", name);
}
if (effects_it != data.end () && effects_it->is_array ()) {
for (auto& cur : *effects_it) {
auto effectVisible = jsonFindUserConfig<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;
}
glm::vec3 CObject::getOrigin () const {
const glm::vec3& CObject::getOrigin () const {
return this->m_origin->processValue (this->getScene ()->getProject ().getProperties ());
}
glm::vec3 CObject::getScale () const {
const glm::vec3& CObject::getScale () const {
return this->m_scale->processValue (this->getScene ()->getProject ().getProperties ());
}
@ -104,10 +97,6 @@ const std::string& CObject::getName () const {
return this->m_name;
}
const std::vector<Objects::CEffect*>& CObject::getEffects () const {
return this->m_effects;
}
const std::vector<int>& CObject::getDependencies () const {
return this->m_dependencies;
}
@ -117,18 +106,10 @@ bool CObject::isVisible () const {
return this->m_visible->processValue (this->getScene ()->getProject ().getProperties ());
}
Wallpapers::CScene* CObject::getScene () const {
const Wallpapers::CScene* CObject::getScene () const {
return this->m_scene;
}
int CObject::getId () const {
return this->m_id;
}
void CObject::insertEffect (Objects::CEffect* effect) {
this->m_effects.push_back (effect);
}
void CObject::insertDependency (int dependency) {
this->m_dependencies.push_back (dependency);
}

View File

@ -29,7 +29,7 @@ class CObject {
friend class Wallpapers::CScene;
public:
static CObject* fromJSON (json data, Wallpapers::CScene* scene, CContainer* container);
static const CObject* fromJSON (const json& data, const Wallpapers::CScene* scene, const CContainer* container);
template <class T> const T* as () const {
assert (is<T> ());
@ -41,42 +41,39 @@ class CObject {
return reinterpret_cast<T*> (this);
}
template <class T> bool is () {
template <class T> bool is () const {
return this->m_type == T::Type;
}
[[nodiscard]] const std::vector<Objects::CEffect*>& getEffects () const;
[[nodiscard]] const std::vector<int>& getDependencies () const;
[[nodiscard]] int getId () const;
[[nodiscard]] glm::vec3 getOrigin () const;
[[nodiscard]] glm::vec3 getScale () const;
[[nodiscard]] const glm::vec3& getOrigin () const;
[[nodiscard]] const glm::vec3& getScale () const;
[[nodiscard]] const glm::vec3& getAngles () const;
[[nodiscard]] const std::string& getName () const;
[[nodiscard]] bool isVisible () const;
[[nodiscard]] Wallpapers::CScene* getScene () const;
[[nodiscard]] const Wallpapers::CScene* getScene () const;
protected:
CObject (Wallpapers::CScene* scene, CUserSettingBoolean* visible, int id, std::string name, std::string type,
CUserSettingVector3* origin, CUserSettingVector3* scale, const glm::vec3& angles);
void insertEffect (Objects::CEffect* effect);
void insertDependency (int dependency);
CObject (
const Wallpapers::CScene* scene, const CUserSettingBoolean* visible, int id, std::string name, std::string type,
const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles,
std::vector<int> dependencies);
private:
std::string m_type;
const std::string m_type;
CUserSettingBoolean* m_visible;
const CUserSettingBoolean* m_visible;
int m_id;
std::string m_name;
CUserSettingVector3* m_origin;
CUserSettingVector3* m_scale;
glm::vec3 m_angles;
const std::string m_name;
const CUserSettingVector3* m_origin;
const CUserSettingVector3* m_scale;
const glm::vec3 m_angles;
std::vector<Objects::CEffect*> m_effects;
std::vector<int> m_dependencies;
const std::vector<int> m_dependencies;
Wallpapers::CScene* m_scene;
const Wallpapers::CScene* m_scene;
};
} // namespace WallpaperEngine::Core

View File

@ -1,7 +1,5 @@
#include <WallpaperEngine/Assets/CContainer.h>
#include <utility>
#include "CProject.h"
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
#include "WallpaperEngine/Core/Wallpapers/CVideo.h"
@ -14,38 +12,44 @@ using namespace WallpaperEngine::Assets;
static int backgroundId = -1;
CProject::CProject (std::string title, std::string type, std::string workshopid, CContainer* container) :
m_workshopid(std::move(workshopid)),
m_title (std::move (title)),
m_type (std::move (type)),
CProject::CProject (std::string title, std::string type, std::string workshopid, const CContainer* container) :
m_workshopid(workshopid),
m_title (title),
m_type (type),
m_wallpaper (nullptr),
m_container (container)
{}
m_container (container) {}
CProject* CProject::fromFile (const std::string& filename, CContainer* container) {
CProject* CProject::fromFile (std::string filename, const CContainer* container) {
json content = json::parse (container->readFileAsString (filename));
std::string dependency = jsonFindDefault<std::string> (content, "dependency", "No dependency");
if (dependency == "No dependency") {
const auto dependency = jsonFindDefault<std::string> (content, "dependency", "No dependency");
if (dependency != "No dependency") {
sLog.exception ("Project have dependency. They are not supported, quiting");
}
// workshopid is not required, but we have to use it for some identification stuff,
// so using a static, decreasing number should be enough
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 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");
CWallpaper* wallpaper;
const CWallpaper* wallpaper;
std::transform (type.begin (), type.end (), type.begin (), tolower);
CProject* project = new CProject (title, type, workshopid, container);
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.c_str (), *project);
wallpaper = new CVideo (file, *project);
else if (type == "web")
wallpaper = new CWeb (file.c_str (), *project);
wallpaper = new CWeb (file, *project);
else
sLog.exception ("Unsupported wallpaper type: ", type);
@ -56,23 +60,20 @@ CProject* CProject::fromFile (const std::string& filename, CContainer* container
if (properties != general->end ()) {
for (const auto& cur : properties->items ()) {
Projects::CProperty* property = Projects::CProperty::fromJSON (cur.value (), cur.key ());
const auto 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");
}
}
void CProject::setWallpaper (CWallpaper* wallpaper) {
void CProject::setWallpaper (const CWallpaper* wallpaper) {
this->m_wallpaper = wallpaper;
}
CWallpaper* CProject::getWallpaper () const {
const CWallpaper* CProject::getWallpaper () const {
return this->m_wallpaper;
}
@ -84,7 +85,7 @@ const std::string& CProject::getType () const {
return this->m_type;
}
const std::vector<Projects::CProperty*>& CProject::getProperties () const {
const std::vector<const Projects::CProperty*>& CProject::getProperties () const {
return this->m_properties;
}
@ -92,10 +93,10 @@ const std::string& CProject::getWorkshopId () const {
return this->m_workshopid;
}
CContainer* CProject::getContainer () {
const CContainer* CProject::getContainer () const {
return this->m_container;
}
void CProject::insertProperty (Projects::CProperty* property) {
void CProject::insertProperty (const Projects::CProperty* property) {
this->m_properties.push_back (property);
}

View File

@ -14,30 +14,30 @@ class CWallpaper;
class CProject {
public:
static CProject* fromFile (const std::string& filename, CContainer* container);
static CProject* fromFile (std::string filename, const CContainer* container);
[[nodiscard]] CWallpaper* getWallpaper () const;
[[nodiscard]] const CWallpaper* getWallpaper () const;
[[nodiscard]] const std::string& getTitle () const;
[[nodiscard]] const std::string& getType () const;
[[nodiscard]] const std::vector<Projects::CProperty*>& getProperties () const;
[[nodiscard]] const std::vector<const Projects::CProperty*>& getProperties () const;
[[nodiscard]] const std::string& getWorkshopId () const;
CContainer* getContainer ();
const CContainer* getContainer () const;
protected:
CProject (std::string title, std::string type, std::string workshopid, CContainer* container);
CProject (std::string title, std::string type, std::string workshopid, const CContainer* container);
void setWallpaper (CWallpaper* wallpaper);
void insertProperty (Projects::CProperty* property);
void setWallpaper (const CWallpaper* wallpaper);
void insertProperty (const Projects::CProperty* property);
private:
std::vector<Projects::CProperty*> m_properties;
std::vector<const Projects::CProperty*> m_properties;
std::string m_workshopid;
std::string m_title;
std::string m_type;
CWallpaper* m_wallpaper;
CContainer* m_container;
const std::string m_workshopid;
const std::string m_title;
const std::string m_type;
const CWallpaper* m_wallpaper;
const CContainer* m_container;
};
} // namespace WallpaperEngine::Core

View File

@ -4,8 +4,10 @@
using namespace WallpaperEngine::Core;
CWallpaper::CWallpaper (std::string type, CProject& project) : m_project (project), m_type (std::move (type)) {}
CWallpaper::CWallpaper (std::string type, const CProject& project) :
m_project (project),
m_type (type) {}
CProject& CWallpaper::getProject () const {
const CProject& CWallpaper::getProject () const {
return this->m_project;
}

View File

@ -20,20 +20,20 @@ class CWallpaper {
return reinterpret_cast<T*> (this);
}
template <class T> bool is () {
template <class T> bool is () const {
return this->m_type == T::Type;
}
CWallpaper (std::string type, CProject& project);
CWallpaper (std::string type, const CProject& project);
CProject& getProject () const;
const CProject& getProject () const;
protected:
friend class CProject;
private:
CProject& m_project;
const CProject& m_project;
std::string m_type;
const std::string m_type;
};
} // namespace WallpaperEngine::Core

View File

@ -44,6 +44,42 @@ glm::vec2 Core::aToVector2 (const char* str) {
return {x, y};
}
glm::ivec4 Core::aToVector4i (const char* str) {
int x = strtol (str, const_cast<char**> (&str), 10);
while (*str == ' ')
str++;
int y = strtol (str, const_cast<char**> (&str), 10);
while (*str == ' ')
str++;
int z = strtol (str, const_cast<char**> (&str), 10);
while (*str == ' ')
str++;
int w = strtol (str, const_cast<char**> (&str), 10);
return {x, y, z, w};
}
glm::ivec3 Core::aToVector3i (const char* str) {
int x = strtol (str, const_cast<char**> (&str), 10);
while (*str == ' ')
str++;
int y = strtol (str, const_cast<char**> (&str), 10);
while (*str == ' ')
str++;
int z = strtol (str, const_cast<char**> (&str), 10);
return {x, y, z};
}
glm::ivec2 Core::aToVector2i (const char* str) {
int x = strtol (str, const_cast<char**> (&str), 10);
while (*str == ' ')
str++;
int y = strtol (str, const_cast<char**> (&str), 10);
return {x, y};
}
glm::vec4 Core::aToVector4 (const std::string& str) {
return Core::aToVector4 (str.c_str ());
}
@ -56,6 +92,18 @@ glm::vec2 Core::aToVector2 (const std::string& str) {
return Core::aToVector2 (str.c_str ());
}
glm::ivec4 Core::aToVector4i (const std::string& str) {
return Core::aToVector4i (str.c_str ());
}
glm::ivec3 Core::aToVector3i (const std::string& str) {
return Core::aToVector3i (str.c_str ());
}
glm::ivec2 Core::aToVector2i (const std::string& str) {
return Core::aToVector2i (str.c_str ());
}
glm::vec3 Core::aToColorf (const char* str) {
float r = strtof (str, const_cast<char**> (&str));
while (*str == ' ')
@ -88,17 +136,172 @@ glm::ivec3 Core::aToColori (const std::string& str) {
return aToColori (str.c_str ());
}
nlohmann::json::iterator Core::jsonFindRequired (nlohmann::json& data, const char* key, const char* notFoundMsg) {
auto value = data.find (key);
template <typename T> bool typeCheck (const nlohmann::json::const_iterator& value) {
if (value->type () == nlohmann::detail::value_t::null) {
return false;
}
if (value == data.end ())
sLog.exception ("Cannot find required key (", key, ") in json: ", notFoundMsg);
// type checks
if constexpr ((std::is_same_v<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,
const char* notFoundMsg) {
template <typename T> const T Core::jsonFindRequired (
const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg
) {
const auto iterator = jsonFindRequired (data, key, notFoundMsg);
#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);
if (value == data->end ())
@ -107,46 +310,184 @@ nlohmann::json::iterator Core::jsonFindRequired (const nlohmann::json::iterator&
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);
if (value == data.end () || value->type () == nlohmann::detail::value_t::null)
return defaultValue;
// type checks
if ((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) {
sLog.error (key, " is not of type double or integer, returning default value");
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 defaultValue;
} else if (std::is_same_v<T, bool> && value->type () != nlohmann::detail::value_t::boolean) {
sLog.error (key, " is not of type boolean, returning default value");
#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;
}
// TODO: SUPPORT INTEGERS AND OTHER TYPES
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 bool Core::jsonFindDefault (nlohmann::json& data, const char* key, bool defaultValue);
template std::string Core::jsonFindDefault (nlohmann::json& data, const char* key, std::string defaultValue);
template int16_t Core::jsonFindDefault (nlohmann::json& data, const char* key, int16_t defaultValue);
template uint16_t Core::jsonFindDefault (nlohmann::json& data, const char* key, uint16_t defaultValue);
template int32_t Core::jsonFindDefault (nlohmann::json& data, const char* key, int32_t defaultValue);
template uint32_t Core::jsonFindDefault (nlohmann::json& data, const char* key, uint32_t defaultValue);
template int64_t Core::jsonFindDefault (nlohmann::json& data, const char* key, int64_t defaultValue);
template uint64_t Core::jsonFindDefault (nlohmann::json& data, const char* key, uint64_t defaultValue);
template float Core::jsonFindDefault (nlohmann::json& data, const char* key, float defaultValue);
template double Core::jsonFindDefault (nlohmann::json& data, const char* key, double defaultValue);
template const bool Core::jsonFindDefault (const nlohmann::json& data, const char* key, const bool defaultValue);
template const std::string Core::jsonFindDefault (const nlohmann::json& data, const char* key, const std::string defaultValue);
template const int16_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const int16_t defaultValue);
template const uint16_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const uint16_t defaultValue);
template const int32_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const int32_t defaultValue);
template const uint32_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const uint32_t defaultValue);
template const int64_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const int64_t defaultValue);
template const uint64_t Core::jsonFindDefault (const nlohmann::json& data, const char* key, const uint64_t defaultValue);
template const float Core::jsonFindDefault (const nlohmann::json& data, const char* key, const float defaultValue);
template const double Core::jsonFindDefault (const nlohmann::json& data, const char* key, const double defaultValue);
template const glm::vec2 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::vec2 defaultValue);
template const glm::vec3 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::vec3 defaultValue);
template const glm::vec4 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::vec4 defaultValue);
template const glm::ivec2 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::ivec2 defaultValue);
template const glm::ivec3 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::ivec3 defaultValue);
template const glm::ivec4 Core::jsonFindDefault (const nlohmann::json& data, const char* key, const glm::ivec4 defaultValue);
template <typename T>
T* Core::jsonFindUserConfig (nlohmann::json& data, const char* key, typename T::data_type defaultValue) {
template <typename T> const T* Core::jsonFindUserConfig (
const nlohmann::json::const_iterator& data, const char* key, typename T::data_type defaultValue
) {
const auto it = data->find (key);
if (it == data->end () || it->type () == nlohmann::detail::value_t::null)
return T::fromScalar (defaultValue);
return T::fromJSON (*it);
}
template const CUserSettingBoolean* Core::jsonFindUserConfig (const nlohmann::json::const_iterator& data, const char* key,
CUserSettingBoolean::data_type defaultValue);
template const CUserSettingVector3* Core::jsonFindUserConfig (const nlohmann::json::const_iterator& data, const char* key,
CUserSettingVector3::data_type defaultValue);
template const CUserSettingFloat* Core::jsonFindUserConfig (const nlohmann::json::const_iterator& data, const char* key,
CUserSettingFloat::data_type defaultValue);
template <typename T> const T* Core::jsonFindUserConfig (
const nlohmann::json& data, const char* key, typename T::data_type defaultValue
) {
const auto it = data.find (key);
if (it == data.end () || it->type () == nlohmann::detail::value_t::null)
@ -155,9 +496,9 @@ T* Core::jsonFindUserConfig (nlohmann::json& data, const char* key, typename T::
return T::fromJSON (*it);
}
template CUserSettingBoolean* Core::jsonFindUserConfig (nlohmann::json& data, const char* key,
template const CUserSettingBoolean* Core::jsonFindUserConfig (const nlohmann::json& data, const char* key,
CUserSettingBoolean::data_type defaultValue);
template CUserSettingVector3* Core::jsonFindUserConfig (nlohmann::json& data, const char* key,
template const CUserSettingVector3* Core::jsonFindUserConfig (const nlohmann::json& data, const char* key,
CUserSettingVector3::data_type defaultValue);
template CUserSettingFloat* Core::jsonFindUserConfig (nlohmann::json& data, const char* key,
template const CUserSettingFloat* Core::jsonFindUserConfig (const nlohmann::json& data, const char* key,
CUserSettingFloat::data_type defaultValue);

View File

@ -15,15 +15,34 @@ glm::vec4 aToVector4 (const std::string& str);
glm::vec3 aToVector3 (const std::string& str);
glm::vec2 aToVector2 (const std::string& str);
glm::ivec4 aToVector4i (const char* str);
glm::ivec3 aToVector3i (const char* str);
glm::ivec2 aToVector2i (const char* str);
glm::ivec4 aToVector4i (const std::string& str);
glm::ivec3 aToVector3i (const std::string& str);
glm::ivec2 aToVector2i (const std::string& str);
glm::vec3 aToColorf (const char* str);
glm::vec3 aToColorf (const std::string& str);
glm::ivec3 aToColori (const char* str);
glm::ivec3 aToColori (const std::string& str);
nlohmann::json::iterator jsonFindRequired (nlohmann::json& data, const char* key, const char* notFoundMsg);
nlohmann::json::iterator jsonFindRequired (const nlohmann::json::iterator& data, const char* key,
const char* notFoundMsg);
template <typename T> T jsonFindDefault (nlohmann::json& data, const char* key, T defaultValue);
template <typename T> T* jsonFindUserConfig (nlohmann::json& data, const char* key, typename T::data_type defaultValue);
template <typename T> const T jsonFindRequired (
const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
template <typename T> const T jsonFindRequired (
const nlohmann::json& data, const char* key, const char* notFoundMsg);
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

View File

@ -1,10 +1,10 @@
#include "CEffect.h"
#include <iostream>
#include <utility>
#include "WallpaperEngine/Core/CProject.h"
#include "WallpaperEngine/Core/Objects/CImage.h"
#include "WallpaperEngine/Core/Objects/Images/Materials/CPass.h"
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h"
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h"
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantInteger.h"
@ -18,109 +18,72 @@ using namespace WallpaperEngine;
using namespace WallpaperEngine::Core::Objects;
using namespace WallpaperEngine::Core::UserSettings;
CEffect::CEffect (std::string name, std::string description, std::string group, std::string preview, CObject* object,
CUserSettingBoolean* visible) :
m_name (std::move (name)),
m_description (std::move (description)),
m_group (std::move (group)),
m_preview (std::move (preview)),
m_object (object),
m_visible (visible) {}
CEffect::CEffect (
std::string name, std::string description, std::string group, std::string preview, const CProject& project,
const CUserSettingBoolean* visible, std::vector<std::string> dependencies, std::vector<const Effects::CFBO*> fbos,
std::vector<const Images::CMaterial*> materials
) :
m_name (name),
m_description (description),
m_group (group),
m_preview (preview),
m_visible (visible),
m_dependencies (dependencies),
m_fbos (fbos),
m_project (project),
m_materials (materials) {}
CEffect* CEffect::fromJSON (json data, CUserSettingBoolean* visible, CObject* object, CContainer* container) {
auto file_it = jsonFindRequired (data, "file", "Object effect must have a file");
auto effectpasses_it = data.find ("passes");
const CEffect* CEffect::fromJSON (
const json& data, const CUserSettingBoolean* visible, const CProject& project, const Images::CMaterial* material,
const CContainer* container
) {
const auto file = jsonFindRequired <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");
auto description = jsonFindDefault<std::string> (content, "description", "");
auto group_it = jsonFindRequired (content, "group", "Effect must have a group");
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");
const auto effectName = jsonFindRequired <std::string> (content, "name", "Effect must have a name");
const auto passes_it = jsonFindRequired (content, "passes", "Effect must have a pass list");
const auto fbos_it = content.find ("fbos");
auto* effect = new CEffect (*name_it, description, *group_it, preview, object, visible);
CEffect::materialsFromJSON (passes_it, effect, container);
CEffect::dependencyFromJSON (dependencies_it, effect);
// info to override in the pass information, used by material generation
std::map<int, Images::CMaterial::OverrideInfo> overrides;
std::vector<const Effects::CFBO*> fbos;
if (fbos_it != content.end ())
CEffect::fbosFromJSON (fbos_it, effect);
fbos = CEffect::fbosFromJSON (fbos_it);
if (effectpasses_it != data.end ()) {
auto cur = effectpasses_it->begin ();
auto end = effectpasses_it->end ();
for (int passNumber = 0; cur != end; ++cur, passNumber++) {
auto constants_it = cur->find ("constantshadervalues");
auto combos_it = cur->find ("combos");
auto textures_it = cur->find ("textures");
if (constants_it == cur->end () && combos_it == cur->end () && textures_it == cur->end ())
continue;
Images::CMaterial* material = effect->getMaterials ().at (passNumber);
for (const auto& passCur : material->getPasses ()) {
if (textures_it != cur->end ()) {
std::vector<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;
overrides = overridesFromJSON (effectpasses_it, material);
}
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 ())
pass->insertCombo (cur.key (), cur.value ());
combos.insert (std::pair (cur.key (), cur.value ()));
return combos;
}
void CEffect::constantsFromJSON (const json::const_iterator& constants_it,
Core::Objects::Images::Materials::CPass* pass) {
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> CEffect::constantsFromJSON (
const json::const_iterator& constants_it
) {
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants;
for (auto& cur : constants_it->items ()) {
auto val = cur.value ();
@ -152,77 +115,154 @@ void CEffect::constantsFromJSON (const json::const_iterator& constants_it,
sLog.exception ("unknown shader constant type ", val);
}
pass->insertConstant (cur.key (), constant);
constants.insert (std::pair (cur.key (), constant));
}
return constants;
}
void CEffect::fbosFromJSON (const json::const_iterator& fbos_it, CEffect* effect) {
std::vector<const Effects::CFBO*> CEffect::fbosFromJSON (const json::const_iterator& fbos_it) {
std::vector<const Effects::CFBO*> fbos;
for (const auto& cur : (*fbos_it))
effect->insertFBO (Effects::CFBO::fromJSON (cur));
fbos.push_back (Effects::CFBO::fromJSON (cur));
return fbos;
}
void CEffect::dependencyFromJSON (const json::const_iterator& dependencies_it, CEffect* effect) {
std::vector<std::string> CEffect::dependenciesFromJSON (const json::const_iterator& dependencies_it) {
std::vector<std::string> dependencies;
for (const auto& cur : (*dependencies_it))
effect->insertDependency (cur);
dependencies.push_back (cur);
return dependencies;
}
void CEffect::materialsFromJSON (const json::const_iterator& passes_it, CEffect* effect, CContainer* container) {
std::vector<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)) {
auto materialfile = cur.find ("material");
auto target = cur.find ("target");
auto bind = cur.find ("bind");
++materialNumber;
const auto materialfile = cur.find ("material");
const auto target = cur.find ("target");
const auto bind_it = cur.find ("bind");
if (materialfile == cur.end ())
sLog.exception ("Found an effect ", effect->m_name, " without material");
sLog.exception ("Found an effect ", name, " without material");
Images::CMaterial* material;
std::map<int, const Effects::CBind*> textureBindings;
if (bind_it != cur.end ()) {
for (const auto& bindCur : (*bind_it)) {
const auto* bind = Effects::CBind::fromJSON (bindCur);
textureBindings.insert (std::pair (bind->getIndex (), bind));
}
}
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);
material = Images::CMaterial::fromFile (materialfile->get<std::string> (), container, textureBindings, overrideInfo);
else
material = Images::CMaterial::fromFile (materialfile->get<std::string> (), *target, container);
material = Images::CMaterial::fromFile (materialfile->get<std::string> (), *target, container, textureBindings, overrideInfo);
if (bind != cur.end ()) {
for (const auto& bindCur : (*bind))
material->insertTextureBind (Effects::CBind::fromJSON (bindCur));
materials.push_back (material);
}
effect->insertMaterial (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 {
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;
}
const std::vector<Effects::CFBO*>& CEffect::getFbos () const {
const std::vector<const Effects::CFBO*>& CEffect::getFbos () const {
return this->m_fbos;
}
bool CEffect::isVisible () const {
return this->m_visible->processValue (this->m_object->getScene ()->getProject ().getProperties ());
const Core::CProject& CEffect::getProject () const {
return this->m_project;
}
Effects::CFBO* CEffect::findFBO (const std::string& name) {
bool CEffect::isVisible () const {
return this->m_visible->processValue (this->getProject ().getProperties ());
}
const Effects::CFBO* CEffect::findFBO (const std::string& name) {
for (const auto& cur : this->m_fbos)
if (cur->getName () == name)
return cur;
sLog.exception ("cannot find fbo ", name);
}
void CEffect::insertDependency (const std::string& dep) {
this->m_dependencies.push_back (dep);
}
void CEffect::insertMaterial (Images::CMaterial* material) {
this->m_materials.push_back (material);
}
void CEffect::insertFBO (Effects::CFBO* fbo) {
this->m_fbos.push_back (fbo);
}

View File

@ -9,6 +9,7 @@
namespace WallpaperEngine::Core {
class CObject;
class CProject;
}
namespace WallpaperEngine::Core::UserSettings {
@ -25,11 +26,14 @@ using namespace WallpaperEngine::Core::UserSettings;
*/
class CEffect {
public:
CEffect (std::string name, std::string description, std::string group, std::string preview, CObject* object,
CUserSettingBoolean* visible);
CEffect (
std::string name, std::string description, std::string group, std::string preview, const CProject& project,
const CUserSettingBoolean* visible, std::vector<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,
CContainer* container);
static const CEffect* fromJSON (
const json& data, const CUserSettingBoolean* visible, const CProject& object, const Images::CMaterial* material,
const CContainer* container);
/**
* @return List of dependencies for the effect to work
@ -38,15 +42,19 @@ class CEffect {
/**
* @return List of materials the effect applies
*/
[[nodiscard]] const std::vector<Images::CMaterial*>& getMaterials () const;
[[nodiscard]] const std::vector<const Images::CMaterial*>& getMaterials () const;
/**
* @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
*/
[[nodiscard]] bool isVisible () const;
/**
* @return The project this effect is part of
*/
[[nodiscard]] const CProject& getProject () const;
/**
* Searches the FBOs list for the given FBO
*
@ -54,39 +62,39 @@ class CEffect {
*
* @return
*/
Effects::CFBO* findFBO (const std::string& name);
const Effects::CFBO* findFBO (const std::string& name);
protected:
static void constantsFromJSON (const json::const_iterator& constants_it,
Core::Objects::Images::Materials::CPass* pass);
static void combosFromJSON (const json::const_iterator& combos_it, Core::Objects::Images::Materials::CPass* pass);
static void fbosFromJSON (const json::const_iterator& fbos_it, CEffect* effect);
static void dependencyFromJSON (const json::const_iterator& dependencies_it, CEffect* effect);
static void materialsFromJSON (const json::const_iterator& passes_it, CEffect* effect, CContainer* container);
void insertDependency (const std::string& dep);
void insertMaterial (Images::CMaterial* material);
void insertFBO (Effects::CFBO* fbo);
static std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constantsFromJSON (
const json::const_iterator& constants_it);
static std::map<std::string, int> combosFromJSON (const json::const_iterator& combos_it);
static std::vector<const Effects::CFBO*> fbosFromJSON (const json::const_iterator& fbos_it);
static std::vector<std::string> dependenciesFromJSON (const json::const_iterator& dependencies_it);
static std::vector<const Images::CMaterial*> materialsFromJSON (
const json::const_iterator& passes_it, std::string name, const CContainer* container,
std::map<int, Images::CMaterial::OverrideInfo>);
static std::map<int, Images::CMaterial::OverrideInfo> overridesFromJSON (
const json::const_iterator& passes_it, const Images::CMaterial* material);
private:
/** Effect's name */
std::string m_name;
const std::string m_name;
/** Effect's description used in the UI */
std::string m_description;
const std::string m_description;
/** Effect's group used in the UI */
std::string m_group;
const std::string m_group;
/** A project that previews the given effect, used in the UI */
std::string m_preview;
/** The object the effect applies to */
CObject* m_object;
const std::string m_preview;
/** If the effect is visible or not */
UserSettings::CUserSettingBoolean* m_visible;
const UserSettings::CUserSettingBoolean* m_visible;
/** Project this effect is part of */
const CProject& m_project;
/** List of dependencies for the effect */
std::vector<std::string> m_dependencies;
const std::vector<std::string> m_dependencies;
/** 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 */
std::vector<Effects::CFBO*> m_fbos;
const std::vector<const Effects::CFBO*> m_fbos;
};
} // namespace WallpaperEngine::Core::Objects

View File

@ -5,53 +5,83 @@
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h"
#include "WallpaperEngine/Core/Wallpapers/CScene.h"
#include <utility>
using namespace WallpaperEngine::Core::Objects;
using namespace WallpaperEngine::Core::UserSettings;
CImage::CImage (Wallpapers::CScene* scene, Images::CMaterial* material, CUserSettingBoolean* visible, int id, std::string name,
CUserSettingVector3* origin, CUserSettingVector3* scale, const glm::vec3& angles, const glm::vec2& size,
std::string alignment, CUserSettingVector3* color, CUserSettingFloat* alpha, float brightness,
uint32_t colorBlendMode, const glm::vec2& parallaxDepth, bool fullscreen, bool passthrough,
bool autosize) :
CObject (scene, visible, id, std::move (name), Type, origin, scale, angles),
CImage::CImage (
const Wallpapers::CScene* scene, const Images::CMaterial* material, const CUserSettingBoolean* visible, int id,
std::string name, const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles,
glm::vec2 size, std::string alignment, const CUserSettingVector3* color, const CUserSettingFloat* alpha,
float brightness, uint32_t colorBlendMode, glm::vec2 parallaxDepth, bool fullscreen, bool passthrough,
bool autosize, std::vector<const Objects::CEffect*> effects, std::vector<int> dependencies
) :
CObject (scene, visible, id, name, Type, origin, scale, angles, dependencies),
m_size (size),
m_parallaxDepth (parallaxDepth),
m_material (material),
m_alignment (std::move (alignment)),
m_alignment (alignment),
m_alpha (alpha),
m_brightness (brightness),
m_color (color),
m_colorBlendMode (colorBlendMode),
m_fullscreen (fullscreen),
m_passthrough (passthrough),
m_autosize (autosize) {}
m_autosize (autosize),
m_effects (effects) {}
WallpaperEngine::Core::CObject* CImage::fromJSON (Wallpapers::CScene* scene, json data, CContainer* container,
CUserSettingBoolean* visible, int id, std::string name,
CUserSettingVector3* origin, CUserSettingVector3* scale,
const glm::vec3& angles) {
const auto image_it = data.find ("image");
const auto size_val = jsonFindDefault<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 alpha = jsonFindUserConfig<CUserSettingFloat> (data, "alpha", 1.0);
const auto color = jsonFindUserConfig<CUserSettingVector3> (data, "color", {1, 1, 1});
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");
const WallpaperEngine::Core::CObject* CImage::fromJSON (
const Wallpapers::CScene* scene, const json& data, const CContainer* container,
const CUserSettingBoolean* visible, int id, std::string name, const CUserSettingVector3* origin,
const CUserSettingVector3* scale, glm::vec3 angles, const json::const_iterator& effects_it,
std::vector<int> dependencies
) {
const auto image = jsonFindRequired <std::string>(data, "image", "Image must have an image");
std::vector<const Objects::CEffect*> effects;
json content = json::parse (container->readFileAsString (image));
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");
const auto fullscreen = jsonFindDefault<bool> (content, "fullscreen", false);
const auto passthrough = jsonFindDefault<bool> (content, "passthrough", false);
const auto autosize = jsonFindDefault<bool> (content, "autosize", false);
if (effects_it != data.end () && effects_it->is_array ()) {
for (auto& cur : *effects_it) {
const auto effectVisible = jsonFindUserConfig<CUserSettingBoolean> (cur, "visible", true);
return new CImage (scene, Images::CMaterial::fromFile (material_it->get<std::string> (), container), visible, id,
std::move (name), origin, scale, angles, WallpaperEngine::Core::aToVector2 (size_val), alignment,
color, alpha, brightness_val, colorBlendMode_val,
WallpaperEngine::Core::aToVector2 (parallaxDepth_val), fullscreen, passthrough, autosize);
if (!effectVisible->processValue (scene->getProject ().getProperties ()))
continue;
effects.push_back (
Objects::CEffect::fromJSON (
cur, effectVisible, scene->getProject (), material, container
)
);
}
}
return new CImage (
scene,
material,
visible,
id,
name,
origin,
scale,
angles,
jsonFindDefault<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 {
@ -70,7 +100,7 @@ float CImage::getAlpha () const {
return this->m_alpha->processValue (this->getScene ()->getProject ().getProperties ());
}
glm::vec3 CImage::getColor () const {
const glm::vec3& CImage::getColor () const {
return this->m_color->processValue (this->getScene ()->getProject ().getProperties ());
}
@ -98,4 +128,8 @@ bool CImage::isAutosize () const {
return this->m_autosize;
}
const std::vector<const CEffect*>& CImage::getEffects () const {
return this->m_effects;
}
const std::string CImage::Type = "image";

View File

@ -27,9 +27,11 @@ class CImage : public CObject {
friend class CObject;
public:
static CObject* fromJSON (Wallpapers::CScene* scene, json data, CContainer* container, CUserSettingBoolean* visible,
int id, std::string name, CUserSettingVector3* origin, CUserSettingVector3* scale,
const glm::vec3& angles);
static const CObject* fromJSON (
const Wallpapers::CScene* scene, const json& data, const CContainer* container,
const CUserSettingBoolean* visible, int id, std::string name, const CUserSettingVector3* origin,
const CUserSettingVector3* scale, glm::vec3 angles, const json::const_iterator& effects_it,
std::vector<int> dependencies);
/**
* @return The base material to use for the image
@ -50,7 +52,7 @@ class CImage : public CObject {
/**
* @return The color to use for the image
*/
[[nodiscard]] glm::vec3 getColor () const;
[[nodiscard]] const glm::vec3& getColor () const;
/**
* @return The brightness to use for the image
*/
@ -75,12 +77,18 @@ class CImage : public CObject {
* @return If the image is autosized or not
*/
[[nodiscard]] bool isAutosize () const;
/**
* @return All of the effects applied to this image
*/
[[nodiscard]] const std::vector<const Objects::CEffect*>& getEffects () const;
protected:
CImage (Wallpapers::CScene* scene, Images::CMaterial* material, CUserSettingBoolean* visible, int id, std::string name,
CUserSettingVector3* origin, CUserSettingVector3* scale, const glm::vec3& angles, const glm::vec2& size,
std::string alignment, CUserSettingVector3* color, CUserSettingFloat* alpha, float brightness,
uint32_t colorBlendMode, const glm::vec2& parallaxDepth, bool fullscreen, bool passthrough, bool autosize);
CImage (
const Wallpapers::CScene* scene, const Images::CMaterial* material, const CUserSettingBoolean* visible, int id,
std::string name, const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles,
glm::vec2 size, std::string alignment, const CUserSettingVector3* color, const CUserSettingFloat* alpha,
float brightness, uint32_t colorBlendMode, glm::vec2 parallaxDepth, bool fullscreen, bool passthrough,
bool autosize, std::vector<const Objects::CEffect*> effects, std::vector<int> dependencies);
/**
* Type value used to differentiate the different types of objects in a background
@ -89,21 +97,23 @@ class CImage : public CObject {
private:
/** The image's size */
glm::vec2 m_size;
const glm::vec2 m_size;
/** Parallax depth */
const glm::vec2 m_parallaxDepth;
/** Base material for the image */
Images::CMaterial* m_material;
const Images::CMaterial* m_material;
/** What type of alignment to use for the image's position */
std::string m_alignment;
const std::string m_alignment;
/** The alpha value for the image */
CUserSettingFloat* m_alpha;
const CUserSettingFloat* m_alpha;
/** The brightness for the image */
float m_brightness;
/** The color to use for the image */
CUserSettingVector3* m_color;
const CUserSettingVector3* m_color;
/** The color blending mode used for the image, special value for shaders */
uint32_t m_colorBlendMode;
const uint32_t m_colorBlendMode;
/** Override for effects */
const std::vector<const Objects::CEffect*> m_effects;
/** If the image is fullscreen or not */
bool m_fullscreen;
/** If the image is passthrough or not */

View File

@ -1,61 +1,70 @@
#include "CParticle.h"
#include <utility>
using namespace WallpaperEngine::Core::Objects;
CParticle* CParticle::fromFile (Wallpapers::CScene* scene, const std::string& filename, CContainer* container,
CUserSettingBoolean* visible, int id, std::string name, CUserSettingVector3* origin,
CUserSettingVector3* scale) {
const CParticle* CParticle::fromFile (
const Wallpapers::CScene* scene, std::string filename, const CContainer* container,
const CUserSettingBoolean* visible, int id, std::string name, const CUserSettingVector3* origin,
const CUserSettingVector3* scale, std::vector<int> dependencies
) {
json data = json::parse (container->readFileAsString (filename));
const auto controlpoint_it = data.find ("controlpoint");
const auto starttime_it = jsonFindRequired (data, "starttime", "Particles must have start time");
const auto maxcount_it = jsonFindRequired (data, "maxcount", "Particles must have maximum count");
const auto emitter_it = jsonFindRequired (data, "emitter", "Particles must have emitters");
const auto initializer_it = jsonFindRequired (data, "initializer", "Particles must have initializers");
auto* particle = new CParticle (scene, *starttime_it, *maxcount_it, visible, id, std::move (name), origin, scale);
std::vector<const Particles::CControlPoint*> controlpoints;
std::vector<const Particles::CEmitter*> emitters;
std::vector<const Particles::CInitializer*> initializers;
if (controlpoint_it != data.end ())
for (const auto& cur : (*controlpoint_it))
particle->insertControlPoint (Particles::CControlPoint::fromJSON (cur));
controlpoints.push_back (Particles::CControlPoint::fromJSON (cur));
for (const auto& cur : (*emitter_it))
particle->insertEmitter (Particles::CEmitter::fromJSON (cur));
emitters.push_back (Particles::CEmitter::fromJSON (cur));
for (const auto& cur : (*initializer_it))
particle->insertInitializer (Particles::CInitializer::fromJSON (cur));
initializers.push_back (Particles::CInitializer::fromJSON (cur));
return particle;
return new CParticle (
scene,
jsonFindRequired <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,
std::string name, CUserSettingVector3* origin, CUserSettingVector3* scale) :
CObject (scene, visible, id, std::move (name), Type, origin, scale, glm::vec3 ()),
CParticle::CParticle (
const Wallpapers::CScene* scene, uint32_t starttime, uint32_t maxcount, const CUserSettingBoolean* visible, int id,
const std::string& name, const CUserSettingVector3* origin, const CUserSettingVector3* scale,
const std::vector<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_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;
}
const std::vector<Particles::CControlPoint*>& CParticle::getControlPoints () const {
const std::vector<const Particles::CControlPoint*>& CParticle::getControlPoints () const {
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;
}
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";

View File

@ -17,39 +17,31 @@ class CParticle : public CObject {
friend class CObject;
public:
static CParticle* fromFile (Wallpapers::CScene* scene, const std::string& filename, CContainer* container,
CUserSettingBoolean* visible, int id, std::string name,
CUserSettingVector3* origin, CUserSettingVector3* scale);
static const CParticle* fromFile (
const Wallpapers::CScene* scene, std::string filename, const CContainer* container,
const CUserSettingBoolean* visible, int id, std::string name, const CUserSettingVector3* origin,
const CUserSettingVector3* scale, std::vector<int> dependencies);
/**
* @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
*/
[[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
*/
[[nodiscard]] const std::vector<Particles::CInitializer*>& getInitializers () const;
[[nodiscard]] const std::vector<const Particles::CInitializer*>& getInitializers () const;
protected:
CParticle (Wallpapers::CScene* scene, uint32_t starttime, uint32_t maxcount, CUserSettingBoolean* visible, int id,
std::string name, CUserSettingVector3* origin, CUserSettingVector3* scale);
/**
* @param controlpoint The control point to add to the particle system
*/
void insertControlPoint (Particles::CControlPoint* controlpoint);
/**
* @param emitter The emitter to add to the particle system
*/
void insertEmitter (Particles::CEmitter* emitter);
/**
* @param initializer The initializer to add to the particle system
*/
void insertInitializer (Particles::CInitializer* initializer);
CParticle (
const Wallpapers::CScene* scene, uint32_t starttime, uint32_t maxcount, const CUserSettingBoolean* visible,
int id, const std::string& name, const CUserSettingVector3* origin, const CUserSettingVector3* scale,
const std::vector<const Particles::CControlPoint*>& controlpoints,
const std::vector<const Particles::CEmitter*>& emitters,
const std::vector<const Particles::CInitializer*>& initializers, std::vector<int> dependencies);
/**
* Type value used to differentiate the different types of objects in a background
@ -58,14 +50,14 @@ class CParticle : public CObject {
private:
/** The time at which the particle system should start emitting */
uint32_t m_starttime;
const uint32_t m_starttime;
/** Maximum number of particles at the same time */
uint32_t m_maxcount;
const uint32_t m_maxcount;
/** List of control points */
std::vector<Particles::CControlPoint*> m_controlpoints;
const std::vector<const Particles::CControlPoint*> m_controlpoints;
/** List of emitters */
std::vector<Particles::CEmitter*> m_emitters;
const std::vector<const Particles::CEmitter*> m_emitters;
/** List of initializers */
std::vector<Particles::CInitializer*> m_initializers;
const std::vector<const Particles::CInitializer*> m_initializers;
};
} // namespace WallpaperEngine::Core::Objects

View File

@ -4,35 +4,42 @@
using namespace WallpaperEngine::Core::Objects;
CSound::CSound (Wallpapers::CScene* scene, CUserSettingBoolean* visible, int id, std::string name, CUserSettingVector3* origin,
CUserSettingVector3* scale, const glm::vec3& angles, bool repeat) :
CObject (scene, visible, id, std::move (name), Type, origin, scale, angles),
m_repeat (repeat) {}
CSound::CSound (
const Wallpapers::CScene* scene, const CUserSettingBoolean* visible, int id, std::string name,
const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles, bool repeat,
std::vector<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 std::string& name, CUserSettingVector3* origin,
CUserSettingVector3* scale, const glm::vec3& angles) {
bool repeat = false;
const WallpaperEngine::Core::CObject* CSound::fromJSON (
const Wallpapers::CScene* scene, const json& data, const CUserSettingBoolean* visible, int id,
std::string name, const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles,
std::vector<int> dependencies
) {
// TODO: PARSE AUDIO VOLUME
std::vector<std::string> sounds;
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 ())
sLog.exception ("Expected sound list on element ", name);
auto* sound = new CSound (scene, visible, id, name, origin, scale, angles, repeat);
for (const auto& cur : (*sound_it))
sound->insertSound (cur);
sounds.push_back (cur);
return sound;
}
void CSound::insertSound (const std::string& filename) {
this->m_sounds.push_back (filename);
return new CSound (
scene,
visible,
id,
name,
origin,
scale,
angles,
jsonFindDefault<std::string> (data, "playbackmode", "") == "loop",
sounds,
dependencies
);
}
const std::vector<std::string>& CSound::getSounds () const {

View File

@ -19,9 +19,10 @@ class CSound : public CObject {
friend class CObject;
public:
static CObject* fromJSON (Wallpapers::CScene* scene, json data, CUserSettingBoolean* visible, int id,
const std::string& name, CUserSettingVector3* origin, CUserSettingVector3* scale,
const glm::vec3& angles);
static const CObject* fromJSON (
const Wallpapers::CScene* scene, const json& data, const CUserSettingBoolean* visible,
int id, std::string name, const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles,
std::vector<int> dependencies);
/**
* @return The list of sounds to play
@ -33,13 +34,10 @@ class CSound : public CObject {
[[nodiscard]] bool isRepeat () const;
protected:
CSound (Wallpapers::CScene* scene, CUserSettingBoolean* visible, int id, std::string name, CUserSettingVector3* origin,
CUserSettingVector3* scale, const glm::vec3& angles, bool repeat);
/**
* @param filename The sound to add
*/
void insertSound (const std::string& filename);
CSound (
const Wallpapers::CScene* scene, const CUserSettingBoolean* visible, int id, std::string name,
const CUserSettingVector3* origin, const CUserSettingVector3* scale, glm::vec3 angles, bool repeat,
std::vector<std::string> sounds, std::vector<int> dependencies);
/**
* Type value used to differentiate the different types of objects in a background

View File

@ -4,13 +4,15 @@
using namespace WallpaperEngine::Core::Objects::Effects;
CBind::CBind (std::string name, uint32_t index) : m_name (std::move (name)), m_index (index) {}
CBind::CBind (std::string name, uint32_t index) :
m_name (name),
m_index (index) {}
CBind* CBind::fromJSON (json data) {
const auto name_it = jsonFindRequired (data, "name", "bind must have texture name");
const auto index_it = jsonFindRequired (data, "index", "bind must have index");
return new CBind (*name_it, *index_it);
const CBind* CBind::fromJSON (const json& data) {
return new CBind (
jsonFindRequired <std::string> (data, "name", "bind must have texture name"),
jsonFindRequired <uint32_t> (data, "index", "bind must have index")
);
}
const std::string& CBind::getName () const {

View File

@ -20,9 +20,7 @@ class CBind {
* @param data
* @return
*/
static CBind* fromJSON (json data);
CBind (std::string name, uint32_t index);
static const CBind* fromJSON (const json& data);
/**
* @return The texture name, previous to use the one already specified by the object's passes
@ -33,10 +31,13 @@ class CBind {
*/
[[nodiscard]] const uint32_t& getIndex () const;
protected:
CBind (std::string name, uint32_t index);
private:
/** The texture's name */
std::string m_name;
const std::string m_name;
/** The texture index to replace */
uint32_t m_index;
const uint32_t m_index;
};
} // namespace WallpaperEngine::Core::Objects::Effects

View File

@ -6,16 +6,16 @@ using namespace WallpaperEngine::Core;
using namespace WallpaperEngine::Core::Objects::Effects;
CFBO::CFBO (std::string name, float scale, std::string format) :
m_name (std::move (name)),
m_name (name),
m_scale (scale),
m_format (std::move (format)) {}
m_format (format) {}
CFBO* CFBO::fromJSON (json data) {
const auto name_it = jsonFindRequired (data, "name", "Name for an FBO is required");
const auto scale = jsonFindDefault<float> (data, "scale", 1.0);
const auto format = jsonFindDefault<std::string> (data, "format", "");
return new CFBO (*name_it, scale, format);
const CFBO* CFBO::fromJSON (const json& data) {
return new CFBO (
jsonFindRequired <std::string> (data, "name", "Name for an FBO is required"),
jsonFindDefault <float> (data, "scale", 1.0),
jsonFindDefault <std::string> (data, "format", "")
);
}
const std::string& CFBO::getName () const {

View File

@ -15,9 +15,7 @@ using json = nlohmann::json;
*/
class CFBO {
public:
CFBO (std::string name, float scale, std::string format);
static CFBO* fromJSON (json data);
static const CFBO* fromJSON (const json& data);
/**
* @return The FBO name used to identify it in the background's files
@ -32,12 +30,15 @@ class CFBO {
*/
[[nodiscard]] const std::string& getFormat () const;
protected:
CFBO (std::string name, float scale, std::string format);
private:
/** The name of the FBO */
std::string m_name;
const std::string m_name;
/** The scale factor of the FBO */
float m_scale;
const float m_scale;
/** The FBO's format for the render */
std::string m_format;
const std::string m_format;
};
} // namespace WallpaperEngine::Core::Objects::Effects

View File

@ -2,7 +2,8 @@
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
CShaderConstant::CShaderConstant (std::string type) : m_type (std::move (type)) {}
CShaderConstant::CShaderConstant (std::string type) :
m_type (type) {}
const std::string& CShaderConstant::getType () const {
return this->m_type;

View File

@ -21,7 +21,7 @@ class CShaderConstant {
return reinterpret_cast<T*> (this);
}
template <class T> bool is () {
template <class T> bool is () const {
return this->m_type == T::Type;
}
@ -31,6 +31,6 @@ class CShaderConstant {
[[nodiscard]] const std::string& getType () const;
private:
std::string m_type;
const std::string m_type;
};
} // namespace WallpaperEngine::Core::Objects::Effects::Constants

View File

@ -2,9 +2,11 @@
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
CShaderConstantFloat::CShaderConstantFloat (float value) : CShaderConstant (Type), m_value (value) {}
CShaderConstantFloat::CShaderConstantFloat (float value) :
CShaderConstant (Type),
m_value (value) {}
float* CShaderConstantFloat::getValue () {
const float* CShaderConstantFloat::getValue () const {
return &this->m_value;
}

View File

@ -15,7 +15,7 @@ class CShaderConstantFloat : public CShaderConstant {
/**
* @return A pointer to the actual value of the constant
*/
float* getValue ();
[[nodiscard]] const float* getValue () const;
/**
* Type string indicator
@ -24,6 +24,6 @@ class CShaderConstantFloat : public CShaderConstant {
protected:
/** The constant's value */
float m_value;
const float m_value;
};
} // namespace WallpaperEngine::Core::Objects::Effects::Constants

View File

@ -2,9 +2,11 @@
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
CShaderConstantInteger::CShaderConstantInteger (int32_t value) : CShaderConstant (Type), m_value (value) {}
CShaderConstantInteger::CShaderConstantInteger (int32_t value) :
CShaderConstant (Type),
m_value (value) {}
int32_t* CShaderConstantInteger::getValue () {
const int32_t* CShaderConstantInteger::getValue () const {
return &this->m_value;
}

View File

@ -15,7 +15,7 @@ class CShaderConstantInteger : public CShaderConstant {
/**
* @return A pointer to the actual value of the constant
*/
int32_t* getValue ();
[[nodiscard]] const int32_t* getValue () const;
/**
* Type string indicator
@ -24,6 +24,6 @@ class CShaderConstantInteger : public CShaderConstant {
protected:
/** The constant's value */
int32_t m_value;
const int32_t m_value;
};
} // namespace WallpaperEngine::Core::Objects::Effects::Constants

View File

@ -2,9 +2,11 @@
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
CShaderConstantVector2::CShaderConstantVector2 (glm::vec2 value) : CShaderConstant (Type), m_value (value) {}
CShaderConstantVector2::CShaderConstantVector2 (glm::vec2 value) :
CShaderConstant (Type),
m_value (value) {}
glm::vec2* CShaderConstantVector2::getValue () {
const glm::vec2* CShaderConstantVector2::getValue () const {
return &this->m_value;
}

View File

@ -17,7 +17,7 @@ class CShaderConstantVector2 : public CShaderConstant {
/**
* @return A pointer to the actual value of the constant
*/
glm::vec2* getValue ();
[[nodiscard]] const glm::vec2* getValue () const;
/**
* Type string indicator
@ -26,6 +26,6 @@ class CShaderConstantVector2 : public CShaderConstant {
protected:
/** The constant's value */
glm::vec2 m_value;
const glm::vec2 m_value;
};
} // namespace WallpaperEngine::Core::Objects::Effects::Constants

View File

@ -2,9 +2,11 @@
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
CShaderConstantVector3::CShaderConstantVector3 (glm::vec3 value) : CShaderConstant (Type), m_value (value) {}
CShaderConstantVector3::CShaderConstantVector3 (glm::vec3 value) :
CShaderConstant (Type),
m_value (value) {}
glm::vec3* CShaderConstantVector3::getValue () {
const glm::vec3* CShaderConstantVector3::getValue () const {
return &this->m_value;
}

View File

@ -16,7 +16,7 @@ class CShaderConstantVector3 : public CShaderConstant {
/**
* @return A pointer to the actual value of the constant
*/
glm::vec3* getValue ();
[[nodiscard]] const glm::vec3* getValue () const;
/**
* Type string indicator
@ -25,6 +25,6 @@ class CShaderConstantVector3 : public CShaderConstant {
protected:
/** The constant's value */
glm::vec3 m_value;
const glm::vec3 m_value;
};
} // namespace WallpaperEngine::Core::Objects::Effects::Constants

View File

@ -2,9 +2,11 @@
using namespace WallpaperEngine::Core::Objects::Effects::Constants;
CShaderConstantVector4::CShaderConstantVector4 (glm::vec4 value) : CShaderConstant (Type), m_value (value) {}
CShaderConstantVector4::CShaderConstantVector4 (glm::vec4 value) :
CShaderConstant (Type),
m_value (value) {}
glm::vec4* CShaderConstantVector4::getValue () {
const glm::vec4* CShaderConstantVector4::getValue () const {
return &this->m_value;
}

View File

@ -16,7 +16,7 @@ class CShaderConstantVector4 : public CShaderConstant {
/**
* @return A pointer to the actual value of the constant
*/
glm::vec4* getValue ();
[[nodiscard]] const glm::vec4* getValue () const;
/**
* Type string indicator
@ -25,6 +25,6 @@ class CShaderConstantVector4 : public CShaderConstant {
protected:
/** The constant's value */
glm::vec4 m_value;
const glm::vec4 m_value;
};
} // namespace WallpaperEngine::Core::Objects::Effects::Constants

View File

@ -1,59 +1,74 @@
#include "CMaterial.h"
#include "WallpaperEngine/Core/Objects/Images/Materials/CPass.h"
#include <nlohmann/json.hpp>
#include <utility>
using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Core::Objects;
using namespace WallpaperEngine::Core::Objects::Images;
CMaterial::CMaterial (std::string name) : 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) {
return fromJSON (filename, json::parse (container->readFileAsString (filename)));
const CMaterial* CMaterial::fromFile (
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) {
return fromJSON (filename, json::parse (container->readFileAsString (filename)), target);
const CMaterial* CMaterial::fromFile (
const std::filesystem::path& filename, const std::string& target,
const CContainer* container, std::map<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) {
CMaterial* material = fromJSON (name, std::move (data));
material->setTarget (target);
return material;
}
CMaterial* CMaterial::fromJSON (const std::string& name, json data) {
const CMaterial* CMaterial::fromJSON (
const std::string& name, const json& data, const std::string& target,
std::map<int, const Effects::CBind*> textureBindings, const OverrideInfo* overrides
) {
const auto passes_it = jsonFindRequired (data, "passes", "Material must have at least one pass");
auto* material = new CMaterial (name);
std::vector<const Materials::CPass*> passes;
for (const auto& cur : (*passes_it))
material->insertPass (Materials::CPass::fromJSON (cur));
passes.push_back (Materials::CPass::fromJSON (cur, overrides));
return material;
return new CMaterial (name, target, textureBindings, passes);
}
void CMaterial::insertPass (Materials::CPass* pass) {
this->m_passes.push_back (pass);
const CMaterial* CMaterial::fromJSON (
const std::string& name, const json& data, std::map<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) {
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 {
const std::vector<const Materials::CPass*>& CMaterial::getPasses () const {
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;
}

View File

@ -1,10 +1,14 @@
#pragma once
#include "WallpaperEngine/Core/Objects/Effects/CBind.h"
#include "WallpaperEngine/Core/Objects/Images/Materials/CPass.h"
#include "WallpaperEngine/Assets/CContainer.h"
#include "WallpaperEngine/Core/Core.h"
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h"
namespace WallpaperEngine::Core::Objects::Images::Materials {
class CPass;
}
namespace WallpaperEngine::Core::Objects::Images {
using json = nlohmann::json;
@ -15,29 +19,34 @@ using namespace WallpaperEngine::Assets;
*/
class CMaterial {
public:
static CMaterial* fromFile (const std::string& filename, Assets::CContainer* container);
static CMaterial* fromJSON (const std::string& name, json data);
static CMaterial* fromFile (const std::string& filename, const std::string& target, Assets::CContainer* container);
static CMaterial* fromJSON (const std::string& name, json data, const std::string& target);
/**
* @param pass The rendering pass to add to the material
*/
void insertPass (Materials::CPass* pass);
/**
* @param bind Texture bind override for the material
*/
void insertTextureBind (Effects::CBind* bind);
struct OverrideInfo {
std::map<std::string, int> combos;
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants;
std::map<int, std::string> textures;
};
static const CMaterial* fromFile (
const std::filesystem::path& filename, const 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
*/
[[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.
* 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
*/
@ -52,21 +61,21 @@ class CMaterial {
[[nodiscard]] const std::string& getName () const;
protected:
explicit CMaterial (std::string name);
/**
* @param target The new target while rendering this material
*/
void setTarget (const std::string& target);
CMaterial (
std::string name, std::map<int, const Effects::CBind*> textureBindings,
std::vector<const Materials::CPass*> passes);
CMaterial (
std::string name, std::string target, std::map<int, const Effects::CBind*> textureBindings,
const std::vector<const Materials::CPass*> passes);
private:
/** 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 */
std::map<int, Effects::CBind*> m_textureBindings;
const std::map<int, const Effects::CBind*> m_textureBindings;
/** The FBO target to render to (if any) */
std::string m_target;
const std::string m_target;
/** The material's name */
std::string m_name;
const std::string m_name;
};
} // namespace WallpaperEngine::Core::Objects::Images

View File

@ -7,72 +7,82 @@ using namespace WallpaperEngine::Core::Objects::Effects::Constants;
using namespace WallpaperEngine::Core::Objects::Images::Materials;
CPass::CPass (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite,
std::string shader) :
m_blending (std::move (blending)),
m_cullmode (std::move (cullmode)),
m_depthtest (std::move (depthtest)),
m_depthwrite (std::move (depthwrite)),
m_shader (std::move (shader)) {}
std::string shader, std::map<int, std::string> textures, std::map<std::string, int> combos,
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants) :
m_blending (blending),
m_cullmode (cullmode),
m_depthtest (depthtest),
m_depthwrite (depthwrite),
m_shader (shader),
m_textures (textures),
m_combos (combos),
m_constants (constants)
{}
CPass* CPass::fromJSON (json data) {
const CPass* CPass::fromJSON (const json& data, const CMaterial::OverrideInfo* overrides) {
// TODO: FIGURE OUT DEFAULT BLENDING MODE
const auto blending = jsonFindDefault<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 combos_it = data.find ("combos");
std::map<int, std::string> textures;
std::map<std::string, int> combos;
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants;
if (textures_it != data.end ()) {
// TODO: FETCH THIS FROM CImage TO MAKE IT COMPATIBLE WITH OLDER WALLPAPERS
if (!textures_it->is_array ())
sLog.exception ("Material's textures must be a list");
}
auto* pass = new CPass (blending, cullmode, *depthtest_it, *depthwrite_it, *shader_it);
if (textures_it != data.end ())
int textureNumber = -1;
for (const auto& cur : (*textures_it))
pass->insertTexture (cur.is_null () ? "" : cur);
textures.insert (std::pair (++textureNumber, cur.is_null () ? "" : cur));
}
if (combos_it != data.end ()) {
for (const auto& cur : combos_it->items ()) {
if (cur.value ().is_number_integer ())
pass->insertCombo (cur.key (), cur.value ());
else
if (cur.value ().is_number_integer ()) {
std::string uppercase = std::string (cur.key ());
std::transform (uppercase.begin (), uppercase.end (), uppercase.begin (), ::toupper);
combos.insert (std::pair (cur.key (), cur.value ()));
} else {
sLog.exception ("unexpected non-integer combo on pass");
}
}
}
return pass;
// apply overrides
if (overrides != nullptr) {
for (const auto& [name, value] : overrides->combos)
combos[name] = value;
for (const auto& [name, value] : overrides->constants)
constants[name] = value;
for (const auto& [id, value] : overrides->textures)
textures.insert(std::pair(id, value));
}
return new CPass (
jsonFindDefault<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) {
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 {
const std::map<int, std::string>& CPass::getTextures () const {
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;
}
std::map<std::string, int>* CPass::getCombos () {
return &this->m_combos;
const std::map<std::string, int>& CPass::getCombos () const {
return this->m_combos;
}
const std::string& CPass::getShader () const {
@ -94,11 +104,3 @@ const std::string& CPass::getDepthTest () const {
const std::string& CPass::getDepthWrite () const {
return this->m_depthwrite;
}
void CPass::setBlendingMode (const std::string& mode) {
this->m_blending = mode;
}
void CPass::insertConstant (const std::string& name, CShaderConstant* constant) {
this->m_constants.insert (std::pair (name, constant));
}

View File

@ -1,13 +1,17 @@
#pragma once
#include "WallpaperEngine/Core/Core.h"
#include "WallpaperEngine/Core/Objects/Images/CMaterial.h"
#include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h"
namespace WallpaperEngine::Core::Objects {
class CEffect;
}
namespace WallpaperEngine::Core::Objects::Images {
class CMaterial;
}
namespace WallpaperEngine::Core::Objects::Images::Materials {
using json = nlohmann::json;
@ -18,20 +22,20 @@ class CPass {
friend class WallpaperEngine::Core::Objects::CEffect;
public:
static CPass* fromJSON (json data);
static const CPass* fromJSON (const json& data, const CMaterial::OverrideInfo* overrides);
/**
* @return The list of textures to bind while rendering
*/
[[nodiscard]] const std::vector<std::string>& getTextures () const;
[[nodiscard]] const std::map<int, std::string>& getTextures () const;
/**
* @return Shader constants that alter how the shader should behave
*/
[[nodiscard]] const std::map<std::string, 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
*/
[[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
*/
@ -52,61 +56,29 @@ class CPass {
* @return If depth write has to happen while rendering
*/
[[nodiscard]] const std::string& getDepthWrite () const;
/**
* @param mode The new blending mode to use
*/
void setBlendingMode (const std::string& mode);
/**
* Add a shader combo value to the list
*
* @param name The combo name
* @param value It's value
*/
void insertCombo (const std::string& name, int value);
/**
* Adds a shader constant to the list
*
* @param name The constant's name
* @param constant It's value
*/
void insertConstant (const std::string& name, Effects::Constants::CShaderConstant* constant);
protected:
CPass (std::string blending, std::string cullmode, std::string depthtest, std::string depthwrite,
std::string shader);
/**
* Adds a new texture to the list of textures to bind while rendering
*
* @param texture
*/
void insertTexture (const std::string& texture);
/**
* Updates a texture in the specified index for binding while rendering
*
* @param index
* @param texture
*/
void setTexture (std::vector<std::string>::size_type index, const std::string& texture);
std::string shader, std::map<int, std::string> textures, std::map<std::string, int> combos,
std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*> constants);
private:
// TODO: CREATE ENUMERATIONS FOR THESE INSTEAD OF USING STRING VALUES!
/** The blending mode to use */
std::string m_blending;
const std::string m_blending;
/** The culling mode to use */
std::string m_cullmode;
const std::string m_cullmode;
/** If depthtesting has to happen while drawing */
std::string m_depthtest;
const std::string m_depthtest;
/** If depthwrite has to happen while drawing */
std::string m_depthwrite;
const std::string m_depthwrite;
/** The shader to use */
std::string m_shader;
const std::string m_shader;
/** The list of textures to use */
std::vector<std::string> m_textures;
const std::map<int, std::string> m_textures;
/** 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 */
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

View File

@ -2,31 +2,18 @@
using namespace WallpaperEngine::Core::Objects::Particles;
CControlPoint* CControlPoint::fromJSON (json data) {
const auto flags_it = data.find ("flags");
const auto id_it = jsonFindRequired (data, "id", "Particle's control point must have id");
const auto offset_it = data.find ("offset");
auto* controlpoint = new CControlPoint (*id_it, 0);
if (offset_it != data.end ())
controlpoint->setOffset (WallpaperEngine::Core::aToVector3 (*offset_it));
if (flags_it != data.end ())
controlpoint->setFlags (*flags_it);
return controlpoint;
const CControlPoint* CControlPoint::fromJSON (const json& data) {
return new CControlPoint (
jsonFindRequired <uint32_t> (data, "id", "Particle's control point must have id"),
jsonFindDefault (data, "flags", 0),
jsonFindDefault (data, "offset", glm::vec3())
);
}
CControlPoint::CControlPoint (uint32_t id, uint32_t flags) : m_id (id), m_flags (flags), m_offset (glm::vec3 ()) {}
void CControlPoint::setOffset (const glm::vec3& offset) {
this->m_offset = offset;
}
void CControlPoint::setFlags (uint32_t flags) {
this->m_flags = flags;
}
CControlPoint::CControlPoint (uint32_t id, uint32_t flags, glm::vec3 offset) :
m_id (id),
m_flags (flags),
m_offset (offset) {}
uint32_t CControlPoint::getId () const {
return this->m_id;

View File

@ -10,7 +10,7 @@ using json = nlohmann::json;
*/
class CControlPoint {
public:
static CControlPoint* fromJSON (json data);
static const CControlPoint* fromJSON (const json& data);
/**
* @return The id of the controlpoint used for ordering purposes
@ -26,23 +26,14 @@ class CControlPoint {
[[nodiscard]] uint32_t getFlags () const;
protected:
explicit CControlPoint (uint32_t id, uint32_t flags = 0);
/**
* @param offset The new offset
*/
void setOffset (const glm::vec3& offset);
/**
* @param flags The new flags
*/
void setFlags (uint32_t flags);
explicit CControlPoint (uint32_t id, uint32_t flags, glm::vec3 offset);
private:
/** ID used for ordering purposes */
uint32_t m_id;
const uint32_t m_id;
/** Flags that control how it behaves */
uint32_t m_flags;
const uint32_t m_flags;
/** The offset from starting position */
glm::vec3 m_offset;
const glm::vec3 m_offset;
};
} // namespace WallpaperEngine::Core::Objects::Particles

View File

@ -2,17 +2,12 @@
using namespace WallpaperEngine::Core::Objects::Particles;
CEmitter* CEmitter::fromJSON (json data) {
const auto directions_it = jsonFindRequired (data, "directions", "Particle emitter must have direction specified");
const CEmitter* CEmitter::fromJSON (const json& data) {
const auto distancemax_it = jsonFindRequired (data, "distancemax", "Particle emitter must have maximum distance");
const auto distancemin_it = jsonFindRequired (data, "distancemin", "Particle emitter must have minimum distance");
const auto id_it = data.find ("id");
const auto name_it = jsonFindRequired (data, "name", "Particle emitter must have a name");
const auto origin_it = jsonFindRequired (data, "origin", "Particle emitter must have an origin");
const auto rate_it = jsonFindRequired (data, "rate", "Particle emitter must have a rate");
glm::vec3 distancemin = glm::vec3(0);
glm::vec3 distancemax = glm::vec3(0);
auto distancemin = glm::vec3(0);
auto distancemax = glm::vec3(0);
if (distancemin_it->is_number()) {
distancemin = glm::vec3(static_cast<uint32_t>(*distancemin_it));
@ -26,18 +21,26 @@ CEmitter* CEmitter::fromJSON (json data) {
distancemax = WallpaperEngine::Core::aToVector3(*distancemax_it);
}
return new CEmitter (WallpaperEngine::Core::aToVector3 (*directions_it), distancemax, distancemin,
(id_it == data.end () ? 0 : static_cast<uint32_t> (*id_it)), *name_it,
WallpaperEngine::Core::aToVector3 (*origin_it), *rate_it);
return new CEmitter (
jsonFindRequired <glm::vec3> (data, "directions", "Particle emitter must have direction specified"),
distancemax,
distancemin,
jsonFindDefault (data, "id", 0),
jsonFindRequired <std::string> (data, "name", "Particle emitter must have a name"),
jsonFindRequired <glm::vec3> (data, "origin", "Particle emitter must have an origin"),
jsonFindRequired <double> (data, "rate", "Particle emitter must have a rate")
);
}
CEmitter::CEmitter (const glm::vec3& directions, const glm::vec3& distancemax, const glm::vec3& distancemin, uint32_t id,
std::string name, const glm::vec3& origin, double rate) :
CEmitter::CEmitter (
glm::vec3 directions, glm::vec3 distancemax, glm::vec3 distancemin, uint32_t id, std::string name, glm::vec3 origin,
double rate
) :
m_directions (directions),
m_distancemax (distancemax),
m_distancemin (distancemin),
m_id (id),
m_name (std::move (name)),
m_name (name),
m_origin (origin),
m_rate (rate) {}
@ -65,6 +68,6 @@ const glm::vec3& CEmitter::getOrigin () const {
return this->m_origin;
}
const double CEmitter::getRate () const {
double CEmitter::getRate () const {
return this->m_rate;
}

View File

@ -10,7 +10,7 @@ using json = nlohmann::json;
*/
class CEmitter {
public:
static CEmitter* fromJSON (json data);
static const CEmitter* fromJSON (const json& data);
/**
* @return The ID of the emitter
@ -39,25 +39,26 @@ class CEmitter {
/**
* @return The rate of particle emission
*/
[[nodiscard]] const double getRate () const;
[[nodiscard]] double getRate () const;
protected:
CEmitter (const glm::vec3& directions, const glm::vec3& distancemax, const glm::vec3& distancemin, uint32_t id, std::string name,
const glm::vec3& origin, double rate);
CEmitter (
glm::vec3 directions, glm::vec3 distancemax, glm::vec3 distancemin, uint32_t id, std::string name,
glm::vec3 origin, double rate);
private:
/** Direction the particles should move to */
glm::vec3 m_directions;
const glm::vec3 m_directions;
/** Maximum distance before the particle is dead */
glm::vec3 m_distancemax;
const glm::vec3 m_distancemax;
/** Minimum distance before the particle is dead */
glm::vec3 m_distancemin;
const glm::vec3 m_distancemin;
/** ID of the emitter */
uint32_t m_id;
const uint32_t m_id;
/** Name of the emitter, indicates the type of emitter */
std::string m_name;
const std::string m_name;
/** The center of the emitter */
glm::vec3 m_origin;
const glm::vec3 m_origin;
/** The rate of emission */
double m_rate;
};

View File

@ -12,40 +12,41 @@
using namespace WallpaperEngine::Core::Objects::Particles;
CInitializer* CInitializer::fromJSON (json data) {
const auto id_it = data.find ("id");
const auto name_it = jsonFindRequired (data, "name", "Particle's initializer must have a name");
const uint32_t id = ((id_it == data.end ()) ? 0 : static_cast<uint32_t> (*id_it));
const CInitializer* CInitializer::fromJSON (const json& data) {
const auto name = jsonFindRequired <std::string> (data, "name", "Particle's initializer must have a name");
const auto id = jsonFindDefault (data, "id", 0);
if (*name_it == "lifetimerandom") {
if (name == "lifetimerandom") {
return Initializers::CLifeTimeRandom::fromJSON (data, id);
}
if (*name_it == "sizerandom") {
if (name == "sizerandom") {
return Initializers::CSizeRandom::fromJSON (data, id);
}
if (*name_it == "rotationrandom") {
if (name == "rotationrandom") {
return Initializers::CRotationRandom::fromJSON (data, id);
}
if (*name_it == "velocityrandom") {
if (name == "velocityrandom") {
return Initializers::CVelocityRandom::fromJSON (data, id);
}
if (*name_it == "colorrandom") {
if (name == "colorrandom") {
return Initializers::CColorRandom::fromJSON (data, id);
}
if (*name_it == "alpharandom") {
if (name == "alpharandom") {
return Initializers::CAlphaRandom::fromJSON (data, id);
}
if (*name_it == "angularvelocityrandom") {
if (name == "angularvelocityrandom") {
return Initializers::CAngularVelocityRandom::fromJSON (data, id);
}
if (*name_it == "turbulentvelocityrandom") {
if (name == "turbulentvelocityrandom") {
return Initializers::CTurbulentVelocityRandom::fromJSON (data, id);
}
sLog.exception ("Found unknown initializer for particles: ", *name_it);
sLog.exception ("Found unknown initializer for particles: ", name);
}
CInitializer::CInitializer (uint32_t id, std::string name) : m_id (id), m_name (std::move (name)) {}
CInitializer::CInitializer (uint32_t id, std::string name) :
m_id (id),
m_name (name) {}
const std::string& CInitializer::getName () const {
return this->m_name;

View File

@ -11,7 +11,7 @@ using json = nlohmann::json;
*/
class CInitializer {
public:
static CInitializer* fromJSON (json data);
static const CInitializer* fromJSON (const json& data);
/**
* @return The name of the particle initializer, indicates what type of initialization to do
@ -27,8 +27,8 @@ class CInitializer {
private:
/** ID for ordering purposes */
uint32_t m_id;
const uint32_t m_id;
/** The name of the initializer, indicates what type of initialization to do */
std::string m_name;
const std::string m_name;
};
} // namespace WallpaperEngine::Core::Objects::Particles

View File

@ -2,11 +2,12 @@
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
CAlphaRandom* CAlphaRandom::fromJSON (json data, uint32_t id) {
const auto min_it = jsonFindRequired (data, "min", "Alpharandom initializer must have a minimum value");
const auto max_it = jsonFindRequired (data, "max", "Alpharandom initializer must have a maximum value");
return new CAlphaRandom (id, *min_it, *max_it);
const CAlphaRandom* CAlphaRandom::fromJSON (const json& data, uint32_t id) {
return new CAlphaRandom (
id,
jsonFindRequired<double> (data, "min", "Alpharandom initializer must have a minimum value"),
jsonFindRequired<double> (data, "max", "Alpharandom initializer must have a maximum value")
);
}
CAlphaRandom::CAlphaRandom (uint32_t id, double min, double max) :

View File

@ -21,14 +21,14 @@ class CAlphaRandom : CInitializer {
protected:
friend class CInitializer;
static CAlphaRandom* fromJSON (json data, uint32_t id);
static const CAlphaRandom* fromJSON (const json& data, uint32_t id);
CAlphaRandom (uint32_t id, double min, double max);
private:
/** Maximum alpha */
double m_max;
const double m_max;
/** Minimum alpha */
double m_min;
const double m_min;
};
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers

View File

@ -2,12 +2,12 @@
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
CAngularVelocityRandom* CAngularVelocityRandom::fromJSON (json data, uint32_t id) {
const auto min_it = jsonFindRequired (data, "min", "Angularvelocityrandom initializer must have a minimum value");
const auto max_it = jsonFindRequired (data, "max", "Angularvelocityrandom initializer must have a maximum value");
return new CAngularVelocityRandom (id, WallpaperEngine::Core::aToVector3 (*min_it),
WallpaperEngine::Core::aToVector3 (*max_it));
const CAngularVelocityRandom* CAngularVelocityRandom::fromJSON (const json& data, uint32_t id) {
return new CAngularVelocityRandom (
id,
jsonFindRequired <glm::vec3> (data, "min", "Angularvelocityrandom initializer must have a minimum value"),
jsonFindRequired <glm::vec3> (data, "max", "Angularvelocityrandom initializer must have a maximum value")
);
}
CAngularVelocityRandom::CAngularVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max) :

View File

@ -21,14 +21,14 @@ class CAngularVelocityRandom : CInitializer {
protected:
friend class CInitializer;
static CAngularVelocityRandom* fromJSON (json data, uint32_t id);
static const CAngularVelocityRandom* fromJSON (const json& data, uint32_t id);
CAngularVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max);
private:
/** Maximum velocity (direction * speed) */
glm::vec3 m_max;
const glm::vec3 m_max;
/** Minimum velocity (direction * speed) */
glm::vec3 m_min;
const glm::vec3 m_min;
};
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers

View File

@ -2,12 +2,12 @@
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
CColorRandom* CColorRandom::fromJSON (json data, uint32_t id) {
const auto min_it = jsonFindRequired (data, "min", "Colorrandom initializer must have a minimum value");
const auto max_it = jsonFindRequired (data, "max", "Colorrandom initializer must have a maximum value");
return new CColorRandom (id, WallpaperEngine::Core::aToColori (*min_it),
WallpaperEngine::Core::aToColori (*max_it));
const CColorRandom* CColorRandom::fromJSON (const json& data, uint32_t id) {
return new CColorRandom (
id,
jsonFindRequired <glm::ivec3> (data, "min", "Colorrandom initializer must have a minimum value"),
jsonFindRequired <glm::ivec3> (data, "max", "Colorrandom initializer must have a maximum value")
);
}
CColorRandom::CColorRandom (uint32_t id, glm::ivec3 min, glm::ivec3 max) :

View File

@ -22,14 +22,14 @@ class CColorRandom : CInitializer {
protected:
friend class CInitializer;
static CColorRandom* fromJSON (json data, uint32_t id);
static const CColorRandom* fromJSON (const json& data, uint32_t id);
CColorRandom (uint32_t id, glm::ivec3 min, glm::ivec3 max);
private:
/** Maximum color */
glm::ivec3 m_max;
const glm::ivec3 m_max;
/** Minimum color */
glm::ivec3 m_min;
const glm::ivec3 m_min;
};
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers

View File

@ -2,11 +2,12 @@
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
CLifeTimeRandom* CLifeTimeRandom::fromJSON (json data, uint32_t id) {
const auto min_it = jsonFindRequired (data, "min", "Lifetimerandom initializer must have a minimum value");
const auto max_it = jsonFindRequired (data, "max", "Lifetimerandom initializer must have a maximum value");
return new CLifeTimeRandom (id, *min_it, *max_it);
const CLifeTimeRandom* CLifeTimeRandom::fromJSON (const json& data, uint32_t id) {
return new CLifeTimeRandom (
id,
jsonFindRequired <uint32_t> (data, "min", "Lifetimerandom initializer must have a minimum value"),
jsonFindRequired <uint32_t> (data, "max", "Lifetimerandom initializer must have a maximum value")
);
}
CLifeTimeRandom::CLifeTimeRandom (uint32_t id, uint32_t min, uint32_t max) :

View File

@ -22,14 +22,14 @@ class CLifeTimeRandom : CInitializer {
protected:
friend class CInitializer;
static CLifeTimeRandom* fromJSON (json data, uint32_t id);
static const CLifeTimeRandom* fromJSON (const json& data, uint32_t id);
CLifeTimeRandom (uint32_t id, uint32_t min, uint32_t max);
private:
/** Maximum lifetime */
uint32_t m_max;
const uint32_t m_max;
/** Minimum lifetime */
uint32_t m_min;
const uint32_t m_min;
};
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers

View File

@ -4,7 +4,7 @@
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
CRotationRandom* CRotationRandom::fromJSON (json data, uint32_t id) {
const CRotationRandom* CRotationRandom::fromJSON (const json& data, uint32_t id) {
const auto min_it = data.find ("minVector");
const auto max_it = data.find ("max");

View File

@ -47,24 +47,24 @@ class CRotationRandom : CInitializer {
protected:
friend class CInitializer;
static CRotationRandom* fromJSON (json data, uint32_t id);
static const CRotationRandom* fromJSON (const json& data, uint32_t id);
CRotationRandom (uint32_t id, glm::vec3 minVector, double minNumber, bool isMinimumVector, glm::vec3 maxVector,
double maxNumber, bool isMaximumVector);
private:
/** Maximum rotation vector */
glm::vec3 m_maxVector;
const glm::vec3 m_maxVector;
/** Maximum rotation angle */
double m_maxNumber;
const double m_maxNumber;
/** Minimum rotation vector */
glm::vec3 m_minVector;
const glm::vec3 m_minVector;
/** Minimum rotation angle */
double m_minNumber;
const double m_minNumber;
/** If minimum is a vector */
bool m_isMinimumVector;
const bool m_isMinimumVector;
/** If maximum is a vector */
bool m_isMaximumVector;
const bool m_isMaximumVector;
};
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers

View File

@ -2,11 +2,12 @@
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
CSizeRandom* CSizeRandom::fromJSON (json data, uint32_t id) {
const auto min_it = jsonFindRequired (data, "min", "Sizerandom initializer must have a minimum value");
const auto max_it = jsonFindRequired (data, "max", "Sizerandom initializer must have a maximum value");
return new CSizeRandom (id, *min_it, *max_it);
const CSizeRandom* CSizeRandom::fromJSON (const json& data, uint32_t id) {
return new CSizeRandom (
id,
jsonFindRequired <uint32_t> (data, "min", "Sizerandom initializer must have a minimum value"),
jsonFindRequired <uint32_t> (data, "max", "Sizerandom initializer must have a maximum value")
);
}
CSizeRandom::CSizeRandom (uint32_t id, uint32_t min, uint32_t max) :

View File

@ -22,14 +22,14 @@ class CSizeRandom : CInitializer {
protected:
friend class CInitializer;
static CSizeRandom* fromJSON (json data, uint32_t id);
static const CSizeRandom* fromJSON (const json& data, uint32_t id);
CSizeRandom (uint32_t id, uint32_t min, uint32_t max);
private:
/** Maximum size */
uint32_t m_max;
const uint32_t m_max;
/** Minimum size */
uint32_t m_min;
const uint32_t m_min;
};
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers

View File

@ -5,25 +5,15 @@
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
CTurbulentVelocityRandom* CTurbulentVelocityRandom::fromJSON (json data, uint32_t id) {
const auto phasemax_it = data.find ("phasemax");
const auto scale_it = data.find ("scale");
const auto speedmax_it = data.find ("speedmax");
const auto speedmin_it = data.find ("speedmin");
const auto timescale_it = data.find ("timescale");
if (phasemax_it == data.end ())
sLog.exception ("TurbulentVelocityRandom initializer must have a phasemax value");
if (scale_it == data.end ())
sLog.exception ("TurbulentVelocityRandom initializer must have a scale value");
if (speedmax_it == data.end ())
sLog.exception ("TurbulentVelocityRandom initializer must have a maximum speed value");
if (speedmin_it == data.end ())
sLog.exception ("TurbulentVelocityRandom initializer must have a minimum speed value");
if (timescale_it == data.end ())
sLog.exception ("TurbulentVelocityRandom initializer must have a timescale value");
return new CTurbulentVelocityRandom (id, *phasemax_it, *scale_it, *timescale_it, *speedmin_it, *speedmax_it);
const CTurbulentVelocityRandom* CTurbulentVelocityRandom::fromJSON (const json& data, uint32_t id) {
return new CTurbulentVelocityRandom (
id,
jsonFindRequired <double> (data, "phasemax", "TurbulentVelocityRandom initializer must have a phasemax value"),
jsonFindRequired <double> (data, "scale", "TurbulentVelocityRandom initializer must have a scale value"),
jsonFindRequired <double>(data, "timescale", "TurbulentVelocityRandom initializer must have a timescale value"),
jsonFindRequired <uint32_t> (data, "speedmin", "TurbulentVelocityRandom initializer must have a minimum speed value"),
jsonFindRequired <uint32_t> (data, "speedmax", "TurbulentVelocityRandom initializer must have a maximum speed value")
);
}
CTurbulentVelocityRandom::CTurbulentVelocityRandom (uint32_t id, double phasemax, double scale, double timescale,

View File

@ -34,21 +34,21 @@ class CTurbulentVelocityRandom : CInitializer {
protected:
friend class CInitializer;
static CTurbulentVelocityRandom* fromJSON (json data, uint32_t id);
static const CTurbulentVelocityRandom* fromJSON (const json& data, uint32_t id);
CTurbulentVelocityRandom (uint32_t id, double phasemax, double scale, double timescale, uint32_t speedmin,
uint32_t speedmax);
private:
/** Phase */
double m_phasemax;
const double m_phasemax;
/** Scale */
double m_scale;
const double m_scale;
/** Time scale, how the time affects the scale */
double m_timescale;
const double m_timescale;
/** Minimum speed */
uint32_t m_speedmin;
const uint32_t m_speedmin;
/** Maximum speed */
uint32_t m_speedmax;
const uint32_t m_speedmax;
};
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers

View File

@ -2,12 +2,12 @@
using namespace WallpaperEngine::Core::Objects::Particles::Initializers;
CVelocityRandom* CVelocityRandom::fromJSON (json data, uint32_t id) {
const auto min_it = jsonFindRequired (data, "min", "Velocityrandom initializer must have a minimum value");
const auto max_it = jsonFindRequired (data, "max", "Velocityrandom initializer must have a maximum value");
return new CVelocityRandom (id, WallpaperEngine::Core::aToVector3 (*min_it),
WallpaperEngine::Core::aToVector3 (*max_it));
const CVelocityRandom* CVelocityRandom::fromJSON (const json& data, uint32_t id) {
return new CVelocityRandom (
id,
jsonFindRequired <glm::vec3> (data, "min", "Velocityrandom initializer must have a minimum value"),
jsonFindRequired <glm::vec3> (data, "max", "Velocityrandom initializer must have a maximum value")
);
}
CVelocityRandom::CVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max) :

View File

@ -22,14 +22,14 @@ class CVelocityRandom : CInitializer {
protected:
friend class CInitializer;
static CVelocityRandom* fromJSON (json data, uint32_t id);
static const CVelocityRandom* fromJSON (const json& data, uint32_t id);
CVelocityRandom (uint32_t id, glm::vec3 min, glm::vec3 max);
private:
/** Maximum velocity */
glm::vec3 m_max;
const glm::vec3 m_max;
/** Minimum velocity */
glm::vec3 m_min;
const glm::vec3 m_min;
};
} // namespace WallpaperEngine::Core::Objects::Particles::Initializers

View File

@ -9,7 +9,7 @@
using namespace WallpaperEngine::Core::Projects;
CProperty* CProperty::fromJSON (json data, const std::string& name) {
const CProperty* CProperty::fromJSON (const json& data, const std::string& name) {
const auto type = jsonFindRequired (data, "type", "Project properties must have the type field");
if (*type == CPropertyColor::Type)
@ -31,9 +31,9 @@ CProperty* CProperty::fromJSON (json data, const std::string& name) {
}
CProperty::CProperty (std::string name, std::string type, std::string text) :
m_type (std::move (type)),
m_name (std::move (name)),
m_text (std::move (text)) {}
m_type (type),
m_name (name),
m_text (text) {}
const std::string& CProperty::getName () const {
return this->m_name;

View File

@ -16,7 +16,7 @@ class CPropertyColor;
class CProperty {
public:
virtual ~CProperty () = default;
static CProperty* fromJSON (json data, const std::string& name);
static const CProperty* fromJSON (const json& data, const std::string& name);
template <class T> const T* as () const {
assert (is<T> ());
@ -28,7 +28,7 @@ class CProperty {
return reinterpret_cast<T*> (this);
}
template <class T> bool is () {
template <class T> bool is () const {
return this->m_type == T::Type;
}
@ -41,7 +41,7 @@ class CProperty {
*
* @param value New value for the property
*/
virtual void update (const std::string& value) = 0;
virtual void update (const std::string& value) const = 0;
/**
* @return Name of the property
@ -60,10 +60,10 @@ class CProperty {
CProperty (std::string name, std::string type, std::string text);
/** Type of property */
std::string m_type;
const std::string m_type;
/** Name of the property */
std::string m_name;
const std::string m_name;
/** Description of the property for the user */
std::string m_text;
mutable std::string m_text;
};
} // namespace WallpaperEngine::Core::Projects

View File

@ -5,18 +5,19 @@
using namespace WallpaperEngine::Core::Projects;
CPropertyBoolean* CPropertyBoolean::fromJSON (json data, const std::string& name) {
const json::const_iterator value = data.find ("value");
const auto text = jsonFindDefault<std::string> (data, "text", "");
return new CPropertyBoolean (*value, name, text);
const CPropertyBoolean* CPropertyBoolean::fromJSON (const json& data, std::string name) {
return new CPropertyBoolean (
jsonFindRequired <bool> (data, "value", "Boolean property must have a value"),
name,
jsonFindDefault<std::string> (data, "text", "")
);
}
bool CPropertyBoolean::getValue () const {
return this->m_value;
}
void CPropertyBoolean::update (const std::string& value) {
void CPropertyBoolean::update (const std::string& value) const {
this->m_value = value == "1" || value == "true";
}
@ -32,7 +33,7 @@ std::string CPropertyBoolean::dump () const {
return ss.str ();
}
CPropertyBoolean::CPropertyBoolean (bool value, const std::string& name, const std::string& text) :
CPropertyBoolean::CPropertyBoolean (bool value, std::string name, std::string text) :
CProperty (name, Type, text),
m_value (value) {}

View File

@ -10,7 +10,7 @@ using json = nlohmann::json;
*/
class CPropertyBoolean final : public CProperty {
public:
static CPropertyBoolean* fromJSON (json data, const std::string& name);
static const CPropertyBoolean* fromJSON (const json& data, std::string name);
/**
* @return The value of the property
@ -19,14 +19,14 @@ class CPropertyBoolean final : public CProperty {
/** @inheritdoc */
[[nodiscard]] std::string dump () const override;
/** @inheritdoc */
void update (const std::string& value) override;
void update (const std::string& value) const override;
static const std::string Type;
private:
CPropertyBoolean (bool value, const std::string& name, const std::string& text);
CPropertyBoolean (bool value, std::string name, std::string text);
/** Property's value */
bool m_value;
mutable bool m_value;
};
} // namespace WallpaperEngine::Core::Projects

View File

@ -19,7 +19,7 @@ glm::vec3 ParseColor (std::string value) {
return WallpaperEngine::Core::aToColorf (value);
}
CPropertyColor* CPropertyColor::fromJSON (json data, const std::string& name) {
const CPropertyColor* CPropertyColor::fromJSON (const json& data, std::string name) {
const std::string value = *jsonFindRequired (data, "value", "Color property must have a value");
const auto text = jsonFindDefault<std::string> (data, "text", "");
@ -30,7 +30,7 @@ const glm::vec3& CPropertyColor::getValue () const {
return this->m_color;
}
void CPropertyColor::update (const std::string& value) {
void CPropertyColor::update (const std::string& value) const {
this->m_color = ParseColor (std::string (value));
}
@ -46,7 +46,7 @@ std::string CPropertyColor::dump () const {
return ss.str ();
}
CPropertyColor::CPropertyColor (glm::vec3 color, const std::string& name, const std::string& text) :
CPropertyColor::CPropertyColor (glm::vec3 color, std::string name, std::string text) :
CProperty (name, Type, text),
m_color (color) {}

View File

@ -12,20 +12,20 @@ using json = nlohmann::json;
*/
class CPropertyColor final : public CProperty {
public:
static CPropertyColor* fromJSON (json data, const std::string& name);
static const CPropertyColor* fromJSON (const json& data, std::string name);
/**
* @return The RGB color value in the 0-1 range
*/
[[nodiscard]] const glm::vec3& getValue () const;
[[nodiscard]] std::string dump () const override;
void update (const std::string& value) override;
void update (const std::string& value) const override;
static const std::string Type;
private:
CPropertyColor (glm::vec3 color, const std::string& name, const std::string& text);
CPropertyColor (glm::vec3 color, std::string name, std::string text);
glm::vec3 m_color;
mutable glm::vec3 m_color;
};
} // namespace WallpaperEngine::Core::Projects

View File

@ -4,17 +4,13 @@
#include "WallpaperEngine/Core/Core.h"
#include "WallpaperEngine/Logging/CLog.h"
#include <utility>
using namespace WallpaperEngine::Core::Projects;
CPropertyCombo* CPropertyCombo::fromJSON (json data, const std::string& name) {
const auto value = data.find ("value");
const auto text = jsonFindDefault<std::string> (data, "text", "");
const CPropertyCombo* CPropertyCombo::fromJSON (const json& data, std::string name) {
std::vector<const CPropertyComboValue*> values;
const auto options = jsonFindRequired (data, "options", "Options for a property combo is required");
auto* combo = new CPropertyCombo (name, text, value->dump ());
if (!options->is_array ())
sLog.exception ("Property combo options should be an array");
@ -24,18 +20,27 @@ CPropertyCombo* CPropertyCombo::fromJSON (json data, const std::string& name) {
continue;
// check for label and value to ensure they're there
auto label = jsonFindRequired (cur, "label", "Label is required for a property combo option");
auto propertyValue = jsonFindRequired (cur, "value", "Value is required for a property combo option");
auto prop = new CPropertyComboValue {
.label = jsonFindRequired <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),
m_defaultValue (std::move (defaultValue)) {}
m_defaultValue (defaultValue) {}
CPropertyCombo::~CPropertyCombo () {
for (const auto* value : this->m_values)
@ -63,7 +68,7 @@ std::string CPropertyCombo::dump () const {
return ss.str ();
}
void CPropertyCombo::update (const std::string& value) {
void CPropertyCombo::update (const std::string& value) const {
bool found = false;
// ensure the value is present somewhere in the value list
@ -80,13 +85,4 @@ void CPropertyCombo::update (const std::string& value) {
this->m_defaultValue = value;
}
void CPropertyCombo::addValue (std::string label, std::string value) {
auto* prop = new CPropertyComboValue;
prop->label = std::move (label);
prop->value = std::move (value);
this->m_values.push_back (prop);
}
const std::string CPropertyCombo::Type = "combo";

View File

@ -10,8 +10,8 @@ using json = nlohmann::json;
*/
class CPropertyComboValue {
public:
std::string label;
std::string value;
const std::string label;
const std::string value;
};
/**
@ -23,7 +23,7 @@ class CPropertyComboValue {
*/
class CPropertyCombo final : public CProperty {
public:
static CPropertyCombo* fromJSON (json data, const std::string& name);
static const CPropertyCombo* fromJSON (const json& data, std::string name);
~CPropertyCombo () override;
@ -32,24 +32,17 @@ class CPropertyCombo final : public CProperty {
*/
[[nodiscard]] const std::string& getValue () const;
[[nodiscard]] std::string dump () const override;
void update (const std::string& value) override;
void update (const std::string& value) const override;
static const std::string Type;
private:
CPropertyCombo (const std::string& name, const std::string& text, std::string defaultValue);
/**
* Adds a combo value to the list of possible values
*
* @param label
* @param value
*/
void addValue (std::string label, std::string value);
CPropertyCombo (
std::string name, std::string text, std::string defaultValue, std::vector<const CPropertyComboValue*> values);
/** List of values available to select */
std::vector<CPropertyComboValue*> m_values;
const std::vector<const CPropertyComboValue*> m_values;
/** The default value */
std::string m_defaultValue;
mutable std::string m_defaultValue;
};
} // namespace WallpaperEngine::Core::Projects

View File

@ -4,7 +4,7 @@
using namespace WallpaperEngine::Core::Projects;
CPropertySlider* CPropertySlider::fromJSON (json data, const std::string& name) {
const CPropertySlider* CPropertySlider::fromJSON (const json& data, const std::string& name) {
const auto value = data.find ("value");
const auto text = jsonFindDefault<std::string> (data, "text", "");
const auto min = jsonFindDefault (data, "min", 0.0);
@ -48,8 +48,8 @@ std::string CPropertySlider::dump () const {
return ss.str ();
}
void CPropertySlider::update (const std::string& value) {
const double newValue = strtod (value.c_str (), nullptr);
void CPropertySlider::update (const std::string& value) const {
const auto newValue = strtod (value.c_str (), nullptr);
if (newValue < this->m_min || newValue > this->m_max)
sLog.exception ("Slider value (", newValue, ") is out of range (", this->m_min, ",", this->m_max, ")");

View File

@ -12,7 +12,7 @@ using json = nlohmann::json;
*/
class CPropertySlider final : public CProperty {
public:
static CPropertySlider* fromJSON (json data, const std::string& name);
static const CPropertySlider* fromJSON (const json& data, const std::string& name);
/**
* @return The slider's value
@ -31,21 +31,20 @@ class CPropertySlider final : public CProperty {
*/
[[nodiscard]] const double& getStep () const;
[[nodiscard]] std::string dump () const override;
void update (const std::string& value) override;
void update (const std::string& value) const override;
static const std::string Type;
private:
CPropertySlider (double value, const std::string& name, const std::string& text, double min, double max,
double step);
CPropertySlider (double value, const std::string& name, const std::string& text, double min, double max, double step);
/** Actual slider value */
double m_value;
mutable double m_value;
/** Minimum value */
double m_min;
const double m_min;
/** Maximum value */
double m_max;
const double m_max;
/** Increment steps for the slider in the UI */
double m_step;
const double m_step;
};
} // namespace WallpaperEngine::Core::Projects

View File

@ -4,8 +4,8 @@
using namespace WallpaperEngine::Core::Projects;
CPropertyText* CPropertyText::fromJSON (json data, const std::string& name) {
const json::const_iterator text = data.find ("type");
const CPropertyText* CPropertyText::fromJSON (const json& data, std::string name) {
const auto text = data.find ("type");
return new CPropertyText (name, *text);
}
@ -20,10 +20,10 @@ std::string CPropertyText::dump () const {
return ss.str ();
}
void CPropertyText::update (const std::string& value) {
void CPropertyText::update (const std::string& value) const {
this->m_text = value;
}
CPropertyText::CPropertyText (const std::string& name, const std::string& text) : CProperty (name, Type, text) {}
CPropertyText::CPropertyText (std::string name, std::string text) : CProperty (name, Type, text) {}
const std::string CPropertyText::Type = "text";

View File

@ -10,13 +10,13 @@ using json = nlohmann::json;
*/
class CPropertyText final : public CProperty {
public:
static CPropertyText* fromJSON (json data, const std::string& name);
static const CPropertyText* fromJSON (const json& data, std::string name);
[[nodiscard]] std::string dump () const override;
void update (const std::string& value) override;
void update (const std::string& value) const override;
static const std::string Type;
private:
CPropertyText (const std::string& name, const std::string& text);
CPropertyText (std::string name, std::string text);
};
} // namespace WallpaperEngine::Core::Projects

View File

@ -2,7 +2,10 @@
using namespace WallpaperEngine::Core::Scenes;
CCamera::CCamera (glm::vec3 center, glm::vec3 eye, glm::vec3 up) : m_center (center), m_eye (eye), m_up (up) {}
CCamera::CCamera (glm::vec3 center, glm::vec3 eye, glm::vec3 up) :
m_center (center),
m_eye (eye),
m_up (up) {}
const glm::vec3& CCamera::getCenter () const {
return this->m_center;
@ -16,11 +19,10 @@ const glm::vec3& CCamera::getUp () const {
return this->m_up;
}
CCamera* CCamera::fromJSON (json data) {
const auto center_it = jsonFindRequired (data, "center", "Camera must have a center position");
const auto eye_it = jsonFindRequired (data, "eye", "Camera must have an eye position");
const auto up_it = jsonFindRequired (data, "up", "Camera must have a up position");
return new CCamera (WallpaperEngine::Core::aToVector3 (*center_it), WallpaperEngine::Core::aToVector3 (*eye_it),
WallpaperEngine::Core::aToVector3 (*up_it));
const CCamera* CCamera::fromJSON (const json::const_iterator& data) {
return new CCamera (
jsonFindRequired <glm::vec3> (data, "center", "Camera must have a center position"),
jsonFindRequired <glm::vec3> (data, "eye", "Camera must have an eye position"),
jsonFindRequired <glm::vec3> (data, "up", "Camera must have a up position")
);
}

View File

@ -7,7 +7,7 @@ using json = nlohmann::json;
class CCamera {
public:
static CCamera* fromJSON (json data);
static const CCamera* fromJSON (const json::const_iterator& data);
const glm::vec3& getCenter () const;
const glm::vec3& getEye () const;
@ -17,8 +17,8 @@ class CCamera {
CCamera (glm::vec3 center, glm::vec3 eye, glm::vec3 up);
private:
glm::vec3 m_center;
glm::vec3 m_eye;
glm::vec3 m_up;
const glm::vec3 m_center;
const glm::vec3 m_eye;
const glm::vec3 m_up;
};
} // namespace WallpaperEngine::Core::Scenes

View File

@ -2,9 +2,15 @@
using namespace WallpaperEngine::Core::Scenes;
CProjection::CProjection (int width, int height) : m_width (width), m_height (height), m_isAuto (false) {}
CProjection::CProjection (int width, int height) :
m_width (width),
m_height (height),
m_isAuto (false) {}
CProjection::CProjection (bool isAuto) : m_width (0), m_height (0), m_isAuto (isAuto) {}
CProjection::CProjection (bool isAuto) :
m_width (0),
m_height (0),
m_isAuto (isAuto) {}
const int& CProjection::getWidth () const {
return this->m_width;
@ -18,15 +24,15 @@ bool CProjection::isAuto () const {
return this->m_isAuto;
}
void CProjection::setWidth (int width) {
void CProjection::setWidth (int width) const {
this->m_width = width;
}
void CProjection::setHeight (int height) {
void CProjection::setHeight (int height) const {
this->m_height = height;
}
CProjection* CProjection::fromJSON (json data) {
const CProjection* CProjection::fromJSON (const json::const_iterator& data) {
const auto auto_it = jsonFindDefault<bool> (data, "auto", false);
const auto width_it = jsonFindRequired (data, "width", "Projection must have width");

View File

@ -7,22 +7,23 @@ using json = nlohmann::json;
class CProjection {
public:
static CProjection* fromJSON (json data);
static const CProjection* fromJSON (const json::const_iterator& data);
[[nodiscard]] const int& getWidth () const;
[[nodiscard]] const int& getHeight () const;
[[nodiscard]] bool isAuto () const;
void setWidth (int width);
void setHeight (int height);
// TODO: CHANGE THIS SO THE RENDER IS THE ONE RESPONSIBLE FOR THIS?
void setWidth (int width) const;
void setHeight (int height) const;
protected:
CProjection (int width, int height);
explicit CProjection (bool isAuto);
private:
int m_width;
int m_height;
bool m_isAuto;
mutable int m_width;
mutable int m_height;
const bool m_isAuto;
};
} // namespace WallpaperEngine::Core::Scenes

View File

@ -12,16 +12,17 @@ using namespace WallpaperEngine::Core;
using namespace WallpaperEngine::Core::Projects;
using namespace WallpaperEngine::Core::UserSettings;
CUserSettingBoolean::CUserSettingBoolean (bool hasCondition, bool hasSource, bool defaultValue, std::string source,
std::string expectedValue) :
CUserSettingBoolean::CUserSettingBoolean (
bool hasCondition,bool hasSource, bool defaultValue, std::string source, std::string expectedValue
) :
CUserSettingValue (Type),
m_default (defaultValue),
m_hasCondition (hasCondition),
m_hasSource (hasSource),
m_source (std::move (source)),
m_expectedValue (std::move (expectedValue)) {}
m_source (source),
m_expectedValue (expectedValue) {}
CUserSettingBoolean* CUserSettingBoolean::fromJSON (nlohmann::json& data) {
const CUserSettingBoolean* CUserSettingBoolean::fromJSON (const nlohmann::json& data) {
bool hasCondition = false;
bool hasSource = false;
bool defaultValue;
@ -38,9 +39,9 @@ CUserSettingBoolean* CUserSettingBoolean::fromJSON (nlohmann::json& data) {
source = *userIt;
} else {
hasCondition = true;
source = *jsonFindRequired (userIt, "name", "Name for conditional setting must be present");
source = jsonFindRequired <std::string> (userIt, "name", "Name for conditional setting must be present");
expectedValue =
*jsonFindRequired (userIt, "condition", "Condition for conditional setting must be present");
jsonFindRequired <std::string> (userIt, "condition", "Condition for conditional setting must be present");
}
} else {
sLog.error ("Boolean property doesn't have user member, this could mean an scripted value");
@ -55,7 +56,7 @@ CUserSettingBoolean* CUserSettingBoolean::fromJSON (nlohmann::json& data) {
return new CUserSettingBoolean (hasCondition, hasSource, defaultValue, source, expectedValue);
}
CUserSettingBoolean* CUserSettingBoolean::fromScalar (bool value) {
const CUserSettingBoolean* CUserSettingBoolean::fromScalar (const bool value) {
return new CUserSettingBoolean (false, false, value, "", "");
}
@ -63,7 +64,7 @@ bool CUserSettingBoolean::getDefaultValue () const {
return this->m_default;
}
bool CUserSettingBoolean::processValue (const std::vector<Projects::CProperty*>& properties) {
bool CUserSettingBoolean::processValue (const std::vector<const Projects::CProperty*>& properties) const {
if (!this->m_hasSource && !this->m_hasCondition)
return this->getDefaultValue ();

View File

@ -11,21 +11,21 @@ class CUserSettingBoolean : public CUserSettingValue {
public:
typedef bool data_type;
static CUserSettingBoolean* fromJSON (nlohmann::json& data);
static CUserSettingBoolean* fromScalar (bool value);
static const CUserSettingBoolean* fromJSON (const nlohmann::json& data);
static const CUserSettingBoolean* fromScalar (const bool value);
static std::string Type;
bool processValue (const std::vector<Projects::CProperty*>& properties);
bool getDefaultValue () const;
[[nodiscard]] bool processValue (const std::vector<const Projects::CProperty*>& properties) const;
[[nodiscard]] bool getDefaultValue () const;
private:
CUserSettingBoolean (bool hasCondition, bool hasSource, bool defaultValue, std::string source,
std::string expectedValue);
CUserSettingBoolean (
bool hasCondition, bool hasSource, bool defaultValue, std::string source, std::string expectedValue);
bool m_default;
bool m_hasCondition;
bool m_hasSource;
std::string m_source;
std::string m_expectedValue;
const bool m_default;
const bool m_hasCondition;
const bool m_hasSource;
const std::string m_source;
const std::string m_expectedValue;
};
} // namespace WallpaperEngine::Core::UserSettings

View File

@ -9,16 +9,17 @@ using namespace WallpaperEngine::Core;
using namespace WallpaperEngine::Core::Projects;
using namespace WallpaperEngine::Core::UserSettings;
CUserSettingFloat::CUserSettingFloat (bool hasCondition, bool hasSource, double defaultValue, std::string source,
std::string expectedValue) :
CUserSettingFloat::CUserSettingFloat (
bool hasCondition, bool hasSource, double defaultValue, std::string source, std::string expectedValue
) :
CUserSettingValue (Type),
m_default (defaultValue),
m_hasCondition (hasCondition),
m_hasSource (hasSource),
m_source (std::move (source)),
m_expectedValue (std::move (expectedValue)) {}
m_source (source),
m_expectedValue (expectedValue) {}
CUserSettingFloat* CUserSettingFloat::fromJSON (nlohmann::json& data) {
const CUserSettingFloat* CUserSettingFloat::fromJSON (const nlohmann::json& data) {
double defaultValue;
std::string source;
std::string expectedValue;
@ -35,9 +36,9 @@ CUserSettingFloat* CUserSettingFloat::fromJSON (nlohmann::json& data) {
source = *userIt;
} else {
hasCondition = true;
source = *jsonFindRequired (userIt, "name", "Name for conditional setting must be present");
source = jsonFindRequired <std::string> (userIt, "name", "Name for conditional setting must be present");
expectedValue =
*jsonFindRequired (userIt, "condition", "Condition for conditional setting must be present");
jsonFindRequired <std::string> (userIt, "condition", "Condition for conditional setting must be present");
}
} else {
sLog.error ("Float property doesn't have user member, this could mean an scripted value");
@ -52,7 +53,7 @@ CUserSettingFloat* CUserSettingFloat::fromJSON (nlohmann::json& data) {
return new CUserSettingFloat (hasCondition, hasSource, defaultValue, source, expectedValue);
}
CUserSettingFloat* CUserSettingFloat::fromScalar (double value) {
const CUserSettingFloat* CUserSettingFloat::fromScalar (const double value) {
return new CUserSettingFloat (false, false, value, "", "");
}
@ -60,7 +61,7 @@ double CUserSettingFloat::getDefaultValue () const {
return this->m_default;
}
double CUserSettingFloat::processValue (const std::vector<Projects::CProperty*>& properties) {
double CUserSettingFloat::processValue (const std::vector<const Projects::CProperty*>& properties) const {
if (!this->m_hasSource && !this->m_hasCondition)
return this->getDefaultValue ();

View File

@ -11,21 +11,21 @@ class CUserSettingFloat : public CUserSettingValue {
public:
typedef double data_type;
static CUserSettingFloat* fromJSON (nlohmann::json& data);
static CUserSettingFloat* fromScalar (double value);
static const CUserSettingFloat* fromJSON (const nlohmann::json& data);
static const CUserSettingFloat* fromScalar (const double value);
static std::string Type;
double processValue (const std::vector<Projects::CProperty*>& properties);
double getDefaultValue () const;
[[nodiscard]] double processValue (const std::vector<const Projects::CProperty*>& properties) const;
[[nodiscard]] double getDefaultValue () const;
private:
CUserSettingFloat (bool hasCondition, bool hasSource, double defaultValue, std::string source,
std::string expectedValue);
CUserSettingFloat (
bool hasCondition, bool hasSource, double defaultValue, std::string source, std::string expectedValue);
double m_default;
bool m_hasCondition;
bool m_hasSource;
std::string m_source;
std::string m_expectedValue;
const double m_default;
const bool m_hasCondition;
const bool m_hasSource;
const std::string m_source;
const std::string m_expectedValue;
};
} // namespace WallpaperEngine::Core::UserSettings

View File

@ -4,4 +4,5 @@
using namespace WallpaperEngine::Core::UserSettings;
CUserSettingValue::CUserSettingValue (std::string type) : m_type (std::move (type)) {}
CUserSettingValue::CUserSettingValue (std::string type) :
m_type (type) {}

View File

@ -15,7 +15,7 @@ class CUserSettingValue {
return reinterpret_cast<T*> (this);
}
template <class T> bool is () {
template <class T> bool is () const {
return this->m_type == T::Type;
}
@ -23,6 +23,6 @@ class CUserSettingValue {
explicit CUserSettingValue (std::string type);
private:
std::string m_type;
const std::string m_type;
};
} // namespace WallpaperEngine::Core::UserSettings

View File

@ -10,16 +10,17 @@ using namespace WallpaperEngine::Core;
using namespace WallpaperEngine::Core::Projects;
using namespace WallpaperEngine::Core::UserSettings;
CUserSettingVector3::CUserSettingVector3 (bool hasCondition, bool hasSource, glm::vec3 defaultValue, std::string source,
std::string expectedValue) :
CUserSettingVector3::CUserSettingVector3 (
bool hasCondition, bool hasSource, glm::vec3 defaultValue, std::string source, std::string expectedValue
) :
CUserSettingValue (Type),
m_default (defaultValue),
m_hasCondition (hasCondition),
m_hasSource (hasSource),
m_source (std::move (source)),
m_expectedValue (std::move (expectedValue)) {}
m_source (source),
m_expectedValue (expectedValue) {}
CUserSettingVector3* CUserSettingVector3::fromJSON (nlohmann::json& data) {
const CUserSettingVector3* CUserSettingVector3::fromJSON (const nlohmann::json& data) {
bool hasCondition = false;
bool hasSource = false;
glm::vec3 defaultValue;
@ -29,17 +30,16 @@ CUserSettingVector3* CUserSettingVector3::fromJSON (nlohmann::json& data) {
if (data.is_object ()) {
hasSource = true;
auto userIt = data.find ("user");
defaultValue = WallpaperEngine::Core::aToColorf (
jsonFindDefault<std::string> (data, "value", "").c_str ()); // is this default value right?
defaultValue = jsonFindDefault (data, "value", glm::vec3()); // is this default value right?
if (userIt != data.end ()) {
if (userIt->is_string ()) {
source = *userIt;
} else {
hasCondition = true;
source = *jsonFindRequired (userIt, "name", "Name for conditional setting must be present");
source = jsonFindRequired <std::string> (userIt, "name", "Name for conditional setting must be present");
expectedValue =
*jsonFindRequired (userIt, "condition", "Condition for conditional setting must be present");
jsonFindRequired <std::string> (userIt, "condition", "Condition for conditional setting must be present");
}
} else {
sLog.error ("Vector property doesn't have user member, this could mean an scripted value");
@ -54,15 +54,15 @@ CUserSettingVector3* CUserSettingVector3::fromJSON (nlohmann::json& data) {
return new CUserSettingVector3 (hasCondition, hasSource, defaultValue, source, expectedValue);
}
CUserSettingVector3* CUserSettingVector3::fromScalar (glm::vec3 value) {
const CUserSettingVector3* CUserSettingVector3::fromScalar (const glm::vec3 value) {
return new CUserSettingVector3 (false, false, value, "", "");
}
glm::vec3 CUserSettingVector3::getDefaultValue () const {
const glm::vec3& CUserSettingVector3::getDefaultValue () const {
return this->m_default;
}
glm::vec3 CUserSettingVector3::processValue (const std::vector<Projects::CProperty*>& properties) {
const glm::vec3& CUserSettingVector3::processValue (const std::vector<const Projects::CProperty*>& properties) const {
if (!this->m_hasSource && !this->m_hasCondition)
return this->getDefaultValue ();

View File

@ -13,21 +13,21 @@ class CUserSettingVector3 : public CUserSettingValue {
public:
typedef glm::vec3 data_type;
static CUserSettingVector3* fromJSON (nlohmann::json& data);
static CUserSettingVector3* fromScalar (glm::vec3 value);
static const CUserSettingVector3* fromJSON (const nlohmann::json& data);
static const CUserSettingVector3* fromScalar (const glm::vec3 value);
static std::string Type;
glm::vec3 processValue (const std::vector<Projects::CProperty*>& properties);
glm::vec3 getDefaultValue () const;
[[nodiscard]] const glm::vec3& processValue (const std::vector<const Projects::CProperty*>& properties) const;
[[nodiscard]] const glm::vec3& getDefaultValue () const;
private:
CUserSettingVector3 (bool hasCondition, bool hasSource, glm::vec3 defaultValue, std::string source,
std::string expectedValue);
CUserSettingVector3 (
bool hasCondition, bool hasSource, glm::vec3 defaultValue, std::string source, std::string expectedValue);
glm::vec3 m_default;
bool m_hasCondition;
bool m_hasSource;
std::string m_source;
std::string m_expectedValue;
const glm::vec3 m_default;
const bool m_hasCondition;
const bool m_hasSource;
const std::string m_source;
const std::string m_expectedValue;
};
} // namespace WallpaperEngine::Core::UserSettings

View File

@ -8,12 +8,14 @@
using namespace WallpaperEngine::Core;
using namespace WallpaperEngine::Core::Wallpapers;
CScene::CScene (CProject& project, CContainer* container, Scenes::CCamera* camera, glm::vec3 ambientColor,
CUserSettingBoolean* bloom, CUserSettingFloat* bloomStrength, CUserSettingFloat* bloomThreshold,
CScene::CScene (
const CProject& project, const CContainer* container, const Scenes::CCamera* camera, glm::vec3 ambientColor,
const CUserSettingBoolean* bloom, const CUserSettingFloat* bloomStrength, const CUserSettingFloat* bloomThreshold,
bool cameraFade, bool cameraParallax, double cameraParallaxAmount, double cameraParallaxDelay,
double cameraParallaxMouseInfluence, bool cameraPreview, bool cameraShake, double cameraShakeAmplitude,
double cameraShakeRoughness, double cameraShakeSpeed, CUserSettingVector3* clearColor,
Scenes::CProjection* orthogonalProjection, glm::vec3 skylightColor) :
double cameraShakeRoughness, double cameraShakeSpeed, const CUserSettingVector3* clearColor,
const Scenes::CProjection* orthogonalProjection, glm::vec3 skylightColor
) :
CWallpaper (Type, project),
m_container (container),
m_camera (camera),
@ -35,41 +37,36 @@ CScene::CScene (CProject& project, CContainer* container, Scenes::CCamera* camer
m_orthogonalProjection (orthogonalProjection),
m_skylightColor (skylightColor) {}
CScene* CScene::fromFile (const std::string& filename, CProject& project, CContainer* container) {
const CScene* CScene::fromFile (std::string filename, const CProject& project, const CContainer* container) {
json content = json::parse (container->readFileAsString (filename));
const auto camera_it = jsonFindRequired (content, "camera", "Scenes must have a defined camera");
const auto general_it = jsonFindRequired (content, "general", "Scenes must have a general section");
const auto objects_it = jsonFindRequired (content, "objects", "Scenes must have a list of objects to display");
// TODO: FIND IF THESE DEFAULTS ARE SENSIBLE OR NOT AND PERFORM PROPER VALIDATION WHEN CAMERA PREVIEW AND CAMERA
// PARALLAX ARE PRESENT
const auto ambientcolor = jsonFindDefault<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 (
project, container, Scenes::CCamera::fromJSON (*camera_it), WallpaperEngine::Core::aToColorf (ambientcolor),
bloom, bloomstrength, bloomthreshold, camerafade, cameraparallax, cameraparallaxamount, cameraparallaxdelay,
cameraparallaxmouseinfluence, camerapreview, camerashake, camerashakeamplitude, camerashakeroughness,
camerashakespeed, clearcolor, Scenes::CProjection::fromJSON (*orthogonalprojection_it),
WallpaperEngine::Core::aToColorf (skylightcolor));
project, container,
Scenes::CCamera::fromJSON (jsonFindRequired (content, "camera", "Scenes must have a defined camera")),
jsonFindDefault<glm::vec3> (*general_it, "ambientcolor", glm::vec3 (0, 0, 0)),
jsonFindUserConfig<CUserSettingBoolean> (*general_it, "bloom", false),
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)
scene->insertObject (CObject::fromJSON (cur, scene, container));
@ -77,23 +74,23 @@ CScene* CScene::fromFile (const std::string& filename, CProject& project, CConta
return scene;
}
const std::map<uint32_t, CObject*>& CScene::getObjects () const {
const std::map<uint32_t, const CObject*>& CScene::getObjects () const {
return this->m_objects;
}
const std::vector<CObject*>& CScene::getObjectsByRenderOrder () const {
const std::vector<const CObject*>& CScene::getObjectsByRenderOrder () const {
return this->m_objectsByRenderOrder;
}
void CScene::insertObject (CObject* object) {
void CScene::insertObject (const CObject* object) {
/// TODO: XXXHACK -- TO REMOVE WHEN PARTICLE SUPPORT IS PROPERLY IMPLEMENTED
if (object != nullptr) {
this->m_objects.insert (std::make_pair (object->getId (), object));
this->m_objects.insert (std::pair (object->getId (), object));
this->m_objectsByRenderOrder.emplace_back (object);
}
}
CContainer* CScene::getContainer () {
const CContainer* CScene::getContainer () const {
return this->m_container;
}
@ -105,7 +102,7 @@ const glm::vec3& CScene::getAmbientColor () const {
return this->m_ambientColor;
}
const bool CScene::isBloom () const {
bool CScene::isBloom () const {
return this->m_bloom->processValue (this->getProject ().getProperties ());
}
@ -117,51 +114,51 @@ double CScene::getBloomThreshold () const {
return this->m_bloomThreshold->processValue (this->getProject ().getProperties ());
}
const bool CScene::isCameraFade () const {
bool CScene::isCameraFade () const {
return this->m_cameraFade;
}
const bool CScene::isCameraParallax () const {
bool CScene::isCameraParallax () const {
return this->m_cameraParallax;
}
const double CScene::getCameraParallaxAmount () const {
double CScene::getCameraParallaxAmount () const {
return this->m_cameraParallaxAmount;
}
const double CScene::getCameraParallaxDelay () const {
double CScene::getCameraParallaxDelay () const {
return this->m_cameraParallaxDelay;
}
const double CScene::getCameraParallaxMouseInfluence () const {
double CScene::getCameraParallaxMouseInfluence () const {
return this->m_cameraParallaxMouseInfluence;
}
const bool CScene::isCameraPreview () const {
bool CScene::isCameraPreview () const {
return this->m_cameraPreview;
}
const bool CScene::isCameraShake () const {
bool CScene::isCameraShake () const {
return this->m_cameraShake;
}
const double CScene::getCameraShakeAmplitude () const {
double CScene::getCameraShakeAmplitude () const {
return this->m_cameraShakeAmplitude;
}
const double CScene::getCameraShakeRoughness () const {
double CScene::getCameraShakeRoughness () const {
return this->m_cameraShakeRoughness;
}
const double CScene::getCameraShakeSpeed () const {
double CScene::getCameraShakeSpeed () const {
return this->m_cameraShakeSpeed;
}
glm::vec3 CScene::getClearColor () const {
const glm::vec3& CScene::getClearColor () const {
return this->m_clearColor->processValue (this->getProject ().getProperties ());
}
Scenes::CProjection* CScene::getOrthogonalProjection () const {
const Scenes::CProjection* CScene::getOrthogonalProjection () const {
return this->m_orthogonalProjection;
}

View File

@ -17,70 +17,71 @@ using json = nlohmann::json;
class CScene : public CWallpaper {
public:
static CScene* fromFile (const std::string& filename, CProject& project, CContainer* container);
static const CScene* fromFile (std::string filename, const CProject& project, const CContainer* container);
const std::map<uint32_t, CObject*>& getObjects () const;
const std::vector<CObject*>& getObjectsByRenderOrder () const;
[[nodiscard]] const std::map<uint32_t, const CObject*>& getObjects () const;
[[nodiscard]] const std::vector<const CObject*>& getObjectsByRenderOrder () const;
const glm::vec3& getAmbientColor () const;
const bool isBloom () const;
double getBloomStrength () const;
double getBloomThreshold () const;
const bool isCameraFade () const;
const bool isCameraParallax () const;
const double getCameraParallaxAmount () const;
const double getCameraParallaxDelay () const;
const double getCameraParallaxMouseInfluence () const;
const bool isCameraPreview () const;
const bool isCameraShake () const;
const double getCameraShakeAmplitude () const;
const double getCameraShakeRoughness () const;
const double getCameraShakeSpeed () const;
glm::vec3 getClearColor () const;
Scenes::CProjection* getOrthogonalProjection () const;
const glm::vec3& getSkylightColor () const;
const Scenes::CCamera* getCamera () const;
[[nodiscard]] const glm::vec3& getAmbientColor () const;
[[nodiscard]] bool isBloom () const;
[[nodiscard]] double getBloomStrength () const;
[[nodiscard]] double getBloomThreshold () const;
[[nodiscard]] bool isCameraFade () const;
[[nodiscard]] bool isCameraParallax () const;
[[nodiscard]] double getCameraParallaxAmount () const;
[[nodiscard]] double getCameraParallaxDelay () const;
[[nodiscard]] double getCameraParallaxMouseInfluence () const;
[[nodiscard]] bool isCameraPreview () const;
[[nodiscard]] bool isCameraShake () const;
[[nodiscard]] double getCameraShakeAmplitude () const;
[[nodiscard]] double getCameraShakeRoughness () const;
[[nodiscard]] double getCameraShakeSpeed () const;
[[nodiscard]] const glm::vec3& getClearColor () const;
[[nodiscard]] const Scenes::CProjection* getOrthogonalProjection () const;
[[nodiscard]] const glm::vec3& getSkylightColor () const;
[[nodiscard]] const Scenes::CCamera* getCamera () const;
protected:
friend class CWallpaper;
CScene (CProject& project, CContainer* container, Scenes::CCamera* camera, glm::vec3 ambientColor,
CUserSettingBoolean* bloom, CUserSettingFloat* bloomStrength, CUserSettingFloat* bloomThreshold,
CScene (
const CProject& project, const CContainer* container, const Scenes::CCamera* camera, glm::vec3 ambientColor,
const CUserSettingBoolean* bloom, const CUserSettingFloat* bloomStrength, const CUserSettingFloat* bloomThreshold,
bool cameraFade, bool cameraParallax, double cameraParallaxAmount, double cameraParallaxDelay,
double cameraParallaxMouseInfluence, bool cameraPreview, bool cameraShake, double cameraShakeAmplitude,
double cameraShakeRoughness, double cameraShakeSpeed, CUserSettingVector3* clearColor,
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;
void insertObject (CObject* object);
void insertObject (const CObject* object);
CContainer* getContainer ();
const CContainer* getContainer () const;
private:
CContainer* m_container;
Scenes::CCamera* m_camera;
const CContainer* m_container;
const Scenes::CCamera* m_camera;
// data from general section on the json
glm::vec3 m_ambientColor;
CUserSettingBoolean* m_bloom;
CUserSettingFloat* m_bloomStrength;
CUserSettingFloat* m_bloomThreshold;
bool m_cameraFade;
bool m_cameraParallax;
double m_cameraParallaxAmount;
double m_cameraParallaxDelay;
double m_cameraParallaxMouseInfluence;
bool m_cameraPreview;
bool m_cameraShake;
double m_cameraShakeAmplitude;
double m_cameraShakeRoughness;
double m_cameraShakeSpeed;
CUserSettingVector3* m_clearColor;
Scenes::CProjection* m_orthogonalProjection;
glm::vec3 m_skylightColor;
const glm::vec3 m_ambientColor;
const CUserSettingBoolean* m_bloom;
const CUserSettingFloat* m_bloomStrength;
const CUserSettingFloat* m_bloomThreshold;
const bool m_cameraFade;
const bool m_cameraParallax;
const double m_cameraParallaxAmount;
const double m_cameraParallaxDelay;
const double m_cameraParallaxMouseInfluence;
const bool m_cameraPreview;
const bool m_cameraShake;
const double m_cameraShakeAmplitude;
const double m_cameraShakeRoughness;
const double m_cameraShakeSpeed;
const CUserSettingVector3* m_clearColor;
const Scenes::CProjection* m_orthogonalProjection;
const glm::vec3 m_skylightColor;
std::map<uint32_t, CObject*> m_objects;
std::vector<CObject*> m_objectsByRenderOrder;
std::map<uint32_t, const CObject*> m_objects;
std::vector<const CObject*> m_objectsByRenderOrder;
};
} // namespace WallpaperEngine::Core

View File

@ -5,11 +5,11 @@
using namespace WallpaperEngine::Core;
using namespace WallpaperEngine::Core::Wallpapers;
CVideo::CVideo (std::string filename, CProject& project) :
CVideo::CVideo (std::string filename, const CProject& project) :
CWallpaper (Type, project),
m_filename (std::move (filename)) {}
m_filename (filename) {}
const std::string& CVideo::getFilename () {
const std::string& CVideo::getFilename () const {
return this->m_filename;
}

View File

@ -13,9 +13,9 @@ extern "C" {
namespace WallpaperEngine::Core::Wallpapers {
class CVideo : public CWallpaper {
public:
explicit CVideo (std::string filename, CProject& project);
CVideo (std::string filename, const CProject& project);
const std::string& getFilename ();
const std::string& getFilename () const;
protected:
friend class CWallpaper;

View File

@ -5,10 +5,12 @@
using namespace WallpaperEngine::Core;
using namespace WallpaperEngine::Core::Wallpapers;
const std::string& CWeb::getFilename () {
const std::string& CWeb::getFilename () const {
return this->m_filename;
}
CWeb::CWeb (std::string filename, CProject& project) : CWallpaper (Type, project), m_filename (std::move (filename)) {}
CWeb::CWeb (std::string filename, const CProject& project) :
CWallpaper (Type, project),
m_filename (filename) {}
const std::string CWeb::Type = "web";

View File

@ -18,12 +18,11 @@ extern "C"
namespace WallpaperEngine::Core::Wallpapers
{
class CWeb : public CWallpaper
{
class CWeb : public CWallpaper {
public:
explicit CWeb (std::string filename, CProject& project);
CWeb (std::string filename, const CProject& project);
const std::string& getFilename ();
const std::string& getFilename () const;
protected:
friend class CWallpaper;

View File

@ -6,7 +6,7 @@ using namespace WallpaperEngine;
using namespace WallpaperEngine::Render;
using namespace WallpaperEngine::Render::Wallpapers;
CObject::CObject (Wallpapers::CScene* scene, std::string type, Core::CObject* object) :
CObject::CObject (Wallpapers::CScene* scene, std::string type, const Core::CObject* object) :
Helpers::CContextAware (scene),
m_type (std::move (type)),
m_scene (scene),
@ -16,7 +16,7 @@ Wallpapers::CScene* CObject::getScene () const {
return this->m_scene;
}
CContainer* CObject::getContainer () const {
const CContainer* CObject::getContainer () const {
return this->getScene ()->getContainer ();
}

View File

@ -31,17 +31,17 @@ class CObject : public Helpers::CContextAware {
virtual void render () = 0;
[[nodiscard]] Wallpapers::CScene* getScene () const;
[[nodiscard]] CContainer* getContainer () const;
[[nodiscard]] const CContainer* getContainer () const;
[[nodiscard]] int getId () const;
protected:
CObject (Wallpapers::CScene* scene, std::string type, Core::CObject* object);
CObject (Wallpapers::CScene* scene, std::string type, const Core::CObject* object);
~CObject () override = default;
private:
std::string m_type;
Wallpapers::CScene* m_scene;
Core::CObject* m_object;
const Core::CObject* m_object;
};
} // namespace WallpaperEngine::Render

View File

@ -10,7 +10,7 @@
using namespace WallpaperEngine::Render;
CWallpaper::CWallpaper (Core::CWallpaper* wallpaperData, std::string type, CRenderContext& context,
CWallpaper::CWallpaper (const Core::CWallpaper* wallpaperData, std::string type, CRenderContext& context,
CAudioContext& audioContext, const CWallpaperState::TextureUVsScaling& scalingMode) :
CContextAware (context),
m_wallpaperData (wallpaperData),
@ -49,11 +49,11 @@ CWallpaper::CWallpaper (Core::CWallpaper* wallpaperData, std::string type, CRend
CWallpaper::~CWallpaper () = default;
CContainer* CWallpaper::getContainer () const {
const CContainer* CWallpaper::getContainer () const {
return this->m_wallpaperData->getProject ().getContainer ();
}
WallpaperEngine::Core::CWallpaper* CWallpaper::getWallpaperData () const {
const WallpaperEngine::Core::CWallpaper* CWallpaper::getWallpaperData () const {
return this->m_wallpaperData;
}
@ -281,7 +281,7 @@ CFBO* CWallpaper::getFBO () const {
return this->m_sceneFBO;
}
CWallpaper* CWallpaper::fromWallpaper (Core::CWallpaper* wallpaper, CRenderContext& context,
CWallpaper* CWallpaper::fromWallpaper (const Core::CWallpaper* wallpaper, CRenderContext& context,
CAudioContext& audioContext, WebBrowser::CWebBrowserContext& browserContext,
const CWallpaperState::TextureUVsScaling& scalingMode) {
if (wallpaper->is<Core::Wallpapers::CScene> ())

View File

@ -59,7 +59,7 @@ class CWallpaper : public Helpers::CContextAware {
/**
* @return The container to resolve files for this wallpaper
*/
[[nodiscard]] CContainer* getContainer () const;
[[nodiscard]] const CContainer* getContainer () const;
/**
* @return The current audio context for this wallpaper
@ -146,12 +146,12 @@ class CWallpaper : public Helpers::CContextAware {
*
* @return
*/
static CWallpaper* fromWallpaper (Core::CWallpaper* wallpaper, CRenderContext& context, CAudioContext& audioContext,
static CWallpaper* fromWallpaper (const Core::CWallpaper* wallpaper, CRenderContext& context, CAudioContext& audioContext,
WebBrowser::CWebBrowserContext& browserContext,
const CWallpaperState::TextureUVsScaling& scalingMode);
protected:
CWallpaper (Core::CWallpaper* wallpaperData, std::string type, CRenderContext& context, CAudioContext& audioContext,
CWallpaper (const Core::CWallpaper* wallpaperData, std::string type, CRenderContext& context, CAudioContext& audioContext,
const CWallpaperState::TextureUVsScaling& scalingMode);
/**
@ -164,9 +164,9 @@ class CWallpaper : public Helpers::CContextAware {
*/
void setupFramebuffers ();
Core::CWallpaper* m_wallpaperData;
const Core::CWallpaper* m_wallpaperData;
[[nodiscard]] Core::CWallpaper* getWallpaperData () const;
[[nodiscard]] const Core::CWallpaper* getWallpaperData () const;
/** The FBO used for scene output */
CFBO* m_sceneFBO;

View File

@ -3,7 +3,9 @@
using namespace WallpaperEngine::Render;
using namespace WallpaperEngine::Render::Objects;
CEffect::CEffect (CImage* image, Core::Objects::CEffect* effect) : m_image (image), m_effect (effect) {
CEffect::CEffect (CImage* image, const Core::Objects::CEffect* effect) :
m_image (image),
m_effect (effect) {
this->generateFBOs ();
this->generatePasses ();
}

View File

@ -14,7 +14,7 @@ class CImage;
class CEffect {
public:
CEffect (CImage* image, Core::Objects::CEffect* effect);
CEffect (CImage* image, const Core::Objects::CEffect* effect);
CImage* getImage () const;
@ -28,7 +28,7 @@ class CEffect {
void generateFBOs ();
CImage* m_image;
Core::Objects::CEffect* m_effect;
const Core::Objects::CEffect* m_effect;
std::vector<CFBO*> m_fbos;
std::vector<Effects::CMaterial*> m_materials;

Some files were not shown because too many files have changed in this diff Show More