Skip to content

Commit f57163c

Browse files
adamgerhantKeavon
andauthored
Port node graph wires to the backend and improve graph UI performance (#2795)
* Improve node graph performance * Fix wire bugs, add type default for properties. * Grid aligned wire paths * remove type source * node from exposed input * Refresh wires on preference change * merge fixes * Code review * Fix names * Code review * Fix wires on redo/undo --------- Co-authored-by: Keavon Chambers <[email protected]>
1 parent 354a689 commit f57163c

File tree

24 files changed

+2078
-1999
lines changed

24 files changed

+2078
-1999
lines changed

editor/src/dispatcher.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ impl DispatcherMessageHandlers {
4040
/// The last occurrence of the message in the message queue is sufficient to ensure correct behavior.
4141
/// In addition, these messages do not change any state in the backend (aside from caches).
4242
const SIDE_EFFECT_FREE_MESSAGES: &[MessageDiscriminant] = &[
43-
MessageDiscriminant::Portfolio(PortfolioMessageDiscriminant::Document(DocumentMessageDiscriminant::NodeGraph(NodeGraphMessageDiscriminant::SendGraph))),
4443
MessageDiscriminant::Portfolio(PortfolioMessageDiscriminant::Document(DocumentMessageDiscriminant::PropertiesPanel(
4544
PropertiesPanelMessageDiscriminant::Refresh,
4645
))),

editor/src/messages/dialog/preferences_dialog/preferences_dialog_message_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::consts::{VIEWPORT_ZOOM_WHEEL_RATE, VIEWPORT_ZOOM_WHEEL_RATE_CHANGE};
22
use crate::messages::layout::utility_types::widget_prelude::*;
3-
use crate::messages::portfolio::document::node_graph::utility_types::GraphWireStyle;
3+
use crate::messages::portfolio::document::utility_types::wires::GraphWireStyle;
44
use crate::messages::preferences::SelectionMode;
55
use crate::messages::prelude::*;
66

editor/src/messages/frontend/frontend_message.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use super::utility_types::{FrontendDocumentDetails, MouseCursorIcon};
22
use crate::messages::layout::utility_types::widget_prelude::*;
33
use crate::messages::portfolio::document::node_graph::utility_types::{
4-
BoxSelection, ContextMenuInformation, FrontendClickTargets, FrontendGraphInput, FrontendGraphOutput, FrontendNode, FrontendNodeType, FrontendNodeWire, Transform, WirePath,
4+
BoxSelection, ContextMenuInformation, FrontendClickTargets, FrontendGraphInput, FrontendGraphOutput, FrontendNode, FrontendNodeType, Transform,
55
};
66
use crate::messages::portfolio::document::utility_types::nodes::{JsRawBuffer, LayerPanelEntry, RawBuffer};
7+
use crate::messages::portfolio::document::utility_types::wires::{WirePath, WirePathUpdate};
78
use crate::messages::prelude::*;
89
use crate::messages::tool::utility_types::HintData;
910
use graph_craft::document::NodeId;
@@ -250,12 +251,16 @@ pub enum FrontendMessage {
250251
UpdateMouseCursor {
251252
cursor: MouseCursorIcon,
252253
},
253-
UpdateNodeGraph {
254+
UpdateNodeGraphNodes {
254255
nodes: Vec<FrontendNode>,
255-
wires: Vec<FrontendNodeWire>,
256-
#[serde(rename = "wiresDirectNotGridAligned")]
257-
wires_direct_not_grid_aligned: bool,
258256
},
257+
UpdateVisibleNodes {
258+
nodes: Vec<NodeId>,
259+
},
260+
UpdateNodeGraphWires {
261+
wires: Vec<WirePathUpdate>,
262+
},
263+
ClearAllNodeGraphWires,
259264
UpdateNodeGraphControlBarLayout {
260265
#[serde(rename = "layoutTarget")]
261266
layout_target: LayoutTarget,

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
444444
DocumentMessage::EnterNestedNetwork { node_id } => {
445445
self.breadcrumb_network_path.push(node_id);
446446
self.selection_network_path.clone_from(&self.breadcrumb_network_path);
447+
responses.add(NodeGraphMessage::UnloadWires);
447448
responses.add(NodeGraphMessage::SendGraph);
448449
responses.add(DocumentMessage::ZoomCanvasToFitAll);
449450
responses.add(NodeGraphMessage::SetGridAlignedEdges);
@@ -473,9 +474,10 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
473474
self.breadcrumb_network_path.pop();
474475
self.selection_network_path.clone_from(&self.breadcrumb_network_path);
475476
}
477+
responses.add(NodeGraphMessage::UnloadWires);
478+
responses.add(NodeGraphMessage::SendGraph);
476479
responses.add(DocumentMessage::PTZUpdate);
477480
responses.add(NodeGraphMessage::SetGridAlignedEdges);
478-
responses.add(NodeGraphMessage::SendGraph);
479481
}
480482
DocumentMessage::FlipSelectedLayers { flip_axis } => {
481483
let scale = match flip_axis {
@@ -525,6 +527,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
525527
}
526528
}
527529
DocumentMessage::GraphViewOverlay { open } => {
530+
let opened = !self.graph_view_overlay_open && open;
528531
self.graph_view_overlay_open = open;
529532

530533
responses.add(FrontendMessage::UpdateGraphViewOverlay { open });
@@ -537,6 +540,9 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
537540

538541
responses.add(DocumentMessage::RenderRulers);
539542
responses.add(DocumentMessage::RenderScrollbars);
543+
if opened {
544+
responses.add(NodeGraphMessage::UnloadWires);
545+
}
540546
if open {
541547
responses.add(ToolMessage::DeactivateTools);
542548
responses.add(OverlaysMessage::Draw); // Clear the overlays
@@ -1878,6 +1884,7 @@ impl DocumentMessageHandler {
18781884
responses.add(NodeGraphMessage::SelectedNodesUpdated);
18791885
responses.add(NodeGraphMessage::ForceRunDocumentGraph);
18801886
// TODO: Remove once the footprint is used to load the imports/export distances from the edge
1887+
responses.add(NodeGraphMessage::UnloadWires);
18811888
responses.add(NodeGraphMessage::SetGridAlignedEdges);
18821889
responses.add(Message::StartBuffer);
18831890
Some(previous_network)
@@ -1909,7 +1916,8 @@ impl DocumentMessageHandler {
19091916
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
19101917
responses.add(NodeGraphMessage::SelectedNodesUpdated);
19111918
responses.add(NodeGraphMessage::ForceRunDocumentGraph);
1912-
1919+
responses.add(NodeGraphMessage::UnloadWires);
1920+
responses.add(NodeGraphMessage::SendWires);
19131921
Some(previous_network)
19141922
}
19151923

@@ -2066,7 +2074,7 @@ impl DocumentMessageHandler {
20662074
/// Loads all of the fonts in the document.
20672075
pub fn load_layer_resources(&self, responses: &mut VecDeque<Message>) {
20682076
let mut fonts = HashSet::new();
2069-
for (_node_id, node) in self.document_network().recursive_nodes() {
2077+
for (_node_id, node, _) in self.document_network().recursive_nodes() {
20702078
for input in &node.inputs {
20712079
if let Some(TaggedValue::Font(font)) = input.as_value() {
20722080
fonts.insert(font.clone());

0 commit comments

Comments
 (0)