From 4a47737d0b11df690e5ca3412325341b0347f3e8 Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 10 Apr 2017 19:01:49 -0700 Subject: [PATCH] REfining the Config behavior, trying to pr next --- libraries/render-utils/src/ZoneRenderer.h | 2 + libraries/render/src/render/DrawTask.h | 2 +- libraries/render/src/render/Engine.cpp | 2 +- libraries/render/src/render/Task.cpp | 31 +++++++- libraries/render/src/render/Task.h | 78 +++++-------------- .../utilities/render/deferredLighting.qml | 2 +- 6 files changed, 56 insertions(+), 61 deletions(-) diff --git a/libraries/render-utils/src/ZoneRenderer.h b/libraries/render-utils/src/ZoneRenderer.h index c55dc2beb4..1218608400 100644 --- a/libraries/render-utils/src/ZoneRenderer.h +++ b/libraries/render-utils/src/ZoneRenderer.h @@ -19,6 +19,8 @@ class ZoneRendererConfig : public render::Task::Config { Q_PROPERTY(int maxDrawn MEMBER maxDrawn NOTIFY dirty) public: + ZoneRendererConfig() : render::Task::Config(false) {} + int maxDrawn { -1 }; signals: diff --git a/libraries/render/src/render/DrawTask.h b/libraries/render/src/render/DrawTask.h index a9c5f3a4d8..d1856cb66e 100755 --- a/libraries/render/src/render/DrawTask.h +++ b/libraries/render/src/render/DrawTask.h @@ -52,7 +52,7 @@ class DrawBounds { public: class Config : public render::JobConfig { public: - Config() : JobConfig(false) {} + Config(bool enabled = false) : JobConfig(enabled) {} }; using Inputs = render::ItemBounds; diff --git a/libraries/render/src/render/Engine.cpp b/libraries/render/src/render/Engine.cpp index 3e6ad458fb..08efb7b281 100644 --- a/libraries/render/src/render/Engine.cpp +++ b/libraries/render/src/render/Engine.cpp @@ -34,7 +34,7 @@ public: } }; -Engine::Engine() : Task("Engine", EngineTask::JobModel::factoryModel()), +Engine::Engine() : Task("Engine", EngineTask::JobModel::create()), _sceneContext(std::make_shared()), _renderContext(std::make_shared()) { diff --git a/libraries/render/src/render/Task.cpp b/libraries/render/src/render/Task.cpp index cd0c938c73..13476f102e 100644 --- a/libraries/render/src/render/Task.cpp +++ b/libraries/render/src/render/Task.cpp @@ -15,13 +15,42 @@ using namespace render; +void TaskConfig::connectChildConfig(QConfigPointer childConfig, const std::string& name) { + childConfig->setParent(this); + childConfig->setObjectName(name.c_str()); + + // Connect loaded->refresh + QObject::connect(childConfig.get(), SIGNAL(loaded()), this, SLOT(refresh())); + static const char* DIRTY_SIGNAL = "dirty()"; + if (childConfig->metaObject()->indexOfSignal(DIRTY_SIGNAL) != -1) { + // Connect dirty->refresh if defined + QObject::connect(childConfig.get(), SIGNAL(dirty()), this, SLOT(refresh())); + } +} + +void TaskConfig::transferChildrenConfigs(QConfigPointer source) { + if (!source) { + return; + } + // Transfer children to the new configuration + auto children = source->children(); + for (auto& child : children) { + child->setParent(this); + QObject::connect(child, SIGNAL(loaded()), this, SLOT(refresh())); + static const char* DIRTY_SIGNAL = "dirty()"; + if (child->metaObject()->indexOfSignal(DIRTY_SIGNAL) != -1) { + // Connect dirty->refresh if defined + QObject::connect(child, SIGNAL(dirty()), this, SLOT(refresh())); + } + } +} + void TaskConfig::refresh() { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "refresh", Qt::BlockingQueuedConnection); return; } - // _task->configure(*this); _task->applyConfiguration(); } diff --git a/libraries/render/src/render/Task.h b/libraries/render/src/render/Task.h index 49499896da..855274e701 100644 --- a/libraries/render/src/render/Task.h +++ b/libraries/render/src/render/Task.h @@ -431,22 +431,8 @@ public: return findChild(name); } - void connectSubJobConfig(QConfigPointer jobConfig, const std::string& name) { - // QConfigPointer config = _jobs.back().getConfiguration(); - jobConfig->setParent(this); - jobConfig->setObjectName(name.c_str()); - - // Connect loaded->refresh - // QObject::connect(config.get(), SIGNAL(loaded()), getConfiguration().get(), SLOT(refresh())); - QObject::connect(jobConfig.get(), SIGNAL(loaded()), this, SLOT(refresh())); - static const char* DIRTY_SIGNAL = "dirty()"; - // if (config->metaObject()->indexOfSignal(DIRTY_SIGNAL) != -1) { - if (jobConfig->metaObject()->indexOfSignal(DIRTY_SIGNAL) != -1) { - // Connect dirty->refresh if defined - // QObject::connect(config.get(), SIGNAL(dirty()), getConfiguration().get(), SLOT(refresh())); - QObject::connect(jobConfig.get(), SIGNAL(dirty()), this, SLOT(refresh())); - } - } + void connectChildConfig(QConfigPointer childConfig, const std::string& name); + void transferChildrenConfigs(QConfigPointer source); public slots: void refresh(); @@ -525,8 +511,8 @@ public: const Varying getOutput() const override { return _output; } template - Model(const Varying& input, A&&... args) : - Concept(std::make_shared()), + Model(const Varying& input, QConfigPointer config, A&&... args) : + Concept(config), _data(Data(std::forward(args)...)), _input(input), _output(Output()) { @@ -534,8 +520,8 @@ public: } template - static std::shared_ptr factoryModel(const Varying& input, A&&... args) { - return std::make_shared(input, std::forward(args)...); + static std::shared_ptr create(const Varying& input, A&&... args) { + return std::make_shared(input, std::make_shared(), std::forward(args)...); } @@ -583,11 +569,6 @@ protected: std::string _name = ""; }; -/* -template void taskBuild(T& data, typename T::JobModel* task, const Varying& input, Varying& output, A&&... args) { - data.build(*(task), input, output, std::forward(args)...); -}*/ - // A task is a specialized job to run a collection of other jobs // It is defined with JobModel = Task::Model @@ -614,20 +595,10 @@ public: // Create a new job in the container's queue; returns the job's output template const Varying addJob(std::string name, const Varying& input, NA&&... args) { - _jobs.emplace_back(name, (NT::JobModel::factoryModel(input, std::forward(args)...))); - /* QConfigPointer config = _jobs.back().getConfiguration(); - config->setParent(getConfiguration().get()); - config->setObjectName(name.c_str()); + _jobs.emplace_back(name, (NT::JobModel::create(input, std::forward(args)...))); - // Connect loaded->refresh - QObject::connect(config.get(), SIGNAL(loaded()), getConfiguration().get(), SLOT(refresh())); - static const char* DIRTY_SIGNAL = "dirty()"; - if (config->metaObject()->indexOfSignal(DIRTY_SIGNAL) != -1) { - // Connect dirty->refresh if defined - QObject::connect(config.get(), SIGNAL(dirty()), getConfiguration().get(), SLOT(refresh())); - }*/ - - std::static_pointer_cast(getConfiguration())->connectSubJobConfig(_jobs.back().getConfiguration(), name); + // Conect the child config to this task's config + std::static_pointer_cast(getConfiguration())->connectChildConfig(_jobs.back().getConfiguration(), name); return _jobs.back().getOutput(); } @@ -645,13 +616,14 @@ public: Data _data; - TaskModel(const Varying& input) : - TaskConcept(input, nullptr), + TaskModel(const Varying& input, QConfigPointer config) : + TaskConcept(input, config), _data(Data()) {} template - static std::shared_ptr factoryModel(const Varying& input, A&&... args) { - auto model = std::make_shared(input); + static std::shared_ptr create(const Varying& input, A&&... args) { + auto model = std::make_shared(input, std::make_shared()); + // std::static_pointer_cast(model->_config)->_task = model.get(); model->_data.build(*(model), model->_input, model->_output, std::forward(args)...); @@ -663,27 +635,19 @@ public: } template - static std::shared_ptr factoryModel(A&&... args) { + static std::shared_ptr create(A&&... args) { const auto input = Varying(Input()); - return factoryModel(input, std::forward(args)...); + return create(input, std::forward(args)...); } void createConfiguration() { + // A brand new config auto config = std::make_shared(); - if (_config) { - // Transfer children to the new configuration - auto children = _config->children(); - for (auto& child : children) { - child->setParent(config.get()); - QObject::connect(child, SIGNAL(loaded()), config.get(), SLOT(refresh())); - static const char* DIRTY_SIGNAL = "dirty()"; - if (child->metaObject()->indexOfSignal(DIRTY_SIGNAL) != -1) { - // Connect dirty->refresh if defined - QObject::connect(child, SIGNAL(dirty()), config.get(), SLOT(refresh())); - } - } - } + // Make sure we transfer the former children configs to the new config + config->transferChildrenConfigs(_config); + // swap _config = config; + // Capture this std::static_pointer_cast(_config)->_task = this; } diff --git a/scripts/developer/utilities/render/deferredLighting.qml b/scripts/developer/utilities/render/deferredLighting.qml index 5be37b2b89..229a2d1c3b 100644 --- a/scripts/developer/utilities/render/deferredLighting.qml +++ b/scripts/developer/utilities/render/deferredLighting.qml @@ -192,7 +192,7 @@ Column { CheckBox { text: "Zones" checked: Render.getConfig("DrawZones")["enabled"] - onCheckedChanged: { Render.getConfig("DrawZones")["enabled"] = checked } + onCheckedChanged: { Render.getConfig("ZoneRenderer")["enabled"] = checked; Render.getConfig("DrawZones")["enabled"] = checked; } } } }