Renamed functions and added a fix for a bug in bring to front/push to back undo
This commit is contained in:
parent
9d539367ec
commit
a3bde62835
4 changed files with 45 additions and 13 deletions
|
|
@ -112,6 +112,18 @@ namespace NetworkingObjects {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T> void sort_netobj_ordered_list_iterator_list(const std::list<NetObjOrderedListObjectInfo<T>>& l, std::vector<NetObjOrderedListIterator<T>>& itListToSort) {
|
||||||
|
std::stable_sort(itListToSort.begin(), itListToSort.end(), [&l](auto& a, auto& b) {
|
||||||
|
return b == l.end() || (a != l.end() && a->pos < b->pos);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> void sort_netobj_ordered_list_iterator_insert_list(const std::list<NetObjOrderedListObjectInfo<T>>& l, std::vector<std::pair<NetObjOrderedListIterator<T>, NetObjOwnerPtr<T>>>& itListToSort) {
|
||||||
|
std::stable_sort(itListToSort.begin(), itListToSort.end(), [&l](auto& a, auto& b) {
|
||||||
|
return b.first == l.end() || (a.first != l.end() && a.first->pos < b.first->pos);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T> class NetObjOrderedList {
|
template <typename T> class NetObjOrderedList {
|
||||||
public:
|
public:
|
||||||
// Don't use this function unless you're sure that class T isn't a base class
|
// Don't use this function unless you're sure that class T isn't a base class
|
||||||
|
|
@ -127,7 +139,7 @@ namespace NetworkingObjects {
|
||||||
static NetObjOrderedListIterator<T> insert_and_send_create(const NetObjTemporaryPtr<NetObjOrderedList<T>>& l, const NetObjOrderedListIterator<T>& it, T* newObj) {
|
static NetObjOrderedListIterator<T> insert_and_send_create(const NetObjTemporaryPtr<NetObjOrderedList<T>>& l, const NetObjOrderedListIterator<T>& it, T* newObj) {
|
||||||
return l->insert_single(l, nullptr, it, l.get_obj_man()->template make_obj_from_ptr<T>(newObj));
|
return l->insert_single(l, nullptr, it, l.get_obj_man()->template make_obj_from_ptr<T>(newObj));
|
||||||
}
|
}
|
||||||
static std::vector<NetObjOrderedListIterator<T>> insert_ordered_list_and_send_create(const NetObjTemporaryPtr<NetObjOrderedList<T>>& l, const std::vector<std::pair<NetObjOrderedListIterator<T>, T*>>& newObjs) {
|
static std::vector<NetObjOrderedListIterator<T>> insert_sorted_list_and_send_create(const NetObjTemporaryPtr<NetObjOrderedList<T>>& l, const std::vector<std::pair<NetObjOrderedListIterator<T>, T*>>& newObjs) {
|
||||||
if(newObjs.empty())
|
if(newObjs.empty())
|
||||||
return {};
|
return {};
|
||||||
std::vector<std::pair<NetObjOrderedListIterator<T>, NetObjOwnerPtr<T>>> ownerPtrOrderedList;
|
std::vector<std::pair<NetObjOrderedListIterator<T>, NetObjOwnerPtr<T>>> ownerPtrOrderedList;
|
||||||
|
|
@ -135,11 +147,26 @@ namespace NetworkingObjects {
|
||||||
ownerPtrOrderedList.emplace_back(newObjs[i].first, std::move(l.get_obj_man()->template make_obj_from_ptr<T>(newObjs[i].second)));
|
ownerPtrOrderedList.emplace_back(newObjs[i].first, std::move(l.get_obj_man()->template make_obj_from_ptr<T>(newObjs[i].second)));
|
||||||
return l->insert_ordered_list(l, nullptr, ownerPtrOrderedList);
|
return l->insert_ordered_list(l, nullptr, ownerPtrOrderedList);
|
||||||
}
|
}
|
||||||
static std::vector<NetObjOrderedListIterator<T>> insert_ordered_list_and_send_create(const NetObjTemporaryPtr<NetObjOrderedList<T>>& l, std::vector<std::pair<NetObjOrderedListIterator<T>, NetObjOwnerPtr<T>>>& newObjPtrs) {
|
static std::vector<NetObjOrderedListIterator<T>> insert_sorted_list_and_send_create(const NetObjTemporaryPtr<NetObjOrderedList<T>>& l, std::vector<std::pair<NetObjOrderedListIterator<T>, NetObjOwnerPtr<T>>>& newObjPtrs) {
|
||||||
if(newObjPtrs.empty())
|
if(newObjPtrs.empty())
|
||||||
return {};
|
return {};
|
||||||
return l->insert_ordered_list(l, nullptr, newObjPtrs);
|
return l->insert_ordered_list(l, nullptr, newObjPtrs);
|
||||||
}
|
}
|
||||||
|
static std::vector<NetObjOrderedListIterator<T>> insert_unsorted_list_and_send_create(const NetObjTemporaryPtr<NetObjOrderedList<T>>& l, const std::vector<std::pair<NetObjOrderedListIterator<T>, T*>>& newObjs) {
|
||||||
|
if(newObjs.empty())
|
||||||
|
return {};
|
||||||
|
std::vector<std::pair<NetObjOrderedListIterator<T>, NetObjOwnerPtr<T>>> ownerPtrOrderedList;
|
||||||
|
for(uint32_t i = 0; i < static_cast<uint32_t>(newObjs.size()); i++)
|
||||||
|
ownerPtrOrderedList.emplace_back(newObjs[i].first, std::move(l.get_obj_man()->template make_obj_from_ptr<T>(newObjs[i].second)));
|
||||||
|
sort_netobj_ordered_list_iterator_insert_list(l, ownerPtrOrderedList);
|
||||||
|
return l->insert_ordered_list(l, nullptr, ownerPtrOrderedList);
|
||||||
|
}
|
||||||
|
static std::vector<NetObjOrderedListIterator<T>> insert_unsorted_list_and_send_create(const NetObjTemporaryPtr<NetObjOrderedList<T>>& l, std::vector<std::pair<NetObjOrderedListIterator<T>, NetObjOwnerPtr<T>>>& newObjPtrs) {
|
||||||
|
if(newObjPtrs.empty())
|
||||||
|
return {};
|
||||||
|
sort_netobj_ordered_list_iterator_insert_list(l, newObjPtrs);
|
||||||
|
return l->insert_ordered_list(l, nullptr, newObjPtrs);
|
||||||
|
}
|
||||||
static void erase_list(const NetObjTemporaryPtr<NetObjOrderedList<T>>& l, const std::vector<NetObjOrderedListIterator<T>>& iterators, std::vector<NetObjOwnerPtr<T>>* erasedObjects = nullptr) {
|
static void erase_list(const NetObjTemporaryPtr<NetObjOrderedList<T>>& l, const std::vector<NetObjOrderedListIterator<T>>& iterators, std::vector<NetObjOwnerPtr<T>>* erasedObjects = nullptr) {
|
||||||
l->erase_it_list(l, iterators, erasedObjects);
|
l->erase_it_list(l, iterators, erasedObjects);
|
||||||
}
|
}
|
||||||
|
|
@ -257,6 +284,9 @@ namespace NetworkingObjects {
|
||||||
toRet.emplace_back(get(id));
|
toRet.emplace_back(get(id));
|
||||||
return toRet;
|
return toRet;
|
||||||
}
|
}
|
||||||
|
void sort_it_list(std::vector<NetObjOrderedListIterator<T>>& itList) const {
|
||||||
|
sort_netobj_ordered_list_iterator_list(data_list(), itList);
|
||||||
|
}
|
||||||
bool empty() const {
|
bool empty() const {
|
||||||
return data_list().empty();
|
return data_list().empty();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ void BookmarkManager::setup_list_gui(const char* id) {
|
||||||
toInsert.emplace_back(insertIt, std::move(*it));
|
toInsert.emplace_back(insertIt, std::move(*it));
|
||||||
toInsert.back().second.reassign_ids();
|
toInsert.back().second.reassign_ids();
|
||||||
}
|
}
|
||||||
std::vector<NetObjOrderedListIterator<BookmarkListItem>> insertedIterators = listPtr->insert_ordered_list_and_send_create(listPtr, toInsert);
|
std::vector<NetObjOrderedListIterator<BookmarkListItem>> insertedIterators = listPtr->insert_sorted_list_and_send_create(listPtr, toInsert);
|
||||||
|
|
||||||
// Prepare insert list for undo
|
// Prepare insert list for undo
|
||||||
insertParentUndoID = world.undo.get_undoid_from_netid(listObj);
|
insertParentUndoID = world.undo.get_undoid_from_netid(listObj);
|
||||||
|
|
@ -210,7 +210,7 @@ void BookmarkManager::setup_list_gui(const char* id) {
|
||||||
toInsert.emplace_back(insertIt, std::move(*it));
|
toInsert.emplace_back(insertIt, std::move(*it));
|
||||||
toInsert.back().second.reassign_ids();
|
toInsert.back().second.reassign_ids();
|
||||||
}
|
}
|
||||||
parentListPtr->insert_ordered_list_and_send_create(parentListPtr, toInsert);
|
parentListPtr->insert_sorted_list_and_send_create(parentListPtr, toInsert);
|
||||||
}
|
}
|
||||||
}, NetObjManager::SendUpdateType::SEND_TO_ALL, nullptr);
|
}, NetObjManager::SendUpdateType::SEND_TO_ALL, nullptr);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -259,7 +259,7 @@ void BookmarkManager::setup_list_gui(const char* id) {
|
||||||
toInsert.emplace_back(insertIt, std::move(*it));
|
toInsert.emplace_back(insertIt, std::move(*it));
|
||||||
toInsert.back().second.reassign_ids();
|
toInsert.back().second.reassign_ids();
|
||||||
}
|
}
|
||||||
listPtr->insert_ordered_list_and_send_create(listPtr, toInsert);
|
listPtr->insert_sorted_list_and_send_create(listPtr, toInsert);
|
||||||
}, NetObjManager::SendUpdateType::SEND_TO_ALL, nullptr);
|
}, NetObjManager::SendUpdateType::SEND_TO_ALL, nullptr);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ void DrawingProgramLayerManager::push_components_to(const std::vector<CanvasComp
|
||||||
toInsert.emplace_back(insertIt, std::move(e));
|
toInsert.emplace_back(insertIt, std::move(e));
|
||||||
toInsert.back().second.reassign_ids();
|
toInsert.back().second.reassign_ids();
|
||||||
}
|
}
|
||||||
components->insert_ordered_list_and_send_create(components, toInsert);
|
components->insert_sorted_list_and_send_create(components, toInsert);
|
||||||
toEraseList.clear();
|
toEraseList.clear();
|
||||||
};
|
};
|
||||||
for(auto& obj : objs) {
|
for(auto& obj : objs) {
|
||||||
|
|
@ -190,6 +190,8 @@ void DrawingProgramLayerManager::push_components_to(const std::vector<CanvasComp
|
||||||
auto components = undoMan.world.netObjMan.get_obj_temporary_ref_from_id<CanvasComponentContainer::NetList>(compNetID);
|
auto components = undoMan.world.netObjMan.get_obj_temporary_ref_from_id<CanvasComponentContainer::NetList>(compNetID);
|
||||||
std::vector<std::pair<CanvasComponentContainer::ObjInfoIterator, NetObjOwnerPtr<CanvasComponentContainer>>> toInsert;
|
std::vector<std::pair<CanvasComponentContainer::ObjInfoIterator, NetObjOwnerPtr<CanvasComponentContainer>>> toInsert;
|
||||||
std::vector<NetObjOrderedListIterator<CanvasComponentContainer>> toErase = components->get_list(moveData.objs);
|
std::vector<NetObjOrderedListIterator<CanvasComponentContainer>> toErase = components->get_list(moveData.objs);
|
||||||
|
components->sort_it_list(toErase); // There's a chance that objects could have changed order on the client side, so sort them
|
||||||
|
|
||||||
std::vector<NetObjOwnerPtr<CanvasComponentContainer>> erasedObjs;
|
std::vector<NetObjOwnerPtr<CanvasComponentContainer>> erasedObjs;
|
||||||
std::vector<uint32_t> newPos;
|
std::vector<uint32_t> newPos;
|
||||||
{
|
{
|
||||||
|
|
@ -205,7 +207,7 @@ void DrawingProgramLayerManager::push_components_to(const std::vector<CanvasComp
|
||||||
toInsert.emplace_back(insertIteratorList[i], std::move(erasedObjs[i]));
|
toInsert.emplace_back(insertIteratorList[i], std::move(erasedObjs[i]));
|
||||||
toInsert.back().second.reassign_ids();
|
toInsert.back().second.reassign_ids();
|
||||||
}
|
}
|
||||||
components->insert_ordered_list_and_send_create(components, toInsert);
|
components->insert_sorted_list_and_send_create(components, toInsert);
|
||||||
*moveData.oldPos = newPos;
|
*moveData.oldPos = newPos;
|
||||||
}
|
}
|
||||||
}, NetObjManager::SendUpdateType::SEND_TO_ALL, nullptr);
|
}, NetObjManager::SendUpdateType::SEND_TO_ALL, nullptr);
|
||||||
|
|
@ -223,7 +225,7 @@ std::vector<CanvasComponentContainer::ObjInfoIterator> DrawingProgramLayerManage
|
||||||
auto editLayerPtr = editingLayer.lock();
|
auto editLayerPtr = editingLayer.lock();
|
||||||
if(!editLayerPtr)
|
if(!editLayerPtr)
|
||||||
throw std::runtime_error("[DrawingProgramLayerManager::add_many_components_to_layer_being_edited] No layer selected!");
|
throw std::runtime_error("[DrawingProgramLayerManager::add_many_components_to_layer_being_edited] No layer selected!");
|
||||||
auto toRet = editLayerPtr->get_layer().components->insert_ordered_list_and_send_create(editLayerPtr->get_layer().components, newObjs);
|
auto toRet = editLayerPtr->get_layer().components->insert_sorted_list_and_send_create(editLayerPtr->get_layer().components, newObjs);
|
||||||
add_undo_place_components(editingLayer.lock().get(), toRet);
|
add_undo_place_components(editingLayer.lock().get(), toRet);
|
||||||
return toRet;
|
return toRet;
|
||||||
}
|
}
|
||||||
|
|
@ -405,7 +407,7 @@ void DrawingProgramLayerManager::add_undo_erase_components(const std::unordered_
|
||||||
toInsert[i].second = undoMan.world.netObjMan.make_obj_direct<CanvasComponentContainer>(undoMan.world.netObjMan, *insertData.copyData->at(i));
|
toInsert[i].second = undoMan.world.netObjMan.make_obj_direct<CanvasComponentContainer>(undoMan.world.netObjMan, *insertData.copyData->at(i));
|
||||||
undoMan.register_new_netid_to_existing_undoid(insertData.undoID->at(i), toInsert[i].second.get_net_id());
|
undoMan.register_new_netid_to_existing_undoid(insertData.undoID->at(i), toInsert[i].second.get_net_id());
|
||||||
}
|
}
|
||||||
parentListPtr->insert_ordered_list_and_send_create(parentListPtr, toInsert);
|
parentListPtr->insert_sorted_list_and_send_create(parentListPtr, toInsert);
|
||||||
insertData.copyData->clear();
|
insertData.copyData->clear();
|
||||||
}
|
}
|
||||||
}, NetworkingObjects::NetObjManager::SendUpdateType::SEND_TO_ALL, nullptr);
|
}, NetworkingObjects::NetObjManager::SendUpdateType::SEND_TO_ALL, nullptr);
|
||||||
|
|
@ -530,7 +532,7 @@ void DrawingProgramLayerManager::add_undo_place_components(DrawingProgramLayerLi
|
||||||
toInsert[i].second = undoMan.world.netObjMan.make_obj_direct<CanvasComponentContainer>(undoMan.world.netObjMan, *undoPlaceData.copyData.at(i));
|
toInsert[i].second = undoMan.world.netObjMan.make_obj_direct<CanvasComponentContainer>(undoMan.world.netObjMan, *undoPlaceData.copyData.at(i));
|
||||||
undoMan.register_new_netid_to_existing_undoid(undoPlaceData.undoID.at(i), toInsert[i].second.get_net_id());
|
undoMan.register_new_netid_to_existing_undoid(undoPlaceData.undoID.at(i), toInsert[i].second.get_net_id());
|
||||||
}
|
}
|
||||||
parentListPtr->insert_ordered_list_and_send_create(parentListPtr, toInsert);
|
parentListPtr->insert_sorted_list_and_send_create(parentListPtr, toInsert);
|
||||||
|
|
||||||
undoPlaceData.copyData.clear();
|
undoPlaceData.copyData.clear();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ void DrawingProgramLayerManagerGUI::setup_list_gui(const char* id, bool& hoverin
|
||||||
toInsert.emplace_back(insertIt, std::move(*it));
|
toInsert.emplace_back(insertIt, std::move(*it));
|
||||||
toInsert.back().second.reassign_ids();
|
toInsert.back().second.reassign_ids();
|
||||||
}
|
}
|
||||||
std::vector<NetObjOrderedListIterator<DrawingProgramLayerListItem>> insertedIterators = listPtr->insert_ordered_list_and_send_create(listPtr, toInsert);
|
std::vector<NetObjOrderedListIterator<DrawingProgramLayerListItem>> insertedIterators = listPtr->insert_sorted_list_and_send_create(listPtr, toInsert);
|
||||||
|
|
||||||
// Prepare insert list for undo
|
// Prepare insert list for undo
|
||||||
insertParentUndoID = world.undo.get_undoid_from_netid(listObj);
|
insertParentUndoID = world.undo.get_undoid_from_netid(listObj);
|
||||||
|
|
@ -225,7 +225,7 @@ void DrawingProgramLayerManagerGUI::setup_list_gui(const char* id, bool& hoverin
|
||||||
toInsert.emplace_back(insertIt, std::move(*it));
|
toInsert.emplace_back(insertIt, std::move(*it));
|
||||||
toInsert.back().second.reassign_ids();
|
toInsert.back().second.reassign_ids();
|
||||||
}
|
}
|
||||||
parentListPtr->insert_ordered_list_and_send_create(parentListPtr, toInsert);
|
parentListPtr->insert_sorted_list_and_send_create(parentListPtr, toInsert);
|
||||||
}
|
}
|
||||||
}, NetObjManager::SendUpdateType::SEND_TO_ALL, nullptr);
|
}, NetObjManager::SendUpdateType::SEND_TO_ALL, nullptr);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -274,7 +274,7 @@ void DrawingProgramLayerManagerGUI::setup_list_gui(const char* id, bool& hoverin
|
||||||
toInsert.emplace_back(insertIt, std::move(*it));
|
toInsert.emplace_back(insertIt, std::move(*it));
|
||||||
toInsert.back().second.reassign_ids();
|
toInsert.back().second.reassign_ids();
|
||||||
}
|
}
|
||||||
listPtr->insert_ordered_list_and_send_create(listPtr, toInsert);
|
listPtr->insert_sorted_list_and_send_create(listPtr, toInsert);
|
||||||
}, NetObjManager::SendUpdateType::SEND_TO_ALL, nullptr);
|
}, NetObjManager::SendUpdateType::SEND_TO_ALL, nullptr);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue