mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 20:06:02 +02:00
Nest Persistent in Config to compile on nix
This commit is contained in:
parent
a7778daed2
commit
d0f3ad75b8
4 changed files with 73 additions and 71 deletions
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
#include "render/DrawTask.h"
|
#include "render/DrawTask.h"
|
||||||
|
|
||||||
class AmbientOcclusionEffectConfig : public render::Job::PersistentConfig {
|
class AmbientOcclusionEffectConfig : public render::Job::Config::Persistent {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(bool enabled MEMBER enabled NOTIFY dirty)
|
Q_PROPERTY(bool enabled MEMBER enabled NOTIFY dirty)
|
||||||
Q_PROPERTY(bool ditheringEnabled MEMBER ditheringEnabled NOTIFY dirty)
|
Q_PROPERTY(bool ditheringEnabled MEMBER ditheringEnabled NOTIFY dirty)
|
||||||
|
@ -32,7 +32,7 @@ class AmbientOcclusionEffectConfig : public render::Job::PersistentConfig {
|
||||||
Q_PROPERTY(int blurRadius MEMBER blurRadius WRITE setBlurRadius)
|
Q_PROPERTY(int blurRadius MEMBER blurRadius WRITE setBlurRadius)
|
||||||
Q_PROPERTY(double gpuTime READ getGpuTime)
|
Q_PROPERTY(double gpuTime READ getGpuTime)
|
||||||
public:
|
public:
|
||||||
AmbientOcclusionEffectConfig() : render::Job::PersistentConfig("Ambient Occlusion", false) {}
|
AmbientOcclusionEffectConfig() : render::Job::Config::Persistent("Ambient Occlusion", false) {}
|
||||||
|
|
||||||
const int MAX_RESOLUTION_LEVEL = 4;
|
const int MAX_RESOLUTION_LEVEL = 4;
|
||||||
const int MAX_BLUR_RADIUS = 6;
|
const int MAX_BLUR_RADIUS = 6;
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
|
|
||||||
#include "render/DrawTask.h"
|
#include "render/DrawTask.h"
|
||||||
|
|
||||||
class AntiAliasingConfig : public render::Job::PersistentConfig {
|
class AntiAliasingConfig : public render::Job::Config::Persistent {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(bool enabled MEMBER enabled)
|
Q_PROPERTY(bool enabled MEMBER enabled)
|
||||||
public:
|
public:
|
||||||
AntiAliasingConfig() : render::Job::PersistentConfig("Antialiasing", false) {}
|
AntiAliasingConfig() : render::Job::Config::Persistent("Antialiasing", false) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Antialiasing {
|
class Antialiasing {
|
||||||
|
|
|
@ -31,11 +31,11 @@ protected:
|
||||||
render::ShapePlumberPointer _shapePlumber;
|
render::ShapePlumberPointer _shapePlumber;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RenderShadowTaskConfig : public render::Task::PersistentConfig {
|
class RenderShadowTaskConfig : public render::Task::Config::Persistent {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(bool enabled MEMBER enabled NOTIFY dirty)
|
Q_PROPERTY(bool enabled MEMBER enabled NOTIFY dirty)
|
||||||
public:
|
public:
|
||||||
RenderShadowTaskConfig() : render::Task::PersistentConfig("Shadows", false) {}
|
RenderShadowTaskConfig() : render::Task::Config::Persistent("Shadows", false) {}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void dirty();
|
void dirty();
|
||||||
|
|
|
@ -61,10 +61,75 @@ class Job;
|
||||||
class Task;
|
class Task;
|
||||||
class JobNoIO {};
|
class JobNoIO {};
|
||||||
|
|
||||||
|
template <class C> class PersistentConfig : public C {
|
||||||
|
public:
|
||||||
|
const QString DEFAULT = "Default";
|
||||||
|
const QString NONE = "None";
|
||||||
|
|
||||||
|
PersistentConfig() = delete;
|
||||||
|
PersistentConfig(const QString& path) :
|
||||||
|
_preset(QStringList() << "Render" << "Engine" << path, DEFAULT) { }
|
||||||
|
PersistentConfig(const QStringList& path) :
|
||||||
|
_preset(QStringList() << "Render" << "Engine" << path, DEFAULT) { }
|
||||||
|
PersistentConfig(const QString& path, bool enabled) : C(enabled),
|
||||||
|
_preset(QStringList() << "Render" << "Engine" << path, enabled ? DEFAULT : NONE) { }
|
||||||
|
PersistentConfig(const QStringList& path, bool enabled) : C(enabled),
|
||||||
|
_preset(QStringList() << "Render" << "Engine" << path, enabled ? DEFAULT : NONE) { }
|
||||||
|
|
||||||
|
QStringList getPresetList() {
|
||||||
|
if (_presets.empty()) {
|
||||||
|
setPresetList(QJsonObject());
|
||||||
|
}
|
||||||
|
return _presets.keys();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void setPresetList(const QJsonObject& list) override {
|
||||||
|
assert(_presets.empty());
|
||||||
|
|
||||||
|
_default = toJsonValue(*this).toObject().toVariantMap();
|
||||||
|
|
||||||
|
_presets.unite(list.toVariantMap());
|
||||||
|
if (C::alwaysEnabled || C::enabled) {
|
||||||
|
_presets.insert(DEFAULT, _default);
|
||||||
|
}
|
||||||
|
if (!C::alwaysEnabled) {
|
||||||
|
_presets.insert(NONE, QVariantMap{{ "enabled", false }});
|
||||||
|
}
|
||||||
|
|
||||||
|
auto preset = _preset.get();
|
||||||
|
if (preset != _preset.getDefault() && _presets.contains(preset)) {
|
||||||
|
// Load the persisted configuration
|
||||||
|
C::load(_presets[preset].toMap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString getPreset() { return _preset.get(); }
|
||||||
|
|
||||||
|
void setPreset(const QString& preset) {
|
||||||
|
_preset.set(preset);
|
||||||
|
if (_presets.contains(preset)) {
|
||||||
|
// Always start back at default to remain deterministic
|
||||||
|
QVariantMap config = _default;
|
||||||
|
QVariantMap presetConfig = _presets[preset].toMap();
|
||||||
|
for (auto it = presetConfig.cbegin(); it != presetConfig.cend(); it++) {
|
||||||
|
config.insert(it.key(), it.value());
|
||||||
|
}
|
||||||
|
C::load(config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QVariantMap _default;
|
||||||
|
QVariantMap _presets;
|
||||||
|
Setting::Handle<QString> _preset;
|
||||||
|
};
|
||||||
|
|
||||||
// A default Config is always on; to create an enableable Config, use the ctor JobConfig(bool enabled)
|
// A default Config is always on; to create an enableable Config, use the ctor JobConfig(bool enabled)
|
||||||
class JobConfig : public QObject {
|
class JobConfig : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
using Persistent = PersistentConfig<JobConfig>;
|
||||||
|
|
||||||
JobConfig() = default;
|
JobConfig() = default;
|
||||||
JobConfig(bool enabled) : alwaysEnabled{ false }, enabled{ enabled } {}
|
JobConfig(bool enabled) : alwaysEnabled{ false }, enabled{ enabled } {}
|
||||||
|
|
||||||
|
@ -96,6 +161,8 @@ signals:
|
||||||
class TaskConfig : public JobConfig {
|
class TaskConfig : public JobConfig {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
using Persistent = PersistentConfig<TaskConfig>;
|
||||||
|
|
||||||
TaskConfig() = default ;
|
TaskConfig() = default ;
|
||||||
TaskConfig(bool enabled) : JobConfig(enabled) {}
|
TaskConfig(bool enabled) : JobConfig(enabled) {}
|
||||||
|
|
||||||
|
@ -116,69 +183,6 @@ private:
|
||||||
Task* _task;
|
Task* _task;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class C> class PersistentConfig : public C {
|
|
||||||
public:
|
|
||||||
const QString DEFAULT = "Default";
|
|
||||||
const QString NONE = "None";
|
|
||||||
|
|
||||||
PersistentConfig() = delete;
|
|
||||||
PersistentConfig(const QString& path) :
|
|
||||||
_preset(QStringList() << "Render" << "Engine" << path, DEFAULT) { }
|
|
||||||
PersistentConfig(const QStringList& path) :
|
|
||||||
_preset(QStringList() << "Render" << "Engine" << path, DEFAULT) { }
|
|
||||||
PersistentConfig(const QString& path, bool enabled) : C(enabled),
|
|
||||||
_preset(QStringList() << "Render" << "Engine" << path, enabled ? DEFAULT : NONE) { }
|
|
||||||
PersistentConfig(const QStringList& path, bool enabled) : C(enabled),
|
|
||||||
_preset(QStringList() << "Render" << "Engine" << path, enabled ? DEFAULT : NONE) { }
|
|
||||||
|
|
||||||
QStringList getPresetList() {
|
|
||||||
if (_presets.empty()) {
|
|
||||||
setPresetList(QJsonObject());
|
|
||||||
}
|
|
||||||
return _presets.keys();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void setPresetList(const QJsonObject& list) override {
|
|
||||||
assert(_presets.empty());
|
|
||||||
|
|
||||||
_default = toJsonValue(*this).toObject().toVariantMap();
|
|
||||||
|
|
||||||
_presets.unite(list.toVariantMap());
|
|
||||||
if (alwaysEnabled || enabled) {
|
|
||||||
_presets.insert(DEFAULT, _default);
|
|
||||||
}
|
|
||||||
if (!alwaysEnabled) {
|
|
||||||
_presets.insert(NONE, QVariantMap{{ "enabled", false }});
|
|
||||||
}
|
|
||||||
|
|
||||||
auto preset = _preset.get();
|
|
||||||
if (preset != _preset.getDefault() && _presets.contains(preset)) {
|
|
||||||
// Load the persisted configuration
|
|
||||||
load(_presets[preset].toMap());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString getPreset() { return _preset.get(); }
|
|
||||||
|
|
||||||
void setPreset(const QString& preset) {
|
|
||||||
_preset.set(preset);
|
|
||||||
if (_presets.contains(preset)) {
|
|
||||||
// Always start back at default to remain deterministic
|
|
||||||
QVariantMap config = _default;
|
|
||||||
QVariantMap presetConfig = _presets[preset].toMap();
|
|
||||||
for (auto it = presetConfig.cbegin(); it != presetConfig.cend(); it++) {
|
|
||||||
config.insert(it.key(), it.value());
|
|
||||||
}
|
|
||||||
load(config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
QVariantMap _default;
|
|
||||||
QVariantMap _presets;
|
|
||||||
Setting::Handle<QString> _preset;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class T, class C> void jobConfigure(T& data, const C& configuration) {
|
template <class T, class C> void jobConfigure(T& data, const C& configuration) {
|
||||||
data.configure(configuration);
|
data.configure(configuration);
|
||||||
}
|
}
|
||||||
|
@ -201,7 +205,6 @@ template <class T, class I, class O> void jobRun(T& data, const SceneContextPoin
|
||||||
class Job {
|
class Job {
|
||||||
public:
|
public:
|
||||||
using Config = JobConfig;
|
using Config = JobConfig;
|
||||||
using PersistentConfig = PersistentConfig<Config>;
|
|
||||||
using QConfigPointer = std::shared_ptr<QObject>;
|
using QConfigPointer = std::shared_ptr<QObject>;
|
||||||
using None = JobNoIO;
|
using None = JobNoIO;
|
||||||
|
|
||||||
|
@ -289,7 +292,6 @@ public:
|
||||||
class Task {
|
class Task {
|
||||||
public:
|
public:
|
||||||
using Config = TaskConfig;
|
using Config = TaskConfig;
|
||||||
using PersistentConfig = PersistentConfig<Config>;
|
|
||||||
using QConfigPointer = Job::QConfigPointer;
|
using QConfigPointer = Job::QConfigPointer;
|
||||||
using None = Job::None;
|
using None = Job::None;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue