Dependencies check in debug mode
Some common resources can depend on each other - this checks that the requirements are consistent
This commit is contained in:
parent
3db3a61520
commit
7e797eaaf8
2 changed files with 33 additions and 7 deletions
|
@ -43,11 +43,24 @@ SelectionInfo* CommonGizmosDataPool::selection_info()
|
|||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
// Check the required resources one by one and return true if all
|
||||
// dependencies are met.
|
||||
bool CommonGizmosDataPool::check_dependencies(CommonGizmosDataID required) const
|
||||
{
|
||||
// This should iterate over currently required data. Each of them should
|
||||
// be asked about its dependencies and it must check that all dependencies
|
||||
// are also in required and before the current one.
|
||||
for (auto& [id, data] : m_data) {
|
||||
// in case we don't use this, the deps are irrelevant
|
||||
if (! (int(required) & int(CommonGizmosDataID(id))))
|
||||
continue;
|
||||
|
||||
|
||||
CommonGizmosDataID deps = data->get_dependencies();
|
||||
assert(int(deps) == (int(deps) & int(required)));
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif // NDEBUG
|
||||
|
@ -57,7 +70,7 @@ bool CommonGizmosDataPool::check_dependencies(CommonGizmosDataID required) const
|
|||
|
||||
void SelectionInfo::on_update()
|
||||
{
|
||||
const Selection& selection = m_common->get_canvas()->get_selection();
|
||||
const Selection& selection = get_pool()->get_canvas()->get_selection();
|
||||
if (selection.is_single_full_instance())
|
||||
m_model_object = selection.get_model()->objects[selection.get_object_idx()];
|
||||
else
|
||||
|
@ -71,7 +84,7 @@ void SelectionInfo::on_release()
|
|||
|
||||
int SelectionInfo::get_active_instance()
|
||||
{
|
||||
const Selection& selection = m_common->get_canvas()->get_selection();
|
||||
const Selection& selection = get_pool()->get_canvas()->get_selection();
|
||||
return selection.get_instance_idx();
|
||||
}
|
||||
|
||||
|
@ -81,9 +94,9 @@ int SelectionInfo::get_active_instance()
|
|||
|
||||
void InstancesHider::on_update()
|
||||
{
|
||||
const ModelObject* mo = m_common->selection_info()->model_object();
|
||||
int active_inst = m_common->selection_info()->get_active_instance();
|
||||
GLCanvas3D* canvas = m_common->get_canvas();
|
||||
const ModelObject* mo = get_pool()->selection_info()->model_object();
|
||||
int active_inst = get_pool()->selection_info()->get_active_instance();
|
||||
GLCanvas3D* canvas = get_pool()->get_canvas();
|
||||
|
||||
if (mo && active_inst != -1) {
|
||||
canvas->toggle_model_objects_visibility(false);
|
||||
|
@ -95,7 +108,7 @@ void InstancesHider::on_update()
|
|||
|
||||
void InstancesHider::on_release()
|
||||
{
|
||||
m_common->get_canvas()->toggle_model_objects_visibility(true);
|
||||
get_pool()->get_canvas()->toggle_model_objects_visibility(true);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -85,13 +85,22 @@ public:
|
|||
// Returns whether the resource is currently maintained.
|
||||
bool is_valid() const { return m_is_valid; }
|
||||
|
||||
#ifndef NDEBUG
|
||||
// Return a bitmask of all resources that this one relies on.
|
||||
// The dependent resource must have higher ID than the one
|
||||
// it depends on.
|
||||
virtual CommonGizmosDataID get_dependencies() const { return CommonGizmosDataID::None; }
|
||||
#endif // NDEBUG
|
||||
|
||||
protected:
|
||||
CommonGizmosDataPool* m_common = nullptr;
|
||||
virtual void on_release() = 0;
|
||||
virtual void on_update() = 0;
|
||||
CommonGizmosDataPool* get_pool() const { return m_common; }
|
||||
|
||||
|
||||
private:
|
||||
bool m_is_valid = false;
|
||||
CommonGizmosDataPool* m_common = nullptr;
|
||||
};
|
||||
|
||||
|
||||
|
@ -125,6 +134,10 @@ class InstancesHider : public CommonGizmosDataBase
|
|||
public:
|
||||
explicit InstancesHider(CommonGizmosDataPool* cgdp)
|
||||
: CommonGizmosDataBase(cgdp) {}
|
||||
#ifndef NDEBUG
|
||||
CommonGizmosDataID get_dependencies() const override { return CommonGizmosDataID::SelectionInfo; }
|
||||
#endif // NDEBUG
|
||||
|
||||
protected:
|
||||
void on_update() override;
|
||||
void on_release() override;
|
||||
|
|
Loading…
Reference in a new issue