mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 10:17:40 +02:00
fix task config initialization
This commit is contained in:
parent
3ab56062d4
commit
e4dabc6be4
2 changed files with 26 additions and 18 deletions
|
@ -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) {
|
||||||
RenderShadowTask::RenderShadowTask(CullFunctor cullFunctor) : Task(std::make_shared<Config>()) {
|
|
||||||
cullFunctor = cullFunctor ? cullFunctor : [](const RenderArgs*, const AABox&){ return true; };
|
cullFunctor = cullFunctor ? cullFunctor : [](const RenderArgs*, const AABox&){ return true; };
|
||||||
|
|
||||||
// Prepare the ShapePipeline
|
// Prepare the ShapePipeline
|
||||||
|
|
|
@ -368,8 +368,6 @@ public:
|
||||||
TaskConfig() = default ;
|
TaskConfig() = default ;
|
||||||
TaskConfig(bool enabled) : JobConfig(enabled) {}
|
TaskConfig(bool enabled) : JobConfig(enabled) {}
|
||||||
|
|
||||||
void init(Task* task) { _task = task; }
|
|
||||||
|
|
||||||
// getter for qml integration, prefer the templated getter
|
// getter for qml integration, prefer the templated getter
|
||||||
Q_INVOKABLE QObject* getConfig(const QString& name) { return QObject::findChild<JobConfig*>(name); }
|
Q_INVOKABLE QObject* getConfig(const QString& name) { return QObject::findChild<JobConfig*>(name); }
|
||||||
// getter for cpp (strictly typed), prefer this getter
|
// getter for cpp (strictly typed), prefer this getter
|
||||||
|
@ -382,6 +380,7 @@ public slots:
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend class Task;
|
||||||
Task* _task;
|
Task* _task;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -521,9 +520,10 @@ public:
|
||||||
|
|
||||||
template <class... A>
|
template <class... A>
|
||||||
Model(const Varying& input, A&&... args) :
|
Model(const Varying& input, A&&... args) :
|
||||||
Concept(std::make_shared<Config>()), _data(Data(std::forward<A>(args)...)), _input(input), _output(Output()) {
|
Concept(nullptr), _data(Data(std::forward<A>(args)...)), _input(input), _output(Output()) {
|
||||||
_config = _data._config;
|
// Recreate the Config to use the templated type
|
||||||
std::static_pointer_cast<Config>(_config)->init(&_data);
|
_data.createConfiguration<C>();
|
||||||
|
_config = _data.getConfiguration();
|
||||||
applyConfiguration();
|
applyConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,23 +545,19 @@ public:
|
||||||
|
|
||||||
using Jobs = std::vector<Job>;
|
using Jobs = std::vector<Job>;
|
||||||
|
|
||||||
// A task must use its Config for construction
|
|
||||||
Task() : _config{ std::make_shared<Config>() } {}
|
|
||||||
template <class C> Task(std::shared_ptr<C> config) : _config{ config } {}
|
|
||||||
|
|
||||||
// Create a new job in the container's queue; returns the job's output
|
// Create a new job in the container's queue; returns the job's output
|
||||||
template <class T, class... A> const Varying addJob(std::string name, const Varying& input, A&&... args) {
|
template <class T, class... A> const Varying addJob(std::string name, const Varying& input, A&&... args) {
|
||||||
_jobs.emplace_back(name, std::make_shared<typename T::JobModel>(input, std::forward<A>(args)...));
|
_jobs.emplace_back(name, std::make_shared<typename T::JobModel>(input, std::forward<A>(args)...));
|
||||||
QConfigPointer config = _jobs.back().getConfiguration();
|
QConfigPointer config = _jobs.back().getConfiguration();
|
||||||
config->setParent(_config.get());
|
config->setParent(getConfiguration().get());
|
||||||
config->setObjectName(name.c_str());
|
config->setObjectName(name.c_str());
|
||||||
|
|
||||||
// Connect loaded->refresh
|
// 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()";
|
static const char* DIRTY_SIGNAL = "dirty()";
|
||||||
if (config->metaObject()->indexOfSignal(DIRTY_SIGNAL) != -1) {
|
if (config->metaObject()->indexOfSignal(DIRTY_SIGNAL) != -1) {
|
||||||
// Connect dirty->refresh if defined
|
// 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();
|
return _jobs.back().getOutput();
|
||||||
|
@ -571,11 +567,24 @@ public:
|
||||||
return addJob<T>(name, input, std::forward<A>(args)...);
|
return addJob<T>(name, input, std::forward<A>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class C> void createConfiguration() {
|
||||||
|
auto config = std::make_shared<C>();
|
||||||
|
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>(_config)->_task = this;
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<Config> getConfiguration() {
|
std::shared_ptr<Config> getConfiguration() {
|
||||||
auto config = std::static_pointer_cast<Config>(_config);
|
if (!_config) {
|
||||||
// If we are here, we were not made by a Model, so we must initialize our own config
|
createConfiguration<Config>();
|
||||||
config->init(this);
|
}
|
||||||
return config;
|
return std::static_pointer_cast<Config>(_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
void configure(const QObject& configuration) {
|
void configure(const QObject& configuration) {
|
||||||
|
|
Loading…
Reference in a new issue