mirror of
https://github.com/overte-org/overte.git
synced 2025-04-15 16:02:08 +02:00
REfining the Config behavior, trying to pr next
This commit is contained in:
parent
16e6f0900d
commit
4a47737d0b
6 changed files with 56 additions and 61 deletions
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
Engine::Engine() : Task("Engine", EngineTask::JobModel::factoryModel()),
|
||||
Engine::Engine() : Task("Engine", EngineTask::JobModel::create()),
|
||||
_sceneContext(std::make_shared<SceneContext>()),
|
||||
_renderContext(std::make_shared<RenderContext>())
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -431,22 +431,8 @@ public:
|
|||
return findChild<typename T::Config*>(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 <class... A>
|
||||
Model(const Varying& input, A&&... args) :
|
||||
Concept(std::make_shared<C>()),
|
||||
Model(const Varying& input, QConfigPointer config, A&&... args) :
|
||||
Concept(config),
|
||||
_data(Data(std::forward<A>(args)...)),
|
||||
_input(input),
|
||||
_output(Output()) {
|
||||
|
@ -534,8 +520,8 @@ public:
|
|||
}
|
||||
|
||||
template <class... A>
|
||||
static std::shared_ptr<Model> factoryModel(const Varying& input, A&&... args) {
|
||||
return std::make_shared<Model>(input, std::forward<A>(args)...);
|
||||
static std::shared_ptr<Model> create(const Varying& input, A&&... args) {
|
||||
return std::make_shared<Model>(input, std::make_shared<C>(), std::forward<A>(args)...);
|
||||
}
|
||||
|
||||
|
||||
|
@ -583,11 +569,6 @@ protected:
|
|||
std::string _name = "";
|
||||
};
|
||||
|
||||
/*
|
||||
template <class T, class... A> void taskBuild(T& data, typename T::JobModel* task, const Varying& input, Varying& output, A&&... args) {
|
||||
data.build(*(task), input, output, std::forward<A>(args)...);
|
||||
}*/
|
||||
|
||||
// A task is a specialized job to run a collection of other jobs
|
||||
// It is defined with JobModel = Task::Model<T>
|
||||
|
||||
|
@ -614,20 +595,10 @@ public:
|
|||
|
||||
// Create a new job in the container's queue; returns the job's output
|
||||
template <class NT, class... NA> const Varying addJob(std::string name, const Varying& input, NA&&... args) {
|
||||
_jobs.emplace_back(name, (NT::JobModel::factoryModel(input, std::forward<NA>(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<NA>(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<TaskConfig>(getConfiguration())->connectSubJobConfig(_jobs.back().getConfiguration(), name);
|
||||
// Conect the child config to this task's config
|
||||
std::static_pointer_cast<TaskConfig>(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 <class... A>
|
||||
static std::shared_ptr<TaskModel> factoryModel(const Varying& input, A&&... args) {
|
||||
auto model = std::make_shared<TaskModel>(input);
|
||||
static std::shared_ptr<TaskModel> create(const Varying& input, A&&... args) {
|
||||
auto model = std::make_shared<TaskModel>(input, std::make_shared<C>());
|
||||
// std::static_pointer_cast<C>(model->_config)->_task = model.get();
|
||||
|
||||
model->_data.build(*(model), model->_input, model->_output, std::forward<A>(args)...);
|
||||
|
||||
|
@ -663,27 +635,19 @@ public:
|
|||
}
|
||||
|
||||
template <class... A>
|
||||
static std::shared_ptr<TaskModel> factoryModel(A&&... args) {
|
||||
static std::shared_ptr<TaskModel> create(A&&... args) {
|
||||
const auto input = Varying(Input());
|
||||
return factoryModel(input, std::forward<A>(args)...);
|
||||
return create(input, std::forward<A>(args)...);
|
||||
}
|
||||
|
||||
void createConfiguration() {
|
||||
// A brand new config
|
||||
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());
|
||||
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<C>(_config)->_task = this;
|
||||
}
|
||||
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue