diff --git a/libraries/render/src/render/Task.h b/libraries/render/src/render/Task.h index ac05fbe68a..66258711cc 100644 --- a/libraries/render/src/render/Task.h +++ b/libraries/render/src/render/Task.h @@ -52,6 +52,7 @@ protected: class Job; class Task; +class JobNoIO {}; // A default Config is always on; to create an enableable Config, use the ctor JobConfig(bool enabled) class JobConfig : public QObject { @@ -101,16 +102,16 @@ template void jobConfigure(T& data, const C& configuration) { template void jobConfigure(T&, const JobConfig&) { // nop, as the default JobConfig was used, so the data does not need a configure method } -template void jobRun(T& data, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { +template void jobRun(T& data, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const JobNoIO& input, JobNoIO& output) { data.run(sceneContext, renderContext); } -template void jobRunI(T& data, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const I& input) { +template void jobRun(T& data, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const I& input, JobNoIO& output) { data.run(sceneContext, renderContext, input); } -template void jobRunO(T& data, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, O& output) { +template void jobRun(T& data, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const JobNoIO& input, O& output) { data.run(sceneContext, renderContext, output); } -template void jobRunIO(T& data, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const I& input, O& output) { +template void jobRun(T& data, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const I& input, O& output) { data.run(sceneContext, renderContext, input, output); } @@ -118,6 +119,7 @@ class Job { public: using Config = JobConfig; using QConfigPointer = std::shared_ptr; + using None = JobNoIO; // The guts of a job class Concept { @@ -138,84 +140,7 @@ public: }; using ConceptPointer = std::shared_ptr; - template class Model : public Concept { - public: - using Data = T; - - Data _data; - - Model(Data data = Data()) : Concept(std::make_shared()), _data(data) { - applyConfiguration(); - } - - void applyConfiguration() { - jobConfigure(_data, *std::static_pointer_cast(_config)); - } - - void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { - renderContext->jobConfig = std::static_pointer_cast(_config); - if (renderContext->jobConfig->alwaysEnabled || renderContext->jobConfig->enabled) { - jobRun(_data, sceneContext, renderContext); - } - renderContext->jobConfig.reset(); - } - }; - - template class ModelI : public Concept { - public: - using Data = T; - using Input = I; - - Data _data; - Varying _input; - - const Varying getInput() const { return _input; } - - ModelI(const Varying& input, Data data = Data()) : Concept(std::make_shared()), _data(data), _input(input) { - applyConfiguration(); - } - - void applyConfiguration() { - jobConfigure(_data, *std::static_pointer_cast(_config)); - } - - void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { - renderContext->jobConfig = std::static_pointer_cast(_config); - if (renderContext->jobConfig->alwaysEnabled || renderContext->jobConfig->enabled) { - jobRunI(_data, sceneContext, renderContext, _input.get()); - } - renderContext->jobConfig.reset(); - } - }; - - template class ModelO : public Concept { - public: - using Data = T; - using Output = O; - - Data _data; - Varying _output; - - const Varying getOutput() const { return _output; } - - ModelO(Data data = Data()) : Concept(std::make_shared()), _data(data), _output(Output()) { - applyConfiguration(); - } - - void applyConfiguration() { - jobConfigure(_data, *std::static_pointer_cast(_config)); - } - - void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { - renderContext->jobConfig = std::static_pointer_cast(_config); - if (renderContext->jobConfig->alwaysEnabled || renderContext->jobConfig->enabled) { - jobRunO(_data, sceneContext, renderContext, _output.edit()); - } - renderContext->jobConfig.reset(); - } - }; - - template class ModelIO : public Concept { + template class Model : public Concept { public: using Data = T; using Input = I; @@ -228,7 +153,7 @@ public: const Varying getInput() const { return _input; } const Varying getOutput() const { return _output; } - ModelIO(const Varying& input, Data data = Data()) : Concept(std::make_shared()), _data(data), _input(input), _output(Output()) { + Model(const Varying& input, Data data = Data()) : Concept(std::make_shared()), _data(data), _input(input), _output(Output()) { applyConfiguration(); } @@ -239,11 +164,14 @@ public: void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { renderContext->jobConfig = std::static_pointer_cast(_config); if (renderContext->jobConfig->alwaysEnabled || renderContext->jobConfig->enabled) { - jobRunIO(_data, sceneContext, renderContext, _input.get(), _output.edit()); + jobRun(_data, sceneContext, renderContext, _input.get(), _output.edit()); } renderContext->jobConfig.reset(); } }; + template using ModelI = Model; + template using ModelO = Model; + template using ModelIO = Model; Job(std::string name, ConceptPointer concept) : _concept(concept), _name(name) {} @@ -278,17 +206,24 @@ class Task { public: using Config = TaskConfig; using QConfigPointer = Job::QConfigPointer; + using None = Job::None; - template class Model : public Job::Concept { + template class Model : public Job::Concept { public: using Data = T; + using Input = I; + using Output = O; Data _data; + Varying _input; + Varying _output; - Model(Data data = Data()) : Concept(std::make_shared()), _data(data) { + const Varying getInput() const { return _input; } + const Varying getOutput() const { return _output; } + + Model(const Varying& input, Data data = Data()) : Concept(std::make_shared()), _data(data), _input(input), _output(Output()) { _config = _data._config; // use the data's config std::static_pointer_cast(_config)->init(&_data); - applyConfiguration(); } @@ -299,11 +234,14 @@ public: void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { renderContext->jobConfig = std::static_pointer_cast(_config); if (renderContext->jobConfig->alwaysEnabled || renderContext->jobConfig->enabled) { - jobRun(_data, sceneContext, renderContext); + jobRun(_data, sceneContext, renderContext, _input.get(), _output.edit()); } renderContext->jobConfig.reset(); } }; + template using ModelI = Model; + template using ModelO = Model; + template using ModelIO = Model; using Jobs = std::vector; @@ -311,15 +249,25 @@ public: Task() : _config{ std::make_shared() } {} template Task(std::shared_ptr config) : _config{ config } {} - // Queue a new job to the container; returns the job's output - template const Varying addJob(std::string name, A&&... args) { - _jobs.emplace_back(name, std::make_shared(std::forward(args)...)); + // 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, + typename T::JobModel::Data(std::forward(args)...))); QConfigPointer config = _jobs.back().getConfiguration(); config->setParent(_config.get()); config->setObjectName(name.c_str()); QObject::connect(config.get(), SIGNAL(dirty()), _config.get(), SLOT(refresh())); return _jobs.back().getOutput(); } + template const Varying addJob(std::string name, Varying& input, A&&... args) { + const auto& in = input; + return addJob(name, in, std::forward(args)...); + } + template const Varying addJob(std::string name, A&&... args) { + auto input = Varying(typename T::JobModel::Input()); + return addJob(name, input, std::forward(args)...); + } std::shared_ptr getConfiguration() { auto config = std::static_pointer_cast(_config); @@ -335,7 +283,7 @@ public: } protected: - template friend class Model; + template friend class Model; QConfigPointer _config; Jobs _jobs;