From e4dabc6be4f883ed3e3386720c0fcb5f564f1812 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 14 Jul 2016 12:53:50 -0700 Subject: [PATCH 1/2] fix task config initialization --- .../render-utils/src/RenderShadowTask.cpp | 3 +- libraries/render/src/render/Task.h | 41 +++++++++++-------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index 5680660122..2e3901a769 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -85,8 +85,7 @@ void RenderShadowMap::run(const render::SceneContextPointer& sceneContext, const }); } -// The shadow task *must* use this base ctor to initialize with its own Config, see Task.h -RenderShadowTask::RenderShadowTask(CullFunctor cullFunctor) : Task(std::make_shared()) { +RenderShadowTask::RenderShadowTask(CullFunctor cullFunctor) { cullFunctor = cullFunctor ? cullFunctor : [](const RenderArgs*, const AABox&){ return true; }; // Prepare the ShapePipeline diff --git a/libraries/render/src/render/Task.h b/libraries/render/src/render/Task.h index a42fb4f0ac..506de4aa6d 100644 --- a/libraries/render/src/render/Task.h +++ b/libraries/render/src/render/Task.h @@ -368,8 +368,6 @@ public: TaskConfig() = default ; TaskConfig(bool enabled) : JobConfig(enabled) {} - void init(Task* task) { _task = task; } - // getter for qml integration, prefer the templated getter Q_INVOKABLE QObject* getConfig(const QString& name) { return QObject::findChild(name); } // getter for cpp (strictly typed), prefer this getter @@ -382,6 +380,7 @@ public slots: void refresh(); private: + friend class Task; Task* _task; }; @@ -521,9 +520,10 @@ public: template Model(const Varying& input, A&&... args) : - Concept(std::make_shared()), _data(Data(std::forward(args)...)), _input(input), _output(Output()) { - _config = _data._config; - std::static_pointer_cast(_config)->init(&_data); + Concept(nullptr), _data(Data(std::forward(args)...)), _input(input), _output(Output()) { + // Recreate the Config to use the templated type + _data.createConfiguration(); + _config = _data.getConfiguration(); applyConfiguration(); } @@ -545,23 +545,19 @@ public: using Jobs = std::vector; - // A task must use its Config for construction - Task() : _config{ std::make_shared() } {} - template Task(std::shared_ptr config) : _config{ config } {} - // Create a new job in the container's queue; returns the job's output template const Varying addJob(std::string name, const Varying& input, A&&... args) { _jobs.emplace_back(name, std::make_shared(input, std::forward(args)...)); QConfigPointer config = _jobs.back().getConfiguration(); - config->setParent(_config.get()); + config->setParent(getConfiguration().get()); config->setObjectName(name.c_str()); // Connect loaded->refresh - QObject::connect(config.get(), SIGNAL(loaded()), _config.get(), SLOT(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()), _config.get(), SLOT(refresh())); + QObject::connect(config.get(), SIGNAL(dirty()), getConfiguration().get(), SLOT(refresh())); } return _jobs.back().getOutput(); @@ -571,11 +567,24 @@ public: return addJob(name, input, std::forward(args)...); } + template void createConfiguration() { + 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()); + } + } + _config = config; + std::static_pointer_cast(_config)->_task = this; + } + std::shared_ptr getConfiguration() { - auto config = std::static_pointer_cast(_config); - // If we are here, we were not made by a Model, so we must initialize our own config - config->init(this); - return config; + if (!_config) { + createConfiguration(); + } + return std::static_pointer_cast(_config); } void configure(const QObject& configuration) { From e71a2097a5c786520d15b614f70296c9c9b6d2dd Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 14 Jul 2016 13:19:49 -0700 Subject: [PATCH 2/2] update doc for task template --- libraries/render/src/render/Task.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/render/src/render/Task.h b/libraries/render/src/render/Task.h index 506de4aa6d..6a7b04198f 100644 --- a/libraries/render/src/render/Task.h +++ b/libraries/render/src/render/Task.h @@ -497,8 +497,6 @@ public: // A task is a specialized job to run a collection of other jobs // It is defined with JobModel = Task::Model -// -// A task with a custom config *must* use the templated constructor class Task { public: using Config = TaskConfig;