Speed up paste action
This commit is contained in:
parent
cf9e8a6848
commit
b9fd39b469
4 changed files with 50 additions and 23 deletions
|
|
@ -435,12 +435,16 @@ void DrawingProgramSelection::paste_clipboard(Vector2f pasteScreenPos) {
|
||||||
newComponentContainer->coords.scale_about(mousePos, scaleMultiplier);
|
newComponentContainer->coords.scale_about(mousePos, scaleMultiplier);
|
||||||
placedComponents.emplace_back(drawP.layerMan.get_edited_layer_end_iterator(), newComponentContainer);
|
placedComponents.emplace_back(drawP.layerMan.get_edited_layer_end_iterator(), newComponentContainer);
|
||||||
}
|
}
|
||||||
auto newlyInsertedObjectIts = drawP.layerMan.add_many_components_to_layer_being_edited(placedComponents);
|
std::vector<CanvasComponentContainer::ObjInfoIterator> newlyInsertedObjectIts;
|
||||||
|
drawP.layerMan.disable_add_to_cache_and_commit_update_block([&]() {
|
||||||
|
newlyInsertedObjectIts = drawP.layerMan.add_many_components_to_layer_being_edited(placedComponents);
|
||||||
|
});
|
||||||
std::vector<CanvasComponentContainer::ObjInfo*> compSetInserted;
|
std::vector<CanvasComponentContainer::ObjInfo*> compSetInserted;
|
||||||
for(auto& it : newlyInsertedObjectIts) {
|
for(auto& it : newlyInsertedObjectIts)
|
||||||
drawP.drawCache.erase_component(&(*it));
|
|
||||||
compSetInserted.emplace_back(&(*it));
|
compSetInserted.emplace_back(&(*it));
|
||||||
}
|
parallel_loop_container(compSetInserted, [&drawP = drawP](CanvasComponentContainer::ObjInfo* comp) {
|
||||||
|
comp->obj->commit_update_dont_invalidate_cache(drawP);
|
||||||
|
});
|
||||||
set_to_selection(compSetInserted);
|
set_to_selection(compSetInserted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,10 @@ void DrawingProgramLayer::set_component_list_callbacks(DrawingProgramLayerListIt
|
||||||
auto insertCallback = [&](const CanvasComponentContainer::ObjInfoIterator& c) {
|
auto insertCallback = [&](const CanvasComponentContainer::ObjInfoIterator& c) {
|
||||||
c->obj->objInfo = c;
|
c->obj->objInfo = c;
|
||||||
c->obj->parentLayer = &layerListItem;
|
c->obj->parentLayer = &layerListItem;
|
||||||
if(layerMan.commitUpdateOnComponentInsert) {
|
if(layerMan.commitUpdateOnComponentInsert)
|
||||||
c->obj->commit_update(layerMan.drawP); // Run commit update on insert so that world bounds are calculated
|
c->obj->commit_update(layerMan.drawP); // Run commit update on insert so that world bounds are calculated
|
||||||
|
if(layerMan.addToCacheOnComponentInsert)
|
||||||
layerMan.drawP.drawCache.add_component(&(*c));
|
layerMan.drawP.drawCache.add_component(&(*c));
|
||||||
}
|
|
||||||
if(c->obj->get_comp().get_type() == CanvasComponentType::IMAGE)
|
if(c->obj->get_comp().get_type() == CanvasComponentType::IMAGE)
|
||||||
layerMan.drawP.updateableComponents.emplace(&(*c));
|
layerMan.drawP.updateableComponents.emplace(&(*c));
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,9 @@ void DrawingProgramLayerManager::write_components_server(cereal::PortableBinaryO
|
||||||
|
|
||||||
void DrawingProgramLayerManager::read_components_client(cereal::PortableBinaryInputArchive& a) {
|
void DrawingProgramLayerManager::read_components_client(cereal::PortableBinaryInputArchive& a) {
|
||||||
layerTreeRoot = drawP.world.netObjMan.read_create_message<DrawingProgramLayerListItem>(a, nullptr);
|
layerTreeRoot = drawP.world.netObjMan.read_create_message<DrawingProgramLayerListItem>(a, nullptr);
|
||||||
commitUpdateOnComponentInsert = false;
|
disable_add_to_cache_and_commit_update_block([&]() {
|
||||||
layerTreeRoot->set_component_list_callbacks(*this);
|
layerTreeRoot->set_component_list_callbacks(*this);
|
||||||
commitUpdateOnComponentInsert = true;
|
});
|
||||||
auto flattenedCompList = get_flattened_component_list();
|
auto flattenedCompList = get_flattened_component_list();
|
||||||
parallel_loop_container(flattenedCompList, [&drawP = drawP](CanvasComponentContainer::ObjInfo* comp) {
|
parallel_loop_container(flattenedCompList, [&drawP = drawP](CanvasComponentContainer::ObjInfo* comp) {
|
||||||
comp->obj->commit_update_dont_invalidate_cache(drawP);
|
comp->obj->commit_update_dont_invalidate_cache(drawP);
|
||||||
|
|
@ -107,6 +107,26 @@ std::vector<CanvasComponentContainer::ObjInfoIterator> DrawingProgramLayerManage
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawingProgramLayerManager::disable_add_to_cache_block(const std::function<void()>& toRun) {
|
||||||
|
addToCacheOnComponentInsert = false;
|
||||||
|
toRun();
|
||||||
|
addToCacheOnComponentInsert = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawingProgramLayerManager::disable_commit_update_block(const std::function<void()>& toRun) {
|
||||||
|
commitUpdateOnComponentInsert = false;
|
||||||
|
toRun();
|
||||||
|
commitUpdateOnComponentInsert = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawingProgramLayerManager::disable_add_to_cache_and_commit_update_block(const std::function<void()>& toRun) {
|
||||||
|
addToCacheOnComponentInsert = false;
|
||||||
|
commitUpdateOnComponentInsert = false;
|
||||||
|
toRun();
|
||||||
|
commitUpdateOnComponentInsert = true;
|
||||||
|
addToCacheOnComponentInsert = true;
|
||||||
|
}
|
||||||
|
|
||||||
CanvasComponentContainer::ObjInfo* DrawingProgramLayerManager::add_component_to_layer_being_edited(CanvasComponentContainer* newObj) {
|
CanvasComponentContainer::ObjInfo* DrawingProgramLayerManager::add_component_to_layer_being_edited(CanvasComponentContainer* newObj) {
|
||||||
auto editLayerPtr = editingLayer.lock();
|
auto editLayerPtr = editingLayer.lock();
|
||||||
if(!editLayerPtr)
|
if(!editLayerPtr)
|
||||||
|
|
@ -118,13 +138,13 @@ void DrawingProgramLayerManager::load_file(cereal::PortableBinaryInputArchive& a
|
||||||
if(version >= VersionNumber(0, 4, 0)) {
|
if(version >= VersionNumber(0, 4, 0)) {
|
||||||
layerTreeRoot = drawP.world.netObjMan.make_obj_from_ptr<DrawingProgramLayerListItem>(new DrawingProgramLayerListItem());
|
layerTreeRoot = drawP.world.netObjMan.make_obj_from_ptr<DrawingProgramLayerListItem>(new DrawingProgramLayerListItem());
|
||||||
layerTreeRoot->load_file(a, version, *this);
|
layerTreeRoot->load_file(a, version, *this);
|
||||||
commitUpdateOnComponentInsert = false;
|
disable_add_to_cache_and_commit_update_block([&]() {
|
||||||
layerTreeRoot->get_folder().set_component_list_callbacks(*this); // Only need to call set_component_list_callbacks on root, and the rest will get the callbacks set as well
|
layerTreeRoot->get_folder().set_component_list_callbacks(*this); // Only need to call set_component_list_callbacks on root, and the rest will get the callbacks set as well
|
||||||
commitUpdateOnComponentInsert = true;
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
server_init_no_file();
|
server_init_no_file();
|
||||||
commitUpdateOnComponentInsert = false;
|
disable_add_to_cache_and_commit_update_block([&]() {
|
||||||
CanvasComponentContainer::NetListTemporaryPtr editingLayerTmpPtrComponents = editingLayer.lock()->get_layer().components;
|
CanvasComponentContainer::NetListTemporaryPtr editingLayerTmpPtrComponents = editingLayer.lock()->get_layer().components;
|
||||||
uint64_t compCount;
|
uint64_t compCount;
|
||||||
a(compCount);
|
a(compCount);
|
||||||
|
|
@ -133,7 +153,7 @@ void DrawingProgramLayerManager::load_file(cereal::PortableBinaryInputArchive& a
|
||||||
newContainer->load_file(a, version, drawP.world.netObjMan);
|
newContainer->load_file(a, version, drawP.world.netObjMan);
|
||||||
editingLayerTmpPtrComponents->push_back_and_send_create(editingLayerTmpPtrComponents, newContainer);
|
editingLayerTmpPtrComponents->push_back_and_send_create(editingLayerTmpPtrComponents, newContainer);
|
||||||
}
|
}
|
||||||
commitUpdateOnComponentInsert = true;
|
});
|
||||||
}
|
}
|
||||||
auto flattenedCompList = get_flattened_component_list();
|
auto flattenedCompList = get_flattened_component_list();
|
||||||
parallel_loop_container(flattenedCompList, [&drawP = drawP](CanvasComponentContainer::ObjInfo* comp) {
|
parallel_loop_container(flattenedCompList, [&drawP = drawP](CanvasComponentContainer::ObjInfo* comp) {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ class DrawingProgramLayerManager {
|
||||||
void add_undo_place_components(DrawingProgramLayerListItem* parent, const std::vector<CanvasComponentContainer::ObjInfoIterator>& placeList);
|
void add_undo_place_components(DrawingProgramLayerListItem* parent, const std::vector<CanvasComponentContainer::ObjInfoIterator>& placeList);
|
||||||
void erase_component_map(const std::unordered_map<DrawingProgramLayerListItem*, std::vector<CanvasComponentContainer::ObjInfoIterator>>& eraseMap);
|
void erase_component_map(const std::unordered_map<DrawingProgramLayerListItem*, std::vector<CanvasComponentContainer::ObjInfoIterator>>& eraseMap);
|
||||||
bool commitUpdateOnComponentInsert = true;
|
bool commitUpdateOnComponentInsert = true;
|
||||||
|
bool addToCacheOnComponentInsert = true;
|
||||||
public:
|
public:
|
||||||
enum class LayerSelector {
|
enum class LayerSelector {
|
||||||
ALL_VISIBLE_LAYERS,
|
ALL_VISIBLE_LAYERS,
|
||||||
|
|
@ -46,6 +47,9 @@ class DrawingProgramLayerManager {
|
||||||
uint32_t edited_layer_component_count();
|
uint32_t edited_layer_component_count();
|
||||||
CanvasComponentContainer::ObjInfoIterator get_edited_layer_end_iterator();
|
CanvasComponentContainer::ObjInfoIterator get_edited_layer_end_iterator();
|
||||||
bool component_passes_layer_selector(CanvasComponentContainer::ObjInfo* c, LayerSelector layerSelector);
|
bool component_passes_layer_selector(CanvasComponentContainer::ObjInfo* c, LayerSelector layerSelector);
|
||||||
|
void disable_add_to_cache_block(const std::function<void()>& toRun);
|
||||||
|
void disable_commit_update_block(const std::function<void()>& toRun);
|
||||||
|
void disable_add_to_cache_and_commit_update_block(const std::function<void()>& toRun);
|
||||||
|
|
||||||
void load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version);
|
void load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version);
|
||||||
void save_file(cereal::PortableBinaryOutputArchive& a) const;
|
void save_file(cereal::PortableBinaryOutputArchive& a) const;
|
||||||
|
|
@ -59,7 +63,6 @@ class DrawingProgramLayerManager {
|
||||||
std::vector<CanvasComponentContainer::ObjInfoIterator> add_many_components_to_layer_being_edited(const std::vector<std::pair<CanvasComponentContainer::ObjInfoIterator, CanvasComponentContainer*>>& newObjs);
|
std::vector<CanvasComponentContainer::ObjInfoIterator> add_many_components_to_layer_being_edited(const std::vector<std::pair<CanvasComponentContainer::ObjInfoIterator, CanvasComponentContainer*>>& newObjs);
|
||||||
std::vector<CanvasComponentContainer::ObjInfo*> get_flattened_component_list() const;
|
std::vector<CanvasComponentContainer::ObjInfo*> get_flattened_component_list() const;
|
||||||
std::vector<DrawingProgramLayerListItem*> get_flattened_layer_list();
|
std::vector<DrawingProgramLayerListItem*> get_flattened_layer_list();
|
||||||
|
|
||||||
void add_undo_place_component(CanvasComponentContainer::ObjInfo* objInfo);
|
void add_undo_place_component(CanvasComponentContainer::ObjInfo* objInfo);
|
||||||
DrawingProgramLayerManagerGUI listGUI;
|
DrawingProgramLayerManagerGUI listGUI;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue