Avoid unnecessary graph sends to the frontend (#1476)
This commit is contained in:
parent
ee95dac74e
commit
94fcd295c5
|
|
@ -101,8 +101,8 @@ pub struct DocumentInputs<'a> {
|
||||||
pub document_id: u64,
|
pub document_id: u64,
|
||||||
pub ipp: &'a InputPreprocessorMessageHandler,
|
pub ipp: &'a InputPreprocessorMessageHandler,
|
||||||
pub persistent_data: &'a PersistentData,
|
pub persistent_data: &'a PersistentData,
|
||||||
pub preferences: &'a PreferencesMessageHandler,
|
|
||||||
pub executor: &'a mut NodeGraphExecutor,
|
pub executor: &'a mut NodeGraphExecutor,
|
||||||
|
pub graph_view_overlay_open: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHandler {
|
impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHandler {
|
||||||
|
|
@ -113,7 +113,7 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
|
||||||
ipp,
|
ipp,
|
||||||
persistent_data,
|
persistent_data,
|
||||||
executor,
|
executor,
|
||||||
..
|
graph_view_overlay_open,
|
||||||
} = document_inputs;
|
} = document_inputs;
|
||||||
use DocumentMessage::*;
|
use DocumentMessage::*;
|
||||||
|
|
||||||
|
|
@ -191,6 +191,7 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
|
||||||
document_id,
|
document_id,
|
||||||
document_name: self.name.as_str(),
|
document_name: self.name.as_str(),
|
||||||
input: ipp,
|
input: ipp,
|
||||||
|
graph_view_overlay_open,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -259,9 +259,13 @@ impl NodeGraphMessageHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_graph(network: &NodeNetwork, layer_path: &Option<Vec<LayerId>>, responses: &mut VecDeque<Message>) {
|
fn send_graph(network: &NodeNetwork, layer_path: &Option<Vec<LayerId>>, graph_view_overlay_open: bool, responses: &mut VecDeque<Message>) {
|
||||||
responses.add(PropertiesPanelMessage::ResendActiveProperties);
|
responses.add(PropertiesPanelMessage::ResendActiveProperties);
|
||||||
|
|
||||||
|
if !graph_view_overlay_open {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let layer_id = layer_path.as_ref().and_then(|path| path.last().copied());
|
let layer_id = layer_path.as_ref().and_then(|path| path.last().copied());
|
||||||
|
|
||||||
// List of links in format (link_start, link_end, link_end_input_index)
|
// List of links in format (link_start, link_end, link_end_input_index)
|
||||||
|
|
@ -439,12 +443,14 @@ pub struct NodeGraphHandlerData<'a> {
|
||||||
pub document_id: u64,
|
pub document_id: u64,
|
||||||
pub document_name: &'a str,
|
pub document_name: &'a str,
|
||||||
pub input: &'a InputPreprocessorMessageHandler,
|
pub input: &'a InputPreprocessorMessageHandler,
|
||||||
|
pub graph_view_overlay_open: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGraphMessageHandler {
|
impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGraphMessageHandler {
|
||||||
fn process_message(&mut self, message: NodeGraphMessage, responses: &mut VecDeque<Message>, data: NodeGraphHandlerData<'a>) {
|
fn process_message(&mut self, message: NodeGraphMessage, responses: &mut VecDeque<Message>, data: NodeGraphHandlerData<'a>) {
|
||||||
let document = data.document;
|
let document = data.document;
|
||||||
let document_id = data.document_id;
|
let document_id = data.document_id;
|
||||||
|
let graph_view_overlay_open = data.graph_view_overlay_open;
|
||||||
match message {
|
match message {
|
||||||
// TODO: automatically remove broadcast messages.
|
// TODO: automatically remove broadcast messages.
|
||||||
NodeGraphMessage::Init => {
|
NodeGraphMessage::Init => {
|
||||||
|
|
@ -595,7 +601,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(network) = document.document_network.nested_network(&self.network) {
|
if let Some(network) = document.document_network.nested_network(&self.network) {
|
||||||
Self::send_graph(network, &self.layer_path, responses);
|
Self::send_graph(network, &self.layer_path, graph_view_overlay_open, responses);
|
||||||
}
|
}
|
||||||
self.collect_nested_addresses(document, data.document_name, responses);
|
self.collect_nested_addresses(document, data.document_name, responses);
|
||||||
self.update_selected(document, responses);
|
self.update_selected(document, responses);
|
||||||
|
|
@ -621,7 +627,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||||
responses.add(NodeGraphMessage::InsertNode { node_id, document_node });
|
responses.add(NodeGraphMessage::InsertNode { node_id, document_node });
|
||||||
}
|
}
|
||||||
|
|
||||||
Self::send_graph(network, &self.layer_path, responses);
|
Self::send_graph(network, &self.layer_path, graph_view_overlay_open, responses);
|
||||||
self.update_selected(document, responses);
|
self.update_selected(document, responses);
|
||||||
responses.add(NodeGraphMessage::SendGraph { should_rerender: false });
|
responses.add(NodeGraphMessage::SendGraph { should_rerender: false });
|
||||||
}
|
}
|
||||||
|
|
@ -632,7 +638,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||||
self.network.pop();
|
self.network.pop();
|
||||||
}
|
}
|
||||||
if let Some(network) = document.document_network.nested_network(&self.network) {
|
if let Some(network) = document.document_network.nested_network(&self.network) {
|
||||||
Self::send_graph(network, &self.layer_path, responses);
|
Self::send_graph(network, &self.layer_path, graph_view_overlay_open, responses);
|
||||||
}
|
}
|
||||||
self.collect_nested_addresses(document, data.document_name, responses);
|
self.collect_nested_addresses(document, data.document_name, responses);
|
||||||
self.update_selected(document, responses);
|
self.update_selected(document, responses);
|
||||||
|
|
@ -683,7 +689,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||||
node.metadata.position += IVec2::new(displacement_x, displacement_y)
|
node.metadata.position += IVec2::new(displacement_x, displacement_y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Self::send_graph(network, &self.layer_path, responses);
|
Self::send_graph(network, &self.layer_path, graph_view_overlay_open, responses);
|
||||||
}
|
}
|
||||||
NodeGraphMessage::OpenNodeGraph { layer_path } => {
|
NodeGraphMessage::OpenNodeGraph { layer_path } => {
|
||||||
self.layer_path = Some(layer_path);
|
self.layer_path = Some(layer_path);
|
||||||
|
|
@ -691,7 +697,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||||
if let Some(network) = document.document_network.nested_network(&self.network) {
|
if let Some(network) = document.document_network.nested_network(&self.network) {
|
||||||
responses.add(document.metadata.clear_selected_nodes());
|
responses.add(document.metadata.clear_selected_nodes());
|
||||||
|
|
||||||
Self::send_graph(network, &self.layer_path, responses);
|
Self::send_graph(network, &self.layer_path, graph_view_overlay_open, responses);
|
||||||
|
|
||||||
let node_types = document_node_types::collect_node_types();
|
let node_types = document_node_types::collect_node_types();
|
||||||
responses.add(FrontendMessage::UpdateNodeTypes { node_types });
|
responses.add(FrontendMessage::UpdateNodeTypes { node_types });
|
||||||
|
|
@ -759,7 +765,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||||
}
|
}
|
||||||
NodeGraphMessage::SendGraph { should_rerender } => {
|
NodeGraphMessage::SendGraph { should_rerender } => {
|
||||||
if let Some(network) = document.document_network.nested_network(&self.network) {
|
if let Some(network) = document.document_network.nested_network(&self.network) {
|
||||||
Self::send_graph(network, &self.layer_path, responses);
|
Self::send_graph(network, &self.layer_path, graph_view_overlay_open, responses);
|
||||||
if should_rerender {
|
if should_rerender {
|
||||||
if let Some(layer_path) = self.layer_path.clone() {
|
if let Some(layer_path) = self.layer_path.clone() {
|
||||||
responses.add(DocumentMessage::InputFrameRasterizeRegionBelowLayer { layer_path });
|
responses.add(DocumentMessage::InputFrameRasterizeRegionBelowLayer { layer_path });
|
||||||
|
|
@ -893,7 +899,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||||
} else if !network.inputs.contains(&node_id) && !network.original_outputs().iter().any(|output| output.node_id == node_id) {
|
} else if !network.inputs.contains(&node_id) && !network.original_outputs().iter().any(|output| output.node_id == node_id) {
|
||||||
network.disabled.push(node_id);
|
network.disabled.push(node_id);
|
||||||
}
|
}
|
||||||
Self::send_graph(network, &self.layer_path, responses);
|
Self::send_graph(network, &self.layer_path, graph_view_overlay_open, responses);
|
||||||
|
|
||||||
// Only generate node graph if one of the selected nodes is connected to the output
|
// Only generate node graph if one of the selected nodes is connected to the output
|
||||||
if network.connected_to_output(node_id) {
|
if network.connected_to_output(node_id) {
|
||||||
|
|
@ -917,7 +923,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Self::send_graph(network, &self.layer_path, responses);
|
Self::send_graph(network, &self.layer_path, graph_view_overlay_open, responses);
|
||||||
}
|
}
|
||||||
self.update_selection_action_buttons(document, responses);
|
self.update_selection_action_buttons(document, responses);
|
||||||
if let Some(layer_path) = self.layer_path.clone() {
|
if let Some(layer_path) = self.layer_path.clone() {
|
||||||
|
|
@ -930,7 +936,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||||
if let Some(network) = document.document_network.nested_network(&self.network) {
|
if let Some(network) = document.document_network.nested_network(&self.network) {
|
||||||
responses.add(document.metadata.clear_selected_nodes());
|
responses.add(document.metadata.clear_selected_nodes());
|
||||||
|
|
||||||
Self::send_graph(network, &self.layer_path, responses);
|
Self::send_graph(network, &self.layer_path, graph_view_overlay_open, responses);
|
||||||
|
|
||||||
let node_types = document_node_types::collect_node_types();
|
let node_types = document_node_types::collect_node_types();
|
||||||
responses.add(FrontendMessage::UpdateNodeTypes { node_types });
|
responses.add(FrontendMessage::UpdateNodeTypes { node_types });
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,8 @@ impl MessageHandler<PortfolioMessage, (&InputPreprocessorMessageHandler, &Prefer
|
||||||
document_id,
|
document_id,
|
||||||
ipp,
|
ipp,
|
||||||
persistent_data: &self.persistent_data,
|
persistent_data: &self.persistent_data,
|
||||||
preferences,
|
|
||||||
executor: &mut self.executor,
|
executor: &mut self.executor,
|
||||||
|
graph_view_overlay_open: self.graph_view_overlay_open,
|
||||||
};
|
};
|
||||||
document.process_message(message, responses, document_inputs)
|
document.process_message(message, responses, document_inputs)
|
||||||
}
|
}
|
||||||
|
|
@ -64,8 +64,8 @@ impl MessageHandler<PortfolioMessage, (&InputPreprocessorMessageHandler, &Prefer
|
||||||
document_id,
|
document_id,
|
||||||
ipp,
|
ipp,
|
||||||
persistent_data: &self.persistent_data,
|
persistent_data: &self.persistent_data,
|
||||||
preferences,
|
|
||||||
executor: &mut self.executor,
|
executor: &mut self.executor,
|
||||||
|
graph_view_overlay_open: self.graph_view_overlay_open,
|
||||||
};
|
};
|
||||||
document.process_message(message, responses, document_inputs)
|
document.process_message(message, responses, document_inputs)
|
||||||
}
|
}
|
||||||
|
|
@ -273,6 +273,9 @@ impl MessageHandler<PortfolioMessage, (&InputPreprocessorMessageHandler, &Prefer
|
||||||
layout_target: LayoutTarget::GraphViewOverlayButton,
|
layout_target: LayoutTarget::GraphViewOverlayButton,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if open {
|
||||||
|
responses.add(NodeGraphMessage::SendGraph { should_rerender: false });
|
||||||
|
}
|
||||||
responses.add(FrontendMessage::TriggerGraphViewOverlay { open });
|
responses.add(FrontendMessage::TriggerGraphViewOverlay { open });
|
||||||
}
|
}
|
||||||
PortfolioMessage::GraphViewOverlayToggle => {
|
PortfolioMessage::GraphViewOverlayToggle => {
|
||||||
|
|
@ -474,6 +477,9 @@ impl MessageHandler<PortfolioMessage, (&InputPreprocessorMessageHandler, &Prefer
|
||||||
responses.add(PortfolioMessage::UpdateDocumentWidgets);
|
responses.add(PortfolioMessage::UpdateDocumentWidgets);
|
||||||
responses.add(NavigationMessage::TranslateCanvas { delta: (0., 0.).into() });
|
responses.add(NavigationMessage::TranslateCanvas { delta: (0., 0.).into() });
|
||||||
responses.add(NodeGraphMessage::RunDocumentGraph);
|
responses.add(NodeGraphMessage::RunDocumentGraph);
|
||||||
|
if self.graph_view_overlay_open {
|
||||||
|
responses.add(NodeGraphMessage::SendGraph { should_rerender: false });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PortfolioMessage::SetActiveDocument { document_id } => {
|
PortfolioMessage::SetActiveDocument { document_id } => {
|
||||||
self.active_document_id = Some(document_id);
|
self.active_document_id = Some(document_id);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue