Fixed issues with scale up and erasing over network
This commit is contained in:
parent
09f29c6329
commit
015e9bc5df
9 changed files with 62 additions and 20 deletions
|
|
@ -79,6 +79,10 @@ void CanvasComponentContainer::send_comp_update(DrawingProgram& drawP, bool fina
|
|||
drawP.world.delayedUpdateObjectManager.send_update_to_all<CanvasComponentAllocator>(compAllocator, finalUpdate);
|
||||
}
|
||||
|
||||
void CanvasComponentContainer::set_object_update_lock(DrawingProgram& drawP, bool lockSet) {
|
||||
drawP.world.delayedUpdateObjectManager.set_object_update_lock<CanvasComponentAllocator>(compAllocator, lockSet);
|
||||
}
|
||||
|
||||
void CanvasComponentContainer::write_constructor_func(const NetworkingObjects::NetObjTemporaryPtr<CanvasComponentContainer>& o, cereal::PortableBinaryOutputArchive& a) {
|
||||
a(o->coords);
|
||||
o->compAllocator.write_create_message(a);
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ class CanvasComponentContainer {
|
|||
void send_comp_update(DrawingProgram& drawP, bool finalUpdate);
|
||||
void scale_up(const WorldScalar& scaleUpAmount);
|
||||
void normalize_object_coordinates();
|
||||
void set_object_update_lock(DrawingProgram& drawP, bool lockSet);
|
||||
|
||||
std::weak_ptr<DrawingProgramCacheBVHNode> cacheParentBvhNode;
|
||||
DrawingProgramLayerListItem* parentLayer = nullptr;
|
||||
|
|
|
|||
|
|
@ -300,11 +300,11 @@ void DrawingProgram::server_init_no_file() {
|
|||
|
||||
void DrawingProgram::scale_up(const WorldScalar& scaleUpAmount) {
|
||||
selection.deselect_all();
|
||||
switch_to_tool(drawTool->get_type() == DrawingProgramToolType::GRIDMODIFY ? DrawingProgramToolType::EDIT : drawTool->get_type(), true);
|
||||
layerMan.scale_up(scaleUpAmount);
|
||||
if(controls.lockedCameraScale.has_value())
|
||||
controls.lockedCameraScale.value() *= scaleUpAmount;
|
||||
rebuild_cache();
|
||||
switch_to_tool(drawTool->get_type() == DrawingProgramToolType::GRIDMODIFY ? DrawingProgramToolType::EDIT : drawTool->get_type(), true);
|
||||
}
|
||||
|
||||
void DrawingProgram::write_components_server(cereal::PortableBinaryOutputArchive& a) {
|
||||
|
|
|
|||
|
|
@ -88,4 +88,8 @@ bool EditTransformCanvasComponentWorldUndoAction::undo_redo(WorldUndoManager& un
|
|||
return true;
|
||||
}
|
||||
|
||||
void EditTransformCanvasComponentWorldUndoAction::scale_up(const WorldScalar& scaleAmount) {
|
||||
coords.scale_about(WorldVec{0, 0}, scaleAmount, true);
|
||||
}
|
||||
|
||||
EditTransformCanvasComponentWorldUndoAction::~EditTransformCanvasComponentWorldUndoAction() {}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ class EditTransformCanvasComponentWorldUndoAction : public WorldUndoAction {
|
|||
bool undo(WorldUndoManager& undoMan) override;
|
||||
bool redo(WorldUndoManager& undoMan) override;
|
||||
bool undo_redo(WorldUndoManager& undoMan);
|
||||
void scale_up(const WorldScalar& scaleAmount) override;
|
||||
~EditTransformCanvasComponentWorldUndoAction();
|
||||
|
||||
std::unique_ptr<CanvasComponent> data;
|
||||
|
|
|
|||
|
|
@ -141,6 +141,7 @@ void EraserTool::erase_on_path() {
|
|||
auto it = updatedComponents.find(c);
|
||||
if(it != updatedComponents.end()) {
|
||||
c->obj->get_comp().set_data_from(*it->second.copyData->obj);
|
||||
c->obj->set_object_update_lock(drawP, false);
|
||||
updatedComponents.erase(it);
|
||||
}
|
||||
erasedComponents.emplace(c);
|
||||
|
|
@ -161,8 +162,10 @@ void EraserTool::erase_on_path() {
|
|||
case CanvasComponentEraseDetailResult::NO_CHANGE:
|
||||
return false;
|
||||
case CanvasComponentEraseDetailResult::CHANGED: {
|
||||
if(!updatedComponents.contains(c))
|
||||
if(!updatedComponents.contains(c)) {
|
||||
c->obj->set_object_update_lock(drawP, true);
|
||||
updatedComponents.emplace(c, std::move(dataCopy));
|
||||
}
|
||||
// NOTE: commit_update is what should be run here, but invalidate_cache is being run instead. This is for a few reasons:
|
||||
// - Mesh initialize_draw_data does nothing, so commit_update isnt necessary
|
||||
// - worldAABB only shrinks, which means that invalidate_cache_at_optional_aabb will invalidate a "good enough" space even if worldAABB isn't updated (which commit_update does)
|
||||
|
|
@ -171,17 +174,20 @@ void EraserTool::erase_on_path() {
|
|||
drawP.drawCache.invalidate_cache_at_optional_aabb(c->obj->get_world_bounds());
|
||||
return false;
|
||||
}
|
||||
case CanvasComponentEraseDetailResult::REMOVED:
|
||||
case CanvasComponentEraseDetailResult::REMOVED: {
|
||||
auto it = updatedComponents.find(c);
|
||||
if(it != updatedComponents.end()) {
|
||||
c->obj->get_comp().set_data_from(*it->second.copyData->obj);
|
||||
c->obj->set_object_update_lock(drawP, false);
|
||||
updatedComponents.erase(it);
|
||||
}
|
||||
else
|
||||
c->obj->get_comp().set_data_from(*dataCopy->obj);
|
||||
|
||||
erasedComponents.emplace(c);
|
||||
drawP.drawCache.invalidate_cache_at_optional_aabb(c->obj->get_world_bounds());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -211,6 +217,7 @@ void EraserTool::reset_erasing_stroke() {
|
|||
void EraserTool::erase_component(CanvasComponentContainer::ObjInfo* erasedComp) {
|
||||
erasedComponents.erase(erasedComp);
|
||||
updatedComponents.erase(erasedComp);
|
||||
erasedComp->obj->set_object_update_lock(drawP, false);
|
||||
}
|
||||
|
||||
void EraserTool::commit_erase() {
|
||||
|
|
@ -223,6 +230,7 @@ void EraserTool::commit_erase() {
|
|||
|
||||
std::erase_if(updatedComponents, [&] (auto& p) {
|
||||
auto& [comp, oldData] = p;
|
||||
comp->obj->set_object_update_lock(drawP, false);
|
||||
if(!oldData.splitComps.empty()) {
|
||||
for(CanvasComponentContainer* c : oldData.splitComps)
|
||||
newObjectsToPlace[comp->obj->parentLayer].emplace_back(std::next(comp->obj->objInfo), c);
|
||||
|
|
|
|||
|
|
@ -628,13 +628,13 @@ void World::scale_up_step() {
|
|||
|
||||
void World::scale_up(const WorldScalar& scaleUpAmount) {
|
||||
Logger::get().log(Logger::LogType::DESKTOP_USERINFO, "Canvas scaled up");
|
||||
// drawProg will be sending info on committed objects/modified grids. These objects will NOT be scaled up.
|
||||
// This means that the scale up message must be sent AFTER the World::scale_up function is called on our end
|
||||
// if this client is the one responsible for the scale up
|
||||
drawProg.scale_up(scaleUpAmount);
|
||||
bMan.scale_up(scaleUpAmount);
|
||||
gridMan.scale_up(scaleUpAmount);
|
||||
drawData.cam.scale_up(*this, scaleUpAmount);
|
||||
// drawProg will be sending info on committed objects/modified grids. These objects will be scaled up already.
|
||||
// This means that the scale up message must be send BEFORE the World::scale_up function is called on our end
|
||||
// if this client is the one responsible for the scale up
|
||||
drawProg.scale_up(scaleUpAmount);
|
||||
undo.scale_up(scaleUpAmount);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue